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.
package/dist/web.js CHANGED
@@ -120,7 +120,7 @@ var LeaferUI = (function (exports) {
120
120
 
121
121
  const { sin: sin$5, cos: cos$5, acos, sqrt: sqrt$3 } = Math;
122
122
  const { float: float$1 } = MathHelper;
123
- const tempPoint$3 = {};
123
+ const tempPoint$4 = {};
124
124
  function getWorld() {
125
125
  return Object.assign(Object.assign(Object.assign({}, getMatrixData()), getBoundsData()), { scaleX: 1, scaleY: 1, rotation: 0, skewX: 0, skewY: 0 });
126
126
  }
@@ -161,8 +161,8 @@ var LeaferUI = (function (exports) {
161
161
  t.d *= scaleY;
162
162
  },
163
163
  scaleOfOuter(t, origin, scaleX, scaleY) {
164
- M$6.toInnerPoint(t, origin, tempPoint$3);
165
- M$6.scaleOfInner(t, tempPoint$3, scaleX, scaleY);
164
+ M$6.toInnerPoint(t, origin, tempPoint$4);
165
+ M$6.scaleOfInner(t, tempPoint$4, scaleX, scaleY);
166
166
  },
167
167
  scaleOfInner(t, origin, scaleX, scaleY = scaleX) {
168
168
  M$6.translateInner(t, origin.x, origin.y);
@@ -180,8 +180,8 @@ var LeaferUI = (function (exports) {
180
180
  t.d = c * sinR + d * cosR;
181
181
  },
182
182
  rotateOfOuter(t, origin, rotation) {
183
- M$6.toInnerPoint(t, origin, tempPoint$3);
184
- M$6.rotateOfInner(t, tempPoint$3, rotation);
183
+ M$6.toInnerPoint(t, origin, tempPoint$4);
184
+ M$6.rotateOfInner(t, tempPoint$4, rotation);
185
185
  },
186
186
  rotateOfInner(t, origin, rotation) {
187
187
  M$6.translateInner(t, origin.x, origin.y);
@@ -202,8 +202,8 @@ var LeaferUI = (function (exports) {
202
202
  }
203
203
  },
204
204
  skewOfOuter(t, origin, skewX, skewY) {
205
- M$6.toInnerPoint(t, origin, tempPoint$3);
206
- M$6.skewOfInner(t, tempPoint$3, skewX, skewY);
205
+ M$6.toInnerPoint(t, origin, tempPoint$4);
206
+ M$6.skewOfInner(t, tempPoint$4, skewX, skewY);
207
207
  },
208
208
  skewOfInner(t, origin, skewX, skewY = 0) {
209
209
  M$6.translateInner(t, origin.x, origin.y);
@@ -597,7 +597,7 @@ var LeaferUI = (function (exports) {
597
597
  return this;
598
598
  }
599
599
  }
600
- const tempPoint$2 = new Point();
600
+ const tempPoint$3 = new Point();
601
601
 
602
602
  class Matrix {
603
603
  constructor(a, b, c, d, e, f) {
@@ -1209,11 +1209,19 @@ var LeaferUI = (function (exports) {
1209
1209
  directionData,
1210
1210
  tempPoint: {},
1211
1211
  get: get$5,
1212
- toPoint(around, bounds, to, onlySize) {
1212
+ toPoint(around, bounds, to, onlySize, pointBounds) {
1213
1213
  to || (to = {});
1214
1214
  const point = get$5(around);
1215
1215
  to.x = point.x * bounds.width;
1216
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);
1224
+ }
1217
1225
  if (!onlySize) {
1218
1226
  to.x += bounds.x;
1219
1227
  to.y += bounds.y;
@@ -2211,7 +2219,7 @@ var LeaferUI = (function (exports) {
2211
2219
  const { setPoint: setPoint$2, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2212
2220
  const { set: set$2 } = PointHelper;
2213
2221
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$5 } = PathCommandMap;
2214
- const tempPoint$1 = {};
2222
+ const tempPoint$2 = {};
2215
2223
  const BezierHelper = {
2216
2224
  points(data, points, curve, close) {
2217
2225
  data.push(M$5, points[0], points[1]);
@@ -2401,8 +2409,8 @@ var LeaferUI = (function (exports) {
2401
2409
  addMode ? addPoint$2(pointBounds, fromX, fromY) : setPoint$2(pointBounds, fromX, fromY);
2402
2410
  addPoint$2(pointBounds, toX, toY);
2403
2411
  for (let i = 0, len = tList.length; i < len; i++) {
2404
- getPointAndSet(tList[i], fromX, fromY, x1, y1, x2, y2, toX, toY, tempPoint$1);
2405
- addPoint$2(pointBounds, tempPoint$1.x, tempPoint$1.y);
2412
+ getPointAndSet(tList[i], fromX, fromY, x1, y1, x2, y2, toX, toY, tempPoint$2);
2413
+ addPoint$2(pointBounds, tempPoint$2.x, tempPoint$2.y);
2406
2414
  }
2407
2415
  },
2408
2416
  getPointAndSet(t, fromX, fromY, x1, y1, x2, y2, toX, toY, setPoint) {
@@ -2472,7 +2480,7 @@ var LeaferUI = (function (exports) {
2472
2480
  };
2473
2481
 
2474
2482
  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;
2475
- const { rect: rect$2, roundRect: roundRect$2, arcTo: arcTo$3, arc: arc$3, ellipse: ellipse$4, quadraticCurveTo: quadraticCurveTo$1 } = BezierHelper;
2483
+ const { rect: rect$3, roundRect: roundRect$2, arcTo: arcTo$3, arc: arc$3, ellipse: ellipse$4, quadraticCurveTo: quadraticCurveTo$1 } = BezierHelper;
2476
2484
  const { ellipticalArc } = EllipseHelper;
2477
2485
  const debug$d = Debug.get('PathConvert');
2478
2486
  const setEndPoint$1 = {};
@@ -2665,7 +2673,7 @@ var LeaferUI = (function (exports) {
2665
2673
  case N$3:
2666
2674
  x = old[i + 1];
2667
2675
  y = old[i + 2];
2668
- curveMode ? rect$2(data, x, y, old[i + 3], old[i + 4]) : copyData(data, old, i, 5);
2676
+ curveMode ? rect$3(data, x, y, old[i + 3], old[i + 4]) : copyData(data, old, i, 5);
2669
2677
  i += 5;
2670
2678
  break;
2671
2679
  case D$3:
@@ -2822,7 +2830,7 @@ var LeaferUI = (function (exports) {
2822
2830
  };
2823
2831
  const { ellipse: ellipse$3, arc: arc$2 } = PathCommandDataHelper;
2824
2832
 
2825
- 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;
2833
+ 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;
2826
2834
  class PathCreator {
2827
2835
  set path(value) { this.__path = value; }
2828
2836
  get path() { return this.__path; }
@@ -2864,7 +2872,7 @@ var LeaferUI = (function (exports) {
2864
2872
  return this;
2865
2873
  }
2866
2874
  rect(x, y, width, height) {
2867
- rect$1(this.__path, x, y, width, height);
2875
+ rect$2(this.__path, x, y, width, height);
2868
2876
  return this;
2869
2877
  }
2870
2878
  roundRect(x, y, width, height, cornerRadius) {
@@ -3959,15 +3967,21 @@ var LeaferUI = (function (exports) {
3959
3967
  }
3960
3968
  return true;
3961
3969
  },
3962
- moveWorld(t, x, y) {
3963
- const local = { x, y };
3970
+ moveWorld(t, x, y = 0) {
3971
+ const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
3964
3972
  if (t.parent)
3965
3973
  toInnerPoint$1(t.parent.worldTransform, local, local, true);
3966
3974
  L.moveLocal(t, local.x, local.y);
3967
3975
  },
3968
3976
  moveLocal(t, x, y = 0) {
3969
- t.x += x;
3970
- t.y += y;
3977
+ if (typeof x === 'object') {
3978
+ t.x += x.x;
3979
+ t.y += x.y;
3980
+ }
3981
+ else {
3982
+ t.x += x;
3983
+ t.y += y;
3984
+ }
3971
3985
  },
3972
3986
  zoomOfWorld(t, origin, scaleX, scaleY, resize) {
3973
3987
  L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
@@ -4529,12 +4543,15 @@ var LeaferUI = (function (exports) {
4529
4543
  break;
4530
4544
  }
4531
4545
  }
4546
+ this.syncEventer && this.syncEventer.emitEvent(event, capture);
4532
4547
  },
4533
4548
  emitEvent(event, capture) {
4534
4549
  event.current = this;
4535
4550
  this.emit(event.type, event, capture);
4536
4551
  },
4537
4552
  hasEvent(type, capture) {
4553
+ if (this.syncEventer && this.syncEventer.hasEvent(type, capture))
4554
+ return true;
4538
4555
  const { __bubbleMap: b, __captureMap: c } = this;
4539
4556
  const hasB = b && b[type], hasC = c && c[type];
4540
4557
  return !!(capture === undefined ? (hasB || hasC) : (capture ? hasC : hasB));
@@ -4754,7 +4771,7 @@ var LeaferUI = (function (exports) {
4754
4771
  };
4755
4772
 
4756
4773
  const { setLayout, multiplyParent: multiplyParent$1, translateInner, defaultWorld } = MatrixHelper;
4757
- const { toPoint, tempPoint } = AroundHelper;
4774
+ const { toPoint, tempPoint: tempPoint$1 } = AroundHelper;
4758
4775
  const LeafMatrix = {
4759
4776
  __updateWorldMatrix() {
4760
4777
  multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__);
@@ -4771,8 +4788,8 @@ var LeaferUI = (function (exports) {
4771
4788
  local.e = data.x;
4772
4789
  local.f = data.y;
4773
4790
  if (data.around) {
4774
- toPoint(data.around, layout.boxBounds, tempPoint);
4775
- translateInner(local, -tempPoint.x, -tempPoint.y);
4791
+ toPoint(data.around, layout.boxBounds, tempPoint$1);
4792
+ translateInner(local, -tempPoint$1.x, -tempPoint$1.y);
4776
4793
  }
4777
4794
  }
4778
4795
  this.__layout.matrixChanged = false;
@@ -6423,32 +6440,38 @@ var LeaferUI = (function (exports) {
6423
6440
  const target = options.target || this.target;
6424
6441
  this.exclude = options.exclude || null;
6425
6442
  this.point = { x: hitPoint.x, y: hitPoint.y, radiusX: hitRadius, radiusY: hitRadius };
6426
- this.findList = options.findList || [];
6443
+ this.findList = new LeafList(options.findList);
6427
6444
  if (!options.findList)
6428
- this.eachFind(target.children, target.__onlyHitMask);
6429
- const list = this.findList;
6430
- const leaf = this.getBestMatchLeaf();
6445
+ this.hitBranch(target);
6446
+ const { list } = this.findList;
6447
+ const leaf = this.getBestMatchLeaf(list, options.bottomList, ignoreHittable);
6431
6448
  const path = ignoreHittable ? this.getPath(leaf) : this.getHitablePath(leaf);
6432
6449
  this.clear();
6433
6450
  return through ? { path, target: leaf, throughPath: list.length ? this.getThroughPath(list) : path } : { path, target: leaf };
6434
6451
  }
6435
- getBestMatchLeaf() {
6436
- const { findList: targets } = this;
6437
- if (targets.length > 1) {
6452
+ getBestMatchLeaf(list, bottomList, ignoreHittable) {
6453
+ if (list.length) {
6438
6454
  let find;
6439
- this.findList = [];
6455
+ this.findList = new LeafList();
6440
6456
  const { x, y } = this.point;
6441
6457
  const point = { x, y, radiusX: 0, radiusY: 0 };
6442
- for (let i = 0, len = targets.length; i < len; i++) {
6443
- find = targets[i];
6444
- if (LeafHelper.worldHittable(find)) {
6458
+ for (let i = 0, len = list.length; i < len; i++) {
6459
+ find = list[i];
6460
+ if (ignoreHittable || LeafHelper.worldHittable(find)) {
6445
6461
  this.hitChild(find, point);
6446
6462
  if (this.findList.length)
6447
- return this.findList[0];
6463
+ return this.findList.list[0];
6448
6464
  }
6449
6465
  }
6450
6466
  }
6451
- return targets[0];
6467
+ if (bottomList) {
6468
+ for (let i = 0, len = bottomList.length; i < len; i++) {
6469
+ this.hitChild(bottomList[i].target, this.point, bottomList[i].proxy);
6470
+ if (this.findList.length)
6471
+ return this.findList.list[0];
6472
+ }
6473
+ }
6474
+ return list[0];
6452
6475
  }
6453
6476
  getPath(leaf) {
6454
6477
  const path = new LeafList();
@@ -6490,6 +6513,9 @@ var LeaferUI = (function (exports) {
6490
6513
  }
6491
6514
  return throughPath;
6492
6515
  }
6516
+ hitBranch(branch) {
6517
+ this.eachFind(branch.children, branch.__onlyHitMask);
6518
+ }
6493
6519
  eachFind(children, hitMask) {
6494
6520
  let child, hit;
6495
6521
  const { point } = this, len = children.length;
@@ -6511,11 +6537,11 @@ var LeaferUI = (function (exports) {
6511
6537
  }
6512
6538
  }
6513
6539
  }
6514
- hitChild(child, point) {
6540
+ hitChild(child, point, proxy) {
6515
6541
  if (this.exclude && this.exclude.has(child))
6516
6542
  return;
6517
6543
  if (child.__hitWorld(point))
6518
- this.findList.push(child);
6544
+ this.findList.add(proxy || child);
6519
6545
  }
6520
6546
  clear() {
6521
6547
  this.point = null;
@@ -6713,7 +6739,11 @@ var LeaferUI = (function (exports) {
6713
6739
  defineKey(target, key, {
6714
6740
  set(value) { if (this.isLeafer)
6715
6741
  this[privateKey] = value; },
6716
- get() { return this.isLeafer ? (this[privateKey] || this) : this.leafer && this.leafer.zoomLayer; }
6742
+ get() {
6743
+ return this.isApp
6744
+ ? this.tree.zoomLayer
6745
+ : (this.isLeafer ? (this[privateKey] || this) : this.leafer && this.leafer.zoomLayer);
6746
+ }
6717
6747
  });
6718
6748
  };
6719
6749
  }
@@ -7119,6 +7149,9 @@ var LeaferUI = (function (exports) {
7119
7149
  pen.set(this.path = this.__.path || []);
7120
7150
  return pen;
7121
7151
  }
7152
+ get editConfig() { return undefined; }
7153
+ get editOuter() { return 'EditTool'; }
7154
+ get editInner() { return 'PathEditor'; }
7122
7155
  constructor(data) {
7123
7156
  super(data);
7124
7157
  }
@@ -7180,7 +7213,8 @@ var LeaferUI = (function (exports) {
7180
7213
  __drawPathByBox(drawer) {
7181
7214
  const { x, y, width, height } = this.__layout.boxBounds;
7182
7215
  if (this.__.cornerRadius) {
7183
- drawer.roundRect(x, y, width, height, this.__.cornerRadius);
7216
+ const { cornerRadius } = this.__;
7217
+ drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
7184
7218
  }
7185
7219
  else {
7186
7220
  drawer.rect(x, y, width, height);
@@ -7201,6 +7235,9 @@ var LeaferUI = (function (exports) {
7201
7235
  static registerData(data) {
7202
7236
  dataProcessor(data)(this.prototype);
7203
7237
  }
7238
+ static setEditConfig(_config) { }
7239
+ static setEditOuter(_toolName) { }
7240
+ static setEditInner(_editorName) { }
7204
7241
  destroy() {
7205
7242
  this.fill = this.stroke = null;
7206
7243
  super.destroy();
@@ -7284,15 +7321,15 @@ var LeaferUI = (function (exports) {
7284
7321
  __decorate([
7285
7322
  dataType(false)
7286
7323
  ], exports.UI.prototype, "draggable", void 0);
7324
+ __decorate([
7325
+ dataType()
7326
+ ], exports.UI.prototype, "dragBounds", void 0);
7287
7327
  __decorate([
7288
7328
  dataType(false)
7289
7329
  ], exports.UI.prototype, "editable", void 0);
7290
7330
  __decorate([
7291
7331
  dataType('size')
7292
7332
  ], exports.UI.prototype, "editSize", void 0);
7293
- __decorate([
7294
- dataType()
7295
- ], exports.UI.prototype, "editorStyle", void 0);
7296
7333
  __decorate([
7297
7334
  hitType(true)
7298
7335
  ], exports.UI.prototype, "hittable", void 0);
@@ -7484,7 +7521,6 @@ var LeaferUI = (function (exports) {
7484
7521
  var Leafer_1;
7485
7522
  const debug$3 = Debug.get('Leafer');
7486
7523
  exports.Leafer = Leafer_1 = class Leafer extends exports.Group {
7487
- static get version() { return '1.0.0-rc.21'; }
7488
7524
  get __tag() { return 'Leafer'; }
7489
7525
  get isApp() { return false; }
7490
7526
  get app() { return this.parent || this; }
@@ -7537,7 +7573,6 @@ var LeaferUI = (function (exports) {
7537
7573
  if (this.isApp)
7538
7574
  this.__setApp();
7539
7575
  this.__checkAutoLayout(config);
7540
- this.updateLazyBounds();
7541
7576
  this.view = canvas.view;
7542
7577
  if (parentApp) {
7543
7578
  this.__bindApp(parentApp);
@@ -7781,6 +7816,7 @@ var LeaferUI = (function (exports) {
7781
7816
  __listenEvents() {
7782
7817
  const runId = Run.start('FirstCreate ' + this.innerName);
7783
7818
  this.once(LeaferEvent.START, () => Run.end(runId));
7819
+ this.once(LayoutEvent.START, () => this.updateLazyBounds());
7784
7820
  this.once(LayoutEvent.END, () => this.__onReady());
7785
7821
  this.once(RenderEvent.START, () => this.__onCreated());
7786
7822
  this.once(RenderEvent.END, () => this.__onViewReady());
@@ -7851,8 +7887,8 @@ var LeaferUI = (function (exports) {
7851
7887
  registerUI()
7852
7888
  ], exports.Rect);
7853
7889
 
7854
- const rect = exports.Rect.prototype;
7855
- const group = exports.Group.prototype;
7890
+ const rect$1 = exports.Rect.prototype;
7891
+ const group$1 = exports.Group.prototype;
7856
7892
  const bounds$1 = {};
7857
7893
  const { copy: copy$3, add } = BoundsHelper;
7858
7894
  exports.Box = class Box extends exports.Group {
@@ -7931,28 +7967,28 @@ var LeaferUI = (function (exports) {
7931
7967
  affectRenderBoundsType('show')
7932
7968
  ], exports.Box.prototype, "overflow", void 0);
7933
7969
  __decorate([
7934
- rewrite(rect.__updateStrokeSpread)
7970
+ rewrite(rect$1.__updateStrokeSpread)
7935
7971
  ], exports.Box.prototype, "__updateStrokeSpread", null);
7936
7972
  __decorate([
7937
- rewrite(rect.__updateRenderSpread)
7973
+ rewrite(rect$1.__updateRenderSpread)
7938
7974
  ], exports.Box.prototype, "__updateRectRenderSpread", null);
7939
7975
  __decorate([
7940
- rewrite(rect.__updateBoxBounds)
7976
+ rewrite(rect$1.__updateBoxBounds)
7941
7977
  ], exports.Box.prototype, "__updateRectBoxBounds", null);
7942
7978
  __decorate([
7943
- rewrite(rect.__updateStrokeBounds)
7979
+ rewrite(rect$1.__updateStrokeBounds)
7944
7980
  ], exports.Box.prototype, "__updateStrokeBounds", null);
7945
7981
  __decorate([
7946
- rewrite(rect.__updateRenderBounds)
7982
+ rewrite(rect$1.__updateRenderBounds)
7947
7983
  ], exports.Box.prototype, "__updateRectRenderBounds", null);
7948
7984
  __decorate([
7949
- rewrite(rect.__updateChange)
7985
+ rewrite(rect$1.__updateChange)
7950
7986
  ], exports.Box.prototype, "__updateRectChange", null);
7951
7987
  __decorate([
7952
- rewrite(rect.__render)
7988
+ rewrite(rect$1.__render)
7953
7989
  ], exports.Box.prototype, "__renderRect", null);
7954
7990
  __decorate([
7955
- rewrite(group.__render)
7991
+ rewrite(group$1.__render)
7956
7992
  ], exports.Box.prototype, "__renderGroup", null);
7957
7993
  exports.Box = __decorate([
7958
7994
  rewriteAble(),
@@ -8299,6 +8335,7 @@ var LeaferUI = (function (exports) {
8299
8335
  const { copyAndSpread, includes, spread, setList } = BoundsHelper;
8300
8336
  exports.Text = class Text extends exports.UI {
8301
8337
  get __tag() { return 'Text'; }
8338
+ get editInner() { return 'TextEditor'; }
8302
8339
  get textDrawData() {
8303
8340
  this.__layout.update();
8304
8341
  return this.__.__textDrawData;
@@ -8621,7 +8658,8 @@ var LeaferUI = (function (exports) {
8621
8658
  this.renderer.update();
8622
8659
  }
8623
8660
  __render(canvas, options) {
8624
- canvas.setWorld(options.matrix || this.__world);
8661
+ if (options.matrix)
8662
+ canvas.setWorld(options.matrix);
8625
8663
  this.children.forEach(leafer => canvas.copyWorld(leafer.canvas));
8626
8664
  }
8627
8665
  __onResize(event) {
@@ -8743,6 +8781,35 @@ var LeaferUI = (function (exports) {
8743
8781
  static setData(data) {
8744
8782
  this.data = data;
8745
8783
  }
8784
+ static getValidMove(leaf, start, total) {
8785
+ const { draggable, dragBounds, x, y } = leaf;
8786
+ const move = leaf.getLocalPoint(total, null, true);
8787
+ move.x += start.x - x;
8788
+ move.y += start.y - y;
8789
+ if (dragBounds)
8790
+ this.getMoveInDragBounds(leaf.__local, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true);
8791
+ if (draggable === 'x')
8792
+ move.y = 0;
8793
+ if (draggable === 'y')
8794
+ move.x = 0;
8795
+ return move;
8796
+ }
8797
+ static getMoveInDragBounds(box, dragBounds, move, change) {
8798
+ const x = box.x + move.x, y = box.y + move.y;
8799
+ const right = x + box.width, bottom = y + box.height;
8800
+ const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
8801
+ if (!change)
8802
+ move = Object.assign({}, move);
8803
+ if (x < dragBounds.x)
8804
+ move.x += dragBounds.x - x;
8805
+ else if (right > boundsRight)
8806
+ move.x += boundsRight - right;
8807
+ if (y < dragBounds.y)
8808
+ move.y += dragBounds.y - y;
8809
+ else if (bottom > boundsBottom)
8810
+ move.y += boundsBottom - bottom;
8811
+ return move;
8812
+ }
8746
8813
  getPageMove(total) {
8747
8814
  this.assignMove(total);
8748
8815
  return this.current.getPagePoint(move, null, true);
@@ -8852,9 +8919,7 @@ var LeaferUI = (function (exports) {
8852
8919
  if (leafer.isApp)
8853
8920
  return;
8854
8921
  leafer.__eventIds.push(leafer.on_(exports.MoveEvent.BEFORE_MOVE, (e) => {
8855
- const { x, y } = leafer.getValidMove(e.moveX, e.moveY);
8856
- if (x || y)
8857
- leafer.zoomLayer.move(x, y);
8922
+ leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
8858
8923
  }), leafer.on_(exports.ZoomEvent.BEFORE_ZOOM, (e) => {
8859
8924
  const { zoomLayer } = leafer;
8860
8925
  const changeScale = leafer.getValidScale(e.scale);
@@ -9123,9 +9188,14 @@ var LeaferUI = (function (exports) {
9123
9188
  if (this.dragging) {
9124
9189
  this.interaction.emit(exports.DragEvent.START, this.dragData);
9125
9190
  this.getDragableList(this.dragData.path);
9191
+ this.setDragStartPoints(this.realDragableList = this.getList());
9126
9192
  }
9127
9193
  }
9128
9194
  }
9195
+ setDragStartPoints(list) {
9196
+ this.dragStartPoints = {};
9197
+ list.forEach(leaf => this.dragStartPoints[leaf.innerId] = { x: leaf.x, y: leaf.y });
9198
+ }
9129
9199
  getDragableList(path) {
9130
9200
  let leaf;
9131
9201
  for (let i = 0, len = path.length; i < len; i++) {
@@ -9155,10 +9225,10 @@ var LeaferUI = (function (exports) {
9155
9225
  }
9156
9226
  dragReal() {
9157
9227
  const { running } = this.interaction;
9158
- const list = this.getList();
9228
+ const list = this.realDragableList;
9159
9229
  if (list.length && running) {
9160
- const { moveX, moveY } = this.dragData;
9161
- list.forEach(leaf => leaf.draggable && leaf.moveWorld(moveX, moveY));
9230
+ const { totalX, totalY } = this.dragData;
9231
+ list.forEach(leaf => leaf.draggable && leaf.move(exports.DragEvent.getValidMove(leaf, this.dragStartPoints[leaf.innerId], { x: totalX, y: totalY })));
9162
9232
  }
9163
9233
  }
9164
9234
  dragOverOrOut(data) {
@@ -9627,7 +9697,8 @@ var LeaferUI = (function (exports) {
9627
9697
  }
9628
9698
  findPath(data, options) {
9629
9699
  const { hitRadius, through } = this.config.pointer;
9630
- const find = this.selector.getByPoint(data, hitRadius, options || { through });
9700
+ const { bottomList } = this;
9701
+ const find = this.selector.getByPoint(data, hitRadius, Object.assign({ bottomList, name: data.type }, (options || { through })));
9631
9702
  if (find.throughPath)
9632
9703
  data.throughPath = find.throughPath;
9633
9704
  data.path = find.path;
@@ -9640,7 +9711,7 @@ var LeaferUI = (function (exports) {
9640
9711
  const app = this.target.app;
9641
9712
  if (!app || !app.isApp)
9642
9713
  return false;
9643
- return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree));
9714
+ return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree) && !data.target.syncEventer);
9644
9715
  }
9645
9716
  checkPath(data, useDefaultPath) {
9646
9717
  if (useDefaultPath || this.canMove(data))
@@ -9706,7 +9777,7 @@ var LeaferUI = (function (exports) {
9706
9777
  const { path } = data;
9707
9778
  for (let i = 0, len = path.length; i < len; i++) {
9708
9779
  leaf = path.list[i];
9709
- cursor = leaf.cursor;
9780
+ cursor = leaf.syncEventer ? leaf.syncEventer.cursor : leaf.cursor;
9710
9781
  if (cursor)
9711
9782
  break;
9712
9783
  }
@@ -9864,6 +9935,8 @@ var LeaferUI = (function (exports) {
9864
9935
  const inner = {};
9865
9936
  const leaf = exports.Leaf.prototype;
9866
9937
  leaf.__hitWorld = function (point) {
9938
+ if (!this.__.hitSelf)
9939
+ return false;
9867
9940
  if (this.__.hitRadius) {
9868
9941
  copy$2(inner, point), point = inner;
9869
9942
  setRadius(point, this.__.hitRadius);
@@ -9891,8 +9964,8 @@ var LeaferUI = (function (exports) {
9891
9964
  this.__drawRenderPath(canvas); };
9892
9965
 
9893
9966
  const matrix = new Matrix();
9894
- const ui$1 = exports.UI.prototype;
9895
- ui$1.__updateHitCanvas = function () {
9967
+ const ui$2 = exports.UI.prototype;
9968
+ ui$2.__updateHitCanvas = function () {
9896
9969
  const data = this.__, { hitCanvasManager } = this.leafer;
9897
9970
  const isHitPixelFill = data.__pixelFill && data.hitFill === 'pixel';
9898
9971
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
@@ -9919,7 +9992,7 @@ var LeaferUI = (function (exports) {
9919
9992
  this.__drawHitPath(h);
9920
9993
  h.setStrokeOptions(data);
9921
9994
  };
9922
- ui$1.__hit = function (inner) {
9995
+ ui$2.__hit = function (inner) {
9923
9996
  if (Platform.name === 'miniapp')
9924
9997
  this.__drawHitPath(this.__hitCanvas);
9925
9998
  const data = this.__;
@@ -9959,22 +10032,24 @@ var LeaferUI = (function (exports) {
9959
10032
  return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
9960
10033
  };
9961
10034
 
9962
- const ui = new exports.UI();
9963
- exports.Rect.prototype.__updateHitCanvas = function () {
10035
+ const ui$1 = new exports.UI();
10036
+ const rect = exports.Rect.prototype;
10037
+ rect.__updateHitCanvas = function () {
9964
10038
  if (this.stroke || this.cornerRadius)
9965
- ui.__updateHitCanvas.call(this);
10039
+ ui$1.__updateHitCanvas.call(this);
9966
10040
  };
9967
- exports.Rect.prototype.__hitFill = function (inner) {
9968
- return this.__hitCanvas ? ui.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
10041
+ rect.__hitFill = function (inner) {
10042
+ return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
9969
10043
  };
9970
10044
 
9971
- exports.UI.prototype.find = function (condition, options) {
10045
+ const ui = exports.UI.prototype, group = exports.Group.prototype;
10046
+ ui.find = function (condition, options) {
9972
10047
  return this.leafer ? this.leafer.selector.getBy(condition, this, false, options) : [];
9973
10048
  };
9974
- exports.UI.prototype.findOne = function (condition, options) {
10049
+ ui.findOne = function (condition, options) {
9975
10050
  return this.leafer ? this.leafer.selector.getBy(condition, this, true, options) : null;
9976
10051
  };
9977
- exports.Group.prototype.pick = function (hitPoint, options) {
10052
+ group.pick = function (hitPoint, options) {
9978
10053
  this.__layout.update();
9979
10054
  if (!options)
9980
10055
  options = {};
@@ -10630,79 +10705,75 @@ var LeaferUI = (function (exports) {
10630
10705
 
10631
10706
  let origin = {};
10632
10707
  const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
10633
- function fillOrFitMode(data, mode, box, width, height, rotation) {
10708
+ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10634
10709
  const transform = get$4();
10635
- const swap = rotation && rotation !== 180;
10636
- const sw = box.width / (swap ? height : width);
10637
- const sh = box.height / (swap ? width : height);
10638
- const scale = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
10639
- const x = box.x + (box.width - width * scale) / 2;
10640
- const y = box.y + (box.height - height * scale) / 2;
10641
- translate$1(transform, x, y);
10642
- scaleHelper(transform, scale);
10710
+ translate$1(transform, box.x + x, box.y + y);
10711
+ scaleHelper(transform, scaleX, scaleY);
10643
10712
  if (rotation)
10644
10713
  rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10645
- data.scaleX = data.scaleY = scale;
10646
10714
  data.transform = transform;
10647
10715
  }
10648
10716
  function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
10649
10717
  const transform = get$4();
10650
- translate$1(transform, box.x, box.y);
10651
- if (x || y)
10652
- translate$1(transform, x, y);
10653
- if (scaleX) {
10718
+ translate$1(transform, box.x + x, box.y + y);
10719
+ if (scaleX)
10654
10720
  scaleHelper(transform, scaleX, scaleY);
10655
- data.scaleX = transform.a;
10656
- data.scaleY = transform.d;
10657
- }
10658
10721
  if (rotation)
10659
10722
  rotate(transform, rotation);
10660
10723
  data.transform = transform;
10661
10724
  }
10662
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation) {
10725
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around) {
10663
10726
  const transform = get$4();
10664
10727
  if (rotation) {
10665
- rotate(transform, rotation);
10666
- switch (rotation) {
10667
- case 90:
10668
- translate$1(transform, height, 0);
10669
- break;
10670
- case 180:
10671
- translate$1(transform, width, height);
10672
- break;
10673
- case 270:
10674
- translate$1(transform, 0, width);
10675
- break;
10728
+ if (around === 'center') {
10729
+ rotateOfOuter$2(transform, { x: width / 2, y: height / 2 }, rotation);
10730
+ }
10731
+ else {
10732
+ rotate(transform, rotation);
10733
+ switch (rotation) {
10734
+ case 90:
10735
+ translate$1(transform, height, 0);
10736
+ break;
10737
+ case 180:
10738
+ translate$1(transform, width, height);
10739
+ break;
10740
+ case 270:
10741
+ translate$1(transform, 0, width);
10742
+ break;
10743
+ }
10676
10744
  }
10677
10745
  }
10678
- origin.x = box.x;
10679
- origin.y = box.y;
10680
- if (x || y)
10681
- origin.x += x, origin.y += y;
10746
+ origin.x = box.x + x;
10747
+ origin.y = box.y + y;
10682
10748
  translate$1(transform, origin.x, origin.y);
10683
- if (scaleX) {
10749
+ if (scaleX)
10684
10750
  scaleOfOuter$2(transform, origin, scaleX, scaleY);
10685
- data.scaleX = scaleX;
10686
- data.scaleY = scaleY;
10687
- }
10688
10751
  data.transform = transform;
10689
10752
  }
10690
10753
 
10691
10754
  const { get: get$3, translate } = MatrixHelper;
10692
10755
  const tempBox = new Bounds();
10756
+ const tempPoint = {};
10693
10757
  function createData(leafPaint, image, paint, box) {
10694
10758
  let { width, height } = image;
10695
10759
  if (paint.padding)
10696
10760
  box = tempBox.set(box).shrink(paint.padding);
10697
- const { opacity, mode, offset, scale, size, rotation, blendMode, repeat } = paint;
10761
+ const { opacity, mode, around, offset, scale, size, rotation, blendMode, repeat } = paint;
10698
10762
  const sameBox = box.width === width && box.height === height;
10699
10763
  if (blendMode)
10700
10764
  leafPaint.blendMode = blendMode;
10701
10765
  const data = leafPaint.data = { mode };
10702
- let x, y, scaleX, scaleY;
10703
- if (offset)
10704
- x = offset.x, y = offset.y;
10705
- if (size) {
10766
+ const swapSize = around !== 'center' && (rotation || 0) % 180 === 90;
10767
+ const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
10768
+ let x = 0, y = 0, scaleX, scaleY;
10769
+ if (!mode || mode === 'cover' || mode === 'fit') {
10770
+ if (!sameBox || rotation) {
10771
+ const sw = box.width / swapWidth, sh = box.height / swapHeight;
10772
+ scaleX = scaleY = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
10773
+ x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
10774
+ }
10775
+ }
10776
+ else if (size) {
10706
10777
  scaleX = (typeof size === 'number' ? size : size.width) / width;
10707
10778
  scaleY = (typeof size === 'number' ? size : size.height) / height;
10708
10779
  }
@@ -10710,26 +10781,36 @@ var LeaferUI = (function (exports) {
10710
10781
  scaleX = typeof scale === 'number' ? scale : scale.x;
10711
10782
  scaleY = typeof scale === 'number' ? scale : scale.y;
10712
10783
  }
10784
+ if (around) {
10785
+ const imageBounds = { x, y, width: swapWidth, height: swapHeight };
10786
+ if (scaleX)
10787
+ imageBounds.width *= scaleX, imageBounds.height *= scaleY;
10788
+ AroundHelper.toPoint(around, box, tempPoint, true, imageBounds);
10789
+ x += tempPoint.x, y += tempPoint.y;
10790
+ }
10791
+ if (offset)
10792
+ x += offset.x, y += offset.y;
10713
10793
  switch (mode) {
10714
10794
  case 'strench':
10715
10795
  if (!sameBox)
10716
10796
  width = box.width, height = box.height;
10717
10797
  break;
10798
+ case 'normal':
10718
10799
  case 'clip':
10719
- if (offset || scaleX || rotation)
10800
+ if (x || y || scaleX || rotation)
10720
10801
  clipMode(data, box, x, y, scaleX, scaleY, rotation);
10721
10802
  break;
10722
10803
  case 'repeat':
10723
10804
  if (!sameBox || scaleX || rotation)
10724
- repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation);
10805
+ repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around);
10725
10806
  if (!repeat)
10726
10807
  data.repeat = 'repeat';
10727
10808
  break;
10728
10809
  case 'fit':
10729
10810
  case 'cover':
10730
10811
  default:
10731
- if (!sameBox || rotation)
10732
- fillOrFitMode(data, mode, box, width, height, rotation);
10812
+ if (scaleX)
10813
+ fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation);
10733
10814
  }
10734
10815
  if (!data.transform) {
10735
10816
  if (box.x || box.y) {
@@ -10737,6 +10818,10 @@ var LeaferUI = (function (exports) {
10737
10818
  translate(data.transform, box.x, box.y);
10738
10819
  }
10739
10820
  }
10821
+ if (scaleX && mode !== 'strench') {
10822
+ data.scaleX = scaleX;
10823
+ data.scaleY = scaleY;
10824
+ }
10740
10825
  data.width = width;
10741
10826
  data.height = height;
10742
10827
  if (opacity)
@@ -11792,6 +11877,13 @@ var LeaferUI = (function (exports) {
11792
11877
  resolve();
11793
11878
  this.running = false;
11794
11879
  };
11880
+ if (filename === 'json') {
11881
+ return over({ data: leaf.toJSON() });
11882
+ }
11883
+ else if (FileHelper.fileType(filename) === 'json') {
11884
+ Platform.origin.download('data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(leaf.toJSON())), filename);
11885
+ return over({ data: true });
11886
+ }
11795
11887
  const { leafer } = leaf;
11796
11888
  if (leafer) {
11797
11889
  leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
@@ -12097,7 +12189,7 @@ var LeaferUI = (function (exports) {
12097
12189
  exports.surfaceType = surfaceType;
12098
12190
  exports.tempBounds = tempBounds$1;
12099
12191
  exports.tempMatrix = tempMatrix;
12100
- exports.tempPoint = tempPoint$2;
12192
+ exports.tempPoint = tempPoint$3;
12101
12193
  exports.useCanvas = useCanvas;
12102
12194
  exports.useModule = useModule;
12103
12195
  exports.version = version;