@excalidraw/common 0.18.0-b9d27d3 → 0.18.0-c141960

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/dev/index.js +321 -50
  2. package/dist/dev/index.js.map +3 -3
  3. package/dist/prod/index.js +3 -3
  4. package/dist/types/common/src/constants.d.ts +9 -13
  5. package/dist/types/common/src/editorInterface.d.ts +34 -0
  6. package/dist/types/common/src/index.d.ts +2 -0
  7. package/dist/types/common/src/utils.d.ts +9 -3
  8. package/dist/types/common/src/visualdebug.d.ts +41 -0
  9. package/dist/types/element/src/binding.d.ts +55 -43
  10. package/dist/types/element/src/collision.d.ts +6 -2
  11. package/dist/types/element/src/index.d.ts +0 -3
  12. package/dist/types/element/src/linearElementEditor.d.ts +15 -18
  13. package/dist/types/element/src/renderElement.d.ts +5 -2
  14. package/dist/types/element/src/resizeTest.d.ts +5 -4
  15. package/dist/types/element/src/transformHandles.d.ts +5 -4
  16. package/dist/types/element/src/typeChecks.d.ts +2 -3
  17. package/dist/types/element/src/types.d.ts +7 -11
  18. package/dist/types/element/src/utils.d.ts +2 -1
  19. package/dist/types/element/src/zindex.d.ts +7 -1
  20. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +34 -13
  21. package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -6
  22. package/dist/types/excalidraw/actions/actionBoundText.d.ts +25 -11
  23. package/dist/types/excalidraw/actions/actionCanvas.d.ts +152 -275
  24. package/dist/types/excalidraw/actions/actionClipboard.d.ts +46 -773
  25. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +12 -5
  26. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +42 -23
  27. package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -2
  28. package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +2 -2
  29. package/dist/types/excalidraw/actions/actionElementLink.d.ts +11 -6
  30. package/dist/types/excalidraw/actions/actionElementLock.d.ts +23 -9
  31. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +12 -5
  32. package/dist/types/excalidraw/actions/actionExport.d.ts +68 -943
  33. package/dist/types/excalidraw/actions/actionFinalize.d.ts +10 -393
  34. package/dist/types/excalidraw/actions/actionFlip.d.ts +2 -2
  35. package/dist/types/excalidraw/actions/actionFrame.d.ts +50 -24
  36. package/dist/types/excalidraw/actions/actionGroup.d.ts +24 -10
  37. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +22 -19
  38. package/dist/types/excalidraw/actions/actionLink.d.ts +9 -2
  39. package/dist/types/excalidraw/actions/actionMenu.d.ts +10 -371
  40. package/dist/types/excalidraw/actions/actionNavigate.d.ts +21 -359
  41. package/dist/types/excalidraw/actions/actionProperties.d.ts +87 -2403
  42. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +12 -5
  43. package/dist/types/excalidraw/actions/actionStyles.d.ts +13 -6
  44. package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +1 -1
  45. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +11 -4
  46. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +11 -4
  47. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +10 -5
  48. package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +1 -1
  49. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +11 -4
  50. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +11 -4
  51. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +12 -5
  52. package/dist/types/excalidraw/actions/actionZindex.d.ts +2 -2
  53. package/dist/types/excalidraw/actions/index.d.ts +2 -2
  54. package/dist/types/excalidraw/actions/manager.d.ts +1 -1
  55. package/dist/types/excalidraw/actions/register.d.ts +1 -1
  56. package/dist/types/excalidraw/actions/types.d.ts +4 -4
  57. package/dist/types/excalidraw/appState.d.ts +9 -4
  58. package/dist/types/excalidraw/clipboard.d.ts +2 -0
  59. package/dist/types/excalidraw/components/Actions.d.ts +21 -4
  60. package/dist/types/excalidraw/components/App.d.ts +26 -19
  61. package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +2 -0
  62. package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +2 -1
  63. package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +2 -1
  64. package/dist/types/excalidraw/components/CommandPalette/CommandPalette.d.ts +1 -0
  65. package/dist/types/excalidraw/components/CommandPalette/types.d.ts +1 -2
  66. package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +1 -1
  67. package/dist/types/excalidraw/components/FilledButton.d.ts +1 -1
  68. package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +2 -1
  69. package/dist/types/excalidraw/components/FontPicker/FontPickerTrigger.d.ts +3 -1
  70. package/dist/types/excalidraw/components/HintViewer.d.ts +4 -3
  71. package/dist/types/excalidraw/components/InlineIcon.d.ts +3 -1
  72. package/dist/types/excalidraw/components/LayerUI.d.ts +2 -1
  73. package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +1 -1
  74. package/dist/types/excalidraw/components/MobileMenu.d.ts +3 -5
  75. package/dist/types/excalidraw/components/MobileToolBar.d.ts +11 -0
  76. package/dist/types/excalidraw/components/Popover.d.ts +2 -1
  77. package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -0
  78. package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -1
  79. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +1 -2
  80. package/dist/types/excalidraw/components/TextField.d.ts +1 -0
  81. package/dist/types/excalidraw/components/ToolPopover.d.ts +25 -0
  82. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +6 -3
  83. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +4 -2
  84. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +2 -1
  85. package/dist/types/excalidraw/components/icons.d.ts +10 -0
  86. package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +13 -1
  87. package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +0 -3
  88. package/dist/types/excalidraw/data/blob.d.ts +2 -2
  89. package/dist/types/excalidraw/data/restore.d.ts +3 -3
  90. package/dist/types/excalidraw/data/types.d.ts +4 -1
  91. package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
  92. package/dist/types/excalidraw/hooks/useOutsideClick.d.ts +3 -1
  93. package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +14 -0
  94. package/dist/types/excalidraw/index.d.ts +2 -3
  95. package/dist/types/excalidraw/renderer/animation.d.ts +12 -0
  96. package/dist/types/excalidraw/renderer/helpers.d.ts +2 -6
  97. package/dist/types/excalidraw/renderer/interactiveScene.d.ts +5 -13
  98. package/dist/types/excalidraw/scene/types.d.ts +15 -3
  99. package/dist/types/excalidraw/shortcut.d.ts +1 -0
  100. package/dist/types/excalidraw/types.d.ts +31 -21
  101. package/dist/types/math/src/segment.d.ts +1 -0
  102. package/package.json +1 -1
