@mce/bigesj 0.17.2 → 0.17.4
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.js +64 -3
- package/dist/loaders/clipboard.d.ts +8 -0
- package/dist/loaders/index.d.ts +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6091,6 +6091,7 @@ async function convertDoc(doc, options2 = {}) {
|
|
|
6091
6091
|
}
|
|
6092
6092
|
async function convertImageElementToUrl(el) {
|
|
6093
6093
|
const {
|
|
6094
|
+
cropping = {},
|
|
6094
6095
|
transform = {},
|
|
6095
6096
|
style = {},
|
|
6096
6097
|
maskUrl,
|
|
@@ -6130,9 +6131,9 @@ async function convertImageElementToUrl(el) {
|
|
|
6130
6131
|
ctx.translate(scaleX < 0 ? -width : 0, scaleY < 0 ? -height : 0);
|
|
6131
6132
|
if (maskUrl) {
|
|
6132
6133
|
const mask = await assets.fetchImageBitmap(maskUrl);
|
|
6133
|
-
ctx.drawImage(mask, 0, 0,
|
|
6134
|
-
mask.close();
|
|
6134
|
+
ctx.drawImage(mask, 0, 0, cropping?.maskWidth ?? width, cropping?.maskHeight ?? height);
|
|
6135
6135
|
ctx.globalCompositeOperation = "source-in";
|
|
6136
|
+
mask.close();
|
|
6136
6137
|
}
|
|
6137
6138
|
const dw = imageWidth * zoom;
|
|
6138
6139
|
const dh = imageHeight * zoom;
|
|
@@ -6395,6 +6396,64 @@ function bigeLoader() {
|
|
|
6395
6396
|
}
|
|
6396
6397
|
};
|
|
6397
6398
|
}
|
|
6399
|
+
function clipboardLoader() {
|
|
6400
|
+
const BIGE_CLIPBOARD_DATA_KEY = "BIGE_CLIPBOARD_DATA";
|
|
6401
|
+
const BIGE_CLIPBOARD_DATA_FLAG = `__${BIGE_CLIPBOARD_DATA_KEY}__`;
|
|
6402
|
+
const BIGE_CLIPBOARD_DATA_SECRET = `${BIGE_CLIPBOARD_DATA_KEY}_SECRET_2025`;
|
|
6403
|
+
function isSignedData(obj) {
|
|
6404
|
+
return obj && typeof obj === "object" && typeof obj.data === "string" && typeof obj.signature === "string" && typeof obj.timestamp === "number";
|
|
6405
|
+
}
|
|
6406
|
+
async function generateSignature(data, secret) {
|
|
6407
|
+
return Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(data + secret)))).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
6408
|
+
}
|
|
6409
|
+
function decodeBase64(base64) {
|
|
6410
|
+
try {
|
|
6411
|
+
const binary = atob(base64);
|
|
6412
|
+
const bytes = new Uint8Array(binary.length);
|
|
6413
|
+
for (let i = 0; i < binary.length; i++) {
|
|
6414
|
+
bytes[i] = binary.charCodeAt(i);
|
|
6415
|
+
}
|
|
6416
|
+
return new TextDecoder().decode(bytes);
|
|
6417
|
+
} catch (_error) {
|
|
6418
|
+
throw new Error("解码失败");
|
|
6419
|
+
}
|
|
6420
|
+
}
|
|
6421
|
+
async function decode(signedData) {
|
|
6422
|
+
if (!isSignedData(signedData)) {
|
|
6423
|
+
throw new Error("格式异常");
|
|
6424
|
+
}
|
|
6425
|
+
const { data, signature, timestamp } = signedData;
|
|
6426
|
+
const signatureData = data + timestamp;
|
|
6427
|
+
const isValid = await generateSignature(signatureData, BIGE_CLIPBOARD_DATA_SECRET) === signature;
|
|
6428
|
+
if (!isValid) {
|
|
6429
|
+
throw new Error("签名无效");
|
|
6430
|
+
}
|
|
6431
|
+
try {
|
|
6432
|
+
return JSON.parse(decodeBase64(data));
|
|
6433
|
+
} catch (_error) {
|
|
6434
|
+
throw new Error("数据异常");
|
|
6435
|
+
}
|
|
6436
|
+
}
|
|
6437
|
+
return {
|
|
6438
|
+
name: "bige-clipboard",
|
|
6439
|
+
test: (doc) => {
|
|
6440
|
+
return doc instanceof Document && Boolean(doc.querySelector("bige-clipboard"));
|
|
6441
|
+
},
|
|
6442
|
+
load: async (doc) => {
|
|
6443
|
+
const clipboard = doc.querySelector("bige-clipboard");
|
|
6444
|
+
const decoded = await decode(JSON.parse(clipboard.textContent));
|
|
6445
|
+
if (decoded && decoded._flag === BIGE_CLIPBOARD_DATA_FLAG) {
|
|
6446
|
+
switch (decoded.type) {
|
|
6447
|
+
case "element":
|
|
6448
|
+
return [await convertElement(decoded.data)];
|
|
6449
|
+
case "layout":
|
|
6450
|
+
return [await convertLayout(decoded.data)];
|
|
6451
|
+
}
|
|
6452
|
+
}
|
|
6453
|
+
return [];
|
|
6454
|
+
}
|
|
6455
|
+
};
|
|
6456
|
+
}
|
|
6398
6457
|
function plugin(options2 = {}) {
|
|
6399
6458
|
const {
|
|
6400
6459
|
font,
|
|
@@ -6411,7 +6470,8 @@ function plugin(options2 = {}) {
|
|
|
6411
6470
|
name: "bigesj",
|
|
6412
6471
|
loaders: [
|
|
6413
6472
|
bigeLoader(),
|
|
6414
|
-
bidTidLoader(editor, _api)
|
|
6473
|
+
bidTidLoader(editor, _api),
|
|
6474
|
+
clipboardLoader()
|
|
6415
6475
|
],
|
|
6416
6476
|
setup: async () => {
|
|
6417
6477
|
if (font) {
|
|
@@ -6508,6 +6568,7 @@ const options = {
|
|
|
6508
6568
|
export {
|
|
6509
6569
|
bidTidLoader,
|
|
6510
6570
|
bigeLoader,
|
|
6571
|
+
clipboardLoader,
|
|
6511
6572
|
convertAnimation,
|
|
6512
6573
|
convertBackground,
|
|
6513
6574
|
convertDoc,
|
package/dist/loaders/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mce/bigesj",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.17.
|
|
4
|
+
"version": "0.17.4",
|
|
5
5
|
"description": "Plugin for mce",
|
|
6
6
|
"author": "wxm",
|
|
7
7
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"modern-openxml": "^1.10.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"mce": "0.17.
|
|
52
|
+
"mce": "0.17.4"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"mce": "^0"
|