leafer-ui 1.0.0-rc.21 → 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;
@@ -2208,7 +2216,7 @@ const { sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil$1, abs: abs$3, PI: PI
2208
2216
  const { setPoint: setPoint$2, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2209
2217
  const { set: set$2 } = PointHelper;
2210
2218
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$5 } = PathCommandMap;
2211
- const tempPoint$1 = {};
2219
+ const tempPoint$2 = {};
2212
2220
  const BezierHelper = {
2213
2221
  points(data, points, curve, close) {
2214
2222
  data.push(M$5, points[0], points[1]);
@@ -2398,8 +2406,8 @@ const BezierHelper = {
2398
2406
  addMode ? addPoint$2(pointBounds, fromX, fromY) : setPoint$2(pointBounds, fromX, fromY);
2399
2407
  addPoint$2(pointBounds, toX, toY);
2400
2408
  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);
2409
+ getPointAndSet(tList[i], fromX, fromY, x1, y1, x2, y2, toX, toY, tempPoint$2);
2410
+ addPoint$2(pointBounds, tempPoint$2.x, tempPoint$2.y);
2403
2411
  }
2404
2412
  },
2405
2413
  getPointAndSet(t, fromX, fromY, x1, y1, x2, y2, toX, toY, setPoint) {
@@ -2469,7 +2477,7 @@ const EllipseHelper = {
2469
2477
  };
2470
2478
 
2471
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;
2472
- 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;
2473
2481
  const { ellipticalArc } = EllipseHelper;
2474
2482
  const debug$d = Debug.get('PathConvert');
2475
2483
  const setEndPoint$1 = {};
@@ -2662,7 +2670,7 @@ const PathConvert = {
2662
2670
  case N$3:
2663
2671
  x = old[i + 1];
2664
2672
  y = old[i + 2];
2665
- 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);
2666
2674
  i += 5;
2667
2675
  break;
2668
2676
  case D$3:
@@ -2819,7 +2827,7 @@ const PathCommandDataHelper = {
2819
2827
  };
2820
2828
  const { ellipse: ellipse$3, arc: arc$2 } = PathCommandDataHelper;
2821
2829
 
2822
- 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;
2823
2831
  class PathCreator {
2824
2832
  set path(value) { this.__path = value; }
2825
2833
  get path() { return this.__path; }
@@ -2861,7 +2869,7 @@ class PathCreator {
2861
2869
  return this;
2862
2870
  }
2863
2871
  rect(x, y, width, height) {
2864
- rect$1(this.__path, x, y, width, height);
2872
+ rect$2(this.__path, x, y, width, height);
2865
2873
  return this;
2866
2874
  }
2867
2875
  roundRect(x, y, width, height, cornerRadius) {
@@ -3956,15 +3964,21 @@ const LeafHelper = {
3956
3964
  }
3957
3965
  return true;
3958
3966
  },
3959
- moveWorld(t, x, y) {
3960
- const local = { x, y };
3967
+ moveWorld(t, x, y = 0) {
3968
+ const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
3961
3969
  if (t.parent)
3962
3970
  toInnerPoint$1(t.parent.worldTransform, local, local, true);
3963
3971
  L.moveLocal(t, local.x, local.y);
3964
3972
  },
3965
3973
  moveLocal(t, x, y = 0) {
3966
- t.x += x;
3967
- 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
+ }
3968
3982
  },
3969
3983
  zoomOfWorld(t, origin, scaleX, scaleY, resize) {
3970
3984
  L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
@@ -4526,12 +4540,15 @@ const LeafEventer = {
4526
4540
  break;
4527
4541
  }
4528
4542
  }
4543
+ this.syncEventer && this.syncEventer.emitEvent(event, capture);
4529
4544
  },
4530
4545
  emitEvent(event, capture) {
4531
4546
  event.current = this;
4532
4547
  this.emit(event.type, event, capture);
4533
4548
  },
4534
4549
  hasEvent(type, capture) {
4550
+ if (this.syncEventer && this.syncEventer.hasEvent(type, capture))
4551
+ return true;
4535
4552
  const { __bubbleMap: b, __captureMap: c } = this;
4536
4553
  const hasB = b && b[type], hasC = c && c[type];
4537
4554
  return !!(capture === undefined ? (hasB || hasC) : (capture ? hasC : hasB));
@@ -4751,7 +4768,7 @@ const LeafDataProxy = {
4751
4768
  };
4752
4769
 
4753
4770
  const { setLayout, multiplyParent: multiplyParent$1, translateInner, defaultWorld } = MatrixHelper;
4754
- const { toPoint, tempPoint } = AroundHelper;
4771
+ const { toPoint, tempPoint: tempPoint$1 } = AroundHelper;
4755
4772
  const LeafMatrix = {
4756
4773
  __updateWorldMatrix() {
4757
4774
  multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__);
@@ -4768,8 +4785,8 @@ const LeafMatrix = {
4768
4785
  local.e = data.x;
4769
4786
  local.f = data.y;
4770
4787
  if (data.around) {
4771
- toPoint(data.around, layout.boxBounds, tempPoint);
4772
- translateInner(local, -tempPoint.x, -tempPoint.y);
4788
+ toPoint(data.around, layout.boxBounds, tempPoint$1);
4789
+ translateInner(local, -tempPoint$1.x, -tempPoint$1.y);
4773
4790
  }
4774
4791
  }
4775
4792
  this.__layout.matrixChanged = false;
@@ -6420,32 +6437,38 @@ class Picker {
6420
6437
  const target = options.target || this.target;
6421
6438
  this.exclude = options.exclude || null;
6422
6439
  this.point = { x: hitPoint.x, y: hitPoint.y, radiusX: hitRadius, radiusY: hitRadius };
6423
- this.findList = options.findList || [];
6440
+ this.findList = new LeafList(options.findList);
6424
6441
  if (!options.findList)
6425
- this.eachFind(target.children, target.__onlyHitMask);
6426
- const list = this.findList;
6427
- const leaf = this.getBestMatchLeaf();
6442
+ this.hitBranch(target);
6443
+ const { list } = this.findList;
6444
+ const leaf = this.getBestMatchLeaf(list, options.bottomList, ignoreHittable);
6428
6445
  const path = ignoreHittable ? this.getPath(leaf) : this.getHitablePath(leaf);
6429
6446
  this.clear();
6430
6447
  return through ? { path, target: leaf, throughPath: list.length ? this.getThroughPath(list) : path } : { path, target: leaf };
6431
6448
  }
6432
- getBestMatchLeaf() {
6433
- const { findList: targets } = this;
6434
- if (targets.length > 1) {
6449
+ getBestMatchLeaf(list, bottomList, ignoreHittable) {
6450
+ if (list.length) {
6435
6451
  let find;
6436
- this.findList = [];
6452
+ this.findList = new LeafList();
6437
6453
  const { x, y } = this.point;
6438
6454
  const point = { x, y, radiusX: 0, radiusY: 0 };
6439
- for (let i = 0, len = targets.length; i < len; i++) {
6440
- find = targets[i];
6441
- 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)) {
6442
6458
  this.hitChild(find, point);
6443
6459
  if (this.findList.length)
6444
- return this.findList[0];
6460
+ return this.findList.list[0];
6445
6461
  }
6446
6462
  }
6447
6463
  }
6448
- 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];
6449
6472
  }
6450
6473
  getPath(leaf) {
6451
6474
  const path = new LeafList();
@@ -6487,6 +6510,9 @@ class Picker {
6487
6510
  }
6488
6511
  return throughPath;
6489
6512
  }
6513
+ hitBranch(branch) {
6514
+ this.eachFind(branch.children, branch.__onlyHitMask);
6515
+ }
6490
6516
  eachFind(children, hitMask) {
6491
6517
  let child, hit;
6492
6518
  const { point } = this, len = children.length;
@@ -6508,11 +6534,11 @@ class Picker {
6508
6534
  }
6509
6535
  }
6510
6536
  }
6511
- hitChild(child, point) {
6537
+ hitChild(child, point, proxy) {
6512
6538
  if (this.exclude && this.exclude.has(child))
6513
6539
  return;
6514
6540
  if (child.__hitWorld(point))
6515
- this.findList.push(child);
6541
+ this.findList.add(proxy || child);
6516
6542
  }
6517
6543
  clear() {
6518
6544
  this.point = null;
@@ -6710,7 +6736,11 @@ function zoomLayerType() {
6710
6736
  defineKey(target, key, {
6711
6737
  set(value) { if (this.isLeafer)
6712
6738
  this[privateKey] = value; },
6713
- 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
+ }
6714
6744
  });
6715
6745
  };
6716
6746
  }
@@ -7116,6 +7146,9 @@ let UI = UI_1 = class UI extends Leaf {
7116
7146
  pen.set(this.path = this.__.path || []);
7117
7147
  return pen;
7118
7148
  }
7149
+ get editConfig() { return undefined; }
7150
+ get editOuter() { return 'EditTool'; }
7151
+ get editInner() { return 'PathEditor'; }
7119
7152
  constructor(data) {
7120
7153
  super(data);
7121
7154
  }
@@ -7177,7 +7210,8 @@ let UI = UI_1 = class UI extends Leaf {
7177
7210
  __drawPathByBox(drawer) {
7178
7211
  const { x, y, width, height } = this.__layout.boxBounds;
7179
7212
  if (this.__.cornerRadius) {
7180
- drawer.roundRect(x, y, width, height, this.__.cornerRadius);
7213
+ const { cornerRadius } = this.__;
7214
+ drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
7181
7215
  }
7182
7216
  else {
7183
7217
  drawer.rect(x, y, width, height);
@@ -7198,6 +7232,9 @@ let UI = UI_1 = class UI extends Leaf {
7198
7232
  static registerData(data) {
7199
7233
  dataProcessor(data)(this.prototype);
7200
7234
  }
7235
+ static setEditConfig(_config) { }
7236
+ static setEditOuter(_toolName) { }
7237
+ static setEditInner(_editorName) { }
7201
7238
  destroy() {
7202
7239
  this.fill = this.stroke = null;
7203
7240
  super.destroy();
@@ -7281,15 +7318,15 @@ __decorate([
7281
7318
  __decorate([
7282
7319
  dataType(false)
7283
7320
  ], UI.prototype, "draggable", void 0);
7321
+ __decorate([
7322
+ dataType()
7323
+ ], UI.prototype, "dragBounds", void 0);
7284
7324
  __decorate([
7285
7325
  dataType(false)
7286
7326
  ], UI.prototype, "editable", void 0);
7287
7327
  __decorate([
7288
7328
  dataType('size')
7289
7329
  ], UI.prototype, "editSize", void 0);
7290
- __decorate([
7291
- dataType()
7292
- ], UI.prototype, "editorStyle", void 0);
7293
7330
  __decorate([
7294
7331
  hitType(true)
7295
7332
  ], UI.prototype, "hittable", void 0);
@@ -7481,7 +7518,6 @@ Group = __decorate([
7481
7518
  var Leafer_1;
7482
7519
  const debug$3 = Debug.get('Leafer');
7483
7520
  let Leafer = Leafer_1 = class Leafer extends Group {
7484
- static get version() { return '1.0.0-rc.21'; }
7485
7521
  get __tag() { return 'Leafer'; }
7486
7522
  get isApp() { return false; }
7487
7523
  get app() { return this.parent || this; }
@@ -7534,7 +7570,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7534
7570
  if (this.isApp)
7535
7571
  this.__setApp();
7536
7572
  this.__checkAutoLayout(config);
7537
- this.updateLazyBounds();
7538
7573
  this.view = canvas.view;
7539
7574
  if (parentApp) {
7540
7575
  this.__bindApp(parentApp);
@@ -7778,6 +7813,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7778
7813
  __listenEvents() {
7779
7814
  const runId = Run.start('FirstCreate ' + this.innerName);
7780
7815
  this.once(LeaferEvent.START, () => Run.end(runId));
7816
+ this.once(LayoutEvent.START, () => this.updateLazyBounds());
7781
7817
  this.once(LayoutEvent.END, () => this.__onReady());
7782
7818
  this.once(RenderEvent.START, () => this.__onCreated());
7783
7819
  this.once(RenderEvent.END, () => this.__onViewReady());
@@ -7848,8 +7884,8 @@ Rect = __decorate([
7848
7884
  registerUI()
7849
7885
  ], Rect);
7850
7886
 
7851
- const rect = Rect.prototype;
7852
- const group = Group.prototype;
7887
+ const rect$1 = Rect.prototype;
7888
+ const group$1 = Group.prototype;
7853
7889
  const bounds$1 = {};
7854
7890
  const { copy: copy$3, add } = BoundsHelper;
7855
7891
  let Box = class Box extends Group {
@@ -7928,28 +7964,28 @@ __decorate([
7928
7964
  affectRenderBoundsType('show')
7929
7965
  ], Box.prototype, "overflow", void 0);
7930
7966
  __decorate([
7931
- rewrite(rect.__updateStrokeSpread)
7967
+ rewrite(rect$1.__updateStrokeSpread)
7932
7968
  ], Box.prototype, "__updateStrokeSpread", null);
7933
7969
  __decorate([
7934
- rewrite(rect.__updateRenderSpread)
7970
+ rewrite(rect$1.__updateRenderSpread)
7935
7971
  ], Box.prototype, "__updateRectRenderSpread", null);
7936
7972
  __decorate([
7937
- rewrite(rect.__updateBoxBounds)
7973
+ rewrite(rect$1.__updateBoxBounds)
7938
7974
  ], Box.prototype, "__updateRectBoxBounds", null);
7939
7975
  __decorate([
7940
- rewrite(rect.__updateStrokeBounds)
7976
+ rewrite(rect$1.__updateStrokeBounds)
7941
7977
  ], Box.prototype, "__updateStrokeBounds", null);
7942
7978
  __decorate([
7943
- rewrite(rect.__updateRenderBounds)
7979
+ rewrite(rect$1.__updateRenderBounds)
7944
7980
  ], Box.prototype, "__updateRectRenderBounds", null);
7945
7981
  __decorate([
7946
- rewrite(rect.__updateChange)
7982
+ rewrite(rect$1.__updateChange)
7947
7983
  ], Box.prototype, "__updateRectChange", null);
7948
7984
  __decorate([
7949
- rewrite(rect.__render)
7985
+ rewrite(rect$1.__render)
7950
7986
  ], Box.prototype, "__renderRect", null);
7951
7987
  __decorate([
7952
- rewrite(group.__render)
7988
+ rewrite(group$1.__render)
7953
7989
  ], Box.prototype, "__renderGroup", null);
7954
7990
  Box = __decorate([
7955
7991
  rewriteAble(),
@@ -8296,6 +8332,7 @@ Canvas = __decorate([
8296
8332
  const { copyAndSpread, includes, spread, setList } = BoundsHelper;
8297
8333
  let Text = class Text extends UI {
8298
8334
  get __tag() { return 'Text'; }
8335
+ get editInner() { return 'TextEditor'; }
8299
8336
  get textDrawData() {
8300
8337
  this.__layout.update();
8301
8338
  return this.__.__textDrawData;
@@ -8618,7 +8655,8 @@ let App = class App extends Leafer {
8618
8655
  this.renderer.update();
8619
8656
  }
8620
8657
  __render(canvas, options) {
8621
- canvas.setWorld(options.matrix || this.__world);
8658
+ if (options.matrix)
8659
+ canvas.setWorld(options.matrix);
8622
8660
  this.children.forEach(leafer => canvas.copyWorld(leafer.canvas));
8623
8661
  }
8624
8662
  __onResize(event) {
@@ -8740,6 +8778,35 @@ let DragEvent = class DragEvent extends PointerEvent {
8740
8778
  static setData(data) {
8741
8779
  this.data = data;
8742
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
+ }
8743
8810
  getPageMove(total) {
8744
8811
  this.assignMove(total);
8745
8812
  return this.current.getPagePoint(move, null, true);
@@ -8849,9 +8916,7 @@ function addInteractionWindow(leafer) {
8849
8916
  if (leafer.isApp)
8850
8917
  return;
8851
8918
  leafer.__eventIds.push(leafer.on_(MoveEvent.BEFORE_MOVE, (e) => {
8852
- const { x, y } = leafer.getValidMove(e.moveX, e.moveY);
8853
- if (x || y)
8854
- leafer.zoomLayer.move(x, y);
8919
+ leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
8855
8920
  }), leafer.on_(ZoomEvent.BEFORE_ZOOM, (e) => {
8856
8921
  const { zoomLayer } = leafer;
8857
8922
  const changeScale = leafer.getValidScale(e.scale);
@@ -9120,9 +9185,14 @@ class Dragger {
9120
9185
  if (this.dragging) {
9121
9186
  this.interaction.emit(DragEvent.START, this.dragData);
9122
9187
  this.getDragableList(this.dragData.path);
9188
+ this.setDragStartPoints(this.realDragableList = this.getList());
9123
9189
  }
9124
9190
  }
9125
9191
  }
9192
+ setDragStartPoints(list) {
9193
+ this.dragStartPoints = {};
9194
+ list.forEach(leaf => this.dragStartPoints[leaf.innerId] = { x: leaf.x, y: leaf.y });
9195
+ }
9126
9196
  getDragableList(path) {
9127
9197
  let leaf;
9128
9198
  for (let i = 0, len = path.length; i < len; i++) {
@@ -9152,10 +9222,10 @@ class Dragger {
9152
9222
  }
9153
9223
  dragReal() {
9154
9224
  const { running } = this.interaction;
9155
- const list = this.getList();
9225
+ const list = this.realDragableList;
9156
9226
  if (list.length && running) {
9157
- const { moveX, moveY } = this.dragData;
9158
- 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 })));
9159
9229
  }
9160
9230
  }
9161
9231
  dragOverOrOut(data) {
@@ -9624,7 +9694,8 @@ class InteractionBase {
9624
9694
  }
9625
9695
  findPath(data, options) {
9626
9696
  const { hitRadius, through } = this.config.pointer;
9627
- 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 })));
9628
9699
  if (find.throughPath)
9629
9700
  data.throughPath = find.throughPath;
9630
9701
  data.path = find.path;
@@ -9637,7 +9708,7 @@ class InteractionBase {
9637
9708
  const app = this.target.app;
9638
9709
  if (!app || !app.isApp)
9639
9710
  return false;
9640
- 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);
9641
9712
  }
9642
9713
  checkPath(data, useDefaultPath) {
9643
9714
  if (useDefaultPath || this.canMove(data))
@@ -9703,7 +9774,7 @@ class InteractionBase {
9703
9774
  const { path } = data;
9704
9775
  for (let i = 0, len = path.length; i < len; i++) {
9705
9776
  leaf = path.list[i];
9706
- cursor = leaf.cursor;
9777
+ cursor = leaf.syncEventer ? leaf.syncEventer.cursor : leaf.cursor;
9707
9778
  if (cursor)
9708
9779
  break;
9709
9780
  }
@@ -9861,6 +9932,8 @@ const { toInnerRadiusPointOf, copy: copy$2, setRadius } = PointHelper;
9861
9932
  const inner = {};
9862
9933
  const leaf = Leaf.prototype;
9863
9934
  leaf.__hitWorld = function (point) {
9935
+ if (!this.__.hitSelf)
9936
+ return false;
9864
9937
  if (this.__.hitRadius) {
9865
9938
  copy$2(inner, point), point = inner;
9866
9939
  setRadius(point, this.__.hitRadius);
@@ -9888,8 +9961,8 @@ leaf.__drawHitPath = function (canvas) { if (canvas)
9888
9961
  this.__drawRenderPath(canvas); };
9889
9962
 
9890
9963
  const matrix = new Matrix();
9891
- const ui$1 = UI.prototype;
9892
- ui$1.__updateHitCanvas = function () {
9964
+ const ui$2 = UI.prototype;
9965
+ ui$2.__updateHitCanvas = function () {
9893
9966
  const data = this.__, { hitCanvasManager } = this.leafer;
9894
9967
  const isHitPixelFill = data.__pixelFill && data.hitFill === 'pixel';
9895
9968
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
@@ -9916,7 +9989,7 @@ ui$1.__updateHitCanvas = function () {
9916
9989
  this.__drawHitPath(h);
9917
9990
  h.setStrokeOptions(data);
9918
9991
  };
9919
- ui$1.__hit = function (inner) {
9992
+ ui$2.__hit = function (inner) {
9920
9993
  if (Platform.name === 'miniapp')
9921
9994
  this.__drawHitPath(this.__hitCanvas);
9922
9995
  const data = this.__;
@@ -9956,22 +10029,24 @@ ui$1.__hit = function (inner) {
9956
10029
  return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
9957
10030
  };
9958
10031
 
9959
- const ui = new UI();
9960
- Rect.prototype.__updateHitCanvas = function () {
10032
+ const ui$1 = new UI();
10033
+ const rect = Rect.prototype;
10034
+ rect.__updateHitCanvas = function () {
9961
10035
  if (this.stroke || this.cornerRadius)
9962
- ui.__updateHitCanvas.call(this);
10036
+ ui$1.__updateHitCanvas.call(this);
9963
10037
  };
9964
- Rect.prototype.__hitFill = function (inner) {
9965
- 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);
9966
10040
  };
9967
10041
 
9968
- UI.prototype.find = function (condition, options) {
10042
+ const ui = UI.prototype, group = Group.prototype;
10043
+ ui.find = function (condition, options) {
9969
10044
  return this.leafer ? this.leafer.selector.getBy(condition, this, false, options) : [];
9970
10045
  };
9971
- UI.prototype.findOne = function (condition, options) {
10046
+ ui.findOne = function (condition, options) {
9972
10047
  return this.leafer ? this.leafer.selector.getBy(condition, this, true, options) : null;
9973
10048
  };
9974
- Group.prototype.pick = function (hitPoint, options) {
10049
+ group.pick = function (hitPoint, options) {
9975
10050
  this.__layout.update();
9976
10051
  if (!options)
9977
10052
  options = {};
@@ -10627,79 +10702,75 @@ const PaintModule = {
10627
10702
 
10628
10703
  let origin = {};
10629
10704
  const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
10630
- function fillOrFitMode(data, mode, box, width, height, rotation) {
10705
+ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10631
10706
  const transform = get$4();
10632
- const swap = rotation && rotation !== 180;
10633
- const sw = box.width / (swap ? height : width);
10634
- const sh = box.height / (swap ? width : height);
10635
- const scale = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
10636
- const x = box.x + (box.width - width * scale) / 2;
10637
- const y = box.y + (box.height - height * scale) / 2;
10638
- translate$1(transform, x, y);
10639
- scaleHelper(transform, scale);
10707
+ translate$1(transform, box.x + x, box.y + y);
10708
+ scaleHelper(transform, scaleX, scaleY);
10640
10709
  if (rotation)
10641
10710
  rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10642
- data.scaleX = data.scaleY = scale;
10643
10711
  data.transform = transform;
10644
10712
  }
10645
10713
  function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
10646
10714
  const transform = get$4();
10647
- translate$1(transform, box.x, box.y);
10648
- if (x || y)
10649
- translate$1(transform, x, y);
10650
- if (scaleX) {
10715
+ translate$1(transform, box.x + x, box.y + y);
10716
+ if (scaleX)
10651
10717
  scaleHelper(transform, scaleX, scaleY);
10652
- data.scaleX = transform.a;
10653
- data.scaleY = transform.d;
10654
- }
10655
10718
  if (rotation)
10656
10719
  rotate(transform, rotation);
10657
10720
  data.transform = transform;
10658
10721
  }
10659
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation) {
10722
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around) {
10660
10723
  const transform = get$4();
10661
10724
  if (rotation) {
10662
- rotate(transform, rotation);
10663
- switch (rotation) {
10664
- case 90:
10665
- translate$1(transform, height, 0);
10666
- break;
10667
- case 180:
10668
- translate$1(transform, width, height);
10669
- break;
10670
- case 270:
10671
- translate$1(transform, 0, width);
10672
- 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
+ }
10673
10741
  }
10674
10742
  }
10675
- origin.x = box.x;
10676
- origin.y = box.y;
10677
- if (x || y)
10678
- origin.x += x, origin.y += y;
10743
+ origin.x = box.x + x;
10744
+ origin.y = box.y + y;
10679
10745
  translate$1(transform, origin.x, origin.y);
10680
- if (scaleX) {
10746
+ if (scaleX)
10681
10747
  scaleOfOuter$2(transform, origin, scaleX, scaleY);
10682
- data.scaleX = scaleX;
10683
- data.scaleY = scaleY;
10684
- }
10685
10748
  data.transform = transform;
10686
10749
  }
10687
10750
 
10688
10751
  const { get: get$3, translate } = MatrixHelper;
10689
10752
  const tempBox = new Bounds();
10753
+ const tempPoint = {};
10690
10754
  function createData(leafPaint, image, paint, box) {
10691
10755
  let { width, height } = image;
10692
10756
  if (paint.padding)
10693
10757
  box = tempBox.set(box).shrink(paint.padding);
10694
- const { opacity, mode, offset, scale, size, rotation, blendMode, repeat } = paint;
10758
+ const { opacity, mode, around, offset, scale, size, rotation, blendMode, repeat } = paint;
10695
10759
  const sameBox = box.width === width && box.height === height;
10696
10760
  if (blendMode)
10697
10761
  leafPaint.blendMode = blendMode;
10698
10762
  const data = leafPaint.data = { mode };
10699
- let x, y, scaleX, scaleY;
10700
- if (offset)
10701
- x = offset.x, y = offset.y;
10702
- 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) {
10703
10774
  scaleX = (typeof size === 'number' ? size : size.width) / width;
10704
10775
  scaleY = (typeof size === 'number' ? size : size.height) / height;
10705
10776
  }
@@ -10707,26 +10778,36 @@ function createData(leafPaint, image, paint, box) {
10707
10778
  scaleX = typeof scale === 'number' ? scale : scale.x;
10708
10779
  scaleY = typeof scale === 'number' ? scale : scale.y;
10709
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;
10710
10790
  switch (mode) {
10711
10791
  case 'strench':
10712
10792
  if (!sameBox)
10713
10793
  width = box.width, height = box.height;
10714
10794
  break;
10795
+ case 'normal':
10715
10796
  case 'clip':
10716
- if (offset || scaleX || rotation)
10797
+ if (x || y || scaleX || rotation)
10717
10798
  clipMode(data, box, x, y, scaleX, scaleY, rotation);
10718
10799
  break;
10719
10800
  case 'repeat':
10720
10801
  if (!sameBox || scaleX || rotation)
10721
- repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation);
10802
+ repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around);
10722
10803
  if (!repeat)
10723
10804
  data.repeat = 'repeat';
10724
10805
  break;
10725
10806
  case 'fit':
10726
10807
  case 'cover':
10727
10808
  default:
10728
- if (!sameBox || rotation)
10729
- fillOrFitMode(data, mode, box, width, height, rotation);
10809
+ if (scaleX)
10810
+ fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation);
10730
10811
  }
10731
10812
  if (!data.transform) {
10732
10813
  if (box.x || box.y) {
@@ -10734,6 +10815,10 @@ function createData(leafPaint, image, paint, box) {
10734
10815
  translate(data.transform, box.x, box.y);
10735
10816
  }
10736
10817
  }
10818
+ if (scaleX && mode !== 'strench') {
10819
+ data.scaleX = scaleX;
10820
+ data.scaleY = scaleY;
10821
+ }
10737
10822
  data.width = width;
10738
10823
  data.height = height;
10739
10824
  if (opacity)
@@ -11789,6 +11874,13 @@ const ExportModule = {
11789
11874
  resolve();
11790
11875
  this.running = false;
11791
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
+ }
11792
11884
  const { leafer } = leaf;
11793
11885
  if (leafer) {
11794
11886
  leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
@@ -11938,4 +12030,4 @@ window.addEventListener('unload', () => {
11938
12030
  ImageManager.destroy();
11939
12031
  });
11940
12032
 
11941
- 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 };