@mce/bigesj 0.24.1 → 0.24.3
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/convert/image.d.ts +3 -0
- package/dist/convert/text.d.ts +3 -1
- package/dist/index.js +264 -219
- package/package.json +3 -3
package/dist/convert/image.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import type { Effect } from 'modern-idoc';
|
|
2
|
+
import type { BigeElement } from './types';
|
|
3
|
+
export declare function convertImageEffects(el: BigeElement): Effect[] | undefined;
|
|
1
4
|
export declare function cachedFetchImageBitmap(url: string): Promise<ImageBitmap>;
|
|
2
5
|
export declare function convertImageElementToUrl(el: Record<string, any>): Promise<string>;
|
package/dist/convert/text.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { NormalizedTextContent, StyleObject } from 'modern-idoc';
|
|
1
|
+
import type { NormalizedTextContent, StyleObject, TextDeformation } from 'modern-idoc';
|
|
2
2
|
import type { BigeElement } from './types';
|
|
3
3
|
export declare function convertTextStyle(el: BigeElement, isByWord?: boolean): Partial<StyleObject>;
|
|
4
4
|
export declare function convertTextEffects(el: BigeElement): Promise<Partial<StyleObject>[] | undefined>;
|
|
5
|
+
export declare function convertDeformationType(oldType: string): string;
|
|
6
|
+
export declare function convertTextDeformation(el: BigeElement): TextDeformation | undefined;
|
|
5
7
|
export declare function getTextContents(el: BigeElement): BigeElement['contents'];
|
|
6
8
|
export declare function convertTextContent(el: BigeElement, isByWord?: boolean): NormalizedTextContent;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { definePlugin, useEditor } from "mce";
|
|
2
2
|
import { onBeforeMount, onScopeDispose, ref } from "vue";
|
|
3
3
|
import { clearUndef, idGenerator, isGradient, isGradientFill, normalizeCRLF, normalizeGradientFill, normalizeNumber } from "modern-idoc";
|
|
4
|
-
import { OoxmlNode, parsePresetShapeDefinition } from "modern-openxml";
|
|
5
4
|
import { assets } from "modern-canvas";
|
|
5
|
+
import { OoxmlNode, parsePresetShapeDefinition } from "modern-openxml";
|
|
6
6
|
import { gunzipSync } from "fflate";
|
|
7
7
|
//#region \0rolldown/runtime.js
|
|
8
8
|
var __create = Object.create;
|
|
@@ -8180,6 +8180,253 @@ ${this.paths.map((path) => path.toSvgPathString()).join("")}
|
|
|
8180
8180
|
}
|
|
8181
8181
|
};
|
|
8182
8182
|
//#endregion
|
|
8183
|
+
//#region src/convert/image.ts
|
|
8184
|
+
function convertImageEffects(el) {
|
|
8185
|
+
const imageEffects = el.imageEffects ?? [];
|
|
8186
|
+
if (!imageEffects.length) return;
|
|
8187
|
+
const ratio = el.imageEffectsRatio ?? 50;
|
|
8188
|
+
const effects = [];
|
|
8189
|
+
for (const entry of imageEffects) {
|
|
8190
|
+
const { filling, offset, stroke } = entry;
|
|
8191
|
+
const transform = offset ? `translate(${offset.x / 50 * ratio * 200}, ${offset.y / 50 * ratio * 200})` : void 0;
|
|
8192
|
+
let fill;
|
|
8193
|
+
if (filling?.color) fill = { color: filling.color };
|
|
8194
|
+
else if (filling?.imageContent?.image) fill = { image: filling.imageContent.image };
|
|
8195
|
+
const strokes = Array.isArray(stroke) ? stroke : stroke ? [stroke] : [];
|
|
8196
|
+
if (strokes.length) {
|
|
8197
|
+
let cumulative = 0;
|
|
8198
|
+
for (const s of strokes) {
|
|
8199
|
+
cumulative += s.width / 50 * ratio;
|
|
8200
|
+
effects.push({
|
|
8201
|
+
...transform ? { transform } : {},
|
|
8202
|
+
outline: {
|
|
8203
|
+
color: s.color,
|
|
8204
|
+
width: cumulative
|
|
8205
|
+
}
|
|
8206
|
+
});
|
|
8207
|
+
}
|
|
8208
|
+
} else if (fill) effects.push({
|
|
8209
|
+
...transform ? { transform } : {},
|
|
8210
|
+
fill
|
|
8211
|
+
});
|
|
8212
|
+
else effects.push(transform ? { transform } : {});
|
|
8213
|
+
}
|
|
8214
|
+
return effects.length ? effects : void 0;
|
|
8215
|
+
}
|
|
8216
|
+
function cachedFetchImageBitmap(url) {
|
|
8217
|
+
if (typeof url === "string" && url.startsWith("http")) return assets.loadBy(url).then((blob) => assets.fetchImageBitmap(blob));
|
|
8218
|
+
return assets.fetchImageBitmap(url);
|
|
8219
|
+
}
|
|
8220
|
+
async function convertImageElementToUrl(el) {
|
|
8221
|
+
const { cropping = {}, transform = {}, style = {}, maskUrl, imageEffects = [], imageEffectsRatio = 1 } = el;
|
|
8222
|
+
const url = el.clipUrl || el.url;
|
|
8223
|
+
const { translateX = 0, translateY = 0, zoom = 1 } = transform ?? {};
|
|
8224
|
+
const { scaleX = 1, scaleY = 1, filter } = style;
|
|
8225
|
+
if (translateX === 0 && translateY === 0 && zoom === 1 && scaleX === 1 && scaleY === 1 && !maskUrl && !filter && !imageEffects.length) return url;
|
|
8226
|
+
const img = await cachedFetchImageBitmap(url);
|
|
8227
|
+
const { originWidth = img.width, originHeight = img.height, imageWidth = originWidth, imageHeight = originHeight } = transform;
|
|
8228
|
+
const { width = originWidth, height = originHeight } = style;
|
|
8229
|
+
const dpr = window.devicePixelRatio || 1;
|
|
8230
|
+
const [canvas, ctx] = createCanvas(width, height, dpr);
|
|
8231
|
+
if (filter) ctx.filter = filter;
|
|
8232
|
+
ctx.scale(scaleX, scaleY);
|
|
8233
|
+
ctx.translate(scaleX < 0 ? -width : 0, scaleY < 0 ? -height : 0);
|
|
8234
|
+
if (maskUrl) {
|
|
8235
|
+
const mask = await cachedFetchImageBitmap(maskUrl);
|
|
8236
|
+
ctx.drawImage(mask, 0, 0, cropping?.maskWidth ?? width, cropping?.maskHeight ?? height);
|
|
8237
|
+
ctx.globalCompositeOperation = "source-in";
|
|
8238
|
+
mask.close();
|
|
8239
|
+
}
|
|
8240
|
+
const dw = imageWidth * zoom;
|
|
8241
|
+
const dh = imageHeight * zoom;
|
|
8242
|
+
const dx = -(dw / 2 - imageWidth / 2) + translateX;
|
|
8243
|
+
const dy = -(dh / 2 - imageHeight / 2) + translateY;
|
|
8244
|
+
ctx.drawImage(img, 0, 0, img.width, img.height, dx, dy, dw, dh);
|
|
8245
|
+
img.close();
|
|
8246
|
+
ctx.globalCompositeOperation = "source-over";
|
|
8247
|
+
if (imageEffects.length > 0) {
|
|
8248
|
+
const scale = .9;
|
|
8249
|
+
const center = {
|
|
8250
|
+
x: (width - width * scale) / 2,
|
|
8251
|
+
y: (height - height * scale) / 2
|
|
8252
|
+
};
|
|
8253
|
+
const canvasBitmap = await createImageBitmap(canvas);
|
|
8254
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
8255
|
+
ctx.scale(scale, scale);
|
|
8256
|
+
for (let i = imageEffects.length - 1; i >= 0; i--) {
|
|
8257
|
+
const { filling, offset, stroke } = imageEffects[i];
|
|
8258
|
+
let effectCanvas = canvasBitmap;
|
|
8259
|
+
if (filling) {
|
|
8260
|
+
const [canvas1, ctx1] = createCanvas(width, height, dpr);
|
|
8261
|
+
ctx1.drawImage(effectCanvas, 0, 0, width, height);
|
|
8262
|
+
ctx1.globalCompositeOperation = "source-in";
|
|
8263
|
+
if (filling.color) {
|
|
8264
|
+
const [canvas2, ctx2] = createCanvas(width, height, dpr);
|
|
8265
|
+
ctx2.fillStyle = filling.color;
|
|
8266
|
+
ctx2.fillRect(0, 0, width, height);
|
|
8267
|
+
ctx1.drawImage(canvas2, 0, 0, width, height);
|
|
8268
|
+
} else if (filling.imageContent?.image) {
|
|
8269
|
+
const img2 = await cachedFetchImageBitmap(filling.imageContent.image);
|
|
8270
|
+
ctx1.drawImage(img2, 0, 0, width, height);
|
|
8271
|
+
img2.close();
|
|
8272
|
+
}
|
|
8273
|
+
effectCanvas = canvas1;
|
|
8274
|
+
}
|
|
8275
|
+
stroke?.forEach(({ width, color }) => {
|
|
8276
|
+
effectCanvas = new ImageStroke().use((ctx, image, options) => {
|
|
8277
|
+
const [, ctx1] = createCanvas(image.width, image.height);
|
|
8278
|
+
ctx1.drawImage(image, 0, 0);
|
|
8279
|
+
const paths = getContours(ctx1);
|
|
8280
|
+
const x = options.thickness;
|
|
8281
|
+
const y = options.thickness;
|
|
8282
|
+
ctx.strokeStyle = options.color;
|
|
8283
|
+
ctx.lineWidth = options.thickness * 2;
|
|
8284
|
+
ctx.lineJoin = "round";
|
|
8285
|
+
paths.forEach((path) => {
|
|
8286
|
+
ctx.beginPath();
|
|
8287
|
+
ctx.moveTo(x + path[0].x, y + path[1].y);
|
|
8288
|
+
for (let i = 1; i < path.length; i++) ctx.lineTo(x + path[i].x, y + path[i].y);
|
|
8289
|
+
ctx.closePath();
|
|
8290
|
+
});
|
|
8291
|
+
ctx.stroke();
|
|
8292
|
+
}).make(effectCanvas, {
|
|
8293
|
+
color,
|
|
8294
|
+
thickness: width / 50 * imageEffectsRatio
|
|
8295
|
+
});
|
|
8296
|
+
});
|
|
8297
|
+
if (offset) {
|
|
8298
|
+
let { x, y } = offset;
|
|
8299
|
+
x = x / 50 * imageEffectsRatio * 200;
|
|
8300
|
+
y = y / 50 * imageEffectsRatio * 200;
|
|
8301
|
+
ctx.drawImage(effectCanvas, x + center.x, y + center.y, width, height);
|
|
8302
|
+
} else ctx.drawImage(effectCanvas, center.x, center.y, width, height);
|
|
8303
|
+
}
|
|
8304
|
+
canvasBitmap.close();
|
|
8305
|
+
}
|
|
8306
|
+
return await new Promise((resolve) => {
|
|
8307
|
+
canvas.toBlob((blob) => {
|
|
8308
|
+
try {
|
|
8309
|
+
resolve(URL.createObjectURL(blob));
|
|
8310
|
+
} catch (e) {
|
|
8311
|
+
console.error(`Failed to URL.createObjectURL, url: ${url}`, e);
|
|
8312
|
+
resolve(url);
|
|
8313
|
+
}
|
|
8314
|
+
});
|
|
8315
|
+
});
|
|
8316
|
+
}
|
|
8317
|
+
function createCanvas(width, height, ratio = 1) {
|
|
8318
|
+
const canvas = document.createElement("canvas");
|
|
8319
|
+
canvas.width = width * ratio;
|
|
8320
|
+
canvas.height = height * ratio;
|
|
8321
|
+
canvas.style.width = `${width}px`;
|
|
8322
|
+
canvas.style.height = `${height}px`;
|
|
8323
|
+
const ctx = canvas.getContext("2d");
|
|
8324
|
+
ctx.scale(ratio, ratio);
|
|
8325
|
+
return [canvas, ctx];
|
|
8326
|
+
}
|
|
8327
|
+
var ImageStroke = class {
|
|
8328
|
+
canvas = document.createElement("canvas");
|
|
8329
|
+
method;
|
|
8330
|
+
use(method) {
|
|
8331
|
+
this.method = method;
|
|
8332
|
+
return this;
|
|
8333
|
+
}
|
|
8334
|
+
make(image, options) {
|
|
8335
|
+
const { canvas } = this;
|
|
8336
|
+
const ctx = this.canvas.getContext("2d");
|
|
8337
|
+
const strokeSize = options.thickness * 2;
|
|
8338
|
+
const [resultWidth, resultHeight] = [image.width, image.height].map((val) => val + strokeSize);
|
|
8339
|
+
if (resultWidth !== canvas.width || resultHeight !== canvas.height) {
|
|
8340
|
+
canvas.width = resultWidth;
|
|
8341
|
+
canvas.height = resultHeight;
|
|
8342
|
+
}
|
|
8343
|
+
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
|
8344
|
+
this.method(ctx, image, options);
|
|
8345
|
+
ctx.drawImage(image, options.thickness, options.thickness);
|
|
8346
|
+
return canvas;
|
|
8347
|
+
}
|
|
8348
|
+
};
|
|
8349
|
+
function getContours(ctx) {
|
|
8350
|
+
const cx = 0;
|
|
8351
|
+
const cy = 0;
|
|
8352
|
+
const canvasWidth = ctx.canvas.width;
|
|
8353
|
+
const canvasHeight = ctx.canvas.height;
|
|
8354
|
+
const paths = [];
|
|
8355
|
+
let lastPos = 3;
|
|
8356
|
+
const alpha = 100;
|
|
8357
|
+
const trace = () => {
|
|
8358
|
+
const path = [];
|
|
8359
|
+
const data = new Uint32Array(ctx.getImageData(cx, cy, canvasWidth, canvasHeight).data.buffer);
|
|
8360
|
+
let x;
|
|
8361
|
+
let y;
|
|
8362
|
+
let startX;
|
|
8363
|
+
let startY;
|
|
8364
|
+
let startPos = -1;
|
|
8365
|
+
let step;
|
|
8366
|
+
let prevStep = 9;
|
|
8367
|
+
const steps = [
|
|
8368
|
+
9,
|
|
8369
|
+
0,
|
|
8370
|
+
3,
|
|
8371
|
+
3,
|
|
8372
|
+
2,
|
|
8373
|
+
0,
|
|
8374
|
+
9,
|
|
8375
|
+
3,
|
|
8376
|
+
1,
|
|
8377
|
+
9,
|
|
8378
|
+
1,
|
|
8379
|
+
1,
|
|
8380
|
+
2,
|
|
8381
|
+
0,
|
|
8382
|
+
2,
|
|
8383
|
+
9
|
|
8384
|
+
];
|
|
8385
|
+
let time = 50;
|
|
8386
|
+
function getState(x, y) {
|
|
8387
|
+
return x >= 0 && y >= 0 && x < canvasWidth && y < canvasHeight ? data[y * canvasWidth + x] >>> 24 > alpha : false;
|
|
8388
|
+
}
|
|
8389
|
+
function getNextStep(x, y) {
|
|
8390
|
+
let v = 0;
|
|
8391
|
+
if (getState(x - 1, y - 1)) v += 1;
|
|
8392
|
+
if (getState(x, y - 1)) v += 2;
|
|
8393
|
+
if (getState(x - 1, y)) v += 4;
|
|
8394
|
+
if (getState(x, y)) v += 8;
|
|
8395
|
+
if (time > 50) time += 10;
|
|
8396
|
+
else time += 10;
|
|
8397
|
+
if (v === 6) return prevStep === 0 ? 2 : 3;
|
|
8398
|
+
else if (v === 9) return prevStep === 3 ? 0 : 1;
|
|
8399
|
+
else return steps[v];
|
|
8400
|
+
}
|
|
8401
|
+
for (let i = lastPos; i < data.length; i++) if (data[i] >>> 24 > alpha) {
|
|
8402
|
+
startPos = lastPos = i;
|
|
8403
|
+
break;
|
|
8404
|
+
}
|
|
8405
|
+
if (startPos >= 0) {
|
|
8406
|
+
x = startX = startPos % canvasWidth;
|
|
8407
|
+
y = startY = Math.floor(startPos / canvasWidth);
|
|
8408
|
+
do {
|
|
8409
|
+
step = getNextStep(x, y);
|
|
8410
|
+
if (step === 0) y--;
|
|
8411
|
+
else if (step === 1) y++;
|
|
8412
|
+
else if (step === 2) x--;
|
|
8413
|
+
else if (step === 3) x++;
|
|
8414
|
+
if (step !== prevStep) {
|
|
8415
|
+
path.push({
|
|
8416
|
+
x: x + cx,
|
|
8417
|
+
y: y + cy
|
|
8418
|
+
});
|
|
8419
|
+
prevStep = step;
|
|
8420
|
+
}
|
|
8421
|
+
} while (x !== startX || y !== startY);
|
|
8422
|
+
}
|
|
8423
|
+
paths.push(path);
|
|
8424
|
+
return path;
|
|
8425
|
+
};
|
|
8426
|
+
trace();
|
|
8427
|
+
return paths;
|
|
8428
|
+
}
|
|
8429
|
+
//#endregion
|
|
8183
8430
|
//#region src/convert/shape.ts
|
|
8184
8431
|
async function convertShapeElementToSvg(el) {
|
|
8185
8432
|
if (![
|
|
@@ -8439,221 +8686,6 @@ function convertSvgLinearGradient(value) {
|
|
|
8439
8686
|
}
|
|
8440
8687
|
}
|
|
8441
8688
|
//#endregion
|
|
8442
|
-
//#region src/convert/image.ts
|
|
8443
|
-
function cachedFetchImageBitmap(url) {
|
|
8444
|
-
if (typeof url === "string" && url.startsWith("http")) return assets.loadBy(url).then((blob) => assets.fetchImageBitmap(blob));
|
|
8445
|
-
return assets.fetchImageBitmap(url);
|
|
8446
|
-
}
|
|
8447
|
-
async function convertImageElementToUrl(el) {
|
|
8448
|
-
const { cropping = {}, transform = {}, style = {}, maskUrl, imageEffects = [], imageEffectsRatio = 1 } = el;
|
|
8449
|
-
const url = el.clipUrl || el.url;
|
|
8450
|
-
const { translateX = 0, translateY = 0, zoom = 1 } = transform ?? {};
|
|
8451
|
-
const { scaleX = 1, scaleY = 1, filter } = style;
|
|
8452
|
-
if (translateX === 0 && translateY === 0 && zoom === 1 && scaleX === 1 && scaleY === 1 && !maskUrl && !filter && !imageEffects.length) return url;
|
|
8453
|
-
const img = await cachedFetchImageBitmap(url);
|
|
8454
|
-
const { originWidth = img.width, originHeight = img.height, imageWidth = originWidth, imageHeight = originHeight } = transform;
|
|
8455
|
-
const { width = originWidth, height = originHeight } = style;
|
|
8456
|
-
const dpr = window.devicePixelRatio || 1;
|
|
8457
|
-
const [canvas, ctx] = createCanvas(width, height, dpr);
|
|
8458
|
-
if (filter) ctx.filter = filter;
|
|
8459
|
-
ctx.scale(scaleX, scaleY);
|
|
8460
|
-
ctx.translate(scaleX < 0 ? -width : 0, scaleY < 0 ? -height : 0);
|
|
8461
|
-
if (maskUrl) {
|
|
8462
|
-
const mask = await cachedFetchImageBitmap(maskUrl);
|
|
8463
|
-
ctx.drawImage(mask, 0, 0, cropping?.maskWidth ?? width, cropping?.maskHeight ?? height);
|
|
8464
|
-
ctx.globalCompositeOperation = "source-in";
|
|
8465
|
-
mask.close();
|
|
8466
|
-
}
|
|
8467
|
-
const dw = imageWidth * zoom;
|
|
8468
|
-
const dh = imageHeight * zoom;
|
|
8469
|
-
const dx = -(dw / 2 - imageWidth / 2) + translateX;
|
|
8470
|
-
const dy = -(dh / 2 - imageHeight / 2) + translateY;
|
|
8471
|
-
ctx.drawImage(img, 0, 0, img.width, img.height, dx, dy, dw, dh);
|
|
8472
|
-
img.close();
|
|
8473
|
-
ctx.globalCompositeOperation = "source-over";
|
|
8474
|
-
if (imageEffects.length > 0) {
|
|
8475
|
-
const scale = .9;
|
|
8476
|
-
const center = {
|
|
8477
|
-
x: (width - width * scale) / 2,
|
|
8478
|
-
y: (height - height * scale) / 2
|
|
8479
|
-
};
|
|
8480
|
-
const canvasBitmap = await createImageBitmap(canvas);
|
|
8481
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
8482
|
-
ctx.scale(scale, scale);
|
|
8483
|
-
for (let i = imageEffects.length - 1; i >= 0; i--) {
|
|
8484
|
-
const { filling, offset, stroke } = imageEffects[i];
|
|
8485
|
-
let effectCanvas = canvasBitmap;
|
|
8486
|
-
if (filling) {
|
|
8487
|
-
const [canvas1, ctx1] = createCanvas(width, height, dpr);
|
|
8488
|
-
ctx1.drawImage(effectCanvas, 0, 0, width, height);
|
|
8489
|
-
ctx1.globalCompositeOperation = "source-in";
|
|
8490
|
-
if (filling.color) {
|
|
8491
|
-
const [canvas2, ctx2] = createCanvas(width, height, dpr);
|
|
8492
|
-
ctx2.fillStyle = filling.color;
|
|
8493
|
-
ctx2.fillRect(0, 0, width, height);
|
|
8494
|
-
ctx1.drawImage(canvas2, 0, 0, width, height);
|
|
8495
|
-
} else if (filling.imageContent?.image) {
|
|
8496
|
-
const img2 = await cachedFetchImageBitmap(filling.imageContent.image);
|
|
8497
|
-
ctx1.drawImage(img2, 0, 0, width, height);
|
|
8498
|
-
img2.close();
|
|
8499
|
-
}
|
|
8500
|
-
effectCanvas = canvas1;
|
|
8501
|
-
}
|
|
8502
|
-
stroke?.forEach(({ width, color }) => {
|
|
8503
|
-
effectCanvas = new ImageStroke().use((ctx, image, options) => {
|
|
8504
|
-
const [, ctx1] = createCanvas(image.width, image.height);
|
|
8505
|
-
ctx1.drawImage(image, 0, 0);
|
|
8506
|
-
const paths = getContours(ctx1);
|
|
8507
|
-
const x = options.thickness;
|
|
8508
|
-
const y = options.thickness;
|
|
8509
|
-
ctx.strokeStyle = options.color;
|
|
8510
|
-
ctx.lineWidth = options.thickness * 2;
|
|
8511
|
-
ctx.lineJoin = "round";
|
|
8512
|
-
paths.forEach((path) => {
|
|
8513
|
-
ctx.beginPath();
|
|
8514
|
-
ctx.moveTo(x + path[0].x, y + path[1].y);
|
|
8515
|
-
for (let i = 1; i < path.length; i++) ctx.lineTo(x + path[i].x, y + path[i].y);
|
|
8516
|
-
ctx.closePath();
|
|
8517
|
-
});
|
|
8518
|
-
ctx.stroke();
|
|
8519
|
-
}).make(effectCanvas, {
|
|
8520
|
-
color,
|
|
8521
|
-
thickness: width / 50 * imageEffectsRatio
|
|
8522
|
-
});
|
|
8523
|
-
});
|
|
8524
|
-
if (offset) {
|
|
8525
|
-
let { x, y } = offset;
|
|
8526
|
-
x = x / 50 * imageEffectsRatio * 200;
|
|
8527
|
-
y = y / 50 * imageEffectsRatio * 200;
|
|
8528
|
-
ctx.drawImage(effectCanvas, x + center.x, y + center.y, width, height);
|
|
8529
|
-
} else ctx.drawImage(effectCanvas, center.x, center.y, width, height);
|
|
8530
|
-
}
|
|
8531
|
-
canvasBitmap.close();
|
|
8532
|
-
}
|
|
8533
|
-
return await new Promise((resolve) => {
|
|
8534
|
-
canvas.toBlob((blob) => {
|
|
8535
|
-
try {
|
|
8536
|
-
resolve(URL.createObjectURL(blob));
|
|
8537
|
-
} catch (e) {
|
|
8538
|
-
console.error(`Failed to URL.createObjectURL, url: ${url}`, e);
|
|
8539
|
-
resolve(url);
|
|
8540
|
-
}
|
|
8541
|
-
});
|
|
8542
|
-
});
|
|
8543
|
-
}
|
|
8544
|
-
function createCanvas(width, height, ratio = 1) {
|
|
8545
|
-
const canvas = document.createElement("canvas");
|
|
8546
|
-
canvas.width = width * ratio;
|
|
8547
|
-
canvas.height = height * ratio;
|
|
8548
|
-
canvas.style.width = `${width}px`;
|
|
8549
|
-
canvas.style.height = `${height}px`;
|
|
8550
|
-
const ctx = canvas.getContext("2d");
|
|
8551
|
-
ctx.scale(ratio, ratio);
|
|
8552
|
-
return [canvas, ctx];
|
|
8553
|
-
}
|
|
8554
|
-
var ImageStroke = class {
|
|
8555
|
-
canvas = document.createElement("canvas");
|
|
8556
|
-
method;
|
|
8557
|
-
use(method) {
|
|
8558
|
-
this.method = method;
|
|
8559
|
-
return this;
|
|
8560
|
-
}
|
|
8561
|
-
make(image, options) {
|
|
8562
|
-
const { canvas } = this;
|
|
8563
|
-
const ctx = this.canvas.getContext("2d");
|
|
8564
|
-
const strokeSize = options.thickness * 2;
|
|
8565
|
-
const [resultWidth, resultHeight] = [image.width, image.height].map((val) => val + strokeSize);
|
|
8566
|
-
if (resultWidth !== canvas.width || resultHeight !== canvas.height) {
|
|
8567
|
-
canvas.width = resultWidth;
|
|
8568
|
-
canvas.height = resultHeight;
|
|
8569
|
-
}
|
|
8570
|
-
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
|
8571
|
-
this.method(ctx, image, options);
|
|
8572
|
-
ctx.drawImage(image, options.thickness, options.thickness);
|
|
8573
|
-
return canvas;
|
|
8574
|
-
}
|
|
8575
|
-
};
|
|
8576
|
-
function getContours(ctx) {
|
|
8577
|
-
const cx = 0;
|
|
8578
|
-
const cy = 0;
|
|
8579
|
-
const canvasWidth = ctx.canvas.width;
|
|
8580
|
-
const canvasHeight = ctx.canvas.height;
|
|
8581
|
-
const paths = [];
|
|
8582
|
-
let lastPos = 3;
|
|
8583
|
-
const alpha = 100;
|
|
8584
|
-
const trace = () => {
|
|
8585
|
-
const path = [];
|
|
8586
|
-
const data = new Uint32Array(ctx.getImageData(cx, cy, canvasWidth, canvasHeight).data.buffer);
|
|
8587
|
-
let x;
|
|
8588
|
-
let y;
|
|
8589
|
-
let startX;
|
|
8590
|
-
let startY;
|
|
8591
|
-
let startPos = -1;
|
|
8592
|
-
let step;
|
|
8593
|
-
let prevStep = 9;
|
|
8594
|
-
const steps = [
|
|
8595
|
-
9,
|
|
8596
|
-
0,
|
|
8597
|
-
3,
|
|
8598
|
-
3,
|
|
8599
|
-
2,
|
|
8600
|
-
0,
|
|
8601
|
-
9,
|
|
8602
|
-
3,
|
|
8603
|
-
1,
|
|
8604
|
-
9,
|
|
8605
|
-
1,
|
|
8606
|
-
1,
|
|
8607
|
-
2,
|
|
8608
|
-
0,
|
|
8609
|
-
2,
|
|
8610
|
-
9
|
|
8611
|
-
];
|
|
8612
|
-
let time = 50;
|
|
8613
|
-
function getState(x, y) {
|
|
8614
|
-
return x >= 0 && y >= 0 && x < canvasWidth && y < canvasHeight ? data[y * canvasWidth + x] >>> 24 > alpha : false;
|
|
8615
|
-
}
|
|
8616
|
-
function getNextStep(x, y) {
|
|
8617
|
-
let v = 0;
|
|
8618
|
-
if (getState(x - 1, y - 1)) v += 1;
|
|
8619
|
-
if (getState(x, y - 1)) v += 2;
|
|
8620
|
-
if (getState(x - 1, y)) v += 4;
|
|
8621
|
-
if (getState(x, y)) v += 8;
|
|
8622
|
-
if (time > 50) time += 10;
|
|
8623
|
-
else time += 10;
|
|
8624
|
-
if (v === 6) return prevStep === 0 ? 2 : 3;
|
|
8625
|
-
else if (v === 9) return prevStep === 3 ? 0 : 1;
|
|
8626
|
-
else return steps[v];
|
|
8627
|
-
}
|
|
8628
|
-
for (let i = lastPos; i < data.length; i++) if (data[i] >>> 24 > alpha) {
|
|
8629
|
-
startPos = lastPos = i;
|
|
8630
|
-
break;
|
|
8631
|
-
}
|
|
8632
|
-
if (startPos >= 0) {
|
|
8633
|
-
x = startX = startPos % canvasWidth;
|
|
8634
|
-
y = startY = Math.floor(startPos / canvasWidth);
|
|
8635
|
-
do {
|
|
8636
|
-
step = getNextStep(x, y);
|
|
8637
|
-
if (step === 0) y--;
|
|
8638
|
-
else if (step === 1) y++;
|
|
8639
|
-
else if (step === 2) x--;
|
|
8640
|
-
else if (step === 3) x++;
|
|
8641
|
-
if (step !== prevStep) {
|
|
8642
|
-
path.push({
|
|
8643
|
-
x: x + cx,
|
|
8644
|
-
y: y + cy
|
|
8645
|
-
});
|
|
8646
|
-
prevStep = step;
|
|
8647
|
-
}
|
|
8648
|
-
} while (x !== startX || y !== startY);
|
|
8649
|
-
}
|
|
8650
|
-
paths.push(path);
|
|
8651
|
-
return path;
|
|
8652
|
-
};
|
|
8653
|
-
trace();
|
|
8654
|
-
return paths;
|
|
8655
|
-
}
|
|
8656
|
-
//#endregion
|
|
8657
8689
|
//#region src/convert/svg.ts
|
|
8658
8690
|
async function convertSvgElementToUrl(el) {
|
|
8659
8691
|
const { id, doc, url, style = {}, background = {} } = el;
|
|
@@ -8755,6 +8787,17 @@ async function convertTextEffects(el) {
|
|
|
8755
8787
|
return result;
|
|
8756
8788
|
}));
|
|
8757
8789
|
}
|
|
8790
|
+
function convertDeformationType(oldType) {
|
|
8791
|
+
return oldType.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`).replace(/^-/, "");
|
|
8792
|
+
}
|
|
8793
|
+
function convertTextDeformation(el) {
|
|
8794
|
+
const deformation = el.deformation;
|
|
8795
|
+
if (!deformation?.type) return;
|
|
8796
|
+
return {
|
|
8797
|
+
...deformation,
|
|
8798
|
+
type: convertDeformationType(deformation.type)
|
|
8799
|
+
};
|
|
8800
|
+
}
|
|
8758
8801
|
function getTextContents(el) {
|
|
8759
8802
|
if (el.version) return el.contents;
|
|
8760
8803
|
return el.contents.map((p) => {
|
|
@@ -8874,7 +8917,8 @@ async function convertElement(el, parent, context) {
|
|
|
8874
8917
|
element.foreground = {
|
|
8875
8918
|
enabled: true,
|
|
8876
8919
|
image: el.clipUrl || el.url,
|
|
8877
|
-
fillWithShape: true
|
|
8920
|
+
fillWithShape: true,
|
|
8921
|
+
effects: convertImageEffects(el)
|
|
8878
8922
|
};
|
|
8879
8923
|
if (el.clipUrl) meta.rawForegroundImage = el.url;
|
|
8880
8924
|
if (el.maskUrl && el.maskUrl !== el.url) style.maskImage = el.maskUrl;
|
|
@@ -8902,7 +8946,8 @@ async function convertElement(el, parent, context) {
|
|
|
8902
8946
|
};
|
|
8903
8947
|
element.text = clearUndef({
|
|
8904
8948
|
content: convertTextContent(el),
|
|
8905
|
-
effects: await convertTextEffects(el)
|
|
8949
|
+
effects: await convertTextEffects(el),
|
|
8950
|
+
deformation: convertTextDeformation(el)
|
|
8906
8951
|
});
|
|
8907
8952
|
meta.textEffectsId = el.effectId;
|
|
8908
8953
|
if (style.color && isGradientFill(style.color)) {
|
|
@@ -9297,4 +9342,4 @@ var options = {
|
|
|
9297
9342
|
//#region src/index.ts
|
|
9298
9343
|
var src_default = plugin;
|
|
9299
9344
|
//#endregion
|
|
9300
|
-
export { bidTidLoader, bigeLoader, cachedFetchImageBitmap, clipboardLoader, convertAnimation, convertBackground, convertDoc, convertElement, convertImageElementToUrl, convertLayout, convertSvgElementToUrl, convertTextContent, convertTextEffects, convertTextStyle, croppingToCropRect, src_default as default, getStyle, getTextContents, options, parseAnimations, plugin, transformToCropRect, useFonts };
|
|
9345
|
+
export { bidTidLoader, bigeLoader, cachedFetchImageBitmap, clipboardLoader, convertAnimation, convertBackground, convertDeformationType, convertDoc, convertElement, convertImageEffects, convertImageElementToUrl, convertLayout, convertSvgElementToUrl, convertTextContent, convertTextDeformation, convertTextEffects, convertTextStyle, croppingToCropRect, src_default as default, getStyle, getTextContents, options, parseAnimations, plugin, transformToCropRect, useFonts };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mce/bigesj",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.24.
|
|
4
|
+
"version": "0.24.3",
|
|
5
5
|
"description": "Plugin for mce",
|
|
6
6
|
"author": "wxm",
|
|
7
7
|
"license": "MIT",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"fflate": "^0.8.3",
|
|
49
|
-
"modern-openxml": "^1.12.
|
|
49
|
+
"modern-openxml": "^1.12.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"mce": "0.24.
|
|
52
|
+
"mce": "0.24.3"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"mce": "^0"
|