@@ -2,7 +2,7 @@ import { IMAGE_MIME_TYPES, MIME_TYPES } from "@excalidraw/common";
2
2
  import type { ValueOf } from "@excalidraw/common/utility-types";
3
3
  import type { ExcalidrawElement, FileId } from "@excalidraw/element/types";
4
4
  import type { AppState, DataURL, LibraryItem } from "../types";
5
- import type { FileSystemHandle } from "./filesystem";
5
+ import type { FileSystemHandle } from "browser-fs-access";
6
6
  import type { ImportedLibraryData } from "./types";
7
7
  export declare const getMimeType: (blob: Blob | string) => string;
8
8
  export declare const getFileHandleType: (handle: FileSystemHandle | null) => string | null;
@@ -41,7 +41,7 @@ export declare const SVGStringToFile: (SVGString: string, filename?: string) =>
41
41
  };
42
42
  export declare const ImageURLToFile: (imageUrl: string, filename?: string) => Promise<File | undefined>;
43
43
  export declare const getFileHandle: (event: DragEvent | React.DragEvent | DataTransferItem) => Promise<FileSystemHandle | null>;
44
- export declare const createFile: (blob: File | Blob | ArrayBuffer, mimeType: ValueOf<typeof MIME_TYPES>, name: string | undefined) => File;
44
+ export declare const createFile: (blob: File | Blob | ArrayBuffer, mimeType: string, name: string | undefined) => File;
45
45
  /** attempts to detect correct mimeType if none is set, or if an image
46
46
  * has an incorrect extension.
47
47
  * Note: doesn't handle missing .excalidraw/.excalidrawlib extension */
