@leafer-draw/miniapp 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 false; }
@@ -6067,7 +6070,10 @@ Object.assign(Creator, {
6067
6070
  });
6068
6071
  function useCanvas(_canvasType, app) {
6069
6072
  Platform.origin = {
6070
- createCanvas: (width, height, _format) => app.createOffscreenCanvas({ type: '2d', width, height }),
6073
+ createCanvas: (width, height, _format) => {
6074
+ const data = { type: '2d', width, height };
6075
+ app.createOffscreenCanvas ? app.createOffscreenCanvas(data) : app.createOffScreenCanvas(data);
6076
+ },
6071
6077
  canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
6072
6078
  canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, { quality }),
6073
6079
  canvasSaveAs: (canvas, filePath, quality) => {
@@ -6821,12 +6827,8 @@ const State = {
6821
6827
  };
6822
6828
  const Transition = {
6823
6829
  list: {},
6824
- register(attrName, fn) {
6825
- Transition.list[attrName] = fn;
6826
- },
6827
- get(attrName) {
6828
- return Transition.list[attrName];
6829
- }
6830
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6831
+ get(attrName) { return Transition.list[attrName]; }
6830
6832
  };
6831
6833
 
6832
6834
  const { parse, objectToCanvasData } = PathConvert;
@@ -7272,8 +7274,8 @@ let UI = UI_1 = class UI extends Leaf {
7272
7274
  pen.set(path = []), this.__drawPathByBox(pen);
7273
7275
  return curve ? PathConvert.toCanvasData(path, true) : path;
7274
7276
  }
7275
- getPathString(curve, pathForRender) {
7276
- return PathConvert.stringify(this.getPath(curve, pathForRender));
7277
+ getPathString(curve, pathForRender, floatLength) {
7278
+ return PathConvert.stringify(this.getPath(curve, pathForRender), floatLength);
7277
7279
  }
7278
7280
  load() {
7279
7281
  this.__.__computePaint();
@@ -7682,11 +7684,11 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7682
7684
  start() {
7683
7685
  clearTimeout(this.__startTimer);
7684
7686
  if (!this.running && this.canvas) {
7687
+ this.running = true;
7685
7688
  this.ready ? this.emitLeafer(LeaferEvent.RESTART) : this.emitLeafer(LeaferEvent.START);
7686
7689
  this.__controllers.forEach(item => item.start());
7687
7690
  if (!this.isApp)
7688
7691
  this.renderer.render();
7689
- this.running = true;
7690
7692
  }
7691
7693
  }
7692
7694
  stop() {
@@ -7792,12 +7794,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7792
7794
  }
7793
7795
  __changeFill(newValue) {
7794
7796
  this.config.fill = newValue;
7795
- if (this.canvas.allowBackgroundColor) {
7797
+ if (this.canvas.allowBackgroundColor)
7796
7798
  this.canvas.backgroundColor = newValue;
7797
- }
7798
- else {
7799
+ else
7799
7800
  this.forceRender();
7800
- }
7801
7801
  }
7802
7802
  __onCreated() {
7803
7803
  this.created = true;
@@ -7864,13 +7864,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7864
7864
  if (bind)
7865
7865
  item = item.bind(bind);
7866
7866
  this.__viewCompletedWait.push(item);
7867
- if (this.viewCompleted) {
7867
+ if (this.viewCompleted)
7868
7868
  this.__checkViewCompleted(false);
7869
- }
7870
- else {
7871
- if (!this.running)
7872
- this.start();
7873
- }
7869
+ else if (!this.running)
7870
+ this.start();
7874
7871
  }
7875
7872
  nextRender(item, bind, off) {
7876
7873
  if (bind)
@@ -7884,9 +7881,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7884
7881
  }
7885
7882
  }
7886
7883
  }
7887
- else {
7884
+ else
7888
7885
  list.push(item);
7889
- }
7890
7886
  }
7891
7887
  zoom(_zoomType, _padding, _fixedScale) {
7892
7888
  return needPlugin('view');
@@ -7930,10 +7926,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7930
7926
  this.stop();
7931
7927
  this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
7932
7928
  this.__removeListenEvents();
7933
- this.__controllers.forEach(item => {
7934
- if (!(this.parent && item === this.interaction))
7935
- item.destroy();
7936
- });
7929
+ this.__controllers.forEach(item => !(this.parent && item === this.interaction) && item.destroy());
7937
7930
  this.__controllers.length = 0;
7938
7931
  if (!this.parent) {
7939
7932
  if (this.selector)
@@ -8466,20 +8459,19 @@ let Text = class Text extends UI {
8466
8459
  }
8467
8460
  __updateTextDrawData() {
8468
8461
  const data = this.__;
8469
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8470
- }
8471
- __updateBoxBounds() {
8472
- const data = this.__;
8473
- const layout = this.__layout;
8474
8462
  const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data;
8475
- const autoWidth = data.__autoWidth;
8476
- const autoHeight = data.__autoHeight;
8477
8463
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
8478
8464
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
8479
8465
  data.__padding = padding ? MathHelper.fourNumber(padding) : undefined;
8480
8466
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8481
8467
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8482
8468
  data.__clipText = textOverflow !== 'show' && !data.__autoSize;
8469
+ data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8470
+ }
8471
+ __updateBoxBounds() {
8472
+ const data = this.__;
8473
+ const layout = this.__layout;
8474
+ const { fontSize, italic, padding, __autoWidth: autoWidth, __autoHeight: autoHeight } = data;
8483
8475
  this.__updateTextDrawData();
8484
8476
  const { bounds } = data.__textDrawData;
8485
8477
  const b = layout.boxBounds;
@@ -8492,20 +8484,15 @@ let Text = class Text extends UI {
8492
8484
  b.height = autoHeight ? bounds.height : data.height;
8493
8485
  if (padding) {
8494
8486
  const [top, right, bottom, left] = data.__padding;
8495
- if (autoWidth) {
8496
- b.x -= left;
8497
- b.width += (right + left);
8498
- }
8499
- if (autoHeight) {
8500
- b.y -= top;
8501
- b.height += (bottom + top);
8502
- }
8487
+ if (autoWidth)
8488
+ b.x -= left, b.width += (right + left);
8489
+ if (autoHeight)
8490
+ b.y -= top, b.height += (bottom + top);
8503
8491
  }
8504
8492
  this.__updateNaturalSize();
8505
8493
  }
8506
- else {
8494
+ else
8507
8495
  super.__updateBoxBounds();
8508
- }
8509
8496
  if (italic)
8510
8497
  b.width += fontSize * 0.16;
8511
8498
  const contentBounds = includes(b, bounds) ? b : bounds;
@@ -8628,11 +8615,7 @@ let Pen = class Pen extends Group {
8628
8615
  this.add(path);
8629
8616
  return this;
8630
8617
  }
8631
- beginPath() {
8632
- this.__path.length = 0;
8633
- this.paint();
8634
- return this;
8635
- }
8618
+ beginPath() { return this; }
8636
8619
  moveTo(_x, _y) { return this; }
8637
8620
  lineTo(_x, _y) { return this; }
8638
8621
  bezierCurveTo(_x1, _y1, _x2, _y2, _x, _y) { return this; }
@@ -8659,7 +8642,7 @@ __decorate([
8659
8642
  penPathType()
8660
8643
  ], Pen.prototype, "path", void 0);
8661
8644
  Pen = __decorate([
8662
- useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8645
+ useModule(PathCreator, ['set', 'path', 'paint']),
8663
8646
  registerUI()
8664
8647
  ], Pen);
8665
8648
  function penPathType() {
@@ -8675,14 +8658,10 @@ function fillText(ui, canvas) {
8675
8658
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
8676
8659
  for (let i = 0, len = rows.length; i < len; i++) {
8677
8660
  row = rows[i];
8678
- if (row.text) {
8661
+ if (row.text)
8679
8662
  canvas.fillText(row.text, row.x, row.y);
8680
- }
8681
- else if (row.data) {
8682
- row.data.forEach(charData => {
8683
- canvas.fillText(charData.char, charData.x, row.y);
8684
- });
8685
- }
8663
+ else if (row.data)
8664
+ row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
8686
8665
  if (decorationY)
8687
8666
  canvas.fillRect(row.x, row.y + decorationY, row.width, decorationHeight);
8688
8667
  }
@@ -8748,12 +8727,10 @@ function drawAlignStroke(align, stroke, isStrokes, ui, canvas) {
8748
8727
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
8749
8728
  fillText(ui, out);
8750
8729
  out.blendMode = 'normal';
8751
- if (ui.__worldFlipped) {
8730
+ if (ui.__worldFlipped)
8752
8731
  canvas.copyWorldByReset(out, ui.__nowWorld);
8753
- }
8754
- else {
8732
+ else
8755
8733
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
8756
- }
8757
8734
  out.recycle(ui.__nowWorld);
8758
8735
  }
8759
8736
  function drawTextStroke(ui, canvas) {
@@ -8761,14 +8738,10 @@ function drawTextStroke(ui, canvas) {
8761
8738
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
8762
8739
  for (let i = 0, len = rows.length; i < len; i++) {
8763
8740
  row = rows[i];
8764
- if (row.text) {
8741
+ if (row.text)
8765
8742
  canvas.strokeText(row.text, row.x, row.y);
8766
- }
8767
- else if (row.data) {
8768
- row.data.forEach(charData => {
8769
- canvas.strokeText(charData.char, charData.x, row.y);
8770
- });
8771
- }
8743
+ else if (row.data)
8744
+ row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
8772
8745
  if (decorationY)
8773
8746
  canvas.strokeRect(row.x, row.y + decorationY, row.width, decorationHeight);
8774
8747
  }
@@ -8821,12 +8794,10 @@ function stroke(stroke, ui, canvas) {
8821
8794
  out.stroke();
8822
8795
  options.windingRule ? out.clip(options.windingRule) : out.clip();
8823
8796
  out.clearWorld(ui.__layout.renderBounds);
8824
- if (ui.__worldFlipped) {
8797
+ if (ui.__worldFlipped)
8825
8798
  canvas.copyWorldByReset(out, ui.__nowWorld);
8826
- }
8827
- else {
8799
+ else
8828
8800
  canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
8829
- }
8830
8801
  out.recycle(ui.__nowWorld);
8831
8802
  break;
8832
8803
  }
@@ -8861,12 +8832,10 @@ function strokes(strokes, ui, canvas) {
8861
8832
  drawStrokesStyle(strokes, false, ui, out);
8862
8833
  options.windingRule ? out.clip(options.windingRule) : out.clip();
8863
8834
  out.clearWorld(renderBounds);
8864
- if (ui.__worldFlipped) {
8835
+ if (ui.__worldFlipped)
8865
8836
  canvas.copyWorldByReset(out, ui.__nowWorld);
8866
- }
8867
- else {
8837
+ else
8868
8838
  canvas.copyWorldToInner(out, ui.__nowWorld, renderBounds);
8869
- }
8870
8839
  out.recycle(ui.__nowWorld);
8871
8840
  break;
8872
8841
  }
@@ -8930,12 +8899,7 @@ function compute(attrName, ui) {
8930
8899
  data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
8931
8900
  if (leafPaints.length && leafPaints[0].image)
8932
8901
  hasOpacityPixel = leafPaints[0].image.hasOpacityPixel;
8933
- if (attrName === 'fill') {
8934
- data.__pixelFill = hasOpacityPixel;
8935
- }
8936
- else {
8937
- data.__pixelStroke = hasOpacityPixel;
8938
- }
8902
+ attrName === 'fill' ? data.__pixelFill = hasOpacityPixel : data.__pixelStroke = hasOpacityPixel;
8939
8903
  }
8940
8904
  function getLeafPaint(attrName, paint, ui) {
8941
8905
  if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)