@excalidraw/common 0.18.0-4ce38fb → 0.18.0-4ce8305

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 (82) hide show
  1. package/dist/dev/index.js +25 -17
  2. package/dist/dev/index.js.map +3 -3
  3. package/dist/prod/index.js +3 -3
  4. package/dist/types/common/src/utils.d.ts +7 -1
  5. package/dist/types/element/src/align.d.ts +4 -1
  6. package/dist/types/element/src/binding.d.ts +36 -0
  7. package/dist/types/element/src/bounds.d.ts +10 -2
  8. package/dist/types/element/src/collision.d.ts +7 -0
  9. package/dist/types/element/src/cropElement.d.ts +36 -4
  10. package/dist/types/element/src/delta.d.ts +7 -1
  11. package/dist/types/element/src/distribute.d.ts +4 -1
  12. package/dist/types/element/src/dragElements.d.ts +8 -3
  13. package/dist/types/element/src/elbowArrow.d.ts +5 -0
  14. package/dist/types/element/src/embeddable.d.ts +2 -1
  15. package/dist/types/element/src/groups.d.ts +1 -6
  16. package/dist/types/element/src/image.d.ts +5 -2
  17. package/dist/types/element/src/index.d.ts +1 -0
  18. package/dist/types/element/src/linearElementEditor.d.ts +4 -1
  19. package/dist/types/element/src/listMarker.d.ts +7 -2
  20. package/dist/types/element/src/newElement.d.ts +3 -1
  21. package/dist/types/element/src/renderElement.d.ts +10 -0
  22. package/dist/types/element/src/renderEnvironment.d.ts +66 -0
  23. package/dist/types/element/src/resizeElements.d.ts +15 -5
  24. package/dist/types/element/src/selection.d.ts +1 -7
  25. package/dist/types/element/src/shape.d.ts +2 -0
  26. package/dist/types/element/src/stickyNote.d.ts +8 -0
  27. package/dist/types/element/src/textElement.d.ts +3 -2
  28. package/dist/types/element/src/textMeasurements.d.ts +15 -11
  29. package/dist/types/element/src/textWrapping.d.ts +3 -2
  30. package/dist/types/element/src/transform.d.ts +5 -1
  31. package/dist/types/excalidraw/actions/actionBoundText.d.ts +46 -221
  32. package/dist/types/excalidraw/actions/actionCanvas.d.ts +2 -2
  33. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +4 -588
  34. package/dist/types/excalidraw/actions/actionExport.d.ts +2 -2
  35. package/dist/types/excalidraw/actions/actionFrame.d.ts +41 -525
  36. package/dist/types/excalidraw/actions/actionToggleWrap.d.ts +12 -0
  37. package/dist/types/excalidraw/actions/index.d.ts +1 -0
  38. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  39. package/dist/types/excalidraw/actions/types.d.ts +1 -1
  40. package/dist/types/excalidraw/appState.d.ts +2 -2
  41. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -1
  42. package/dist/types/excalidraw/charts/charts.helpers.d.ts +6 -5
  43. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -1
  44. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -1
  45. package/dist/types/excalidraw/charts/index.d.ts +2 -1
  46. package/dist/types/excalidraw/components/App.d.ts +34 -20
  47. package/dist/types/excalidraw/components/App.host.d.ts +102 -0
  48. package/dist/types/excalidraw/components/App.modifiers.d.ts +38 -0
  49. package/dist/types/excalidraw/components/App.selection.d.ts +265 -0
  50. package/dist/types/excalidraw/components/App.selectionTool.d.ts +93 -0
  51. package/dist/types/excalidraw/components/App.viewport.d.ts +13 -3
  52. package/dist/types/excalidraw/components/App.wrap.d.ts +31 -0
  53. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -1
  54. package/dist/types/excalidraw/components/Stats/utils.d.ts +4 -2
  55. package/dist/types/excalidraw/components/TTDDialog/MermaidToExcalidraw.d.ts +2 -1
  56. package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +5 -2
  57. package/dist/types/excalidraw/components/TTDDialog/TTDPreviewPanel.d.ts +5 -2
  58. package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +2 -1
  59. package/dist/types/excalidraw/components/TTDDialog/common.d.ts +4 -1
  60. package/dist/types/excalidraw/components/TTDDialog/hooks/useTextGeneration.d.ts +3 -2
  61. package/dist/types/excalidraw/components/TTDDialog/types.d.ts +14 -1
  62. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +27 -1
  63. package/dist/types/excalidraw/components/Tooltip.d.ts +11 -1
  64. package/dist/types/excalidraw/components/TopPicksDnD/topPicksDnD.d.ts +1 -1
  65. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +0 -1
  66. package/dist/types/excalidraw/components/hyperlink/Hyperlink.d.ts +3 -2
  67. package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +13 -2
  68. package/dist/types/excalidraw/data/blob.d.ts +4 -4
  69. package/dist/types/excalidraw/data/index.d.ts +3 -3
  70. package/dist/types/excalidraw/data/json.d.ts +2 -2
  71. package/dist/types/excalidraw/fonts/Fonts.d.ts +9 -6
  72. package/dist/types/excalidraw/history.d.ts +10 -4
  73. package/dist/types/excalidraw/reactUtils.d.ts +1 -1
  74. package/dist/types/excalidraw/renderer/animation.d.ts +11 -4
  75. package/dist/types/excalidraw/renderer/staticScene.d.ts +11 -6
  76. package/dist/types/excalidraw/scene/Renderer.d.ts +1 -1
  77. package/dist/types/excalidraw/scene/export.d.ts +343 -20
  78. package/dist/types/excalidraw/scene/types.d.ts +23 -1
  79. package/dist/types/excalidraw/types.d.ts +49 -1
  80. package/dist/types/utils/src/index.d.ts +3 -1
  81. package/package.json +1 -1
  82. package/dist/types/utils/src/export.d.ts +0 -36
