@leafer-ui/miniapp 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.
@@ -382,7 +382,6 @@ function updateChange(updateList) {
382
382
  }
383
383
 
384
384
  const { worldBounds } = LeafBoundsHelper;
385
- const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
386
385
  class LayoutBlockData {
387
386
  constructor(list) {
388
387
  this.updatedBounds = new Bounds();
@@ -396,13 +395,7 @@ class LayoutBlockData {
396
395
  this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
397
396
  }
398
397
  setAfter() {
399
- const { list } = this.updatedList;
400
- if (list.some(leaf => leaf.noBounds)) {
401
- this.afterBounds.set(bigBounds);
402
- }
403
- else {
404
- this.afterBounds.setListWithFn(list, worldBounds);
405
- }
398
+ this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
406
399
  this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
407
400
  }
408
401
  merge(data) {
@@ -604,6 +597,22 @@ class Renderer {
604
597
  requestLayout() {
605
598
  this.target.emit(LayoutEvent.REQUEST);
606
599
  }
600
+ checkRender() {
601
+ if (this.running) {
602
+ const { target } = this;
603
+ if (target.isApp) {
604
+ target.emit(RenderEvent.CHILD_START, target);
605
+ target.children.forEach(leafer => {
606
+ leafer.renderer.FPS = this.FPS;
607
+ leafer.renderer.checkRender();
608
+ });
609
+ target.emit(RenderEvent.CHILD_END, target);
610
+ }
611
+ if (this.changed && this.canvas.view)
612
+ this.render();
613
+ this.target.emit(RenderEvent.NEXT);
614
+ }
615
+ }
607
616
  render(callback) {
608
617
  if (!(this.running && this.canvas.view))
609
618
  return this.update();
@@ -612,8 +621,6 @@ class Renderer {
612
621
  this.totalBounds = new Bounds();
613
622
  debug.log(target.innerName, '--->');
614
623
  try {
615
- if (!target.isApp)
616
- target.app.emit(RenderEvent.CHILD_START, target);
617
624
  this.emitRender(RenderEvent.START);
618
625
  this.renderOnce(callback);
619
626
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -681,20 +688,12 @@ class Renderer {
681
688
  }
682
689
  clipRender(block) {
683
690
  const t = Run.start('PartRender');
684
- const { canvas } = this;
685
- const bounds = block.getIntersect(canvas.bounds);
686
- const includes = block.includes(this.target.__world);
687
- const realBounds = new Bounds(bounds);
691
+ const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
688
692
  canvas.save();
689
- if (includes && !Debug.showRepaint) {
690
- canvas.clear();
691
- }
692
- else {
693
- bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
694
- canvas.clearWorld(bounds, true);
695
- canvas.clipWorld(bounds, true);
696
- }
697
- this.__render(bounds, includes, realBounds);
693
+ bounds.spread(Renderer.clipSpread).ceil();
694
+ canvas.clearWorld(bounds, true);
695
+ canvas.clipWorld(bounds, true);
696
+ this.__render(bounds, realBounds);
698
697
  canvas.restore();
699
698
  Run.end(t);
700
699
  }
@@ -703,28 +702,22 @@ class Renderer {
703
702
  const { canvas } = this;
704
703
  canvas.save();
705
704
  canvas.clear();
706
- this.__render(canvas.bounds, true);
705
+ this.__render(canvas.bounds);
707
706
  canvas.restore();
708
707
  Run.end(t);
709
708
  }
710
- __render(bounds, includes, realBounds) {
711
- const options = bounds.includes(this.target.__world) ? { includes } : { bounds, includes };
709
+ __render(bounds, realBounds) {
710
+ const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
712
711
  if (this.needFill)
713
- this.canvas.fillWorld(bounds, this.config.fill);
712
+ canvas.fillWorld(bounds, this.config.fill);
714
713
  if (Debug.showRepaint)
715
- this.canvas.strokeWorld(bounds, 'red');
716
- this.target.__render(this.canvas, options);
714
+ Debug.drawRepaint(canvas, bounds);
715
+ this.target.__render(canvas, options);
717
716
  this.renderBounds = realBounds = realBounds || bounds;
718
717
  this.renderOptions = options;
719
718
  this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
720
- if (Debug.showHitView)
721
- this.renderHitView(options);
722
- if (Debug.showBoundsView)
723
- this.renderBoundsView(options);
724
- this.canvas.updateRender(realBounds);
725
- }
726
- renderHitView(_options) { }
727
- renderBoundsView(_options) { }
719
+ canvas.updateRender(realBounds);
720
+ }
728
721
  addBlock(block) {
729
722
  if (!this.updateBlocks)
730
723
  this.updateBlocks = [];
@@ -740,17 +733,16 @@ class Renderer {
740
733
  }
741
734
  }
742
735
  __requestRender() {
743
- if (this.requestTime)
736
+ const target = this.target;
737
+ if (this.requestTime || !target)
744
738
  return;
739
+ if (target.parentApp)
740
+ return target.parentApp.requestRender(false);
745
741
  const requestTime = this.requestTime = Date.now();
746
742
  Platform.requestRender(() => {
747
743
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
748
744
  this.requestTime = 0;
749
- if (this.running) {
750
- if (this.changed && this.canvas.view)
751
- this.render();
752
- this.target.emit(RenderEvent.NEXT);
753
- }
745
+ this.checkRender();
754
746
  });
755
747
  }
756
748
  __onResize(e) {
@@ -808,6 +800,7 @@ class Renderer {
808
800
  }
809
801
  }
810
802
  }
803
+ Renderer.clipSpread = 10;
811
804
 
812
805
  const { hitRadiusPoint } = BoundsHelper;
813
806
  class Picker {
@@ -1432,9 +1425,11 @@ const tempBox = new Bounds();
1432
1425
  const tempPoint = {};
1433
1426
  const tempScaleData = {};
1434
1427
  function createData(leafPaint, image, paint, box) {
1435
- const { blendMode, sync } = paint;
1428
+ const { blendMode, changeful, sync } = paint;
1436
1429
  if (blendMode)
1437
1430
  leafPaint.blendMode = blendMode;
1431
+ if (changeful)
1432
+ leafPaint.changeful = changeful;
1438
1433
  if (sync)
1439
1434
  leafPaint.sync = sync;
1440
1435
  leafPaint.data = getPatternData(paint, box, image);
@@ -1699,40 +1694,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1699
1694
  };
1700
1695
 
1701
1696
  const { abs } = Math;
1702
- function checkImage(ui, canvas, paint, allowPaint) {
1697
+ function checkImage(ui, canvas, paint, allowDraw) {
1703
1698
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1704
- const { pixelRatio } = canvas;
1705
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1699
+ const { pixelRatio } = canvas, { data } = paint;
1700
+ if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1706
1701
  return false;
1707
1702
  }
1708
1703
  else {
1709
- const { data } = paint;
1710
- if (allowPaint) {
1711
- if (!data.repeat) {
1712
- let { width, height } = data;
1713
- width *= abs(scaleX) * pixelRatio;
1714
- height *= abs(scaleY) * pixelRatio;
1715
- if (data.scaleX) {
1716
- width *= data.scaleX;
1717
- height *= data.scaleY;
1718
- }
1719
- allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
1704
+ if (allowDraw) {
1705
+ if (data.repeat) {
1706
+ allowDraw = false;
1720
1707
  }
1721
1708
  else {
1722
- allowPaint = false;
1709
+ if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
1710
+ let { width, height } = data;
1711
+ width *= abs(scaleX) * pixelRatio;
1712
+ height *= abs(scaleY) * pixelRatio;
1713
+ if (data.scaleX) {
1714
+ width *= data.scaleX;
1715
+ height *= data.scaleY;
1716
+ }
1717
+ allowDraw = (width * height > Platform.image.maxCacheSize);
1718
+ }
1723
1719
  }
1724
1720
  }
1725
- if (allowPaint) {
1726
- canvas.save();
1727
- ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1728
- if (paint.blendMode)
1729
- canvas.blendMode = paint.blendMode;
1730
- if (data.opacity)
1731
- canvas.opacity *= data.opacity;
1732
- if (data.transform)
1733
- canvas.transform(data.transform);
1734
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1735
- canvas.restore();
1721
+ if (allowDraw) {
1722
+ drawImage(ui, canvas, paint, data);
1736
1723
  return true;
1737
1724
  }
1738
1725
  else {
@@ -1753,13 +1740,26 @@ function checkImage(ui, canvas, paint, allowPaint) {
1753
1740
  }
1754
1741
  }
1755
1742
  }
1743
+ function drawImage(ui, canvas, paint, data) {
1744
+ canvas.save();
1745
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1746
+ if (paint.blendMode)
1747
+ canvas.blendMode = paint.blendMode;
1748
+ if (data.opacity)
1749
+ canvas.opacity *= data.opacity;
1750
+ if (data.transform)
1751
+ canvas.transform(data.transform);
1752
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1753
+ canvas.restore();
1754
+ }
1756
1755
 
1757
1756
  function recycleImage(attrName, data) {
1758
1757
  const paints = data['_' + attrName];
1759
1758
  if (paints instanceof Array) {
1760
- let image, recycleMap, input, url;
1759
+ let paint, image, recycleMap, input, url;
1761
1760
  for (let i = 0, len = paints.length; i < len; i++) {
1762
- image = paints[i].image;
1761
+ paint = paints[i];
1762
+ image = paint.image;
1763
1763
  url = image && image.url;
1764
1764
  if (url) {
1765
1765
  if (!recycleMap)
@@ -1774,8 +1774,6 @@ function recycleImage(attrName, data) {
1774
1774
  }
1775
1775
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
1776
1776
  }
1777
- else
1778
- paints[i].style = null;
1779
1777
  }
1780
1778
  }
1781
1779
  return recycleMap;
@@ -1954,7 +1952,7 @@ const { toOffsetOutBounds } = BoundsHelper;
1954
1952
  const offsetOutBounds = {};
1955
1953
  function innerShadow(ui, current, shape) {
1956
1954
  let copyBounds, spreadScale;
1957
- const { __nowWorld: nowWorld, __layout: __layout } = ui;
1955
+ const { __nowWorld: nowWorld, __layout } = ui;
1958
1956
  const { innerShadow } = ui.__;
1959
1957
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1960
1958
  const other = current.getSameCanvas();