@leafer-draw/node 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/node.cjs +73 -75
- package/dist/node.cjs.map +1 -1
- package/dist/node.esm.js +73 -75
- package/dist/node.esm.js.map +1 -1
- package/dist/node.esm.min.js +1 -1
- package/dist/node.esm.min.js.map +1 -1
- package/dist/node.min.cjs +1 -1
- package/dist/node.min.cjs.map +1 -1
- package/package.json +10 -8
- package/src/core.ts +73 -0
- package/src/index.ts +1 -1
- package/types/index.d.ts +8 -1
package/dist/node.esm.js
CHANGED
|
@@ -255,7 +255,6 @@ function updateChange(updateList) {
|
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
const { worldBounds } = LeafBoundsHelper;
|
|
258
|
-
const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
|
|
259
258
|
class LayoutBlockData {
|
|
260
259
|
constructor(list) {
|
|
261
260
|
this.updatedBounds = new Bounds();
|
|
@@ -269,13 +268,7 @@ class LayoutBlockData {
|
|
|
269
268
|
this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
|
|
270
269
|
}
|
|
271
270
|
setAfter() {
|
|
272
|
-
|
|
273
|
-
if (list.some(leaf => leaf.noBounds)) {
|
|
274
|
-
this.afterBounds.set(bigBounds);
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
this.afterBounds.setListWithFn(list, worldBounds);
|
|
278
|
-
}
|
|
271
|
+
this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
|
|
279
272
|
this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
|
|
280
273
|
}
|
|
281
274
|
merge(data) {
|
|
@@ -477,6 +470,22 @@ class Renderer {
|
|
|
477
470
|
requestLayout() {
|
|
478
471
|
this.target.emit(LayoutEvent.REQUEST);
|
|
479
472
|
}
|
|
473
|
+
checkRender() {
|
|
474
|
+
if (this.running) {
|
|
475
|
+
const { target } = this;
|
|
476
|
+
if (target.isApp) {
|
|
477
|
+
target.emit(RenderEvent.CHILD_START, target);
|
|
478
|
+
target.children.forEach(leafer => {
|
|
479
|
+
leafer.renderer.FPS = this.FPS;
|
|
480
|
+
leafer.renderer.checkRender();
|
|
481
|
+
});
|
|
482
|
+
target.emit(RenderEvent.CHILD_END, target);
|
|
483
|
+
}
|
|
484
|
+
if (this.changed && this.canvas.view)
|
|
485
|
+
this.render();
|
|
486
|
+
this.target.emit(RenderEvent.NEXT);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
480
489
|
render(callback) {
|
|
481
490
|
if (!(this.running && this.canvas.view))
|
|
482
491
|
return this.update();
|
|
@@ -485,8 +494,6 @@ class Renderer {
|
|
|
485
494
|
this.totalBounds = new Bounds();
|
|
486
495
|
debug$1.log(target.innerName, '--->');
|
|
487
496
|
try {
|
|
488
|
-
if (!target.isApp)
|
|
489
|
-
target.app.emit(RenderEvent.CHILD_START, target);
|
|
490
497
|
this.emitRender(RenderEvent.START);
|
|
491
498
|
this.renderOnce(callback);
|
|
492
499
|
this.emitRender(RenderEvent.END, this.totalBounds);
|
|
@@ -554,20 +561,12 @@ class Renderer {
|
|
|
554
561
|
}
|
|
555
562
|
clipRender(block) {
|
|
556
563
|
const t = Run.start('PartRender');
|
|
557
|
-
const { canvas } = this;
|
|
558
|
-
const bounds = block.getIntersect(canvas.bounds);
|
|
559
|
-
const includes = block.includes(this.target.__world);
|
|
560
|
-
const realBounds = new Bounds(bounds);
|
|
564
|
+
const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
|
|
561
565
|
canvas.save();
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
|
|
567
|
-
canvas.clearWorld(bounds, true);
|
|
568
|
-
canvas.clipWorld(bounds, true);
|
|
569
|
-
}
|
|
570
|
-
this.__render(bounds, includes, realBounds);
|
|
566
|
+
bounds.spread(Renderer.clipSpread).ceil();
|
|
567
|
+
canvas.clearWorld(bounds, true);
|
|
568
|
+
canvas.clipWorld(bounds, true);
|
|
569
|
+
this.__render(bounds, realBounds);
|
|
571
570
|
canvas.restore();
|
|
572
571
|
Run.end(t);
|
|
573
572
|
}
|
|
@@ -576,28 +575,22 @@ class Renderer {
|
|
|
576
575
|
const { canvas } = this;
|
|
577
576
|
canvas.save();
|
|
578
577
|
canvas.clear();
|
|
579
|
-
this.__render(canvas.bounds
|
|
578
|
+
this.__render(canvas.bounds);
|
|
580
579
|
canvas.restore();
|
|
581
580
|
Run.end(t);
|
|
582
581
|
}
|
|
583
|
-
__render(bounds,
|
|
584
|
-
const
|
|
582
|
+
__render(bounds, realBounds) {
|
|
583
|
+
const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
|
|
585
584
|
if (this.needFill)
|
|
586
|
-
|
|
585
|
+
canvas.fillWorld(bounds, this.config.fill);
|
|
587
586
|
if (Debug.showRepaint)
|
|
588
|
-
|
|
589
|
-
this.target.__render(
|
|
587
|
+
Debug.drawRepaint(canvas, bounds);
|
|
588
|
+
this.target.__render(canvas, options);
|
|
590
589
|
this.renderBounds = realBounds = realBounds || bounds;
|
|
591
590
|
this.renderOptions = options;
|
|
592
591
|
this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
if (Debug.showBoundsView)
|
|
596
|
-
this.renderBoundsView(options);
|
|
597
|
-
this.canvas.updateRender(realBounds);
|
|
598
|
-
}
|
|
599
|
-
renderHitView(_options) { }
|
|
600
|
-
renderBoundsView(_options) { }
|
|
592
|
+
canvas.updateRender(realBounds);
|
|
593
|
+
}
|
|
601
594
|
addBlock(block) {
|
|
602
595
|
if (!this.updateBlocks)
|
|
603
596
|
this.updateBlocks = [];
|
|
@@ -613,17 +606,16 @@ class Renderer {
|
|
|
613
606
|
}
|
|
614
607
|
}
|
|
615
608
|
__requestRender() {
|
|
616
|
-
|
|
609
|
+
const target = this.target;
|
|
610
|
+
if (this.requestTime || !target)
|
|
617
611
|
return;
|
|
612
|
+
if (target.parentApp)
|
|
613
|
+
return target.parentApp.requestRender(false);
|
|
618
614
|
const requestTime = this.requestTime = Date.now();
|
|
619
615
|
Platform.requestRender(() => {
|
|
620
616
|
this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
|
|
621
617
|
this.requestTime = 0;
|
|
622
|
-
|
|
623
|
-
if (this.changed && this.canvas.view)
|
|
624
|
-
this.render();
|
|
625
|
-
this.target.emit(RenderEvent.NEXT);
|
|
626
|
-
}
|
|
618
|
+
this.checkRender();
|
|
627
619
|
});
|
|
628
620
|
}
|
|
629
621
|
__onResize(e) {
|
|
@@ -681,6 +673,7 @@ class Renderer {
|
|
|
681
673
|
}
|
|
682
674
|
}
|
|
683
675
|
}
|
|
676
|
+
Renderer.clipSpread = 10;
|
|
684
677
|
|
|
685
678
|
Object.assign(Creator, {
|
|
686
679
|
watcher: (target, options) => new Watcher(target, options),
|
|
@@ -1043,9 +1036,11 @@ const tempBox = new Bounds();
|
|
|
1043
1036
|
const tempPoint = {};
|
|
1044
1037
|
const tempScaleData = {};
|
|
1045
1038
|
function createData(leafPaint, image, paint, box) {
|
|
1046
|
-
const { blendMode, sync } = paint;
|
|
1039
|
+
const { blendMode, changeful, sync } = paint;
|
|
1047
1040
|
if (blendMode)
|
|
1048
1041
|
leafPaint.blendMode = blendMode;
|
|
1042
|
+
if (changeful)
|
|
1043
|
+
leafPaint.changeful = changeful;
|
|
1049
1044
|
if (sync)
|
|
1050
1045
|
leafPaint.sync = sync;
|
|
1051
1046
|
leafPaint.data = getPatternData(paint, box, image);
|
|
@@ -1278,40 +1273,32 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1278
1273
|
}
|
|
1279
1274
|
|
|
1280
1275
|
const { abs } = Math;
|
|
1281
|
-
function checkImage(ui, canvas, paint,
|
|
1276
|
+
function checkImage(ui, canvas, paint, allowDraw) {
|
|
1282
1277
|
const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
|
|
1283
|
-
const { pixelRatio } = canvas;
|
|
1284
|
-
if (!
|
|
1278
|
+
const { pixelRatio } = canvas, { data } = paint;
|
|
1279
|
+
if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
|
|
1285
1280
|
return false;
|
|
1286
1281
|
}
|
|
1287
1282
|
else {
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
let { width, height } = data;
|
|
1292
|
-
width *= abs(scaleX) * pixelRatio;
|
|
1293
|
-
height *= abs(scaleY) * pixelRatio;
|
|
1294
|
-
if (data.scaleX) {
|
|
1295
|
-
width *= data.scaleX;
|
|
1296
|
-
height *= data.scaleY;
|
|
1297
|
-
}
|
|
1298
|
-
allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
|
|
1283
|
+
if (allowDraw) {
|
|
1284
|
+
if (data.repeat) {
|
|
1285
|
+
allowDraw = false;
|
|
1299
1286
|
}
|
|
1300
1287
|
else {
|
|
1301
|
-
|
|
1288
|
+
if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
|
|
1289
|
+
let { width, height } = data;
|
|
1290
|
+
width *= abs(scaleX) * pixelRatio;
|
|
1291
|
+
height *= abs(scaleY) * pixelRatio;
|
|
1292
|
+
if (data.scaleX) {
|
|
1293
|
+
width *= data.scaleX;
|
|
1294
|
+
height *= data.scaleY;
|
|
1295
|
+
}
|
|
1296
|
+
allowDraw = (width * height > Platform.image.maxCacheSize);
|
|
1297
|
+
}
|
|
1302
1298
|
}
|
|
1303
1299
|
}
|
|
1304
|
-
if (
|
|
1305
|
-
canvas
|
|
1306
|
-
ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
|
|
1307
|
-
if (paint.blendMode)
|
|
1308
|
-
canvas.blendMode = paint.blendMode;
|
|
1309
|
-
if (data.opacity)
|
|
1310
|
-
canvas.opacity *= data.opacity;
|
|
1311
|
-
if (data.transform)
|
|
1312
|
-
canvas.transform(data.transform);
|
|
1313
|
-
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
|
|
1314
|
-
canvas.restore();
|
|
1300
|
+
if (allowDraw) {
|
|
1301
|
+
drawImage(ui, canvas, paint, data);
|
|
1315
1302
|
return true;
|
|
1316
1303
|
}
|
|
1317
1304
|
else {
|
|
@@ -1332,13 +1319,26 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1332
1319
|
}
|
|
1333
1320
|
}
|
|
1334
1321
|
}
|
|
1322
|
+
function drawImage(ui, canvas, paint, data) {
|
|
1323
|
+
canvas.save();
|
|
1324
|
+
ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
|
|
1325
|
+
if (paint.blendMode)
|
|
1326
|
+
canvas.blendMode = paint.blendMode;
|
|
1327
|
+
if (data.opacity)
|
|
1328
|
+
canvas.opacity *= data.opacity;
|
|
1329
|
+
if (data.transform)
|
|
1330
|
+
canvas.transform(data.transform);
|
|
1331
|
+
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
|
|
1332
|
+
canvas.restore();
|
|
1333
|
+
}
|
|
1335
1334
|
|
|
1336
1335
|
function recycleImage(attrName, data) {
|
|
1337
1336
|
const paints = data['_' + attrName];
|
|
1338
1337
|
if (paints instanceof Array) {
|
|
1339
|
-
let image, recycleMap, input, url;
|
|
1338
|
+
let paint, image, recycleMap, input, url;
|
|
1340
1339
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
1341
|
-
|
|
1340
|
+
paint = paints[i];
|
|
1341
|
+
image = paint.image;
|
|
1342
1342
|
url = image && image.url;
|
|
1343
1343
|
if (url) {
|
|
1344
1344
|
if (!recycleMap)
|
|
@@ -1353,8 +1353,6 @@ function recycleImage(attrName, data) {
|
|
|
1353
1353
|
}
|
|
1354
1354
|
image.unload(paints[i].loadId, !input.some((item) => item.url === url));
|
|
1355
1355
|
}
|
|
1356
|
-
else
|
|
1357
|
-
paints[i].style = null;
|
|
1358
1356
|
}
|
|
1359
1357
|
}
|
|
1360
1358
|
return recycleMap;
|
|
@@ -1533,7 +1531,7 @@ const { toOffsetOutBounds } = BoundsHelper;
|
|
|
1533
1531
|
const offsetOutBounds = {};
|
|
1534
1532
|
function innerShadow(ui, current, shape) {
|
|
1535
1533
|
let copyBounds, spreadScale;
|
|
1536
|
-
const { __nowWorld: nowWorld, __layout
|
|
1534
|
+
const { __nowWorld: nowWorld, __layout } = ui;
|
|
1537
1535
|
const { innerShadow } = ui.__;
|
|
1538
1536
|
const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
|
|
1539
1537
|
const other = current.getSameCanvas();
|