@excalidraw/common 0.18.0-abeeaeb → 0.18.0-afa3a65

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 (79) hide show
  1. package/dist/dev/index.js +91 -10
  2. package/dist/dev/index.js.map +2 -2
  3. package/dist/prod/index.js +3 -3
  4. package/dist/types/common/src/colors.d.ts +8 -0
  5. package/dist/types/common/src/constants.d.ts +44 -0
  6. package/dist/types/common/src/keys.d.ts +2 -0
  7. package/dist/types/common/src/random.d.ts +7 -0
  8. package/dist/types/element/src/Scene.d.ts +1 -1
  9. package/dist/types/element/src/comparisons.d.ts +5 -3
  10. package/dist/types/element/src/delta.d.ts +23 -1
  11. package/dist/types/element/src/flowchart.d.ts +5 -1
  12. package/dist/types/element/src/frame.d.ts +2 -2
  13. package/dist/types/element/src/index.d.ts +1 -0
  14. package/dist/types/element/src/linearElementEditor.d.ts +10 -0
  15. package/dist/types/element/src/mutateElement.d.ts +1 -1
  16. package/dist/types/element/src/newElement.d.ts +24 -2
  17. package/dist/types/element/src/sizeHelpers.d.ts +6 -0
  18. package/dist/types/element/src/stickyNote.d.ts +183 -0
  19. package/dist/types/element/src/textElement.d.ts +2 -1
  20. package/dist/types/element/src/transform.d.ts +25 -6
  21. package/dist/types/element/src/typeChecks.d.ts +3 -2
  22. package/dist/types/element/src/types.d.ts +35 -6
  23. package/dist/types/element/src/utils.d.ts +7 -3
  24. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +12 -0
  25. package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -6
  26. package/dist/types/excalidraw/actions/actionBoundText.d.ts +8 -0
  27. package/dist/types/excalidraw/actions/actionCanvas.d.ts +28 -0
  28. package/dist/types/excalidraw/actions/actionClipboard.d.ts +8 -0
  29. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +4 -0
  30. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +13 -1
  31. package/dist/types/excalidraw/actions/actionDeselect.d.ts +4 -0
  32. package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -2
  33. package/dist/types/excalidraw/actions/actionElementLink.d.ts +4 -0
  34. package/dist/types/excalidraw/actions/actionElementLock.d.ts +8 -0
  35. package/dist/types/excalidraw/actions/actionExport.d.ts +8 -0
  36. package/dist/types/excalidraw/actions/actionFinalize.d.ts +1 -0
  37. package/dist/types/excalidraw/actions/actionFrame.d.ts +63 -1
  38. package/dist/types/excalidraw/actions/actionGroup.d.ts +8 -0
  39. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +55 -1
  40. package/dist/types/excalidraw/actions/actionLink.d.ts +4 -0
  41. package/dist/types/excalidraw/actions/actionMenu.d.ts +4 -0
  42. package/dist/types/excalidraw/actions/actionProperties.d.ts +18 -6
  43. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +4 -0
  44. package/dist/types/excalidraw/actions/actionStyles.d.ts +5 -1
  45. package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +4 -0
  46. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +4 -0
  47. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +4 -0
  48. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +4 -0
  49. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +4 -0
  50. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +4 -0
  51. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +4 -0
  52. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +4 -0
  53. package/dist/types/excalidraw/actions/colorTargets.d.ts +39 -0
  54. package/dist/types/excalidraw/appState.d.ts +4 -0
  55. package/dist/types/excalidraw/components/App.arrowText.d.ts +40 -8
  56. package/dist/types/excalidraw/components/App.cursor.d.ts +8 -0
  57. package/dist/types/excalidraw/components/App.d.ts +92 -6
  58. package/dist/types/excalidraw/components/App.toolDrag.d.ts +63 -0
  59. package/dist/types/excalidraw/components/IconButton.d.ts +2 -0
  60. package/dist/types/excalidraw/components/Tools.d.ts +7 -2
  61. package/dist/types/excalidraw/components/canvases/NewElementCanvas.d.ts +2 -0
  62. package/dist/types/excalidraw/components/icons.d.ts +1 -0
  63. package/dist/types/excalidraw/components/shapeActionPredicates.d.ts +2 -2
  64. package/dist/types/excalidraw/data/blob.d.ts +8 -0
  65. package/dist/types/excalidraw/data/json.d.ts +4 -0
  66. package/dist/types/excalidraw/fonts/Fonts.d.ts +3 -2
  67. package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +5 -5
  68. package/dist/types/excalidraw/renderer/helpers.d.ts +25 -0
  69. package/dist/types/excalidraw/renderer/interactiveScene.d.ts +1 -1
  70. package/dist/types/excalidraw/scene/Renderer.d.ts +50 -1
  71. package/dist/types/excalidraw/scene/index.d.ts +1 -1
  72. package/dist/types/excalidraw/scene/types.d.ts +1 -0
  73. package/dist/types/excalidraw/types.d.ts +30 -2
  74. package/dist/types/excalidraw/viewport.d.ts +4 -0
  75. package/dist/types/math/src/curve.d.ts +19 -12
  76. package/dist/types/math/src/segment.d.ts +6 -0
  77. package/dist/types/utils/src/export.d.ts +1 -0
  78. package/dist/types/utils/src/shape.d.ts +2 -2
  79. package/package.json +1 -1
