leafer-draw 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/web.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
  const debug$5 = Debug.get('LeaferCanvas');
5933
5968
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6085,7 +6120,7 @@ var LeaferUI = (function (exports) {
6085
6120
  const oldSize = {};
6086
6121
  DataHelper.copyAttrs(oldSize, this, canvasSizeAttrs);
6087
6122
  this.resize(size);
6088
- if (this.width !== undefined)
6123
+ if (this.resizeListener && this.width !== undefined)
6089
6124
  this.resizeListener(new ResizeEvent(size, oldSize));
6090
6125
  }
6091
6126
  unrealCanvas() {
@@ -6809,6 +6844,13 @@ var LeaferUI = (function (exports) {
6809
6844
 
6810
6845
  const TextConvert = {};
6811
6846
  const ColorConvert = {};
6847
+ const UnitConvert = {
6848
+ number(value, percentRefer) {
6849
+ if (typeof value === 'object')
6850
+ return value.type === 'percent' ? value.value * percentRefer : value.value;
6851
+ return value;
6852
+ }
6853
+ };
6812
6854
  const PathArrow = {};
6813
6855
  const Paint = {};
6814
6856
  const PaintImage = {};
@@ -6829,7 +6871,7 @@ var LeaferUI = (function (exports) {
6829
6871
  }
6830
6872
  };
6831
6873
 
6832
- const { parse } = PathConvert;
6874
+ const { parse, objectToCanvasData } = PathConvert;
6833
6875
  const emptyPaint = {};
6834
6876
  const debug$2 = Debug.get('UIData');
6835
6877
  class UIData extends LeafData {
@@ -6843,10 +6885,11 @@ var LeaferUI = (function (exports) {
6843
6885
  scaleX = -scaleX;
6844
6886
  return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
6845
6887
  }
6846
- else {
6888
+ else
6847
6889
  return strokeWidth;
6848
- }
6849
6890
  }
6891
+ get __hasStroke() { return this.stroke && this.strokeWidth; }
6892
+ get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6850
6893
  get __autoWidth() { return !this._width; }
6851
6894
  get __autoHeight() { return !this._height; }
6852
6895
  get __autoSide() { return !this._width || !this._height; }
@@ -6863,9 +6906,8 @@ var LeaferUI = (function (exports) {
6863
6906
  this.__leaf.scaleX *= -1;
6864
6907
  debug$2.warn('width < 0, instead -scaleX ', this);
6865
6908
  }
6866
- else {
6909
+ else
6867
6910
  this._width = value;
6868
- }
6869
6911
  }
6870
6912
  setHeight(value) {
6871
6913
  if (value < 0) {
@@ -6873,9 +6915,8 @@ var LeaferUI = (function (exports) {
6873
6915
  this.__leaf.scaleY *= -1;
6874
6916
  debug$2.warn('height < 0, instead -scaleY', this);
6875
6917
  }
6876
- else {
6918
+ else
6877
6919
  this._height = value;
6878
- }
6879
6920
  }
6880
6921
  setFill(value) {
6881
6922
  if (this.__naturalWidth)
@@ -6916,9 +6957,10 @@ var LeaferUI = (function (exports) {
6916
6957
  }
6917
6958
  }
6918
6959
  setPath(value) {
6919
- if (typeof value === 'string') {
6960
+ const isString = typeof value === 'string';
6961
+ if (isString || (value && typeof value[0] === 'object')) {
6920
6962
  this.__setInput('path', value);
6921
- this._path = parse(value);
6963
+ this._path = isString ? parse(value) : objectToCanvasData(value);
6922
6964
  }
6923
6965
  else {
6924
6966
  if (this.__input)
@@ -6933,12 +6975,8 @@ var LeaferUI = (function (exports) {
6933
6975
  value = value.filter((item) => item.visible !== false);
6934
6976
  this._shadow = value.length ? value : null;
6935
6977
  }
6936
- else if (value) {
6937
- this._shadow = value.visible === false ? null : [value];
6938
- }
6939
- else {
6940
- this._shadow = null;
6941
- }
6978
+ else
6979
+ this._shadow = value && value.visible !== false ? [value] : null;
6942
6980
  }
6943
6981
  setInnerShadow(value) {
6944
6982
  this.__setInput('innerShadow', value);
@@ -6947,12 +6985,8 @@ var LeaferUI = (function (exports) {
6947
6985
  value = value.filter((item) => item.visible !== false);
6948
6986
  this._innerShadow = value.length ? value : null;
6949
6987
  }
6950
- else if (value) {
6951
- this._innerShadow = value.visible === false ? null : [value];
6952
- }
6953
- else {
6954
- this._innerShadow = null;
6955
- }
6988
+ else
6989
+ this._innerShadow = value && value.visible !== false ? [value] : null;
6956
6990
  }
6957
6991
  __computePaint() {
6958
6992
  const { fill, stroke } = this.__input;
@@ -6963,24 +6997,19 @@ var LeaferUI = (function (exports) {
6963
6997
  this.__needComputePaint = false;
6964
6998
  }
6965
6999
  }
6966
- const UnitConvert = {
6967
- number(value, percentRefer) {
6968
- if (typeof value === 'object')
6969
- return value.type === 'percent' ? value.value * percentRefer : value.value;
6970
- return value;
6971
- }
6972
- };
6973
7000
 
6974
7001
  class GroupData extends UIData {
6975
7002
  }
6976
7003
 
6977
7004
  class BoxData extends GroupData {
6978
7005
  get __boxStroke() { return !this.__pathInputed; }
7006
+ get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
7007
+ get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
6979
7008
  }
6980
7009
 
6981
7010
  class LeaferData extends GroupData {
6982
- __getInputData() {
6983
- const data = super.__getInputData();
7011
+ __getInputData(names, options) {
7012
+ const data = super.__getInputData(names, options);
6984
7013
  canvasSizeAttrs.forEach(key => delete data[key]);
6985
7014
  return data;
6986
7015
  }
@@ -7007,6 +7036,7 @@ var LeaferUI = (function (exports) {
7007
7036
  }
7008
7037
 
7009
7038
  class PathData extends UIData {
7039
+ get __pathInputed() { return 2; }
7010
7040
  }
7011
7041
 
7012
7042
  class PenData extends GroupData {
@@ -7053,16 +7083,18 @@ var LeaferUI = (function (exports) {
7053
7083
  delete data.fill;
7054
7084
  return data;
7055
7085
  }
7056
- __getInputData() {
7057
- const data = super.__getInputData();
7086
+ __getInputData(names, options) {
7087
+ const data = super.__getInputData(names, options);
7058
7088
  delete data.fill;
7059
7089
  return data;
7060
7090
  }
7061
7091
  }
7062
7092
 
7063
7093
  class CanvasData extends RectData {
7064
- __getInputData() {
7065
- const data = super.__getInputData();
7094
+ get __isCanvas() { return true; }
7095
+ get __drawAfterFill() { return true; }
7096
+ __getInputData(names, options) {
7097
+ const data = super.__getInputData(names, options);
7066
7098
  data.url = this.__leaf.canvas.toDataURL('image/png');
7067
7099
  return data;
7068
7100
  }
@@ -7089,16 +7121,12 @@ var LeaferUI = (function (exports) {
7089
7121
  let width = 0;
7090
7122
  const { shadow, innerShadow, blur, backgroundBlur } = this.__;
7091
7123
  if (shadow)
7092
- shadow.forEach(item => {
7093
- width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5);
7094
- });
7124
+ 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));
7095
7125
  if (blur)
7096
7126
  width = Math.max(width, blur);
7097
7127
  let shapeWidth = width = Math.ceil(width);
7098
7128
  if (innerShadow)
7099
- innerShadow.forEach(item => {
7100
- shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5);
7101
- });
7129
+ 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));
7102
7130
  if (backgroundBlur)
7103
7131
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
7104
7132
  this.__layout.renderShapeSpread = shapeWidth;
@@ -7180,6 +7208,16 @@ var LeaferUI = (function (exports) {
7180
7208
  if (stroke && !ignoreStroke)
7181
7209
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7182
7210
  }
7211
+ },
7212
+ __drawAfterFill(canvas, options) {
7213
+ if (this.__.__clipAfterFill) {
7214
+ canvas.save();
7215
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
7216
+ this.__drawContent(canvas, options);
7217
+ canvas.restore();
7218
+ }
7219
+ else
7220
+ this.__drawContent(canvas, options);
7183
7221
  }
7184
7222
  };
7185
7223
  function drawFast(ui, canvas, options) {
@@ -7246,8 +7284,8 @@ var LeaferUI = (function (exports) {
7246
7284
  return pen;
7247
7285
  }
7248
7286
  get editConfig() { return undefined; }
7249
- get editOuter() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
7250
- get editInner() { return 'PathEditor'; }
7287
+ get editOuter() { return ''; }
7288
+ get editInner() { return ''; }
7251
7289
  constructor(data) {
7252
7290
  super(data);
7253
7291
  }
@@ -7258,9 +7296,8 @@ var LeaferUI = (function (exports) {
7258
7296
  Object.assign(this, data);
7259
7297
  this.lockNormalStyle = false;
7260
7298
  }
7261
- else {
7299
+ else
7262
7300
  Object.assign(this, data);
7263
- }
7264
7301
  }
7265
7302
  get(name) {
7266
7303
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
@@ -7562,23 +7599,13 @@ var LeaferUI = (function (exports) {
7562
7599
  if (data.children) {
7563
7600
  const { children } = data;
7564
7601
  delete data.children;
7565
- if (!this.children) {
7566
- this.__setBranch();
7567
- }
7568
- else {
7569
- this.clear();
7570
- }
7602
+ this.children ? this.clear() : this.__setBranch();
7571
7603
  super.set(data, isTemp);
7572
- let child;
7573
- children.forEach(childData => {
7574
- child = childData.__ ? childData : UICreator.get(childData.tag, childData);
7575
- this.add(child);
7576
- });
7604
+ children.forEach(child => this.add(child));
7577
7605
  data.children = children;
7578
7606
  }
7579
- else {
7607
+ else
7580
7608
  super.set(data, isTemp);
7581
- }
7582
7609
  }
7583
7610
  toJSON(options) {
7584
7611
  const data = super.toJSON(options);
@@ -8010,9 +8037,7 @@ var LeaferUI = (function (exports) {
8010
8037
  }
8011
8038
  __updateStrokeSpread() { return 0; }
8012
8039
  __updateRectRenderSpread() { return 0; }
8013
- __updateRenderSpread() {
8014
- return this.__updateRectRenderSpread() || -1;
8015
- }
8040
+ __updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
8016
8041
  __updateRectBoxBounds() { }
8017
8042
  __updateBoxBounds(_secondLayout) {
8018
8043
  const data = this.__;
@@ -8032,13 +8057,11 @@ var LeaferUI = (function (exports) {
8032
8057
  }
8033
8058
  this.__updateNaturalSize();
8034
8059
  }
8035
- else {
8060
+ else
8036
8061
  this.__updateRectBoxBounds();
8037
- }
8038
8062
  }
8039
- else {
8063
+ else
8040
8064
  this.__updateRectBoxBounds();
8041
- }
8042
8065
  }
8043
8066
  __updateStrokeBounds() { }
8044
8067
  __updateRenderBounds() {
@@ -8048,14 +8071,13 @@ var LeaferUI = (function (exports) {
8048
8071
  super.__updateRenderBounds();
8049
8072
  copy$2(childrenRenderBounds, renderBounds);
8050
8073
  this.__updateRectRenderBounds();
8051
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
8074
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds);
8075
+ if (isOverflow && this.__.overflow !== 'hide')
8076
+ add(renderBounds, childrenRenderBounds);
8052
8077
  }
8053
- else {
8078
+ else
8054
8079
  this.__updateRectRenderBounds();
8055
- }
8056
- this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8057
- if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
8058
- add(renderBounds, childrenRenderBounds);
8080
+ !this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow);
8059
8081
  }
8060
8082
  __updateRectRenderBounds() { }
8061
8083
  __updateRectChange() { }
@@ -8075,20 +8097,9 @@ var LeaferUI = (function (exports) {
8075
8097
  this.__renderGroup(canvas, options);
8076
8098
  }
8077
8099
  }
8078
- __drawAfterFill(canvas, options) {
8079
- const { length } = this.children;
8080
- if (this.isOverflow) {
8081
- canvas.save();
8082
- canvas.clip();
8083
- if (length)
8084
- this.__renderGroup(canvas, options);
8085
- canvas.restore();
8086
- }
8087
- else {
8088
- if (length)
8089
- this.__renderGroup(canvas, options);
8090
- }
8091
- if (this.__.stroke && length) {
8100
+ __drawContent(canvas, options) {
8101
+ this.__renderGroup(canvas, options);
8102
+ if (this.__.__hasStroke) {
8092
8103
  canvas.setWorld(this.__nowWorld);
8093
8104
  this.__drawRenderPath(canvas);
8094
8105
  }
@@ -8252,17 +8263,15 @@ var LeaferUI = (function (exports) {
8252
8263
  if (data.__useArrow)
8253
8264
  PathArrow.addArrows(this, false);
8254
8265
  }
8255
- else {
8266
+ else
8256
8267
  super.__updateRenderPath();
8257
- }
8258
8268
  }
8259
8269
  __updateBoxBounds() {
8260
8270
  if (this.points) {
8261
8271
  toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
8262
8272
  }
8263
- else {
8273
+ else
8264
8274
  super.__updateBoxBounds();
8265
- }
8266
8275
  }
8267
8276
  };
8268
8277
  __decorate([
@@ -8400,7 +8409,6 @@ var LeaferUI = (function (exports) {
8400
8409
  super(data);
8401
8410
  this.canvas = Creator.canvas(this.__);
8402
8411
  this.context = this.canvas.context;
8403
- this.__.__isCanvas = this.__.__drawAfterFill = true;
8404
8412
  if (data && data.url)
8405
8413
  this.drawImage(data.url);
8406
8414
  }
@@ -8413,8 +8421,7 @@ var LeaferUI = (function (exports) {
8413
8421
  });
8414
8422
  }
8415
8423
  draw(ui, offset, scale, rotation) {
8416
- ui.__layout.update();
8417
- const matrix = new Matrix(ui.__world).invert();
8424
+ const matrix = new Matrix(ui.worldTransform).invert();
8418
8425
  const m = new Matrix();
8419
8426
  if (offset)
8420
8427
  m.translate(offset.x, offset.y);
@@ -8429,17 +8436,9 @@ var LeaferUI = (function (exports) {
8429
8436
  paint() {
8430
8437
  this.forceRender();
8431
8438
  }
8432
- __drawAfterFill(canvas, _options) {
8433
- const { width, height, cornerRadius } = this.__, { view } = this.canvas;
8434
- if (cornerRadius || this.pathInputed) {
8435
- canvas.save();
8436
- canvas.clip();
8437
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8438
- canvas.restore();
8439
- }
8440
- else {
8441
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8442
- }
8439
+ __drawContent(canvas, _options) {
8440
+ const { width, height } = this.__, { view } = this.canvas;
8441
+ canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8443
8442
  }
8444
8443
  __updateSize() {
8445
8444
  const { canvas } = this;
@@ -8483,7 +8482,6 @@ var LeaferUI = (function (exports) {
8483
8482
  const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8484
8483
  exports.Text = class Text extends exports.UI {
8485
8484
  get __tag() { return 'Text'; }
8486
- get editInner() { return 'TextEditor'; }
8487
8485
  get textDrawData() {
8488
8486
  this.__layout.update();
8489
8487
  return this.__.__textDrawData;
@@ -8649,7 +8647,6 @@ var LeaferUI = (function (exports) {
8649
8647
  get __tag() { return 'Path'; }
8650
8648
  constructor(data) {
8651
8649
  super(data);
8652
- this.__.__pathInputed = 2;
8653
8650
  }
8654
8651
  };
8655
8652
  __decorate([
@@ -9327,7 +9324,7 @@ var LeaferUI = (function (exports) {
9327
9324
  }
9328
9325
  if (allowPaint) {
9329
9326
  canvas.save();
9330
- canvas.clip();
9327
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9331
9328
  if (paint.blendMode)
9332
9329
  canvas.blendMode = paint.blendMode;
9333
9330
  if (data.opacity)