@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.
package/dist/worker.cjs CHANGED
@@ -679,14 +679,10 @@ function fillText(ui, canvas) {
679
679
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
680
680
  for (let i = 0, len = rows.length; i < len; i++) {
681
681
  row = rows[i];
682
- if (row.text) {
682
+ if (row.text)
683
683
  canvas.fillText(row.text, row.x, row.y);
684
- }
685
- else if (row.data) {
686
- row.data.forEach(charData => {
687
- canvas.fillText(charData.char, charData.x, row.y);
688
- });
689
- }
684
+ else if (row.data)
685
+ row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
690
686
  if (decorationY)
691
687
  canvas.fillRect(row.x, row.y + decorationY, row.width, decorationHeight);
692
688
  }
@@ -752,12 +748,10 @@ function drawAlignStroke(align, stroke, isStrokes, ui, canvas) {
752
748
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
753
749
  fillText(ui, out);
754
750
  out.blendMode = 'normal';
755
- if (ui.__worldFlipped) {
751
+ if (ui.__worldFlipped)
756
752
  canvas.copyWorldByReset(out, ui.__nowWorld);
757
- }
758
- else {
753
+ else
759
754
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
760
- }
761
755
  out.recycle(ui.__nowWorld);
762
756
  }
763
757
  function drawTextStroke(ui, canvas) {
@@ -765,14 +759,10 @@ function drawTextStroke(ui, canvas) {
765
759
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
766
760
  for (let i = 0, len = rows.length; i < len; i++) {
767
761
  row = rows[i];
768
- if (row.text) {
762
+ if (row.text)
769
763
  canvas.strokeText(row.text, row.x, row.y);
770
- }
771
- else if (row.data) {
772
- row.data.forEach(charData => {
773
- canvas.strokeText(charData.char, charData.x, row.y);
774
- });
775
- }
764
+ else if (row.data)
765
+ row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
776
766
  if (decorationY)
777
767
  canvas.strokeRect(row.x, row.y + decorationY, row.width, decorationHeight);
778
768
  }
@@ -825,12 +815,10 @@ function stroke(stroke, ui, canvas) {
825
815
  out.stroke();
826
816
  options.windingRule ? out.clip(options.windingRule) : out.clip();
827
817
  out.clearWorld(ui.__layout.renderBounds);
828
- if (ui.__worldFlipped) {
818
+ if (ui.__worldFlipped)
829
819
  canvas.copyWorldByReset(out, ui.__nowWorld);
830
- }
831
- else {
820
+ else
832
821
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
833
- }
834
822
  out.recycle(ui.__nowWorld);
835
823
  break;
836
824
  }
@@ -865,12 +853,10 @@ function strokes(strokes, ui, canvas) {
865
853
  drawStrokesStyle(strokes, false, ui, out);
866
854
  options.windingRule ? out.clip(options.windingRule) : out.clip();
867
855
  out.clearWorld(renderBounds);
868
- if (ui.__worldFlipped) {
856
+ if (ui.__worldFlipped)
869
857
  canvas.copyWorldByReset(out, ui.__nowWorld);
870
- }
871
- else {
858
+ else
872
859
  canvas.copyWorldToInner(out, ui.__nowWorld, renderBounds);
873
- }
874
860
  out.recycle(ui.__nowWorld);
875
861
  break;
876
862
  }
@@ -934,12 +920,7 @@ function compute(attrName, ui) {
934
920
  data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
935
921
  if (leafPaints.length && leafPaints[0].image)
936
922
  hasOpacityPixel = leafPaints[0].image.hasOpacityPixel;
937
- if (attrName === 'fill') {
938
- data.__pixelFill = hasOpacityPixel;
939
- }
940
- else {
941
- data.__pixelStroke = hasOpacityPixel;
942
- }
923
+ attrName === 'fill' ? data.__pixelFill = hasOpacityPixel : data.__pixelStroke = hasOpacityPixel;
943
924
  }
944
925
  function getLeafPaint(attrName, paint, ui) {
945
926
  if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)
@@ -680,14 +680,10 @@ function fillText(ui, canvas) {
680
680
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
681
681
  for (let i = 0, len = rows.length; i < len; i++) {
682
682
  row = rows[i];
683
- if (row.text) {
683
+ if (row.text)
684
684
  canvas.fillText(row.text, row.x, row.y);
685
- }
686
- else if (row.data) {
687
- row.data.forEach(charData => {
688
- canvas.fillText(charData.char, charData.x, row.y);
689
- });
690
- }
685
+ else if (row.data)
686
+ row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
691
687
  if (decorationY)
692
688
  canvas.fillRect(row.x, row.y + decorationY, row.width, decorationHeight);
693
689
  }
@@ -753,12 +749,10 @@ function drawAlignStroke(align, stroke, isStrokes, ui, canvas) {
753
749
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
754
750
  fillText(ui, out);
755
751
  out.blendMode = 'normal';
756
- if (ui.__worldFlipped) {
752
+ if (ui.__worldFlipped)
757
753
  canvas.copyWorldByReset(out, ui.__nowWorld);
758
- }
759
- else {
754
+ else
760
755
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
761
- }
762
756
  out.recycle(ui.__nowWorld);
763
757
  }
764
758
  function drawTextStroke(ui, canvas) {
@@ -766,14 +760,10 @@ function drawTextStroke(ui, canvas) {
766
760
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
767
761
  for (let i = 0, len = rows.length; i < len; i++) {
768
762
  row = rows[i];
769
- if (row.text) {
763
+ if (row.text)
770
764
  canvas.strokeText(row.text, row.x, row.y);
771
- }
772
- else if (row.data) {
773
- row.data.forEach(charData => {
774
- canvas.strokeText(charData.char, charData.x, row.y);
775
- });
776
- }
765
+ else if (row.data)
766
+ row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
777
767
  if (decorationY)
778
768
  canvas.strokeRect(row.x, row.y + decorationY, row.width, decorationHeight);
779
769
  }
@@ -826,12 +816,10 @@ function stroke(stroke, ui, canvas) {
826
816
  out.stroke();
827
817
  options.windingRule ? out.clip(options.windingRule) : out.clip();
828
818
  out.clearWorld(ui.__layout.renderBounds);
829
- if (ui.__worldFlipped) {
819
+ if (ui.__worldFlipped)
830
820
  canvas.copyWorldByReset(out, ui.__nowWorld);
831
- }
832
- else {
821
+ else
833
822
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
834
- }
835
823
  out.recycle(ui.__nowWorld);
836
824
  break;
837
825
  }
@@ -866,12 +854,10 @@ function strokes(strokes, ui, canvas) {
866
854
  drawStrokesStyle(strokes, false, ui, out);
867
855
  options.windingRule ? out.clip(options.windingRule) : out.clip();
868
856
  out.clearWorld(renderBounds);
869
- if (ui.__worldFlipped) {
857
+ if (ui.__worldFlipped)
870
858
  canvas.copyWorldByReset(out, ui.__nowWorld);
871
- }
872
- else {
859
+ else
873
860
  canvas.copyWorldToInner(out, ui.__nowWorld, renderBounds);
874
- }
875
861
  out.recycle(ui.__nowWorld);
876
862
  break;
877
863
  }
@@ -935,12 +921,7 @@ function compute(attrName, ui) {
935
921
  data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
936
922
  if (leafPaints.length && leafPaints[0].image)
937
923
  hasOpacityPixel = leafPaints[0].image.hasOpacityPixel;
938
- if (attrName === 'fill') {
939
- data.__pixelFill = hasOpacityPixel;
940
- }
941
- else {
942
- data.__pixelStroke = hasOpacityPixel;
943
- }
924
+ attrName === 'fill' ? data.__pixelFill = hasOpacityPixel : data.__pixelStroke = hasOpacityPixel;
944
925
  }
945
926
  function getLeafPaint(attrName, paint, ui) {
946
927
  if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)
package/dist/worker.js CHANGED
@@ -2961,7 +2961,6 @@ var LeaferUI = (function (exports) {
2961
2961
  set path(value) { this.__path = value; }
2962
2962
  get path() { return this.__path; }
2963
2963
  constructor(path) {
2964
- this.clearPath = this.beginPath;
2965
2964
  this.set(path);
2966
2965
  }
2967
2966
  set(path) {
@@ -3043,6 +3042,9 @@ var LeaferUI = (function (exports) {
3043
3042
  this.paint();
3044
3043
  return this;
3045
3044
  }
3045
+ clearPath() {
3046
+ return this.beginPath();
3047
+ }
3046
3048
  paint() { }
3047
3049
  }
3048
3050
 
@@ -3638,6 +3640,8 @@ var LeaferUI = (function (exports) {
3638
3640
  else {
3639
3641
  if (url.includes('.' + format) || url.includes('.' + FileHelper.upperCaseTypeMap[format]))
3640
3642
  return true;
3643
+ else if (format === 'png' && !url.includes('.'))
3644
+ return true;
3641
3645
  }
3642
3646
  return false;
3643
3647
  },
@@ -5641,11 +5645,10 @@ var LeaferUI = (function (exports) {
5641
5645
  }
5642
5646
  destroy() {
5643
5647
  if (!this.destroyed) {
5644
- const { parent } = this;
5645
- if (parent)
5648
+ if (this.parent)
5646
5649
  this.remove();
5647
5650
  if (this.children)
5648
- this.removeAll(true);
5651
+ this.clear();
5649
5652
  this.__emitLifeEvent(ChildEvent.DESTROY);
5650
5653
  this.__.destroy();
5651
5654
  this.__layout.destroy();
@@ -5959,7 +5962,7 @@ var LeaferUI = (function (exports) {
5959
5962
  }
5960
5963
  }
5961
5964
 
5962
- const version = "1.0.7";
5965
+ const version = "1.0.9";
5963
5966
 
5964
5967
  class LeaferCanvas extends LeaferCanvasBase {
5965
5968
  get allowBackgroundColor() { return true; }
@@ -6687,12 +6690,8 @@ var LeaferUI = (function (exports) {
6687
6690
  };
6688
6691
  const Transition = {
6689
6692
  list: {},
6690
- register(attrName, fn) {
6691
- Transition.list[attrName] = fn;
6692
- },
6693
- get(attrName) {
6694
- return Transition.list[attrName];
6695
- }
6693
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6694
+ get(attrName) { return Transition.list[attrName]; }
6696
6695
  };
6697
6696
 
6698
6697
  const { parse, objectToCanvasData } = PathConvert;
@@ -7138,8 +7137,8 @@ var LeaferUI = (function (exports) {
7138
7137
  pen.set(path = []), this.__drawPathByBox(pen);
7139
7138
  return curve ? PathConvert.toCanvasData(path, true) : path;
7140
7139
  }
7141
- getPathString(curve, pathForRender) {
7142
- return PathConvert.stringify(this.getPath(curve, pathForRender));
7140
+ getPathString(curve, pathForRender, floatLength) {
7141
+ return PathConvert.stringify(this.getPath(curve, pathForRender), floatLength);
7143
7142
  }
7144
7143
  load() {
7145
7144
  this.__.__computePaint();
@@ -7548,11 +7547,11 @@ var LeaferUI = (function (exports) {
7548
7547
  start() {
7549
7548
  clearTimeout(this.__startTimer);
7550
7549
  if (!this.running && this.canvas) {
7550
+ this.running = true;
7551
7551
  this.ready ? this.emitLeafer(LeaferEvent.RESTART) : this.emitLeafer(LeaferEvent.START);
7552
7552
  this.__controllers.forEach(item => item.start());
7553
7553
  if (!this.isApp)
7554
7554
  this.renderer.render();
7555
- this.running = true;
7556
7555
  }
7557
7556
  }
7558
7557
  stop() {
@@ -7658,12 +7657,10 @@ var LeaferUI = (function (exports) {
7658
7657
  }
7659
7658
  __changeFill(newValue) {
7660
7659
  this.config.fill = newValue;
7661
- if (this.canvas.allowBackgroundColor) {
7660
+ if (this.canvas.allowBackgroundColor)
7662
7661
  this.canvas.backgroundColor = newValue;
7663
- }
7664
- else {
7662
+ else
7665
7663
  this.forceRender();
7666
- }
7667
7664
  }
7668
7665
  __onCreated() {
7669
7666
  this.created = true;
@@ -7730,13 +7727,10 @@ var LeaferUI = (function (exports) {
7730
7727
  if (bind)
7731
7728
  item = item.bind(bind);
7732
7729
  this.__viewCompletedWait.push(item);
7733
- if (this.viewCompleted) {
7730
+ if (this.viewCompleted)
7734
7731
  this.__checkViewCompleted(false);
7735
- }
7736
- else {
7737
- if (!this.running)
7738
- this.start();
7739
- }
7732
+ else if (!this.running)
7733
+ this.start();
7740
7734
  }
7741
7735
  nextRender(item, bind, off) {
7742
7736
  if (bind)
@@ -7750,9 +7744,8 @@ var LeaferUI = (function (exports) {
7750
7744
  }
7751
7745
  }
7752
7746
  }
7753
- else {
7747
+ else
7754
7748
  list.push(item);
7755
- }
7756
7749
  }
7757
7750
  zoom(_zoomType, _padding, _fixedScale) {
7758
7751
  return needPlugin('view');
@@ -7796,10 +7789,7 @@ var LeaferUI = (function (exports) {
7796
7789
  this.stop();
7797
7790
  this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
7798
7791
  this.__removeListenEvents();
7799
- this.__controllers.forEach(item => {
7800
- if (!(this.parent && item === this.interaction))
7801
- item.destroy();
7802
- });
7792
+ this.__controllers.forEach(item => !(this.parent && item === this.interaction) && item.destroy());
7803
7793
  this.__controllers.length = 0;
7804
7794
  if (!this.parent) {
7805
7795
  if (this.selector)
@@ -8332,20 +8322,19 @@ var LeaferUI = (function (exports) {
8332
8322
  }
8333
8323
  __updateTextDrawData() {
8334
8324
  const data = this.__;
8335
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8336
- }
8337
- __updateBoxBounds() {
8338
- const data = this.__;
8339
- const layout = this.__layout;
8340
8325
  const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data;
8341
- const autoWidth = data.__autoWidth;
8342
- const autoHeight = data.__autoHeight;
8343
8326
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
8344
8327
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
8345
8328
  data.__padding = padding ? MathHelper.fourNumber(padding) : undefined;
8346
8329
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8347
8330
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8348
8331
  data.__clipText = textOverflow !== 'show' && !data.__autoSize;
8332
+ data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8333
+ }
8334
+ __updateBoxBounds() {
8335
+ const data = this.__;
8336
+ const layout = this.__layout;
8337
+ const { fontSize, italic, padding, __autoWidth: autoWidth, __autoHeight: autoHeight } = data;
8349
8338
  this.__updateTextDrawData();
8350
8339
  const { bounds } = data.__textDrawData;
8351
8340
  const b = layout.boxBounds;
@@ -8358,20 +8347,15 @@ var LeaferUI = (function (exports) {
8358
8347
  b.height = autoHeight ? bounds.height : data.height;
8359
8348
  if (padding) {
8360
8349
  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
- }
8350
+ if (autoWidth)
8351
+ b.x -= left, b.width += (right + left);
8352
+ if (autoHeight)
8353
+ b.y -= top, b.height += (bottom + top);
8369
8354
  }
8370
8355
  this.__updateNaturalSize();
8371
8356
  }
8372
- else {
8357
+ else
8373
8358
  super.__updateBoxBounds();
8374
- }
8375
8359
  if (italic)
8376
8360
  b.width += fontSize * 0.16;
8377
8361
  const contentBounds = includes(b, bounds) ? b : bounds;
@@ -8494,11 +8478,7 @@ var LeaferUI = (function (exports) {
8494
8478
  this.add(path);
8495
8479
  return this;
8496
8480
  }
8497
- beginPath() {
8498
- this.__path.length = 0;
8499
- this.paint();
8500
- return this;
8501
- }
8481
+ beginPath() { return this; }
8502
8482
  moveTo(_x, _y) { return this; }
8503
8483
  lineTo(_x, _y) { return this; }
8504
8484
  bezierCurveTo(_x1, _y1, _x2, _y2, _x, _y) { return this; }
@@ -8525,7 +8505,7 @@ var LeaferUI = (function (exports) {
8525
8505
  penPathType()
8526
8506
  ], exports.Pen.prototype, "path", void 0);
8527
8507
  exports.Pen = __decorate([
8528
- useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8508
+ useModule(PathCreator, ['set', 'path', 'paint']),
8529
8509
  registerUI()
8530
8510
  ], exports.Pen);
8531
8511
  function penPathType() {
@@ -8541,14 +8521,10 @@ var LeaferUI = (function (exports) {
8541
8521
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
8542
8522
  for (let i = 0, len = rows.length; i < len; i++) {
8543
8523
  row = rows[i];
8544
- if (row.text) {
8524
+ if (row.text)
8545
8525
  canvas.fillText(row.text, row.x, row.y);
8546
- }
8547
- else if (row.data) {
8548
- row.data.forEach(charData => {
8549
- canvas.fillText(charData.char, charData.x, row.y);
8550
- });
8551
- }
8526
+ else if (row.data)
8527
+ row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
8552
8528
  if (decorationY)
8553
8529
  canvas.fillRect(row.x, row.y + decorationY, row.width, decorationHeight);
8554
8530
  }
@@ -8614,12 +8590,10 @@ var LeaferUI = (function (exports) {
8614
8590
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
8615
8591
  fillText(ui, out);
8616
8592
  out.blendMode = 'normal';
8617
- if (ui.__worldFlipped) {
8593
+ if (ui.__worldFlipped)
8618
8594
  canvas.copyWorldByReset(out, ui.__nowWorld);
8619
- }
8620
- else {
8595
+ else
8621
8596
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
8622
- }
8623
8597
  out.recycle(ui.__nowWorld);
8624
8598
  }
8625
8599
  function drawTextStroke(ui, canvas) {
@@ -8627,14 +8601,10 @@ var LeaferUI = (function (exports) {
8627
8601
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
8628
8602
  for (let i = 0, len = rows.length; i < len; i++) {
8629
8603
  row = rows[i];
8630
- if (row.text) {
8604
+ if (row.text)
8631
8605
  canvas.strokeText(row.text, row.x, row.y);
8632
- }
8633
- else if (row.data) {
8634
- row.data.forEach(charData => {
8635
- canvas.strokeText(charData.char, charData.x, row.y);
8636
- });
8637
- }
8606
+ else if (row.data)
8607
+ row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
8638
8608
  if (decorationY)
8639
8609
  canvas.strokeRect(row.x, row.y + decorationY, row.width, decorationHeight);
8640
8610
  }
@@ -8687,12 +8657,10 @@ var LeaferUI = (function (exports) {
8687
8657
  out.stroke();
8688
8658
  options.windingRule ? out.clip(options.windingRule) : out.clip();
8689
8659
  out.clearWorld(ui.__layout.renderBounds);
8690
- if (ui.__worldFlipped) {
8660
+ if (ui.__worldFlipped)
8691
8661
  canvas.copyWorldByReset(out, ui.__nowWorld);
8692
- }
8693
- else {
8662
+ else
8694
8663
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
8695
- }
8696
8664
  out.recycle(ui.__nowWorld);
8697
8665
  break;
8698
8666
  }
@@ -8727,12 +8695,10 @@ var LeaferUI = (function (exports) {
8727
8695
  drawStrokesStyle(strokes, false, ui, out);
8728
8696
  options.windingRule ? out.clip(options.windingRule) : out.clip();
8729
8697
  out.clearWorld(renderBounds);
8730
- if (ui.__worldFlipped) {
8698
+ if (ui.__worldFlipped)
8731
8699
  canvas.copyWorldByReset(out, ui.__nowWorld);
8732
- }
8733
- else {
8700
+ else
8734
8701
  canvas.copyWorldToInner(out, ui.__nowWorld, renderBounds);
8735
- }
8736
8702
  out.recycle(ui.__nowWorld);
8737
8703
  break;
8738
8704
  }
@@ -8796,12 +8762,7 @@ var LeaferUI = (function (exports) {
8796
8762
  data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
8797
8763
  if (leafPaints.length && leafPaints[0].image)
8798
8764
  hasOpacityPixel = leafPaints[0].image.hasOpacityPixel;
8799
- if (attrName === 'fill') {
8800
- data.__pixelFill = hasOpacityPixel;
8801
- }
8802
- else {
8803
- data.__pixelStroke = hasOpacityPixel;
8804
- }
8765
+ attrName === 'fill' ? data.__pixelFill = hasOpacityPixel : data.__pixelStroke = hasOpacityPixel;
8805
8766
  }
8806
8767
  function getLeafPaint(attrName, paint, ui) {
8807
8768
  if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)