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