@mce/bigesj 0.24.1 → 0.24.2
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 +265 -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,254 @@ ${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
|
+
let needsBase = false;
|
|
8190
|
+
for (const effect of imageEffects) {
|
|
8191
|
+
const { filling, offset, stroke } = effect;
|
|
8192
|
+
const transform = offset ? `translate(${offset.x / 50 * ratio * 200}, ${offset.y / 50 * ratio * 200})` : void 0;
|
|
8193
|
+
if (offset) needsBase = true;
|
|
8194
|
+
let fill;
|
|
8195
|
+
if (filling?.color) fill = { color: filling.color };
|
|
8196
|
+
else if (filling?.imageContent?.image) fill = { image: filling.imageContent.image };
|
|
8197
|
+
const strokes = Array.isArray(stroke) ? stroke : stroke ? [stroke] : [];
|
|
8198
|
+
if (strokes.length) strokes.forEach((s, i) => {
|
|
8199
|
+
effects.push({
|
|
8200
|
+
...transform ? { transform } : {},
|
|
8201
|
+
...i === 0 && fill ? { fill } : {},
|
|
8202
|
+
outline: {
|
|
8203
|
+
color: s.color,
|
|
8204
|
+
width: s.width / 50 * ratio
|
|
8205
|
+
}
|
|
8206
|
+
});
|
|
8207
|
+
});
|
|
8208
|
+
else if (fill) effects.push({
|
|
8209
|
+
...transform ? { transform } : {},
|
|
8210
|
+
fill
|
|
8211
|
+
});
|
|
8212
|
+
else if (transform) effects.push({ transform });
|
|
8213
|
+
}
|
|
8214
|
+
if (needsBase && effects.length) effects.push({});
|
|
8215
|
+
return effects.length ? effects : void 0;
|
|
8216
|
+
}
|
|
8217
|
+
function cachedFetchImageBitmap(url) {
|
|
8218
|
+
if (typeof url === "string" && url.startsWith("http")) return assets.loadBy(url).then((blob) => assets.fetchImageBitmap(blob));
|
|
8219
|
+
return assets.fetchImageBitmap(url);
|
|
8220
|
+
}
|
|
8221
|
+
async function convertImageElementToUrl(el) {
|
|
8222
|
+
const { cropping = {}, transform = {}, style = {}, maskUrl, imageEffects = [], imageEffectsRatio = 1 } = el;
|
|
8223
|
+
const url = el.clipUrl || el.url;
|
|
8224
|
+
const { translateX = 0, translateY = 0, zoom = 1 } = transform ?? {};
|
|
8225
|
+
const { scaleX = 1, scaleY = 1, filter } = style;
|
|
8226
|
+
if (translateX === 0 && translateY === 0 && zoom === 1 && scaleX === 1 && scaleY === 1 && !maskUrl && !filter && !imageEffects.length) return url;
|
|
8227
|
+
const img = await cachedFetchImageBitmap(url);
|
|
8228
|
+
const { originWidth = img.width, originHeight = img.height, imageWidth = originWidth, imageHeight = originHeight } = transform;
|
|
8229
|
+
const { width = originWidth, height = originHeight } = style;
|
|
8230
|
+
const dpr = window.devicePixelRatio || 1;
|
|
8231
|
+
const [canvas, ctx] = createCanvas(width, height, dpr);
|
|
8232
|
+
if (filter) ctx.filter = filter;
|
|
8233
|
+
ctx.scale(scaleX, scaleY);
|
|
8234
|
+
ctx.translate(scaleX < 0 ? -width : 0, scaleY < 0 ? -height : 0);
|
|
8235
|
+
if (maskUrl) {
|
|
8236
|
+
const mask = await cachedFetchImageBitmap(maskUrl);
|
|
8237
|
+
ctx.drawImage(mask, 0, 0, cropping?.maskWidth ?? width, cropping?.maskHeight ?? height);
|
|
8238
|
+
ctx.globalCompositeOperation = "source-in";
|
|
8239
|
+
mask.close();
|
|
8240
|
+
}
|
|
8241
|
+
const dw = imageWidth * zoom;
|
|
8242
|
+
const dh = imageHeight * zoom;
|
|
8243
|
+
const dx = -(dw / 2 - imageWidth / 2) + translateX;
|
|
8244
|
+
const dy = -(dh / 2 - imageHeight / 2) + translateY;
|
|
8245
|
+
ctx.drawImage(img, 0, 0, img.width, img.height, dx, dy, dw, dh);
|
|
8246
|
+
img.close();
|
|
8247
|
+
ctx.globalCompositeOperation = "source-over";
|
|
8248
|
+
if (imageEffects.length > 0) {
|
|
8249
|
+
const scale = .9;
|
|
8250
|
+
const center = {
|
|
8251
|
+
x: (width - width * scale) / 2,
|
|
8252
|
+
y: (height - height * scale) / 2
|
|
8253
|
+
};
|
|
8254
|
+
const canvasBitmap = await createImageBitmap(canvas);
|
|
8255
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
8256
|
+
ctx.scale(scale, scale);
|
|
8257
|
+
for (let i = imageEffects.length - 1; i >= 0; i--) {
|
|
8258
|
+
const { filling, offset, stroke } = imageEffects[i];
|
|
8259
|
+
let effectCanvas = canvasBitmap;
|
|
8260
|
+
if (filling) {
|
|
8261
|
+
const [canvas1, ctx1] = createCanvas(width, height, dpr);
|
|
8262
|
+
ctx1.drawImage(effectCanvas, 0, 0, width, height);
|
|
8263
|
+
ctx1.globalCompositeOperation = "source-in";
|
|
8264
|
+
if (filling.color) {
|
|
8265
|
+
const [canvas2, ctx2] = createCanvas(width, height, dpr);
|
|
8266
|
+
ctx2.fillStyle = filling.color;
|
|
8267
|
+
ctx2.fillRect(0, 0, width, height);
|
|
8268
|
+
ctx1.drawImage(canvas2, 0, 0, width, height);
|
|
8269
|
+
} else if (filling.imageContent?.image) {
|
|
8270
|
+
const img2 = await cachedFetchImageBitmap(filling.imageContent.image);
|
|
8271
|
+
ctx1.drawImage(img2, 0, 0, width, height);
|
|
8272
|
+
img2.close();
|
|
8273
|
+
}
|
|
8274
|
+
effectCanvas = canvas1;
|
|
8275
|
+
}
|
|
8276
|
+
stroke?.forEach(({ width, color }) => {
|
|
8277
|
+
effectCanvas = new ImageStroke().use((ctx, image, options) => {
|
|
8278
|
+
const [, ctx1] = createCanvas(image.width, image.height);
|
|
8279
|
+
ctx1.drawImage(image, 0, 0);
|
|
8280
|
+
const paths = getContours(ctx1);
|
|
8281
|
+
const x = options.thickness;
|
|
8282
|
+
const y = options.thickness;
|
|
8283
|
+
ctx.strokeStyle = options.color;
|
|
8284
|
+
ctx.lineWidth = options.thickness * 2;
|
|
8285
|
+
ctx.lineJoin = "round";
|
|
8286
|
+
paths.forEach((path) => {
|
|
8287
|
+
ctx.beginPath();
|
|
8288
|
+
ctx.moveTo(x + path[0].x, y + path[1].y);
|
|
8289
|
+
for (let i = 1; i < path.length; i++) ctx.lineTo(x + path[i].x, y + path[i].y);
|
|
8290
|
+
ctx.closePath();
|
|
8291
|
+
});
|
|
8292
|
+
ctx.stroke();
|
|
8293
|
+
}).make(effectCanvas, {
|
|
8294
|
+
color,
|
|
8295
|
+
thickness: width / 50 * imageEffectsRatio
|
|
8296
|
+
});
|
|
8297
|
+
});
|
|
8298
|
+
if (offset) {
|
|
8299
|
+
let { x, y } = offset;
|
|
8300
|
+
x = x / 50 * imageEffectsRatio * 200;
|
|
8301
|
+
y = y / 50 * imageEffectsRatio * 200;
|
|
8302
|
+
ctx.drawImage(effectCanvas, x + center.x, y + center.y, width, height);
|
|
8303
|
+
} else ctx.drawImage(effectCanvas, center.x, center.y, width, height);
|
|
8304
|
+
}
|
|
8305
|
+
canvasBitmap.close();
|
|
8306
|
+
}
|
|
8307
|
+
return await new Promise((resolve) => {
|
|
8308
|
+
canvas.toBlob((blob) => {
|
|
8309
|
+
try {
|
|
8310
|
+
resolve(URL.createObjectURL(blob));
|
|
8311
|
+
} catch (e) {
|
|
8312
|
+
console.error(`Failed to URL.createObjectURL, url: ${url}`, e);
|
|
8313
|
+
resolve(url);
|
|
8314
|
+
}
|
|
8315
|
+
});
|
|
8316
|
+
});
|
|
8317
|
+
}
|
|
8318
|
+
function createCanvas(width, height, ratio = 1) {
|
|
8319
|
+
const canvas = document.createElement("canvas");
|
|
8320
|
+
canvas.width = width * ratio;
|
|
8321
|
+
canvas.height = height * ratio;
|
|
8322
|
+
canvas.style.width = `${width}px`;
|
|
8323
|
+
canvas.style.height = `${height}px`;
|
|
8324
|
+
const ctx = canvas.getContext("2d");
|
|
8325
|
+
ctx.scale(ratio, ratio);
|
|
8326
|
+
return [canvas, ctx];
|
|
8327
|
+
}
|
|
8328
|
+
var ImageStroke = class {
|
|
8329
|
+
canvas = document.createElement("canvas");
|
|
8330
|
+
method;
|
|
8331
|
+
use(method) {
|
|
8332
|
+
this.method = method;
|
|
8333
|
+
return this;
|
|
8334
|
+
}
|
|
8335
|
+
make(image, options) {
|
|
8336
|
+
const { canvas } = this;
|
|
8337
|
+
const ctx = this.canvas.getContext("2d");
|
|
8338
|
+
const strokeSize = options.thickness * 2;
|
|
8339
|
+
const [resultWidth, resultHeight] = [image.width, image.height].map((val) => val + strokeSize);
|
|
8340
|
+
if (resultWidth !== canvas.width || resultHeight !== canvas.height) {
|
|
8341
|
+
canvas.width = resultWidth;
|
|
8342
|
+
canvas.height = resultHeight;
|
|
8343
|
+
}
|
|
8344
|
+
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
|
8345
|
+
this.method(ctx, image, options);
|
|
8346
|
+
ctx.drawImage(image, options.thickness, options.thickness);
|
|
8347
|
+
return canvas;
|
|
8348
|
+
}
|
|
8349
|
+
};
|
|
8350
|
+
function getContours(ctx) {
|
|
8351
|
+
const cx = 0;
|
|
8352
|
+
const cy = 0;
|
|
8353
|
+
const canvasWidth = ctx.canvas.width;
|
|
8354
|
+
const canvasHeight = ctx.canvas.height;
|
|
8355
|
+
const paths = [];
|
|
8356
|
+
let lastPos = 3;
|
|
8357
|
+
const alpha = 100;
|
|
8358
|
+
const trace = () => {
|
|
8359
|
+
const path = [];
|
|
8360
|
+
const data = new Uint32Array(ctx.getImageData(cx, cy, canvasWidth, canvasHeight).data.buffer);
|
|
8361
|
+
let x;
|
|
8362
|
+
let y;
|
|
8363
|
+
let startX;
|
|
8364
|
+
let startY;
|
|
8365
|
+
let startPos = -1;
|
|
8366
|
+
let step;
|
|
8367
|
+
let prevStep = 9;
|
|
8368
|
+
const steps = [
|
|
8369
|
+
9,
|
|
8370
|
+
0,
|
|
8371
|
+
3,
|
|
8372
|
+
3,
|
|
8373
|
+
2,
|
|
8374
|
+
0,
|
|
8375
|
+
9,
|
|
8376
|
+
3,
|
|
8377
|
+
1,
|
|
8378
|
+
9,
|
|
8379
|
+
1,
|
|
8380
|
+
1,
|
|
8381
|
+
2,
|
|
8382
|
+
0,
|
|
8383
|
+
2,
|
|
8384
|
+
9
|
|
8385
|
+
];
|
|
8386
|
+
let time = 50;
|
|
8387
|
+
function getState(x, y) {
|
|
8388
|
+
return x >= 0 && y >= 0 && x < canvasWidth && y < canvasHeight ? data[y * canvasWidth + x] >>> 24 > alpha : false;
|
|
8389
|
+
}
|
|
8390
|
+
function getNextStep(x, y) {
|
|
8391
|
+
let v = 0;
|
|
8392
|
+
if (getState(x - 1, y - 1)) v += 1;
|
|
8393
|
+
if (getState(x, y - 1)) v += 2;
|
|
8394
|
+
if (getState(x - 1, y)) v += 4;
|
|
8395
|
+
if (getState(x, y)) v += 8;
|
|
8396
|
+
if (time > 50) time += 10;
|
|
8397
|
+
else time += 10;
|
|
8398
|
+
if (v === 6) return prevStep === 0 ? 2 : 3;
|
|
8399
|
+
else if (v === 9) return prevStep === 3 ? 0 : 1;
|
|
8400
|
+
else return steps[v];
|
|
8401
|
+
}
|
|
8402
|
+
for (let i = lastPos; i < data.length; i++) if (data[i] >>> 24 > alpha) {
|
|
8403
|
+
startPos = lastPos = i;
|
|
8404
|
+
break;
|
|
8405
|
+
}
|
|
8406
|
+
if (startPos >= 0) {
|
|
8407
|
+
x = startX = startPos % canvasWidth;
|
|
8408
|
+
y = startY = Math.floor(startPos / canvasWidth);
|
|
8409
|
+
do {
|
|
8410
|
+
step = getNextStep(x, y);
|
|
8411
|
+
if (step === 0) y--;
|
|
8412
|
+
else if (step === 1) y++;
|
|
8413
|
+
else if (step === 2) x--;
|
|
8414
|
+
else if (step === 3) x++;
|
|
8415
|
+
if (step !== prevStep) {
|
|
8416
|
+
path.push({
|
|
8417
|
+
x: x + cx,
|
|
8418
|
+
y: y + cy
|
|
8419
|
+
});
|
|
8420
|
+
prevStep = step;
|
|
8421
|
+
}
|
|
8422
|
+
} while (x !== startX || y !== startY);
|
|
8423
|
+
}
|
|
8424
|
+
paths.push(path);
|
|
8425
|
+
return path;
|
|
8426
|
+
};
|
|
8427
|
+
trace();
|
|
8428
|
+
return paths;
|
|
8429
|
+
}
|
|
8430
|
+
//#endregion
|
|
8183
8431
|
//#region src/convert/shape.ts
|
|
8184
8432
|
async function convertShapeElementToSvg(el) {
|
|
8185
8433
|
if (![
|
|
@@ -8439,221 +8687,6 @@ function convertSvgLinearGradient(value) {
|
|
|
8439
8687
|
}
|
|
8440
8688
|
}
|
|
8441
8689
|
//#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
8690
|
//#region src/convert/svg.ts
|
|
8658
8691
|
async function convertSvgElementToUrl(el) {
|
|
8659
8692
|
const { id, doc, url, style = {}, background = {} } = el;
|
|
@@ -8755,6 +8788,17 @@ async function convertTextEffects(el) {
|
|
|
8755
8788
|
return result;
|
|
8756
8789
|
}));
|
|
8757
8790
|
}
|
|
8791
|
+
function convertDeformationType(oldType) {
|
|
8792
|
+
return oldType.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`).replace(/^-/, "");
|
|
8793
|
+
}
|
|
8794
|
+
function convertTextDeformation(el) {
|
|
8795
|
+
const deformation = el.deformation;
|
|
8796
|
+
if (!deformation?.type) return;
|
|
8797
|
+
return {
|
|
8798
|
+
...deformation,
|
|
8799
|
+
type: convertDeformationType(deformation.type)
|
|
8800
|
+
};
|
|
8801
|
+
}
|
|
8758
8802
|
function getTextContents(el) {
|
|
8759
8803
|
if (el.version) return el.contents;
|
|
8760
8804
|
return el.contents.map((p) => {
|
|
@@ -8874,7 +8918,8 @@ async function convertElement(el, parent, context) {
|
|
|
8874
8918
|
element.foreground = {
|
|
8875
8919
|
enabled: true,
|
|
8876
8920
|
image: el.clipUrl || el.url,
|
|
8877
|
-
fillWithShape: true
|
|
8921
|
+
fillWithShape: true,
|
|
8922
|
+
effects: convertImageEffects(el)
|
|
8878
8923
|
};
|
|
8879
8924
|
if (el.clipUrl) meta.rawForegroundImage = el.url;
|
|
8880
8925
|
if (el.maskUrl && el.maskUrl !== el.url) style.maskImage = el.maskUrl;
|
|
@@ -8902,7 +8947,8 @@ async function convertElement(el, parent, context) {
|
|
|
8902
8947
|
};
|
|
8903
8948
|
element.text = clearUndef({
|
|
8904
8949
|
content: convertTextContent(el),
|
|
8905
|
-
effects: await convertTextEffects(el)
|
|
8950
|
+
effects: await convertTextEffects(el),
|
|
8951
|
+
deformation: convertTextDeformation(el)
|
|
8906
8952
|
});
|
|
8907
8953
|
meta.textEffectsId = el.effectId;
|
|
8908
8954
|
if (style.color && isGradientFill(style.color)) {
|
|
@@ -9297,4 +9343,4 @@ var options = {
|
|
|
9297
9343
|
//#region src/index.ts
|
|
9298
9344
|
var src_default = plugin;
|
|
9299
9345
|
//#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 };
|
|
9346
|
+
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.2",
|
|
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.2"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"mce": "^0"
|