mirror of
https://github.com/excalidraw/excalidraw.git
synced 2026-12-05 18:55:28 +03:00
* fix(editor): keep the split-paste preference in the app state, not in localStorage The editor wrote the preference to the host's localStorage itself. It's an app state key now (splitPastedTextEnabled, kept in the browser as the other preferences are), for the host to store with the rest. Removes the EDITOR_LS_KEYS.PASTE_TEXT_AS_LINES key and the ownerWindow parameter of EditorLocalStorage, which nothing uses any more. * refactor(editor): rename splitPastedTextEnabled to splitOnPaste
632 lines
19 KiB
TypeScript
632 lines
19 KiB
TypeScript
import type {
|
|
ExcalidrawElement,
|
|
FontFamilyValues,
|
|
} from "@excalidraw/element/types";
|
|
import type {
|
|
AppProps,
|
|
AppState,
|
|
NormalizedZoomValue,
|
|
} from "@excalidraw/excalidraw/types";
|
|
|
|
import { COLOR_PALETTE } from "./colors";
|
|
|
|
export { DEFAULT_STICKY_NOTE_BG } from "./colors";
|
|
|
|
export const supportsResizeObserver =
|
|
typeof window !== "undefined" && "ResizeObserver" in window;
|
|
|
|
export const APP_NAME = "Excalidraw";
|
|
|
|
// distance when creating text before it's considered `autoResize: false`
|
|
// we're using higher threshold so that clicks that end up being drags
|
|
// don't unintentionally create text elements that are wrapped to a few chars
|
|
// (happens a lot with fast clicks with the text tool)
|
|
export const TEXT_AUTOWRAP_THRESHOLD = 36; // px
|
|
// room left at each side of the visible canvas when a text stops growing at
|
|
// its width, or is brought into view once it wraps
|
|
export const TEXT_VIEWPORT_PADDING = 20; // px
|
|
// the widest a typed or pasted text gets before it wraps, however wide the
|
|
// view: in scene units when zoomed in or at 100%, on screen when zoomed out
|
|
// (so the further out, the wider in scene units)...
|
|
export const TEXT_MAX_WRAP_WIDTH = 800; // px
|
|
// ...up to this width, in scene units
|
|
export const TEXT_MAX_WRAP_WIDTH_ZOOMED_OUT = 2000; // px
|
|
export const DRAGGING_THRESHOLD = 10; // px
|
|
export const MINIMUM_ARROW_SIZE = 20; // px
|
|
export const LINE_CONFIRM_THRESHOLD = 8; // px
|
|
export const ELEMENT_SHIFT_TRANSLATE_AMOUNT = 5;
|
|
export const ELEMENT_TRANSLATE_AMOUNT = 1;
|
|
export const TEXT_TO_CENTER_SNAP_THRESHOLD = 30;
|
|
export const SHIFT_LOCKING_ANGLE = Math.PI / 12;
|
|
export const DEFAULT_LASER_COLOR = "red";
|
|
export const CURSOR_TYPE = {
|
|
TEXT: "text",
|
|
CROSSHAIR: "crosshair",
|
|
GRABBING: "grabbing",
|
|
GRAB: "grab",
|
|
POINTER: "pointer",
|
|
MOVE: "move",
|
|
AUTO: "",
|
|
};
|
|
export const POINTER_BUTTON = {
|
|
MAIN: 0,
|
|
WHEEL: 1,
|
|
SECONDARY: 2,
|
|
TOUCH: -1,
|
|
ERASER: 5,
|
|
} as const;
|
|
|
|
export const POINTER_EVENTS = {
|
|
enabled: "all",
|
|
disabled: "none",
|
|
// asserted as any so it can be freely assigned to React Element
|
|
// "pointerEnvets" CSS prop
|
|
inheritFromUI: "var(--ui-pointerEvents)" as any,
|
|
} as const;
|
|
|
|
export enum EVENT {
|
|
COPY = "copy",
|
|
PASTE = "paste",
|
|
CUT = "cut",
|
|
KEYDOWN = "keydown",
|
|
KEYUP = "keyup",
|
|
MOUSE_MOVE = "mousemove",
|
|
RESIZE = "resize",
|
|
UNLOAD = "unload",
|
|
FOCUS = "focus",
|
|
BLUR = "blur",
|
|
DRAG_OVER = "dragover",
|
|
DROP = "drop",
|
|
GESTURE_END = "gestureend",
|
|
BEFORE_UNLOAD = "beforeunload",
|
|
GESTURE_START = "gesturestart",
|
|
GESTURE_CHANGE = "gesturechange",
|
|
POINTER_MOVE = "pointermove",
|
|
POINTER_DOWN = "pointerdown",
|
|
POINTER_UP = "pointerup",
|
|
POINTER_CANCEL = "pointercancel",
|
|
STATE_CHANGE = "statechange",
|
|
WHEEL = "wheel",
|
|
TOUCH_START = "touchstart",
|
|
TOUCH_END = "touchend",
|
|
HASHCHANGE = "hashchange",
|
|
VISIBILITY_CHANGE = "visibilitychange",
|
|
SCROLL = "scroll",
|
|
// custom events
|
|
EXCALIDRAW_LINK = "excalidraw-link",
|
|
MENU_ITEM_SELECT = "menu.itemSelect",
|
|
MESSAGE = "message",
|
|
FULLSCREENCHANGE = "fullscreenchange",
|
|
}
|
|
|
|
export const YOUTUBE_STATES = {
|
|
UNSTARTED: -1,
|
|
ENDED: 0,
|
|
PLAYING: 1,
|
|
PAUSED: 2,
|
|
BUFFERING: 3,
|
|
CUED: 5,
|
|
} as const;
|
|
|
|
export const ENV = {
|
|
TEST: "test",
|
|
DEVELOPMENT: "development",
|
|
PRODUCTION: "production",
|
|
};
|
|
|
|
export const CLASSES = {
|
|
SIDEBAR: "sidebar",
|
|
SHAPE_ACTIONS_MENU: "App-menu__left",
|
|
ZOOM_ACTIONS: "zoom-actions",
|
|
SEARCH_MENU_INPUT_WRAPPER: "layer-ui__search-inputWrapper",
|
|
CONVERT_ELEMENT_TYPE_POPUP: "ConvertElementTypePopup",
|
|
SHAPE_ACTIONS_THEME_SCOPE: "shape-actions-theme-scope",
|
|
FRAME_NAME: "frame-name",
|
|
DROPDOWN_MENU_EVENT_WRAPPER: "dropdown-menu-event-wrapper",
|
|
};
|
|
|
|
export const FONT_SIZES = {
|
|
sm: 16,
|
|
md: 20,
|
|
lg: 28,
|
|
xl: 36,
|
|
} as const;
|
|
|
|
export const CJK_HAND_DRAWN_FALLBACK_FONT = "Xiaolai";
|
|
export const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
|
|
|
|
/**
|
|
* // TODO: shouldn't be really `const`, likely neither have integers as values, due to value for the custom fonts, which should likely be some hash.
|
|
*
|
|
* Let's think this through and consider:
|
|
* - https://developer.mozilla.org/en-US/docs/Web/CSS/generic-family
|
|
* - https://drafts.csswg.org/css-fonts-4/#font-family-prop
|
|
* - https://learn.microsoft.com/en-us/typography/opentype/spec/ibmfc
|
|
*/
|
|
export const FONT_FAMILY = {
|
|
Virgil: 1,
|
|
Helvetica: 2,
|
|
Cascadia: 3,
|
|
// leave 4 unused as it was historically used for Assistant (which we don't use anymore) or custom font (Obsidian)
|
|
Excalifont: 5,
|
|
Nunito: 6,
|
|
"Lilita One": 7,
|
|
"Comic Shanns": 8,
|
|
"Liberation Sans": 9,
|
|
Assistant: 10,
|
|
};
|
|
|
|
// Segoe UI Emoji fails to properly fallback for some glyphs: ∞, ∫, ≠
|
|
// so we need to have generic font fallback before it
|
|
export const SANS_SERIF_GENERIC_FONT = "sans-serif";
|
|
export const MONOSPACE_GENERIC_FONT = "monospace";
|
|
|
|
export const FONT_FAMILY_GENERIC_FALLBACKS = {
|
|
[SANS_SERIF_GENERIC_FONT]: 998,
|
|
[MONOSPACE_GENERIC_FONT]: 999,
|
|
};
|
|
|
|
export const FONT_FAMILY_FALLBACKS = {
|
|
[CJK_HAND_DRAWN_FALLBACK_FONT]: 100,
|
|
...FONT_FAMILY_GENERIC_FALLBACKS,
|
|
[WINDOWS_EMOJI_FALLBACK_FONT]: 1000,
|
|
};
|
|
|
|
export function getGenericFontFamilyFallback(
|
|
fontFamily: number,
|
|
): keyof typeof FONT_FAMILY_GENERIC_FALLBACKS {
|
|
switch (fontFamily) {
|
|
case FONT_FAMILY.Cascadia:
|
|
case FONT_FAMILY["Comic Shanns"]:
|
|
return MONOSPACE_GENERIC_FONT;
|
|
|
|
default:
|
|
return SANS_SERIF_GENERIC_FONT;
|
|
}
|
|
}
|
|
|
|
export const getFontFamilyFallbacks = (
|
|
fontFamily: number,
|
|
): Array<keyof typeof FONT_FAMILY_FALLBACKS> => {
|
|
const genericFallbackFont = getGenericFontFamilyFallback(fontFamily);
|
|
|
|
switch (fontFamily) {
|
|
case FONT_FAMILY.Excalifont:
|
|
return [
|
|
CJK_HAND_DRAWN_FALLBACK_FONT,
|
|
genericFallbackFont,
|
|
WINDOWS_EMOJI_FALLBACK_FONT,
|
|
];
|
|
default:
|
|
return [genericFallbackFont, WINDOWS_EMOJI_FALLBACK_FONT];
|
|
}
|
|
};
|
|
|
|
export const THEME = {
|
|
LIGHT: "light",
|
|
DARK: "dark",
|
|
} as const;
|
|
|
|
export const DARK_THEME_FILTER = "invert(93%) hue-rotate(180deg)";
|
|
|
|
export const FRAME_STYLE = {
|
|
strokeColor: "#bbb" as ExcalidrawElement["strokeColor"],
|
|
strokeWidth: 2 as ExcalidrawElement["strokeWidth"],
|
|
strokeStyle: "solid" as ExcalidrawElement["strokeStyle"],
|
|
fillStyle: "solid" as ExcalidrawElement["fillStyle"],
|
|
roughness: 0 as ExcalidrawElement["roughness"],
|
|
roundness: null as ExcalidrawElement["roundness"],
|
|
backgroundColor: "transparent" as ExcalidrawElement["backgroundColor"],
|
|
radius: 8,
|
|
nameOffsetY: 3,
|
|
nameColorLightTheme: "#999999",
|
|
nameColorDarkTheme: "#7a7a7a",
|
|
nameFontSize: 14,
|
|
nameLineHeight: 1.25,
|
|
};
|
|
|
|
export const MIN_FONT_SIZE = 1;
|
|
export const DEFAULT_FONT_SIZE = 20;
|
|
export const STICKY_NOTE_MIN_FONT_SIZE = 16;
|
|
export const STICKY_NOTE_MAX_FONT_SIZE = 512;
|
|
export const STICKY_NOTE_FALLBACK_FONT_SIZE = 28;
|
|
export const STICKY_NOTE_FONT_STEP = 2;
|
|
export const STICKY_NOTE_PADDING = 16;
|
|
/**
|
|
* The creation-date footer: a 20px text row under the label body plus a 12px
|
|
* gap above it, inside the note's bottom padding. Reserved for every note —
|
|
* also when `created` is unknown — so geometry never depends on data
|
|
* availability. The label is chosen by width bucket, never measured, so
|
|
* painting stays measurement-free (the server has no text measurer):
|
|
* `minBodyWidthForYear` is the worst case ("30 May 2026") in the system sans
|
|
* stack at 12px, with margin for wider fallbacks such as DejaVu Sans.
|
|
*/
|
|
/**
|
|
* The creation-date footer of a sticky note. The label body ends `height`
|
|
* above the note's bottom padding, and the date's baseline sits
|
|
* `baselineFromBottom` above the note's bottom edge — so the 12px glyphs
|
|
* (~9px above the baseline, ~3px below) end up roughly 11px from the edge
|
|
* with a ~13px gap to the label body above them.
|
|
*/
|
|
export const STICKY_NOTE_FOOTER = {
|
|
height: 20,
|
|
fontSize: 12,
|
|
fontFamily: "Helvetica, Arial, sans-serif",
|
|
baselineFromBottom: 14,
|
|
opacity: 1,
|
|
minBodyWidthForYear: 80,
|
|
} as const;
|
|
/**
|
|
* outer height → label body height: top + bottom padding + footer. The body
|
|
* is what the label is fitted into; a middle-aligned label is still centered
|
|
* in the whole padded note when it fits (see `computeBoundTextPosition`).
|
|
*/
|
|
export const STICKY_NOTE_BODY_INSET_Y =
|
|
STICKY_NOTE_PADDING * 2 + STICKY_NOTE_FOOTER.height;
|
|
export const DEFAULT_STICKY_NOTE_SIZE = 250;
|
|
// floor for a finalized note's width and base height; the UI floor is font-aware
|
|
// on top of it (see `getStickyNoteMinSize`)
|
|
export const STICKY_NOTE_MIN_SIZE = 75;
|
|
export const STICKY_NOTE_SHADOW_OFFSET = 3;
|
|
export const STICKY_NOTE_SHADOW_OPACITY = 0.16;
|
|
export const STICKY_NOTE_EDGE_SHADOW_WIDTH = 0.5;
|
|
export const STICKY_NOTE_EDGE_SHADOW_OPACITY = 0.08;
|
|
export const DEFAULT_FONT_FAMILY: FontFamilyValues = FONT_FAMILY.Excalifont;
|
|
/** number of slots in the font-picker top-picks strip — pick customization
|
|
* (replace / reorder) preserves it. Must equal `DEFAULT_FONTS.length` in
|
|
* `packages/excalidraw/components/FontPicker/FontPicker.tsx` (enforced by
|
|
* `fontTopPicks.test.ts`) */
|
|
export const FONT_TOP_PICKS_SLOTS = 3;
|
|
export const DEFAULT_TEXT_ALIGN = "left";
|
|
export const DEFAULT_VERTICAL_ALIGN = "top";
|
|
export const DEFAULT_VERSION = "{version}";
|
|
export const DEFAULT_TRANSFORM_HANDLE_SPACING = 2;
|
|
|
|
export const SIDE_RESIZING_THRESHOLD = 2 * DEFAULT_TRANSFORM_HANDLE_SPACING;
|
|
// a small epsilon to make side resizing always take precedence
|
|
// (avoids an increase in renders and changes to tests)
|
|
export const EPSILON = 0.00001;
|
|
export const DEFAULT_COLLISION_THRESHOLD =
|
|
2 * SIDE_RESIZING_THRESHOLD - EPSILON;
|
|
|
|
export const COLOR_WHITE = "#ffffff";
|
|
export const COLOR_CHARCOAL_BLACK = "#1e1e1e";
|
|
// keep this in sync with CSS
|
|
export const COLOR_VOICE_CALL = "#a2f1a6";
|
|
|
|
export const CANVAS_ONLY_ACTIONS = ["selectAll"];
|
|
|
|
export const DEFAULT_GRID_SIZE = 20;
|
|
export const DEFAULT_GRID_STEP = 5;
|
|
|
|
export const IMAGE_MIME_TYPES = {
|
|
svg: "image/svg+xml",
|
|
png: "image/png",
|
|
jpg: "image/jpeg",
|
|
gif: "image/gif",
|
|
webp: "image/webp",
|
|
bmp: "image/bmp",
|
|
ico: "image/x-icon",
|
|
avif: "image/avif",
|
|
jfif: "image/jfif",
|
|
} as const;
|
|
|
|
export const STRING_MIME_TYPES = {
|
|
text: "text/plain",
|
|
html: "text/html",
|
|
json: "application/json",
|
|
// excalidraw data
|
|
excalidraw: "application/vnd.excalidraw+json",
|
|
excalidrawClipboard: "application/vnd.excalidraw.clipboard+json",
|
|
// LEGACY: fully-qualified library JSON data
|
|
excalidrawlib: "application/vnd.excalidrawlib+json",
|
|
// list of excalidraw library item ids
|
|
excalidrawlibIds: "application/vnd.excalidrawlib.ids+json",
|
|
} as const;
|
|
|
|
export const MIME_TYPES = {
|
|
...STRING_MIME_TYPES,
|
|
// image-encoded excalidraw data
|
|
"excalidraw.svg": "image/svg+xml",
|
|
"excalidraw.png": "image/png",
|
|
// binary
|
|
binary: "application/octet-stream",
|
|
// image
|
|
...IMAGE_MIME_TYPES,
|
|
} as const;
|
|
|
|
export const ALLOWED_PASTE_MIME_TYPES = [
|
|
MIME_TYPES.text,
|
|
MIME_TYPES.html,
|
|
...Object.values(IMAGE_MIME_TYPES),
|
|
] as const;
|
|
|
|
export const EXPORT_IMAGE_TYPES = {
|
|
png: "png",
|
|
svg: "svg",
|
|
clipboard: "clipboard",
|
|
} as const;
|
|
|
|
export const EXPORT_DATA_TYPES = {
|
|
excalidraw: "excalidraw",
|
|
excalidrawClipboard: "excalidraw/clipboard",
|
|
excalidrawLibrary: "excalidrawlib",
|
|
excalidrawClipboardWithAPI: "excalidraw-api/clipboard",
|
|
} as const;
|
|
|
|
export const getExportSource = () =>
|
|
window.EXCALIDRAW_EXPORT_SOURCE || window.location.origin;
|
|
|
|
// time in milliseconds
|
|
export const IMAGE_RENDER_TIMEOUT = 500;
|
|
export const TAP_TWICE_TIMEOUT = 300;
|
|
export const TOUCH_CTX_MENU_TIMEOUT = 500;
|
|
export const TITLE_TIMEOUT = 10000;
|
|
export const VERSION_TIMEOUT = 30000;
|
|
export const SCROLL_TIMEOUT = 100;
|
|
export const ZEN_MODE_TRANSITION_DURATION = 250;
|
|
export const ZOOM_STEP = 0.1;
|
|
export const MIN_ZOOM = 0.1;
|
|
export const MAX_ZOOM = 30;
|
|
/** 100% zoom, for computations that have no editor zoom to go by */
|
|
export const DEFAULT_ZOOM: AppState["zoom"] = Object.freeze({
|
|
value: 1 as NormalizedZoomValue,
|
|
});
|
|
export const HYPERLINK_TOOLTIP_DELAY = 300;
|
|
|
|
// Report a user inactive after IDLE_THRESHOLD milliseconds
|
|
export const IDLE_THRESHOLD = 60_000;
|
|
// Report a user active each ACTIVE_THRESHOLD milliseconds
|
|
export const ACTIVE_THRESHOLD = 3_000;
|
|
|
|
export const URL_QUERY_KEYS = {
|
|
addLibrary: "addLibrary",
|
|
} as const;
|
|
|
|
export const URL_HASH_KEYS = {
|
|
addLibrary: "addLibrary",
|
|
} as const;
|
|
|
|
export const DEFAULT_UI_OPTIONS: AppProps["UIOptions"] = {
|
|
canvasActions: {
|
|
changeViewBackgroundColor: true,
|
|
clearCanvas: true,
|
|
export: { saveFileToDisk: true },
|
|
loadScene: true,
|
|
saveToActiveFile: true,
|
|
toggleTheme: null,
|
|
saveAsImage: true,
|
|
},
|
|
tools: {
|
|
image: true,
|
|
},
|
|
};
|
|
|
|
export const MAX_DECIMALS_FOR_SVG_EXPORT = 2;
|
|
|
|
export const EXPORT_SCALES = [1, 2, 3];
|
|
export const DEFAULT_EXPORT_PADDING = 10; // px
|
|
|
|
export const DEFAULT_IMAGE_OPTIONS: AppProps["imageOptions"] = {
|
|
maxWidthOrHeight: 1440,
|
|
maxFileSizeBytes: 4 * 1024 * 1024,
|
|
};
|
|
|
|
export const SVG_NS = "http://www.w3.org/2000/svg";
|
|
export const SVG_DOCUMENT_PREAMBLE = `<?xml version="1.0" standalone="no"?>
|
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
`;
|
|
|
|
export const ENCRYPTION_KEY_BITS = 128;
|
|
|
|
export const VERSIONS = {
|
|
excalidraw: 2,
|
|
excalidrawLibrary: 2,
|
|
} as const;
|
|
|
|
export const BOUND_TEXT_PADDING = 5;
|
|
export const ARROW_LABEL_WIDTH_FRACTION = 0.7;
|
|
export const ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO = 11;
|
|
|
|
export const VERTICAL_ALIGN = {
|
|
TOP: "top",
|
|
MIDDLE: "middle",
|
|
BOTTOM: "bottom",
|
|
};
|
|
|
|
export const TEXT_ALIGN = {
|
|
LEFT: "left",
|
|
CENTER: "center",
|
|
RIGHT: "right",
|
|
};
|
|
|
|
export const ELEMENT_READY_TO_ERASE_OPACITY = 20;
|
|
export const ELEMENT_PENDING_DRAW_SHAPE_OPACITY = 70;
|
|
|
|
// Radius represented as 25% of element's largest side (width/height).
|
|
// Used for LEGACY and PROPORTIONAL_RADIUS algorithms, or when the element is
|
|
// below the cutoff size.
|
|
export const DEFAULT_PROPORTIONAL_RADIUS = 0.25;
|
|
// Fixed radius for the ADAPTIVE_RADIUS algorithm. In pixels.
|
|
export const DEFAULT_ADAPTIVE_RADIUS = 32;
|
|
// roundness type (algorithm)
|
|
export const ROUNDNESS = {
|
|
// Used for legacy rounding (rectangles), which currently works the same
|
|
// as PROPORTIONAL_RADIUS, but we need to differentiate for UI purposes and
|
|
// forwards-compat.
|
|
LEGACY: 1,
|
|
|
|
// Used for linear elements & diamonds
|
|
PROPORTIONAL_RADIUS: 2,
|
|
|
|
// Current default algorithm for rectangles, using fixed pixel radius.
|
|
// It's working similarly to a regular border-radius, but attemps to make
|
|
// radius visually similar across differnt element sizes, especially
|
|
// very large and very small elements.
|
|
//
|
|
// NOTE right now we don't allow configuration and use a constant radius
|
|
// (see DEFAULT_ADAPTIVE_RADIUS constant)
|
|
ADAPTIVE_RADIUS: 3,
|
|
} as const;
|
|
|
|
export const ROUGHNESS = {
|
|
architect: 0,
|
|
artist: 1,
|
|
cartoonist: 2,
|
|
} as const;
|
|
|
|
export type StrokeWidthKey = "thin" | "medium" | "bold";
|
|
|
|
export const STROKE_WIDTH_KEYS: readonly StrokeWidthKey[] = [
|
|
"thin",
|
|
"medium",
|
|
"bold",
|
|
];
|
|
|
|
export const STROKE_WIDTH: Readonly<
|
|
Record<StrokeWidthKey | "extraBold", ExcalidrawElement["strokeWidth"]>
|
|
> = {
|
|
thin: 1,
|
|
medium: 2,
|
|
bold: 4,
|
|
extraBold: 8, // unused (may be introduced in the future)
|
|
};
|
|
|
|
// freedraw schema 2.0 uses thinner stroke, but to maintain backwards and
|
|
// forwards compatibility, instead of changing the shape renderer, we scale
|
|
// the stroke width by 1/2 (previous, thin was 1, medium 2 etc.)
|
|
//
|
|
// note that in the UI, STROKE_WIDTH.thin == FREEDRAW_STROKE_WIDTH.thin still
|
|
export const FREEDRAW_STROKE_WIDTH: Readonly<
|
|
Record<StrokeWidthKey | "extraBold", ExcalidrawElement["strokeWidth"]>
|
|
> = {
|
|
thin: 0.5,
|
|
medium: 1,
|
|
bold: 2,
|
|
extraBold: 4, // legacy (may be used again in the future)
|
|
};
|
|
|
|
export const getStrokeWidthByKey = (
|
|
elementType: ExcalidrawElement["type"],
|
|
strokeWidthKey: StrokeWidthKey,
|
|
): ExcalidrawElement["strokeWidth"] => {
|
|
return elementType === "freedraw"
|
|
? FREEDRAW_STROKE_WIDTH[strokeWidthKey]
|
|
: STROKE_WIDTH[strokeWidthKey];
|
|
};
|
|
|
|
export const DEFAULT_ELEMENT_STROKE_WIDTH_KEY: StrokeWidthKey = "medium";
|
|
|
|
export const DEFAULT_ELEMENT_PROPS: {
|
|
strokeColor: ExcalidrawElement["strokeColor"];
|
|
backgroundColor: ExcalidrawElement["backgroundColor"];
|
|
fillStyle: ExcalidrawElement["fillStyle"];
|
|
strokeWidth: ExcalidrawElement["strokeWidth"];
|
|
strokeStyle: ExcalidrawElement["strokeStyle"];
|
|
roughness: ExcalidrawElement["roughness"];
|
|
opacity: ExcalidrawElement["opacity"];
|
|
locked: ExcalidrawElement["locked"];
|
|
} = {
|
|
strokeColor: COLOR_PALETTE.black,
|
|
backgroundColor: COLOR_PALETTE.transparent,
|
|
fillStyle: "solid",
|
|
strokeWidth: STROKE_WIDTH[DEFAULT_ELEMENT_STROKE_WIDTH_KEY],
|
|
strokeStyle: "solid",
|
|
roughness: ROUGHNESS.artist,
|
|
opacity: 100,
|
|
locked: false,
|
|
};
|
|
|
|
export const LIBRARY_SIDEBAR_TAB = "library";
|
|
export const CANVAS_SEARCH_TAB = "search";
|
|
|
|
export const DEFAULT_SIDEBAR = {
|
|
name: "default",
|
|
defaultTab: LIBRARY_SIDEBAR_TAB,
|
|
} as const;
|
|
|
|
export const LIBRARY_DISABLED_TYPES = new Set([
|
|
"iframe",
|
|
"embeddable",
|
|
"image",
|
|
] as const);
|
|
|
|
// use these constants to easily identify reference sites
|
|
export const TOOL_TYPE = {
|
|
selection: "selection",
|
|
lasso: "lasso",
|
|
rectangle: "rectangle",
|
|
diamond: "diamond",
|
|
ellipse: "ellipse",
|
|
arrow: "arrow",
|
|
line: "line",
|
|
freedraw: "freedraw",
|
|
text: "text",
|
|
image: "image",
|
|
eraser: "eraser",
|
|
hand: "hand",
|
|
frame: "frame",
|
|
magicframe: "magicframe",
|
|
stickynote: "stickynote",
|
|
embeddable: "embeddable",
|
|
laser: "laser",
|
|
autoshape: "autoshape",
|
|
bucketfill: "bucketfill",
|
|
} as const;
|
|
|
|
export const EDITOR_LS_KEYS = {
|
|
OAI_API_KEY: "excalidraw-oai-api-key",
|
|
// legacy naming (non)scheme
|
|
MERMAID_TO_EXCALIDRAW: "mermaid-to-excalidraw",
|
|
PUBLISH_LIBRARY: "publish-library-data",
|
|
// TEMPORARY (see MinimapAnnouncementDot)
|
|
MINIMAP_ANNOUNCEMENT_DISMISSED: "excalidraw-minimap-announcement-dismissed",
|
|
} as const;
|
|
|
|
/**
|
|
* not translated as this is used only in public, stateless API as default value
|
|
* where filename is optional and we can't retrieve name from app state
|
|
*/
|
|
export const DEFAULT_FILENAME = "Untitled";
|
|
|
|
export const STATS_PANELS = { generalStats: 1, elementProperties: 2 } as const;
|
|
|
|
export const MIN_WIDTH_OR_HEIGHT = 1;
|
|
|
|
export const ARROW_TYPE: { [T in AppState["currentItemArrowType"]]: T } = {
|
|
sharp: "sharp",
|
|
round: "round",
|
|
elbow: "elbow",
|
|
};
|
|
|
|
export const DEFAULT_REDUCED_GLOBAL_ALPHA = 0.3;
|
|
export const ELEMENT_LINK_KEY = "element";
|
|
|
|
/** used in tests */
|
|
export const ORIG_ID = Symbol.for("__test__originalId__");
|
|
|
|
export enum UserIdleState {
|
|
ACTIVE = "active",
|
|
AWAY = "away",
|
|
IDLE = "idle",
|
|
}
|
|
|
|
/**
|
|
* distance at which we merge points instead of adding a new merge-point
|
|
* when converting a line to a polygon (merge currently means overlaping
|
|
* the start and end points)
|
|
*/
|
|
export const LINE_POLYGON_POINT_MERGE_DISTANCE = 20;
|
|
|
|
export const DOUBLE_TAP_POSITION_THRESHOLD = 35;
|
|
|
|
export const BIND_MODE_TIMEOUT = 700; // ms
|
|
|
|
// glass background for mobile action buttons
|
|
export const MOBILE_ACTION_BUTTON_BG = {
|
|
background: "var(--mobile-action-button-bg)",
|
|
} as const;
|
|
|
|
export const DEFAULT_STROKE_STREAMLINE = 0.5;
|
|
export const DEFAULT_STROKE_STREAMLINE_PRECISE = 0.2;
|