@leafer-draw/worker 1.0.6 → 1.0.8

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.
@@ -2958,7 +2958,6 @@ class PathCreator {
2958
2958
  set path(value) { this.__path = value; }
2959
2959
  get path() { return this.__path; }
2960
2960
  constructor(path) {
2961
- this.clearPath = this.beginPath;
2962
2961
  this.set(path);
2963
2962
  }
2964
2963
  set(path) {
@@ -3040,6 +3039,9 @@ class PathCreator {
3040
3039
  this.paint();
3041
3040
  return this;
3042
3041
  }
3042
+ clearPath() {
3043
+ return this.beginPath();
3044
+ }
3043
3045
  paint() { }
3044
3046
  }
3045
3047
 
@@ -3635,6 +3637,8 @@ const ImageManager = {
3635
3637
  else {
3636
3638
  if (url.includes('.' + format) || url.includes('.' + FileHelper.upperCaseTypeMap[format]))
3637
3639
  return true;
3640
+ else if (format === 'png' && !url.includes('.'))
3641
+ return true;
3638
3642
  }
3639
3643
  return false;
3640
3644
  },
@@ -4426,13 +4430,10 @@ class LeafLayout {
4426
4430
  update() {
4427
4431
  const { leafer } = this.leaf;
4428
4432
  if (leafer) {
4429
- if (leafer.ready) {
4430
- if (leafer.watcher.changed)
4431
- leafer.layouter.layout();
4432
- }
4433
- else {
4433
+ if (leafer.ready)
4434
+ leafer.watcher.changed && leafer.layouter.layout();
4435
+ else
4434
4436
  leafer.start();
4435
- }
4436
4437
  }
4437
4438
  else {
4438
4439
  let root = this.leaf;
@@ -5641,11 +5642,10 @@ let Leaf = class Leaf {
5641
5642
  }
5642
5643
  destroy() {
5643
5644
  if (!this.destroyed) {
5644
- const { parent } = this;
5645
- if (parent)
5645
+ if (this.parent)
5646
5646
  this.remove();
5647
5647
  if (this.children)
5648
- this.removeAll(true);
5648
+ this.clear();
5649
5649
  this.__emitLifeEvent(ChildEvent.DESTROY);
5650
5650
  this.__.destroy();
5651
5651
  this.__layout.destroy();
@@ -5959,7 +5959,7 @@ class LeafLevelList {
5959
5959
  }
5960
5960
  }
5961
5961
 
5962
- const version = "1.0.6";
5962
+ const version = "1.0.8";
5963
5963
 
5964
5964
  class LeaferCanvas extends LeaferCanvasBase {
5965
5965
  get allowBackgroundColor() { return true; }
@@ -6687,12 +6687,8 @@ const State = {
6687
6687
  };
6688
6688
  const Transition = {
6689
6689
  list: {},
6690
- register(attrName, fn) {
6691
- Transition.list[attrName] = fn;
6692
- },
6693
- get(attrName) {
6694
- return Transition.list[attrName];
6695
- }
6690
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6691
+ get(attrName) { return Transition.list[attrName]; }
6696
6692
  };
6697
6693
 
6698
6694
  const { parse, objectToCanvasData } = PathConvert;
@@ -7138,8 +7134,8 @@ let UI = UI_1 = class UI extends Leaf {
7138
7134
  pen.set(path = []), this.__drawPathByBox(pen);
7139
7135
  return curve ? PathConvert.toCanvasData(path, true) : path;
7140
7136
  }
7141
- getPathString(curve, pathForRender) {
7142
- return PathConvert.stringify(this.getPath(curve, pathForRender));
7137
+ getPathString(curve, pathForRender, floatLength) {
7138
+ return PathConvert.stringify(this.getPath(curve, pathForRender), floatLength);
7143
7139
  }
7144
7140
  load() {
7145
7141
  this.__.__computePaint();
@@ -7548,11 +7544,11 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7548
7544
  start() {
7549
7545
  clearTimeout(this.__startTimer);
7550
7546
  if (!this.running && this.canvas) {
7547
+ this.running = true;
7551
7548
  this.ready ? this.emitLeafer(LeaferEvent.RESTART) : this.emitLeafer(LeaferEvent.START);
7552
7549
  this.__controllers.forEach(item => item.start());
7553
7550
  if (!this.isApp)
7554
7551
  this.renderer.render();
7555
- this.running = true;
7556
7552
  }
7557
7553
  }
7558
7554
  stop() {
@@ -7658,12 +7654,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7658
7654
  }
7659
7655
  __changeFill(newValue) {
7660
7656
  this.config.fill = newValue;
7661
- if (this.canvas.allowBackgroundColor) {
7657
+ if (this.canvas.allowBackgroundColor)
7662
7658
  this.canvas.backgroundColor = newValue;
7663
- }
7664
- else {
7659
+ else
7665
7660
  this.forceRender();
7666
- }
7667
7661
  }
7668
7662
  __onCreated() {
7669
7663
  this.created = true;
@@ -7730,13 +7724,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7730
7724
  if (bind)
7731
7725
  item = item.bind(bind);
7732
7726
  this.__viewCompletedWait.push(item);
7733
- if (this.viewCompleted) {
7727
+ if (this.viewCompleted)
7734
7728
  this.__checkViewCompleted(false);
7735
- }
7736
- else {
7737
- if (!this.running)
7738
- this.start();
7739
- }
7729
+ else if (!this.running)
7730
+ this.start();
7740
7731
  }
7741
7732
  nextRender(item, bind, off) {
7742
7733
  if (bind)
@@ -7750,9 +7741,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7750
7741
  }
7751
7742
  }
7752
7743
  }
7753
- else {
7744
+ else
7754
7745
  list.push(item);
7755
- }
7756
7746
  }
7757
7747
  zoom(_zoomType, _padding, _fixedScale) {
7758
7748
  return needPlugin('view');
@@ -7796,10 +7786,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7796
7786
  this.stop();
7797
7787
  this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
7798
7788
  this.__removeListenEvents();
7799
- this.__controllers.forEach(item => {
7800
- if (!(this.parent && item === this.interaction))
7801
- item.destroy();
7802
- });
7789
+ this.__controllers.forEach(item => !(this.parent && item === this.interaction) && item.destroy());
7803
7790
  this.__controllers.length = 0;
7804
7791
  if (!this.parent) {
7805
7792
  if (this.selector)
@@ -8332,23 +8319,23 @@ let Text = class Text extends UI {
8332
8319
  }
8333
8320
  __updateTextDrawData() {
8334
8321
  const data = this.__;
8335
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8336
- }
8337
- __updateBoxBounds() {
8338
- const data = this.__;
8339
- const layout = this.__layout;
8340
8322
  const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data;
8341
- const autoWidth = data.__autoWidth;
8342
- const autoHeight = data.__autoHeight;
8343
8323
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
8344
8324
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
8345
8325
  data.__padding = padding ? MathHelper.fourNumber(padding) : undefined;
8346
8326
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8347
8327
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8348
8328
  data.__clipText = textOverflow !== 'show' && !data.__autoSize;
8329
+ data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8330
+ }
8331
+ __updateBoxBounds() {
8332
+ const data = this.__;
8333
+ const layout = this.__layout;
8334
+ const { fontSize, italic, padding, __autoWidth: autoWidth, __autoHeight: autoHeight } = data;
8349
8335
  this.__updateTextDrawData();
8350
8336
  const { bounds } = data.__textDrawData;
8351
8337
  const b = layout.boxBounds;
8338
+ console.log(bounds, autoWidth, autoHeight);
8352
8339
  if (data.__lineHeight < fontSize)
8353
8340
  spread(bounds, fontSize / 2);
8354
8341
  if (autoWidth || autoHeight) {
@@ -8358,20 +8345,15 @@ let Text = class Text extends UI {
8358
8345
  b.height = autoHeight ? bounds.height : data.height;
8359
8346
  if (padding) {
8360
8347
  const [top, right, bottom, left] = data.__padding;
8361
- if (autoWidth) {
8362
- b.x -= left;
8363
- b.width += (right + left);
8364
- }
8365
- if (autoHeight) {
8366
- b.y -= top;
8367
- b.height += (bottom + top);
8368
- }
8348
+ if (autoWidth)
8349
+ b.x -= left, b.width += (right + left);
8350
+ if (autoHeight)
8351
+ b.y -= top, b.height += (bottom + top);
8369
8352
  }
8370
8353
  this.__updateNaturalSize();
8371
8354
  }
8372
- else {
8355
+ else
8373
8356
  super.__updateBoxBounds();
8374
- }
8375
8357
  if (italic)
8376
8358
  b.width += fontSize * 0.16;
8377
8359
  const contentBounds = includes(b, bounds) ? b : bounds;
@@ -8380,9 +8362,8 @@ let Text = class Text extends UI {
8380
8362
  layout.renderChanged = true;
8381
8363
  setList(data.__textBoxBounds = {}, [b, bounds]);
8382
8364
  }
8383
- else {
8365
+ else
8384
8366
  data.__textBoxBounds = contentBounds;
8385
- }
8386
8367
  }
8387
8368
  __updateRenderSpread() {
8388
8369
  let width = super.__updateRenderSpread();
@@ -8495,11 +8476,7 @@ let Pen = class Pen extends Group {
8495
8476
  this.add(path);
8496
8477
  return this;
8497
8478
  }
8498
- beginPath() {
8499
- this.__path.length = 0;
8500
- this.paint();
8501
- return this;
8502
- }
8479
+ beginPath() { return this; }
8503
8480
  moveTo(_x, _y) { return this; }
8504
8481
  lineTo(_x, _y) { return this; }
8505
8482
  bezierCurveTo(_x1, _y1, _x2, _y2, _x, _y) { return this; }
@@ -8526,7 +8503,7 @@ __decorate([
8526
8503
  penPathType()
8527
8504
  ], Pen.prototype, "path", void 0);
8528
8505
  Pen = __decorate([
8529
- useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8506
+ useModule(PathCreator, ['set', 'path', 'paint']),
8530
8507
  registerUI()
8531
8508
  ], Pen);
8532
8509
  function penPathType() {
@@ -8542,14 +8519,10 @@ function fillText(ui, canvas) {
8542
8519
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
8543
8520
  for (let i = 0, len = rows.length; i < len; i++) {
8544
8521
  row = rows[i];
8545
- if (row.text) {
8522
+ if (row.text)
8546
8523
  canvas.fillText(row.text, row.x, row.y);
8547
- }
8548
- else if (row.data) {
8549
- row.data.forEach(charData => {
8550
- canvas.fillText(charData.char, charData.x, row.y);
8551
- });
8552
- }
8524
+ else if (row.data)
8525
+ row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
8553
8526
  if (decorationY)
8554
8527
  canvas.fillRect(row.x, row.y + decorationY, row.width, decorationHeight);
8555
8528
  }
@@ -8615,12 +8588,10 @@ function drawAlignStroke(align, stroke, isStrokes, ui, canvas) {
8615
8588
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
8616
8589
  fillText(ui, out);
8617
8590
  out.blendMode = 'normal';
8618
- if (ui.__worldFlipped) {
8591
+ if (ui.__worldFlipped)
8619
8592
  canvas.copyWorldByReset(out, ui.__nowWorld);
8620
- }
8621
- else {
8593
+ else
8622
8594
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
8623
- }
8624
8595
  out.recycle(ui.__nowWorld);
8625
8596
  }
8626
8597
  function drawTextStroke(ui, canvas) {
@@ -8628,14 +8599,10 @@ function drawTextStroke(ui, canvas) {
8628
8599
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
8629
8600
  for (let i = 0, len = rows.length; i < len; i++) {
8630
8601
  row = rows[i];
8631
- if (row.text) {
8602
+ if (row.text)
8632
8603
  canvas.strokeText(row.text, row.x, row.y);
8633
- }
8634
- else if (row.data) {
8635
- row.data.forEach(charData => {
8636
- canvas.strokeText(charData.char, charData.x, row.y);
8637
- });
8638
- }
8604
+ else if (row.data)
8605
+ row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
8639
8606
  if (decorationY)
8640
8607
  canvas.strokeRect(row.x, row.y + decorationY, row.width, decorationHeight);
8641
8608
  }
@@ -8688,12 +8655,10 @@ function stroke(stroke, ui, canvas) {
8688
8655
  out.stroke();
8689
8656
  options.windingRule ? out.clip(options.windingRule) : out.clip();
8690
8657
  out.clearWorld(ui.__layout.renderBounds);
8691
- if (ui.__worldFlipped) {
8658
+ if (ui.__worldFlipped)
8692
8659
  canvas.copyWorldByReset(out, ui.__nowWorld);
8693
- }
8694
- else {
8660
+ else
8695
8661
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
8696
- }
8697
8662
  out.recycle(ui.__nowWorld);
8698
8663
  break;
8699
8664
  }
@@ -8728,12 +8693,10 @@ function strokes(strokes, ui, canvas) {
8728
8693
  drawStrokesStyle(strokes, false, ui, out);
8729
8694
  options.windingRule ? out.clip(options.windingRule) : out.clip();
8730
8695
  out.clearWorld(renderBounds);
8731
- if (ui.__worldFlipped) {
8696
+ if (ui.__worldFlipped)
8732
8697
  canvas.copyWorldByReset(out, ui.__nowWorld);
8733
- }
8734
- else {
8698
+ else
8735
8699
  canvas.copyWorldToInner(out, ui.__nowWorld, renderBounds);
8736
- }
8737
8700
  out.recycle(ui.__nowWorld);
8738
8701
  break;
8739
8702
  }
@@ -8797,12 +8760,7 @@ function compute(attrName, ui) {
8797
8760
  data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
8798
8761
  if (leafPaints.length && leafPaints[0].image)
8799
8762
  hasOpacityPixel = leafPaints[0].image.hasOpacityPixel;
8800
- if (attrName === 'fill') {
8801
- data.__pixelFill = hasOpacityPixel;
8802
- }
8803
- else {
8804
- data.__pixelStroke = hasOpacityPixel;
8805
- }
8763
+ attrName === 'fill' ? data.__pixelFill = hasOpacityPixel : data.__pixelStroke = hasOpacityPixel;
8806
8764
  }
8807
8765
  function getLeafPaint(attrName, paint, ui) {
8808
8766
  if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)