@@ -85,7 +85,7 @@ export type BinaryFileData = {
85
85
  };
86
86
  export type BinaryFileMetadata = Omit<BinaryFileData, "dataURL">;
87
87
  export type BinaryFiles = Record<ExcalidrawElement["id"], BinaryFileData>;
88
- export type ToolType = "selection" | "lasso" | "rectangle" | "diamond" | "ellipse" | "arrow" | "line" | "freedraw" | "text" | "image" | "eraser" | "hand" | "frame" | "magicframe" | "embeddable" | "laser" | "autoshape" | "bucketfill";
88
+ export type ToolType = "selection" | "lasso" | "rectangle" | "diamond" | "ellipse" | "arrow" | "line" | "freedraw" | "text" | "image" | "eraser" | "hand" | "frame" | "magicframe" | "stickynote" | "embeddable" | "laser" | "autoshape" | "bucketfill";
89
89
  export type ElementOrToolType = ExcalidrawElementType | ToolType | "custom";
90
90
  export type ActiveTool = {
91
91
  type: ToolType;
@@ -308,6 +308,8 @@ export interface AppState {
308
308
  exportWithDarkMode: boolean;
309
309
  exportScale: number;
310
310
  currentItemStrokeColor: string;
311
+ currentItemStickynoteStrokeColor: string;
312
+ currentItemStickynoteBackgroundColor: string;
311
313
  currentItemBackgroundColor: string;
312
314
  currentItemFillStyle: ExcalidrawElement["fillStyle"];
313
315
  currentItemStrokeWidthKey: StrokeWidthKey;
@@ -438,6 +440,9 @@ export interface AppState {
438
440
  * even though both drive `currentItemBackgroundColor` (its defaults and
439
441
  * use case differ — no transparent) */
440
442
  bucketFill: readonly string[] | null;
443
+ /** sticky notes are their own color domain (own defaults, own picks) */
444
+ stickyNoteStroke: readonly string[] | null;
445
+ stickyNoteBackground: readonly string[] | null;
441
446
  };
442
447
  }
443
448
  export type SearchMatch = {
@@ -632,6 +637,16 @@ export type UIConfig = {
632
637
  };
633
638
  export interface ExcalidrawProps {
634
639
  className?: string;
640
+ /**
641
+ * Document that owns Excalidraw's mounted DOM.
642
+ *
643
+ * Set only when it differs from the global `document`, such as when code
644
+ * executing in a parent window mounts Excalidraw into an iframe document.
645
+ * The value must remain stable for the editor's lifetime.
646
+ *
647
+ * @default document
648
+ */
649
+ ownerDocument?: Document;
635
650
  onChange?: (elements: readonly OrderedExcalidrawElement[], appState: AppState, files: BinaryFiles) => void;
636
651
  onThemeChange?: (theme: Theme | "system") => void;
637
652
  /**
@@ -821,7 +836,8 @@ export interface ExcalidrawProps {
821
836
  }) => MaybePromise<void> | AsyncGenerator<OnExportProgress, void>;
822
837
  }
823
838
  export type SceneData = {
824
- elements?: ImportedDataState["elements"];
839
+ /** Expects normalized elements; restore imported data before updating the scene. */
840
+ elements?: readonly ExcalidrawElement[] | null;
825
841
  appState?: ImportedDataState["appState"];
826
842
  collaborators?: Map<SocketId, Collaborator>;
827
843
  captureUpdate?: CaptureUpdateActionType;
@@ -881,6 +897,8 @@ export type AppProps = Merge<ExcalidrawProps, {
881
897
  export type AppClassProperties = {
882
898
  props: AppProps;
883
899
  state: AppState;
900
+ readonly ownerDocument: Document;
901
+ readonly ownerWindow: Window & typeof globalThis;
884
902
  api: App["api"];
885
903
  sessionExportThemeOverride: App["sessionExportThemeOverride"];
886
904
  interactiveCanvas: HTMLCanvasElement | null;
@@ -914,8 +932,11 @@ export type AppClassProperties = {
914
932
  dismissLinearEditor: App["dismissLinearEditor"];
915
933
  flowchart: App["flowchart"];
916
934
  drawShape: App["drawShape"];
935
+ arrowText: App["arrowText"];
917
936
  cursor: App["cursor"];
918
937
  bucketFill: App["bucketFill"];
938
+ toolDrag: App["toolDrag"];
939
+ activeResizeHandle: App["activeResizeHandle"];
919
940
  isToolLocked: App["isToolLocked"];
920
941
  getEffectiveGridSize: App["getEffectiveGridSize"];
921
942
  setPlugins: App["setPlugins"];
@@ -970,6 +991,7 @@ export type PointerDownState = Readonly<{
970
991
  wasAddedToSelection: boolean;
971
992
  hasBeenDuplicated: boolean;
972
993
  hasHitCommonBoundingBoxOfSelectedElements: boolean;
994
+ arrowLabel: boolean;
973
995
  };
974
996
  withCmdOrCtrl: boolean;
975
997
  drag: {
@@ -1077,6 +1099,12 @@ export type NullableGridSize = (AppState["gridSize"] & MakeBrand<"NullableGridSi
1077
1099
  export type GenerateDiagramToCode = (props: {
1078
1100
  frame: NonDeleted<ExcalidrawMagicFrameElement>;
1079
1101
  children: readonly NonDeletedExcalidrawElement[];
1102
+ /**
1103
+ * Optional streaming hook. Call with the accumulated response text as it
1104
+ * streams in so the editor can progressively render the partial HTML
1105
+ * inside the generated frame.
1106
+ */
1107
+ onPartial?: (html: string) => void;
1080
1108
  }) => MaybePromise<{
1081
1109
  html: string;
1082
1110
  }>;
@@ -142,6 +142,8 @@ export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fit, m
142
142
  exportWithDarkMode: boolean;
143
143
  exportScale: number;
144
144
  currentItemStrokeColor: string;
145
+ currentItemStickynoteStrokeColor: string;
146
+ currentItemStickynoteBackgroundColor: string;
145
147
  currentItemBackgroundColor: string;
146
148
  currentItemFillStyle: ExcalidrawElement["fillStyle"];
147
149
  currentItemStrokeWidthKey: import("@excalidraw/common").StrokeWidthKey;
@@ -248,6 +250,8 @@ export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fit, m
248
250
  elementStroke: readonly string[] | null;
249
251
  elementBackground: readonly string[] | null;
250
252
  bucketFill: readonly string[] | null;
253
+ stickyNoteStroke: readonly string[] | null;
254
+ stickyNoteBackground: readonly string[] | null;
251
255
  };
252
256
  };
253
257
  captureUpdate: "EVENTUALLY";
@@ -16,20 +16,25 @@ export declare function curveIntersectLineSegment<Point extends GlobalPoint | Lo
16
16
  tolerance?: number;
17
17
  iterLimit?: number;
18
18
  }): Point[];
19
+ /**
20
+ * Finds the parameter on the Bezier curve whose point is closest to another
21
+ * point
22
+ *
23
+ * @param c The curve to test
24
+ * @param p The point to measure from
25
+ * @param tolerance The width of the search window under which the bisection
26
+ * stops refining the parameter
27
+ */
28
+ export declare function curveClosestParameter<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, p: Point, tolerance?: number): number;
19
29
  /**
20
30
  * Finds the closest point on the Bezier curve from another point
21
31
  *
22
- * @param x
23
- * @param y
24
- * @param P0
25
- * @param P1
26
- * @param P2
27
- * @param P3
28
- * @param tolerance
29
- * @param maxLevel
30
- * @returns
32
+ * @param c The curve to test
33
+ * @param p The point to measure from
34
+ * @param tolerance The width of the search window under which the bisection
35
+ * stops refining the parameter
31
36
  */
32
- export declare function curveClosestPoint<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, p: Point, tolerance?: number): Point | null;
37
+ export declare function curveClosestPoint<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, p: Point, tolerance?: number): Point;
33
38
  /**
34
39
  * Determines the distance between a point and the closest point on the
35
40
  * Bezier curve.
@@ -37,7 +42,7 @@ export declare function curveClosestPoint<Point extends GlobalPoint | LocalPoint
37
42
  * @param c The curve to test
38
43
  * @param p The point to measure from
39
44
  */
40
- export declare function curvePointDistance<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, p: Point): number;
45
+ export declare function curvePointDistance<Point extends GlobalPoint | LocalPoint>(c: Curve<Point>, p: Point, tolerance?: number): number;
41
46
  /**
42
47
  * Determines if the parameter is a Curve
43
48
  */
