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