@leafer-ui/worker 1.0.1 → 1.0.3

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
@@ -114,6 +114,26 @@ var LeaferUI = (function (exports) {
114
114
  const a = maxLength ? pow$1(10, maxLength) : 1000000000000;
115
115
  num = round(num * a) / a;
116
116
  return num === -0 ? 0 : num;
117
+ },
118
+ getScaleData(scale, size, originSize, scaleData) {
119
+ if (!scaleData)
120
+ scaleData = {};
121
+ if (size) {
122
+ scaleData.scaleX = (typeof size === 'number' ? size : size.width) / originSize.width;
123
+ scaleData.scaleY = (typeof size === 'number' ? size : size.height) / originSize.height;
124
+ }
125
+ else if (scale)
126
+ MathHelper.assignScale(scaleData, scale);
127
+ return scaleData;
128
+ },
129
+ assignScale(scaleData, scale) {
130
+ if (typeof scale === 'number') {
131
+ scaleData.scaleX = scaleData.scaleY = scale;
132
+ }
133
+ else {
134
+ scaleData.scaleX = scale.x;
135
+ scaleData.scaleY = scale.y;
136
+ }
117
137
  }
118
138
  };
119
139
  const OneRadian = PI$4 / 180;
@@ -412,7 +432,7 @@ var LeaferUI = (function (exports) {
412
432
  };
413
433
  const M$6 = MatrixHelper;
414
434
 
415
- const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$2 } = MatrixHelper;
435
+ const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
416
436
  const { sin: sin$4, cos: cos$4, abs: abs$4, sqrt: sqrt$2, atan2: atan2$2, min: min$1, PI: PI$3 } = Math;
