@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.
@@ -552,6 +552,12 @@ const PointHelper = {
552
552
  to.y = t.y + sin$4(r) * distance;
553
553
  return to;
554
554
  },
555
+ toNumberPoints(originPoints) {
556
+ let points = originPoints;
557
+ if (typeof originPoints[0] === 'object')
558
+ points = [], originPoints.forEach(p => points.push(p.x, p.y));
559
+ return points;
560
+ },
555
561
  reset(t) {
556
562
  P$5.reset(t);
557
563
  }
@@ -1542,7 +1548,10 @@ const { assign } = DataHelper;
1542
1548
 
1543
1549
  class LeafData {
1544
1550
  get __useNaturalRatio() { return true; }
1545
- get __isLinePath() { return this.path && this.path.length === 6; }
1551
+ get __isLinePath() {
1552
+ const { path } = this;
1553
+ return path && path.length === 6 && path[0] === 1;
1554
+ }
1546
1555
  get __blendMode() {
1547
1556
  if (this.eraser && this.eraser !== 'path')
1548
1557
  return 'destination-out';
@@ -2305,11 +2314,12 @@ const RectHelper = {
2305
2314
 
2306
2315
  const { sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil$1, abs: abs$3, PI: PI$2, sqrt: sqrt$1, pow } = Math;
2307
2316
  const { setPoint: setPoint$2, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2308
- const { set } = PointHelper;
2317
+ const { set, toNumberPoints } = PointHelper;
2309
2318
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$5 } = PathCommandMap;
2310
2319
  const tempPoint$2 = {};
2311
2320
  const BezierHelper = {
2312
- points(data, points, curve, close) {
2321
+ points(data, originPoints, curve, close) {
2322
+ let points = toNumberPoints(originPoints);
2313
2323
  data.push(M$5, points[0], points[1]);
2314
2324
  if (curve && points.length > 5) {
2315
2325
  let aX, aY, bX, bY, cX, cY, c1X, c1Y, c2X, c2Y;
@@ -2818,6 +2828,27 @@ const PathConvert = {
2818
2828
  }
2819
2829
  return data;
2820
2830
  },
2831
+ objectToCanvasData(list) {
2832
+ const data = [];
2833
+ list.forEach(item => {
2834
+ switch (item.name) {
2835
+ case 'M':
2836
+ data.push(M$4, item.x, item.y);
2837
+ break;
2838
+ case 'L':
2839
+ data.push(L$5, item.x, item.y);
2840
+ break;
2841
+ case 'C':
2842
+ data.push(C$4, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2843
+ break;
2844
+ case 'Q':
2845
+ data.push(Q$3, item.x1, item.y1, item.x, item.y);
2846
+ break;
2847
+ case 'Z': data.push(Z$4);
2848
+ }
2849
+ });
2850
+ return data;
2851
+ },
2821
2852
  copyData(data, old, index, count) {
2822
2853
  for (let i = index, end = index + count; i < end; i++) {
2823
2854
  data.push(old[i]);
@@ -5159,7 +5190,7 @@ const LeafRender = {
5159
5190
  if (this.__worldOpacity) {
5160
5191
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5161
5192
  this.__drawRenderPath(canvas);
5162
- this.__.windingRule ? canvas.clip(this.__.windingRule) : canvas.clip();
5193
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
5163
5194
  }
5164
5195
  },
5165
5196
  __updateWorldOpacity() {
@@ -5676,11 +5707,17 @@ let Branch = class Branch extends Leaf {
5676
5707
  add(child, index) {
5677
5708
  if (child === this)
5678
5709
  return;
5679
- child.__ || (child = UICreator.get(child.tag, child));
5710
+ const noIndex = index === undefined;
5711
+ if (!child.__) {
5712
+ if (child instanceof Array)
5713
+ return child.forEach(item => { this.add(item, index); noIndex || index++; });
5714
+ else
5715
+ child = UICreator.get(child.tag, child);
5716
+ }
5680
5717
  if (child.parent)
5681
5718
  child.parent.remove(child);
5682
5719
  child.parent = this;
5683
- index === undefined ? this.children.push(child) : this.children.splice(index, 0, child);
5720
+ noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
5684
5721
  if (child.isBranch)
5685
5722
  this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
5686
5723
  child.__layout.boxChanged || child.__layout.boxChange();
@@ -5694,9 +5731,7 @@ let Branch = class Branch extends Leaf {
5694
5731
  }
5695
5732
  this.__layout.affectChildrenSort && this.__layout.childrenSortChange();
5696
5733
  }
5697
- addMany(...children) {
5698
- children.forEach(child => this.add(child));
5699
- }
5734
+ addMany(...children) { this.add(children); }
5700
5735
  remove(child, destroy) {
5701
5736
  if (child) {
5702
5737
  if (child.__) {
@@ -5924,7 +5959,7 @@ class LeafLevelList {
5924
5959
  }
5925
5960
  }
5926
5961
 
5927
- const version = "1.0.5";
5962
+ const version = "1.0.6";
5928
5963
 
5929
5964
  class LeaferCanvas extends LeaferCanvasBase {
5930
5965
  get allowBackgroundColor() { return true; }
@@ -6633,6 +6668,13 @@ function zoomLayerType() {
6633
6668
 
6634
6669
  const TextConvert = {};
6635
6670
  const ColorConvert = {};
6671
+ const UnitConvert = {
6672
+ number(value, percentRefer) {
6673
+ if (typeof value === 'object')
6674
+ return value.type === 'percent' ? value.value * percentRefer : value.value;
6675
+ return value;
6676
+ }
6677
+ };
6636
6678
  const PathArrow = {};
6637
6679
  const Paint = {};
6638
6680
  const PaintImage = {};
@@ -6653,7 +6695,7 @@ const Transition = {
6653
6695
  }
6654
6696
  };
6655
6697
 
6656
- const { parse } = PathConvert;
6698
+ const { parse, objectToCanvasData } = PathConvert;
6657
6699
  const emptyPaint = {};
6658
6700
  const debug$2 = Debug.get('UIData');
6659
6701
  class UIData extends LeafData {
@@ -6667,10 +6709,11 @@ class UIData extends LeafData {
6667
6709
  scaleX = -scaleX;
6668
6710
  return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
6669
6711
  }
6670
- else {
6712
+ else
6671
6713
  return strokeWidth;
6672
- }
6673
6714
  }
6715
+ get __hasStroke() { return this.stroke && this.strokeWidth; }
6716
+ get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6674
6717
  get __autoWidth() { return !this._width; }
6675
6718
  get __autoHeight() { return !this._height; }
6676
6719
  get __autoSide() { return !this._width || !this._height; }
@@ -6687,9 +6730,8 @@ class UIData extends LeafData {
6687
6730
  this.__leaf.scaleX *= -1;
6688
6731
  debug$2.warn('width < 0, instead -scaleX ', this);
6689
6732
  }
6690
- else {
6733
+ else
6691
6734
  this._width = value;
6692
- }
6693
6735
  }
6694
6736
  setHeight(value) {
6695
6737
  if (value < 0) {
@@ -6697,9 +6739,8 @@ class UIData extends LeafData {
6697
6739
  this.__leaf.scaleY *= -1;
6698
6740
  debug$2.warn('height < 0, instead -scaleY', this);
6699
6741
  }
6700
- else {
6742
+ else
6701
6743
  this._height = value;
6702
- }
6703
6744
  }
6704
6745
  setFill(value) {
6705
6746
  if (this.__naturalWidth)
@@ -6740,9 +6781,10 @@ class UIData extends LeafData {
6740
6781
  }
6741
6782
  }
6742
6783
  setPath(value) {
6743
- if (typeof value === 'string') {
6784
+ const isString = typeof value === 'string';
6785
+ if (isString || (value && typeof value[0] === 'object')) {
6744
6786
  this.__setInput('path', value);
6745
- this._path = parse(value);
6787
+ this._path = isString ? parse(value) : objectToCanvasData(value);
6746
6788
  }
6747
6789
  else {
6748
6790
  if (this.__input)
@@ -6757,12 +6799,8 @@ class UIData extends LeafData {
6757
6799
  value = value.filter((item) => item.visible !== false);
6758
6800
  this._shadow = value.length ? value : null;
6759
6801
  }
6760
- else if (value) {
6761
- this._shadow = value.visible === false ? null : [value];
6762
- }
6763
- else {
6764
- this._shadow = null;
6765
- }
6802
+ else
6803
+ this._shadow = value && value.visible !== false ? [value] : null;
6766
6804
  }
6767
6805
  setInnerShadow(value) {
6768
6806
  this.__setInput('innerShadow', value);
@@ -6771,12 +6809,8 @@ class UIData extends LeafData {
6771
6809
  value = value.filter((item) => item.visible !== false);
6772
6810
  this._innerShadow = value.length ? value : null;
6773
6811
  }
6774
- else if (value) {
6775
- this._innerShadow = value.visible === false ? null : [value];
6776
- }
6777
- else {
6778
- this._innerShadow = null;
6779
- }
6812
+ else
6813
+ this._innerShadow = value && value.visible !== false ? [value] : null;
6780
6814
  }
6781
6815
  __computePaint() {
6782
6816
  const { fill, stroke } = this.__input;
@@ -6787,24 +6821,19 @@ class UIData extends LeafData {
6787
6821
  this.__needComputePaint = false;
6788
6822
  }
6789
6823
  }
6790
- const UnitConvert = {
6791
- number(value, percentRefer) {
6792
- if (typeof value === 'object')
6793
- return value.type === 'percent' ? value.value * percentRefer : value.value;
6794
- return value;
6795
- }
6796
- };
6797
6824
 
6798
6825
  class GroupData extends UIData {
6799
6826
  }
6800
6827
 
6801
6828
  class BoxData extends GroupData {
6802
6829
  get __boxStroke() { return !this.__pathInputed; }
6830
+ get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
6831
+ get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
6803
6832
  }
6804
6833
 
6805
6834
  class LeaferData extends GroupData {
6806
- __getInputData() {
6807
- const data = super.__getInputData();
6835
+ __getInputData(names, options) {
6836
+ const data = super.__getInputData(names, options);
6808
6837
  canvasSizeAttrs.forEach(key => delete data[key]);
6809
6838
  return data;
6810
6839
  }
@@ -6831,6 +6860,7 @@ class StarData extends UIData {
6831
6860
  }
6832
6861
 
6833
6862
  class PathData extends UIData {
6863
+ get __pathInputed() { return 2; }
6834
6864
  }
6835
6865
 
6836
6866
  class PenData extends GroupData {
@@ -6877,16 +6907,18 @@ class ImageData extends RectData {
6877
6907
  delete data.fill;
6878
6908
  return data;
6879
6909
  }
6880
- __getInputData() {
6881
- const data = super.__getInputData();
6910
+ __getInputData(names, options) {
6911
+ const data = super.__getInputData(names, options);
6882
6912
  delete data.fill;
6883
6913
  return data;
6884
6914
  }
6885
6915
  }
6886
6916
 
6887
6917
  class CanvasData extends RectData {
6888
- __getInputData() {
6889
- const data = super.__getInputData();
6918
+ get __isCanvas() { return true; }
6919
+ get __drawAfterFill() { return true; }
6920
+ __getInputData(names, options) {
6921
+ const data = super.__getInputData(names, options);
6890
6922
  data.url = this.__leaf.canvas.toDataURL('image/png');
6891
6923
  return data;
6892
6924
  }
@@ -6913,16 +6945,12 @@ const UIBounds = {
6913
6945
  let width = 0;
6914
6946
  const { shadow, innerShadow, blur, backgroundBlur } = this.__;
6915
6947
  if (shadow)
6916
- shadow.forEach(item => {
6917
- width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5);
6918
- });
6948
+ 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));
6919
6949
  if (blur)
6920
6950
  width = Math.max(width, blur);
6921
6951
  let shapeWidth = width = Math.ceil(width);
6922
6952
  if (innerShadow)
6923
- innerShadow.forEach(item => {
6924
- shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5);
6925
- });
6953
+ 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));
6926
6954
  if (backgroundBlur)
6927
6955
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
6928
6956
  this.__layout.renderShapeSpread = shapeWidth;
@@ -7004,6 +7032,16 @@ const UIRender = {
7004
7032
  if (stroke && !ignoreStroke)
7005
7033
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7006
7034
  }
7035
+ },
7036
+ __drawAfterFill(canvas, options) {
7037
+ if (this.__.__clipAfterFill) {
7038
+ canvas.save();
7039
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
7040
+ this.__drawContent(canvas, options);
7041
+ canvas.restore();
7042
+ }
7043
+ else
7044
+ this.__drawContent(canvas, options);
7007
7045
  }
7008
7046
  };
7009
7047
  function drawFast(ui, canvas, options) {
@@ -7070,8 +7108,8 @@ let UI = UI_1 = class UI extends Leaf {
7070
7108
  return pen;
7071
7109
  }
7072
7110
  get editConfig() { return undefined; }
7073
- get editOuter() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
7074
- get editInner() { return 'PathEditor'; }
7111
+ get editOuter() { return ''; }
7112
+ get editInner() { return ''; }
7075
7113
  constructor(data) {
7076
7114
  super(data);
7077
7115
  }
@@ -7082,9 +7120,8 @@ let UI = UI_1 = class UI extends Leaf {
7082
7120
  Object.assign(this, data);
7083
7121
  this.lockNormalStyle = false;
7084
7122
  }
7085
- else {
7123
+ else
7086
7124
  Object.assign(this, data);
7087
- }
7088
7125
  }
7089
7126
  get(name) {
7090
7127
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
@@ -7386,23 +7423,13 @@ let Group = class Group extends UI {
7386
7423
  if (data.children) {
7387
7424
  const { children } = data;
7388
7425
  delete data.children;
7389
- if (!this.children) {
7390
- this.__setBranch();
7391
- }
7392
- else {
7393
- this.clear();
7394
- }
7426
+ this.children ? this.clear() : this.__setBranch();
7395
7427
  super.set(data, isTemp);
7396
- let child;
7397
- children.forEach(childData => {
7398
- child = childData.__ ? childData : UICreator.get(childData.tag, childData);
7399
- this.add(child);
7400
- });
7428
+ children.forEach(child => this.add(child));
7401
7429
  data.children = children;
7402
7430
  }
7403
- else {
7431
+ else
7404
7432
  super.set(data, isTemp);
7405
- }
7406
7433
  }
7407
7434
  toJSON(options) {
7408
7435
  const data = super.toJSON(options);
@@ -7834,9 +7861,7 @@ let Box = class Box extends Group {
7834
7861
  }
7835
7862
  __updateStrokeSpread() { return 0; }
7836
7863
  __updateRectRenderSpread() { return 0; }
7837
- __updateRenderSpread() {
7838
- return this.__updateRectRenderSpread() || -1;
7839
- }
7864
+ __updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
7840
7865
  __updateRectBoxBounds() { }
7841
7866
  __updateBoxBounds(_secondLayout) {
7842
7867
  const data = this.__;
@@ -7856,13 +7881,11 @@ let Box = class Box extends Group {
7856
7881
  }
7857
7882
  this.__updateNaturalSize();
7858
7883
  }
7859
- else {
7884
+ else
7860
7885
  this.__updateRectBoxBounds();
7861
- }
7862
7886
  }
7863
- else {
7887
+ else
7864
7888
  this.__updateRectBoxBounds();
7865
- }
7866
7889
  }
7867
7890
  __updateStrokeBounds() { }
7868
7891
  __updateRenderBounds() {
@@ -7872,14 +7895,13 @@ let Box = class Box extends Group {
7872
7895
  super.__updateRenderBounds();
7873
7896
  copy$2(childrenRenderBounds, renderBounds);
7874
7897
  this.__updateRectRenderBounds();
7875
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
7898
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds);
7899
+ if (isOverflow && this.__.overflow !== 'hide')
7900
+ add(renderBounds, childrenRenderBounds);
7876
7901
  }
7877
- else {
7902
+ else
7878
7903
  this.__updateRectRenderBounds();
7879
- }
7880
- this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
7881
- if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
7882
- add(renderBounds, childrenRenderBounds);
7904
+ !this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow);
7883
7905
  }
7884
7906
  __updateRectRenderBounds() { }
7885
7907
  __updateRectChange() { }
@@ -7899,20 +7921,9 @@ let Box = class Box extends Group {
7899
7921
  this.__renderGroup(canvas, options);
7900
7922
  }
7901
7923
  }
7902
- __drawAfterFill(canvas, options) {
7903
- const { length } = this.children;
7904
- if (this.isOverflow) {
7905
- canvas.save();
7906
- canvas.clip();
7907
- if (length)
7908
- this.__renderGroup(canvas, options);
7909
- canvas.restore();
7910
- }
7911
- else {
7912
- if (length)
7913
- this.__renderGroup(canvas, options);
7914
- }
7915
- if (this.__.stroke && length) {
7924
+ __drawContent(canvas, options) {
7925
+ this.__renderGroup(canvas, options);
7926
+ if (this.__.__hasStroke) {
7916
7927
  canvas.setWorld(this.__nowWorld);
7917
7928
  this.__drawRenderPath(canvas);
7918
7929
  }
@@ -8076,17 +8087,15 @@ let Line = class Line extends UI {
8076
8087
  if (data.__useArrow)
8077
8088
  PathArrow.addArrows(this, false);
8078
8089
  }
8079
- else {
8090
+ else
8080
8091
  super.__updateRenderPath();
8081
- }
8082
8092
  }
8083
8093
  __updateBoxBounds() {
8084
8094
  if (this.points) {
8085
8095
  toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
8086
8096
  }
8087
- else {
8097
+ else
8088
8098
  super.__updateBoxBounds();
8089
- }
8090
8099
  }
8091
8100
  };
8092
8101
  __decorate([
@@ -8224,7 +8233,6 @@ let Canvas = class Canvas extends Rect {
8224
8233
  super(data);
8225
8234
  this.canvas = Creator.canvas(this.__);
8226
8235
  this.context = this.canvas.context;
8227
- this.__.__isCanvas = this.__.__drawAfterFill = true;
8228
8236
  if (data && data.url)
8229
8237
  this.drawImage(data.url);
8230
8238
  }
@@ -8237,8 +8245,7 @@ let Canvas = class Canvas extends Rect {
8237
8245
  });
8238
8246
  }
8239
8247
  draw(ui, offset, scale, rotation) {
8240
- ui.__layout.update();
8241
- const matrix = new Matrix(ui.__world).invert();
8248
+ const matrix = new Matrix(ui.worldTransform).invert();
8242
8249
  const m = new Matrix();
8243
8250
  if (offset)
8244
8251
  m.translate(offset.x, offset.y);
@@ -8253,17 +8260,9 @@ let Canvas = class Canvas extends Rect {
8253
8260
  paint() {
8254
8261
  this.forceRender();
8255
8262
  }
8256
- __drawAfterFill(canvas, _options) {
8257
- const { width, height, cornerRadius } = this.__, { view } = this.canvas;
8258
- if (cornerRadius || this.pathInputed) {
8259
- canvas.save();
8260
- canvas.clip();
8261
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8262
- canvas.restore();
8263
- }
8264
- else {
8265
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8266
- }
8263
+ __drawContent(canvas, _options) {
8264
+ const { width, height } = this.__, { view } = this.canvas;
8265
+ canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8267
8266
  }
8268
8267
  __updateSize() {
8269
8268
  const { canvas } = this;
@@ -8307,7 +8306,6 @@ Canvas = __decorate([
8307
8306
  const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8308
8307
  let Text = class Text extends UI {
8309
8308
  get __tag() { return 'Text'; }
8310
- get editInner() { return 'TextEditor'; }
8311
8309
  get textDrawData() {
8312
8310
  this.__layout.update();
8313
8311
  return this.__.__textDrawData;
@@ -8473,7 +8471,6 @@ let Path = class Path extends UI {
8473
8471
  get __tag() { return 'Path'; }
8474
8472
  constructor(data) {
8475
8473
  super(data);
8476
- this.__.__pathInputed = 2;
8477
8474
  }
8478
8475
  };
8479
8476
  __decorate([
@@ -9151,7 +9148,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
9151
9148
  }
9152
9149
  if (allowPaint) {
9153
9150
  canvas.save();
9154
- canvas.clip();
9151
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9155
9152
  if (paint.blendMode)
9156
9153
  canvas.blendMode = paint.blendMode;
9157
9154
  if (data.opacity)