leafer-ui 1.0.0-rc.22 → 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.
package/dist/web.js CHANGED
@@ -6,7 +6,7 @@ var LeaferUI = (function (exports) {
6
6
  hitCanvasSize: 100,
7
7
  maxCacheSize: 2560 * 1600,
8
8
  maxPatternSize: 4096 * 2160,
9
- suffix: 'leaf',
9
+ suffix: '',
10
10
  crossOrigin: 'anonymous'
11
11
  }
12
12
  };
@@ -36,24 +36,12 @@ var LeaferUI = (function (exports) {
36
36
  const { round, pow: pow$1, PI: PI$4 } = Math;
37
37
  const MathHelper = {
38
38
  within(value, min, max) {
39
- if (value < min)
39
+ if (min !== undefined && value < min)
40
40
  value = min;
41
- if (value > max)
41
+ if (max !== undefined && value > max)
42
42
  value = max;
43
43
  return value;
44
44
  },
45
- minus(value, isFourNumber) {
46
- if (value instanceof Array) {
47
- if (isFourNumber)
48
- value = MathHelper.fourNumber(value, 0);
49
- for (let i = 0; i < value.length; i++)
50
- value[i] = -value[i];
51
- }
52
- else {
53
- value = -value;
54
- }
55
- return value;
56
- },
57
45
  fourNumber(num, maxValue) {
58
46
  let data;
59
47
  if (num instanceof Array) {
@@ -150,9 +138,11 @@ var LeaferUI = (function (exports) {
150
138
  t.e += x;
151
139
  t.f += y;
152
140
  },
153
- translateInner(t, x, y) {
141
+ translateInner(t, x, y, isMoveOrigin) {
154
142
  t.e += t.a * x + t.c * y;
155
143
  t.f += t.b * x + t.d * y;
144
+ if (isMoveOrigin)
145
+ t.e -= x, t.f -= y;
156
146
  },
157
147
  scale(t, scaleX, scaleY = scaleX) {
158
148
  t.a *= scaleX;
@@ -219,8 +209,10 @@ var LeaferUI = (function (exports) {
219
209
  t.e = child.e * a + child.f * c + e;
220
210
  t.f = child.e * b + child.f * d + f;
221
211
  },
222
- multiplyParent(t, parent, to, abcdChanged, childScaleData) {
223
- const { e, f } = t;
212
+ multiplyParent(t, parent, to, abcdChanged, childScaleData, scrollData) {
213
+ let { e, f } = t;
214
+ if (scrollData)
215
+ e += scrollData.scrollX, f += scrollData.scrollY;
224
216
  to || (to = t);
225
217
  if (abcdChanged === undefined)
226
218
  abcdChanged = t.a !== 1 || t.b || t.c || t.d !== 1;
@@ -341,7 +333,7 @@ var LeaferUI = (function (exports) {
341
333
  t.e = x;
342
334
  t.f = y;
343
335
  if (origin)
344
- M$6.translateInner(t, -origin.x, -origin.y);
336
+ M$6.translateInner(t, -origin.x, -origin.y, true);
345
337
  },
346
338
  getLayout(t, origin, firstSkewY) {
347
339
  const { a, b, c, d, e, f } = t;
@@ -761,7 +753,7 @@ var LeaferUI = (function (exports) {
761
753
  const { floor, ceil: ceil$2 } = Math;
762
754
  let right$1, bottom$1, boundsRight, boundsBottom;
763
755
  const point = {};
764
- const toPoint$1 = {};
756
+ const toPoint$2 = {};
765
757
  const BoundsHelper = {
766
758
  tempBounds: {},
767
759
  set(t, x = 0, y = 0, width = 0, height = 0) {
@@ -776,15 +768,17 @@ var LeaferUI = (function (exports) {
776
768
  t.width = bounds.width;
777
769
  t.height = bounds.height;
778
770
  },
779
- copyAndSpread(t, bounds, spreadX, spreadY) {
780
- if (spreadX instanceof Array) {
781
- const four = fourNumber(spreadX);
782
- B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
771
+ copyAndSpread(t, bounds, spread, isShrink) {
772
+ if (spread instanceof Array) {
773
+ const four = fourNumber(spread);
774
+ isShrink
775
+ ? B.set(t, bounds.x + four[3], bounds.y + four[0], bounds.width - four[1] - four[3], bounds.height - four[2] - four[0])
776
+ : B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
783
777
  }
784
778
  else {
785
- if (!spreadY)
786
- spreadY = spreadX;
787
- B.set(t, bounds.x - spreadX, bounds.y - spreadY, bounds.width + spreadX * 2, bounds.height + spreadY * 2);
779
+ if (isShrink)
780
+ spread = -spread;
781
+ B.set(t, bounds.x - spread, bounds.y - spread, bounds.width + spread * 2, bounds.height + spread * 2);
788
782
  }
789
783
  },
790
784
  minX(t) { return t.width > 0 ? t.x : t.x + t.width; },
@@ -861,17 +855,17 @@ var LeaferUI = (function (exports) {
861
855
  else {
862
856
  point.x = t.x;
863
857
  point.y = t.y;
864
- toOuterPoint$1(matrix, point, toPoint$1);
865
- setPoint$3(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
858
+ toOuterPoint$1(matrix, point, toPoint$2);
859
+ setPoint$3(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
866
860
  point.x = t.x + t.width;
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.y = t.y + t.height;
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
  point.x = t.x;
873
- toOuterPoint$1(matrix, point, toPoint$1);
874
- addPoint$3(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
867
+ toOuterPoint$1(matrix, point, toPoint$2);
868
+ addPoint$3(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
875
869
  toBounds$4(tempPointBounds$1, to);
876
870
  }
877
871
  },
@@ -884,13 +878,16 @@ var LeaferUI = (function (exports) {
884
878
  const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
885
879
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
886
880
  },
887
- getSpread(t, spreadX, spreadY) {
881
+ getSpread(t, spread) {
888
882
  const n = {};
889
- B.copyAndSpread(n, t, spreadX, spreadY);
883
+ B.copyAndSpread(n, t, spread);
890
884
  return n;
891
885
  },
892
- spread(t, spreadX, spreadY = spreadX) {
893
- B.copyAndSpread(t, t, spreadX, spreadY);
886
+ spread(t, spread) {
887
+ B.copyAndSpread(t, t, spread);
888
+ },
889
+ shrink(t, shrink) {
890
+ B.copyAndSpread(t, t, shrink, true);
894
891
  },
895
892
  ceil(t) {
896
893
  const { x, y } = t;
@@ -1070,12 +1067,12 @@ var LeaferUI = (function (exports) {
1070
1067
  getFitMatrix(put, baseScale) {
1071
1068
  return BoundsHelper.getFitMatrix(this, put, baseScale);
1072
1069
  }
1073
- spread(fourNumber, spreadY) {
1074
- BoundsHelper.spread(this, fourNumber, spreadY);
1070
+ spread(fourNumber) {
1071
+ BoundsHelper.spread(this, fourNumber);
1075
1072
  return this;
1076
1073
  }
1077
1074
  shrink(fourNumber) {
1078
- BoundsHelper.spread(this, MathHelper.minus(fourNumber, true));
1075
+ BoundsHelper.shrink(this, fourNumber);
1079
1076
  return this;
1080
1077
  }
1081
1078
  ceil() {
@@ -1192,6 +1189,10 @@ var LeaferUI = (function (exports) {
1192
1189
  Direction9[Direction9["bottomLeft"] = 6] = "bottomLeft";
1193
1190
  Direction9[Direction9["left"] = 7] = "left";
1194
1191
  Direction9[Direction9["center"] = 8] = "center";
1192
+ Direction9[Direction9["top-left"] = 0] = "top-left";
1193
+ Direction9[Direction9["top-right"] = 2] = "top-right";
1194
+ Direction9[Direction9["bottom-right"] = 4] = "bottom-right";
1195
+ Direction9[Direction9["bottom-left"] = 6] = "bottom-left";
1195
1196
  })(exports.Direction9 || (exports.Direction9 = {}));
1196
1197
 
1197
1198
  const directionData = [
@@ -1205,6 +1206,7 @@ var LeaferUI = (function (exports) {
1205
1206
  { x: 0, y: 0.5 },
1206
1207
  { x: 0.5, y: 0.5 }
1207
1208
  ];
1209
+ directionData.forEach(item => item.type = 'percent');
1208
1210
  const AroundHelper = {
1209
1211
  directionData,
1210
1212
  tempPoint: {},
@@ -1212,15 +1214,19 @@ var LeaferUI = (function (exports) {
1212
1214
  toPoint(around, bounds, to, onlySize, pointBounds) {
1213
1215
  to || (to = {});
1214
1216
  const point = get$5(around);
1215
- to.x = point.x * bounds.width;
1216
- to.y = point.y * bounds.height;
1217
- if (pointBounds) {
1218
- to.x -= pointBounds.x;
1219
- to.y -= pointBounds.y;
1220
- if (point.x)
1221
- to.x -= (point.x === 1) ? pointBounds.width : (point.x === 0.5 ? point.x * pointBounds.width : 0);
1222
- if (point.y)
1223
- to.y -= (point.y === 1) ? pointBounds.height : (point.y === 0.5 ? point.y * pointBounds.height : 0);
1217
+ to.x = point.x;
1218
+ to.y = point.y;
1219
+ if (point.type === 'percent') {
1220
+ to.x *= bounds.width;
1221
+ to.y *= bounds.height;
1222
+ if (pointBounds) {
1223
+ to.x -= pointBounds.x;
1224
+ to.y -= pointBounds.y;
1225
+ if (point.x)
1226
+ to.x -= (point.x === 1) ? pointBounds.width : (point.x === 0.5 ? point.x * pointBounds.width : 0);
1227
+ if (point.y)
1228
+ to.y -= (point.y === 1) ? pointBounds.height : (point.y === 0.5 ? point.y * pointBounds.height : 0);
1229
+ }
1224
1230
  }
1225
1231
  if (!onlySize) {
1226
1232
  to.x += bounds.x;
@@ -1232,6 +1238,13 @@ var LeaferUI = (function (exports) {
1232
1238
  return typeof around === 'string' ? directionData[exports.Direction9[around]] : around;
1233
1239
  }
1234
1240
 
1241
+ const { toPoint: toPoint$1 } = AroundHelper;
1242
+ const AlignHelper = {
1243
+ toPoint(align, contentBounds, bounds, to, onlySize) {
1244
+ toPoint$1(align, bounds, to, onlySize, contentBounds);
1245
+ }
1246
+ };
1247
+
1235
1248
  const StringNumberMap = {
1236
1249
  '0': 1,
1237
1250
  '1': 1,
@@ -1464,13 +1477,19 @@ var LeaferUI = (function (exports) {
1464
1477
  },
1465
1478
  clone(data) {
1466
1479
  return JSON.parse(JSON.stringify(data));
1480
+ },
1481
+ toMap(list) {
1482
+ const map = {};
1483
+ for (let i = 0, len = list.length; i < len; i++)
1484
+ map[list[i]] = true;
1485
+ return map;
1467
1486
  }
1468
1487
  };
1469
1488
  const { assign } = DataHelper;
1470
1489
 
1471
1490
  class LeafData {
1472
1491
  get __blendMode() {
1473
- if (this.eraser)
1492
+ if (this.eraser && this.eraser !== 'path')
1474
1493
  return 'destination-out';
1475
1494
  const { blendMode } = this;
1476
1495
  return blendMode === 'pass-through' ? null : blendMode;
@@ -2100,7 +2119,7 @@ var LeaferUI = (function (exports) {
2100
2119
  }
2101
2120
  clear() {
2102
2121
  const { pixelRatio } = this;
2103
- this.clearRect(0, 0, this.width * pixelRatio, this.height * pixelRatio);
2122
+ this.clearRect(0, 0, this.width * pixelRatio + 2, this.height * pixelRatio + 2);
2104
2123
  }
2105
2124
  isSameSize(size) {
2106
2125
  return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
@@ -3756,6 +3775,8 @@ var LeaferUI = (function (exports) {
3756
3775
  this.__setAttr(key, value);
3757
3776
  this.__layout.boxChanged || this.__layout.boxChange();
3758
3777
  this.waitParent(() => { this.parent.__updateMask(value); });
3778
+ if (typeof value === 'string')
3779
+ this.maskType = value;
3759
3780
  }
3760
3781
  }));
3761
3782
  }
@@ -4185,11 +4206,19 @@ var LeaferUI = (function (exports) {
4185
4206
 
4186
4207
  const { getRelativeWorld: getRelativeWorld$1 } = LeafHelper;
4187
4208
  const { toOuterOf: toOuterOf$2, getPoints, copy: copy$6 } = BoundsHelper;
4209
+ const localContent = '_localContentBounds';
4210
+ const worldContent = '_worldContentBounds', worldBox = '_worldBoxBounds', worldStroke = '_worldStrokeBounds';
4188
4211
  class LeafLayout {
4212
+ get contentBounds() { return this._contentBounds || this.boxBounds; }
4213
+ set contentBounds(bounds) { this._contentBounds = bounds; }
4189
4214
  get strokeBounds() { return this._strokeBounds || this.boxBounds; }
4190
4215
  get renderBounds() { return this._renderBounds || this.boxBounds; }
4216
+ get localContentBounds() { toOuterOf$2(this.contentBounds, this.leaf.__localMatrix, this[localContent] || (this[localContent] = {})); return this[localContent]; }
4191
4217
  get localStrokeBounds() { return this._localStrokeBounds || this; }
4192
4218
  get localRenderBounds() { return this._localRenderBounds || this; }
4219
+ get worldContentBounds() { toOuterOf$2(this.contentBounds, this.leaf.__world, this[worldContent] || (this[worldContent] = {})); return this[worldContent]; }
4220
+ get worldBoxBounds() { toOuterOf$2(this.boxBounds, this.leaf.__world, this[worldBox] || (this[worldBox] = {})); return this[worldBox]; }
4221
+ get worldStrokeBounds() { toOuterOf$2(this.strokeBounds, this.leaf.__world, this[worldStroke] || (this[worldStroke] = {})); return this[worldStroke]; }
4193
4222
  get a() { return 1; }
4194
4223
  get b() { return 0; }
4195
4224
  get c() { return 0; }
@@ -4272,7 +4301,6 @@ var LeaferUI = (function (exports) {
4272
4301
  case 'content':
4273
4302
  if (this.contentBounds)
4274
4303
  return this.contentBounds;
4275
- case 'margin':
4276
4304
  case 'box':
4277
4305
  return this.boxBounds;
4278
4306
  case 'stroke':
@@ -4285,8 +4313,9 @@ var LeaferUI = (function (exports) {
4285
4313
  return this.localRenderBounds;
4286
4314
  case 'stroke':
4287
4315
  return this.localStrokeBounds;
4288
- case 'margin':
4289
4316
  case 'content':
4317
+ if (this.contentBounds)
4318
+ return this.localContentBounds;
4290
4319
  case 'box':
4291
4320
  return this.leaf.__localBoxBounds;
4292
4321
  }
@@ -4295,15 +4324,13 @@ var LeaferUI = (function (exports) {
4295
4324
  switch (type) {
4296
4325
  case 'render':
4297
4326
  return this.leaf.__world;
4327
+ case 'stroke':
4328
+ return this.worldStrokeBounds;
4298
4329
  case 'content':
4299
4330
  if (this.contentBounds)
4300
- return this.getWorldContentBounds();
4301
- case 'margin':
4331
+ return this.worldContentBounds;
4302
4332
  case 'box':
4303
- return this.getWorldBoxBounds();
4304
- case 'margin':
4305
- case 'stroke':
4306
- return this.getWorldStrokeBounds();
4333
+ return this.worldBoxBounds;
4307
4334
  }
4308
4335
  }
4309
4336
  getLayoutBounds(type, relative = 'world', unscale) {
@@ -4366,20 +4393,24 @@ var LeaferUI = (function (exports) {
4366
4393
  points.forEach(point => leaf.innerToWorld(point, null, false, relativeLeaf));
4367
4394
  return points;
4368
4395
  }
4369
- getWorldContentBounds() {
4370
- this._worldContentBounds || (this._worldContentBounds = {});
4371
- toOuterOf$2(this.contentBounds, this.leaf.__world, this._worldContentBounds);
4372
- return this._worldContentBounds;
4396
+ shrinkContent() {
4397
+ const { x, y, width, height } = this.boxBounds;
4398
+ this._contentBounds = { x, y, width, height };
4399
+ }
4400
+ spreadStroke() {
4401
+ const { x, y, width, height } = this.strokeBounds;
4402
+ this._strokeBounds = { x, y, width, height };
4403
+ this._localStrokeBounds = { x, y, width, height };
4404
+ if (!this.renderSpread)
4405
+ this.spreadRenderCancel();
4373
4406
  }
4374
- getWorldBoxBounds() {
4375
- this._worldBoxBounds || (this._worldBoxBounds = {});
4376
- toOuterOf$2(this.boxBounds, this.leaf.__world, this._worldBoxBounds);
4377
- return this._worldBoxBounds;
4407
+ spreadRender() {
4408
+ const { x, y, width, height } = this.renderBounds;
4409
+ this._renderBounds = { x, y, width, height };
4410
+ this._localRenderBounds = { x, y, width, height };
4378
4411
  }
4379
- getWorldStrokeBounds() {
4380
- this._worldStrokeBounds || (this._worldStrokeBounds = {});
4381
- toOuterOf$2(this.strokeBounds, this.leaf.__world, this._worldStrokeBounds);
4382
- return this._worldStrokeBounds;
4412
+ shrinkContentCancel() {
4413
+ this._contentBounds = undefined;
4383
4414
  }
4384
4415
  spreadStrokeCancel() {
4385
4416
  const same = this.renderBounds === this.strokeBounds;
@@ -4392,18 +4423,6 @@ var LeaferUI = (function (exports) {
4392
4423
  this._renderBounds = this._strokeBounds;
4393
4424
  this._localRenderBounds = this._localStrokeBounds;
4394
4425
  }
4395
- spreadStroke() {
4396
- const { x, y, width, height } = this.strokeBounds;
4397
- this._strokeBounds = { x, y, width, height };
4398
- this._localStrokeBounds = { x, y, width, height };
4399
- if (!this.renderSpread)
4400
- this.spreadRenderCancel();
4401
- }
4402
- spreadRender() {
4403
- const { x, y, width, height } = this.renderBounds;
4404
- this._renderBounds = { x, y, width, height };
4405
- this._localRenderBounds = { x, y, width, height };
4406
- }
4407
4426
  boxChange() {
4408
4427
  this.boxChanged = true;
4409
4428
  this.localBoxChanged || this.localBoxChange();
@@ -4490,24 +4509,40 @@ var LeaferUI = (function (exports) {
4490
4509
  });
4491
4510
  },
4492
4511
  off(type, listener, options) {
4493
- let capture;
4494
- if (options)
4495
- capture = typeof options === 'boolean' ? options : options.capture;
4496
- let events, index;
4497
- const map = __getListenerMap(this, capture);
4498
- const typeList = typeof type === 'string' ? type.split(' ') : type;
4499
- typeList.forEach(type => {
4500
- if (type) {
4501
- events = map[type];
4502
- if (events) {
4503
- index = events.findIndex(item => item.listener === listener);
4504
- if (index > -1)
4505
- events.splice(index, 1);
4506
- if (!events.length)
4507
- delete map[type];
4508
- }
4512
+ if (type) {
4513
+ const typeList = typeof type === 'string' ? type.split(' ') : type;
4514
+ if (listener) {
4515
+ let capture;
4516
+ if (options)
4517
+ capture = typeof options === 'boolean' ? options : options.capture;
4518
+ let events, index;
4519
+ const map = __getListenerMap(this, capture);
4520
+ typeList.forEach(type => {
4521
+ if (type) {
4522
+ events = map[type];
4523
+ if (events) {
4524
+ index = events.findIndex(item => item.listener === listener);
4525
+ if (index > -1)
4526
+ events.splice(index, 1);
4527
+ if (!events.length)
4528
+ delete map[type];
4529
+ }
4530
+ }
4531
+ });
4509
4532
  }
4510
- });
4533
+ else {
4534
+ const { __bubbleMap: b, __captureMap: c } = this;
4535
+ typeList.forEach(type => {
4536
+ if (b)
4537
+ delete b[type];
4538
+ if (c)
4539
+ delete c[type];
4540
+ });
4541
+ }
4542
+ }
4543
+ else {
4544
+ this.__bubbleMap = this.__captureMap = undefined;
4545
+ }
4511
4546
  },
4512
4547
  on_(type, listener, bind, options) {
4513
4548
  if (bind)
@@ -4774,7 +4809,7 @@ var LeaferUI = (function (exports) {
4774
4809
  const { toPoint, tempPoint: tempPoint$1 } = AroundHelper;
4775
4810
  const LeafMatrix = {
4776
4811
  __updateWorldMatrix() {
4777
- multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__);
4812
+ multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__, this.parent && this.parent.__);
4778
4813
  },
4779
4814
  __updateLocalMatrix() {
4780
4815
  if (this.__local) {
@@ -4785,11 +4820,11 @@ var LeaferUI = (function (exports) {
4785
4820
  layout.scaleChanged = layout.rotationChanged = false;
4786
4821
  }
4787
4822
  }
4788
- local.e = data.x;
4789
- local.f = data.y;
4790
- if (data.around) {
4791
- toPoint(data.around, layout.boxBounds, tempPoint$1);
4792
- translateInner(local, -tempPoint$1.x, -tempPoint$1.y);
4823
+ local.e = data.x + data.offsetX;
4824
+ local.f = data.y + data.offsetY;
4825
+ if (data.around || data.origin) {
4826
+ toPoint(data.around || data.origin, layout.boxBounds, tempPoint$1);
4827
+ translateInner(local, -tempPoint$1.x, -tempPoint$1.y, data.origin);
4793
4828
  }
4794
4829
  }
4795
4830
  this.__layout.matrixChanged = false;
@@ -4895,6 +4930,8 @@ var LeaferUI = (function (exports) {
4895
4930
  if (this.isBranch) {
4896
4931
  if (this.leafer)
4897
4932
  this.leafer.layouter.addExtra(this);
4933
+ if (this.__.flow)
4934
+ this.__updateFlowLayout();
4898
4935
  if (hasParentAutoLayout(this)) {
4899
4936
  updateMatrix$1(this);
4900
4937
  }
@@ -4927,6 +4964,8 @@ var LeaferUI = (function (exports) {
4927
4964
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
4928
4965
  canvas.opacity = this.__.opacity;
4929
4966
  if (this.__.__single) {
4967
+ if (this.__.eraser === 'path')
4968
+ return this.__renderEraser(canvas, options);
4930
4969
  const tempCanvas = canvas.getSameCanvas(true, true);
4931
4970
  this.__draw(tempCanvas, options);
4932
4971
  if (this.__worldFlipped) {
@@ -4969,6 +5008,8 @@ var LeaferUI = (function (exports) {
4969
5008
  __render(canvas, options) {
4970
5009
  if (this.__worldOpacity) {
4971
5010
  if (this.__.__single) {
5011
+ if (this.__.eraser === 'path')
5012
+ return this.__renderEraser(canvas, options);
4972
5013
  const tempCanvas = canvas.getSameCanvas(false, true);
4973
5014
  this.__renderBranch(tempCanvas, options);
4974
5015
  const nowWorld = this.__getNowWorld(options);
@@ -5108,7 +5149,9 @@ var LeaferUI = (function (exports) {
5108
5149
  setProxyAttr(_attrName, _newValue) { }
5109
5150
  getProxyAttr(_attrName) { return undefined; }
5110
5151
  find(_condition, _options) { return undefined; }
5152
+ findTag(_tag) { return undefined; }
5111
5153
  findOne(_condition, _options) { return undefined; }
5154
+ findId(_id) { return undefined; }
5112
5155
  focus(_value) { }
5113
5156
  forceUpdate(attrName) {
5114
5157
  if (attrName === undefined)
@@ -5130,9 +5173,11 @@ var LeaferUI = (function (exports) {
5130
5173
  __updateLocalStrokeBounds() { }
5131
5174
  __updateLocalRenderBounds() { }
5132
5175
  __updateBoxBounds() { }
5176
+ __updateContentBounds() { }
5133
5177
  __updateStrokeBounds() { }
5134
5178
  __updateRenderBounds() { }
5135
5179
  __updateAutoLayout() { }
5180
+ __updateFlowLayout() { }
5136
5181
  __updateNaturalSize() { }
5137
5182
  __updateStrokeSpread() { return 0; }
5138
5183
  __updateRenderSpread() { return 0; }
@@ -5140,6 +5185,13 @@ var LeaferUI = (function (exports) {
5140
5185
  __updateEraser(value) {
5141
5186
  this.__hasEraser = value ? true : this.children.some(item => item.__.eraser);
5142
5187
  }
5188
+ __renderEraser(canvas, options) {
5189
+ canvas.save();
5190
+ this.__clip(canvas, options);
5191
+ const { renderBounds: r } = this.__layout;
5192
+ canvas.clearRect(r.x, r.y, r.width, r.height);
5193
+ canvas.restore();
5194
+ }
5143
5195
  __updateMask(value) {
5144
5196
  this.__hasMask = value ? true : this.children.some(item => item.__.mask);
5145
5197
  }
@@ -5320,8 +5372,8 @@ var LeaferUI = (function (exports) {
5320
5372
  emit(_type, _event, _capture) { }
5321
5373
  emitEvent(_event, _capture) { }
5322
5374
  hasEvent(_type, _capture) { return false; }
5323
- static changeAttr(attrName, defaultValue) {
5324
- defineDataProcessor(this.prototype, attrName, defaultValue);
5375
+ static changeAttr(attrName, defaultValue, fn) {
5376
+ fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5325
5377
  }
5326
5378
  static addAttr(attrName, defaultValue, fn) {
5327
5379
  if (!fn)
@@ -5818,7 +5870,7 @@ var LeaferUI = (function (exports) {
5818
5870
  }
5819
5871
  img.onload = () => { resolve(img); };
5820
5872
  img.onerror = (e) => { reject(e); };
5821
- if (!src.startsWith('data:') && !src.startsWith('blob:') && suffix)
5873
+ if (suffix && !src.startsWith('data:') && !src.startsWith('blob:'))
5822
5874
  src += (src.includes("?") ? "&" : "?") + suffix;
5823
5875
  img.src = src;
5824
5876
  });
@@ -6380,8 +6432,11 @@ var LeaferUI = (function (exports) {
6380
6432
  if (!bounds.includes(this.target.__world) || this.needFill || !e.samePixelRatio) {
6381
6433
  this.addBlock(this.canvas.bounds);
6382
6434
  this.target.forceUpdate('surface');
6435
+ return;
6383
6436
  }
6384
6437
  }
6438
+ this.addBlock(new Bounds(0, 0, 1, 1));
6439
+ this.changed = true;
6385
6440
  }
6386
6441
  __onLayoutEnd(event) {
6387
6442
  if (event.data)
@@ -6554,6 +6609,7 @@ var LeaferUI = (function (exports) {
6554
6609
  }
6555
6610
 
6556
6611
  const { Yes, NoAndSkip, YesAndSkip } = exports.Answer;
6612
+ const idCondition = {}, classNameCondition = {}, tagCondition = {};
6557
6613
  class Selector {
6558
6614
  constructor(target, userConfig) {
6559
6615
  this.config = {};
@@ -6563,7 +6619,8 @@ var LeaferUI = (function (exports) {
6563
6619
  id: (leaf, name) => leaf.id === name ? (this.idMap[name] = leaf, 1) : 0,
6564
6620
  innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.innerIdMap[innerId] = leaf, 1) : 0,
6565
6621
  className: (leaf, name) => leaf.className === name ? 1 : 0,
6566
- tag: (leaf, name) => leaf.__tag === name ? 1 : 0
6622
+ tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
6623
+ tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
6567
6624
  };
6568
6625
  this.target = target;
6569
6626
  if (userConfig)
@@ -6579,12 +6636,25 @@ var LeaferUI = (function (exports) {
6579
6636
  case 'string':
6580
6637
  switch (condition[0]) {
6581
6638
  case '#':
6582
- const leaf = this.getById(condition.substring(1), branch);
6583
- return one ? leaf : (leaf ? [leaf] : []);
6639
+ idCondition.id = condition.substring(1), condition = idCondition;
6640
+ break;
6584
6641
  case '.':
6585
- return this.getByMethod(this.methods.className, branch, one, condition.substring(1));
6642
+ classNameCondition.className = condition.substring(1), condition = classNameCondition;
6643
+ break;
6586
6644
  default:
6587
- return this.getByMethod(this.methods.tag, branch, one, condition);
6645
+ tagCondition.tag = condition, condition = tagCondition;
6646
+ }
6647
+ case 'object':
6648
+ if (condition.id !== undefined) {
6649
+ const leaf = this.getById(condition.id, branch);
6650
+ return one ? leaf : (leaf ? [leaf] : []);
6651
+ }
6652
+ else if (condition.tag) {
6653
+ const { tag } = condition, isArray = tag instanceof Array;
6654
+ return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag);
6655
+ }
6656
+ else {
6657
+ return this.getByMethod(this.methods.className, branch, one, condition.className);
6588
6658
  }
6589
6659
  case 'function':
6590
6660
  return this.getByMethod(condition, branch, one, options);
@@ -6883,7 +6953,7 @@ var LeaferUI = (function (exports) {
6883
6953
  const UnitConvert = {
6884
6954
  number(value, percentRefer) {
6885
6955
  if (typeof value === 'object')
6886
- return value.type === 'percent' ? value.value / 100 * percentRefer : value.value;
6956
+ return value.type === 'percent' ? (value.value > 49 ? value.value / 100 : value.value) * percentRefer : value.value;
6887
6957
  return value;
6888
6958
  }
6889
6959
  };
@@ -7164,7 +7234,9 @@ var LeaferUI = (function (exports) {
7164
7234
  }
7165
7235
  createProxyData() { return undefined; }
7166
7236
  find(_condition, _options) { return undefined; }
7237
+ findTag(tag) { return this.find({ tag }); }
7167
7238
  findOne(_condition, _options) { return undefined; }
7239
+ findId(id) { return this.findOne({ id }); }
7168
7240
  getPath(curve, pathForRender) {
7169
7241
  this.__layout.update();
7170
7242
  let path = pathForRender ? this.__.__pathForRender : this.__.path;
@@ -7315,9 +7387,75 @@ var LeaferUI = (function (exports) {
7315
7387
  __decorate([
7316
7388
  rotationType(0, true)
7317
7389
  ], exports.UI.prototype, "skewY", void 0);
7390
+ __decorate([
7391
+ positionType(0, true)
7392
+ ], exports.UI.prototype, "offsetX", void 0);
7393
+ __decorate([
7394
+ positionType(0, true)
7395
+ ], exports.UI.prototype, "offsetY", void 0);
7396
+ __decorate([
7397
+ positionType(0, true)
7398
+ ], exports.UI.prototype, "scrollX", void 0);
7399
+ __decorate([
7400
+ positionType(0, true)
7401
+ ], exports.UI.prototype, "scrollY", void 0);
7402
+ __decorate([
7403
+ autoLayoutType()
7404
+ ], exports.UI.prototype, "origin", void 0);
7318
7405
  __decorate([
7319
7406
  autoLayoutType()
7320
7407
  ], exports.UI.prototype, "around", void 0);
7408
+ __decorate([
7409
+ dataType(false)
7410
+ ], exports.UI.prototype, "lazy", void 0);
7411
+ __decorate([
7412
+ naturalBoundsType(1)
7413
+ ], exports.UI.prototype, "pixelRatio", void 0);
7414
+ __decorate([
7415
+ pathInputType()
7416
+ ], exports.UI.prototype, "path", void 0);
7417
+ __decorate([
7418
+ pathType()
7419
+ ], exports.UI.prototype, "windingRule", void 0);
7420
+ __decorate([
7421
+ pathType(true)
7422
+ ], exports.UI.prototype, "closed", void 0);
7423
+ __decorate([
7424
+ autoLayoutType(false)
7425
+ ], exports.UI.prototype, "flow", void 0);
7426
+ __decorate([
7427
+ boundsType(0)
7428
+ ], exports.UI.prototype, "padding", void 0);
7429
+ __decorate([
7430
+ boundsType(0)
7431
+ ], exports.UI.prototype, "gap", void 0);
7432
+ __decorate([
7433
+ boundsType('top-left')
7434
+ ], exports.UI.prototype, "align", void 0);
7435
+ __decorate([
7436
+ boundsType(false)
7437
+ ], exports.UI.prototype, "wrap", void 0);
7438
+ __decorate([
7439
+ boundsType('box')
7440
+ ], exports.UI.prototype, "itemBox", void 0);
7441
+ __decorate([
7442
+ boundsType(true)
7443
+ ], exports.UI.prototype, "inFlow", void 0);
7444
+ __decorate([
7445
+ boundsType()
7446
+ ], exports.UI.prototype, "autoWidth", void 0);
7447
+ __decorate([
7448
+ boundsType()
7449
+ ], exports.UI.prototype, "autoHeight", void 0);
7450
+ __decorate([
7451
+ boundsType()
7452
+ ], exports.UI.prototype, "autoBox", void 0);
7453
+ __decorate([
7454
+ boundsType()
7455
+ ], exports.UI.prototype, "widthRange", void 0);
7456
+ __decorate([
7457
+ boundsType()
7458
+ ], exports.UI.prototype, "heightRange", void 0);
7321
7459
  __decorate([
7322
7460
  dataType(false)
7323
7461
  ], exports.UI.prototype, "draggable", void 0);
@@ -7327,9 +7465,6 @@ var LeaferUI = (function (exports) {
7327
7465
  __decorate([
7328
7466
  dataType(false)
7329
7467
  ], exports.UI.prototype, "editable", void 0);
7330
- __decorate([
7331
- dataType('size')
7332
- ], exports.UI.prototype, "editSize", void 0);
7333
7468
  __decorate([
7334
7469
  hitType(true)
7335
7470
  ], exports.UI.prototype, "hittable", void 0);
@@ -7384,21 +7519,6 @@ var LeaferUI = (function (exports) {
7384
7519
  __decorate([
7385
7520
  strokeType(10)
7386
7521
  ], exports.UI.prototype, "miterLimit", void 0);
7387
- __decorate([
7388
- dataType(false)
7389
- ], exports.UI.prototype, "lazy", void 0);
7390
- __decorate([
7391
- naturalBoundsType(1)
7392
- ], exports.UI.prototype, "pixelRatio", void 0);
7393
- __decorate([
7394
- pathInputType()
7395
- ], exports.UI.prototype, "path", void 0);
7396
- __decorate([
7397
- pathType()
7398
- ], exports.UI.prototype, "windingRule", void 0);
7399
- __decorate([
7400
- pathType(true)
7401
- ], exports.UI.prototype, "closed", void 0);
7402
7522
  __decorate([
7403
7523
  arrowType('none')
7404
7524
  ], exports.UI.prototype, "startArrow", void 0);
@@ -7632,9 +7752,6 @@ var LeaferUI = (function (exports) {
7632
7752
  const data = DataHelper.copyAttrs({}, size, canvasSizeAttrs);
7633
7753
  Object.keys(data).forEach(key => this[key] = data[key]);
7634
7754
  }
7635
- forceFullRender() {
7636
- this.forceRender();
7637
- }
7638
7755
  forceRender(bounds) {
7639
7756
  this.renderer.addBlock(bounds ? new Bounds(bounds) : this.canvas.bounds);
7640
7757
  if (this.viewReady)
@@ -7712,7 +7829,7 @@ var LeaferUI = (function (exports) {
7712
7829
  this.canvas.backgroundColor = newValue;
7713
7830
  }
7714
7831
  else {
7715
- this.forceFullRender();
7832
+ this.forceRender();
7716
7833
  }
7717
7834
  }
7718
7835
  __onCreated() {
@@ -7923,6 +8040,8 @@ var LeaferUI = (function (exports) {
7923
8040
  else {
7924
8041
  this.__updateRectBoxBounds();
7925
8042
  }
8043
+ if (data.flow)
8044
+ this.__updateContentBounds();
7926
8045
  }
7927
8046
  __updateStrokeBounds() { }
7928
8047
  __updateRenderBounds() {
@@ -8332,7 +8451,7 @@ var LeaferUI = (function (exports) {
8332
8451
  registerUI()
8333
8452
  ], exports.Canvas);
8334
8453
 
8335
- const { copyAndSpread, includes, spread, setList } = BoundsHelper;
8454
+ const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8336
8455
  exports.Text = class Text extends exports.UI {
8337
8456
  get __tag() { return 'Text'; }
8338
8457
  get editInner() { return 'TextEditor'; }
@@ -8405,7 +8524,7 @@ var LeaferUI = (function (exports) {
8405
8524
  if (italic)
8406
8525
  b.width += fontSize * 0.16;
8407
8526
  const contentBounds = includes(b, bounds) ? b : bounds;
8408
- if (contentBounds !== layout.contentBounds) {
8527
+ if (!isSame$1(contentBounds, layout.contentBounds)) {
8409
8528
  layout.contentBounds = contentBounds;
8410
8529
  layout.renderChanged = true;
8411
8530
  setList(data.__textBoxBounds = {}, [b, bounds]);
@@ -8433,9 +8552,6 @@ var LeaferUI = (function (exports) {
8433
8552
  __decorate([
8434
8553
  boundsType(0)
8435
8554
  ], exports.Text.prototype, "height", void 0);
8436
- __decorate([
8437
- boundsType(0)
8438
- ], exports.Text.prototype, "padding", void 0);
8439
8555
  __decorate([
8440
8556
  surfaceType('#000000')
8441
8557
  ], exports.Text.prototype, "fill", void 0);
@@ -8564,7 +8680,7 @@ var LeaferUI = (function (exports) {
8564
8680
  };
8565
8681
  }
8566
8682
 
8567
- const version = "1.0.0-rc.21";
8683
+ const version = "1.0.0-rc.23";
8568
8684
 
8569
8685
  exports.App = class App extends exports.Leafer {
8570
8686
  get __tag() { return 'App'; }
@@ -8658,8 +8774,10 @@ var LeaferUI = (function (exports) {
8658
8774
  this.renderer.update();
8659
8775
  }
8660
8776
  __render(canvas, options) {
8661
- if (options.matrix)
8662
- canvas.setWorld(options.matrix);
8777
+ if (options.matrix) {
8778
+ const { a, b, c, d, e, f } = options.matrix;
8779
+ canvas.setTransform(a, b, c, d, e, f);
8780
+ }
8663
8781
  this.children.forEach(leafer => canvas.copyWorld(leafer.canvas));
8664
8782
  }
8665
8783
  __onResize(event) {
@@ -10622,7 +10740,7 @@ var LeaferUI = (function (exports) {
10622
10740
  }
10623
10741
  else {
10624
10742
  const { renderShapeSpread: spread } = ui.__layout;
10625
- const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, spread * scaleX, spread * scaleY) : current.bounds, nowWorld);
10743
+ const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [spread * scaleY, spread * scaleX]) : current.bounds, nowWorld);
10626
10744
  fitMatrix = current.bounds.getFitMatrix(worldClipBounds);
10627
10745
  let { a: fitScaleX, d: fitScaleY } = fitMatrix;
10628
10746
  if (fitMatrix.a < 1) {
@@ -10722,10 +10840,10 @@ var LeaferUI = (function (exports) {
10722
10840
  rotate(transform, rotation);
10723
10841
  data.transform = transform;
10724
10842
  }
10725
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around) {
10843
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
10726
10844
  const transform = get$4();
10727
10845
  if (rotation) {
10728
- if (around === 'center') {
10846
+ if (align === 'center') {
10729
10847
  rotateOfOuter$2(transform, { x: width / 2, y: height / 2 }, rotation);
10730
10848
  }
10731
10849
  else {
@@ -10758,12 +10876,12 @@ var LeaferUI = (function (exports) {
10758
10876
  let { width, height } = image;
10759
10877
  if (paint.padding)
10760
10878
  box = tempBox.set(box).shrink(paint.padding);
10761
- const { opacity, mode, around, offset, scale, size, rotation, blendMode, repeat } = paint;
10879
+ const { opacity, mode, align, offset, scale, size, rotation, blendMode, repeat } = paint;
10762
10880
  const sameBox = box.width === width && box.height === height;
10763
10881
  if (blendMode)
10764
10882
  leafPaint.blendMode = blendMode;
10765
10883
  const data = leafPaint.data = { mode };
10766
- const swapSize = around !== 'center' && (rotation || 0) % 180 === 90;
10884
+ const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
10767
10885
  const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
10768
10886
  let x = 0, y = 0, scaleX, scaleY;
10769
10887
  if (!mode || mode === 'cover' || mode === 'fit') {
@@ -10781,11 +10899,11 @@ var LeaferUI = (function (exports) {
10781
10899
  scaleX = typeof scale === 'number' ? scale : scale.x;
10782
10900
  scaleY = typeof scale === 'number' ? scale : scale.y;
10783
10901
  }
10784
- if (around) {
10902
+ if (align) {
10785
10903
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
10786
10904
  if (scaleX)
10787
10905
  imageBounds.width *= scaleX, imageBounds.height *= scaleY;
10788
- AroundHelper.toPoint(around, box, tempPoint, true, imageBounds);
10906
+ AlignHelper.toPoint(align, imageBounds, box, tempPoint, true);
10789
10907
  x += tempPoint.x, y += tempPoint.y;
10790
10908
  }
10791
10909
  if (offset)
@@ -10802,7 +10920,7 @@ var LeaferUI = (function (exports) {
10802
10920
  break;
10803
10921
  case 'repeat':
10804
10922
  if (!sameBox || scaleX || rotation)
10805
- repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around);
10923
+ repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align);
10806
10924
  if (!repeat)
10807
10925
  data.repeat = 'repeat';
10808
10926
  break;
@@ -11719,11 +11837,13 @@ var LeaferUI = (function (exports) {
11719
11837
  const { rows, overflow } = drawData;
11720
11838
  let { textOverflow } = style;
11721
11839
  rows.splice(overflow);
11722
- if (textOverflow !== 'hide') {
11723
- if (textOverflow === 'ellipsis')
11840
+ if (textOverflow && textOverflow !== 'show') {
11841
+ if (textOverflow === 'hide')
11842
+ textOverflow = '';
11843
+ else if (textOverflow === 'ellipsis')
11724
11844
  textOverflow = '...';
11725
11845
  let char, charRight;
11726
- const ellipsisWidth = Platform.canvas.measureText(textOverflow).width;
11846
+ const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
11727
11847
  const right = style.x + style.width - ellipsisWidth;
11728
11848
  const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
11729
11849
  list.forEach(row => {
@@ -11891,8 +12011,12 @@ var LeaferUI = (function (exports) {
11891
12011
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
11892
12012
  const { worldTransform, isLeafer, isFrame } = leaf;
11893
12013
  const { slice, trim, onCanvas } = options;
11894
- const scale = options.scale || 1;
11895
- const pixelRatio = options.pixelRatio || 1;
12014
+ let scale = options.scale || 1;
12015
+ let pixelRatio = options.pixelRatio || 1;
12016
+ if (leaf.isApp) {
12017
+ scale *= pixelRatio;
12018
+ pixelRatio = leaf.app.pixelRatio;
12019
+ }
11896
12020
  const screenshot = options.screenshot || leaf.isApp;
11897
12021
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
11898
12022
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -12033,6 +12157,7 @@ var LeaferUI = (function (exports) {
12033
12157
  ImageManager.destroy();
12034
12158
  });
12035
12159
 
12160
+ exports.AlignHelper = AlignHelper;
12036
12161
  exports.AnimateEvent = AnimateEvent;
12037
12162
  exports.AroundHelper = AroundHelper;
12038
12163
  exports.AutoBounds = AutoBounds;