@leafer-draw/worker 1.0.7 → 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
  },
@@ -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.8";
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,23 +8319,23 @@ 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;
8338
+ console.log(bounds, autoWidth, autoHeight);
8349
8339
  if (data.__lineHeight < fontSize)
8350
8340
  spread(bounds, fontSize / 2);
8351
8341
  if (autoWidth || autoHeight) {
@@ -8355,20 +8345,15 @@ let Text = class Text extends UI {
8355
8345
  b.height = autoHeight ? bounds.height : data.height;
8356
8346
  if (padding) {
8357
8347
  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
- }
8348
+ if (autoWidth)
8349
+ b.x -= left, b.width += (right + left);
8350
+ if (autoHeight)
8351
+ b.y -= top, b.height += (bottom + top);
8366
8352
  }
8367
8353
  this.__updateNaturalSize();
8368
8354
  }
8369
- else {
8355
+ else
8370
8356
  super.__updateBoxBounds();
8371
- }
8372
8357
  if (italic)
8373
8358
  b.width += fontSize * 0.16;
8374
8359
  const contentBounds = includes(b, bounds) ? b : bounds;
@@ -8491,11 +8476,7 @@ let Pen = class Pen extends Group {
8491
8476
  this.add(path);
8492
8477
  return this;
8493
8478
  }
8494
- beginPath() {
8495
- this.__path.length = 0;
8496
- this.paint();
8497
- return this;
8498
- }
8479
+ beginPath() { return this; }
8499
8480
  moveTo(_x, _y) { return this; }
8500
8481
  lineTo(_x, _y) { return this; }
8501
8482
  bezierCurveTo(_x1, _y1, _x2, _y2, _x, _y) { return this; }
@@ -8522,7 +8503,7 @@ __decorate([
8522
8503
  penPathType()
8523
8504
  ], Pen.prototype, "path", void 0);
8524
8505
  Pen = __decorate([
8525
- useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8506
+ useModule(PathCreator, ['set', 'path', 'paint']),
8526
8507
  registerUI()
8527
8508
  ], Pen);
8528
8509
  function penPathType() {
@@ -8538,14 +8519,10 @@ function fillText(ui, canvas) {
8538
8519
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
8539
8520
  for (let i = 0, len = rows.length; i < len; i++) {
8540
8521
  row = rows[i];
8541
- if (row.text) {
8522
+ if (row.text)
8542
8523
  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
- }
8524
+ else if (row.data)
8525
+ row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
8549
8526
  if (decorationY)
8550
8527
  canvas.fillRect(row.x, row.y + decorationY, row.width, decorationHeight);
8551
8528
  }
@@ -8611,12 +8588,10 @@ function drawAlignStroke(align, stroke, isStrokes, ui, canvas) {
8611
8588
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
8612
8589
  fillText(ui, out);
8613
8590
  out.blendMode = 'normal';
8614
- if (ui.__worldFlipped) {
8591
+ if (ui.__worldFlipped)
8615
8592
  canvas.copyWorldByReset(out, ui.__nowWorld);
8616
- }
8617
- else {
8593
+ else
8618
8594
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
8619
- }
8620
8595
  out.recycle(ui.__nowWorld);
8621
8596
  }
8622
8597
  function drawTextStroke(ui, canvas) {
@@ -8624,14 +8599,10 @@ function drawTextStroke(ui, canvas) {
8624
8599
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
8625
8600
  for (let i = 0, len = rows.length; i < len; i++) {
8626
8601
  row = rows[i];
8627
- if (row.text) {
8602
+ if (row.text)
8628
8603
  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
- }
8604
+ else if (row.data)
8605
+ row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
8635
8606
  if (decorationY)
8636
8607
  canvas.strokeRect(row.x, row.y + decorationY, row.width, decorationHeight);
8637
8608
  }
@@ -8684,12 +8655,10 @@ function stroke(stroke, ui, canvas) {
8684
8655
  out.stroke();
8685
8656
  options.windingRule ? out.clip(options.windingRule) : out.clip();
8686
8657
  out.clearWorld(ui.__layout.renderBounds);
8687
- if (ui.__worldFlipped) {
8658
+ if (ui.__worldFlipped)
8688
8659
  canvas.copyWorldByReset(out, ui.__nowWorld);
8689
- }
8690
- else {
8660
+ else
8691
8661
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
8692
- }
8693
8662
  out.recycle(ui.__nowWorld);
8694
8663
  break;
8695
8664
  }
@@ -8724,12 +8693,10 @@ function strokes(strokes, ui, canvas) {
8724
8693
  drawStrokesStyle(strokes, false, ui, out);
8725
8694
  options.windingRule ? out.clip(options.windingRule) : out.clip();
8726
8695
  out.clearWorld(renderBounds);
8727
- if (ui.__worldFlipped) {
8696
+ if (ui.__worldFlipped)
8728
8697
  canvas.copyWorldByReset(out, ui.__nowWorld);
8729
- }
8730
- else {
8698
+ else
8731
8699
  canvas.copyWorldToInner(out, ui.__nowWorld, renderBounds);
8732
- }
8733
8700
  out.recycle(ui.__nowWorld);
8734
8701
  break;
8735
8702
  }
@@ -8793,12 +8760,7 @@ function compute(attrName, ui) {
8793
8760
  data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
8794
8761
  if (leafPaints.length && leafPaints[0].image)
8795
8762
  hasOpacityPixel = leafPaints[0].image.hasOpacityPixel;
8796
- if (attrName === 'fill') {
8797
- data.__pixelFill = hasOpacityPixel;
8798
- }
8799
- else {
8800
- data.__pixelStroke = hasOpacityPixel;
8801
- }
8763
+ attrName === 'fill' ? data.__pixelFill = hasOpacityPixel : data.__pixelStroke = hasOpacityPixel;
8802
8764
  }
8803
8765
  function getLeafPaint(attrName, paint, ui) {
8804
8766
  if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)