@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.
package/dist/miniapp.cjs CHANGED
@@ -380,7 +380,6 @@ function updateChange(updateList) {
380
380
  }
381
381
 
382
382
  const { worldBounds } = core.LeafBoundsHelper;
383
- const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
384
383
  class LayoutBlockData {
385
384
  constructor(list) {
386
385
  this.updatedBounds = new core.Bounds();
@@ -394,13 +393,7 @@ class LayoutBlockData {
394
393
  this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
395
394
  }
396
395
  setAfter() {
397
- const { list } = this.updatedList;
398
- if (list.some(leaf => leaf.noBounds)) {
399
- this.afterBounds.set(bigBounds);
400
- }
401
- else {
402
- this.afterBounds.setListWithFn(list, worldBounds);
403
- }
396
+ this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
404
397
  this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
405
398
  }
406
399
  merge(data) {
@@ -602,6 +595,22 @@ class Renderer {
602
595
  requestLayout() {
603
596
  this.target.emit(core.LayoutEvent.REQUEST);
604
597
  }
598
+ checkRender() {
599
+ if (this.running) {
600
+ const { target } = this;
601
+ if (target.isApp) {
602
+ target.emit(core.RenderEvent.CHILD_START, target);
603
+ target.children.forEach(leafer => {
604
+ leafer.renderer.FPS = this.FPS;
605
+ leafer.renderer.checkRender();
606
+ });
607
+ target.emit(core.RenderEvent.CHILD_END, target);
608
+ }
609
+ if (this.changed && this.canvas.view)
610
+ this.render();
611
+ this.target.emit(core.RenderEvent.NEXT);
612
+ }
613
+ }
605
614
  render(callback) {
606
615
  if (!(this.running && this.canvas.view))
607
616
  return this.update();
@@ -610,8 +619,6 @@ class Renderer {
610
619
  this.totalBounds = new core.Bounds();
611
620
  debug.log(target.innerName, '--->');
612
621
  try {
613
- if (!target.isApp)
614
- target.app.emit(core.RenderEvent.CHILD_START, target);
615
622
  this.emitRender(core.RenderEvent.START);
616
623
  this.renderOnce(callback);
617
624
  this.emitRender(core.RenderEvent.END, this.totalBounds);
@@ -679,20 +686,12 @@ class Renderer {
679
686
  }
680
687
  clipRender(block) {
681
688
  const t = core.Run.start('PartRender');
682
- const { canvas } = this;
683
- const bounds = block.getIntersect(canvas.bounds);
684
- const includes = block.includes(this.target.__world);
685
- const realBounds = new core.Bounds(bounds);
689
+ const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new core.Bounds(bounds);
686
690
  canvas.save();
687
- if (includes && !core.Debug.showRepaint) {
688
- canvas.clear();
689
- }
690
- else {
691
- bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
692
- canvas.clearWorld(bounds, true);
693
- canvas.clipWorld(bounds, true);
694
- }
695
- this.__render(bounds, includes, realBounds);
691
+ bounds.spread(Renderer.clipSpread).ceil();
692
+ canvas.clearWorld(bounds, true);
693
+ canvas.clipWorld(bounds, true);
694
+ this.__render(bounds, realBounds);
696
695
  canvas.restore();
697
696
  core.Run.end(t);
698
697
  }
@@ -701,28 +700,22 @@ class Renderer {
701
700
  const { canvas } = this;
702
701
  canvas.save();
703
702
  canvas.clear();
704
- this.__render(canvas.bounds, true);
703
+ this.__render(canvas.bounds);
705
704
  canvas.restore();
706
705
  core.Run.end(t);
707
706
  }
708
- __render(bounds, includes, realBounds) {
709
- const options = bounds.includes(this.target.__world) ? { includes } : { bounds, includes };
707
+ __render(bounds, realBounds) {
708
+ const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
710
709
  if (this.needFill)
711
- this.canvas.fillWorld(bounds, this.config.fill);
710
+ canvas.fillWorld(bounds, this.config.fill);
712
711
  if (core.Debug.showRepaint)
713
- this.canvas.strokeWorld(bounds, 'red');
714
- this.target.__render(this.canvas, options);
712
+ core.Debug.drawRepaint(canvas, bounds);
713
+ this.target.__render(canvas, options);
715
714
  this.renderBounds = realBounds = realBounds || bounds;
716
715
  this.renderOptions = options;
717
716
  this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
718
- if (core.Debug.showHitView)
719
- this.renderHitView(options);
720
- if (core.Debug.showBoundsView)
721
- this.renderBoundsView(options);
722
- this.canvas.updateRender(realBounds);
723
- }
724
- renderHitView(_options) { }
725
- renderBoundsView(_options) { }
717
+ canvas.updateRender(realBounds);
718
+ }
726
719
  addBlock(block) {
727
720
  if (!this.updateBlocks)
728
721
  this.updateBlocks = [];
@@ -738,17 +731,16 @@ class Renderer {
738
731
  }
739
732
  }
740
733
  __requestRender() {
741
- if (this.requestTime)
734
+ const target = this.target;
735
+ if (this.requestTime || !target)
742
736
  return;
737
+ if (target.parentApp)
738
+ return target.parentApp.requestRender(false);
743
739
  const requestTime = this.requestTime = Date.now();
744
740
  core.Platform.requestRender(() => {
745
741
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
746
742
  this.requestTime = 0;
747
- if (this.running) {
748
- if (this.changed && this.canvas.view)
749
- this.render();
750
- this.target.emit(core.RenderEvent.NEXT);
751
- }
743
+ this.checkRender();
752
744
  });
753
745
  }
754
746
  __onResize(e) {
@@ -806,6 +798,7 @@ class Renderer {
806
798
  }
807
799
  }
808
800
  }
801
+ Renderer.clipSpread = 10;
809
802
 
810
803
  Object.assign(core.Creator, {
811
804
  watcher: (target, options) => new Watcher(target, options),
@@ -1168,9 +1161,11 @@ const tempBox = new core.Bounds();
1168
1161
  const tempPoint = {};
1169
1162
  const tempScaleData = {};
1170
1163
  function createData(leafPaint, image, paint, box) {
1171
- const { blendMode, sync } = paint;
1164
+ const { blendMode, changeful, sync } = paint;
1172
1165
  if (blendMode)
1173
1166
  leafPaint.blendMode = blendMode;
1167
+ if (changeful)
1168
+ leafPaint.changeful = changeful;
1174
1169
  if (sync)
1175
1170
  leafPaint.sync = sync;
1176
1171
  leafPaint.data = getPatternData(paint, box, image);
@@ -1435,40 +1430,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1435
1430
  };
1436
1431
 
1437
1432
  const { abs } = Math;
1438
- function checkImage(ui, canvas, paint, allowPaint) {
1433
+ function checkImage(ui, canvas, paint, allowDraw) {
1439
1434
  const { scaleX, scaleY } = core.ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1440
- const { pixelRatio } = canvas;
1441
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !draw.Export.running)) {
1435
+ const { pixelRatio } = canvas, { data } = paint;
1436
+ if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !draw.Export.running)) {
1442
1437
  return false;
1443
1438
  }
1444
1439
  else {
1445
- const { data } = paint;
1446
- if (allowPaint) {
1447
- if (!data.repeat) {
1448
- let { width, height } = data;
1449
- width *= abs(scaleX) * pixelRatio;
1450
- height *= abs(scaleY) * pixelRatio;
1451
- if (data.scaleX) {
1452
- width *= data.scaleX;
1453
- height *= data.scaleY;
1454
- }
1455
- allowPaint = (width * height > core.Platform.image.maxCacheSize) || draw.Export.running;
1440
+ if (allowDraw) {
1441
+ if (data.repeat) {
1442
+ allowDraw = false;
1456
1443
  }
1457
1444
  else {
1458
- allowPaint = false;
1445
+ if (!(paint.changeful || core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1446
+ let { width, height } = data;
1447
+ width *= abs(scaleX) * pixelRatio;
1448
+ height *= abs(scaleY) * pixelRatio;
1449
+ if (data.scaleX) {
1450
+ width *= data.scaleX;
1451
+ height *= data.scaleY;
1452
+ }
1453
+ allowDraw = (width * height > core.Platform.image.maxCacheSize);
1454
+ }
1459
1455
  }
1460
1456
  }
1461
- if (allowPaint) {
1462
- canvas.save();
1463
- ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1464
- if (paint.blendMode)
1465
- canvas.blendMode = paint.blendMode;
1466
- if (data.opacity)
1467
- canvas.opacity *= data.opacity;
1468
- if (data.transform)
1469
- canvas.transform(data.transform);
1470
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1471
- canvas.restore();
1457
+ if (allowDraw) {
1458
+ drawImage(ui, canvas, paint, data);
1472
1459
  return true;
1473
1460
  }
1474
1461
  else {
@@ -1489,13 +1476,26 @@ function checkImage(ui, canvas, paint, allowPaint) {
1489
1476
  }
1490
1477
  }
1491
1478
  }
1479
+ function drawImage(ui, canvas, paint, data) {
1480
+ canvas.save();
1481
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1482
+ if (paint.blendMode)
1483
+ canvas.blendMode = paint.blendMode;
1484
+ if (data.opacity)
1485
+ canvas.opacity *= data.opacity;
1486
+ if (data.transform)
1487
+ canvas.transform(data.transform);
1488
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1489
+ canvas.restore();
1490
+ }
1492
1491
 
1493
1492
  function recycleImage(attrName, data) {
1494
1493
  const paints = data['_' + attrName];
1495
1494
  if (paints instanceof Array) {
1496
- let image, recycleMap, input, url;
1495
+ let paint, image, recycleMap, input, url;
1497
1496
  for (let i = 0, len = paints.length; i < len; i++) {
1498
- image = paints[i].image;
1497
+ paint = paints[i];
1498
+ image = paint.image;
1499
1499
  url = image && image.url;
1500
1500
  if (url) {
1501
1501
  if (!recycleMap)
@@ -1510,8 +1510,6 @@ function recycleImage(attrName, data) {
1510
1510
  }
1511
1511
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
1512
1512
  }
1513
- else
1514
- paints[i].style = null;
1515
1513
  }
1516
1514
  }
1517
1515
  return recycleMap;
@@ -1690,7 +1688,7 @@ const { toOffsetOutBounds } = core.BoundsHelper;
1690
1688
  const offsetOutBounds = {};
1691
1689
  function innerShadow(ui, current, shape) {
1692
1690
  let copyBounds, spreadScale;
1693
- const { __nowWorld: nowWorld, __layout: __layout } = ui;
1691
+ const { __nowWorld: nowWorld, __layout } = ui;
1694
1692
  const { innerShadow } = ui.__;
1695
1693
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1696
1694
  const other = current.getSameCanvas();