@zsviczian/excalidraw 0.13.0-obsidian-1 → 0.13.0-obsidian-2

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 (45) hide show
  1. package/README.md +1 -1
  2. package/dist/excalidraw.development.js +76 -54
  3. package/dist/excalidraw.production.min.js +1 -1
  4. package/package.json +1 -1
  5. package/types/actions/actionAddToLibrary.d.ts +3 -6
  6. package/types/actions/actionBoundText.d.ts +1 -2
  7. package/types/actions/actionCanvas.d.ts +21 -25
  8. package/types/actions/actionClipboard.d.ts +14 -10
  9. package/types/actions/actionDeleteSelected.d.ts +12 -6
  10. package/types/actions/actionExport.d.ts +17 -25
  11. package/types/actions/actionFinalize.d.ts +2 -4
  12. package/types/actions/actionLinearEditor.d.ts +1 -2
  13. package/types/actions/actionMenu.d.ts +5 -6
  14. package/types/actions/actionNavigate.d.ts +1 -0
  15. package/types/actions/actionProperties.d.ts +15 -28
  16. package/types/actions/actionStyles.d.ts +1 -2
  17. package/types/actions/actionToggleGridMode.d.ts +2 -2
  18. package/types/actions/actionToggleLock.d.ts +1 -2
  19. package/types/actions/actionToggleStats.d.ts +2 -2
  20. package/types/actions/actionToggleViewMode.d.ts +2 -2
  21. package/types/actions/actionToggleZenMode.d.ts +2 -2
  22. package/types/actions/types.d.ts +4 -1
  23. package/types/appState.d.ts +8 -9
  24. package/types/clipboard.d.ts +6 -1
  25. package/types/components/App.d.ts +1 -1
  26. package/types/components/ContextMenu.d.ts +9 -10
  27. package/types/constants.d.ts +7 -5
  28. package/types/element/Hyperlink.d.ts +1 -2
  29. package/types/element/bounds.d.ts +3 -2
  30. package/types/element/linearElementEditor.d.ts +32 -5
  31. package/types/element/newElement.d.ts +2 -2
  32. package/types/element/resizeElements.d.ts +0 -1
  33. package/types/element/textElement.d.ts +17 -2
  34. package/types/element/transformHandles.d.ts +2 -3
  35. package/types/element/typeChecks.d.ts +10 -1
  36. package/types/element/types.d.ts +11 -4
  37. package/types/excalidraw-app/data/index.d.ts +8 -9
  38. package/types/excalidraw-app/data/localStorage.d.ts +8 -9
  39. package/types/math.d.ts +2 -1
  40. package/types/renderer/renderElement.d.ts +4 -3
  41. package/types/scene/Fonts.d.ts +21 -0
  42. package/types/scene/Scene.d.ts +15 -0
  43. package/types/scene/comparisons.d.ts +2 -3
  44. package/types/scene/index.d.ts +1 -1
  45. package/types/types.d.ts +2 -3
@@ -1,5 +1,5 @@
1
1
  import { AppState } from "../types";
2
- import { ExcalidrawElement, ExcalidrawTextElement, ExcalidrawLinearElement, ExcalidrawBindableElement, ExcalidrawGenericElement, ExcalidrawFreeDrawElement, InitializedExcalidrawImageElement, ExcalidrawImageElement, ExcalidrawTextElementWithContainer, ExcalidrawTextContainer } from "./types";
2
+ import { ExcalidrawElement, ExcalidrawTextElement, ExcalidrawLinearElement, ExcalidrawBindableElement, ExcalidrawGenericElement, ExcalidrawFreeDrawElement, InitializedExcalidrawImageElement, ExcalidrawImageElement, ExcalidrawTextElementWithContainer, ExcalidrawTextContainer, RoundnessType } from "./types";
3
3
  export declare const isGenericElement: (element: ExcalidrawElement | null) => element is ExcalidrawGenericElement;
4
4
  export declare const isInitializedImageElement: (element: ExcalidrawElement | null) => element is InitializedExcalidrawImageElement;
