@excalidraw/excalidraw 0.15.2-b7350f9 → 0.15.2-fc9a9a2

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 (99) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/dist/excalidraw-assets/locales/{es-ES-json-f2467c6a875a9e288756.js → es-ES-json-4f3da97feff33cb00e6d.js} +1 -1
  3. package/dist/excalidraw-assets/locales/{hi-IN-json-e22f4ad73126c2971850.js → hi-IN-json-3898c9c1216b44476529.js} +1 -1
  4. package/dist/excalidraw-assets/locales/{id-ID-json-0e69caf5d919807ed234.js → id-ID-json-43d505d7071a0e359681.js} +1 -1
  5. package/dist/excalidraw-assets/locales/{kk-KZ-json-106d2a41c68f69765668.js → kk-KZ-json-f648362328b839e9313f.js} +1 -1
  6. package/dist/excalidraw-assets/locales/{pa-IN-json-0fd029451b07248c5194.js → pa-IN-json-d9ee09801ed220840b2b.js} +1 -1
  7. package/dist/excalidraw-assets/{vendor-53d1c69ef585b6dd219b.js → vendor-ef3c5d81a00ef582b871.js} +2 -2
  8. package/dist/excalidraw-assets-dev/{vendor-e6df8519da951026ff69.js → vendor-a14cd58fa2db417e42b2.js} +6 -6
  9. package/dist/excalidraw.development.js +2189 -2123
  10. package/dist/excalidraw.production.min.js +1 -1
  11. package/dist/excalidraw.production.min.js.LICENSE.txt +15 -0
  12. package/package.json +7 -2
  13. package/types/actions/actionAddToLibrary.d.ts +51 -25
  14. package/types/actions/actionAlign.d.ts +19 -20
  15. package/types/actions/actionBoundText.d.ts +38 -20
  16. package/types/actions/actionCanvas.d.ts +310 -88
  17. package/types/actions/actionClipboard.d.ts +81 -40
  18. package/types/actions/actionDeleteSelected.d.ts +45 -22
  19. package/types/actions/actionDistribute.d.ts +5 -6
  20. package/types/actions/actionDuplicateSelection.d.ts +0 -1
  21. package/types/actions/actionElementLock.d.ts +36 -19
  22. package/types/actions/actionExport.d.ts +161 -80
  23. package/types/actions/actionFinalize.d.ts +31 -17
  24. package/types/actions/actionFlip.d.ts +2 -3
  25. package/types/actions/actionFrame.d.ts +56 -30
  26. package/types/actions/actionGroup.d.ts +5 -6
  27. package/types/actions/actionLinearEditor.d.ts +19 -11
  28. package/types/actions/actionMenu.d.ts +51 -25
  29. package/types/actions/actionProperties.d.ts +221 -105
  30. package/types/actions/actionSelectAll.d.ts +0 -1
  31. package/types/actions/actionStyles.d.ts +17 -9
  32. package/types/actions/actionToggleGridMode.d.ts +17 -9
  33. package/types/actions/actionToggleStats.d.ts +17 -9
  34. package/types/actions/actionToggleViewMode.d.ts +17 -9
  35. package/types/actions/actionToggleZenMode.d.ts +17 -9
  36. package/types/actions/types.d.ts +4 -3
  37. package/types/appState.d.ts +7 -7
  38. package/types/colors.d.ts +9 -9
  39. package/types/components/App.d.ts +27 -1
  40. package/types/components/Button.d.ts +0 -1
  41. package/types/components/Card.d.ts +0 -1
  42. package/types/components/ColorPicker/keyboardNavHandlers.d.ts +0 -1
  43. package/types/components/DefaultSidebar.d.ts +0 -1
  44. package/types/components/EyeDropper.d.ts +0 -1
  45. package/types/components/HintViewer.d.ts +3 -4
  46. package/types/components/LayerUI.d.ts +2 -1
  47. package/types/components/LibraryMenuHeaderContent.d.ts +0 -1
  48. package/types/components/LibraryUnit.d.ts +0 -1
  49. package/types/components/LoadingMessage.d.ts +0 -1
  50. package/types/components/MobileMenu.d.ts +3 -2
  51. package/types/components/Section.d.ts +1 -1
  52. package/types/components/Sidebar/SidebarTab.d.ts +0 -1
  53. package/types/components/Sidebar/SidebarTabTrigger.d.ts +0 -1
  54. package/types/components/Sidebar/SidebarTabTriggers.d.ts +0 -1
  55. package/types/components/Sidebar/SidebarTabs.d.ts +0 -1
  56. package/types/components/Stack.d.ts +2 -2
  57. package/types/components/Trans.d.ts +2 -1
  58. package/types/components/dropdownMenu/DropdownMenuTrigger.d.ts +0 -1
  59. package/types/components/icons.d.ts +1 -0
  60. package/types/components/live-collaboration/LiveCollaborationTrigger.d.ts +0 -1
  61. package/types/components/welcome-screen/WelcomeScreen.Center.d.ts +0 -1
  62. package/types/components/welcome-screen/WelcomeScreen.d.ts +0 -1
  63. package/types/constants.d.ts +13 -3
  64. package/types/data/url.d.ts +7 -0
  65. package/types/element/Hyperlink.d.ts +26 -14
  66. package/types/element/collision.d.ts +2 -2
  67. package/types/element/embeddable.d.ts +153 -0
  68. package/types/element/linearElementEditor.d.ts +18 -10
  69. package/types/element/newElement.d.ts +5 -2
  70. package/types/element/transformHandles.d.ts +1 -1
  71. package/types/element/typeChecks.d.ts +2 -1
  72. package/types/element/types.d.ts +13 -2
  73. package/types/frame.d.ts +2 -2
  74. package/types/groups.d.ts +3 -3
  75. package/types/history.d.ts +3 -3
  76. package/types/hooks/useOutsideClick.d.ts +0 -1
  77. package/types/hooks/useScrollPosition.d.ts +0 -1
  78. package/types/i18n.d.ts +5 -2
  79. package/types/keys.d.ts +2 -0
  80. package/types/packages/excalidraw/index.d.ts +1 -0
  81. package/types/packages/excalidraw/webpack.dev.config.d.ts +5 -2
  82. package/types/packages/excalidraw/webpack.prod.config.d.ts +3 -0
  83. package/types/packages/utils.d.ts +2 -1
  84. package/types/renderer/renderElement.d.ts +1 -1
  85. package/types/renderer/renderScene.d.ts +2 -1
  86. package/types/scene/Scene.d.ts +13 -0
  87. package/types/scene/export.d.ts +1 -0
  88. package/types/scene/selection.d.ts +11 -1
  89. package/types/types.d.ts +20 -9
  90. package/types/utility-types.d.ts +3 -1
  91. package/types/utils.d.ts +42 -15
  92. /package/dist/excalidraw-assets/{vendor-53d1c69ef585b6dd219b.js.LICENSE.txt → vendor-ef3c5d81a00ef582b871.js.LICENSE.txt} +0 -0
  93. /package/types/packages/excalidraw/dist/excalidraw-assets/locales/{es-ES-json-f2467c6a875a9e288756.d.ts → es-ES-json-4f3da97feff33cb00e6d.d.ts} +0 -0
  94. /package/types/packages/excalidraw/dist/excalidraw-assets/locales/{hi-IN-json-e22f4ad73126c2971850.d.ts → hi-IN-json-3898c9c1216b44476529.d.ts} +0 -0
  95. /package/types/packages/excalidraw/dist/excalidraw-assets/locales/{id-ID-json-0e69caf5d919807ed234.d.ts → id-ID-json-43d505d7071a0e359681.d.ts} +0 -0
  96. /package/types/packages/excalidraw/dist/excalidraw-assets/locales/{kk-KZ-json-106d2a41c68f69765668.d.ts → kk-KZ-json-f648362328b839e9313f.d.ts} +0 -0
  97. /package/types/packages/excalidraw/dist/excalidraw-assets/locales/{pa-IN-json-0fd029451b07248c5194.d.ts → pa-IN-json-d9ee09801ed220840b2b.d.ts} +0 -0
  98. /package/types/packages/excalidraw/dist/excalidraw-assets/{vendor-53d1c69ef585b6dd219b.d.ts → vendor-ef3c5d81a00ef582b871.d.ts} +0 -0
  99. /package/types/packages/excalidraw/dist/excalidraw-assets-dev/{vendor-e6df8519da951026ff69.d.ts → vendor-a14cd58fa2db417e42b2.d.ts} +0 -0
