leafer-draw 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) {
@@ -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;
@@ -6470,7 +6487,11 @@ var LeaferUI = (function (exports) {
6470
6487
  defineKey(target, key, {
6471
6488
  set(value) { if (this.isLeafer)
6472
6489
  this[privateKey] = value; },
6473
- get() { return this.isLeafer ? (this[privateKey] || this) : this.leafer && this.leafer.zoomLayer; }
6490
+ get() {
6491
+ return this.isApp
6492
+ ? this.tree.zoomLayer
6493
+ : (this.isLeafer ? (this[privateKey] || this) : this.leafer && this.leafer.zoomLayer);
6494
+ }
6474
6495
  });
6475
6496
  };
6476
6497
  }
@@ -6876,6 +6897,9 @@ var LeaferUI = (function (exports) {
6876
6897
  pen.set(this.path = this.__.path || []);
6877
6898
  return pen;
6878
6899
  }
6900
+ get editConfig() { return undefined; }
6901
+ get editOuter() { return 'EditTool'; }
6902
+ get editInner() { return 'PathEditor'; }
6879
6903
  constructor(data) {
6880
6904
  super(data);
6881
6905
  }
@@ -6937,7 +6961,8 @@ var LeaferUI = (function (exports) {
6937
6961
  __drawPathByBox(drawer) {
6938
6962
  const { x, y, width, height } = this.__layout.boxBounds;
6939
6963
  if (this.__.cornerRadius) {
6940
- drawer.roundRect(x, y, width, height, this.__.cornerRadius);
6964
+ const { cornerRadius } = this.__;
6965
+ drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
6941
6966
  }
6942
6967
  else {
6943
6968
  drawer.rect(x, y, width, height);
@@ -6958,6 +6983,9 @@ var LeaferUI = (function (exports) {
6958
6983
  static registerData(data) {
6959
6984
  dataProcessor(data)(this.prototype);
6960
6985
  }
6986
+ static setEditConfig(_config) { }
6987
+ static setEditOuter(_toolName) { }
6988
+ static setEditInner(_editorName) { }
6961
6989
  destroy() {
6962
6990
  this.fill = this.stroke = null;
6963
6991
  super.destroy();
@@ -7041,15 +7069,15 @@ var LeaferUI = (function (exports) {
7041
7069
  __decorate([
7042
7070
  dataType(false)
7043
7071
  ], exports.UI.prototype, "draggable", void 0);
7072
+ __decorate([
7073
+ dataType()
7074
+ ], exports.UI.prototype, "dragBounds", void 0);
7044
7075
  __decorate([
7045
7076
  dataType(false)
7046
7077
  ], exports.UI.prototype, "editable", void 0);
7047
7078
  __decorate([
7048
7079
  dataType('size')
7049
7080
  ], exports.UI.prototype, "editSize", void 0);
7050
- __decorate([
7051
- dataType()
7052
- ], exports.UI.prototype, "editorStyle", void 0);
7053
7081
  __decorate([
7054
7082
  hitType(true)
7055
7083
  ], exports.UI.prototype, "hittable", void 0);
@@ -7241,7 +7269,6 @@ var LeaferUI = (function (exports) {
7241
7269
  var Leafer_1;
7242
7270
  const debug$1 = Debug.get('Leafer');
7243
7271
  exports.Leafer = Leafer_1 = class Leafer extends exports.Group {
7244
- static get version() { return '1.0.0-rc.21'; }
7245
7272
  get __tag() { return 'Leafer'; }
7246
7273
  get isApp() { return false; }
7247
7274
  get app() { return this.parent || this; }
@@ -7294,7 +7321,6 @@ var LeaferUI = (function (exports) {
7294
7321
  if (this.isApp)
7295
7322
  this.__setApp();
7296
7323
  this.__checkAutoLayout(config);
7297
- this.updateLazyBounds();
7298
7324
  this.view = canvas.view;
7299
7325
  if (parentApp) {
7300
7326
  this.__bindApp(parentApp);
@@ -7538,6 +7564,7 @@ var LeaferUI = (function (exports) {
7538
7564
  __listenEvents() {
7539
7565
  const runId = Run.start('FirstCreate ' + this.innerName);
7540
7566
  this.once(LeaferEvent.START, () => Run.end(runId));
7567
+ this.once(LayoutEvent.START, () => this.updateLazyBounds());
7541
7568
  this.once(LayoutEvent.END, () => this.__onReady());
7542
7569
  this.once(RenderEvent.START, () => this.__onCreated());
7543
7570
  this.once(RenderEvent.END, () => this.__onViewReady());
@@ -8056,6 +8083,7 @@ var LeaferUI = (function (exports) {
8056
8083
  const { copyAndSpread, includes, spread, setList } = BoundsHelper;
8057
8084
  exports.Text = class Text extends exports.UI {
8058
8085
  get __tag() { return 'Text'; }
8086
+ get editInner() { return 'TextEditor'; }
8059
8087
  get textDrawData() {
8060
8088
  this.__layout.update();
8061
8089
  return this.__.__textDrawData;
@@ -8588,79 +8616,75 @@ var LeaferUI = (function (exports) {
8588
8616
 
8589
8617
  let origin = {};
8590
8618
  const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
8591
- function fillOrFitMode(data, mode, box, width, height, rotation) {
8619
+ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
8592
8620
  const transform = get$4();
8593
- const swap = rotation && rotation !== 180;
8594
- const sw = box.width / (swap ? height : width);
8595
- const sh = box.height / (swap ? width : height);
8596
- const scale = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
8597
- const x = box.x + (box.width - width * scale) / 2;
8598
- const y = box.y + (box.height - height * scale) / 2;
8599
- translate$1(transform, x, y);
8600
- scaleHelper(transform, scale);
8621
+ translate$1(transform, box.x + x, box.y + y);
8622
+ scaleHelper(transform, scaleX, scaleY);
8601
8623
  if (rotation)
8602
8624
  rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
8603
- data.scaleX = data.scaleY = scale;
8604
8625
  data.transform = transform;
8605
8626
  }
8606
8627
  function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
8607
8628
  const transform = get$4();
8608
- translate$1(transform, box.x, box.y);
8609
- if (x || y)
8610
- translate$1(transform, x, y);
8611
- if (scaleX) {
8629
+ translate$1(transform, box.x + x, box.y + y);
8630
+ if (scaleX)
8612
8631
  scaleHelper(transform, scaleX, scaleY);
8613
- data.scaleX = transform.a;
8614
- data.scaleY = transform.d;
8615
- }
8616
8632
  if (rotation)
8617
8633
  rotate(transform, rotation);
8618
8634
  data.transform = transform;
8619
8635
  }
8620
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation) {
8636
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around) {
8621
8637
  const transform = get$4();
8622
8638
  if (rotation) {
8623
- rotate(transform, rotation);
8624
- switch (rotation) {
8625
- case 90:
8626
- translate$1(transform, height, 0);
8627
- break;
8628
- case 180:
8629
- translate$1(transform, width, height);
8630
- break;
8631
- case 270:
8632
- translate$1(transform, 0, width);
8633
- break;
8639
+ if (around === 'center') {
8640
+ rotateOfOuter$2(transform, { x: width / 2, y: height / 2 }, rotation);
8641
+ }
8642
+ else {
8643
+ rotate(transform, rotation);
8644
+ switch (rotation) {
8645
+ case 90:
8646
+ translate$1(transform, height, 0);
8647
+ break;
8648
+ case 180:
8649
+ translate$1(transform, width, height);
8650
+ break;
8651
+ case 270:
8652
+ translate$1(transform, 0, width);
8653
+ break;
8654
+ }
8634
8655
  }
8635
8656
  }
8636
- origin.x = box.x;
8637
- origin.y = box.y;
8638
- if (x || y)
8639
- origin.x += x, origin.y += y;
8657
+ origin.x = box.x + x;
8658
+ origin.y = box.y + y;
8640
8659
  translate$1(transform, origin.x, origin.y);
8641
- if (scaleX) {
8660
+ if (scaleX)
8642
8661
  scaleOfOuter$2(transform, origin, scaleX, scaleY);
8643
- data.scaleX = scaleX;
8644
- data.scaleY = scaleY;
8645
- }
8646
8662
  data.transform = transform;
8647
8663
  }
8648
8664
 
8649
8665
  const { get: get$3, translate } = MatrixHelper;
8650
8666
  const tempBox = new Bounds();
8667
+ const tempPoint = {};
8651
8668
  function createData(leafPaint, image, paint, box) {
8652
8669
  let { width, height } = image;
8653
8670
  if (paint.padding)
8654
8671
  box = tempBox.set(box).shrink(paint.padding);
8655
- const { opacity, mode, offset, scale, size, rotation, blendMode, repeat } = paint;
8672
+ const { opacity, mode, around, offset, scale, size, rotation, blendMode, repeat } = paint;
8656
8673
  const sameBox = box.width === width && box.height === height;
8657
8674
  if (blendMode)
8658
8675
  leafPaint.blendMode = blendMode;
8659
8676
  const data = leafPaint.data = { mode };
8660
- let x, y, scaleX, scaleY;
8661
- if (offset)
8662
- x = offset.x, y = offset.y;
8663
- if (size) {
8677
+ const swapSize = around !== 'center' && (rotation || 0) % 180 === 90;
8678
+ const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
8679
+ let x = 0, y = 0, scaleX, scaleY;
8680
+ if (!mode || mode === 'cover' || mode === 'fit') {
8681
+ if (!sameBox || rotation) {
8682
+ const sw = box.width / swapWidth, sh = box.height / swapHeight;
8683
+ scaleX = scaleY = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
8684
+ x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
8685
+ }
8686
+ }
8687
+ else if (size) {
8664
8688
  scaleX = (typeof size === 'number' ? size : size.width) / width;
8665
8689
  scaleY = (typeof size === 'number' ? size : size.height) / height;
8666
8690
  }
@@ -8668,26 +8692,36 @@ var LeaferUI = (function (exports) {
8668
8692
  scaleX = typeof scale === 'number' ? scale : scale.x;
8669
8693
  scaleY = typeof scale === 'number' ? scale : scale.y;
8670
8694
  }
8695
+ if (around) {
8696
+ const imageBounds = { x, y, width: swapWidth, height: swapHeight };
8697
+ if (scaleX)
8698
+ imageBounds.width *= scaleX, imageBounds.height *= scaleY;
8699
+ AroundHelper.toPoint(around, box, tempPoint, true, imageBounds);
8700
+ x += tempPoint.x, y += tempPoint.y;
8701
+ }
8702
+ if (offset)
8703
+ x += offset.x, y += offset.y;
8671
8704
  switch (mode) {
8672
8705
  case 'strench':
8673
8706
  if (!sameBox)
8674
8707
  width = box.width, height = box.height;
8675
8708
  break;
8709
+ case 'normal':
8676
8710
  case 'clip':
8677
- if (offset || scaleX || rotation)
8711
+ if (x || y || scaleX || rotation)
8678
8712
  clipMode(data, box, x, y, scaleX, scaleY, rotation);
8679
8713
  break;
8680
8714
  case 'repeat':
8681
8715
  if (!sameBox || scaleX || rotation)
8682
- repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation);
8716
+ repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around);
8683
8717
  if (!repeat)
8684
8718
  data.repeat = 'repeat';
8685
8719
  break;
8686
8720
  case 'fit':
8687
8721
  case 'cover':
8688
8722
  default:
8689
- if (!sameBox || rotation)
8690
- fillOrFitMode(data, mode, box, width, height, rotation);
8723
+ if (scaleX)
8724
+ fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation);
8691
8725
  }
8692
8726
  if (!data.transform) {
8693
8727
  if (box.x || box.y) {
@@ -8695,6 +8729,10 @@ var LeaferUI = (function (exports) {
8695
8729
  translate(data.transform, box.x, box.y);
8696
8730
  }
8697
8731
  }
8732
+ if (scaleX && mode !== 'strench') {
8733
+ data.scaleX = scaleX;
8734
+ data.scaleY = scaleY;
8735
+ }
8698
8736
  data.width = width;
8699
8737
  data.height = height;
8700
8738
  if (opacity)
@@ -9750,6 +9788,13 @@ var LeaferUI = (function (exports) {
9750
9788
  resolve();
9751
9789
  this.running = false;
9752
9790
  };
9791
+ if (filename === 'json') {
9792
+ return over({ data: leaf.toJSON() });
9793
+ }
9794
+ else if (FileHelper.fileType(filename) === 'json') {
9795
+ Platform.origin.download('data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(leaf.toJSON())), filename);
9796
+ return over({ data: true });
9797
+ }
9753
9798
  const { leafer } = leaf;
9754
9799
  if (leafer) {
9755
9800
  leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
@@ -10033,7 +10078,7 @@ var LeaferUI = (function (exports) {
10033
10078
  exports.surfaceType = surfaceType;
10034
10079
  exports.tempBounds = tempBounds$1;
10035
10080
  exports.tempMatrix = tempMatrix;
10036
- exports.tempPoint = tempPoint$2;
10081
+ exports.tempPoint = tempPoint$3;
10037
10082
  exports.useCanvas = useCanvas;
10038
10083
  exports.useModule = useModule;
10039
10084
  exports.version = version;