@leafer-draw/worker 1.5.3 → 1.6.1
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 +73 -75
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.esm.js +73 -75
- package/dist/worker.esm.js.map +1 -1
- package/dist/worker.esm.min.js +1 -1
- package/dist/worker.esm.min.js.map +1 -1
- package/dist/worker.js +265 -169
- package/dist/worker.js.map +1 -1
- 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 +265 -169
- package/dist/worker.module.js.map +1 -1
- package/dist/worker.module.min.js +1 -1
- package/dist/worker.module.min.js.map +1 -1
- package/package.json +9 -7
- package/src/core.ts +86 -0
- package/src/index.ts +2 -2
- package/types/index.d.ts +8 -1
package/dist/worker.esm.js
CHANGED
|
@@ -242,7 +242,6 @@ function updateChange(updateList) {
|
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
const { worldBounds } = LeafBoundsHelper;
|
|
245
|
-
const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
|
|
246
245
|
class LayoutBlockData {
|
|
247
246
|
constructor(list) {
|
|
248
247
|
this.updatedBounds = new Bounds();
|
|
@@ -256,13 +255,7 @@ class LayoutBlockData {
|
|
|
256
255
|
this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
|
|
257
256
|
}
|
|
258
257
|
setAfter() {
|
|
259
|
-
|
|
260
|
-
if (list.some(leaf => leaf.noBounds)) {
|
|
261
|
-
this.afterBounds.set(bigBounds);
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
this.afterBounds.setListWithFn(list, worldBounds);
|
|
265
|
-
}
|
|
258
|
+
this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
|
|
266
259
|
this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
|
|
267
260
|
}
|
|
268
261
|
merge(data) {
|
|
@@ -464,6 +457,22 @@ class Renderer {
|
|
|
464
457
|
requestLayout() {
|
|
465
458
|
this.target.emit(LayoutEvent.REQUEST);
|
|
466
459
|
}
|
|
460
|
+
checkRender() {
|
|
461
|
+
if (this.running) {
|
|
462
|
+
const { target } = this;
|
|
463
|
+
if (target.isApp) {
|
|
464
|
+
target.emit(RenderEvent.CHILD_START, target);
|
|
465
|
+
target.children.forEach(leafer => {
|
|
466
|
+
leafer.renderer.FPS = this.FPS;
|
|
467
|
+
leafer.renderer.checkRender();
|
|
468
|
+
});
|
|
469
|
+
target.emit(RenderEvent.CHILD_END, target);
|
|
470
|
+
}
|
|
471
|
+
if (this.changed && this.canvas.view)
|
|
472
|
+
this.render();
|
|
473
|
+
this.target.emit(RenderEvent.NEXT);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
467
476
|
render(callback) {
|
|
468
477
|
if (!(this.running && this.canvas.view))
|
|
469
478
|
return this.update();
|
|
@@ -472,8 +481,6 @@ class Renderer {
|
|
|
472
481
|
this.totalBounds = new Bounds();
|
|
473
482
|
debug.log(target.innerName, '--->');
|
|
474
483
|
try {
|
|
475
|
-
if (!target.isApp)
|
|
476
|
-
target.app.emit(RenderEvent.CHILD_START, target);
|
|
477
484
|
this.emitRender(RenderEvent.START);
|
|
478
485
|
this.renderOnce(callback);
|
|
479
486
|
this.emitRender(RenderEvent.END, this.totalBounds);
|
|
@@ -541,20 +548,12 @@ class Renderer {
|
|
|
541
548
|
}
|
|
542
549
|
clipRender(block) {
|
|
543
550
|
const t = Run.start('PartRender');
|
|
544
|
-
const { canvas } = this;
|
|
545
|
-
const bounds = block.getIntersect(canvas.bounds);
|
|
546
|
-
const includes = block.includes(this.target.__world);
|
|
547
|
-
const realBounds = new Bounds(bounds);
|
|
551
|
+
const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
|
|
548
552
|
canvas.save();
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
|
|
554
|
-
canvas.clearWorld(bounds, true);
|
|
555
|
-
canvas.clipWorld(bounds, true);
|
|
556
|
-
}
|
|
557
|
-
this.__render(bounds, includes, realBounds);
|
|
553
|
+
bounds.spread(Renderer.clipSpread).ceil();
|
|
554
|
+
canvas.clearWorld(bounds, true);
|
|
555
|
+
canvas.clipWorld(bounds, true);
|
|
556
|
+
this.__render(bounds, realBounds);
|
|
558
557
|
canvas.restore();
|
|
559
558
|
Run.end(t);
|
|
560
559
|
}
|
|
@@ -563,28 +562,22 @@ class Renderer {
|
|
|
563
562
|
const { canvas } = this;
|
|
564
563
|
canvas.save();
|
|
565
564
|
canvas.clear();
|
|
566
|
-
this.__render(canvas.bounds
|
|
565
|
+
this.__render(canvas.bounds);
|
|
567
566
|
canvas.restore();
|
|
568
567
|
Run.end(t);
|
|
569
568
|
}
|
|
570
|
-
__render(bounds,
|
|
571
|
-
const
|
|
569
|
+
__render(bounds, realBounds) {
|
|
570
|
+
const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
|
|
572
571
|
if (this.needFill)
|
|
573
|
-
|
|
572
|
+
canvas.fillWorld(bounds, this.config.fill);
|
|
574
573
|
if (Debug.showRepaint)
|
|
575
|
-
|
|
576
|
-
this.target.__render(
|
|
574
|
+
Debug.drawRepaint(canvas, bounds);
|
|
575
|
+
this.target.__render(canvas, options);
|
|
577
576
|
this.renderBounds = realBounds = realBounds || bounds;
|
|
578
577
|
this.renderOptions = options;
|
|
579
578
|
this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
if (Debug.showBoundsView)
|
|
583
|
-
this.renderBoundsView(options);
|
|
584
|
-
this.canvas.updateRender(realBounds);
|
|
585
|
-
}
|
|
586
|
-
renderHitView(_options) { }
|
|
587
|
-
renderBoundsView(_options) { }
|
|
579
|
+
canvas.updateRender(realBounds);
|
|
580
|
+
}
|
|
588
581
|
addBlock(block) {
|
|
589
582
|
if (!this.updateBlocks)
|
|
590
583
|
this.updateBlocks = [];
|
|
@@ -600,17 +593,16 @@ class Renderer {
|
|
|
600
593
|
}
|
|
601
594
|
}
|
|
602
595
|
__requestRender() {
|
|
603
|
-
|
|
596
|
+
const target = this.target;
|
|
597
|
+
if (this.requestTime || !target)
|
|
604
598
|
return;
|
|
599
|
+
if (target.parentApp)
|
|
600
|
+
return target.parentApp.requestRender(false);
|
|
605
601
|
const requestTime = this.requestTime = Date.now();
|
|
606
602
|
Platform.requestRender(() => {
|
|
607
603
|
this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
|
|
608
604
|
this.requestTime = 0;
|
|
609
|
-
|
|
610
|
-
if (this.changed && this.canvas.view)
|
|
611
|
-
this.render();
|
|
612
|
-
this.target.emit(RenderEvent.NEXT);
|
|
613
|
-
}
|
|
605
|
+
this.checkRender();
|
|
614
606
|
});
|
|
615
607
|
}
|
|
616
608
|
__onResize(e) {
|
|
@@ -668,6 +660,7 @@ class Renderer {
|
|
|
668
660
|
}
|
|
669
661
|
}
|
|
670
662
|
}
|
|
663
|
+
Renderer.clipSpread = 10;
|
|
671
664
|
|
|
672
665
|
Object.assign(Creator, {
|
|
673
666
|
watcher: (target, options) => new Watcher(target, options),
|
|
@@ -1030,9 +1023,11 @@ const tempBox = new Bounds();
|
|
|
1030
1023
|
const tempPoint = {};
|
|
1031
1024
|
const tempScaleData = {};
|
|
1032
1025
|
function createData(leafPaint, image, paint, box) {
|
|
1033
|
-
const { blendMode, sync } = paint;
|
|
1026
|
+
const { blendMode, changeful, sync } = paint;
|
|
1034
1027
|
if (blendMode)
|
|
1035
1028
|
leafPaint.blendMode = blendMode;
|
|
1029
|
+
if (changeful)
|
|
1030
|
+
leafPaint.changeful = changeful;
|
|
1036
1031
|
if (sync)
|
|
1037
1032
|
leafPaint.sync = sync;
|
|
1038
1033
|
leafPaint.data = getPatternData(paint, box, image);
|
|
@@ -1297,40 +1292,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
1297
1292
|
};
|
|
1298
1293
|
|
|
1299
1294
|
const { abs } = Math;
|
|
1300
|
-
function checkImage(ui, canvas, paint,
|
|
1295
|
+
function checkImage(ui, canvas, paint, allowDraw) {
|
|
1301
1296
|
const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
|
|
1302
|
-
const { pixelRatio } = canvas;
|
|
1303
|
-
if (!
|
|
1297
|
+
const { pixelRatio } = canvas, { data } = paint;
|
|
1298
|
+
if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
|
|
1304
1299
|
return false;
|
|
1305
1300
|
}
|
|
1306
1301
|
else {
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
let { width, height } = data;
|
|
1311
|
-
width *= abs(scaleX) * pixelRatio;
|
|
1312
|
-
height *= abs(scaleY) * pixelRatio;
|
|
1313
|
-
if (data.scaleX) {
|
|
1314
|
-
width *= data.scaleX;
|
|
1315
|
-
height *= data.scaleY;
|
|
1316
|
-
}
|
|
1317
|
-
allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
|
|
1302
|
+
if (allowDraw) {
|
|
1303
|
+
if (data.repeat) {
|
|
1304
|
+
allowDraw = false;
|
|
1318
1305
|
}
|
|
1319
1306
|
else {
|
|
1320
|
-
|
|
1307
|
+
if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
|
|
1308
|
+
let { width, height } = data;
|
|
1309
|
+
width *= abs(scaleX) * pixelRatio;
|
|
1310
|
+
height *= abs(scaleY) * pixelRatio;
|
|
1311
|
+
if (data.scaleX) {
|
|
1312
|
+
width *= data.scaleX;
|
|
1313
|
+
height *= data.scaleY;
|
|
1314
|
+
}
|
|
1315
|
+
allowDraw = (width * height > Platform.image.maxCacheSize);
|
|
1316
|
+
}
|
|
1321
1317
|
}
|
|
1322
1318
|
}
|
|
1323
|
-
if (
|
|
1324
|
-
canvas
|
|
1325
|
-
ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
|
|
1326
|
-
if (paint.blendMode)
|
|
1327
|
-
canvas.blendMode = paint.blendMode;
|
|
1328
|
-
if (data.opacity)
|
|
1329
|
-
canvas.opacity *= data.opacity;
|
|
1330
|
-
if (data.transform)
|
|
1331
|
-
canvas.transform(data.transform);
|
|
1332
|
-
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
|
|
1333
|
-
canvas.restore();
|
|
1319
|
+
if (allowDraw) {
|
|
1320
|
+
drawImage(ui, canvas, paint, data);
|
|
1334
1321
|
return true;
|
|
1335
1322
|
}
|
|
1336
1323
|
else {
|
|
@@ -1351,13 +1338,26 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1351
1338
|
}
|
|
1352
1339
|
}
|
|
1353
1340
|
}
|
|
1341
|
+
function drawImage(ui, canvas, paint, data) {
|
|
1342
|
+
canvas.save();
|
|
1343
|
+
ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
|
|
1344
|
+
if (paint.blendMode)
|
|
1345
|
+
canvas.blendMode = paint.blendMode;
|
|
1346
|
+
if (data.opacity)
|
|
1347
|
+
canvas.opacity *= data.opacity;
|
|
1348
|
+
if (data.transform)
|
|
1349
|
+
canvas.transform(data.transform);
|
|
1350
|
+
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
|
|
1351
|
+
canvas.restore();
|
|
1352
|
+
}
|
|
1354
1353
|
|
|
1355
1354
|
function recycleImage(attrName, data) {
|
|
1356
1355
|
const paints = data['_' + attrName];
|
|
1357
1356
|
if (paints instanceof Array) {
|
|
1358
|
-
let image, recycleMap, input, url;
|
|
1357
|
+
let paint, image, recycleMap, input, url;
|
|
1359
1358
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
1360
|
-
|
|
1359
|
+
paint = paints[i];
|
|
1360
|
+
image = paint.image;
|
|
1361
1361
|
url = image && image.url;
|
|
1362
1362
|
if (url) {
|
|
1363
1363
|
if (!recycleMap)
|
|
@@ -1372,8 +1372,6 @@ function recycleImage(attrName, data) {
|
|
|
1372
1372
|
}
|
|
1373
1373
|
image.unload(paints[i].loadId, !input.some((item) => item.url === url));
|
|
1374
1374
|
}
|
|
1375
|
-
else
|
|
1376
|
-
paints[i].style = null;
|
|
1377
1375
|
}
|
|
1378
1376
|
}
|
|
1379
1377
|
return recycleMap;
|
|
@@ -1552,7 +1550,7 @@ const { toOffsetOutBounds } = BoundsHelper;
|
|
|
1552
1550
|
const offsetOutBounds = {};
|
|
1553
1551
|
function innerShadow(ui, current, shape) {
|
|
1554
1552
|
let copyBounds, spreadScale;
|
|
1555
|
-
const { __nowWorld: nowWorld, __layout
|
|
1553
|
+
const { __nowWorld: nowWorld, __layout } = ui;
|
|
1556
1554
|
const { innerShadow } = ui.__;
|
|
1557
1555
|
const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
|
|
1558
1556
|
const other = current.getSameCanvas();
|