@zsviczian/excalidraw 0.17.6-7 → 0.17.6-9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zsviczian/excalidraw",
3
- "version": "0.17.6-7",
3
+ "version": "0.17.6-9",
4
4
  "main": "main.js",
5
5
  "types": "types/excalidraw/index.d.ts",
6
6
  "files": [
@@ -364,7 +364,10 @@ declare class App extends React.Component<AppProps, AppState> {
364
364
  duration?: number;
365
365
  } | null) => void;
366
366
  restoreFileFromShare: () => Promise<void>;
367
- /** adds supplied files to existing files in the appState */
367
+ /**
368
+ * adds supplied files to existing files in the appState.
369
+ * NOTE if file already exists in editor state, the file data is not updated
370
+ * */
368
371
  addFiles: ExcalidrawImperativeAPI["addFiles"];
369
372
  setMobileModeAllowed: ExcalidrawImperativeAPI["setMobileModeAllowed"];
370
373
  private debounceClearHighlightSearchResults;
@@ -373,6 +376,7 @@ declare class App extends React.Component<AppProps, AppState> {
373
376
  bringForward: ExcalidrawImperativeAPI["bringForward"];
374
377
  sendToBack: ExcalidrawImperativeAPI["sendToBack"];
375
378
  sendBackward: ExcalidrawImperativeAPI["sendBackward"];
379
+ private addMissingFiles;
376
380
  updateScene: <K extends keyof AppState>(sceneData: {
377
381
  elements?: SceneData["elements"];
378
382
  appState?: Pick<AppState, K> | null | undefined;
@@ -25,8 +25,11 @@ export declare const canvasToBlob: (canvas: HTMLCanvasElement | Promise<HTMLCanv
25
25
  /** generates SHA-1 digest from supplied file (if not supported, falls back
26
26
  to a 40-char base64 random id) */
27
27
  export declare const generateIdFromFile: (file: File) => Promise<FileId>;
28
+ /** async. For sync variant, use getDataURL_sync */
28
29
  export declare const getDataURL: (file: Blob | File) => Promise<DataURL>;
30
+ export declare const getDataURL_sync: (data: string | Uint8Array | ArrayBuffer, mimeType: ValueOf<typeof MIME_TYPES>) => DataURL;
29
31
  export declare const dataURLToFile: (dataURL: DataURL, filename?: string) => File;
32
+ export declare const dataURLToString: (dataURL: DataURL) => string;
30
33
  export declare const resizeImageFile: (file: File, opts: {
31
34
  /** undefined indicates auto */
32
35
  outputType?: (typeof MIME_TYPES)["jpg"];
@@ -1,10 +1,10 @@
1
- export declare const toByteString: (data: string | Uint8Array | ArrayBuffer) => Promise<string>;
1
+ export declare const toByteString: (data: string | Uint8Array | ArrayBuffer) => string;
2
2
  /**
3
3
  * @param isByteString set to true if already byte string to prevent bloat
4
4
  * due to reencoding
5
5
  */
6
- export declare const stringToBase64: (str: string, isByteString?: boolean) => Promise<string>;
7
- export declare const base64ToString: (base64: string, isByteString?: boolean) => Promise<string>;
6
+ export declare const stringToBase64: (str: string, isByteString?: boolean) => string;
7
+ export declare const base64ToString: (base64: string, isByteString?: boolean) => string;
8
8
  export declare const base64ToArrayBuffer: (base64: string) => ArrayBuffer;
9
9
  type EncodedData = {
10
10
  encoded: string;
@@ -21,8 +21,8 @@ export declare const encode: ({ text, compress, }: {
21
21
  text: string;
22
22
  /** defaults to `true`. If compression fails, falls back to bstring alone. */
23
23
  compress?: boolean | undefined;
24
- }) => Promise<EncodedData>;
25
- export declare const decode: (data: EncodedData) => Promise<string>;
24
+ }) => EncodedData;
25
+ export declare const decode: (data: EncodedData) => string;
26
26
  /**
27
27
  * The returned buffer has following format:
28
28
  * `[]` refers to a buffers wrapper (see `concatBuffers`)
@@ -9,7 +9,7 @@ export declare const encodePngMetadata: ({ blob, metadata, }: {
9
9
  export declare const decodePngMetadata: (blob: Blob) => Promise<string>;
10
10
  export declare const encodeSvgMetadata: ({ text }: {
11
11
  text: string;
12
- }) => Promise<string>;
12
+ }) => string;
13
13
  export declare const decodeSvgMetadata: ({ svg }: {
14
14
  svg: string;
15
- }) => Promise<string>;
15
+ }) => string;
@@ -29,4 +29,4 @@ export declare const updateImageCache: ({ fileIds, files, imageCache, }: {
29
29
  }>;
30
30
  export declare const getInitializedImageElements: (elements: readonly ExcalidrawElement[]) => InitializedExcalidrawImageElement[];
31
31
  export declare const isHTMLSVGElement: (node: Node | null) => node is SVGElement;
32
- export declare const normalizeSVG: (SVGString: string) => Promise<string>;
32
+ export declare const normalizeSVG: (SVGString: string) => string;
@@ -2,8 +2,6 @@ import type { ElementsMap, ExcalidrawElement, ExcalidrawElementType, ExcalidrawT
2
2
  import type { MaybeTransformHandleType } from "./transformHandles";
3
3
  import type { AppState } from "../types";
4
4
  import type { ExtractSetType } from "../utility-types";
5
- export declare const containsCJK: (text: string) => boolean;
6
- export declare const containsEmoji: (text: string) => boolean;
7
5
  export declare const normalizeText: (text: string) => string;
8
6
  export declare const redrawTextBoundingBox: (textElement: ExcalidrawTextElement, container: ExcalidrawElement | null, elementsMap: ElementsMap, informMutation?: boolean) => void;
9
7
  export declare const bindTextToShapeAfterDuplication: (newElements: ExcalidrawElement[], oldElements: ExcalidrawElement[], oldIdToDuplicatedId: Map<ExcalidrawElement["id"], ExcalidrawElement["id"]>) => void;
@@ -29,10 +27,22 @@ export declare const detectLineHeight: (textElement: ExcalidrawTextElement) => n
29
27
  */
30
28
  export declare const getLineHeightInPx: (fontSize: ExcalidrawTextElement["fontSize"], lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
31
29
  export declare const getApproxMinLineHeight: (fontSize: ExcalidrawTextElement["fontSize"], lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
30
+ /**
31
+ * @param forceAdvanceWidth use to force retrieve the "advance width" ~ `metrics.width`, instead of the actual boundind box width.
32
+ *
33
+ * > The advance width is the distance between the glyph's initial pen position and the next glyph's initial pen position.
34
+ *
35
+ * We need to use the advance width as that's the closest thing to the browser wrapping algo, hence using it for:
36
+ * - text wrapping
37
+ * - wysiwyg editor (+padding)
38
+ *
39
+ * Everything else should be based on the actual bounding box width.
40
+ *
41
+ * `Math.ceil` of the final width adds additional buffer which stabilizes slight wrapping incosistencies.
42
+ */
43
+ export declare const getLineWidth: (text: string, font: FontString, forceAdvanceWidth?: true) => number;
32
44
  export declare const getTextWidth: (text: string, font: FontString, forceAdvanceWidth?: true) => number;
33
45
  export declare const getTextHeight: (text: string, fontSize: number, lineHeight: ExcalidrawTextElement["lineHeight"]) => number;
34
- export declare const parseTokens: (line: string) => string[];
35
- export declare const wrapText: (text: string, font: FontString, maxWidth: number) => string;
36
46
  export declare const charWidth: {
37
47
  calculate: (char: string, font: FontString) => number;
38
48
  getCache: (font: FontString) => number[];
@@ -0,0 +1,13 @@
1
+ import type { FontString } from "./types";
2
+ /**
3
+ * Test if a given text contains any CJK characters (including symbols, punctuation, etc,).
4
+ */
5
+ export declare const containsCJK: (text: string) => boolean;
6
+ /**
7
+ * Breaks the line into the tokens based on the found line break opporutnities.
8
+ */
9
+ export declare const parseTokens: (line: string) => string[];
10
+ /**
11
+ * Wraps the original text into the lines based on the given width.
12
+ */
13
+ export declare const wrapText: (text: string, font: FontString, maxWidth: number) => string;
@@ -16,6 +16,10 @@ export declare class Fonts {
16
16
  }>;
17
17
  private readonly scene;
18
18
  constructor(scene: Scene);
19
+ /**
20
+ * Get all the font families for the given scene.
21
+ */
22
+ getSceneFamilies: () => number[];
19
23
  /**
20
24
  * if we load a (new) font, it's likely that text elements using it have
21
25
  * already been rendered using a fallback font. Thus, we want invalidate
@@ -27,21 +31,35 @@ export declare class Fonts {
27
31
  onLoaded: (fontFaces: readonly FontFace[]) => void;
28
32
  /**
29
33
  * Load font faces for a given scene and trigger scene update.
34
+ *
35
+ * FontFaceSet loadingdone event we listen on may not always
36
+ * fire (looking at you Safari), so on init we manually load all
37
+ * fonts and rerender scene text elements once done.
38
+ *
39
+ * For Safari we make sure to check against each loaded font face
40
+ * with the unique characters per family in the scene,
41
+ * otherwise fonts might remain unloaded.
30
42
  */
31
43
  loadSceneFonts: () => Promise<FontFace[]>;
32
- /**
33
- * Load all registered font faces.
34
- */
35
- static loadAllFonts: () => Promise<FontFace[]>;
36
44
  /**
37
45
  * Load font faces for passed elements - use when the scene is unavailable (i.e. export).
46
+ *
47
+ * For Safari we make sure to check against each loaded font face,
48
+ * with the unique characters per family in the elements
49
+ * otherwise fonts might remain unloaded.
38
50
  */
39
51
  static loadElementsFonts: (elements: readonly ExcalidrawElement[]) => Promise<FontFace[]>;
40
- static loadFontFaces(fontFamilies: Array<ExcalidrawTextElement["fontFamily"]>): Promise<FontFace[]>;
41
52
  /**
42
- * WARN: should be called just once on init, even across multiple instances.
53
+ * Load all registered font faces.
43
54
  */
44
- private static init;
55
+ static loadAllFonts: () => Promise<FontFace[]>;
56
+ /**
57
+ * Generate CSS @font-face declarations for the given elements.
58
+ */
59
+ static generateFontFaceDeclarations(elements: readonly ExcalidrawElement[]): Promise<string[]>;
60
+ static loadFontFaces(fontFamilies: Array<ExcalidrawTextElement["fontFamily"]>, charsPerFamily?: Record<number, Set<string>>): Promise<FontFace[]>;
61
+ private static fontFacesLoader;
62
+ private static fontFacesStylesGenerator;
45
63
  /**
46
64
  * Register a new font.
47
65
  *
@@ -63,11 +81,25 @@ export declare class Fonts {
63
81
  fontFaces: ExcalidrawFontFace[];
64
82
  }>;
65
83
  /**
66
- * Gets all the font families for the given scene.
84
+ * WARN: should be called just once on init, even across multiple instances.
85
+ */
86
+ private static init;
87
+ /**
88
+ * Get all the unique font families for the given elements.
89
+ */
90
+ static getUniqueFamilies(elements: ReadonlyArray<ExcalidrawElement>): Array<ExcalidrawTextElement["fontFamily"]>;
91
+ /**
92
+ * Get all the unique characters per font family for the given scene.
93
+ */
94
+ private static getCharsPerFamily;
95
+ /**
96
+ * Get characters for a given family.
97
+ */
98
+ private static getCharacters;
99
+ /**
100
+ * Get all registered font families.
67
101
  */
68
- getSceneFamilies: () => number[];
69
102
  private static getAllFamilies;
70
- static getElementsFamilies(elements: ReadonlyArray<ExcalidrawElement>): Array<ExcalidrawTextElement["fontFamily"]>;
71
103
  }
72
104
  /**
73
105
  * Calculates vertical offset for a text with alphabetic baseline.
@@ -25,5 +25,6 @@ export declare const exportToSvg: (elements: readonly NonDeletedExcalidrawElemen
25
25
  renderEmbeddables?: boolean;
26
26
  exportingFrame?: ExcalidrawFrameLikeElement | null;
27
27
  skipInliningFonts?: true;
28
+ reuseImages?: boolean;
28
29
  }) => Promise<SVGSVGElement>;
29
30
  export declare const getExportSize: (elements: readonly NonDeletedExcalidrawElement[], exportPadding: number, scale: number) => [number, number];
@@ -26,6 +26,13 @@ export type SVGRenderConfig = {
26
26
  canvasBackgroundColor: AppState["viewBackgroundColor"];
27
27
  frameColor?: AppState["frameColor"];
28
28
  embedsValidationStatus: EmbedsValidationStatus;
29
+ /**
30
+ * whether to attempt to reuse images as much as possible through symbols
31
+ * (reduces SVG size, but may be incompoatible with some SVG renderers)
32
+ *
33
+ * @default true
34
+ */
35
+ reuseImages: boolean;
29
36
  };
30
37
  export type InteractiveCanvasRenderConfig = {
31
38
  remoteSelectedElementIds: Map<ExcalidrawElement["id"], SocketId[]>;
@@ -77,6 +77,11 @@ export type BinaryFileData = {
77
77
  * Epoch timestamp in milliseconds.
78
78
  */
79
79
  lastRetrieved?: number;
80
+ /**
81
+ * indicates the version of the file. This can be used to determine whether
82
+ * the file dataURL has changed e.g. as part of restore due to schema update.
83
+ */
84
+ version?: number;
80
85
  };
81
86
  export type BinaryFileMetadata = Omit<BinaryFileData, "dataURL">;
82
87
  export type BinaryFiles = Record<ExcalidrawElement["id"], BinaryFileData>;
@@ -22,10 +22,11 @@ export declare const exportToBlob: (opts: ExportOpts & {
22
22
  quality?: number;
23
23
  exportPadding?: number;
24
24
  }) => Promise<Blob>;
25
- export declare const exportToSvg: ({ elements, appState, files, exportPadding, renderEmbeddables, exportingFrame, skipInliningFonts, }: Omit<ExportOpts, "getDimensions"> & {
25
+ export declare const exportToSvg: ({ elements, appState, files, exportPadding, renderEmbeddables, exportingFrame, skipInliningFonts, reuseImages, }: Omit<ExportOpts, "getDimensions"> & {
26
26
  exportPadding?: number | undefined;
27
27
  renderEmbeddables?: boolean | undefined;
28
28
  skipInliningFonts?: true | undefined;
29
+ reuseImages?: boolean | undefined;
29
30
  }) => Promise<SVGSVGElement>;
30
31
  export declare const exportToClipboard: (opts: ExportOpts & {
31
32
  mimeType?: string;
@@ -36,7 +37,8 @@ export { getCommonBoundingBox } from "../excalidraw/element/bounds";
36
37
  export { getMaximumGroups } from "../excalidraw/groups";
37
38
  export { intersectElementWithLine } from "../excalidraw/element/binding";
38
39
  export { determineFocusDistance } from "../excalidraw/element/binding";
39
- export { measureText, wrapText } from "../excalidraw/element/textElement";
40
+ export { measureText } from "../excalidraw/element/textElement";
41
+ export { wrapText } from "../excalidraw/element/textWrapping";
40
42
  export { getLineHeight } from "../excalidraw/fonts/index";
41
43
  export { getFontString, getFontFamilyString } from "../excalidraw/utils";
42
44
  export { getBoundTextMaxWidth } from "../excalidraw/element/textElement";