@dwelle/excalidraw 0.3.64 → 0.3.67

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/CHANGELOG.md CHANGED
@@ -17,6 +17,24 @@ Please add the latest change on the top under the correct section.
17
17
 
18
18
  #### Features
19
19
 
20
+ - Export API to [set](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#setCursor) and [reset](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#resetCursor) mouse cursor on the canvas [#5215](https://github.com/excalidraw/excalidraw/pull/5215).
21
+
22
+ - Export [`sceneCoordsToViewportCoords`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onPointerDown) and [`viewportCoordsToSceneCoords`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onPointerDown) utilities [#5187](https://github.com/excalidraw/excalidraw/pull/5187).
23
+
24
+ - Added [`useHandleLibrary`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#useHandleLibrary) hook to automatically handle importing of libraries when `#addLibrary` URL hash key is present, and potentially for initializing library as well [#5115](https://github.com/excalidraw/excalidraw/pull/5115).
25
+
26
+ Also added [`parseLibraryTokensFromUrl`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#parseLibraryTokensFromUrl) to help in manually importing library from URL if desired.
27
+
28
+ ##### BREAKING CHANGE
29
+
30
+ - Libraries are no longer automatically initialized from URL when `#addLibrary` hash key is present. Host apps now need to handle this themselves with the help of either of the above APIs (`useHandleLibrary` is recommended).
31
+
32
+ - Added [`updateLibrary`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#updateLibrary) API to update (replace/merge) the library [#5115](https://github.com/excalidraw/excalidraw/pull/5115).
33
+
34
+ ##### BREAKING CHANGE
35
+
36
+ - `updateScene` API no longer supports passing `libraryItems`. Instead, use the `updateLibrary` API.
37
+
20
38
  - Add support for integrating custom elements [#5164](https://github.com/excalidraw/excalidraw/pull/5164).
21
39
 
22
40
  - Add [`onPointerDown`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onPointerDown) callback which gets triggered on pointer down events.
@@ -25,7 +43,7 @@ Please add the latest change on the top under the correct section.
25
43
 
26
44
  - Exported [`loadSceneOrLibraryFromBlob`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#loadSceneOrLibraryFromBlob) function [#5057](https://github.com/excalidraw/excalidraw/pull/5057).
27
45
  - Export [`MIME_TYPES`](https://github.com/excalidraw/excalidraw/blob/master/src/constants.ts#L92) supported by Excalidraw [#5135](https://github.com/excalidraw/excalidraw/pull/5135).
28
- - Support [`src`](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L50) for collaborators. Now onwards host can pass `src` to render the customized avatar for collaborators [#5114](https://github.com/excalidraw/excalidraw/pull/5114).
46
+ - Support [`avatarUrl`](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L50) for collaborators. Now onwards host can pass `avatarUrl` to render the customized avatar for collaborators [#5114](https://github.com/excalidraw/excalidraw/pull/5114), renamed in [#5177](https://github.com/excalidraw/excalidraw/pull/5177).
29
47
  - Support `libraryItems` argument in `initialData.libraryItems` and `updateScene({ libraryItems })` to be a Promise resolving to `LibraryItems`, and support functional update of `libraryItems` in [`updateScene({ libraryItems })`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#updateScene). [#5101](https://github.com/excalidraw/excalidraw/pull/5101).
30
48
  - Expose util [`mergeLibraryItems`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#mergeLibraryItems) [#5101](https://github.com/excalidraw/excalidraw/pull/5101).
31
49
  - Expose util [`exportToClipboard`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#exportToClipboard) which allows to copy the scene contents to clipboard as `svg`, `png` or `json` [#5103](https://github.com/excalidraw/excalidraw/pull/5103).
package/README_NEXT.md CHANGED
@@ -383,7 +383,7 @@ For a complete list of variables, check [theme.scss](https://github.com/excalidr
383
383
  | Name | Type | Default | Description |
384
384
  | --- | --- | --- | --- |
385
385
  | [`onChange`](#onChange) | Function | | This callback is triggered whenever the component updates due to any change. This callback will receive the excalidraw elements and the current app state. |
386
- | [`initialData`](#initialData) | <pre>{elements?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a>, appState?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState<a> } </pre> | null | The initial data with which app loads. |
386
+ | [`initialData`](#initialData) | <pre>{elements?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a>, appState?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState<a> } </pre> | null | The initial data with which app loads. |
387
387
  | [`ref`](#ref) | [`createRef`](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) &#124; [`useRef`](https://reactjs.org/docs/hooks-reference.html#useref) &#124; [`callbackRef`](https://reactjs.org/docs/refs-and-the-dom.html#callback-refs) &#124; <pre>{ current: { readyPromise: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/utils.ts#L317">resolvablePromise</a> } }</pre> | | Ref to be passed to Excalidraw |
388
388
  | [`onCollabButtonClick`](#onCollabButtonClick) | Function | | Callback to be triggered when the collab button is clicked |
389
389
  | [`isCollaborating`](#isCollaborating) | `boolean` | | This implies if the app is in collaboration mode |
@@ -423,7 +423,7 @@ Every time component updates, this callback if passed will get triggered and has
423
423
 
424
424
  1.`excalidrawElements`: Array of [excalidrawElements](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106) in the scene.
425
425
 
426
- 2.`appState`: [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66) of the scene.
426
+ 2.`appState`: [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79) of the scene.
427
427
 
428
428
  3. `files`: The [`BinaryFiles`]([BinaryFiles](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64) which are added to the scene.
429
429
 
@@ -436,7 +436,7 @@ This helps to load Excalidraw with `initialData`. It must be an object or a [pro
436
436
  | Name | Type | Description |
437
437
  | --- | --- | --- |
438
438
  | `elements` | [ExcalidrawElement[]](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106) | The elements with which Excalidraw should be mounted. |
439
- | `appState` | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66) | The App state with which Excalidraw should be mounted. |
439
+ | `appState` | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79) | The App state with which Excalidraw should be mounted. |
440
440
  | `scrollToContent` | boolean | This attribute implies whether to scroll to the nearest element to center once Excalidraw is mounted. By default, it will not scroll the nearest element to the center. Make sure you pass `initialData.appState.scrollX` and `initialData.appState.scrollY` when `scrollToContent` is false so that scroll positions are retained |
441
441
  | `libraryItems` | [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200) &#124; Promise<[LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200)> | This library items with which Excalidraw should be mounted. |
442
442
  | `files` | [BinaryFiles](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64) | The files added to the scene. |
@@ -480,20 +480,23 @@ You can pass a `ref` when you want to access some excalidraw APIs. We expose the
480
480
  | --- | --- | --- |
481
481
  | ready | `boolean` | This is set to true once Excalidraw is rendered |
482
482
  | readyPromise | [resolvablePromise](https://github.com/excalidraw/excalidraw/blob/master/src/utils.ts#L317) | This promise will be resolved with the api once excalidraw has rendered. This will be helpful when you want do some action on the host app once this promise resolves. For this to work you will have to pass ref as shown [here](#readyPromise) |
483
- | [updateScene](#updateScene) | <pre>(scene: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L207">sceneData</a>) => void </pre> | updates the scene with the sceneData |
484
- | [addFiles](#addFiles) | <pre>(files: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts">BinaryFileData</a>) => void </pre> | add files data to the appState |
483
+ | [updateScene](#updateScene) | <code>(scene: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L207">sceneData</a>) => void </code> | updates the scene with the sceneData |
484
+ | [updateLibrary](#updateLibrary) | <code>(<a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/library.ts#L136">opts</a>) => Promise<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>> </code> | updates the scene with the sceneData |
485
+ | [addFiles](#addFiles) | <code>(files: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts">BinaryFileData</a>) => void </code> | add files data to the appState |
485
486
  | resetScene | `({ resetLoadingState: boolean }) => void` | Resets the scene. If `resetLoadingState` is passed as true then it will also force set the loading state to false. |
486
- | getSceneElementsIncludingDeleted | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a></pre> | Returns all the elements including the deleted in the scene |
487
- | getSceneElements | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a></pre> | Returns all the elements excluding the deleted in the scene |
488
- | getAppState | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a></pre> | Returns current appState |
487
+ | getSceneElementsIncludingDeleted | <code> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a></code> | Returns all the elements including the deleted in the scene |
488
+ | getSceneElements | <code> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a></code> | Returns all the elements excluding the deleted in the scene |
489
+ | getAppState | <code> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a></code> | Returns current appState |
489
490
  | history | `{ clear: () => void }` | This is the history API. `history.clear()` will clear the history |
490
- | scrollToContent | <pre> (target?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement</a> &#124; <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement</a>[]) => void </pre> | Scroll the nearest element out of the elements supplied to the center. Defaults to the elements on the scene. |
491
+ | scrollToContent | <code> (target?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement</a> &#124; <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement</a>[]) => void </code> | Scroll the nearest element out of the elements supplied to the center. Defaults to the elements on the scene. |
491
492
  | refresh | `() => void` | Updates the offsets for the Excalidraw component so that the coordinates are computed correctly (for example the cursor position). You don't have to call this when the position is changed on page scroll or when the excalidraw container resizes (we handle that ourselves). For any other cases if the position of excalidraw is updated (example due to scroll on parent container and not page scroll) you should call this API. |
492
493
  | [importLibrary](#importlibrary) | `(url: string, token?: string) => void` | Imports library from given URL |
493
494
  | setToastMessage | `(message: string) => void` | This API can be used to show the toast with custom message. |
494
495
  | [id](#id) | string | Unique ID for the excalidraw component. |
495
- | [getFiles](#getFiles) | <pre>() => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64">files</a> </pre> | This API can be used to get the files present in the scene. It may contain files that aren't referenced by any element, so if you're persisting the files to a storage, you should compare them against stored elements. |
496
- | [setActiveTool](#setActiveTool) | <pre>(tool: { type: typeof <a href="https://github.com/excalidraw/excalidraw/blob/master/src/shapes.tsx#L4">SHAPES</a>[number]["value"] &#124; "eraser" } &#124; { type: "custom"; customType: string }) => void</pre> | This API can be used to set the active tool |
496
+ | [getFiles](#getFiles) | <code>() => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64">files</a> </code> | This API can be used to get the files present in the scene. It may contain files that aren't referenced by any element, so if you're persisting the files to a storage, you should compare them against stored elements. |
497
+ | [setActiveTool](#setActiveTool) | <code>(tool: { type: typeof <a href="https://github.com/excalidraw/excalidraw/blob/master/src/shapes.tsx#L4">SHAPES</a>[number]["value"] &#124; "eraser" } &#124; { type: "custom"; customType: string }) => void</code> | This API can be used to set the active tool |
498
+ | [setCursor](#setCursor) | <code>(cursor: string) => void </code> | This API can be used to set customise the mouse cursor on the canvas |
499
+ | [resetCursor](#resetCursor) | <code>() => void </code> | This API can be used to reset to default mouse cursor on the canvas |
497
500
 
498
501
  #### `readyPromise`
499
502
 
@@ -519,6 +522,28 @@ You can use this function to update the scene with the sceneData. It accepts the
519
522
  | `commitToHistory` | `boolean` | Implies if the `history (undo/redo)` should be recorded. Defaults to `false`. |
520
523
  | `libraryItems` | [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200) &#124; Promise<[LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200)> &#124; ((currentItems: [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200)>) => [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200) &#124; Promise<[LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200)>) | The `libraryItems` to be update in the scene. |
521
524
 
525
+ ### `updateLibrary`
526
+
527
+ <pre>
528
+ (opts: {
529
+ libraryItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L224">LibraryItemsSource</a>;
530
+ merge?: boolean;
531
+ prompt?: boolean;
532
+ openLibraryMenu?: boolean;
533
+ defaultStatus?: "unpublished" | "published";
534
+ }) => Promise<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>>
535
+ </pre>
536
+
537
+ You can use this function to update the library. It accepts the below attributes.
538
+
539
+ | Name | Type | Default | Description |
540
+ | --- | --- | --- | --- |
541
+ | `libraryItems` | | [LibraryItems](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L224) | The `libraryItems` to be replaced/merged with current library |
542
+ | `merge` | boolean | `false` | Whether to merge with existing library items. |
543
+ | `prompt` | boolean | `false` | Whether to prompt user for confirmation. |
544
+ | `openLibraryMenu` | boolean | `false` | Whether to open the library menu before importing. |
545
+ | `defaultStatus` | <code>"unpublished" &#124; "published"</code> | `"unpublished"` | Default library item's `status` if not present. |
546
+
522
547
  ### `addFiles`
523
548
 
524
549
  <pre>(files: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts">BinaryFileData</a>) => void </pre>
@@ -552,7 +577,7 @@ This callback is triggered when mouse pointer is updated.
552
577
  ```
553
578
 
554
579
  1. `exportedElements`: An array of [non deleted elements](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L87) which needs to be exported.
555
- 2. `appState`: [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66) of the scene.
580
+ 2. `appState`: [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79) of the scene.
556
581
  3. `canvas`: The `HTMLCanvasElement` of the scene.
557
582
 
558
583
  #### `langCode`
@@ -571,7 +596,7 @@ import { defaultLang, languages } from "@excalidraw/excalidraw-next";
571
596
  #### `renderTopRightUI`
572
597
 
573
598
  <pre>
574
- (isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>) => JSX
599
+ (isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>) => JSX
575
600
  </pre>
576
601
 
577
602
  A function returning JSX to render custom UI in the top right corner of the app.
@@ -579,7 +604,7 @@ A function returning JSX to render custom UI in the top right corner of the app.
579
604
  #### `renderFooter`
580
605
 
581
606
  <pre>
582
- (isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>) => JSX
607
+ (isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>) => JSX
583
608
  </pre>
584
609
 
585
610
  A function returning JSX to render custom UI footer. For example, you can use this to render a language picker that was previously being rendered by Excalidraw itself (for now, you'll need to implement your own language picker).
@@ -684,6 +709,18 @@ This API has the below signature. It sets the `tool` passed in param as the acti
684
709
  (tool: { type: typeof <a href="https://github.com/excalidraw/excalidraw/blob/master/src/shapes.tsx#L4">SHAPES</a>[number]["value"] &#124; "eraser" } &#124; { type: "custom"; customType: string }) => void
685
710
  </pre>
686
711
 
712
+ #### `setCursor`
713
+
714
+ This API can be used to customise the mouse cursor on the canvas and has the below signature. It sets the mouse cursor to the cursor passed in param.
715
+
716
+ <pre>
717
+ (cursor: string) => void
718
+ </pre>
719
+
720
+ #### `resetCursor`
721
+
722
+ This API can be used to reset to default mouse cursor.
723
+
687
724
  #### `detectScroll`
688
725
 
689
726
  Indicates whether Excalidraw should listen for `scroll` event on the nearest scrollable container in the DOM tree and recompute the coordinates (e.g. to correctly handle the cursor) when the component's position changes. You can disable this when you either know this doesn't affect your app or you want to take care of it yourself (calling the [`refresh()`](#ref) method).
@@ -780,7 +817,7 @@ No, Excalidraw package doesn't come with collaboration built in, since the imple
780
817
  **_Signature_**
781
818
 
782
819
  <pre>
783
- restoreAppState(appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L17">ImportedDataState["appState"]</a>, localAppState: Partial<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>> | null): <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>
820
+ restoreAppState(appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L17">ImportedDataState["appState"]</a>, localAppState: Partial<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>> | null): <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>
784
821
  </pre>
785
822
 
786
823
  **_How to use_**
@@ -789,7 +826,7 @@ restoreAppState(appState: <a href="https://github.com/excalidraw/excalidraw/blob
789
826
  import { restoreAppState } from "@excalidraw/excalidraw-next";
790
827
  ```
791
828
 
792
- This function will make sure all the keys have appropriate values in [appState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66) and if any key is missing, it will be set to default value.
829
+ This function will make sure all the keys have appropriate values in [appState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79) and if any key is missing, it will be set to default value.
793
830
 
794
831
  When `localAppState` is supplied, it's used in place of values that are missing (`undefined`) in `appState` instead of defaults. Use this as a way to not override user's defaults if you persist them. Required: supply `null`/`undefined` if not applicable.
795
832
 
@@ -816,7 +853,7 @@ When `localElements` are supplied, they are used to ensure that existing restore
816
853
  **_Signature_**
817
854
 
818
855
  <pre>
819
- restoreElements(data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L12">ImportedDataState</a>, localAppState: Partial<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>> | null | undefined, localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L16">ExcalidrawElement[]</a> | null | undefined): <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L4">DataState</a>
856
+ restoreElements(data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L12">ImportedDataState</a>, localAppState: Partial<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>> | null | undefined, localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L16">ExcalidrawElement[]</a> | null | undefined): <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L4">DataState</a>
820
857
  </pre>
821
858
 
822
859
  See [`restoreAppState()`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#restoreAppState) about `localAppState`, and [`restoreElements()`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#restoreElements) about `localElements`.
@@ -911,7 +948,7 @@ Returns a promise which resolves with a [blob](https://developer.mozilla.org/en-
911
948
  <pre>
912
949
  exportToSvg({
913
950
  elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a>,
914
- appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>,
951
+ appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>,
915
952
  exportPadding?: number,
916
953
  metadata?: string,
917
954
  files?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64">BinaryFiles</a>
@@ -921,7 +958,7 @@ exportToSvg({
921
958
  | Name | Type | Default | Description |
922
959
  | --- | --- | --- | --- |
923
960
  | elements | [Excalidraw Element []](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106) | | The elements to exported as svg |
924
- | appState | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66) | [defaultAppState](https://github.com/excalidraw/excalidraw/blob/master/src/appState.ts#L11) | The app state of the scene |
961
+ | appState | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79) | [defaultAppState](https://github.com/excalidraw/excalidraw/blob/master/src/appState.ts#L11) | The app state of the scene |
925
962
  | exportPadding | number | 10 | The padding to be added on canvas |
926
963
  | files | [BinaryFiles](The [`BinaryFiles`](<[BinaryFiles](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L64)>) | undefined | The files added to the scene. |
927
964
 
@@ -973,7 +1010,7 @@ Copies the scene data in the specified format (determined by `type`) to clipboar
973
1010
  <pre>
974
1011
  serializeAsJSON({
975
1012
  elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a>,
976
- appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a>,
1013
+ appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>,
977
1014
  }): string
978
1015
  </pre>
979
1016
 
@@ -1051,7 +1088,7 @@ excalidrawAPI.updateScene(scene);
1051
1088
  <pre>
1052
1089
  loadFromBlob(
1053
1090
  blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>,
1054
- localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a> | null,
1091
+ localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a> | null,
1055
1092
  localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a> | null,
1056
1093
  fileHandle?: FileSystemHandle | null
1057
1094
  ) => Promise<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/restore.ts#L53">RestoredDataState</a>>
@@ -1067,12 +1104,10 @@ This function loads the scene data from the blob (or file). If you pass `localAp
1067
1104
  import { loadSceneOrLibraryFromBlob, MIME_TYPES } from "@excalidraw/excalidraw";
1068
1105
 
1069
1106
  const contents = await loadSceneOrLibraryFromBlob(file, null, null);
1070
- // if you need, you can check what data you're dealing with before
1071
- // passing down
1072
1107
  if (contents.type === MIME_TYPES.excalidraw) {
1073
1108
  excalidrawAPI.updateScene(contents.data);
1074
- } else {
1075
- excalidrawAPI.updateScene(contents.data);
1109
+ } else if (contents.type === MIME_TYPES.excalidrawlib) {
1110
+ excalidrawAPI.updateLibrary(contents.data);
1076
1111
  }
1077
1112
  ```
1078
1113
 
@@ -1081,7 +1116,7 @@ if (contents.type === MIME_TYPES.excalidraw) {
1081
1116
  <pre>
1082
1117
  loadSceneOrLibraryFromBlob(
1083
1118
  blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>,
1084
- localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L66">AppState</a> | null,
1119
+ localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a> | null,
1085
1120
  localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L106">ExcalidrawElement[]</a> | null,
1086
1121
  fileHandle?: FileSystemHandle | null
1087
1122
  ) => Promise<{ type: string, data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/restore.ts#L53">RestoredDataState</a> | <a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/types.ts#L33">ImportedLibraryState</a>}>
@@ -1151,6 +1186,79 @@ mergeLibraryItems(localItems: <a href="https://github.com/excalidraw/excalidraw/
1151
1186
 
1152
1187
  This function merges two `LibraryItems` arrays, where unique items from `otherItems` are sorted first in the returned array.
1153
1188
 
1189
+ #### `parseLibraryTokensFromUrl`
1190
+
1191
+ **How to use**
1192
+
1193
+ ```js
1194
+ import { parseLibraryTokensFromUrl } from "@excalidraw/excalidraw-next";
1195
+ ```
1196
+
1197
+ **Signature**
1198
+
1199
+ <pre>
1200
+ parseLibraryTokensFromUrl(): {
1201
+ libraryUrl: string;
1202
+ idToken: string | null;
1203
+ } | null
1204
+ </pre>
1205
+
1206
+ Parses library parameters from URL if present (expects the `#addLibrary` hash key), and returns an object with the `libraryUrl` and `idToken`. Returns `null` if `#addLibrary` hash key not found.
1207
+
1208
+ #### `useHandleLibrary`
1209
+
1210
+ **How to use**
1211
+
1212
+ ```js
1213
+ import { useHandleLibrary } from "@excalidraw/excalidraw-next";
1214
+
1215
+ export const App = () => {
1216
+ // ...
1217
+ useHandleLibrary({ excalidrawAPI });
1218
+ };
1219
+ ```
1220
+
1221
+ **Signature**
1222
+
1223
+ <pre>
1224
+ useHandleLibrary(opts: {
1225
+ excalidrawAPI: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L432">ExcalidrawAPI</a>,
1226
+ getInitialLibraryItems?: () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L224">LibraryItemsSource</a>
1227
+ });
1228
+ </pre>
1229
+
1230
+ A hook that automatically imports library from url if `#addLibrary` hash key exists on initial load, or when it changes during the editing session (e.g. when a user installs a new library), and handles initial library load if `getInitialLibraryItems` getter is supplied.
1231
+
1232
+ In the future, we will be adding support for handling library persistence to browser storage (or elsewhere).
1233
+
1234
+ #### `sceneCoordsToViewportCoords`
1235
+
1236
+ ```js
1237
+ import { sceneCoordsToViewportCoords } from "@excalidraw/excalidraw-next";
1238
+ ```
1239
+
1240
+ **_Signature_**
1241
+
1242
+ <pre>
1243
+ sceneCoordsToViewportCoords({sceneX: number, sceneY: number}, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>): {x: number, y: number}
1244
+ </pre>
1245
+
1246
+ This function returns equivalent viewport coords for the provided scene coords in params.
1247
+
1248
+ #### `viewportCoordsToSceneCoords`
1249
+
1250
+ ```js
1251
+ import { viewportCoordsToSceneCoords } from "@excalidraw/excalidraw-next";
1252
+ ```
1253
+
1254
+ **_Signature_**
1255
+
1256
+ <pre>
1257
+ viewportCoordsToSceneCoords({clientX: number, clientY: number}, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>): {x: number, y: number}
1258
+ </pre>
1259
+
1260
+ This function returns equivalent scene coords for the provided viewport coords in params.
1261
+
1154
1262
  ### Exported constants
1155
1263
 
1156
1264
  #### `FONT_FAMILY`