@leafer-draw/worker 2.0.1 → 2.0.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/worker.cjs +92 -65
- package/dist/worker.esm.js +80 -67
- package/dist/worker.esm.min.js +1 -1
- package/dist/worker.esm.min.js.map +1 -1
- package/dist/worker.js +139 -86
- package/dist/worker.min.cjs +1 -1
- package/dist/worker.min.cjs.map +1 -1
- package/dist/worker.min.js +1 -1
- package/dist/worker.min.js.map +1 -1
- package/dist/worker.module.js +144 -91
- package/dist/worker.module.min.js +1 -1
- package/dist/worker.module.min.js.map +1 -1
- package/package.json +7 -9
- package/src/index.ts +2 -2
- package/types/index.d.ts +1 -8
- package/src/core.ts +0 -86
package/dist/worker.cjs
CHANGED
|
@@ -13,6 +13,39 @@ exports.PathNodeHandleType = void 0;
|
|
|
13
13
|
PathNodeHandleType[PathNodeHandleType["mirror"] = 4] = "mirror";
|
|
14
14
|
})(exports.PathNodeHandleType || (exports.PathNodeHandleType = {}));
|
|
15
15
|
|
|
16
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) {
|
|
18
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
19
|
+
resolve(value);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
23
|
+
function fulfilled(value) {
|
|
24
|
+
try {
|
|
25
|
+
step(generator.next(value));
|
|
26
|
+
} catch (e) {
|
|
27
|
+
reject(e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function rejected(value) {
|
|
31
|
+
try {
|
|
32
|
+
step(generator["throw"](value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function step(result) {
|
|
38
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
39
|
+
}
|
|
40
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
45
|
+
var e = new Error(message);
|
|
46
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
47
|
+
};
|
|
48
|
+
|
|
16
49
|
class LeaferCanvas extends core.LeaferCanvasBase {
|
|
17
50
|
get allowBackgroundColor() {
|
|
18
51
|
return true;
|
|
@@ -37,8 +70,6 @@ core.canvasPatch(OffscreenCanvasRenderingContext2D.prototype);
|
|
|
37
70
|
|
|
38
71
|
core.canvasPatch(Path2D.prototype);
|
|
39
72
|
|
|
40
|
-
const {mineType: mineType} = core.FileHelper;
|
|
41
|
-
|
|
42
73
|
Object.assign(core.Creator, {
|
|
43
74
|
canvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
44
75
|
image: options => new core.LeaferImage(options)
|
|
@@ -49,7 +80,7 @@ function useCanvas(_canvasType, _power) {
|
|
|
49
80
|
createCanvas: (width, height) => new OffscreenCanvas(width, height),
|
|
50
81
|
canvasToDataURL: (canvas, type, quality) => new Promise((resolve, reject) => {
|
|
51
82
|
canvas.convertToBlob({
|
|
52
|
-
type:
|
|
83
|
+
type: core.FileHelper.mimeType(type),
|
|
53
84
|
quality: quality
|
|
54
85
|
}).then(blob => {
|
|
55
86
|
var reader = new FileReader;
|
|
@@ -61,14 +92,14 @@ function useCanvas(_canvasType, _power) {
|
|
|
61
92
|
});
|
|
62
93
|
}),
|
|
63
94
|
canvasToBolb: (canvas, type, quality) => canvas.convertToBlob({
|
|
64
|
-
type:
|
|
95
|
+
type: core.FileHelper.mimeType(type),
|
|
65
96
|
quality: quality
|
|
66
97
|
}),
|
|
67
98
|
canvasSaveAs: (_canvas, _filename, _quality) => new Promise(resolve => resolve()),
|
|
68
99
|
download(_url, _filename) {
|
|
69
100
|
return undefined;
|
|
70
101
|
},
|
|
71
|
-
loadImage(src) {
|
|
102
|
+
loadImage(src, _crossOrigin, _leaferImage) {
|
|
72
103
|
return new Promise((resolve, reject) => {
|
|
73
104
|
let req = new XMLHttpRequest;
|
|
74
105
|
req.open("GET", core.Platform.image.getRealURL(src), true);
|
|
@@ -83,6 +114,13 @@ function useCanvas(_canvasType, _power) {
|
|
|
83
114
|
req.onerror = e => reject(e);
|
|
84
115
|
req.send();
|
|
85
116
|
});
|
|
117
|
+
},
|
|
118
|
+
loadContent(url_1) {
|
|
119
|
+
return __awaiter(this, arguments, void 0, function*(url, responseType = "text") {
|
|
120
|
+
const response = yield fetch(url);
|
|
121
|
+
if (!response.ok) throw new Error(`${response.status}`);
|
|
122
|
+
return yield response[responseType]();
|
|
123
|
+
});
|
|
86
124
|
}
|
|
87
125
|
};
|
|
88
126
|
core.Platform.canvas = core.Creator.canvas();
|
|
@@ -582,7 +620,7 @@ class Renderer {
|
|
|
582
620
|
getCellList() {
|
|
583
621
|
return undefined;
|
|
584
622
|
}
|
|
585
|
-
addBlock(block) {
|
|
623
|
+
addBlock(block, _leafList) {
|
|
586
624
|
if (!this.updateBlocks) this.updateBlocks = [];
|
|
587
625
|
this.updateBlocks.push(block);
|
|
588
626
|
}
|
|
@@ -630,7 +668,8 @@ class Renderer {
|
|
|
630
668
|
__onLayoutEnd(event) {
|
|
631
669
|
if (event.data) event.data.map(item => {
|
|
632
670
|
let empty;
|
|
633
|
-
|
|
671
|
+
const {updatedList: updatedList} = item;
|
|
672
|
+
if (updatedList) updatedList.list.some(leaf => {
|
|
634
673
|
empty = !leaf.__world.width || !leaf.__world.height;
|
|
635
674
|
if (empty) {
|
|
636
675
|
if (!leaf.isLeafer) debug.tip(leaf.innerName, ": empty");
|
|
@@ -638,7 +677,7 @@ class Renderer {
|
|
|
638
677
|
}
|
|
639
678
|
return empty;
|
|
640
679
|
});
|
|
641
|
-
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
|
|
680
|
+
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds, updatedList);
|
|
642
681
|
});
|
|
643
682
|
}
|
|
644
683
|
emitRender(type, bounds, options) {
|
|
@@ -978,11 +1017,14 @@ function compute(attrName, ui) {
|
|
|
978
1017
|
function getLeafPaint(attrName, paint, ui) {
|
|
979
1018
|
if (!core.isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
|
|
980
1019
|
let leafPaint;
|
|
981
|
-
const {boxBounds: boxBounds} = ui.__layout;
|
|
982
|
-
switch (
|
|
1020
|
+
const {boxBounds: boxBounds} = ui.__layout, {type: type} = paint;
|
|
1021
|
+
switch (type) {
|
|
983
1022
|
case "image":
|
|
1023
|
+
case "film":
|
|
1024
|
+
case "video":
|
|
984
1025
|
if (!paint.url) return undefined;
|
|
985
1026
|
leafPaint = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
|
|
1027
|
+
if (type !== "image") draw.PaintImage[type](leafPaint);
|
|
986
1028
|
break;
|
|
987
1029
|
|
|
988
1030
|
case "linear":
|
|
@@ -998,7 +1040,7 @@ function getLeafPaint(attrName, paint, ui) {
|
|
|
998
1040
|
break;
|
|
999
1041
|
|
|
1000
1042
|
case "solid":
|
|
1001
|
-
const {
|
|
1043
|
+
const {color: color, opacity: opacity} = paint;
|
|
1002
1044
|
leafPaint = {
|
|
1003
1045
|
type: type,
|
|
1004
1046
|
style: draw.ColorConvert.string(color, opacity)
|
|
@@ -1042,7 +1084,7 @@ const {isSame: isSame} = core.BoundsHelper;
|
|
|
1042
1084
|
|
|
1043
1085
|
function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
1044
1086
|
let leafPaint, event;
|
|
1045
|
-
const image = core.ImageManager.get(paint);
|
|
1087
|
+
const image = core.ImageManager.get(paint, paint.type);
|
|
1046
1088
|
if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
|
|
1047
1089
|
leafPaint = cache.leafPaint;
|
|
1048
1090
|
} else {
|
|
@@ -1103,8 +1145,8 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
|
1103
1145
|
}
|
|
1104
1146
|
|
|
1105
1147
|
function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
|
|
1106
|
-
|
|
1107
|
-
|
|
1148
|
+
const data = ui.__;
|
|
1149
|
+
if (attrName === "fill" && !data.__naturalWidth) {
|
|
1108
1150
|
data.__naturalWidth = image.width / data.pixelRatio;
|
|
1109
1151
|
data.__naturalHeight = image.height / data.pixelRatio;
|
|
1110
1152
|
if (data.__autoSide) {
|
|
@@ -1116,7 +1158,12 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
|
|
|
1116
1158
|
return false;
|
|
1117
1159
|
}
|
|
1118
1160
|
}
|
|
1119
|
-
if (!leafPaint.data)
|
|
1161
|
+
if (!leafPaint.data) {
|
|
1162
|
+
draw.PaintImage.createData(leafPaint, image, paint, boxBounds);
|
|
1163
|
+
const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
|
|
1164
|
+
const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
|
|
1165
|
+
if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
|
|
1166
|
+
}
|
|
1120
1167
|
return true;
|
|
1121
1168
|
}
|
|
1122
1169
|
|
|
@@ -1159,7 +1206,7 @@ function getPatternData(paint, box, image) {
|
|
|
1159
1206
|
if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
|
|
1160
1207
|
if (paint.mode === "strench") paint.mode = "stretch";
|
|
1161
1208
|
const {width: width, height: height} = image;
|
|
1162
|
-
const {
|
|
1209
|
+
const {mode: mode, align: align, offset: offset, scale: scale, size: size, rotation: rotation, skew: skew, clipSize: clipSize, repeat: repeat, gap: gap, interlace: interlace} = paint;
|
|
1163
1210
|
const sameBox = box.width === width && box.height === height;
|
|
1164
1211
|
const data = {
|
|
1165
1212
|
mode: mode
|
|
@@ -1222,8 +1269,6 @@ function getPatternData(paint, box, image) {
|
|
|
1222
1269
|
data.scaleX = scaleX;
|
|
1223
1270
|
data.scaleY = scaleY;
|
|
1224
1271
|
}
|
|
1225
|
-
if (opacity && opacity < 1) data.opacity = opacity;
|
|
1226
|
-
if (filters) data.filters = filters;
|
|
1227
1272
|
if (repeat) data.repeat = core.isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
|
|
1228
1273
|
if (interlace) data.interlace = core.isNumber(interlace) || interlace.type === "percent" ? {
|
|
1229
1274
|
type: "x",
|
|
@@ -1254,7 +1299,7 @@ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translat
|
|
|
1254
1299
|
|
|
1255
1300
|
function stretchMode(data, box, scaleX, scaleY) {
|
|
1256
1301
|
const transform = get$2(), {x: x, y: y} = box;
|
|
1257
|
-
if (x || y) translate(transform, x, y); else transform.onlyScale = true;
|
|
1302
|
+
if (x || y) translate(transform, x, y); else if (scaleX > 0 && scaleY > 0) transform.onlyScale = true;
|
|
1258
1303
|
scaleHelper(transform, scaleX, scaleY);
|
|
1259
1304
|
data.transform = transform;
|
|
1260
1305
|
}
|
|
@@ -1326,39 +1371,6 @@ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
|
|
|
1326
1371
|
translate(transform, box.x + x, box.y + y);
|
|
1327
1372
|
}
|
|
1328
1373
|
|
|
1329
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
1330
|
-
function adopt(value) {
|
|
1331
|
-
return value instanceof P ? value : new P(function(resolve) {
|
|
1332
|
-
resolve(value);
|
|
1333
|
-
});
|
|
1334
|
-
}
|
|
1335
|
-
return new (P || (P = Promise))(function(resolve, reject) {
|
|
1336
|
-
function fulfilled(value) {
|
|
1337
|
-
try {
|
|
1338
|
-
step(generator.next(value));
|
|
1339
|
-
} catch (e) {
|
|
1340
|
-
reject(e);
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
function rejected(value) {
|
|
1344
|
-
try {
|
|
1345
|
-
step(generator["throw"](value));
|
|
1346
|
-
} catch (e) {
|
|
1347
|
-
reject(e);
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
function step(result) {
|
|
1351
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
1352
|
-
}
|
|
1353
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1354
|
-
});
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
1358
|
-
var e = new Error(message);
|
|
1359
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1360
|
-
};
|
|
1361
|
-
|
|
1362
1374
|
const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
|
|
1363
1375
|
|
|
1364
1376
|
const {getFloorScale: getFloorScale} = core.MathHelper, {abs: abs$1} = Math;
|
|
@@ -1376,10 +1388,10 @@ function createPatternTask(paint, ui, canvas, renderOptions) {
|
|
|
1376
1388
|
}
|
|
1377
1389
|
|
|
1378
1390
|
function createPattern(paint, ui, canvas, renderOptions) {
|
|
1379
|
-
let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
|
|
1391
|
+
let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
|
|
1380
1392
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1381
1393
|
if (!(core.Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
|
|
1382
|
-
const {image: image, data: data} = paint, {transform: transform, gap: gap} = data, fixScale = draw.PaintImage.getPatternFixScale(paint, scaleX, scaleY);
|
|
1394
|
+
const {image: image, data: data} = paint, {opacity: opacity, filters: filters} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = draw.PaintImage.getPatternFixScale(paint, scaleX, scaleY);
|
|
1383
1395
|
let imageMatrix, xGap, yGap, {width: width, height: height} = image;
|
|
1384
1396
|
if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
|
|
1385
1397
|
width *= scaleX;
|
|
@@ -1395,7 +1407,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
|
|
|
1395
1407
|
if (transform) copy$1(imageMatrix, transform);
|
|
1396
1408
|
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1397
1409
|
}
|
|
1398
|
-
const imageCanvas = image.getCanvas(width, height,
|
|
1410
|
+
const imageCanvas = image.getCanvas(width, height, opacity, filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
|
|
1399
1411
|
const pattern = image.getPattern(imageCanvas, data.repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
|
|
1400
1412
|
paint.style = pattern;
|
|
1401
1413
|
paint.patternId = id;
|
|
@@ -1416,15 +1428,15 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
|
|
|
1416
1428
|
}
|
|
1417
1429
|
|
|
1418
1430
|
function checkImage(paint, drawImage, ui, canvas, renderOptions) {
|
|
1419
|
-
const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
|
|
1431
|
+
const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
|
|
1420
1432
|
const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
|
|
1421
|
-
if (!data || paint.patternId ===
|
|
1433
|
+
if (!data || paint.patternId === id && !exporting || snapshot) {
|
|
1422
1434
|
return false;
|
|
1423
1435
|
} else {
|
|
1424
1436
|
if (drawImage) {
|
|
1425
1437
|
if (data.repeat) {
|
|
1426
1438
|
drawImage = false;
|
|
1427
|
-
} else if (!(originPaint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
|
|
1439
|
+
} else if (!(originPaint.changeful || paint.film || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
|
|
1428
1440
|
drawImage = core.Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096;
|
|
1429
1441
|
}
|
|
1430
1442
|
}
|
|
@@ -1442,20 +1454,21 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
|
|
|
1442
1454
|
}
|
|
1443
1455
|
}
|
|
1444
1456
|
|
|
1445
|
-
function drawImage(paint,
|
|
1446
|
-
const {data: data, image: image
|
|
1447
|
-
let {width: width, height: height} = image
|
|
1448
|
-
if (
|
|
1457
|
+
function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
|
|
1458
|
+
const {data: data, image: image, complex: complex} = paint;
|
|
1459
|
+
let {width: width, height: height} = image;
|
|
1460
|
+
if (complex) {
|
|
1461
|
+
const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
|
|
1449
1462
|
canvas.save();
|
|
1450
|
-
|
|
1463
|
+
complex === 2 && canvas.clipUI(ui);
|
|
1451
1464
|
blendMode && (canvas.blendMode = blendMode);
|
|
1452
1465
|
opacity && (canvas.opacity *= opacity);
|
|
1453
1466
|
transform && canvas.transform(transform);
|
|
1454
|
-
|
|
1467
|
+
image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
|
|
1455
1468
|
canvas.restore();
|
|
1456
1469
|
} else {
|
|
1457
1470
|
if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
|
|
1458
|
-
|
|
1471
|
+
image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
|
|
1459
1472
|
}
|
|
1460
1473
|
}
|
|
1461
1474
|
|
|
@@ -2394,6 +2407,13 @@ Object.assign(draw.Effect, EffectModule);
|
|
|
2394
2407
|
|
|
2395
2408
|
useCanvas();
|
|
2396
2409
|
|
|
2410
|
+
Object.defineProperty(exports, "LeaferFilm", {
|
|
2411
|
+
enumerable: true,
|
|
2412
|
+
get: function() {
|
|
2413
|
+
return core.LeaferFilm;
|
|
2414
|
+
}
|
|
2415
|
+
});
|
|
2416
|
+
|
|
2397
2417
|
Object.defineProperty(exports, "LeaferImage", {
|
|
2398
2418
|
enumerable: true,
|
|
2399
2419
|
get: function() {
|
|
@@ -2401,6 +2421,13 @@ Object.defineProperty(exports, "LeaferImage", {
|
|
|
2401
2421
|
}
|
|
2402
2422
|
});
|
|
2403
2423
|
|
|
2424
|
+
Object.defineProperty(exports, "LeaferVideo", {
|
|
2425
|
+
enumerable: true,
|
|
2426
|
+
get: function() {
|
|
2427
|
+
return core.LeaferVideo;
|
|
2428
|
+
}
|
|
2429
|
+
});
|
|
2430
|
+
|
|
2404
2431
|
exports.Layouter = Layouter;
|
|
2405
2432
|
|
|
2406
2433
|
exports.LeaferCanvas = LeaferCanvas;
|
package/dist/worker.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { LeaferCanvasBase, Platform, canvasPatch,
|
|
1
|
+
import { LeaferCanvasBase, Platform, canvasPatch, Creator, LeaferImage, defineKey, FileHelper, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, isArray, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, ResizeEvent, isObject, BoundsHelper, FourNumberHelper, Matrix, isUndefined, isString, ImageEvent, MatrixHelper, MathHelper, AlignHelper, PointHelper, isNumber, getMatrixData, AroundHelper, Direction4 } from "@leafer/core";
|
|
2
2
|
|
|
3
3
|
export * from "@leafer/core";
|
|
4
4
|
|
|
5
|
-
export { LeaferImage } from "@leafer/core";
|
|
5
|
+
export { LeaferFilm, LeaferImage, LeaferVideo } from "@leafer/core";
|
|
6
6
|
|
|
7
7
|
import { Paint, PaintImage, ColorConvert, PaintGradient, Effect, Group, TextConvert } from "@leafer-ui/draw";
|
|
8
8
|
|
|
@@ -17,6 +17,39 @@ var PathNodeHandleType;
|
|
|
17
17
|
PathNodeHandleType[PathNodeHandleType["mirror"] = 4] = "mirror";
|
|
18
18
|
})(PathNodeHandleType || (PathNodeHandleType = {}));
|
|
19
19
|
|
|
20
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
21
|
+
function adopt(value) {
|
|
22
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
23
|
+
resolve(value);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
27
|
+
function fulfilled(value) {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.next(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function rejected(value) {
|
|
35
|
+
try {
|
|
36
|
+
step(generator["throw"](value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function step(result) {
|
|
42
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
43
|
+
}
|
|
44
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
49
|
+
var e = new Error(message);
|
|
50
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
51
|
+
};
|
|
52
|
+
|
|
20
53
|
class LeaferCanvas extends LeaferCanvasBase {
|
|
21
54
|
get allowBackgroundColor() {
|
|
22
55
|
return true;
|
|
@@ -41,8 +74,6 @@ canvasPatch(OffscreenCanvasRenderingContext2D.prototype);
|
|
|
41
74
|
|
|
42
75
|
canvasPatch(Path2D.prototype);
|
|
43
76
|
|
|
44
|
-
const {mineType: mineType} = FileHelper;
|
|
45
|
-
|
|
46
77
|
Object.assign(Creator, {
|
|
47
78
|
canvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
48
79
|
image: options => new LeaferImage(options)
|
|
@@ -53,7 +84,7 @@ function useCanvas(_canvasType, _power) {
|
|
|
53
84
|
createCanvas: (width, height) => new OffscreenCanvas(width, height),
|
|
54
85
|
canvasToDataURL: (canvas, type, quality) => new Promise((resolve, reject) => {
|
|
55
86
|
canvas.convertToBlob({
|
|
56
|
-
type:
|
|
87
|
+
type: FileHelper.mimeType(type),
|
|
57
88
|
quality: quality
|
|
58
89
|
}).then(blob => {
|
|
59
90
|
var reader = new FileReader;
|
|
@@ -65,14 +96,14 @@ function useCanvas(_canvasType, _power) {
|
|
|
65
96
|
});
|
|
66
97
|
}),
|
|
67
98
|
canvasToBolb: (canvas, type, quality) => canvas.convertToBlob({
|
|
68
|
-
type:
|
|
99
|
+
type: FileHelper.mimeType(type),
|
|
69
100
|
quality: quality
|
|
70
101
|
}),
|
|
71
102
|
canvasSaveAs: (_canvas, _filename, _quality) => new Promise(resolve => resolve()),
|
|
72
103
|
download(_url, _filename) {
|
|
73
104
|
return undefined;
|
|
74
105
|
},
|
|
75
|
-
loadImage(src) {
|
|
106
|
+
loadImage(src, _crossOrigin, _leaferImage) {
|
|
76
107
|
return new Promise((resolve, reject) => {
|
|
77
108
|
let req = new XMLHttpRequest;
|
|
78
109
|
req.open("GET", Platform.image.getRealURL(src), true);
|
|
@@ -87,6 +118,13 @@ function useCanvas(_canvasType, _power) {
|
|
|
87
118
|
req.onerror = e => reject(e);
|
|
88
119
|
req.send();
|
|
89
120
|
});
|
|
121
|
+
},
|
|
122
|
+
loadContent(url_1) {
|
|
123
|
+
return __awaiter(this, arguments, void 0, function*(url, responseType = "text") {
|
|
124
|
+
const response = yield fetch(url);
|
|
125
|
+
if (!response.ok) throw new Error(`${response.status}`);
|
|
126
|
+
return yield response[responseType]();
|
|
127
|
+
});
|
|
90
128
|
}
|
|
91
129
|
};
|
|
92
130
|
Platform.canvas = Creator.canvas();
|
|
@@ -586,7 +624,7 @@ class Renderer {
|
|
|
586
624
|
getCellList() {
|
|
587
625
|
return undefined;
|
|
588
626
|
}
|
|
589
|
-
addBlock(block) {
|
|
627
|
+
addBlock(block, _leafList) {
|
|
590
628
|
if (!this.updateBlocks) this.updateBlocks = [];
|
|
591
629
|
this.updateBlocks.push(block);
|
|
592
630
|
}
|
|
@@ -634,7 +672,8 @@ class Renderer {
|
|
|
634
672
|
__onLayoutEnd(event) {
|
|
635
673
|
if (event.data) event.data.map(item => {
|
|
636
674
|
let empty;
|
|
637
|
-
|
|
675
|
+
const {updatedList: updatedList} = item;
|
|
676
|
+
if (updatedList) updatedList.list.some(leaf => {
|
|
638
677
|
empty = !leaf.__world.width || !leaf.__world.height;
|
|
639
678
|
if (empty) {
|
|
640
679
|
if (!leaf.isLeafer) debug.tip(leaf.innerName, ": empty");
|
|
@@ -642,7 +681,7 @@ class Renderer {
|
|
|
642
681
|
}
|
|
643
682
|
return empty;
|
|
644
683
|
});
|
|
645
|
-
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
|
|
684
|
+
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds, updatedList);
|
|
646
685
|
});
|
|
647
686
|
}
|
|
648
687
|
emitRender(type, bounds, options) {
|
|
@@ -982,11 +1021,14 @@ function compute(attrName, ui) {
|
|
|
982
1021
|
function getLeafPaint(attrName, paint, ui) {
|
|
983
1022
|
if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
|
|
984
1023
|
let leafPaint;
|
|
985
|
-
const {boxBounds: boxBounds} = ui.__layout;
|
|
986
|
-
switch (
|
|
1024
|
+
const {boxBounds: boxBounds} = ui.__layout, {type: type} = paint;
|
|
1025
|
+
switch (type) {
|
|
987
1026
|
case "image":
|
|
1027
|
+
case "film":
|
|
1028
|
+
case "video":
|
|
988
1029
|
if (!paint.url) return undefined;
|
|
989
1030
|
leafPaint = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
|
|
1031
|
+
if (type !== "image") PaintImage[type](leafPaint);
|
|
990
1032
|
break;
|
|
991
1033
|
|
|
992
1034
|
case "linear":
|
|
@@ -1002,7 +1044,7 @@ function getLeafPaint(attrName, paint, ui) {
|
|
|
1002
1044
|
break;
|
|
1003
1045
|
|
|
1004
1046
|
case "solid":
|
|
1005
|
-
const {
|
|
1047
|
+
const {color: color, opacity: opacity} = paint;
|
|
1006
1048
|
leafPaint = {
|
|
1007
1049
|
type: type,
|
|
1008
1050
|
style: ColorConvert.string(color, opacity)
|
|
@@ -1046,7 +1088,7 @@ const {isSame: isSame} = BoundsHelper;
|
|
|
1046
1088
|
|
|
1047
1089
|
function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
1048
1090
|
let leafPaint, event;
|
|
1049
|
-
const image = ImageManager.get(paint);
|
|
1091
|
+
const image = ImageManager.get(paint, paint.type);
|
|
1050
1092
|
if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
|
|
1051
1093
|
leafPaint = cache.leafPaint;
|
|
1052
1094
|
} else {
|
|
@@ -1107,8 +1149,8 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
|
1107
1149
|
}
|
|
1108
1150
|
|
|
1109
1151
|
function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
|
|
1110
|
-
|
|
1111
|
-
|
|
1152
|
+
const data = ui.__;
|
|
1153
|
+
if (attrName === "fill" && !data.__naturalWidth) {
|
|
1112
1154
|
data.__naturalWidth = image.width / data.pixelRatio;
|
|
1113
1155
|
data.__naturalHeight = image.height / data.pixelRatio;
|
|
1114
1156
|
if (data.__autoSide) {
|
|
@@ -1120,7 +1162,12 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
|
|
|
1120
1162
|
return false;
|
|
1121
1163
|
}
|
|
1122
1164
|
}
|
|
1123
|
-
if (!leafPaint.data)
|
|
1165
|
+
if (!leafPaint.data) {
|
|
1166
|
+
PaintImage.createData(leafPaint, image, paint, boxBounds);
|
|
1167
|
+
const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
|
|
1168
|
+
const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
|
|
1169
|
+
if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
|
|
1170
|
+
}
|
|
1124
1171
|
return true;
|
|
1125
1172
|
}
|
|
1126
1173
|
|
|
@@ -1163,7 +1210,7 @@ function getPatternData(paint, box, image) {
|
|
|
1163
1210
|
if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
|
|
1164
1211
|
if (paint.mode === "strench") paint.mode = "stretch";
|
|
1165
1212
|
const {width: width, height: height} = image;
|
|
1166
|
-
const {
|
|
1213
|
+
const {mode: mode, align: align, offset: offset, scale: scale, size: size, rotation: rotation, skew: skew, clipSize: clipSize, repeat: repeat, gap: gap, interlace: interlace} = paint;
|
|
1167
1214
|
const sameBox = box.width === width && box.height === height;
|
|
1168
1215
|
const data = {
|
|
1169
1216
|
mode: mode
|
|
@@ -1226,8 +1273,6 @@ function getPatternData(paint, box, image) {
|
|
|
1226
1273
|
data.scaleX = scaleX;
|
|
1227
1274
|
data.scaleY = scaleY;
|
|
1228
1275
|
}
|
|
1229
|
-
if (opacity && opacity < 1) data.opacity = opacity;
|
|
1230
|
-
if (filters) data.filters = filters;
|
|
1231
1276
|
if (repeat) data.repeat = isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
|
|
1232
1277
|
if (interlace) data.interlace = isNumber(interlace) || interlace.type === "percent" ? {
|
|
1233
1278
|
type: "x",
|
|
@@ -1258,7 +1303,7 @@ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translat
|
|
|
1258
1303
|
|
|
1259
1304
|
function stretchMode(data, box, scaleX, scaleY) {
|
|
1260
1305
|
const transform = get$2(), {x: x, y: y} = box;
|
|
1261
|
-
if (x || y) translate(transform, x, y); else transform.onlyScale = true;
|
|
1306
|
+
if (x || y) translate(transform, x, y); else if (scaleX > 0 && scaleY > 0) transform.onlyScale = true;
|
|
1262
1307
|
scaleHelper(transform, scaleX, scaleY);
|
|
1263
1308
|
data.transform = transform;
|
|
1264
1309
|
}
|
|
@@ -1330,39 +1375,6 @@ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
|
|
|
1330
1375
|
translate(transform, box.x + x, box.y + y);
|
|
1331
1376
|
}
|
|
1332
1377
|
|
|
1333
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
1334
|
-
function adopt(value) {
|
|
1335
|
-
return value instanceof P ? value : new P(function(resolve) {
|
|
1336
|
-
resolve(value);
|
|
1337
|
-
});
|
|
1338
|
-
}
|
|
1339
|
-
return new (P || (P = Promise))(function(resolve, reject) {
|
|
1340
|
-
function fulfilled(value) {
|
|
1341
|
-
try {
|
|
1342
|
-
step(generator.next(value));
|
|
1343
|
-
} catch (e) {
|
|
1344
|
-
reject(e);
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
function rejected(value) {
|
|
1348
|
-
try {
|
|
1349
|
-
step(generator["throw"](value));
|
|
1350
|
-
} catch (e) {
|
|
1351
|
-
reject(e);
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
function step(result) {
|
|
1355
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
1356
|
-
}
|
|
1357
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1358
|
-
});
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
1362
|
-
var e = new Error(message);
|
|
1363
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1364
|
-
};
|
|
1365
|
-
|
|
1366
1378
|
const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
|
|
1367
1379
|
|
|
1368
1380
|
const {getFloorScale: getFloorScale} = MathHelper, {abs: abs$1} = Math;
|
|
@@ -1380,10 +1392,10 @@ function createPatternTask(paint, ui, canvas, renderOptions) {
|
|
|
1380
1392
|
}
|
|
1381
1393
|
|
|
1382
1394
|
function createPattern(paint, ui, canvas, renderOptions) {
|
|
1383
|
-
let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
|
|
1395
|
+
let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
|
|
1384
1396
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1385
1397
|
if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
|
|
1386
|
-
const {image: image, data: data} = paint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
|
|
1398
|
+
const {image: image, data: data} = paint, {opacity: opacity, filters: filters} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
|
|
1387
1399
|
let imageMatrix, xGap, yGap, {width: width, height: height} = image;
|
|
1388
1400
|
if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
|
|
1389
1401
|
width *= scaleX;
|
|
@@ -1399,7 +1411,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
|
|
|
1399
1411
|
if (transform) copy$1(imageMatrix, transform);
|
|
1400
1412
|
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1401
1413
|
}
|
|
1402
|
-
const imageCanvas = image.getCanvas(width, height,
|
|
1414
|
+
const imageCanvas = image.getCanvas(width, height, opacity, filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
|
|
1403
1415
|
const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
|
|
1404
1416
|
paint.style = pattern;
|
|
1405
1417
|
paint.patternId = id;
|
|
@@ -1420,15 +1432,15 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
|
|
|
1420
1432
|
}
|
|
1421
1433
|
|
|
1422
1434
|
function checkImage(paint, drawImage, ui, canvas, renderOptions) {
|
|
1423
|
-
const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
|
|
1435
|
+
const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
|
|
1424
1436
|
const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
|
|
1425
|
-
if (!data || paint.patternId ===
|
|
1437
|
+
if (!data || paint.patternId === id && !exporting || snapshot) {
|
|
1426
1438
|
return false;
|
|
1427
1439
|
} else {
|
|
1428
1440
|
if (drawImage) {
|
|
1429
1441
|
if (data.repeat) {
|
|
1430
1442
|
drawImage = false;
|
|
1431
|
-
} else if (!(originPaint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
|
|
1443
|
+
} else if (!(originPaint.changeful || paint.film || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
|
|
1432
1444
|
drawImage = Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096;
|
|
1433
1445
|
}
|
|
1434
1446
|
}
|
|
@@ -1446,20 +1458,21 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
|
|
|
1446
1458
|
}
|
|
1447
1459
|
}
|
|
1448
1460
|
|
|
1449
|
-
function drawImage(paint,
|
|
1450
|
-
const {data: data, image: image
|
|
1451
|
-
let {width: width, height: height} = image
|
|
1452
|
-
if (
|
|
1461
|
+
function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
|
|
1462
|
+
const {data: data, image: image, complex: complex} = paint;
|
|
1463
|
+
let {width: width, height: height} = image;
|
|
1464
|
+
if (complex) {
|
|
1465
|
+
const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
|
|
1453
1466
|
canvas.save();
|
|
1454
|
-
|
|
1467
|
+
complex === 2 && canvas.clipUI(ui);
|
|
1455
1468
|
blendMode && (canvas.blendMode = blendMode);
|
|
1456
1469
|
opacity && (canvas.opacity *= opacity);
|
|
1457
1470
|
transform && canvas.transform(transform);
|
|
1458
|
-
|
|
1471
|
+
image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
|
|
1459
1472
|
canvas.restore();
|
|
1460
1473
|
} else {
|
|
1461
1474
|
if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
|
|
1462
|
-
|
|
1475
|
+
image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
|
|
1463
1476
|
}
|
|
1464
1477
|
}
|
|
1465
1478
|
|