@excalidraw/excalidraw 0.14.2-cef6094 → 0.14.2-f8e65bb

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 (38) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/dist/excalidraw.development.js +44 -34
  3. package/dist/excalidraw.production.min.js +1 -1
  4. package/package.json +2 -2
  5. package/types/actions/actionAddToLibrary.d.ts +2 -1
  6. package/types/actions/actionBoundText.d.ts +2 -1
  7. package/types/actions/actionCanvas.d.ts +115 -9
  8. package/types/actions/actionClipboard.d.ts +3 -3
  9. package/types/actions/actionDeleteSelected.d.ts +3 -3
  10. package/types/actions/actionDuplicateSelection.d.ts +1 -1
  11. package/types/actions/actionExport.d.ts +8 -8
  12. package/types/actions/actionFinalize.d.ts +2 -2
  13. package/types/actions/actionLinearEditor.d.ts +2 -1
  14. package/types/actions/actionMenu.d.ts +3 -3
  15. package/types/actions/actionProperties.d.ts +13 -13
  16. package/types/actions/actionStyles.d.ts +1 -1
  17. package/types/actions/actionToggleGridMode.d.ts +1 -1
  18. package/types/actions/actionToggleLock.d.ts +1 -1
  19. package/types/actions/actionToggleStats.d.ts +1 -1
  20. package/types/actions/actionToggleViewMode.d.ts +1 -1
  21. package/types/actions/actionToggleZenMode.d.ts +1 -1
  22. package/types/actions/shortcuts.d.ts +1 -0
  23. package/types/actions/types.d.ts +1 -0
  24. package/types/components/App.d.ts +12 -1
  25. package/types/components/BraveMeasureTextError.d.ts +2 -0
  26. package/types/components/ErrorDialog.d.ts +3 -2
  27. package/types/constants.d.ts +1 -0
  28. package/types/data/blob.d.ts +1 -0
  29. package/types/element/Hyperlink.d.ts +1 -1
  30. package/types/element/linearElementEditor.d.ts +1 -1
  31. package/types/element/mutateElement.d.ts +1 -0
  32. package/types/element/newElement.d.ts +2 -0
  33. package/types/element/textElement.d.ts +24 -6
  34. package/types/element/typeChecks.d.ts +1 -0
  35. package/types/element/types.d.ts +8 -0
  36. package/types/types.d.ts +3 -2
  37. package/types/utility-types.d.ts +22 -0
  38. package/types/utils.d.ts +20 -1
