Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

feat: expose getFreeDrawSvg, loadFromBlob and loadLibraryFromBlob from excalidraw package (#3764)

Aakansha Doshibdead4d1641d
diff --git a/src/packages/excalidraw/CHANGELOG.md b/src/packages/excalidraw/CHANGELOG.md
index 0eb239d0e4..901e7ef895 100644
--- a/src/packages/excalidraw/CHANGELOG.md
+++ b/src/packages/excalidraw/CHANGELOG.md
@@ -19,6 +19,8 @@ Please add the latest change on the top under the correct section.
### Features
+- Expose [`loadLibraryFromBlob`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#loadLibraryFromBlobY), [`loadFromBlob`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#loadFromBlob), and [`getFreeDrawSvgPath`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#getFreeDrawSvgPath).
+
- Expose [`FONT_FAMILY`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#FONT_FAMILY) so that consumer can use when passing `initialData.appState.currentItemFontFamily`.
- Added prop [`autoFocus`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#autoFocus) to focus the excalidraw component on page load when enabled, defaults to false [#3691](https://github.com/excalidraw/excalidraw/pull/3691).
diff --git a/src/packages/excalidraw/README_NEXT.md b/src/packages/excalidraw/README_NEXT.md
index df2183a321..1c0c010a08 100644
--- a/src/packages/excalidraw/README_NEXT.md
+++ b/src/packages/excalidraw/README_NEXT.md
@@ -843,10 +843,10 @@ This function returns a svg with the exported elements.
### FONT_FAMILY
-**_Signature_**
+**How to use**
```js
-import { FONT_FAMILY } from "./constants";
+import { FONT_FAMILY } from "@excalidraw/excalidraw-next";
```
`FONT_FAMILY` contains all the font families used in `Excalidraw` as explained below
@@ -858,3 +858,49 @@ import { FONT_FAMILY } from "./constants";
| Cacadia | The Code Font |
Defaults to `FONT_FAMILY.Virgil` unless passed in `initialData.appState.currentItemFontFamily`.
+
+### loadLibraryFromBlob
+
+```js
+import { loadLibraryFromBlob } from "@excalidraw/excalidraw-next";
+```
+
+**_Signature_**
+
+<pre>
+loadLibraryFromBlob(blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>)
+</pre>
+
+This function loads the library from the blob.
+
+### loadFromBlob
+
+**How to use**
+
+```js
+import { loadFromBlob } from "@excalidraw/excalidraw-next";
+```
+
+**Signature**
+
+<pre>
+loadFromBlob(blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>, localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L42">AppState</a> | null)
+</pre>
+
+This function loads the scene data from the blob. If you pass `localAppState`, `localAppState` value will be preferred over the `appState` derived from `blob`
+
+### getFreeDrawSvgPath
+
+**How to use**
+
+```js
+import { getFreeDrawSvgPath } from "@excalidraw/excalidraw-next";
+```
+
+**Signature**
+
+<pre>
+getFreeDrawSvgPath(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L127">ExcalidrawFreeDrawElement</a>
+</pre>
+
+This function returns the free draw svg path for the element.
diff --git a/src/packages/excalidraw/index.tsx b/src/packages/excalidraw/index.tsx
index c2d2f74df8..1291bb0a55 100644
--- a/src/packages/excalidraw/index.tsx
+++ b/src/packages/excalidraw/index.tsx
@@ -178,6 +178,9 @@ export {
exportToCanvas,
exportToBlob,
exportToSvg,
+ serializeAsJSON,
+ loadLibraryFromBlob,
+ loadFromBlob,
+ getFreeDrawSvgPath,
} from "../../packages/utils";
-export { serializeAsJSON } from "../../data/json";
export { FONT_FAMILY } from "../../constants";
diff --git a/src/packages/utils.ts b/src/packages/utils.ts
index 97196a656d..3fb446f679 100644
--- a/src/packages/utils.ts
+++ b/src/packages/utils.ts
@@ -95,3 +95,5 @@ export const exportToSvg = ({
};
export { serializeAsJSON } from "../data/json";
+export { loadFromBlob, loadLibraryFromBlob } from "../data/blob";
+export { getFreeDrawSvgPath } from "../renderer/renderElement";