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.
package/dist/web.js CHANGED
@@ -2,6 +2,14 @@ var LeaferUI = (function (exports) {
2
2
  'use strict';
3
3
 
4
4
  const Platform = {
5
+ toURL(text, fileType) {
6
+ let url = encodeURIComponent(text);
7
+ if (fileType === 'text')
8
+ url = 'data:text/plain;charset=utf-8,' + url;
9
+ else if (fileType === 'svg')
10
+ url = 'data:image/svg+xml,' + url;
11
+ return url;
12
+ },
5
13
  image: {
6
14
  hitCanvasSize: 100,
7
15
  maxCacheSize: 2560 * 1600,
@@ -959,6 +967,9 @@ var LeaferUI = (function (exports) {
959
967
  points.forEach((point, index) => index === 0 ? setPoint$3(tempPointBounds$1, point.x, point.y) : addPoint$3(tempPointBounds$1, point.x, point.y));
960
968
  toBounds$4(tempPointBounds$1, t);
961
969
  },
970
+ setPoint(t, point) {
971
+ B.set(t, point.x, point.y);
972
+ },
962
973
  addPoint(t, point) {
963
974
  add$1(t, point, true);
964
975
  },
@@ -1107,6 +1118,10 @@ var LeaferUI = (function (exports) {
1107
1118
  BoundsHelper.setListWithFn(this, list, boundsDataFn);
1108
1119
  return this;
1109
1120
  }
1121
+ setPoint(point) {
1122
+ BoundsHelper.setPoint(this, point);
1123
+ return this;
1124
+ }
1110
1125
  setPoints(points) {
1111
1126
  BoundsHelper.setPoints(this, points);
1112
1127
  return this;
@@ -1210,10 +1225,10 @@ var LeaferUI = (function (exports) {
1210
1225
  const AroundHelper = {
1211
1226
  directionData,
1212
1227
  tempPoint: {},
1213
- get: get$5,
1228
+ get: get$4,
1214
1229
  toPoint(around, bounds, to, onlySize, pointBounds) {
1215
1230
  to || (to = {});
1216
- const point = get$5(around);
1231
+ const point = get$4(around);
1217
1232
  to.x = point.x;
1218
1233
  to.y = point.y;
1219
1234
  if (point.type === 'percent') {
@@ -1234,7 +1249,7 @@ var LeaferUI = (function (exports) {
1234
1249
  }
1235
1250
  }
1236
1251
  };
1237
- function get$5(around) {
1252
+ function get$4(around) {
1238
1253
  return typeof around === 'string' ? directionData[exports.Direction9[around]] : around;
1239
1254
  }
1240
1255
 
@@ -3811,6 +3826,7 @@ var LeaferUI = (function (exports) {
3811
3826
  return decorateLeafAttr(defaultValue, (key) => attr({
3812
3827
  set(value) {
3813
3828
  if (this.__setAttr(key, value)) {
3829
+ this.__layout.hitCanvasChanged = true;
3814
3830
  if (Debug.showHitView) {
3815
3831
  this.__layout.surfaceChanged || this.__layout.surfaceChange();
3816
3832
  }
@@ -3953,7 +3969,7 @@ var LeaferUI = (function (exports) {
3953
3969
  };
3954
3970
  }
3955
3971
 
3956
- const { copy: copy$7, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$3, rotateOfOuter: rotateOfOuter$3, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3972
+ const { copy: copy$7, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3957
3973
  const matrix$1 = {};
3958
3974
  const LeafHelper = {
3959
3975
  updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
@@ -4039,7 +4055,7 @@ var LeaferUI = (function (exports) {
4039
4055
  },
4040
4056
  zoomOfLocal(t, origin, scaleX, scaleY = scaleX, resize) {
4041
4057
  copy$7(matrix$1, t.__localMatrix);
4042
- scaleOfOuter$3(matrix$1, origin, scaleX, scaleY);
4058
+ scaleOfOuter$2(matrix$1, origin, scaleX, scaleY);
4043
4059
  moveByMatrix(t, matrix$1);
4044
4060
  t.scaleResize(scaleX, scaleY, resize !== true);
4045
4061
  },
@@ -4048,7 +4064,7 @@ var LeaferUI = (function (exports) {
4048
4064
  },
4049
4065
  rotateOfLocal(t, origin, angle) {
4050
4066
  copy$7(matrix$1, t.__localMatrix);
4051
- rotateOfOuter$3(matrix$1, origin, angle);
4067
+ rotateOfOuter$2(matrix$1, origin, angle);
4052
4068
  moveByMatrix(t, matrix$1);
4053
4069
  t.rotation = MathHelper.formatRotation(t.rotation + angle);
4054
4070
  },
@@ -4075,11 +4091,24 @@ var LeaferUI = (function (exports) {
4075
4091
  setTransform(t, transform, resize) {
4076
4092
  const layout = getLayout(transform);
4077
4093
  if (resize) {
4078
- t.scaleResize(layout.scaleX / t.scaleX, layout.scaleY / t.scaleY, resize !== true);
4094
+ const scaleX = layout.scaleX / t.scaleX;
4095
+ const scaleY = layout.scaleY / t.scaleY;
4079
4096
  delete layout.scaleX;
4080
4097
  delete layout.scaleY;
4098
+ t.set(layout);
4099
+ t.scaleResize(scaleX, scaleY, resize !== true);
4081
4100
  }
4082
- t.set(layout);
4101
+ else {
4102
+ t.set(layout);
4103
+ }
4104
+ },
4105
+ getLocalOrigin(t, origin) {
4106
+ return PointHelper.tempToOuterOf(L.getInnerOrigin(t, origin), t.localTransform);
4107
+ },
4108
+ getInnerOrigin(t, origin) {
4109
+ if (typeof origin === 'string')
4110
+ AroundHelper.toPoint(origin, t.boxBounds, origin = {});
4111
+ return origin;
4083
4112
  },
4084
4113
  getRelativeWorld(t, relative, temp) {
4085
4114
  copy$7(matrix$1, t.worldTransform);
@@ -5075,8 +5104,8 @@ var LeaferUI = (function (exports) {
5075
5104
  const { LEAF, create } = IncrementId;
5076
5105
  const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper;
5077
5106
  const { toOuterOf } = BoundsHelper;
5078
- const { tempToOuterOf, copy: copy$4 } = PointHelper;
5079
- const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getRelativeWorld, drop } = LeafHelper;
5107
+ const { copy: copy$4 } = PointHelper;
5108
+ const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getLocalOrigin, getRelativeWorld, drop } = LeafHelper;
5080
5109
  exports.Leaf = class Leaf {
5081
5110
  get tag() { return this.__tag; }
5082
5111
  set tag(_value) { }
@@ -5163,12 +5192,18 @@ var LeaferUI = (function (exports) {
5163
5192
  }
5164
5193
  set(_data) { }
5165
5194
  get(_name) { return undefined; }
5195
+ setAttr(name, value) { this[name] = value; }
5196
+ getAttr(name) { return this[name]; }
5197
+ getComputedAttr(name) { return this.__[name]; }
5166
5198
  toJSON() {
5167
5199
  return this.__.__getInputData();
5168
5200
  }
5169
5201
  toString() {
5170
5202
  return JSON.stringify(this.toJSON());
5171
5203
  }
5204
+ toSVG() { return undefined; }
5205
+ __SVG(_data) { }
5206
+ toHTML() { return undefined; }
5172
5207
  __setAttr(_attrName, _newValue) { return true; }
5173
5208
  __getAttr(_attrName) { return undefined; }
5174
5209
  setProxyAttr(_attrName, _newValue) { }
@@ -5334,13 +5369,13 @@ var LeaferUI = (function (exports) {
5334
5369
  moveLocal(this, x, y);
5335
5370
  }
5336
5371
  scaleOf(origin, scaleX, scaleY, resize) {
5337
- zoomOfLocal(this, tempToOuterOf(origin, this.localTransform), scaleX, scaleY, resize);
5372
+ zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
5338
5373
  }
5339
5374
  rotateOf(origin, rotation) {
5340
- rotateOfLocal(this, tempToOuterOf(origin, this.localTransform), rotation);
5375
+ rotateOfLocal(this, getLocalOrigin(this, origin), rotation);
5341
5376
  }
5342
5377
  skewOf(origin, skewX, skewY, resize) {
5343
- skewOfLocal(this, tempToOuterOf(origin, this.localTransform), skewX, skewY, resize);
5378
+ skewOfLocal(this, getLocalOrigin(this, origin), skewX, skewY, resize);
5344
5379
  }
5345
5380
  transformWorld(worldTransform, resize) {
5346
5381
  transformWorld(this, worldTransform, resize);
@@ -5362,6 +5397,14 @@ var LeaferUI = (function (exports) {
5362
5397
  this.scaleY *= scaleY;
5363
5398
  }
5364
5399
  __scaleResize(_scaleX, _scaleY) { }
5400
+ resizeWidth(width) {
5401
+ const scale = width / this.__localBoxBounds.width;
5402
+ this.scaleResize(scale, this.__.lockRatio ? scale : 1);
5403
+ }
5404
+ resizeHeight(height) {
5405
+ const scale = height / this.__localBoxBounds.height;
5406
+ this.scaleResize(this.__.lockRatio ? scale : 1, scale);
5407
+ }
5365
5408
  __hitWorld(_point) { return true; }
5366
5409
  __hit(_local) { return true; }
5367
5410
  __hitFill(_inner) { return true; }
@@ -5712,7 +5755,7 @@ var LeaferUI = (function (exports) {
5712
5755
  }
5713
5756
  }
5714
5757
 
5715
- const version = "1.0.0-rc.25";
5758
+ const version = "1.0.0-rc.27";
5716
5759
  const inviteCode = {};
5717
5760
 
5718
5761
  const debug$7 = Debug.get('LeaferCanvas');
@@ -5723,10 +5766,12 @@ var LeaferUI = (function (exports) {
5723
5766
  const { style } = this.view;
5724
5767
  style.display || (style.display = 'block');
5725
5768
  this.parentView = this.view.parentElement;
5726
- if (this.parentView)
5727
- this.parentView.style.userSelect = 'none';
5769
+ if (this.parentView) {
5770
+ const pStyle = this.parentView.style;
5771
+ pStyle.webkitUserSelect = pStyle.userSelect = 'none';
5772
+ }
5728
5773
  if (Platform.syncDomFont && !this.parentView) {
5729
- this.view.style.display = 'none';
5774
+ style.display = 'none';
5730
5775
  document.body.appendChild(this.view);
5731
5776
  }
5732
5777
  this.__createContext();
@@ -6623,8 +6668,12 @@ var LeaferUI = (function (exports) {
6623
6668
  hitChild(child, point, proxy) {
6624
6669
  if (this.exclude && this.exclude.has(child))
6625
6670
  return;
6626
- if (child.__hitWorld(point))
6671
+ if (child.__hitWorld(point)) {
6672
+ const { parent } = child;
6673
+ if (parent && parent.__hasMask && !child.__.mask && !parent.children.some(item => item.__.mask && item.__hitWorld(point)))
6674
+ return;
6627
6675
  this.findList.add(proxy || child);
6676
+ }
6628
6677
  }
6629
6678
  clear() {
6630
6679
  this.point = null;
@@ -7181,6 +7230,8 @@ var LeaferUI = (function (exports) {
7181
7230
  this.__drawRenderPath(canvas);
7182
7231
  if (fill && !ignoreFill)
7183
7232
  this.__.__pixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7233
+ if (this.__.__isCanvas)
7234
+ this.__drawAfterFill(canvas, options);
7184
7235
  if (stroke && !ignoreStroke)
7185
7236
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7186
7237
  }
@@ -7385,7 +7436,7 @@ var LeaferUI = (function (exports) {
7385
7436
  stateType(false)
7386
7437
  ], exports.UI.prototype, "disabled", void 0);
7387
7438
  __decorate([
7388
- dataType(false)
7439
+ surfaceType(false)
7389
7440
  ], exports.UI.prototype, "locked", void 0);
7390
7441
  __decorate([
7391
7442
  sortType(0)
@@ -7483,6 +7534,9 @@ var LeaferUI = (function (exports) {
7483
7534
  __decorate([
7484
7535
  boundsType()
7485
7536
  ], exports.UI.prototype, "autoHeight", void 0);
7537
+ __decorate([
7538
+ boundsType()
7539
+ ], exports.UI.prototype, "lockRatio", void 0);
7486
7540
  __decorate([
7487
7541
  boundsType()
7488
7542
  ], exports.UI.prototype, "autoBox", void 0);
@@ -7600,6 +7654,9 @@ var LeaferUI = (function (exports) {
7600
7654
  __decorate([
7601
7655
  dataType()
7602
7656
  ], exports.UI.prototype, "disabledStyle", void 0);
7657
+ __decorate([
7658
+ dataType({})
7659
+ ], exports.UI.prototype, "data", void 0);
7603
7660
  __decorate([
7604
7661
  rewrite(exports.Leaf.prototype.reset)
7605
7662
  ], exports.UI.prototype, "reset", null);
@@ -8072,9 +8129,9 @@ var LeaferUI = (function (exports) {
8072
8129
  if (!data.__autoSize) {
8073
8130
  const b = this.__layout.boxBounds;
8074
8131
  if (!data.__autoWidth)
8075
- b.x = 0, b.width = data.width;
8132
+ b.height += b.y, b.width = data.width, b.x = b.y = 0;
8076
8133
  if (!data.__autoHeight)
8077
- b.y = 0, b.height = data.height;
8134
+ b.width += b.x, b.height = data.height, b.y = b.x = 0;
8078
8135
  }
8079
8136
  }
8080
8137
  else {
@@ -8144,6 +8201,9 @@ var LeaferUI = (function (exports) {
8144
8201
  __decorate([
8145
8202
  dataProcessor(BoxData)
8146
8203
  ], exports.Box.prototype, "__", void 0);
8204
+ __decorate([
8205
+ dataType(false)
8206
+ ], exports.Box.prototype, "resizeChildren", void 0);
8147
8207
  __decorate([
8148
8208
  affectRenderBoundsType('show')
8149
8209
  ], exports.Box.prototype, "overflow", void 0);
@@ -8253,7 +8313,7 @@ var LeaferUI = (function (exports) {
8253
8313
  ], exports.Ellipse);
8254
8314
 
8255
8315
  const { moveTo: moveTo$2, lineTo: lineTo$2, drawPoints: drawPoints$1 } = PathCommandDataHelper;
8256
- const { rotate: rotate$1, getAngle: getAngle$2, getDistance: getDistance$2, defaultPoint } = PointHelper;
8316
+ const { rotate: rotate$1, getAngle: getAngle$1, getDistance: getDistance$2, defaultPoint } = PointHelper;
8257
8317
  const { toBounds: toBounds$1 } = PathBounds;
8258
8318
  exports.Line = class Line extends exports.UI {
8259
8319
  get __tag() { return 'Line'; }
@@ -8268,7 +8328,7 @@ var LeaferUI = (function (exports) {
8268
8328
  }
8269
8329
  set toPoint(value) {
8270
8330
  this.width = getDistance$2(defaultPoint, value);
8271
- this.rotation = getAngle$2(defaultPoint, value);
8331
+ this.rotation = getAngle$1(defaultPoint, value);
8272
8332
  if (this.height)
8273
8333
  this.height = 0;
8274
8334
  }
@@ -8439,7 +8499,7 @@ var LeaferUI = (function (exports) {
8439
8499
  super(data);
8440
8500
  this.canvas = Creator.canvas(this.__);
8441
8501
  this.context = this.canvas.context;
8442
- this.__.__drawAfterFill = true;
8502
+ this.__.__isCanvas = this.__.__drawAfterFill = true;
8443
8503
  }
8444
8504
  draw(ui, offset, scale, rotation) {
8445
8505
  ui.__layout.update();
@@ -8507,9 +8567,6 @@ var LeaferUI = (function (exports) {
8507
8567
  __decorate([
8508
8568
  resizeType()
8509
8569
  ], exports.Canvas.prototype, "contextSettings", void 0);
8510
- __decorate([
8511
- hitType('all')
8512
- ], exports.Canvas.prototype, "hitFill", void 0);
8513
8570
  exports.Canvas = __decorate([
8514
8571
  registerUI()
8515
8572
  ], exports.Canvas);
@@ -8615,6 +8672,9 @@ var LeaferUI = (function (exports) {
8615
8672
  __decorate([
8616
8673
  boundsType(0)
8617
8674
  ], exports.Text.prototype, "height", void 0);
8675
+ __decorate([
8676
+ dataType(false)
8677
+ ], exports.Text.prototype, "resizeFontSize", void 0);
8618
8678
  __decorate([
8619
8679
  surfaceType('#000000')
8620
8680
  ], exports.Text.prototype, "fill", void 0);
@@ -8973,20 +9033,32 @@ var LeaferUI = (function (exports) {
8973
9033
  move.x = 0;
8974
9034
  return move;
8975
9035
  }
8976
- static getMoveInDragBounds(box, dragBounds, move, change) {
8977
- const x = box.x + move.x, y = box.y + move.y;
8978
- const right = x + box.width, bottom = y + box.height;
9036
+ static getMoveInDragBounds(childBox, dragBounds, move, change) {
9037
+ const x = childBox.x + move.x, y = childBox.y + move.y;
9038
+ const right = x + childBox.width, bottom = y + childBox.height;
8979
9039
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
8980
9040
  if (!change)
8981
9041
  move = Object.assign({}, move);
8982
- if (x < dragBounds.x)
8983
- move.x += dragBounds.x - x;
8984
- else if (right > boundsRight)
8985
- move.x += boundsRight - right;
8986
- if (y < dragBounds.y)
8987
- move.y += dragBounds.y - y;
8988
- else if (bottom > boundsBottom)
8989
- move.y += boundsBottom - bottom;
9042
+ if (BoundsHelper.includes(childBox, dragBounds)) {
9043
+ if (x > dragBounds.x)
9044
+ move.x += dragBounds.x - x;
9045
+ else if (right < boundsRight)
9046
+ move.x += boundsRight - right;
9047
+ if (y > dragBounds.y)
9048
+ move.y += dragBounds.y - y;
9049
+ else if (bottom < boundsBottom)
9050
+ move.y += boundsBottom - bottom;
9051
+ }
9052
+ else {
9053
+ if (x < dragBounds.x)
9054
+ move.x += dragBounds.x - x;
9055
+ else if (right > boundsRight)
9056
+ move.x += boundsRight - right;
9057
+ if (y < dragBounds.y)
9058
+ move.y += dragBounds.y - y;
9059
+ else if (bottom > boundsBottom)
9060
+ move.y += boundsBottom - bottom;
9061
+ }
8990
9062
  return move;
8991
9063
  }
8992
9064
  getPageMove(total) {
@@ -9014,6 +9086,14 @@ var LeaferUI = (function (exports) {
9014
9086
  getLocalTotal(relative) {
9015
9087
  return this.getLocalMove(relative, true);
9016
9088
  }
9089
+ getPageBounds() {
9090
+ const total = this.getPageTotal();
9091
+ const start = this.getPage();
9092
+ const bounds = {};
9093
+ BoundsHelper.set(bounds, start.x - total.x, start.y - total.y, total.x, total.y);
9094
+ BoundsHelper.unsign(bounds);
9095
+ return bounds;
9096
+ }
9017
9097
  assignMove(total) {
9018
9098
  move.x = total ? this.totalX : this.moveX;
9019
9099
  move.y = total ? this.totalY : this.moveY;
@@ -9630,7 +9710,8 @@ var LeaferUI = (function (exports) {
9630
9710
  swipeDistance: 20,
9631
9711
  preventDefaultMenu: true
9632
9712
  },
9633
- cursor: {}
9713
+ cursor: {},
9714
+ keyEvent: true
9634
9715
  };
9635
9716
 
9636
9717
  const { pathHasEventType, getMoveEventData: getMoveEventData$1, getZoomEventData: getZoomEventData$1, getRotateEventData: getRotateEventData$1 } = InteractionHelper;
@@ -9780,6 +9861,8 @@ var LeaferUI = (function (exports) {
9780
9861
  this.transformer.transformEnd();
9781
9862
  }
9782
9863
  keyDown(data) {
9864
+ if (!this.config.keyEvent)
9865
+ return;
9783
9866
  const { code } = data;
9784
9867
  if (!this.downKeyMap[code]) {
9785
9868
  this.downKeyMap[code] = true;
@@ -9793,6 +9876,8 @@ var LeaferUI = (function (exports) {
9793
9876
  this.emit(exports.KeyEvent.DOWN, data, this.defaultPath);
9794
9877
  }
9795
9878
  keyUp(data) {
9879
+ if (!this.config.keyEvent)
9880
+ return;
9796
9881
  const { code } = data;
9797
9882
  this.downKeyMap[code] = false;
9798
9883
  Keyboard.setUpCode(code);
@@ -10093,27 +10178,6 @@ var LeaferUI = (function (exports) {
10093
10178
  }
10094
10179
  }
10095
10180
 
10096
- const canvas$1 = LeaferCanvasBase.prototype;
10097
- canvas$1.hitFill = function (point, fillRule) {
10098
- return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y);
10099
- };
10100
- canvas$1.hitStroke = function (point, strokeWidth) {
10101
- this.strokeWidth = strokeWidth;
10102
- return this.context.isPointInStroke(point.x, point.y);
10103
- };
10104
- canvas$1.hitPixel = function (radiusPoint, offset, scale = 1) {
10105
- let { x, y, radiusX, radiusY } = radiusPoint;
10106
- if (offset)
10107
- x -= offset.x, y -= offset.y;
10108
- tempBounds$1.set(x - radiusX, y - radiusY, radiusX * 2, radiusY * 2).scale(scale).ceil();
10109
- const { data } = this.context.getImageData(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
10110
- for (let i = 0, len = data.length; i < len; i += 4) {
10111
- if (data[i + 3] > 0)
10112
- return true;
10113
- }
10114
- return data[3] > 0;
10115
- };
10116
-
10117
10181
  const { toInnerRadiusPointOf, copy: copy$2, setRadius } = PointHelper;
10118
10182
  const inner = {};
10119
10183
  const leaf = exports.Leaf.prototype;
@@ -10150,7 +10214,7 @@ var LeaferUI = (function (exports) {
10150
10214
  const ui$2 = exports.UI.prototype;
10151
10215
  ui$2.__updateHitCanvas = function () {
10152
10216
  const data = this.__, { hitCanvasManager } = this.leafer;
10153
- const isHitPixelFill = data.__pixelFill && data.hitFill === 'pixel';
10217
+ const isHitPixelFill = (data.__pixelFill || data.__isCanvas) && data.hitFill === 'pixel';
10154
10218
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
10155
10219
  const isHitPixel = isHitPixelFill || isHitPixelStroke;
10156
10220
  if (!this.__hitCanvas)
@@ -10182,11 +10246,11 @@ var LeaferUI = (function (exports) {
10182
10246
  if (data.__isHitPixel && this.__hitPixel(inner))
10183
10247
  return true;
10184
10248
  const { hitFill } = data;
10185
- const needHitFillPath = ((data.fill && hitFill == 'path') || hitFill === 'all');
10249
+ const needHitFillPath = ((data.fill || data.__isCanvas) && (hitFill === 'path' || (hitFill === 'pixel' && !(data.__pixelFill || data.__isCanvas)))) || hitFill === 'all';
10186
10250
  if (needHitFillPath && this.__hitFill(inner))
10187
10251
  return true;
10188
10252
  const { hitStroke, __strokeWidth } = data;
10189
- const needHitStrokePath = ((data.stroke && hitStroke == 'path') || hitStroke === 'all');
10253
+ const needHitStrokePath = (data.stroke && (hitStroke === 'path' || (hitStroke === 'pixel' && !data.__pixelStroke))) || hitStroke === 'all';
10190
10254
  if (!needHitFillPath && !needHitStrokePath)
10191
10255
  return false;
10192
10256
  const radiusWidth = inner.radiusX * 2;
@@ -10218,8 +10282,10 @@ var LeaferUI = (function (exports) {
10218
10282
  const ui$1 = new exports.UI();
10219
10283
  const rect = exports.Rect.prototype;
10220
10284
  rect.__updateHitCanvas = function () {
10221
- if (this.stroke || this.cornerRadius)
10285
+ if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
10222
10286
  ui$1.__updateHitCanvas.call(this);
10287
+ else if (this.__hitCanvas)
10288
+ this.__hitCanvas = null;
10223
10289
  };
10224
10290
  rect.__hitFill = function (inner) {
10225
10291
  return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
@@ -10239,6 +10305,27 @@ var LeaferUI = (function (exports) {
10239
10305
  return this.leafer ? this.leafer.selector.getByPoint(hitPoint, options.hitRadius || 0, Object.assign(Object.assign({}, options), { target: this })) : null;
10240
10306
  };
10241
10307
 
10308
+ const canvas$1 = LeaferCanvasBase.prototype;
10309
+ canvas$1.hitFill = function (point, fillRule) {
10310
+ return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y);
10311
+ };
10312
+ canvas$1.hitStroke = function (point, strokeWidth) {
10313
+ this.strokeWidth = strokeWidth;
10314
+ return this.context.isPointInStroke(point.x, point.y);
10315
+ };
10316
+ canvas$1.hitPixel = function (radiusPoint, offset, scale = 1) {
10317
+ let { x, y, radiusX, radiusY } = radiusPoint;
10318
+ if (offset)
10319
+ x -= offset.x, y -= offset.y;
10320
+ tempBounds$1.set(x - radiusX, y - radiusY, radiusX * 2, radiusY * 2).scale(scale).ceil();
10321
+ const { data } = this.context.getImageData(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width || 1, tempBounds$1.height || 1);
10322
+ for (let i = 0, len = data.length; i < len; i += 4) {
10323
+ if (data[i + 3] > 0)
10324
+ return true;
10325
+ }
10326
+ return data[3] > 0;
10327
+ };
10328
+
10242
10329
  const PointerEventHelper = {
10243
10330
  convert(e, local) {
10244
10331
  const base = InteractionHelper.getBase(e);
@@ -10527,11 +10614,15 @@ var LeaferUI = (function (exports) {
10527
10614
  scale !== 1 ? this.zoom(getZoomEventData(local, scale, eventBase)) : this.move(getMoveEventData(local, wheel.getMove ? wheel.getMove(e, wheel) : WheelEventHelper.getMove(e, wheel), eventBase));
10528
10615
  }
10529
10616
  onGesturestart(e) {
10617
+ if (this.useMultiTouch)
10618
+ return;
10530
10619
  this.preventDefaultWheel(e);
10531
10620
  this.lastGestureScale = 1;
10532
10621
  this.lastGestureRotation = 0;
10533
10622
  }
10534
10623
  onGesturechange(e) {
10624
+ if (this.useMultiTouch)
10625
+ return;
10535
10626
  this.preventDefaultWheel(e);
10536
10627
  const local = this.getLocal(e);
10537
10628
  const eventBase = InteractionHelper.getBase(e);
@@ -10545,6 +10636,8 @@ var LeaferUI = (function (exports) {
10545
10636
  this.lastGestureRotation = e.rotation;
10546
10637
  }
10547
10638
  onGestureend(e) {
10639
+ if (this.useMultiTouch)
10640
+ return;
10548
10641
  this.preventDefaultWheel(e);
10549
10642
  this.transformEnd();
10550
10643
  }
@@ -10864,7 +10957,7 @@ var LeaferUI = (function (exports) {
10864
10957
  case 'angular':
10865
10958
  return PaintGradient.conicGradient(paint, boxBounds);
10866
10959
  default:
10867
- return paint.r ? { type: 'solid', style: ColorConvert.string(paint) } : undefined;
10960
+ return paint.r !== undefined ? { type: 'solid', style: ColorConvert.string(paint) } : undefined;
10868
10961
  }
10869
10962
  }
10870
10963
 
@@ -10881,17 +10974,17 @@ var LeaferUI = (function (exports) {
10881
10974
  };
10882
10975
 
10883
10976
  let origin = {};
10884
- const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
10977
+ const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate } = MatrixHelper;
10885
10978
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10886
- const transform = get$4();
10979
+ const transform = get$3();
10887
10980
  translate$1(transform, box.x + x, box.y + y);
10888
10981
  scaleHelper(transform, scaleX, scaleY);
10889
10982
  if (rotation)
10890
- rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10983
+ rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10891
10984
  data.transform = transform;
10892
10985
  }
10893
10986
  function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
10894
- const transform = get$4();
10987
+ const transform = get$3();
10895
10988
  translate$1(transform, box.x + x, box.y + y);
10896
10989
  if (scaleX)
10897
10990
  scaleHelper(transform, scaleX, scaleY);
@@ -10900,10 +10993,10 @@ var LeaferUI = (function (exports) {
10900
10993
  data.transform = transform;
10901
10994
  }
10902
10995
  function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
10903
- const transform = get$4();
10996
+ const transform = get$3();
10904
10997
  if (rotation) {
10905
10998
  if (align === 'center') {
10906
- rotateOfOuter$2(transform, { x: width / 2, y: height / 2 }, rotation);
10999
+ rotateOfOuter$1(transform, { x: width / 2, y: height / 2 }, rotation);
10907
11000
  }
10908
11001
  else {
10909
11002
  rotate(transform, rotation);
@@ -10924,22 +11017,26 @@ var LeaferUI = (function (exports) {
10924
11017
  origin.y = box.y + y;
10925
11018
  translate$1(transform, origin.x, origin.y);
10926
11019
  if (scaleX)
10927
- scaleOfOuter$2(transform, origin, scaleX, scaleY);
11020
+ scaleOfOuter$1(transform, origin, scaleX, scaleY);
10928
11021
  data.transform = transform;
10929
11022
  }
10930
11023
 
10931
- const { get: get$3, translate } = MatrixHelper;
11024
+ const { get: get$2, translate } = MatrixHelper;
10932
11025
  const tempBox = new Bounds();
10933
11026
  const tempPoint = {};
10934
11027
  function createData(leafPaint, image, paint, box) {
11028
+ const { blendMode } = paint;
11029
+ if (blendMode)
11030
+ leafPaint.blendMode = blendMode;
11031
+ leafPaint.data = getPatternData(paint, box, image);
11032
+ }
11033
+ function getPatternData(paint, box, image) {
10935
11034
  let { width, height } = image;
10936
11035
  if (paint.padding)
10937
11036
  box = tempBox.set(box).shrink(paint.padding);
10938
- const { opacity, mode, align, offset, scale, size, rotation, blendMode, repeat } = paint;
11037
+ const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
10939
11038
  const sameBox = box.width === width && box.height === height;
10940
- if (blendMode)
10941
- leafPaint.blendMode = blendMode;
10942
- const data = leafPaint.data = { mode };
11039
+ const data = { mode };
10943
11040
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
10944
11041
  const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
10945
11042
  let x = 0, y = 0, scaleX, scaleY;
@@ -10991,7 +11088,7 @@ var LeaferUI = (function (exports) {
10991
11088
  }
10992
11089
  if (!data.transform) {
10993
11090
  if (box.x || box.y) {
10994
- data.transform = get$3();
11091
+ data.transform = get$2();
10995
11092
  translate(data.transform, box.x, box.y);
10996
11093
  }
10997
11094
  }
@@ -11005,6 +11102,7 @@ var LeaferUI = (function (exports) {
11005
11102
  data.opacity = opacity;
11006
11103
  if (repeat)
11007
11104
  data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
11105
+ return data;
11008
11106
  }
11009
11107
 
11010
11108
  let cache, box = new Bounds();
@@ -11094,7 +11192,7 @@ var LeaferUI = (function (exports) {
11094
11192
  leafer.renderer.ignore = value;
11095
11193
  }
11096
11194
 
11097
- const { get: get$2, scale, copy: copy$1 } = MatrixHelper;
11195
+ const { get: get$1, scale, copy: copy$1 } = MatrixHelper;
11098
11196
  const { ceil, abs: abs$1 } = Math;
11099
11197
  function createPattern(ui, paint, pixelRatio) {
11100
11198
  let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
@@ -11105,7 +11203,7 @@ var LeaferUI = (function (exports) {
11105
11203
  const { image, data } = paint;
11106
11204
  let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data;
11107
11205
  if (sx) {
11108
- imageMatrix = get$2();
11206
+ imageMatrix = get$1();
11109
11207
  copy$1(imageMatrix, transform);
11110
11208
  scale(imageMatrix, 1 / sx, 1 / sy);
11111
11209
  scaleX *= sx;
@@ -11140,7 +11238,7 @@ var LeaferUI = (function (exports) {
11140
11238
  }
11141
11239
  if (transform || scaleX !== 1 || scaleY !== 1) {
11142
11240
  if (!imageMatrix) {
11143
- imageMatrix = get$2();
11241
+ imageMatrix = get$1();
11144
11242
  if (transform)
11145
11243
  copy$1(imageMatrix, transform);
11146
11244
  }
@@ -11241,13 +11339,14 @@ var LeaferUI = (function (exports) {
11241
11339
 
11242
11340
  const PaintImageModule = {
11243
11341
  image,
11342
+ checkImage,
11343
+ createPattern,
11344
+ recycleImage,
11244
11345
  createData,
11346
+ getPatternData,
11245
11347
  fillOrFitMode,
11246
11348
  clipMode,
11247
- repeatMode,
11248
- createPattern,
11249
- checkImage,
11250
- recycleImage
11349
+ repeatMode
11251
11350
  };
11252
11351
 
11253
11352
  const { toPoint: toPoint$2 } = AroundHelper;
@@ -11277,8 +11376,8 @@ var LeaferUI = (function (exports) {
11277
11376
  }
11278
11377
  }
11279
11378
 
11280
- const { getAngle: getAngle$1, getDistance: getDistance$1 } = PointHelper;
11281
- const { get: get$1, rotateOfOuter: rotateOfOuter$1, scaleOfOuter: scaleOfOuter$1 } = MatrixHelper;
11379
+ const { getAngle, getDistance: getDistance$1 } = PointHelper;
11380
+ const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
11282
11381
  const { toPoint: toPoint$1 } = AroundHelper;
11283
11382
  const realFrom$1 = {};
11284
11383
  const realTo$1 = {};
@@ -11286,23 +11385,35 @@ var LeaferUI = (function (exports) {
11286
11385
  let { from, to, type, opacity, blendMode, stretch } = paint;
11287
11386
  toPoint$1(from || 'center', box, realFrom$1);
11288
11387
  toPoint$1(to || 'bottom', box, realTo$1);
11289
- const { width, height } = box;
11290
- let transform;
11291
- if (width !== height || stretch) {
11292
- transform = get$1();
11293
- scaleOfOuter$1(transform, realFrom$1, width / height * (stretch || 1), 1);
11294
- rotateOfOuter$1(transform, realFrom$1, getAngle$1(realFrom$1, realTo$1) + 90);
11295
- }
11296
11388
  const style = Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$1(realFrom$1, realTo$1));
11297
11389
  applyStops(style, paint.stops, opacity);
11298
- const data = { type, style, transform };
11390
+ const data = { type, style };
11391
+ const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
11392
+ if (transform)
11393
+ data.transform = transform;
11299
11394
  if (blendMode)
11300
11395
  data.blendMode = blendMode;
11301
11396
  return data;
11302
11397
  }
11398
+ function getTransform(box, from, to, stretch, rotate90) {
11399
+ let transform;
11400
+ const { width, height } = box;
11401
+ if (width !== height || stretch) {
11402
+ const angle = getAngle(from, to);
11403
+ transform = get();
11404
+ if (rotate90) {
11405
+ scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
11406
+ rotateOfOuter(transform, from, angle + 90);
11407
+ }
11408
+ else {
11409
+ scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
11410
+ rotateOfOuter(transform, from, angle);
11411
+ }
11412
+ }
11413
+ return transform;
11414
+ }
11303
11415
 
11304
- const { getAngle, getDistance } = PointHelper;
11305
- const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
11416
+ const { getDistance } = PointHelper;
11306
11417
  const { toPoint } = AroundHelper;
11307
11418
  const realFrom = {};
11308
11419
  const realTo = {};
@@ -11310,20 +11421,12 @@ var LeaferUI = (function (exports) {
11310
11421
  let { from, to, type, opacity, blendMode, stretch } = paint;
11311
11422
  toPoint(from || 'center', box, realFrom);
11312
11423
  toPoint(to || 'bottom', box, realTo);
11313
- const { width, height } = box;
11314
- const transform = get();
11315
- const angle = getAngle(realFrom, realTo);
11316
- if (Platform.conicGradientRotate90) {
11317
- scaleOfOuter(transform, realFrom, width / height * (stretch || 1), 1);
11318
- rotateOfOuter(transform, realFrom, angle + 90);
11319
- }
11320
- else {
11321
- scaleOfOuter(transform, realFrom, 1, width / height * (stretch || 1));
11322
- rotateOfOuter(transform, realFrom, angle);
11323
- }
11324
11424
  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));
11325
11425
  applyStops(style, paint.stops, opacity);
11326
- const data = { type, style, transform };
11426
+ const data = { type, style };
11427
+ const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
11428
+ if (transform)
11429
+ data.transform = transform;
11327
11430
  if (blendMode)
11328
11431
  data.blendMode = blendMode;
11329
11432
  return data;
@@ -11332,7 +11435,8 @@ var LeaferUI = (function (exports) {
11332
11435
  const PaintGradientModule = {
11333
11436
  linearGradient,
11334
11437
  radialGradient,
11335
- conicGradient
11438
+ conicGradient,
11439
+ getTransform
11336
11440
  };
11337
11441
 
11338
11442
  const { copy, toOffsetOutBounds: toOffsetOutBounds$1 } = BoundsHelper;
@@ -12058,11 +12162,21 @@ var LeaferUI = (function (exports) {
12058
12162
  resolve();
12059
12163
  this.running = false;
12060
12164
  };
12165
+ const { toURL } = Platform;
12166
+ const { download } = Platform.origin;
12167
+ const fileType = FileHelper.fileType(filename);
12061
12168
  if (filename === 'json') {
12062
12169
  return over({ data: leaf.toJSON() });
12063
12170
  }
12064
- else if (FileHelper.fileType(filename) === 'json') {
12065
- Platform.origin.download('data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(leaf.toJSON())), filename);
12171
+ else if (fileType === 'json') {
12172
+ download(toURL(JSON.stringify(leaf.toJSON()), 'text'), filename);
12173
+ return over({ data: true });
12174
+ }
12175
+ if (filename === 'svg') {
12176
+ return over({ data: leaf.toSVG() });
12177
+ }
12178
+ else if (fileType === 'svg') {
12179
+ download(toURL(leaf.toSVG(), 'svg'), filename);
12066
12180
  return over({ data: true });
12067
12181
  }
12068
12182
  const { leafer } = leaf;
@@ -12211,12 +12325,6 @@ var LeaferUI = (function (exports) {
12211
12325
  hitCanvasManager: () => new HitCanvasManager()
12212
12326
  });
12213
12327
  useCanvas();
12214
- window.addEventListener('unload', () => {
12215
- const { list } = exports.Leafer;
12216
- list.forEach(leafer => leafer.destroy(true));
12217
- list.destroy();
12218
- ImageManager.destroy();
12219
- });
12220
12328
 
12221
12329
  exports.AlignHelper = AlignHelper;
12222
12330
  exports.AnimateEvent = AnimateEvent;