leafer-ui 1.0.0-rc.20 → 1.0.0-rc.22

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.
@@ -117,7 +117,7 @@ function getMatrixData() { return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }; }
117
117
 
118
118
  const { sin: sin$5, cos: cos$5, acos, sqrt: sqrt$3 } = Math;
119
119
  const { float: float$1 } = MathHelper;
120
- const tempPoint$3 = {};
120
+ const tempPoint$4 = {};
121
121
  function getWorld() {
122
122
  return Object.assign(Object.assign(Object.assign({}, getMatrixData()), getBoundsData()), { scaleX: 1, scaleY: 1, rotation: 0, skewX: 0, skewY: 0 });
123
123
  }
@@ -158,8 +158,8 @@ const MatrixHelper = {
158
158
  t.d *= scaleY;
159
159
  },
160
160
  scaleOfOuter(t, origin, scaleX, scaleY) {
161
- M$6.toInnerPoint(t, origin, tempPoint$3);
162
- M$6.scaleOfInner(t, tempPoint$3, scaleX, scaleY);
161
+ M$6.toInnerPoint(t, origin, tempPoint$4);
162
+ M$6.scaleOfInner(t, tempPoint$4, scaleX, scaleY);
163
163
  },
164
164
  scaleOfInner(t, origin, scaleX, scaleY = scaleX) {
165
165
  M$6.translateInner(t, origin.x, origin.y);
@@ -177,8 +177,8 @@ const MatrixHelper = {
177
177
  t.d = c * sinR + d * cosR;
178
178
  },
179
179
  rotateOfOuter(t, origin, rotation) {
180
- M$6.toInnerPoint(t, origin, tempPoint$3);
181
- M$6.rotateOfInner(t, tempPoint$3, rotation);
180
+ M$6.toInnerPoint(t, origin, tempPoint$4);
181
+ M$6.rotateOfInner(t, tempPoint$4, rotation);
182
182
  },
183
183
  rotateOfInner(t, origin, rotation) {
184
184
  M$6.translateInner(t, origin.x, origin.y);
@@ -199,8 +199,8 @@ const MatrixHelper = {
199
199
  }
200
200
  },
201
201
  skewOfOuter(t, origin, skewX, skewY) {
202
- M$6.toInnerPoint(t, origin, tempPoint$3);
203
- M$6.skewOfInner(t, tempPoint$3, skewX, skewY);
202
+ M$6.toInnerPoint(t, origin, tempPoint$4);
203
+ M$6.skewOfInner(t, tempPoint$4, skewX, skewY);
204
204
  },
205
205
  skewOfInner(t, origin, skewX, skewY = 0) {
206
206
  M$6.translateInner(t, origin.x, origin.y);
@@ -594,7 +594,7 @@ class Point {
594
594
  return this;
595
595
  }
596
596
  }
597
- const tempPoint$2 = new Point();
597
+ const tempPoint$3 = new Point();
598
598
 
599
599
  class Matrix {
600
600
  constructor(a, b, c, d, e, f) {
@@ -1206,11 +1206,19 @@ const AroundHelper = {
1206
1206
  directionData,
1207
1207
  tempPoint: {},
1208
1208
  get: get$5,
1209
- toPoint(around, bounds, to, onlySize) {
1209
+ toPoint(around, bounds, to, onlySize, pointBounds) {
1210
1210
  to || (to = {});
1211
1211
  const point = get$5(around);
1212
1212
  to.x = point.x * bounds.width;
1213
1213
  to.y = point.y * bounds.height;
1214
+ if (pointBounds) {
1215
+ to.x -= pointBounds.x;
1216
+ to.y -= pointBounds.y;
1217
+ if (point.x)
1218
+ to.x -= (point.x === 1) ? pointBounds.width : (point.x === 0.5 ? point.x * pointBounds.width : 0);
1219
+ if (point.y)
1220
+ to.y -= (point.y === 1) ? pointBounds.height : (point.y === 0.5 ? point.y * pointBounds.height : 0);
1221
+ }
1214
1222
  if (!onlySize) {
1215
1223
  to.x += bounds.x;
1216
1224
  to.y += bounds.y;
@@ -1265,7 +1273,8 @@ class Debug {
1265
1273
  this.warn(...messages);
1266
1274
  }
1267
1275
  warn(...messages) {
1268
- console.warn(this.name, ...messages);
1276
+ if (D$4.showWarn)
1277
+ console.warn(this.name, ...messages);
1269
1278
  }
1270
1279
  repeat(name, ...messages) {
1271
1280
  if (!this.repeatMap[name]) {
@@ -1284,6 +1293,7 @@ class Debug {
1284
1293
  }
1285
1294
  Debug.filterList = [];
1286
1295
  Debug.excludeList = [];
1296
+ Debug.showWarn = true;
1287
1297
  function getNameList(name) {
1288
1298
  if (!name)
1289
1299
  name = [];
@@ -2206,7 +2216,7 @@ const { sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil$1, abs: abs$3, PI: PI
2206
2216
  const { setPoint: setPoint$2, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2207
2217
  const { set: set$2 } = PointHelper;
2208
2218
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$5 } = PathCommandMap;
2209
- const tempPoint$1 = {};
2219
+ const tempPoint$2 = {};
2210
2220
  const BezierHelper = {
2211
2221
  points(data, points, curve, close) {
2212
2222
  data.push(M$5, points[0], points[1]);
@@ -2396,8 +2406,8 @@ const BezierHelper = {
2396
2406
  addMode ? addPoint$2(pointBounds, fromX, fromY) : setPoint$2(pointBounds, fromX, fromY);
2397
2407
  addPoint$2(pointBounds, toX, toY);
2398
2408
  for (let i = 0, len = tList.length; i < len; i++) {
2399
- getPointAndSet(tList[i], fromX, fromY, x1, y1, x2, y2, toX, toY, tempPoint$1);
2400
- addPoint$2(pointBounds, tempPoint$1.x, tempPoint$1.y);
2409
+ getPointAndSet(tList[i], fromX, fromY, x1, y1, x2, y2, toX, toY, tempPoint$2);
2410
+ addPoint$2(pointBounds, tempPoint$2.x, tempPoint$2.y);
2401
2411
  }
2402
2412
  },
2403
2413
  getPointAndSet(t, fromX, fromY, x1, y1, x2, y2, toX, toY, setPoint) {
@@ -2467,7 +2477,7 @@ const EllipseHelper = {
2467
2477
  };
2468
2478
 
2469
2479
  const { M: M$4, m, L: L$5, l, H, h, V, v, C: C$4, c, S, s, Q: Q$3, q, T, t, A, a, Z: Z$4, z, N: N$3, D: D$3, X: X$3, G: G$3, F: F$4, O: O$3, P: P$3, U: U$3 } = PathCommandMap;
2470
- const { rect: rect$2, roundRect: roundRect$2, arcTo: arcTo$3, arc: arc$3, ellipse: ellipse$4, quadraticCurveTo: quadraticCurveTo$1 } = BezierHelper;
2480
+ const { rect: rect$3, roundRect: roundRect$2, arcTo: arcTo$3, arc: arc$3, ellipse: ellipse$4, quadraticCurveTo: quadraticCurveTo$1 } = BezierHelper;
2471
2481
  const { ellipticalArc } = EllipseHelper;
2472
2482
  const debug$d = Debug.get('PathConvert');
2473
2483
  const setEndPoint$1 = {};
@@ -2660,7 +2670,7 @@ const PathConvert = {
2660
2670
  case N$3:
2661
2671
  x = old[i + 1];
2662
2672
  y = old[i + 2];
2663
- curveMode ? rect$2(data, x, y, old[i + 3], old[i + 4]) : copyData(data, old, i, 5);
2673
+ curveMode ? rect$3(data, x, y, old[i + 3], old[i + 4]) : copyData(data, old, i, 5);
2664
2674
  i += 5;
2665
2675
  break;
2666
2676
  case D$3:
@@ -2817,7 +2827,7 @@ const PathCommandDataHelper = {
2817
2827
  };
2818
2828
  const { ellipse: ellipse$3, arc: arc$2 } = PathCommandDataHelper;
2819
2829
 
2820
- const { moveTo: moveTo$4, lineTo: lineTo$3, quadraticCurveTo, bezierCurveTo, closePath: closePath$3, beginPath, rect: rect$1, roundRect: roundRect$1, ellipse: ellipse$2, arc: arc$1, arcTo: arcTo$2, drawEllipse, drawArc, drawPoints: drawPoints$2 } = PathCommandDataHelper;
2830
+ const { moveTo: moveTo$4, lineTo: lineTo$3, quadraticCurveTo, bezierCurveTo, closePath: closePath$3, beginPath, rect: rect$2, roundRect: roundRect$1, ellipse: ellipse$2, arc: arc$1, arcTo: arcTo$2, drawEllipse, drawArc, drawPoints: drawPoints$2 } = PathCommandDataHelper;
2821
2831
  class PathCreator {
2822
2832
  set path(value) { this.__path = value; }
2823
2833
  get path() { return this.__path; }
@@ -2859,7 +2869,7 @@ class PathCreator {
2859
2869
  return this;
2860
2870
  }
2861
2871
  rect(x, y, width, height) {
2862
- rect$1(this.__path, x, y, width, height);
2872
+ rect$2(this.__path, x, y, width, height);
2863
2873
  return this;
2864
2874
  }
2865
2875
  roundRect(x, y, width, height, cornerRadius) {
@@ -3954,15 +3964,21 @@ const LeafHelper = {
3954
3964
  }
3955
3965
  return true;
3956
3966
  },
3957
- moveWorld(t, x, y) {
3958
- const local = { x, y };
3967
+ moveWorld(t, x, y = 0) {
3968
+ const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
3959
3969
  if (t.parent)
3960
3970
  toInnerPoint$1(t.parent.worldTransform, local, local, true);
3961
3971
  L.moveLocal(t, local.x, local.y);
3962
3972
  },
3963
3973
  moveLocal(t, x, y = 0) {
3964
- t.x += x;
3965
- t.y += y;
3974
+ if (typeof x === 'object') {
3975
+ t.x += x.x;
3976
+ t.y += x.y;
3977
+ }
3978
+ else {
3979
+ t.x += x;
3980
+ t.y += y;
3981
+ }
3966
3982
  },
3967
3983
  zoomOfWorld(t, origin, scaleX, scaleY, resize) {
3968
3984
  L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
@@ -4524,12 +4540,15 @@ const LeafEventer = {
4524
4540
  break;
4525
4541
  }
4526
4542
  }
4543
+ this.syncEventer && this.syncEventer.emitEvent(event, capture);
4527
4544
  },
4528
4545
  emitEvent(event, capture) {
4529
4546
  event.current = this;
4530
4547
  this.emit(event.type, event, capture);
4531
4548
  },
4532
4549
  hasEvent(type, capture) {
4550
+ if (this.syncEventer && this.syncEventer.hasEvent(type, capture))
4551
+ return true;
4533
4552
  const { __bubbleMap: b, __captureMap: c } = this;
4534
4553
  const hasB = b && b[type], hasC = c && c[type];
4535
4554
  return !!(capture === undefined ? (hasB || hasC) : (capture ? hasC : hasB));
@@ -4749,7 +4768,7 @@ const LeafDataProxy = {
4749
4768
  };
4750
4769
 
4751
4770
  const { setLayout, multiplyParent: multiplyParent$1, translateInner, defaultWorld } = MatrixHelper;
4752
- const { toPoint, tempPoint } = AroundHelper;
4771
+ const { toPoint, tempPoint: tempPoint$1 } = AroundHelper;
4753
4772
  const LeafMatrix = {
4754
4773
  __updateWorldMatrix() {
4755
4774
  multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__);
@@ -4766,8 +4785,8 @@ const LeafMatrix = {
4766
4785
  local.e = data.x;
4767
4786
  local.f = data.y;
4768
4787
  if (data.around) {
4769
- toPoint(data.around, layout.boxBounds, tempPoint);
4770
- translateInner(local, -tempPoint.x, -tempPoint.y);
4788
+ toPoint(data.around, layout.boxBounds, tempPoint$1);
4789
+ translateInner(local, -tempPoint$1.x, -tempPoint$1.y);
4771
4790
  }
4772
4791
  }
4773
4792
  this.__layout.matrixChanged = false;
@@ -6418,32 +6437,38 @@ class Picker {
6418
6437
  const target = options.target || this.target;
6419
6438
  this.exclude = options.exclude || null;
6420
6439
  this.point = { x: hitPoint.x, y: hitPoint.y, radiusX: hitRadius, radiusY: hitRadius };
6421
- this.findList = options.findList || [];
6440
+ this.findList = new LeafList(options.findList);
6422
6441
  if (!options.findList)
6423
- this.eachFind(target.children, target.__onlyHitMask);
6424
- const list = this.findList;
6425
- const leaf = this.getBestMatchLeaf();
6442
+ this.hitBranch(target);
6443
+ const { list } = this.findList;
6444
+ const leaf = this.getBestMatchLeaf(list, options.bottomList, ignoreHittable);
6426
6445
  const path = ignoreHittable ? this.getPath(leaf) : this.getHitablePath(leaf);
6427
6446
  this.clear();
6428
6447
  return through ? { path, target: leaf, throughPath: list.length ? this.getThroughPath(list) : path } : { path, target: leaf };
6429
6448
  }
6430
- getBestMatchLeaf() {
6431
- const { findList: targets } = this;
6432
- if (targets.length > 1) {
6449
+ getBestMatchLeaf(list, bottomList, ignoreHittable) {
6450
+ if (list.length) {
6433
6451
  let find;
6434
- this.findList = [];
6452
+ this.findList = new LeafList();
6435
6453
  const { x, y } = this.point;
6436
6454
  const point = { x, y, radiusX: 0, radiusY: 0 };
6437
- for (let i = 0, len = targets.length; i < len; i++) {
6438
- find = targets[i];
6439
- if (LeafHelper.worldHittable(find)) {
6455
+ for (let i = 0, len = list.length; i < len; i++) {
6456
+ find = list[i];
6457
+ if (ignoreHittable || LeafHelper.worldHittable(find)) {
6440
6458
  this.hitChild(find, point);
6441
6459
  if (this.findList.length)
6442
- return this.findList[0];
6460
+ return this.findList.list[0];
6443
6461
  }
6444
6462
  }
6445
6463
  }
6446
- return targets[0];
6464
+ if (bottomList) {
6465
+ for (let i = 0, len = bottomList.length; i < len; i++) {
6466
+ this.hitChild(bottomList[i].target, this.point, bottomList[i].proxy);
6467
+ if (this.findList.length)
6468
+ return this.findList.list[0];
6469
+ }
6470
+ }
6471
+ return list[0];
6447
6472
  }
6448
6473
  getPath(leaf) {
6449
6474
  const path = new LeafList();
@@ -6485,6 +6510,9 @@ class Picker {
6485
6510
  }
6486
6511
  return throughPath;
6487
6512
  }
6513
+ hitBranch(branch) {
6514
+ this.eachFind(branch.children, branch.__onlyHitMask);
6515
+ }
6488
6516
  eachFind(children, hitMask) {
6489
6517
  let child, hit;
6490
6518
  const { point } = this, len = children.length;
@@ -6506,11 +6534,11 @@ class Picker {
6506
6534
  }
6507
6535
  }
6508
6536
  }
6509
- hitChild(child, point) {
6537
+ hitChild(child, point, proxy) {
6510
6538
  if (this.exclude && this.exclude.has(child))
6511
6539
  return;
6512
6540
  if (child.__hitWorld(point))
6513
- this.findList.push(child);
6541
+ this.findList.add(proxy || child);
6514
6542
  }
6515
6543
  clear() {
6516
6544
  this.point = null;
@@ -6708,7 +6736,11 @@ function zoomLayerType() {
6708
6736
  defineKey(target, key, {
6709
6737
  set(value) { if (this.isLeafer)
6710
6738
  this[privateKey] = value; },
6711
- get() { return this.isLeafer ? (this[privateKey] || this) : this.leafer && this.leafer.zoomLayer; }
6739
+ get() {
6740
+ return this.isApp
6741
+ ? this.tree.zoomLayer
6742
+ : (this.isLeafer ? (this[privateKey] || this) : this.leafer && this.leafer.zoomLayer);
6743
+ }
6712
6744
  });
6713
6745
  };
6714
6746
  }
@@ -7114,6 +7146,9 @@ let UI = UI_1 = class UI extends Leaf {
7114
7146
  pen.set(this.path = this.__.path || []);
7115
7147
  return pen;
7116
7148
  }
7149
+ get editConfig() { return undefined; }
7150
+ get editOuter() { return 'EditTool'; }
7151
+ get editInner() { return 'PathEditor'; }
7117
7152
  constructor(data) {
7118
7153
  super(data);
7119
7154
  }
@@ -7175,7 +7210,8 @@ let UI = UI_1 = class UI extends Leaf {
7175
7210
  __drawPathByBox(drawer) {
7176
7211
  const { x, y, width, height } = this.__layout.boxBounds;
7177
7212
  if (this.__.cornerRadius) {
7178
- drawer.roundRect(x, y, width, height, this.__.cornerRadius);
7213
+ const { cornerRadius } = this.__;
7214
+ drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
7179
7215
  }
7180
7216
  else {
7181
7217
  drawer.rect(x, y, width, height);
@@ -7196,6 +7232,9 @@ let UI = UI_1 = class UI extends Leaf {
7196
7232
  static registerData(data) {
7197
7233
  dataProcessor(data)(this.prototype);
7198
7234
  }
7235
+ static setEditConfig(_config) { }
7236
+ static setEditOuter(_toolName) { }
7237
+ static setEditInner(_editorName) { }
7199
7238
  destroy() {
7200
7239
  this.fill = this.stroke = null;
7201
7240
  super.destroy();
@@ -7279,15 +7318,15 @@ __decorate([
7279
7318
  __decorate([
7280
7319
  dataType(false)
7281
7320
  ], UI.prototype, "draggable", void 0);
7321
+ __decorate([
7322
+ dataType()
7323
+ ], UI.prototype, "dragBounds", void 0);
7282
7324
  __decorate([
7283
7325
  dataType(false)
7284
7326
  ], UI.prototype, "editable", void 0);
7285
7327
  __decorate([
7286
7328
  dataType('size')
7287
7329
  ], UI.prototype, "editSize", void 0);
7288
- __decorate([
7289
- dataType()
7290
- ], UI.prototype, "editorStyle", void 0);
7291
7330
  __decorate([
7292
7331
  hitType(true)
7293
7332
  ], UI.prototype, "hittable", void 0);
@@ -7479,7 +7518,6 @@ Group = __decorate([
7479
7518
  var Leafer_1;
7480
7519
  const debug$3 = Debug.get('Leafer');
7481
7520
  let Leafer = Leafer_1 = class Leafer extends Group {
7482
- static get version() { return '1.0.0-rc.20'; }
7483
7521
  get __tag() { return 'Leafer'; }
7484
7522
  get isApp() { return false; }
7485
7523
  get app() { return this.parent || this; }
@@ -7532,7 +7570,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7532
7570
  if (this.isApp)
7533
7571
  this.__setApp();
7534
7572
  this.__checkAutoLayout(config);
7535
- this.updateLazyBounds();
7536
7573
  this.view = canvas.view;
7537
7574
  if (parentApp) {
7538
7575
  this.__bindApp(parentApp);
@@ -7776,6 +7813,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7776
7813
  __listenEvents() {
7777
7814
  const runId = Run.start('FirstCreate ' + this.innerName);
7778
7815
  this.once(LeaferEvent.START, () => Run.end(runId));
7816
+ this.once(LayoutEvent.START, () => this.updateLazyBounds());
7779
7817
  this.once(LayoutEvent.END, () => this.__onReady());
7780
7818
  this.once(RenderEvent.START, () => this.__onCreated());
7781
7819
  this.once(RenderEvent.END, () => this.__onViewReady());
@@ -7846,8 +7884,8 @@ Rect = __decorate([
7846
7884
  registerUI()
7847
7885
  ], Rect);
7848
7886
 
7849
- const rect = Rect.prototype;
7850
- const group = Group.prototype;
7887
+ const rect$1 = Rect.prototype;
7888
+ const group$1 = Group.prototype;
7851
7889
  const bounds$1 = {};
7852
7890
  const { copy: copy$3, add } = BoundsHelper;
7853
7891
  let Box = class Box extends Group {
@@ -7926,28 +7964,28 @@ __decorate([
7926
7964
  affectRenderBoundsType('show')
7927
7965
  ], Box.prototype, "overflow", void 0);
7928
7966
  __decorate([
7929
- rewrite(rect.__updateStrokeSpread)
7967
+ rewrite(rect$1.__updateStrokeSpread)
7930
7968
  ], Box.prototype, "__updateStrokeSpread", null);
7931
7969
  __decorate([
7932
- rewrite(rect.__updateRenderSpread)
7970
+ rewrite(rect$1.__updateRenderSpread)
7933
7971
  ], Box.prototype, "__updateRectRenderSpread", null);
7934
7972
  __decorate([
7935
- rewrite(rect.__updateBoxBounds)
7973
+ rewrite(rect$1.__updateBoxBounds)
7936
7974
  ], Box.prototype, "__updateRectBoxBounds", null);
7937
7975
  __decorate([
7938
- rewrite(rect.__updateStrokeBounds)
7976
+ rewrite(rect$1.__updateStrokeBounds)
7939
7977
  ], Box.prototype, "__updateStrokeBounds", null);
7940
7978
  __decorate([
7941
- rewrite(rect.__updateRenderBounds)
7979
+ rewrite(rect$1.__updateRenderBounds)
7942
7980
  ], Box.prototype, "__updateRectRenderBounds", null);
7943
7981
  __decorate([
7944
- rewrite(rect.__updateChange)
7982
+ rewrite(rect$1.__updateChange)
7945
7983
  ], Box.prototype, "__updateRectChange", null);
7946
7984
  __decorate([
7947
- rewrite(rect.__render)
7985
+ rewrite(rect$1.__render)
7948
7986
  ], Box.prototype, "__renderRect", null);
7949
7987
  __decorate([
7950
- rewrite(group.__render)
7988
+ rewrite(group$1.__render)
7951
7989
  ], Box.prototype, "__renderGroup", null);
7952
7990
  Box = __decorate([
7953
7991
  rewriteAble(),
@@ -8294,6 +8332,7 @@ Canvas = __decorate([
8294
8332
  const { copyAndSpread, includes, spread, setList } = BoundsHelper;
8295
8333
  let Text = class Text extends UI {
8296
8334
  get __tag() { return 'Text'; }
8335
+ get editInner() { return 'TextEditor'; }
8297
8336
  get textDrawData() {
8298
8337
  this.__layout.update();
8299
8338
  return this.__.__textDrawData;
@@ -8522,7 +8561,7 @@ function penPathType() {
8522
8561
  };
8523
8562
  }
8524
8563
 
8525
- const version = "1.0.0-rc.20";
8564
+ const version = "1.0.0-rc.21";
8526
8565
 
8527
8566
  let App = class App extends Leafer {
8528
8567
  get __tag() { return 'App'; }
@@ -8616,7 +8655,8 @@ let App = class App extends Leafer {
8616
8655
  this.renderer.update();
8617
8656
  }
8618
8657
  __render(canvas, options) {
8619
- canvas.setWorld(options.matrix || this.__world);
8658
+ if (options.matrix)
8659
+ canvas.setWorld(options.matrix);
8620
8660
  this.children.forEach(leafer => canvas.copyWorld(leafer.canvas));
8621
8661
  }
8622
8662
  __onResize(event) {
@@ -8738,6 +8778,35 @@ let DragEvent = class DragEvent extends PointerEvent {
8738
8778
  static setData(data) {
8739
8779
  this.data = data;
8740
8780
  }
8781
+ static getValidMove(leaf, start, total) {
8782
+ const { draggable, dragBounds, x, y } = leaf;
8783
+ const move = leaf.getLocalPoint(total, null, true);
8784
+ move.x += start.x - x;
8785
+ move.y += start.y - y;
8786
+ if (dragBounds)
8787
+ this.getMoveInDragBounds(leaf.__local, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true);
8788
+ if (draggable === 'x')
8789
+ move.y = 0;
8790
+ if (draggable === 'y')
8791
+ move.x = 0;
8792
+ return move;
8793
+ }
8794
+ static getMoveInDragBounds(box, dragBounds, move, change) {
8795
+ const x = box.x + move.x, y = box.y + move.y;
8796
+ const right = x + box.width, bottom = y + box.height;
8797
+ const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
8798
+ if (!change)
8799
+ move = Object.assign({}, move);
8800
+ if (x < dragBounds.x)
8801
+ move.x += dragBounds.x - x;
8802
+ else if (right > boundsRight)
8803
+ move.x += boundsRight - right;
8804
+ if (y < dragBounds.y)
8805
+ move.y += dragBounds.y - y;
8806
+ else if (bottom > boundsBottom)
8807
+ move.y += boundsBottom - bottom;
8808
+ return move;
8809
+ }
8741
8810
  getPageMove(total) {
8742
8811
  this.assignMove(total);
8743
8812
  return this.current.getPagePoint(move, null, true);
@@ -8847,9 +8916,7 @@ function addInteractionWindow(leafer) {
8847
8916
  if (leafer.isApp)
8848
8917
  return;
8849
8918
  leafer.__eventIds.push(leafer.on_(MoveEvent.BEFORE_MOVE, (e) => {
8850
- const { x, y } = leafer.getValidMove(e.moveX, e.moveY);
8851
- if (x || y)
8852
- leafer.zoomLayer.move(x, y);
8919
+ leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
8853
8920
  }), leafer.on_(ZoomEvent.BEFORE_ZOOM, (e) => {
8854
8921
  const { zoomLayer } = leafer;
8855
8922
  const changeScale = leafer.getValidScale(e.scale);
@@ -9118,9 +9185,14 @@ class Dragger {
9118
9185
  if (this.dragging) {
9119
9186
  this.interaction.emit(DragEvent.START, this.dragData);
9120
9187
  this.getDragableList(this.dragData.path);
9188
+ this.setDragStartPoints(this.realDragableList = this.getList());
9121
9189
  }
9122
9190
  }
9123
9191
  }
9192
+ setDragStartPoints(list) {
9193
+ this.dragStartPoints = {};
9194
+ list.forEach(leaf => this.dragStartPoints[leaf.innerId] = { x: leaf.x, y: leaf.y });
9195
+ }
9124
9196
  getDragableList(path) {
9125
9197
  let leaf;
9126
9198
  for (let i = 0, len = path.length; i < len; i++) {
@@ -9150,10 +9222,10 @@ class Dragger {
9150
9222
  }
9151
9223
  dragReal() {
9152
9224
  const { running } = this.interaction;
9153
- const list = this.getList();
9225
+ const list = this.realDragableList;
9154
9226
  if (list.length && running) {
9155
- const { moveX, moveY } = this.dragData;
9156
- list.forEach(leaf => leaf.draggable && leaf.moveWorld(moveX, moveY));
9227
+ const { totalX, totalY } = this.dragData;
9228
+ list.forEach(leaf => leaf.draggable && leaf.move(DragEvent.getValidMove(leaf, this.dragStartPoints[leaf.innerId], { x: totalX, y: totalY })));
9157
9229
  }
9158
9230
  }
9159
9231
  dragOverOrOut(data) {
@@ -9622,7 +9694,8 @@ class InteractionBase {
9622
9694
  }
9623
9695
  findPath(data, options) {
9624
9696
  const { hitRadius, through } = this.config.pointer;
9625
- const find = this.selector.getByPoint(data, hitRadius, options || { through });
9697
+ const { bottomList } = this;
9698
+ const find = this.selector.getByPoint(data, hitRadius, Object.assign({ bottomList, name: data.type }, (options || { through })));
9626
9699
  if (find.throughPath)
9627
9700
  data.throughPath = find.throughPath;
9628
9701
  data.path = find.path;
@@ -9635,7 +9708,7 @@ class InteractionBase {
9635
9708
  const app = this.target.app;
9636
9709
  if (!app || !app.isApp)
9637
9710
  return false;
9638
- return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree));
9711
+ return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree) && !data.target.syncEventer);
9639
9712
  }
9640
9713
  checkPath(data, useDefaultPath) {
9641
9714
  if (useDefaultPath || this.canMove(data))
@@ -9701,7 +9774,7 @@ class InteractionBase {
9701
9774
  const { path } = data;
9702
9775
  for (let i = 0, len = path.length; i < len; i++) {
9703
9776
  leaf = path.list[i];
9704
- cursor = leaf.cursor;
9777
+ cursor = leaf.syncEventer ? leaf.syncEventer.cursor : leaf.cursor;
9705
9778
  if (cursor)
9706
9779
  break;
9707
9780
  }
@@ -9859,6 +9932,8 @@ const { toInnerRadiusPointOf, copy: copy$2, setRadius } = PointHelper;
9859
9932
  const inner = {};
9860
9933
  const leaf = Leaf.prototype;
9861
9934
  leaf.__hitWorld = function (point) {
9935
+ if (!this.__.hitSelf)
9936
+ return false;
9862
9937
  if (this.__.hitRadius) {
9863
9938
  copy$2(inner, point), point = inner;
9864
9939
  setRadius(point, this.__.hitRadius);
@@ -9886,8 +9961,8 @@ leaf.__drawHitPath = function (canvas) { if (canvas)
9886
9961
  this.__drawRenderPath(canvas); };
9887
9962
 
9888
9963
  const matrix = new Matrix();
9889
- const ui$1 = UI.prototype;
9890
- ui$1.__updateHitCanvas = function () {
9964
+ const ui$2 = UI.prototype;
9965
+ ui$2.__updateHitCanvas = function () {
9891
9966
  const data = this.__, { hitCanvasManager } = this.leafer;
9892
9967
  const isHitPixelFill = data.__pixelFill && data.hitFill === 'pixel';
9893
9968
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
@@ -9914,7 +9989,7 @@ ui$1.__updateHitCanvas = function () {
9914
9989
  this.__drawHitPath(h);
9915
9990
  h.setStrokeOptions(data);
9916
9991
  };
9917
- ui$1.__hit = function (inner) {
9992
+ ui$2.__hit = function (inner) {
9918
9993
  if (Platform.name === 'miniapp')
9919
9994
  this.__drawHitPath(this.__hitCanvas);
9920
9995
  const data = this.__;
@@ -9954,22 +10029,24 @@ ui$1.__hit = function (inner) {
9954
10029
  return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
9955
10030
  };
9956
10031
 
9957
- const ui = new UI();
9958
- Rect.prototype.__updateHitCanvas = function () {
10032
+ const ui$1 = new UI();
10033
+ const rect = Rect.prototype;
10034
+ rect.__updateHitCanvas = function () {
9959
10035
  if (this.stroke || this.cornerRadius)
9960
- ui.__updateHitCanvas.call(this);
10036
+ ui$1.__updateHitCanvas.call(this);
9961
10037
  };
9962
- Rect.prototype.__hitFill = function (inner) {
9963
- return this.__hitCanvas ? ui.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
10038
+ rect.__hitFill = function (inner) {
10039
+ return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
9964
10040
  };
9965
10041
 
9966
- UI.prototype.find = function (condition, options) {
10042
+ const ui = UI.prototype, group = Group.prototype;
10043
+ ui.find = function (condition, options) {
9967
10044
  return this.leafer ? this.leafer.selector.getBy(condition, this, false, options) : [];
9968
10045
  };
9969
- UI.prototype.findOne = function (condition, options) {
10046
+ ui.findOne = function (condition, options) {
9970
10047
  return this.leafer ? this.leafer.selector.getBy(condition, this, true, options) : null;
9971
10048
  };
9972
- Group.prototype.pick = function (hitPoint, options) {
10049
+ group.pick = function (hitPoint, options) {
9973
10050
  this.__layout.update();
9974
10051
  if (!options)
9975
10052
  options = {};
@@ -10625,79 +10702,75 @@ const PaintModule = {
10625
10702
 
10626
10703
  let origin = {};
10627
10704
  const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
10628
- function fillOrFitMode(data, mode, box, width, height, rotation) {
10705
+ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10629
10706
  const transform = get$4();
10630
- const swap = rotation && rotation !== 180;
10631
- const sw = box.width / (swap ? height : width);
10632
- const sh = box.height / (swap ? width : height);
10633
- const scale = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
10634
- const x = box.x + (box.width - width * scale) / 2;
10635
- const y = box.y + (box.height - height * scale) / 2;
10636
- translate$1(transform, x, y);
10637
- scaleHelper(transform, scale);
10707
+ translate$1(transform, box.x + x, box.y + y);
10708
+ scaleHelper(transform, scaleX, scaleY);
10638
10709
  if (rotation)
10639
10710
  rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10640
- data.scaleX = data.scaleY = scale;
10641
10711
  data.transform = transform;
10642
10712
  }
10643
10713
  function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
10644
10714
  const transform = get$4();
10645
- translate$1(transform, box.x, box.y);
10646
- if (x || y)
10647
- translate$1(transform, x, y);
10648
- if (scaleX) {
10715
+ translate$1(transform, box.x + x, box.y + y);
10716
+ if (scaleX)
10649
10717
  scaleHelper(transform, scaleX, scaleY);
10650
- data.scaleX = transform.a;
10651
- data.scaleY = transform.d;
10652
- }
10653
10718
  if (rotation)
10654
10719
  rotate(transform, rotation);
10655
10720
  data.transform = transform;
10656
10721
  }
10657
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation) {
10722
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around) {
10658
10723
  const transform = get$4();
10659
10724
  if (rotation) {
10660
- rotate(transform, rotation);
10661
- switch (rotation) {
10662
- case 90:
10663
- translate$1(transform, height, 0);
10664
- break;
10665
- case 180:
10666
- translate$1(transform, width, height);
10667
- break;
10668
- case 270:
10669
- translate$1(transform, 0, width);
10670
- break;
10725
+ if (around === 'center') {
10726
+ rotateOfOuter$2(transform, { x: width / 2, y: height / 2 }, rotation);
10727
+ }
10728
+ else {
10729
+ rotate(transform, rotation);
10730
+ switch (rotation) {
10731
+ case 90:
10732
+ translate$1(transform, height, 0);
10733
+ break;
10734
+ case 180:
10735
+ translate$1(transform, width, height);
10736
+ break;
10737
+ case 270:
10738
+ translate$1(transform, 0, width);
10739
+ break;
10740
+ }
10671
10741
  }
10672
10742
  }
10673
- origin.x = box.x;
10674
- origin.y = box.y;
10675
- if (x || y)
10676
- origin.x += x, origin.y += y;
10743
+ origin.x = box.x + x;
10744
+ origin.y = box.y + y;
10677
10745
  translate$1(transform, origin.x, origin.y);
10678
- if (scaleX) {
10746
+ if (scaleX)
10679
10747
  scaleOfOuter$2(transform, origin, scaleX, scaleY);
10680
- data.scaleX = scaleX;
10681
- data.scaleY = scaleY;
10682
- }
10683
10748
  data.transform = transform;
10684
10749
  }
10685
10750
 
10686
10751
  const { get: get$3, translate } = MatrixHelper;
10687
10752
  const tempBox = new Bounds();
10753
+ const tempPoint = {};
10688
10754
  function createData(leafPaint, image, paint, box) {
10689
10755
  let { width, height } = image;
10690
10756
  if (paint.padding)
10691
10757
  box = tempBox.set(box).shrink(paint.padding);
10692
- const { opacity, mode, offset, scale, size, rotation, blendMode, repeat } = paint;
10758
+ const { opacity, mode, around, offset, scale, size, rotation, blendMode, repeat } = paint;
10693
10759
  const sameBox = box.width === width && box.height === height;
10694
10760
  if (blendMode)
10695
10761
  leafPaint.blendMode = blendMode;
10696
10762
  const data = leafPaint.data = { mode };
10697
- let x, y, scaleX, scaleY;
10698
- if (offset)
10699
- x = offset.x, y = offset.y;
10700
- if (size) {
10763
+ const swapSize = around !== 'center' && (rotation || 0) % 180 === 90;
10764
+ const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
10765
+ let x = 0, y = 0, scaleX, scaleY;
10766
+ if (!mode || mode === 'cover' || mode === 'fit') {
10767
+ if (!sameBox || rotation) {
10768
+ const sw = box.width / swapWidth, sh = box.height / swapHeight;
10769
+ scaleX = scaleY = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
10770
+ x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
10771
+ }
10772
+ }
10773
+ else if (size) {
10701
10774
  scaleX = (typeof size === 'number' ? size : size.width) / width;
10702
10775
  scaleY = (typeof size === 'number' ? size : size.height) / height;
10703
10776
  }
@@ -10705,26 +10778,36 @@ function createData(leafPaint, image, paint, box) {
10705
10778
  scaleX = typeof scale === 'number' ? scale : scale.x;
10706
10779
  scaleY = typeof scale === 'number' ? scale : scale.y;
10707
10780
  }
10781
+ if (around) {
10782
+ const imageBounds = { x, y, width: swapWidth, height: swapHeight };
10783
+ if (scaleX)
10784
+ imageBounds.width *= scaleX, imageBounds.height *= scaleY;
10785
+ AroundHelper.toPoint(around, box, tempPoint, true, imageBounds);
10786
+ x += tempPoint.x, y += tempPoint.y;
10787
+ }
10788
+ if (offset)
10789
+ x += offset.x, y += offset.y;
10708
10790
  switch (mode) {
10709
10791
  case 'strench':
10710
10792
  if (!sameBox)
10711
10793
  width = box.width, height = box.height;
10712
10794
  break;
10795
+ case 'normal':
10713
10796
  case 'clip':
10714
- if (offset || scaleX || rotation)
10797
+ if (x || y || scaleX || rotation)
10715
10798
  clipMode(data, box, x, y, scaleX, scaleY, rotation);
10716
10799
  break;
10717
10800
  case 'repeat':
10718
10801
  if (!sameBox || scaleX || rotation)
10719
- repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation);
10802
+ repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around);
10720
10803
  if (!repeat)
10721
10804
  data.repeat = 'repeat';
10722
10805
  break;
10723
10806
  case 'fit':
10724
10807
  case 'cover':
10725
10808
  default:
10726
- if (!sameBox || rotation)
10727
- fillOrFitMode(data, mode, box, width, height, rotation);
10809
+ if (scaleX)
10810
+ fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation);
10728
10811
  }
10729
10812
  if (!data.transform) {
10730
10813
  if (box.x || box.y) {
@@ -10732,6 +10815,10 @@ function createData(leafPaint, image, paint, box) {
10732
10815
  translate(data.transform, box.x, box.y);
10733
10816
  }
10734
10817
  }
10818
+ if (scaleX && mode !== 'strench') {
10819
+ data.scaleX = scaleX;
10820
+ data.scaleY = scaleY;
10821
+ }
10735
10822
  data.width = width;
10736
10823
  data.height = height;
10737
10824
  if (opacity)
@@ -11787,6 +11874,13 @@ const ExportModule = {
11787
11874
  resolve();
11788
11875
  this.running = false;
11789
11876
  };
11877
+ if (filename === 'json') {
11878
+ return over({ data: leaf.toJSON() });
11879
+ }
11880
+ else if (FileHelper.fileType(filename) === 'json') {
11881
+ Platform.origin.download('data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(leaf.toJSON())), filename);
11882
+ return over({ data: true });
11883
+ }
11790
11884
  const { leafer } = leaf;
11791
11885
  if (leafer) {
11792
11886
  leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
@@ -11936,4 +12030,4 @@ window.addEventListener('unload', () => {
11936
12030
  ImageManager.destroy();
11937
12031
  });
11938
12032
 
11939
- export { AnimateEvent, Answer, App, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, DropEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, HitCanvasManager, Image$1 as Image, ImageData, ImageEvent, ImageManager, IncrementId, Interaction, 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, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, 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, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, RotateEvent, Run, Selector, Star, StarData, State, StringNumberMap, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, ZoomEvent, 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 };
12033
+ export { AnimateEvent, Answer, App, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, DropEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, HitCanvasManager, Image$1 as Image, ImageData, ImageEvent, ImageManager, IncrementId, Interaction, 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, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, 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, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, RotateEvent, Run, Selector, Star, StarData, State, StringNumberMap, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, ZoomEvent, 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 };