@excalidraw/excalidraw 0.17.1-7500-ac247a0 → 0.17.1-b7babe5
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.
- package/CHANGELOG.md +56 -2
- package/dist/browser/dev/excalidraw-assets-dev/{chunk-2W5GQUR4.js → chunk-6NMK7JTV.js} +13 -6
- package/dist/browser/dev/excalidraw-assets-dev/chunk-6NMK7JTV.js.map +7 -0
- package/dist/browser/dev/excalidraw-assets-dev/chunk-CX3RATXT.js +20324 -0
- package/dist/browser/dev/excalidraw-assets-dev/chunk-CX3RATXT.js.map +7 -0
- package/dist/browser/dev/excalidraw-assets-dev/{en-OC6JWP3X.js → en-BZY7JRTM.js} +4 -2
- package/dist/browser/dev/excalidraw-assets-dev/{image-5TVMINCA.js → image-CVN3YKRW.js} +2 -4
- package/dist/browser/dev/excalidraw-assets-dev/image-LK4UNFRZ.css +6 -0
- package/dist/browser/dev/excalidraw-assets-dev/image-LK4UNFRZ.css.map +7 -0
- package/dist/browser/dev/excalidraw-assets-dev/roundRect-T5BX56ZF.js +161 -0
- package/dist/browser/dev/excalidraw-assets-dev/roundRect-T5BX56ZF.js.map +7 -0
- package/dist/browser/dev/index.css +189 -129
- package/dist/browser/dev/index.css.map +3 -3
- package/dist/browser/dev/index.js +34964 -37
- package/dist/browser/dev/index.js.map +4 -4
- package/dist/browser/prod/excalidraw-assets/chunk-VJAIK3AX.js +55 -0
- package/dist/browser/prod/excalidraw-assets/chunk-YYO5DFUW.js +11 -0
- package/dist/browser/prod/excalidraw-assets/en-O2YCQM2W.js +1 -0
- package/dist/browser/prod/excalidraw-assets/image-6FKY54X5.js +1 -0
- package/dist/browser/prod/excalidraw-assets/image-X66R2EM5.css +1 -0
- package/dist/browser/prod/excalidraw-assets/roundRect-2ACQK4DA.js +1 -0
- package/dist/browser/prod/index.css +1 -1
- package/dist/browser/prod/index.js +203 -1
- package/dist/{prod/en-RLIAOBCI.json → dev/en-EY7E2L5O.json} +10 -5
- package/dist/dev/index.css +189 -129
- package/dist/dev/index.css.map +3 -3
- package/dist/dev/index.js +38702 -39409
- package/dist/dev/index.js.map +4 -4
- package/dist/excalidraw/actions/actionAddToLibrary.d.ts +15 -15
- package/dist/excalidraw/actions/actionAlign.d.ts +6 -6
- package/dist/excalidraw/actions/actionAlign.js +2 -1
- package/dist/excalidraw/actions/actionBoundText.d.ts +10 -10
- package/dist/excalidraw/actions/actionBoundText.js +8 -8
- package/dist/excalidraw/actions/actionCanvas.d.ts +58 -58
- package/dist/excalidraw/actions/actionClipboard.d.ts +34 -34
- package/dist/excalidraw/actions/actionClipboard.js +9 -2
- package/dist/excalidraw/actions/actionDeleteSelected.d.ts +15 -15
- package/dist/excalidraw/actions/actionDeleteSelected.js +3 -2
- package/dist/excalidraw/actions/actionDistribute.d.ts +2 -2
- package/dist/excalidraw/actions/actionDistribute.js +1 -1
- package/dist/excalidraw/actions/actionDuplicateSelection.d.ts +1 -1
- package/dist/excalidraw/actions/actionDuplicateSelection.js +4 -3
- package/dist/excalidraw/actions/actionElementLock.d.ts +10 -10
- package/dist/excalidraw/actions/actionExport.d.ts +43 -43
- package/dist/excalidraw/actions/actionExport.js +4 -4
- package/dist/excalidraw/actions/actionFinalize.d.ts +9 -9
- package/dist/excalidraw/actions/actionFinalize.js +7 -6
- package/dist/excalidraw/actions/actionFlip.d.ts +2 -2
- package/dist/excalidraw/actions/actionFlip.js +11 -11
- package/dist/excalidraw/actions/actionFrame.d.ts +16 -16
- package/dist/excalidraw/actions/actionFrame.js +1 -1
- package/dist/excalidraw/actions/actionGroup.d.ts +10 -10
- package/dist/excalidraw/actions/actionGroup.js +3 -2
- package/dist/excalidraw/actions/actionLinearEditor.d.ts +5 -5
- package/dist/excalidraw/actions/actionLinearEditor.js +1 -1
- package/dist/excalidraw/{element/Hyperlink.d.ts → actions/actionLink.d.ts} +29 -51
- package/dist/excalidraw/actions/actionLink.js +40 -0
- package/dist/excalidraw/actions/actionMenu.d.ts +13 -13
- package/dist/excalidraw/actions/actionNavigate.d.ts +10 -10
- package/dist/excalidraw/actions/actionNavigate.js +1 -1
- package/dist/excalidraw/actions/actionProperties.d.ts +77 -77
- package/dist/excalidraw/actions/actionProperties.js +32 -27
- package/dist/excalidraw/actions/actionSelectAll.d.ts +5 -5
- package/dist/excalidraw/actions/actionSelectAll.js +1 -1
- package/dist/excalidraw/actions/actionStyles.d.ts +7 -7
- package/dist/excalidraw/actions/actionStyles.js +4 -4
- package/dist/excalidraw/actions/actionToggleGridMode.d.ts +5 -5
- package/dist/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +5 -5
- package/dist/excalidraw/actions/actionToggleStats.d.ts +5 -5
- package/dist/excalidraw/actions/actionToggleViewMode.d.ts +5 -5
- package/dist/excalidraw/actions/actionToggleZenMode.d.ts +5 -5
- package/dist/excalidraw/actions/index.d.ts +1 -1
- package/dist/excalidraw/actions/index.js +1 -1
- package/dist/excalidraw/actions/manager.js +2 -1
- package/dist/excalidraw/align.d.ts +2 -2
- package/dist/excalidraw/align.js +2 -2
- package/dist/excalidraw/animated-trail.d.ts +33 -0
- package/dist/excalidraw/animated-trail.js +96 -0
- package/dist/excalidraw/animation-frame-handler.d.ts +16 -0
- package/dist/excalidraw/animation-frame-handler.js +55 -0
- package/dist/excalidraw/appState.d.ts +1 -1
- package/dist/excalidraw/appState.js +1 -3
- package/dist/excalidraw/clipboard.js +5 -5
- package/dist/excalidraw/components/Actions.d.ts +3 -3
- package/dist/excalidraw/components/Actions.js +18 -7
- package/dist/excalidraw/components/App.d.ts +23 -16
- package/dist/excalidraw/components/App.js +387 -272
- package/dist/excalidraw/components/Button.d.ts +1 -1
- package/dist/excalidraw/components/FilledButton.d.ts +2 -2
- package/dist/excalidraw/components/FilledButton.js +27 -3
- package/dist/excalidraw/components/FollowMode/FollowMode.js +1 -1
- package/dist/excalidraw/components/ImageExportDialog.d.ts +2 -1
- package/dist/excalidraw/components/ImageExportDialog.js +17 -13
- package/dist/excalidraw/components/JSONExportDialog.js +1 -1
- package/dist/excalidraw/components/{LaserTool/LaserPointerButton.d.ts → LaserPointerButton.d.ts} +1 -1
- package/dist/excalidraw/components/{LaserTool/LaserPointerButton.js → LaserPointerButton.js} +2 -2
- package/dist/excalidraw/components/LayerUI.js +3 -3
- package/dist/excalidraw/components/MobileMenu.js +1 -1
- package/dist/excalidraw/components/ProjectName.d.ts +0 -1
- package/dist/excalidraw/components/ProjectName.js +1 -1
- package/dist/excalidraw/components/PublishLibrary.js +1 -1
- package/dist/excalidraw/components/SVGLayer.d.ts +8 -0
- package/dist/excalidraw/components/SVGLayer.js +20 -0
- package/dist/excalidraw/components/ShareableLinkDialog.js +10 -10
- package/dist/excalidraw/components/Sidebar/Sidebar.d.ts +1 -1
- package/dist/excalidraw/components/Stack.d.ts +2 -2
- package/dist/excalidraw/components/TTDDialog/common.js +10 -1
- package/dist/excalidraw/components/TextField.d.ts +5 -2
- package/dist/excalidraw/components/TextField.js +6 -3
- package/dist/excalidraw/components/Toast.d.ts +3 -2
- package/dist/excalidraw/components/Toast.js +2 -2
- package/dist/excalidraw/components/ToolButton.js +2 -1
- package/dist/excalidraw/components/canvases/InteractiveCanvas.d.ts +2 -2
- package/dist/excalidraw/components/canvases/InteractiveCanvas.js +6 -5
- package/dist/excalidraw/components/canvases/StaticCanvas.d.ts +4 -3
- package/dist/excalidraw/components/canvases/StaticCanvas.js +7 -5
- package/dist/excalidraw/components/dropdownMenu/DropdownMenuContent.js +22 -2
- package/dist/excalidraw/components/hyperlink/Hyperlink.d.ts +19 -0
- package/dist/excalidraw/{element → components/hyperlink}/Hyperlink.js +40 -115
- package/dist/excalidraw/components/hyperlink/helpers.d.ts +7 -0
- package/dist/excalidraw/components/hyperlink/helpers.js +49 -0
- package/dist/excalidraw/components/icons.d.ts +2 -1
- package/dist/excalidraw/components/icons.js +2 -1
- package/dist/excalidraw/components/live-collaboration/LiveCollaborationTrigger.js +3 -2
- package/dist/excalidraw/components/main-menu/DefaultItems.js +5 -2
- package/dist/excalidraw/constants.d.ts +6 -0
- package/dist/excalidraw/constants.js +6 -0
- package/dist/excalidraw/data/blob.js +13 -14
- package/dist/excalidraw/data/filesystem.d.ts +1 -1
- package/dist/excalidraw/data/index.d.ts +2 -1
- package/dist/excalidraw/data/index.js +20 -16
- package/dist/excalidraw/data/json.d.ts +1 -1
- package/dist/excalidraw/data/json.js +5 -3
- package/dist/excalidraw/data/library.d.ts +60 -8
- package/dist/excalidraw/data/library.js +302 -33
- package/dist/excalidraw/data/resave.d.ts +1 -1
- package/dist/excalidraw/data/resave.js +2 -2
- package/dist/excalidraw/data/restore.js +8 -13
- package/dist/excalidraw/data/transform.js +13 -9
- package/dist/excalidraw/distribute.d.ts +2 -2
- package/dist/excalidraw/distribute.js +2 -2
- package/dist/excalidraw/element/ElementCanvasButtons.d.ts +3 -2
- package/dist/excalidraw/element/ElementCanvasButtons.js +4 -4
- package/dist/excalidraw/element/binding.d.ts +9 -9
- package/dist/excalidraw/element/binding.js +61 -59
- package/dist/excalidraw/element/bounds.d.ts +5 -5
- package/dist/excalidraw/element/bounds.js +29 -32
- package/dist/excalidraw/element/collision.d.ts +11 -11
- package/dist/excalidraw/element/collision.js +49 -46
- package/dist/excalidraw/element/containerCache.d.ts +11 -0
- package/dist/excalidraw/element/containerCache.js +14 -0
- package/dist/excalidraw/element/dragElements.js +10 -19
- package/dist/excalidraw/element/embeddable.d.ts +12 -13
- package/dist/excalidraw/element/embeddable.js +17 -27
- package/dist/excalidraw/element/image.js +1 -2
- package/dist/excalidraw/element/index.d.ts +8 -1
- package/dist/excalidraw/element/index.js +23 -1
- package/dist/excalidraw/element/linearElementEditor.d.ts +36 -36
- package/dist/excalidraw/element/linearElementEditor.js +79 -80
- package/dist/excalidraw/element/newElement.d.ts +4 -6
- package/dist/excalidraw/element/newElement.js +11 -16
- package/dist/excalidraw/element/resizeElements.d.ts +6 -6
- package/dist/excalidraw/element/resizeElements.js +40 -46
- package/dist/excalidraw/element/resizeTest.d.ts +3 -3
- package/dist/excalidraw/element/resizeTest.js +4 -4
- package/dist/excalidraw/element/sizeHelpers.d.ts +2 -2
- package/dist/excalidraw/element/sizeHelpers.js +2 -2
- package/dist/excalidraw/element/textElement.d.ts +34 -21
- package/dist/excalidraw/element/textElement.js +87 -111
- package/dist/excalidraw/element/textWysiwyg.d.ts +1 -6
- package/dist/excalidraw/element/textWysiwyg.js +15 -37
- package/dist/excalidraw/element/transformHandles.d.ts +4 -4
- package/dist/excalidraw/element/transformHandles.js +6 -6
- package/dist/excalidraw/element/typeChecks.js +4 -1
- package/dist/excalidraw/element/types.d.ts +24 -11
- package/dist/excalidraw/frame.d.ts +26 -20
- package/dist/excalidraw/frame.js +157 -84
- package/dist/excalidraw/groups.d.ts +3 -3
- package/dist/excalidraw/groups.js +11 -3
- package/dist/excalidraw/history.d.ts +1 -1
- package/dist/excalidraw/hooks/useLibraryItemSvg.js +1 -1
- package/dist/excalidraw/index.d.ts +9 -10
- package/dist/excalidraw/index.js +16 -12
- package/dist/excalidraw/laser-trails.d.ts +19 -0
- package/dist/excalidraw/laser-trails.js +95 -0
- package/dist/excalidraw/locales/en.json +10 -5
- package/dist/excalidraw/queue.d.ts +9 -0
- package/dist/excalidraw/queue.js +27 -0
- package/dist/excalidraw/reactUtils.d.ts +14 -0
- package/dist/excalidraw/reactUtils.js +45 -0
- package/dist/excalidraw/renderer/helpers.d.ts +13 -0
- package/dist/excalidraw/renderer/helpers.js +39 -0
- package/dist/excalidraw/renderer/interactiveScene.d.ts +20 -0
- package/dist/excalidraw/renderer/{renderScene.js → interactiveScene.js} +199 -474
- package/dist/excalidraw/renderer/renderElement.d.ts +6 -6
- package/dist/excalidraw/renderer/renderElement.js +54 -366
- package/dist/excalidraw/renderer/staticScene.d.ts +11 -0
- package/dist/excalidraw/renderer/staticScene.js +205 -0
- package/dist/excalidraw/renderer/staticSvgScene.d.ts +5 -0
- package/dist/excalidraw/renderer/staticSvgScene.js +385 -0
- package/dist/excalidraw/scene/Fonts.js +2 -1
- package/dist/excalidraw/scene/Renderer.d.ts +1 -1
- package/dist/excalidraw/scene/Renderer.js +32 -20
- package/dist/excalidraw/scene/Scene.d.ts +10 -9
- package/dist/excalidraw/scene/Scene.js +45 -21
- package/dist/excalidraw/scene/Shape.d.ts +3 -1
- package/dist/excalidraw/scene/Shape.js +7 -5
- package/dist/excalidraw/scene/ShapeCache.d.ts +2 -1
- package/dist/excalidraw/scene/ShapeCache.js +1 -0
- package/dist/excalidraw/scene/comparisons.js +2 -1
- package/dist/excalidraw/scene/export.d.ts +3 -0
- package/dist/excalidraw/scene/export.js +20 -40
- package/dist/excalidraw/scene/index.d.ts +0 -1
- package/dist/excalidraw/scene/index.js +0 -1
- package/dist/excalidraw/scene/scrollbars.d.ts +1 -1
- package/dist/excalidraw/scene/scrollbars.js +1 -1
- package/dist/excalidraw/scene/selection.d.ts +5 -5
- package/dist/excalidraw/scene/selection.js +16 -14
- package/dist/excalidraw/scene/types.d.ts +11 -5
- package/dist/excalidraw/snapping.d.ts +7 -7
- package/dist/excalidraw/snapping.js +21 -20
- package/dist/excalidraw/types.d.ts +16 -17
- package/dist/excalidraw/utility-types.d.ts +7 -0
- package/dist/excalidraw/utils.d.ts +21 -16
- package/dist/excalidraw/utils.js +43 -45
- package/dist/{dev/en-RLIAOBCI.json → prod/en-EY7E2L5O.json} +10 -5
- package/dist/prod/index.css +1 -1
- package/dist/prod/index.js +42 -42
- package/dist/utils/bbox.d.ts +2 -2
- package/dist/utils/export.d.ts +3 -3
- package/dist/utils/export.js +3 -13
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +2 -2
- package/dist/utils/withinBounds.d.ts +1 -1
- package/dist/utils/withinBounds.js +5 -2
- package/package.json +4 -4
- package/dist/browser/dev/excalidraw-assets-dev/chunk-2W5GQUR4.js.map +0 -7
- package/dist/browser/dev/excalidraw-assets-dev/chunk-KGZXLFLR.js +0 -53497
- package/dist/browser/dev/excalidraw-assets-dev/chunk-KGZXLFLR.js.map +0 -7
- package/dist/browser/dev/excalidraw-assets-dev/image-3MFRCKYM.css +0 -5797
- package/dist/browser/dev/excalidraw-assets-dev/image-3MFRCKYM.css.map +0 -7
- package/dist/browser/prod/excalidraw-assets/chunk-4YN2HN3S.js +0 -257
- package/dist/browser/prod/excalidraw-assets/chunk-OWLL6VOG.js +0 -11
- package/dist/browser/prod/excalidraw-assets/en-ERQOR3OC.js +0 -1
- package/dist/browser/prod/excalidraw-assets/image-LTLHTTSE.js +0 -1
- package/dist/browser/prod/excalidraw-assets/image-QBL334OA.css +0 -1
- package/dist/excalidraw/components/LaserTool/LaserPathManager.d.ts +0 -28
- package/dist/excalidraw/components/LaserTool/LaserPathManager.js +0 -225
- package/dist/excalidraw/components/LaserTool/LaserTool.d.ts +0 -8
- package/dist/excalidraw/components/LaserTool/LaserTool.js +0 -15
- package/dist/excalidraw/renderer/renderScene.d.ts +0 -25
- package/dist/excalidraw/vite.config.d.mts +0 -2
- package/dist/excalidraw/vite.config.mjs +0 -13
- /package/dist/browser/dev/excalidraw-assets-dev/{en-OC6JWP3X.js.map → en-BZY7JRTM.js.map} +0 -0
- /package/dist/browser/dev/excalidraw-assets-dev/{image-5TVMINCA.js.map → image-CVN3YKRW.js.map} +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { RoughCanvas } from "roughjs/bin/canvas";
|
|
2
2
|
import { Drawable } from "roughjs/bin/core";
|
|
3
|
-
import { ExcalidrawTextElement, NonDeletedExcalidrawElement } from "../element/types";
|
|
4
|
-
import { AppClassProperties, AppState, InteractiveCanvasAppState, StaticCanvasAppState } from "../types";
|
|
3
|
+
import { ExcalidrawTextElement, NonDeletedElementsMap, NonDeletedExcalidrawElement, NonDeletedSceneElementsMap } from "../element/types";
|
|
4
|
+
import { AppClassProperties, AppState, EmbedsValidationStatus, ElementsPendingErasure, InteractiveCanvasAppState, StaticCanvasAppState } from "../types";
|
|
5
|
+
import { MakeBrand } from "../utility-types";
|
|
6
|
+
export type RenderableElementsMap = NonDeletedElementsMap & MakeBrand<"RenderableElementsMap">;
|
|
5
7
|
export type StaticCanvasRenderConfig = {
|
|
6
8
|
canvasBackgroundColor: AppState["viewBackgroundColor"];
|
|
7
9
|
imageCache: AppClassProperties["imageCache"];
|
|
@@ -9,6 +11,8 @@ export type StaticCanvasRenderConfig = {
|
|
|
9
11
|
/** when exporting the behavior is slightly different (e.g. we can't use
|
|
10
12
|
CSS filters), and we disable render optimizations for best output */
|
|
11
13
|
isExporting: boolean;
|
|
14
|
+
embedsValidationStatus: EmbedsValidationStatus;
|
|
15
|
+
elementsPendingErasure: ElementsPendingErasure;
|
|
12
16
|
};
|
|
13
17
|
export type SVGRenderConfig = {
|
|
14
18
|
offsetX: number;
|
|
@@ -18,6 +22,7 @@ export type SVGRenderConfig = {
|
|
|
18
22
|
renderEmbeddables: boolean;
|
|
19
23
|
frameRendering: AppState["frameRendering"];
|
|
20
24
|
canvasBackgroundColor: AppState["viewBackgroundColor"];
|
|
25
|
+
embedsValidationStatus: EmbedsValidationStatus;
|
|
21
26
|
};
|
|
22
27
|
export type InteractiveCanvasRenderConfig = {
|
|
23
28
|
remoteSelectedElementIds: {
|
|
@@ -43,13 +48,14 @@ export type InteractiveCanvasRenderConfig = {
|
|
|
43
48
|
};
|
|
44
49
|
export type RenderInteractiveSceneCallback = {
|
|
45
50
|
atLeastOneVisibleElement: boolean;
|
|
46
|
-
|
|
51
|
+
elementsMap: RenderableElementsMap;
|
|
47
52
|
scrollBars?: ScrollBars;
|
|
48
53
|
};
|
|
49
54
|
export type StaticSceneRenderConfig = {
|
|
50
55
|
canvas: HTMLCanvasElement;
|
|
51
56
|
rc: RoughCanvas;
|
|
52
|
-
|
|
57
|
+
elementsMap: RenderableElementsMap;
|
|
58
|
+
allElementsMap: NonDeletedSceneElementsMap;
|
|
53
59
|
visibleElements: readonly NonDeletedExcalidrawElement[];
|
|
54
60
|
scale: number;
|
|
55
61
|
appState: StaticCanvasAppState;
|
|
@@ -57,7 +63,7 @@ export type StaticSceneRenderConfig = {
|
|
|
57
63
|
};
|
|
58
64
|
export type InteractiveSceneRenderConfig = {
|
|
59
65
|
canvas: HTMLCanvasElement | null;
|
|
60
|
-
|
|
66
|
+
elementsMap: RenderableElementsMap;
|
|
61
67
|
visibleElements: readonly NonDeletedExcalidrawElement[];
|
|
62
68
|
selectedElements: readonly NonDeletedExcalidrawElement[];
|
|
63
69
|
scale: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Bounds } from "./element/bounds";
|
|
2
2
|
import { MaybeTransformHandleType } from "./element/transformHandles";
|
|
3
|
-
import { ExcalidrawElement, NonDeletedExcalidrawElement } from "./element/types";
|
|
3
|
+
import { ElementsMap, ExcalidrawElement, NonDeletedExcalidrawElement } from "./element/types";
|
|
4
4
|
import { AppState, KeyboardModifiersObject, Point } from "./types";
|
|
5
5
|
export declare const getSnapDistance: (zoomValue: number) => number;
|
|
6
6
|
type Vector2D = {
|
|
@@ -66,17 +66,17 @@ export declare const isSnappingEnabled: ({ event, appState, selectedElements, }:
|
|
|
66
66
|
selectedElements: NonDeletedExcalidrawElement[];
|
|
67
67
|
}) => boolean;
|
|
68
68
|
export declare const areRoughlyEqual: (a: number, b: number, precision?: number) => boolean;
|
|
69
|
-
export declare const getElementsCorners: (elements: ExcalidrawElement[], { omitCenter, boundingBoxCorners, dragOffset, }?: {
|
|
69
|
+
export declare const getElementsCorners: (elements: ExcalidrawElement[], elementsMap: ElementsMap, { omitCenter, boundingBoxCorners, dragOffset, }?: {
|
|
70
70
|
omitCenter?: boolean | undefined;
|
|
71
71
|
boundingBoxCorners?: boolean | undefined;
|
|
72
72
|
dragOffset?: Vector2D | undefined;
|
|
73
73
|
}) => Point[];
|
|
74
|
-
export declare const getVisibleGaps: (elements: readonly NonDeletedExcalidrawElement[], selectedElements: ExcalidrawElement[], appState: AppState) => {
|
|
74
|
+
export declare const getVisibleGaps: (elements: readonly NonDeletedExcalidrawElement[], selectedElements: ExcalidrawElement[], appState: AppState, elementsMap: ElementsMap) => {
|
|
75
75
|
horizontalGaps: Gap[];
|
|
76
76
|
verticalGaps: Gap[];
|
|
77
77
|
};
|
|
78
|
-
export declare const getReferenceSnapPoints: (elements: readonly NonDeletedExcalidrawElement[], selectedElements: ExcalidrawElement[], appState: AppState) => (readonly [number, number])[];
|
|
79
|
-
export declare const snapDraggedElements: (
|
|
78
|
+
export declare const getReferenceSnapPoints: (elements: readonly NonDeletedExcalidrawElement[], selectedElements: ExcalidrawElement[], appState: AppState, elementsMap: ElementsMap) => (readonly [number, number])[];
|
|
79
|
+
export declare const snapDraggedElements: (elements: ExcalidrawElement[], dragOffset: Vector2D, appState: AppState, event: KeyboardModifiersObject, elementsMap: ElementsMap) => {
|
|
80
80
|
snapOffset: {
|
|
81
81
|
x: number;
|
|
82
82
|
y: number;
|
|
@@ -90,14 +90,14 @@ export declare const snapResizingElements: (selectedElements: ExcalidrawElement[
|
|
|
90
90
|
};
|
|
91
91
|
snapLines: PointSnapLine[];
|
|
92
92
|
};
|
|
93
|
-
export declare const snapNewElement: (draggingElement: ExcalidrawElement, appState: AppState, event: KeyboardModifiersObject, origin: Vector2D, dragOffset: Vector2D) => {
|
|
93
|
+
export declare const snapNewElement: (draggingElement: ExcalidrawElement, appState: AppState, event: KeyboardModifiersObject, origin: Vector2D, dragOffset: Vector2D, elementsMap: ElementsMap) => {
|
|
94
94
|
snapOffset: {
|
|
95
95
|
x: number;
|
|
96
96
|
y: number;
|
|
97
97
|
};
|
|
98
98
|
snapLines: PointSnapLine[];
|
|
99
99
|
};
|
|
100
|
-
export declare const getSnapLinesAtPointer: (elements: readonly ExcalidrawElement[], appState: AppState, pointer: Vector2D, event: KeyboardModifiersObject) => {
|
|
100
|
+
export declare const getSnapLinesAtPointer: (elements: readonly ExcalidrawElement[], appState: AppState, pointer: Vector2D, event: KeyboardModifiersObject, elementsMap: ElementsMap) => {
|
|
101
101
|
originOffset: {
|
|
102
102
|
x: number;
|
|
103
103
|
y: number;
|
|
@@ -4,7 +4,7 @@ import { isBoundToContainer, isFrameLikeElement } from "./element/typeChecks";
|
|
|
4
4
|
import { getMaximumGroups } from "./groups";
|
|
5
5
|
import { KEYS } from "./keys";
|
|
6
6
|
import { rangeIntersection, rangesOverlap, rotatePoint } from "./math";
|
|
7
|
-
import { getVisibleAndNonSelectedElements } from "./scene/selection";
|
|
7
|
+
import { getSelectedElements, getVisibleAndNonSelectedElements, } from "./scene/selection";
|
|
8
8
|
const SNAP_DISTANCE = 8;
|
|
9
9
|
// do not comput more gaps per axis than this limit
|
|
10
10
|
// TODO increase or remove once we optimize
|
|
@@ -51,14 +51,14 @@ export const isSnappingEnabled = ({ event, appState, selectedElements, }) => {
|
|
|
51
51
|
export const areRoughlyEqual = (a, b, precision = 0.01) => {
|
|
52
52
|
return Math.abs(a - b) <= precision;
|
|
53
53
|
};
|
|
54
|
-
export const getElementsCorners = (elements, { omitCenter, boundingBoxCorners, dragOffset, } = {
|
|
54
|
+
export const getElementsCorners = (elements, elementsMap, { omitCenter, boundingBoxCorners, dragOffset, } = {
|
|
55
55
|
omitCenter: false,
|
|
56
56
|
boundingBoxCorners: false,
|
|
57
57
|
}) => {
|
|
58
58
|
let result = [];
|
|
59
59
|
if (elements.length === 1) {
|
|
60
60
|
const element = elements[0];
|
|
61
|
-
let [x1, y1, x2, y2, cx, cy] = getElementAbsoluteCoords(element);
|
|
61
|
+
let [x1, y1, x2, y2, cx, cy] = getElementAbsoluteCoords(element, elementsMap);
|
|
62
62
|
if (dragOffset) {
|
|
63
63
|
x1 += dragOffset.x;
|
|
64
64
|
x2 += dragOffset.x;
|
|
@@ -106,15 +106,15 @@ export const getElementsCorners = (elements, { omitCenter, boundingBoxCorners, d
|
|
|
106
106
|
}
|
|
107
107
|
return result.map((point) => [round(point[0]), round(point[1])]);
|
|
108
108
|
};
|
|
109
|
-
const getReferenceElements = (elements, selectedElements, appState) => {
|
|
109
|
+
const getReferenceElements = (elements, selectedElements, appState, elementsMap) => {
|
|
110
110
|
const selectedFrames = selectedElements
|
|
111
111
|
.filter((element) => isFrameLikeElement(element))
|
|
112
112
|
.map((frame) => frame.id);
|
|
113
|
-
return getVisibleAndNonSelectedElements(elements, selectedElements, appState).filter((element) => !(element.frameId && selectedFrames.includes(element.frameId)));
|
|
113
|
+
return getVisibleAndNonSelectedElements(elements, selectedElements, appState, elementsMap).filter((element) => !(element.frameId && selectedFrames.includes(element.frameId)));
|
|
114
114
|
};
|
|
115
|
-
export const getVisibleGaps = (elements, selectedElements, appState) => {
|
|
116
|
-
const referenceElements = getReferenceElements(elements, selectedElements, appState);
|
|
117
|
-
const referenceBounds = getMaximumGroups(referenceElements)
|
|
115
|
+
export const getVisibleGaps = (elements, selectedElements, appState, elementsMap) => {
|
|
116
|
+
const referenceElements = getReferenceElements(elements, selectedElements, appState, elementsMap);
|
|
117
|
+
const referenceBounds = getMaximumGroups(referenceElements, elementsMap)
|
|
118
118
|
.filter((elementsGroup) => !(elementsGroup.length === 1 && isBoundToContainer(elementsGroup[0])))
|
|
119
119
|
.map((group) => getCommonBounds(group).map((bound) => round(bound)));
|
|
120
120
|
const horizontallySorted = referenceBounds.sort((a, b) => a[0] - b[0]);
|
|
@@ -317,11 +317,11 @@ const getGapSnaps = (selectedElements, dragOffset, appState, event, nearestSnaps
|
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
};
|
|
320
|
-
export const getReferenceSnapPoints = (elements, selectedElements, appState) => {
|
|
321
|
-
const referenceElements = getReferenceElements(elements, selectedElements, appState);
|
|
322
|
-
return getMaximumGroups(referenceElements)
|
|
320
|
+
export const getReferenceSnapPoints = (elements, selectedElements, appState, elementsMap) => {
|
|
321
|
+
const referenceElements = getReferenceElements(elements, selectedElements, appState, elementsMap);
|
|
322
|
+
return getMaximumGroups(referenceElements, elementsMap)
|
|
323
323
|
.filter((elementsGroup) => !(elementsGroup.length === 1 && isBoundToContainer(elementsGroup[0])))
|
|
324
|
-
.flatMap((elementGroup) => getElementsCorners(elementGroup));
|
|
324
|
+
.flatMap((elementGroup) => getElementsCorners(elementGroup, elementsMap));
|
|
325
325
|
};
|
|
326
326
|
const getPointSnaps = (selectedElements, selectionSnapPoints, appState, event, nearestSnapsX, nearestSnapsY, minOffset) => {
|
|
327
327
|
if (!isSnappingEnabled({ appState, event, selectedElements }) ||
|
|
@@ -360,7 +360,8 @@ const getPointSnaps = (selectedElements, selectionSnapPoints, appState, event, n
|
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
};
|
|
363
|
-
export const snapDraggedElements = (
|
|
363
|
+
export const snapDraggedElements = (elements, dragOffset, appState, event, elementsMap) => {
|
|
364
|
+
const selectedElements = getSelectedElements(elements, appState);
|
|
364
365
|
if (!isSnappingEnabled({ appState, event, selectedElements }) ||
|
|
365
366
|
selectedElements.length === 0) {
|
|
366
367
|
return {
|
|
@@ -380,7 +381,7 @@ export const snapDraggedElements = (selectedElements, dragOffset, appState, even
|
|
|
380
381
|
x: snapDistance,
|
|
381
382
|
y: snapDistance,
|
|
382
383
|
};
|
|
383
|
-
const selectionPoints = getElementsCorners(selectedElements, {
|
|
384
|
+
const selectionPoints = getElementsCorners(selectedElements, elementsMap, {
|
|
384
385
|
dragOffset,
|
|
385
386
|
});
|
|
386
387
|
// get the nearest horizontal and vertical point and gap snaps
|
|
@@ -406,7 +407,7 @@ export const snapDraggedElements = (selectedElements, dragOffset, appState, even
|
|
|
406
407
|
x: round(dragOffset.x + snapOffset.x),
|
|
407
408
|
y: round(dragOffset.y + snapOffset.y),
|
|
408
409
|
};
|
|
409
|
-
getPointSnaps(selectedElements, getElementsCorners(selectedElements, {
|
|
410
|
+
getPointSnaps(selectedElements, getElementsCorners(selectedElements, elementsMap, {
|
|
410
411
|
dragOffset: newDragOffset,
|
|
411
412
|
}), appState, event, nearestSnapsX, nearestSnapsY, minOffset);
|
|
412
413
|
getGapSnaps(selectedElements, newDragOffset, appState, event, nearestSnapsX, nearestSnapsY, minOffset);
|
|
@@ -735,7 +736,7 @@ selectedOriginalElements, appState, event, dragOffset, transformHandle) => {
|
|
|
735
736
|
snapLines: pointSnapLines,
|
|
736
737
|
};
|
|
737
738
|
};
|
|
738
|
-
export const snapNewElement = (draggingElement, appState, event, origin, dragOffset) => {
|
|
739
|
+
export const snapNewElement = (draggingElement, appState, event, origin, dragOffset, elementsMap) => {
|
|
739
740
|
if (!isSnappingEnabled({ event, selectedElements: [draggingElement], appState })) {
|
|
740
741
|
return {
|
|
741
742
|
snapOffset: { x: 0, y: 0 },
|
|
@@ -761,7 +762,7 @@ export const snapNewElement = (draggingElement, appState, event, origin, dragOff
|
|
|
761
762
|
minOffset.y = 0;
|
|
762
763
|
nearestSnapsX.length = 0;
|
|
763
764
|
nearestSnapsY.length = 0;
|
|
764
|
-
const corners = getElementsCorners([draggingElement], {
|
|
765
|
+
const corners = getElementsCorners([draggingElement], elementsMap, {
|
|
765
766
|
boundingBoxCorners: true,
|
|
766
767
|
omitCenter: true,
|
|
767
768
|
});
|
|
@@ -772,14 +773,14 @@ export const snapNewElement = (draggingElement, appState, event, origin, dragOff
|
|
|
772
773
|
snapLines: pointSnapLines,
|
|
773
774
|
};
|
|
774
775
|
};
|
|
775
|
-
export const getSnapLinesAtPointer = (elements, appState, pointer, event) => {
|
|
776
|
+
export const getSnapLinesAtPointer = (elements, appState, pointer, event, elementsMap) => {
|
|
776
777
|
if (!isSnappingEnabled({ event, selectedElements: [], appState })) {
|
|
777
778
|
return {
|
|
778
779
|
originOffset: { x: 0, y: 0 },
|
|
779
780
|
snapLines: [],
|
|
780
781
|
};
|
|
781
782
|
}
|
|
782
|
-
const referenceElements = getVisibleAndNonSelectedElements(elements, [], appState);
|
|
783
|
+
const referenceElements = getVisibleAndNonSelectedElements(elements, [], appState, elementsMap);
|
|
783
784
|
const snapDistance = getSnapDistance(appState.zoom.value);
|
|
784
785
|
const minOffset = {
|
|
785
786
|
x: snapDistance,
|
|
@@ -788,7 +789,7 @@ export const getSnapLinesAtPointer = (elements, appState, pointer, event) => {
|
|
|
788
789
|
const horizontalSnapLines = [];
|
|
789
790
|
const verticalSnapLines = [];
|
|
790
791
|
for (const referenceElement of referenceElements) {
|
|
791
|
-
const corners = getElementsCorners([referenceElement]);
|
|
792
|
+
const corners = getElementsCorners([referenceElement], elementsMap);
|
|
792
793
|
for (const corner of corners) {
|
|
793
794
|
const offsetX = corner[0] - pointer.x;
|
|
794
795
|
if (Math.abs(offsetX) <= Math.abs(minOffset.x)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, ExcalidrawImageElement, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType } from "./element/types";
|
|
2
|
+
import { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, ExcalidrawImageElement, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement } from "./element/types";
|
|
3
3
|
import { Action } from "./actions/types";
|
|
4
4
|
import { Point as RoughPoint } from "roughjs/bin/geometry";
|
|
5
5
|
import { LinearElementEditor } from "./element/linearElementEditor";
|
|
@@ -10,14 +10,14 @@ import type { throttleRAF } from "./utils";
|
|
|
10
10
|
import { Spreadsheet } from "./charts";
|
|
11
11
|
import { Language } from "./i18n";
|
|
12
12
|
import { ClipboardData } from "./clipboard";
|
|
13
|
-
import { isOverScrollBars } from "./scene";
|
|
13
|
+
import { isOverScrollBars } from "./scene/scrollbars";
|
|
14
14
|
import { MaybeTransformHandleType } from "./element/transformHandles";
|
|
15
15
|
import Library from "./data/library";
|
|
16
16
|
import type { FileSystemHandle } from "./data/filesystem";
|
|
17
17
|
import type { IMAGE_MIME_TYPES, MIME_TYPES } from "./constants";
|
|
18
18
|
import { ContextMenuItems } from "./components/ContextMenu";
|
|
19
19
|
import { SnapLine } from "./snapping";
|
|
20
|
-
import { Merge, ValueOf } from "./utility-types";
|
|
20
|
+
import { Merge, MaybePromise, ValueOf } from "./utility-types";
|
|
21
21
|
export type Point = Readonly<RoughPoint>;
|
|
22
22
|
export type SocketId = string & {
|
|
23
23
|
_brand: "SocketId";
|
|
@@ -181,7 +181,7 @@ export interface AppState {
|
|
|
181
181
|
scrollY: number;
|
|
182
182
|
cursorButton: "up" | "down";
|
|
183
183
|
scrolledOutside: boolean;
|
|
184
|
-
name: string;
|
|
184
|
+
name: string | null;
|
|
185
185
|
isResizing: boolean;
|
|
186
186
|
isRotating: boolean;
|
|
187
187
|
zoom: Zoom;
|
|
@@ -304,9 +304,9 @@ export type LibraryItem = {
|
|
|
304
304
|
};
|
|
305
305
|
export type LibraryItems = readonly LibraryItem[];
|
|
306
306
|
export type LibraryItems_anyVersion = LibraryItems | LibraryItems_v1;
|
|
307
|
-
export type LibraryItemsSource = ((currentLibraryItems: LibraryItems) =>
|
|
307
|
+
export type LibraryItemsSource = ((currentLibraryItems: LibraryItems) => MaybePromise<LibraryItems_anyVersion | Blob>) | MaybePromise<LibraryItems_anyVersion | Blob>;
|
|
308
308
|
export type ExcalidrawInitialDataState = Merge<ImportedDataState, {
|
|
309
|
-
libraryItems?:
|
|
309
|
+
libraryItems?: MaybePromise<Required<ImportedDataState>["libraryItems"]>;
|
|
310
310
|
}>;
|
|
311
311
|
export type OnUserFollowedPayload = {
|
|
312
312
|
userToFollow: UserToFollow;
|
|
@@ -314,7 +314,7 @@ export type OnUserFollowedPayload = {
|
|
|
314
314
|
};
|
|
315
315
|
export interface ExcalidrawProps {
|
|
316
316
|
onChange?: (elements: readonly ExcalidrawElement[], appState: AppState, files: BinaryFiles) => void;
|
|
317
|
-
initialData?:
|
|
317
|
+
initialData?: MaybePromise<ExcalidrawInitialDataState | null>;
|
|
318
318
|
excalidrawAPI?: (api: ExcalidrawImperativeAPI) => void;
|
|
319
319
|
isCollaborating?: boolean;
|
|
320
320
|
onPointerUpdate?: (payload: {
|
|
@@ -347,6 +347,7 @@ export interface ExcalidrawProps {
|
|
|
347
347
|
nativeEvent: MouseEvent | React.PointerEvent<HTMLCanvasElement>;
|
|
348
348
|
}>) => void;
|
|
349
349
|
onPointerDown?: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState) => void;
|
|
350
|
+
onPointerUp?: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState) => void;
|
|
350
351
|
onScrollChange?: (scrollX: number, scrollY: number, zoom: Zoom) => void;
|
|
351
352
|
onUserFollow?: (payload: OnUserFollowedPayload) => void;
|
|
352
353
|
children?: React.ReactNode;
|
|
@@ -367,7 +368,7 @@ export declare enum UserIdleState {
|
|
|
367
368
|
}
|
|
368
369
|
export type ExportOpts = {
|
|
369
370
|
saveFileToDisk?: boolean;
|
|
370
|
-
onExportToBackend?: (exportedElements: readonly NonDeletedExcalidrawElement[], appState: UIAppState, files: BinaryFiles
|
|
371
|
+
onExportToBackend?: (exportedElements: readonly NonDeletedExcalidrawElement[], appState: UIAppState, files: BinaryFiles) => void;
|
|
371
372
|
renderCustomUI?: (exportedElements: readonly NonDeletedExcalidrawElement[], appState: UIAppState, files: BinaryFiles, canvas: HTMLCanvasElement) => JSX.Element;
|
|
372
373
|
};
|
|
373
374
|
export type CanvasActions = Partial<{
|
|
@@ -429,6 +430,7 @@ export type AppClassProperties = {
|
|
|
429
430
|
setOpenDialog: App["setOpenDialog"];
|
|
430
431
|
insertEmbeddableElement: App["insertEmbeddableElement"];
|
|
431
432
|
onMagicframeToolSelect: App["onMagicframeToolSelect"];
|
|
433
|
+
getName: App["getName"];
|
|
432
434
|
};
|
|
433
435
|
export type PointerDownState = Readonly<{
|
|
434
436
|
origin: Readonly<{
|
|
@@ -482,15 +484,9 @@ export type PointerDownState = Readonly<{
|
|
|
482
484
|
boxSelection: {
|
|
483
485
|
hasOccurred: boolean;
|
|
484
486
|
};
|
|
485
|
-
elementIdsToErase: {
|
|
486
|
-
[key: ExcalidrawElement["id"]]: {
|
|
487
|
-
opacity: ExcalidrawElement["opacity"];
|
|
488
|
-
erase: boolean;
|
|
489
|
-
};
|
|
490
|
-
};
|
|
491
487
|
}>;
|
|
492
488
|
export type UnsubscribeCallback = () => void;
|
|
493
|
-
export
|
|
489
|
+
export interface ExcalidrawImperativeAPI {
|
|
494
490
|
updateScene: InstanceType<typeof App>["updateScene"];
|
|
495
491
|
updateLibrary: InstanceType<typeof Library>["updateLibrary"];
|
|
496
492
|
resetScene: InstanceType<typeof App>["resetScene"];
|
|
@@ -498,10 +494,11 @@ export type ExcalidrawImperativeAPI = {
|
|
|
498
494
|
history: {
|
|
499
495
|
clear: InstanceType<typeof App>["resetHistory"];
|
|
500
496
|
};
|
|
501
|
-
scrollToContent: InstanceType<typeof App>["scrollToContent"];
|
|
502
497
|
getSceneElements: InstanceType<typeof App>["getSceneElements"];
|
|
503
498
|
getAppState: () => InstanceType<typeof App>["state"];
|
|
504
499
|
getFiles: () => InstanceType<typeof App>["files"];
|
|
500
|
+
getName: InstanceType<typeof App>["getName"];
|
|
501
|
+
scrollToContent: InstanceType<typeof App>["scrollToContent"];
|
|
505
502
|
registerAction: (action: Action) => void;
|
|
506
503
|
refresh: InstanceType<typeof App>["refresh"];
|
|
507
504
|
setToast: InstanceType<typeof App>["setToast"];
|
|
@@ -522,7 +519,7 @@ export type ExcalidrawImperativeAPI = {
|
|
|
522
519
|
onPointerUp: (callback: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState, event: PointerEvent) => void) => UnsubscribeCallback;
|
|
523
520
|
onScrollChange: (callback: (scrollX: number, scrollY: number, zoom: Zoom) => void) => UnsubscribeCallback;
|
|
524
521
|
onUserFollow: (callback: (payload: OnUserFollowedPayload) => void) => UnsubscribeCallback;
|
|
525
|
-
}
|
|
522
|
+
}
|
|
526
523
|
export type Device = Readonly<{
|
|
527
524
|
viewport: {
|
|
528
525
|
isMobile: boolean;
|
|
@@ -556,4 +553,6 @@ export type KeyboardModifiersObject = {
|
|
|
556
553
|
};
|
|
557
554
|
export type Primitive = number | string | boolean | bigint | symbol | null | undefined;
|
|
558
555
|
export type JSONValue = string | number | boolean | null | object;
|
|
556
|
+
export type EmbedsValidationStatus = Map<ExcalidrawIframeLikeElement["id"], boolean>;
|
|
557
|
+
export type ElementsPendingErasure = Set<ExcalidrawElement["id"]>;
|
|
559
558
|
export {};
|
|
@@ -23,3 +23,10 @@ export type ExtractSetType<T extends Set<any>> = T extends Set<infer U> ? U : ne
|
|
|
23
23
|
export type SameType<T, U> = T extends U ? (U extends T ? true : false) : false;
|
|
24
24
|
export type Assert<T extends true> = T;
|
|
25
25
|
export type NestedKeyOf<T, K = keyof T> = K extends keyof T & (string | number) ? `${K}` | (T[K] extends object ? `${K}.${NestedKeyOf<T[K]>}` : never) : never;
|
|
26
|
+
export type SetLike<T> = Set<T> | T[];
|
|
27
|
+
export type ReadonlySetLike<T> = ReadonlySet<T> | readonly T[];
|
|
28
|
+
export type MakeBrand<T extends string> = {
|
|
29
|
+
[K in `~brand~${T}`]: T;
|
|
30
|
+
};
|
|
31
|
+
/** Maybe just promise or already fulfilled one! */
|
|
32
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EVENT } from "./constants";
|
|
2
2
|
import { FontFamilyValues, FontString } from "./element/types";
|
|
3
3
|
import { ActiveTool, AppState, ToolType, UnsubscribeCallback, Zoom } from "./types";
|
|
4
|
+
import { MaybePromise } from "./utility-types";
|
|
4
5
|
export declare const setDateTimeForTests: (dateTime: string) => void;
|
|
5
6
|
export declare const getDateTime: () => string;
|
|
6
7
|
export declare const capitalizeString: (str: string) => string;
|
|
@@ -137,23 +138,10 @@ export declare const findIndex: <T>(array: readonly T[], cb: (element: T, index:
|
|
|
137
138
|
export declare const findLastIndex: <T>(array: readonly T[], cb: (element: T, index: number, array: readonly T[]) => boolean, fromIndex?: number) => number;
|
|
138
139
|
export declare const isTransparent: (color: string) => boolean;
|
|
139
140
|
export type ResolvablePromise<T> = Promise<T> & {
|
|
140
|
-
resolve: [T] extends [undefined] ? (value?: T) => void : (value: T) => void;
|
|
141
|
+
resolve: [T] extends [undefined] ? (value?: MaybePromise<Awaited<T>>) => void : (value: MaybePromise<Awaited<T>>) => void;
|
|
141
142
|
reject: (error: Error) => void;
|
|
142
143
|
};
|
|
143
144
|
export declare const resolvablePromise: <T>() => ResolvablePromise<T>;
|
|
144
|
-
/**
|
|
145
|
-
* @param func handler taking at most single parameter (event).
|
|
146
|
-
*/
|
|
147
|
-
export declare const withBatchedUpdates: <TFunction extends ((event: any) => void) | (() => void)>(func: Parameters<TFunction>["length"] extends 0 | 1 ? TFunction : never) => TFunction;
|
|
148
|
-
/**
|
|
149
|
-
* barches React state updates and throttles the calls to a single call per
|
|
150
|
-
* animation frame
|
|
151
|
-
*/
|
|
152
|
-
export declare const withBatchedUpdatesThrottled: <TFunction extends ((event: any) => void) | (() => void)>(func: Parameters<TFunction>["length"] extends 0 | 1 ? TFunction : never) => {
|
|
153
|
-
(...args: Parameters<TFunction>): void;
|
|
154
|
-
flush(): void;
|
|
155
|
-
cancel(): void;
|
|
156
|
-
};
|
|
157
145
|
export declare const nFormatter: (num: number, digits: number) => string;
|
|
158
146
|
export declare const getVersion: () => string;
|
|
159
147
|
export declare const supportsEmoji: () => boolean;
|
|
@@ -168,7 +156,7 @@ export declare const getUpdatedTimestamp: () => number;
|
|
|
168
156
|
*/
|
|
169
157
|
export declare const arrayToMap: <T extends string | {
|
|
170
158
|
id: string;
|
|
171
|
-
}>(items: readonly T[]) => Map<string, T>;
|
|
159
|
+
}>(items: Map<string, T> | readonly T[]) => Map<string, T>;
|
|
172
160
|
export declare const arrayToMapWithIndex: <T extends {
|
|
173
161
|
id: string;
|
|
174
162
|
}>(elements: readonly T[]) => Map<string, [element: T, index: number]>;
|
|
@@ -205,7 +193,6 @@ export declare const assertNever: (value: never, message: string | null, softAss
|
|
|
205
193
|
export declare const memoize: <T extends Record<string, any>, R extends unknown>(func: (opts: T) => R) => ((opts: T) => R) & {
|
|
206
194
|
clear: () => void;
|
|
207
195
|
};
|
|
208
|
-
export declare const isRenderThrottlingEnabled: () => boolean;
|
|
209
196
|
/** Checks if value is inside given collection. Useful for type-safety. */
|
|
210
197
|
export declare const isMemberOf: <T extends string>(collection: Set<T> | Record<T, any> | Map<T, any> | readonly T[], value: string) => value is T;
|
|
211
198
|
export declare const cloneJSON: <T>(obj: T) => T;
|
|
@@ -217,3 +204,21 @@ export declare function addEventListener<K extends keyof DocumentEventMap>(targe
|
|
|
217
204
|
export declare function addEventListener(target: Document, type: string, listener: (this: Document, ev: Event) => any, options?: boolean | AddEventListenerOptions): UnsubscribeCallback;
|
|
218
205
|
export declare function addEventListener<K extends keyof FontFaceSetEventMap>(target: FontFaceSet, type: K, listener: (this: FontFaceSet, ev: FontFaceSetEventMap[K]) => any, options?: boolean | AddEventListenerOptions): UnsubscribeCallback;
|
|
219
206
|
export declare function addEventListener<K extends keyof HTMLElementEventMap>(target: Document | (Window & typeof globalThis) | HTMLElement | undefined | null | false, type: K, listener: (this: HTMLDivElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): UnsubscribeCallback;
|
|
207
|
+
export declare function getSvgPathFromStroke(points: number[][], closed?: boolean): string;
|
|
208
|
+
export declare const normalizeEOL: (str: string) => string;
|
|
209
|
+
type HasBrand<T> = {
|
|
210
|
+
[K in keyof T]: K extends `~brand${infer _}` ? true : never;
|
|
211
|
+
}[keyof T];
|
|
212
|
+
type RemoveAllBrands<T> = HasBrand<T> extends true ? {
|
|
213
|
+
[K in keyof T as K extends `~brand~${infer _}` ? never : K]: T[K];
|
|
214
|
+
} : never;
|
|
215
|
+
type Unbrand<T> = T extends Map<infer E, infer F> ? Map<E, F> : T extends Set<infer E> ? Set<E> : T extends Array<infer E> ? Array<E> : RemoveAllBrands<T>;
|
|
216
|
+
/**
|
|
217
|
+
* Makes type into a branded type, ensuring that value is assignable to
|
|
218
|
+
* the base ubranded type. Optionally you can explicitly supply current value
|
|
219
|
+
* type to combine both (useful for composite branded types. Make sure you
|
|
220
|
+
* compose branded types which are not composite themselves.)
|
|
221
|
+
*/
|
|
222
|
+
export declare const toBrandedType: <BrandedType, CurrentType = BrandedType>(value: Unbrand<BrandedType>) => CurrentType & BrandedType;
|
|
223
|
+
export declare const promiseTry: <TValue, TArgs extends unknown[]>(fn: (...args: TArgs) => TValue | PromiseLike<TValue>, ...args: TArgs) => Promise<TValue>;
|
|
224
|
+
export {};
|
package/dist/excalidraw/utils.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { COLOR_PALETTE } from "./colors";
|
|
2
2
|
import { DEFAULT_VERSION, FONT_FAMILY, isDarwin, WINDOWS_EMOJI_FALLBACK_FONT, } from "./constants";
|
|
3
|
-
import { unstable_batchedUpdates } from "react-dom";
|
|
4
|
-
import React from "react";
|
|
5
3
|
let mockDateTime = null;
|
|
6
4
|
export const setDateTimeForTests = (dateTime) => {
|
|
7
5
|
mockDateTime = dateTime;
|
|
@@ -354,22 +352,6 @@ export const resolvablePromise = () => {
|
|
|
354
352
|
promise.reject = reject;
|
|
355
353
|
return promise;
|
|
356
354
|
};
|
|
357
|
-
/**
|
|
358
|
-
* @param func handler taking at most single parameter (event).
|
|
359
|
-
*/
|
|
360
|
-
export const withBatchedUpdates = (func) => ((event) => {
|
|
361
|
-
unstable_batchedUpdates(func, event);
|
|
362
|
-
});
|
|
363
|
-
/**
|
|
364
|
-
* barches React state updates and throttles the calls to a single call per
|
|
365
|
-
* animation frame
|
|
366
|
-
*/
|
|
367
|
-
export const withBatchedUpdatesThrottled = (func) => {
|
|
368
|
-
// @ts-ignore
|
|
369
|
-
return throttleRAF(((event) => {
|
|
370
|
-
unstable_batchedUpdates(func, event);
|
|
371
|
-
}));
|
|
372
|
-
};
|
|
373
355
|
//https://stackoverflow.com/a/9462382/8418
|
|
374
356
|
export const nFormatter = (num, digits) => {
|
|
375
357
|
const si = [
|
|
@@ -451,6 +433,9 @@ export const getUpdatedTimestamp = () => (isTestEnv() ? 1 : Date.now());
|
|
|
451
433
|
* or array of ids (strings), into a Map, keyd by `id`.
|
|
452
434
|
*/
|
|
453
435
|
export const arrayToMap = (items) => {
|
|
436
|
+
if (items instanceof Map) {
|
|
437
|
+
return items;
|
|
438
|
+
}
|
|
454
439
|
return items.reduce((acc, element) => {
|
|
455
440
|
acc.set(typeof element === "string" ? element : element.id, element);
|
|
456
441
|
return acc;
|
|
@@ -568,7 +553,7 @@ export const composeEventHandlers = (originalEventHandler, ourEventHandler, { ch
|
|
|
568
553
|
return function handleEvent(event) {
|
|
569
554
|
originalEventHandler?.(event);
|
|
570
555
|
if (!checkForDefaultPrevented ||
|
|
571
|
-
!event
|
|
556
|
+
!event?.defaultPrevented) {
|
|
572
557
|
return ourEventHandler?.(event);
|
|
573
558
|
}
|
|
574
559
|
};
|
|
@@ -618,32 +603,6 @@ export const memoize = (func) => {
|
|
|
618
603
|
};
|
|
619
604
|
return ret;
|
|
620
605
|
};
|
|
621
|
-
export const isRenderThrottlingEnabled = (() => {
|
|
622
|
-
// we don't want to throttle in react < 18 because of #5439 and it was
|
|
623
|
-
// getting more complex to maintain the fix
|
|
624
|
-
let IS_REACT_18_AND_UP;
|
|
625
|
-
try {
|
|
626
|
-
const version = React.version.split(".");
|
|
627
|
-
IS_REACT_18_AND_UP = Number(version[0]) > 17;
|
|
628
|
-
}
|
|
629
|
-
catch {
|
|
630
|
-
IS_REACT_18_AND_UP = false;
|
|
631
|
-
}
|
|
632
|
-
let hasWarned = false;
|
|
633
|
-
return () => {
|
|
634
|
-
if (window.EXCALIDRAW_THROTTLE_RENDER === true) {
|
|
635
|
-
if (!IS_REACT_18_AND_UP) {
|
|
636
|
-
if (!hasWarned) {
|
|
637
|
-
hasWarned = true;
|
|
638
|
-
console.warn("Excalidraw: render throttling is disabled on React versions < 18.");
|
|
639
|
-
}
|
|
640
|
-
return false;
|
|
641
|
-
}
|
|
642
|
-
return true;
|
|
643
|
-
}
|
|
644
|
-
return false;
|
|
645
|
-
};
|
|
646
|
-
})();
|
|
647
606
|
/** Checks if value is inside given collection. Useful for type-safety. */
|
|
648
607
|
export const isMemberOf = (
|
|
649
608
|
/** Set/Map/Array/Object */
|
|
@@ -681,3 +640,42 @@ target, type, listener, options) {
|
|
|
681
640
|
target?.removeEventListener?.(type, listener, options);
|
|
682
641
|
};
|
|
683
642
|
}
|
|
643
|
+
const average = (a, b) => (a + b) / 2;
|
|
644
|
+
export function getSvgPathFromStroke(points, closed = true) {
|
|
645
|
+
const len = points.length;
|
|
646
|
+
if (len < 4) {
|
|
647
|
+
return ``;
|
|
648
|
+
}
|
|
649
|
+
let a = points[0];
|
|
650
|
+
let b = points[1];
|
|
651
|
+
const c = points[2];
|
|
652
|
+
let result = `M${a[0].toFixed(2)},${a[1].toFixed(2)} Q${b[0].toFixed(2)},${b[1].toFixed(2)} ${average(b[0], c[0]).toFixed(2)},${average(b[1], c[1]).toFixed(2)} T`;
|
|
653
|
+
for (let i = 2, max = len - 1; i < max; i++) {
|
|
654
|
+
a = points[i];
|
|
655
|
+
b = points[i + 1];
|
|
656
|
+
result += `${average(a[0], b[0]).toFixed(2)},${average(a[1], b[1]).toFixed(2)} `;
|
|
657
|
+
}
|
|
658
|
+
if (closed) {
|
|
659
|
+
result += "Z";
|
|
660
|
+
}
|
|
661
|
+
return result;
|
|
662
|
+
}
|
|
663
|
+
export const normalizeEOL = (str) => {
|
|
664
|
+
return str.replace(/\r?\n|\r/g, "\n");
|
|
665
|
+
};
|
|
666
|
+
/**
|
|
667
|
+
* Makes type into a branded type, ensuring that value is assignable to
|
|
668
|
+
* the base ubranded type. Optionally you can explicitly supply current value
|
|
669
|
+
* type to combine both (useful for composite branded types. Make sure you
|
|
670
|
+
* compose branded types which are not composite themselves.)
|
|
671
|
+
*/
|
|
672
|
+
export const toBrandedType = (value) => {
|
|
673
|
+
return value;
|
|
674
|
+
};
|
|
675
|
+
// -----------------------------------------------------------------------------
|
|
676
|
+
// Promise.try, adapted from https://github.com/sindresorhus/p-try
|
|
677
|
+
export const promiseTry = async (fn, ...args) => {
|
|
678
|
+
return new Promise((resolve) => {
|
|
679
|
+
resolve(fn(...args));
|
|
680
|
+
});
|
|
681
|
+
};
|
|
@@ -138,7 +138,9 @@
|
|
|
138
138
|
"removeAllElementsFromFrame": "Remove all elements from frame",
|
|
139
139
|
"eyeDropper": "Pick color from canvas",
|
|
140
140
|
"textToDiagram": "Text to diagram",
|
|
141
|
-
"prompt": "Prompt"
|
|
141
|
+
"prompt": "Prompt",
|
|
142
|
+
"followUs": "Follow us",
|
|
143
|
+
"discordChat": "Discord chat"
|
|
142
144
|
},
|
|
143
145
|
"library": {
|
|
144
146
|
"noItems": "No items added yet...",
|
|
@@ -212,9 +214,9 @@
|
|
|
212
214
|
"fileTooBig": "File is too big. Maximum allowed size is {{maxSize}}.",
|
|
213
215
|
"svgImageInsertError": "Couldn't insert SVG image. The SVG markup looks invalid.",
|
|
214
216
|
"failedToFetchImage": "Failed to fetch image.",
|
|
215
|
-
"invalidSVGString": "Invalid SVG.",
|
|
216
217
|
"cannotResolveCollabServer": "Couldn't connect to the collab server. Please reload the page and try again.",
|
|
217
218
|
"importLibraryError": "Couldn't load library",
|
|
219
|
+
"saveLibraryError": "Couldn't save library to storage. Please save your library to a file locally to make sure you don't lose changes.",
|
|
218
220
|
"collabSaveFailed": "Couldn't save to the backend database. If problems persist, you should save your file locally to ensure you don't lose your work.",
|
|
219
221
|
"collabSaveFailed_sizeExceeded": "Couldn't save to the backend database, the canvas seems to be too big. You should save the file locally to ensure you don't lose your work.",
|
|
220
222
|
"imageToolNotSupported": "Images are disabled.",
|
|
@@ -246,7 +248,7 @@
|
|
|
246
248
|
"library": "Library",
|
|
247
249
|
"lock": "Keep selected tool active after drawing",
|
|
248
250
|
"penMode": "Pen mode - prevent touch",
|
|
249
|
-
"link": "Add/ Update link for a selected shape",
|
|
251
|
+
"link": "Add / Update link for a selected shape",
|
|
250
252
|
"eraser": "Eraser",
|
|
251
253
|
"frame": "Frame tool",
|
|
252
254
|
"magicframe": "Wireframe to code",
|
|
@@ -299,9 +301,12 @@
|
|
|
299
301
|
"openIssueMessage": "We were very cautious not to include your scene information on the error. If your scene is not private, please consider following up on our <button>bug tracker</button>. Please include information below by copying and pasting into the GitHub issue.",
|
|
300
302
|
"sceneContent": "Scene content:"
|
|
301
303
|
},
|
|
304
|
+
"shareDialog": {
|
|
305
|
+
"or": "Or"
|
|
306
|
+
},
|
|
302
307
|
"roomDialog": {
|
|
303
|
-
"desc_intro": "
|
|
304
|
-
"desc_privacy": "Don't worry, the session
|
|
308
|
+
"desc_intro": "Invite people to collaborate on your drawing.",
|
|
309
|
+
"desc_privacy": "Don't worry, the session is end-to-end encrypted, and fully private. Not even our server can see what you draw.",
|
|
305
310
|
"button_startSession": "Start session",
|
|
306
311
|
"button_stopSession": "Stop session",
|
|
307
312
|
"desc_inProgressIntro": "Live-collaboration session is now in progress.",
|