@8btc/xcanvas 0.0.14-beta.10 → 0.0.14-beta.12
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 +5 -1
- package/dist/index.js +15 -4
- package/dist/index.umd.cjs +15 -4
- package/package.json +1 -1
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.
|
|
5
|
+
const version = "0.0.14-beta.12";
|
|
6
6
|
const packageJson = {
|
|
7
7
|
version
|
|
8
8
|
};
|
|
@@ -144,7 +144,11 @@ function ApiFactory() {
|
|
|
144
144
|
height: it.height,
|
|
145
145
|
x: places[index].x,
|
|
146
146
|
y: places[index].y,
|
|
147
|
-
fileId: it.url
|
|
147
|
+
fileId: it.url,
|
|
148
|
+
customData: {
|
|
149
|
+
naturalWidth: it.width,
|
|
150
|
+
naturalHeight: it.height
|
|
151
|
+
}
|
|
148
152
|
};
|
|
149
153
|
})
|
|
150
154
|
);
|
|
@@ -327,8 +331,7 @@ function ApiFactory() {
|
|
|
327
331
|
}
|
|
328
332
|
});
|
|
329
333
|
},
|
|
330
|
-
exportSelection: async () => {
|
|
331
|
-
if (!excalidrawAPI) return;
|
|
334
|
+
exportSelection: async (tryToSplit) => {
|
|
332
335
|
const appState = excalidrawAPI.getAppState();
|
|
333
336
|
const selectedElements = getSelectedElements(
|
|
334
337
|
excalidrawAPI.getSceneElements(),
|
|
@@ -344,6 +347,14 @@ function ApiFactory() {
|
|
|
344
347
|
}
|
|
345
348
|
return files[selectedElements[0].fileId].dataURL;
|
|
346
349
|
}
|
|
350
|
+
if (tryToSplit && selectedElements.every((el) => el.type === "image")) {
|
|
351
|
+
return selectedElements.map((el) => {
|
|
352
|
+
if (el.fileId?.startsWith("http") && !el.crop) {
|
|
353
|
+
return selectedElements[0].fileId;
|
|
354
|
+
}
|
|
355
|
+
return files[el.fileId].dataURL;
|
|
356
|
+
});
|
|
357
|
+
}
|
|
347
358
|
const canvas = await exportToCanvas({
|
|
348
359
|
elements: selectedElements,
|
|
349
360
|
appState: {
|
package/dist/index.umd.cjs
CHANGED
|
@@ -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.
|
|
5
|
+
const version = "0.0.14-beta.12";
|
|
6
6
|
const packageJson = {
|
|
7
7
|
version
|
|
8
8
|
};
|
|
@@ -144,7 +144,11 @@
|
|
|
144
144
|
height: it.height,
|
|
145
145
|
x: places[index].x,
|
|
146
146
|
y: places[index].y,
|
|
147
|
-
fileId: it.url
|
|
147
|
+
fileId: it.url,
|
|
148
|
+
customData: {
|
|
149
|
+
naturalWidth: it.width,
|
|
150
|
+
naturalHeight: it.height
|
|
151
|
+
}
|
|
148
152
|
};
|
|
149
153
|
})
|
|
150
154
|
);
|
|
@@ -327,8 +331,7 @@
|
|
|
327
331
|
}
|
|
328
332
|
});
|
|
329
333
|
},
|
|
330
|
-
exportSelection: async () => {
|
|
331
|
-
if (!excalidrawAPI) return;
|
|
334
|
+
exportSelection: async (tryToSplit) => {
|
|
332
335
|
const appState = excalidrawAPI.getAppState();
|
|
333
336
|
const selectedElements = getSelectedElements(
|
|
334
337
|
excalidrawAPI.getSceneElements(),
|
|
@@ -344,6 +347,14 @@
|
|
|
344
347
|
}
|
|
345
348
|
return files[selectedElements[0].fileId].dataURL;
|
|
346
349
|
}
|
|
350
|
+
if (tryToSplit && selectedElements.every((el) => el.type === "image")) {
|
|
351
|
+
return selectedElements.map((el) => {
|
|
352
|
+
if (el.fileId?.startsWith("http") && !el.crop) {
|
|
353
|
+
return selectedElements[0].fileId;
|
|
354
|
+
}
|
|
355
|
+
return files[el.fileId].dataURL;
|
|
356
|
+
});
|
|
357
|
+
}
|
|
347
358
|
const canvas = await excalidraw.exportToCanvas({
|
|
348
359
|
elements: selectedElements,
|
|
349
360
|
appState: {
|