leafer-draw 1.5.2 → 1.6.0

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/web.esm.js CHANGED
@@ -423,7 +423,6 @@ function updateChange(updateList) {
423
423
  }
424
424
 
425
425
  const { worldBounds } = LeafBoundsHelper;
426
- const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
427
426
  class LayoutBlockData {
428
427
  constructor(list) {
429
428
  this.updatedBounds = new Bounds();
@@ -437,13 +436,7 @@ class LayoutBlockData {
437
436
  this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
438
437
  }
439
438
  setAfter() {
440
- const { list } = this.updatedList;
441
- if (list.some(leaf => leaf.noBounds)) {
442
- this.afterBounds.set(bigBounds);
443
- }
444
- else {
445
- this.afterBounds.setListWithFn(list, worldBounds);
446
- }
439
+ this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
447
440
  this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
448
441
  }
449
442
  merge(data) {
@@ -645,6 +638,13 @@ class Renderer {
645
638
  requestLayout() {
646
639
  this.target.emit(LayoutEvent.REQUEST);
647
640
  }
641
+ checkRender() {
642
+ if (this.running) {
643
+ if (this.changed && this.canvas.view)
644
+ this.render();
645
+ this.target.emit(RenderEvent.NEXT);
646
+ }
647
+ }
648
648
  render(callback) {
649
649
  if (!(this.running && this.canvas.view))
650
650
  return this.update();
@@ -653,8 +653,6 @@ class Renderer {
653
653
  this.totalBounds = new Bounds();
654
654
  debug.log(target.innerName, '--->');
655
655
  try {
656
- if (!target.isApp)
657
- target.app.emit(RenderEvent.CHILD_START, target);
658
656
  this.emitRender(RenderEvent.START);
659
657
  this.renderOnce(callback);
660
658
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -722,20 +720,12 @@ class Renderer {
722
720
  }
723
721
  clipRender(block) {
724
722
  const t = Run.start('PartRender');
725
- const { canvas } = this;
726
- const bounds = block.getIntersect(canvas.bounds);
727
- const includes = block.includes(this.target.__world);
728
- const realBounds = new Bounds(bounds);
723
+ const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
729
724
  canvas.save();
730
- if (includes && !Debug.showRepaint) {
731
- canvas.clear();
732
- }
733
- else {
734
- bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
735
- canvas.clearWorld(bounds, true);
736
- canvas.clipWorld(bounds, true);
737
- }
738
- this.__render(bounds, includes, realBounds);
725
+ bounds.spread(Renderer.clipSpread).ceil();
726
+ canvas.clearWorld(bounds, true);
727
+ canvas.clipWorld(bounds, true);
728
+ this.__render(bounds, block.includes(this.target.__world), realBounds);
739
729
  canvas.restore();
740
730
  Run.end(t);
741
731
  }
@@ -749,23 +739,17 @@ class Renderer {
749
739
  Run.end(t);
750
740
  }
751
741
  __render(bounds, includes, realBounds) {
752
- const options = bounds.includes(this.target.__world) ? { includes } : { bounds, includes };
742
+ const { canvas } = this, options = includes ? { includes } : { bounds, includes };
753
743
  if (this.needFill)
754
- this.canvas.fillWorld(bounds, this.config.fill);
744
+ canvas.fillWorld(bounds, this.config.fill);
755
745
  if (Debug.showRepaint)
756
- this.canvas.strokeWorld(bounds, 'red');
757
- this.target.__render(this.canvas, options);
746
+ Debug.drawRepaint(canvas, bounds);
747
+ this.target.__render(canvas, options);
758
748
  this.renderBounds = realBounds = realBounds || bounds;
759
749
  this.renderOptions = options;
760
750
  this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
761
- if (Debug.showHitView)
762
- this.renderHitView(options);
763
- if (Debug.showBoundsView)
764
- this.renderBoundsView(options);
765
- this.canvas.updateRender(realBounds);
766
- }
767
- renderHitView(_options) { }
768
- renderBoundsView(_options) { }
751
+ canvas.updateRender(realBounds);
752
+ }
769
753
  addBlock(block) {
770
754
  if (!this.updateBlocks)
771
755
  this.updateBlocks = [];
@@ -781,17 +765,24 @@ class Renderer {
781
765
  }
782
766
  }
783
767
  __requestRender() {
768
+ const target = this.target;
769
+ if (target.parentApp)
770
+ return target.parentApp.renderer.update(false);
784
771
  if (this.requestTime)
785
772
  return;
786
773
  const requestTime = this.requestTime = Date.now();
787
774
  Platform.requestRender(() => {
788
775
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
789
776
  this.requestTime = 0;
790
- if (this.running) {
791
- if (this.changed && this.canvas.view)
792
- this.render();
793
- this.target.emit(RenderEvent.NEXT);
777
+ if (target.isApp) {
778
+ target.emit(RenderEvent.CHILD_START, target);
779
+ target.children.forEach(leafer => {
780
+ leafer.renderer.FPS = this.FPS;
781
+ leafer.renderer.checkRender();
782
+ });
783
+ target.emit(RenderEvent.CHILD_END, target);
794
784
  }
785
+ this.checkRender();
795
786
  });
796
787
  }
797
788
  __onResize(e) {
@@ -849,6 +840,7 @@ class Renderer {
849
840
  }
850
841
  }
851
842
  }
843
+ Renderer.clipSpread = 10;
852
844
 
853
845
  Object.assign(Creator, {
854
846
  watcher: (target, options) => new Watcher(target, options),
@@ -1211,9 +1203,11 @@ const tempBox = new Bounds();
1211
1203
  const tempPoint = {};
1212
1204
  const tempScaleData = {};
1213
1205
  function createData(leafPaint, image, paint, box) {
1214
- const { blendMode, sync } = paint;
1206
+ const { blendMode, changeful, sync } = paint;
1215
1207
  if (blendMode)
1216
1208
  leafPaint.blendMode = blendMode;
1209
+ if (changeful)
1210
+ leafPaint.changeful = changeful;
1217
1211
  if (sync)
1218
1212
  leafPaint.sync = sync;
1219
1213
  leafPaint.data = getPatternData(paint, box, image);
@@ -1478,40 +1472,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1478
1472
  };
1479
1473
 
1480
1474
  const { abs } = Math;
1481
- function checkImage(ui, canvas, paint, allowPaint) {
1475
+ function checkImage(ui, canvas, paint, allowDraw) {
1482
1476
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1483
- const { pixelRatio } = canvas;
1484
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1477
+ const { pixelRatio } = canvas, { data } = paint;
1478
+ if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1485
1479
  return false;
1486
1480
  }
1487
1481
  else {
1488
- const { data } = paint;
1489
- if (allowPaint) {
1490
- if (!data.repeat) {
1491
- let { width, height } = data;
1492
- width *= abs(scaleX) * pixelRatio;
1493
- height *= abs(scaleY) * pixelRatio;
1494
- if (data.scaleX) {
1495
- width *= data.scaleX;
1496
- height *= data.scaleY;
1497
- }
1498
- allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
1482
+ if (allowDraw) {
1483
+ if (data.repeat) {
1484
+ allowDraw = false;
1499
1485
  }
1500
1486
  else {
1501
- allowPaint = false;
1487
+ if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
1488
+ let { width, height } = data;
1489
+ width *= abs(scaleX) * pixelRatio;
1490
+ height *= abs(scaleY) * pixelRatio;
1491
+ if (data.scaleX) {
1492
+ width *= data.scaleX;
1493
+ height *= data.scaleY;
1494
+ }
1495
+ allowDraw = (width * height > Platform.image.maxCacheSize);
1496
+ }
1502
1497
  }
1503
1498
  }
1504
- if (allowPaint) {
1505
- canvas.save();
1506
- ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1507
- if (paint.blendMode)
1508
- canvas.blendMode = paint.blendMode;
1509
- if (data.opacity)
1510
- canvas.opacity *= data.opacity;
1511
- if (data.transform)
1512
- canvas.transform(data.transform);
1513
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1514
- canvas.restore();
1499
+ if (allowDraw) {
1500
+ drawImage(ui, canvas, paint, data);
1515
1501
  return true;
1516
1502
  }
1517
1503
  else {
@@ -1532,13 +1518,26 @@ function checkImage(ui, canvas, paint, allowPaint) {
1532
1518
  }
1533
1519
  }
1534
1520
  }
1521
+ function drawImage(ui, canvas, paint, data) {
1522
+ canvas.save();
1523
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1524
+ if (paint.blendMode)
1525
+ canvas.blendMode = paint.blendMode;
1526
+ if (data.opacity)
1527
+ canvas.opacity *= data.opacity;
1528
+ if (data.transform)
1529
+ canvas.transform(data.transform);
1530
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1531
+ canvas.restore();
1532
+ }
1535
1533
 
1536
1534
  function recycleImage(attrName, data) {
1537
1535
  const paints = data['_' + attrName];
1538
1536
  if (paints instanceof Array) {
1539
- let image, recycleMap, input, url;
1537
+ let paint, image, recycleMap, input, url;
1540
1538
  for (let i = 0, len = paints.length; i < len; i++) {
1541
- image = paints[i].image;
1539
+ paint = paints[i];
1540
+ image = paint.image;
1542
1541
  url = image && image.url;
1543
1542
  if (url) {
1544
1543
  if (!recycleMap)
@@ -1553,8 +1552,6 @@ function recycleImage(attrName, data) {
1553
1552
  }
1554
1553
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
1555
1554
  }
1556
- else
1557
- paints[i].style = null;
1558
1555
  }
1559
1556
  }
1560
1557
  return recycleMap;
@@ -1733,7 +1730,7 @@ const { toOffsetOutBounds } = BoundsHelper;
1733
1730
  const offsetOutBounds = {};
1734
1731
  function innerShadow(ui, current, shape) {
1735
1732
  let copyBounds, spreadScale;
1736
- const { __nowWorld: nowWorld, __layout: __layout } = ui;
1733
+ const { __nowWorld: nowWorld, __layout } = ui;
1737
1734
  const { innerShadow } = ui.__;
1738
1735
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1739
1736
  const other = current.getSameCanvas();