leafer-ui 1.0.0-rc.25 → 1.0.0-rc.27

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.
@@ -1,4 +1,12 @@
1
1
  const Platform = {
2
+ toURL(text, fileType) {
3
+ let url = encodeURIComponent(text);
4
+ if (fileType === 'text')
5
+ url = 'data:text/plain;charset=utf-8,' + url;
6
+ else if (fileType === 'svg')
7
+ url = 'data:image/svg+xml,' + url;
8
+ return url;
9
+ },
2
10
  image: {
3
11
  hitCanvasSize: 100,
4
12
  maxCacheSize: 2560 * 1600,
@@ -956,6 +964,9 @@ const BoundsHelper = {
956
964
  points.forEach((point, index) => index === 0 ? setPoint$3(tempPointBounds$1, point.x, point.y) : addPoint$3(tempPointBounds$1, point.x, point.y));
957
965
  toBounds$4(tempPointBounds$1, t);
958
966
  },
967
+ setPoint(t, point) {
968
+ B.set(t, point.x, point.y);
969
+ },
959
970
  addPoint(t, point) {
960
971
  add$1(t, point, true);
961
972
  },
@@ -1104,6 +1115,10 @@ class Bounds {
1104
1115
  BoundsHelper.setListWithFn(this, list, boundsDataFn);
1105
1116
  return this;
1106
1117
  }
1118
+ setPoint(point) {
1119
+ BoundsHelper.setPoint(this, point);
1120
+ return this;
1121
+ }
1107
1122
  setPoints(points) {
1108
1123
  BoundsHelper.setPoints(this, points);
1109
1124
  return this;
@@ -1207,10 +1222,10 @@ directionData.forEach(item => item.type = 'percent');
1207
1222
  const AroundHelper = {
1208
1223
  directionData,
1209
1224
  tempPoint: {},
1210
- get: get$5,
1225
+ get: get$4,
1211
1226
  toPoint(around, bounds, to, onlySize, pointBounds) {
1212
1227
  to || (to = {});
1213
- const point = get$5(around);
1228
+ const point = get$4(around);
1214
1229
  to.x = point.x;
1215
1230
  to.y = point.y;
1216
1231
  if (point.type === 'percent') {
@@ -1231,7 +1246,7 @@ const AroundHelper = {
1231
1246
  }
1232
1247
  }
1233
1248
  };
1234
- function get$5(around) {
1249
+ function get$4(around) {
1235
1250
  return typeof around === 'string' ? directionData[Direction9[around]] : around;
1236
1251
  }
1237
1252
 
@@ -3808,6 +3823,7 @@ function hitType(defaultValue) {
3808
3823
  return decorateLeafAttr(defaultValue, (key) => attr({
3809
3824
  set(value) {
3810
3825
  if (this.__setAttr(key, value)) {
3826
+ this.__layout.hitCanvasChanged = true;
3811
3827
  if (Debug.showHitView) {
3812
3828
  this.__layout.surfaceChanged || this.__layout.surfaceChange();
3813
3829
  }
@@ -3950,7 +3966,7 @@ function registerUIEvent() {
3950
3966
  };
3951
3967
  }
3952
3968
 
3953
- const { copy: copy$7, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$3, rotateOfOuter: rotateOfOuter$3, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3969
+ const { copy: copy$7, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3954
3970
  const matrix$1 = {};
3955
3971
  const LeafHelper = {
3956
3972
  updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
@@ -4036,7 +4052,7 @@ const LeafHelper = {
4036
4052
  },
4037
4053
  zoomOfLocal(t, origin, scaleX, scaleY = scaleX, resize) {
4038
4054
  copy$7(matrix$1, t.__localMatrix);
4039
- scaleOfOuter$3(matrix$1, origin, scaleX, scaleY);
4055
+ scaleOfOuter$2(matrix$1, origin, scaleX, scaleY);
4040
4056
  moveByMatrix(t, matrix$1);
4041
4057
  t.scaleResize(scaleX, scaleY, resize !== true);
4042
4058
  },
@@ -4045,7 +4061,7 @@ const LeafHelper = {
4045
4061
  },
4046
4062
  rotateOfLocal(t, origin, angle) {
4047
4063
  copy$7(matrix$1, t.__localMatrix);
4048
- rotateOfOuter$3(matrix$1, origin, angle);
4064
+ rotateOfOuter$2(matrix$1, origin, angle);
4049
4065
  moveByMatrix(t, matrix$1);
4050
4066
  t.rotation = MathHelper.formatRotation(t.rotation + angle);
4051
4067
  },
@@ -4072,11 +4088,24 @@ const LeafHelper = {
4072
4088
  setTransform(t, transform, resize) {
4073
4089
  const layout = getLayout(transform);
4074
4090
  if (resize) {
4075
- t.scaleResize(layout.scaleX / t.scaleX, layout.scaleY / t.scaleY, resize !== true);
4091
+ const scaleX = layout.scaleX / t.scaleX;
4092
+ const scaleY = layout.scaleY / t.scaleY;
4076
4093
  delete layout.scaleX;
4077
4094
  delete layout.scaleY;
4095
+ t.set(layout);
4096
+ t.scaleResize(scaleX, scaleY, resize !== true);
4078
4097
  }
4079
- t.set(layout);
4098
+ else {
4099
+ t.set(layout);
4100
+ }
4101
+ },
4102
+ getLocalOrigin(t, origin) {
4103
+ return PointHelper.tempToOuterOf(L.getInnerOrigin(t, origin), t.localTransform);
4104
+ },
4105
+ getInnerOrigin(t, origin) {
4106
+ if (typeof origin === 'string')
4107
+ AroundHelper.toPoint(origin, t.boxBounds, origin = {});
4108
+ return origin;
4080
4109
  },
4081
4110
  getRelativeWorld(t, relative, temp) {
4082
4111
  copy$7(matrix$1, t.worldTransform);
@@ -5072,8 +5101,8 @@ const BranchRender = {
5072
5101
  const { LEAF, create } = IncrementId;
5073
5102
  const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper;
5074
5103
  const { toOuterOf } = BoundsHelper;
5075
- const { tempToOuterOf, copy: copy$4 } = PointHelper;
5076
- const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getRelativeWorld, drop } = LeafHelper;
5104
+ const { copy: copy$4 } = PointHelper;
5105
+ const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getLocalOrigin, getRelativeWorld, drop } = LeafHelper;
5077
5106
  let Leaf = class Leaf {
5078
5107
  get tag() { return this.__tag; }
5079
5108
  set tag(_value) { }
@@ -5160,12 +5189,18 @@ let Leaf = class Leaf {
5160
5189
  }
5161
5190
  set(_data) { }
5162
5191
  get(_name) { return undefined; }
5192
+ setAttr(name, value) { this[name] = value; }
5193
+ getAttr(name) { return this[name]; }
5194
+ getComputedAttr(name) { return this.__[name]; }
5163
5195
  toJSON() {
5164
5196
  return this.__.__getInputData();
5165
5197
  }
5166
5198
  toString() {
5167
5199
  return JSON.stringify(this.toJSON());
5168
5200
  }
5201
+ toSVG() { return undefined; }
5202
+ __SVG(_data) { }
5203
+ toHTML() { return undefined; }
5169
5204
  __setAttr(_attrName, _newValue) { return true; }
5170
5205
  __getAttr(_attrName) { return undefined; }
5171
5206
  setProxyAttr(_attrName, _newValue) { }
@@ -5331,13 +5366,13 @@ let Leaf = class Leaf {
5331
5366
  moveLocal(this, x, y);
5332
5367
  }
5333
5368
  scaleOf(origin, scaleX, scaleY, resize) {
5334
- zoomOfLocal(this, tempToOuterOf(origin, this.localTransform), scaleX, scaleY, resize);
5369
+ zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
5335
5370
  }
5336
5371
  rotateOf(origin, rotation) {
5337
- rotateOfLocal(this, tempToOuterOf(origin, this.localTransform), rotation);
5372
+ rotateOfLocal(this, getLocalOrigin(this, origin), rotation);
5338
5373
  }
5339
5374
  skewOf(origin, skewX, skewY, resize) {
5340
- skewOfLocal(this, tempToOuterOf(origin, this.localTransform), skewX, skewY, resize);
5375
+ skewOfLocal(this, getLocalOrigin(this, origin), skewX, skewY, resize);
5341
5376
  }
5342
5377
  transformWorld(worldTransform, resize) {
5343
5378
  transformWorld(this, worldTransform, resize);
@@ -5359,6 +5394,14 @@ let Leaf = class Leaf {
5359
5394
  this.scaleY *= scaleY;
5360
5395
  }
5361
5396
  __scaleResize(_scaleX, _scaleY) { }
5397
+ resizeWidth(width) {
5398
+ const scale = width / this.__localBoxBounds.width;
5399
+ this.scaleResize(scale, this.__.lockRatio ? scale : 1);
5400
+ }
5401
+ resizeHeight(height) {
5402
+ const scale = height / this.__localBoxBounds.height;
5403
+ this.scaleResize(this.__.lockRatio ? scale : 1, scale);
5404
+ }
5362
5405
  __hitWorld(_point) { return true; }
5363
5406
  __hit(_local) { return true; }
5364
5407
  __hitFill(_inner) { return true; }
@@ -5709,7 +5752,7 @@ class LeafLevelList {
5709
5752
  }
5710
5753
  }
5711
5754
 
5712
- const version = "1.0.0-rc.25";
5755
+ const version = "1.0.0-rc.27";
5713
5756
  const inviteCode = {};
5714
5757
 
5715
5758
  const debug$7 = Debug.get('LeaferCanvas');
@@ -5720,10 +5763,12 @@ class LeaferCanvas extends LeaferCanvasBase {
5720
5763
  const { style } = this.view;
5721
5764
  style.display || (style.display = 'block');
5722
5765
  this.parentView = this.view.parentElement;
5723
- if (this.parentView)
5724
- this.parentView.style.userSelect = 'none';
5766
+ if (this.parentView) {
5767
+ const pStyle = this.parentView.style;
5768
+ pStyle.webkitUserSelect = pStyle.userSelect = 'none';
5769
+ }
5725
5770
  if (Platform.syncDomFont && !this.parentView) {
5726
- this.view.style.display = 'none';
5771
+ style.display = 'none';
5727
5772
  document.body.appendChild(this.view);
5728
5773
  }
5729
5774
  this.__createContext();
@@ -6620,8 +6665,12 @@ class Picker {
6620
6665
  hitChild(child, point, proxy) {
6621
6666
  if (this.exclude && this.exclude.has(child))
6622
6667
  return;
6623
- if (child.__hitWorld(point))
6668
+ if (child.__hitWorld(point)) {
6669
+ const { parent } = child;
6670
+ if (parent && parent.__hasMask && !child.__.mask && !parent.children.some(item => item.__.mask && item.__hitWorld(point)))
6671
+ return;
6624
6672
  this.findList.add(proxy || child);
6673
+ }
6625
6674
  }
6626
6675
  clear() {
6627
6676
  this.point = null;
@@ -7178,6 +7227,8 @@ const UIRender = {
7178
7227
  this.__drawRenderPath(canvas);
7179
7228
  if (fill && !ignoreFill)
7180
7229
  this.__.__pixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7230
+ if (this.__.__isCanvas)
7231
+ this.__drawAfterFill(canvas, options);
7181
7232
  if (stroke && !ignoreStroke)
7182
7233
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7183
7234
  }
@@ -7382,7 +7433,7 @@ __decorate([
7382
7433
  stateType(false)
7383
7434
  ], UI.prototype, "disabled", void 0);
7384
7435
  __decorate([
7385
- dataType(false)
7436
+ surfaceType(false)
7386
7437
  ], UI.prototype, "locked", void 0);
7387
7438
  __decorate([
7388
7439
  sortType(0)
@@ -7480,6 +7531,9 @@ __decorate([
7480
7531
  __decorate([
7481
7532
  boundsType()
7482
7533
  ], UI.prototype, "autoHeight", void 0);
7534
+ __decorate([
7535
+ boundsType()
7536
+ ], UI.prototype, "lockRatio", void 0);
7483
7537
  __decorate([
7484
7538
  boundsType()
7485
7539
  ], UI.prototype, "autoBox", void 0);
@@ -7597,6 +7651,9 @@ __decorate([
7597
7651
  __decorate([
7598
7652
  dataType()
7599
7653
  ], UI.prototype, "disabledStyle", void 0);
7654
+ __decorate([
7655
+ dataType({})
7656
+ ], UI.prototype, "data", void 0);
7600
7657
  __decorate([
7601
7658
  rewrite(Leaf.prototype.reset)
7602
7659
  ], UI.prototype, "reset", null);
@@ -8069,9 +8126,9 @@ let Box = class Box extends Group {
8069
8126
  if (!data.__autoSize) {
8070
8127
  const b = this.__layout.boxBounds;
8071
8128
  if (!data.__autoWidth)
8072
- b.x = 0, b.width = data.width;
8129
+ b.height += b.y, b.width = data.width, b.x = b.y = 0;
8073
8130
  if (!data.__autoHeight)
8074
- b.y = 0, b.height = data.height;
8131
+ b.width += b.x, b.height = data.height, b.y = b.x = 0;
8075
8132
  }
8076
8133
  }
8077
8134
  else {
@@ -8141,6 +8198,9 @@ let Box = class Box extends Group {
8141
8198
  __decorate([
8142
8199
  dataProcessor(BoxData)
8143
8200
  ], Box.prototype, "__", void 0);
8201
+ __decorate([
8202
+ dataType(false)
8203
+ ], Box.prototype, "resizeChildren", void 0);
8144
8204
  __decorate([
8145
8205
  affectRenderBoundsType('show')
8146
8206
  ], Box.prototype, "overflow", void 0);
@@ -8250,7 +8310,7 @@ Ellipse = __decorate([
8250
8310
  ], Ellipse);
8251
8311
 
8252
8312
  const { moveTo: moveTo$2, lineTo: lineTo$2, drawPoints: drawPoints$1 } = PathCommandDataHelper;
8253
- const { rotate: rotate$1, getAngle: getAngle$2, getDistance: getDistance$2, defaultPoint } = PointHelper;
8313
+ const { rotate: rotate$1, getAngle: getAngle$1, getDistance: getDistance$2, defaultPoint } = PointHelper;
8254
8314
  const { toBounds: toBounds$1 } = PathBounds;
8255
8315
  let Line = class Line extends UI {
8256
8316
  get __tag() { return 'Line'; }
@@ -8265,7 +8325,7 @@ let Line = class Line extends UI {
8265
8325
  }
8266
8326
  set toPoint(value) {
8267
8327
  this.width = getDistance$2(defaultPoint, value);
8268
- this.rotation = getAngle$2(defaultPoint, value);
8328
+ this.rotation = getAngle$1(defaultPoint, value);
8269
8329
  if (this.height)
8270
8330
  this.height = 0;
8271
8331
  }
@@ -8436,7 +8496,7 @@ let Canvas = class Canvas extends Rect {
8436
8496
  super(data);
8437
8497
  this.canvas = Creator.canvas(this.__);
8438
8498
  this.context = this.canvas.context;
8439
- this.__.__drawAfterFill = true;
8499
+ this.__.__isCanvas = this.__.__drawAfterFill = true;
8440
8500
  }
8441
8501
  draw(ui, offset, scale, rotation) {
8442
8502
  ui.__layout.update();
@@ -8504,9 +8564,6 @@ __decorate([
8504
8564
  __decorate([
8505
8565
  resizeType()
8506
8566
  ], Canvas.prototype, "contextSettings", void 0);
8507
- __decorate([
8508
- hitType('all')
8509
- ], Canvas.prototype, "hitFill", void 0);
8510
8567
  Canvas = __decorate([
8511
8568
  registerUI()
8512
8569
  ], Canvas);
@@ -8612,6 +8669,9 @@ __decorate([
8612
8669
  __decorate([
8613
8670
  boundsType(0)
8614
8671
  ], Text.prototype, "height", void 0);
8672
+ __decorate([
8673
+ dataType(false)
8674
+ ], Text.prototype, "resizeFontSize", void 0);
8615
8675
  __decorate([
8616
8676
  surfaceType('#000000')
8617
8677
  ], Text.prototype, "fill", void 0);
@@ -8970,20 +9030,32 @@ let DragEvent = class DragEvent extends PointerEvent {
8970
9030
  move.x = 0;
8971
9031
  return move;
8972
9032
  }
8973
- static getMoveInDragBounds(box, dragBounds, move, change) {
8974
- const x = box.x + move.x, y = box.y + move.y;
8975
- const right = x + box.width, bottom = y + box.height;
9033
+ static getMoveInDragBounds(childBox, dragBounds, move, change) {
9034
+ const x = childBox.x + move.x, y = childBox.y + move.y;
9035
+ const right = x + childBox.width, bottom = y + childBox.height;
8976
9036
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
8977
9037
  if (!change)
8978
9038
  move = Object.assign({}, move);
8979
- if (x < dragBounds.x)
8980
- move.x += dragBounds.x - x;
8981
- else if (right > boundsRight)
8982
- move.x += boundsRight - right;
8983
- if (y < dragBounds.y)
8984
- move.y += dragBounds.y - y;
8985
- else if (bottom > boundsBottom)
8986
- move.y += boundsBottom - bottom;
9039
+ if (BoundsHelper.includes(childBox, dragBounds)) {
9040
+ if (x > dragBounds.x)
9041
+ move.x += dragBounds.x - x;
9042
+ else if (right < boundsRight)
9043
+ move.x += boundsRight - right;
9044
+ if (y > dragBounds.y)
9045
+ move.y += dragBounds.y - y;
9046
+ else if (bottom < boundsBottom)
9047
+ move.y += boundsBottom - bottom;
9048
+ }
9049
+ else {
9050
+ if (x < dragBounds.x)
9051
+ move.x += dragBounds.x - x;
9052
+ else if (right > boundsRight)
9053
+ move.x += boundsRight - right;
9054
+ if (y < dragBounds.y)
9055
+ move.y += dragBounds.y - y;
9056
+ else if (bottom > boundsBottom)
9057
+ move.y += boundsBottom - bottom;
9058
+ }
8987
9059
  return move;
8988
9060
  }
8989
9061
  getPageMove(total) {
@@ -9011,6 +9083,14 @@ let DragEvent = class DragEvent extends PointerEvent {
9011
9083
  getLocalTotal(relative) {
9012
9084
  return this.getLocalMove(relative, true);
9013
9085
  }
9086
+ getPageBounds() {
9087
+ const total = this.getPageTotal();
9088
+ const start = this.getPage();
9089
+ const bounds = {};
9090
+ BoundsHelper.set(bounds, start.x - total.x, start.y - total.y, total.x, total.y);
9091
+ BoundsHelper.unsign(bounds);
9092
+ return bounds;
9093
+ }
9014
9094
  assignMove(total) {
9015
9095
  move.x = total ? this.totalX : this.moveX;
9016
9096
  move.y = total ? this.totalY : this.moveY;
@@ -9627,7 +9707,8 @@ const config = {
9627
9707
  swipeDistance: 20,
9628
9708
  preventDefaultMenu: true
9629
9709
  },
9630
- cursor: {}
9710
+ cursor: {},
9711
+ keyEvent: true
9631
9712
  };
9632
9713
 
9633
9714
  const { pathHasEventType, getMoveEventData: getMoveEventData$1, getZoomEventData: getZoomEventData$1, getRotateEventData: getRotateEventData$1 } = InteractionHelper;
@@ -9777,6 +9858,8 @@ class InteractionBase {
9777
9858
  this.transformer.transformEnd();
9778
9859
  }
9779
9860
  keyDown(data) {
9861
+ if (!this.config.keyEvent)
9862
+ return;
9780
9863
  const { code } = data;
9781
9864
  if (!this.downKeyMap[code]) {
9782
9865
  this.downKeyMap[code] = true;
@@ -9790,6 +9873,8 @@ class InteractionBase {
9790
9873
  this.emit(KeyEvent.DOWN, data, this.defaultPath);
9791
9874
  }
9792
9875
  keyUp(data) {
9876
+ if (!this.config.keyEvent)
9877
+ return;
9793
9878
  const { code } = data;
9794
9879
  this.downKeyMap[code] = false;
9795
9880
  Keyboard.setUpCode(code);
@@ -10090,27 +10175,6 @@ class HitCanvasManager extends CanvasManager {
10090
10175
  }
10091
10176
  }
10092
10177
 
10093
- const canvas$1 = LeaferCanvasBase.prototype;
10094
- canvas$1.hitFill = function (point, fillRule) {
10095
- return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y);
10096
- };
10097
- canvas$1.hitStroke = function (point, strokeWidth) {
10098
- this.strokeWidth = strokeWidth;
10099
- return this.context.isPointInStroke(point.x, point.y);
10100
- };
10101
- canvas$1.hitPixel = function (radiusPoint, offset, scale = 1) {
10102
- let { x, y, radiusX, radiusY } = radiusPoint;
10103
- if (offset)
10104
- x -= offset.x, y -= offset.y;
10105
- tempBounds$1.set(x - radiusX, y - radiusY, radiusX * 2, radiusY * 2).scale(scale).ceil();
10106
- const { data } = this.context.getImageData(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
10107
- for (let i = 0, len = data.length; i < len; i += 4) {
10108
- if (data[i + 3] > 0)
10109
- return true;
10110
- }
10111
- return data[3] > 0;
10112
- };
10113
-
10114
10178
  const { toInnerRadiusPointOf, copy: copy$2, setRadius } = PointHelper;
10115
10179
  const inner = {};
10116
10180
  const leaf = Leaf.prototype;
@@ -10147,7 +10211,7 @@ const matrix = new Matrix();
10147
10211
  const ui$2 = UI.prototype;
10148
10212
  ui$2.__updateHitCanvas = function () {
10149
10213
  const data = this.__, { hitCanvasManager } = this.leafer;
10150
- const isHitPixelFill = data.__pixelFill && data.hitFill === 'pixel';
10214
+ const isHitPixelFill = (data.__pixelFill || data.__isCanvas) && data.hitFill === 'pixel';
10151
10215
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
10152
10216
  const isHitPixel = isHitPixelFill || isHitPixelStroke;
10153
10217
  if (!this.__hitCanvas)
@@ -10179,11 +10243,11 @@ ui$2.__hit = function (inner) {
10179
10243
  if (data.__isHitPixel && this.__hitPixel(inner))
10180
10244
  return true;
10181
10245
  const { hitFill } = data;
10182
- const needHitFillPath = ((data.fill && hitFill == 'path') || hitFill === 'all');
10246
+ const needHitFillPath = ((data.fill || data.__isCanvas) && (hitFill === 'path' || (hitFill === 'pixel' && !(data.__pixelFill || data.__isCanvas)))) || hitFill === 'all';
10183
10247
  if (needHitFillPath && this.__hitFill(inner))
10184
10248
  return true;
10185
10249
  const { hitStroke, __strokeWidth } = data;
10186
- const needHitStrokePath = ((data.stroke && hitStroke == 'path') || hitStroke === 'all');
10250
+ const needHitStrokePath = (data.stroke && (hitStroke === 'path' || (hitStroke === 'pixel' && !data.__pixelStroke))) || hitStroke === 'all';
10187
10251
  if (!needHitFillPath && !needHitStrokePath)
10188
10252
  return false;
10189
10253
  const radiusWidth = inner.radiusX * 2;
@@ -10215,8 +10279,10 @@ ui$2.__hit = function (inner) {
10215
10279
  const ui$1 = new UI();
10216
10280
  const rect = Rect.prototype;
10217
10281
  rect.__updateHitCanvas = function () {
10218
- if (this.stroke || this.cornerRadius)
10282
+ if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
10219
10283
  ui$1.__updateHitCanvas.call(this);
10284
+ else if (this.__hitCanvas)
10285
+ this.__hitCanvas = null;
10220
10286
  };
10221
10287
  rect.__hitFill = function (inner) {
10222
10288
  return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
@@ -10236,6 +10302,27 @@ group.pick = function (hitPoint, options) {
10236
10302
  return this.leafer ? this.leafer.selector.getByPoint(hitPoint, options.hitRadius || 0, Object.assign(Object.assign({}, options), { target: this })) : null;
10237
10303
  };
10238
10304
 
10305
+ const canvas$1 = LeaferCanvasBase.prototype;
10306
+ canvas$1.hitFill = function (point, fillRule) {
10307
+ return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y);
10308
+ };
10309
+ canvas$1.hitStroke = function (point, strokeWidth) {
10310
+ this.strokeWidth = strokeWidth;
10311
+ return this.context.isPointInStroke(point.x, point.y);
10312
+ };
10313
+ canvas$1.hitPixel = function (radiusPoint, offset, scale = 1) {
10314
+ let { x, y, radiusX, radiusY } = radiusPoint;
10315
+ if (offset)
10316
+ x -= offset.x, y -= offset.y;
10317
+ tempBounds$1.set(x - radiusX, y - radiusY, radiusX * 2, radiusY * 2).scale(scale).ceil();
10318
+ const { data } = this.context.getImageData(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width || 1, tempBounds$1.height || 1);
10319
+ for (let i = 0, len = data.length; i < len; i += 4) {
10320
+ if (data[i + 3] > 0)
10321
+ return true;
10322
+ }
10323
+ return data[3] > 0;
10324
+ };
10325
+
10239
10326
  const PointerEventHelper = {
10240
10327
  convert(e, local) {
10241
10328
  const base = InteractionHelper.getBase(e);
@@ -10524,11 +10611,15 @@ class Interaction extends InteractionBase {
10524
10611
  scale !== 1 ? this.zoom(getZoomEventData(local, scale, eventBase)) : this.move(getMoveEventData(local, wheel.getMove ? wheel.getMove(e, wheel) : WheelEventHelper.getMove(e, wheel), eventBase));
10525
10612
  }
10526
10613
  onGesturestart(e) {
10614
+ if (this.useMultiTouch)
10615
+ return;
10527
10616
  this.preventDefaultWheel(e);
10528
10617
  this.lastGestureScale = 1;
10529
10618
  this.lastGestureRotation = 0;
10530
10619
  }
10531
10620
  onGesturechange(e) {
10621
+ if (this.useMultiTouch)
10622
+ return;
10532
10623
  this.preventDefaultWheel(e);
10533
10624
  const local = this.getLocal(e);
10534
10625
  const eventBase = InteractionHelper.getBase(e);
@@ -10542,6 +10633,8 @@ class Interaction extends InteractionBase {
10542
10633
  this.lastGestureRotation = e.rotation;
10543
10634
  }
10544
10635
  onGestureend(e) {
10636
+ if (this.useMultiTouch)
10637
+ return;
10545
10638
  this.preventDefaultWheel(e);
10546
10639
  this.transformEnd();
10547
10640
  }
@@ -10861,7 +10954,7 @@ function getLeafPaint(attrName, paint, ui) {
10861
10954
  case 'angular':
10862
10955
  return PaintGradient.conicGradient(paint, boxBounds);
10863
10956
  default:
10864
- return paint.r ? { type: 'solid', style: ColorConvert.string(paint) } : undefined;
10957
+ return paint.r !== undefined ? { type: 'solid', style: ColorConvert.string(paint) } : undefined;
10865
10958
  }
10866
10959
  }
10867
10960
 
@@ -10878,17 +10971,17 @@ const PaintModule = {
10878
10971
  };
10879
10972
 
10880
10973
  let origin = {};
10881
- const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
10974
+ const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate } = MatrixHelper;
10882
10975
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10883
- const transform = get$4();
10976
+ const transform = get$3();
10884
10977
  translate$1(transform, box.x + x, box.y + y);
10885
10978
  scaleHelper(transform, scaleX, scaleY);
10886
10979
  if (rotation)
10887
- rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10980
+ rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10888
10981
  data.transform = transform;
10889
10982
  }
10890
10983
  function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
10891
- const transform = get$4();
10984
+ const transform = get$3();
10892
10985
  translate$1(transform, box.x + x, box.y + y);
10893
10986
  if (scaleX)
10894
10987
  scaleHelper(transform, scaleX, scaleY);
@@ -10897,10 +10990,10 @@ function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
10897
10990
  data.transform = transform;
10898
10991
  }
10899
10992
  function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
10900
- const transform = get$4();
10993
+ const transform = get$3();
10901
10994
  if (rotation) {
10902
10995
  if (align === 'center') {
10903
- rotateOfOuter$2(transform, { x: width / 2, y: height / 2 }, rotation);
10996
+ rotateOfOuter$1(transform, { x: width / 2, y: height / 2 }, rotation);
10904
10997
  }
10905
10998
  else {
10906
10999
  rotate(transform, rotation);
@@ -10921,22 +11014,26 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
10921
11014
  origin.y = box.y + y;
10922
11015
  translate$1(transform, origin.x, origin.y);
10923
11016
  if (scaleX)
10924
- scaleOfOuter$2(transform, origin, scaleX, scaleY);
11017
+ scaleOfOuter$1(transform, origin, scaleX, scaleY);
10925
11018
  data.transform = transform;
10926
11019
  }
10927
11020
 
10928
- const { get: get$3, translate } = MatrixHelper;
11021
+ const { get: get$2, translate } = MatrixHelper;
10929
11022
  const tempBox = new Bounds();
10930
11023
  const tempPoint = {};
10931
11024
  function createData(leafPaint, image, paint, box) {
11025
+ const { blendMode } = paint;
11026
+ if (blendMode)
11027
+ leafPaint.blendMode = blendMode;
11028
+ leafPaint.data = getPatternData(paint, box, image);
11029
+ }
11030
+ function getPatternData(paint, box, image) {
10932
11031
  let { width, height } = image;
10933
11032
  if (paint.padding)
10934
11033
  box = tempBox.set(box).shrink(paint.padding);
10935
- const { opacity, mode, align, offset, scale, size, rotation, blendMode, repeat } = paint;
11034
+ const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
10936
11035
  const sameBox = box.width === width && box.height === height;
10937
- if (blendMode)
10938
- leafPaint.blendMode = blendMode;
10939
- const data = leafPaint.data = { mode };
11036
+ const data = { mode };
10940
11037
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
10941
11038
  const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
10942
11039
  let x = 0, y = 0, scaleX, scaleY;
@@ -10988,7 +11085,7 @@ function createData(leafPaint, image, paint, box) {
10988
11085
  }
10989
11086
  if (!data.transform) {
10990
11087
  if (box.x || box.y) {
10991
- data.transform = get$3();
11088
+ data.transform = get$2();
10992
11089
  translate(data.transform, box.x, box.y);
10993
11090
  }
10994
11091
  }
@@ -11002,6 +11099,7 @@ function createData(leafPaint, image, paint, box) {
11002
11099
  data.opacity = opacity;
11003
11100
  if (repeat)
11004
11101
  data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
11102
+ return data;
11005
11103
  }
11006
11104
 
11007
11105
  let cache, box = new Bounds();
@@ -11091,7 +11189,7 @@ function ignoreRender(ui, value) {
11091
11189
  leafer.renderer.ignore = value;
11092
11190
  }
11093
11191
 
11094
- const { get: get$2, scale, copy: copy$1 } = MatrixHelper;
11192
+ const { get: get$1, scale, copy: copy$1 } = MatrixHelper;
11095
11193
  const { ceil, abs: abs$1 } = Math;
11096
11194
  function createPattern(ui, paint, pixelRatio) {
11097
11195
  let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
@@ -11102,7 +11200,7 @@ function createPattern(ui, paint, pixelRatio) {
11102
11200
  const { image, data } = paint;
11103
11201
  let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data;
11104
11202
  if (sx) {
11105
- imageMatrix = get$2();
11203
+ imageMatrix = get$1();
11106
11204
  copy$1(imageMatrix, transform);
11107
11205
  scale(imageMatrix, 1 / sx, 1 / sy);
11108
11206
  scaleX *= sx;
@@ -11137,7 +11235,7 @@ function createPattern(ui, paint, pixelRatio) {
11137
11235
  }
11138
11236
  if (transform || scaleX !== 1 || scaleY !== 1) {
11139
11237
  if (!imageMatrix) {
11140
- imageMatrix = get$2();
11238
+ imageMatrix = get$1();
11141
11239
  if (transform)
11142
11240
  copy$1(imageMatrix, transform);
11143
11241
  }
@@ -11238,13 +11336,14 @@ function recycleImage(attrName, data) {
11238
11336
 
11239
11337
  const PaintImageModule = {
11240
11338
  image,
11339
+ checkImage,
11340
+ createPattern,
11341
+ recycleImage,
11241
11342
  createData,
11343
+ getPatternData,
11242
11344
  fillOrFitMode,
11243
11345
  clipMode,
11244
- repeatMode,
11245
- createPattern,
11246
- checkImage,
11247
- recycleImage
11346
+ repeatMode
11248
11347
  };
11249
11348
 
11250
11349
  const { toPoint: toPoint$2 } = AroundHelper;
@@ -11274,8 +11373,8 @@ function applyStops(gradient, stops, opacity) {
11274
11373
  }
11275
11374
  }
11276
11375
 
11277
- const { getAngle: getAngle$1, getDistance: getDistance$1 } = PointHelper;
11278
- const { get: get$1, rotateOfOuter: rotateOfOuter$1, scaleOfOuter: scaleOfOuter$1 } = MatrixHelper;
11376
+ const { getAngle, getDistance: getDistance$1 } = PointHelper;
11377
+ const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
11279
11378
  const { toPoint: toPoint$1 } = AroundHelper;
11280
11379
  const realFrom$1 = {};
11281
11380
  const realTo$1 = {};
@@ -11283,23 +11382,35 @@ function radialGradient(paint, box) {
11283
11382
  let { from, to, type, opacity, blendMode, stretch } = paint;
11284
11383
  toPoint$1(from || 'center', box, realFrom$1);
11285
11384
  toPoint$1(to || 'bottom', box, realTo$1);
11286
- const { width, height } = box;
11287
- let transform;
11288
- if (width !== height || stretch) {
11289
- transform = get$1();
11290
- scaleOfOuter$1(transform, realFrom$1, width / height * (stretch || 1), 1);
11291
- rotateOfOuter$1(transform, realFrom$1, getAngle$1(realFrom$1, realTo$1) + 90);
11292
- }
11293
11385
  const style = Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$1(realFrom$1, realTo$1));
11294
11386
  applyStops(style, paint.stops, opacity);
11295
- const data = { type, style, transform };
11387
+ const data = { type, style };
11388
+ const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
11389
+ if (transform)
11390
+ data.transform = transform;
11296
11391
  if (blendMode)
11297
11392
  data.blendMode = blendMode;
11298
11393
  return data;
11299
11394
  }
11395
+ function getTransform(box, from, to, stretch, rotate90) {
11396
+ let transform;
11397
+ const { width, height } = box;
11398
+ if (width !== height || stretch) {
11399
+ const angle = getAngle(from, to);
11400
+ transform = get();
11401
+ if (rotate90) {
11402
+ scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
11403
+ rotateOfOuter(transform, from, angle + 90);
11404
+ }
11405
+ else {
11406
+ scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
11407
+ rotateOfOuter(transform, from, angle);
11408
+ }
11409
+ }
11410
+ return transform;
11411
+ }
11300
11412
 
11301
- const { getAngle, getDistance } = PointHelper;
11302
- const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
11413
+ const { getDistance } = PointHelper;
11303
11414
  const { toPoint } = AroundHelper;
11304
11415
  const realFrom = {};
11305
11416
  const realTo = {};
@@ -11307,20 +11418,12 @@ function conicGradient(paint, box) {
11307
11418
  let { from, to, type, opacity, blendMode, stretch } = paint;
11308
11419
  toPoint(from || 'center', box, realFrom);
11309
11420
  toPoint(to || 'bottom', box, realTo);
11310
- const { width, height } = box;
11311
- const transform = get();
11312
- const angle = getAngle(realFrom, realTo);
11313
- if (Platform.conicGradientRotate90) {
11314
- scaleOfOuter(transform, realFrom, width / height * (stretch || 1), 1);
11315
- rotateOfOuter(transform, realFrom, angle + 90);
11316
- }
11317
- else {
11318
- scaleOfOuter(transform, realFrom, 1, width / height * (stretch || 1));
11319
- rotateOfOuter(transform, realFrom, angle);
11320
- }
11321
11421
  const style = Platform.conicGradientSupport ? Platform.canvas.createConicGradient(0, realFrom.x, realFrom.y) : Platform.canvas.createRadialGradient(realFrom.x, realFrom.y, 0, realFrom.x, realFrom.y, getDistance(realFrom, realTo));
11322
11422
  applyStops(style, paint.stops, opacity);
11323
- const data = { type, style, transform };
11423
+ const data = { type, style };
11424
+ const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
11425
+ if (transform)
11426
+ data.transform = transform;
11324
11427
  if (blendMode)
11325
11428
  data.blendMode = blendMode;
11326
11429
  return data;
@@ -11329,7 +11432,8 @@ function conicGradient(paint, box) {
11329
11432
  const PaintGradientModule = {
11330
11433
  linearGradient,
11331
11434
  radialGradient,
11332
- conicGradient
11435
+ conicGradient,
11436
+ getTransform
11333
11437
  };
11334
11438
 
11335
11439
  const { copy, toOffsetOutBounds: toOffsetOutBounds$1 } = BoundsHelper;
@@ -12055,11 +12159,21 @@ const ExportModule = {
12055
12159
  resolve();
12056
12160
  this.running = false;
12057
12161
  };
12162
+ const { toURL } = Platform;
12163
+ const { download } = Platform.origin;
12164
+ const fileType = FileHelper.fileType(filename);
12058
12165
  if (filename === 'json') {
12059
12166
  return over({ data: leaf.toJSON() });
12060
12167
  }
12061
- else if (FileHelper.fileType(filename) === 'json') {
12062
- Platform.origin.download('data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(leaf.toJSON())), filename);
12168
+ else if (fileType === 'json') {
12169
+ download(toURL(JSON.stringify(leaf.toJSON()), 'text'), filename);
12170
+ return over({ data: true });
12171
+ }
12172
+ if (filename === 'svg') {
12173
+ return over({ data: leaf.toSVG() });
12174
+ }
12175
+ else if (fileType === 'svg') {
12176
+ download(toURL(leaf.toSVG(), 'svg'), filename);
12063
12177
  return over({ data: true });
12064
12178
  }
12065
12179
  const { leafer } = leaf;
@@ -12208,11 +12322,5 @@ Object.assign(Creator, {
12208
12322
  hitCanvasManager: () => new HitCanvasManager()
12209
12323
  });
12210
12324
  useCanvas();
12211
- window.addEventListener('unload', () => {
12212
- const { list } = Leafer;
12213
- list.forEach(leafer => leafer.destroy(true));
12214
- list.destroy();
12215
- ImageManager.destroy();
12216
- });
12217
12325
 
12218
12326
  export { AlignHelper, AnimateEvent, Answer, App, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, DropEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, HitCanvasManager, Image$1 as Image, ImageData, ImageEvent, ImageManager, IncrementId, Interaction, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, RotateEvent, Run, Selector, Star, StarData, State, StringNumberMap, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, ZoomEvent, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, inviteCode, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, stateType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };