@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.
@@ -116,8 +116,9 @@ const MathHelper = {
116
116
  if (!scaleData)
117
117
  scaleData = {};
118
118
  if (size) {
119
- scaleData.scaleX = (typeof size === 'number' ? size : size.width) / originSize.width;
120
- scaleData.scaleY = (typeof size === 'number' ? size : size.height) / originSize.height;
119
+ const scaleX = (typeof size === 'number' ? size : size.width || 0) / originSize.width, scaleY = (typeof size === 'number' ? size : size.height || 0) / originSize.height;
120
+ scaleData.scaleX = scaleX || scaleY || 1;
121
+ scaleData.scaleY = scaleY || scaleX || 1;
121
122
  }
122
123
  else if (scale)
123
124
  MathHelper.assignScale(scaleData, scale);
@@ -1690,6 +1691,9 @@ const emptyData = {};
1690
1691
  function isNull(value) {
1691
1692
  return value === undefined || value === null;
1692
1693
  }
1694
+ function isEmptyData(value) {
1695
+ return JSON.stringify(value) === '{}';
1696
+ }
1693
1697
 
1694
1698
  /******************************************************************************
1695
1699
  Copyright (c) Microsoft Corporation.
@@ -2029,13 +2033,11 @@ class LeaferCanvasBase extends Canvas$1 {
2029
2033
  this.worldTransform = {};
2030
2034
  if (!config)
2031
2035
  config = minSize;
2032
- if (!config.pixelRatio)
2033
- config.pixelRatio = Platform.devicePixelRatio;
2034
2036
  this.manager = manager;
2035
2037
  this.innerId = IncrementId.create(IncrementId.CNAVAS);
2036
2038
  const { width, height, pixelRatio } = config;
2037
2039
  this.autoLayout = !width || !height;
2038
- this.size.pixelRatio = pixelRatio;
2040
+ this.size.pixelRatio = pixelRatio | Platform.devicePixelRatio;
2039
2041
  this.config = config;
2040
2042
  this.init();
2041
2043
  }
@@ -2232,7 +2234,7 @@ class LeaferCanvasBase extends Canvas$1 {
2232
2234
  tempBounds$1.ceil();
2233
2235
  }
2234
2236
  isSameSize(size) {
2235
- return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
2237
+ return this.width === size.width && this.height === size.height && (!size.pixelRatio || this.pixelRatio === size.pixelRatio);
2236
2238
  }
2237
2239
  getSameCanvas(useSameWorldTransform, useSameSmooth) {
2238
2240
  const canvas = this.manager ? this.manager.get(this.size) : Creator.canvas(Object.assign({}, this.size));
@@ -2347,7 +2349,7 @@ const RectHelper = {
2347
2349
  const { sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil$1, abs: abs$5, PI: PI$2, sqrt: sqrt$1, pow } = Math;
2348
2350
  const { setPoint: setPoint$4, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2349
2351
  const { set, toNumberPoints: toNumberPoints$1 } = PointHelper;
2350
- const { M: M$8, L: L$9, C: C$8, Q: Q$7, Z: Z$7 } = PathCommandMap;
2352
+ const { M: M$8, L: L$9, C: C$7, Q: Q$7, Z: Z$7 } = PathCommandMap;
2351
2353
  const tempPoint$2 = {};
2352
2354
  const BezierHelper = {
2353
2355
  points(data, originPoints, curve, close) {
@@ -2382,7 +2384,7 @@ const BezierHelper = {
2382
2384
  data.push(Q$7, c1X, c1Y, bX, bY);
2383
2385
  }
2384
2386
  else {
2385
- data.push(C$8, c2X, c2Y, c1X, c1Y, bX, bY);
2387
+ data.push(C$7, c2X, c2Y, c1X, c1Y, bX, bY);
2386
2388
  }
2387
2389
  c2X = bX + cb * cX;
2388
2390
  c2Y = bY + cb * cY;
@@ -2487,7 +2489,7 @@ const BezierHelper = {
2487
2489
  x2 = cx + x + control * (rotationCos * radiusX * endSin + rotationSin * radiusY * endCos);
2488
2490
  y2 = cy + y + control * (rotationSin * radiusX * endSin - rotationCos * radiusY * endCos);
2489
2491
  if (data)
2490
- data.push(C$8, x1, y1, x2, y2, cx + x, cy + y);
2492
+ data.push(C$7, x1, y1, x2, y2, cx + x, cy + y);
2491
2493
  if (setPointBounds)
2492
2494
  toTwoPointBounds$1(cx + startX, cy + startY, x1, y1, x2, y2, cx + x, cy + y, setPointBounds, true);
2493
2495
  startX = x;
@@ -2501,7 +2503,7 @@ const BezierHelper = {
2501
2503
  set(setEndPoint, cx + x, cy + y);
2502
2504
  },
2503
2505
  quadraticCurveTo(data, fromX, fromY, x1, y1, toX, toY) {
2504
- data.push(C$8, (fromX + 2 * x1) / 3, (fromY + 2 * y1) / 3, (toX + 2 * x1) / 3, (toY + 2 * y1) / 3, toX, toY);
2506
+ data.push(C$7, (fromX + 2 * x1) / 3, (fromY + 2 * y1) / 3, (toX + 2 * x1) / 3, (toY + 2 * y1) / 3, toX, toY);
2505
2507
  },
2506
2508
  toTwoPointBoundsByQuadraticCurve(fromX, fromY, x1, y1, toX, toY, pointBounds, addMode) {
2507
2509
  toTwoPointBounds$1(fromX, fromY, (fromX + 2 * x1) / 3, (fromY + 2 * y1) / 3, (toX + 2 * x1) / 3, (toY + 2 * y1) / 3, toX, toY, pointBounds, addMode);
@@ -2609,7 +2611,7 @@ const EllipseHelper = {
2609
2611
  }
2610
2612
  };
2611
2613
 
2612
- 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;
2614
+ 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;
2613
2615
  const { rect: rect$3, roundRect: roundRect$2, arcTo: arcTo$3, arc: arc$3, ellipse: ellipse$4, quadraticCurveTo: quadraticCurveTo$1 } = BezierHelper;
2614
2616
  const { ellipticalArc } = EllipseHelper;
2615
2617
  const debug$f = Debug.get('PathConvert');
@@ -2737,14 +2739,14 @@ const PathConvert = {
2737
2739
  old[i + 4] += y;
2738
2740
  command = S;
2739
2741
  case S:
2740
- smooth = (lastCommand === C$7) || (lastCommand === S);
2742
+ smooth = (lastCommand === C$6) || (lastCommand === S);
2741
2743
  x1 = smooth ? (x * 2 - controlX) : old[i + 1];
2742
2744
  y1 = smooth ? (y * 2 - controlY) : old[i + 2];
2743
2745
  controlX = old[i + 1];
2744
2746
  controlY = old[i + 2];
2745
2747
  x = old[i + 3];
2746
2748
  y = old[i + 4];
2747
- data.push(C$7, x1, y1, controlX, controlY, x, y);
2749
+ data.push(C$6, x1, y1, controlX, controlY, x, y);
2748
2750
  i += 5;
2749
2751
  break;
2750
2752
  case c:
@@ -2754,13 +2756,13 @@ const PathConvert = {
2754
2756
  old[i + 4] += y;
2755
2757
  old[i + 5] += x;
2756
2758
  old[i + 6] += y;
2757
- command = C$7;
2758
- case C$7:
2759
+ command = C$6;
2760
+ case C$6:
2759
2761
  controlX = old[i + 3];
2760
2762
  controlY = old[i + 4];
2761
2763
  x = old[i + 5];
2762
2764
  y = old[i + 6];
2763
- data.push(C$7, old[i + 1], old[i + 2], controlX, controlY, x, y);
2765
+ data.push(C$6, old[i + 1], old[i + 2], controlX, controlY, x, y);
2764
2766
  i += 7;
2765
2767
  break;
2766
2768
  case t:
@@ -2871,7 +2873,7 @@ const PathConvert = {
2871
2873
  data.push(L$8, item.x, item.y);
2872
2874
  break;
2873
2875
  case 'C':
2874
- data.push(C$7, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2876
+ data.push(C$6, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2875
2877
  break;
2876
2878
  case 'Q':
2877
2879
  data.push(Q$6, item.x1, item.y1, item.x, item.y);
@@ -2898,7 +2900,7 @@ const PathConvert = {
2898
2900
  };
2899
2901
  const { current, pushData, copyData } = PathConvert;
2900
2902
 
2901
- 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;
2903
+ 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;
2902
2904
  const { getMinDistanceFrom, getRadianFrom } = PointHelper;
2903
2905
  const { tan, min, abs: abs$4 } = Math;
2904
2906
  const startPoint = {};
@@ -2913,7 +2915,7 @@ const PathCommandDataHelper = {
2913
2915
  data.push(L$7, x, y);
2914
2916
  },
2915
2917
  bezierCurveTo(data, x1, y1, x2, y2, x, y) {
2916
- data.push(C$6, x1, y1, x2, y2, x, y);
2918
+ data.push(C$5, x1, y1, x2, y2, x, y);
2917
2919
  },
2918
2920
  quadraticCurveTo(data, x1, y1, x, y) {
2919
2921
  data.push(Q$5, x1, y1, x, y);
@@ -3075,7 +3077,7 @@ class PathCreator {
3075
3077
  paint() { }
3076
3078
  }
3077
3079
 
3078
- 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;
3080
+ 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;
3079
3081
  const debug$e = Debug.get('PathDrawer');
3080
3082
  const PathDrawer = {
3081
3083
  drawPathByData(drawer, data) {
@@ -3094,7 +3096,7 @@ const PathDrawer = {
3094
3096
  drawer.lineTo(data[i + 1], data[i + 2]);
3095
3097
  i += 3;
3096
3098
  break;
3097
- case C$5:
3099
+ case C$4:
3098
3100
  drawer.bezierCurveTo(data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6]);
3099
3101
  i += 7;
3100
3102
  break;
@@ -3146,7 +3148,7 @@ const PathDrawer = {
3146
3148
  }
3147
3149
  };
3148
3150
 
3149
- 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;
3151
+ 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;
3150
3152
  const { toTwoPointBounds, toTwoPointBoundsByQuadraticCurve, arcTo: arcTo$1, arc, ellipse: ellipse$1 } = BezierHelper;
3151
3153
  const { addPointBounds, copy: copy$b, addPoint: addPoint$1, setPoint: setPoint$3, addBounds, toBounds: toBounds$3 } = TwoPointBoundsHelper;
3152
3154
  const debug$d = Debug.get('PathBounds');
@@ -3167,7 +3169,7 @@ const PathBounds = {
3167
3169
  while (i < len) {
3168
3170
  command = data[i];
3169
3171
  if (i === 0) {
3170
- if (command === Z$3 || command === C$4 || command === Q$3) {
3172
+ if (command === Z$3 || command === C$3 || command === Q$3) {
3171
3173
  setPoint$3(setPointBounds, x, y);
3172
3174
  }
3173
3175
  else {
@@ -3182,7 +3184,7 @@ const PathBounds = {
3182
3184
  addPoint$1(setPointBounds, x, y);
3183
3185
  i += 3;
3184
3186
  break;
3185
- case C$4:
3187
+ case C$3:
3186
3188
  toX = data[i + 5];
3187
3189
  toY = data[i + 6];
3188
3190
  toTwoPointBounds(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY, tempPointBounds);
@@ -3264,12 +3266,12 @@ const PathBounds = {
3264
3266
  }
3265
3267
  };
3266
3268
 
3267
- const { M: M$3, L: L$4, C: C$3, Z: Z$2 } = PathCommandMap;
3269
+ const { M: M$3, L: L$4, Z: Z$2 } = PathCommandMap;
3268
3270
  const { getCenterX, getCenterY } = PointHelper;
3269
3271
  const { arcTo } = PathCommandDataHelper;
3270
3272
  const PathCorner = {
3271
3273
  smooth(data, cornerRadius, _cornerSmoothing) {
3272
- let command;
3274
+ let command, commandLen;
3273
3275
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0;
3274
3276
  const len = data.length;
3275
3277
  const smooth = [];
@@ -3306,15 +3308,16 @@ const PathCorner = {
3306
3308
  lastX = x;
3307
3309
  lastY = y;
3308
3310
  break;
3309
- case C$3:
3310
- smooth.push(C$3, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6]);
3311
- i += 7;
3312
- break;
3313
3311
  case Z$2:
3314
3312
  arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3315
3313
  smooth.push(Z$2);
3316
3314
  i += 1;
3317
3315
  break;
3316
+ default:
3317
+ commandLen = PathNumberCommandLengthMap[command];
3318
+ for (let j = 0; j < commandLen; j++)
3319
+ smooth.push(data[i + j]);
3320
+ i += commandLen;
3318
3321
  }
3319
3322
  }
3320
3323
  if (command !== Z$2) {
@@ -4073,33 +4076,45 @@ function defineDataProcessor(target, key, defaultValue) {
4073
4076
  else if (typeof defaultValue === 'function') {
4074
4077
  property.get = function () {
4075
4078
  let v = this[computedKey];
4076
- if (v === undefined)
4077
- this[computedKey] = v = defaultValue(this.__leaf);
4078
- return v;
4079
+ return v === undefined ? defaultValue(this.__leaf) : v;
4079
4080
  };
4080
4081
  }
4082
+ else if (typeof defaultValue === 'object') {
4083
+ const isEmpty = isEmptyData(defaultValue);
4084
+ property.get = function () {
4085
+ let v = this[computedKey];
4086
+ return v === undefined ? this[computedKey] = isEmpty ? {} : DataHelper.clone(defaultValue) : v;
4087
+ };
4088
+ }
4089
+ const isBox = target.isBranchLeaf;
4081
4090
  if (key === 'width') {
4082
4091
  property.get = function () {
4083
4092
  const v = this[computedKey];
4084
4093
  if (v === undefined) {
4085
- const t = this;
4086
- return t._height && t.__naturalWidth && t.__useNaturalRatio ? t._height * t.__naturalWidth / t.__naturalHeight : t.__naturalWidth || defaultValue;
4094
+ const t = this, naturalWidth = t.__naturalWidth, leaf = t.__leaf;
4095
+ if (!defaultValue || leaf.pathInputed)
4096
+ return leaf.boxBounds.width;
4097
+ if (naturalWidth)
4098
+ return t._height && t.__useNaturalRatio ? t._height * naturalWidth / t.__naturalHeight : naturalWidth;
4099
+ return (isBox && leaf.children.length) ? leaf.boxBounds.width : defaultValue;
4087
4100
  }
4088
- else {
4101
+ else
4089
4102
  return v;
4090
- }
4091
4103
  };
4092
4104
  }
4093
4105
  else if (key === 'height') {
4094
4106
  property.get = function () {
4095
4107
  const v = this[computedKey];
4096
4108
  if (v === undefined) {
4097
- const t = this;
4098
- return t._width && t.__naturalHeight && t.__useNaturalRatio ? t._width * t.__naturalHeight / t.__naturalWidth : t.__naturalHeight || defaultValue;
4109
+ const t = this, naturalHeight = t.__naturalHeight, leaf = t.__leaf;
4110
+ if (!defaultValue || leaf.pathInputed)
4111
+ return leaf.boxBounds.height;
4112
+ if (naturalHeight)
4113
+ return t._width && t.__useNaturalRatio ? t._width * naturalHeight / t.__naturalWidth : naturalHeight;
4114
+ return (isBox && leaf.children.length) ? leaf.boxBounds.height : defaultValue;
4099
4115
  }
4100
- else {
4116
+ else
4101
4117
  return v;
4102
- }
4103
4118
  };
4104
4119
  }
4105
4120
  let descriptor, find = data;
@@ -4526,7 +4541,12 @@ class LeafLayout {
4526
4541
  while (root.parent && !root.parent.leafer) {
4527
4542
  root = root.parent;
4528
4543
  }
4529
- Platform.layout(root);
4544
+ const r = root;
4545
+ if (r.__fullLayouting)
4546
+ return;
4547
+ r.__fullLayouting = true;
4548
+ Platform.layout(r);
4549
+ delete r.__fullLayouting;
4530
4550
  }
4531
4551
  }
4532
4552
  getTransform(relative = 'world') {
@@ -6051,7 +6071,7 @@ class LeafLevelList {
6051
6071
  }
6052
6072
  }
6053
6073
 
6054
- const version = "1.5.0";
6074
+ const version = "1.5.2";
6055
6075
 
6056
6076
  class LeaferCanvas extends LeaferCanvasBase {
6057
6077
  get allowBackgroundColor() { return true; }
@@ -7641,7 +7661,7 @@ __decorate([
7641
7661
  strokeType()
7642
7662
  ], UI.prototype, "dashPattern", void 0);
7643
7663
  __decorate([
7644
- strokeType()
7664
+ strokeType(0)
7645
7665
  ], UI.prototype, "dashOffset", void 0);
7646
7666
  __decorate([
7647
7667
  strokeType(10)
@@ -7734,6 +7754,12 @@ let Group = class Group extends UI {
7734
7754
  __decorate([
7735
7755
  dataProcessor(GroupData)
7736
7756
  ], Group.prototype, "__", void 0);
7757
+ __decorate([
7758
+ boundsType(0)
7759
+ ], Group.prototype, "width", void 0);
7760
+ __decorate([
7761
+ boundsType(0)
7762
+ ], Group.prototype, "height", void 0);
7737
7763
  Group = __decorate([
7738
7764
  useModule(Branch),
7739
7765
  registerUI()
@@ -8149,7 +8175,7 @@ let Box = class Box extends Group {
8149
8175
  __updateRectBoxBounds() { }
8150
8176
  __updateBoxBounds(_secondLayout) {
8151
8177
  const data = this.__;
8152
- if (this.children.length) {
8178
+ if (this.children.length && !this.pathInputed) {
8153
8179
  if (data.__autoSide) {
8154
8180
  if (data.__hasSurface)
8155
8181
  this.__extraUpdate();
@@ -8218,6 +8244,12 @@ let Box = class Box extends Group {
8218
8244
  __decorate([
8219
8245
  dataProcessor(BoxData)
8220
8246
  ], Box.prototype, "__", void 0);
8247
+ __decorate([
8248
+ boundsType(100)
8249
+ ], Box.prototype, "width", void 0);
8250
+ __decorate([
8251
+ boundsType(100)
8252
+ ], Box.prototype, "height", void 0);
8221
8253
  __decorate([
8222
8254
  dataType(false)
8223
8255
  ], Box.prototype, "resizeChildren", void 0);
@@ -10103,16 +10135,20 @@ canvas$1.hitPixel = function (radiusPoint, offset, scale = 1) {
10103
10135
  };
10104
10136
 
10105
10137
  function fillText(ui, canvas) {
10106
- let row;
10107
- const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
10138
+ let row, data = ui.__.__textDrawData;
10139
+ const { rows, decorationY } = data;
10108
10140
  for (let i = 0, len = rows.length; i < len; i++) {
10109
10141
  row = rows[i];
10110
10142
  if (row.text)
10111
10143
  canvas.fillText(row.text, row.x, row.y);
10112
10144
  else if (row.data)
10113
10145
  row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
10114
- if (decorationY)
10115
- canvas.fillRect(row.x, row.y + decorationY, row.width, decorationHeight);
10146
+ }
10147
+ if (decorationY) {
10148
+ const { decorationColor, decorationHeight } = data;
10149
+ if (decorationColor)
10150
+ canvas.fillStyle = decorationColor;
10151
+ rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
10116
10152
  }
10117
10153
  }
10118
10154
 
@@ -10183,16 +10219,18 @@ function drawAlignStroke(align, stroke, isStrokes, ui, canvas) {
10183
10219
  out.recycle(ui.__nowWorld);
10184
10220
  }
10185
10221
  function drawTextStroke(ui, canvas) {
10186
- let row;
10187
- const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
10222
+ let row, data = ui.__.__textDrawData;
10223
+ const { rows, decorationY } = data;
10188
10224
  for (let i = 0, len = rows.length; i < len; i++) {
10189
10225
  row = rows[i];
10190
10226
  if (row.text)
10191
10227
  canvas.strokeText(row.text, row.x, row.y);
10192
10228
  else if (row.data)
10193
10229
  row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
10194
- if (decorationY)
10195
- canvas.strokeRect(row.x, row.y + decorationY, row.width, decorationHeight);
10230
+ }
10231
+ if (decorationY) {
10232
+ const { decorationHeight } = data;
10233
+ rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
10196
10234
  }
10197
10235
  }
10198
10236
  function drawStrokesStyle(strokes, isText, ui, canvas) {
@@ -10758,6 +10796,8 @@ function recycleImage(attrName, data) {
10758
10796
  }
10759
10797
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
10760
10798
  }
10799
+ else
10800
+ paints[i].style = null;
10761
10801
  }
10762
10802
  }
10763
10803
  return recycleMap;
@@ -11490,14 +11530,25 @@ function toTextChar(row) {
11490
11530
  }
11491
11531
 
11492
11532
  function decorationText(drawData, style) {
11493
- const { fontSize } = style;
11533
+ let type;
11534
+ const { fontSize, textDecoration } = style;
11494
11535
  drawData.decorationHeight = fontSize / 11;
11495
- switch (style.textDecoration) {
11536
+ if (typeof textDecoration === 'object') {
11537
+ type = textDecoration.type;
11538
+ if (textDecoration.color)
11539
+ drawData.decorationColor = ColorConvert.string(textDecoration.color);
11540
+ }
11541
+ else
11542
+ type = textDecoration;
11543
+ switch (type) {
11496
11544
  case 'under':
11497
- drawData.decorationY = fontSize * 0.15;
11545
+ drawData.decorationY = [fontSize * 0.15];
11498
11546
  break;
11499
11547
  case 'delete':
11500
- drawData.decorationY = -fontSize * 0.35;
11548
+ drawData.decorationY = [-fontSize * 0.35];
11549
+ break;
11550
+ case 'under-delete':
11551
+ drawData.decorationY = [fontSize * 0.15, -fontSize * 0.35];
11501
11552
  }
11502
11553
  }
11503
11554
 
@@ -11610,7 +11661,9 @@ class EditorEvent extends Event {
11610
11661
  Object.assign(this, data);
11611
11662
  }
11612
11663
  }
11664
+ EditorEvent.BEFORE_SELECT = 'editor.before_select';
11613
11665
  EditorEvent.SELECT = 'editor.select';
11666
+ EditorEvent.BEFORE_HOVER = 'editor.before_hover';
11614
11667
  EditorEvent.HOVER = 'editor.hover';
11615
11668
 
11616
11669
  class EditorMoveEvent extends EditorEvent {
@@ -11652,8 +11705,12 @@ function targetAttr(fn) {
11652
11705
  get() { return this[privateKey]; },
11653
11706
  set(value) {
11654
11707
  const old = this[privateKey];
11655
- if (old !== value)
11708
+ if (old !== value) {
11709
+ const type = key === 'target' ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
11710
+ if (this.hasEvent(type))
11711
+ this.emitEvent(new EditorEvent(type, { editor: this, value: value, oldValue: old }));
11656
11712
  this[privateKey] = value, fn(this, old);
11713
+ }
11657
11714
  }
11658
11715
  });
11659
11716
  };
@@ -11952,7 +12009,8 @@ class EditSelect extends Group {
11952
12009
  return target.leafer !== this.editor.leafer;
11953
12010
  }
11954
12011
  allowDrag(e) {
11955
- if (this.running && (this.editor.mergeConfig.boxSelect) && !e.target.draggable) {
12012
+ const { boxSelect, multipleSelect } = this.editor.mergeConfig;
12013
+ if (this.running && (multipleSelect && boxSelect) && !e.target.draggable) {
11956
12014
  return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path));
11957
12015
  }
11958
12016
  else {
@@ -11970,7 +12028,8 @@ class EditSelect extends Group {
11970
12028
  return this.isMultipleSelect(e) ? this.findDeepOne(e) : findOne(e.path);
11971
12029
  }
11972
12030
  isMultipleSelect(e) {
11973
- return e.shiftKey || this.editor.mergeConfig.continuousSelect;
12031
+ const { multipleSelect, continuousSelect } = this.editor.mergeConfig;
12032
+ return multipleSelect && (e.shiftKey || continuousSelect);
11974
12033
  }
11975
12034
  __listenEvents() {
11976
12035
  const { editor } = this;
@@ -12145,21 +12204,25 @@ const EditDataHelper = {
12145
12204
  let last;
12146
12205
  switch (direction) {
12147
12206
  case top$1:
12207
+ case topLeft$1:
12148
12208
  last = { x: 0.5, y: 0 };
12149
12209
  align = 'bottom';
12150
12210
  skewX = 1;
12151
12211
  break;
12152
12212
  case bottom$1:
12213
+ case bottomRight:
12153
12214
  last = { x: 0.5, y: 1 };
12154
12215
  align = 'top';
12155
12216
  skewX = 1;
12156
12217
  break;
12157
12218
  case left$2:
12219
+ case bottomLeft:
12158
12220
  last = { x: 0, y: 0.5 };
12159
12221
  align = 'right';
12160
12222
  skewY = 1;
12161
12223
  break;
12162
12224
  case right$2:
12225
+ case topRight$1:
12163
12226
  last = { x: 1, y: 0.5 };
12164
12227
  align = 'left';
12165
12228
  skewY = 1;
@@ -12248,7 +12311,7 @@ function updateCursor(editor, e) {
12248
12311
  let showResize = pointType.includes('resize');
12249
12312
  if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
12250
12313
  showResize = false;
12251
- const showSkew = skewable && !showResize && point.name === 'resize-line';
12314
+ const showSkew = skewable && !showResize && (point.name === 'resize-line' || pointType === 'skew');
12252
12315
  const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor);
12253
12316
  rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45;
12254
12317
  rotation = Math.round(MathHelper.formatRotation(rotation, true) / 2) * 2;
@@ -12470,6 +12533,8 @@ class EditBox extends Group {
12470
12533
  editor.onRotate(e);
12471
12534
  if (pointType.includes('resize'))
12472
12535
  editor.onScale(e);
12536
+ if (pointType === 'skew')
12537
+ editor.onSkew(e);
12473
12538
  updateCursor(editor, e);
12474
12539
  }
12475
12540
  onArrow(e) {
@@ -12651,6 +12716,7 @@ const config = {
12651
12716
  hover: true,
12652
12717
  select: 'press',
12653
12718
  openInner: 'double',
12719
+ multipleSelect: true,
12654
12720
  boxSelect: true,
12655
12721
  moveable: true,
12656
12722
  resizeable: true,
@@ -12742,13 +12808,16 @@ const EditorHelper = {
12742
12808
  const ungroupList = [];
12743
12809
  app.lockLayout();
12744
12810
  list.forEach(leaf => {
12745
- if (leaf.isBranch && !leaf.isBranchLeaf) {
12811
+ if (leaf.isBranch) {
12746
12812
  const { parent, children } = leaf;
12747
12813
  while (children.length) {
12748
12814
  ungroupList.push(children[0]);
12749
12815
  children[0].dropTo(parent, parent.children.indexOf(leaf));
12750
12816
  }
12751
- leaf.remove();
12817
+ if (leaf.isBranchLeaf)
12818
+ ungroupList.push(leaf);
12819
+ else
12820
+ leaf.remove();
12752
12821
  }
12753
12822
  else {
12754
12823
  ungroupList.push(leaf);
@@ -13053,13 +13122,22 @@ class Editor extends Group {
13053
13122
  this.skewOf(origin, skewX, skewY);
13054
13123
  }
13055
13124
  move(x, y = 0) {
13056
- const { element } = this;
13057
13125
  if (!this.checkTransform('moveable'))
13058
13126
  return;
13059
- const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
13127
+ if (typeof x === 'object')
13128
+ y = x.y, x = x.x;
13129
+ const { element: target } = this, { beforeMove } = this.mergeConfig;
13130
+ if (beforeMove) {
13131
+ const check = beforeMove({ target, x, y });
13132
+ if (typeof check === 'object')
13133
+ x = check.x, y = check.y;
13134
+ else if (check === false)
13135
+ return;
13136
+ }
13137
+ const world = target.getWorldPointByLocal({ x, y }, null, true);
13060
13138
  if (this.multiple)
13061
- element.safeChange(() => element.move(x, y));
13062
- const data = { target: element, editor: this, moveX: world.x, moveY: world.y };
13139
+ target.safeChange(() => target.move(x, y));
13140
+ const data = { target, editor: this, moveX: world.x, moveY: world.y };
13063
13141
  this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
13064
13142
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
13065
13143
  this.editTool.onMove(event);
@@ -13068,8 +13146,14 @@ class Editor extends Group {
13068
13146
  scaleWithDrag(data) {
13069
13147
  if (!this.checkTransform('resizeable'))
13070
13148
  return;
13071
- const { element } = this;
13072
- data = Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) });
13149
+ const { element: target } = this, { beforeScale } = this.mergeConfig;
13150
+ if (beforeScale) {
13151
+ const { origin, scaleX, scaleY, drag } = data;
13152
+ const check = beforeScale({ target, drag, origin, scaleX, scaleY });
13153
+ if (check === false)
13154
+ return;
13155
+ }
13156
+ data = Object.assign(Object.assign({}, data), { target, editor: this, worldOrigin: target.getWorldPoint(data.origin) });
13073
13157
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13074
13158
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13075
13159
  this.editTool.onScaleWithDrag(event);
@@ -13078,10 +13162,17 @@ class Editor extends Group {
13078
13162
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
13079
13163
  if (!this.checkTransform('resizeable'))
13080
13164
  return;
13081
- const { element } = this;
13165
+ const { element: target } = this, { beforeScale } = this.mergeConfig;
13166
+ if (beforeScale) {
13167
+ const check = beforeScale({ target, origin, scaleX, scaleY });
13168
+ if (typeof check === 'object')
13169
+ scaleX = check.scaleX, scaleY = check.scaleY;
13170
+ else if (check === false)
13171
+ return;
13172
+ }
13082
13173
  const worldOrigin = this.getWorldOrigin(origin);
13083
- const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.scaleOf(origin, scaleX, scaleY)));
13084
- const data = { target: element, editor: this, worldOrigin, scaleX, scaleY, transform };
13174
+ const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
13175
+ const data = { target, editor: this, worldOrigin, scaleX, scaleY, transform };
13085
13176
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13086
13177
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13087
13178
  this.editTool.onScale(event);
@@ -13102,10 +13193,17 @@ class Editor extends Group {
13102
13193
  rotateOf(origin, rotation) {
13103
13194
  if (!this.checkTransform('rotateable'))
13104
13195
  return;
13105
- const { element } = this;
13196
+ const { element: target } = this, { beforeRotate } = this.mergeConfig;
13197
+ if (beforeRotate) {
13198
+ const check = beforeRotate({ target, origin, rotation });
13199
+ if (typeof check === 'number')
13200
+ rotation = check;
13201
+ else if (check === false)
13202
+ return;
13203
+ }
13106
13204
  const worldOrigin = this.getWorldOrigin(origin);
13107
- const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.rotateOf(origin, rotation)));
13108
- const data = { target: element, editor: this, worldOrigin, rotation, transform };
13205
+ const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
13206
+ const data = { target, editor: this, worldOrigin, rotation, transform };
13109
13207
  this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
13110
13208
  const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
13111
13209
  this.editTool.onRotate(event);
@@ -13114,10 +13212,17 @@ class Editor extends Group {
13114
13212
  skewOf(origin, skewX, skewY = 0, _resize) {
13115
13213
  if (!this.checkTransform('skewable'))
13116
13214
  return;
13117
- const { element } = this;
13215
+ const { element: target } = this, { beforeSkew } = this.mergeConfig;
13216
+ if (beforeSkew) {
13217
+ const check = beforeSkew({ target, origin, skewX, skewY });
13218
+ if (typeof check === 'object')
13219
+ skewX = check.skewX, skewY = check.skewY;
13220
+ else if (check === false)
13221
+ return;
13222
+ }
13118
13223
  const worldOrigin = this.getWorldOrigin(origin);
13119
- const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.skewOf(origin, skewX, skewY)));
13120
- const data = { target: element, editor: this, worldOrigin, skewX, skewY, transform };
13224
+ const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
13225
+ const data = { target, editor: this, worldOrigin, skewX, skewY, transform };
13121
13226
  this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
13122
13227
  const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
13123
13228
  this.editTool.onSkew(event);
@@ -13630,7 +13735,9 @@ function scaleResizeFontSize(leaf, scaleX, scaleY, direction) {
13630
13735
  }
13631
13736
  }
13632
13737
  leaf.fontSize *= fontScale;
13633
- const data = leaf.__;
13738
+ const data = leaf.__, { padding } = data;
13739
+ if (padding)
13740
+ leaf.padding = padding instanceof Array ? padding.map(item => item * fontScale) : padding * fontScale;
13634
13741
  if (!data.__autoWidth)
13635
13742
  leaf.width *= fontScale;
13636
13743
  if (!data.__autoHeight)
@@ -13718,14 +13825,11 @@ Group.prototype.__scaleResize = function (scaleX, scaleY) {
13718
13825
  scaleResizeGroup(this, scaleX, scaleY);
13719
13826
  };
13720
13827
  Box.prototype.__scaleResize = function (scaleX, scaleY) {
13721
- if (this.__.__autoSize && this.children.length) {
13722
- scaleResizeGroup(this, scaleX, scaleY);
13723
- }
13724
- else {
13828
+ const { resizeChildren, __autoSize } = this.__;
13829
+ if (!(__autoSize && resizeChildren))
13725
13830
  scaleResize(this, scaleX, scaleY);
13726
- if (this.__.resizeChildren)
13727
- scaleResizeGroup(this, scaleX, scaleY);
13728
- }
13831
+ if (resizeChildren)
13832
+ scaleResizeGroup(this, scaleX, scaleY);
13729
13833
  };
13730
13834
 
13731
13835
  Plugin.add('resize');
@@ -14925,6 +15029,12 @@ const verticalAlignMap = {
14925
15029
  'middle': 'center',
14926
15030
  'bottom': 'flex-end'
14927
15031
  };
15032
+ const textDecorationMap = {
15033
+ 'none': 'none',
15034
+ 'under': 'underline',
15035
+ 'delete': 'line-through',
15036
+ 'under-delete': 'underline line-through'
15037
+ };
14928
15038
  function updateStyle(textDom, text, textScale) {
14929
15039
  const { style } = textDom;
14930
15040
  const { fill, padding, textWrap, textOverflow, textDecoration } = text;
@@ -14933,7 +15043,16 @@ function updateStyle(textDom, text, textScale) {
14933
15043
  setFill(style, fill);
14934
15044
  style.fontStyle = text.italic ? 'italic' : 'normal';
14935
15045
  style.fontWeight = text.fontWeight;
14936
- style.textDecoration = textDecoration === 'delete' ? 'line-through' : textDecoration;
15046
+ let decorationType;
15047
+ if (typeof textDecoration === 'object') {
15048
+ decorationType = textDecoration.type;
15049
+ if (textDecoration.color)
15050
+ style.textDecorationColor = ColorConvert.string(textDecoration.color);
15051
+ }
15052
+ else {
15053
+ decorationType = textDecoration;
15054
+ }
15055
+ style.textDecoration = textDecorationMap[decorationType];
14937
15056
  style.textTransform = textCaseMap[text.textCase];
14938
15057
  style.textAlign = text.textAlign === 'both' ? 'justify' : text.textAlign;
14939
15058
  style.display = 'flex';
@@ -15190,5 +15309,5 @@ HTMLText = __decorate([
15190
15309
 
15191
15310
  Plugin.add('html');
15192
15311
 
15193
- export { AlignHelper, Answer, App, AroundHelper, Arrow, ArrowData, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, Dragger, DropEvent, EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, Finder, Frame, FrameData, Group, GroupData, HTMLText, HTMLTextData, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, LineEditTool, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, MyDragEvent, MyImage, MyPointerEvent, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathArrowModule, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathMatrixHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Picker, Platform, Plugin, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, RotateEvent, Run, ScrollBar, SelectArea, Selector, Star, StarData, State, StringNumberMap, Stroker, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TextEditor, Transformer, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, WheelEventHelper, ZoomEvent, addViewport, addViewportConfig, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isNull, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerEditTool, registerInnerEditor, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };
15312
+ export { AlignHelper, Answer, App, AroundHelper, Arrow, ArrowData, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, Dragger, DropEvent, EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, Finder, Frame, FrameData, Group, GroupData, HTMLText, HTMLTextData, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, LineEditTool, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, MyDragEvent, MyImage, MyPointerEvent, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathArrowModule, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathMatrixHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Picker, Platform, Plugin, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, RotateEvent, Run, ScrollBar, SelectArea, Selector, Star, StarData, State, StringNumberMap, Stroker, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TextEditor, Transformer, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, WheelEventHelper, ZoomEvent, addViewport, addViewportConfig, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isEmptyData, isNull, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerEditTool, registerInnerEditor, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };
15194
15313
  //# sourceMappingURL=worker.module.js.map