@leafer-editor/worker 1.0.10 → 1.1.1

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/worker.js CHANGED
@@ -111,7 +111,7 @@ var LeaferUI = (function (exports) {
111
111
  return rotation - oldRotation;
112
112
  },
113
113
  float(num, maxLength) {
114
- const a = maxLength ? pow$1(10, maxLength) : 1000000000000;
114
+ const a = maxLength !== undefined ? pow$1(10, maxLength) : 1000000000000;
115
115
  num = round(num * a) / a;
116
116
  return num === -0 ? 0 : num;
117
117
  },
@@ -433,7 +433,7 @@ var LeaferUI = (function (exports) {
433
433
  const M$9 = MatrixHelper;
434
434
 
435
435
  const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
436
- const { sin: sin$4, cos: cos$4, abs: abs$5, sqrt: sqrt$2, atan2: atan2$2, min: min$1, PI: PI$3 } = Math;
436
+ const { sin: sin$4, cos: cos$4, abs: abs$6, sqrt: sqrt$2, atan2: atan2$2, min: min$1, PI: PI$3 } = Math;
437
437
  const PointHelper = {
438
438
  defaultPoint: getPointData(),
439
439
  tempPoint: {},
@@ -522,8 +522,8 @@ var LeaferUI = (function (exports) {
522
522
  return getDistanceFrom(t.x, t.y, point.x, point.y);
523
523
  },
524
524
  getDistanceFrom(x1, y1, x2, y2) {
525
- const x = abs$5(x2 - x1);
526
- const y = abs$5(y2 - y1);
525
+ const x = abs$6(x2 - x1);
526
+ const y = abs$6(y2 - y1);
527
527
  return sqrt$2(x * x + y * y);
528
528
  },
529
529
  getMinDistanceFrom(x1, y1, x2, y2, x3, y3) {
@@ -1377,7 +1377,7 @@ var LeaferUI = (function (exports) {
1377
1377
  }
1378
1378
  const D$6 = Debug;
1379
1379
 
1380
- const debug$g = Debug.get('RunTime');
1380
+ const debug$h = Debug.get('RunTime');
1381
1381
  const Run = {
1382
1382
  currentId: 0,
1383
1383
  currentName: '',
@@ -1395,7 +1395,7 @@ var LeaferUI = (function (exports) {
1395
1395
  const time = R.idMap[id], name = R.nameMap[id];
1396
1396
  const duration = microsecond ? (performance.now() - time) / 1000 : Date.now() - time;
1397
1397
  R.idMap[id] = R.nameMap[id] = R.nameToIdMap[name] = undefined;
1398
- debug$g.log(name, duration, 'ms');
1398
+ debug$h.log(name, duration, 'ms');
1399
1399
  },
1400
1400
  endOfName(name, microsecond) {
1401
1401
  const id = R.nameToIdMap[name];
@@ -1409,18 +1409,18 @@ var LeaferUI = (function (exports) {
1409
1409
  console.error('need plugin: @leafer-in/' + name);
1410
1410
  }
1411
1411
 
1412
- const debug$f = Debug.get('UICreator');
1412
+ const debug$g = Debug.get('UICreator');
1413
1413
  const UICreator = {
1414
1414
  list: {},
1415
1415
  register(UI) {
1416
1416
  const { __tag: tag } = UI.prototype;
1417
1417
  if (list$3[tag])
1418
- debug$f.repeat(tag);
1418
+ debug$g.repeat(tag);
1419
1419
  list$3[tag] = UI;
1420
1420
  },
1421
1421
  get(tag, data, x, y, width, height) {
1422
1422
  if (!list$3[tag])
1423
- debug$f.error('not register ' + tag);
1423
+ debug$g.error('not register ' + tag);
1424
1424
  const ui = new list$3[tag](data);
1425
1425
  if (x !== undefined) {
1426
1426
  ui.x = x;
@@ -1436,7 +1436,7 @@ var LeaferUI = (function (exports) {
1436
1436
  };
1437
1437
  const { list: list$3 } = UICreator;
1438
1438
 
1439
- const debug$e = Debug.get('EventCreator');
1439
+ const debug$f = Debug.get('EventCreator');
1440
1440
  const EventCreator = {
1441
1441
  nameList: {},
1442
1442
  register(Event) {
@@ -1444,7 +1444,7 @@ var LeaferUI = (function (exports) {
1444
1444
  Object.keys(Event).forEach(key => {
1445
1445
  name = Event[key];
1446
1446
  if (typeof name === 'string')
1447
- nameList[name] && debug$e.repeat(name), nameList[name] = Event;
1447
+ nameList[name] && debug$f.repeat(name), nameList[name] = Event;
1448
1448
  });
1449
1449
  },
1450
1450
  changeName(oldName, newName) {
@@ -1516,17 +1516,19 @@ var LeaferUI = (function (exports) {
1516
1516
  assign(t, defaultData);
1517
1517
  return t;
1518
1518
  },
1519
- assign(t, merge) {
1519
+ assign(t, merge, exclude) {
1520
1520
  let value;
1521
1521
  Object.keys(merge).forEach(key => {
1522
- var _a;
1522
+ var _a, _b;
1523
1523
  value = merge[key];
1524
- if ((value === null || value === void 0 ? void 0 : value.constructor) === Object) {
1525
- (((_a = t[key]) === null || _a === void 0 ? void 0 : _a.constructor) === Object) ? assign(t[key], merge[key]) : t[key] = merge[key];
1526
- }
1527
- else {
1528
- t[key] = merge[key];
1524
+ if ((value === null || value === void 0 ? void 0 : value.constructor) === Object && ((_a = t[key]) === null || _a === void 0 ? void 0 : _a.constructor) === Object)
1525
+ return assign(t[key], merge[key], exclude && exclude[key]);
1526
+ if (exclude && (key in exclude)) {
1527
+ if (((_b = exclude[key]) === null || _b === void 0 ? void 0 : _b.constructor) === Object)
1528
+ assign(t[key] = {}, merge[key], exclude[key]);
1529
+ return;
1529
1530
  }
1531
+ t[key] = merge[key];
1530
1532
  });
1531
1533
  },
1532
1534
  copyAttrs(t, from, include) {
@@ -2330,7 +2332,7 @@ var LeaferUI = (function (exports) {
2330
2332
  }
2331
2333
  };
2332
2334
 
2333
- const { sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil$1, abs: abs$4, PI: PI$2, sqrt: sqrt$1, pow } = Math;
2335
+ const { sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil$1, abs: abs$5, PI: PI$2, sqrt: sqrt$1, pow } = Math;
2334
2336
  const { setPoint: setPoint$4, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2335
2337
  const { set, toNumberPoints: toNumberPoints$1 } = PointHelper;
2336
2338
  const { M: M$8, L: L$9, C: C$8, Q: Q$7, Z: Z$7 } = PathCommandMap;
@@ -2403,7 +2405,7 @@ var LeaferUI = (function (exports) {
2403
2405
  let totalRadian = endRadian - startRadian;
2404
2406
  if (totalRadian < 0)
2405
2407
  totalRadian += PI2;
2406
- if (totalRadian === PI$2 || (abs$4(BAx + BAy) < 1.e-12) || (abs$4(CBx + CBy) < 1.e-12)) {
2408
+ if (totalRadian === PI$2 || (abs$5(BAx + BAy) < 1.e-12) || (abs$5(CBx + CBy) < 1.e-12)) {
2407
2409
  if (data)
2408
2410
  data.push(L$9, x1, y1);
2409
2411
  if (setPointBounds) {
@@ -2445,7 +2447,7 @@ var LeaferUI = (function (exports) {
2445
2447
  totalRadian -= PI2;
2446
2448
  if (anticlockwise)
2447
2449
  totalRadian -= PI2;
2448
- const parts = ceil$1(abs$4(totalRadian / PI_2));
2450
+ const parts = ceil$1(abs$5(totalRadian / PI_2));
2449
2451
  const partRadian = totalRadian / parts;
2450
2452
  const partRadian4Sin = sin$3(partRadian / 4);
2451
2453
  const control = 8 / 3 * partRadian4Sin * partRadian4Sin / sin$3(partRadian / 2);
@@ -2598,7 +2600,7 @@ var LeaferUI = (function (exports) {
2598
2600
  const { M: M$7, m, L: L$8, l, H, h, V, v, C: C$7, c, S, s, Q: Q$6, q, T, t, A, a, Z: Z$6, z, N: N$5, D: D$5, X: X$5, G: G$5, F: F$6, O: O$6, P: P$5, U: U$5 } = PathCommandMap;
2599
2601
  const { rect: rect$3, roundRect: roundRect$2, arcTo: arcTo$3, arc: arc$3, ellipse: ellipse$4, quadraticCurveTo: quadraticCurveTo$1 } = BezierHelper;
2600
2602
  const { ellipticalArc } = EllipseHelper;
2601
- const debug$d = Debug.get('PathConvert');
2603
+ const debug$e = Debug.get('PathConvert');
2602
2604
  const setEndPoint$1 = {};
2603
2605
  const PathConvert = {
2604
2606
  current: { dot: 0 },
@@ -2839,7 +2841,7 @@ var LeaferUI = (function (exports) {
2839
2841
  i += 6;
2840
2842
  break;
2841
2843
  default:
2842
- debug$d.error(`command: ${command} [index:${i}]`, old);
2844
+ debug$e.error(`command: ${command} [index:${i}]`, old);
2843
2845
  return data;
2844
2846
  }
2845
2847
  lastCommand = command;
@@ -2886,7 +2888,7 @@ var LeaferUI = (function (exports) {
2886
2888
 
2887
2889
  const { M: M$6, L: L$7, C: C$6, Q: Q$5, Z: Z$5, N: N$4, D: D$4, X: X$4, G: G$4, F: F$5, O: O$5, P: P$4, U: U$4 } = PathCommandMap;
2888
2890
  const { getMinDistanceFrom, getRadianFrom } = PointHelper;
2889
- const { tan, min, abs: abs$3 } = Math;
2891
+ const { tan, min, abs: abs$4 } = Math;
2890
2892
  const startPoint = {};
2891
2893
  const PathCommandDataHelper = {
2892
2894
  beginPath(data) {
@@ -2949,7 +2951,7 @@ var LeaferUI = (function (exports) {
2949
2951
  arcTo(data, x1, y1, x2, y2, radius, lastX, lastY) {
2950
2952
  if (lastX !== undefined) {
2951
2953
  const maxRadius = tan(getRadianFrom(lastX, lastY, x1, y1, x2, y2) / 2) * (getMinDistanceFrom(lastX, lastY, x1, y1, x2, y2) / 2);
2952
- data.push(U$4, x1, y1, x2, y2, min(radius, abs$3(maxRadius)));
2954
+ data.push(U$4, x1, y1, x2, y2, min(radius, abs$4(maxRadius)));
2953
2955
  }
2954
2956
  else {
2955
2957
  data.push(U$4, x1, y1, x2, y2, radius);
@@ -3064,7 +3066,7 @@ var LeaferUI = (function (exports) {
3064
3066
  }
3065
3067
 
3066
3068
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$4, N: N$3, D: D$3, X: X$3, G: G$3, F: F$4, O: O$4, P: P$3, U: U$3 } = PathCommandMap;
3067
- const debug$c = Debug.get('PathDrawer');
3069
+ const debug$d = Debug.get('PathDrawer');
3068
3070
  const PathDrawer = {
3069
3071
  drawPathByData(drawer, data) {
3070
3072
  if (!data)
@@ -3127,7 +3129,7 @@ var LeaferUI = (function (exports) {
3127
3129
  i += 6;
3128
3130
  break;
3129
3131
  default:
3130
- debug$c.error(`command: ${command} [index:${i}]`, data);
3132
+ debug$d.error(`command: ${command} [index:${i}]`, data);
3131
3133
  return;
3132
3134
  }
3133
3135
  }
@@ -3137,7 +3139,7 @@ var LeaferUI = (function (exports) {
3137
3139
  const { M: M$4, L: L$5, C: C$4, Q: Q$3, Z: Z$3, N: N$2, D: D$2, X: X$2, G: G$2, F: F$3, O: O$3, P: P$2, U: U$2 } = PathCommandMap;
3138
3140
  const { toTwoPointBounds, toTwoPointBoundsByQuadraticCurve, arcTo: arcTo$1, arc, ellipse: ellipse$1 } = BezierHelper;
3139
3141
  const { addPointBounds, copy: copy$b, addPoint: addPoint$1, setPoint: setPoint$3, addBounds, toBounds: toBounds$3 } = TwoPointBoundsHelper;
3140
- const debug$b = Debug.get('PathBounds');
3142
+ const debug$c = Debug.get('PathBounds');
3141
3143
  let radius, radiusX, radiusY;
3142
3144
  const tempPointBounds = {};
3143
3145
  const setPointBounds = {};
@@ -3245,7 +3247,7 @@ var LeaferUI = (function (exports) {
3245
3247
  i += 6;
3246
3248
  break;
3247
3249
  default:
3248
- debug$b.error(`command: ${command} [index:${i}]`, data);
3250
+ debug$c.error(`command: ${command} [index:${i}]`, data);
3249
3251
  return;
3250
3252
  }
3251
3253
  }
@@ -3361,7 +3363,7 @@ var LeaferUI = (function (exports) {
3361
3363
  const F$2 = FileHelper;
3362
3364
  F$2.opacityTypes.forEach(type => F$2.upperCaseTypeMap[type] = type.toUpperCase());
3363
3365
 
3364
- const debug$a = Debug.get('TaskProcessor');
3366
+ const debug$b = Debug.get('TaskProcessor');
3365
3367
  class TaskItem {
3366
3368
  constructor(task) {
3367
3369
  this.parallel = true;
@@ -3376,7 +3378,7 @@ var LeaferUI = (function (exports) {
3376
3378
  yield this.task();
3377
3379
  }
3378
3380
  catch (error) {
3379
- debug$a.error(error);
3381
+ debug$b.error(error);
3380
3382
  }
3381
3383
  });
3382
3384
  }
@@ -3894,6 +3896,8 @@ var LeaferUI = (function (exports) {
3894
3896
  return decorateLeafAttr(defaultValue, (key) => attr({
3895
3897
  set(value) {
3896
3898
  this.__setAttr(key, value) && (this.__layout.opacityChanged || this.__layout.opacityChange());
3899
+ if (this.mask)
3900
+ checkMask(this);
3897
3901
  }
3898
3902
  }));
3899
3903
  }
@@ -3910,9 +3914,20 @@ var LeaferUI = (function (exports) {
3910
3914
  this.__runAnimation('in');
3911
3915
  }
3912
3916
  doVisible(this, key, value, oldValue);
3917
+ if (this.mask)
3918
+ checkMask(this);
3913
3919
  }
3914
3920
  }));
3915
3921
  }
3922
+ function checkMask(leaf) {
3923
+ const { parent } = leaf;
3924
+ if (parent) {
3925
+ const { __hasMask } = parent;
3926
+ parent.__updateMask();
3927
+ if (__hasMask !== parent.__hasMask)
3928
+ parent.forceUpdate();
3929
+ }
3930
+ }
3916
3931
  function doVisible(leaf, key, value, oldValue) {
3917
3932
  if (leaf.__setAttr(key, value)) {
3918
3933
  leaf.__layout.opacityChanged || leaf.__layout.opacityChange();
@@ -4050,7 +4065,7 @@ var LeaferUI = (function (exports) {
4050
4065
  defineKey(data, key, property);
4051
4066
  }
4052
4067
 
4053
- const debug$9 = new Debug('rewrite');
4068
+ const debug$a = new Debug('rewrite');
4054
4069
  const list$2 = [];
4055
4070
  const excludeNames = ['destroy', 'constructor'];
4056
4071
  function rewrite(method) {
@@ -4067,7 +4082,7 @@ var LeaferUI = (function (exports) {
4067
4082
  if (list$2.length) {
4068
4083
  list$2.forEach(item => {
4069
4084
  if (error)
4070
- debug$9.error(item.name, '需在Class上装饰@rewriteAble()');
4085
+ debug$a.error(item.name, '需在Class上装饰@rewriteAble()');
4071
4086
  item.run();
4072
4087
  });
4073
4088
  list$2.length = 0;
@@ -4168,20 +4183,17 @@ var LeaferUI = (function (exports) {
4168
4183
  }
4169
4184
  return true;
4170
4185
  },
4171
- moveWorld(t, x, y = 0, isInnerPoint) {
4186
+ moveWorld(t, x, y = 0, isInnerPoint, transition) {
4172
4187
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4173
4188
  isInnerPoint ? toOuterPoint$1(t.localTransform, local, local, true) : (t.parent && toInnerPoint$1(t.parent.worldTransform, local, local, true));
4174
- L$3.moveLocal(t, local.x, local.y);
4189
+ L$3.moveLocal(t, local.x, local.y, transition);
4175
4190
  },
4176
- moveLocal(t, x, y = 0) {
4177
- if (typeof x === 'object') {
4178
- t.x += x.x;
4179
- t.y += x.y;
4180
- }
4181
- else {
4182
- t.x += x;
4183
- t.y += y;
4184
- }
4191
+ moveLocal(t, x, y = 0, transition) {
4192
+ if (typeof x === 'object')
4193
+ y = x.y, x = x.x;
4194
+ x += t.x;
4195
+ y += t.y;
4196
+ transition ? t.animate({ x, y }, transition) : (t.x = x, t.y = y);
4185
4197
  },
4186
4198
  zoomOfWorld(t, origin, scaleX, scaleY, resize) {
4187
4199
  L$3.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
@@ -4978,13 +4990,13 @@ var LeaferUI = (function (exports) {
4978
4990
  const LeafEventer = { on, on_, off, off_, once, emit: emit$2, emitEvent: emitEvent$1, hasEvent, destroyEventer: destroy };
4979
4991
 
4980
4992
  const { isFinite } = Number;
4981
- const debug$8 = Debug.get('setAttr');
4993
+ const debug$9 = Debug.get('setAttr');
4982
4994
  const LeafDataProxy = {
4983
4995
  __setAttr(name, newValue, checkFiniteNumber) {
4984
4996
  if (this.leaferIsCreated) {
4985
4997
  const oldValue = this.__.__getInput(name);
4986
4998
  if (checkFiniteNumber && !isFinite(newValue) && newValue !== undefined) {
4987
- debug$8.warn(this.innerName, name, newValue);
4999
+ debug$9.warn(this.innerName, name, newValue);
4988
5000
  newValue = undefined;
4989
5001
  }
4990
5002
  if (typeof newValue === 'object' || oldValue !== newValue) {
@@ -5440,8 +5452,8 @@ var LeaferUI = (function (exports) {
5440
5452
  canvas.clearRect(r.x, r.y, r.width, r.height);
5441
5453
  canvas.restore();
5442
5454
  }
5443
- __updateMask(value) {
5444
- this.__hasMask = value ? true : this.children.some(item => item.__.mask);
5455
+ __updateMask(_value) {
5456
+ this.__hasMask = this.children.some(item => item.__.mask && item.__.visible && item.__.opacity);
5445
5457
  }
5446
5458
  __renderMask(_canvas, _options) { }
5447
5459
  __getNowWorld(options) {
@@ -5561,11 +5573,11 @@ var LeaferUI = (function (exports) {
5561
5573
  transform(matrix, resize) {
5562
5574
  transform(this, matrix, resize);
5563
5575
  }
5564
- move(x, y) {
5565
- moveLocal(this, x, y);
5576
+ move(x, y, transition) {
5577
+ moveLocal(this, x, y, transition);
5566
5578
  }
5567
- moveInner(x, y) {
5568
- moveWorld(this, x, y, true);
5579
+ moveInner(x, y, transition) {
5580
+ moveWorld(this, x, y, true, transition);
5569
5581
  }
5570
5582
  scaleOf(origin, scaleX, scaleY, resize) {
5571
5583
  zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
@@ -5579,8 +5591,8 @@ var LeaferUI = (function (exports) {
5579
5591
  transformWorld(worldTransform, resize) {
5580
5592
  transformWorld(this, worldTransform, resize);
5581
5593
  }
5582
- moveWorld(x, y) {
5583
- moveWorld(this, x, y);
5594
+ moveWorld(x, y, transition) {
5595
+ moveWorld(this, x, y, false, transition);
5584
5596
  }
5585
5597
  scaleOfWorld(worldOrigin, scaleX, scaleY, resize) {
5586
5598
  zoomOfWorld(this, worldOrigin, scaleX, scaleY, resize);
@@ -5681,9 +5693,10 @@ var LeaferUI = (function (exports) {
5681
5693
  useModule(LeafRender)
5682
5694
  ], exports.Leaf);
5683
5695
 
5684
- const { setListWithFn } = BoundsHelper;
5696
+ const { setListWithFn: setListWithFn$1 } = BoundsHelper;
5685
5697
  const { sort } = BranchHelper;
5686
5698
  const { localBoxBounds, localStrokeBounds, localRenderBounds, maskLocalBoxBounds, maskLocalStrokeBounds, maskLocalRenderBounds } = LeafBoundsHelper;
5699
+ const debug$8 = new Debug('Branch');
5687
5700
  exports.Branch = class Branch extends exports.Leaf {
5688
5701
  __updateStrokeSpread() {
5689
5702
  const { children } = this;
@@ -5702,13 +5715,13 @@ var LeaferUI = (function (exports) {
5702
5715
  return 0;
5703
5716
  }
5704
5717
  __updateBoxBounds() {
5705
- setListWithFn(this.__layout.boxBounds, this.children, this.__hasMask ? maskLocalBoxBounds : localBoxBounds);
5718
+ setListWithFn$1(this.__layout.boxBounds, this.children, this.__hasMask ? maskLocalBoxBounds : localBoxBounds);
5706
5719
  }
5707
5720
  __updateStrokeBounds() {
5708
- setListWithFn(this.__layout.strokeBounds, this.children, this.__hasMask ? maskLocalStrokeBounds : localStrokeBounds);
5721
+ setListWithFn$1(this.__layout.strokeBounds, this.children, this.__hasMask ? maskLocalStrokeBounds : localStrokeBounds);
5709
5722
  }
5710
5723
  __updateRenderBounds() {
5711
- setListWithFn(this.__layout.renderBounds, this.children, this.__hasMask ? maskLocalRenderBounds : localRenderBounds);
5724
+ setListWithFn$1(this.__layout.renderBounds, this.children, this.__hasMask ? maskLocalRenderBounds : localRenderBounds);
5712
5725
  }
5713
5726
  __updateSortChildren() {
5714
5727
  let affectSort;
@@ -5724,8 +5737,8 @@ var LeaferUI = (function (exports) {
5724
5737
  }
5725
5738
  }
5726
5739
  add(child, index) {
5727
- if (child === this)
5728
- return;
5740
+ if (child === this || child.destroyed)
5741
+ return debug$8.warn('add self or destroyed');
5729
5742
  const noIndex = index === undefined;
5730
5743
  if (!child.__) {
5731
5744
  if (child instanceof Array)
@@ -5739,8 +5752,9 @@ var LeaferUI = (function (exports) {
5739
5752
  noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
5740
5753
  if (child.isBranch)
5741
5754
  this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
5742
- child.__layout.boxChanged || child.__layout.boxChange();
5743
- child.__layout.matrixChanged || child.__layout.matrixChange();
5755
+ const childLayout = child.__layout;
5756
+ childLayout.boxChanged || childLayout.boxChange();
5757
+ childLayout.matrixChanged || childLayout.matrixChange();
5744
5758
  if (child.__bubbleMap)
5745
5759
  child.__emitLifeEvent(ChildEvent.ADD);
5746
5760
  if (this.leafer) {
@@ -5978,7 +5992,7 @@ var LeaferUI = (function (exports) {
5978
5992
  }
5979
5993
  }
5980
5994
 
5981
- const version = "1.0.10";
5995
+ const version = "1.1.1";
5982
5996
 
5983
5997
  class LeaferCanvas extends LeaferCanvasBase {
5984
5998
  get allowBackgroundColor() { return true; }
@@ -6216,7 +6230,7 @@ var LeaferUI = (function (exports) {
6216
6230
  });
6217
6231
  }
6218
6232
 
6219
- const { worldBounds } = LeafBoundsHelper;
6233
+ const { worldBounds: worldBounds$1 } = LeafBoundsHelper;
6220
6234
  const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
6221
6235
  class LayoutBlockData {
6222
6236
  constructor(list) {
@@ -6228,7 +6242,7 @@ var LeaferUI = (function (exports) {
6228
6242
  this.updatedList = list;
6229
6243
  }
6230
6244
  setBefore() {
6231
- this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
6245
+ this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds$1);
6232
6246
  }
6233
6247
  setAfter() {
6234
6248
  const { list } = this.updatedList;
@@ -6236,7 +6250,7 @@ var LeaferUI = (function (exports) {
6236
6250
  this.afterBounds.set(bigBounds);
6237
6251
  }
6238
6252
  else {
6239
- this.afterBounds.setListWithFn(list, worldBounds);
6253
+ this.afterBounds.setListWithFn(list, worldBounds$1);
6240
6254
  }
6241
6255
  this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
6242
6256
  }
@@ -6423,25 +6437,25 @@ var LeaferUI = (function (exports) {
6423
6437
  if (userConfig)
6424
6438
  this.config = DataHelper.default(userConfig, this.config);
6425
6439
  this.__listenEvents();
6426
- this.__requestRender();
6427
6440
  }
6428
6441
  start() {
6429
6442
  this.running = true;
6443
+ this.update(false);
6430
6444
  }
6431
6445
  stop() {
6432
6446
  this.running = false;
6433
6447
  }
6434
- update() {
6435
- this.changed = true;
6448
+ update(change = true) {
6449
+ if (!this.changed)
6450
+ this.changed = change;
6451
+ this.__requestRender();
6436
6452
  }
6437
6453
  requestLayout() {
6438
6454
  this.target.emit(LayoutEvent.REQUEST);
6439
6455
  }
6440
6456
  render(callback) {
6441
- if (!(this.running && this.canvas.view)) {
6442
- this.changed = true;
6443
- return;
6444
- }
6457
+ if (!(this.running && this.canvas.view))
6458
+ return this.update();
6445
6459
  const { target } = this;
6446
6460
  this.times = 0;
6447
6461
  this.totalBounds = new Bounds();
@@ -6575,16 +6589,17 @@ var LeaferUI = (function (exports) {
6575
6589
  }
6576
6590
  }
6577
6591
  __requestRender() {
6578
- const startTime = Date.now();
6592
+ if (this.requestTime)
6593
+ return;
6594
+ const requestTime = this.requestTime = Date.now();
6579
6595
  Platform.requestRender(() => {
6580
- this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - startTime)));
6596
+ this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
6597
+ this.requestTime = 0;
6581
6598
  if (this.running) {
6582
6599
  if (this.changed && this.canvas.view)
6583
6600
  this.render();
6584
6601
  this.target.emit(RenderEvent.NEXT);
6585
6602
  }
6586
- if (this.target)
6587
- this.__requestRender();
6588
6603
  });
6589
6604
  }
6590
6605
  __onResize(e) {
@@ -6600,7 +6615,7 @@ var LeaferUI = (function (exports) {
6600
6615
  }
6601
6616
  }
6602
6617
  this.addBlock(new Bounds(0, 0, 1, 1));
6603
- this.changed = true;
6618
+ this.update();
6604
6619
  }
6605
6620
  __onLayoutEnd(event) {
6606
6621
  if (event.data)
@@ -7008,7 +7023,7 @@ var LeaferUI = (function (exports) {
7008
7023
  return true;
7009
7024
  return t.fill && this.__hasStroke;
7010
7025
  }
7011
- get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
7026
+ get __clipAfterFill() { const t = this; return (t.cornerRadius || t.innerShadow || t.__pathInputed); }
7012
7027
  get __autoWidth() { return !this._width; }
7013
7028
  get __autoHeight() { return !this._height; }
7014
7029
  get __autoSide() { return !this._width || !this._height; }
@@ -7122,7 +7137,7 @@ var LeaferUI = (function (exports) {
7122
7137
 
7123
7138
  class BoxData extends GroupData {
7124
7139
  get __boxStroke() { return !this.__pathInputed; }
7125
- get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
7140
+ get __drawAfterFill() { const t = this; return (t.overflow === 'hide' && (t.__clipAfterFill || t.innerShadow) && t.__leaf.children.length); }
7126
7141
  get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
7127
7142
  }
7128
7143
 
@@ -7408,11 +7423,15 @@ var LeaferUI = (function (exports) {
7408
7423
  super(data);
7409
7424
  }
7410
7425
  reset(_data) { }
7411
- set(data, isTemp) {
7412
- if (isTemp) {
7413
- this.lockNormalStyle = true;
7414
- Object.assign(this, data);
7415
- this.lockNormalStyle = false;
7426
+ set(data, transition) {
7427
+ if (transition) {
7428
+ if (transition === 'temp') {
7429
+ this.lockNormalStyle = true;
7430
+ Object.assign(this, data);
7431
+ this.lockNormalStyle = false;
7432
+ }
7433
+ else
7434
+ this.animate(data, transition);
7416
7435
  }
7417
7436
  else
7418
7437
  Object.assign(this, data);
@@ -7722,17 +7741,17 @@ var LeaferUI = (function (exports) {
7722
7741
  if (!this.children)
7723
7742
  this.children = [];
7724
7743
  }
7725
- set(data, isTemp) {
7744
+ set(data, transition) {
7726
7745
  if (data.children) {
7727
7746
  const { children } = data;
7728
7747
  delete data.children;
7729
7748
  this.children ? this.clear() : this.__setBranch();
7730
- super.set(data, isTemp);
7749
+ super.set(data, transition);
7731
7750
  children.forEach(child => this.add(child));
7732
7751
  data.children = children;
7733
7752
  }
7734
7753
  else
7735
- super.set(data, isTemp);
7754
+ super.set(data, transition);
7736
7755
  }
7737
7756
  toJSON(options) {
7738
7757
  const data = super.toJSON(options);
@@ -7778,20 +7797,10 @@ var LeaferUI = (function (exports) {
7778
7797
  constructor(userConfig, data) {
7779
7798
  super(data);
7780
7799
  this.config = {
7781
- type: 'design',
7782
7800
  start: true,
7783
7801
  hittable: true,
7784
7802
  smooth: true,
7785
- lazySpeard: 100,
7786
- zoom: {
7787
- min: 0.01,
7788
- max: 256
7789
- },
7790
- move: {
7791
- holdSpaceKey: true,
7792
- holdMiddleKey: true,
7793
- autoDistance: 2
7794
- }
7803
+ lazySpeard: 100
7795
7804
  };
7796
7805
  this.leafs = 0;
7797
7806
  this.__eventIds = [];
@@ -7808,23 +7817,27 @@ var LeaferUI = (function (exports) {
7808
7817
  init(userConfig, parentApp) {
7809
7818
  if (this.canvas)
7810
7819
  return;
7811
- this.__setLeafer(this);
7812
- if (userConfig)
7813
- DataHelper.assign(this.config, userConfig);
7814
7820
  let start;
7815
7821
  const { config } = this;
7816
- this.initType(config.type);
7822
+ this.__setLeafer(this);
7823
+ if (parentApp) {
7824
+ this.parentApp = parentApp;
7825
+ this.__bindApp(parentApp);
7826
+ start = parentApp.running;
7827
+ }
7828
+ if (userConfig) {
7829
+ this.parent = parentApp;
7830
+ this.initType(userConfig.type);
7831
+ this.parent = undefined;
7832
+ DataHelper.assign(config, userConfig);
7833
+ }
7817
7834
  const canvas = this.canvas = Creator.canvas(config);
7818
7835
  this.__controllers.push(this.renderer = Creator.renderer(this, canvas, config), this.watcher = Creator.watcher(this, config), this.layouter = Creator.layouter(this, config));
7819
7836
  if (this.isApp)
7820
7837
  this.__setApp();
7821
7838
  this.__checkAutoLayout(config, parentApp);
7822
7839
  this.view = canvas.view;
7823
- if (parentApp) {
7824
- this.__bindApp(parentApp);
7825
- start = parentApp.running;
7826
- }
7827
- else {
7840
+ if (!parentApp) {
7828
7841
  this.selector = Creator.selector(this);
7829
7842
  this.interaction = Creator.interaction(this, canvas, this.selector, config);
7830
7843
  if (this.interaction) {
@@ -7845,8 +7858,8 @@ var LeaferUI = (function (exports) {
7845
7858
  }
7846
7859
  onInit() { }
7847
7860
  initType(_type) { }
7848
- set(data) {
7849
- this.waitInit(() => { super.set(data); });
7861
+ set(data, transition) {
7862
+ this.waitInit(() => { super.set(data, transition); });
7850
7863
  }
7851
7864
  start() {
7852
7865
  clearTimeout(this.__startTimer);
@@ -7881,7 +7894,11 @@ var LeaferUI = (function (exports) {
7881
7894
  forceRender(bounds) {
7882
7895
  this.renderer.addBlock(bounds ? new Bounds(bounds) : this.canvas.bounds);
7883
7896
  if (this.viewReady)
7884
- this.renderer.update();
7897
+ this.renderer.render();
7898
+ }
7899
+ requestRender(change = false) {
7900
+ if (this.renderer)
7901
+ this.renderer.update(change);
7885
7902
  }
7886
7903
  updateCursor(cursor) {
7887
7904
  const i = this.interaction;
@@ -7989,8 +8006,10 @@ var LeaferUI = (function (exports) {
7989
8006
  const { imageReady } = this;
7990
8007
  if (imageReady && !this.viewCompleted)
7991
8008
  this.__checkViewCompleted();
7992
- if (!imageReady)
8009
+ if (!imageReady) {
7993
8010
  this.viewCompleted = false;
8011
+ this.requestRender();
8012
+ }
7994
8013
  }
7995
8014
  }
7996
8015
  __checkViewCompleted(emit = true) {
@@ -8048,6 +8067,7 @@ var LeaferUI = (function (exports) {
8048
8067
  }
8049
8068
  else
8050
8069
  list.push(item);
8070
+ this.requestRender();
8051
8071
  }
8052
8072
  zoom(_zoomType, _padding, _fixedScale) {
8053
8073
  return needPlugin('view');
@@ -8101,7 +8121,7 @@ var LeaferUI = (function (exports) {
8101
8121
  this.canvasManager.destroy();
8102
8122
  }
8103
8123
  this.canvas.destroy();
8104
- this.config.view = this.view = null;
8124
+ this.config.view = this.view = this.parentApp = null;
8105
8125
  if (this.userConfig)
8106
8126
  this.userConfig.view = null;
8107
8127
  super.destroy();
@@ -8828,9 +8848,9 @@ var LeaferUI = (function (exports) {
8828
8848
  if (ground)
8829
8849
  this.ground = this.addLeafer(ground);
8830
8850
  if (tree || editor)
8831
- this.tree = this.addLeafer(tree);
8851
+ this.tree = this.addLeafer(tree || { type: userConfig.type || 'design' });
8832
8852
  if (sky || editor)
8833
- this.sky = this.addLeafer(sky || { type: 'draw', usePartRender: false });
8853
+ this.sky = this.addLeafer(sky);
8834
8854
  if (editor)
8835
8855
  this.sky.add(this.editor = Creator.editor(editor));
8836
8856
  }
@@ -9035,10 +9055,8 @@ var LeaferUI = (function (exports) {
9035
9055
  this.data = data;
9036
9056
  }
9037
9057
  static getValidMove(leaf, start, total) {
9038
- const { draggable, dragBounds, x, y } = leaf;
9039
- const move = leaf.getLocalPoint(total, null, true);
9040
- move.x += start.x - x;
9041
- move.y += start.y - y;
9058
+ const { draggable, dragBounds } = leaf, move = leaf.getLocalPoint(total, null, true);
9059
+ PointHelper.move(move, start.x - leaf.x, start.y - leaf.y);
9042
9060
  if (dragBounds)
9043
9061
  this.getMoveInDragBounds(leaf.__local, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true);
9044
9062
  if (draggable === 'x')
@@ -9048,8 +9066,7 @@ var LeaferUI = (function (exports) {
9048
9066
  return move;
9049
9067
  }
9050
9068
  static getMoveInDragBounds(childBox, dragBounds, move, change) {
9051
- const x = childBox.x + move.x, y = childBox.y + move.y;
9052
- const right = x + childBox.width, bottom = y + childBox.height;
9069
+ const x = childBox.x + move.x, y = childBox.y + move.y, right = x + childBox.width, bottom = y + childBox.height;
9053
9070
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
9054
9071
  if (!change)
9055
9072
  move = Object.assign({}, move);
@@ -9101,9 +9118,7 @@ var LeaferUI = (function (exports) {
9101
9118
  return this.getLocalMove(relative, true);
9102
9119
  }
9103
9120
  getPageBounds() {
9104
- const total = this.getPageTotal();
9105
- const start = this.getPagePoint();
9106
- const bounds = {};
9121
+ const total = this.getPageTotal(), start = this.getPagePoint(), bounds = {};
9107
9122
  BoundsHelper.set(bounds, start.x - total.x, start.y - total.y, total.x, total.y);
9108
9123
  BoundsHelper.unsign(bounds);
9109
9124
  return bounds;
@@ -9189,184 +9204,7 @@ var LeaferUI = (function (exports) {
9189
9204
  registerUIEvent()
9190
9205
  ], exports.KeyEvent);
9191
9206
 
9192
- function addInteractionWindow(leafer) {
9193
- if (leafer.isApp)
9194
- return;
9195
- leafer.__eventIds.push(leafer.on_(exports.MoveEvent.BEFORE_MOVE, (e) => {
9196
- leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
9197
- }), leafer.on_(exports.ZoomEvent.BEFORE_ZOOM, (e) => {
9198
- const { zoomLayer } = leafer;
9199
- const changeScale = leafer.getValidScale(e.scale);
9200
- if (changeScale !== 1) {
9201
- PointHelper.scaleOf(zoomLayer, e, changeScale);
9202
- zoomLayer.scale = zoomLayer.__.scaleX * changeScale;
9203
- }
9204
- }));
9205
- }
9206
-
9207
- function document$1(leafer) {
9208
- addInteractionWindow(leafer);
9209
- const { move, zoom } = leafer.config;
9210
- move.scroll = 'limit';
9211
- zoom.min = 1;
9212
- }
9213
-
9214
- function block(leafer) {
9215
- const { config } = leafer;
9216
- (config.wheel || (config.wheel = {})).preventDefault = false;
9217
- (config.touch || (config.touch = {})).preventDefault = 'auto';
9218
- }
9219
-
9220
- const debug$3 = Debug.get('LeaferTypeCreator');
9221
- const LeaferTypeCreator = {
9222
- list: {},
9223
- register(name, fn) {
9224
- list$1[name] && debug$3.repeat(name);
9225
- list$1[name] = fn;
9226
- },
9227
- run(name, leafer) {
9228
- const fn = list$1[name];
9229
- fn && fn(leafer);
9230
- }
9231
- };
9232
- const { list: list$1, register } = LeaferTypeCreator;
9233
- register('design', addInteractionWindow);
9234
- register('document', document$1);
9235
- register('block', block);
9236
-
9237
- const leafer = exports.Leafer.prototype;
9238
- leafer.initType = function (type) {
9239
- LeaferTypeCreator.run(type, this);
9240
- };
9241
- leafer.getValidMove = function (moveX, moveY) {
9242
- const { scroll, disabled } = this.app.config.move;
9243
- if (scroll) {
9244
- Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0;
9245
- if (scroll === 'limit') {
9246
- const { x, y, width, height } = new Bounds(this.__world).addPoint(this.zoomLayer);
9247
- const right = x + width - this.width, bottom = y + height - this.height;
9248
- if (x >= 0 && right <= 0)
9249
- moveX = 0;
9250
- else if (moveX > 0) {
9251
- if (x + moveX > 0)
9252
- moveX = -x;
9253
- }
9254
- else if (moveX < 0 && right + moveX < 0)
9255
- moveX = -right;
9256
- if (y >= 0 && bottom <= 0)
9257
- moveY = 0;
9258
- else if (moveY > 0) {
9259
- if (y + moveY > 0)
9260
- moveY = -y;
9261
- }
9262
- else if (moveY < 0 && bottom + moveY < 0)
9263
- moveY = -bottom;
9264
- }
9265
- }
9266
- return { x: disabled ? 0 : moveX, y: disabled ? 0 : moveY };
9267
- };
9268
- leafer.getValidScale = function (changeScale) {
9269
- const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale);
9270
- if (absScale < min)
9271
- changeScale = min / scaleX;
9272
- else if (absScale > max)
9273
- changeScale = max / scaleX;
9274
- return disabled ? 1 : changeScale;
9275
- };
9276
-
9277
- class Transformer {
9278
- get transforming() { return !!(this.moveData || this.zoomData || this.rotateData); }
9279
- constructor(interaction) {
9280
- this.interaction = interaction;
9281
- }
9282
- move(data) {
9283
- const { interaction } = this;
9284
- if (!data.moveType)
9285
- data.moveType = 'move';
9286
- if (!this.moveData) {
9287
- const { path } = interaction.selector.getByPoint(data, interaction.hitRadius);
9288
- data.path = path;
9289
- this.moveData = Object.assign(Object.assign({}, data), { moveX: 0, moveY: 0 });
9290
- interaction.cancelHover();
9291
- interaction.emit(exports.MoveEvent.START, this.moveData);
9292
- }
9293
- data.path = this.moveData.path;
9294
- interaction.emit(exports.MoveEvent.BEFORE_MOVE, data);
9295
- interaction.emit(exports.MoveEvent.MOVE, data);
9296
- this.transformEndWait();
9297
- }
9298
- zoom(data) {
9299
- const { interaction } = this;
9300
- if (!this.zoomData) {
9301
- const { path } = interaction.selector.getByPoint(data, interaction.hitRadius);
9302
- data.path = path;
9303
- this.zoomData = Object.assign(Object.assign({}, data), { scale: 1 });
9304
- interaction.cancelHover();
9305
- interaction.emit(exports.ZoomEvent.START, this.zoomData);
9306
- }
9307
- data.path = this.zoomData.path;
9308
- interaction.emit(exports.ZoomEvent.BEFORE_ZOOM, data);
9309
- interaction.emit(exports.ZoomEvent.ZOOM, data);
9310
- this.transformEndWait();
9311
- }
9312
- rotate(data) {
9313
- const { interaction } = this;
9314
- if (!this.rotateData) {
9315
- const { path } = interaction.selector.getByPoint(data, interaction.hitRadius);
9316
- data.path = path;
9317
- this.rotateData = Object.assign(Object.assign({}, data), { rotation: 0 });
9318
- interaction.cancelHover();
9319
- interaction.emit(exports.RotateEvent.START, this.rotateData);
9320
- }
9321
- data.path = this.rotateData.path;
9322
- interaction.emit(exports.RotateEvent.BEFORE_ROTATE, data);
9323
- interaction.emit(exports.RotateEvent.ROTATE, data);
9324
- this.transformEndWait();
9325
- }
9326
- transformEndWait() {
9327
- clearTimeout(this.transformTimer);
9328
- this.transformTimer = setTimeout(() => {
9329
- this.transformEnd();
9330
- }, this.interaction.config.pointer.transformTime);
9331
- }
9332
- transformEnd() {
9333
- this.moveEnd();
9334
- this.zoomEnd();
9335
- this.rotateEnd();
9336
- }
9337
- moveEnd() {
9338
- if (this.moveData) {
9339
- this.interaction.emit(exports.MoveEvent.END, this.moveData);
9340
- this.moveData = null;
9341
- }
9342
- }
9343
- zoomEnd() {
9344
- if (this.zoomData) {
9345
- this.interaction.emit(exports.ZoomEvent.END, this.zoomData);
9346
- this.zoomData = null;
9347
- }
9348
- }
9349
- rotateEnd() {
9350
- if (this.rotateData) {
9351
- this.interaction.emit(exports.RotateEvent.END, this.rotateData);
9352
- this.rotateData = null;
9353
- }
9354
- }
9355
- destroy() {
9356
- this.zoomData = this.moveData = this.rotateData = null;
9357
- }
9358
- }
9359
-
9360
9207
  const InteractionHelper = {
9361
- getMoveEventData(center, move, event) {
9362
- return Object.assign(Object.assign({}, event), { x: center.x, y: center.y, moveX: move.x, moveY: move.y });
9363
- },
9364
- getRotateEventData(center, angle, event) {
9365
- return Object.assign(Object.assign({}, event), { x: center.x, y: center.y, rotation: angle });
9366
- },
9367
- getZoomEventData(center, scale, event) {
9368
- return Object.assign(Object.assign({}, event), { x: center.x, y: center.y, scale });
9369
- },
9370
9208
  getDragEventData(startPoint, lastPoint, event) {
9371
9209
  return Object.assign(Object.assign({}, event), { x: event.x, y: event.y, moveX: event.x - lastPoint.x, moveY: event.y - lastPoint.y, totalX: event.x - startPoint.x, totalY: event.y - startPoint.y });
9372
9210
  },
@@ -9375,18 +9213,14 @@ var LeaferUI = (function (exports) {
9375
9213
  data });
9376
9214
  },
9377
9215
  getSwipeDirection(angle) {
9378
- if (angle < -45 && angle > -135) {
9216
+ if (angle < -45 && angle > -135)
9379
9217
  return exports.SwipeEvent.UP;
9380
- }
9381
- else if (angle > 45 && angle < 135) {
9218
+ else if (angle > 45 && angle < 135)
9382
9219
  return exports.SwipeEvent.DOWN;
9383
- }
9384
- else if (angle <= 45 && angle >= -45) {
9220
+ else if (angle <= 45 && angle >= -45)
9385
9221
  return exports.SwipeEvent.RIGHT;
9386
- }
9387
- else {
9222
+ else
9388
9223
  return exports.SwipeEvent.LEFT;
9389
- }
9390
9224
  },
9391
9225
  getSwipeEventData(startPoint, lastDragData, event) {
9392
9226
  return Object.assign(Object.assign({}, event), { moveX: lastDragData.moveX, moveY: lastDragData.moveY, totalX: event.x - startPoint.x, totalY: event.y - startPoint.y, type: I.getSwipeDirection(PointHelper.getAngle(startPoint, event)) });
@@ -9459,9 +9293,8 @@ var LeaferUI = (function (exports) {
9459
9293
  interaction.emit(exports.MoveEvent.START, this.dragData);
9460
9294
  }
9461
9295
  }
9462
- if (!this.moving) {
9296
+ if (!this.moving)
9463
9297
  this.dragStart(data, canDrag);
9464
- }
9465
9298
  this.drag(data);
9466
9299
  }
9467
9300
  dragStart(data, canDrag) {
@@ -9539,16 +9372,9 @@ var LeaferUI = (function (exports) {
9539
9372
  dragEnd(data, speed) {
9540
9373
  if (!this.dragging && !this.moving)
9541
9374
  return;
9542
- const { moveX, moveY } = this.dragData;
9543
- if (this.interaction.config.move.dragAnimate && this.canAnimate && this.moving && (Math.abs(moveX) > 1 || Math.abs(moveY) > 1)) {
9544
- data = Object.assign({}, data);
9545
- speed = (speed || (data.pointerType === 'touch' ? 2 : 1)) * 0.9;
9546
- PointHelper.move(data, moveX * speed, moveY * speed);
9547
- this.drag(data);
9548
- this.animate(() => { this.dragEnd(data, 1); });
9549
- }
9550
- else
9551
- this.dragEndReal(data);
9375
+ if (this.checkDragEndAnimate(data, speed))
9376
+ return;
9377
+ this.dragEndReal(data);
9552
9378
  }
9553
9379
  dragEndReal(data) {
9554
9380
  const { interaction, downData, dragData } = this;
@@ -9575,12 +9401,6 @@ var LeaferUI = (function (exports) {
9575
9401
  this.dragReset();
9576
9402
  this.animate(null, 'off');
9577
9403
  }
9578
- animate(func, off) {
9579
- const animateWait = func || this.animateWait;
9580
- if (animateWait)
9581
- this.interaction.target.nextRender(animateWait, null, off);
9582
- this.animateWait = func;
9583
- }
9584
9404
  swipe(data, downData, dragData, endDragData) {
9585
9405
  const { interaction } = this;
9586
9406
  if (PointHelper.getDistance(downData, data) > interaction.config.pointer.swipeDistance) {
@@ -9597,45 +9417,17 @@ var LeaferUI = (function (exports) {
9597
9417
  dragReset() {
9598
9418
  exports.DragEvent.list = exports.DragEvent.data = this.draggableList = this.dragData = this.downData = this.dragOverPath = this.dragEnterPath = null;
9599
9419
  }
9600
- checkDragOut(data) {
9601
- const { interaction } = this;
9602
- this.autoMoveCancel();
9603
- if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data))
9604
- this.autoMoveOnDragOut(data);
9605
- }
9606
- autoMoveOnDragOut(data) {
9607
- const { interaction, downData, canDragOut } = this;
9608
- const { autoDistance, dragOut } = interaction.config.move;
9609
- if (!dragOut || !canDragOut || !autoDistance)
9610
- return;
9611
- const bounds = interaction.shrinkCanvasBounds;
9612
- const { x, y } = bounds;
9613
- const right = BoundsHelper.maxX(bounds);
9614
- const bottom = BoundsHelper.maxY(bounds);
9615
- const moveX = data.x < x ? autoDistance : (right < data.x ? -autoDistance : 0);
9616
- const moveY = data.y < y ? autoDistance : (bottom < data.y ? -autoDistance : 0);
9617
- let totalX = 0, totalY = 0;
9618
- this.autoMoveTimer = setInterval(() => {
9619
- totalX += moveX;
9620
- totalY += moveY;
9621
- PointHelper.move(downData, moveX, moveY);
9622
- PointHelper.move(this.dragData, moveX, moveY);
9623
- interaction.move(Object.assign(Object.assign({}, data), { moveX, moveY, totalX, totalY, moveType: 'drag' }));
9624
- interaction.pointerMoveReal(data);
9625
- }, 10);
9626
- }
9627
- autoMoveCancel() {
9628
- if (this.autoMoveTimer) {
9629
- clearInterval(this.autoMoveTimer);
9630
- this.autoMoveTimer = 0;
9631
- }
9632
- }
9420
+ checkDragEndAnimate(_data, _speed) { return false; }
9421
+ animate(_func, _off) { }
9422
+ checkDragOut(_data) { }
9423
+ autoMoveOnDragOut(_data) { }
9424
+ autoMoveCancel() { }
9633
9425
  destroy() {
9634
9426
  this.dragReset();
9635
9427
  }
9636
9428
  }
9637
9429
 
9638
- const debug$2 = Debug.get('emit');
9430
+ const debug$3 = Debug.get('emit');
9639
9431
  function emit$1(type, data, path, excludePath) {
9640
9432
  if (!path && !data.path)
9641
9433
  return;
@@ -9665,7 +9457,7 @@ var LeaferUI = (function (exports) {
9665
9457
  }
9666
9458
  }
9667
9459
  catch (e) {
9668
- debug$2.error(e);
9460
+ debug$3.error(e);
9669
9461
  }
9670
9462
  }
9671
9463
  const allowTypes = ['move', 'zoom', 'rotate', 'key'];
@@ -9699,28 +9491,12 @@ var LeaferUI = (function (exports) {
9699
9491
  return excludePath && excludePath.has(leaf);
9700
9492
  }
9701
9493
 
9702
- const MultiTouchHelper = {
9703
- getData(list) {
9704
- const a = list[0];
9705
- const b = list[1];
9706
- const lastCenter = PointHelper.getCenter(a.from, b.from);
9707
- const center = PointHelper.getCenter(a.to, b.to);
9708
- const move = { x: center.x - lastCenter.x, y: center.y - lastCenter.y };
9709
- const lastDistance = PointHelper.getDistance(a.from, b.from);
9710
- const distance = PointHelper.getDistance(a.to, b.to);
9711
- const scale = distance / lastDistance;
9712
- const angle = PointHelper.getRotation(a.from, b.from, a.to, b.to);
9713
- return { move, scale, angle, center };
9714
- }
9715
- };
9716
-
9717
9494
  const config$1 = {
9718
9495
  wheel: {
9719
9496
  zoomSpeed: 0.5,
9720
9497
  moveSpeed: 0.5,
9721
9498
  rotateSpeed: 0.5,
9722
9499
  delta: { x: 80 / 4, y: 8.0 },
9723
- preventDefault: true
9724
9500
  },
9725
9501
  pointer: {
9726
9502
  hitRadius: 5,
@@ -9731,17 +9507,18 @@ var LeaferUI = (function (exports) {
9731
9507
  dragHover: true,
9732
9508
  dragDistance: 2,
9733
9509
  swipeDistance: 20,
9734
- preventDefaultMenu: true
9735
9510
  },
9736
9511
  touch: {
9737
- preventDefault: true
9512
+ preventDefault: 'auto'
9738
9513
  },
9739
9514
  multiTouch: {},
9515
+ move: { autoDistance: 2 },
9516
+ zoom: {},
9740
9517
  cursor: true,
9741
9518
  keyEvent: true
9742
9519
  };
9743
9520
 
9744
- const { pathHasEventType, getMoveEventData, getZoomEventData, getRotateEventData, pathCanDrag, pathHasOutside } = InteractionHelper;
9521
+ const { pathHasEventType, pathCanDrag, pathHasOutside } = InteractionHelper;
9745
9522
  class InteractionBase {
9746
9523
  get dragging() { return this.dragger.dragging; }
9747
9524
  get transforming() { return this.transformer.transforming; }
@@ -9763,7 +9540,7 @@ var LeaferUI = (function (exports) {
9763
9540
  this.canvas = canvas;
9764
9541
  this.selector = selector;
9765
9542
  this.defaultPath = new LeafList(target);
9766
- this.transformer = new Transformer(this);
9543
+ this.createTransformer();
9767
9544
  this.dragger = new Dragger(this);
9768
9545
  if (userConfig)
9769
9546
  this.config = DataHelper.default(userConfig, this.config);
@@ -9864,14 +9641,6 @@ var LeaferUI = (function (exports) {
9864
9641
  data.isCancel = true;
9865
9642
  this.pointerUp(data);
9866
9643
  }
9867
- multiTouch(data, list) {
9868
- if (this.config.multiTouch.disabled)
9869
- return;
9870
- const { move, angle, scale, center } = MultiTouchHelper.getData(list);
9871
- this.rotate(getRotateEventData(center, angle, data));
9872
- this.zoom(getZoomEventData(center, scale, data));
9873
- this.move(getMoveEventData(center, move, data));
9874
- }
9875
9644
  menu(data) {
9876
9645
  this.findPath(data);
9877
9646
  this.emit(exports.PointerEvent.MENU, data);
@@ -9885,18 +9654,13 @@ var LeaferUI = (function (exports) {
9885
9654
  this.waitRightTap = this.waitMenuTap = false;
9886
9655
  }
9887
9656
  }
9888
- move(data) {
9889
- this.transformer.move(data);
9890
- }
9891
- zoom(data) {
9892
- this.transformer.zoom(data);
9893
- }
9894
- rotate(data) {
9895
- this.transformer.rotate(data);
9896
- }
9897
- transformEnd() {
9898
- this.transformer.transformEnd();
9899
- }
9657
+ createTransformer() { }
9658
+ move(_data) { }
9659
+ zoom(_data) { }
9660
+ rotate(_data) { }
9661
+ transformEnd() { }
9662
+ wheel(_data) { }
9663
+ multiTouch(_data, _list) { }
9900
9664
  keyDown(data) {
9901
9665
  if (!this.config.keyEvent)
9902
9666
  return;
@@ -10134,8 +9898,9 @@ var LeaferUI = (function (exports) {
10134
9898
  this.longPressed = false;
10135
9899
  }
10136
9900
  __onResize() {
9901
+ const { dragOut } = this.m;
10137
9902
  this.shrinkCanvasBounds = new Bounds(this.canvas.bounds);
10138
- this.shrinkCanvasBounds.spread(-2);
9903
+ this.shrinkCanvasBounds.spread(-(typeof dragOut === 'number' ? dragOut : 2));
10139
9904
  }
10140
9905
  __listenEvents() {
10141
9906
  const { target } = this;
@@ -10155,7 +9920,8 @@ var LeaferUI = (function (exports) {
10155
9920
  this.stop();
10156
9921
  this.__removeListenEvents();
10157
9922
  this.dragger.destroy();
10158
- this.transformer.destroy();
9923
+ if (this.transformer)
9924
+ this.transformer.destroy();
10159
9925
  this.downData = this.overPath = this.enterPath = null;
10160
9926
  }
10161
9927
  }
@@ -10491,6 +10257,8 @@ var LeaferUI = (function (exports) {
10491
10257
  case 'center':
10492
10258
  canvas.setStroke(stroke, __strokeWidth, options);
10493
10259
  canvas.stroke();
10260
+ if (options.__useArrow)
10261
+ strokeArrow(ui, canvas);
10494
10262
  break;
10495
10263
  case 'inside':
10496
10264
  canvas.save();
@@ -10528,6 +10296,8 @@ var LeaferUI = (function (exports) {
10528
10296
  case 'center':
10529
10297
  canvas.setStroke(undefined, __strokeWidth, options);
10530
10298
  drawStrokesStyle(strokes, false, ui, canvas);
10299
+ if (options.__useArrow)
10300
+ strokeArrow(ui, canvas);
10531
10301
  break;
10532
10302
  case 'inside':
10533
10303
  canvas.save();
@@ -10553,6 +10323,14 @@ var LeaferUI = (function (exports) {
10553
10323
  }
10554
10324
  }
10555
10325
  }
10326
+ function strokeArrow(ui, canvas) {
10327
+ if (ui.__.dashPattern) {
10328
+ canvas.beginPath();
10329
+ ui.__drawPathByData(canvas, ui.__.__pathForArrow);
10330
+ canvas.dashPattern = null;
10331
+ canvas.stroke();
10332
+ }
10333
+ }
10556
10334
 
10557
10335
  const { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper;
10558
10336
  function shape(ui, current, options) {
@@ -10869,13 +10647,13 @@ var LeaferUI = (function (exports) {
10869
10647
  }
10870
10648
 
10871
10649
  const { get: get$1, scale: scale$2, copy: copy$4 } = MatrixHelper;
10872
- const { ceil, abs: abs$2 } = Math;
10650
+ const { ceil, abs: abs$3 } = Math;
10873
10651
  function createPattern(ui, paint, pixelRatio) {
10874
10652
  let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
10875
10653
  const id = scaleX + '-' + scaleY + '-' + pixelRatio;
10876
10654
  if (paint.patternId !== id && !ui.destroyed) {
10877
- scaleX = abs$2(scaleX);
10878
- scaleY = abs$2(scaleY);
10655
+ scaleX = abs$3(scaleX);
10656
+ scaleY = abs$3(scaleY);
10879
10657
  const { image, data } = paint;
10880
10658
  let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data;
10881
10659
  if (sx) {
@@ -10931,7 +10709,7 @@ var LeaferUI = (function (exports) {
10931
10709
  }
10932
10710
  }
10933
10711
 
10934
- const { abs: abs$1 } = Math;
10712
+ const { abs: abs$2 } = Math;
10935
10713
  function checkImage(ui, canvas, paint, allowPaint) {
10936
10714
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
10937
10715
  const { pixelRatio } = canvas;
@@ -10943,8 +10721,8 @@ var LeaferUI = (function (exports) {
10943
10721
  if (allowPaint) {
10944
10722
  if (!data.repeat) {
10945
10723
  let { width, height } = data;
10946
- width *= abs$1(scaleX) * pixelRatio;
10947
- height *= abs$1(scaleY) * pixelRatio;
10724
+ width *= abs$2(scaleX) * pixelRatio;
10725
+ height *= abs$2(scaleY) * pixelRatio;
10948
10726
  if (data.scaleX) {
10949
10727
  width *= data.scaleX;
10950
10728
  height *= data.scaleY;
@@ -11423,15 +11201,15 @@ var LeaferUI = (function (exports) {
11423
11201
  const { Letter, Single, Before, After, Symbol, Break } = CharType;
11424
11202
  let word, row, wordWidth, rowWidth, realWidth;
11425
11203
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
11426
- let textDrawData, rows = [], bounds$1, findMaxWidth;
11204
+ let textDrawData, rows = [], bounds$3, findMaxWidth;
11427
11205
  function createRows(drawData, content, style) {
11428
11206
  textDrawData = drawData;
11429
11207
  rows = drawData.rows;
11430
- bounds$1 = drawData.bounds;
11431
- findMaxWidth = !bounds$1.width && !style.autoSizeAlign;
11208
+ bounds$3 = drawData.bounds;
11209
+ findMaxWidth = !bounds$3.width && !style.autoSizeAlign;
11432
11210
  const { __letterSpacing, paraIndent, textCase } = style;
11433
11211
  const { canvas } = Platform;
11434
- const { width, height } = bounds$1;
11212
+ const { width, height } = bounds$3;
11435
11213
  const charMode = width || height || __letterSpacing || (textCase !== 'none');
11436
11214
  if (charMode) {
11437
11215
  const wrap = style.textWrap !== 'none';
@@ -11545,7 +11323,7 @@ var LeaferUI = (function (exports) {
11545
11323
  startCharSize = 0;
11546
11324
  }
11547
11325
  row.width = rowWidth;
11548
- if (bounds$1.width)
11326
+ if (bounds$3.width)
11549
11327
  trimRight(row);
11550
11328
  else if (findMaxWidth)
11551
11329
  setMaxWidth();
@@ -11982,7 +11760,7 @@ var LeaferUI = (function (exports) {
11982
11760
  }
11983
11761
 
11984
11762
  const canvas = LeaferCanvasBase.prototype;
11985
- const debug$1 = Debug.get('@leafer-ui/export');
11763
+ const debug$2 = Debug.get('@leafer-ui/export');
11986
11764
  canvas.export = function (filename, options) {
11987
11765
  const { quality, blob } = FileHelper.getExportOptions(options);
11988
11766
  if (filename.includes('.'))
@@ -11997,7 +11775,7 @@ var LeaferUI = (function (exports) {
11997
11775
  Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
11998
11776
  resolve(blob);
11999
11777
  }).catch((e) => {
12000
- debug$1.error(e);
11778
+ debug$2.error(e);
12001
11779
  resolve(null);
12002
11780
  });
12003
11781
  });
@@ -12010,7 +11788,7 @@ var LeaferUI = (function (exports) {
12010
11788
  Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
12011
11789
  resolve(true);
12012
11790
  }).catch((e) => {
12013
- debug$1.error(e);
11791
+ debug$2.error(e);
12014
11792
  resolve(false);
12015
11793
  });
12016
11794
  });
@@ -12300,9 +12078,12 @@ var LeaferUI = (function (exports) {
12300
12078
  };
12301
12079
  }
12302
12080
 
12303
- const matrix = MatrixHelper.get();
12304
- const { abs } = Math;
12081
+ const { abs: abs$1 } = Math;
12305
12082
  const { copy: copy$2, scale: scale$1 } = MatrixHelper;
12083
+ const { setListWithFn } = BoundsHelper;
12084
+ const { worldBounds } = LeafBoundsHelper;
12085
+ const matrix = getMatrixData();
12086
+ const bounds$2 = getBoundsData();
12306
12087
  class Stroker extends exports.UI {
12307
12088
  constructor() {
12308
12089
  super();
@@ -12313,6 +12094,17 @@ var LeaferUI = (function (exports) {
12313
12094
  setTarget(target, style) {
12314
12095
  this.set(style);
12315
12096
  this.target = target;
12097
+ this.update();
12098
+ }
12099
+ update() {
12100
+ const { list } = this;
12101
+ if (list.length) {
12102
+ setListWithFn(bounds$2, list, worldBounds);
12103
+ this.set(bounds$2);
12104
+ }
12105
+ else {
12106
+ this.width = this.height = 1;
12107
+ }
12316
12108
  }
12317
12109
  __draw(canvas, options) {
12318
12110
  const { list } = this;
@@ -12322,8 +12114,8 @@ var LeaferUI = (function (exports) {
12322
12114
  for (let i = 0; i < list.length; i++) {
12323
12115
  leaf = list[i];
12324
12116
  const { worldTransform, worldRenderBounds } = leaf;
12325
- if (bounds && bounds.hit(worldRenderBounds, options.matrix)) {
12326
- const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
12117
+ if (!bounds || bounds.hit(worldRenderBounds, options.matrix)) {
12118
+ const aScaleX = abs$1(worldTransform.scaleX), aScaleY = abs$1(worldTransform.scaleY);
12327
12119
  if (aScaleX !== aScaleY) {
12328
12120
  copy$2(matrix, worldTransform);
12329
12121
  scale$1(matrix, 1 / aScaleX, 1 / aScaleY);
@@ -12340,7 +12132,7 @@ var LeaferUI = (function (exports) {
12340
12132
  leaf.__drawPath(canvas);
12341
12133
  else
12342
12134
  leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
12343
- data.strokeWidth = strokeWidth / abs(worldTransform.scaleX);
12135
+ data.strokeWidth = strokeWidth / abs$1(worldTransform.scaleX);
12344
12136
  }
12345
12137
  if (stroke)
12346
12138
  typeof stroke === 'string' ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas);
@@ -12362,7 +12154,6 @@ var LeaferUI = (function (exports) {
12362
12154
  function onTarget$1(stroker) {
12363
12155
  const value = stroker.target;
12364
12156
  stroker.list = value ? (value instanceof Array ? value : [value]) : [];
12365
- stroker.forceUpdate();
12366
12157
  }
12367
12158
 
12368
12159
  class SelectArea extends exports.Group {
@@ -12447,8 +12238,8 @@ var LeaferUI = (function (exports) {
12447
12238
  }
12448
12239
  }
12449
12240
  update() {
12450
- if (this.targetStroker.target)
12451
- this.targetStroker.forceUpdate();
12241
+ this.hoverStroker.update();
12242
+ this.targetStroker.update();
12452
12243
  }
12453
12244
  onPointerMove(e) {
12454
12245
  const { app, editor } = this;
@@ -13266,11 +13057,11 @@ ${filterStyle}
13266
13057
  skewable: true
13267
13058
  };
13268
13059
 
13269
- const bounds = new Bounds();
13060
+ const bounds$1 = new Bounds();
13270
13061
  function simulate(editor) {
13271
13062
  const { simulateTarget, list } = editor;
13272
13063
  const { zoomLayer } = list[0].leafer.zoomLayer;
13273
- simulateTarget.safeChange(() => simulateTarget.reset(bounds.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page')).get()));
13064
+ simulateTarget.safeChange(() => simulateTarget.reset(bounds$1.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page')).get()));
13274
13065
  zoomLayer.add(simulateTarget);
13275
13066
  }
13276
13067
 
@@ -13366,7 +13157,7 @@ ${filterStyle}
13366
13157
  }
13367
13158
  };
13368
13159
 
13369
- const debug = Debug.get('EditToolCreator');
13160
+ const debug$1 = Debug.get('EditToolCreator');
13370
13161
  function registerEditTool() {
13371
13162
  return (target) => {
13372
13163
  EditToolCreator.register(target);
@@ -13377,14 +13168,14 @@ ${filterStyle}
13377
13168
  list: {},
13378
13169
  register(EditTool) {
13379
13170
  const { tag } = EditTool.prototype;
13380
- list[tag] && debug.repeat(tag);
13381
- list[tag] = EditTool;
13171
+ list$1[tag] && debug$1.repeat(tag);
13172
+ list$1[tag] = EditTool;
13382
13173
  },
13383
13174
  get(tag, editor) {
13384
- return new list[tag](editor);
13175
+ return new list$1[tag](editor);
13385
13176
  }
13386
13177
  };
13387
- const { list } = EditToolCreator;
13178
+ const { list: list$1 } = EditToolCreator;
13388
13179
 
13389
13180
  class InnerEditorEvent extends EditorEvent {
13390
13181
  constructor(type, data) {
@@ -14101,6 +13892,349 @@ ${filterStyle}
14101
13892
  });
14102
13893
  };
14103
13894
 
13895
+ function addViewport(leafer, mergeConfig, custom) {
13896
+ addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig);
13897
+ if (leafer.isApp || custom)
13898
+ return;
13899
+ leafer.__eventIds.push(leafer.on_(exports.MoveEvent.BEFORE_MOVE, (e) => {
13900
+ leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
13901
+ }), leafer.on_(exports.ZoomEvent.BEFORE_ZOOM, (e) => {
13902
+ const { zoomLayer } = leafer;
13903
+ const changeScale = leafer.getValidScale(e.scale);
13904
+ if (changeScale !== 1) {
13905
+ PointHelper.scaleOf(zoomLayer, e, changeScale);
13906
+ zoomLayer.scale = zoomLayer.__.scaleX * changeScale;
13907
+ }
13908
+ }));
13909
+ }
13910
+ function addViewportConfig(leafer, mergeConfig) {
13911
+ if (mergeConfig)
13912
+ DataHelper.assign(leafer.config, mergeConfig);
13913
+ DataHelper.assign(leafer.config, {
13914
+ wheel: { preventDefault: true },
13915
+ touch: { preventDefault: true },
13916
+ pointer: { preventDefaultMenu: true }
13917
+ }, leafer.userConfig);
13918
+ }
13919
+
13920
+ function custom(leafer) {
13921
+ addViewport(leafer, null, true);
13922
+ }
13923
+
13924
+ function design(leafer) {
13925
+ addViewport(leafer, {
13926
+ zoom: {
13927
+ min: 0.01,
13928
+ max: 256
13929
+ },
13930
+ move: {
13931
+ holdSpaceKey: true,
13932
+ holdMiddleKey: true,
13933
+ }
13934
+ });
13935
+ }
13936
+
13937
+ function document$1(leafer) {
13938
+ addViewport(leafer, {
13939
+ zoom: { min: 1 },
13940
+ move: { scroll: 'limit' }
13941
+ });
13942
+ }
13943
+
13944
+ const debug = Debug.get('LeaferTypeCreator');
13945
+ const LeaferTypeCreator = {
13946
+ list: {},
13947
+ register(name, fn) {
13948
+ list[name] && debug.repeat(name);
13949
+ list[name] = fn;
13950
+ },
13951
+ run(name, leafer) {
13952
+ const fn = list[name];
13953
+ fn && fn(leafer);
13954
+ }
13955
+ };
13956
+ const { list, register } = LeaferTypeCreator;
13957
+ register('viewport', addViewport);
13958
+ register('custom', custom);
13959
+ register('design', design);
13960
+ register('document', document$1);
13961
+
13962
+ const MultiTouchHelper = {
13963
+ getData(list) {
13964
+ const a = list[0], b = list[1];
13965
+ const lastCenter = PointHelper.getCenter(a.from, b.from);
13966
+ const center = PointHelper.getCenter(a.to, b.to);
13967
+ const move = { x: center.x - lastCenter.x, y: center.y - lastCenter.y };
13968
+ const lastDistance = PointHelper.getDistance(a.from, b.from);
13969
+ const distance = PointHelper.getDistance(a.to, b.to);
13970
+ const scale = distance / lastDistance;
13971
+ const rotation = PointHelper.getRotation(a.from, b.from, a.to, b.to);
13972
+ return { move, scale, rotation, center };
13973
+ }
13974
+ };
13975
+
13976
+ const WheelEventHelper = {
13977
+ getMove(event, config) {
13978
+ let { moveSpeed } = config;
13979
+ let { deltaX, deltaY } = event;
13980
+ if (event.shiftKey && !deltaX) {
13981
+ deltaX = deltaY;
13982
+ deltaY = 0;
13983
+ }
13984
+ if (deltaX > 50)
13985
+ deltaX = Math.max(50, deltaX / 3);
13986
+ if (deltaY > 50)
13987
+ deltaY = Math.max(50, deltaY / 3);
13988
+ return { x: -deltaX * moveSpeed * 2, y: -deltaY * moveSpeed * 2 };
13989
+ },
13990
+ getScale(event, config) {
13991
+ let zoom;
13992
+ let scale = 1;
13993
+ let { zoomMode, zoomSpeed } = config;
13994
+ const delta = event.deltaY || event.deltaX;
13995
+ if (zoomMode) {
13996
+ zoom = (zoomMode === 'mouse') ? true : (!event.deltaX && (Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta));
13997
+ if (event.shiftKey || event.metaKey || event.ctrlKey)
13998
+ zoom = true;
13999
+ }
14000
+ else {
14001
+ zoom = !event.shiftKey && (event.metaKey || event.ctrlKey);
14002
+ }
14003
+ if (zoom) {
14004
+ zoomSpeed = MathHelper.within(zoomSpeed, 0, 1);
14005
+ const min = event.deltaY ? config.delta.y : config.delta.x;
14006
+ scale = 1 - delta / (min * 4) * zoomSpeed;
14007
+ if (scale < 0.5)
14008
+ scale = 0.5;
14009
+ if (scale >= 1.5)
14010
+ scale = 1.5;
14011
+ }
14012
+ return scale;
14013
+ }
14014
+ };
14015
+
14016
+ class Transformer {
14017
+ get transforming() { return !!(this.moveData || this.zoomData || this.rotateData); }
14018
+ constructor(interaction) {
14019
+ this.interaction = interaction;
14020
+ }
14021
+ move(data) {
14022
+ const { interaction } = this;
14023
+ if (!data.moveType)
14024
+ data.moveType = 'move';
14025
+ if (!this.moveData) {
14026
+ this.setPath(data);
14027
+ this.moveData = Object.assign(Object.assign({}, data), { moveX: 0, moveY: 0 });
14028
+ interaction.emit(exports.MoveEvent.START, this.moveData);
14029
+ }
14030
+ data.path = this.moveData.path;
14031
+ interaction.emit(exports.MoveEvent.BEFORE_MOVE, data);
14032
+ interaction.emit(exports.MoveEvent.MOVE, data);
14033
+ this.transformEndWait();
14034
+ }
14035
+ zoom(data) {
14036
+ const { interaction } = this;
14037
+ if (!this.zoomData) {
14038
+ this.setPath(data);
14039
+ this.zoomData = Object.assign(Object.assign({}, data), { scale: 1 });
14040
+ interaction.emit(exports.ZoomEvent.START, this.zoomData);
14041
+ }
14042
+ data.path = this.zoomData.path;
14043
+ interaction.emit(exports.ZoomEvent.BEFORE_ZOOM, data);
14044
+ interaction.emit(exports.ZoomEvent.ZOOM, data);
14045
+ this.transformEndWait();
14046
+ }
14047
+ rotate(data) {
14048
+ const { interaction } = this;
14049
+ if (!this.rotateData) {
14050
+ this.setPath(data);
14051
+ this.rotateData = Object.assign(Object.assign({}, data), { rotation: 0 });
14052
+ interaction.emit(exports.RotateEvent.START, this.rotateData);
14053
+ }
14054
+ data.path = this.rotateData.path;
14055
+ interaction.emit(exports.RotateEvent.BEFORE_ROTATE, data);
14056
+ interaction.emit(exports.RotateEvent.ROTATE, data);
14057
+ this.transformEndWait();
14058
+ }
14059
+ setPath(data) {
14060
+ const { interaction } = this;
14061
+ const { path } = interaction.selector.getByPoint(data, interaction.hitRadius);
14062
+ data.path = path;
14063
+ interaction.cancelHover();
14064
+ }
14065
+ transformEndWait() {
14066
+ clearTimeout(this.transformTimer);
14067
+ this.transformTimer = setTimeout(() => {
14068
+ this.transformEnd();
14069
+ }, this.interaction.p.transformTime);
14070
+ }
14071
+ transformEnd() {
14072
+ const { interaction, moveData, zoomData, rotateData } = this;
14073
+ if (moveData)
14074
+ interaction.emit(exports.MoveEvent.END, moveData);
14075
+ if (zoomData)
14076
+ interaction.emit(exports.ZoomEvent.END, zoomData);
14077
+ if (rotateData)
14078
+ interaction.emit(exports.RotateEvent.END, rotateData);
14079
+ this.reset();
14080
+ }
14081
+ reset() {
14082
+ this.zoomData = this.moveData = this.rotateData = null;
14083
+ }
14084
+ destroy() {
14085
+ this.reset();
14086
+ }
14087
+ }
14088
+
14089
+ const leafer = exports.Leafer.prototype;
14090
+ const bounds = new Bounds();
14091
+ leafer.initType = function (type) {
14092
+ LeaferTypeCreator.run(type, this);
14093
+ };
14094
+ leafer.getValidMove = function (moveX, moveY) {
14095
+ const { scroll, disabled } = this.app.config.move;
14096
+ if (scroll) {
14097
+ const type = scroll === true ? '' : scroll;
14098
+ if (type.includes('x'))
14099
+ moveX = moveX || moveY, moveY = 0;
14100
+ else if (type.includes('y'))
14101
+ moveY = moveY || moveX, moveX = 0;
14102
+ else
14103
+ Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0;
14104
+ if (type.includes('limit')) {
14105
+ const { x, y, width, height } = bounds.set(this.__world).addPoint(this.zoomLayer);
14106
+ const right = x + width - this.width, bottom = y + height - this.height;
14107
+ if (x >= 0 && right <= 0)
14108
+ moveX = 0;
14109
+ else if (moveX > 0) {
14110
+ if (x + moveX > 0)
14111
+ moveX = -x;
14112
+ }
14113
+ else if (moveX < 0 && right + moveX < 0)
14114
+ moveX = -right;
14115
+ if (y >= 0 && bottom <= 0)
14116
+ moveY = 0;
14117
+ else if (moveY > 0) {
14118
+ if (y + moveY > 0)
14119
+ moveY = -y;
14120
+ }
14121
+ else if (moveY < 0 && bottom + moveY < 0)
14122
+ moveY = -bottom;
14123
+ }
14124
+ }
14125
+ return { x: disabled ? 0 : moveX, y: disabled ? 0 : moveY };
14126
+ };
14127
+ leafer.getValidScale = function (changeScale) {
14128
+ const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale);
14129
+ if (min && absScale < min)
14130
+ changeScale = min / scaleX;
14131
+ else if (max && absScale > max)
14132
+ changeScale = max / scaleX;
14133
+ return disabled ? 1 : MathHelper.float(changeScale);
14134
+ };
14135
+
14136
+ function getMoveEventData(move, event) {
14137
+ return Object.assign(Object.assign({}, event), { moveX: move.x, moveY: move.y });
14138
+ }
14139
+ function getRotateEventData(rotation, event) {
14140
+ return Object.assign(Object.assign({}, event), { rotation });
14141
+ }
14142
+ function getZoomEventData(scale, event) {
14143
+ return Object.assign(Object.assign({}, event), { scale });
14144
+ }
14145
+ const interaction = InteractionBase.prototype;
14146
+ interaction.createTransformer = function () {
14147
+ this.transformer = new Transformer(this);
14148
+ };
14149
+ interaction.move = function (data) {
14150
+ this.transformer.move(data);
14151
+ };
14152
+ interaction.zoom = function (data) {
14153
+ this.transformer.zoom(data);
14154
+ };
14155
+ interaction.rotate = function (data) {
14156
+ this.transformer.rotate(data);
14157
+ };
14158
+ interaction.transformEnd = function () {
14159
+ this.transformer.transformEnd();
14160
+ };
14161
+ interaction.wheel = function (data) {
14162
+ const { wheel } = this.config;
14163
+ if (wheel.disabled)
14164
+ return;
14165
+ const scale = wheel.getScale ? wheel.getScale(data, wheel) : WheelEventHelper.getScale(data, wheel);
14166
+ scale !== 1 ? this.zoom(getZoomEventData(scale, data)) : this.move(getMoveEventData(wheel.getMove ? wheel.getMove(data, wheel) : WheelEventHelper.getMove(data, wheel), data));
14167
+ };
14168
+ interaction.multiTouch = function (data, list) {
14169
+ if (this.config.multiTouch.disabled)
14170
+ return;
14171
+ const { move, rotation, scale, center } = MultiTouchHelper.getData(list);
14172
+ Object.assign(data, center);
14173
+ this.rotate(getRotateEventData(rotation, data));
14174
+ this.zoom(getZoomEventData(scale, data));
14175
+ this.move(getMoveEventData(move, data));
14176
+ };
14177
+
14178
+ const dragger = Dragger.prototype;
14179
+ const { abs } = Math;
14180
+ dragger.checkDragEndAnimate = function (data, speed) {
14181
+ const { moveX, moveY } = this.dragData;
14182
+ const absMoveX = abs(moveX), absMoveY = abs(moveY), minMove = speed ? 1 : 0.1;
14183
+ const dragAnimate = this.interaction.m.dragAnimate && this.canAnimate && this.moving && (absMoveX > minMove || absMoveY > minMove);
14184
+ if (dragAnimate) {
14185
+ const inertia = data.pointerType === 'touch' ? 3 : 1, maxMove = 70;
14186
+ speed = speed ? 0.95 : inertia;
14187
+ if (absMoveX * speed > maxMove)
14188
+ speed = maxMove / absMoveX;
14189
+ else if (absMoveY * speed > maxMove)
14190
+ speed = maxMove / absMoveY;
14191
+ data = Object.assign({}, data);
14192
+ PointHelper.move(data, moveX * speed, moveY * speed);
14193
+ this.drag(data);
14194
+ this.animate(() => { this.dragEnd(data, 1); });
14195
+ }
14196
+ return dragAnimate;
14197
+ };
14198
+ dragger.animate = function (func, off) {
14199
+ const animateWait = func || this.animateWait;
14200
+ if (animateWait)
14201
+ this.interaction.target.nextRender(animateWait, null, off);
14202
+ this.animateWait = func;
14203
+ };
14204
+ dragger.checkDragOut = function (data) {
14205
+ const { interaction } = this;
14206
+ this.autoMoveCancel();
14207
+ if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data))
14208
+ this.autoMoveOnDragOut(data);
14209
+ };
14210
+ dragger.autoMoveOnDragOut = function (data) {
14211
+ const { interaction, downData, canDragOut } = this;
14212
+ const { autoDistance, dragOut } = interaction.m;
14213
+ if (!dragOut || !canDragOut || !autoDistance)
14214
+ return;
14215
+ const bounds = interaction.shrinkCanvasBounds;
14216
+ const { x, y } = bounds;
14217
+ const right = BoundsHelper.maxX(bounds);
14218
+ const bottom = BoundsHelper.maxY(bounds);
14219
+ const moveX = data.x < x ? autoDistance : (right < data.x ? -autoDistance : 0);
14220
+ const moveY = data.y < y ? autoDistance : (bottom < data.y ? -autoDistance : 0);
14221
+ let totalX = 0, totalY = 0;
14222
+ this.autoMoveTimer = setInterval(() => {
14223
+ totalX += moveX;
14224
+ totalY += moveY;
14225
+ PointHelper.move(downData, moveX, moveY);
14226
+ PointHelper.move(this.dragData, moveX, moveY);
14227
+ interaction.move(Object.assign(Object.assign({}, data), { moveX, moveY, totalX, totalY, moveType: 'drag' }));
14228
+ interaction.pointerMoveReal(data);
14229
+ }, 10);
14230
+ };
14231
+ dragger.autoMoveCancel = function () {
14232
+ if (this.autoMoveTimer) {
14233
+ clearInterval(this.autoMoveTimer);
14234
+ this.autoMoveTimer = 0;
14235
+ }
14236
+ };
14237
+
14104
14238
  function getZoomScale(scaleX, type) {
14105
14239
  let scale = 1;
14106
14240
  const out = type === 'out', absScale = Math.abs(scaleX);
@@ -14130,7 +14264,7 @@ ${filterStyle}
14130
14264
 
14131
14265
  exports.Leafer.prototype.zoom = function (zoomType, padding, fixed) {
14132
14266
  const { zoomLayer } = this;
14133
- const limitBounds = this.canvas.bounds.clone().shrink(padding ? padding : 30), bounds = new Bounds();
14267
+ const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds();
14134
14268
  const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
14135
14269
  let changeScale;
14136
14270
  const { scaleX } = this.__;
@@ -14378,13 +14512,13 @@ ${filterStyle}
14378
14512
  const angle = { connect: half, offset: { x: -0.71, bevelJoin: 0.36, roundJoin: 0.22 }, path: [1, -3, -3, 2, 0, 0, 2, -3, 3] };
14379
14513
  const angleSide = { connect: half, offset: { x: -1.207, bevelJoin: 0.854, roundJoin: 0.707 }, path: [1, -3, -3, 2, 0, 0, 2, -1, 0] };
14380
14514
  const triangleLinePath = [1, -3, 0, 2, -3, -2, 2, 0, 0, 2, -3, 2, 2, -3, 0];
14381
- const triangle = { connect: half, offset: { x: -0.9, bevelJoin: 0.624, roundJoin: 0.4 }, path: [...triangleLinePath, 1, -2.05, 1.1, 2, -2.05, -1.1] };
14515
+ const triangle = { connect: half, offset: { x: -0.9, bevelJoin: 0.624, roundJoin: 0.4 }, path: [...triangleLinePath, 1, -2.05, 1.1, 2, -2.05, -1.1], dashPath: [1, -2, 0, 2, -0.5, 0] };
14382
14516
  const arrowLinePath = [1, -3, 0, 2, -3.5, -1.8, 2, 0, 0, 2, -3.5, 1.8, 2, -3, 0];
14383
- const arrow = { connect: half, offset: { x: -1.1, bevelJoin: 0.872, roundJoin: 0.6 }, path: [...arrowLinePath, 1, -2.25, 0.95, 2, -2.25, -0.95] };
14384
- const triangleFlip = { offset: half, path: [...triangle.path], };
14517
+ const arrow = { connect: half, offset: { x: -1.1, bevelJoin: 0.872, roundJoin: 0.6 }, path: [...arrowLinePath, 1, -2.25, 0.95, 2, -2.25, -0.95], dashPath: [1, -3, 0, 2, -0.5, 0] };
14518
+ const triangleFlip = { offset: half, path: [...triangle.path], dashPath: [1, -2.5, 0, 2, -1, 0] };
14385
14519
  rotate(triangleFlip.path, 180, { x: -1.5, y: 0 });
14386
14520
  const circleLine = { connect: { x: -1.3 }, path: [1, 1.8, -0.1, 2, 1.8, 0, 26, 0, 0, 1.8, 0, 359, 0], };
14387
- const circle = { connect: { x: 0.5 }, path: [...circleLine.path, 1, 0, 0, 26, 0, 0, 1, 0, 360, 0] };
14521
+ const circle = { connect: { x: 0.5 }, path: [...circleLine.path, 1, 0, 0, 26, 0, 0, 1, 0, 360, 0], dashPath: [1, -0.5, 0, 2, 0.5, 0] };
14388
14522
  const squareLine = { connect: { x: -1.3 }, path: [1, -1.4, 0, 2, -1.4, -1.4, 2, 1.4, -1.4, 2, 1.4, 1.4, 2, -1.4, 1.4, 2, -1.4, 0] };
14389
14523
  const square = { path: [...squareLine.path, 2, -1.4, -0.49, 2, 1, -0.49, 1, -1.4, 0.49, 2, 1, 0.49] };
14390
14524
  const diamondLine = DataHelper.clone(squareLine);
@@ -14406,12 +14540,14 @@ ${filterStyle}
14406
14540
  'diamond-line': diamondLine,
14407
14541
  mark,
14408
14542
  };
14409
- function getArrowPath(ui, arrow, from, to, scale, connectOffset) {
14543
+ function getArrowPath(ui, arrow, from, to, scale, connectOffset, hasDashPattern) {
14410
14544
  const { strokeCap, strokeJoin } = ui.__;
14411
- const { offset, connect, path } = (typeof arrow === 'object' ? arrow : arrows[arrow]);
14545
+ const { offset, connect, path, dashPath } = (typeof arrow === 'object' ? arrow : arrows[arrow]);
14412
14546
  let connectX = connect ? connect.x : 0;
14413
14547
  let offsetX = offset ? offset.x : 0;
14414
14548
  const data = [...path];
14549
+ if (hasDashPattern && dashPath)
14550
+ data.push(...dashPath);
14415
14551
  if (strokeCap !== 'none')
14416
14552
  connectX -= 0.5;
14417
14553
  if (offset) {
@@ -14435,7 +14571,7 @@ ${filterStyle}
14435
14571
  const PathArrowModule = {
14436
14572
  list: arrows,
14437
14573
  addArrows(ui, changeRenderPath) {
14438
- const { startArrow, endArrow, strokeWidth, __pathForRender: data } = ui.__;
14574
+ const { startArrow, endArrow, strokeWidth, dashPattern, __pathForRender: data } = ui.__;
14439
14575
  let command, i = 0, len = data.length, count = 0, useStartArrow = startArrow && startArrow !== 'none';
14440
14576
  while (i < len) {
14441
14577
  command = data[i];
@@ -14494,17 +14630,20 @@ ${filterStyle}
14494
14630
  if (count === 2 && useStartArrow)
14495
14631
  copy(second, command === L ? now : last);
14496
14632
  if (i === len) {
14497
- const p = ui.__.__pathForRender = changeRenderPath ? [...data] : data;
14633
+ const path = ui.__.__pathForRender = changeRenderPath ? [...data] : data;
14634
+ const pathForArrow = ui.__.__pathForArrow = [];
14498
14635
  if (useStartArrow) {
14499
- p.push(...getArrowPath(ui, startArrow, second, first, strokeWidth, connectPoint));
14636
+ const startArrowPath = getArrowPath(ui, startArrow, second, first, strokeWidth, connectPoint, !!dashPattern);
14637
+ dashPattern ? pathForArrow.push(...startArrowPath) : path.push(...startArrowPath);
14500
14638
  if (connectPoint.x) {
14501
14639
  getDistancePoint(first, second, -connectPoint.x, true);
14502
- p[1] = second.x;
14503
- p[2] = second.y;
14640
+ path[1] = second.x;
14641
+ path[2] = second.y;
14504
14642
  }
14505
14643
  }
14506
14644
  if (endArrow && endArrow !== 'none') {
14507
- p.push(...getArrowPath(ui, endArrow, last, now, strokeWidth, connectPoint));
14645
+ const endArrowPath = getArrowPath(ui, endArrow, last, now, strokeWidth, connectPoint, !!dashPattern);
14646
+ dashPattern ? pathForArrow.push(...endArrowPath) : path.push(...endArrowPath);
14508
14647
  if (connectPoint.x) {
14509
14648
  getDistancePoint(now, last, -connectPoint.x, true);
14510
14649
  let index;
@@ -14523,7 +14662,7 @@ ${filterStyle}
14523
14662
  break;
14524
14663
  }
14525
14664
  if (index)
14526
- setPoint(p, last, index);
14665
+ setPoint(path, last, index);
14527
14666
  }
14528
14667
  }
14529
14668
  }
@@ -14648,7 +14787,7 @@ ${filterStyle}
14648
14787
  style.position = 'fixed';
14649
14788
  style.transformOrigin = 'left top';
14650
14789
  style.boxSizing = 'border-box';
14651
- this.isHTMLText ? div.innerHTML = text.text : div.innerText = text.text;
14790
+ this.isHTMLText ? div.innerHTML = String(text.text) : div.innerText = String(text.text);
14652
14791
  const { view } = editor.app;
14653
14792
  (this.inBody = view instanceof HTMLCanvasElement) ? document.body.appendChild(div) : view.appendChild(div);
14654
14793
  this.eventIds = [
@@ -14837,6 +14976,7 @@ ${filterStyle}
14837
14976
  exports.Cursor = Cursor;
14838
14977
  exports.DataHelper = DataHelper;
14839
14978
  exports.Debug = Debug;
14979
+ exports.Dragger = Dragger;
14840
14980
  exports.EditBox = EditBox;
14841
14981
  exports.EditDataHelper = EditDataHelper;
14842
14982
  exports.EditPoint = EditPoint;
@@ -14946,6 +15086,7 @@ ${filterStyle}
14946
15086
  exports.TaskProcessor = TaskProcessor;
14947
15087
  exports.TextConvert = TextConvert;
14948
15088
  exports.TextData = TextData;
15089
+ exports.Transformer = Transformer;
14949
15090
  exports.Transition = Transition;
14950
15091
  exports.TwoPointBoundsHelper = TwoPointBoundsHelper;
14951
15092
  exports.UIBounds = UIBounds;
@@ -14957,7 +15098,9 @@ ${filterStyle}
14957
15098
  exports.WaitHelper = WaitHelper;
14958
15099
  exports.WatchEvent = WatchEvent;
14959
15100
  exports.Watcher = Watcher;
14960
- exports.addInteractionWindow = addInteractionWindow;
15101
+ exports.WheelEventHelper = WheelEventHelper;
15102
+ exports.addViewport = addViewport;
15103
+ exports.addViewportConfig = addViewportConfig;
14961
15104
  exports.affectRenderBoundsType = affectRenderBoundsType;
14962
15105
  exports.affectStrokeBoundsType = affectStrokeBoundsType;
14963
15106
  exports.arrowType = arrowType;