@@ -1,12 +1,28 @@
1
1
  import type { UserIdleState, EditorInterface } from "@excalidraw/common";
2
- import type { ExcalidrawElement, NonDeletedElementsMap, NonDeletedExcalidrawElement, NonDeletedSceneElementsMap } from "@excalidraw/element/types";
2
+ import type { ExcalidrawElement, ExcalidrawFrameLikeElement, NonDeletedElementsMap, NonDeletedExcalidrawElement, NonDeletedSceneElementsMap } from "@excalidraw/element/types";
3
3
  import type { MakeBrand } from "@excalidraw/common/utility-types";
4
+ import type { RenderEnvironment } from "@excalidraw/element/renderEnvironment";
4
5
  import type { AppClassProperties, AppState, EmbedsValidationStatus, ElementRenderOverrides, ElementsPendingErasure, InteractiveCanvasAppState, StaticCanvasAppState, SocketId, PendingExcalidrawElements } from "../types";
5
6
  import type { RoughCanvas } from "roughjs/bin/canvas";
6
7
  import type { Drawable } from "roughjs/bin/core";
7
8
  export type RenderableElementsMap = NonDeletedElementsMap & MakeBrand<"RenderableElementsMap">;
8
9
  export type StaticCanvasRenderConfig = {
9
10
  canvasBackgroundColor: AppState["viewBackgroundColor"];
11
+ /**
12
+ * Backing-store scale the target canvas was bootstrapped with -- the owner
13
+ * window's devicePixelRatio when rendering into the editor, exportScale when
14
+ * exporting. Element caches are built and blitted at this ratio, so it must
15
+ * be the same value passed as `StaticSceneRenderConfig["scale"]`.
16
+ */
17
+ scale: number;
18
+ /**
19
+ * Host environment that creates the canvases and images this render
20
+ * rasterizes (per-editor owner window in the app; the export's
21
+ * `config.environment` when exporting). Defaults to the browser's.
22
+ */
23
+ renderEnvironment?: RenderEnvironment;
24
+ /** export only: clips everything drawn to this frame (square corners) */
25
+ clipToFrame?: ExcalidrawFrameLikeElement | null;
10
26
  imageCache: AppClassProperties["imageCache"];
11
27
  renderGrid: boolean;
12
28
  /** whether to render link icons on elements with links (never rendered
@@ -22,6 +38,12 @@ export type StaticCanvasRenderConfig = {
22
38
  elementRenderOverrides?: ElementRenderOverrides;
23
39
  };
24
40
  export type SVGRenderConfig = {
41
+ /**
42
+ * Host environment used for the text measurements this render needs (the
43
+ * SVG itself is built through `exportToSvg`'s owner document). Defaults to
44
+ * the browser's.
45
+ */
46
+ renderEnvironment?: RenderEnvironment;
25
47
  offsetX: number;
26
48
  offsetY: number;
27
49
  isExporting: boolean;
@@ -3,7 +3,7 @@ import type { LinearElementEditor } from "@excalidraw/element";
3
3
  import type { ListMarkerAdvance, MaybeTransformHandleType } from "@excalidraw/element";
4
4
  import type { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, ExcalidrawArrowElement, Arrowhead, FontFamilyValues, FileId, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement, OrderedExcalidrawElement, ExcalidrawNonSelectionElement, BindMode, ExcalidrawTextElement, StrokeVariability } from "@excalidraw/element/types";
5
5
  import type { Merge, MaybePromise, ValueOf, MakeBrand } from "@excalidraw/common/utility-types";
6
- import type { CaptureUpdateActionType, DurableIncrement, EphemeralIncrement, OnDuplicateData } from "@excalidraw/element";
6
+ import type { CaptureUpdateActionType, DurableIncrement, EphemeralIncrement, RenderEnvironment, OnDuplicateData } from "@excalidraw/element";
7
7
  import type { GlobalPoint } from "@excalidraw/math";
8
8
  import type { Action } from "./actions/types";
9
9
  import type { Spreadsheet } from "./charts";
@@ -692,6 +692,30 @@ export interface ExcalidrawProps {
692
692
  * @default document
693
693
  */
694
694
  ownerDocument?: Document;
695
+ /**
696
+ * Host environment used by the renderer and export pipeline to create
697
+ * canvases and images. Supply a custom implementation to redirect canvas
698
+ * creation and image decoding to e.g. a host canvas pool, an
699
+ * `OffscreenCanvas`, or a non-DOM image decoder. When omitted, canvas and
700
+ * image creation fall back to `ownerDocument` / `ownerWindow`.
701
+ *
702
+ * The value must be referentially stable -- every render cache (element
703
+ * canvases, text metrics, char widths, link icons) is keyed by this
704
+ * object's identity, so a new identity is a full cache miss. Passing an
705
+ * inline object literal mints a fresh identity on every React render,
706
+ * which silently re-rasterizes every element on every frame; hoist it to a
707
+ * module constant or memoize it (e.g. `useMemo`) instead.
708
+ *
709
+ * Only `createCanvas` and `createImage` are required. `createPath` (used to
710
+ * fill freedraw strokes) falls back to the global `Path2D`, which every
711
+ * browser has -- a non-browser host without one must supply it. Pass
712
+ * `document` (the owner document) for SVG exports to be built in it rather
713
+ * than in the global `document`, and `textMetrics` to measure the editor's
714
+ * text with your own provider.
715
+ *
716
+ * @default { createCanvas: () => ownerDocument.createElement("canvas"), createImage: () => new ownerWindow.Image(), createPath: (d) => new ownerWindow.Path2D(d), document: ownerDocument }
717
+ */
718
+ renderEnvironment?: RenderEnvironment;
695
719
  onChange?: (elements: readonly OrderedExcalidrawElement[], appState: AppState, files: BinaryFiles) => void;
696
720
  onThemeChange?: (theme: Theme | "system") => void;
697
721
  /**
@@ -960,6 +984,7 @@ export type AppClassProperties = {
960
984
  state: AppState;
961
985
  readonly ownerDocument: Document;
962
986
  readonly ownerWindow: Window & typeof globalThis;
987
+ renderEnvironment: RenderEnvironment;
963
988
  api: App["api"];
964
989
  sessionExportThemeOverride: App["sessionExportThemeOverride"];
965
990
  interactiveCanvas: HTMLCanvasElement | null;
@@ -1000,6 +1025,9 @@ export type AppClassProperties = {
1000
1025
  duplicate: App["duplicate"];
1001
1026
  toolDrag: App["toolDrag"];
1002
1027
  activeResizeHandle: App["activeResizeHandle"];
1028
+ selectionTool: App["selectionTool"];
1029
+ wrap: App["wrap"];
1030
+ modifiers: App["modifiers"];
1003
1031
  isToolLocked: App["isToolLocked"];
1004
1032
  getEffectiveGridSize: App["getEffectiveGridSize"];
1005
1033
  setPlugins: App["setPlugins"];
@@ -1052,6 +1080,7 @@ export type PointerDownState = Readonly<{
1052
1080
  element: NonDeleted<ExcalidrawElement> | null;
1053
1081
  allHitElements: NonDeleted<ExcalidrawElement>[];
1054
1082
  wasAddedToSelection: boolean;
1083
+ cycleTarget: NonDeleted<ExcalidrawElement> | null;
1055
1084
  hasBeenDuplicated: boolean;
1056
1085
  advancedListMarkers: readonly ListMarkerAdvance[];
1057
1086
  editedTextId: ExcalidrawTextElement["id"] | null;
@@ -1069,6 +1098,10 @@ export type PointerDownState = Readonly<{
1069
1098
  x: number;
1070
1099
  y: number;
1071
1100
  };
1101
+ lastOffset: {
1102
+ x: number;
1103
+ y: number;
1104
+ };
1072
1105
  blockDragging: boolean;
1073
1106
  };
1074
1107
  eventListeners: {
@@ -1104,6 +1137,21 @@ export interface ExcalidrawImperativeAPI {
1104
1137
  history: {
1105
1138
  clear: InstanceType<typeof App>["resetHistory"];
1106
1139
  };
1140
+ /**
1141
+ * Selects elements (or their ids — one or many), adds them to or removes
1142
+ * them from the selection, or clears it — as the editor does: an element is
1143
+ * selected with its group (unless `deep`), a frame and its children aren't
1144
+ * selected at the same time, and locked elements are skipped (unless
1145
+ * `includeLocked`). Text editing and cropping end, and the link popup of a
1146
+ * lone selected element shows. Missing and deleted elements are skipped.
1147
+ *
1148
+ * By default the change is recorded for undo along with the next undoable
1149
+ * change — pass `captureUpdate` as for `updateScene()` otherwise. Like
1150
+ * `updateScene()`, it applies on the next render: read it back through
1151
+ * `onChange()` or `getAppState()` after that. Works in view mode too, where
1152
+ * the selection shows without transform handles.
1153
+ */
1154
+ selection: Pick<InstanceType<typeof App>["selection"], "select" | "add" | "remove" | "clear">;
1107
1155
  getSceneElements: InstanceType<typeof App>["getSceneElements"];
1108
1156
  getAppState: () => InstanceType<typeof App>["state"];
1109
1157
  getFiles: () => InstanceType<typeof App>["files"];
@@ -1,3 +1,5 @@
1
- export * from "./export";
1
+ export { exportScene, exportToClipboard, MIME_TYPES, } from "@excalidraw/excalidraw/scene/export";
2
+ export type { ExportSceneData, ExportSceneConfig, ExportSceneOptions, } from "@excalidraw/excalidraw/scene/export";
2
3
  export { elementsOverlappingBBox } from "@excalidraw/element";
3
4
  export { getCommonBounds } from "@excalidraw/element";
5
+ export type { RenderEnvironment } from "@excalidraw/element";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excalidraw/common",
3
- "version": "0.18.0-4ce38fb",
3
+ "version": "0.18.0-4ce8305",
4
4
  "type": "module",
5
5
  "types": "./dist/types/common/src/index.d.ts",
6
6
  "main": "./dist/prod/index.js",
@@ -1,36 +0,0 @@
1
- import { MIME_TYPES } from "@excalidraw/common";
2
- import type { ExcalidrawFrameLikeElement, NonDeleted, NonDeletedExcalidrawElement } from "@excalidraw/element/types";
3
- import type { AppState, BinaryFiles } from "@excalidraw/excalidraw/types";
4
- export { MIME_TYPES };
5
- type ExportOpts = {
6
- /** restored before exporting */
7
- elements: readonly NonDeletedExcalidrawElement[];
8
- appState?: Partial<Omit<AppState, "offsetTop" | "offsetLeft">>;
9
- files: BinaryFiles | null;
10
- maxWidthOrHeight?: number;
11
- exportingFrame?: NonDeleted<ExcalidrawFrameLikeElement> | null;
12
- getDimensions?: (width: number, height: number) => {
13
- width: number;
14
- height: number;
15
- scale?: number;
16
- };
17
- };
18
- export declare const exportToCanvas: ({ elements, appState, files, maxWidthOrHeight, getDimensions, exportPadding, exportingFrame, }: ExportOpts & {
19
- exportPadding?: number;
20
- }) => Promise<HTMLCanvasElement>;
21
- export declare const exportToBlob: (opts: ExportOpts & {
22
- mimeType?: string;
23
- quality?: number;
24
- exportPadding?: number;
25
- }) => Promise<Blob>;
26
- export declare const exportToSvg: ({ elements, appState, files, exportPadding, renderEmbeddables, exportingFrame, skipInliningFonts, reuseImages, }: Omit<ExportOpts, "getDimensions"> & {
27
- exportPadding?: number;
28
- renderEmbeddables?: boolean;
29
- skipInliningFonts?: true;
30
- reuseImages?: boolean;
31
- }) => Promise<SVGSVGElement>;
32
- export declare const exportToClipboard: (opts: ExportOpts & {
33
- mimeType?: string;
34
- quality?: number;
35
- type: "png" | "svg" | "json";
36
- }) => Promise<void>;