@leafer-draw/miniapp 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 false; }
@@ -6770,6 +6805,13 @@ function zoomLayerType() {
6770
6805
 
6771
6806
  const TextConvert = {};
6772
6807
  const ColorConvert = {};
6808
+ const UnitConvert = {
6809
+ number(value, percentRefer) {
6810
+ if (typeof value === 'object')
6811
+ return value.type === 'percent' ? value.value * percentRefer : value.value;
6812
+ return value;
6813
+ }
6814
+ };
6773
6815
  const PathArrow = {};
6774
6816
  const Paint = {};
6775
6817
  const PaintImage = {};
@@ -6790,7 +6832,7 @@ const Transition = {
6790
6832
  }
6791
6833
  };
6792
6834
 
6793
- const { parse } = PathConvert;
6835
+ const { parse, objectToCanvasData } = PathConvert;
6794
6836
  const emptyPaint = {};
6795
6837
  const debug$2 = Debug.get('UIData');
6796
6838
  class UIData extends LeafData {
@@ -6804,10 +6846,11 @@ class UIData extends LeafData {
6804
6846
  scaleX = -scaleX;
6805
6847
  return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
6806
6848
  }
6807
- else {
6849
+ else
6808
6850
  return strokeWidth;
6809
- }
6810
6851
  }
6852
+ get __hasStroke() { return this.stroke && this.strokeWidth; }
6853
+ get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6811
6854
  get __autoWidth() { return !this._width; }
6812
6855
  get __autoHeight() { return !this._height; }
6813
6856
  get __autoSide() { return !this._width || !this._height; }
@@ -6824,9 +6867,8 @@ class UIData extends LeafData {
6824
6867
  this.__leaf.scaleX *= -1;
6825
6868
  debug$2.warn('width < 0, instead -scaleX ', this);
6826
6869
  }
6827
- else {
6870
+ else
6828
6871
  this._width = value;
6829
- }
6830
6872
  }
6831
6873
  setHeight(value) {
6832
6874
  if (value < 0) {
@@ -6834,9 +6876,8 @@ class UIData extends LeafData {
6834
6876
  this.__leaf.scaleY *= -1;
6835
6877
  debug$2.warn('height < 0, instead -scaleY', this);
6836
6878
  }
6837
- else {
6879
+ else
6838
6880
  this._height = value;
6839
- }
6840
6881
  }
6841
6882
  setFill(value) {
6842
6883
  if (this.__naturalWidth)
@@ -6877,9 +6918,10 @@ class UIData extends LeafData {
6877
6918
  }
6878
6919
  }
6879
6920
  setPath(value) {
6880
- if (typeof value === 'string') {
6921
+ const isString = typeof value === 'string';
6922
+ if (isString || (value && typeof value[0] === 'object')) {
6881
6923
  this.__setInput('path', value);
6882
- this._path = parse(value);
6924
+ this._path = isString ? parse(value) : objectToCanvasData(value);
6883
6925
  }
6884
6926
  else {
6885
6927
  if (this.__input)
@@ -6894,12 +6936,8 @@ class UIData extends LeafData {
6894
6936
  value = value.filter((item) => item.visible !== false);
6895
6937
  this._shadow = value.length ? value : null;
6896
6938
  }
6897
- else if (value) {
6898
- this._shadow = value.visible === false ? null : [value];
6899
- }
6900
- else {
6901
- this._shadow = null;
6902
- }
6939
+ else
6940
+ this._shadow = value && value.visible !== false ? [value] : null;
6903
6941
  }
6904
6942
  setInnerShadow(value) {
6905
6943
  this.__setInput('innerShadow', value);
@@ -6908,12 +6946,8 @@ class UIData extends LeafData {
6908
6946
  value = value.filter((item) => item.visible !== false);
6909
6947
  this._innerShadow = value.length ? value : null;
6910
6948
  }
6911
- else if (value) {
6912
- this._innerShadow = value.visible === false ? null : [value];
6913
- }
6914
- else {
6915
- this._innerShadow = null;
6916
- }
6949
+ else
6950
+ this._innerShadow = value && value.visible !== false ? [value] : null;
6917
6951
  }
6918
6952
  __computePaint() {
6919
6953
  const { fill, stroke } = this.__input;
@@ -6924,24 +6958,19 @@ class UIData extends LeafData {
6924
6958
  this.__needComputePaint = false;
6925
6959
  }
6926
6960
  }
6927
- const UnitConvert = {
6928
- number(value, percentRefer) {
6929
- if (typeof value === 'object')
6930
- return value.type === 'percent' ? value.value * percentRefer : value.value;
6931
- return value;
6932
- }
6933
- };
6934
6961
 
6935
6962
  class GroupData extends UIData {
6936
6963
  }
6937
6964
 
6938
6965
  class BoxData extends GroupData {
6939
6966
  get __boxStroke() { return !this.__pathInputed; }
6967
+ get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
6968
+ get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
6940
6969
  }
6941
6970
 
6942
6971
  class LeaferData extends GroupData {
6943
- __getInputData() {
6944
- const data = super.__getInputData();
6972
+ __getInputData(names, options) {
6973
+ const data = super.__getInputData(names, options);
6945
6974
  canvasSizeAttrs.forEach(key => delete data[key]);
6946
6975
  return data;
6947
6976
  }
@@ -6968,6 +6997,7 @@ class StarData extends UIData {
6968
6997
  }
6969
6998
 
6970
6999
  class PathData extends UIData {
7000
+ get __pathInputed() { return 2; }
6971
7001
  }
6972
7002
 
6973
7003
  class PenData extends GroupData {
@@ -7014,16 +7044,18 @@ class ImageData extends RectData {
7014
7044
  delete data.fill;
7015
7045
  return data;
7016
7046
  }
7017
- __getInputData() {
7018
- const data = super.__getInputData();
7047
+ __getInputData(names, options) {
7048
+ const data = super.__getInputData(names, options);
7019
7049
  delete data.fill;
7020
7050
  return data;
7021
7051
  }
7022
7052
  }
7023
7053
 
7024
7054
  class CanvasData extends RectData {
7025
- __getInputData() {
7026
- const data = super.__getInputData();
7055
+ get __isCanvas() { return true; }
7056
+ get __drawAfterFill() { return true; }
7057
+ __getInputData(names, options) {
7058
+ const data = super.__getInputData(names, options);
7027
7059
  data.url = this.__leaf.canvas.toDataURL('image/png');
7028
7060
  return data;
7029
7061
  }
@@ -7050,16 +7082,12 @@ const UIBounds = {
7050
7082
  let width = 0;
7051
7083
  const { shadow, innerShadow, blur, backgroundBlur } = this.__;
7052
7084
  if (shadow)
7053
- shadow.forEach(item => {
7054
- width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5);
7055
- });
7085
+ 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));
7056
7086
  if (blur)
7057
7087
  width = Math.max(width, blur);
7058
7088
  let shapeWidth = width = Math.ceil(width);
7059
7089
  if (innerShadow)
7060
- innerShadow.forEach(item => {
7061
- shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5);
7062
- });
7090
+ 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));
7063
7091
  if (backgroundBlur)
7064
7092
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
7065
7093
  this.__layout.renderShapeSpread = shapeWidth;
@@ -7141,6 +7169,16 @@ const UIRender = {
7141
7169
  if (stroke && !ignoreStroke)
7142
7170
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7143
7171
  }
7172
+ },
7173
+ __drawAfterFill(canvas, options) {
7174
+ if (this.__.__clipAfterFill) {
7175
+ canvas.save();
7176
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
7177
+ this.__drawContent(canvas, options);
7178
+ canvas.restore();
7179
+ }
7180
+ else
7181
+ this.__drawContent(canvas, options);
7144
7182
  }
7145
7183
  };
7146
7184
  function drawFast(ui, canvas, options) {
@@ -7207,8 +7245,8 @@ let UI = UI_1 = class UI extends Leaf {
7207
7245
  return pen;
7208
7246
  }
7209
7247
  get editConfig() { return undefined; }
7210
- get editOuter() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
7211
- get editInner() { return 'PathEditor'; }
7248
+ get editOuter() { return ''; }
7249
+ get editInner() { return ''; }
7212
7250
  constructor(data) {
7213
7251
  super(data);
7214
7252
  }
@@ -7219,9 +7257,8 @@ let UI = UI_1 = class UI extends Leaf {
7219
7257
  Object.assign(this, data);
7220
7258
  this.lockNormalStyle = false;
7221
7259
  }
7222
- else {
7260
+ else
7223
7261
  Object.assign(this, data);
7224
- }
7225
7262
  }
7226
7263
  get(name) {
7227
7264
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
@@ -7523,23 +7560,13 @@ let Group = class Group extends UI {
7523
7560
  if (data.children) {
7524
7561
  const { children } = data;
7525
7562
  delete data.children;
7526
- if (!this.children) {
7527
- this.__setBranch();
7528
- }
7529
- else {
7530
- this.clear();
7531
- }
7563
+ this.children ? this.clear() : this.__setBranch();
7532
7564
  super.set(data, isTemp);
7533
- let child;
7534
- children.forEach(childData => {
7535
- child = childData.__ ? childData : UICreator.get(childData.tag, childData);
7536
- this.add(child);
7537
- });
7565
+ children.forEach(child => this.add(child));
7538
7566
  data.children = children;
7539
7567
  }
7540
- else {
7568
+ else
7541
7569
  super.set(data, isTemp);
7542
- }
7543
7570
  }
7544
7571
  toJSON(options) {
7545
7572
  const data = super.toJSON(options);
@@ -7971,9 +7998,7 @@ let Box = class Box extends Group {
7971
7998
  }
7972
7999
  __updateStrokeSpread() { return 0; }
7973
8000
  __updateRectRenderSpread() { return 0; }
7974
- __updateRenderSpread() {
7975
- return this.__updateRectRenderSpread() || -1;
7976
- }
8001
+ __updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
7977
8002
  __updateRectBoxBounds() { }
7978
8003
  __updateBoxBounds(_secondLayout) {
7979
8004
  const data = this.__;
@@ -7993,13 +8018,11 @@ let Box = class Box extends Group {
7993
8018
  }
7994
8019
  this.__updateNaturalSize();
7995
8020
  }
7996
- else {
8021
+ else
7997
8022
  this.__updateRectBoxBounds();
7998
- }
7999
8023
  }
8000
- else {
8024
+ else
8001
8025
  this.__updateRectBoxBounds();
8002
- }
8003
8026
  }
8004
8027
  __updateStrokeBounds() { }
8005
8028
  __updateRenderBounds() {
@@ -8009,14 +8032,13 @@ let Box = class Box extends Group {
8009
8032
  super.__updateRenderBounds();
8010
8033
  copy$2(childrenRenderBounds, renderBounds);
8011
8034
  this.__updateRectRenderBounds();
8012
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
8035
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds);
8036
+ if (isOverflow && this.__.overflow !== 'hide')
8037
+ add(renderBounds, childrenRenderBounds);
8013
8038
  }
8014
- else {
8039
+ else
8015
8040
  this.__updateRectRenderBounds();
8016
- }
8017
- this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8018
- if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
8019
- add(renderBounds, childrenRenderBounds);
8041
+ !this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow);
8020
8042
  }
