|
@@ -8,7 +8,7 @@ These are pure Javascript functions exported from the @excalidraw/excalidraw [`@
|
|
|
|
|
|
### serializeAsJSON
|
|
### serializeAsJSON
|
|
|
|
|
|
-Takes the scene elements and state and returns a JSON string. `Deleted` elements as well as most properties from `AppState` are removed from the resulting JSON. (see [`serializeAsJSON()`](https://github.com/excalidraw/excalidraw/blob/master/src/data/json.ts#L42) source for details).
|
|
|
|
|
|
+Takes the scene elements and state and returns a JSON string. `Deleted` elements as well as most properties from `AppState` are removed from the resulting JSON. (see [`serializeAsJSON()`](https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/data/json.ts#L42) source for details).
|
|
|
|
|
|
If you want to overwrite the `source` field in the `JSON` string, you can set `window.EXCALIDRAW_EXPORT_SOURCE` to the desired value.
|
|
If you want to overwrite the `source` field in the `JSON` string, you can set `window.EXCALIDRAW_EXPORT_SOURCE` to the desired value.
|
|
|
|
|
|
@@ -16,8 +16,8 @@ If you want to overwrite the `source` field in the `JSON` string, you can set `w
|
|
|
|
|
|
<pre>
|
|
<pre>
|
|
serializeAsJSON({<br/>
|
|
serializeAsJSON({<br/>
|
|
- elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L114">ExcalidrawElement[]</a>,<br/>
|
|
|
|
- appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L95">AppState</a>,<br/>
|
|
|
|
|
|
+ elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/element/types.ts#L114">ExcalidrawElement[]</a>,<br/>
|
|
|
|
+ appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/types.ts#L95">AppState</a>,<br/>
|
|
}): string
|
|
}): string
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
@@ -37,7 +37,7 @@ If you want to overwrite the source field in the JSON string, you can set `windo
|
|
|
|
|
|
<pre>
|
|
<pre>
|
|
serializeLibraryAsJSON(
|
|
serializeLibraryAsJSON(
|
|
- libraryItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems[]</a>)
|
|
|
|
|
|
+ libraryItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/types.ts#L200">LibraryItems[]</a>)
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
**How to use**
|
|
**How to use**
|
|
@@ -53,7 +53,7 @@ Returns `true` if element is invisibly small (e.g. width & height are zero).
|
|
**_Signature_**
|
|
**_Signature_**
|
|
|
|
|
|
<pre>
|
|
<pre>
|
|
-isInvisiblySmallElement(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L114">ExcalidrawElement</a>): boolean
|
|
|
|
|
|
+isInvisiblySmallElement(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/element/types.ts#L114">ExcalidrawElement</a>): boolean
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
**How to use**
|
|
**How to use**
|
|
@@ -80,10 +80,10 @@ excalidrawAPI.updateScene(scene);
|
|
<pre>
|
|
<pre>
|
|
loadFromBlob(<br/>
|
|
loadFromBlob(<br/>
|
|
blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>,<br/>
|
|
blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>,<br/>
|
|
- localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L95">AppState</a> | null,<br/>
|
|
|
|
- localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L114">ExcalidrawElement[]</a> | null,<br/>
|
|
|
|
|
|
+ localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/types.ts#L95">AppState</a> | null,<br/>
|
|
|
|
+ localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/element/types.ts#L114">ExcalidrawElement[]</a> | null,<br/>
|
|
fileHandle?: FileSystemHandle | null <br/>
|
|
fileHandle?: FileSystemHandle | null <br/>
|
|
-) => Promise<<a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/restore.ts#L61">RestoredDataState</a>>
|
|
|
|
|
|
+) => Promise<<a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/data/restore.ts#L61">RestoredDataState</a>>
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
### loadLibraryFromBlob
|
|
### loadLibraryFromBlob
|
|
@@ -130,10 +130,10 @@ if (contents.type === MIME_TYPES.excalidraw) {
|
|
<pre>
|
|
<pre>
|
|
loadSceneOrLibraryFromBlob(<br/>
|
|
loadSceneOrLibraryFromBlob(<br/>
|
|
blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>,<br/>
|
|
blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>,<br/>
|
|
- localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L95">AppState</a> | null,<br/>
|
|
|
|
- localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L114">ExcalidrawElement[]</a> | null,<br/>
|
|
|
|
|
|
+ localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/types.ts#L95">AppState</a> | null,<br/>
|
|
|
|
+ localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/element/types.ts#L114">ExcalidrawElement[]</a> | null,<br/>
|
|
fileHandle?: FileSystemHandle | null<br/>
|
|
fileHandle?: FileSystemHandle | null<br/>
|
|
-) => 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>}>
|
|
|
|
|
|
+) => Promise<{ type: string, data: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/data/restore.ts#L53">RestoredDataState</a> | <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/data/types.ts#L33">ImportedLibraryState</a>}>
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
### getFreeDrawSvgPath
|
|
### getFreeDrawSvgPath
|
|
@@ -149,7 +149,7 @@ import { getFreeDrawSvgPath } from "@excalidraw/excalidraw";
|
|
**Signature**
|
|
**Signature**
|
|
|
|
|
|
<pre>
|
|
<pre>
|
|
-getFreeDrawSvgPath(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L182">ExcalidrawFreeDrawElement</a>)
|
|
|
|
|
|
+getFreeDrawSvgPath(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/element/types.ts#L182">ExcalidrawFreeDrawElement</a>)
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
### isLinearElement
|
|
### isLinearElement
|
|
@@ -165,7 +165,7 @@ import { isLinearElement } from "@excalidraw/excalidraw";
|
|
**Signature**
|
|
**Signature**
|
|
|
|
|
|
<pre>
|
|
<pre>
|
|
-isLinearElement(elementType?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L80">ExcalidrawElement</a>): boolean
|
|
|
|
|
|
+isLinearElement(elementType?: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/element/types.ts#L80">ExcalidrawElement</a>): boolean
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
### getNonDeletedElements
|
|
### getNonDeletedElements
|
|
@@ -181,7 +181,7 @@ import { getNonDeletedElements } from "@excalidraw/excalidraw";
|
|
**Signature**
|
|
**Signature**
|
|
|
|
|
|
<pre>
|
|
<pre>
|
|
-getNonDeletedElements(elements:<a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L114"> readonly ExcalidrawElement[]</a>): as readonly <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L125">NonDeletedExcalidrawElement[]</a>
|
|
|
|
|
|
+getNonDeletedElements(elements:<a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/element/types.ts#L114"> readonly ExcalidrawElement[]</a>): as readonly <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/element/types.ts#L125">NonDeletedExcalidrawElement[]</a>
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
### mergeLibraryItems
|
|
### mergeLibraryItems
|
|
@@ -196,9 +196,9 @@ import { mergeLibraryItems } from "@excalidraw/excalidraw";
|
|
|
|
|
|
<pre>
|
|
<pre>
|
|
mergeLibraryItems(<br/>
|
|
mergeLibraryItems(<br/>
|
|
- localItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L250">LibraryItems</a>,<br/>
|
|
|
|
- otherItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a><br/>
|
|
|
|
-): <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L250">LibraryItems</a>
|
|
|
|
|
|
+ localItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/types.ts#L250">LibraryItems</a>,<br/>
|
|
|
|
+ otherItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/types.ts#L200">LibraryItems</a><br/>
|
|
|
|
+): <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/types.ts#L250">LibraryItems</a>
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
### parseLibraryTokensFromUrl
|
|
### parseLibraryTokensFromUrl
|
|
@@ -239,8 +239,8 @@ export const App = () => {
|
|
|
|
|
|
<pre>
|
|
<pre>
|
|
useHandleLibrary(opts: {<br/>
|
|
useHandleLibrary(opts: {<br/>
|
|
- excalidrawAPI: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L494">ExcalidrawAPI</a>,<br/>
|
|
|
|
- getInitialLibraryItems?: () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L253">LibraryItemsSource</a><br/>
|
|
|
|
|
|
+ excalidrawAPI: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/types.ts#L494">ExcalidrawAPI</a>,<br/>
|
|
|
|
+ getInitialLibraryItems?: () => <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/types.ts#L253">LibraryItemsSource</a><br/>
|
|
});
|
|
});
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
@@ -253,7 +253,7 @@ This function returns the current `scene` version.
|
|
**_Signature_**
|
|
**_Signature_**
|
|
|
|
|
|
<pre>
|
|
<pre>
|
|
-getSceneVersion(elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L114">ExcalidrawElement[]</a>)
|
|
|
|
|
|
+getSceneVersion(elements: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/element/types.ts#L114">ExcalidrawElement[]</a>)
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
**How to use**
|
|
**How to use**
|
|
@@ -274,7 +274,7 @@ import { sceneCoordsToViewportCoords } from "@excalidraw/excalidraw";
|
|
|
|
|
|
<pre>
|
|
<pre>
|
|
sceneCoordsToViewportCoords({ sceneX: number, sceneY: number },<br/>
|
|
sceneCoordsToViewportCoords({ sceneX: number, sceneY: number },<br/>
|
|
- appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L95">AppState</a><br/>): { x: number, y: number }
|
|
|
|
|
|
+ appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/types.ts#L95">AppState</a><br/>): { x: number, y: number }
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
### viewportCoordsToSceneCoords
|
|
### viewportCoordsToSceneCoords
|
|
@@ -289,7 +289,7 @@ import { viewportCoordsToSceneCoords } from "@excalidraw/excalidraw";
|
|
|
|
|
|
<pre>
|
|
<pre>
|
|
viewportCoordsToSceneCoords({ clientX: number, clientY: number },<br/>
|
|
viewportCoordsToSceneCoords({ clientX: number, clientY: number },<br/>
|
|
- appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L95">AppState</a><br/>): {x: number, y: number}
|
|
|
|
|
|
+ appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/types.ts#L95">AppState</a><br/>): {x: number, y: number}
|
|
</pre>
|
|
</pre>
|
|
|
|
|
|
### useDevice
|
|
### useDevice
|
|
@@ -350,8 +350,8 @@ To help with localization, we export the following.
|
|
| name | type |
|
|
| name | type |
|
|
| --- | --- |
|
|
| --- | --- |
|
|
| `defaultLang` | `string` |
|
|
| `defaultLang` | `string` |
|
|
-| `languages` | [`Language[]`](https://github.com/excalidraw/excalidraw/blob/master/src/i18n.ts#L15) |
|
|
|
|
-| `useI18n` | [`() => { langCode, t }`](https://github.com/excalidraw/excalidraw/blob/master/src/i18n.ts#L15) |
|
|
|
|
|
|
+| `languages` | [`Language[]`](https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/i18n.ts#L15) |
|
|
|
|
+| `useI18n` | [`() => { langCode, t }`](https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/i18n.ts#L15) |
|
|
|
|
|
|
```js
|
|
```js
|
|
import { defaultLang, languages, useI18n } from "@excalidraw/excalidraw";
|
|
import { defaultLang, languages, useI18n } from "@excalidraw/excalidraw";
|