@leafer-draw/worker 1.0.5 → 1.0.6

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.js CHANGED
@@ -555,6 +555,12 @@ var LeaferUI = (function (exports) {
555
555
  to.y = t.y + sin$4(r) * distance;
556
556
  return to;
557
557
  },
558
+ toNumberPoints(originPoints) {
559
+ let points = originPoints;
560
+ if (typeof originPoints[0] === 'object')
561
+ points = [], originPoints.forEach(p => points.push(p.x, p.y));
562
+ return points;
563
+ },
558
564
  reset(t) {
559
565
  P$5.reset(t);
560
566
  }
@@ -1545,7 +1551,10 @@ var LeaferUI = (function (exports) {
1545
1551
 
1546
1552
  class LeafData {
1547
1553
  get __useNaturalRatio() { return true; }
1548
- get __isLinePath() { return this.path && this.path.length === 6; }
1554
+ get __isLinePath() {
1555
+ const { path } = this;
1556
+ return path && path.length === 6 && path[0] === 1;
1557
+ }
1549
1558
  get __blendMode() {
1550
1559
  if (this.eraser && this.eraser !== 'path')
1551
1560
  return 'destination-out';
@@ -2308,11 +2317,12 @@ var LeaferUI = (function (exports) {
2308
2317
 
2309
2318
  const { sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil$1, abs: abs$3, PI: PI$2, sqrt: sqrt$1, pow } = Math;
2310
2319
  const { setPoint: setPoint$2, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2311
- const { set } = PointHelper;
2320
+ const { set, toNumberPoints } = PointHelper;
2312
2321
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$5 } = PathCommandMap;
2313
2322
  const tempPoint$2 = {};
2314
2323
  const BezierHelper = {
2315
- points(data, points, curve, close) {
2324
+ points(data, originPoints, curve, close) {
2325
+ let points = toNumberPoints(originPoints);
2316
2326
  data.push(M$5, points[0], points[1]);
2317
2327
  if (curve && points.length > 5) {
2318
2328
  let aX, aY, bX, bY, cX, cY, c1X, c1Y, c2X, c2Y;
@@ -2821,6 +2831,27 @@ var LeaferUI = (function (exports) {
2821
2831
  }
2822
2832
  return data;
2823
2833
  },
2834
+ objectToCanvasData(list) {
2835
+ const data = [];
2836
+ list.forEach(item => {
2837
+ switch (item.name) {
2838
+ case 'M':
2839
+ data.push(M$4, item.x, item.y);
2840
+ break;
2841
+ case 'L':
2842
+ data.push(L$5, item.x, item.y);
2843
+ break;
2844
+ case 'C':
2845
+ data.push(C$4, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2846
+ break;
2847
+ case 'Q':
2848
+ data.push(Q$3, item.x1, item.y1, item.x, item.y);
2849
+ break;
2850
+ case 'Z': data.push(Z$4);
2851
+ }
2852
+ });
2853
+ return data;
2854
+ },
2824
2855
  copyData(data, old, index, count) {
2825
2856
  for (let i = index, end = index + count; i < end; i++) {
2826
2857
  data.push(old[i]);
@@ -5162,7 +5193,7 @@ var LeaferUI = (function (exports) {
5162
5193
  if (this.__worldOpacity) {
5163
5194
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5164
5195
  this.__drawRenderPath(canvas);
5165
- this.__.windingRule ? canvas.clip(this.__.windingRule) : canvas.clip();
5196
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
5166
5197
  }
5167
5198
  },
5168
5199
  __updateWorldOpacity() {
@@ -5679,11 +5710,17 @@ var LeaferUI = (function (exports) {
5679
5710
  add(child, index) {
5680
5711
  if (child === this)
5681
5712
  return;
5682
- child.__ || (child = UICreator.get(child.tag, child));
5713
+ const noIndex = index === undefined;
5714
+ if (!child.__) {
5715
+ if (child instanceof Array)
5716
+ return child.forEach(item => { this.add(item, index); noIndex || index++; });
5717
+ else
5718
+ child = UICreator.get(child.tag, child);
5719
+ }
5683
5720
  if (child.parent)
5684
5721
  child.parent.remove(child);
5685
5722
  child.parent = this;
5686
- index === undefined ? this.children.push(child) : this.children.splice(index, 0, child);
5723
+ noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
5687
5724
  if (child.isBranch)
5688
5725
  this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
5689
5726
  child.__layout.boxChanged || child.__layout.boxChange();
@@ -5697,9 +5734,7 @@ var LeaferUI = (function (exports) {
5697
5734
  }
5698
5735
  this.__layout.affectChildrenSort && this.__layout.childrenSortChange();
5699
5736
  }
5700
- addMany(...children) {
5701
- children.forEach(child => this.add(child));
5702
- }
5737
+ addMany(...children) { this.add(children); }
5703
5738
  remove(child, destroy) {
5704
5739
  if (child) {
5705
5740
  if (child.__) {
@@ -5927,7 +5962,7 @@ var LeaferUI = (function (exports) {
5927
5962
  }
5928
5963
  }
5929
5964
 
5930
- const version = "1.0.5";
5965
+ const version = "1.0.6";
5931
5966
 
5932
5967
  class LeaferCanvas extends LeaferCanvasBase {
5933
5968
  get allowBackgroundColor() { return true; }
@@ -6636,6 +6671,13 @@ var LeaferUI = (function (exports) {
6636
6671
 
6637
6672
  const TextConvert = {};
6638
6673
  const ColorConvert = {};
6674
+ const UnitConvert = {
6675
+ number(value, percentRefer) {
6676
+ if (typeof value === 'object')
6677
+ return value.type === 'percent' ? value.value * percentRefer : value.value;
6678
+ return value;
6679
+ }
6680
+ };
6639
6681
  const PathArrow = {};
6640
6682
  const Paint = {};
6641
6683
  const PaintImage = {};
@@ -6656,7 +6698,7 @@ var LeaferUI = (function (exports) {
6656
6698
  }
6657
6699
  };
6658
6700
 
6659
- const { parse } = PathConvert;
6701
+ const { parse, objectToCanvasData } = PathConvert;
6660
6702
  const emptyPaint = {};
6661
6703
  const debug$2 = Debug.get('UIData');
6662
6704
  class UIData extends LeafData {
@@ -6670,10 +6712,11 @@ var LeaferUI = (function (exports) {
6670
6712
  scaleX = -scaleX;
6671
6713
  return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
6672
6714
  }
6673
- else {
6715
+ else
6674
6716
  return strokeWidth;
6675
- }
6676
6717
  }
6718
+ get __hasStroke() { return this.stroke && this.strokeWidth; }
6719
+ get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6677
6720
  get __autoWidth() { return !this._width; }
6678
6721
  get __autoHeight() { return !this._height; }
6679
6722
  get __autoSide() { return !this._width || !this._height; }
@@ -6690,9 +6733,8 @@ var LeaferUI = (function (exports) {
6690
6733
  this.__leaf.scaleX *= -1;
6691
6734
  debug$2.warn('width < 0, instead -scaleX ', this);
6692
6735
  }
6693
- else {
6736
+ else
6694
6737
  this._width = value;
6695
- }
6696
6738
  }
6697
6739
  setHeight(value) {
6698
6740
  if (value < 0) {
@@ -6700,9 +6742,8 @@ var LeaferUI = (function (exports) {
6700
6742
  this.__leaf.scaleY *= -1;
6701
6743
  debug$2.warn('height < 0, instead -scaleY', this);
6702
6744
  }
6703
- else {
6745
+ else
6704
6746
  this._height = value;
6705
- }
6706
6747
  }
6707
6748
  setFill(value) {
6708
6749
  if (this.__naturalWidth)
@@ -6743,9 +6784,10 @@ var LeaferUI = (function (exports) {
6743
6784
  }
6744
6785
  }
6745
6786
  setPath(value) {
6746
- if (typeof value === 'string') {
6787
+ const isString = typeof value === 'string';
6788
+ if (isString || (value && typeof value[0] === 'object')) {
6747
6789
  this.__setInput('path', value);
6748
- this._path = parse(value);
6790
+ this._path = isString ? parse(value) : objectToCanvasData(value);
6749
6791
  }
6750
6792
  else {
6751
6793
  if (this.__input)
@@ -6760,12 +6802,8 @@ var LeaferUI = (function (exports) {
6760
6802
  value = value.filter((item) => item.visible !== false);
6761
6803
  this._shadow = value.length ? value : null;
6762
6804
  }
6763
- else if (value) {
6764
- this._shadow = value.visible === false ? null : [value];
6765
- }
6766
- else {
6767
- this._shadow = null;
6768
- }
6805
+ else
6806
+ this._shadow = value && value.visible !== false ? [value] : null;
6769
6807
  }
6770
6808
  setInnerShadow(value) {
6771
6809
  this.__setInput('innerShadow', value);
@@ -6774,12 +6812,8 @@ var LeaferUI = (function (exports) {
6774
6812
  value = value.filter((item) => item.visible !== false);
6775
6813
  this._innerShadow = value.length ? value : null;
6776
6814
  }
6777
- else if (value) {
6778
- this._innerShadow = value.visible === false ? null : [value];
6779
- }
6780
- else {
6781
- this._innerShadow = null;
6782
- }
6815
+ else
6816
+ this._innerShadow = value && value.visible !== false ? [value] : null;
6783
6817
  }
6784
6818
  __computePaint() {
6785
6819
  const { fill, stroke } = this.__input;
@@ -6790,24 +6824,19 @@ var LeaferUI = (function (exports) {
6790
6824
  this.__needComputePaint = false;
6791
6825
  }
6792
6826
  }
6793
- const UnitConvert = {
6794
- number(value, percentRefer) {
6795
- if (typeof value === 'object')
6796
- return value.type === 'percent' ? value.value * percentRefer : value.value;
6797
- return value;
6798
- }
6799
- };
6800
6827
 
6801
6828
  class GroupData extends UIData {
6802
6829
  }
6803
6830
 
6804
6831
  class BoxData extends GroupData {
6805
6832
  get __boxStroke() { return !this.__pathInputed; }
6833
+ get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
6834
+ get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
6806
6835
  }
6807
6836
 
6808
6837
  class LeaferData extends GroupData {
6809
- __getInputData() {
6810
- const data = super.__getInputData();
6838
+ __getInputData(names, options) {
6839
+ const data = super.__getInputData(names, options);
6811
6840
  canvasSizeAttrs.forEach(key => delete data[key]);
6812
6841
  return data;
6813
6842
  }
@@ -6834,6 +6863,7 @@ var LeaferUI = (function (exports) {
6834
6863
  }
6835
6864
 
6836
6865
  class PathData extends UIData {
6866
+ get __pathInputed() { return 2; }
6837
6867
  }
6838
6868
 
6839
6869
  class PenData extends GroupData {
@@ -6880,16 +6910,18 @@ var LeaferUI = (function (exports) {
6880
6910
  delete data.fill;
6881
6911
  return data;
6882
6912
  }
6883
- __getInputData() {
6884
- const data = super.__getInputData();
6913
+ __getInputData(names, options) {
6914
+ const data = super.__getInputData(names, options);
6885
6915
  delete data.fill;
6886
6916
  return data;
6887
6917
  }
6888
6918
  }
6889
6919
 
6890
6920
  class CanvasData extends RectData {
6891
- __getInputData() {
6892
- const data = super.__getInputData();
6921
+ get __isCanvas() { return true; }
6922
+ get __drawAfterFill() { return true; }
6923
+ __getInputData(names, options) {
6924
+ const data = super.__getInputData(names, options);
6893
6925
  data.url = this.__leaf.canvas.toDataURL('image/png');
6894
6926
  return data;
6895
6927
  }
@@ -6916,16 +6948,12 @@ var LeaferUI = (function (exports) {
6916
6948
  let width = 0;
6917
6949
  const { shadow, innerShadow, blur, backgroundBlur } = this.__;
6918
6950
  if (shadow)
6919
- shadow.forEach(item => {
6920
- width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5);
6921
- });
6951
+ shadow.forEach(item => width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5));
6922
6952
  if (blur)
6923
6953
  width = Math.max(width, blur);
6924
6954
  let shapeWidth = width = Math.ceil(width);
6925
6955
  if (innerShadow)
6926
- innerShadow.forEach(item => {
6927
- shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5);
6928
- });
6956
+ innerShadow.forEach(item => shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5));
6929
6957
  if (backgroundBlur)
6930
6958
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
6931
6959
  this.__layout.renderShapeSpread = shapeWidth;
@@ -7007,6 +7035,16 @@ var LeaferUI = (function (exports) {
7007
7035
  if (stroke && !ignoreStroke)
7008
7036
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7009
7037
  }
7038
+ },
7039
+ __drawAfterFill(canvas, options) {
7040
+ if (this.__.__clipAfterFill) {
7041
+ canvas.save();
7042
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
7043
+ this.__drawContent(canvas, options);
7044
+ canvas.restore();
7045
+ }
7046
+ else
7047
+ this.__drawContent(canvas, options);
7010
7048
  }
7011
7049
  };
7012
7050
  function drawFast(ui, canvas, options) {
@@ -7073,8 +7111,8 @@ var LeaferUI = (function (exports) {
7073
7111
  return pen;
7074
7112
  }
7075
7113
  get editConfig() { return undefined; }
7076
- get editOuter() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
7077
- get editInner() { return 'PathEditor'; }
7114
+ get editOuter() { return ''; }
7115
+ get editInner() { return ''; }
7078
7116
  constructor(data) {
7079
7117
  super(data);
7080
7118
  }
@@ -7085,9 +7123,8 @@ var LeaferUI = (function (exports) {
7085
7123
  Object.assign(this, data);
7086
7124
  this.lockNormalStyle = false;
7087
7125
  }
7088
- else {
7126
+ else
7089
7127
  Object.assign(this, data);
7090
- }
7091
7128
  }
7092
7129
  get(name) {
7093
7130
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
@@ -7389,23 +7426,13 @@ var LeaferUI = (function (exports) {
7389
7426
  if (data.children) {
7390
7427
  const { children } = data;
7391
7428
  delete data.children;
7392
- if (!this.children) {
7393
- this.__setBranch();
7394
- }
7395
- else {
7396
- this.clear();
7397
- }
7429
+ this.children ? this.clear() : this.__setBranch();
7398
7430
  super.set(data, isTemp);
7399
- let child;
7400
- children.forEach(childData => {
7401
- child = childData.__ ? childData : UICreator.get(childData.tag, childData);
7402
- this.add(child);
7403
- });
7431
+ children.forEach(child => this.add(child));
7404
7432
  data.children = children;
7405
7433
  }
7406
- else {
7434
+ else
7407
7435
  super.set(data, isTemp);
7408
- }
7409
7436
  }
7410
7437
  toJSON(options) {
7411
7438
  const data = super.toJSON(options);
@@ -7837,9 +7864,7 @@ var LeaferUI = (function (exports) {
7837
7864
  }
7838
7865
  __updateStrokeSpread() { return 0; }
7839
7866
  __updateRectRenderSpread() { return 0; }
7840
- __updateRenderSpread() {
7841
- return this.__updateRectRenderSpread() || -1;
7842
- }
7867
+ __updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
7843
7868
  __updateRectBoxBounds() { }
7844
7869
  __updateBoxBounds(_secondLayout) {
7845
7870
  const data = this.__;
@@ -7859,13 +7884,11 @@ var LeaferUI = (function (exports) {
7859
7884
  }
7860
7885
  this.__updateNaturalSize();
7861
7886
  }
7862
- else {
7887
+ else
7863
7888
  this.__updateRectBoxBounds();
7864
- }
7865
7889
  }
7866
- else {
7890
+ else
7867
7891
  this.__updateRectBoxBounds();
7868
- }
7869
7892
  }
7870
7893
  __updateStrokeBounds() { }
7871
7894
  __updateRenderBounds() {
@@ -7875,14 +7898,13 @@ var LeaferUI = (function (exports) {
7875
7898
  super.__updateRenderBounds();
7876
7899
  copy$2(childrenRenderBounds, renderBounds);
7877
7900
  this.__updateRectRenderBounds();
7878
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
7901
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds);
7902
+ if (isOverflow && this.__.overflow !== 'hide')
7903
+ add(renderBounds, childrenRenderBounds);
7879
7904
  }
7880
- else {
7905
+ else
7881
7906
  this.__updateRectRenderBounds();
7882
- }
7883
- this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
7884
- if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
7885
- add(renderBounds, childrenRenderBounds);
7907
+ !this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow);
7886
7908
  }
7887
7909
  __updateRectRenderBounds() { }
7888
7910
  __updateRectChange() { }
@@ -7902,20 +7924,9 @@ var LeaferUI = (function (exports) {
7902
7924
  this.__renderGroup(canvas, options);
7903
7925
  }
7904
7926
  }
7905
- __drawAfterFill(canvas, options) {
7906
- const { length } = this.children;
7907
- if (this.isOverflow) {
7908
- canvas.save();
7909
- canvas.clip();
7910
- if (length)
7911
- this.__renderGroup(canvas, options);
7912
- canvas.restore();
7913
- }
7914
- else {
7915
- if (length)
7916
- this.__renderGroup(canvas, options);
7917
- }
7918
- if (this.__.stroke && length) {
7927
+ __drawContent(canvas, options) {
7928
+ this.__renderGroup(canvas, options);
7929
+ if (this.__.__hasStroke) {
7919
7930
  canvas.setWorld(this.__nowWorld);
7920
7931
  this.__drawRenderPath(canvas);
7921
7932
  }
@@ -8079,17 +8090,15 @@ var LeaferUI = (function (exports) {
8079
8090
  if (data.__useArrow)
8080
8091
  PathArrow.addArrows(this, false);
8081
8092
  }
8082
- else {
8093
+ else
8083
8094
  super.__updateRenderPath();
8084
- }
8085
8095
  }
8086
8096
  __updateBoxBounds() {
8087
8097
  if (this.points) {
8088
8098
  toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
8089
8099
  }
8090
- else {
8100
+ else
8091
8101
  super.__updateBoxBounds();
8092
- }
8093
8102
  }
8094
8103
  };
8095
8104
  __decorate([
@@ -8227,7 +8236,6 @@ var LeaferUI = (function (exports) {
8227
8236
  super(data);
8228
8237
  this.canvas = Creator.canvas(this.__);
8229
8238
  this.context = this.canvas.context;
8230
- this.__.__isCanvas = this.__.__drawAfterFill = true;
8231
8239
  if (data && data.url)
8232
8240
  this.drawImage(data.url);
8233
8241
  }
@@ -8240,8 +8248,7 @@ var LeaferUI = (function (exports) {
8240
8248
  });
8241
8249
  }
8242
8250
  draw(ui, offset, scale, rotation) {
8243
- ui.__layout.update();
8244
- const matrix = new Matrix(ui.__world).invert();
8251
+ const matrix = new Matrix(ui.worldTransform).invert();
8245
8252
  const m = new Matrix();
8246
8253
  if (offset)
8247
8254
  m.translate(offset.x, offset.y);
@@ -8256,17 +8263,9 @@ var LeaferUI = (function (exports) {
8256
8263
  paint() {
8257
8264
  this.forceRender();
8258
8265
  }
8259
- __drawAfterFill(canvas, _options) {
8260
- const { width, height, cornerRadius } = this.__, { view } = this.canvas;
8261
- if (cornerRadius || this.pathInputed) {
8262
- canvas.save();
8263
- canvas.clip();
8264
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8265
- canvas.restore();
8266
- }
8267
- else {
8268
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8269
- }
8266
+ __drawContent(canvas, _options) {
8267
+ const { width, height } = this.__, { view } = this.canvas;
8268
+ canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8270
8269
  }
8271
8270
  __updateSize() {
8272
8271
  const { canvas } = this;
@@ -8310,7 +8309,6 @@ var LeaferUI = (function (exports) {
8310
8309
  const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8311
8310
  exports.Text = class Text extends exports.UI {
8312
8311
  get __tag() { return 'Text'; }
8313
- get editInner() { return 'TextEditor'; }
8314
8312
  get textDrawData() {
8315
8313
  this.__layout.update();
8316
8314
  return this.__.__textDrawData;
@@ -8476,7 +8474,6 @@ var LeaferUI = (function (exports) {
8476
8474
  get __tag() { return 'Path'; }
8477
8475
  constructor(data) {
8478
8476
  super(data);
8479
- this.__.__pathInputed = 2;
8480
8477
  }
8481
8478
  };
8482
8479
  __decorate([
@@ -9154,7 +9151,7 @@ var LeaferUI = (function (exports) {
9154
9151
  }
9155
9152
  if (allowPaint) {
9156
9153
  canvas.save();
9157
- canvas.clip();
9154
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9158
9155
  if (paint.blendMode)
9159
9156
  canvas.blendMode = paint.blendMode;
9160
9157
  if (data.opacity)