feat: Export THEME from the package (#4055)

* Use Theme type everywhere
* Rename Appearance type to Theme for consistency
* Reorder headers in readme
The host don't need to pass hardcoded strings any more and instead can use the exported constant
This commit is contained in:
Aakansha Doshi 2021-10-14 14:15:57 +05:30 committed by GitHub
parent be2da9539e
commit 463857ad9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 582 additions and 559 deletions

View File

@ -4,7 +4,7 @@ import { ColorPicker } from "../components/ColorPicker";
import { trash, zoomIn, zoomOut } from "../components/icons"; import { trash, zoomIn, zoomOut } from "../components/icons";
import { ToolButton } from "../components/ToolButton"; import { ToolButton } from "../components/ToolButton";
import { DarkModeToggle } from "../components/DarkModeToggle"; import { DarkModeToggle } from "../components/DarkModeToggle";
import { ZOOM_STEP } from "../constants"; import { THEME, ZOOM_STEP } from "../constants";
import { getCommonBounds, getNonDeletedElements } from "../element"; import { getCommonBounds, getNonDeletedElements } from "../element";
import { newElementWith } from "../element/mutateElement"; import { newElementWith } from "../element/mutateElement";
import { ExcalidrawElement } from "../element/types"; import { ExcalidrawElement } from "../element/types";
@ -279,7 +279,8 @@ export const actionToggleTheme = register({
return { return {
appState: { appState: {
...appState, ...appState,
theme: value || (appState.theme === "light" ? "dark" : "light"), theme:
value || (appState.theme === THEME.LIGHT ? THEME.DARK : THEME.LIGHT),
}, },
commitToHistory: false, commitToHistory: false,
}; };

View File

@ -5,7 +5,7 @@ import { ProjectName } from "../components/ProjectName";
import { ToolButton } from "../components/ToolButton"; import { ToolButton } from "../components/ToolButton";
import "../components/ToolIcon.scss"; import "../components/ToolIcon.scss";
import { Tooltip } from "../components/Tooltip"; import { Tooltip } from "../components/Tooltip";
import { DarkModeToggle, Appearence } from "../components/DarkModeToggle"; import { DarkModeToggle } from "../components/DarkModeToggle";
import { loadFromJSON, saveAsJSON } from "../data"; import { loadFromJSON, saveAsJSON } from "../data";
import { resaveAsImageWithScene } from "../data/resave"; import { resaveAsImageWithScene } from "../data/resave";
import { t } from "../i18n"; import { t } from "../i18n";
@ -14,12 +14,13 @@ import { KEYS } from "../keys";
import { register } from "./register"; import { register } from "./register";
import { CheckboxItem } from "../components/CheckboxItem"; import { CheckboxItem } from "../components/CheckboxItem";
import { getExportSize } from "../scene/export"; import { getExportSize } from "../scene/export";
import { DEFAULT_EXPORT_PADDING, EXPORT_SCALES } from "../constants"; import { DEFAULT_EXPORT_PADDING, EXPORT_SCALES, THEME } from "../constants";
import { getSelectedElements, isSomeElementSelected } from "../scene"; import { getSelectedElements, isSomeElementSelected } from "../scene";
import { getNonDeletedElements } from "../element"; import { getNonDeletedElements } from "../element";
import { ActiveFile } from "../components/ActiveFile"; import { ActiveFile } from "../components/ActiveFile";
import { isImageFileHandle } from "../data/blob"; import { isImageFileHandle } from "../data/blob";
import { nativeFileSystemSupported } from "../data/filesystem"; import { nativeFileSystemSupported } from "../data/filesystem";
import { Theme } from "../element/types";
export const actionChangeProjectName = register({ export const actionChangeProjectName = register({
name: "changeProjectName", name: "changeProjectName",
@ -256,9 +257,9 @@ export const actionExportWithDarkMode = register({
}} }}
> >
<DarkModeToggle <DarkModeToggle
value={appState.exportWithDarkMode ? "dark" : "light"} value={appState.exportWithDarkMode ? THEME.DARK : THEME.LIGHT}
onChange={(theme: Appearence) => { onChange={(theme: Theme) => {
updateData(theme === "dark"); updateData(theme === THEME.DARK);
}} }}
title={t("labels.toggleExportColorScheme")} title={t("labels.toggleExportColorScheme")}
/> />

View File

@ -4,6 +4,7 @@ import {
DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE,
DEFAULT_TEXT_ALIGN, DEFAULT_TEXT_ALIGN,
EXPORT_SCALES, EXPORT_SCALES,
THEME,
} from "./constants"; } from "./constants";
import { t } from "./i18n"; import { t } from "./i18n";
import { AppState, NormalizedZoomValue } from "./types"; import { AppState, NormalizedZoomValue } from "./types";
@ -18,7 +19,7 @@ export const getDefaultAppState = (): Omit<
"offsetTop" | "offsetLeft" | "width" | "height" "offsetTop" | "offsetLeft" | "width" | "height"
> => { > => {
return { return {
theme: "light", theme: THEME.LIGHT,
collaborators: new Map(), collaborators: new Map(),
currentChartType: "bar", currentChartType: "bar",
currentItemBackgroundColor: "transparent", currentItemBackgroundColor: "transparent",

View File

@ -60,6 +60,7 @@ import {
SCROLL_TIMEOUT, SCROLL_TIMEOUT,
TAP_TWICE_TIMEOUT, TAP_TWICE_TIMEOUT,
TEXT_TO_CENTER_SNAP_THRESHOLD, TEXT_TO_CENTER_SNAP_THRESHOLD,
THEME,
TOUCH_CTX_MENU_TIMEOUT, TOUCH_CTX_MENU_TIMEOUT,
URL_HASH_KEYS, URL_HASH_KEYS,
URL_QUERY_KEYS, URL_QUERY_KEYS,
@ -513,7 +514,7 @@ class App extends React.Component<AppProps, AppState> {
let viewModeEnabled = actionResult?.appState?.viewModeEnabled || false; let viewModeEnabled = actionResult?.appState?.viewModeEnabled || false;
let zenModeEnabled = actionResult?.appState?.zenModeEnabled || false; let zenModeEnabled = actionResult?.appState?.zenModeEnabled || false;
let gridSize = actionResult?.appState?.gridSize || null; let gridSize = actionResult?.appState?.gridSize || null;
let theme = actionResult?.appState?.theme || "light"; let theme = actionResult?.appState?.theme || THEME.LIGHT;
let name = actionResult?.appState?.name ?? this.state.name; let name = actionResult?.appState?.name ?? this.state.name;
if (typeof this.props.viewModeEnabled !== "undefined") { if (typeof this.props.viewModeEnabled !== "undefined") {
viewModeEnabled = this.props.viewModeEnabled; viewModeEnabled = this.props.viewModeEnabled;

View File

@ -3,14 +3,14 @@ import "./ToolIcon.scss";
import React from "react"; import React from "react";
import { t } from "../i18n"; import { t } from "../i18n";
import { ToolButton } from "./ToolButton"; import { ToolButton } from "./ToolButton";
import { THEME } from "../constants";
export type Appearence = "light" | "dark"; import { Theme } from "../element/types";
// We chose to use only explicit toggle and not a third option for system value, // We chose to use only explicit toggle and not a third option for system value,
// but this could be added in the future. // but this could be added in the future.
export const DarkModeToggle = (props: { export const DarkModeToggle = (props: {
value: Appearence; value: Theme;
onChange: (value: Appearence) => void; onChange: (value: Theme) => void;
title?: string; title?: string;
}) => { }) => {
const title = const title =
@ -20,10 +20,12 @@ export const DarkModeToggle = (props: {
return ( return (
<ToolButton <ToolButton
type="icon" type="icon"
icon={props.value === "light" ? ICONS.MOON : ICONS.SUN} icon={props.value === THEME.LIGHT ? ICONS.MOON : ICONS.SUN}
title={title} title={title}
aria-label={title} aria-label={title}
onClick={() => props.onChange(props.value === "dark" ? "light" : "dark")} onClick={() =>
props.onChange(props.value === THEME.DARK ? THEME.LIGHT : THEME.DARK)
}
data-testid="toggle-dark-mode" data-testid="toggle-dark-mode"
/> />
); );

View File

@ -6,6 +6,7 @@ import clsx from "clsx";
import { KEYS } from "../keys"; import { KEYS } from "../keys";
import { useExcalidrawContainer, useIsMobile } from "./App"; import { useExcalidrawContainer, useIsMobile } from "./App";
import { AppState } from "../types"; import { AppState } from "../types";
import { THEME } from "../constants";
export const Modal = (props: { export const Modal = (props: {
className?: string; className?: string;
@ -15,7 +16,7 @@ export const Modal = (props: {
labelledBy: string; labelledBy: string;
theme?: AppState["theme"]; theme?: AppState["theme"];
}) => { }) => {
const { theme = "light" } = props; const { theme = THEME.LIGHT } = props;
const modalRoot = useBodyRoot(theme); const modalRoot = useBodyRoot(theme);
if (!modalRoot) { if (!modalRoot) {

View File

@ -10,13 +10,15 @@ import React from "react";
import oc from "open-color"; import oc from "open-color";
import clsx from "clsx"; import clsx from "clsx";
import { Theme } from "../element/types";
import { THEME } from "../constants";
const activeElementColor = (theme: "light" | "dark") => const activeElementColor = (theme: Theme) =>
theme === "light" ? oc.orange[4] : oc.orange[9]; theme === THEME.LIGHT ? oc.orange[4] : oc.orange[9];
const iconFillColor = (theme: "light" | "dark") => const iconFillColor = (theme: Theme) =>
theme === "light" ? oc.black : oc.gray[4]; theme === THEME.LIGHT ? oc.black : oc.gray[4];
const handlerColor = (theme: "light" | "dark") => const handlerColor = (theme: Theme) =>
theme === "light" ? oc.white : "#1e1e1e"; theme === THEME.LIGHT ? oc.white : "#1e1e1e";
type Opts = { type Opts = {
width?: number; width?: number;
@ -175,8 +177,7 @@ export const resetZoom = createIcon(
{ width: 1024 }, { width: 1024 },
); );
export const BringForwardIcon = React.memo( export const BringForwardIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path <path
@ -196,8 +197,7 @@ export const BringForwardIcon = React.memo(
), ),
); );
export const SendBackwardIcon = React.memo( export const SendBackwardIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path <path
@ -217,8 +217,7 @@ export const SendBackwardIcon = React.memo(
), ),
); );
export const BringToFrontIcon = React.memo( export const BringToFrontIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path <path
@ -238,8 +237,7 @@ export const BringToFrontIcon = React.memo(
), ),
); );
export const SendToBackIcon = React.memo( export const SendToBackIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path <path
@ -265,8 +263,7 @@ export const SendToBackIcon = React.memo(
// first one the user sees. Horizontal align icons should not be flipped since // first one the user sees. Horizontal align icons should not be flipped since
// that would make them lie about their function. // that would make them lie about their function.
// //
export const AlignTopIcon = React.memo( export const AlignTopIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path <path
@ -287,8 +284,7 @@ export const AlignTopIcon = React.memo(
), ),
); );
export const AlignBottomIcon = React.memo( export const AlignBottomIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path <path
@ -309,8 +305,7 @@ export const AlignBottomIcon = React.memo(
), ),
); );
export const AlignLeftIcon = React.memo( export const AlignLeftIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path <path
@ -331,8 +326,7 @@ export const AlignLeftIcon = React.memo(
), ),
); );
export const AlignRightIcon = React.memo( export const AlignRightIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path <path
@ -354,7 +348,7 @@ export const AlignRightIcon = React.memo(
); );
export const DistributeHorizontallyIcon = React.memo( export const DistributeHorizontallyIcon = React.memo(
({ theme }: { theme: "light" | "dark" }) => ({ theme }: { theme: Theme }) =>
createIcon( createIcon(
<> <>
<path <path
@ -375,7 +369,7 @@ export const DistributeHorizontallyIcon = React.memo(
); );
export const DistributeVerticallyIcon = React.memo( export const DistributeVerticallyIcon = React.memo(
({ theme }: { theme: "light" | "dark" }) => ({ theme }: { theme: Theme }) =>
createIcon( createIcon(
<> <>
<path <path
@ -396,8 +390,7 @@ export const DistributeVerticallyIcon = React.memo(
), ),
); );
export const CenterVerticallyIcon = React.memo( export const CenterVerticallyIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path <path
@ -420,7 +413,7 @@ export const CenterVerticallyIcon = React.memo(
); );
export const CenterHorizontallyIcon = React.memo( export const CenterHorizontallyIcon = React.memo(
({ theme }: { theme: "light" | "dark" }) => ({ theme }: { theme: Theme }) =>
createIcon( createIcon(
<> <>
<path <path
@ -482,7 +475,7 @@ export const file = createIcon(
{ width: 384, height: 512 }, { width: 384, height: 512 },
); );
export const GroupIcon = React.memo(({ theme }: { theme: "light" | "dark" }) => export const GroupIcon = React.memo(({ theme }: { theme: Theme }) =>
createIcon( createIcon(
<> <>
<path d="M25 26H111V111H25" fill={iconFillColor(theme)} /> <path d="M25 26H111V111H25" fill={iconFillColor(theme)} />
@ -512,8 +505,7 @@ export const GroupIcon = React.memo(({ theme }: { theme: "light" | "dark" }) =>
), ),
); );
export const UngroupIcon = React.memo( export const UngroupIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path d="M25 26H111V111H25" fill={iconFillColor(theme)} /> <path d="M25 26H111V111H25" fill={iconFillColor(theme)} />
@ -545,8 +537,7 @@ export const UngroupIcon = React.memo(
), ),
); );
export const FillHachureIcon = React.memo( export const FillHachureIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
fillRule="evenodd" fillRule="evenodd"
@ -558,8 +549,7 @@ export const FillHachureIcon = React.memo(
), ),
); );
export const FillCrossHatchIcon = React.memo( export const FillCrossHatchIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<g fill={iconFillColor(theme)} fillRule="evenodd" clipRule="evenodd"> <g fill={iconFillColor(theme)} fillRule="evenodd" clipRule="evenodd">
<path d="M20.101 16H28.0934L36 8.95989V4H33.5779L20.101 16ZM30.5704 4L17.0935 16H9.10101L22.5779 4H30.5704ZM19.5704 4L6.09349 16H4V10.7475L11.5779 4H19.5704ZM8.57036 4H4V8.06952L8.57036 4ZM36 11.6378L31.101 16H36V11.6378ZM2 2V18H38V2H2Z" /> <path d="M20.101 16H28.0934L36 8.95989V4H33.5779L20.101 16ZM30.5704 4L17.0935 16H9.10101L22.5779 4H30.5704ZM19.5704 4L6.09349 16H4V10.7475L11.5779 4H19.5704ZM8.57036 4H4V8.06952L8.57036 4ZM36 11.6378L31.101 16H36V11.6378ZM2 2V18H38V2H2Z" />
@ -569,8 +559,7 @@ export const FillCrossHatchIcon = React.memo(
), ),
); );
export const FillSolidIcon = React.memo( export const FillSolidIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon(<path d="M2 2H38V18H2V2Z" fill={iconFillColor(theme)} />, { createIcon(<path d="M2 2H38V18H2V2Z" fill={iconFillColor(theme)} />, {
width: 40, width: 40,
height: 20, height: 20,
@ -578,7 +567,7 @@ export const FillSolidIcon = React.memo(
); );
export const StrokeWidthIcon = React.memo( export const StrokeWidthIcon = React.memo(
({ theme, strokeWidth }: { theme: "light" | "dark"; strokeWidth: number }) => ({ theme, strokeWidth }: { theme: Theme; strokeWidth: number }) =>
createIcon( createIcon(
<path <path
d="M6 10H32" d="M6 10H32"
@ -591,8 +580,7 @@ export const StrokeWidthIcon = React.memo(
), ),
); );
export const StrokeStyleSolidIcon = React.memo( export const StrokeStyleSolidIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
d="M6 10H34" d="M6 10H34"
@ -608,8 +596,7 @@ export const StrokeStyleSolidIcon = React.memo(
), ),
); );
export const StrokeStyleDashedIcon = React.memo( export const StrokeStyleDashedIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
d="M6 10H34" d="M6 10H34"
@ -623,8 +610,7 @@ export const StrokeStyleDashedIcon = React.memo(
), ),
); );
export const StrokeStyleDottedIcon = React.memo( export const StrokeStyleDottedIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
d="M6 10H36" d="M6 10H36"
@ -639,7 +625,7 @@ export const StrokeStyleDottedIcon = React.memo(
); );
export const SloppinessArchitectIcon = React.memo( export const SloppinessArchitectIcon = React.memo(
({ theme }: { theme: "light" | "dark" }) => ({ theme }: { theme: Theme }) =>
createIcon( createIcon(
<path <path
d="M3.00098 16.1691C6.28774 13.9744 19.6399 2.8905 22.7215 3.00082C25.8041 3.11113 19.1158 15.5488 21.4962 16.8309C23.8757 18.1131 34.4155 11.7148 37.0001 10.6919" d="M3.00098 16.1691C6.28774 13.9744 19.6399 2.8905 22.7215 3.00082C25.8041 3.11113 19.1158 15.5488 21.4962 16.8309C23.8757 18.1131 34.4155 11.7148 37.0001 10.6919"
@ -652,8 +638,7 @@ export const SloppinessArchitectIcon = React.memo(
), ),
); );
export const SloppinessArtistIcon = React.memo( export const SloppinessArtistIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
d="M3 17C6.68158 14.8752 16.1296 9.09849 22.0648 6.54922C28 3.99995 22.2896 13.3209 25 14C27.7104 14.6791 36.3757 9.6471 36.3757 9.6471M6.40706 15C13 11.1918 20.0468 1.51045 23.0234 3.0052C26 4.49995 20.457 12.8659 22.7285 16.4329C25 20 36.3757 13 36.3757 13" d="M3 17C6.68158 14.8752 16.1296 9.09849 22.0648 6.54922C28 3.99995 22.2896 13.3209 25 14C27.7104 14.6791 36.3757 9.6471 36.3757 9.6471M6.40706 15C13 11.1918 20.0468 1.51045 23.0234 3.0052C26 4.49995 20.457 12.8659 22.7285 16.4329C25 20 36.3757 13 36.3757 13"
@ -667,7 +652,7 @@ export const SloppinessArtistIcon = React.memo(
); );
export const SloppinessCartoonistIcon = React.memo( export const SloppinessCartoonistIcon = React.memo(
({ theme }: { theme: "light" | "dark" }) => ({ theme }: { theme: Theme }) =>
createIcon( createIcon(
<path <path
d="M3 15.6468C6.93692 13.5378 22.5544 2.81528 26.6206 3.00242C30.6877 3.18956 25.6708 15.3346 27.4009 16.7705C29.1309 18.2055 35.4001 12.4762 37 11.6177M3.97143 10.4917C6.61158 9.24563 16.3706 2.61886 19.8104 3.01724C23.2522 3.41472 22.0773 12.2013 24.6181 12.8783C27.1598 13.5536 33.3179 8.04068 35.0571 7.07244" d="M3 15.6468C6.93692 13.5378 22.5544 2.81528 26.6206 3.00242C30.6877 3.18956 25.6708 15.3346 27.4009 16.7705C29.1309 18.2055 35.4001 12.4762 37 11.6177M3.97143 10.4917C6.61158 9.24563 16.3706 2.61886 19.8104 3.01724C23.2522 3.41472 22.0773 12.2013 24.6181 12.8783C27.1598 13.5536 33.3179 8.04068 35.0571 7.07244"
@ -680,8 +665,7 @@ export const SloppinessCartoonistIcon = React.memo(
), ),
); );
export const EdgeSharpIcon = React.memo( export const EdgeSharpIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
d="M10 17L10 5L35 5" d="M10 17L10 5L35 5"
@ -694,8 +678,7 @@ export const EdgeSharpIcon = React.memo(
), ),
); );
export const EdgeRoundIcon = React.memo( export const EdgeRoundIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
d="M10 17V15C10 8 13 5 21 5L33.5 5" d="M10 17V15C10 8 13 5 21 5L33.5 5"
@ -708,8 +691,7 @@ export const EdgeRoundIcon = React.memo(
), ),
); );
export const ArrowheadNoneIcon = React.memo( export const ArrowheadNoneIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
d="M6 10H34" d="M6 10H34"
@ -725,7 +707,7 @@ export const ArrowheadNoneIcon = React.memo(
); );
export const ArrowheadArrowIcon = React.memo( export const ArrowheadArrowIcon = React.memo(
({ theme, flip = false }: { theme: "light" | "dark"; flip?: boolean }) => ({ theme, flip = false }: { theme: Theme; flip?: boolean }) =>
createIcon( createIcon(
<g <g
transform={flip ? "translate(40, 0) scale(-1, 1)" : ""} transform={flip ? "translate(40, 0) scale(-1, 1)" : ""}
@ -741,7 +723,7 @@ export const ArrowheadArrowIcon = React.memo(
); );
export const ArrowheadDotIcon = React.memo( export const ArrowheadDotIcon = React.memo(
({ theme, flip = false }: { theme: "light" | "dark"; flip?: boolean }) => ({ theme, flip = false }: { theme: Theme; flip?: boolean }) =>
createIcon( createIcon(
<g <g
stroke={iconFillColor(theme)} stroke={iconFillColor(theme)}
@ -756,7 +738,7 @@ export const ArrowheadDotIcon = React.memo(
); );
export const ArrowheadBarIcon = React.memo( export const ArrowheadBarIcon = React.memo(
({ theme, flip = false }: { theme: "light" | "dark"; flip?: boolean }) => ({ theme, flip = false }: { theme: Theme; flip?: boolean }) =>
createIcon( createIcon(
<g transform={flip ? "translate(40, 0) scale(-1, 1)" : ""}> <g transform={flip ? "translate(40, 0) scale(-1, 1)" : ""}>
<path <path
@ -770,8 +752,7 @@ export const ArrowheadBarIcon = React.memo(
), ),
); );
export const FontSizeSmallIcon = React.memo( export const FontSizeSmallIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
fill={iconFillColor(theme)} fill={iconFillColor(theme)}
@ -781,8 +762,7 @@ export const FontSizeSmallIcon = React.memo(
), ),
); );
export const FontSizeMediumIcon = React.memo( export const FontSizeMediumIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
fill={iconFillColor(theme)} fill={iconFillColor(theme)}
@ -792,8 +772,7 @@ export const FontSizeMediumIcon = React.memo(
), ),
); );
export const FontSizeLargeIcon = React.memo( export const FontSizeLargeIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
fill={iconFillColor(theme)} fill={iconFillColor(theme)}
@ -804,7 +783,7 @@ export const FontSizeLargeIcon = React.memo(
); );
export const FontSizeExtraLargeIcon = React.memo( export const FontSizeExtraLargeIcon = React.memo(
({ theme }: { theme: "light" | "dark" }) => ({ theme }: { theme: Theme }) =>
createIcon( createIcon(
<path <path
fill={iconFillColor(theme)} fill={iconFillColor(theme)}
@ -815,7 +794,7 @@ export const FontSizeExtraLargeIcon = React.memo(
); );
export const FontFamilyHandDrawnIcon = React.memo( export const FontFamilyHandDrawnIcon = React.memo(
({ theme }: { theme: "light" | "dark" }) => ({ theme }: { theme: Theme }) =>
createIcon( createIcon(
<path <path
fill={iconFillColor(theme)} fill={iconFillColor(theme)}
@ -825,8 +804,7 @@ export const FontFamilyHandDrawnIcon = React.memo(
), ),
); );
export const FontFamilyNormalIcon = React.memo( export const FontFamilyNormalIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path <path
@ -842,8 +820,7 @@ export const FontFamilyNormalIcon = React.memo(
), ),
); );
export const FontFamilyCodeIcon = React.memo( export const FontFamilyCodeIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<> <>
<path <path
@ -855,8 +832,7 @@ export const FontFamilyCodeIcon = React.memo(
), ),
); );
export const TextAlignLeftIcon = React.memo( export const TextAlignLeftIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
d="M12.83 352h262.34A12.82 12.82 0 00288 339.17v-38.34A12.82 12.82 0 00275.17 288H12.83A12.82 12.82 0 000 300.83v38.34A12.82 12.82 0 0012.83 352zm0-256h262.34A12.82 12.82 0 00288 83.17V44.83A12.82 12.82 0 00275.17 32H12.83A12.82 12.82 0 000 44.83v38.34A12.82 12.82 0 0012.83 96zM432 160H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16zm0 256H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16z" d="M12.83 352h262.34A12.82 12.82 0 00288 339.17v-38.34A12.82 12.82 0 00275.17 288H12.83A12.82 12.82 0 000 300.83v38.34A12.82 12.82 0 0012.83 352zm0-256h262.34A12.82 12.82 0 00288 83.17V44.83A12.82 12.82 0 00275.17 32H12.83A12.82 12.82 0 000 44.83v38.34A12.82 12.82 0 0012.83 96zM432 160H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16zm0 256H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16z"
@ -867,8 +843,7 @@ export const TextAlignLeftIcon = React.memo(
), ),
); );
export const TextAlignCenterIcon = React.memo( export const TextAlignCenterIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
d="M432 160H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16zm0 256H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16zM108.1 96h231.81A12.09 12.09 0 00352 83.9V44.09A12.09 12.09 0 00339.91 32H108.1A12.09 12.09 0 0096 44.09V83.9A12.1 12.1 0 00108.1 96zm231.81 256A12.09 12.09 0 00352 339.9v-39.81A12.09 12.09 0 00339.91 288H108.1A12.09 12.09 0 0096 300.09v39.81a12.1 12.1 0 0012.1 12.1z" d="M432 160H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16zm0 256H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16zM108.1 96h231.81A12.09 12.09 0 00352 83.9V44.09A12.09 12.09 0 00339.91 32H108.1A12.09 12.09 0 0096 44.09V83.9A12.1 12.1 0 00108.1 96zm231.81 256A12.09 12.09 0 00352 339.9v-39.81A12.09 12.09 0 00339.91 288H108.1A12.09 12.09 0 0096 300.09v39.81a12.1 12.1 0 0012.1 12.1z"
@ -878,8 +853,7 @@ export const TextAlignCenterIcon = React.memo(
), ),
); );
export const TextAlignRightIcon = React.memo( export const TextAlignRightIcon = React.memo(({ theme }: { theme: Theme }) =>
({ theme }: { theme: "light" | "dark" }) =>
createIcon( createIcon(
<path <path
d="M16 224h416a16 16 0 0016-16v-32a16 16 0 00-16-16H16a16 16 0 00-16 16v32a16 16 0 0016 16zm416 192H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16zm3.17-384H172.83A12.82 12.82 0 00160 44.83v38.34A12.82 12.82 0 00172.83 96h262.34A12.82 12.82 0 00448 83.17V44.83A12.82 12.82 0 00435.17 32zm0 256H172.83A12.82 12.82 0 00160 300.83v38.34A12.82 12.82 0 00172.83 352h262.34A12.82 12.82 0 00448 339.17v-38.34A12.82 12.82 0 00435.17 288z" d="M16 224h416a16 16 0 0016-16v-32a16 16 0 00-16-16H16a16 16 0 00-16 16v32a16 16 0 0016 16zm416 192H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16zm3.17-384H172.83A12.82 12.82 0 00160 44.83v38.34A12.82 12.82 0 00172.83 96h262.34A12.82 12.82 0 00448 83.17V44.83A12.82 12.82 0 00435.17 32zm0 256H172.83A12.82 12.82 0 00160 300.83v38.34A12.82 12.82 0 00172.83 352h262.34A12.82 12.82 0 00448 339.17v-38.34A12.82 12.82 0 00435.17 288z"

View File

@ -70,6 +70,11 @@ export const FONT_FAMILY = {
Cascadia: 3, Cascadia: 3,
}; };
export const THEME = {
LIGHT: "light",
DARK: "dark",
};
export const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji"; export const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
export const DEFAULT_FONT_SIZE = 20; export const DEFAULT_FONT_SIZE = 20;

View File

@ -1,10 +1,11 @@
import { Point } from "../types"; import { Point } from "../types";
import { FONT_FAMILY } from "../constants"; import { FONT_FAMILY, THEME } from "../constants";
export type ChartType = "bar" | "line"; export type ChartType = "bar" | "line";
export type FillStyle = "hachure" | "cross-hatch" | "solid"; export type FillStyle = "hachure" | "cross-hatch" | "solid";
export type FontFamilyKeys = keyof typeof FONT_FAMILY; export type FontFamilyKeys = keyof typeof FONT_FAMILY;
export type FontFamilyValues = typeof FONT_FAMILY[FontFamilyKeys]; export type FontFamilyValues = typeof FONT_FAMILY[FontFamilyKeys];
export type Theme = typeof THEME[keyof typeof THEME];
export type FontString = string & { _brand: "fontString" }; export type FontString = string & { _brand: "fontString" };
export type GroupId = string; export type GroupId = string;
export type PointerType = "mouse" | "pen" | "touch"; export type PointerType = "mouse" | "pen" | "touch";

View File

@ -1,9 +1,11 @@
import oc from "open-color"; import oc from "open-color";
import React from "react"; import React from "react";
import { THEME } from "../../constants";
import { Theme } from "../../element/types";
// https://github.com/tholman/github-corners // https://github.com/tholman/github-corners
export const GitHubCorner = React.memo( export const GitHubCorner = React.memo(
({ theme, dir }: { theme: "light" | "dark"; dir: string }) => ( ({ theme, dir }: { theme: Theme; dir: string }) => (
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
width="40" width="40"
@ -25,18 +27,18 @@ export const GitHubCorner = React.memo(
> >
<path <path
d="M0 0l115 115h15l12 27 108 108V0z" d="M0 0l115 115h15l12 27 108 108V0z"
fill={theme === "light" ? oc.gray[6] : oc.gray[7]} fill={theme === THEME.LIGHT ? oc.gray[6] : oc.gray[7]}
/> />
<path <path
className="octo-arm" className="octo-arm"
d="M128 109c-15-9-9-19-9-19 3-7 2-11 2-11-1-7 3-2 3-2 4 5 2 11 2 11-3 10 5 15 9 16" d="M128 109c-15-9-9-19-9-19 3-7 2-11 2-11-1-7 3-2 3-2 4 5 2 11 2 11-3 10 5 15 9 16"
style={{ transformOrigin: "130px 106px" }} style={{ transformOrigin: "130px 106px" }}
fill={theme === "light" ? oc.white : "var(--default-bg-color)"} fill={theme === THEME.LIGHT ? oc.white : "var(--default-bg-color)"}
/> />
<path <path
className="octo-body" className="octo-body"
d="M115 115s4 2 5 0l14-14c3-2 6-3 8-3-8-11-15-24 2-41 5-5 10-7 16-7 1-2 3-7 12-11 0 0 5 3 7 16 4 2 8 5 12 9s7 8 9 12c14 3 17 7 17 7-4 8-9 11-11 11 0 6-2 11-7 16-16 16-30 10-41 2 0 3-1 7-5 11l-12 11c-1 1 1 5 1 5z" d="M115 115s4 2 5 0l14-14c3-2 6-3 8-3-8-11-15-24 2-41 5-5 10-7 16-7 1-2 3-7 12-11 0 0 5 3 7 16 4 2 8 5 12 9s7 8 9 12c14 3 17 7 17 7-4 8-9 11-11 11 0 6-2 11-7 16-16 16-30 10-41 2 0 3-1 7-5 11l-12 11c-1 1 1 5 1 5z"
fill={theme === "light" ? oc.white : "var(--default-bg-color)"} fill={theme === THEME.LIGHT ? oc.white : "var(--default-bg-color)"}
/> />
</a> </a>
</svg> </svg>

View File

@ -11,6 +11,20 @@ The change should be grouped under one of the below section and must contain PR
Please add the latest change on the top under the correct section. Please add the latest change on the top under the correct section.
--> -->
## Unreleased
## Excalidraw API
### Features
- Export `THEME` constant from the package so host can use this when passing the theme
#### BREAKING CHANGE
The `Appearance` type is now removed and renamed to `Theme` so `Theme` type needs to be used.
---
## 0.10.0 (2021-10-13) ## 0.10.0 (2021-10-13)
## Excalidraw API ## Excalidraw API

View File

@ -371,7 +371,7 @@ To view the full example visit :point_down:
| [`zenModeEnabled`](#zenModeEnabled) | boolean | | This implies if the zen mode is enabled | | [`zenModeEnabled`](#zenModeEnabled) | boolean | | This implies if the zen mode is enabled |
| [`gridModeEnabled`](#gridModeEnabled) | boolean | | This implies if the grid mode is enabled | | [`gridModeEnabled`](#gridModeEnabled) | boolean | | This implies if the grid mode is enabled |
| [`libraryReturnUrl`](#libraryReturnUrl) | string | | What URL should [libraries.excalidraw.com](https://libraries.excalidraw.com) be installed to | | [`libraryReturnUrl`](#libraryReturnUrl) | string | | What URL should [libraries.excalidraw.com](https://libraries.excalidraw.com) be installed to |
| [`theme`](#theme) | `light` or `dark` | | The theme of the Excalidraw component | | [`theme`](#theme) | [THEME.LIGHT](#THEME-1) &#124; [THEME.LIGHT](#THEME-1) | [THEME.LIGHT](#THEME-1) | The theme of the Excalidraw component |
| [`name`](#name) | string | | Name of the drawing | | [`name`](#name) | string | | Name of the drawing |
| [`UIOptions`](#UIOptions) | <pre>{ canvasActions: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L208"> CanvasActions<a/> }</pre> | [DEFAULT UI OPTIONS](https://github.com/excalidraw/excalidraw/blob/master/src/constants.ts#L129) | To customise UI options. Currently we support customising [`canvas actions`](#canvasActions) | | [`UIOptions`](#UIOptions) | <pre>{ canvasActions: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L208"> CanvasActions<a/> }</pre> | [DEFAULT UI OPTIONS](https://github.com/excalidraw/excalidraw/blob/master/src/constants.ts#L129) | To customise UI options. Currently we support customising [`canvas actions`](#canvasActions) |
| [`onPaste`](#onPaste) | <pre>(data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/clipboard.ts#L17">ClipboardData</a>, event: ClipboardEvent &#124; null) => boolean</pre> | | Callback to be triggered if passed when the something is pasted in to the scene | | [`onPaste`](#onPaste) | <pre>(data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/clipboard.ts#L17">ClipboardData</a>, event: ClipboardEvent &#124; null) => boolean</pre> | | Callback to be triggered if passed when the something is pasted in to the scene |
@ -564,7 +564,7 @@ If supplied, this URL will be used when user tries to install a library from [li
#### `theme` #### `theme`
This prop controls Excalidraw's theme. When supplied, the value takes precedence over `intialData.appState.theme`, the theme will be fully controlled by the host app, and users won't be able to toggle it from within the app. This prop controls Excalidraw's theme. When supplied, the value takes precedence over `intialData.appState.theme`, the theme will be fully controlled by the host app, and users won't be able to toggle it from within the app. You can use [`THEME`](#THEME-1) to specify the theme.
#### `name` #### `name`
@ -612,11 +612,7 @@ This callback must return a `boolean` value or a [promise](https://developer.moz
In case you want to prevent the excalidraw paste action you must return `false`, it will stop the native excalidraw clipboard management flow (nothing will be pasted into the scene). In case you want to prevent the excalidraw paste action you must return `false`, it will stop the native excalidraw clipboard management flow (nothing will be pasted into the scene).
### Does it support collaboration ? #### `importLibrary`
No, Excalidraw package doesn't come with collaboration built in, since the implementation is specific to each host app. We expose APIs which you can use to communicate with Excalidraw which you can use to implement it. You can check our own implementation [here](https://github.com/excalidraw/excalidraw/blob/master/src/excalidraw-app/index.tsx).
### importLibrary
Imports library from given URL. You should call this on `hashchange`, passing the `addLibrary` value if you detect it as shown below. Optionally pass a CSRF `token` to skip prompting during installation (retrievable via `token` key from the url coming from [https://libraries.excalidraw.com](https://libraries.excalidraw.com/)). Imports library from given URL. You should call this on `hashchange`, passing the `addLibrary` value if you detect it as shown below. Optionally pass a CSRF `token` to skip prompting during installation (retrievable via `token` key from the url coming from [https://libraries.excalidraw.com](https://libraries.excalidraw.com/)).
@ -638,17 +634,17 @@ useEffect(() => {
Try out the [Demo](#Demo) to see it in action. Try out the [Demo](#Demo) to see it in action.
### detectScroll #### `detectScroll`
Indicates whether Excalidraw should listen for `scroll` event on the nearest scrollable container in the DOM tree and recompute the coordinates (e.g. to correctly handle the cursor) when the component's position changes. You can disable this when you either know this doesn't affect your app or you want to take care of it yourself (calling the [`refresh()`](#ref) method). Indicates whether Excalidraw should listen for `scroll` event on the nearest scrollable container in the DOM tree and recompute the coordinates (e.g. to correctly handle the cursor) when the component's position changes. You can disable this when you either know this doesn't affect your app or you want to take care of it yourself (calling the [`refresh()`](#ref) method).
### handleKeyboardGlobally #### `handleKeyboardGlobally`
Indicates whether to bind keyboard events to `document`. Disabled by default, meaning the keyboard events are bound to the Excalidraw component. This allows for multiple Excalidraw components to live on the same page, and ensures that Excalidraw keyboard handling doesn't collide with your app's (or the browser) when the component isn't focused. Indicates whether to bind keyboard events to `document`. Disabled by default, meaning the keyboard events are bound to the Excalidraw component. This allows for multiple Excalidraw components to live on the same page, and ensures that Excalidraw keyboard handling doesn't collide with your app's (or the browser) when the component isn't focused.
Enable this if you want Excalidraw to handle keyboard even if the component isn't focused (e.g. a user is interacting with the navbar, sidebar, or similar). Enable this if you want Excalidraw to handle keyboard even if the component isn't focused (e.g. a user is interacting with the navbar, sidebar, or similar).
### onLibraryChange #### `onLibraryChange`
Ths callback if supplied will get triggered when the library is updated and has the below signature. Ths callback if supplied will get triggered when the library is updated and has the below signature.
@ -658,58 +654,17 @@ Ths callback if supplied will get triggered when the library is updated and has
It is invoked with empty items when user clears the library. You can use this callback when you want to do something additional when library is updated for example persisting it to local storage. It is invoked with empty items when user clears the library. You can use this callback when you want to do something additional when library is updated for example persisting it to local storage.
### id #### `id`
The unique id of the excalidraw component. This can be used to identify the excalidraw component, for example importing the library items to the excalidraw component from where it was initiated when you have multiple excalidraw components rendered on the same page as shown in [multiple excalidraw demo](https://codesandbox.io/s/multiple-excalidraw-k1xx5). The unique id of the excalidraw component. This can be used to identify the excalidraw component, for example importing the library items to the excalidraw component from where it was initiated when you have multiple excalidraw components rendered on the same page as shown in [multiple excalidraw demo](https://codesandbox.io/s/multiple-excalidraw-k1xx5).
### autoFocus #### `autoFocus`
This prop implies whether to focus the Excalidraw component on page load. Defaults to false. This prop implies whether to focus the Excalidraw component on page load. Defaults to false.
### Extra API's ### Does it support collaboration ?
#### `getSceneVersion` No, Excalidraw package doesn't come with collaboration built in, since the implementation is specific to each host app. We expose APIs which you can use to communicate with Excalidraw which you can use to implement it. You can check our own implementation [here](https://github.com/excalidraw/excalidraw/blob/master/src/excalidraw-app/index.tsx).
**How to use**
<pre>
import { getSceneVersion } from "@excalidraw/excalidraw-next";
getSceneVersion(elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>)
</pre>
This function returns the current scene version.
#### `isInvisiblySmallElement`
**_Signature_**
<pre>
isInvisiblySmallElement(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement</a>): boolean
</pre>
**How to use**
```js
import { isInvisiblySmallElement } from "@excalidraw/excalidraw-next";
```
Returns `true` if element is invisibly small (e.g. width & height are zero).
#### `getElementMap`
**_Signature_**
<pre>
getElementsMap(elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>): {[id: string]: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement</a>}
</pre>
**How to use**
```js
import { getElementsMap } from "@excalidraw/excalidraw-next";
```
This function returns an object where each element is mapped to its id.
### Restore utilities ### Restore utilities
@ -767,19 +722,6 @@ import { restore } from "@excalidraw/excalidraw-next";
This function makes sure elements and state is set to appropriate values and set to default value if not present. It is a combination of [restoreElements](#restoreElements) and [restoreAppState](#restoreAppState). This function makes sure elements and state is set to appropriate values and set to default value if not present. It is a combination of [restoreElements](#restoreElements) and [restoreAppState](#restoreAppState).
#### `serializeAsJSON`
**_Signature_**
<pre>
serializeAsJSON({
elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>,
appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L42">AppState</a>,
}): string
</pre>
Takes the scene elements and state and returns a JSON string. Deleted `elements`as well as most properties from `AppState` are removed from the resulting JSON. (see [`serializeAsJSON()`](https://github.com/excalidraw/excalidraw/blob/master/src/data/json.ts#L16) source for details).
### Export utilities ### Export utilities
#### `exportToCanvas` #### `exportToCanvas`
@ -864,7 +806,113 @@ This function returns a promise which resolves to svg of the exported drawing.
| exportWithDarkMode | boolean | false | Indicates whether to export with dark mode | | exportWithDarkMode | boolean | false | Indicates whether to export with dark mode |
| exportEmbedScene | boolean | false | Indicates whether scene data should be embedded in svg. This will increase the svg size. | | exportEmbedScene | boolean | false | Indicates whether scene data should be embedded in svg. This will increase the svg size. |
### FONT_FAMILY ### Extra API's
#### `serializeAsJSON`
**_Signature_**
<pre>
serializeAsJSON({
elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>,
appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L42">AppState</a>,
}): string
</pre>
Takes the scene elements and state and returns a JSON string. Deleted `elements`as well as most properties from `AppState` are removed from the resulting JSON. (see [`serializeAsJSON()`](https://github.com/excalidraw/excalidraw/blob/master/src/data/json.ts#L16) source for details).
#### `getSceneVersion`
**How to use**
<pre>
import { getSceneVersion } from "@excalidraw/excalidraw-next";
getSceneVersion(elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>)
</pre>
This function returns the current scene version.
#### `isInvisiblySmallElement`
**_Signature_**
<pre>
isInvisiblySmallElement(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement</a>): boolean
</pre>
**How to use**
```js
import { isInvisiblySmallElement } from "@excalidraw/excalidraw-next";
```
Returns `true` if element is invisibly small (e.g. width & height are zero).
#### `getElementMap`
**_Signature_**
<pre>
getElementsMap(elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>): {[id: string]: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement</a>}
</pre>
**How to use**
```js
import { getElementsMap } from "@excalidraw/excalidraw-next";
```
This function returns an object where each element is mapped to its id.
#### `loadLibraryFromBlob`
```js
import { loadLibraryFromBlob } from "@excalidraw/excalidraw-next";
```
**_Signature_**
<pre>
loadLibraryFromBlob(blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>)
</pre>
This function loads the library from the blob.
#### `loadFromBlob`
**How to use**
```js
import { loadFromBlob } from "@excalidraw/excalidraw-next";
```
**Signature**
<pre>
loadFromBlob(blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>, localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L42">AppState</a> | null)
</pre>
This function loads the scene data from the blob. If you pass `localAppState`, `localAppState` value will be preferred over the `appState` derived from `blob`
#### `getFreeDrawSvgPath`
**How to use**
```js
import { getFreeDrawSvgPath } from "@excalidraw/excalidraw-next";
```
**Signature**
<pre>
getFreeDrawSvgPath(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L127">ExcalidrawFreeDrawElement</a>
</pre>
This function returns the free draw svg path for the element.
### Exported constants
#### `FONT_FAMILY`
**How to use** **How to use**
@ -882,51 +930,22 @@ import { FONT_FAMILY } from "@excalidraw/excalidraw-next";
Defaults to `FONT_FAMILY.Virgil` unless passed in `initialData.appState.currentItemFontFamily`. Defaults to `FONT_FAMILY.Virgil` unless passed in `initialData.appState.currentItemFontFamily`.
### loadLibraryFromBlob #### `THEME`
```js
import { loadLibraryFromBlob } from "@excalidraw/excalidraw-next";
```
**_Signature_**
<pre>
loadLibraryFromBlob(blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>)
</pre>
This function loads the library from the blob.
### loadFromBlob
**How to use** **How to use**
```js ```js
import { loadFromBlob } from "@excalidraw/excalidraw-next"; import { THEME } from "@excalidraw/excalidraw-next";
``` ```
**Signature** `THEME` contains all the themes supported by `Excalidraw` as explained below
<pre> | Theme | Description |
loadFromBlob(blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>, localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L42">AppState</a> | null) | ----- | --------------- |
</pre> | LIGHT | The light theme |
| DARK | The Dark theme |
This function loads the scene data from the blob. If you pass `localAppState`, `localAppState` value will be preferred over the `appState` derived from `blob` Defaults to `THEME.LIGHT` unless passed in `initialData.appState.theme`
### getFreeDrawSvgPath
**How to use**
```js
import { getFreeDrawSvgPath } from "@excalidraw/excalidraw-next";
```
**Signature**
<pre>
getFreeDrawSvgPath(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L127">ExcalidrawFreeDrawElement</a>
</pre>
This function returns the free draw svg path for the element.
## Need help? ## Need help?

View File

@ -183,4 +183,4 @@ export {
loadFromBlob, loadFromBlob,
getFreeDrawSvgPath, getFreeDrawSvgPath,
} from "../../packages/utils"; } from "../../packages/utils";
export { FONT_FAMILY } from "../../constants"; export { FONT_FAMILY, THEME } from "../../constants";

View File

@ -2,7 +2,7 @@ import React from "react";
import { fireEvent, GlobalTestState, render } from "../test-utils"; import { fireEvent, GlobalTestState, render } from "../test-utils";
import Excalidraw from "../../packages/excalidraw/index"; import Excalidraw from "../../packages/excalidraw/index";
import { queryByText, queryByTestId } from "@testing-library/react"; import { queryByText, queryByTestId } from "@testing-library/react";
import { GRID_SIZE } from "../../constants"; import { GRID_SIZE, THEME } from "../../constants";
import { t } from "../../i18n"; import { t } from "../../i18n";
const { h } = window; const { h } = window;
@ -91,7 +91,7 @@ describe("<Excalidraw/>", () => {
describe("Test theme prop", () => { describe("Test theme prop", () => {
it('should show the dark mode toggle when the theme prop is "undefined"', async () => { it('should show the dark mode toggle when the theme prop is "undefined"', async () => {
const { container } = await render(<Excalidraw />); const { container } = await render(<Excalidraw />);
expect(h.state.theme).toBe("light"); expect(h.state.theme).toBe(THEME.LIGHT);
const darkModeToggle = queryByTestId(container, "toggle-dark-mode"); const darkModeToggle = queryByTestId(container, "toggle-dark-mode");
@ -100,7 +100,7 @@ describe("<Excalidraw/>", () => {
it('should not show the dark mode toggle when the theme prop is not "undefined"', async () => { it('should not show the dark mode toggle when the theme prop is not "undefined"', async () => {
const { container } = await render(<Excalidraw theme="dark" />); const { container } = await render(<Excalidraw theme="dark" />);
expect(h.state.theme).toBe("dark"); expect(h.state.theme).toBe(THEME.DARK);
expect(queryByTestId(container, "toggle-dark-mode")).toBe(null); expect(queryByTestId(container, "toggle-dark-mode")).toBe(null);
}); });

View File

@ -10,6 +10,7 @@ import {
Arrowhead, Arrowhead,
ChartType, ChartType,
FontFamilyValues, FontFamilyValues,
Theme,
} from "./element/types"; } from "./element/types";
import { SHAPES } from "./shapes"; import { SHAPES } from "./shapes";
import { Point as RoughPoint } from "roughjs/bin/geometry"; import { Point as RoughPoint } from "roughjs/bin/geometry";
@ -98,7 +99,7 @@ export type AppState = {
showHelpDialog: boolean; showHelpDialog: boolean;
toastMessage: string | null; toastMessage: string | null;
zenModeEnabled: boolean; zenModeEnabled: boolean;
theme: "light" | "dark"; theme: Theme;
gridSize: number | null; gridSize: number | null;
viewModeEnabled: boolean; viewModeEnabled: boolean;
@ -192,7 +193,7 @@ export interface ExcalidrawProps {
zenModeEnabled?: boolean; zenModeEnabled?: boolean;
gridModeEnabled?: boolean; gridModeEnabled?: boolean;
libraryReturnUrl?: string; libraryReturnUrl?: string;
theme?: "dark" | "light"; theme?: Theme;
name?: string; name?: string;
renderCustomStats?: ( renderCustomStats?: (
elements: readonly NonDeletedExcalidrawElement[], elements: readonly NonDeletedExcalidrawElement[],