8021
8043
  __updateRectRenderBounds() { }
8022
8044
  __updateRectChange() { }
@@ -8036,20 +8058,9 @@ let Box = class Box extends Group {
8036
8058
  this.__renderGroup(canvas, options);
8037
8059
  }
8038
8060
  }
8039
- __drawAfterFill(canvas, options) {
8040
- const { length } = this.children;
8041
- if (this.isOverflow) {
8042
- canvas.save();
8043
- canvas.clip();
8044
- if (length)
8045
- this.__renderGroup(canvas, options);
8046
- canvas.restore();
8047
- }
8048
- else {
8049
- if (length)
8050
- this.__renderGroup(canvas, options);
8051
- }
8052
- if (this.__.stroke && length) {
8061
+ __drawContent(canvas, options) {
8062
+ this.__renderGroup(canvas, options);
8063
+ if (this.__.__hasStroke) {
8053
8064
  canvas.setWorld(this.__nowWorld);
8054
8065
  this.__drawRenderPath(canvas);
8055
8066
  }
@@ -8213,17 +8224,15 @@ let Line = class Line extends UI {
8213
8224
  if (data.__useArrow)
8214
8225
  PathArrow.addArrows(this, false);
8215
8226
  }
8216
- else {
8227
+ else
8217
8228
  super.__updateRenderPath();
8218
- }
8219
8229
  }
8220
8230
  __updateBoxBounds() {
8221
8231
  if (this.points) {
8222
8232
  toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
8223
8233
  }
8224
- else {
8234
+ else
8225
8235
  super.__updateBoxBounds();
8226
- }
8227
8236
  }
8228
8237
  };
8229
8238
  __decorate([
@@ -8361,7 +8370,6 @@ let Canvas = class Canvas extends Rect {
8361
8370
  super(data);
8362
8371
  this.canvas = Creator.canvas(this.__);
8363
8372
  this.context = this.canvas.context;
8364
- this.__.__isCanvas = this.__.__drawAfterFill = true;
8365
8373
  if (data && data.url)
8366
8374
  this.drawImage(data.url);
8367
8375
  }
@@ -8374,8 +8382,7 @@ let Canvas = class Canvas extends Rect {
8374
8382
  });
8375
8383
  }
8376
8384
  draw(ui, offset, scale, rotation) {
8377
- ui.__layout.update();
8378
- const matrix = new Matrix(ui.__world).invert();
8385
+ const matrix = new Matrix(ui.worldTransform).invert();
8379
8386
  const m = new Matrix();
8380
8387
  if (offset)
8381
8388
  m.translate(offset.x, offset.y);
@@ -8390,17 +8397,9 @@ let Canvas = class Canvas extends Rect {
8390
8397
  paint() {
8391
8398
  this.forceRender();
8392
8399
  }
8393
- __drawAfterFill(canvas, _options) {
8394
- const { width, height, cornerRadius } = this.__, { view } = this.canvas;
8395
- if (cornerRadius || this.pathInputed) {
8396
- canvas.save();
8397
- canvas.clip();
8398
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8399
- canvas.restore();
8400
- }
8401
- else {
8402
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8403
- }
8400
+ __drawContent(canvas, _options) {
8401
+ const { width, height } = this.__, { view } = this.canvas;
8402
+ canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8404
8403
  }
8405
8404
  __updateSize() {
8406
8405
  const { canvas } = this;
@@ -8444,7 +8443,6 @@ Canvas = __decorate([
8444
8443
  const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8445
8444
  let Text = class Text extends UI {
8446
8445
  get __tag() { return 'Text'; }
8447
- get editInner() { return 'TextEditor'; }
8448
8446
  get textDrawData() {
8449
8447
  this.__layout.update();
8450
8448
  return this.__.__textDrawData;
@@ -8610,7 +8608,6 @@ let Path = class Path extends UI {
8610
8608
  get __tag() { return 'Path'; }
8611
8609
  constructor(data) {
8612
8610
  super(data);
8613
- this.__.__pathInputed = 2;
8614
8611
  }
8615
8612
  };
8616
8613
  __decorate([
@@ -9288,7 +9285,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
9288
9285
  }
9289
9286
  if (allowPaint) {
9290
9287
  canvas.save();
9291
- canvas.clip();
9288
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9292
9289
  if (paint.blendMode)
9293
9290
  canvas.blendMode = paint.blendMode;
9294
9291
  if (data.opacity)