leafer-ui 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/web.esm.js CHANGED
@@ -424,7 +424,6 @@ function updateChange(updateList) {
424
424
  }
425
425
 
426
426
  const { worldBounds } = LeafBoundsHelper;
427
- const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
428
427
  class LayoutBlockData {
429
428
  constructor(list) {
430
429
  this.updatedBounds = new Bounds();
@@ -438,13 +437,7 @@ class LayoutBlockData {
438
437
  this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
439
438
  }
440
439
  setAfter() {
441
- const { list } = this.updatedList;
442
- if (list.some(leaf => leaf.noBounds)) {
443
- this.afterBounds.set(bigBounds);
444
- }
445
- else {
446
- this.afterBounds.setListWithFn(list, worldBounds);
447
- }
440
+ this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
448
441
  this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
449
442
  }
450
443
  merge(data) {
@@ -646,6 +639,22 @@ class Renderer {
646
639
  requestLayout() {
647
640
  this.target.emit(LayoutEvent.REQUEST);
648
641
  }
642
+ checkRender() {
643
+ if (this.running) {
644
+ const { target } = this;
645
+ if (target.isApp) {
646
+ target.emit(RenderEvent.CHILD_START, target);
647
+ target.children.forEach(leafer => {
648
+ leafer.renderer.FPS = this.FPS;
649
+ leafer.renderer.checkRender();
650
+ });
651
+ target.emit(RenderEvent.CHILD_END, target);
652
+ }
653
+ if (this.changed && this.canvas.view)
654
+ this.render();
655
+ this.target.emit(RenderEvent.NEXT);
656
+ }
657
+ }
649
658
  render(callback) {
650
659
  if (!(this.running && this.canvas.view))
651
660
  return this.update();
@@ -654,8 +663,6 @@ class Renderer {
654
663
  this.totalBounds = new Bounds();
655
664
  debug.log(target.innerName, '--->');
656
665
  try {
657
- if (!target.isApp)
658
- target.app.emit(RenderEvent.CHILD_START, target);
659
666
  this.emitRender(RenderEvent.START);
660
667
  this.renderOnce(callback);
661
668
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -723,20 +730,12 @@ class Renderer {
723
730
  }
724
731
  clipRender(block) {
725
732
  const t = Run.start('PartRender');
726
- const { canvas } = this;
727
- const bounds = block.getIntersect(canvas.bounds);
728
- const includes = block.includes(this.target.__world);
729
- const realBounds = new Bounds(bounds);
733
+ const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
730
734
  canvas.save();
731
- if (includes && !Debug.showRepaint) {
732
- canvas.clear();
733
- }
734
- else {
735
- bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
736
- canvas.clearWorld(bounds, true);
737
- canvas.clipWorld(bounds, true);
738
- }
739
- this.__render(bounds, includes, realBounds);
735
+ bounds.spread(Renderer.clipSpread).ceil();
736
+ canvas.clearWorld(bounds, true);
737
+ canvas.clipWorld(bounds, true);
738
+ this.__render(bounds, realBounds);
740
739
  canvas.restore();
741
740
  Run.end(t);
742
741
  }
@@ -745,28 +744,22 @@ class Renderer {
745
744
  const { canvas } = this;
746
745
  canvas.save();
747
746
  canvas.clear();
748
- this.__render(canvas.bounds, true);
747
+ this.__render(canvas.bounds);
749
748
  canvas.restore();
750
749
  Run.end(t);
751
750
  }
752
- __render(bounds, includes, realBounds) {
753
- const options = bounds.includes(this.target.__world) ? { includes } : { bounds, includes };
751
+ __render(bounds, realBounds) {
752
+ const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
754
753
  if (this.needFill)
755
- this.canvas.fillWorld(bounds, this.config.fill);
754
+ canvas.fillWorld(bounds, this.config.fill);
756
755
  if (Debug.showRepaint)
757
- this.canvas.strokeWorld(bounds, 'red');
758
- this.target.__render(this.canvas, options);
756
+ Debug.drawRepaint(canvas, bounds);
757
+ this.target.__render(canvas, options);
759
758
  this.renderBounds = realBounds = realBounds || bounds;
760
759
  this.renderOptions = options;
761
760
  this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
762
- if (Debug.showHitView)
763
- this.renderHitView(options);
764
- if (Debug.showBoundsView)
765
- this.renderBoundsView(options);
766
- this.canvas.updateRender(realBounds);
767
- }
768
- renderHitView(_options) { }
769
- renderBoundsView(_options) { }
761
+ canvas.updateRender(realBounds);
762
+ }
770
763
  addBlock(block) {
771
764
  if (!this.updateBlocks)
772
765
  this.updateBlocks = [];
@@ -782,17 +775,16 @@ class Renderer {
782
775
  }
783
776
  }
784
777
  __requestRender() {
785
- if (this.requestTime)
778
+ const target = this.target;
779
+ if (this.requestTime || !target)
786
780
  return;
781
+ if (target.parentApp)
782
+ return target.parentApp.requestRender(false);
787
783
  const requestTime = this.requestTime = Date.now();
788
784
  Platform.requestRender(() => {
789
785
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
790
786
  this.requestTime = 0;
791
- if (this.running) {
792
- if (this.changed && this.canvas.view)
793
- this.render();
794
- this.target.emit(RenderEvent.NEXT);
795
- }
787
+ this.checkRender();
796
788
  });
797
789
  }
798
790
  __onResize(e) {
@@ -850,6 +842,7 @@ class Renderer {
850
842
  }
851
843
  }
852
844
  }
845
+ Renderer.clipSpread = 10;
853
846
 
854
847
  const { hitRadiusPoint } = BoundsHelper;
855
848
  class Picker {
@@ -1678,9 +1671,11 @@ const tempBox = new Bounds();
1678
1671
  const tempPoint = {};
1679
1672
  const tempScaleData = {};
1680
1673
  function createData(leafPaint, image, paint, box) {
1681
- const { blendMode, sync } = paint;
1674
+ const { blendMode, changeful, sync } = paint;
1682
1675
  if (blendMode)
1683
1676
  leafPaint.blendMode = blendMode;
1677
+ if (changeful)
1678
+ leafPaint.changeful = changeful;
1684
1679
  if (sync)
1685
1680
  leafPaint.sync = sync;
1686
1681
  leafPaint.data = getPatternData(paint, box, image);
@@ -1945,40 +1940,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1945
1940
  };
1946
1941
 
1947
1942
  const { abs } = Math;
1948
- function checkImage(ui, canvas, paint, allowPaint) {
1943
+ function checkImage(ui, canvas, paint, allowDraw) {
1949
1944
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1950
- const { pixelRatio } = canvas;
1951
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1945
+ const { pixelRatio } = canvas, { data } = paint;
1946
+ if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1952
1947
  return false;
1953
1948
  }
1954
1949
  else {
1955
- const { data } = paint;
1956
- if (allowPaint) {
1957
- if (!data.repeat) {
1958
- let { width, height } = data;
1959
- width *= abs(scaleX) * pixelRatio;
1960
- height *= abs(scaleY) * pixelRatio;
1961
- if (data.scaleX) {
1962
- width *= data.scaleX;
1963
- height *= data.scaleY;
1964
- }
1965
- allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
1950
+ if (allowDraw) {
1951
+ if (data.repeat) {
1952
+ allowDraw = false;
1966
1953
  }
1967
1954
  else {
1968
- allowPaint = false;
1955
+ if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
1956
+ let { width, height } = data;
1957
+ width *= abs(scaleX) * pixelRatio;
1958
+ height *= abs(scaleY) * pixelRatio;
1959
+ if (data.scaleX) {
1960
+ width *= data.scaleX;
1961
+ height *= data.scaleY;
1962
+ }
1963
+ allowDraw = (width * height > Platform.image.maxCacheSize);
1964
+ }
1969
1965
  }
1970
1966
  }
1971
- if (allowPaint) {
1972
- canvas.save();
1973
- ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1974
- if (paint.blendMode)
1975
- canvas.blendMode = paint.blendMode;
1976
- if (data.opacity)
1977
- canvas.opacity *= data.opacity;
1978
- if (data.transform)
1979
- canvas.transform(data.transform);
1980
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1981
- canvas.restore();
1967
+ if (allowDraw) {
1968
+ drawImage(ui, canvas, paint, data);
1982
1969
  return true;
1983
1970
  }
1984
1971
  else {
@@ -1999,13 +1986,26 @@ function checkImage(ui, canvas, paint, allowPaint) {
1999
1986
  }
2000
1987
  }
2001
1988
  }
1989
+ function drawImage(ui, canvas, paint, data) {
1990
+ canvas.save();
1991
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1992
+ if (paint.blendMode)
1993
+ canvas.blendMode = paint.blendMode;
1994
+ if (data.opacity)
1995
+ canvas.opacity *= data.opacity;
1996
+ if (data.transform)
1997
+ canvas.transform(data.transform);
1998
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1999
+ canvas.restore();
2000
+ }
2002
2001
 
2003
2002
  function recycleImage(attrName, data) {
2004
2003
  const paints = data['_' + attrName];
2005
2004
  if (paints instanceof Array) {
2006
- let image, recycleMap, input, url;
2005
+ let paint, image, recycleMap, input, url;
2007
2006
  for (let i = 0, len = paints.length; i < len; i++) {
2008
- image = paints[i].image;
2007
+ paint = paints[i];
2008
+ image = paint.image;
2009
2009
  url = image && image.url;
2010
2010
  if (url) {
2011
2011
  if (!recycleMap)
@@ -2020,8 +2020,6 @@ function recycleImage(attrName, data) {
2020
2020
  }
2021
2021
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
2022
2022
  }
2023
- else
2024
- paints[i].style = null;
2025
2023
  }
2026
2024
  }
2027
2025
  return recycleMap;
@@ -2200,7 +2198,7 @@ const { toOffsetOutBounds } = BoundsHelper;
2200
2198
  const offsetOutBounds = {};
2201
2199
  function innerShadow(ui, current, shape) {
2202
2200
  let copyBounds, spreadScale;
2203
- const { __nowWorld: nowWorld, __layout: __layout } = ui;
2201
+ const { __nowWorld: nowWorld, __layout } = ui;
2204
2202
  const { innerShadow } = ui.__;
2205
2203
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
2206
2204
  const other = current.getSameCanvas();