@@ -74,4 +79,6 @@ export declare function curveLengthAtParameter<P extends GlobalPoint | LocalPoin
74
79
  * @param percent A value between 0 and 1 representing the percentage of the curve's length
75
80
  * @returns The point at the specified percentage of curve length
76
81
  */
77
- export declare function curvePointAtLength<P extends GlobalPoint | LocalPoint>(c: Curve<P>, percent: number): P;
82
+ export declare function curvePointAtLength<P extends GlobalPoint | LocalPoint>(c: Curve<P>, percent: number,
83
+ /** pass the curve's total length when already known to skip recomputing it */
84
+ totalLength?: number): P;
@@ -29,6 +29,11 @@ export declare const lineSegmentRotate: <Point extends LocalPoint | GlobalPoint>
29
29
  export declare const segmentsIntersectAt: <Point extends GlobalPoint | LocalPoint>(a: Readonly<LineSegment<Point>>, b: Readonly<LineSegment<Point>>) => Point | null;
30
30
  export declare const pointOnLineSegment: <Point extends LocalPoint | GlobalPoint>(point: Point, line: LineSegment<Point>, threshold?: number) => boolean;
31
31
  export declare const distanceToLineSegment: <Point extends LocalPoint | GlobalPoint>(point: Point, line: LineSegment<Point>) => number;