5
5
  export declare const isImageElement: (element: ExcalidrawElement | null) => element is ExcalidrawImageElement;
@@ -7,6 +7,7 @@ export declare const isTextElement: (element: ExcalidrawElement | null) => eleme
7
7
  export declare const isFreeDrawElement: (element?: ExcalidrawElement | null) => element is ExcalidrawFreeDrawElement;
8
8
  export declare const isFreeDrawElementType: (elementType: ExcalidrawElement["type"]) => boolean;
9
9
  export declare const isLinearElement: (element?: ExcalidrawElement | null) => element is ExcalidrawLinearElement;
10
+ export declare const isArrowElement: (element?: ExcalidrawElement | null) => element is ExcalidrawLinearElement;
10
11
  export declare const isLinearElementType: (elementType: AppState["activeTool"]["type"]) => boolean;
11
12
  export declare const isBindingElement: (element?: ExcalidrawElement | null, includeLocked?: boolean) => element is ExcalidrawLinearElement;
12
13
  export declare const isBindingElementType: (elementType: AppState["activeTool"]["type"]) => boolean;
@@ -15,3 +16,11 @@ export declare const isTextBindableContainer: (element: ExcalidrawElement | null
15
16
  export declare const isExcalidrawElement: (element: any) => boolean;
16
17
  export declare const hasBoundTextElement: (element: ExcalidrawElement | null) => element is ExcalidrawBindableElement;
17
18
  export declare const isBoundToContainer: (element: ExcalidrawElement | null) => element is ExcalidrawTextElementWithContainer;
19
+ export declare const isUsingAdaptiveRadius: (type: string) => boolean;
20
+ export declare const isUsingProportionalRadius: (type: string) => boolean;
21
+ export declare const canApplyRoundnessTypeToElement: (roundnessType: RoundnessType, element: ExcalidrawElement) => boolean;
22
+ export declare const getDefaultRoundnessTypeForElement: (element: ExcalidrawElement) => {
23
+ type: 2;
24
+ } | {
25
+ type: 3;
26
+ } | null;
@@ -1,5 +1,5 @@
1
1
  import { Point } from "../types";
2
- import { FONT_FAMILY, TEXT_ALIGN, THEME, VERTICAL_ALIGN } from "../constants";
2
+ import { FONT_FAMILY, ROUNDNESS, TEXT_ALIGN, THEME, VERTICAL_ALIGN } from "../constants";
3
3
  export declare type ChartType = "bar" | "line";
4
4
  export declare type FillStyle = "hachure" | "cross-hatch" | "solid";
5
5
  export declare type FontFamilyKeys = keyof typeof FONT_FAMILY;
@@ -10,7 +10,8 @@ export declare type FontString = string & {
10
10
  };
11
11
  export declare type GroupId = string;
12
12
  export declare type PointerType = "mouse" | "pen" | "touch";
13
- export declare type StrokeSharpness = "round" | "sharp";
13
+ export declare type StrokeRoundness = "round" | "sharp";
14
+ export declare type RoundnessType = ValueOf<typeof ROUNDNESS>;
14
15
  export declare type StrokeStyle = "solid" | "dashed" | "dotted";
15
16
  export declare type TextAlign = typeof TEXT_ALIGN[keyof typeof TEXT_ALIGN];
16
17
  declare type VerticalAlignKeys = keyof typeof VERTICAL_ALIGN;
@@ -24,7 +25,10 @@ declare type _ExcalidrawElementBase = Readonly<{
24
25
  fillStyle: FillStyle;
25
26
  strokeWidth: number;
26
27
  strokeStyle: StrokeStyle;
27
- strokeSharpness: StrokeSharpness;
28
+ roundness: null | {
29
+ type: RoundnessType;
30
+ value?: number;
31
+ };
28
32
  roughness: number;
29
33
  opacity: number;
30
34
  width: number;
@@ -103,7 +107,7 @@ export declare type ExcalidrawTextElement = _ExcalidrawElementBase & Readonly<{
103
107
  originalText: string;
104
108
  }>;
105
109
  export declare type ExcalidrawBindableElement = ExcalidrawRectangleElement | ExcalidrawDiamondElement | ExcalidrawEllipseElement | ExcalidrawTextElement | ExcalidrawImageElement;
106
- export declare type ExcalidrawTextContainer = ExcalidrawRectangleElement | ExcalidrawDiamondElement | ExcalidrawEllipseElement | ExcalidrawImageElement;
110
+ export declare type ExcalidrawTextContainer = ExcalidrawRectangleElement | ExcalidrawDiamondElement | ExcalidrawEllipseElement | ExcalidrawImageElement | ExcalidrawArrowElement;
107
111
  export declare type ExcalidrawTextElementWithContainer = {
108
112
  containerId: ExcalidrawTextContainer["id"];
109
113
  } & ExcalidrawTextElement;
@@ -122,6 +126,9 @@ export declare type ExcalidrawLinearElement = _ExcalidrawElementBase & Readonly<
122
126
  startArrowhead: Arrowhead | null;
123
127
  endArrowhead: Arrowhead | null;
124
128
  }>;
129
+ export declare type ExcalidrawArrowElement = ExcalidrawLinearElement & Readonly<{
130
+ type: "arrow";
131
+ }>;
125
132
  export declare type ExcalidrawFreeDrawElement = _ExcalidrawElementBase & Readonly<{
126
133
  type: "freedraw";
127
134
  points: readonly Point[];
@@ -91,13 +91,6 @@ export declare const loadScene: (id: string | null, privateKey: string | null, l
91
91
  lastActiveToolBeforeEraser: import("../../types").LastActiveToolBeforeEraser;
92
92
  locked: boolean;
93
93
  };
94
- scrollX: number;
95
- scrollY: number;
96
- viewBackgroundColor: string;
97
- zoom: Readonly<{
98
- value: import("../../types").NormalizedZoomValue;
99
- }>;
100
- shouldCacheIgnoreZoom: boolean;
101
94
  showWelcomeScreen: boolean;
102
95
  isLoading: boolean;
103
96
  errorMessage: string | null;
@@ -126,14 +119,19 @@ export declare const loadScene: (id: string | null, privateKey: string | null, l
126
119
  currentItemFontFamily: number;
127
120
  currentItemFontSize: number;
128
121
  currentItemTextAlign: string;
129
- currentItemStrokeSharpness: import("../../element/types").StrokeSharpness;
130
122
  currentItemStartArrowhead: import("../../element/types").Arrowhead | null;
131
123
  currentItemEndArrowhead: import("../../element/types").Arrowhead | null;
132
- currentItemLinearStrokeSharpness: import("../../element/types").StrokeSharpness;
124
+ currentItemRoundness: import("../../element/types").StrokeRoundness;
125
+ viewBackgroundColor: string;
126
+ scrollX: number;
127
+ scrollY: number;
133
128
  cursorButton: "up" | "down";
134
129
  scrolledOutside: boolean;
135
130
  isResizing: boolean;
136
131
  isRotating: boolean;
132
+ zoom: Readonly<{
133
+ value: import("../../types").NormalizedZoomValue;
134
+ }>;
137
135
  openMenu: "canvas" | "shape" | null;
138
136
  openPopup: "canvasColorPicker" | "backgroundColorPicker" | "strokeColorPicker" | null;
139
137
  openSidebar: "library" | "customSidebar" | null;
@@ -146,6 +144,7 @@ export declare const loadScene: (id: string | null, privateKey: string | null, l
146
144
  previousSelectedElementIds: {
147
145
  [id: string]: boolean;
148
146
  };
147
+ shouldCacheIgnoreZoom: boolean;
149
148
  toast: {
150
149
  message: string;
151
150
  closable?: boolean | undefined;
@@ -17,13 +17,6 @@ export declare const importFromLocalStorage: () => {
17
17
  lastActiveToolBeforeEraser: import("../../types").LastActiveToolBeforeEraser;
18
18
  locked: boolean;
19
19
  };
20
- scrollX: number;
21
- scrollY: number;
22
- viewBackgroundColor: string;
23
- zoom: Readonly<{
24
- value: import("../../types").NormalizedZoomValue;
25
- }>;
26
- shouldCacheIgnoreZoom: boolean;
27
20
  showWelcomeScreen: boolean;
28
21
  penMode: boolean;
29
22
  penDetected: boolean;
@@ -41,12 +34,17 @@ export declare const importFromLocalStorage: () => {
41
34
  currentItemFontFamily: number;
42
35
  currentItemFontSize: number;
43
36
  currentItemTextAlign: string;
44
- currentItemStrokeSharpness: import("../../element/types").StrokeSharpness;
45
37
  currentItemStartArrowhead: import("../../element/types").Arrowhead | null;
46
38
  currentItemEndArrowhead: import("../../element/types").Arrowhead | null;
47
- currentItemLinearStrokeSharpness: import("../../element/types").StrokeSharpness;
39
+ currentItemRoundness: import("../../element/types").StrokeRoundness;
40
+ viewBackgroundColor: string;
41
+ scrollX: number;
42
+ scrollY: number;
48
43
  cursorButton: "up" | "down";
49
44
  scrolledOutside: boolean;
45
+ zoom: Readonly<{
46
+ value: import("../../types").NormalizedZoomValue;
47
+ }>;
50
48
  openMenu: "canvas" | "shape" | null;
51
49
  openSidebar: "library" | "customSidebar" | null;
52
50
  isSidebarDocked: boolean;
@@ -57,6 +55,7 @@ export declare const importFromLocalStorage: () => {
57
55
  previousSelectedElementIds: {
58
56
  [id: string]: boolean;
59
57
  };
58
+ shouldCacheIgnoreZoom: boolean;
60
59
  zenModeEnabled: boolean;
61
60
  gridSize: number | null;
62
61
  selectedGroupIds: {
package/types/math.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Point, Zoom } from "./types";
2
- import { ExcalidrawLinearElement, NonDeleted } from "./element/types";
2
+ import { ExcalidrawElement, ExcalidrawLinearElement, NonDeleted } from "./element/types";
3
3
  export declare const rotate: (x1: number, y1: number, x2: number, y2: number, angle: number) => [number, number];
4
4
  export declare const rotatePoint: (point: readonly [number, number], center: readonly [number, number], angle: number) => [number, number];
5
5
  export declare const adjustXYWithRotation: (sides: {
@@ -18,6 +18,7 @@ export declare const centerPoint: (a: readonly [number, number], b: readonly [nu
18
18
  export declare const isPathALoop: (points: ExcalidrawLinearElement["points"], zoomValue?: Zoom["value"]) => boolean;
19
19
  export declare const isPointInPolygon: (points: Point[], x: number, y: number) => boolean;
20
20
  export declare const getGridPoint: (x: number, y: number, gridSize: number | null) => [number, number];
21
+ export declare const getCornerRadius: (x: number, element: ExcalidrawElement) => number;
21
22
  export declare const getControlPointsForBezierCurve: (element: NonDeleted<ExcalidrawLinearElement>, endPoint: readonly [number, number]) => [number, number][] | null;
22
23
  export declare const getBezierXY: (p0: readonly [number, number], p1: readonly [number, number], p2: readonly [number, number], p3: readonly [number, number], t: number) => number[];
23
24
  export declare const getPointsInBezierCurve: (element: NonDeleted<ExcalidrawLinearElement>, endPoint: readonly [number, number]) => [number, number][];
@@ -3,7 +3,7 @@ import { RoughCanvas } from "roughjs/bin/canvas";
3
3
  import { Drawable, Options } from "roughjs/bin/core";
4
4
  import { RoughSVG } from "roughjs/bin/svg";
5
5
  import { RenderConfig } from "../scene/types";
6
- import { BinaryFiles, Zoom } from "../types";
6
+ import { AppState, BinaryFiles, Zoom } from "../types";
7
7
  export interface ExcalidrawElementWithCanvas {
8
8
  element: ExcalidrawElement | ExcalidrawTextElement;
9
9
  canvas: HTMLCanvasElement;
@@ -11,6 +11,7 @@ export interface ExcalidrawElementWithCanvas {
11
11
  canvasZoom: Zoom["value"];
12
12
  canvasOffsetX: number;
13
13
  canvasOffsetY: number;
14
+ boundTextElementVersion: number | null;
14
15
  }
15
16
  export declare const DEFAULT_LINK_SIZE = 14;
16
17
  declare type ElementShape = Drawable | Drawable[] | null;
@@ -25,8 +26,8 @@ export declare const getShapeForElement: <T extends ExcalidrawElement>(element:
25
26
  export declare const setShapeForElement: <T extends ExcalidrawElement>(element: T, shape: T["type"] extends keyof ElementShapes ? ElementShapes[T["type"]] : Drawable) => WeakMap<ExcalidrawElement, ElementShape>;
26
27
  export declare const invalidateShapeForElement: (element: ExcalidrawElement) => boolean;
27
28
  export declare const generateRoughOptions: (element: ExcalidrawElement, continuousPath?: boolean) => Options;
28
- export declare const renderElement: (element: NonDeletedExcalidrawElement, rc: RoughCanvas, context: CanvasRenderingContext2D, renderConfig: RenderConfig) => void;
29
- export declare const renderElementToSvg: (element: NonDeletedExcalidrawElement, rsvg: RoughSVG, svgRoot: SVGElement, files: BinaryFiles, offsetX?: number, offsetY?: number, exportWithDarkMode?: boolean) => void;
29
+ export declare const renderElement: (element: NonDeletedExcalidrawElement, rc: RoughCanvas, context: CanvasRenderingContext2D, renderConfig: RenderConfig, appState: AppState) => void;
30
+ export declare const renderElementToSvg: (element: NonDeletedExcalidrawElement, rsvg: RoughSVG, svgRoot: SVGElement, files: BinaryFiles, offsetX: number, offsetY: number, exportWithDarkMode?: boolean) => void;
30
31
  export declare const pathsCache: WeakMap<ExcalidrawFreeDrawElement, Path2D>;
31
32
  export declare function generateFreeDrawShape(element: ExcalidrawFreeDrawElement): Path2D;
32
33
  export declare function getFreeDrawPath2D(element: ExcalidrawFreeDrawElement): Path2D | undefined;
@@ -0,0 +1,21 @@
1
+ import { ExcalidrawElement } from "../element/types";
2
+ import type Scene from "./Scene";
3
+ export declare class Fonts {
4
+ private scene;
5
+ private onSceneUpdated;
6
+ constructor({ scene, onSceneUpdated, }: {
7
+ scene: Scene;
8
+ onSceneUpdated: () => void;
9
+ });
10
+ private static loadedFontFaces;
11
+ /**
12
+ * if we load a (new) font, it's likely that text elements using it have
13
+ * already been rendered using a fallback font. Thus, we want invalidate
14
+ * their shapes and rerender. See #637.
15
+ *
16
+ * Invalidates text elements and rerenders scene, provided that at least one
17
+ * of the supplied fontFaces has not already been processed.
18
+ */
19
+ onFontsLoaded: (fontFaces: readonly FontFace[]) => false | undefined;
20
+ loadFontsForElements: (elements: readonly ExcalidrawElement[]) => Promise<void>;
21
+ }
@@ -17,9 +17,24 @@ declare class Scene {
17
17
  getNonDeletedElements(): readonly NonDeletedExcalidrawElement[];
18
18
  getElement<T extends ExcalidrawElement>(id: T["id"]): T | null;
19
19
  getNonDeletedElement(id: ExcalidrawElement["id"]): NonDeleted<ExcalidrawElement> | null;
20
+ /**
21
+ * A utility method to help with updating all scene elements, with the added
22
+ * performance optimization of not renewing the array if no change is made.
23
+ *
24
+ * Maps all current excalidraw elements, invoking the callback for each
25
+ * element. The callback should either return a new mapped element, or the
26
+ * original element if no changes are made. If no changes are made to any
27
+ * element, this results in a no-op. Otherwise, the newly mapped elements
28
+ * are set as the next scene's elements.
29
+ *
30
+ * @returns whether a change was made
31
+ */
32
+ mapElements(iteratee: (element: ExcalidrawElement) => ExcalidrawElement): boolean;
20
33
  replaceAllElements(nextElements: readonly ExcalidrawElement[]): void;
21
34
  informMutation(): void;
22
35
  addCallback(cb: SceneStateCallback): SceneStateCallbackRemover;
23
36
  destroy(): void;
37
+ insertElementAtIndex(element: ExcalidrawElement, index: number): void;
38
+ getElementIndex(elementId: string): number;
24
39
  }
25
40
  export default Scene;
@@ -1,11 +1,10 @@
1
- import { ExcalidrawElement, ExcalidrawTextContainer, NonDeletedExcalidrawElement } from "../element/types";
1
+ import { NonDeletedExcalidrawElement } from "../element/types";
2
2
  export declare const hasBackground: (type: string) => boolean;
3
3
  export declare const hasStrokeColor: (type: string) => boolean;
4
4
  export declare const hasStrokeWidth: (type: string) => boolean;
5
5
  export declare const hasStrokeStyle: (type: string) => boolean;
6
- export declare const canChangeSharpness: (type: string) => boolean;
6
+ export declare const canChangeRoundness: (type: string) => boolean;
7
7
  export declare const hasText: (type: string) => boolean;
8
8
  export declare const canHaveArrowheads: (type: string) => boolean;
9
9
  export declare const getElementAtPosition: (elements: readonly NonDeletedExcalidrawElement[], isAtPositionFn: (element: NonDeletedExcalidrawElement) => boolean) => NonDeletedExcalidrawElement | null;
10
10
  export declare const getElementsAtPosition: (elements: readonly NonDeletedExcalidrawElement[], isAtPositionFn: (element: NonDeletedExcalidrawElement) => boolean) => NonDeletedExcalidrawElement[];
11
- export declare const getTextBindableContainerAtPosition: (elements: readonly ExcalidrawElement[], x: number, y: number) => ExcalidrawTextContainer | null;
@@ -1,5 +1,5 @@
1
1
  export { isOverScrollBars } from "./scrollbars";
2
2
  export { isSomeElementSelected, getElementsWithinSelection, getCommonAttributeOfSelectedElements, getSelectedElements, getTargetElements, } from "./selection";
3
3
  export { calculateScrollCenter } from "./scroll";
4
- export { hasBackground, hasStrokeWidth, hasStrokeStyle, canHaveArrowheads, canChangeSharpness, getElementAtPosition, getTextBindableContainerAtPosition, hasText, getElementsAtPosition, } from "./comparisons";
4
+ export { hasBackground, hasStrokeWidth, hasStrokeStyle, canHaveArrowheads, canChangeRoundness, getElementAtPosition, hasText, getElementsAtPosition, } from "./comparisons";
5
5
  export { getNormalizedZoom } from "./zoom";
package/types/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, ExcalidrawTextElement, FileId, ExcalidrawImageElement, Theme } from "./element/types";
2
+ import { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, ExcalidrawTextElement, FileId, ExcalidrawImageElement, Theme, StrokeRoundness } 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";
@@ -101,10 +101,9 @@ export declare type AppState = {
101
101
  currentItemFontFamily: FontFamilyValues;
102
102
  currentItemFontSize: number;
103
103
  currentItemTextAlign: TextAlign;
104
- currentItemStrokeSharpness: ExcalidrawElement["strokeSharpness"];
105
104
  currentItemStartArrowhead: Arrowhead | null;
106
105
  currentItemEndArrowhead: Arrowhead | null;
107
- currentItemLinearStrokeSharpness: ExcalidrawElement["strokeSharpness"];
106
+ currentItemRoundness: StrokeRoundness;
108
107
  viewBackgroundColor: string;
109
108
  scrollX: number;
110
109
  scrollY: number;