417
437
  const PointHelper = {
418
438
  defaultPoint: getPointData(),
@@ -468,7 +488,7 @@ var LeaferUI = (function (exports) {
468
488
  tempToOuterOf(t, matrix) {
469
489
  const { tempPoint: temp } = P$5;
470
490
  copy$b(temp, t);
471
- toOuterPoint$2(matrix, temp, temp);
491
+ toOuterPoint$3(matrix, temp, temp);
472
492
  return temp;
473
493
  },
474
494
  tempToInnerRadiusPointOf(t, matrix) {
@@ -487,7 +507,7 @@ var LeaferUI = (function (exports) {
487
507
  toInnerPoint$2(matrix, t, to);
488
508
  },
489
509
  toOuterOf(t, matrix, to) {
490
- toOuterPoint$2(matrix, t, to);
510
+ toOuterPoint$3(matrix, t, to);
491
511
  },
492
512
  getCenter(t, to) {
493
513
  return { x: t.x + (to.x - t.x) / 2, y: t.y + (to.y - t.y) / 2 };
@@ -767,7 +787,7 @@ var LeaferUI = (function (exports) {
767
787
  const { addPoint: addPoint$4 } = TwoPointBoundsHelper;
768
788
 
769
789
  const { tempPointBounds: tempPointBounds$1, setPoint: setPoint$3, addPoint: addPoint$3, toBounds: toBounds$4 } = TwoPointBoundsHelper;
770
- const { toOuterPoint: toOuterPoint$1 } = MatrixHelper;
790
+ const { toOuterPoint: toOuterPoint$2 } = MatrixHelper;
771
791
  const { float, fourNumber } = MathHelper;
772
792
  const { floor, ceil: ceil$2 } = Math;
773
793
  let right$1, bottom$1, boundsRight, boundsBottom;
@@ -787,17 +807,24 @@ var LeaferUI = (function (exports) {
787
807
  t.width = bounds.width;
788
808
  t.height = bounds.height;
789
809
  },
790
- copyAndSpread(t, bounds, spread, isShrink) {
810
+ copyAndSpread(t, bounds, spread, isShrink, side) {
811
+ const { x, y, width, height } = bounds;
791
812
  if (spread instanceof Array) {
792
813
  const four = fourNumber(spread);
793
814
  isShrink
794
- ? B.set(t, bounds.x + four[3], bounds.y + four[0], bounds.width - four[1] - four[3], bounds.height - four[2] - four[0])
795
- : B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
815
+ ? B.set(t, x + four[3], y + four[0], width - four[1] - four[3], height - four[2] - four[0])
816
+ : B.set(t, x - four[3], y - four[0], width + four[1] + four[3], height + four[2] + four[0]);
796
817
  }
797
818
  else {
798
819
  if (isShrink)
799
820
  spread = -spread;
800
- B.set(t, bounds.x - spread, bounds.y - spread, bounds.width + spread * 2, bounds.height + spread * 2);
821
+ B.set(t, x - spread, y - spread, width + spread * 2, height + spread * 2);
822
+ }
823
+ if (side) {
824
+ if (side === 'width')
825
+ t.y = y, t.height = height;
826
+ else
827
+ t.x = x, t.width = width;
801
828
  }
802
829
  },
803
830
  minX(t) { return t.width > 0 ? t.x : t.x + t.width; },
@@ -874,16 +901,16 @@ var LeaferUI = (function (exports) {
874
901
  else {
875
902
  point.x = t.x;
876
903
  point.y = t.y;
877
- toOuterPoint$1(matrix, point, toPoint$5);
904
+ toOuterPoint$2(matrix, point, toPoint$5);
878
905
  setPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
879
906
  point.x = t.x + t.width;
880
- toOuterPoint$1(matrix, point, toPoint$5);
907
+ toOuterPoint$2(matrix, point, toPoint$5);
881
908
  addPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
882
909
  point.y = t.y + t.height;
883
- toOuterPoint$1(matrix, point, toPoint$5);
910
+ toOuterPoint$2(matrix, point, toPoint$5);
884
911
  addPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
885
912
  point.x = t.x;
886
- toOuterPoint$1(matrix, point, toPoint$5);
913
+ toOuterPoint$2(matrix, point, toPoint$5);
887
914
  addPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
888
915
  toBounds$4(tempPointBounds$1, to);
889
916
  }
@@ -897,16 +924,16 @@ var LeaferUI = (function (exports) {
897
924
  const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
898
925
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
899
926
  },
900
- getSpread(t, spread) {
927
+ getSpread(t, spread, side) {
901
928
  const n = {};
902
- B.copyAndSpread(n, t, spread);
929
+ B.copyAndSpread(n, t, spread, false, side);
903
930
  return n;
904
931
  },
905
- spread(t, spread) {
906
- B.copyAndSpread(t, t, spread);
932
+ spread(t, spread, side) {
933
+ B.copyAndSpread(t, t, spread, false, side);
907
934
  },
908
- shrink(t, shrink) {
909
- B.copyAndSpread(t, t, shrink, true);
935
+ shrink(t, shrink, side) {
936
+ B.copyAndSpread(t, t, shrink, true, side);
910
937
  },
911
938
  ceil(t) {
912
939
  const { x, y } = t;
@@ -1089,12 +1116,12 @@ var LeaferUI = (function (exports) {
1089
1116
  getFitMatrix(put, baseScale) {
1090
1117
  return BoundsHelper.getFitMatrix(this, put, baseScale);
1091
1118
  }
1092
- spread(fourNumber) {
1093
- BoundsHelper.spread(this, fourNumber);
1119
+ spread(fourNumber, side) {
1120
+ BoundsHelper.spread(this, fourNumber, side);
1094
1121
  return this;
1095
1122
  }
1096
- shrink(fourNumber) {
1097
- BoundsHelper.shrink(this, fourNumber);
1123
+ shrink(fourNumber, side) {
1124
+ BoundsHelper.shrink(this, fourNumber, side);
1098
1125
  return this;
1099
1126
  }
1100
1127
  ceil() {
@@ -1238,7 +1265,6 @@ var LeaferUI = (function (exports) {
1238
1265
  tempPoint: {},
1239
1266
  get: get$4,
1240
1267
  toPoint(around, bounds, to, onlySize, pointBounds) {
1241
- to || (to = {});
1242
1268
  const point = get$4(around);
1243
1269
  to.x = point.x;
1244
1270
  to.y = point.y;
@@ -1373,6 +1399,10 @@ var LeaferUI = (function (exports) {
1373
1399
  };
1374
1400
  const R = Run;
1375
1401
 
1402
+ function needPlugin(name) {
1403
+ console.error('need plugin: @leafer-in/' + name);
1404
+ }
1405
+
1376
1406
  const debug$e = Debug.get('UICreator');
1377
1407
  const UICreator = {
1378
1408
  list: {},
@@ -1635,6 +1665,9 @@ var LeaferUI = (function (exports) {
1635
1665
  Answer[Answer["YesAndSkip"] = 3] = "YesAndSkip";
1636
1666
  })(exports.Answer || (exports.Answer = {}));
1637
1667
  const emptyData = {};
1668
+ function isNull(value) {
1669
+ return value === undefined || value === null;
1670
+ }
1638
1671
 
1639
1672
  /******************************************************************************
1640
1673
  Copyright (c) Microsoft Corporation.
@@ -2400,7 +2433,7 @@ var LeaferUI = (function (exports) {
2400
2433
  let startY = y = rotationSin * radiusX * startCos + rotationCos * radiusY * startSin;
2401
2434
  let fromX = cx + x, fromY = cy + y;
2402
2435
  if (data)
2403
- data.push(L$6, fromX, fromY);
2436
+ data.push(data.length ? L$6 : M$5, fromX, fromY);
2404
2437
  if (setPointBounds)
2405
2438
  setPoint$2(setPointBounds, fromX, fromY);
2406
2439
  if (setStartPoint)
@@ -2911,60 +2944,75 @@ var LeaferUI = (function (exports) {
2911
2944
  }
2912
2945
  beginPath() {
2913
2946
  beginPath(this.__path);
2947
+ this.paint();
2914
2948
  return this;
2915
2949
  }
2916
2950
  moveTo(x, y) {
2917
2951
  moveTo$4(this.__path, x, y);
2952
+ this.paint();
2918
2953
  return this;
2919
2954
  }
2920
2955
  lineTo(x, y) {
2921
2956
  lineTo$3(this.__path, x, y);
2957
+ this.paint();
2922
2958
  return this;
2923
2959
  }
2924
2960
  bezierCurveTo(x1, y1, x2, y2, x, y) {
2925
2961
  bezierCurveTo(this.__path, x1, y1, x2, y2, x, y);
2962
+ this.paint();
2926
2963
  return this;
2927
2964
  }
2928
2965
  quadraticCurveTo(x1, y1, x, y) {
2929
2966
  quadraticCurveTo(this.__path, x1, y1, x, y);
2967
+ this.paint();
2930
2968
  return this;
2931
2969
  }
2932
2970
  closePath() {
2933
2971
  closePath$3(this.__path);
2972
+ this.paint();
2934
2973
  return this;
2935
2974
  }
2936
2975
  rect(x, y, width, height) {
2937
2976
  rect$2(this.__path, x, y, width, height);
2977
+ this.paint();
2938
2978
  return this;
2939
2979
  }
2940
2980
  roundRect(x, y, width, height, cornerRadius) {
2941
2981
  roundRect$1(this.__path, x, y, width, height, cornerRadius);
2982
+ this.paint();
2942
2983
  return this;
2943
2984
  }
2944
2985
  ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
2945
2986
  ellipse$2(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
2987
+ this.paint();
2946
2988
  return this;
2947
2989
  }
2948
2990
  arc(x, y, radius, startAngle, endAngle, anticlockwise) {
2949
2991
  arc$1(this.__path, x, y, radius, startAngle, endAngle, anticlockwise);
2992
+ this.paint();
2950
2993
  return this;
2951
2994
  }
2952
2995
  arcTo(x1, y1, x2, y2, radius) {
2953
2996
  arcTo$2(this.__path, x1, y1, x2, y2, radius);
2997
+ this.paint();
2954
2998
  return this;
2955
2999
  }
2956
3000
  drawEllipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
2957
3001
  drawEllipse(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
3002
+ this.paint();
2958
3003
  return this;
2959
3004
  }
2960
3005
  drawArc(x, y, radius, startAngle, endAngle, anticlockwise) {
2961
3006
  drawArc(this.__path, x, y, radius, startAngle, endAngle, anticlockwise);
3007
+ this.paint();
2962
3008
  return this;
2963
3009
  }
2964
3010
  drawPoints(points, curve, close) {
2965
3011
  drawPoints$2(this.__path, points, curve, close);
3012
+ this.paint();
2966
3013
  return this;
2967
3014
  }
3015
+ paint() { }
2968
3016
  }
2969
3017
 
2970
3018
  const { M: M$2, L: L$3, C: C$2, Q: Q$1, Z: Z$2, N: N$1, D: D$1, X: X$1, G: G$1, F: F$2, O: O$1, P: P$1, U: U$1 } = PathCommandMap;
@@ -3054,8 +3102,7 @@ var LeaferUI = (function (exports) {
3054
3102
  toTwoPointBounds(data, setPointBounds) {
3055
3103
  if (!data || !data.length)
3056
3104
  return setPoint$1(setPointBounds, 0, 0);
3057
- let command;
3058
- let i = 0, x = 0, y = 0, x1, y1, toX, toY;
3105
+ let i = 0, x = 0, y = 0, x1, y1, toX, toY, command;
3059
3106
  const len = data.length;
3060
3107
  while (i < len) {
3061
3108
  command = data[i];
@@ -3711,7 +3758,7 @@ var LeaferUI = (function (exports) {
3711
3758
  set(value) {
3712
3759
  if (this.__setAttr(key, value)) {
3713
3760
  this.__layout.matrixChanged || this.__layout.matrixChange();
3714
- this.__hasAutoLayout = !!value;
3761
+ this.__hasAutoLayout = !!(this.origin || this.around || this.flow);
3715
3762
  if (!this.__local)
3716
3763
  this.__layout.createLocal();
3717
3764
  }
@@ -3804,14 +3851,25 @@ var LeaferUI = (function (exports) {
3804
3851
  return decorateLeafAttr(defaultValue, (key) => attr({
3805
3852
  set(value) {
3806
3853
  const oldValue = this.visible;
3807
- if (this.__setAttr(key, value)) {
3808
- this.__layout.opacityChanged || this.__layout.opacityChange();
3809
- if (oldValue === 0 || value === 0)
3810
- doBoundsType(this);
3854
+ if (oldValue === true && value === 0) {
3855
+ if (this.animationOut)
3856
+ return this.__runAnimation('out', () => doVisible(this, key, value, oldValue));
3811
3857
  }
3858
+ else if (oldValue === 0 && value === true) {
3859
+ if (this.animation)
3860
+ this.__runAnimation('in');
3861
+ }
3862
+ doVisible(this, key, value, oldValue);
3812
3863
  }
3813
3864
  }));
3814
3865
  }
3866
+ function doVisible(leaf, key, value, oldValue) {
3867
+ if (leaf.__setAttr(key, value)) {
3868
+ leaf.__layout.opacityChanged || leaf.__layout.opacityChange();
3869
+ if (oldValue === 0 || value === 0)
3870
+ doBoundsType(leaf);
3871
+ }
3872
+ }
3815
3873
  function sortType(defaultValue) {
3816
3874
  return decorateLeafAttr(defaultValue, (key) => attr({
3817
3875
  set(value) {
@@ -3895,7 +3953,16 @@ var LeaferUI = (function (exports) {
3895
3953
  if (defaultValue === undefined) {
3896
3954
  property.get = function () { return this[computedKey]; };
3897
3955
  }
3898
- else if (key === 'width') {
3956
+ else if (typeof defaultValue === 'object') {
3957
+ const { clone } = DataHelper;
3958
+ property.get = function () {
3959
+ let v = this[computedKey];
3960
+ if (v === undefined)
3961
+ this[computedKey] = v = clone(defaultValue);
3962
+ return v;
3963
+ };
3964
+ }
3965
+ if (key === 'width') {
3899
3966
  property.get = function () {
3900
3967
  const v = this[computedKey];
3901
3968
  if (v === undefined) {
@@ -3986,7 +4053,7 @@ var LeaferUI = (function (exports) {
3986
4053
  };
3987
4054
  }
3988
4055
 
3989
- const { copy: copy$7, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
4056
+ const { copy: copy$7, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3990
4057
  const matrix$1 = {};
3991
4058
  const LeafHelper = {
3992
4059
  updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
@@ -4051,10 +4118,9 @@ var LeaferUI = (function (exports) {
4051
4118
  }
4052
4119
  return true;
4053
4120
  },
4054
- moveWorld(t, x, y = 0) {
4121
+ moveWorld(t, x, y = 0, isInnerPoint) {
4055
4122
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4056
- if (t.parent)
4057
- toInnerPoint$1(t.parent.worldTransform, local, local, true);
4123
+ isInnerPoint ? toOuterPoint$1(t.localTransform, local, local, true) : (t.parent && toInnerPoint$1(t.parent.worldTransform, local, local, true));
4058
4124
  L.moveLocal(t, local.x, local.y);
4059
4125
  },
4060
4126
  moveLocal(t, x, y = 0) {
@@ -4563,144 +4629,6 @@ var LeaferUI = (function (exports) {
4563
4629
  destroy() { }
4564
4630
  }
4565
4631
 
4566
- const empty = {};
4567
- const LeafEventer = {
4568
- on(type, listener, options) {
4569
- let capture, once;
4570
- if (options) {
4571
- if (options === 'once') {
4572
- once = true;
4573
- }
4574
- else if (typeof options === 'boolean') {
4575
- capture = options;
4576
- }
4577
- else {
4578
- capture = options.capture;
4579
- once = options.once;
4580
- }
4581
- }
4582
- let events;
4583
- const map = __getListenerMap(this, capture, true);
4584
- const typeList = typeof type === 'string' ? type.split(' ') : type;
4585
- const item = once ? { listener, once } : { listener };
4586
- typeList.forEach(type => {
4587
- if (type) {
4588
- events = map[type];
4589
- if (events) {
4590
- if (events.findIndex(item => item.listener === listener) === -1)
4591
- events.push(item);
4592
- }
4593
- else {
4594
- map[type] = [item];
4595
- }
4596
- }
4597
- });
4598
- },
4599
- off(type, listener, options) {
4600
- if (type) {
4601
- const typeList = typeof type === 'string' ? type.split(' ') : type;
4602
- if (listener) {
4603
- let capture;
4604
- if (options)
4605
- capture = typeof options === 'boolean' ? options : (options === 'once' ? false : options.capture);
4606
- let events, index;
4607
- const map = __getListenerMap(this, capture);
4608
- typeList.forEach(type => {
4609
- if (type) {
4610
- events = map[type];
4611
- if (events) {
4612
- index = events.findIndex(item => item.listener === listener);
4613
- if (index > -1)
4614
- events.splice(index, 1);
4615
- if (!events.length)
4616
- delete map[type];
4617
- }
4618
- }
4619
- });
4620
- }
4621
- else {
4622
- const { __bubbleMap: b, __captureMap: c } = this;
4623
- typeList.forEach(type => {
4624
- if (b)
4625
- delete b[type];
4626
- if (c)
4627
- delete c[type];
4628
- });
4629
- }
4630
- }
4631
- else {
4632
- this.__bubbleMap = this.__captureMap = undefined;
4633
- }
4634
- },
4635
- on_(type, listener, bind, options) {
4636
- if (bind)
4637
- listener = listener.bind(bind);
4638
- this.on(type, listener, options);
4639
- return { type, current: this, listener, options };
4640
- },
4641
- off_(id) {
4642
- if (!id)
4643
- return;
4644
- const list = id instanceof Array ? id : [id];
4645
- list.forEach(item => item.current.off(item.type, item.listener, item.options));
4646
- list.length = 0;
4647
- },
4648
- once(type, listener, capture) {
4649
- this.on(type, listener, { once: true, capture });
4650
- },
4651
- emit(type, event, capture) {
4652
- if (!event && EventCreator.has(type))
4653
- event = EventCreator.get(type, { type, target: this, current: this });
4654
- const map = __getListenerMap(this, capture);
4655
- const list = map[type];
4656
- if (list) {
4657
- let item;
4658
- for (let i = 0, len = list.length; i < len; i++) {
4659
- item = list[i];
4660
- item.listener(event);
4661
- if (item.once) {
4662
- this.off(type, item.listener, capture);
4663
- i--, len--;
4664
- }
4665
- if (event && event.isStopNow)
4666
- break;
4667
- }
4668
- }
4669
- this.syncEventer && this.syncEventer.emitEvent(event, capture);
4670
- },
4671
- emitEvent(event, capture) {
4672
- event.current = this;
4673
- this.emit(event.type, event, capture);
4674
- },
4675
- hasEvent(type, capture) {
4676
- if (this.syncEventer && this.syncEventer.hasEvent(type, capture))
4677
- return true;
4678
- const { __bubbleMap: b, __captureMap: c } = this;
4679
- const hasB = b && b[type], hasC = c && c[type];
4680
- return !!(capture === undefined ? (hasB || hasC) : (capture ? hasC : hasB));
4681
- },
4682
- };
4683
- function __getListenerMap(eventer, capture, create) {
4684
- if (capture) {
4685
- const { __captureMap: c } = eventer;
4686
- if (c) {
4687
- return c;
4688
- }
4689
- else {
4690
- return create ? eventer.__captureMap = {} : empty;
4691
- }
4692
- }
4693
- else {
4694
- const { __bubbleMap: b } = eventer;
4695
- if (b) {
4696
- return b;
4697
- }
4698
- else {
4699
- return create ? eventer.__bubbleMap = {} : empty;
4700
- }
4701
- }
4702
- }
4703
-
4704
4632
  class Event {
4705
4633
  constructor(type, target) {
4706
4634
  this.bubbles = false;
@@ -4735,7 +4663,10 @@ var LeaferUI = (function (exports) {
4735
4663
  }
4736
4664
  ChildEvent.ADD = 'child.add';
4737
4665
  ChildEvent.REMOVE = 'child.remove';
4738
- ChildEvent.DESTROY = 'child.destroy';
4666
+ ChildEvent.CREATED = 'created';
4667
+ ChildEvent.MOUNTED = 'mounted';
4668
+ ChildEvent.UNMOUNTED = 'unmounted';
4669
+ ChildEvent.DESTROY = 'destroy';
4739
4670
 
4740
4671
  class PropertyEvent extends Event {
4741
4672
  constructor(type, target, attrName, oldValue, newValue) {
@@ -4813,10 +4744,6 @@ var LeaferUI = (function (exports) {
4813
4744
  LayoutEvent.AGAIN = 'layout.again';
4814
4745
  LayoutEvent.END = 'layout.end';
4815
4746
 
4816
- class AnimateEvent extends Event {
4817
- }
4818
- AnimateEvent.FRAME = 'animate.frame';
4819
-
4820
4747
  class RenderEvent extends Event {
4821
4748
  constructor(type, times, bounds, options) {
4822
4749
  super(type);
@@ -4849,6 +4776,157 @@ var LeaferUI = (function (exports) {
4849
4776
  LeaferEvent.RESTART = 'leafer.restart';
4850
4777
  LeaferEvent.END = 'leafer.end';
4851
4778
 
4779
+ const empty = {};
4780
+ class Eventer {
4781
+ set event(map) { this.on(map); }
4782
+ on(type, listener, options) {
4783
+ if (!listener) {
4784
+ let event, map = type;
4785
+ for (let key in map)
4786
+ event = map[key], event instanceof Array ? this.on(key, event[0], event[1]) : this.on(key, event);
4787
+ return;
4788
+ }
4789
+ let capture, once;
4790
+ if (options) {
4791
+ if (options === 'once') {
4792
+ once = true;
4793
+ }
4794
+ else if (typeof options === 'boolean') {
4795
+ capture = options;
4796
+ }
4797
+ else {
4798
+ capture = options.capture;
4799
+ once = options.once;
4800
+ }
4801
+ }
4802
+ let events;
4803
+ const map = __getListenerMap(this, capture, true);
4804
+ const typeList = typeof type === 'string' ? type.split(' ') : type;
4805
+ const item = once ? { listener, once } : { listener };
4806
+ typeList.forEach(type => {
4807
+ if (type) {
4808
+ events = map[type];
4809
+ if (events) {
4810
+ if (events.findIndex(item => item.listener === listener) === -1)
4811
+ events.push(item);
4812
+ }
4813
+ else {
4814
+ map[type] = [item];
4815
+ }
4816
+ }
4817
+ });
4818
+ }
4819
+ off(type, listener, options) {
4820
+ if (type) {
4821
+ const typeList = typeof type === 'string' ? type.split(' ') : type;
4822
+ if (listener) {
4823
+ let capture;
4824
+ if (options)
4825
+ capture = typeof options === 'boolean' ? options : (options === 'once' ? false : options.capture);
4826
+ let events, index;
4827
+ const map = __getListenerMap(this, capture);
4828
+ typeList.forEach(type => {
4829
+ if (type) {
4830
+ events = map[type];
4831
+ if (events) {
4832
+ index = events.findIndex(item => item.listener === listener);
4833
+ if (index > -1)
4834
+ events.splice(index, 1);
4835
+ if (!events.length)
4836
+ delete map[type];
4837
+ }
4838
+ }
4839
+ });
4840
+ }
4841
+ else {
4842
+ const { __bubbleMap: b, __captureMap: c } = this;
4843
+ typeList.forEach(type => {
4844
+ if (b)
4845
+ delete b[type];
4846
+ if (c)
4847
+ delete c[type];
4848
+ });
4849
+ }
4850
+ }
4851
+ else {
4852
+ this.__bubbleMap = this.__captureMap = undefined;
4853
+ }
4854
+ }
4855
+ on_(type, listener, bind, options) {
4856
+ if (bind)
4857
+ listener = listener.bind(bind);
4858
+ this.on(type, listener, options);
4859
+ return { type, current: this, listener, options };
4860
+ }
4861
+ off_(id) {
4862
+ if (!id)
4863
+ return;
4864
+ const list = id instanceof Array ? id : [id];
4865
+ list.forEach(item => item.current.off(item.type, item.listener, item.options));
4866
+ list.length = 0;
4867
+ }
4868
+ once(type, listener, capture) {
4869
+ this.on(type, listener, { once: true, capture });
4870
+ }
4871
+ emit(type, event, capture) {
4872
+ if (!event && EventCreator.has(type))
4873
+ event = EventCreator.get(type, { type, target: this, current: this });
4874
+ const map = __getListenerMap(this, capture);
4875
+ const list = map[type];
4876
+ if (list) {
4877
+ let item;
4878
+ for (let i = 0, len = list.length; i < len; i++) {
4879
+ item = list[i];
4880
+ item.listener(event);
4881
+ if (item.once) {
4882
+ this.off(type, item.listener, capture);
4883
+ i--, len--;
4884
+ }
4885
+ if (event && event.isStopNow)
4886
+ break;
4887
+ }
4888
+ }
4889
+ this.syncEventer && this.syncEventer.emitEvent(event, capture);
4890
+ }
4891
+ emitEvent(event, capture) {
4892
+ event.current = this;
4893
+ this.emit(event.type, event, capture);
4894
+ }
4895
+ hasEvent(type, capture) {
4896
+ if (this.syncEventer && this.syncEventer.hasEvent(type, capture))
4897
+ return true;
4898
+ const { __bubbleMap: b, __captureMap: c } = this;
4899
+ const hasB = b && b[type], hasC = c && c[type];
4900
+ return !!(capture === undefined ? (hasB || hasC) : (capture ? hasC : hasB));
4901
+ }
4902
+ destroy() {
4903
+ this.__captureMap = this.__bubbleMap = this.syncEventer = null;
4904
+ }
4905
+ }
4906
+ function __getListenerMap(eventer, capture, create) {
4907
+ if (capture) {
4908
+ const { __captureMap: c } = eventer;
4909
+ if (c) {
4910
+ return c;
4911
+ }
4912
+ else {
4913
+ return create ? eventer.__captureMap = {} : empty;
4914
+ }
4915
+ }
4916
+ else {
4917
+ const { __bubbleMap: b } = eventer;
4918
+ if (b) {
4919
+ return b;
4920
+ }
4921
+ else {
4922
+ return create ? eventer.__bubbleMap = {} : empty;
4923
+ }
4924
+ }
4925
+ }
4926
+
4927
+ const { on, on_, off, off_, once, emit: emit$2, emitEvent: emitEvent$1, hasEvent, destroy } = Eventer.prototype;
4928
+ const LeafEventer = { on, on_, off, off_, once, emit: emit$2, emitEvent: emitEvent$1, hasEvent, destroyEventer: destroy };
4929
+
4852
4930
  const { isFinite } = Number;
4853
4931
  const debug$7 = Debug.get('setAttr');
4854
4932
  const LeafDataProxy = {
@@ -4860,9 +4938,7 @@ var LeaferUI = (function (exports) {
4860
4938
  newValue = undefined;
4861
4939
  }
4862
4940
  if (typeof newValue === 'object' || oldValue !== newValue) {
4863
- this.__[name] = newValue;
4864
- if (this.__proxyData)
4865
- this.setProxyAttr(name, newValue);
4941
+ this.__realSetAttr(name, newValue);
4866
4942
  const { CHANGE } = PropertyEvent;
4867
4943
  const event = new PropertyEvent(CHANGE, this, name, oldValue, newValue);
4868
4944
  if (this.isLeafer) {
@@ -4880,12 +4956,18 @@ var LeaferUI = (function (exports) {
4880
4956
  }
4881
4957
  }
4882
4958
  else {
4883
- this.__[name] = newValue;
4884
- if (this.__proxyData)
4885
- this.setProxyAttr(name, newValue);
4959
+ this.__realSetAttr(name, newValue);
4886
4960
  return true;
4887
4961
  }
4888
4962
  },
4963
+ __realSetAttr(name, newValue) {
4964
+ const data = this.__;
4965
+ data[name] = newValue;
4966
+ if (this.__proxyData)
4967
+ this.setProxyAttr(name, newValue);
4968
+ if (data.normalStyle)
4969
+ this.lockNormalStyle || data.normalStyle[name] === undefined || (data.normalStyle[name] = newValue);
4970
+ },
4889
4971
  __getAttr(name) {
4890
4972
  if (this.__proxyData)
4891
4973
  return this.getProxyAttr(name);
@@ -4921,7 +5003,7 @@ var LeaferUI = (function (exports) {
4921
5003
 
4922
5004
  const { updateMatrix: updateMatrix$1, updateAllMatrix: updateAllMatrix$2 } = LeafHelper;
4923
5005
  const { updateBounds: updateBounds$1 } = BranchHelper;
4924
- const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$5 } = BoundsHelper;
5006
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$2, copy: copy$5 } = BoundsHelper;
4925
5007
  const { toBounds: toBounds$2 } = PathBounds;
4926
5008
  const LeafBounds = {
4927
5009
  __updateWorldBounds() {
@@ -4988,6 +5070,8 @@ var LeaferUI = (function (exports) {
4988
5070
  layout.boundsChanged = false;
4989
5071
  },
4990
5072
  __updateLocalBoxBounds() {
5073
+ if (this.__hasMotionPath)
5074
+ this.__updateMotionPath();
4991
5075
  if (this.__hasAutoLayout)
4992
5076
  this.__updateAutoLayout();
4993
5077
  toOuterOf$1(this.__layout.boxBounds, this.__local, this.__local);
@@ -5022,7 +5106,7 @@ var LeaferUI = (function (exports) {
5022
5106
  updateAllMatrix$2(this);
5023
5107
  updateBounds$1(this, this);
5024
5108
  if (this.__.__autoSide)
5025
- this.__updateBoxBounds();
5109
+ this.__updateBoxBounds(true);
5026
5110
  }
5027
5111
  else {
5028
5112
  updateAllMatrix$2(this);
@@ -5040,11 +5124,11 @@ var LeaferUI = (function (exports) {
5040
5124
  },
5041
5125
  __updateStrokeBounds() {
5042
5126
  const layout = this.__layout;
5043
- copyAndSpread$1(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5127
+ copyAndSpread$2(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5044
5128
  },
5045
5129
  __updateRenderBounds() {
5046
5130
  const layout = this.__layout;
5047
- layout.renderSpread > 0 ? copyAndSpread$1(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$5(layout.renderBounds, layout.strokeBounds);
5131
+ layout.renderSpread > 0 ? copyAndSpread$2(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$5(layout.renderBounds, layout.strokeBounds);
5048
5132
  }
5049
5133
  };
5050
5134
 
@@ -5140,7 +5224,7 @@ var LeaferUI = (function (exports) {
5140
5224
  const { LEAF, create } = IncrementId;
5141
5225
  const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper;
5142
5226
  const { toOuterOf } = BoundsHelper;
5143
- const { copy: copy$4 } = PointHelper;
5227
+ const { copy: copy$4, move: move$1 } = PointHelper;
5144
5228
  const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getFlipTransform, getLocalOrigin, getRelativeWorld, drop } = LeafHelper;
5145
5229
  exports.Leaf = class Leaf {
5146
5230
  get tag() { return this.__tag; }
@@ -5167,13 +5251,16 @@ var LeaferUI = (function (exports) {
5167
5251
  get __ignoreHitWorld() { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren; }
5168
5252
  get __inLazyBounds() { const { leafer } = this; return leafer && leafer.created && leafer.lazyBounds.hit(this.__world); }
5169
5253
  get pathInputed() { return this.__.__pathInputed; }
5170
- set event(map) { let event; for (let key in map)
5171
- event = map[key], event instanceof Array ? this.on(key, event[0], event[1]) : this.on(key, event); }
5254
+ set event(map) { this.on(map); }
5172
5255
  constructor(data) {
5173
5256
  this.innerId = create(LEAF);
5174
5257
  this.reset(data);
5258
+ if (this.__bubbleMap)
5259
+ this.__emitLifeEvent(ChildEvent.CREATED);
5175
5260
  }
5176
5261
  reset(data) {
5262
+ if (this.leafer)
5263
+ this.leafer.forceRender(this.__world);
5177
5264
  this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1 };
5178
5265
  if (data !== null)
5179
5266
  this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 };
@@ -5195,12 +5282,12 @@ var LeaferUI = (function (exports) {
5195
5282
  waitParent(item, bind) {
5196
5283
  if (bind)
5197
5284
  item = item.bind(bind);
5198
- this.parent ? item() : (this.__parentWait ? this.__parentWait.push(item) : this.__parentWait = [item]);
5285
+ this.parent ? item() : this.on(ChildEvent.ADD, item, 'once');
5199
5286
  }
5200
5287
  waitLeafer(item, bind) {
5201
5288
  if (bind)
5202
5289
  item = item.bind(bind);
5203
- this.leafer ? item() : (this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item]);
5290
+ this.leafer ? item() : this.on(ChildEvent.MOUNTED, item, 'once');
5204
5291
  }
5205
5292
  nextRender(item, bind, off) {
5206
5293
  this.leafer ? this.leafer.nextRender(item, bind, off) : this.waitLeafer(() => this.leafer.nextRender(item, bind, off));
@@ -5209,18 +5296,21 @@ var LeaferUI = (function (exports) {
5209
5296
  this.nextRender(item, null, 'off');
5210
5297
  }
5211
5298
  __bindLeafer(leafer) {
5212
- if (this.isLeafer) {
5213
- if (leafer !== null)
5214
- leafer = this;
5215
- }
5299
+ if (this.isLeafer && leafer !== null)
5300
+ leafer = this;
5216
5301
  if (this.leafer && !leafer)
5217
5302
  this.leafer.leafs--;
5218
5303
  this.leafer = leafer;
5219
5304
  if (leafer) {
5220
5305
  leafer.leafs++;
5221
5306
  this.__level = this.parent ? this.parent.__level + 1 : 1;
5222
- if (this.__leaferWait)
5223
- WaitHelper.run(this.__leaferWait);
5307
+ if (this.animation)
5308
+ this.__runAnimation('in');
5309
+ if (this.__bubbleMap)
5310
+ this.__emitLifeEvent(ChildEvent.MOUNTED);
5311
+ }
5312
+ else {
5313
+ this.__emitLifeEvent(ChildEvent.UNMOUNTED);
5224
5314
  }
5225
5315
  if (this.isBranch) {
5226
5316
  const { children } = this;
@@ -5229,7 +5319,7 @@ var LeaferUI = (function (exports) {
5229
5319
  }
5230
5320
  }
5231
5321
  }
5232
- set(_data) { }
5322
+ set(_data, _isTemp) { }
5233
5323
  get(_name) { return undefined; }
5234
5324
  setAttr(name, value) { this[name] = value; }
5235
5325
  getAttr(name) { return this[name]; }
@@ -5254,6 +5344,7 @@ var LeaferUI = (function (exports) {
5254
5344
  findOne(_condition, _options) { return undefined; }
5255
5345
  findId(_id) { return undefined; }
5256
5346
  focus(_value) { }
5347
+ updateState() { }
5257
5348
  updateLayout() {
5258
5349
  this.__layout.update();
5259
5350
  }
@@ -5361,11 +5452,24 @@ var LeaferUI = (function (exports) {
5361
5452
  if (relative)
5362
5453
  relative.worldToInner(to ? to : inner, null, distance);
5363
5454
  }
5455
+ getBoxPoint(world, relative, distance, change) {
5456
+ return this.getBoxPointByInner(this.getInnerPoint(world, relative, distance, change), null, null, true);
5457
+ }
5458
+ getBoxPointByInner(inner, _relative, _distance, change) {
5459
+ const point = change ? inner : Object.assign({}, inner), { x, y } = this.boxBounds;
5460
+ move$1(point, -x, -y);
5461
+ return point;
5462
+ }
5364
5463
  getInnerPoint(world, relative, distance, change) {
5365
5464
  const point = change ? world : {};
5366
5465
  this.worldToInner(world, point, distance, relative);
5367
5466
  return point;
5368
5467
  }
5468
+ getInnerPointByBox(box, _relative, _distance, change) {
5469
+ const point = change ? box : Object.assign({}, box), { x, y } = this.boxBounds;
5470
+ move$1(point, x, y);
5471
+ return point;
5472
+ }
5369
5473
  getInnerPointByLocal(local, _relative, distance, change) {
5370
5474
  return this.getInnerPoint(local, this.parent, distance, change);
5371
5475
  }
@@ -5377,20 +5481,23 @@ var LeaferUI = (function (exports) {
5377
5481
  getLocalPointByInner(inner, _relative, distance, change) {
5378
5482
  return this.getWorldPoint(inner, this.parent, distance, change);
5379
5483
  }
5484
+ getPagePoint(world, relative, distance, change) {
5485
+ const layer = this.leafer ? this.leafer.zoomLayer : this;
5486
+ return layer.getInnerPoint(world, relative, distance, change);
5487
+ }
5380
5488
  getWorldPoint(inner, relative, distance, change) {
5381
5489
  const point = change ? inner : {};
5382
5490
  this.innerToWorld(inner, point, distance, relative);
5383
5491
  return point;
5384
5492
  }
5493
+ getWorldPointByBox(box, relative, distance, change) {
5494
+ return this.getWorldPoint(this.getInnerPointByBox(box, null, null, change), relative, distance, true);
5495
+ }
5385
5496
  getWorldPointByLocal(local, relative, distance, change) {
5386
5497
  const point = change ? local : {};
5387
5498
  this.localToWorld(local, point, distance, relative);
5388
5499
  return point;
5389
5500
  }
5390
- getPagePoint(world, relative, distance, change) {
5391
- const layer = this.leafer ? this.leafer.zoomLayer : this;
5392
- return layer.getInnerPoint(world, relative, distance, change);
5393
- }
5394
5501
  getWorldPointByPage(page, relative, distance, change) {
5395
5502
  const layer = this.leafer ? this.leafer.zoomLayer : this;
5396
5503
  return layer.getWorldPoint(page, relative, distance, change);
@@ -5404,6 +5511,9 @@ var LeaferUI = (function (exports) {
5404
5511
  move(x, y) {
5405
5512
  moveLocal(this, x, y);
5406
5513
  }
5514
+ moveInner(x, y) {
5515
+ moveWorld(this, x, y, true);
5516
+ }
5407
5517
  scaleOf(origin, scaleX, scaleY, resize) {
5408
5518
  zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
5409
5519
  }
@@ -5456,6 +5566,17 @@ var LeaferUI = (function (exports) {
5456
5566
  __drawRenderPath(_canvas) { }
5457
5567
  __updatePath() { }
5458
5568
  __updateRenderPath() { }
5569
+ getMotionPathData() {
5570
+ return needPlugin('path');
5571
+ }
5572
+ getMotionPoint(_motionDistance) {
5573
+ return needPlugin('path');
5574
+ }
5575
+ getMotionTotal() {
5576
+ return 0;
5577
+ }
5578
+ __updateMotionPath() { }
5579
+ __runAnimation(_type, _complete) { }
5459
5580
  __updateSortChildren() { }
5460
5581
  add(_child, _index) { }
5461
5582
  remove(_child, destroy) {
@@ -5481,6 +5602,10 @@ var LeaferUI = (function (exports) {
5481
5602
  fn = boundsType;
5482
5603
  fn(defaultValue)(this.prototype, attrName);
5483
5604
  }
5605
+ __emitLifeEvent(type) {
5606
+ if (this.hasEvent(type))
5607
+ this.emitEvent(new ChildEvent(type, this, this.parent));
5608
+ }
5484
5609
  destroy() {
5485
5610
  if (!this.destroyed) {
5486
5611
  const { parent } = this;
@@ -5488,11 +5613,10 @@ var LeaferUI = (function (exports) {
5488
5613
  this.remove();
5489
5614
  if (this.children)
5490
5615
  this.removeAll(true);
5491
- if (this.hasEvent(ChildEvent.DESTROY))
5492
- this.emitEvent(new ChildEvent(ChildEvent.DESTROY, this, parent));
5616
+ this.__emitLifeEvent(ChildEvent.DESTROY);
5493
5617
  this.__.destroy();
5494
5618
  this.__layout.destroy();
5495
- this.__captureMap = this.__bubbleMap = this.__parentWait = this.__leaferWait = null;
5619
+ this.destroyEventer();
5496
5620
  this.destroyed = true;
5497
5621
  }
5498
5622
  }
@@ -5558,8 +5682,8 @@ var LeaferUI = (function (exports) {
5558
5682
  this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
5559
5683
  child.__layout.boxChanged || child.__layout.boxChange();
5560
5684
  child.__layout.matrixChanged || child.__layout.matrixChange();
5561
- if (child.__parentWait)
5562
- WaitHelper.run(child.__parentWait);
5685
+ if (child.__bubbleMap)
5686
+ child.__emitLifeEvent(ChildEvent.ADD);
5563
5687
  if (this.leafer) {
5564
5688
  child.__bindLeafer(this.leafer);
5565
5689
  if (this.leafer.created)
@@ -5572,16 +5696,10 @@ var LeaferUI = (function (exports) {
5572
5696
  }
5573
5697
  remove(child, destroy) {
5574
5698
  if (child) {
5575
- const index = this.children.indexOf(child);
5576
- if (index > -1) {
5577
- this.children.splice(index, 1);
5578
- if (child.isBranch)
5579
- this.__.__childBranchNumber = (this.__.__childBranchNumber || 1) - 1;
5580
- this.__preRemove();
5581
- this.__realRemoveChild(child);
5582
- if (destroy)
5583
- child.destroy();
5584
- }
5699
+ if (child.animationOut)
5700
+ child.__runAnimation('out', () => this.__remove(child, destroy));
5701
+ else
5702
+ this.__remove(child, destroy);
5585
5703
  }
5586
5704
  else if (child === undefined) {
5587
5705
  super.remove(null, destroy);
@@ -5603,6 +5721,18 @@ var LeaferUI = (function (exports) {
5603
5721
  clear() {
5604
5722
  this.removeAll(true);
5605
5723
  }
5724
+ __remove(child, destroy) {
5725
+ const index = this.children.indexOf(child);
5726
+ if (index > -1) {
5727
+ this.children.splice(index, 1);
5728
+ if (child.isBranch)
5729
+ this.__.__childBranchNumber = (this.__.__childBranchNumber || 1) - 1;
5730
+ this.__preRemove();
5731
+ this.__realRemoveChild(child);
5732
+ if (destroy)
5733
+ child.destroy();
5734
+ }
5735
+ }
5606
5736
  __preRemove() {
5607
5737
  if (this.__hasMask)
5608
5738
  this.__updateMask();
@@ -5612,6 +5742,7 @@ var LeaferUI = (function (exports) {
5612
5742
  this.__layout.affectChildrenSort && this.__layout.childrenSortChange();
5613
5743
  }
5614
5744
  __realRemoveChild(child) {
5745
+ child.__emitLifeEvent(ChildEvent.REMOVE);
5615
5746
  child.parent = null;
5616
5747
  if (this.leafer) {
5617
5748
  child.__bindLeafer(null);
@@ -5624,8 +5755,6 @@ var LeaferUI = (function (exports) {
5624
5755
  }
5625
5756
  __emitChildEvent(type, child) {
5626
5757
  const event = new ChildEvent(type, child, this);
5627
- if (child.hasEvent(type))
5628
- child.emitEvent(event);
5629
5758
  if (this.hasEvent(type) && !this.isLeafer)
5630
5759
  this.emitEvent(event);
5631
5760
  this.leafer.emitEvent(event);
@@ -5788,8 +5917,7 @@ var LeaferUI = (function (exports) {
5788
5917
  }
5789
5918
  }
5790
5919
 
5791
- const version = "1.0.1";
5792
- const inviteCode = {};
5920
+ const version = "1.0.3";
5793
5921
 
5794
5922
  class LeaferCanvas extends LeaferCanvasBase {
5795
5923
  get allowBackgroundColor() { return true; }
@@ -6016,9 +6144,13 @@ var LeaferUI = (function (exports) {
6016
6144
  });
6017
6145
  }
6018
6146
  function updateChange(updateList) {
6147
+ let layout;
6019
6148
  updateList.list.forEach(leaf => {
6020
- if (leaf.__layout.opacityChanged)
6149
+ layout = leaf.__layout;
6150
+ if (layout.opacityChanged)
6021
6151
  updateAllWorldOpacity(leaf);
6152
+ if (layout.stateStyleChanged)
6153
+ setTimeout(() => layout.stateStyleChanged && leaf.updateState());
6022
6154
  leaf.__updateChange();
6023
6155
  });
6024
6156
  }
@@ -6384,7 +6516,6 @@ var LeaferUI = (function (exports) {
6384
6516
  Platform.requestRender(() => {
6385
6517
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - startTime)));
6386
6518
  if (this.running) {
6387
- this.target.emit(AnimateEvent.FRAME);
6388
6519
  if (this.changed && this.canvas.view)
6389
6520
  this.render();
6390
6521
  this.target.emit(RenderEvent.NEXT);
@@ -6729,36 +6860,6 @@ var LeaferUI = (function (exports) {
6729
6860
  });
6730
6861
  Platform.layout = Layouter.fullLayout;
6731
6862
 
6732
- const TextConvert = {};
6733
- const ColorConvert = {};
6734
- const PathArrow = {};
6735
- const Paint = {};
6736
- const PaintImage = {};
6737
- const PaintGradient = {};
6738
- const Effect = {};
6739
- const Export = {};
6740
- const State = {};
6741
-
6742
- function stateType(defaultValue) {
6743
- return decorateLeafAttr(defaultValue, (key) => attr({
6744
- set(value) {
6745
- this.__setAttr(key, value);
6746
- this.waitLeafer(() => { if (State.setStyle)
6747
- State.setStyle(this, key + 'Style', value); });
6748
- }
6749
- }));
6750
- }
6751
- function arrowType(defaultValue) {
6752
- return decorateLeafAttr(defaultValue, (key) => attr({
6753
- set(value) {
6754
- if (this.__setAttr(key, value)) {
6755
- const data = this.__;
6756
- data.__useArrow = data.startArrow !== 'none' || data.endArrow !== 'none';
6757
- doStrokeType(this);
6758
- }
6759
- }
6760
- }));
6761
- }
6762
6863
  function effectType(defaultValue) {
6763
6864
  return decorateLeafAttr(defaultValue, (key) => attr({
6764
6865
  set(value) {
@@ -6793,10 +6894,33 @@ var LeaferUI = (function (exports) {
6793
6894
  };
6794
6895
  }
6795
6896
 
6897
+ const TextConvert = {};
6898
+ const ColorConvert = {};
6899
+ const PathArrow = {};
6900
+ const Paint = {};
6901
+ const PaintImage = {};
6902
+ const PaintGradient = {};
6903
+ const Effect = {};
6904
+ const Export = {};
6905
+ const State = {
6906
+ setStyleName(_leaf, _styleName, _value) { return needPlugin('state'); },
6907
+ set(_leaf, _stateName) { return needPlugin('state'); }
6908
+ };
6909
+ const Transition = {
6910
+ list: {},
6911
+ register(attrName, fn) {
6912
+ Transition.list[attrName] = fn;
6913
+ },
6914
+ get(attrName) {
6915
+ return Transition.list[attrName];
6916
+ }
6917
+ };
6918
+
6796
6919
  const { parse } = PathConvert;
6797
6920
  const emptyPaint = {};
6798
6921
  const debug$4 = Debug.get('UIData');
6799
6922
  class UIData extends LeafData {
6923
+ get scale() { const { scaleX, scaleY } = this; return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX; }
6800
6924
  get __strokeWidth() {
6801
6925
  const { strokeWidth, strokeWidthFixed } = this;
6802
6926
  if (strokeWidthFixed) {
@@ -6815,9 +6939,10 @@ var LeaferUI = (function (exports) {
6815
6939
  get __autoSide() { return !this._width || !this._height; }
6816
6940
  get __autoSize() { return !this._width && !this._height; }
6817
6941
  setVisible(value) {
6818
- if (this.__leaf.leafer)
6819
- this.__leaf.leafer.watcher.hasVisible = true;
6820
6942
  this._visible = value;
6943
+ const { leafer } = this.__leaf;
6944
+ if (leafer)
6945
+ leafer.watcher.hasVisible = true;
6821
6946
  }
6822
6947
  setWidth(value) {
6823
6948
  if (value < 0) {
@@ -6941,6 +7066,11 @@ var LeaferUI = (function (exports) {
6941
7066
  }
6942
7067
 
6943
7068
  class LeaferData extends GroupData {
7069
+ __getInputData() {
7070
+ const data = super.__getInputData();
7071
+ canvasSizeAttrs.forEach(key => delete data[key]);
7072
+ return data;
7073
+ }
6944
7074
  }
6945
7075
 
6946
7076
  class FrameData extends BoxData {
@@ -7003,7 +7133,7 @@ var LeaferUI = (function (exports) {
7003
7133
  __setImageFill(value) {
7004
7134
  if (this.__leaf.image)
7005
7135
  this.__leaf.image = null;
7006
- this.fill = value ? { type: 'image', mode: 'strench', url: value } : undefined;
7136
+ this.fill = value ? { type: 'image', mode: 'stretch', url: value } : undefined;
7007
7137
  }
7008
7138
  __getData() {
7009
7139
  const data = super.__getData();
@@ -7018,6 +7148,11 @@ var LeaferUI = (function (exports) {
7018
7148
  }
7019
7149
 
7020
7150
  class CanvasData extends RectData {
7151
+ __getInputData() {
7152
+ const data = super.__getInputData();
7153
+ data.url = this.__leaf.canvas.toDataURL('image/png');
7154
+ return data;
7155
+ }
7021
7156
  }
7022
7157
 
7023
7158
  const UIBounds = {
@@ -7188,19 +7323,8 @@ var LeaferUI = (function (exports) {
7188
7323
  exports.UI = UI_1 = class UI extends exports.Leaf {
7189
7324
  get app() { return this.leafer && this.leafer.app; }
7190
7325
  get isFrame() { return false; }
7191
- set scale(value) {
7192
- if (typeof value === 'number') {
7193
- this.scaleX = this.scaleY = value;
7194
- }
7195
- else {
7196
- this.scaleX = value.x;
7197
- this.scaleY = value.y;
7198
- }
7199
- }
7200
- get scale() {
7201
- const { scaleX, scaleY } = this;
7202
- return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX;
7203
- }
7326
+ set scale(value) { MathHelper.assignScale(this, value); }
7327
+ get scale() { return this.__.scale; }
7204
7328
  get pen() {
7205
7329
  const { path } = this.__;
7206
7330
  pen.set(this.path = path || []);
@@ -7215,8 +7339,15 @@ var LeaferUI = (function (exports) {
7215
7339
  super(data);
7216
7340
  }
7217
7341
  reset(_data) { }
7218
- set(data) {
7219
- Object.assign(this, data);
7342
+ set(data, isTemp) {
7343
+ if (isTemp) {
7344
+ this.lockNormalStyle = true;
7345
+ Object.assign(this, data);
7346
+ this.lockNormalStyle = false;
7347
+ }
7348
+ else {
7349
+ Object.assign(this, data);
7350
+ }
7220
7351
  }
7221
7352
  get(name) {
7222
7353
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
@@ -7279,11 +7410,18 @@ var LeaferUI = (function (exports) {
7279
7410
  drawer.rect(x, y, width, height);
7280
7411
  }
7281
7412
  }
7413
+ animate(_keyframe, _options, _type, _isTemp) {
7414
+ return needPlugin('animate');
7415
+ }
7416
+ killAnimate(_type) { }
7282
7417
  export(filename, options) {
7283
7418
  return Export.export(this, filename, options);
7284
7419
  }
7285
- clone() {
7286
- return UI_1.one(this.toJSON());
7420
+ clone(newData) {
7421
+ const json = this.toJSON();
7422
+ if (newData)
7423
+ Object.assign(json, newData);
7424
+ return UI_1.one(json);
7287
7425
  }
7288
7426
  static one(data, x, y, width, height) {
7289
7427
  return UICreator.get(data.tag || this.prototype.__tag, data, x, y, width, height);
@@ -7299,6 +7437,8 @@ var LeaferUI = (function (exports) {
7299
7437
  static setEditInner(_editorName) { }
7300
7438
  destroy() {
7301
7439
  this.fill = this.stroke = null;
7440
+ if (this.__animate)
7441
+ this.killAnimate();
7302
7442
  super.destroy();
7303
7443
  }
7304
7444
  };
@@ -7326,12 +7466,6 @@ var LeaferUI = (function (exports) {
7326
7466
  __decorate([
7327
7467
  visibleType(true)
7328
7468
  ], exports.UI.prototype, "visible", void 0);
7329
- __decorate([
7330
- stateType(false)
7331
- ], exports.UI.prototype, "selected", void 0);
7332
- __decorate([
7333
- stateType(false)
7334
- ], exports.UI.prototype, "disabled", void 0);
7335
7469
  __decorate([
7336
7470
  surfaceType(false)
7337
7471
  ], exports.UI.prototype, "locked", void 0);
@@ -7404,45 +7538,9 @@ var LeaferUI = (function (exports) {
7404
7538
  __decorate([
7405
7539
  pathType(true)
7406
7540
  ], exports.UI.prototype, "closed", void 0);
7407
- __decorate([
7408
- autoLayoutType(false)
7409
- ], exports.UI.prototype, "flow", void 0);
7410
7541
  __decorate([
7411
7542
  boundsType(0)
7412
7543
  ], exports.UI.prototype, "padding", void 0);
7413
- __decorate([
7414
- boundsType(0)
7415
- ], exports.UI.prototype, "gap", void 0);
7416
- __decorate([
7417
- boundsType('top-left')
7418
- ], exports.UI.prototype, "flowAlign", void 0);
7419
- __decorate([
7420
- boundsType(false)
7421
- ], exports.UI.prototype, "flowWrap", void 0);
7422
- __decorate([
7423
- boundsType('box')
7424
- ], exports.UI.prototype, "itemBox", void 0);
7425
- __decorate([
7426
- boundsType(true)
7427
- ], exports.UI.prototype, "inFlow", void 0);
7428
- __decorate([
7429
- boundsType()
7430
- ], exports.UI.prototype, "autoWidth", void 0);
7431
- __decorate([
7432
- boundsType()
7433
- ], exports.UI.prototype, "autoHeight", void 0);
7434
- __decorate([
7435
- boundsType()
7436
- ], exports.UI.prototype, "lockRatio", void 0);
7437
- __decorate([
7438
- boundsType()
7439
- ], exports.UI.prototype, "autoBox", void 0);
7440
- __decorate([
7441
- boundsType()
7442
- ], exports.UI.prototype, "widthRange", void 0);
7443
- __decorate([
7444
- boundsType()
7445
- ], exports.UI.prototype, "heightRange", void 0);
7446
7544
  __decorate([
7447
7545
  dataType(false)
7448
7546
  ], exports.UI.prototype, "draggable", void 0);
@@ -7506,12 +7604,6 @@ var LeaferUI = (function (exports) {
7506
7604
  __decorate([
7507
7605
  strokeType(10)
7508
7606
  ], exports.UI.prototype, "miterLimit", void 0);
7509
- __decorate([
7510
- arrowType('none')
7511
- ], exports.UI.prototype, "startArrow", void 0);
7512
- __decorate([
7513
- arrowType('none')
7514
- ], exports.UI.prototype, "endArrow", void 0);
7515
7607
  __decorate([
7516
7608
  pathType(0)
7517
7609
  ], exports.UI.prototype, "cornerRadius", void 0);
@@ -7533,24 +7625,6 @@ var LeaferUI = (function (exports) {
7533
7625
  __decorate([
7534
7626
  effectType()
7535
7627
  ], exports.UI.prototype, "grayscale", void 0);
7536
- __decorate([
7537
- dataType()
7538
- ], exports.UI.prototype, "normalStyle", void 0);
7539
- __decorate([
7540
- dataType()
7541
- ], exports.UI.prototype, "hoverStyle", void 0);
7542
- __decorate([
7543
- dataType()
7544
- ], exports.UI.prototype, "pressStyle", void 0);
7545
- __decorate([
7546
- dataType()
7547
- ], exports.UI.prototype, "focusStyle", void 0);
7548
- __decorate([
7549
- dataType()
7550
- ], exports.UI.prototype, "selectedStyle", void 0);
7551
- __decorate([
7552
- dataType()
7553
- ], exports.UI.prototype, "disabledStyle", void 0);
7554
7628
  __decorate([
7555
7629
  dataType({})
7556
7630
  ], exports.UI.prototype, "data", void 0);
@@ -7577,7 +7651,7 @@ var LeaferUI = (function (exports) {
7577
7651
  if (!this.children)
7578
7652
  this.children = [];
7579
7653
  }
7580
- set(data) {
7654
+ set(data, isTemp) {
7581
7655
  if (data.children) {
7582
7656
  const { children } = data;
7583
7657
  delete data.children;
@@ -7587,7 +7661,7 @@ var LeaferUI = (function (exports) {
7587
7661
  else {
7588
7662
  this.clear();
7589
7663
  }
7590
- super.set(data);
7664
+ super.set(data, isTemp);
7591
7665
  let child;
7592
7666
  children.forEach(childData => {
7593
7667
  child = childData.__ ? childData : UICreator.get(childData.tag, childData);
@@ -7596,7 +7670,7 @@ var LeaferUI = (function (exports) {
7596
7670
  data.children = children;
7597
7671
  }
7598
7672
  else {
7599
- super.set(data);
7673
+ super.set(data, isTemp);
7600
7674
  }
7601
7675
  }
7602
7676
  toJSON(options) {
@@ -7923,13 +7997,20 @@ var LeaferUI = (function (exports) {
7923
7997
  }
7924
7998
  }
7925
7999
  zoom(_zoomType, _padding, _fixedScale) {
7926
- return debug$3.error('need @leafer-in/view');
8000
+ return needPlugin('view');
7927
8001
  }
7928
8002
  getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
7929
8003
  getValidScale(changeScale) { return changeScale; }
7930
8004
  getWorldPointByClient(clientPoint, updateClient) {
7931
8005
  return this.interaction && this.interaction.getLocal(clientPoint, updateClient);
7932
8006
  }
8007
+ getPagePointByClient(clientPoint, updateClient) {
8008
+ return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8009
+ }
8010
+ updateClientBounds() {
8011
+ this.canvas && this.canvas.updateClientBounds();
8012
+ }
8013
+ receiveEvent(_event) { }
7933
8014
  __checkUpdateLayout() {
7934
8015
  this.__layout.update();
7935
8016
  }
@@ -8013,7 +8094,7 @@ var LeaferUI = (function (exports) {
8013
8094
  const rect$1 = exports.Rect.prototype;
8014
8095
  const group$1 = exports.Group.prototype;
8015
8096
  const childrenRenderBounds = {};
8016
- const { copy: copy$3, add, includes: includes$1 } = BoundsHelper;
8097
+ const { copy: copy$3, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
8017
8098
  exports.Box = class Box extends exports.Group {
8018
8099
  get __tag() { return 'Box'; }
8019
8100
  get isBranchLeaf() { return true; }
@@ -8027,20 +8108,23 @@ var LeaferUI = (function (exports) {
8027
8108
  return this.__updateRectRenderSpread() || -1;
8028
8109
  }
8029
8110
  __updateRectBoxBounds() { }
8030
- __updateBoxBounds() {
8111
+ __updateBoxBounds(secondLayout) {
8031
8112
  const data = this.__;
8032
8113
  if (this.children.length) {
8033
8114
  if (data.__autoSide) {
8034
8115
  if (this.leafer && this.leafer.ready)
8035
8116
  this.leafer.layouter.addExtra(this);
8036
8117
  super.__updateBoxBounds();
8118
+ const { boxBounds } = this.__layout;
8037
8119
  if (!data.__autoSize) {
8038
- const b = this.__layout.boxBounds;
8039
- if (!data.__autoWidth)
8040
- b.height += b.y, b.width = data.width, b.x = b.y = 0;
8041
- if (!data.__autoHeight)
8042
- b.width += b.x, b.height = data.height, b.y = b.x = 0;
8120
+ if (data.__autoWidth)
8121
+ boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
8122
+ else
8123
+ boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
8043
8124
  }
8125
+ if (secondLayout && data.flow && data.padding)
8126
+ copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
8127
+ this.__updateNaturalSize();
8044
8128
  }
8045
8129
  else {
8046
8130
  this.__updateRectBoxBounds();
@@ -8060,13 +8144,13 @@ var LeaferUI = (function (exports) {
8060
8144
  super.__updateRenderBounds();
8061
8145
  copy$3(childrenRenderBounds, renderBounds);
8062
8146
  this.__updateRectRenderBounds();
8063
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
8147
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
8064
8148
  }
8065
8149
  else {
8066
8150
  this.__updateRectRenderBounds();
8067
8151
  }
8068
8152
  this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8069
- if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide'))
8153
+ if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
8070
8154
  add(renderBounds, childrenRenderBounds);
8071
8155
  }
8072
8156
  __updateRectRenderBounds() { }
@@ -8400,14 +8484,26 @@ var LeaferUI = (function (exports) {
8400
8484
  exports.Image = __decorate([
8401
8485
  registerUI()
8402
8486
  ], exports.Image);
8487
+ const MyImage = exports.Image;
8403
8488
 
8404
8489
  exports.Canvas = class Canvas extends exports.Rect {
8405
8490
  get __tag() { return 'Canvas'; }
8491
+ get ready() { return !this.url; }
8406
8492
  constructor(data) {
8407
8493
  super(data);
8408
8494
  this.canvas = Creator.canvas(this.__);
8409
8495
  this.context = this.canvas.context;
8410
8496
  this.__.__isCanvas = this.__.__drawAfterFill = true;
8497
+ if (data && data.url)
8498
+ this.drawImage(data.url);
8499
+ }
8500
+ drawImage(url) {
8501
+ new LeaferImage({ url }).load((image) => {
8502
+ this.context.drawImage(image.view, 0, 0);
8503
+ this.url = undefined;
8504
+ this.paint();
8505
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
8506
+ });
8411
8507
  }
8412
8508
  draw(ui, offset, scale, rotation) {
8413
8509
  ui.__layout.update();
@@ -8424,19 +8520,18 @@ var LeaferUI = (function (exports) {
8424
8520
  this.paint();
8425
8521
  }
8426
8522
  paint() {
8427
- this.forceUpdate('fill');
8523
+ this.forceRender();
8428
8524
  }
8429
8525
  __drawAfterFill(canvas, _options) {
8430
- const origin = this.canvas.view;
8431
- const { width, height } = this;
8432
- if (this.__.cornerRadius || this.pathInputed) {
8526
+ const { width, height, cornerRadius } = this.__, { view } = this.canvas;
8527
+ if (cornerRadius || this.pathInputed) {
8433
8528
  canvas.save();
8434
8529
  canvas.clip();
8435
- canvas.drawImage(this.canvas.view, 0, 0, origin.width, origin.height, 0, 0, width, height);
8530
+ canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8436
8531
  canvas.restore();
8437
8532
  }
8438
8533
  else {
8439
- canvas.drawImage(this.canvas.view, 0, 0, origin.width, origin.height, 0, 0, width, height);
8534
+ canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8440
8535
  }
8441
8536
  }
8442
8537
  __updateSize() {
@@ -8466,7 +8561,7 @@ var LeaferUI = (function (exports) {
8466
8561
  resizeType(100)
8467
8562
  ], exports.Canvas.prototype, "height", void 0);
8468
8563
  __decorate([
8469
- resizeType(Platform.devicePixelRatio)
8564
+ resizeType(1)
8470
8565
  ], exports.Canvas.prototype, "pixelRatio", void 0);
8471
8566
  __decorate([
8472
8567
  resizeType(true)
@@ -8490,13 +8585,13 @@ var LeaferUI = (function (exports) {
8490
8585
  super(data);
8491
8586
  }
8492
8587
  __drawHitPath(canvas) {
8493
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
8588
+ const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8494
8589
  canvas.beginPath();
8495
8590
  if (this.__.__letterSpacing < 0) {
8496
8591
  this.__drawPathByData(canvas);
8497
8592
  }
8498
8593
  else {
8499
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
8594
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8500
8595
  }
8501
8596
  }
8502
8597
  __drawPathByData(drawer, _data) {
@@ -8689,7 +8784,8 @@ var LeaferUI = (function (exports) {
8689
8784
  drawPoints(_points, _curve, _close) { return this; }
8690
8785
  clearPath() { return this; }
8691
8786
  paint() {
8692
- this.pathElement.forceUpdate('path');
8787
+ if (!this.pathElement.__layout.boxChanged)
8788
+ this.pathElement.forceUpdate('path');
8693
8789
  }
8694
8790
  };
8695
8791
  __decorate([
@@ -8699,7 +8795,7 @@ var LeaferUI = (function (exports) {
8699
8795
  penPathType()
8700
8796
  ], exports.Pen.prototype, "path", void 0);
8701
8797
  exports.Pen = __decorate([
8702
- useModule(PathCreator, ['set', 'beginPath', 'path']),
8798
+ useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8703
8799
  registerUI()
8704
8800
  ], exports.Pen);
8705
8801
  function penPathType() {
@@ -8878,21 +8974,29 @@ var LeaferUI = (function (exports) {
8878
8974
  constructor(params) {
8879
8975
  super(params.type);
8880
8976
  this.bubbles = true;
8977
+ this.getInner = this.getInnerPoint;
8978
+ this.getLocal = this.getLocalPoint;
8979
+ this.getPage = this.getPagePoint;
8881
8980
  Object.assign(this, params);
8882
8981
  }
8883
- getPage() {
8884
- return this.current.getPagePoint(this);
8982
+ getBoxPoint(relative) {
8983
+ if (!relative)
8984
+ relative = this.current;
8985
+ return relative.getBoxPoint(this);
8885
8986
  }
8886
- getInner(relative) {
8987
+ getInnerPoint(relative) {
8887
8988
  if (!relative)
8888
8989
  relative = this.current;
8889
8990
  return relative.getInnerPoint(this);
8890
8991
  }
8891
- getLocal(relative) {
8992
+ getLocalPoint(relative) {
8892
8993
  if (!relative)
8893
8994
  relative = this.current;
8894
8995
  return relative.getLocalPoint(this);
8895
8996
  }
8997
+ getPagePoint() {
8998
+ return this.current.getPagePoint(this);
8999
+ }
8896
9000
  static changeName(oldName, newName) {
8897
9001
  EventCreator.changeName(oldName, newName);
8898
9002
  }
@@ -8922,6 +9026,7 @@ var LeaferUI = (function (exports) {
8922
9026
  exports.PointerEvent = __decorate([
8923
9027
  registerUIEvent()
8924
9028
  ], exports.PointerEvent);
9029
+ const MyPointerEvent = exports.PointerEvent;
8925
9030
 
8926
9031
  const move = {};
8927
9032
  exports.DragEvent = class DragEvent extends exports.PointerEvent {
@@ -8999,7 +9104,7 @@ var LeaferUI = (function (exports) {
8999
9104
  }
9000
9105
  getPageBounds() {
9001
9106
  const total = this.getPageTotal();
9002
- const start = this.getPage();
9107
+ const start = this.getPagePoint();
9003
9108
  const bounds = {};
9004
9109
  BoundsHelper.set(bounds, start.x - total.x, start.y - total.y, total.x, total.y);
9005
9110
  BoundsHelper.unsign(bounds);
@@ -9021,6 +9126,7 @@ var LeaferUI = (function (exports) {
9021
9126
  exports.DragEvent = __decorate([
9022
9127
  registerUIEvent()
9023
9128
  ], exports.DragEvent);
9129
+ const MyDragEvent = exports.DragEvent;
9024
9130
 
9025
9131
  exports.DropEvent = class DropEvent extends exports.PointerEvent {
9026
9132
  static setList(data) {
@@ -9102,36 +9208,32 @@ var LeaferUI = (function (exports) {
9102
9208
 
9103
9209
  function document(leafer) {
9104
9210
  addInteractionWindow(leafer);
9105
- leafer.config.move.scroll = 'limit';
9106
- leafer.config.zoom.min = 1;
9211
+ const { move, zoom } = leafer.config;
9212
+ move.scroll = 'limit';
9213
+ zoom.min = 1;
9214
+ }
9215
+
9216
+ function block(leafer) {
9217
+ const { config } = leafer;
9218
+ (config.wheel || (config.wheel = {})).preventDefault = false;
9219
+ (config.touch || (config.touch = {})).preventDefault = 'auto';
9107
9220
  }
9108
9221
 
9109
9222
  const debug$2 = Debug.get('LeaferTypeCreator');
9110
9223
  const LeaferTypeCreator = {
9111
9224
  list: {},
9112
9225
  register(name, fn) {
9113
- if (list[name]) {
9114
- debug$2.repeat(name);
9115
- }
9116
- else {
9117
- list[name] = fn;
9118
- }
9226
+ list[name] ? debug$2.repeat(name) : list[name] = fn;
9119
9227
  },
9120
9228
  run(name, leafer) {
9121
9229
  const fn = list[name];
9122
- if (fn) {
9123
- fn(leafer);
9124
- }
9125
- else {
9126
- debug$2.error('no', name);
9127
- }
9230
+ fn && fn(leafer);
9128
9231
  }
9129
9232
  };
9130
9233
  const { list, register } = LeaferTypeCreator;
9131
- register('draw', () => { });
9132
- register('custom', () => { });
9133
9234
  register('design', addInteractionWindow);
9134
9235
  register('document', document);
9236
+ register('block', block);
9135
9237
 
9136
9238
  const leafer = exports.Leafer.prototype;
9137
9239
  leafer.initType = function (type) {
@@ -9320,7 +9422,13 @@ var LeaferUI = (function (exports) {
9320
9422
  find.add(list[i]);
9321
9423
  }
9322
9424
  return find;
9323
- }
9425
+ },
9426
+ pathCanDrag(path) {
9427
+ return path && path.list.some(item => item.draggable || item.editable || (!item.isLeafer && item.hasEvent(exports.DragEvent.DRAG)));
9428
+ },
9429
+ pathHasOutside(path) {
9430
+ return path && path.list.some(item => item.isOutside);
9431
+ },
9324
9432
  };
9325
9433
  const I = InteractionHelper;
9326
9434
 
@@ -9580,7 +9688,7 @@ var LeaferUI = (function (exports) {
9580
9688
  if (leaf.destroyed)
9581
9689
  return false;
9582
9690
  if (leaf.__.hitSelf && !exclude(leaf, excludePath)) {
9583
- if (State.updateEventStyle)
9691
+ if (State.updateEventStyle && !capture)
9584
9692
  State.updateEventStyle(leaf, type);
9585
9693
  if (leaf.hasEvent(type, capture)) {
9586
9694
  data.phase = capture ? 1 : ((leaf === data.target) ? 2 : 3);
@@ -9630,15 +9738,18 @@ var LeaferUI = (function (exports) {
9630
9738
  swipeDistance: 20,
9631
9739
  preventDefaultMenu: true
9632
9740
  },
9741
+ touch: {
9742
+ preventDefault: true
9743
+ },
9633
9744
  cursor: true,
9634
9745
  keyEvent: true
9635
9746
  };
9636
9747
 
9637
- const { pathHasEventType, getMoveEventData, getZoomEventData, getRotateEventData } = InteractionHelper;
9748
+ const { pathHasEventType, getMoveEventData, getZoomEventData, getRotateEventData, pathCanDrag, pathHasOutside } = InteractionHelper;
9638
9749
  class InteractionBase {
9639
9750
  get dragging() { return this.dragger.dragging; }
9640
9751
  get transforming() { return this.transformer.transforming; }
9641
- get moveMode() { return this.config.move.drag || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty; }
9752
+ get moveMode() { return this.config.move.drag === true || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty; }
9642
9753
  get canHover() { return this.config.pointer.hover && !this.config.mobile; }
9643
9754
  get isDragEmpty() { return this.config.move.dragEmpty && this.isRootPath(this.hoverData) && (!this.downData || this.isRootPath(this.downData)); }
9644
9755
  get isMobileDragEmpty() { return this.config.move.dragEmpty && !this.canHover && this.downData && this.isTreePath(this.downData); }
@@ -9647,7 +9758,7 @@ var LeaferUI = (function (exports) {
9647
9758
  get isHoldSpaceKey() { return this.config.move.holdSpaceKey && Keyboard.isHoldSpaceKey(); }
9648
9759
  get hitRadius() { return this.config.pointer.hitRadius; }
9649
9760
  constructor(target, canvas, selector, userConfig) {
9650
- this.config = config;
9761
+ this.config = DataHelper.clone(config);
9651
9762
  this.tapCount = 0;
9652
9763
  this.downKeyMap = {};
9653
9764
  this.target = target;
@@ -9682,7 +9793,7 @@ var LeaferUI = (function (exports) {
9682
9793
  this.tapWait();
9683
9794
  this.longPressWait(data);
9684
9795
  }
9685
- this.waitMenuTap = PointerButton.right(data);
9796
+ this.waitRightTap = PointerButton.right(data);
9686
9797
  this.dragger.setDragData(data);
9687
9798
  if (!this.isHoldRightKey)
9688
9799
  this.updateCursor(data);
@@ -9710,7 +9821,7 @@ var LeaferUI = (function (exports) {
9710
9821
  if (canDrag) {
9711
9822
  if (this.waitTap)
9712
9823
  this.pointerWaitCancel();
9713
- this.waitMenuTap = false;
9824
+ this.waitRightTap = false;
9714
9825
  }
9715
9826
  this.dragger.checkDrag(data, canDrag);
9716
9827
  }
@@ -9764,10 +9875,15 @@ var LeaferUI = (function (exports) {
9764
9875
  menu(data) {
9765
9876
  this.findPath(data);
9766
9877
  this.emit(exports.PointerEvent.MENU, data);
9878
+ this.waitMenuTap = true;
9879
+ if (!this.downData && this.waitRightTap)
9880
+ this.menuTap(data);
9767
9881
  }
9768
9882
  menuTap(data) {
9769
- if (this.waitMenuTap)
9883
+ if (this.waitRightTap && this.waitMenuTap) {
9770
9884
  this.emit(exports.PointerEvent.MENU_TAP, data);
9885
+ this.waitRightTap = this.waitMenuTap = false;
9886
+ }
9771
9887
  }
9772
9888
  move(data) {
9773
9889
  this.transformer.move(data);
@@ -9899,11 +10015,11 @@ var LeaferUI = (function (exports) {
9899
10015
  return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree) && !data.target.syncEventer);
9900
10016
  }
9901
10017
  checkPath(data, useDefaultPath) {
9902
- if (useDefaultPath || this.canMove(data))
10018
+ if (useDefaultPath || (this.moveMode && !pathHasOutside(data.path)))
9903
10019
  data.path = this.defaultPath;
9904
10020
  }
9905
10021
  canMove(data) {
9906
- return this.moveMode && data && data.path.list.every(item => !item.isOutside);
10022
+ return data && (this.moveMode || (this.config.move.drag === 'auto' && !pathCanDrag(data.path))) && !pathHasOutside(data.path);
9907
10023
  }
9908
10024
  isDrag(leaf) {
9909
10025
  return this.dragger.getList().has(leaf);
@@ -10598,16 +10714,21 @@ var LeaferUI = (function (exports) {
10598
10714
  const { get: get$2, translate } = MatrixHelper;
10599
10715
  const tempBox = new Bounds();
10600
10716
  const tempPoint = {};
10717
+ const tempScaleData = {};
10601
10718
  function createData(leafPaint, image, paint, box) {
10602
- const { blendMode } = paint;
10719
+ const { blendMode, sync } = paint;
10603
10720
  if (blendMode)
10604
10721
  leafPaint.blendMode = blendMode;
10722
+ if (sync)
10723
+ leafPaint.sync = sync;
10605
10724
  leafPaint.data = getPatternData(paint, box, image);
10606
10725
  }
10607
10726
  function getPatternData(paint, box, image) {
10608
10727
  let { width, height } = image;
10609
10728
  if (paint.padding)
10610
10729
  box = tempBox.set(box).shrink(paint.padding);
10730
+ if (paint.mode === 'strench')
10731
+ paint.mode = 'stretch';
10611
10732
  const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
10612
10733
  const sameBox = box.width === width && box.height === height;
10613
10734
  const data = { mode };
@@ -10621,13 +10742,10 @@ var LeaferUI = (function (exports) {
10621
10742
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
10622
10743
  }
10623
10744
  }
10624
- else if (size) {
10625
- scaleX = (typeof size === 'number' ? size : size.width) / width;
10626
- scaleY = (typeof size === 'number' ? size : size.height) / height;
10627
- }
10628
- else if (scale) {
10629
- scaleX = typeof scale === 'number' ? scale : scale.x;
10630
- scaleY = typeof scale === 'number' ? scale : scale.y;
10745
+ else if (scale || size) {
10746
+ MathHelper.getScaleData(scale, size, image, tempScaleData);
10747
+ scaleX = tempScaleData.scaleX;
10748
+ scaleY = tempScaleData.scaleY;
10631
10749
  }
10632
10750
  if (align) {
10633
10751
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -10639,7 +10757,7 @@ var LeaferUI = (function (exports) {
10639
10757
  if (offset)
10640
10758
  x += offset.x, y += offset.y;
10641
10759
  switch (mode) {
10642
- case 'strench':
10760
+ case 'stretch':
10643
10761
  if (!sameBox)
10644
10762
  width = box.width, height = box.height;
10645
10763
  break;
@@ -10666,7 +10784,7 @@ var LeaferUI = (function (exports) {
10666
10784
  translate(data.transform, box.x, box.y);
10667
10785
  }
10668
10786
  }
10669
- if (scaleX && mode !== 'strench') {
10787
+ if (scaleX && mode !== 'stretch') {
10670
10788
  data.scaleX = scaleX;
10671
10789
  data.scaleY = scaleY;
10672
10790
  }
@@ -10770,7 +10888,7 @@ var LeaferUI = (function (exports) {
10770
10888
  const { ceil, abs: abs$1 } = Math;
10771
10889
  function createPattern(ui, paint, pixelRatio) {
10772
10890
  let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
10773
- const id = scaleX + '-' + scaleY;
10891
+ const id = scaleX + '-' + scaleY + '-' + pixelRatio;
10774
10892
  if (paint.patternId !== id && !ui.destroyed) {
10775
10893
  scaleX = abs$1(scaleX);
10776
10894
  scaleY = abs$1(scaleY);
@@ -10832,7 +10950,8 @@ var LeaferUI = (function (exports) {
10832
10950
  const { abs } = Math;
10833
10951
  function checkImage(ui, canvas, paint, allowPaint) {
10834
10952
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
10835
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY && !Export.running)) {
10953
+ const { pixelRatio } = canvas;
10954
+ if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
10836
10955
  return false;
10837
10956
  }
10838
10957
  else {
@@ -10840,8 +10959,8 @@ var LeaferUI = (function (exports) {
10840
10959
  if (allowPaint) {
10841
10960
  if (!data.repeat) {
10842
10961
  let { width, height } = data;
10843
- width *= abs(scaleX) * canvas.pixelRatio;
10844
- height *= abs(scaleY) * canvas.pixelRatio;
10962
+ width *= abs(scaleX) * pixelRatio;
10963
+ height *= abs(scaleY) * pixelRatio;
10845
10964
  if (data.scaleX) {
10846
10965
  width *= data.scaleX;
10847
10966
  height *= data.scaleY;
@@ -10866,15 +10985,15 @@ var LeaferUI = (function (exports) {
10866
10985
  return true;
10867
10986
  }
10868
10987
  else {
10869
- if (!paint.style || Export.running) {
10870
- createPattern(ui, paint, canvas.pixelRatio);
10988
+ if (!paint.style || paint.sync || Export.running) {
10989
+ createPattern(ui, paint, pixelRatio);
10871
10990
  }
10872
10991
  else {
10873
10992
  if (!paint.patternTask) {
10874
10993
  paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
10875
10994
  paint.patternTask = null;
10876
10995
  if (canvas.bounds.hit(ui.__nowWorld))
10877
- createPattern(ui, paint, canvas.pixelRatio);
10996
+ createPattern(ui, paint, pixelRatio);
10878
10997
  ui.forceUpdate('surface');
10879
10998
  }), 300);
10880
10999
  }
@@ -10938,14 +11057,16 @@ var LeaferUI = (function (exports) {
10938
11057
  return data;
10939
11058
  }
10940
11059
  function applyStops(gradient, stops, opacity) {
10941
- let stop;
10942
- for (let i = 0, len = stops.length; i < len; i++) {
10943
- stop = stops[i];
10944
- if (typeof stop === 'string') {
10945
- gradient.addColorStop(i / (len - 1), ColorConvert.string(stop, opacity));
10946
- }
10947
- else {
10948
- gradient.addColorStop(stop.offset, ColorConvert.string(stop.color, opacity));
11060
+ if (stops) {
11061
+ let stop;
11062
+ for (let i = 0, len = stops.length; i < len; i++) {
11063
+ stop = stops[i];
11064
+ if (typeof stop === 'string') {
11065
+ gradient.addColorStop(i / (len - 1), ColorConvert.string(stop, opacity));
11066
+ }
11067
+ else {
11068
+ gradient.addColorStop(stop.offset, ColorConvert.string(stop.color, opacity));
11069
+ }
10949
11070
  }
10950
11071
  }
10951
11072
  }
@@ -11701,10 +11822,15 @@ var LeaferUI = (function (exports) {
11701
11822
  };
11702
11823
 
11703
11824
  function string(color, opacity) {
11704
- if (typeof color === 'string')
11705
- return color;
11825
+ const doOpacity = typeof opacity === 'number' && opacity !== 1;
11826
+ if (typeof color === 'string') {
11827
+ if (doOpacity && ColorConvert.object)
11828
+ color = ColorConvert.object(color);
11829
+ else
11830
+ return color;
11831
+ }
11706
11832
  let a = color.a === undefined ? 1 : color.a;
11707
- if (opacity)
11833
+ if (doOpacity)
11708
11834
  a *= opacity;
11709
11835
  const rgb = color.r + ',' + color.g + ',' + color.b;
11710
11836
  return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
@@ -11736,6 +11862,7 @@ var LeaferUI = (function (exports) {
11736
11862
  export(leaf, filename, options) {
11737
11863
  this.running = true;
11738
11864
  const fileType = FileHelper.fileType(filename);
11865
+ const isDownload = filename.includes('.');
11739
11866
  options = FileHelper.getExportOptions(options);
11740
11867
  return addTask((success) => new Promise((resolve) => {
11741
11868
  const over = (result) => {
@@ -11745,19 +11872,13 @@ var LeaferUI = (function (exports) {
11745
11872
  };
11746
11873
  const { toURL } = Platform;
11747
11874
  const { download } = Platform.origin;
11748
- if (filename === 'json') {
11749
- return over({ data: leaf.toJSON(options.json) });
11750
- }
11751
- else if (fileType === 'json') {
11752
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
11753
- return over({ data: true });
11875
+ if (fileType === 'json') {
11876
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
11877
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
11754
11878
  }
11755
- if (filename === 'svg') {
11756
- return over({ data: leaf.toSVG() });
11757
- }
11758
- else if (fileType === 'svg') {
11759
- download(toURL(leaf.toSVG(), 'svg'), filename);
11760
- return over({ data: true });
11879
+ if (fileType === 'svg') {
11880
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
11881
+ return over({ data: isDownload ? true : leaf.toSVG() });
11761
11882
  }
11762
11883
  const { leafer } = leaf;
11763
11884
  if (leafer) {
@@ -11766,14 +11887,8 @@ var LeaferUI = (function (exports) {
11766
11887
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
11767
11888
  const { worldTransform, isLeafer, isFrame } = leaf;
11768
11889
  const { slice, trim, onCanvas } = options;
11769
- let scale = options.scale || 1;
11770
- let pixelRatio = options.pixelRatio || 1;
11771
11890
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
11772
11891
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
11773
- if (leaf.isApp) {
11774
- scale *= pixelRatio;
11775
- pixelRatio = leaf.app.pixelRatio;
11776
- }
11777
11892
  const screenshot = options.screenshot || leaf.isApp;
11778
11893
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
11779
11894
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -11807,9 +11922,17 @@ var LeaferUI = (function (exports) {
11807
11922
  }
11808
11923
  renderBounds = leaf.getBounds('render', relative);
11809
11924
  }
11810
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
11925
+ const scaleData = { scaleX: 1, scaleY: 1 };
11926
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
11927
+ let pixelRatio = options.pixelRatio || 1;
11928
+ if (leaf.isApp) {
11929
+ scaleData.scaleX *= pixelRatio;
11930
+ scaleData.scaleY *= pixelRatio;
11931
+ pixelRatio = leaf.app.pixelRatio;
11932
+ }
11933
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
11934
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
11811
11935
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
11812
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
11813
11936
  let sliceLeaf;
11814
11937
  if (slice) {
11815
11938
  sliceLeaf = leaf;
@@ -11920,7 +12043,6 @@ var LeaferUI = (function (exports) {
11920
12043
  useCanvas();
11921
12044
 
11922
12045
  exports.AlignHelper = AlignHelper;
11923
- exports.AnimateEvent = AnimateEvent;
11924
12046
  exports.AroundHelper = AroundHelper;
11925
12047
  exports.AutoBounds = AutoBounds;
11926
12048
  exports.BezierHelper = BezierHelper;
@@ -11942,6 +12064,7 @@ var LeaferUI = (function (exports) {
11942
12064
  exports.EllipseHelper = EllipseHelper;
11943
12065
  exports.Event = Event;
11944
12066
  exports.EventCreator = EventCreator;
12067
+ exports.Eventer = Eventer;
11945
12068
  exports.Export = Export;
11946
12069
  exports.FileHelper = FileHelper;
11947
12070
  exports.FrameData = FrameData;
@@ -11978,6 +12101,9 @@ var LeaferUI = (function (exports) {
11978
12101
  exports.Matrix = Matrix;
11979
12102
  exports.MatrixHelper = MatrixHelper;
11980
12103
  exports.MultiTouchHelper = MultiTouchHelper;
12104
+ exports.MyDragEvent = MyDragEvent;
12105
+ exports.MyImage = MyImage;
12106
+ exports.MyPointerEvent = MyPointerEvent;
11981
12107
  exports.NeedConvertToCanvasCommandMap = NeedConvertToCanvasCommandMap;
11982
12108
  exports.OneRadian = OneRadian;
11983
12109
  exports.PI2 = PI2;
@@ -12019,6 +12145,7 @@ var LeaferUI = (function (exports) {
12019
12145
  exports.TaskProcessor = TaskProcessor;
12020
12146
  exports.TextConvert = TextConvert;
12021
12147
  exports.TextData = TextData;
12148
+ exports.Transition = Transition;
12022
12149
  exports.TwoPointBoundsHelper = TwoPointBoundsHelper;
12023
12150
  exports.UIBounds = UIBounds;
12024
12151
  exports.UICreator = UICreator;
@@ -12032,7 +12159,6 @@ var LeaferUI = (function (exports) {
12032
12159
  exports.addInteractionWindow = addInteractionWindow;
12033
12160
  exports.affectRenderBoundsType = affectRenderBoundsType;
12034
12161
  exports.affectStrokeBoundsType = affectStrokeBoundsType;
12035
- exports.arrowType = arrowType;
12036
12162
  exports.attr = attr;
12037
12163
  exports.autoLayoutType = autoLayoutType;
12038
12164
  exports.boundsType = boundsType;
@@ -12055,10 +12181,11 @@ var LeaferUI = (function (exports) {
12055
12181
  exports.getMatrixData = getMatrixData;
12056
12182
  exports.getPointData = getPointData;
12057
12183
  exports.hitType = hitType;
12058
- exports.inviteCode = inviteCode;
12184
+ exports.isNull = isNull;
12059
12185
  exports.layoutProcessor = layoutProcessor;
12060
12186
  exports.maskType = maskType;
12061
12187
  exports.naturalBoundsType = naturalBoundsType;
12188
+ exports.needPlugin = needPlugin;
12062
12189
  exports.opacityType = opacityType;
12063
12190
  exports.pathInputType = pathInputType;
12064
12191
  exports.pathType = pathType;
@@ -12072,7 +12199,6 @@ var LeaferUI = (function (exports) {
12072
12199
  exports.rotationType = rotationType;
12073
12200
  exports.scaleType = scaleType;
12074
12201
  exports.sortType = sortType;
12075
- exports.stateType = stateType;
12076
12202
  exports.strokeType = strokeType;
12077
12203
  exports.surfaceType = surfaceType;
12078
12204
  exports.tempBounds = tempBounds$1;