@leafer-draw/node 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.
package/dist/node.esm.js CHANGED
@@ -255,7 +255,6 @@ function updateChange(updateList) {
255
255
  }
256
256
 
257
257
  const { worldBounds } = LeafBoundsHelper;
258
- const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
259
258
  class LayoutBlockData {
260
259
  constructor(list) {
261
260
  this.updatedBounds = new Bounds();
@@ -269,13 +268,7 @@ class LayoutBlockData {
269
268
  this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
270
269
  }
271
270
  setAfter() {
272
- const { list } = this.updatedList;
273
- if (list.some(leaf => leaf.noBounds)) {
274
- this.afterBounds.set(bigBounds);
275
- }
276
- else {
277
- this.afterBounds.setListWithFn(list, worldBounds);
278
- }
271
+ this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
279
272
  this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
280
273
  }
281
274
  merge(data) {
@@ -477,6 +470,13 @@ class Renderer {
477
470
  requestLayout() {
478
471
  this.target.emit(LayoutEvent.REQUEST);
479
472
  }
473
+ checkRender() {
474
+ if (this.running) {
475
+ if (this.changed && this.canvas.view)
476
+ this.render();
477
+ this.target.emit(RenderEvent.NEXT);
478
+ }
479
+ }
480
480
  render(callback) {
481
481
  if (!(this.running && this.canvas.view))
482
482
  return this.update();
@@ -485,8 +485,6 @@ class Renderer {
485
485
  this.totalBounds = new Bounds();
486
486
  debug$1.log(target.innerName, '--->');
487
487
  try {
488
- if (!target.isApp)
489
- target.app.emit(RenderEvent.CHILD_START, target);
490
488
  this.emitRender(RenderEvent.START);
491
489
  this.renderOnce(callback);
492
490
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -554,20 +552,12 @@ class Renderer {
554
552
  }
555
553
  clipRender(block) {
556
554
  const t = Run.start('PartRender');
557
- const { canvas } = this;
558
- const bounds = block.getIntersect(canvas.bounds);
559
- const includes = block.includes(this.target.__world);
560
- const realBounds = new Bounds(bounds);
555
+ const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
561
556
  canvas.save();
562
- if (includes && !Debug.showRepaint) {
563
- canvas.clear();
564
- }
565
- else {
566
- bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
567
- canvas.clearWorld(bounds, true);
568
- canvas.clipWorld(bounds, true);
569
- }
570
- this.__render(bounds, includes, realBounds);
557
+ bounds.spread(Renderer.clipSpread).ceil();
558
+ canvas.clearWorld(bounds, true);
559
+ canvas.clipWorld(bounds, true);
560
+ this.__render(bounds, block.includes(this.target.__world), realBounds);
571
561
  canvas.restore();
572
562
  Run.end(t);
573
563
  }
@@ -581,23 +571,17 @@ class Renderer {
581
571
  Run.end(t);
582
572
  }
583
573
  __render(bounds, includes, realBounds) {
584
- const options = bounds.includes(this.target.__world) ? { includes } : { bounds, includes };
574
+ const { canvas } = this, options = includes ? { includes } : { bounds, includes };
585
575
  if (this.needFill)
586
- this.canvas.fillWorld(bounds, this.config.fill);
576
+ canvas.fillWorld(bounds, this.config.fill);
587
577
  if (Debug.showRepaint)
588
- this.canvas.strokeWorld(bounds, 'red');
589
- this.target.__render(this.canvas, options);
578
+ Debug.drawRepaint(canvas, bounds);
579
+ this.target.__render(canvas, options);
590
580
  this.renderBounds = realBounds = realBounds || bounds;
591
581
  this.renderOptions = options;
592
582
  this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
593
- if (Debug.showHitView)
594
- this.renderHitView(options);
595
- if (Debug.showBoundsView)
596
- this.renderBoundsView(options);
597
- this.canvas.updateRender(realBounds);
598
- }
599
- renderHitView(_options) { }
600
- renderBoundsView(_options) { }
583
+ canvas.updateRender(realBounds);
584
+ }
601
585
  addBlock(block) {
602
586
  if (!this.updateBlocks)
603
587
  this.updateBlocks = [];
@@ -613,17 +597,24 @@ class Renderer {
613
597
  }
614
598
  }
615
599
  __requestRender() {
600
+ const target = this.target;
601
+ if (target.parentApp)
602
+ return target.parentApp.renderer.update(false);
616
603
  if (this.requestTime)
617
604
  return;
618
605
  const requestTime = this.requestTime = Date.now();
619
606
  Platform.requestRender(() => {
620
607
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
621
608
  this.requestTime = 0;
622
- if (this.running) {
623
- if (this.changed && this.canvas.view)
624
- this.render();
625
- this.target.emit(RenderEvent.NEXT);
609
+ if (target.isApp) {
610
+ target.emit(RenderEvent.CHILD_START, target);
611
+ target.children.forEach(leafer => {
612
+ leafer.renderer.FPS = this.FPS;
613
+ leafer.renderer.checkRender();
614
+ });
615
+ target.emit(RenderEvent.CHILD_END, target);
626
616
  }
617
+ this.checkRender();
627
618
  });
628
619
  }
629
620
  __onResize(e) {
@@ -681,6 +672,7 @@ class Renderer {
681
672
  }
682
673
  }
683
674
  }
675
+ Renderer.clipSpread = 10;
684
676
 
685
677
  Object.assign(Creator, {
686
678
  watcher: (target, options) => new Watcher(target, options),
@@ -1043,9 +1035,11 @@ const tempBox = new Bounds();
1043
1035
  const tempPoint = {};
1044
1036
  const tempScaleData = {};
1045
1037
  function createData(leafPaint, image, paint, box) {
1046
- const { blendMode, sync } = paint;
1038
+ const { blendMode, changeful, sync } = paint;
1047
1039
  if (blendMode)
1048
1040
  leafPaint.blendMode = blendMode;
1041
+ if (changeful)
1042
+ leafPaint.changeful = changeful;
1049
1043
  if (sync)
1050
1044
  leafPaint.sync = sync;
1051
1045
  leafPaint.data = getPatternData(paint, box, image);
@@ -1278,40 +1272,32 @@ function createPattern(ui, paint, pixelRatio) {
1278
1272
  }
1279
1273
 
1280
1274
  const { abs } = Math;
1281
- function checkImage(ui, canvas, paint, allowPaint) {
1275
+ function checkImage(ui, canvas, paint, allowDraw) {
1282
1276
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1283
- const { pixelRatio } = canvas;
1284
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1277
+ const { pixelRatio } = canvas, { data } = paint;
1278
+ if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1285
1279
  return false;
1286
1280
  }
1287
1281
  else {
1288
- const { data } = paint;
1289
- if (allowPaint) {
1290
- if (!data.repeat) {
1291
- let { width, height } = data;
1292
- width *= abs(scaleX) * pixelRatio;
1293
- height *= abs(scaleY) * pixelRatio;
1294
- if (data.scaleX) {
1295
- width *= data.scaleX;
1296
- height *= data.scaleY;
1297
- }
1298
- allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
1282
+ if (allowDraw) {
1283
+ if (data.repeat) {
1284
+ allowDraw = false;
1299
1285
  }
1300
1286
  else {
1301
- allowPaint = false;
1287
+ if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
1288
+ let { width, height } = data;
1289
+ width *= abs(scaleX) * pixelRatio;
1290
+ height *= abs(scaleY) * pixelRatio;
1291
+ if (data.scaleX) {
1292
+ width *= data.scaleX;
1293
+ height *= data.scaleY;
1294
+ }
1295
+ allowDraw = (width * height > Platform.image.maxCacheSize);
1296
+ }
1302
1297
  }
1303
1298
  }
1304
- if (allowPaint) {
1305
- canvas.save();
1306
- ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1307
- if (paint.blendMode)
1308
- canvas.blendMode = paint.blendMode;
1309
- if (data.opacity)
1310
- canvas.opacity *= data.opacity;
1311
- if (data.transform)
1312
- canvas.transform(data.transform);
1313
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1314
- canvas.restore();
1299
+ if (allowDraw) {
1300
+ drawImage(ui, canvas, paint, data);
1315
1301
  return true;
1316
1302
  }
1317
1303
  else {
@@ -1332,13 +1318,26 @@ function checkImage(ui, canvas, paint, allowPaint) {
1332
1318
  }
1333
1319
  }
1334
1320
  }
1321
+ function drawImage(ui, canvas, paint, data) {
1322
+ canvas.save();
1323
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
1324
+ if (paint.blendMode)
1325
+ canvas.blendMode = paint.blendMode;
1326
+ if (data.opacity)
1327
+ canvas.opacity *= data.opacity;
1328
+ if (data.transform)
1329
+ canvas.transform(data.transform);
1330
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1331
+ canvas.restore();
1332
+ }
1335
1333
 
1336
1334
  function recycleImage(attrName, data) {
1337
1335
  const paints = data['_' + attrName];
1338
1336
  if (paints instanceof Array) {
1339
- let image, recycleMap, input, url;
1337
+ let paint, image, recycleMap, input, url;
1340
1338
  for (let i = 0, len = paints.length; i < len; i++) {
1341
- image = paints[i].image;
1339
+ paint = paints[i];
1340
+ image = paint.image;
1342
1341
  url = image && image.url;
1343
1342
  if (url) {
1344
1343
  if (!recycleMap)
@@ -1353,8 +1352,6 @@ function recycleImage(attrName, data) {
1353
1352
  }
1354
1353
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
1355
1354
  }
1356
- else
1357
- paints[i].style = null;
1358
1355
  }
1359
1356
  }
1360
1357
  return recycleMap;
@@ -1533,7 +1530,7 @@ const { toOffsetOutBounds } = BoundsHelper;
1533
1530
  const offsetOutBounds = {};
1534
1531
  function innerShadow(ui, current, shape) {
1535
1532
  let copyBounds, spreadScale;
1536
- const { __nowWorld: nowWorld, __layout: __layout } = ui;
1533
+ const { __nowWorld: nowWorld, __layout } = ui;
1537
1534
  const { innerShadow } = ui.__;
1538
1535
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1539
1536
  const other = current.getSameCanvas();