@leafer-ui/miniapp 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/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,13 @@ class Renderer {
603
596
  requestLayout() {
604
597
  this.target.emit(core.LayoutEvent.REQUEST);
605
598
  }
599
+ checkRender() {
600
+ if (this.running) {
601
+ if (this.changed && this.canvas.view)
602
+ this.render();
603
+ this.target.emit(core.RenderEvent.NEXT);
604
+ }
605
+ }
606
606
  render(callback) {
607
607
  if (!(this.running && this.canvas.view))
608
608
  return this.update();
@@ -611,8 +611,6 @@ class Renderer {
611
611
  this.totalBounds = new core.Bounds();
612
612
  debug.log(target.innerName, '--->');
613
613
  try {
614
- if (!target.isApp)
615
- target.app.emit(core.RenderEvent.CHILD_START, target);
616
614
  this.emitRender(core.RenderEvent.START);
617
615
  this.renderOnce(callback);
618
616
  this.emitRender(core.RenderEvent.END, this.totalBounds);
@@ -680,20 +678,12 @@ class Renderer {
680
678
  }
681
679
  clipRender(block) {
682
680
  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);
681
+ const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new core.Bounds(bounds);
687
682
  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);
683
+ bounds.spread(Renderer.clipSpread).ceil();
684
+ canvas.clearWorld(bounds, true);
685
+ canvas.clipWorld(bounds, true);
686
+ this.__render(bounds, block.includes(this.target.__world), realBounds);
697
687
  canvas.restore();
698
688
  core.Run.end(t);
699
689
  }
@@ -707,23 +697,17 @@ class Renderer {
707
697
  core.Run.end(t);
708
698
  }
709
699
  __render(bounds, includes, realBounds) {
710
- const options = bounds.includes(this.target.__world) ? { includes } : { bounds, includes };
700
+ const { canvas } = this, options = includes ? { includes } : { bounds, includes };
711
701
  if (this.needFill)
712
- this.canvas.fillWorld(bounds, this.config.fill);
702
+ canvas.fillWorld(bounds, this.config.fill);
713
703
  if (core.Debug.showRepaint)
714
- this.canvas.strokeWorld(bounds, 'red');
715
- this.target.__render(this.canvas, options);
704
+ core.Debug.drawRepaint(canvas, bounds);
705
+ this.target.__render(canvas, options);
716
706
  this.renderBounds = realBounds = realBounds || bounds;
717
707
  this.renderOptions = options;
718
708
  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) { }
709
+ canvas.updateRender(realBounds);
710
+ }
727
711
  addBlock(block) {
728
712
  if (!this.updateBlocks)
729
713
  this.updateBlocks = [];
@@ -739,17 +723,24 @@ class Renderer {
739
723
  }
740
724
  }
741
725
  __requestRender() {
726
+ const target = this.target;
727
+ if (target.parentApp)
728
+ return target.parentApp.renderer.update(false);
742
729
  if (this.requestTime)
743
730
  return;
744
731
  const requestTime = this.requestTime = Date.now();
745
732
  core.Platform.requestRender(() => {
746
733
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
747
734
  this.requestTime = 0;
748
- if (this.running) {
749
- if (this.changed && this.canvas.view)
750
- this.render();
751
- this.target.emit(core.RenderEvent.NEXT);
735
+ if (target.isApp) {
736
+ target.emit(core.RenderEvent.CHILD_START, target);
737
+ target.children.forEach(leafer => {
738
+ leafer.renderer.FPS = this.FPS;
739
+ leafer.renderer.checkRender();
740
+ });
741
+ target.emit(core.RenderEvent.CHILD_END, target);
752
742
  }
743
+ this.checkRender();
753
744
  });
754
745
  }
755
746
  __onResize(e) {
@@ -807,6 +798,7 @@ class Renderer {
807
798
  }
808
799
  }
809
800
  }
801
+ Renderer.clipSpread = 10;
810
802
 
811
803
  const { hitRadiusPoint } = core.BoundsHelper;
812
804
  class Picker {
@@ -1431,9 +1423,11 @@ const tempBox = new core.Bounds();
1431
1423
  const tempPoint = {};
1432
1424
  const tempScaleData = {};
1433
1425
  function createData(leafPaint, image, paint, box) {
1434
- const { blendMode, sync } = paint;
1426
+ const { blendMode, changeful, sync } = paint;
1435
1427
  if (blendMode)
1436
1428
  leafPaint.blendMode = blendMode;
1429
+ if (changeful)
1430
+ leafPaint.changeful = changeful;
1437
1431
  if (sync)
1438
1432
  leafPaint.sync = sync;
1439
1433
  leafPaint.data = getPatternData(paint, box, image);
@@ -1698,40 +1692,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1698
1692
  };
1699
1693
 
1700
1694
  const { abs } = Math;
1701
- function checkImage(ui, canvas, paint, allowPaint) {
1695
+ function checkImage(ui, canvas, paint, allowDraw) {
1702
1696
  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)) {
1697
+ const { pixelRatio } = canvas, { data } = paint;
1698
+ if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !draw.Export.running)) {
1705
1699
  return false;
1706
1700
  }
1707
1701
  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;
1702
+ if (allowDraw) {
1703
+ if (data.repeat) {
1704
+ allowDraw = false;
1719
1705
  }
1720
1706
  else {
1721
- allowPaint = false;
1707
+ if (!(paint.changeful || core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1708
+ let { width, height } = data;
1709
+ width *= abs(scaleX) * pixelRatio;
1710
+ height *= abs(scaleY) * pixelRatio;
1711
+ if (data.scaleX) {
1712
+ width *= data.scaleX;
1713
+ height *= data.scaleY;
1714
+ }
1715
+ allowDraw = (width * height > core.Platform.image.maxCacheSize);
1716
+ }
1722
1717
  }
1723
1718
  }
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();
1719
+ if (allowDraw) {
1720
+ drawImage(ui, canvas, paint, data);
1735
1721
  return true;
1736
1722
  }
1737
1723
  else {
@@ -1752,13 +1738,26 @@ function checkImage(ui, canvas, paint, allowPaint) {
1752
1738
  }
1753
1739
  }
1754
1740
  }
1741
+ function drawImage(ui, canvas, paint, data) {
1742
+ canvas.save();
1743
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1744
+ if (paint.blendMode)
1745
+ canvas.blendMode = paint.blendMode;
1746
+ if (data.opacity)
1747
+ canvas.opacity *= data.opacity;
1748
+ if (data.transform)
1749
+ canvas.transform(data.transform);
1750
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1751
+ canvas.restore();
1752
+ }
1755
1753
 
1756
1754
  function recycleImage(attrName, data) {
1757
1755
  const paints = data['_' + attrName];
1758
1756
  if (paints instanceof Array) {
1759
- let image, recycleMap, input, url;
1757
+ let paint, image, recycleMap, input, url;
1760
1758
  for (let i = 0, len = paints.length; i < len; i++) {
1761
- image = paints[i].image;
1759
+ paint = paints[i];
1760
+ image = paint.image;
1762
1761
  url = image && image.url;
1763
1762
  if (url) {
1764
1763
  if (!recycleMap)
@@ -1773,8 +1772,6 @@ function recycleImage(attrName, data) {
1773
1772
  }
1774
1773
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
1775
1774
  }
1776
- else
1777
- paints[i].style = null;
1778
1775
  }
1779
1776
  }
1780
1777
  return recycleMap;
@@ -1953,7 +1950,7 @@ const { toOffsetOutBounds } = core.BoundsHelper;
1953
1950
  const offsetOutBounds = {};
1954
1951
  function innerShadow(ui, current, shape) {
1955
1952
  let copyBounds, spreadScale;
1956
- const { __nowWorld: nowWorld, __layout: __layout } = ui;
1953
+ const { __nowWorld: nowWorld, __layout } = ui;
1957
1954
  const { innerShadow } = ui.__;
1958
1955
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1959
1956
  const other = current.getSameCanvas();