@leafer-editor/worker 1.5.0 → 1.5.2

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/worker.js CHANGED
@@ -119,8 +119,9 @@ var LeaferUI = (function (exports) {
119
119
  if (!scaleData)
120
120
  scaleData = {};
121
121
  if (size) {
122
- scaleData.scaleX = (typeof size === 'number' ? size : size.width) / originSize.width;
123
- scaleData.scaleY = (typeof size === 'number' ? size : size.height) / originSize.height;
122
+ const scaleX = (typeof size === 'number' ? size : size.width || 0) / originSize.width, scaleY = (typeof size === 'number' ? size : size.height || 0) / originSize.height;
123
+ scaleData.scaleX = scaleX || scaleY || 1;
124
+ scaleData.scaleY = scaleY || scaleX || 1;
124
125
  }
125
126
  else if (scale)
126
127
  MathHelper.assignScale(scaleData, scale);
@@ -1693,6 +1694,9 @@ var LeaferUI = (function (exports) {
1693
1694
  function isNull(value) {
1694
1695
  return value === undefined || value === null;
1695
1696
  }
1697
+ function isEmptyData(value) {
1698
+ return JSON.stringify(value) === '{}';
1699
+ }
1696
1700
 
1697
1701
  /******************************************************************************
1698
1702
  Copyright (c) Microsoft Corporation.
@@ -2032,13 +2036,11 @@ var LeaferUI = (function (exports) {
2032
2036
  this.worldTransform = {};
2033
2037
  if (!config)
2034
2038
  config = minSize;
2035
- if (!config.pixelRatio)
2036
- config.pixelRatio = Platform.devicePixelRatio;
2037
2039
  this.manager = manager;
2038
2040
  this.innerId = IncrementId.create(IncrementId.CNAVAS);
2039
2041
  const { width, height, pixelRatio } = config;
2040
2042
  this.autoLayout = !width || !height;
2041
- this.size.pixelRatio = pixelRatio;
2043
+ this.size.pixelRatio = pixelRatio | Platform.devicePixelRatio;
2042
2044
  this.config = config;
2043
2045
  this.init();
2044
2046
  }
@@ -2235,7 +2237,7 @@ var LeaferUI = (function (exports) {
2235
2237
  tempBounds$1.ceil();
2236
2238
  }
2237
2239
  isSameSize(size) {
2238
- return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
2240
+ return this.width === size.width && this.height === size.height && (!size.pixelRatio || this.pixelRatio === size.pixelRatio);
2239
2241
  }
2240
2242
  getSameCanvas(useSameWorldTransform, useSameSmooth) {
2241
2243
  const canvas = this.manager ? this.manager.get(this.size) : Creator.canvas(Object.assign({}, this.size));
@@ -2350,7 +2352,7 @@ var LeaferUI = (function (exports) {
2350
2352
  const { sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil$1, abs: abs$5, PI: PI$2, sqrt: sqrt$1, pow } = Math;
2351
2353
  const { setPoint: setPoint$4, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2352
2354
  const { set, toNumberPoints: toNumberPoints$1 } = PointHelper;
2353
- const { M: M$8, L: L$9, C: C$8, Q: Q$7, Z: Z$7 } = PathCommandMap;
2355
+ const { M: M$8, L: L$9, C: C$7, Q: Q$7, Z: Z$7 } = PathCommandMap;
2354
2356
  const tempPoint$2 = {};
2355
2357
  const BezierHelper = {
2356
2358
  points(data, originPoints, curve, close) {
@@ -2385,7 +2387,7 @@ var LeaferUI = (function (exports) {
2385
2387
  data.push(Q$7, c1X, c1Y, bX, bY);
2386
2388
  }
2387
2389
  else {
2388
- data.push(C$8, c2X, c2Y, c1X, c1Y, bX, bY);
2390
+ data.push(C$7, c2X, c2Y, c1X, c1Y, bX, bY);
2389
2391
  }
2390
2392
  c2X = bX + cb * cX;
2391
2393
  c2Y = bY + cb * cY;
@@ -2490,7 +2492,7 @@ var LeaferUI = (function (exports) {
2490
2492
  x2 = cx + x + control * (rotationCos * radiusX * endSin + rotationSin * radiusY * endCos);
2491
2493
  y2 = cy + y + control * (rotationSin * radiusX * endSin - rotationCos * radiusY * endCos);
2492
2494
  if (data)
2493
- data.push(C$8, x1, y1, x2, y2, cx + x, cy + y);
2495
+ data.push(C$7, x1, y1, x2, y2, cx + x, cy + y);
2494
2496
  if (setPointBounds)
2495
2497
  toTwoPointBounds$1(cx + startX, cy + startY, x1, y1, x2, y2, cx + x, cy + y, setPointBounds, true);
2496
2498
  startX = x;
@@ -2504,7 +2506,7 @@ var LeaferUI = (function (exports) {
2504
2506
  set(setEndPoint, cx + x, cy + y);
2505
2507
  },
2506
2508
  quadraticCurveTo(data, fromX, fromY, x1, y1, toX, toY) {
2507
- data.push(C$8, (fromX + 2 * x1) / 3, (fromY + 2 * y1) / 3, (toX + 2 * x1) / 3, (toY + 2 * y1) / 3, toX, toY);
2509
+ data.push(C$7, (fromX + 2 * x1) / 3, (fromY + 2 * y1) / 3, (toX + 2 * x1) / 3, (toY + 2 * y1) / 3, toX, toY);
2508
2510
  },
2509
2511
  toTwoPointBoundsByQuadraticCurve(fromX, fromY, x1, y1, toX, toY, pointBounds, addMode) {
2510
2512
  toTwoPointBounds$1(fromX, fromY, (fromX + 2 * x1) / 3, (fromY + 2 * y1) / 3, (toX + 2 * x1) / 3, (toY + 2 * y1) / 3, toX, toY, pointBounds, addMode);
@@ -2612,7 +2614,7 @@ var LeaferUI = (function (exports) {
2612
2614
  }
2613
2615
  };
2614
2616
 
2615
- const { M: M$7, m, L: L$8, l, H, h, V, v, C: C$7, c, S, s, Q: Q$6, q, T, t, A, a, Z: Z$6, z, N: N$5, D: D$5, X: X$5, G: G$5, F: F$6, O: O$6, P: P$5, U: U$5 } = PathCommandMap;
2617
+ const { M: M$7, m, L: L$8, l, H, h, V, v, C: C$6, c, S, s, Q: Q$6, q, T, t, A, a, Z: Z$6, z, N: N$5, D: D$5, X: X$5, G: G$5, F: F$6, O: O$6, P: P$5, U: U$5 } = PathCommandMap;
2616
2618
  const { rect: rect$3, roundRect: roundRect$2, arcTo: arcTo$3, arc: arc$3, ellipse: ellipse$4, quadraticCurveTo: quadraticCurveTo$1 } = BezierHelper;
2617
2619
  const { ellipticalArc } = EllipseHelper;
2618
2620
  const debug$f = Debug.get('PathConvert');
@@ -2740,14 +2742,14 @@ var LeaferUI = (function (exports) {
2740
2742
  old[i + 4] += y;
2741
2743
  command = S;
2742
2744
  case S:
2743
- smooth = (lastCommand === C$7) || (lastCommand === S);
2745
+ smooth = (lastCommand === C$6) || (lastCommand === S);
2744
2746
  x1 = smooth ? (x * 2 - controlX) : old[i + 1];
2745
2747
  y1 = smooth ? (y * 2 - controlY) : old[i + 2];
2746
2748
  controlX = old[i + 1];
2747
2749
  controlY = old[i + 2];
2748
2750
  x = old[i + 3];
2749
2751
  y = old[i + 4];
2750
- data.push(C$7, x1, y1, controlX, controlY, x, y);
2752
+ data.push(C$6, x1, y1, controlX, controlY, x, y);
2751
2753
  i += 5;
2752
2754
  break;
2753
2755
  case c:
@@ -2757,13 +2759,13 @@ var LeaferUI = (function (exports) {
2757
2759
  old[i + 4] += y;
2758
2760
  old[i + 5] += x;
2759
2761
  old[i + 6] += y;
2760
- command = C$7;
2761
- case C$7:
2762
+ command = C$6;
2763
+ case C$6:
2762
2764
  controlX = old[i + 3];
2763
2765
  controlY = old[i + 4];
2764
2766
  x = old[i + 5];
2765
2767
  y = old[i + 6];
2766
- data.push(C$7, old[i + 1], old[i + 2], controlX, controlY, x, y);
2768
+ data.push(C$6, old[i + 1], old[i + 2], controlX, controlY, x, y);
2767
2769
  i += 7;
2768
2770
  break;
2769
2771
  case t:
@@ -2874,7 +2876,7 @@ var LeaferUI = (function (exports) {
2874
2876
  data.push(L$8, item.x, item.y);
2875
2877
  break;
2876
2878
  case 'C':
2877
- data.push(C$7, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2879
+ data.push(C$6, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2878
2880
  break;
2879
2881
  case 'Q':
2880
2882
  data.push(Q$6, item.x1, item.y1, item.x, item.y);
@@ -2901,7 +2903,7 @@ var LeaferUI = (function (exports) {
2901
2903
  };
2902
2904
  const { current, pushData, copyData } = PathConvert;
2903
2905
 
2904
- const { M: M$6, L: L$7, C: C$6, Q: Q$5, Z: Z$5, N: N$4, D: D$4, X: X$4, G: G$4, F: F$5, O: O$5, P: P$4, U: U$4 } = PathCommandMap;
2906
+ const { M: M$6, L: L$7, C: C$5, Q: Q$5, Z: Z$5, N: N$4, D: D$4, X: X$4, G: G$4, F: F$5, O: O$5, P: P$4, U: U$4 } = PathCommandMap;
2905
2907
  const { getMinDistanceFrom, getRadianFrom } = PointHelper;
2906
2908
  const { tan, min, abs: abs$4 } = Math;
2907
2909
  const startPoint = {};
@@ -2916,7 +2918,7 @@ var LeaferUI = (function (exports) {
2916
2918
  data.push(L$7, x, y);
2917
2919
  },
2918
2920
  bezierCurveTo(data, x1, y1, x2, y2, x, y) {
2919
- data.push(C$6, x1, y1, x2, y2, x, y);
2921
+ data.push(C$5, x1, y1, x2, y2, x, y);
2920
2922
  },
2921
2923
  quadraticCurveTo(data, x1, y1, x, y) {
2922
2924
  data.push(Q$5, x1, y1, x, y);
@@ -3078,7 +3080,7 @@ var LeaferUI = (function (exports) {
3078
3080
  paint() { }
3079
3081
  }
3080
3082
 
3081
- const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$4, N: N$3, D: D$3, X: X$3, G: G$3, F: F$4, O: O$4, P: P$3, U: U$3 } = PathCommandMap;
3083
+ const { M: M$5, L: L$6, C: C$4, Q: Q$4, Z: Z$4, N: N$3, D: D$3, X: X$3, G: G$3, F: F$4, O: O$4, P: P$3, U: U$3 } = PathCommandMap;
3082
3084
  const debug$e = Debug.get('PathDrawer');
3083
3085
  const PathDrawer = {
3084
3086
  drawPathByData(drawer, data) {
@@ -3097,7 +3099,7 @@ var LeaferUI = (function (exports) {
3097
3099
  drawer.lineTo(data[i + 1], data[i + 2]);
3098
3100
  i += 3;
3099
3101
  break;
3100
- case C$5:
3102
+ case C$4:
3101
3103
  drawer.bezierCurveTo(data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6]);
3102
3104
  i += 7;
3103
3105
  break;
@@ -3149,7 +3151,7 @@ var LeaferUI = (function (exports) {
3149
3151
  }
3150
3152
  };
3151
3153
 
3152
- const { M: M$4, L: L$5, C: C$4, Q: Q$3, Z: Z$3, N: N$2, D: D$2, X: X$2, G: G$2, F: F$3, O: O$3, P: P$2, U: U$2 } = PathCommandMap;
3154
+ const { M: M$4, L: L$5, C: C$3, Q: Q$3, Z: Z$3, N: N$2, D: D$2, X: X$2, G: G$2, F: F$3, O: O$3, P: P$2, U: U$2 } = PathCommandMap;
3153
3155
  const { toTwoPointBounds, toTwoPointBoundsByQuadraticCurve, arcTo: arcTo$1, arc, ellipse: ellipse$1 } = BezierHelper;
3154
3156
  const { addPointBounds, copy: copy$b, addPoint: addPoint$1, setPoint: setPoint$3, addBounds, toBounds: toBounds$3 } = TwoPointBoundsHelper;
3155
3157
  const debug$d = Debug.get('PathBounds');
@@ -3170,7 +3172,7 @@ var LeaferUI = (function (exports) {
3170
3172
  while (i < len) {
3171
3173
  command = data[i];
3172
3174
  if (i === 0) {
3173
- if (command === Z$3 || command === C$4 || command === Q$3) {
3175
+ if (command === Z$3 || command === C$3 || command === Q$3) {
3174
3176
  setPoint$3(setPointBounds, x, y);
3175
3177
  }
3176
3178
  else {
@@ -3185,7 +3187,7 @@ var LeaferUI = (function (exports) {
3185
3187
  addPoint$1(setPointBounds, x, y);
3186
3188
  i += 3;
3187
3189
  break;
3188
- case C$4:
3190
+ case C$3:
3189
3191
  toX = data[i + 5];
3190
3192
  toY = data[i + 6];
3191
3193
  toTwoPointBounds(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY, tempPointBounds);
@@ -3267,12 +3269,12 @@ var LeaferUI = (function (exports) {
3267
3269
  }
3268
3270
  };
3269
3271
 
3270
- const { M: M$3, L: L$4, C: C$3, Z: Z$2 } = PathCommandMap;
3272
+ const { M: M$3, L: L$4, Z: Z$2 } = PathCommandMap;
3271
3273
  const { getCenterX, getCenterY } = PointHelper;
3272
3274
  const { arcTo } = PathCommandDataHelper;
3273
3275
  const PathCorner = {
3274
3276
  smooth(data, cornerRadius, _cornerSmoothing) {
3275
- let command;
3277
+ let command, commandLen;
3276
3278
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0;
3277
3279
  const len = data.length;
3278
3280
  const smooth = [];
@@ -3309,15 +3311,16 @@ var LeaferUI = (function (exports) {
3309
3311
  lastX = x;
3310
3312
  lastY = y;
3311
3313
  break;
3312
- case C$3:
3313
- smooth.push(C$3, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6]);
3314
- i += 7;
3315
- break;
3316
3314
  case Z$2:
3317
3315
  arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3318
3316
  smooth.push(Z$2);
3319
3317
  i += 1;
3320
3318
  break;
3319
+ default:
3320
+ commandLen = PathNumberCommandLengthMap[command];
3321
+ for (let j = 0; j < commandLen; j++)
3322
+ smooth.push(data[i + j]);
3323
+ i += commandLen;
3321
3324
  }
3322
3325
  }
3323
3326
  if (command !== Z$2) {
@@ -4076,33 +4079,45 @@ var LeaferUI = (function (exports) {
4076
4079
  else if (typeof defaultValue === 'function') {
4077
4080
  property.get = function () {
4078
4081
  let v = this[computedKey];
4079
- if (v === undefined)
4080
- this[computedKey] = v = defaultValue(this.__leaf);
4081
- return v;
4082
+ return v === undefined ? defaultValue(this.__leaf) : v;
4082
4083
  };
4083
4084
  }
4085
+ else if (typeof defaultValue === 'object') {
4086
+ const isEmpty = isEmptyData(defaultValue);
4087
+ property.get = function () {
4088
+ let v = this[computedKey];
4089
+ return v === undefined ? this[computedKey] = isEmpty ? {} : DataHelper.clone(defaultValue) : v;
4090
+ };
4091
+ }
4092
+ const isBox = target.isBranchLeaf;
4084
4093
  if (key === 'width') {
4085
4094
  property.get = function () {
4086
4095
  const v = this[computedKey];
4087
4096
  if (v === undefined) {
4088
- const t = this;
4089
- return t._height && t.__naturalWidth && t.__useNaturalRatio ? t._height * t.__naturalWidth / t.__naturalHeight : t.__naturalWidth || defaultValue;
4097
+ const t = this, naturalWidth = t.__naturalWidth, leaf = t.__leaf;
4098
+ if (!defaultValue || leaf.pathInputed)
4099
+ return leaf.boxBounds.width;
4100
+ if (naturalWidth)
4101
+ return t._height && t.__useNaturalRatio ? t._height * naturalWidth / t.__naturalHeight : naturalWidth;
4102
+ return (isBox && leaf.children.length) ? leaf.boxBounds.width : defaultValue;
4090
4103
  }
4091
- else {
4104
+ else
4092
4105
  return v;
4093
- }
4094
4106
  };
4095
4107
  }
4096
4108
  else if (key === 'height') {
4097
4109
  property.get = function () {
4098
4110
  const v = this[computedKey];
4099
4111
  if (v === undefined) {
4100
- const t = this;
4101
- return t._width && t.__naturalHeight && t.__useNaturalRatio ? t._width * t.__naturalHeight / t.__naturalWidth : t.__naturalHeight || defaultValue;
4112
+ const t = this, naturalHeight = t.__naturalHeight, leaf = t.__leaf;
4113
+ if (!defaultValue || leaf.pathInputed)
4114
+ return leaf.boxBounds.height;
4115
+ if (naturalHeight)
4116
+ return t._width && t.__useNaturalRatio ? t._width * naturalHeight / t.__naturalWidth : naturalHeight;
4117
+ return (isBox && leaf.children.length) ? leaf.boxBounds.height : defaultValue;
4102
4118
  }
4103
- else {
4119
+ else
4104
4120
  return v;
4105
- }
4106
4121
  };
4107
4122
  }
4108
4123
  let descriptor, find = data;
@@ -4529,7 +4544,12 @@ var LeaferUI = (function (exports) {
4529
4544
  while (root.parent && !root.parent.leafer) {
4530
4545
  root = root.parent;
4531
4546
  }
4532
- Platform.layout(root);
4547
+ const r = root;
4548
+ if (r.__fullLayouting)
4549
+ return;
4550
+ r.__fullLayouting = true;
4551
+ Platform.layout(r);
4552
+ delete r.__fullLayouting;
4533
4553
  }
4534
4554
  }
4535
4555
  getTransform(relative = 'world') {
@@ -6054,7 +6074,7 @@ var LeaferUI = (function (exports) {
6054
6074
  }
6055
6075
  }
6056
6076
 
6057
- const version = "1.5.0";
6077
+ const version = "1.5.2";
6058
6078
 
6059
6079
  class LeaferCanvas extends LeaferCanvasBase {
6060
6080
  get allowBackgroundColor() { return true; }
@@ -7644,7 +7664,7 @@ var LeaferUI = (function (exports) {
7644
7664
  strokeType()
7645
7665
  ], exports.UI.prototype, "dashPattern", void 0);
7646
7666
  __decorate([
7647
- strokeType()
7667
+ strokeType(0)
7648
7668
  ], exports.UI.prototype, "dashOffset", void 0);
7649
7669
  __decorate([
7650
7670
  strokeType(10)
@@ -7737,6 +7757,12 @@ var LeaferUI = (function (exports) {
7737
7757
  __decorate([
7738
7758
  dataProcessor(GroupData)
7739
7759
  ], exports.Group.prototype, "__", void 0);
7760
+ __decorate([
7761
+ boundsType(0)
7762
+ ], exports.Group.prototype, "width", void 0);
7763
+ __decorate([
7764
+ boundsType(0)
7765
+ ], exports.Group.prototype, "height", void 0);
7740
7766
  exports.Group = __decorate([
7741
7767
  useModule(exports.Branch),
7742
7768
  registerUI()
@@ -8152,7 +8178,7 @@ var LeaferUI = (function (exports) {
8152
8178
  __updateRectBoxBounds() { }
8153
8179
  __updateBoxBounds(_secondLayout) {
8154
8180
  const data = this.__;
8155
- if (this.children.length) {
8181
+ if (this.children.length && !this.pathInputed) {
8156
8182
  if (data.__autoSide) {
8157
8183
  if (data.__hasSurface)
8158
8184
  this.__extraUpdate();
@@ -8221,6 +8247,12 @@ var LeaferUI = (function (exports) {
8221
8247
  __decorate([
8222
8248
  dataProcessor(BoxData)
8223
8249
  ], exports.Box.prototype, "__", void 0);
8250
+ __decorate([
8251
+ boundsType(100)
8252
+ ], exports.Box.prototype, "width", void 0);
8253
+ __decorate([
8254
+ boundsType(100)
8255
+ ], exports.Box.prototype, "height", void 0);
8224
8256
  __decorate([
8225
8257
  dataType(false)
8226
8258
  ], exports.Box.prototype, "resizeChildren", void 0);
@@ -10106,16 +10138,20 @@ var LeaferUI = (function (exports) {
10106
10138
  };
10107
10139
 
10108
10140
  function fillText(ui, canvas) {
10109
- let row;
10110
- const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
10141
+ let row, data = ui.__.__textDrawData;
10142
+ const { rows, decorationY } = data;
10111
10143
  for (let i = 0, len = rows.length; i < len; i++) {
10112
10144
  row = rows[i];
10113
10145
  if (row.text)
10114
10146
  canvas.fillText(row.text, row.x, row.y);
10115
10147
  else if (row.data)
10116
10148
  row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
10117
- if (decorationY)
10118
- canvas.fillRect(row.x, row.y + decorationY, row.width, decorationHeight);
10149
+ }
10150
+ if (decorationY) {
10151
+ const { decorationColor, decorationHeight } = data;
10152
+ if (decorationColor)
10153
+ canvas.fillStyle = decorationColor;
10154
+ rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
10119
10155
  }
10120
10156
  }
10121
10157
 
@@ -10186,16 +10222,18 @@ var LeaferUI = (function (exports) {
10186
10222
  out.recycle(ui.__nowWorld);
10187
10223
  }
10188
10224
  function drawTextStroke(ui, canvas) {
10189
- let row;
10190
- const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
10225
+ let row, data = ui.__.__textDrawData;
10226
+ const { rows, decorationY } = data;
10191
10227
  for (let i = 0, len = rows.length; i < len; i++) {
10192
10228
  row = rows[i];
10193
10229
  if (row.text)
10194
10230
  canvas.strokeText(row.text, row.x, row.y);
10195
10231
  else if (row.data)
10196
10232
  row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
10197
- if (decorationY)
10198
- canvas.strokeRect(row.x, row.y + decorationY, row.width, decorationHeight);
10233
+ }
10234
+ if (decorationY) {
10235
+ const { decorationHeight } = data;
10236
+ rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
10199
10237
  }
10200
10238
  }
10201
10239
  function drawStrokesStyle(strokes, isText, ui, canvas) {
@@ -10761,6 +10799,8 @@ var LeaferUI = (function (exports) {
10761
10799
  }
10762
10800
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
10763
10801
  }
10802
+ else
10803
+ paints[i].style = null;
10764
10804
  }
10765
10805
  }
10766
10806
  return recycleMap;
@@ -11493,14 +11533,25 @@ var LeaferUI = (function (exports) {
11493
11533
  }
11494
11534
 
11495
11535
  function decorationText(drawData, style) {
11496
- const { fontSize } = style;
11536
+ let type;
11537
+ const { fontSize, textDecoration } = style;
11497
11538
  drawData.decorationHeight = fontSize / 11;
11498
- switch (style.textDecoration) {
11539
+ if (typeof textDecoration === 'object') {
11540
+ type = textDecoration.type;
11541
+ if (textDecoration.color)
11542
+ drawData.decorationColor = ColorConvert.string(textDecoration.color);
11543
+ }
11544
+ else
11545
+ type = textDecoration;
11546
+ switch (type) {
11499
11547
  case 'under':
11500
- drawData.decorationY = fontSize * 0.15;
11548
+ drawData.decorationY = [fontSize * 0.15];
11501
11549
  break;
11502
11550
  case 'delete':
11503
- drawData.decorationY = -fontSize * 0.35;
11551
+ drawData.decorationY = [-fontSize * 0.35];
11552
+ break;
11553
+ case 'under-delete':
11554
+ drawData.decorationY = [fontSize * 0.15, -fontSize * 0.35];
11504
11555
  }
11505
11556
  }
11506
11557
 
@@ -11613,7 +11664,9 @@ var LeaferUI = (function (exports) {
11613
11664
  Object.assign(this, data);
11614
11665
  }
11615
11666
  }
11667
+ EditorEvent.BEFORE_SELECT = 'editor.before_select';
11616
11668
  EditorEvent.SELECT = 'editor.select';
11669
+ EditorEvent.BEFORE_HOVER = 'editor.before_hover';
11617
11670
  EditorEvent.HOVER = 'editor.hover';
11618
11671
 
11619
11672
  class EditorMoveEvent extends EditorEvent {
@@ -11655,8 +11708,12 @@ var LeaferUI = (function (exports) {
11655
11708
  get() { return this[privateKey]; },
11656
11709
  set(value) {
11657
11710
  const old = this[privateKey];
11658
- if (old !== value)
11711
+ if (old !== value) {
11712
+ const type = key === 'target' ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
11713
+ if (this.hasEvent(type))
11714
+ this.emitEvent(new EditorEvent(type, { editor: this, value: value, oldValue: old }));
11659
11715
  this[privateKey] = value, fn(this, old);
11716
+ }
11660
11717
  }
11661
11718
  });
11662
11719
  };
@@ -11955,7 +12012,8 @@ var LeaferUI = (function (exports) {
11955
12012
  return target.leafer !== this.editor.leafer;
11956
12013
  }
11957
12014
  allowDrag(e) {
11958
- if (this.running && (this.editor.mergeConfig.boxSelect) && !e.target.draggable) {
12015
+ const { boxSelect, multipleSelect } = this.editor.mergeConfig;
12016
+ if (this.running && (multipleSelect && boxSelect) && !e.target.draggable) {
11959
12017
  return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path));
11960
12018
  }
11961
12019
  else {
@@ -11973,7 +12031,8 @@ var LeaferUI = (function (exports) {
11973
12031
  return this.isMultipleSelect(e) ? this.findDeepOne(e) : findOne(e.path);
11974
12032
  }
11975
12033
  isMultipleSelect(e) {
11976
- return e.shiftKey || this.editor.mergeConfig.continuousSelect;
12034
+ const { multipleSelect, continuousSelect } = this.editor.mergeConfig;
12035
+ return multipleSelect && (e.shiftKey || continuousSelect);
11977
12036
  }
11978
12037
  __listenEvents() {
11979
12038
  const { editor } = this;
@@ -12148,21 +12207,25 @@ var LeaferUI = (function (exports) {
12148
12207
  let last;
12149
12208
  switch (direction) {
12150
12209
  case top$1:
12210
+ case topLeft$1:
12151
12211
  last = { x: 0.5, y: 0 };
12152
12212
  align = 'bottom';
12153
12213
  skewX = 1;
12154
12214
  break;
12155
12215
  case bottom$1:
12216
+ case bottomRight:
12156
12217
  last = { x: 0.5, y: 1 };
12157
12218
  align = 'top';
12158
12219
  skewX = 1;
12159
12220
  break;
12160
12221
  case left$2:
12222
+ case bottomLeft:
12161
12223
  last = { x: 0, y: 0.5 };
12162
12224
  align = 'right';
12163
12225
  skewY = 1;
12164
12226
  break;
12165
12227
  case right$2:
12228
+ case topRight$1:
12166
12229
  last = { x: 1, y: 0.5 };
12167
12230
  align = 'left';
12168
12231
  skewY = 1;
@@ -12251,7 +12314,7 @@ var LeaferUI = (function (exports) {
12251
12314
  let showResize = pointType.includes('resize');
12252
12315
  if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
12253
12316
  showResize = false;
12254
- const showSkew = skewable && !showResize && point.name === 'resize-line';
12317
+ const showSkew = skewable && !showResize && (point.name === 'resize-line' || pointType === 'skew');
12255
12318
  const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor);
12256
12319
  rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45;
12257
12320
  rotation = Math.round(MathHelper.formatRotation(rotation, true) / 2) * 2;
@@ -12473,6 +12536,8 @@ var LeaferUI = (function (exports) {
12473
12536
  editor.onRotate(e);
12474
12537
  if (pointType.includes('resize'))
12475
12538
  editor.onScale(e);
12539
+ if (pointType === 'skew')
12540
+ editor.onSkew(e);
12476
12541
  updateCursor(editor, e);
12477
12542
  }
12478
12543
  onArrow(e) {
@@ -12654,6 +12719,7 @@ ${filterStyle}
12654
12719
  hover: true,
12655
12720
  select: 'press',
12656
12721
  openInner: 'double',
12722
+ multipleSelect: true,
12657
12723
  boxSelect: true,
12658
12724
  moveable: true,
12659
12725
  resizeable: true,
@@ -12745,13 +12811,16 @@ ${filterStyle}
12745
12811
  const ungroupList = [];
12746
12812
  app.lockLayout();
12747
12813
  list.forEach(leaf => {
12748
- if (leaf.isBranch && !leaf.isBranchLeaf) {
12814
+ if (leaf.isBranch) {
12749
12815
  const { parent, children } = leaf;
12750
12816
  while (children.length) {
12751
12817
  ungroupList.push(children[0]);
12752
12818
  children[0].dropTo(parent, parent.children.indexOf(leaf));
12753
12819
  }
12754
- leaf.remove();
12820
+ if (leaf.isBranchLeaf)
12821
+ ungroupList.push(leaf);
12822
+ else
12823
+ leaf.remove();
12755
12824
  }
12756
12825
  else {
12757
12826
  ungroupList.push(leaf);
@@ -13056,13 +13125,22 @@ ${filterStyle}
13056
13125
  this.skewOf(origin, skewX, skewY);
13057
13126
  }
13058
13127
  move(x, y = 0) {
13059
- const { element } = this;
13060
13128
  if (!this.checkTransform('moveable'))
13061
13129
  return;
13062
- const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
13130
+ if (typeof x === 'object')
13131
+ y = x.y, x = x.x;
13132
+ const { element: target } = this, { beforeMove } = this.mergeConfig;
13133
+ if (beforeMove) {
13134
+ const check = beforeMove({ target, x, y });
13135
+ if (typeof check === 'object')
13136
+ x = check.x, y = check.y;
13137
+ else if (check === false)
13138
+ return;
13139
+ }
13140
+ const world = target.getWorldPointByLocal({ x, y }, null, true);
13063
13141
  if (this.multiple)
13064
- element.safeChange(() => element.move(x, y));
13065
- const data = { target: element, editor: this, moveX: world.x, moveY: world.y };
13142
+ target.safeChange(() => target.move(x, y));
13143
+ const data = { target, editor: this, moveX: world.x, moveY: world.y };
13066
13144
  this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
13067
13145
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
13068
13146
  this.editTool.onMove(event);
@@ -13071,8 +13149,14 @@ ${filterStyle}
13071
13149
  scaleWithDrag(data) {
13072
13150
  if (!this.checkTransform('resizeable'))
13073
13151
  return;
13074
- const { element } = this;
13075
- data = Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) });
13152
+ const { element: target } = this, { beforeScale } = this.mergeConfig;
13153
+ if (beforeScale) {
13154
+ const { origin, scaleX, scaleY, drag } = data;
13155
+ const check = beforeScale({ target, drag, origin, scaleX, scaleY });
13156
+ if (check === false)
13157
+ return;
13158
+ }
13159
+ data = Object.assign(Object.assign({}, data), { target, editor: this, worldOrigin: target.getWorldPoint(data.origin) });
13076
13160
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13077
13161
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13078
13162
  this.editTool.onScaleWithDrag(event);
@@ -13081,10 +13165,17 @@ ${filterStyle}
13081
13165
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
13082
13166
  if (!this.checkTransform('resizeable'))
13083
13167
  return;
13084
- const { element } = this;
13168
+ const { element: target } = this, { beforeScale } = this.mergeConfig;
13169
+ if (beforeScale) {
13170
+ const check = beforeScale({ target, origin, scaleX, scaleY });
13171
+ if (typeof check === 'object')
13172
+ scaleX = check.scaleX, scaleY = check.scaleY;
13173
+ else if (check === false)
13174
+ return;
13175
+ }
13085
13176
  const worldOrigin = this.getWorldOrigin(origin);
13086
- const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.scaleOf(origin, scaleX, scaleY)));
13087
- const data = { target: element, editor: this, worldOrigin, scaleX, scaleY, transform };
13177
+ const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
13178
+ const data = { target, editor: this, worldOrigin, scaleX, scaleY, transform };
13088
13179
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13089
13180
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13090
13181
  this.editTool.onScale(event);
@@ -13105,10 +13196,17 @@ ${filterStyle}
13105
13196
  rotateOf(origin, rotation) {
13106
13197
  if (!this.checkTransform('rotateable'))
13107
13198
  return;
13108
- const { element } = this;
13199
+ const { element: target } = this, { beforeRotate } = this.mergeConfig;
13200
+ if (beforeRotate) {
13201
+ const check = beforeRotate({ target, origin, rotation });
13202
+ if (typeof check === 'number')
13203
+ rotation = check;
13204
+ else if (check === false)
13205
+ return;
13206
+ }
13109
13207
  const worldOrigin = this.getWorldOrigin(origin);
13110
- const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.rotateOf(origin, rotation)));
13111
- const data = { target: element, editor: this, worldOrigin, rotation, transform };
13208
+ const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
13209
+ const data = { target, editor: this, worldOrigin, rotation, transform };
13112
13210
  this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
13113
13211
  const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
13114
13212
  this.editTool.onRotate(event);
@@ -13117,10 +13215,17 @@ ${filterStyle}
13117
13215
  skewOf(origin, skewX, skewY = 0, _resize) {
13118
13216
  if (!this.checkTransform('skewable'))
13119
13217
  return;
13120
- const { element } = this;
13218
+ const { element: target } = this, { beforeSkew } = this.mergeConfig;
13219
+ if (beforeSkew) {
13220
+ const check = beforeSkew({ target, origin, skewX, skewY });
13221
+ if (typeof check === 'object')
13222
+ skewX = check.skewX, skewY = check.skewY;
13223
+ else if (check === false)
13224
+ return;
13225
+ }
13121
13226
  const worldOrigin = this.getWorldOrigin(origin);
13122
- const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.skewOf(origin, skewX, skewY)));
13123
- const data = { target: element, editor: this, worldOrigin, skewX, skewY, transform };
13227
+ const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
13228
+ const data = { target, editor: this, worldOrigin, skewX, skewY, transform };
13124
13229
  this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
13125
13230
  const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
13126
13231
  this.editTool.onSkew(event);
@@ -13633,7 +13738,9 @@ ${filterStyle}
13633
13738
  }
13634
13739
  }
13635
13740
  leaf.fontSize *= fontScale;
13636
- const data = leaf.__;
13741
+ const data = leaf.__, { padding } = data;
13742
+ if (padding)
13743
+ leaf.padding = padding instanceof Array ? padding.map(item => item * fontScale) : padding * fontScale;
13637
13744
  if (!data.__autoWidth)
13638
13745
  leaf.width *= fontScale;
13639
13746
  if (!data.__autoHeight)
@@ -13721,14 +13828,11 @@ ${filterStyle}
13721
13828
  scaleResizeGroup(this, scaleX, scaleY);
13722
13829
  };
13723
13830
  exports.Box.prototype.__scaleResize = function (scaleX, scaleY) {
13724
- if (this.__.__autoSize && this.children.length) {
13725
- scaleResizeGroup(this, scaleX, scaleY);
13726
- }
13727
- else {
13831
+ const { resizeChildren, __autoSize } = this.__;
13832
+ if (!(__autoSize && resizeChildren))
13728
13833
  scaleResize(this, scaleX, scaleY);
13729
- if (this.__.resizeChildren)
13730
- scaleResizeGroup(this, scaleX, scaleY);
13731
- }
13834
+ if (resizeChildren)
13835
+ scaleResizeGroup(this, scaleX, scaleY);
13732
13836
  };
13733
13837
 
13734
13838
  Plugin.add('resize');
@@ -14928,6 +15032,12 @@ ${filterStyle}
14928
15032
  'middle': 'center',
14929
15033
  'bottom': 'flex-end'
14930
15034
  };
15035
+ const textDecorationMap = {
15036
+ 'none': 'none',
15037
+ 'under': 'underline',
15038
+ 'delete': 'line-through',
15039
+ 'under-delete': 'underline line-through'
15040
+ };
14931
15041
  function updateStyle(textDom, text, textScale) {
14932
15042
  const { style } = textDom;
14933
15043
  const { fill, padding, textWrap, textOverflow, textDecoration } = text;
@@ -14936,7 +15046,16 @@ ${filterStyle}
14936
15046
  setFill(style, fill);
14937
15047
  style.fontStyle = text.italic ? 'italic' : 'normal';
14938
15048
  style.fontWeight = text.fontWeight;
14939
- style.textDecoration = textDecoration === 'delete' ? 'line-through' : textDecoration;
15049
+ let decorationType;
15050
+ if (typeof textDecoration === 'object') {
15051
+ decorationType = textDecoration.type;
15052
+ if (textDecoration.color)
15053
+ style.textDecorationColor = ColorConvert.string(textDecoration.color);
15054
+ }
15055
+ else {
15056
+ decorationType = textDecoration;
15057
+ }
15058
+ style.textDecoration = textDecorationMap[decorationType];
14940
15059
  style.textTransform = textCaseMap[text.textCase];
14941
15060
  style.textAlign = text.textAlign === 'both' ? 'justify' : text.textAlign;
14942
15061
  style.display = 'flex';
@@ -15365,6 +15484,7 @@ ${filterStyle}
15365
15484
  exports.getMatrixData = getMatrixData;
15366
15485
  exports.getPointData = getPointData;
15367
15486
  exports.hitType = hitType;
15487
+ exports.isEmptyData = isEmptyData;
15368
15488
  exports.isNull = isNull;
15369
15489
  exports.layoutProcessor = layoutProcessor;
15370
15490
  exports.maskType = maskType;