@leafer-draw/worker 1.0.0-rc.21 → 1.0.0-rc.23

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.
@@ -3,7 +3,7 @@ const Platform = {
3
3
  hitCanvasSize: 100,
4
4
  maxCacheSize: 2560 * 1600,
5
5
  maxPatternSize: 4096 * 2160,
6
- suffix: 'leaf',
6
+ suffix: '',
7
7
  crossOrigin: 'anonymous'
8
8
  }
9
9
  };
@@ -33,24 +33,12 @@ const I$1 = IncrementId;
33
33
  const { round, pow: pow$1, PI: PI$4 } = Math;
34
34
  const MathHelper = {
35
35
  within(value, min, max) {
36
- if (value < min)
36
+ if (min !== undefined && value < min)
37
37
  value = min;
38
- if (value > max)
38
+ if (max !== undefined && value > max)
39
39
  value = max;
40
40
  return value;
41
41
  },
42
- minus(value, isFourNumber) {
43
- if (value instanceof Array) {
44
- if (isFourNumber)
45
- value = MathHelper.fourNumber(value, 0);
46
- for (let i = 0; i < value.length; i++)
47
- value[i] = -value[i];
48
- }
49
- else {
50
- value = -value;
51
- }
52
- return value;
53
- },
54
42
  fourNumber(num, maxValue) {
55
43
  let data;
56
44
  if (num instanceof Array) {
@@ -117,7 +105,7 @@ function getMatrixData() { return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }; }
117
105
 
118
106
  const { sin: sin$5, cos: cos$5, acos, sqrt: sqrt$3 } = Math;
119
107
  const { float: float$1 } = MathHelper;
120
- const tempPoint$3 = {};
108
+ const tempPoint$4 = {};
121
109
  function getWorld() {
122
110
  return Object.assign(Object.assign(Object.assign({}, getMatrixData()), getBoundsData()), { scaleX: 1, scaleY: 1, rotation: 0, skewX: 0, skewY: 0 });
123
111
  }
@@ -147,9 +135,11 @@ const MatrixHelper = {
147
135
  t.e += x;
148
136
  t.f += y;
149
137
  },
150
- translateInner(t, x, y) {
138
+ translateInner(t, x, y, isMoveOrigin) {
151
139
  t.e += t.a * x + t.c * y;
152
140
  t.f += t.b * x + t.d * y;
141
+ if (isMoveOrigin)
142
+ t.e -= x, t.f -= y;
153
143
  },
154
144
  scale(t, scaleX, scaleY = scaleX) {
155
145
  t.a *= scaleX;
@@ -158,8 +148,8 @@ const MatrixHelper = {
158
148
  t.d *= scaleY;
159
149
  },
160
150
  scaleOfOuter(t, origin, scaleX, scaleY) {
161
- M$6.toInnerPoint(t, origin, tempPoint$3);
162
- M$6.scaleOfInner(t, tempPoint$3, scaleX, scaleY);
151
+ M$6.toInnerPoint(t, origin, tempPoint$4);
152
+ M$6.scaleOfInner(t, tempPoint$4, scaleX, scaleY);
163
153
  },
164
154
  scaleOfInner(t, origin, scaleX, scaleY = scaleX) {
165
155
  M$6.translateInner(t, origin.x, origin.y);
@@ -177,8 +167,8 @@ const MatrixHelper = {
177
167
  t.d = c * sinR + d * cosR;
178
168
  },
179
169
  rotateOfOuter(t, origin, rotation) {
180
- M$6.toInnerPoint(t, origin, tempPoint$3);
181
- M$6.rotateOfInner(t, tempPoint$3, rotation);
170
+ M$6.toInnerPoint(t, origin, tempPoint$4);
171
+ M$6.rotateOfInner(t, tempPoint$4, rotation);
182
172
  },
183
173
  rotateOfInner(t, origin, rotation) {
184
174
  M$6.translateInner(t, origin.x, origin.y);
@@ -199,8 +189,8 @@ const MatrixHelper = {
199
189
  }
200
190
  },
201
191
  skewOfOuter(t, origin, skewX, skewY) {
202
- M$6.toInnerPoint(t, origin, tempPoint$3);
203
- M$6.skewOfInner(t, tempPoint$3, skewX, skewY);
192
+ M$6.toInnerPoint(t, origin, tempPoint$4);
193
+ M$6.skewOfInner(t, tempPoint$4, skewX, skewY);
204
194
  },
205
195
  skewOfInner(t, origin, skewX, skewY = 0) {
206
196
  M$6.translateInner(t, origin.x, origin.y);
@@ -216,8 +206,10 @@ const MatrixHelper = {
216
206
  t.e = child.e * a + child.f * c + e;
217
207
  t.f = child.e * b + child.f * d + f;
218
208
  },
219
- multiplyParent(t, parent, to, abcdChanged, childScaleData) {
220
- const { e, f } = t;
209
+ multiplyParent(t, parent, to, abcdChanged, childScaleData, scrollData) {
210
+ let { e, f } = t;
211
+ if (scrollData)
212
+ e += scrollData.scrollX, f += scrollData.scrollY;
221
213
  to || (to = t);
222
214
  if (abcdChanged === undefined)
223
215
  abcdChanged = t.a !== 1 || t.b || t.c || t.d !== 1;
@@ -338,7 +330,7 @@ const MatrixHelper = {
338
330
  t.e = x;
339
331
  t.f = y;
340
332
  if (origin)
341
- M$6.translateInner(t, -origin.x, -origin.y);
333
+ M$6.translateInner(t, -origin.x, -origin.y, true);
342
334
  },
343
335
  getLayout(t, origin, firstSkewY) {
344
336
  const { a, b, c, d, e, f } = t;
@@ -594,7 +586,7 @@ class Point {
594
586
  return this;
595
587
  }
596
588
  }
597
- const tempPoint$2 = new Point();
589
+ const tempPoint$3 = new Point();
598
590
 
599
591
  class Matrix {
600
592
  constructor(a, b, c, d, e, f) {
@@ -758,7 +750,7 @@ const { float, fourNumber } = MathHelper;
758
750
  const { floor, ceil: ceil$2 } = Math;
759
751
  let right$1, bottom$1, boundsRight, boundsBottom;
760
752
  const point = {};
761
- const toPoint$1 = {};
753
+ const toPoint$2 = {};
762
754
  const BoundsHelper = {
763
755
  tempBounds: {},
764
756
  set(t, x = 0, y = 0, width = 0, height = 0) {
@@ -773,15 +765,17 @@ const BoundsHelper = {
773
765
  t.width = bounds.width;
774
766
  t.height = bounds.height;
775
767
  },
776
- copyAndSpread(t, bounds, spreadX, spreadY) {
777
- if (spreadX instanceof Array) {
778
- const four = fourNumber(spreadX);
779
- B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
768
+ copyAndSpread(t, bounds, spread, isShrink) {
769
+ if (spread instanceof Array) {
770
+ const four = fourNumber(spread);
771
+ isShrink
772
+ ? B.set(t, bounds.x + four[3], bounds.y + four[0], bounds.width - four[1] - four[3], bounds.height - four[2] - four[0])
773
+ : B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
780
774
  }
781
775
  else {
782
- if (!spreadY)
783
- spreadY = spreadX;
784
- B.set(t, bounds.x - spreadX, bounds.y - spreadY, bounds.width + spreadX * 2, bounds.height + spreadY * 2);
776
+ if (isShrink)
777
+ spread = -spread;
778
+ B.set(t, bounds.x - spread, bounds.y - spread, bounds.width + spread * 2, bounds.height + spread * 2);
785
779
  }
786
780
  },
787
781
  minX(t) { return t.width > 0 ? t.x : t.x + t.width; },
@@ -858,17 +852,17 @@ const BoundsHelper = {
858
852
  else {
859
853
  point.x = t.x;
860
854
  point.y = t.y;
861
- toOuterPoint$1(matrix, point, toPoint$1);
862
- setPoint$3(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
855
+ toOuterPoint$1(matrix, point, toPoint$2);
856
+ setPoint$3(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
863
857
  point.x = t.x + t.width;
864
- toOuterPoint$1(matrix, point, toPoint$1);
865
- addPoint$3(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
858
+ toOuterPoint$1(matrix, point, toPoint$2);
859
+ addPoint$3(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
866
860
  point.y = t.y + t.height;
867
- toOuterPoint$1(matrix, point, toPoint$1);
868
- addPoint$3(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
861
+ toOuterPoint$1(matrix, point, toPoint$2);
862
+ addPoint$3(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
869
863
  point.x = t.x;
870
- toOuterPoint$1(matrix, point, toPoint$1);
871
- addPoint$3(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
864
+ toOuterPoint$1(matrix, point, toPoint$2);
865
+ addPoint$3(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
872
866
  toBounds$4(tempPointBounds$1, to);
873
867
  }
874
868
  },
@@ -881,13 +875,16 @@ const BoundsHelper = {
881
875
  const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
882
876
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
883
877
  },
884
- getSpread(t, spreadX, spreadY) {
878
+ getSpread(t, spread) {
885
879
  const n = {};
886
- B.copyAndSpread(n, t, spreadX, spreadY);
880
+ B.copyAndSpread(n, t, spread);
887
881
  return n;
888
882
  },
889
- spread(t, spreadX, spreadY = spreadX) {
890
- B.copyAndSpread(t, t, spreadX, spreadY);
883
+ spread(t, spread) {
884
+ B.copyAndSpread(t, t, spread);
885
+ },
886
+ shrink(t, shrink) {
887
+ B.copyAndSpread(t, t, shrink, true);
891
888
  },
892
889
  ceil(t) {
893
890
  const { x, y } = t;
@@ -1067,12 +1064,12 @@ class Bounds {
1067
1064
  getFitMatrix(put, baseScale) {
1068
1065
  return BoundsHelper.getFitMatrix(this, put, baseScale);
1069
1066
  }
1070
- spread(fourNumber, spreadY) {
1071
- BoundsHelper.spread(this, fourNumber, spreadY);
1067
+ spread(fourNumber) {
1068
+ BoundsHelper.spread(this, fourNumber);
1072
1069
  return this;
1073
1070
  }
1074
1071
  shrink(fourNumber) {
1075
- BoundsHelper.spread(this, MathHelper.minus(fourNumber, true));
1072
+ BoundsHelper.shrink(this, fourNumber);
1076
1073
  return this;
1077
1074
  }
1078
1075
  ceil() {
@@ -1189,6 +1186,10 @@ var Direction9;
1189
1186
  Direction9[Direction9["bottomLeft"] = 6] = "bottomLeft";
1190
1187
  Direction9[Direction9["left"] = 7] = "left";
1191
1188
  Direction9[Direction9["center"] = 8] = "center";
1189
+ Direction9[Direction9["top-left"] = 0] = "top-left";
1190
+ Direction9[Direction9["top-right"] = 2] = "top-right";
1191
+ Direction9[Direction9["bottom-right"] = 4] = "bottom-right";
1192
+ Direction9[Direction9["bottom-left"] = 6] = "bottom-left";
1192
1193
  })(Direction9 || (Direction9 = {}));
1193
1194
 
1194
1195
  const directionData = [
@@ -1202,15 +1203,28 @@ const directionData = [
1202
1203
  { x: 0, y: 0.5 },
1203
1204
  { x: 0.5, y: 0.5 }
1204
1205
  ];
1206
+ directionData.forEach(item => item.type = 'percent');
1205
1207
  const AroundHelper = {
1206
1208
  directionData,
1207
1209
  tempPoint: {},
1208
1210
  get: get$5,
1209
- toPoint(around, bounds, to, onlySize) {
1211
+ toPoint(around, bounds, to, onlySize, pointBounds) {
1210
1212
  to || (to = {});
1211
1213
  const point = get$5(around);
1212
- to.x = point.x * bounds.width;
1213
- to.y = point.y * bounds.height;
1214
+ to.x = point.x;
1215
+ to.y = point.y;
1216
+ if (point.type === 'percent') {
1217
+ to.x *= bounds.width;
1218
+ to.y *= bounds.height;
1219
+ if (pointBounds) {
1220
+ to.x -= pointBounds.x;
1221
+ to.y -= pointBounds.y;
1222
+ if (point.x)
1223
+ to.x -= (point.x === 1) ? pointBounds.width : (point.x === 0.5 ? point.x * pointBounds.width : 0);
1224
+ if (point.y)
1225
+ to.y -= (point.y === 1) ? pointBounds.height : (point.y === 0.5 ? point.y * pointBounds.height : 0);
1226
+ }
1227
+ }
1214
1228
  if (!onlySize) {
1215
1229
  to.x += bounds.x;
1216
1230
  to.y += bounds.y;
@@ -1221,6 +1235,13 @@ function get$5(around) {
1221
1235
  return typeof around === 'string' ? directionData[Direction9[around]] : around;
1222
1236
  }
1223
1237
 
1238
+ const { toPoint: toPoint$1 } = AroundHelper;
1239
+ const AlignHelper = {
1240
+ toPoint(align, contentBounds, bounds, to, onlySize) {
1241
+ toPoint$1(align, bounds, to, onlySize, contentBounds);
1242
+ }
1243
+ };
1244
+
1224
1245
  const StringNumberMap = {
1225
1246
  '0': 1,
1226
1247
  '1': 1,
@@ -1453,13 +1474,19 @@ const DataHelper = {
1453
1474
  },
1454
1475
  clone(data) {
1455
1476
  return JSON.parse(JSON.stringify(data));
1477
+ },
1478
+ toMap(list) {
1479
+ const map = {};
1480
+ for (let i = 0, len = list.length; i < len; i++)
1481
+ map[list[i]] = true;
1482
+ return map;
1456
1483
  }
1457
1484
  };
1458
1485
  const { assign } = DataHelper;
1459
1486
 
1460
1487
  class LeafData {
1461
1488
  get __blendMode() {
1462
- if (this.eraser)
1489
+ if (this.eraser && this.eraser !== 'path')
1463
1490
  return 'destination-out';
1464
1491
  const { blendMode } = this;
1465
1492
  return blendMode === 'pass-through' ? null : blendMode;
@@ -2089,7 +2116,7 @@ class LeaferCanvasBase extends Canvas$1 {
2089
2116
  }
2090
2117
  clear() {
2091
2118
  const { pixelRatio } = this;
2092
- this.clearRect(0, 0, this.width * pixelRatio, this.height * pixelRatio);
2119
+ this.clearRect(0, 0, this.width * pixelRatio + 2, this.height * pixelRatio + 2);
2093
2120
  }
2094
2121
  isSameSize(size) {
2095
2122
  return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
@@ -2208,7 +2235,7 @@ const { sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil$1, abs: abs$3, PI: PI
2208
2235
  const { setPoint: setPoint$2, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2209
2236
  const { set: set$2 } = PointHelper;
2210
2237
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$5 } = PathCommandMap;
2211
- const tempPoint$1 = {};
2238
+ const tempPoint$2 = {};
2212
2239
  const BezierHelper = {
2213
2240
  points(data, points, curve, close) {
2214
2241
  data.push(M$5, points[0], points[1]);
@@ -2398,8 +2425,8 @@ const BezierHelper = {
2398
2425
  addMode ? addPoint$2(pointBounds, fromX, fromY) : setPoint$2(pointBounds, fromX, fromY);
2399
2426
  addPoint$2(pointBounds, toX, toY);
2400
2427
  for (let i = 0, len = tList.length; i < len; i++) {
2401
- getPointAndSet(tList[i], fromX, fromY, x1, y1, x2, y2, toX, toY, tempPoint$1);
2402
- addPoint$2(pointBounds, tempPoint$1.x, tempPoint$1.y);
2428
+ getPointAndSet(tList[i], fromX, fromY, x1, y1, x2, y2, toX, toY, tempPoint$2);
2429
+ addPoint$2(pointBounds, tempPoint$2.x, tempPoint$2.y);
2403
2430
  }
2404
2431
  },
2405
2432
  getPointAndSet(t, fromX, fromY, x1, y1, x2, y2, toX, toY, setPoint) {
@@ -3745,6 +3772,8 @@ function maskType(defaultValue) {
3745
3772
  this.__setAttr(key, value);
3746
3773
  this.__layout.boxChanged || this.__layout.boxChange();
3747
3774
  this.waitParent(() => { this.parent.__updateMask(value); });
3775
+ if (typeof value === 'string')
3776
+ this.maskType = value;
3748
3777
  }
3749
3778
  }));
3750
3779
  }
@@ -3956,15 +3985,21 @@ const LeafHelper = {
3956
3985
  }
3957
3986
  return true;
3958
3987
  },
3959
- moveWorld(t, x, y) {
3960
- const local = { x, y };
3988
+ moveWorld(t, x, y = 0) {
3989
+ const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
3961
3990
  if (t.parent)
3962
3991
  toInnerPoint$1(t.parent.worldTransform, local, local, true);
3963
3992
  L.moveLocal(t, local.x, local.y);
3964
3993
  },
3965
3994
  moveLocal(t, x, y = 0) {
3966
- t.x += x;
3967
- t.y += y;
3995
+ if (typeof x === 'object') {
3996
+ t.x += x.x;
3997
+ t.y += x.y;
3998
+ }
3999
+ else {
4000
+ t.x += x;
4001
+ t.y += y;
4002
+ }
3968
4003
  },
3969
4004
  zoomOfWorld(t, origin, scaleX, scaleY, resize) {
3970
4005
  L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
@@ -4168,11 +4203,19 @@ const WaitHelper = {
4168
4203
 
4169
4204
  const { getRelativeWorld: getRelativeWorld$1 } = LeafHelper;
4170
4205
  const { toOuterOf: toOuterOf$2, getPoints, copy: copy$5 } = BoundsHelper;
4206
+ const localContent = '_localContentBounds';
4207
+ const worldContent = '_worldContentBounds', worldBox = '_worldBoxBounds', worldStroke = '_worldStrokeBounds';
4171
4208
  class LeafLayout {
4209
+ get contentBounds() { return this._contentBounds || this.boxBounds; }
4210
+ set contentBounds(bounds) { this._contentBounds = bounds; }
4172
4211
  get strokeBounds() { return this._strokeBounds || this.boxBounds; }
4173
4212
  get renderBounds() { return this._renderBounds || this.boxBounds; }
4213
+ get localContentBounds() { toOuterOf$2(this.contentBounds, this.leaf.__localMatrix, this[localContent] || (this[localContent] = {})); return this[localContent]; }
4174
4214
  get localStrokeBounds() { return this._localStrokeBounds || this; }
4175
4215
  get localRenderBounds() { return this._localRenderBounds || this; }
4216
+ get worldContentBounds() { toOuterOf$2(this.contentBounds, this.leaf.__world, this[worldContent] || (this[worldContent] = {})); return this[worldContent]; }
4217
+ get worldBoxBounds() { toOuterOf$2(this.boxBounds, this.leaf.__world, this[worldBox] || (this[worldBox] = {})); return this[worldBox]; }
4218
+ get worldStrokeBounds() { toOuterOf$2(this.strokeBounds, this.leaf.__world, this[worldStroke] || (this[worldStroke] = {})); return this[worldStroke]; }
4176
4219
  get a() { return 1; }
4177
4220
  get b() { return 0; }
4178
4221
  get c() { return 0; }
@@ -4255,7 +4298,6 @@ class LeafLayout {
4255
4298
  case 'content':
4256
4299
  if (this.contentBounds)
4257
4300
  return this.contentBounds;
4258
- case 'margin':
4259
4301
  case 'box':
4260
4302
  return this.boxBounds;
4261
4303
  case 'stroke':
@@ -4268,8 +4310,9 @@ class LeafLayout {
4268
4310
  return this.localRenderBounds;
4269
4311
  case 'stroke':
4270
4312
  return this.localStrokeBounds;
4271
- case 'margin':
4272
4313
  case 'content':
4314
+ if (this.contentBounds)
4315
+ return this.localContentBounds;
4273
4316
  case 'box':
4274
4317
  return this.leaf.__localBoxBounds;
4275
4318
  }
@@ -4278,15 +4321,13 @@ class LeafLayout {
4278
4321
  switch (type) {
4279
4322
  case 'render':
4280
4323
  return this.leaf.__world;
4324
+ case 'stroke':
4325
+ return this.worldStrokeBounds;
4281
4326
  case 'content':
4282
4327
  if (this.contentBounds)
4283
- return this.getWorldContentBounds();
4284
- case 'margin':
4328
+ return this.worldContentBounds;
4285
4329
  case 'box':
4286
- return this.getWorldBoxBounds();
4287
- case 'margin':
4288
- case 'stroke':
4289
- return this.getWorldStrokeBounds();
4330
+ return this.worldBoxBounds;
4290
4331
  }
4291
4332
  }
4292
4333
  getLayoutBounds(type, relative = 'world', unscale) {
@@ -4349,20 +4390,24 @@ class LeafLayout {
4349
4390
  points.forEach(point => leaf.innerToWorld(point, null, false, relativeLeaf));
4350
4391
  return points;
4351
4392
  }
4352
- getWorldContentBounds() {
4353
- this._worldContentBounds || (this._worldContentBounds = {});
4354
- toOuterOf$2(this.contentBounds, this.leaf.__world, this._worldContentBounds);
4355
- return this._worldContentBounds;
4393
+ shrinkContent() {
4394
+ const { x, y, width, height } = this.boxBounds;
4395
+ this._contentBounds = { x, y, width, height };
4396
+ }
4397
+ spreadStroke() {
4398
+ const { x, y, width, height } = this.strokeBounds;
4399
+ this._strokeBounds = { x, y, width, height };
4400
+ this._localStrokeBounds = { x, y, width, height };
4401
+ if (!this.renderSpread)
4402
+ this.spreadRenderCancel();
4356
4403
  }
4357
- getWorldBoxBounds() {
4358
- this._worldBoxBounds || (this._worldBoxBounds = {});
4359
- toOuterOf$2(this.boxBounds, this.leaf.__world, this._worldBoxBounds);
4360
- return this._worldBoxBounds;
4404
+ spreadRender() {
4405
+ const { x, y, width, height } = this.renderBounds;
4406
+ this._renderBounds = { x, y, width, height };
4407
+ this._localRenderBounds = { x, y, width, height };
4361
4408
  }
4362
- getWorldStrokeBounds() {
4363
- this._worldStrokeBounds || (this._worldStrokeBounds = {});
4364
- toOuterOf$2(this.strokeBounds, this.leaf.__world, this._worldStrokeBounds);
4365
- return this._worldStrokeBounds;
4409
+ shrinkContentCancel() {
4410
+ this._contentBounds = undefined;
4366
4411
  }
4367
4412
  spreadStrokeCancel() {
4368
4413
  const same = this.renderBounds === this.strokeBounds;
@@ -4375,18 +4420,6 @@ class LeafLayout {
4375
4420
  this._renderBounds = this._strokeBounds;
4376
4421
  this._localRenderBounds = this._localStrokeBounds;
4377
4422
  }
4378
- spreadStroke() {
4379
- const { x, y, width, height } = this.strokeBounds;
4380
- this._strokeBounds = { x, y, width, height };
4381
- this._localStrokeBounds = { x, y, width, height };
4382
- if (!this.renderSpread)
4383
- this.spreadRenderCancel();
4384
- }
4385
- spreadRender() {
4386
- const { x, y, width, height } = this.renderBounds;
4387
- this._renderBounds = { x, y, width, height };
4388
- this._localRenderBounds = { x, y, width, height };
4389
- }
4390
4423
  boxChange() {
4391
4424
  this.boxChanged = true;
4392
4425
  this.localBoxChanged || this.localBoxChange();
@@ -4473,24 +4506,40 @@ const LeafEventer = {
4473
4506
  });
4474
4507
  },
4475
4508
  off(type, listener, options) {
4476
- let capture;
4477
- if (options)
4478
- capture = typeof options === 'boolean' ? options : options.capture;
4479
- let events, index;
4480
- const map = __getListenerMap(this, capture);
4481
- const typeList = typeof type === 'string' ? type.split(' ') : type;
4482
- typeList.forEach(type => {
4483
- if (type) {
4484
- events = map[type];
4485
- if (events) {
4486
- index = events.findIndex(item => item.listener === listener);
4487
- if (index > -1)
4488
- events.splice(index, 1);
4489
- if (!events.length)
4490
- delete map[type];
4491
- }
4509
+ if (type) {
4510
+ const typeList = typeof type === 'string' ? type.split(' ') : type;
4511
+ if (listener) {
4512
+ let capture;
4513
+ if (options)
4514
+ capture = typeof options === 'boolean' ? options : options.capture;
4515
+ let events, index;
4516
+ const map = __getListenerMap(this, capture);
4517
+ typeList.forEach(type => {
4518
+ if (type) {
4519
+ events = map[type];
4520
+ if (events) {
4521
+ index = events.findIndex(item => item.listener === listener);
4522
+ if (index > -1)
4523
+ events.splice(index, 1);
4524
+ if (!events.length)
4525
+ delete map[type];
4526
+ }
4527
+ }
4528
+ });
4492
4529
  }
4493
- });
4530
+ else {
4531
+ const { __bubbleMap: b, __captureMap: c } = this;
4532
+ typeList.forEach(type => {
4533
+ if (b)
4534
+ delete b[type];
4535
+ if (c)
4536
+ delete c[type];
4537
+ });
4538
+ }
4539
+ }
4540
+ else {
4541
+ this.__bubbleMap = this.__captureMap = undefined;
4542
+ }
4494
4543
  },
4495
4544
  on_(type, listener, bind, options) {
4496
4545
  if (bind)
@@ -4526,12 +4575,15 @@ const LeafEventer = {
4526
4575
  break;
4527
4576
  }
4528
4577
  }
4578
+ this.syncEventer && this.syncEventer.emitEvent(event, capture);
4529
4579
  },
4530
4580
  emitEvent(event, capture) {
4531
4581
  event.current = this;
4532
4582
  this.emit(event.type, event, capture);
4533
4583
  },
4534
4584
  hasEvent(type, capture) {
4585
+ if (this.syncEventer && this.syncEventer.hasEvent(type, capture))
4586
+ return true;
4535
4587
  const { __bubbleMap: b, __captureMap: c } = this;
4536
4588
  const hasB = b && b[type], hasC = c && c[type];
4537
4589
  return !!(capture === undefined ? (hasB || hasC) : (capture ? hasC : hasB));
@@ -4751,10 +4803,10 @@ const LeafDataProxy = {
4751
4803
  };
4752
4804
 
4753
4805
  const { setLayout, multiplyParent: multiplyParent$1, translateInner, defaultWorld } = MatrixHelper;
4754
- const { toPoint, tempPoint } = AroundHelper;
4806
+ const { toPoint, tempPoint: tempPoint$1 } = AroundHelper;
4755
4807
  const LeafMatrix = {
4756
4808
  __updateWorldMatrix() {
4757
- multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__);
4809
+ multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__, this.parent && this.parent.__);
4758
4810
  },
4759
4811
  __updateLocalMatrix() {
4760
4812
  if (this.__local) {
@@ -4765,11 +4817,11 @@ const LeafMatrix = {
4765
4817
  layout.scaleChanged = layout.rotationChanged = false;
4766
4818
  }
4767
4819
  }
4768
- local.e = data.x;
4769
- local.f = data.y;
4770
- if (data.around) {
4771
- toPoint(data.around, layout.boxBounds, tempPoint);
4772
- translateInner(local, -tempPoint.x, -tempPoint.y);
4820
+ local.e = data.x + data.offsetX;
4821
+ local.f = data.y + data.offsetY;
4822
+ if (data.around || data.origin) {
4823
+ toPoint(data.around || data.origin, layout.boxBounds, tempPoint$1);
4824
+ translateInner(local, -tempPoint$1.x, -tempPoint$1.y, data.origin);
4773
4825
  }
4774
4826
  }
4775
4827
  this.__layout.matrixChanged = false;
@@ -4875,6 +4927,8 @@ const LeafBounds = {
4875
4927
  if (this.isBranch) {
4876
4928
  if (this.leafer)
4877
4929
  this.leafer.layouter.addExtra(this);
4930
+ if (this.__.flow)
4931
+ this.__updateFlowLayout();
4878
4932
  if (hasParentAutoLayout(this)) {
4879
4933
  updateMatrix$1(this);
4880
4934
  }
@@ -4907,6 +4961,8 @@ const LeafRender = {
4907
4961
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
4908
4962
  canvas.opacity = this.__.opacity;
4909
4963
  if (this.__.__single) {
4964
+ if (this.__.eraser === 'path')
4965
+ return this.__renderEraser(canvas, options);
4910
4966
  const tempCanvas = canvas.getSameCanvas(true, true);
4911
4967
  this.__draw(tempCanvas, options);
4912
4968
  if (this.__worldFlipped) {
@@ -4949,6 +5005,8 @@ const BranchRender = {
4949
5005
  __render(canvas, options) {
4950
5006
  if (this.__worldOpacity) {
4951
5007
  if (this.__.__single) {
5008
+ if (this.__.eraser === 'path')
5009
+ return this.__renderEraser(canvas, options);
4952
5010
  const tempCanvas = canvas.getSameCanvas(false, true);
4953
5011
  this.__renderBranch(tempCanvas, options);
4954
5012
  const nowWorld = this.__getNowWorld(options);
@@ -5088,7 +5146,9 @@ let Leaf = class Leaf {
5088
5146
  setProxyAttr(_attrName, _newValue) { }
5089
5147
  getProxyAttr(_attrName) { return undefined; }
5090
5148
  find(_condition, _options) { return undefined; }
5149
+ findTag(_tag) { return undefined; }
5091
5150
  findOne(_condition, _options) { return undefined; }
5151
+ findId(_id) { return undefined; }
5092
5152
  focus(_value) { }
5093
5153
  forceUpdate(attrName) {
5094
5154
  if (attrName === undefined)
@@ -5110,9 +5170,11 @@ let Leaf = class Leaf {
5110
5170
  __updateLocalStrokeBounds() { }
5111
5171
  __updateLocalRenderBounds() { }
5112
5172
  __updateBoxBounds() { }
5173
+ __updateContentBounds() { }
5113
5174
  __updateStrokeBounds() { }
5114
5175
  __updateRenderBounds() { }
5115
5176
  __updateAutoLayout() { }
5177
+ __updateFlowLayout() { }
5116
5178
  __updateNaturalSize() { }
5117
5179
  __updateStrokeSpread() { return 0; }
5118
5180
  __updateRenderSpread() { return 0; }
@@ -5120,6 +5182,13 @@ let Leaf = class Leaf {
5120
5182
  __updateEraser(value) {
5121
5183
  this.__hasEraser = value ? true : this.children.some(item => item.__.eraser);
5122
5184
  }
5185
+ __renderEraser(canvas, options) {
5186
+ canvas.save();
5187
+ this.__clip(canvas, options);
5188
+ const { renderBounds: r } = this.__layout;
5189
+ canvas.clearRect(r.x, r.y, r.width, r.height);
5190
+ canvas.restore();
5191
+ }
5123
5192
  __updateMask(value) {
5124
5193
  this.__hasMask = value ? true : this.children.some(item => item.__.mask);
5125
5194
  }
@@ -5300,8 +5369,8 @@ let Leaf = class Leaf {
5300
5369
  emit(_type, _event, _capture) { }
5301
5370
  emitEvent(_event, _capture) { }
5302
5371
  hasEvent(_type, _capture) { return false; }
5303
- static changeAttr(attrName, defaultValue) {
5304
- defineDataProcessor(this.prototype, attrName, defaultValue);
5372
+ static changeAttr(attrName, defaultValue, fn) {
5373
+ fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5305
5374
  }
5306
5375
  static addAttr(attrName, defaultValue, fn) {
5307
5376
  if (!fn)
@@ -6228,8 +6297,11 @@ class Renderer {
6228
6297
  if (!bounds.includes(this.target.__world) || this.needFill || !e.samePixelRatio) {
6229
6298
  this.addBlock(this.canvas.bounds);
6230
6299
  this.target.forceUpdate('surface');
6300
+ return;
6231
6301
  }
6232
6302
  }
6303
+ this.addBlock(new Bounds(0, 0, 1, 1));
6304
+ this.changed = true;
6233
6305
  }
6234
6306
  __onLayoutEnd(event) {
6235
6307
  if (event.data)
@@ -6335,7 +6407,11 @@ function zoomLayerType() {
6335
6407
  defineKey(target, key, {
6336
6408
  set(value) { if (this.isLeafer)
6337
6409
  this[privateKey] = value; },
6338
- get() { return this.isLeafer ? (this[privateKey] || this) : this.leafer && this.leafer.zoomLayer; }
6410
+ get() {
6411
+ return this.isApp
6412
+ ? this.tree.zoomLayer
6413
+ : (this.isLeafer ? (this[privateKey] || this) : this.leafer && this.leafer.zoomLayer);
6414
+ }
6339
6415
  });
6340
6416
  };
6341
6417
  }
@@ -6475,7 +6551,7 @@ class UIData extends LeafData {
6475
6551
  const UnitConvert = {
6476
6552
  number(value, percentRefer) {
6477
6553
  if (typeof value === 'object')
6478
- return value.type === 'percent' ? value.value / 100 * percentRefer : value.value;
6554
+ return value.type === 'percent' ? (value.value > 49 ? value.value / 100 : value.value) * percentRefer : value.value;
6479
6555
  return value;
6480
6556
  }
6481
6557
  };
@@ -6741,6 +6817,9 @@ let UI = UI_1 = class UI extends Leaf {
6741
6817
  pen.set(this.path = this.__.path || []);
6742
6818
  return pen;
6743
6819
  }
6820
+ get editConfig() { return undefined; }
6821
+ get editOuter() { return 'EditTool'; }
6822
+ get editInner() { return 'PathEditor'; }
6744
6823
  constructor(data) {
6745
6824
  super(data);
6746
6825
  }
@@ -6753,7 +6832,9 @@ let UI = UI_1 = class UI extends Leaf {
6753
6832
  }
6754
6833
  createProxyData() { return undefined; }
6755
6834
  find(_condition, _options) { return undefined; }
6835
+ findTag(tag) { return this.find({ tag }); }
6756
6836
  findOne(_condition, _options) { return undefined; }
6837
+ findId(id) { return this.findOne({ id }); }
6757
6838
  getPath(curve, pathForRender) {
6758
6839
  this.__layout.update();
6759
6840
  let path = pathForRender ? this.__.__pathForRender : this.__.path;
@@ -6802,7 +6883,8 @@ let UI = UI_1 = class UI extends Leaf {
6802
6883
  __drawPathByBox(drawer) {
6803
6884
  const { x, y, width, height } = this.__layout.boxBounds;
6804
6885
  if (this.__.cornerRadius) {
6805
- drawer.roundRect(x, y, width, height, this.__.cornerRadius);
6886
+ const { cornerRadius } = this.__;
6887
+ drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
6806
6888
  }
6807
6889
  else {
6808
6890
  drawer.rect(x, y, width, height);
@@ -6823,6 +6905,9 @@ let UI = UI_1 = class UI extends Leaf {
6823
6905
  static registerData(data) {
6824
6906
  dataProcessor(data)(this.prototype);
6825
6907
  }
6908
+ static setEditConfig(_config) { }
6909
+ static setEditOuter(_toolName) { }
6910
+ static setEditInner(_editorName) { }
6826
6911
  destroy() {
6827
6912
  this.fill = this.stroke = null;
6828
6913
  super.destroy();
@@ -6900,21 +6985,84 @@ __decorate([
6900
6985
  __decorate([
6901
6986
  rotationType(0, true)
6902
6987
  ], UI.prototype, "skewY", void 0);
6988
+ __decorate([
6989
+ positionType(0, true)
6990
+ ], UI.prototype, "offsetX", void 0);
6991
+ __decorate([
6992
+ positionType(0, true)
6993
+ ], UI.prototype, "offsetY", void 0);
6994
+ __decorate([
6995
+ positionType(0, true)
6996
+ ], UI.prototype, "scrollX", void 0);
6997
+ __decorate([
6998
+ positionType(0, true)
6999
+ ], UI.prototype, "scrollY", void 0);
7000
+ __decorate([
7001
+ autoLayoutType()
7002
+ ], UI.prototype, "origin", void 0);
6903
7003
  __decorate([
6904
7004
  autoLayoutType()
6905
7005
  ], UI.prototype, "around", void 0);
6906
7006
  __decorate([
6907
7007
  dataType(false)
6908
- ], UI.prototype, "draggable", void 0);
7008
+ ], UI.prototype, "lazy", void 0);
6909
7009
  __decorate([
6910
- dataType(false)
6911
- ], UI.prototype, "editable", void 0);
7010
+ naturalBoundsType(1)
7011
+ ], UI.prototype, "pixelRatio", void 0);
7012
+ __decorate([
7013
+ pathInputType()
7014
+ ], UI.prototype, "path", void 0);
7015
+ __decorate([
7016
+ pathType()
7017
+ ], UI.prototype, "windingRule", void 0);
7018
+ __decorate([
7019
+ pathType(true)
7020
+ ], UI.prototype, "closed", void 0);
7021
+ __decorate([
7022
+ autoLayoutType(false)
7023
+ ], UI.prototype, "flow", void 0);
7024
+ __decorate([
7025
+ boundsType(0)
7026
+ ], UI.prototype, "padding", void 0);
7027
+ __decorate([
7028
+ boundsType(0)
7029
+ ], UI.prototype, "gap", void 0);
7030
+ __decorate([
7031
+ boundsType('top-left')
7032
+ ], UI.prototype, "align", void 0);
7033
+ __decorate([
7034
+ boundsType(false)
7035
+ ], UI.prototype, "wrap", void 0);
6912
7036
  __decorate([
6913
- dataType('size')
6914
- ], UI.prototype, "editSize", void 0);
7037
+ boundsType('box')
7038
+ ], UI.prototype, "itemBox", void 0);
7039
+ __decorate([
7040
+ boundsType(true)
7041
+ ], UI.prototype, "inFlow", void 0);
7042
+ __decorate([
7043
+ boundsType()
7044
+ ], UI.prototype, "autoWidth", void 0);
7045
+ __decorate([
7046
+ boundsType()
7047
+ ], UI.prototype, "autoHeight", void 0);
7048
+ __decorate([
7049
+ boundsType()
7050
+ ], UI.prototype, "autoBox", void 0);
7051
+ __decorate([
7052
+ boundsType()
7053
+ ], UI.prototype, "widthRange", void 0);
7054
+ __decorate([
7055
+ boundsType()
7056
+ ], UI.prototype, "heightRange", void 0);
7057
+ __decorate([
7058
+ dataType(false)
7059
+ ], UI.prototype, "draggable", void 0);
6915
7060
  __decorate([
6916
7061
  dataType()
6917
- ], UI.prototype, "editorStyle", void 0);
7062
+ ], UI.prototype, "dragBounds", void 0);
7063
+ __decorate([
7064
+ dataType(false)
7065
+ ], UI.prototype, "editable", void 0);
6918
7066
  __decorate([
6919
7067
  hitType(true)
6920
7068
  ], UI.prototype, "hittable", void 0);
@@ -6969,21 +7117,6 @@ __decorate([
6969
7117
  __decorate([
6970
7118
  strokeType(10)
6971
7119
  ], UI.prototype, "miterLimit", void 0);
6972
- __decorate([
6973
- dataType(false)
6974
- ], UI.prototype, "lazy", void 0);
6975
- __decorate([
6976
- naturalBoundsType(1)
6977
- ], UI.prototype, "pixelRatio", void 0);
6978
- __decorate([
6979
- pathInputType()
6980
- ], UI.prototype, "path", void 0);
6981
- __decorate([
6982
- pathType()
6983
- ], UI.prototype, "windingRule", void 0);
6984
- __decorate([
6985
- pathType(true)
6986
- ], UI.prototype, "closed", void 0);
6987
7120
  __decorate([
6988
7121
  arrowType('none')
6989
7122
  ], UI.prototype, "startArrow", void 0);
@@ -7106,7 +7239,6 @@ Group = __decorate([
7106
7239
  var Leafer_1;
7107
7240
  const debug$1 = Debug.get('Leafer');
7108
7241
  let Leafer = Leafer_1 = class Leafer extends Group {
7109
- static get version() { return '1.0.0-rc.21'; }
7110
7242
  get __tag() { return 'Leafer'; }
7111
7243
  get isApp() { return false; }
7112
7244
  get app() { return this.parent || this; }
@@ -7159,7 +7291,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7159
7291
  if (this.isApp)
7160
7292
  this.__setApp();
7161
7293
  this.__checkAutoLayout(config);
7162
- this.updateLazyBounds();
7163
7294
  this.view = canvas.view;
7164
7295
  if (parentApp) {
7165
7296
  this.__bindApp(parentApp);
@@ -7219,9 +7350,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7219
7350
  const data = DataHelper.copyAttrs({}, size, canvasSizeAttrs);
7220
7351
  Object.keys(data).forEach(key => this[key] = data[key]);
7221
7352
  }
7222
- forceFullRender() {
7223
- this.forceRender();
7224
- }
7225
7353
  forceRender(bounds) {
7226
7354
  this.renderer.addBlock(bounds ? new Bounds(bounds) : this.canvas.bounds);
7227
7355
  if (this.viewReady)
@@ -7299,7 +7427,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7299
7427
  this.canvas.backgroundColor = newValue;
7300
7428
  }
7301
7429
  else {
7302
- this.forceFullRender();
7430
+ this.forceRender();
7303
7431
  }
7304
7432
  }
7305
7433
  __onCreated() {
@@ -7403,6 +7531,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7403
7531
  __listenEvents() {
7404
7532
  const runId = Run.start('FirstCreate ' + this.innerName);
7405
7533
  this.once(LeaferEvent.START, () => Run.end(runId));
7534
+ this.once(LayoutEvent.START, () => this.updateLazyBounds());
7406
7535
  this.once(LayoutEvent.END, () => this.__onReady());
7407
7536
  this.once(RenderEvent.START, () => this.__onCreated());
7408
7537
  this.once(RenderEvent.END, () => this.__onViewReady());
@@ -7509,6 +7638,8 @@ let Box = class Box extends Group {
7509
7638
  else {
7510
7639
  this.__updateRectBoxBounds();
7511
7640
  }
7641
+ if (data.flow)
7642
+ this.__updateContentBounds();
7512
7643
  }
7513
7644
  __updateStrokeBounds() { }
7514
7645
  __updateRenderBounds() {
@@ -7918,9 +8049,10 @@ Canvas = __decorate([
7918
8049
  registerUI()
7919
8050
  ], Canvas);
7920
8051
 
7921
- const { copyAndSpread, includes, spread, setList } = BoundsHelper;
8052
+ const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
7922
8053
  let Text = class Text extends UI {
7923
8054
  get __tag() { return 'Text'; }
8055
+ get editInner() { return 'TextEditor'; }
7924
8056
  get textDrawData() {
7925
8057
  this.__layout.update();
7926
8058
  return this.__.__textDrawData;
@@ -7990,7 +8122,7 @@ let Text = class Text extends UI {
7990
8122
  if (italic)
7991
8123
  b.width += fontSize * 0.16;
7992
8124
  const contentBounds = includes(b, bounds) ? b : bounds;
7993
- if (contentBounds !== layout.contentBounds) {
8125
+ if (!isSame$1(contentBounds, layout.contentBounds)) {
7994
8126
  layout.contentBounds = contentBounds;
7995
8127
  layout.renderChanged = true;
7996
8128
  setList(data.__textBoxBounds = {}, [b, bounds]);
@@ -8018,9 +8150,6 @@ __decorate([
8018
8150
  __decorate([
8019
8151
  boundsType(0)
8020
8152
  ], Text.prototype, "height", void 0);
8021
- __decorate([
8022
- boundsType(0)
8023
- ], Text.prototype, "padding", void 0);
8024
8153
  __decorate([
8025
8154
  surfaceType('#000000')
8026
8155
  ], Text.prototype, "fill", void 0);
@@ -8149,7 +8278,7 @@ function penPathType() {
8149
8278
  };
8150
8279
  }
8151
8280
 
8152
- const version = "1.0.0-rc.21";
8281
+ const version = "1.0.0-rc.23";
8153
8282
 
8154
8283
  function fillText(ui, canvas) {
8155
8284
  let row;
@@ -8370,7 +8499,7 @@ function shape(ui, current, options) {
8370
8499
  }
8371
8500
  else {
8372
8501
  const { renderShapeSpread: spread } = ui.__layout;
8373
- const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, spread * scaleX, spread * scaleY) : current.bounds, nowWorld);
8502
+ const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [spread * scaleY, spread * scaleX]) : current.bounds, nowWorld);
8374
8503
  fitMatrix = current.bounds.getFitMatrix(worldClipBounds);
8375
8504
  let { a: fitScaleX, d: fitScaleY } = fitMatrix;
8376
8505
  if (fitMatrix.a < 1) {
@@ -8453,79 +8582,75 @@ const PaintModule = {
8453
8582
 
8454
8583
  let origin = {};
8455
8584
  const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
8456
- function fillOrFitMode(data, mode, box, width, height, rotation) {
8585
+ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
8457
8586
  const transform = get$4();
8458
- const swap = rotation && rotation !== 180;
8459
- const sw = box.width / (swap ? height : width);
8460
- const sh = box.height / (swap ? width : height);
8461
- const scale = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
8462
- const x = box.x + (box.width - width * scale) / 2;
8463
- const y = box.y + (box.height - height * scale) / 2;
8464
- translate$1(transform, x, y);
8465
- scaleHelper(transform, scale);
8587
+ translate$1(transform, box.x + x, box.y + y);
8588
+ scaleHelper(transform, scaleX, scaleY);
8466
8589
  if (rotation)
8467
8590
  rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
8468
- data.scaleX = data.scaleY = scale;
8469
8591
  data.transform = transform;
8470
8592
  }
8471
8593
  function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
8472
8594
  const transform = get$4();
8473
- translate$1(transform, box.x, box.y);
8474
- if (x || y)
8475
- translate$1(transform, x, y);
8476
- if (scaleX) {
8595
+ translate$1(transform, box.x + x, box.y + y);
8596
+ if (scaleX)
8477
8597
  scaleHelper(transform, scaleX, scaleY);
8478
- data.scaleX = transform.a;
8479
- data.scaleY = transform.d;
8480
- }
8481
8598
  if (rotation)
8482
8599
  rotate(transform, rotation);
8483
8600
  data.transform = transform;
8484
8601
  }
8485
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation) {
8602
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
8486
8603
  const transform = get$4();
8487
8604
  if (rotation) {
8488
- rotate(transform, rotation);
8489
- switch (rotation) {
8490
- case 90:
8491
- translate$1(transform, height, 0);
8492
- break;
8493
- case 180:
8494
- translate$1(transform, width, height);
8495
- break;
8496
- case 270:
8497
- translate$1(transform, 0, width);
8498
- break;
8605
+ if (align === 'center') {
8606
+ rotateOfOuter$2(transform, { x: width / 2, y: height / 2 }, rotation);
8607
+ }
8608
+ else {
8609
+ rotate(transform, rotation);
8610
+ switch (rotation) {
8611
+ case 90:
8612
+ translate$1(transform, height, 0);
8613
+ break;
8614
+ case 180:
8615
+ translate$1(transform, width, height);
8616
+ break;
8617
+ case 270:
8618
+ translate$1(transform, 0, width);
8619
+ break;
8620
+ }
8499
8621
  }
8500
8622
  }
8501
- origin.x = box.x;
8502
- origin.y = box.y;
8503
- if (x || y)
8504
- origin.x += x, origin.y += y;
8623
+ origin.x = box.x + x;
8624
+ origin.y = box.y + y;
8505
8625
  translate$1(transform, origin.x, origin.y);
8506
- if (scaleX) {
8626
+ if (scaleX)
8507
8627
  scaleOfOuter$2(transform, origin, scaleX, scaleY);
8508
- data.scaleX = scaleX;
8509
- data.scaleY = scaleY;
8510
- }
8511
8628
  data.transform = transform;
8512
8629
  }
8513
8630
 
8514
8631
  const { get: get$3, translate } = MatrixHelper;
8515
8632
  const tempBox = new Bounds();
8633
+ const tempPoint = {};
8516
8634
  function createData(leafPaint, image, paint, box) {
8517
8635
  let { width, height } = image;
8518
8636
  if (paint.padding)
8519
8637
  box = tempBox.set(box).shrink(paint.padding);
8520
- const { opacity, mode, offset, scale, size, rotation, blendMode, repeat } = paint;
8638
+ const { opacity, mode, align, offset, scale, size, rotation, blendMode, repeat } = paint;
8521
8639
  const sameBox = box.width === width && box.height === height;
8522
8640
  if (blendMode)
8523
8641
  leafPaint.blendMode = blendMode;
8524
8642
  const data = leafPaint.data = { mode };
8525
- let x, y, scaleX, scaleY;
8526
- if (offset)
8527
- x = offset.x, y = offset.y;
8528
- if (size) {
8643
+ const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
8644
+ const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
8645
+ let x = 0, y = 0, scaleX, scaleY;
8646
+ if (!mode || mode === 'cover' || mode === 'fit') {
8647
+ if (!sameBox || rotation) {
8648
+ const sw = box.width / swapWidth, sh = box.height / swapHeight;
8649
+ scaleX = scaleY = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
8650
+ x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
8651
+ }
8652
+ }
8653
+ else if (size) {
8529
8654
  scaleX = (typeof size === 'number' ? size : size.width) / width;
8530
8655
  scaleY = (typeof size === 'number' ? size : size.height) / height;
8531
8656
  }
@@ -8533,26 +8658,36 @@ function createData(leafPaint, image, paint, box) {
8533
8658
  scaleX = typeof scale === 'number' ? scale : scale.x;
8534
8659
  scaleY = typeof scale === 'number' ? scale : scale.y;
8535
8660
  }
8661
+ if (align) {
8662
+ const imageBounds = { x, y, width: swapWidth, height: swapHeight };
8663
+ if (scaleX)
8664
+ imageBounds.width *= scaleX, imageBounds.height *= scaleY;
8665
+ AlignHelper.toPoint(align, imageBounds, box, tempPoint, true);
8666
+ x += tempPoint.x, y += tempPoint.y;
8667
+ }
8668
+ if (offset)
8669
+ x += offset.x, y += offset.y;
8536
8670
  switch (mode) {
8537
8671
  case 'strench':
8538
8672
  if (!sameBox)
8539
8673
  width = box.width, height = box.height;
8540
8674
  break;
8675
+ case 'normal':
8541
8676
  case 'clip':
8542
- if (offset || scaleX || rotation)
8677
+ if (x || y || scaleX || rotation)
8543
8678
  clipMode(data, box, x, y, scaleX, scaleY, rotation);
8544
8679
  break;
8545
8680
  case 'repeat':
8546
8681
  if (!sameBox || scaleX || rotation)
8547
- repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation);
8682
+ repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align);
8548
8683
  if (!repeat)
8549
8684
  data.repeat = 'repeat';
8550
8685
  break;
8551
8686
  case 'fit':
8552
8687
  case 'cover':
8553
8688
  default:
8554
- if (!sameBox || rotation)
8555
- fillOrFitMode(data, mode, box, width, height, rotation);
8689
+ if (scaleX)
8690
+ fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation);
8556
8691
  }
8557
8692
  if (!data.transform) {
8558
8693
  if (box.x || box.y) {
@@ -8560,6 +8695,10 @@ function createData(leafPaint, image, paint, box) {
8560
8695
  translate(data.transform, box.x, box.y);
8561
8696
  }
8562
8697
  }
8698
+ if (scaleX && mode !== 'strench') {
8699
+ data.scaleX = scaleX;
8700
+ data.scaleY = scaleY;
8701
+ }
8563
8702
  data.width = width;
8564
8703
  data.height = height;
8565
8704
  if (opacity)
@@ -9457,11 +9596,13 @@ function clipText(drawData, style) {
9457
9596
  const { rows, overflow } = drawData;
9458
9597
  let { textOverflow } = style;
9459
9598
  rows.splice(overflow);
9460
- if (textOverflow !== 'hide') {
9461
- if (textOverflow === 'ellipsis')
9599
+ if (textOverflow && textOverflow !== 'show') {
9600
+ if (textOverflow === 'hide')
9601
+ textOverflow = '';
9602
+ else if (textOverflow === 'ellipsis')
9462
9603
  textOverflow = '...';
9463
9604
  let char, charRight;
9464
- const ellipsisWidth = Platform.canvas.measureText(textOverflow).width;
9605
+ const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
9465
9606
  const right = style.x + style.width - ellipsisWidth;
9466
9607
  const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
9467
9608
  list.forEach(row => {
@@ -9615,6 +9756,13 @@ const ExportModule = {
9615
9756
  resolve();
9616
9757
  this.running = false;
9617
9758
  };
9759
+ if (filename === 'json') {
9760
+ return over({ data: leaf.toJSON() });
9761
+ }
9762
+ else if (FileHelper.fileType(filename) === 'json') {
9763
+ Platform.origin.download('data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(leaf.toJSON())), filename);
9764
+ return over({ data: true });
9765
+ }
9618
9766
  const { leafer } = leaf;
9619
9767
  if (leafer) {
9620
9768
  leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
@@ -9622,8 +9770,12 @@ const ExportModule = {
9622
9770
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
9623
9771
  const { worldTransform, isLeafer, isFrame } = leaf;
9624
9772
  const { slice, trim, onCanvas } = options;
9625
- const scale = options.scale || 1;
9626
- const pixelRatio = options.pixelRatio || 1;
9773
+ let scale = options.scale || 1;
9774
+ let pixelRatio = options.pixelRatio || 1;
9775
+ if (leaf.isApp) {
9776
+ scale *= pixelRatio;
9777
+ pixelRatio = leaf.app.pixelRatio;
9778
+ }
9627
9779
  const screenshot = options.screenshot || leaf.isApp;
9628
9780
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
9629
9781
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -9753,4 +9905,4 @@ Object.assign(Export, ExportModule);
9753
9905
 
9754
9906
  useCanvas();
9755
9907
 
9756
- export { AnimateEvent, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, DataHelper, Debug, Direction4, Direction9, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, Image, ImageData, ImageEvent, ImageManager, IncrementId, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, Line, LineData, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Point, PointHelper, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Run, Star, StarData, State, StringNumberMap, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, 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, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, stateType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$2 as tempPoint, useCanvas, useModule, version, zoomLayerType };
9908
+ export { AlignHelper, AnimateEvent, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, DataHelper, Debug, Direction4, Direction9, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, Image, ImageData, ImageEvent, ImageManager, IncrementId, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, Line, LineData, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Point, PointHelper, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Run, Star, StarData, State, StringNumberMap, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, 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, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, stateType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, zoomLayerType };