@leafer-draw/worker 1.0.5 → 1.0.7

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]);
@@ -4395,13 +4426,10 @@ class LeafLayout {
4395
4426
  update() {
4396
4427
  const { leafer } = this.leaf;
4397
4428
  if (leafer) {
4398
- if (leafer.ready) {
4399
- if (leafer.watcher.changed)
4400
- leafer.layouter.layout();
4401
- }
4402
- else {
4429
+ if (leafer.ready)
4430
+ leafer.watcher.changed && leafer.layouter.layout();
4431
+ else
4403
4432
  leafer.start();
4404
- }
4405
4433
  }
4406
4434
  else {
4407
4435
  let root = this.leaf;
@@ -5159,7 +5187,7 @@ const LeafRender = {
5159
5187
  if (this.__worldOpacity) {
5160
5188
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5161
5189
  this.__drawRenderPath(canvas);
5162
- this.__.windingRule ? canvas.clip(this.__.windingRule) : canvas.clip();
5190
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
5163
5191
  }
5164
5192
  },
5165
5193
  __updateWorldOpacity() {
@@ -5676,11 +5704,17 @@ let Branch = class Branch extends Leaf {
5676
5704
  add(child, index) {
5677
5705
  if (child === this)
5678
5706
  return;
5679
- child.__ || (child = UICreator.get(child.tag, child));
5707
+ const noIndex = index === undefined;
5708
+ if (!child.__) {
5709
+ if (child instanceof Array)
5710
+ return child.forEach(item => { this.add(item, index); noIndex || index++; });
5711
+ else
5712
+ child = UICreator.get(child.tag, child);
5713
+ }
5680
5714
  if (child.parent)
5681
5715
  child.parent.remove(child);
5682
5716
  child.parent = this;
5683
- index === undefined ? this.children.push(child) : this.children.splice(index, 0, child);
5717
+ noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
5684
5718
  if (child.isBranch)
5685
5719
  this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
5686
5720
  child.__layout.boxChanged || child.__layout.boxChange();
@@ -5694,9 +5728,7 @@ let Branch = class Branch extends Leaf {
5694
5728
  }
5695
5729
  this.__layout.affectChildrenSort && this.__layout.childrenSortChange();
5696
5730
  }
5697
- addMany(...children) {
5698
- children.forEach(child => this.add(child));
5699
- }
5731
+ addMany(...children) { this.add(children); }
5700
5732
  remove(child, destroy) {
5701
5733
  if (child) {
5702
5734
  if (child.__) {
@@ -5924,7 +5956,7 @@ class LeafLevelList {
5924
5956
  }
5925
5957
  }
5926
5958
 
5927
- const version = "1.0.5";
5959
+ const version = "1.0.7";
5928
5960
 
5929
5961
  class LeaferCanvas extends LeaferCanvasBase {
5930
5962
  get allowBackgroundColor() { return true; }
@@ -6633,6 +6665,13 @@ function zoomLayerType() {
6633
6665
 
6634
6666
  const TextConvert = {};
6635
6667
  const ColorConvert = {};
6668
+ const UnitConvert = {
6669
+ number(value, percentRefer) {
6670
+ if (typeof value === 'object')
6671
+ return value.type === 'percent' ? value.value * percentRefer : value.value;
6672
+ return value;
6673
+ }
6674
+ };
6636
6675
  const PathArrow = {};
6637
6676
  const Paint = {};
6638
6677
  const PaintImage = {};
@@ -6653,7 +6692,7 @@ const Transition = {
6653
6692
  }
6654
6693
  };
6655
6694
 
6656
- const { parse } = PathConvert;
6695
+ const { parse, objectToCanvasData } = PathConvert;
6657
6696
  const emptyPaint = {};
6658
6697
  const debug$2 = Debug.get('UIData');
6659
6698
  class UIData extends LeafData {
@@ -6667,10 +6706,11 @@ class UIData extends LeafData {
6667
6706
  scaleX = -scaleX;
6668
6707
  return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
6669
6708
  }
6670
- else {
6709
+ else
6671
6710
  return strokeWidth;
6672
- }
6673
6711
  }
6712
+ get __hasStroke() { return this.stroke && this.strokeWidth; }
6713
+ get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6674
6714
  get __autoWidth() { return !this._width; }
6675
6715
  get __autoHeight() { return !this._height; }
6676
6716
  get __autoSide() { return !this._width || !this._height; }
@@ -6687,9 +6727,8 @@ class UIData extends LeafData {
6687
6727
  this.__leaf.scaleX *= -1;
6688
6728
  debug$2.warn('width < 0, instead -scaleX ', this);
6689
6729
  }
6690
- else {
6730
+ else
6691
6731
  this._width = value;
6692
- }
6693
6732
  }
6694
6733
  setHeight(value) {
6695
6734
  if (value < 0) {
@@ -6697,9 +6736,8 @@ class UIData extends LeafData {
6697
6736
  this.__leaf.scaleY *= -1;
6698
6737
  debug$2.warn('height < 0, instead -scaleY', this);
6699
6738
  }
6700
- else {
6739
+ else
6701
6740
  this._height = value;
6702
- }
6703
6741
  }
6704
6742
  setFill(value) {
6705
6743
  if (this.__naturalWidth)
@@ -6740,9 +6778,10 @@ class UIData extends LeafData {
6740
6778
  }
6741
6779
  }
6742
6780
  setPath(value) {
6743
- if (typeof value === 'string') {
6781
+ const isString = typeof value === 'string';
6782
+ if (isString || (value && typeof value[0] === 'object')) {
6744
6783
  this.__setInput('path', value);
6745
- this._path = parse(value);
6784
+ this._path = isString ? parse(value) : objectToCanvasData(value);
6746
6785
  }
6747
6786
  else {
6748
6787
  if (this.__input)
@@ -6757,12 +6796,8 @@ class UIData extends LeafData {
6757
6796
  value = value.filter((item) => item.visible !== false);
6758
6797
  this._shadow = value.length ? value : null;
6759
6798
  }
6760
- else if (value) {
6761
- this._shadow = value.visible === false ? null : [value];
6762
- }
6763
- else {
6764
- this._shadow = null;
6765
- }
6799
+ else
6800
+ this._shadow = value && value.visible !== false ? [value] : null;
6766
6801
  }
6767
6802
  setInnerShadow(value) {
6768
6803
  this.__setInput('innerShadow', value);
@@ -6771,12 +6806,8 @@ class UIData extends LeafData {
6771
6806
  value = value.filter((item) => item.visible !== false);
6772
6807
  this._innerShadow = value.length ? value : null;
6773
6808
  }
6774
- else if (value) {
6775
- this._innerShadow = value.visible === false ? null : [value];
6776
- }
6777
- else {
6778
- this._innerShadow = null;
6779
- }
6809
+ else
6810
+ this._innerShadow = value && value.visible !== false ? [value] : null;
6780
6811
  }
6781
6812
  __computePaint() {
6782
6813
  const { fill, stroke } = this.__input;
@@ -6787,24 +6818,19 @@ class UIData extends LeafData {
6787
6818
  this.__needComputePaint = false;
6788
6819
  }
6789
6820
  }
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
6821
 
6798
6822
  class GroupData extends UIData {
6799
6823
  }
6800
6824
 
6801
6825
  class BoxData extends GroupData {
6802
6826
  get __boxStroke() { return !this.__pathInputed; }
6827
+ get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
6828
+ get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
6803
6829
  }
6804
6830
 
6805
6831
  class LeaferData extends GroupData {
6806
- __getInputData() {
6807
- const data = super.__getInputData();
6832
+ __getInputData(names, options) {
6833
+ const data = super.__getInputData(names, options);
6808
6834
  canvasSizeAttrs.forEach(key => delete data[key]);
6809
6835
  return data;
6810
6836
  }
@@ -6831,6 +6857,7 @@ class StarData extends UIData {
6831
6857
  }
6832
6858
 
6833
6859
  class PathData extends UIData {
6860
+ get __pathInputed() { return 2; }
6834
6861
  }
6835
6862
 
6836
6863
  class PenData extends GroupData {
@@ -6877,16 +6904,18 @@ class ImageData extends RectData {
6877
6904
  delete data.fill;
6878
6905
  return data;
6879
6906
  }
6880
- __getInputData() {
6881
- const data = super.__getInputData();
6907
+ __getInputData(names, options) {
6908
+ const data = super.__getInputData(names, options);
6882
6909
  delete data.fill;
6883
6910
  return data;
6884
6911
  }
6885
6912
  }
6886
6913
 
6887
6914
  class CanvasData extends RectData {
6888
- __getInputData() {
6889
- const data = super.__getInputData();
6915
+ get __isCanvas() { return true; }
6916
+ get __drawAfterFill() { return true; }
6917
+ __getInputData(names, options) {
6918
+ const data = super.__getInputData(names, options);
6890
6919
  data.url = this.__leaf.canvas.toDataURL('image/png');
6891
6920
  return data;
6892
6921
  }
@@ -6913,16 +6942,12 @@ const UIBounds = {
6913
6942
  let width = 0;
6914
6943
  const { shadow, innerShadow, blur, backgroundBlur } = this.__;
6915
6944
  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
- });
6945
+ 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
6946
  if (blur)
6920
6947
  width = Math.max(width, blur);
6921
6948
  let shapeWidth = width = Math.ceil(width);
6922
6949
  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
- });
6950
+ 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
6951
  if (backgroundBlur)
6927
6952
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
6928
6953
  this.__layout.renderShapeSpread = shapeWidth;
@@ -7004,6 +7029,16 @@ const UIRender = {
7004
7029
  if (stroke && !ignoreStroke)
7005
7030
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7006
7031
  }
7032
+ },
7033
+ __drawAfterFill(canvas, options) {
7034
+ if (this.__.__clipAfterFill) {
7035
+ canvas.save();
7036
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
7037
+ this.__drawContent(canvas, options);
7038
+ canvas.restore();
7039
+ }
7040
+ else
7041
+ this.__drawContent(canvas, options);
7007
7042
  }
7008
7043
  };
7009
7044
  function drawFast(ui, canvas, options) {
@@ -7070,8 +7105,8 @@ let UI = UI_1 = class UI extends Leaf {
7070
7105
  return pen;
7071
7106
  }
7072
7107
  get editConfig() { return undefined; }
7073
- get editOuter() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
7074
- get editInner() { return 'PathEditor'; }
7108
+ get editOuter() { return ''; }
7109
+ get editInner() { return ''; }
7075
7110
  constructor(data) {
7076
7111
  super(data);
7077
7112
  }
@@ -7082,9 +7117,8 @@ let UI = UI_1 = class UI extends Leaf {
7082
7117
  Object.assign(this, data);
7083
7118
  this.lockNormalStyle = false;
7084
7119
  }
7085
- else {
7120
+ else
7086
7121
  Object.assign(this, data);
7087
- }
7088
7122
  }
7089
7123
  get(name) {
7090
7124
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
@@ -7386,23 +7420,13 @@ let Group = class Group extends UI {
7386
7420
  if (data.children) {
7387
7421
  const { children } = data;
7388
7422
  delete data.children;
7389
- if (!this.children) {
7390
- this.__setBranch();
7391
- }
7392
- else {
7393
- this.clear();
7394
- }
7423
+ this.children ? this.clear() : this.__setBranch();
7395
7424
  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
- });
7425
+ children.forEach(child => this.add(child));
7401
7426
  data.children = children;
7402
7427
  }
7403
- else {
7428
+ else
7404
7429
  super.set(data, isTemp);
7405
- }
7406
7430
  }
7407
7431
  toJSON(options) {
7408
7432
  const data = super.toJSON(options);
@@ -7834,9 +7858,7 @@ let Box = class Box extends Group {
7834
7858
  }
7835
7859
  __updateStrokeSpread() { return 0; }
7836
7860
  __updateRectRenderSpread() { return 0; }
7837
- __updateRenderSpread() {
7838
- return this.__updateRectRenderSpread() || -1;
7839
- }
7861
+ __updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
7840
7862
  __updateRectBoxBounds() { }
7841
7863
  __updateBoxBounds(_secondLayout) {
7842
7864
  const data = this.__;
@@ -7856,13 +7878,11 @@ let Box = class Box extends Group {
7856
7878
  }
7857
7879
  this.__updateNaturalSize();
7858
7880
  }
7859
- else {
7881
+ else
7860
7882
  this.__updateRectBoxBounds();
7861
- }
7862
7883
  }
7863
- else {
7884
+ else
7864
7885
  this.__updateRectBoxBounds();
7865
- }
7866
7886
  }
7867
7887
  __updateStrokeBounds() { }
7868
7888
  __updateRenderBounds() {
@@ -7872,14 +7892,13 @@ let Box = class Box extends Group {
7872
7892
  super.__updateRenderBounds();
7873
7893
  copy$2(childrenRenderBounds, renderBounds);
7874
7894
  this.__updateRectRenderBounds();
7875
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
7895
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds);
7896
+ if (isOverflow && this.__.overflow !== 'hide')
7897
+ add(renderBounds, childrenRenderBounds);
7876
7898
  }
7877
- else {
7899
+ else
7878
7900
  this.__updateRectRenderBounds();
7879
- }
7880
- this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
7881
- if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
7882
- add(renderBounds, childrenRenderBounds);
7901
+ !this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow);
7883
7902
  }
7884
7903
  __updateRectRenderBounds() { }
7885
7904
  __updateRectChange() { }
@@ -7899,20 +7918,9 @@ let Box = class Box extends Group {
7899
7918
  this.__renderGroup(canvas, options);
7900
7919
  }
7901
7920
  }
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) {
7921
+ __drawContent(canvas, options) {
7922
+ this.__renderGroup(canvas, options);
7923
+ if (this.__.__hasStroke) {
7916
7924
  canvas.setWorld(this.__nowWorld);
7917
7925
  this.__drawRenderPath(canvas);
7918
7926
  }
@@ -8076,17 +8084,15 @@ let Line = class Line extends UI {
8076
8084
  if (data.__useArrow)
8077
8085
  PathArrow.addArrows(this, false);
8078
8086
  }
8079
- else {
8087
+ else
8080
8088
  super.__updateRenderPath();
8081
- }
8082
8089
  }
8083
8090
  __updateBoxBounds() {
8084
8091
  if (this.points) {
8085
8092
  toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
8086
8093
  }
8087
- else {
8094
+ else
8088
8095
  super.__updateBoxBounds();
8089
- }
8090
8096
  }
8091
8097
  };
8092
8098
  __decorate([
@@ -8224,7 +8230,6 @@ let Canvas = class Canvas extends Rect {
8224
8230
  super(data);
8225
8231
  this.canvas = Creator.canvas(this.__);
8226
8232
  this.context = this.canvas.context;
8227
- this.__.__isCanvas = this.__.__drawAfterFill = true;
8228
8233
  if (data && data.url)
8229
8234
  this.drawImage(data.url);
8230
8235
  }
@@ -8237,8 +8242,7 @@ let Canvas = class Canvas extends Rect {
8237
8242
  });
8238
8243
  }
8239
8244
  draw(ui, offset, scale, rotation) {
8240
- ui.__layout.update();
8241
- const matrix = new Matrix(ui.__world).invert();
8245
+ const matrix = new Matrix(ui.worldTransform).invert();
8242
8246
  const m = new Matrix();
8243
8247
  if (offset)
8244
8248
  m.translate(offset.x, offset.y);
@@ -8253,17 +8257,9 @@ let Canvas = class Canvas extends Rect {
8253
8257
  paint() {
8254
8258
  this.forceRender();
8255
8259
  }
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
- }
8260
+ __drawContent(canvas, _options) {
8261
+ const { width, height } = this.__, { view } = this.canvas;
8262
+ canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8267
8263
  }
8268
8264
  __updateSize() {
8269
8265
  const { canvas } = this;
@@ -8307,7 +8303,6 @@ Canvas = __decorate([
8307
8303
  const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8308
8304
  let Text = class Text extends UI {
8309
8305
  get __tag() { return 'Text'; }
8310
- get editInner() { return 'TextEditor'; }
8311
8306
  get textDrawData() {
8312
8307
  this.__layout.update();
8313
8308
  return this.__.__textDrawData;
@@ -8382,9 +8377,8 @@ let Text = class Text extends UI {
8382
8377
  layout.renderChanged = true;
8383
8378
  setList(data.__textBoxBounds = {}, [b, bounds]);
8384
8379
  }
8385
- else {
8380
+ else
8386
8381
  data.__textBoxBounds = contentBounds;
8387
- }
8388
8382
  }
8389
8383
  __updateRenderSpread() {
8390
8384
  let width = super.__updateRenderSpread();
@@ -8473,7 +8467,6 @@ let Path = class Path extends UI {
8473
8467
  get __tag() { return 'Path'; }
8474
8468
  constructor(data) {
8475
8469
  super(data);
8476
- this.__.__pathInputed = 2;
8477
8470
  }
8478
8471
  };
8479
8472
  __decorate([
@@ -9151,7 +9144,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
9151
9144
  }
9152
9145
  if (allowPaint) {
9153
9146
  canvas.save();
9154
- canvas.clip();
9147
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9155
9148
  if (paint.blendMode)
9156
9149
  canvas.blendMode = paint.blendMode;
9157
9150
  if (data.opacity)