@8btc/xcanvas 0.0.14-beta.10 → 0.0.14-beta.11

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/dist/index.d.ts CHANGED
@@ -33,10 +33,14 @@ export declare interface XCanvasAPI {
33
33
  reset: () => void;
34
34
  /**
35
35
  * 导出当前选区为图片(dataUrl), 特殊情况:当前选区为单张外部传入图片,则直接返回外部图片url
36
+ *
37
+ * @param tryToSplit 是否尝试拆分选区内的图片元素(当选区内全是图片时生效)
38
+ * 如果选区内的元素都是图片,则返回选区内图片url数组
39
+ * 如果选区内有非图片元素,则返回选区区域的dataUrl
36
40
  * @returns dataUrl | url
37
41
  * @throws 如果没有选区,调用这个函数会抛出错误
38
42
  */
39
- exportSelection: () => Promise<string>;
43
+ exportSelection: (tryToSplit?: boolean) => Promise<string | string[]>;
40
44
  /**
41
45
  * 插入embeddableElement元素
42
46
  *
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { atom, useAtom, useAtomValue, useSetAtom } from "jotai";
3
3
  import { Excalidraw, convertToExcalidrawElements, exportToCanvas } from "@8btc/excalidraw";
4
4
  import { useEffect } from "react";
5
- const version = "0.0.14-beta.10";
5
+ const version = "0.0.14-beta.11";
6
6
  const packageJson = {
7
7
  version
8
8
  };
@@ -327,8 +327,7 @@ function ApiFactory() {
327
327
  }
328
328
  });
329
329
  },
330
- exportSelection: async () => {
331
- if (!excalidrawAPI) return;
330
+ exportSelection: async (tryToSplit) => {
332
331
  const appState = excalidrawAPI.getAppState();
333
332
  const selectedElements = getSelectedElements(
334
333
  excalidrawAPI.getSceneElements(),
@@ -344,6 +343,14 @@ function ApiFactory() {
344
343
  }
345
344
  return files[selectedElements[0].fileId].dataURL;
346
345
  }
346
+ if (tryToSplit && selectedElements.every((el) => el.type === "image")) {
347
+ return selectedElements.map((el) => {
348
+ if (el.fileId?.startsWith("http") && !el.crop) {
349
+ return selectedElements[0].fileId;
350
+ }
351
+ return files[el.fileId].dataURL;
352
+ });
353
+ }
347
354
  const canvas = await exportToCanvas({
348
355
  elements: selectedElements,
349
356
  appState: {
@@ -2,7 +2,7 @@
2
2
  typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("jotai"), require("@8btc/excalidraw"), require("react")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "jotai", "@8btc/excalidraw", "react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.XCanvas = {}, global.jsxRuntime, global.Jotai, global.Excalidraw, global.React));
3
3
  })(this, (function(exports2, jsxRuntime, jotai, excalidraw, react) {
4
4
  "use strict";
5
- const version = "0.0.14-beta.10";
5
+ const version = "0.0.14-beta.11";
6
6
  const packageJson = {
7
7
  version
8
8
  };
@@ -327,8 +327,7 @@
327
327
  }
328
328
  });
329
329
  },
330
- exportSelection: async () => {
331
- if (!excalidrawAPI) return;
330
+ exportSelection: async (tryToSplit) => {
332
331
  const appState = excalidrawAPI.getAppState();
333
332
  const selectedElements = getSelectedElements(
334
333
  excalidrawAPI.getSceneElements(),
@@ -344,6 +343,14 @@
344
343
  }
345
344
  return files[selectedElements[0].fileId].dataURL;
346
345
  }
346
+ if (tryToSplit && selectedElements.every((el) => el.type === "image")) {
347
+ return selectedElements.map((el) => {
348
+ if (el.fileId?.startsWith("http") && !el.crop) {
349
+ return selectedElements[0].fileId;
350
+ }
351
+ return files[el.fileId].dataURL;
352
+ });
353
+ }
347
354
  const canvas = await excalidraw.exportToCanvas({
348
355
  elements: selectedElements,
349
356
  appState: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8btc/xcanvas",
3
3
  "private": false,
4
- "version": "0.0.14-beta.10",
4
+ "version": "0.0.14-beta.11",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": {