@@ -93,7 +93,18 @@ declare class App extends React.Component<AppProps, AppState> {
93
93
  toggleLock: (source?: "keyboard" | "ui") => void;
94
94
  togglePenMode: () => void;
95
95
  onHandToolToggle: () => void;
96
- scrollToContent: (target?: ExcalidrawElement | readonly ExcalidrawElement[]) => void;
96
+ /**
97
+ * Zooms on canvas viewport center
98
+ */
99
+ zoomCanvas: (value: number) => void;
100
+ private cancelInProgresAnimation;
101
+ scrollToContent: (target?: ExcalidrawElement | readonly ExcalidrawElement[], opts?: {
102
+ fitToContent?: boolean;
103
+ animate?: boolean;
104
+ duration?: number;
105
+ }) => void;
106
+ /** use when changing scrollX/scrollY/zoom based on user interaction */
107
+ private translateCanvas;
97
108
  setToast: (toast: {
98
109
  message: string;
99
110
  closable?: boolean;
@@ -0,0 +1,2 @@
1
+ declare const BraveMeasureTextError: () => JSX.Element;
2
+ export default BraveMeasureTextError;
@@ -1,4 +1,5 @@
1
- export declare const ErrorDialog: ({ message, onClose, }: {
2
- message: string;
1
+ import React from "react";
2
+ export declare const ErrorDialog: ({ children, onClose, }: {
3
+ children?: React.ReactNode;
3
4
  onClose?: (() => void) | undefined;
4
5
  }) => JSX.Element;
@@ -6,6 +6,7 @@ export declare const isAndroid: boolean;
6
6
  export declare const isFirefox: boolean;
7
7
  export declare const isChrome: boolean;
8
8
  export declare const isSafari: boolean;
9
+ export declare const isBrave: () => boolean;
9
10
  export declare const APP_NAME = "Excalidraw";
10
11
  export declare const DRAGGING_THRESHOLD = 10;
11
12
  export declare const LINE_CONFIRM_THRESHOLD = 8;
@@ -1,6 +1,7 @@
1
1
  import { ALLOWED_IMAGE_MIME_TYPES, MIME_TYPES } from "../constants";
2
2
  import { ExcalidrawElement, FileId } from "../element/types";
3
3
  import { AppState, DataURL, LibraryItem } from "../types";
4
+ import { ValueOf } from "../utility-types";
4
5
  import { FileSystemHandle } from "./filesystem";
5
6
  import { ImportedLibraryData } from "./types";
6
7
  export declare const getMimeType: (blob: Blob | string) => string;
@@ -25,7 +25,7 @@ export declare const actionLink: {
25
25
  } | null;
26
26
  showWelcomeScreen: boolean;
27
27
  isLoading: boolean;
28
- errorMessage: string | null;
28
+ errorMessage: import("react").ReactNode;
29
29
  draggingElement: NonDeletedExcalidrawElement | null;
30
30
  resizingElement: NonDeletedExcalidrawElement | null;
31
31
  multiElement: import("./types").NonDeleted<import("./types").ExcalidrawLinearElement> | null;
@@ -130,7 +130,7 @@ export declare class LinearElementEditor {
130
130
  } | null;
131
131
  showWelcomeScreen: boolean;
132
132
  isLoading: boolean;
133
- errorMessage: string | null;
133
+ errorMessage: import("react").ReactNode;
134
134
  draggingElement: import("./types").NonDeletedExcalidrawElement | null;
135
135
  resizingElement: import("./types").NonDeletedExcalidrawElement | null;
136
136
  multiElement: NonDeleted<ExcalidrawLinearElement> | null;
@@ -1,4 +1,5 @@
1
1
  import { ExcalidrawElement } from "./types";
2
+ import { Mutable } from "../utility-types";
2
3
  declare type ElementUpdate<TElement extends ExcalidrawElement> = Omit<Partial<TElement>, "id" | "version" | "versionNonce">;
3
4
  export declare const mutateElement: <TElement extends Mutable<ExcalidrawElement>>(element: TElement, updates: ElementUpdate<TElement>, informMutation?: boolean) => TElement;
4
5
  export declare const newElementWith: <TElement extends ExcalidrawElement>(element: TElement, updates: ElementUpdate<TElement>) => TElement;
@@ -1,5 +1,6 @@
1
1
  import { ExcalidrawElement, ExcalidrawImageElement, ExcalidrawTextElement, ExcalidrawLinearElement, ExcalidrawGenericElement, NonDeleted, TextAlign, GroupId, VerticalAlign, Arrowhead, ExcalidrawFreeDrawElement, FontFamilyValues, ExcalidrawTextContainer } from "../element/types";
2
2
  import { AppState } from "../types";
3
+ import { MarkOptional, Mutable } from "../utility-types";
3
4
  declare type ElementConstructorOpts = MarkOptional<Omit<ExcalidrawGenericElement, "id" | "type" | "isDeleted" | "updated">, "width" | "height" | "angle" | "groupIds" | "boundElements" | "seed" | "version" | "versionNonce" | "link">;
4
5
  export declare const newElement: (opts: {
5
6
  type: ExcalidrawGenericElement["type"];
@@ -11,6 +12,7 @@ export declare const newTextElement: (opts: {
11
12
  textAlign: TextAlign;
12
13
  verticalAlign: VerticalAlign;
13
14
  containerId?: ExcalidrawTextContainer["id"];
15
+ lineHeight?: ExcalidrawTextElement["lineHeight"];
14
16
  } & ElementConstructorOpts) => NonDeleted<ExcalidrawTextElement>;
15
17
  export declare const refreshTextDimensions: (textElement: ExcalidrawTextElement, text?: string) => {
16
18
  x: number;
@@ -1,24 +1,37 @@
1
- import { ExcalidrawElement, ExcalidrawTextContainer, ExcalidrawTextElement, ExcalidrawTextElementWithContainer, FontString, NonDeletedExcalidrawElement } from "./types";
1
+ import { ExcalidrawElement, ExcalidrawTextContainer, ExcalidrawTextElement, ExcalidrawTextElementWithContainer, FontFamilyValues, FontString, NonDeletedExcalidrawElement } from "./types";
2
2
  import { MaybeTransformHandleType } from "./transformHandles";
3
3
  import { AppState } from "../types";
4
+ import { ExtractSetType } from "../utility-types";
4
5
  export declare const normalizeText: (text: string) => string;
6
+ export declare const splitIntoLines: (text: string) => string[];
5
7
  export declare const redrawTextBoundingBox: (textElement: ExcalidrawTextElement, container: ExcalidrawElement | null) => void;
6
8
  export declare const bindTextToShapeAfterDuplication: (sceneElements: ExcalidrawElement[], oldElements: ExcalidrawElement[], oldIdToDuplicatedId: Map<ExcalidrawElement["id"], ExcalidrawElement["id"]>) => void;
7
9
  export declare const handleBindTextResize: (container: NonDeletedExcalidrawElement, transformHandleType: MaybeTransformHandleType) => void;
8
- export declare const measureText: (text: string, font: FontString) => {
10
+ export declare const measureText: (text: string, font: FontString, lineHeight: ExcalidrawTextElement["lineHeight"]) => {
9
11
  width: number;
10
12
  height: number;
11
13
  };
12
- export declare const getApproxLineHeight: (font: FontString) => number;
14
+ /**
15
+ * To get unitless line-height (if unknown) we can calculate it by dividing
16
+ * height-per-line by fontSize.
17
+ */
18
+ export declare const detectLineHeight: (textElement: ExcalidrawTextElement) => number & {
19
+ _brand: "unitlessLineHeight";
20
+ };
21
+ /**
22
+ * We calculate the line height from the font size and the unitless line height,
23
+ * aligning with the W3C spec.
24
+ */
25
+ export declare const getLineHeightInPx: (fontSize: ExcalidrawTextElement["fontSize"], lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
26
+ export declare const getApproxMinLineHeight: (fontSize: ExcalidrawTextElement["fontSize"], lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
13
27
  export declare const getTextWidth: (text: string, font: FontString) => number;
14
- export declare const getTextHeight: (text: string, font: FontString) => number;
28
+ export declare const getTextHeight: (text: string, fontSize: number, lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
15
29
  export declare const wrapText: (text: string, font: FontString, maxWidth: number) => string;
16
30
  export declare const charWidth: {
17
31
  calculate: (char: string, font: FontString) => number;
18
32
  getCache: (font: FontString) => number[];
19
33
  };
20
- export declare const getApproxMinLineWidth: (font: FontString) => number;
21
- export declare const getApproxMinLineHeight: (font: FontString) => number;
34
+ export declare const getApproxMinLineWidth: (font: FontString, lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
22
35
  export declare const getMinCharWidth: (font: FontString) => number;
23
36
  export declare const getMaxCharWidth: (font: FontString) => number;
24
37
  export declare const getApproxCharsToFitInWidth: (font: FontString, width: number) => number;
@@ -46,10 +59,15 @@ export declare const getBoundTextElementPosition: (container: ExcalidrawElement,
46
59
  y: number;
47
60
  } | undefined;
48
61
  export declare const shouldAllowVerticalAlign: (selectedElements: NonDeletedExcalidrawElement[]) => boolean;
62
+ export declare const suppportsHorizontalAlign: (selectedElements: NonDeletedExcalidrawElement[]) => boolean;
49
63
  export declare const getTextBindableContainerAtPosition: (elements: readonly ExcalidrawElement[], appState: AppState, x: number, y: number) => ExcalidrawTextContainer | null;
50
64
  declare const VALID_CONTAINER_TYPES: Set<string>;
51
65
  export declare const isValidTextContainer: (element: ExcalidrawElement) => boolean;
52
66
  export declare const computeContainerDimensionForBoundText: (dimension: number, containerType: ExtractSetType<typeof VALID_CONTAINER_TYPES>) => number;
53
67
  export declare const getMaxContainerWidth: (container: ExcalidrawElement) => number;
54
68
  export declare const getMaxContainerHeight: (container: ExcalidrawElement) => number;
69
+ export declare const isMeasureTextSupported: () => boolean;
70
+ export declare const getDefaultLineHeight: (fontFamily: FontFamilyValues) => number & {
71
+ _brand: "unitlessLineHeight";
72
+ };
55
73
  export {};
@@ -1,4 +1,5 @@
1
1
  import { AppState } from "../types";
2
+ import { MarkNonNullable } from "../utility-types";
2
3
  import { ExcalidrawElement, ExcalidrawTextElement, ExcalidrawLinearElement, ExcalidrawBindableElement, ExcalidrawGenericElement, ExcalidrawFreeDrawElement, InitializedExcalidrawImageElement, ExcalidrawImageElement, ExcalidrawTextElementWithContainer, ExcalidrawTextContainer, RoundnessType } from "./types";
3
4
  export declare const isGenericElement: (element: ExcalidrawElement | null) => element is ExcalidrawGenericElement;
4
5
  export declare const isInitializedImageElement: (element: ExcalidrawElement | null) => element is InitializedExcalidrawImageElement;
@@ -1,5 +1,6 @@
1
1
  import { Point } from "../types";
2
2
  import { FONT_FAMILY, ROUNDNESS, TEXT_ALIGN, THEME, VERTICAL_ALIGN } from "../constants";
3
+ import { MarkNonNullable, ValueOf } from "../utility-types";
3
4
  export declare type ChartType = "bar" | "line";
4
5
  export declare type FillStyle = "hachure" | "cross-hatch" | "solid";
5
6
  export declare type FontFamilyKeys = keyof typeof FONT_FAMILY;
@@ -103,6 +104,13 @@ export declare type ExcalidrawTextElement = _ExcalidrawElementBase & Readonly<{
103
104
  verticalAlign: VerticalAlign;
104
105
  containerId: ExcalidrawGenericElement["id"] | null;
105
106
  originalText: string;
107
+ /**
108
+ * Unitless line height (aligned to W3C). To get line height in px, multiply
109
+ * with font size (using `getLineHeightInPx` helper).
110
+ */
111
+ lineHeight: number & {
112
+ _brand: "unitlessLineHeight";
113
+ };
106
114
  }>;
107
115
  export declare type ExcalidrawBindableElement = ExcalidrawRectangleElement | ExcalidrawDiamondElement | ExcalidrawEllipseElement | ExcalidrawTextElement | ExcalidrawImageElement;
108
116
  export declare type ExcalidrawTextContainer = ExcalidrawRectangleElement | ExcalidrawDiamondElement | ExcalidrawEllipseElement | ExcalidrawImageElement | ExcalidrawArrowElement;
package/types/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, ExcalidrawImageElement, Theme, StrokeRoundness } from "./element/types";
3
2
  import { SHAPES } from "./shapes";
4
3
  import { Point as RoughPoint } from "roughjs/bin/geometry";
@@ -16,6 +15,8 @@ import Library from "./data/library";
16
15
  import type { FileSystemHandle } from "./data/filesystem";
17
16
  import type { ALLOWED_IMAGE_MIME_TYPES, MIME_TYPES } from "./constants";
18
17
  import { ContextMenuItems } from "./components/ContextMenu";
18
+ import { Merge, ForwardRef } from "./utility-types";
19
+ import React from "react";
19
20
  export declare type Point = Readonly<RoughPoint>;
20
21
  export declare type Collaborator = {
21
22
  pointer?: {
@@ -70,7 +71,7 @@ export declare type AppState = {
70
71
  } | null;
71
72
  showWelcomeScreen: boolean;
72
73
  isLoading: boolean;
73
- errorMessage: string | null;
74
+ errorMessage: React.ReactNode;
74
75
  draggingElement: NonDeletedExcalidrawElement | null;
75
76
  resizingElement: NonDeletedExcalidrawElement | null;
76
77
  multiElement: NonDeleted<ExcalidrawLinearElement> | null;
@@ -0,0 +1,22 @@
1
+ /// <reference types="react" />
2
+ export declare type Mutable<T> = {
3
+ -readonly [P in keyof T]: T[P];
4
+ };
5
+ export declare type ValueOf<T> = T[keyof T];
6
+ export declare type Merge<M, N> = Omit<M, keyof N> & N;
7
+ /** utility type to assert that the second type is a subtype of the first type.
8
+ * Returns the subtype. */
9
+ export declare type SubtypeOf<Supertype, Subtype extends Supertype> = Subtype;
10
+ export declare type ResolutionType<T extends (...args: any) => any> = T extends (...args: any) => Promise<infer R> ? R : any;
11
+ export declare type MarkOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
12
+ export declare type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> & Required<Pick<T, RK>>;
13
+ export declare type MarkNonNullable<T, K extends keyof T> = {
14
+ [P in K]-?: P extends K ? NonNullable<T[P]> : T[P];
15
+ } & {
16
+ [P in keyof T]: T[P];
17
+ };
18
+ export declare type NonOptional<T> = Exclude<T, undefined>;
19
+ export declare type SignatureType<T> = T extends (...args: infer R) => any ? R : never;
20
+ export declare type CallableType<T extends (...args: any[]) => any> = (...args: SignatureType<T>) => ReturnType<T>;
21
+ export declare type ForwardRef<T, P = any> = Parameters<CallableType<React.ForwardRefRenderFunction<T, P>>>[1];
22
+ export declare type ExtractSetType<T extends Set<any>> = T extends Set<infer U> ? U : never;
package/types/utils.d.ts CHANGED
@@ -28,6 +28,26 @@ export declare const throttleRAF: <T extends any[]>(fn: (...args: T) => void, op
28
28
  flush(): void;
29
29
  cancel(): void;
30
30
  };
31
+ /**
32
+ * Compute new values based on the same ease function and trigger the
33
+ * callback through a requestAnimationFrame call
34
+ *
35
+ * use `opts` to define a duration and/or an easeFn
36
+ *
37
+ * for example:
38
+ * ```ts
39
+ * easeToValuesRAF([10, 20, 10], [0, 0, 0], (a, b, c) => setState(a,b, c))
40
+ * ```
41
+ *
42
+ * @param fromValues The initial values, must be numeric
43
+ * @param toValues The destination values, must also be numeric
44
+ * @param callback The callback receiving the values
45
+ * @param opts default to 250ms duration and the easeOut function
46
+ */
47
+ export declare const easeToValuesRAF: (fromValues: number[], toValues: number[], callback: (...values: number[]) => void, opts?: {
48
+ duration?: number | undefined;
49
+ easeFn?: ((value: number) => number) | undefined;
50
+ } | undefined) => () => void;
31
51
  export declare const chunk: <T extends unknown>(array: readonly T[], size: number) => T[][];
32
52
  export declare const selectNode: (node: Element) => void;
33
53
  export declare const removeSelection: () => void;
@@ -128,7 +148,6 @@ export declare const arrayToMapWithIndex: <T extends {
128
148
  id: string;
129
149
  }>(elements: readonly T[]) => Map<string, [element: T, index: number]>;
130
150
  export declare const isTestEnv: () => boolean;
131
- export declare const isProdEnv: () => boolean;
132
151
  export declare const wrapEvent: <T extends Event>(name: EVENT, nativeEvent: T) => CustomEvent<{
133
152
  nativeEvent: T;
134
153
  }>;