package/types/i18n.d.ts CHANGED
@@ -1,8 +1,11 @@
1
+ import fallbackLangData from "./locales/en.json";
2
+ import { NestedKeyOf } from "./utility-types";
1
3
  export interface Language {
2
4
  code: string;
3
5
  label: string;
4
6
  rtl?: boolean;
5
7
  }
8
+ export type TranslationKeys = NestedKeyOf<typeof fallbackLangData>;
6
9
  export declare const defaultLang: {
7
10
  code: string;
8
11
  label: string;
@@ -10,11 +13,11 @@ export declare const defaultLang: {
10
13
  export declare const languages: Language[];
11
14
  export declare const setLanguage: (lang: Language) => Promise<void>;
12
15
  export declare const getLanguage: () => Language;
13
- export declare const t: (path: string, replacement?: {
16
+ export declare const t: (path: NestedKeyOf<typeof fallbackLangData>, replacement?: {
14
17
  [key: string]: string | number;
15
18
  } | null | undefined, fallback?: string) => string;
16
19
  export declare const useI18n: () => {
17
- t: (path: string, replacement?: {
20
+ t: (path: NestedKeyOf<typeof fallbackLangData>, replacement?: {
18
21
  [key: string]: string | number;
19
22
  } | null | undefined, fallback?: string) => string;
20
23
  langCode: string;
package/types/keys.d.ts CHANGED
@@ -8,6 +8,7 @@ export declare const CODES: {
8
8
  readonly BRACKET_LEFT: "BracketLeft";
9
9
  readonly ONE: "Digit1";
10
10
  readonly TWO: "Digit2";
11
+ readonly THREE: "Digit3";
11
12
  readonly NINE: "Digit9";
12
13
  readonly QUOTE: "Quote";
13
14
  readonly ZERO: "Digit0";
@@ -60,6 +61,7 @@ export declare const KEYS: {
60
61
  readonly Y: "y";
61
62
  readonly Z: "z";
62
63
  readonly K: "k";
64
+ readonly W: "w";
63
65
  readonly 0: "0";
64
66
  readonly 1: "1";
65
67
  readonly 2: "2";
@@ -25,3 +25,4 @@ export { useDevice } from "../../components/App";
25
25
  export { WelcomeScreen };
26
26
  export { LiveCollaborationTrigger };
27
27
  export { DefaultSidebar } from "../../components/DefaultSidebar";
28
+ export { normalizeLink } from "../../data/url";
@@ -36,13 +36,16 @@ export namespace module {
36
36
  } | {
37
37
  test: RegExp;
38
38
  exclude: RegExp;
39
- use: {
39
+ use: ({
40
+ loader: string;
41
+ options?: undefined;
42
+ } | {
40
43
  loader: string;
41
44
  options: {
42
45
  transpileOnly: boolean;
43
46
  configFile: string;
44
47
  };
45
- }[];
48
+ })[];
46
49
  type?: undefined;
47
50
  } | {
48
51
  test: RegExp;
@@ -36,6 +36,9 @@ export namespace module {
36
36
  test: RegExp;
37
37
  exclude: RegExp;
38
38
  use: ({
39
+ loader: string;
40
+ options?: undefined;
41
+ } | {
39
42
  loader: string;
40
43
  options: {
41
44
  transpileOnly: boolean;
@@ -21,8 +21,9 @@ export declare const exportToBlob: (opts: ExportOpts & {
21
21
  quality?: number;
22
22
  exportPadding?: number;
23
23
  }) => Promise<Blob>;
24
- export declare const exportToSvg: ({ elements, appState, files, exportPadding, }: Omit<ExportOpts, "getDimensions"> & {
24
+ export declare const exportToSvg: ({ elements, appState, files, exportPadding, renderEmbeddables, }: Omit<ExportOpts, "getDimensions"> & {
25
25
  exportPadding?: number | undefined;
26
+ renderEmbeddables?: boolean | undefined;
26
27
  }) => Promise<SVGSVGElement>;
27
28
  export declare const exportToClipboard: (opts: ExportOpts & {
28
29
  mimeType?: string;
@@ -29,7 +29,7 @@ export declare const setShapeForElement: <T extends ExcalidrawElement>(element:
29
29
  export declare const invalidateShapeForElement: (element: ExcalidrawElement) => boolean;
30
30
  export declare const generateRoughOptions: (element: ExcalidrawElement, continuousPath?: boolean) => Options;
31
31
  export declare const renderElement: (element: NonDeletedExcalidrawElement, rc: RoughCanvas, context: CanvasRenderingContext2D, renderConfig: RenderConfig, appState: AppState) => void;
32
- export declare const renderElementToSvg: (element: NonDeletedExcalidrawElement, rsvg: RoughSVG, svgRoot: SVGElement, files: BinaryFiles, offsetX: number, offsetY: number, exportWithDarkMode?: boolean, exportingFrameId?: string | null) => void;
32
+ export declare const renderElementToSvg: (element: NonDeletedExcalidrawElement, rsvg: RoughSVG, svgRoot: SVGElement, files: BinaryFiles, offsetX: number, offsetY: number, exportWithDarkMode?: boolean, exportingFrameId?: string | null, renderEmbeddables?: boolean) => void;
33
33
  export declare const pathsCache: WeakMap<ExcalidrawFreeDrawElement, Path2D>;
34
34
  export declare function generateFreeDrawShape(element: ExcalidrawFreeDrawElement): Path2D;
35
35
  export declare function getFreeDrawPath2D(element: ExcalidrawFreeDrawElement): Path2D | undefined;
@@ -42,9 +42,10 @@ export declare const isVisibleElement: (element: ExcalidrawElement, canvasWidth:
42
42
  scrollX: number;
43
43
  scrollY: number;
44
44
  }) => boolean;
45
- export declare const renderSceneToSvg: (elements: readonly NonDeletedExcalidrawElement[], rsvg: RoughSVG, svgRoot: SVGElement, files: BinaryFiles, { offsetX, offsetY, exportWithDarkMode, exportingFrameId, }?: {
45
+ export declare const renderSceneToSvg: (elements: readonly NonDeletedExcalidrawElement[], rsvg: RoughSVG, svgRoot: SVGElement, files: BinaryFiles, { offsetX, offsetY, exportWithDarkMode, exportingFrameId, renderEmbeddables, }?: {
46
46
  offsetX?: number | undefined;
47
47
  offsetY?: number | undefined;
48
48
  exportWithDarkMode?: boolean | undefined;
49
49
  exportingFrameId?: string | null | undefined;
50
+ renderEmbeddables?: boolean | undefined;
50
51
  }) => void;
@@ -1,5 +1,6 @@
1
1
  import { ExcalidrawElement, NonDeletedExcalidrawElement, NonDeleted, ExcalidrawFrameElement } from "../element/types";
2
2
  import { LinearElementEditor } from "../element/linearElementEditor";
3
+ import { AppState } from "../types";
3
4
  type ElementIdKey = InstanceType<typeof LinearElementEditor>["elementId"];
4
5
  type ElementKey = ExcalidrawElement | ElementIdKey;
5
6
  type SceneStateCallback = () => void;
@@ -16,9 +17,21 @@ declare class Scene {
16
17
  private nonDeletedFrames;
17
18
  private frames;
18
19
  private elementsMap;
20
+ private selectedElementsCache;
19
21
  getElementsIncludingDeleted(): readonly ExcalidrawElement[];
20
22
  getNonDeletedElements(): readonly NonDeletedExcalidrawElement[];
21
23
  getFramesIncludingDeleted(): readonly ExcalidrawFrameElement[];
24
+ getSelectedElements(opts: {
25
+ selectedElementIds: AppState["selectedElementIds"];
26
+ /**
27
+ * for specific cases where you need to use elements not from current
28
+ * scene state. This in effect will likely result in cache-miss, and
29
+ * the cache won't be updated in this case.
30
+ */
31
+ elements?: readonly ExcalidrawElement[];
32
+ includeBoundTextElement?: boolean;
33
+ includeElementsInFrames?: boolean;
34
+ }): NonDeleted<ExcalidrawElement>[];
22
35
  getNonDeletedFrames(): readonly NonDeleted<ExcalidrawFrameElement>[];
23
36
  getElement<T extends ExcalidrawElement>(id: T["id"]): T | null;
24
37
  getNonDeletedElement(id: ExcalidrawElement["id"]): NonDeleted<ExcalidrawElement> | null;
@@ -20,5 +20,6 @@ export declare const exportToSvg: (elements: readonly NonDeletedExcalidrawElemen
20
20
  renderFrame?: boolean;
21
21
  }, files: BinaryFiles | null, opts?: {
22
22
  serializeAsJSON?: () => string;
23
+ renderEmbeddables?: boolean;
23
24
  }) => Promise<SVGSVGElement>;
24
25
  export declare const getExportSize: (elements: readonly NonDeletedExcalidrawElement[], exportPadding: number, scale: number) => [number, number];
@@ -8,7 +8,10 @@ import { AppState } from "../types";
8
8
  */
9
9
  export declare const excludeElementsInFramesFromSelection: <T extends ExcalidrawElement>(selectedElements: readonly T[]) => T[];
10
10
  export declare const getElementsWithinSelection: (elements: readonly NonDeletedExcalidrawElement[], selection: NonDeletedExcalidrawElement, excludeElementsInFrames?: boolean) => NonDeletedExcalidrawElement[];
11
- export declare const isSomeElementSelected: (elements: readonly NonDeletedExcalidrawElement[], appState: Pick<AppState, "selectedElementIds">) => boolean;
11
+ export declare const isSomeElementSelected: {
12
+ (elements: readonly NonDeletedExcalidrawElement[], appState: Pick<AppState, "selectedElementIds">): boolean;
13
+ clearCache(): void;
14
+ };
12
15
  /**
13
16
  * Returns common attribute (picked by `getAttribute` callback) of selected
14
17
  * elements. If elements don't share the same value, returns `null`.
@@ -19,3 +22,10 @@ export declare const getSelectedElements: (elements: readonly NonDeletedExcalidr
19
22
  includeElementsInFrames?: boolean;
20
23
  }) => ExcalidrawElement[];
21
24
  export declare const getTargetElements: (elements: readonly NonDeletedExcalidrawElement[], appState: Pick<AppState, "selectedElementIds" | "editingElement">) => ExcalidrawElement[];
25
+ /**
26
+ * returns prevState's selectedElementids if no change from previous, so as to
27
+ * retain reference identity for memoization
28
+ */
29
+ export declare const makeNextSelectedElementIds: (nextSelectedElementIds: AppState["selectedElementIds"], prevState: Pick<AppState, "selectedElementIds">) => Readonly<{
30
+ [id: string]: true;
31
+ }>;
package/types/types.d.ts CHANGED
@@ -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, ExcalidrawFrameElement } from "./element/types";
2
+ import { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, ExcalidrawImageElement, Theme, StrokeRoundness, ExcalidrawFrameElement, ExcalidrawEmbeddableElement } from "./element/types";
3
3
  import { SHAPES } from "./shapes";
4
4
  import { Point as RoughPoint } from "roughjs/bin/geometry";
5
5
  import { LinearElementEditor } from "./element/linearElementEditor";
@@ -57,7 +57,7 @@ export type BinaryFileData = {
57
57
  export type BinaryFileMetadata = Omit<BinaryFileData, "dataURL">;
58
58
  export type BinaryFiles = Record<ExcalidrawElement["id"], BinaryFileData>;
59
59
  export type LastActiveTool = {
60
- type: typeof SHAPES[number]["value"] | "eraser" | "hand" | "frame";
60
+ type: typeof SHAPES[number]["value"] | "eraser" | "hand" | "frame" | "embeddable";
61
61
  customType: null;
62
62
  } | {
63
63
  type: "custom";
@@ -74,6 +74,10 @@ export type AppState = {
74
74
  showWelcomeScreen: boolean;
75
75
  isLoading: boolean;
76
76
  errorMessage: React.ReactNode;
77
+ activeEmbeddable: {
78
+ element: NonDeletedExcalidrawElement;
79
+ state: "hover" | "active";
80
+ } | null;
77
81
  draggingElement: NonDeletedExcalidrawElement | null;
78
82
  resizingElement: NonDeletedExcalidrawElement | null;
79
83
  multiElement: NonDeleted<ExcalidrawLinearElement> | null;
@@ -82,7 +86,12 @@ export type AppState = {
82
86
  startBoundElement: NonDeleted<ExcalidrawBindableElement> | null;
83
87
  suggestedBindings: SuggestedBinding[];
84
88
  frameToHighlight: NonDeleted<ExcalidrawFrameElement> | null;
85
- shouldRenderFrames: boolean;
89
+ frameRendering: {
90
+ enabled: boolean;
91
+ name: boolean;
92
+ outline: boolean;
93
+ clip: boolean;
94
+ };
86
95
  editingFrame: string | null;
87
96
  elementsToHighlight: NonDeleted<ExcalidrawElement>[] | null;
88
97
  editingElement: NonDeletedExcalidrawElement | null;
@@ -95,7 +104,7 @@ export type AppState = {
95
104
  lastActiveTool: LastActiveTool;
96
105
  locked: boolean;
97
106
  } & ({
98
- type: typeof SHAPES[number]["value"] | "eraser" | "hand" | "frame";
107
+ type: typeof SHAPES[number]["value"] | "eraser" | "hand" | "frame" | "embeddable";
99
108
  customType: null;
100
109
  } | {
101
110
  type: "custom";
@@ -145,11 +154,11 @@ export type AppState = {
145
154
  */
146
155
  defaultSidebarDockedPreference: boolean;
147
156
  lastPointerDownWith: PointerType;
148
- selectedElementIds: {
149
- [id: string]: boolean;
150
- };
157
+ selectedElementIds: Readonly<{
158
+ [id: string]: true;
159
+ }>;
151
160
  previousSelectedElementIds: {
152
- [id: string]: boolean;
161
+ [id: string]: true;
153
162
  };
154
163
  selectedElementsAreBeingDragged: boolean;
155
164
  shouldCacheIgnoreZoom: boolean;
@@ -272,6 +281,8 @@ export interface ExcalidrawProps {
272
281
  onPointerDown?: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState) => void;
273
282
  onScrollChange?: (scrollX: number, scrollY: number) => void;
274
283
  children?: React.ReactNode;
284
+ validateEmbeddable?: boolean | string[] | RegExp | RegExp[] | ((link: string) => boolean | undefined);
285
+ renderEmbeddable?: (element: NonDeleted<ExcalidrawEmbeddableElement>, appState: AppState) => JSX.Element | null;
275
286
  }
276
287
  export type SceneData = {
277
288
  elements?: ImportedDataState["elements"];
@@ -421,7 +432,7 @@ export type ExcalidrawImperativeAPI = {
421
432
  * the frames are still interactive in edit mode. As such, this API should be
422
433
  * used in conjunction with view mode (props.viewModeEnabled).
423
434
  */
424
- toggleFrameRendering: InstanceType<typeof App>["toggleFrameRendering"];
435
+ updateFrameRendering: InstanceType<typeof App>["updateFrameRendering"];
425
436
  };
426
437
  export type Device = Readonly<{
427
438
  isSmScreen: boolean;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export type Mutable<T> = {
3
2
  -readonly [P in keyof T]: T[P];
4
3
  };
@@ -20,3 +19,6 @@ export type SignatureType<T> = T extends (...args: infer R) => any ? R : never;
20
19
  export type CallableType<T extends (...args: any[]) => any> = (...args: SignatureType<T>) => ReturnType<T>;
21
20
  export type ForwardRef<T, P = any> = Parameters<CallableType<React.ForwardRefRenderFunction<T, P>>>[1];
22
21
  export type ExtractSetType<T extends Set<any>> = T extends Set<infer U> ? U : never;
22
+ export type SameType<T, U> = T extends U ? (U extends T ? true : false) : false;
23
+ export type Assert<T extends true> = T;
24
+ export type NestedKeyOf<T, K = keyof T> = K extends keyof T & (string | number) ? `${K}` | (T[K] extends object ? `${K}.${NestedKeyOf<T[K]>}` : never) : never;
package/types/utils.d.ts CHANGED
@@ -30,31 +30,58 @@ export declare const throttleRAF: <T extends any[]>(fn: (...args: T) => void, op
30
30
  cancel(): void;
31
31
  };
32
32
  /**
33
- * Compute new values based on the same ease function and trigger the
34
- * callback through a requestAnimationFrame call
33
+ * Exponential ease-out method
35
34
  *
36
- * use `opts` to define a duration and/or an easeFn
35
+ * @param {number} k - The value to be tweened.
36
+ * @returns {number} The tweened value.
37
+ */
38
+ export declare const easeOut: (k: number) => number;
39
+ /**
40
+ * Animates values from `fromValues` to `toValues` using the requestAnimationFrame API.
41
+ * Executes the `onStep` callback on each step with the interpolated values.
42
+ * Returns a function that can be called to cancel the animation.
43
+ *
44
+ * @example
45
+ * // Example usage:
46
+ * const fromValues = { x: 0, y: 0 };
47
+ * const toValues = { x: 100, y: 200 };
48
+ * const onStep = ({x, y}) => {
49
+ * setState(x, y)
50
+ * };
51
+ * const onCancel = () => {
52
+ * console.log("Animation canceled");
53
+ * };
37
54
  *
38
- * for example:
39
- * ```ts
40
- * easeToValuesRAF([10, 20, 10], [0, 0, 0], (a, b, c) => setState(a,b, c))
41
- * ```
55
+ * const cancelAnimation = easeToValuesRAF({
56
+ * fromValues,
57
+ * toValues,
58
+ * onStep,
59
+ * onCancel,
60
+ * });
42
61
  *
43
- * @param fromValues The initial values, must be numeric
44
- * @param toValues The destination values, must also be numeric
45
- * @param callback The callback receiving the values
46
- * @param opts default to 250ms duration and the easeOut function
62
+ * // To cancel the animation:
63
+ * cancelAnimation();
47
64
  */
48
- export declare const easeToValuesRAF: (fromValues: number[], toValues: number[], callback: (...values: number[]) => void, opts?: {
65
+ export declare const easeToValuesRAF: <T extends Record<keyof T, number>, K extends keyof T>({ fromValues, toValues, onStep, duration, interpolateValue, onStart, onEnd, onCancel, }: {
66
+ fromValues: T;
67
+ toValues: T;
68
+ /**
69
+ * Interpolate a single value.
70
+ * Return undefined to be handled by the default interpolator.
71
+ */
72
+ interpolateValue?: ((fromValue: number, toValue: number, progress: number, key: K) => number | undefined) | undefined;
73
+ onStep: (values: T) => void;
49
74
  duration?: number | undefined;
50
- easeFn?: ((value: number) => number) | undefined;
51
- } | undefined) => () => void;
75
+ onStart?: (() => void) | undefined;
76
+ onEnd?: (() => void) | undefined;
77
+ onCancel?: (() => void) | undefined;
78
+ }) => () => void;
52
79
  export declare const chunk: <T extends unknown>(array: readonly T[], size: number) => T[][];
53
80
  export declare const selectNode: (node: Element) => void;
54
81
  export declare const removeSelection: () => void;
55
82
  export declare const distance: (x: number, y: number) => number;
56
83
  export declare const updateActiveTool: (appState: Pick<AppState, "activeTool">, data: ({
57
- type: (typeof SHAPES)[number]["value"] | "eraser" | "hand" | "frame";
84
+ type: (typeof SHAPES)[number]["value"] | "eraser" | "hand" | "frame" | "embeddable";
58
85
  } | {
59
86
  type: "custom";
60
87
  customType: string;