@leafer-draw/worker 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.
@@ -242,7 +242,6 @@ function updateChange(updateList) {
242
242
  }
243
243
 
244
244
  const { worldBounds } = 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 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,13 @@ class Renderer {
464
457
  requestLayout() {
465
458
  this.target.emit(LayoutEvent.REQUEST);
466
459
  }
460
+ checkRender() {
461
+ if (this.running) {
462
+ if (this.changed && this.canvas.view)
463
+ this.render();
464
+ this.target.emit(RenderEvent.NEXT);
465
+ }
466
+ }
467
467
  render(callback) {
468
468
  if (!(this.running && this.canvas.view))
469
469
  return this.update();
@@ -472,8 +472,6 @@ class Renderer {
472
472
  this.totalBounds = new Bounds();
473
473
  debug.log(target.innerName, '--->');
474
474
  try {
475
- if (!target.isApp)
476
- target.app.emit(RenderEvent.CHILD_START, target);
477
475
  this.emitRender(RenderEvent.START);
478
476
  this.renderOnce(callback);
479
477
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -541,20 +539,12 @@ class Renderer {
541
539
  }
542
540
  clipRender(block) {
543
541
  const t = 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 Bounds(bounds);
542
+ const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
548
543
  canvas.save();
549
- if (includes && !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);
544
+ bounds.spread(Renderer.clipSpread).ceil();
545
+ canvas.clearWorld(bounds, true);
546
+ canvas.clipWorld(bounds, true);
547
+ this.__render(bounds, block.includes(this.target.__world), realBounds);
558
548
  canvas.restore();
559
549
  Run.end(t);
560
550
  }
@@ -568,23 +558,17 @@ class Renderer {
568
558
  Run.end(t);
569
559
  }
570
560
  __render(bounds, includes, realBounds) {
571
- const options = bounds.includes(this.target.__world) ? { includes } : { bounds, includes };
561
+ const { canvas } = this, options = includes ? { includes } : { bounds, includes };
572
562
  if (this.needFill)
573
- this.canvas.fillWorld(bounds, this.config.fill);
563
+ canvas.fillWorld(bounds, this.config.fill);
574
564
  if (Debug.showRepaint)
575
- this.canvas.strokeWorld(bounds, 'red');
576
- this.target.__render(this.canvas, options);
565
+ Debug.drawRepaint(canvas, bounds);
566
+ this.target.__render(canvas, options);
577
567
  this.renderBounds = realBounds = realBounds || bounds;
578
568
  this.renderOptions = options;
579
569
  this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
580
- if (Debug.showHitView)
581
- this.renderHitView(options);
582
- if (Debug.showBoundsView)
583
- this.renderBoundsView(options);
584
- this.canvas.updateRender(realBounds);
585
- }
586
- renderHitView(_options) { }
587
- renderBoundsView(_options) { }
570
+ canvas.updateRender(realBounds);
571
+ }
588
572
  addBlock(block) {
589
573
  if (!this.updateBlocks)
590
574
  this.updateBlocks = [];
@@ -600,17 +584,24 @@ class Renderer {
600
584
  }
601
585
  }
602
586
  __requestRender() {
587
+ const target = this.target;
588
+ if (target.parentApp)
589
+ return target.parentApp.renderer.update(false);
603
590
  if (this.requestTime)
604
591
  return;
605
592
  const requestTime = this.requestTime = Date.now();
606
593
  Platform.requestRender(() => {
607
594
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
608
595
  this.requestTime = 0;
609
- if (this.running) {
610
- if (this.changed && this.canvas.view)
611
- this.render();
612
- this.target.emit(RenderEvent.NEXT);
596
+ if (target.isApp) {
597
+ target.emit(RenderEvent.CHILD_START, target);
598
+ target.children.forEach(leafer => {
599
+ leafer.renderer.FPS = this.FPS;
600
+ leafer.renderer.checkRender();
601
+ });
602
+ target.emit(RenderEvent.CHILD_END, target);
613
603
  }
604
+ this.checkRender();
614
605
  });
615
606
  }
616
607
  __onResize(e) {
@@ -668,6 +659,7 @@ class Renderer {
668
659
  }
669
660
  }
670
661
  }
662
+ Renderer.clipSpread = 10;
671
663
 
672
664
  Object.assign(Creator, {
673
665
  watcher: (target, options) => new Watcher(target, options),
@@ -1030,9 +1022,11 @@ const tempBox = new Bounds();
1030
1022
  const tempPoint = {};
1031
1023
  const tempScaleData = {};
1032
1024
  function createData(leafPaint, image, paint, box) {
1033
- const { blendMode, sync } = paint;
1025
+ const { blendMode, changeful, sync } = paint;
1034
1026
  if (blendMode)
1035
1027
  leafPaint.blendMode = blendMode;
1028
+ if (changeful)
1029
+ leafPaint.changeful = changeful;
1036
1030
  if (sync)
1037
1031
  leafPaint.sync = sync;
1038
1032
  leafPaint.data = getPatternData(paint, box, image);
@@ -1297,40 +1291,32 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1297
1291
  };
1298
1292
 
1299
1293
  const { abs } = Math;
1300
- function checkImage(ui, canvas, paint, allowPaint) {
1294
+ function checkImage(ui, canvas, paint, allowDraw) {
1301
1295
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1302
- const { pixelRatio } = canvas;
1303
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1296
+ const { pixelRatio } = canvas, { data } = paint;
1297
+ if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1304
1298
  return false;
1305
1299
  }
1306
1300
  else {
1307
- const { data } = paint;
1308
- if (allowPaint) {
1309
- if (!data.repeat) {
1310
- let { width, height } = data;
1311
- width *= abs(scaleX) * pixelRatio;
1312
- height *= abs(scaleY) * pixelRatio;
1313
- if (data.scaleX) {
1314
- width *= data.scaleX;
1315
- height *= data.scaleY;
1316
- }
1317
- allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
1301
+ if (allowDraw) {
1302
+ if (data.repeat) {
1303
+ allowDraw = false;
1318
1304
  }
1319
1305
  else {
1320
- allowPaint = false;
1306
+ if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
1307
+ let { width, height } = data;
1308
+ width *= abs(scaleX) * pixelRatio;
1309
+ height *= abs(scaleY) * pixelRatio;
1310
+ if (data.scaleX) {
1311
+ width *= data.scaleX;
1312
+ height *= data.scaleY;
1313
+ }
1314
+ allowDraw = (width * height > Platform.image.maxCacheSize);
1315
+ }
1321
1316
  }
1322
1317
  }
1323
- if (allowPaint) {
1324
- canvas.save();
1325
- ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1326
- if (paint.blendMode)
1327
- canvas.blendMode = paint.blendMode;
1328
- if (data.opacity)
1329
- canvas.opacity *= data.opacity;
1330
- if (data.transform)
1331
- canvas.transform(data.transform);
1332
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1333
- canvas.restore();
1318
+ if (allowDraw) {
1319
+ drawImage(ui, canvas, paint, data);
1334
1320
  return true;
1335
1321
  }
1336
1322
  else {
@@ -1351,13 +1337,26 @@ function checkImage(ui, canvas, paint, allowPaint) {
1351
1337
  }
1352
1338
  }
1353
1339
  }
1340
+ function drawImage(ui, canvas, paint, data) {
1341
+ canvas.save();
1342
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1343
+ if (paint.blendMode)
1344
+ canvas.blendMode = paint.blendMode;
1345
+ if (data.opacity)
1346
+ canvas.opacity *= data.opacity;
1347
+ if (data.transform)
1348
+ canvas.transform(data.transform);
1349
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1350
+ canvas.restore();
1351
+ }
1354
1352
 
1355
1353
  function recycleImage(attrName, data) {
1356
1354
  const paints = data['_' + attrName];
1357
1355
  if (paints instanceof Array) {
1358
- let image, recycleMap, input, url;
1356
+ let paint, image, recycleMap, input, url;
1359
1357
  for (let i = 0, len = paints.length; i < len; i++) {
1360
- image = paints[i].image;
1358
+ paint = paints[i];
1359
+ image = paint.image;
1361
1360
  url = image && image.url;
1362
1361
  if (url) {
1363
1362
  if (!recycleMap)
@@ -1372,8 +1371,6 @@ function recycleImage(attrName, data) {
1372
1371
  }
1373
1372
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
1374
1373
  }
1375
- else
1376
- paints[i].style = null;
1377
1374
  }
1378
1375
  }
1379
1376
  return recycleMap;
@@ -1552,7 +1549,7 @@ const { toOffsetOutBounds } = BoundsHelper;
1552
1549
  const offsetOutBounds = {};
1553
1550
  function innerShadow(ui, current, shape) {
1554
1551
  let copyBounds, spreadScale;
1555
- const { __nowWorld: nowWorld, __layout: __layout } = ui;
1552
+ const { __nowWorld: nowWorld, __layout } = ui;
1556
1553
  const { innerShadow } = ui.__;
1557
1554
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1558
1555
  const other = current.getSameCanvas();