@excalidraw/excalidraw 0.14.2-38fc51b → 0.14.2-8338397

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 (36) hide show
  1. package/dist/excalidraw.development.js +49 -39
  2. package/dist/excalidraw.production.min.js +1 -1
  3. package/package.json +2 -2
  4. package/types/actions/actionAddToLibrary.d.ts +2 -1
  5. package/types/actions/actionBoundText.d.ts +25 -8
  6. package/types/actions/actionCanvas.d.ts +9 -9
  7. package/types/actions/actionClipboard.d.ts +3 -3
  8. package/types/actions/actionDeleteSelected.d.ts +3 -3
  9. package/types/actions/actionDuplicateSelection.d.ts +1 -1
  10. package/types/actions/actionExport.d.ts +8 -8
  11. package/types/actions/actionFinalize.d.ts +2 -2
  12. package/types/actions/actionLinearEditor.d.ts +2 -1
  13. package/types/actions/actionMenu.d.ts +3 -3
  14. package/types/actions/actionProperties.d.ts +13 -13
  15. package/types/actions/actionStyles.d.ts +1 -1
  16. package/types/actions/actionToggleGridMode.d.ts +1 -1
  17. package/types/actions/actionToggleLock.d.ts +1 -1
  18. package/types/actions/actionToggleStats.d.ts +1 -1
  19. package/types/actions/actionToggleViewMode.d.ts +1 -1
  20. package/types/actions/actionToggleZenMode.d.ts +1 -1
  21. package/types/actions/shortcuts.d.ts +1 -0
  22. package/types/actions/types.d.ts +2 -1
  23. package/types/components/BraveMeasureTextError.d.ts +2 -0
  24. package/types/components/ErrorDialog.d.ts +3 -2
  25. package/types/components/HelpButton.d.ts +0 -1
  26. package/types/constants.d.ts +1 -0
  27. package/types/data/blob.d.ts +1 -0
  28. package/types/element/Hyperlink.d.ts +1 -1
  29. package/types/element/linearElementEditor.d.ts +1 -1
  30. package/types/element/mutateElement.d.ts +1 -0
  31. package/types/element/newElement.d.ts +2 -0
  32. package/types/element/textElement.d.ts +27 -7
  33. package/types/element/typeChecks.d.ts +1 -0
  34. package/types/element/types.d.ts +8 -0
  35. package/types/types.d.ts +3 -2
  36. package/types/utility-types.d.ts +22 -0
@@ -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,8 +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;
64
+ declare const VALID_CONTAINER_TYPES: Set<string>;
50
65
  export declare const isValidTextContainer: (element: ExcalidrawElement) => boolean;
51
- export declare const computeContainerHeightForBoundText: (container: NonDeletedExcalidrawElement, boundTextElementHeight: number) => number;
66
+ export declare const computeContainerDimensionForBoundText: (dimension: number, containerType: ExtractSetType<typeof VALID_CONTAINER_TYPES>) => number;
52
67
  export declare const getMaxContainerWidth: (container: ExcalidrawElement) => number;
53
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
+ };
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;