@leafer-ui/worker 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/worker.cjs CHANGED
@@ -242,7 +242,6 @@ function updateChange(updateList) {
242
242
  }
243
243
 
244
244
  const { worldBounds } = core.LeafBoundsHelper;
245
- const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
246
245
  class LayoutBlockData {
247
246
  constructor(list) {
248
247
  this.updatedBounds = new core.Bounds();
@@ -256,13 +255,7 @@ class LayoutBlockData {
256
255
  this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
257
256
  }
258
257
  setAfter() {
259
- const { list } = this.updatedList;
260
- if (list.some(leaf => leaf.noBounds)) {
261
- this.afterBounds.set(bigBounds);
262
- }
263
- else {
264
- this.afterBounds.setListWithFn(list, worldBounds);
265
- }
258
+ this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
266
259
  this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
267
260
  }
268
261
  merge(data) {
@@ -464,6 +457,22 @@ class Renderer {
464
457
  requestLayout() {
465
458
  this.target.emit(core.LayoutEvent.REQUEST);
466
459
  }
460
+ checkRender() {
461
+ if (this.running) {
462
+ const { target } = this;
463
+ if (target.isApp) {
464
+ target.emit(core.RenderEvent.CHILD_START, target);
465
+ target.children.forEach(leafer => {
466
+ leafer.renderer.FPS = this.FPS;
467
+ leafer.renderer.checkRender();
468
+ });
469
+ target.emit(core.RenderEvent.CHILD_END, target);
470
+ }
471
+ if (this.changed && this.canvas.view)
472
+ this.render();
473
+ this.target.emit(core.RenderEvent.NEXT);
474
+ }
475
+ }
467
476
  render(callback) {
468
477
  if (!(this.running && this.canvas.view))
469
478
  return this.update();
@@ -472,8 +481,6 @@ class Renderer {
472
481
  this.totalBounds = new core.Bounds();
473
482
  debug.log(target.innerName, '--->');
474
483
  try {
475
- if (!target.isApp)
476
- target.app.emit(core.RenderEvent.CHILD_START, target);
477
484
  this.emitRender(core.RenderEvent.START);
478
485
  this.renderOnce(callback);
479
486
  this.emitRender(core.RenderEvent.END, this.totalBounds);
@@ -541,20 +548,12 @@ class Renderer {
541
548
  }
542
549
  clipRender(block) {
543
550
  const t = core.Run.start('PartRender');
544
- const { canvas } = this;
545
- const bounds = block.getIntersect(canvas.bounds);
546
- const includes = block.includes(this.target.__world);
547
- const realBounds = new core.Bounds(bounds);
551
+ const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new core.Bounds(bounds);
548
552
  canvas.save();
549
- if (includes && !core.Debug.showRepaint) {
550
- canvas.clear();
551
- }
552
- else {
553
- bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
554
- canvas.clearWorld(bounds, true);
555
- canvas.clipWorld(bounds, true);
556
- }
557
- this.__render(bounds, includes, realBounds);
553
+ bounds.spread(Renderer.clipSpread).ceil();
554
+ canvas.clearWorld(bounds, true);
555
+ canvas.clipWorld(bounds, true);
556
+ this.__render(bounds, realBounds);
558
557
  canvas.restore();
559
558
  core.Run.end(t);
560
559
  }
@@ -563,28 +562,22 @@ class Renderer {
563
562
  const { canvas } = this;
564
563
  canvas.save();
565
564
  canvas.clear();
566
- this.__render(canvas.bounds, true);
565
+ this.__render(canvas.bounds);
567
566
  canvas.restore();
568
567
  core.Run.end(t);
569
568
  }
570
- __render(bounds, includes, realBounds) {
571
- const options = bounds.includes(this.target.__world) ? { includes } : { bounds, includes };
569
+ __render(bounds, realBounds) {
570
+ const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
572
571
  if (this.needFill)
573
- this.canvas.fillWorld(bounds, this.config.fill);
572
+ canvas.fillWorld(bounds, this.config.fill);
574
573
  if (core.Debug.showRepaint)
575
- this.canvas.strokeWorld(bounds, 'red');
576
- this.target.__render(this.canvas, options);
574
+ core.Debug.drawRepaint(canvas, bounds);
575
+ this.target.__render(canvas, options);
577
576
  this.renderBounds = realBounds = realBounds || bounds;
578
577
  this.renderOptions = options;
579
578
  this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
580
- if (core.Debug.showHitView)
581
- this.renderHitView(options);
582
- if (core.Debug.showBoundsView)
583
- this.renderBoundsView(options);
584
- this.canvas.updateRender(realBounds);
585
- }
586
- renderHitView(_options) { }
587
- renderBoundsView(_options) { }
579
+ canvas.updateRender(realBounds);
580
+ }
588
581
  addBlock(block) {
589
582
  if (!this.updateBlocks)
590
583
  this.updateBlocks = [];
@@ -600,17 +593,16 @@ class Renderer {
600
593
  }
601
594
  }
602
595
  __requestRender() {
603
- if (this.requestTime)
596
+ const target = this.target;
597
+ if (this.requestTime || !target)
604
598
  return;
599
+ if (target.parentApp)
600
+ return target.parentApp.requestRender(false);
605
601
  const requestTime = this.requestTime = Date.now();
606
602
  core.Platform.requestRender(() => {
607
603
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
608
604
  this.requestTime = 0;
609
- if (this.running) {
610
- if (this.changed && this.canvas.view)
611
- this.render();
612
- this.target.emit(core.RenderEvent.NEXT);
613
- }
605
+ this.checkRender();
614
606
  });
615
607
  }
616
608
  __onResize(e) {
@@ -668,6 +660,7 @@ class Renderer {
668
660
  }
669
661
  }
670
662
  }
663
+ Renderer.clipSpread = 10;
671
664
 
672
665
  const { hitRadiusPoint } = core.BoundsHelper;
673
666
  class Picker {
@@ -1187,9 +1180,11 @@ const tempBox = new core.Bounds();
1187
1180
  const tempPoint = {};
1188
1181
  const tempScaleData = {};
1189
1182
  function createData(leafPaint, image, paint, box) {
1190
- const { blendMode, sync } = paint;
1183
+ const { blendMode, changeful, sync } = paint;
1191
1184
  if (blendMode)
1192
1185
  leafPaint.blendMode = blendMode;
1186
+ if (changeful)
1187
+ leafPaint.changeful = changeful;
1193
1188
  if (sync)
1194
1189
  leafPaint.sync = sync;
1195
1190
  leafPaint.data = getPatternData(paint, box, image);
@@ -1454,40 +1449,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1454
1449
  };
1455
1450
 
1456
1451
  const { abs } = Math;
1457
- function checkImage(ui, canvas, paint, allowPaint) {
1452
+ function checkImage(ui, canvas, paint, allowDraw) {
1458
1453
  const { scaleX, scaleY } = core.ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1459
- const { pixelRatio } = canvas;
1460
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !draw.Export.running)) {
1454
+ const { pixelRatio } = canvas, { data } = paint;
1455
+ if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !draw.Export.running)) {
1461
1456
  return false;
1462
1457
  }
1463
1458
  else {
1464
- const { data } = paint;
1465
- if (allowPaint) {
1466
- if (!data.repeat) {
1467
- let { width, height } = data;
1468
- width *= abs(scaleX) * pixelRatio;
1469
- height *= abs(scaleY) * pixelRatio;
1470
- if (data.scaleX) {
1471
- width *= data.scaleX;
1472
- height *= data.scaleY;
1473
- }
1474
- allowPaint = (width * height > core.Platform.image.maxCacheSize) || draw.Export.running;
1459
+ if (allowDraw) {
1460
+ if (data.repeat) {
1461
+ allowDraw = false;
1475
1462
  }
1476
1463
  else {
1477
- allowPaint = false;
1464
+ if (!(paint.changeful || core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1465
+ let { width, height } = data;
1466
+ width *= abs(scaleX) * pixelRatio;
1467
+ height *= abs(scaleY) * pixelRatio;
1468
+ if (data.scaleX) {
1469
+ width *= data.scaleX;
1470
+ height *= data.scaleY;
1471
+ }
1472
+ allowDraw = (width * height > core.Platform.image.maxCacheSize);
1473
+ }
1478
1474
  }
1479
1475
  }
1480
- if (allowPaint) {
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();
1476
+ if (allowDraw) {
1477
+ drawImage(ui, canvas, paint, data);
1491
1478
  return true;
1492
1479
  }
1493
1480
  else {
@@ -1508,13 +1495,26 @@ function checkImage(ui, canvas, paint, allowPaint) {
1508
1495
  }
1509
1496
  }
1510
1497
  }
1498
+ function drawImage(ui, canvas, paint, data) {
1499
+ canvas.save();
1500
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1501
+ if (paint.blendMode)
1502
+ canvas.blendMode = paint.blendMode;
1503
+ if (data.opacity)
1504
+ canvas.opacity *= data.opacity;
1505
+ if (data.transform)
1506
+ canvas.transform(data.transform);
1507
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1508
+ canvas.restore();
1509
+ }
1511
1510
 
1512
1511
  function recycleImage(attrName, data) {
1513
1512
  const paints = data['_' + attrName];
1514
1513
  if (paints instanceof Array) {
1515
- let image, recycleMap, input, url;
1514
+ let paint, image, recycleMap, input, url;
1516
1515
  for (let i = 0, len = paints.length; i < len; i++) {
1517
- image = paints[i].image;
1516
+ paint = paints[i];
1517
+ image = paint.image;
1518
1518
  url = image && image.url;
1519
1519
  if (url) {
1520
1520
  if (!recycleMap)
@@ -1529,8 +1529,6 @@ function recycleImage(attrName, data) {
1529
1529
  }
1530
1530
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
1531
1531
  }
1532
- else
1533
- paints[i].style = null;
1534
1532
  }
1535
1533
  }
1536
1534
  return recycleMap;
@@ -1709,7 +1707,7 @@ const { toOffsetOutBounds } = core.BoundsHelper;
1709
1707
  const offsetOutBounds = {};
1710
1708
  function innerShadow(ui, current, shape) {
1711
1709
  let copyBounds, spreadScale;
1712
- const { __nowWorld: nowWorld, __layout: __layout } = ui;
1710
+ const { __nowWorld: nowWorld, __layout } = ui;
1713
1711
  const { innerShadow } = ui.__;
1714
1712
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1715
1713
  const other = current.getSameCanvas();