@leafer-draw/worker 1.0.7 → 1.0.9

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
  },
@@ -5638,11 +5642,10 @@ let Leaf = class Leaf {
5638
5642
  }
5639
5643
  destroy() {
5640
5644
  if (!this.destroyed) {
5641
- const { parent } = this;
5642
- if (parent)
5645
+ if (this.parent)
5643
5646
  this.remove();
5644
5647
  if (this.children)
5645
- this.removeAll(true);
5648
+ this.clear();
5646
5649
  this.__emitLifeEvent(ChildEvent.DESTROY);
5647
5650
  this.__.destroy();
5648
5651
  this.__layout.destroy();
@@ -5956,7 +5959,7 @@ class LeafLevelList {
5956
5959
  }
5957
5960
  }
5958
5961
 
5959
- const version = "1.0.7";
5962
+ const version = "1.0.9";
5960
5963
 
5961
5964
  class LeaferCanvas extends LeaferCanvasBase {
5962
5965
  get allowBackgroundColor() { return true; }
@@ -6684,12 +6687,8 @@ const State = {
6684
6687
  };
6685
6688
  const Transition = {
6686
6689
  list: {},
6687
- register(attrName, fn) {
6688
- Transition.list[attrName] = fn;
6689
- },
6690
- get(attrName) {
6691
- return Transition.list[attrName];
6692
- }
6690
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6691
+ get(attrName) { return Transition.list[attrName]; }
6693
6692
  };
6694
6693
 
6695
6694
  const { parse, objectToCanvasData } = PathConvert;
@@ -7135,8 +7134,8 @@ let UI = UI_1 = class UI extends Leaf {
7135
7134
  pen.set(path = []), this.__drawPathByBox(pen);
7136
7135
  return curve ? PathConvert.toCanvasData(path, true) : path;
7137
7136
  }
7138
- getPathString(curve, pathForRender) {
7139
- return PathConvert.stringify(this.getPath(curve, pathForRender));
7137
+ getPathString(curve, pathForRender, floatLength) {
7138
+ return PathConvert.stringify(this.getPath(curve, pathForRender), floatLength);
7140
7139
  }
7141
7140
  load() {
7142
7141
  this.__.__computePaint();
@@ -7545,11 +7544,11 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7545
7544
  start() {
7546
7545
  clearTimeout(this.__startTimer);
7547
7546
  if (!this.running && this.canvas) {
7547
+ this.running = true;
7548
7548
  this.ready ? this.emitLeafer(LeaferEvent.RESTART) : this.emitLeafer(LeaferEvent.START);
7549
7549
  this.__controllers.forEach(item => item.start());
7550
7550
  if (!this.isApp)
7551
7551
  this.renderer.render();
7552
- this.running = true;
7553
7552
  }
7554
7553
  }
7555
7554
  stop() {
@@ -7655,12 +7654,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7655
7654
  }
7656
7655
  __changeFill(newValue) {
7657
7656
  this.config.fill = newValue;
7658
- if (this.canvas.allowBackgroundColor) {
7657
+ if (this.canvas.allowBackgroundColor)
7659
7658
  this.canvas.backgroundColor = newValue;
7660
- }
7661
- else {
7659
+ else
7662
7660
  this.forceRender();
7663
- }
7664
7661
  }
7665
7662
  __onCreated() {
7666
7663
  this.created = true;
@@ -7727,13 +7724,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7727
7724
  if (bind)
7728
7725
  item = item.bind(bind);
7729
7726
  this.__viewCompletedWait.push(item);
7730
- if (this.viewCompleted) {
7727
+ if (this.viewCompleted)
7731
7728
  this.__checkViewCompleted(false);
7732
- }
7733
- else {
7734
- if (!this.running)
7735
- this.start();
7736
- }
7729
+ else if (!this.running)
7730
+ this.start();
7737
7731
  }
7738
7732
  nextRender(item, bind, off) {
7739
7733
  if (bind)
@@ -7747,9 +7741,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7747
7741
  }
7748
7742
  }
7749
7743
  }
7750
- else {
7744
+ else
7751
7745
  list.push(item);
7752
- }
7753
7746
  }
7754
7747
  zoom(_zoomType, _padding, _fixedScale) {
7755
7748
  return needPlugin('view');
@@ -7793,10 +7786,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7793
7786
  this.stop();
7794
7787
  this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
7795
7788
  this.__removeListenEvents();
7796
- this.__controllers.forEach(item => {
7797
- if (!(this.parent && item === this.interaction))
7798
- item.destroy();
7799
- });
7789
+ this.__controllers.forEach(item => !(this.parent && item === this.interaction) && item.destroy());
7800
7790
  this.__controllers.length = 0;
7801
7791
  if (!this.parent) {
7802
7792
  if (this.selector)
@@ -8329,20 +8319,19 @@ let Text = class Text extends UI {
8329
8319
  }
8330
8320
  __updateTextDrawData() {
8331
8321
  const data = this.__;
8332
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8333
- }
8334
- __updateBoxBounds() {
8335
- const data = this.__;
8336
- const layout = this.__layout;
8337
8322
  const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data;
8338
- const autoWidth = data.__autoWidth;
8339
- const autoHeight = data.__autoHeight;
8340
8323
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
8341
8324
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
8342
8325
  data.__padding = padding ? MathHelper.fourNumber(padding) : undefined;
8343
8326
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8344
8327
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8345
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;
8346
8335
  this.__updateTextDrawData();
8347
8336
  const { bounds } = data.__textDrawData;
8348
8337
  const b = layout.boxBounds;
@@ -8355,20 +8344,15 @@ let Text = class Text extends UI {
8355
8344
  b.height = autoHeight ? bounds.height : data.height;
8356
8345
  if (padding) {
8357
8346
  const [top, right, bottom, left] = data.__padding;
8358
- if (autoWidth) {
8359
- b.x -= left;
8360
- b.width += (right + left);
8361
- }
8362
- if (autoHeight) {
8363
- b.y -= top;
8364
- b.height += (bottom + top);
8365
- }
8347
+ if (autoWidth)
8348
+ b.x -= left, b.width += (right + left);
8349
+ if (autoHeight)
8350
+ b.y -= top, b.height += (bottom + top);
8366
8351
  }
8367
8352
  this.__updateNaturalSize();
8368
8353
  }
8369
- else {
8354
+ else
8370
8355
  super.__updateBoxBounds();
8371
- }
8372
8356
  if (italic)
8373
8357
  b.width += fontSize * 0.16;
8374
8358
  const contentBounds = includes(b, bounds) ? b : bounds;
@@ -8491,11 +8475,7 @@ let Pen = class Pen extends Group {
8491
8475
  this.add(path);
8492
8476
  return this;
8493
8477
  }
8494
- beginPath() {
8495
- this.__path.length = 0;
8496
- this.paint();
8497
- return this;
8498
- }
8478
+ beginPath() { return this; }
8499
8479
  moveTo(_x, _y) { return this; }
8500
8480
  lineTo(_x, _y) { return this; }
8501
8481
  bezierCurveTo(_x1, _y1, _x2, _y2, _x, _y) { return this; }
@@ -8522,7 +8502,7 @@ __decorate([
8522
8502
  penPathType()
8523
8503
  ], Pen.prototype, "path", void 0);
8524
8504
  Pen = __decorate([
8525
- useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8505
+ useModule(PathCreator, ['set', 'path', 'paint']),
8526
8506
  registerUI()
8527
8507
  ], Pen);
8528
8508
  function penPathType() {
@@ -8538,14 +8518,10 @@ function fillText(ui, canvas) {
8538
8518
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
8539
8519
  for (let i = 0, len = rows.length; i < len; i++) {
8540
8520
  row = rows[i];
8541
- if (row.text) {
8521
+ if (row.text)
8542
8522
  canvas.fillText(row.text, row.x, row.y);
8543
- }
8544
- else if (row.data) {
8545
- row.data.forEach(charData => {
8546
- canvas.fillText(charData.char, charData.x, row.y);
8547
- });
8548
- }
8523
+ else if (row.data)
8524
+ row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
8549
8525
  if (decorationY)
8550
8526
  canvas.fillRect(row.x, row.y + decorationY, row.width, decorationHeight);
8551
8527
  }
@@ -8611,12 +8587,10 @@ function drawAlignStroke(align, stroke, isStrokes, ui, canvas) {
8611
8587
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
8612
8588
  fillText(ui, out);
8613
8589
  out.blendMode = 'normal';
8614
- if (ui.__worldFlipped) {
8590
+ if (ui.__worldFlipped)
8615
8591
  canvas.copyWorldByReset(out, ui.__nowWorld);
8616
- }
8617
- else {
8592
+ else
8618
8593
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
8619
- }
8620
8594
  out.recycle(ui.__nowWorld);
8621
8595
  }
8622
8596
  function drawTextStroke(ui, canvas) {
@@ -8624,14 +8598,10 @@ function drawTextStroke(ui, canvas) {
8624
8598
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
8625
8599
  for (let i = 0, len = rows.length; i < len; i++) {
8626
8600
  row = rows[i];
8627
- if (row.text) {
8601
+ if (row.text)
8628
8602
  canvas.strokeText(row.text, row.x, row.y);
8629
- }
8630
- else if (row.data) {
8631
- row.data.forEach(charData => {
8632
- canvas.strokeText(charData.char, charData.x, row.y);
8633
- });
8634
- }
8603
+ else if (row.data)
8604
+ row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
8635
8605
  if (decorationY)
8636
8606
  canvas.strokeRect(row.x, row.y + decorationY, row.width, decorationHeight);
8637
8607
  }
@@ -8684,12 +8654,10 @@ function stroke(stroke, ui, canvas) {
8684
8654
  out.stroke();
8685
8655
  options.windingRule ? out.clip(options.windingRule) : out.clip();
8686
8656
  out.clearWorld(ui.__layout.renderBounds);
8687
- if (ui.__worldFlipped) {
8657
+ if (ui.__worldFlipped)
8688
8658
  canvas.copyWorldByReset(out, ui.__nowWorld);
8689
- }
8690
- else {
8659
+ else
8691
8660
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
8692
- }
8693
8661
  out.recycle(ui.__nowWorld);
8694
8662
  break;
8695
8663
  }
@@ -8724,12 +8692,10 @@ function strokes(strokes, ui, canvas) {
8724
8692
  drawStrokesStyle(strokes, false, ui, out);
8725
8693
  options.windingRule ? out.clip(options.windingRule) : out.clip();
8726
8694
  out.clearWorld(renderBounds);
8727
- if (ui.__worldFlipped) {
8695
+ if (ui.__worldFlipped)
8728
8696
  canvas.copyWorldByReset(out, ui.__nowWorld);
8729
- }
8730
- else {
8697
+ else
8731
8698
  canvas.copyWorldToInner(out, ui.__nowWorld, renderBounds);
8732
- }
8733
8699
  out.recycle(ui.__nowWorld);
8734
8700
  break;
8735
8701
  }
@@ -8793,12 +8759,7 @@ function compute(attrName, ui) {
8793
8759
  data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
8794
8760
  if (leafPaints.length && leafPaints[0].image)
8795
8761
  hasOpacityPixel = leafPaints[0].image.hasOpacityPixel;
8796
- if (attrName === 'fill') {
8797
- data.__pixelFill = hasOpacityPixel;
8798
- }
8799
- else {
8800
- data.__pixelStroke = hasOpacityPixel;
8801
- }
8762
+ attrName === 'fill' ? data.__pixelFill = hasOpacityPixel : data.__pixelStroke = hasOpacityPixel;
8802
8763
  }
8803
8764
  function getLeafPaint(attrName, paint, ui) {
8804
8765
  if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)