@leafer-draw/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.
@@ -381,7 +381,6 @@ function updateChange(updateList) {
381
381
  }
382
382
 
383
383
  const { worldBounds } = 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 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(LayoutEvent.REQUEST);
605
598
  }
599
+ checkRender() {
600
+ if (this.running) {
601
+ const { target } = this;
602
+ if (target.isApp) {
603
+ target.emit(RenderEvent.CHILD_START, target);
604
+ target.children.forEach(leafer => {
605
+ leafer.renderer.FPS = this.FPS;
606
+ leafer.renderer.checkRender();
607
+ });
608
+ target.emit(RenderEvent.CHILD_END, target);
609
+ }
610
+ if (this.changed && this.canvas.view)
611
+ this.render();
612
+ this.target.emit(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 Bounds();
612
621
  debug.log(target.innerName, '--->');
613
622
  try {
614
- if (!target.isApp)
615
- target.app.emit(RenderEvent.CHILD_START, target);
616
623
  this.emitRender(RenderEvent.START);
617
624
  this.renderOnce(callback);
618
625
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -680,20 +687,12 @@ class Renderer {
680
687
  }
681
688
  clipRender(block) {
682
689
  const t = 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 Bounds(bounds);
690
+ const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
687
691
  canvas.save();
688
- if (includes && !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
  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
  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 (Debug.showRepaint)
714
- this.canvas.strokeWorld(bounds, 'red');
715
- this.target.__render(this.canvas, options);
713
+ 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 (Debug.showHitView)
720
- this.renderHitView(options);
721
- if (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
  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(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
  Object.assign(Creator, {
812
805
  watcher: (target, options) => new Watcher(target, options),
@@ -1169,9 +1162,11 @@ const tempBox = new Bounds();
1169
1162
  const tempPoint = {};
1170
1163
  const tempScaleData = {};
1171
1164
  function createData(leafPaint, image, paint, box) {
1172
- const { blendMode, sync } = paint;
1165
+ const { blendMode, changeful, sync } = paint;
1173
1166
  if (blendMode)
1174
1167
  leafPaint.blendMode = blendMode;
1168
+ if (changeful)
1169
+ leafPaint.changeful = changeful;
1175
1170
  if (sync)
1176
1171
  leafPaint.sync = sync;
1177
1172
  leafPaint.data = getPatternData(paint, box, image);
@@ -1436,40 +1431,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1436
1431
  };
1437
1432
 
1438
1433
  const { abs } = Math;
1439
- function checkImage(ui, canvas, paint, allowPaint) {
1434
+ function checkImage(ui, canvas, paint, allowDraw) {
1440
1435
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1441
- const { pixelRatio } = canvas;
1442
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1436
+ const { pixelRatio } = canvas, { data } = paint;
1437
+ if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1443
1438
  return false;
1444
1439
  }
1445
1440
  else {
1446
- const { data } = paint;
1447
- if (allowPaint) {
1448
- if (!data.repeat) {
1449
- let { width, height } = data;
1450
- width *= abs(scaleX) * pixelRatio;
1451
- height *= abs(scaleY) * pixelRatio;
1452
- if (data.scaleX) {
1453
- width *= data.scaleX;
1454
- height *= data.scaleY;
1455
- }
1456
- allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
1441
+ if (allowDraw) {
1442
+ if (data.repeat) {
1443
+ allowDraw = false;
1457
1444
  }
1458
1445
  else {
1459
- allowPaint = false;
1446
+ if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
1447
+ let { width, height } = data;
1448
+ width *= abs(scaleX) * pixelRatio;
1449
+ height *= abs(scaleY) * pixelRatio;
1450
+ if (data.scaleX) {
1451
+ width *= data.scaleX;
1452
+ height *= data.scaleY;
1453
+ }
1454
+ allowDraw = (width * height > Platform.image.maxCacheSize);
1455
+ }
1460
1456
  }
1461
1457
  }
1462
- if (allowPaint) {
1463
- canvas.save();
1464
- ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1465
- if (paint.blendMode)
1466
- canvas.blendMode = paint.blendMode;
1467
- if (data.opacity)
1468
- canvas.opacity *= data.opacity;
1469
- if (data.transform)
1470
- canvas.transform(data.transform);
1471
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1472
- canvas.restore();
1458
+ if (allowDraw) {
1459
+ drawImage(ui, canvas, paint, data);
1473
1460
  return true;
1474
1461
  }
1475
1462
  else {
@@ -1490,13 +1477,26 @@ function checkImage(ui, canvas, paint, allowPaint) {
1490
1477
  }
1491
1478
  }
1492
1479
  }
1480
+ function drawImage(ui, canvas, paint, data) {
1481
+ canvas.save();
1482
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1483
+ if (paint.blendMode)
1484
+ canvas.blendMode = paint.blendMode;
1485
+ if (data.opacity)
1486
+ canvas.opacity *= data.opacity;
1487
+ if (data.transform)
1488
+ canvas.transform(data.transform);
1489
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1490
+ canvas.restore();
1491
+ }
1493
1492
 
1494
1493
  function recycleImage(attrName, data) {
1495
1494
  const paints = data['_' + attrName];
1496
1495
  if (paints instanceof Array) {
1497
- let image, recycleMap, input, url;
1496
+ let paint, image, recycleMap, input, url;
1498
1497
  for (let i = 0, len = paints.length; i < len; i++) {
1499
- image = paints[i].image;
1498
+ paint = paints[i];
1499
+ image = paint.image;
1500
1500
  url = image && image.url;
1501
1501
  if (url) {
1502
1502
  if (!recycleMap)
@@ -1511,8 +1511,6 @@ function recycleImage(attrName, data) {
1511
1511
  }
1512
1512
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
1513
1513
  }
1514
- else
1515
- paints[i].style = null;
1516
1514
  }
1517
1515
  }
1518
1516
  return recycleMap;
@@ -1691,7 +1689,7 @@ const { toOffsetOutBounds } = BoundsHelper;
1691
1689
  const offsetOutBounds = {};
1692
1690
  function innerShadow(ui, current, shape) {
1693
1691
  let copyBounds, spreadScale;
1694
- const { __nowWorld: nowWorld, __layout: __layout } = ui;
1692
+ const { __nowWorld: nowWorld, __layout } = ui;
1695
1693
  const { innerShadow } = ui.__;
1696
1694
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1697
1695
  const other = current.getSameCanvas();