@@ -1,4 +1,4 @@
1
- import type { ExcalidrawArrowElement, ExcalidrawElement, ExcalidrawLinearElement, ExcalidrawSelectionElement, ExcalidrawTextElement, OrderedExcalidrawElement } from "@excalidraw/element/types";
1
+ import type { ElementsMap, ExcalidrawArrowElement, ExcalidrawElement, ExcalidrawLinearElement, ExcalidrawSelectionElement, ExcalidrawTextElement, OrderedExcalidrawElement } from "@excalidraw/element/types";
2
2
  import type { AppState, BinaryFiles, LibraryItem } from "../types";
3
3
  import type { ImportedDataState } from "./types";
4
4
  type RestoredAppState = Omit<AppState, "offsetTop" | "offsetLeft" | "width" | "height">;
@@ -8,10 +8,10 @@ export type RestoredDataState = {
8
8
  appState: RestoredAppState;
9
9
  files: BinaryFiles;
10
10
  };
11
- export declare const restoreElement: (element: Exclude<ExcalidrawElement, ExcalidrawSelectionElement>, opts?: {
11
+ export declare const restoreElement: (element: Exclude<ExcalidrawElement, ExcalidrawSelectionElement>, elementsMap: Readonly<ElementsMap>, opts?: {
12
12
  deleteInvisibleElements?: boolean;
13
13
  }) => ExcalidrawTextElement | import("@excalidraw/element/types").ExcalidrawRectangleElement | import("@excalidraw/element/types").ExcalidrawDiamondElement | import("@excalidraw/element/types").ExcalidrawFrameElement | import("@excalidraw/element/types").ExcalidrawMagicFrameElement | import("@excalidraw/element/types").ExcalidrawEmbeddableElement | import("@excalidraw/element/types").ExcalidrawImageElement | import("@excalidraw/element/types").ExcalidrawIframeElement | import("@excalidraw/element/types").ExcalidrawEllipseElement | ExcalidrawLinearElement | ExcalidrawArrowElement | import("@excalidraw/element/types").ExcalidrawFreeDrawElement | null;
14
- export declare const restoreElements: (elements: ImportedDataState["elements"], localElements: readonly ExcalidrawElement[] | null | undefined, opts?: {
14
+ export declare const restoreElements: (targetElements: ImportedDataState["elements"], localElements: readonly ExcalidrawElement[] | null | undefined, opts?: {
15
15
  refreshDimensions?: boolean;
16
16
  repairBindings?: boolean;
17
17
  deleteInvisibleElements?: boolean;
@@ -1,7 +1,7 @@
1
1
  import type { VERSIONS } from "@excalidraw/common";
2
2
  import type { ExcalidrawElement } from "@excalidraw/element/types";
3
3
  import type { cleanAppStateForExport } from "../appState";
4
- import type { AppState, BinaryFiles, LibraryItems, LibraryItems_anyVersion } from "../types";
4
+ import type { AppState, BinaryFiles, LibraryItem, LibraryItems, LibraryItems_anyVersion } from "../types";
5
5
  export interface ExportedDataState {
6
6
  type: string;
7
7
  version: number;
@@ -43,3 +43,6 @@ export interface ImportedLibraryData extends Partial<ExportedLibraryData> {
43
43
  /** @deprecated v1 */
44
44
  library?: LibraryItems;
45
45
  }
46
+ export type ExcalidrawLibraryIds = {
47
+ itemIds: LibraryItem["id"][];
48
+ };
@@ -3,7 +3,7 @@ export type SvgCache = Map<LibraryItem["id"], SVGSVGElement>;
3
3
  export declare const libraryItemSvgsCache: import("jotai/vanilla/atom").PrimitiveAtom<SvgCache> & {
4
4
  init: SvgCache;
5
5
  };
6
- export declare const useLibraryItemSvg: (id: LibraryItem["id"] | null, elements: LibraryItem["elements"] | undefined, svgCache: SvgCache) => SVGSVGElement | undefined;
6
+ export declare const useLibraryItemSvg: (id: LibraryItem["id"] | null, elements: LibraryItem["elements"] | undefined, svgCache: SvgCache, ref: React.RefObject<HTMLDivElement | null>) => SVGSVGElement | undefined;
7
7
  export declare const useLibraryCache: () => {
8
8
  clearLibraryCache: () => void;
9
9
  deleteItemsFromLibraryCache: (items: LibraryItem["id"][]) => void;
@@ -1,7 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  export declare function useOutsideClick<T extends HTMLElement>(ref: React.RefObject<T | null>,
3
3
  /** if performance is of concern, memoize the callback */
4
- callback: (event: Event) => void,
4
+ callback: (event: Event & {
5
+ target: T;
6
+ }) => void,
5
7
  /**
6
8
  * Optional callback which is called on every click.
7
9
  *
@@ -0,0 +1,14 @@
1
+ export type CaretPosition = {
2
+ start: number;
3
+ end: number;
4
+ };
5
+ export declare const saveCaretPosition: () => CaretPosition | null;
6
+ export declare const restoreCaretPosition: (position: CaretPosition | null) => void;
7
+ export declare const withCaretPositionPreservation: (callback: () => void, isCompactMode: boolean, isEditingText: boolean, onPreventClose?: () => void) => void;
8
+ export declare const useTextEditorFocus: () => {
9
+ saveCaretPosition: () => void;
10
+ restoreCaretPosition: () => void;
11
+ clearSavedPosition: () => void;
12
+ hasSavedPosition: boolean;
13
+ };
14
+ export declare const temporarilyDisableTextEditorBlur: (duration?: number) => void;
@@ -20,17 +20,16 @@ export { loadFromBlob, loadSceneOrLibraryFromBlob, loadLibraryFromBlob, } from "
20
20
  export { getFreeDrawSvgPath } from "@excalidraw/element";
21
21
  export { mergeLibraryItems, getLibraryItemsHash } from "./data/library";
22
22
  export { isLinearElement } from "@excalidraw/element";
23
- export { FONT_FAMILY, THEME, MIME_TYPES, ROUNDNESS, DEFAULT_LASER_COLOR, UserIdleState, normalizeLink, } from "@excalidraw/common";
23
+ export { FONT_FAMILY, THEME, MIME_TYPES, ROUNDNESS, DEFAULT_LASER_COLOR, UserIdleState, normalizeLink, sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, getFormFactor, } from "@excalidraw/common";
24
24
  export { mutateElement, newElementWith, bumpVersion, } from "@excalidraw/element";
25
25
  export { CaptureUpdateAction } from "@excalidraw/element";
26
26
  export { parseLibraryTokensFromUrl, useHandleLibrary } from "./data/library";
27
- export { sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, } from "@excalidraw/common";
28
27
  export { Sidebar } from "./components/Sidebar/Sidebar";
29
28
  export { Button } from "./components/Button";
30
29
  export { Footer };
31
30
  export { MainMenu };
32
31
  export { Ellipsify } from "./components/Ellipsify";
33
- export { useDevice } from "./components/App";
32
+ export { useEditorInterface, useStylesPanelMode } from "./components/App";
34
33
  export { WelcomeScreen };
35
34
  export { LiveCollaborationTrigger };
36
35
  export { Stats } from "./components/Stats";
@@ -0,0 +1,12 @@
1
+ export type Animation<R extends object> = (params: {
2
+ deltaTime: number;
3
+ state?: R;
4
+ }) => R | null | undefined;
5
+ export declare class AnimationController {
6
+ private static isRunning;
7
+ private static animations;
8
+ static start<R extends object>(key: string, animation: Animation<R>): void;
9
+ private static tick;
10
+ static running(key: string): boolean;
11
+ static cancel(key: string): void;
12
+ }
@@ -1,4 +1,3 @@
1
- import type { ElementsMap, ExcalidrawDiamondElement, ExcalidrawRectanguloidElement } from "@excalidraw/element/types";
2
1
  import type { StaticCanvasRenderConfig } from "../scene/types";
3
2
  import type { AppState, StaticCanvasAppState } from "../types";
4
3
  export declare const fillCircle: (context: CanvasRenderingContext2D, cx: number, cy: number, radius: number, stroke: boolean, fill?: boolean) => void;
@@ -8,11 +7,8 @@ export declare const bootstrapCanvas: ({ canvas, scale, normalizedWidth, normali
8
7
  scale: number;
9
8
  normalizedWidth: number;
10
9
  normalizedHeight: number;
11
- theme?: import("@excalidraw/element/types").Theme | undefined;
10
+ theme?: import("../../element/src/types").Theme | undefined;
12
11
  isExporting?: boolean | undefined;
13
12
  viewBackgroundColor?: string | null | undefined;
14
13
  }) => CanvasRenderingContext2D;
15
- export declare const drawHighlightForRectWithRotation: (context: CanvasRenderingContext2D, element: ExcalidrawRectanguloidElement, elementsMap: ElementsMap, padding: number) => void;
16
- export declare const strokeEllipseWithRotation: (context: CanvasRenderingContext2D, width: number, height: number, cx: number, cy: number, angle: number) => void;
17
- export declare const strokeRectWithRotation: (context: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, cx: number, cy: number, angle: number, fill?: boolean, radius?: number) => void;
18
- export declare const drawHighlightForDiamondWithRotation: (context: CanvasRenderingContext2D, padding: number, element: ExcalidrawDiamondElement, elementsMap: ElementsMap) => void;
14
+ export declare const strokeRectWithRotation_simple: (context: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, cx: number, cy: number, angle: number, fill?: boolean, radius?: number) => void;
@@ -1,20 +1,12 @@
1
+ import { getScrollBars } from "../scene/scrollbars";
1
2
  import type { InteractiveSceneRenderConfig, RenderableElementsMap } from "../scene/types";
2
- /** throttled to animation framerate */
3
- export declare const renderInteractiveSceneThrottled: {
4
- (config: InteractiveSceneRenderConfig): void;
5
- flush(): void;
6
- cancel(): void;
7
- };
8
3
  /**
9
4
  * Interactive scene is the ui-canvas where we render bounding boxes, selections
10
5
  * and other ui stuff.
11
6
  */
12
- export declare const renderInteractiveScene: <U extends ({ canvas, elementsMap, visibleElements, selectedElements, allElementsMap, scale, appState, renderConfig, device, }: InteractiveSceneRenderConfig) => {
7
+ export declare const renderInteractiveScene: <U extends ({ app, canvas, elementsMap, visibleElements, selectedElements, allElementsMap, scale, appState, renderConfig, editorInterface, animationState, deltaTime, }: InteractiveSceneRenderConfig) => {
8
+ scrollBars?: import("../scene/types").ScrollBars | undefined;
13
9
  atLeastOneVisibleElement: boolean;
14
10
  elementsMap: RenderableElementsMap;
15
- scrollBars?: undefined;
16
- } | {
17
- scrollBars: import("../scene/types").ScrollBars | undefined;
18
- atLeastOneVisibleElement: boolean;
19
- elementsMap: RenderableElementsMap;
20
- }, T extends boolean = false>(renderConfig: InteractiveSceneRenderConfig, throttle?: T | undefined) => T extends true ? void : ReturnType<U>;
11
+ animationState?: import("../scene/types").InteractiveSceneRenderAnimationState | undefined;
12
+ }>(renderConfig: InteractiveSceneRenderConfig) => ReturnType<U>;
@@ -1,7 +1,7 @@
1
- import type { UserIdleState } from "@excalidraw/common";
1
+ import type { UserIdleState, EditorInterface } from "@excalidraw/common";
2
2
  import type { ExcalidrawElement, NonDeletedElementsMap, NonDeletedExcalidrawElement, NonDeletedSceneElementsMap } from "@excalidraw/element/types";
3
3
  import type { MakeBrand } from "@excalidraw/common/utility-types";
4
- import type { AppClassProperties, AppState, EmbedsValidationStatus, ElementsPendingErasure, InteractiveCanvasAppState, StaticCanvasAppState, SocketId, Device, PendingExcalidrawElements } from "../types";
4
+ import type { AppClassProperties, AppState, EmbedsValidationStatus, ElementsPendingErasure, InteractiveCanvasAppState, StaticCanvasAppState, SocketId, PendingExcalidrawElements } from "../types";
5
5
  import type { RoughCanvas } from "roughjs/bin/canvas";
6
6
  import type { Drawable } from "roughjs/bin/core";
7
7
  export type RenderableElementsMap = NonDeletedElementsMap & MakeBrand<"RenderableElementsMap">;
@@ -43,6 +43,10 @@ export type InteractiveCanvasRenderConfig = {
43
43
  remotePointerUsernames: Map<SocketId, string>;
44
44
  remotePointerButton: Map<SocketId, string | undefined>;
45
45
  selectionColor: string;
46
+ lastViewportPosition: {
47
+ x: number;
48
+ y: number;
49
+ };
46
50
  renderScrollbars?: boolean;
47
51
  };
48
52
  export type RenderInteractiveSceneCallback = {
@@ -60,7 +64,13 @@ export type StaticSceneRenderConfig = {
60
64
  appState: StaticCanvasAppState;
61
65
  renderConfig: StaticCanvasRenderConfig;
62
66
  };
67
+ export type InteractiveSceneRenderAnimationState = {
68
+ bindingHighlight: {
69
+ runtime: number;
70
+ } | undefined;
71
+ };
63
72
  export type InteractiveSceneRenderConfig = {
73
+ app: AppClassProperties;
64
74
  canvas: HTMLCanvasElement | null;
65
75
  elementsMap: RenderableElementsMap;
66
76
  visibleElements: readonly NonDeletedExcalidrawElement[];
@@ -69,8 +79,10 @@ export type InteractiveSceneRenderConfig = {
69
79
  scale: number;
70
80
  appState: InteractiveCanvasAppState;
71
81
  renderConfig: InteractiveCanvasRenderConfig;
72
- device: Device;
82
+ editorInterface: EditorInterface;
73
83
  callback: (data: RenderInteractiveSceneCallback) => void;
84
+ animationState?: InteractiveSceneRenderAnimationState;
85
+ deltaTime: number;
74
86
  };
75
87
  export type NewElementSceneRenderConfig = {
76
88
  canvas: HTMLCanvasElement | null;
@@ -0,0 +1 @@
1
+ export declare const getShortcutKey: (shortcut: string) => string;
@@ -1,8 +1,7 @@
1
- import type { IMAGE_MIME_TYPES, UserIdleState, throttleRAF, MIME_TYPES } from "@excalidraw/common";
2
- import type { SuggestedBinding } from "@excalidraw/element";
1
+ import type { IMAGE_MIME_TYPES, UserIdleState, throttleRAF, MIME_TYPES, EditorInterface } from "@excalidraw/common";
3
2
  import type { LinearElementEditor } from "@excalidraw/element";
4
3
  import type { MaybeTransformHandleType } from "@excalidraw/element";
5
- import type { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement, OrderedExcalidrawElement, ExcalidrawNonSelectionElement } from "@excalidraw/element/types";
4
+ import type { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement, OrderedExcalidrawElement, ExcalidrawNonSelectionElement, BindMode } from "@excalidraw/element/types";
6
5
  import type { Merge, MaybePromise, ValueOf, MakeBrand } from "@excalidraw/common/utility-types";
7
6
  import type { CaptureUpdateActionType, DurableIncrement, EphemeralIncrement } from "@excalidraw/element";
8
7
  import type { Action } from "./actions/types";
@@ -125,6 +124,7 @@ export type StaticCanvasAppState = Readonly<_CommonCanvasAppState & {
125
124
  frameRendering: AppState["frameRendering"];
126
125
  currentHoveredFontFamily: AppState["currentHoveredFontFamily"];
127
126
  hoveredElementIds: AppState["hoveredElementIds"];
127
+ suggestedBinding: AppState["suggestedBinding"];
128
128
  croppingElementId: AppState["croppingElementId"];
129
129
  }>;
130
130
  export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
@@ -133,8 +133,9 @@ export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
133
133
  selectedGroupIds: AppState["selectedGroupIds"];
134
134
  selectedLinearElement: AppState["selectedLinearElement"];
135
135
  multiElement: AppState["multiElement"];
136
+ newElement: AppState["newElement"];
136
137
  isBindingEnabled: AppState["isBindingEnabled"];
137
- suggestedBindings: AppState["suggestedBindings"];
138
+ suggestedBinding: AppState["suggestedBinding"];
138
139
  isRotating: AppState["isRotating"];
139
140
  elementsToHighlight: AppState["elementsToHighlight"];
140
141
  collaborators: AppState["collaborators"];
@@ -145,6 +146,10 @@ export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
145
146
  croppingElementId: AppState["croppingElementId"];
146
147
  searchMatches: AppState["searchMatches"];
147
148
  activeLockedId: AppState["activeLockedId"];
149
+ hoveredElementIds: AppState["hoveredElementIds"];
150
+ frameRendering: AppState["frameRendering"];
151
+ shouldCacheIgnoreZoom: AppState["shouldCacheIgnoreZoom"];
152
+ exportScale: AppState["exportScale"];
148
153
  }>;
149
154
  export type ObservedAppState = ObservedStandaloneAppState & ObservedElementsAppState;
150
155
  export type ObservedStandaloneAppState = {
@@ -198,7 +203,7 @@ export interface AppState {
198
203
  selectionElement: NonDeletedExcalidrawElement | null;
199
204
  isBindingEnabled: boolean;
200
205
  startBoundElement: NonDeleted<ExcalidrawBindableElement> | null;
201
- suggestedBindings: SuggestedBinding[];
206
+ suggestedBinding: NonDeleted<ExcalidrawBindableElement> | null;
202
207
  frameToHighlight: NonDeleted<ExcalidrawFrameLikeElement> | null;
203
208
  frameRendering: {
204
209
  enabled: boolean;
@@ -221,6 +226,10 @@ export interface AppState {
221
226
  locked: boolean;
222
227
  fromSelection: boolean;
223
228
  } & ActiveTool;
229
+ preferredSelectionTool: {
230
+ type: "selection" | "lasso";
231
+ initialized: boolean;
232
+ };
224
233
  penMode: boolean;
225
234
  penDetected: boolean;
226
235
  exportBackground: boolean;
@@ -251,8 +260,8 @@ export interface AppState {
251
260
  isResizing: boolean;
252
261
  isRotating: boolean;
253
262
  zoom: Zoom;
254
- openMenu: "canvas" | "shape" | null;
255
- openPopup: "canvasBackground" | "elementBackground" | "elementStroke" | "fontFamily" | null;
263
+ openMenu: "canvas" | null;
264
+ openPopup: "canvasBackground" | "elementBackground" | "elementStroke" | "fontFamily" | "compactTextProperties" | "compactStrokeStyles" | "compactOtherProperties" | "compactArrowProperties" | null;
256
265
  openSidebar: {
257
266
  name: SidebarName;
258
267
  tab?: SidebarTabName;
@@ -264,6 +273,8 @@ export interface AppState {
264
273
  tab: "text-to-diagram" | "mermaid";
265
274
  } | {
266
275
  name: "commandPalette";
276
+ } | {
277
+ name: "settings";
267
278
  } | {
268
279
  name: "elementLinkSelector";
269
280
  sourceElementId: ExcalidrawElement["id"];
@@ -351,6 +362,7 @@ export interface AppState {
351
362
  lockedMultiSelections: {
352
363
  [groupId: string]: true;
353
364
  };
365
+ bindMode: BindMode;
354
366
  }
355
367
  export type SearchMatch = {
356
368
  id: string;
@@ -363,7 +375,7 @@ export type SearchMatch = {
363
375
  showOnCanvas: boolean;
364
376
  }[];
365
377
  };
366
- export type UIAppState = Omit<AppState, "suggestedBindings" | "startBoundElement" | "cursorButton" | "scrollX" | "scrollY">;
378
+ export type UIAppState = Omit<AppState, "suggestedBinding" | "startBoundElement" | "cursorButton" | "scrollX" | "scrollY">;
367
379
  export type NormalizedZoomValue = number & {
368
380
  _brand: "normalizedZoom";
369
381
  };
@@ -441,6 +453,7 @@ export interface ExcalidrawProps {
441
453
  onDuplicate?: (nextElements: readonly ExcalidrawElement[],
442
454
  /** excludes the duplicated elements */
443
455
  prevElements: readonly ExcalidrawElement[]) => ExcalidrawElement[] | void;
456
+ renderTopLeftUI?: (isMobile: boolean, appState: UIAppState) => JSX.Element | null;
444
457
  renderTopRightUI?: (isMobile: boolean, appState: UIAppState) => JSX.Element | null;
445
458
  langCode?: Language["code"];
446
459
  viewModeEnabled?: boolean;
@@ -498,6 +511,12 @@ export type UIOptions = Partial<{
498
511
  tools: {
499
512
  image: boolean;
500
513
  };
514
+ /**
515
+ * Optionally control the editor form factor and desktop UI mode from the host app.
516
+ * If not provided, we will take care of it internally.
517
+ */
518
+ formFactor?: EditorInterface["formFactor"];
519
+ desktopUIMode?: EditorInterface["desktopUIMode"];
501
520
  /** @deprecated does nothing. Will be removed in 0.15 */
502
521
  welcomeScreen?: boolean;
503
522
  }>;
@@ -528,7 +547,7 @@ export type AppClassProperties = {
528
547
  mimeType: ValueOf<typeof IMAGE_MIME_TYPES>;
529
548
  }>;
530
549
  files: BinaryFiles;
531
- device: App["device"];
550
+ editorInterface: App["editorInterface"];
532
551
  scene: App["scene"];
533
552
  syncActionResult: App["syncActionResult"];
534
553
  fonts: App["fonts"];
@@ -557,7 +576,8 @@ export type AppClassProperties = {
557
576
  excalidrawContainerValue: App["excalidrawContainerValue"];
558
577
  onPointerUpEmitter: App["onPointerUpEmitter"];
559
578
  updateEditorAtom: App["updateEditorAtom"];
560
- defaultSelectionTool: "selection" | "lasso";
579
+ onPointerDownEmitter: App["onPointerDownEmitter"];
580
+ bindModeHandler: App["bindModeHandler"];
561
581
  };
562
582
  export type PointerDownState = Readonly<{
563
583
  origin: Readonly<{
@@ -643,6 +663,7 @@ export interface ExcalidrawImperativeAPI {
643
663
  setCursor: InstanceType<typeof App>["setCursor"];
644
664
  resetCursor: InstanceType<typeof App>["resetCursor"];
645
665
  toggleSidebar: InstanceType<typeof App>["toggleSidebar"];
666
+ getEditorInterface: () => EditorInterface;
646
667
  /**
647
668
  * Disables rendering of frames (including element clipping), but currently
648
669
  * the frames are still interactive in edit mode. As such, this API should be
@@ -656,17 +677,6 @@ export interface ExcalidrawImperativeAPI {
656
677
  onScrollChange: (callback: (scrollX: number, scrollY: number, zoom: Zoom) => void) => UnsubscribeCallback;
657
678
  onUserFollow: (callback: (payload: OnUserFollowedPayload) => void) => UnsubscribeCallback;
658
679
  }
659
- export type Device = Readonly<{
660
- viewport: {
661
- isMobile: boolean;
662
- isLandscape: boolean;
663
- };
664
- editor: {
665
- isMobile: boolean;
666
- canFitSidebar: boolean;
667
- };
668
- isTouchScreen: boolean;
669
- }>;
670
680
  export type FrameNameBounds = {
671
681
  x: number;
672
682
  y: number;
@@ -37,3 +37,4 @@ export declare const distanceToLineSegment: <Point extends GlobalPoint | LocalPo
37
37
  * @returns
38
38
  */
39
39
  export declare function lineSegmentIntersectionPoints<Point extends GlobalPoint | LocalPoint>(l: LineSegment<Point>, s: LineSegment<Point>, threshold?: number): Point | null;
40
+ export declare function lineSegmentsDistance<Point extends GlobalPoint | LocalPoint>(s1: LineSegment<Point>, s2: LineSegment<Point>): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excalidraw/common",
3
- "version": "0.18.0-b9d27d3",
3
+ "version": "0.18.0-c141960",
4
4
  "type": "module",
5
5
  "types": "./dist/types/common/src/index.d.ts",
6
6
  "main": "./dist/prod/index.js",