32
+ /**
33
+ * Returns the point at parameter `t` along the segment, where `t = 0` is the
34
+ * segment's start and `t = 1` its end. Not clamped.
35
+ */
36
+ export declare function lineSegmentPointAt<Point extends GlobalPoint | LocalPoint>(line: LineSegment<Point>, t: number): Point;
32
37
  /**
33
38
  * Returns the intersection point of a segment and a line
34
39
  *
@@ -38,3 +43,4 @@ export declare const distanceToLineSegment: <Point extends LocalPoint | GlobalPo
38
43
  */
39
44
  export declare function lineSegmentIntersectionPoints<Point extends GlobalPoint | LocalPoint>(l: LineSegment<Point>, s: LineSegment<Point>, threshold?: number): Point | null;
40
45
  export declare function lineSegmentsDistance<Point extends GlobalPoint | LocalPoint>(s1: LineSegment<Point>, s2: LineSegment<Point>): number;
46
+ export declare function lineSegmentClosestParameter<Point extends GlobalPoint | LocalPoint>(point: Point, line: LineSegment<Point>): number;
@@ -3,6 +3,7 @@ import type { ExcalidrawFrameLikeElement, NonDeleted, NonDeletedExcalidrawElemen
3
3
  import type { AppState, BinaryFiles } from "@excalidraw/excalidraw/types";
4
4
  export { MIME_TYPES };
5
5
  type ExportOpts = {
6
+ /** restored before exporting */
6
7
  elements: readonly NonDeletedExcalidrawElement[];
7
8
  appState?: Partial<Omit<AppState, "offsetTop" | "offsetLeft">>;
8
9
  files: BinaryFiles | null;
@@ -1,5 +1,5 @@
1
1
  import { type GlobalPoint, type LocalPoint } from "@excalidraw/math";
2
- import type { ElementsMap, ExcalidrawBindableElement, ExcalidrawDiamondElement, ExcalidrawElement, ExcalidrawEllipseElement, ExcalidrawEmbeddableElement, ExcalidrawFrameLikeElement, ExcalidrawFreeDrawElement, ExcalidrawIframeElement, ExcalidrawImageElement, ExcalidrawLinearElement, ExcalidrawRectangleElement, ExcalidrawSelectionElement, ExcalidrawTextElement } from "@excalidraw/element/types";
2
+ import type { ElementsMap, ExcalidrawBindableElement, ExcalidrawDiamondElement, ExcalidrawElement, ExcalidrawEllipseElement, ExcalidrawEmbeddableElement, ExcalidrawFrameLikeElement, ExcalidrawFreeDrawElement, ExcalidrawIframeElement, ExcalidrawImageElement, ExcalidrawLinearElement, ExcalidrawRectangleElement, ExcalidrawSelectionElement, ExcalidrawStickyNoteElement, ExcalidrawTextElement } from "@excalidraw/element/types";
3
3
  import type { Curve, LineSegment, Polygon, Radians } from "@excalidraw/math";
4
4
  import type { Drawable, Op } from "roughjs/bin/core";
5
5
  export type Polyline<Point extends GlobalPoint | LocalPoint> = LineSegment<Point>[];
@@ -29,7 +29,7 @@ export type GeometricShape<Point extends GlobalPoint | LocalPoint> = {
29
29
  type: "polycurve";
30
30
  data: Polycurve<Point>;
31
31
  };
32
- type RectangularElement = ExcalidrawRectangleElement | ExcalidrawDiamondElement | ExcalidrawFrameLikeElement | ExcalidrawEmbeddableElement | ExcalidrawImageElement | ExcalidrawIframeElement | ExcalidrawTextElement | ExcalidrawSelectionElement;
32
+ type RectangularElement = ExcalidrawRectangleElement | ExcalidrawStickyNoteElement | ExcalidrawDiamondElement | ExcalidrawFrameLikeElement | ExcalidrawEmbeddableElement | ExcalidrawImageElement | ExcalidrawIframeElement | ExcalidrawTextElement | ExcalidrawSelectionElement;
33
33
  export declare const getPolygonShape: <Point extends GlobalPoint | LocalPoint>(element: RectangularElement) => GeometricShape<Point>;
34
34
  export declare const getSelectionBoxShape: <Point extends GlobalPoint | LocalPoint>(element: ExcalidrawElement, elementsMap: ElementsMap, padding?: number) => GeometricShape<Point>;
35
35
  export declare const getEllipseShape: <Point extends GlobalPoint | LocalPoint>(element: ExcalidrawEllipseElement) => GeometricShape<Point>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excalidraw/common",
3
- "version": "0.18.0-abeeaeb",
3
+ "version": "0.18.0-afa3a65",
4
4
  "type": "module",
5
5
  "types": "./dist/types/common/src/index.d.ts",
6
6
  "main": "./dist/prod/index.js",