@leafer-ui/miniapp 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
  class LeaferCanvas extends LeaferCanvasBase {
@@ -5834,9 +5877,12 @@ function useCanvas(_canvasType, app) {
5834
5877
  if (toAlbum) {
5835
5878
  Platform.miniapp.saveToAlbum(filePath).then(() => {
5836
5879
  fs.unlink({ filePath });
5880
+ resolve();
5837
5881
  });
5838
5882
  }
5839
- resolve();
5883
+ else {
5884
+ resolve();
5885
+ }
5840
5886
  },
5841
5887
  fail(error) {
5842
5888
  reject(error);
@@ -6607,8 +6653,12 @@ class Picker {
6607
6653
  hitChild(child, point, proxy) {
6608
6654
  if (this.exclude && this.exclude.has(child))
6609
6655
  return;
6610
- if (child.__hitWorld(point))
6656
+ if (child.__hitWorld(point)) {
6657
+ const { parent } = child;
6658
+ if (parent && parent.__hasMask && !child.__.mask && !parent.children.some(item => item.__.mask && item.__hitWorld(point)))
6659
+ return;
6611
6660
  this.findList.add(proxy || child);
6661
+ }
6612
6662
  }
6613
6663
  clear() {
6614
6664
  this.point = null;
@@ -7165,6 +7215,8 @@ const UIRender = {
7165
7215
  this.__drawRenderPath(canvas);
7166
7216
  if (fill && !ignoreFill)
7167
7217
  this.__.__pixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7218
+ if (this.__.__isCanvas)
7219
+ this.__drawAfterFill(canvas, options);
7168
7220
  if (stroke && !ignoreStroke)
7169
7221
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7170
7222
  }
@@ -7369,7 +7421,7 @@ __decorate([
7369
7421
  stateType(false)
7370
7422
  ], UI.prototype, "disabled", void 0);
7371
7423
  __decorate([
7372
- dataType(false)
7424
+ surfaceType(false)
7373
7425
  ], UI.prototype, "locked", void 0);
7374
7426
  __decorate([
7375
7427
  sortType(0)
@@ -7467,6 +7519,9 @@ __decorate([
7467
7519
  __decorate([
7468
7520
  boundsType()
7469
7521
  ], UI.prototype, "autoHeight", void 0);
7522
+ __decorate([
7523
+ boundsType()
7524
+ ], UI.prototype, "lockRatio", void 0);
7470
7525
  __decorate([
7471
7526
  boundsType()
7472
7527
  ], UI.prototype, "autoBox", void 0);
@@ -7584,6 +7639,9 @@ __decorate([
7584
7639
  __decorate([
7585
7640
  dataType()
7586
7641
  ], UI.prototype, "disabledStyle", void 0);
7642
+ __decorate([
7643
+ dataType({})
7644
+ ], UI.prototype, "data", void 0);
7587
7645
  __decorate([
7588
7646
  rewrite(Leaf.prototype.reset)
7589
7647
  ], UI.prototype, "reset", null);
@@ -8056,9 +8114,9 @@ let Box = class Box extends Group {
8056
8114
  if (!data.__autoSize) {
8057
8115
  const b = this.__layout.boxBounds;
8058
8116
  if (!data.__autoWidth)
8059
- b.x = 0, b.width = data.width;
8117
+ b.height += b.y, b.width = data.width, b.x = b.y = 0;
8060
8118
  if (!data.__autoHeight)
8061
- b.y = 0, b.height = data.height;
8119
+ b.width += b.x, b.height = data.height, b.y = b.x = 0;
8062
8120
  }
8063
8121
  }
8064
8122
  else {
@@ -8128,6 +8186,9 @@ let Box = class Box extends Group {
8128
8186
  __decorate([
8129
8187
  dataProcessor(BoxData)
8130
8188
  ], Box.prototype, "__", void 0);
8189
+ __decorate([
8190
+ dataType(false)
8191
+ ], Box.prototype, "resizeChildren", void 0);
8131
8192
  __decorate([
8132
8193
  affectRenderBoundsType('show')
8133
8194
  ], Box.prototype, "overflow", void 0);
@@ -8237,7 +8298,7 @@ Ellipse = __decorate([
8237
8298
  ], Ellipse);
8238
8299
 
8239
8300
  const { moveTo: moveTo$2, lineTo: lineTo$2, drawPoints: drawPoints$1 } = PathCommandDataHelper;
8240
- const { rotate: rotate$1, getAngle: getAngle$2, getDistance: getDistance$2, defaultPoint } = PointHelper;
8301
+ const { rotate: rotate$1, getAngle: getAngle$1, getDistance: getDistance$2, defaultPoint } = PointHelper;
8241
8302
  const { toBounds: toBounds$1 } = PathBounds;
8242
8303
  let Line = class Line extends UI {
8243
8304
  get __tag() { return 'Line'; }
@@ -8252,7 +8313,7 @@ let Line = class Line extends UI {
8252
8313
  }
8253
8314
  set toPoint(value) {
8254
8315
  this.width = getDistance$2(defaultPoint, value);
8255
- this.rotation = getAngle$2(defaultPoint, value);
8316
+ this.rotation = getAngle$1(defaultPoint, value);
8256
8317
  if (this.height)
8257
8318
  this.height = 0;
8258
8319
  }
@@ -8423,7 +8484,7 @@ let Canvas = class Canvas extends Rect {
8423
8484
  super(data);
8424
8485
  this.canvas = Creator.canvas(this.__);
8425
8486
  this.context = this.canvas.context;
8426
- this.__.__drawAfterFill = true;
8487
+ this.__.__isCanvas = this.__.__drawAfterFill = true;
8427
8488
  }
8428
8489
  draw(ui, offset, scale, rotation) {
8429
8490
  ui.__layout.update();
@@ -8491,9 +8552,6 @@ __decorate([
8491
8552
  __decorate([
8492
8553
  resizeType()
8493
8554
  ], Canvas.prototype, "contextSettings", void 0);
8494
- __decorate([
8495
- hitType('all')
8496
- ], Canvas.prototype, "hitFill", void 0);
8497
8555
  Canvas = __decorate([
8498
8556
  registerUI()
8499
8557
  ], Canvas);
@@ -8599,6 +8657,9 @@ __decorate([
8599
8657
  __decorate([
8600
8658
  boundsType(0)
8601
8659
  ], Text.prototype, "height", void 0);
8660
+ __decorate([
8661
+ dataType(false)
8662
+ ], Text.prototype, "resizeFontSize", void 0);
8602
8663
  __decorate([
8603
8664
  surfaceType('#000000')
8604
8665
  ], Text.prototype, "fill", void 0);
@@ -8957,20 +9018,32 @@ let DragEvent = class DragEvent extends PointerEvent {
8957
9018
  move.x = 0;
8958
9019
  return move;
8959
9020
  }
8960
- static getMoveInDragBounds(box, dragBounds, move, change) {
8961
- const x = box.x + move.x, y = box.y + move.y;
8962
- const right = x + box.width, bottom = y + box.height;
9021
+ static getMoveInDragBounds(childBox, dragBounds, move, change) {
9022
+ const x = childBox.x + move.x, y = childBox.y + move.y;
9023
+ const right = x + childBox.width, bottom = y + childBox.height;
8963
9024
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
8964
9025
  if (!change)
8965
9026
  move = Object.assign({}, move);
8966
- if (x < dragBounds.x)
8967
- move.x += dragBounds.x - x;
8968
- else if (right > boundsRight)
8969
- move.x += boundsRight - right;
8970
- if (y < dragBounds.y)
8971
- move.y += dragBounds.y - y;
8972
- else if (bottom > boundsBottom)
8973
- move.y += boundsBottom - bottom;
9027
+ if (BoundsHelper.includes(childBox, dragBounds)) {
9028
+ if (x > dragBounds.x)
9029
+ move.x += dragBounds.x - x;
9030
+ else if (right < boundsRight)
9031
+ move.x += boundsRight - right;
9032
+ if (y > dragBounds.y)
9033
+ move.y += dragBounds.y - y;
9034
+ else if (bottom < boundsBottom)
9035
+ move.y += boundsBottom - bottom;
9036
+ }
9037
+ else {
9038
+ if (x < dragBounds.x)
9039
+ move.x += dragBounds.x - x;
9040
+ else if (right > boundsRight)
9041
+ move.x += boundsRight - right;
9042
+ if (y < dragBounds.y)
9043
+ move.y += dragBounds.y - y;
9044
+ else if (bottom > boundsBottom)
9045
+ move.y += boundsBottom - bottom;
9046
+ }
8974
9047
  return move;
8975
9048
  }
8976
9049
  getPageMove(total) {
@@ -8998,6 +9071,14 @@ let DragEvent = class DragEvent extends PointerEvent {
8998
9071
  getLocalTotal(relative) {
8999
9072
  return this.getLocalMove(relative, true);
9000
9073
  }
9074
+ getPageBounds() {
9075
+ const total = this.getPageTotal();
9076
+ const start = this.getPage();
9077
+ const bounds = {};
9078
+ BoundsHelper.set(bounds, start.x - total.x, start.y - total.y, total.x, total.y);
9079
+ BoundsHelper.unsign(bounds);
9080
+ return bounds;
9081
+ }
9001
9082
  assignMove(total) {
9002
9083
  move.x = total ? this.totalX : this.moveX;
9003
9084
  move.y = total ? this.totalY : this.moveY;
@@ -9614,7 +9695,8 @@ const config = {
9614
9695
  swipeDistance: 20,
9615
9696
  preventDefaultMenu: true
9616
9697
  },
9617
- cursor: {}
9698
+ cursor: {},
9699
+ keyEvent: true
9618
9700
  };
9619
9701
 
9620
9702
  const { pathHasEventType, getMoveEventData, getZoomEventData, getRotateEventData } = InteractionHelper;
@@ -9764,6 +9846,8 @@ class InteractionBase {
9764
9846
  this.transformer.transformEnd();
9765
9847
  }
9766
9848
  keyDown(data) {
9849
+ if (!this.config.keyEvent)
9850
+ return;
9767
9851
  const { code } = data;
9768
9852
  if (!this.downKeyMap[code]) {
9769
9853
  this.downKeyMap[code] = true;
@@ -9777,6 +9861,8 @@ class InteractionBase {
9777
9861
  this.emit(KeyEvent.DOWN, data, this.defaultPath);
9778
9862
  }
9779
9863
  keyUp(data) {
9864
+ if (!this.config.keyEvent)
9865
+ return;
9780
9866
  const { code } = data;
9781
9867
  this.downKeyMap[code] = false;
9782
9868
  Keyboard.setUpCode(code);
@@ -10077,27 +10163,6 @@ class HitCanvasManager extends CanvasManager {
10077
10163
  }
10078
10164
  }
10079
10165
 
10080
- const canvas$1 = LeaferCanvasBase.prototype;
10081
- canvas$1.hitFill = function (point, fillRule) {
10082
- return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y);
10083
- };
10084
- canvas$1.hitStroke = function (point, strokeWidth) {
10085
- this.strokeWidth = strokeWidth;
10086
- return this.context.isPointInStroke(point.x, point.y);
10087
- };
10088
- canvas$1.hitPixel = function (radiusPoint, offset, scale = 1) {
10089
- let { x, y, radiusX, radiusY } = radiusPoint;
10090
- if (offset)
10091
- x -= offset.x, y -= offset.y;
10092
- tempBounds$1.set(x - radiusX, y - radiusY, radiusX * 2, radiusY * 2).scale(scale).ceil();
10093
- const { data } = this.context.getImageData(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
10094
- for (let i = 0, len = data.length; i < len; i += 4) {
10095
- if (data[i + 3] > 0)
10096
- return true;
10097
- }
10098
- return data[3] > 0;
10099
- };
10100
-
10101
10166
  const { toInnerRadiusPointOf, copy: copy$2, setRadius } = PointHelper;
10102
10167
  const inner = {};
10103
10168
  const leaf = Leaf.prototype;
@@ -10134,7 +10199,7 @@ const matrix = new Matrix();
10134
10199
  const ui$2 = UI.prototype;
10135
10200
  ui$2.__updateHitCanvas = function () {
10136
10201
  const data = this.__, { hitCanvasManager } = this.leafer;
10137
- const isHitPixelFill = data.__pixelFill && data.hitFill === 'pixel';
10202
+ const isHitPixelFill = (data.__pixelFill || data.__isCanvas) && data.hitFill === 'pixel';
10138
10203
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
10139
10204
  const isHitPixel = isHitPixelFill || isHitPixelStroke;
10140
10205
  if (!this.__hitCanvas)
@@ -10166,11 +10231,11 @@ ui$2.__hit = function (inner) {
10166
10231
  if (data.__isHitPixel && this.__hitPixel(inner))
10167
10232
  return true;
10168
10233
  const { hitFill } = data;
10169
- const needHitFillPath = ((data.fill && hitFill == 'path') || hitFill === 'all');
10234
+ const needHitFillPath = ((data.fill || data.__isCanvas) && (hitFill === 'path' || (hitFill === 'pixel' && !(data.__pixelFill || data.__isCanvas)))) || hitFill === 'all';
10170
10235
  if (needHitFillPath && this.__hitFill(inner))
10171
10236
  return true;
10172
10237
  const { hitStroke, __strokeWidth } = data;
10173
- const needHitStrokePath = ((data.stroke && hitStroke == 'path') || hitStroke === 'all');
10238
+ const needHitStrokePath = (data.stroke && (hitStroke === 'path' || (hitStroke === 'pixel' && !data.__pixelStroke))) || hitStroke === 'all';
10174
10239
  if (!needHitFillPath && !needHitStrokePath)
10175
10240
  return false;
10176
10241
  const radiusWidth = inner.radiusX * 2;
@@ -10202,8 +10267,10 @@ ui$2.__hit = function (inner) {
10202
10267
  const ui$1 = new UI();
10203
10268
  const rect = Rect.prototype;
10204
10269
  rect.__updateHitCanvas = function () {
10205
- if (this.stroke || this.cornerRadius)
10270
+ if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
10206
10271
  ui$1.__updateHitCanvas.call(this);
10272
+ else if (this.__hitCanvas)
10273
+ this.__hitCanvas = null;
10207
10274
  };
10208
10275
  rect.__hitFill = function (inner) {
10209
10276
  return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
@@ -10223,6 +10290,27 @@ group.pick = function (hitPoint, options) {
10223
10290
  return this.leafer ? this.leafer.selector.getByPoint(hitPoint, options.hitRadius || 0, Object.assign(Object.assign({}, options), { target: this })) : null;
10224
10291
  };
10225
10292
 
10293
+ const canvas$1 = LeaferCanvasBase.prototype;
10294
+ canvas$1.hitFill = function (point, fillRule) {
10295
+ return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y);
10296
+ };
10297
+ canvas$1.hitStroke = function (point, strokeWidth) {
10298
+ this.strokeWidth = strokeWidth;
10299
+ return this.context.isPointInStroke(point.x, point.y);
10300
+ };
10301
+ canvas$1.hitPixel = function (radiusPoint, offset, scale = 1) {
10302
+ let { x, y, radiusX, radiusY } = radiusPoint;
10303
+ if (offset)
10304
+ x -= offset.x, y -= offset.y;
10305
+ tempBounds$1.set(x - radiusX, y - radiusY, radiusX * 2, radiusY * 2).scale(scale).ceil();
10306
+ const { data } = this.context.getImageData(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width || 1, tempBounds$1.height || 1);
10307
+ for (let i = 0, len = data.length; i < len; i += 4) {
10308
+ if (data[i + 3] > 0)
10309
+ return true;
10310
+ }
10311
+ return data[3] > 0;
10312
+ };
10313
+
10226
10314
  const PointerEventHelper = {
10227
10315
  convertTouch(e, local) {
10228
10316
  const touch = PointerEventHelper.getTouch(e);
@@ -10612,7 +10700,7 @@ function getLeafPaint(attrName, paint, ui) {
10612
10700
  case 'angular':
10613
10701
  return PaintGradient.conicGradient(paint, boxBounds);
10614
10702
  default:
10615
- return paint.r ? { type: 'solid', style: ColorConvert.string(paint) } : undefined;
10703
+ return paint.r !== undefined ? { type: 'solid', style: ColorConvert.string(paint) } : undefined;
10616
10704
  }
10617
10705
  }
10618
10706
 
@@ -10629,17 +10717,17 @@ const PaintModule = {
10629
10717
  };
10630
10718
 
10631
10719
  let origin = {};
10632
- const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
10720
+ const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate } = MatrixHelper;
10633
10721
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10634
- const transform = get$4();
10722
+ const transform = get$3();
10635
10723
  translate$1(transform, box.x + x, box.y + y);
10636
10724
  scaleHelper(transform, scaleX, scaleY);
10637
10725
  if (rotation)
10638
- rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10726
+ rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10639
10727
  data.transform = transform;
10640
10728
  }
10641
10729
  function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
10642
- const transform = get$4();
10730
+ const transform = get$3();
10643
10731
  translate$1(transform, box.x + x, box.y + y);
10644
10732
  if (scaleX)
10645
10733
  scaleHelper(transform, scaleX, scaleY);
@@ -10648,10 +10736,10 @@ function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
10648
10736
  data.transform = transform;
10649
10737
  }
10650
10738
  function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
10651
- const transform = get$4();
10739
+ const transform = get$3();
10652
10740
  if (rotation) {
10653
10741
  if (align === 'center') {
10654
- rotateOfOuter$2(transform, { x: width / 2, y: height / 2 }, rotation);
10742
+ rotateOfOuter$1(transform, { x: width / 2, y: height / 2 }, rotation);
10655
10743
  }
10656
10744
  else {
10657
10745
  rotate(transform, rotation);
@@ -10672,22 +10760,26 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
10672
10760
  origin.y = box.y + y;
10673
10761
  translate$1(transform, origin.x, origin.y);
10674
10762
  if (scaleX)
10675
- scaleOfOuter$2(transform, origin, scaleX, scaleY);
10763
+ scaleOfOuter$1(transform, origin, scaleX, scaleY);
10676
10764
  data.transform = transform;
10677
10765
  }
10678
10766
 
10679
- const { get: get$3, translate } = MatrixHelper;
10767
+ const { get: get$2, translate } = MatrixHelper;
10680
10768
  const tempBox = new Bounds();
10681
10769
  const tempPoint = {};
10682
10770
  function createData(leafPaint, image, paint, box) {
10771
+ const { blendMode } = paint;
10772
+ if (blendMode)
10773
+ leafPaint.blendMode = blendMode;
10774
+ leafPaint.data = getPatternData(paint, box, image);
10775
+ }
10776
+ function getPatternData(paint, box, image) {
10683
10777
  let { width, height } = image;
10684
10778
  if (paint.padding)
10685
10779
  box = tempBox.set(box).shrink(paint.padding);
10686
- const { opacity, mode, align, offset, scale, size, rotation, blendMode, repeat } = paint;
10780
+ const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
10687
10781
  const sameBox = box.width === width && box.height === height;
10688
- if (blendMode)
10689
- leafPaint.blendMode = blendMode;
10690
- const data = leafPaint.data = { mode };
10782
+ const data = { mode };
10691
10783
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
10692
10784
  const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
10693
10785
  let x = 0, y = 0, scaleX, scaleY;
@@ -10739,7 +10831,7 @@ function createData(leafPaint, image, paint, box) {
10739
10831
  }
10740
10832
  if (!data.transform) {
10741
10833
  if (box.x || box.y) {
10742
- data.transform = get$3();
10834
+ data.transform = get$2();
10743
10835
  translate(data.transform, box.x, box.y);
10744
10836
  }
10745
10837
  }
@@ -10753,6 +10845,7 @@ function createData(leafPaint, image, paint, box) {
10753
10845
  data.opacity = opacity;
10754
10846
  if (repeat)
10755
10847
  data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
10848
+ return data;
10756
10849
  }
10757
10850
 
10758
10851
  let cache, box = new Bounds();
@@ -10842,7 +10935,7 @@ function ignoreRender(ui, value) {
10842
10935
  leafer.renderer.ignore = value;
10843
10936
  }
10844
10937
 
10845
- const { get: get$2, scale, copy: copy$1 } = MatrixHelper;
10938
+ const { get: get$1, scale, copy: copy$1 } = MatrixHelper;
10846
10939
  const { ceil, abs: abs$1 } = Math;
10847
10940
  function createPattern(ui, paint, pixelRatio) {
10848
10941
  let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
@@ -10853,7 +10946,7 @@ function createPattern(ui, paint, pixelRatio) {
10853
10946
  const { image, data } = paint;
10854
10947
  let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data;
10855
10948
  if (sx) {
10856
- imageMatrix = get$2();
10949
+ imageMatrix = get$1();
10857
10950
  copy$1(imageMatrix, transform);
10858
10951
  scale(imageMatrix, 1 / sx, 1 / sy);
10859
10952
  scaleX *= sx;
@@ -10888,7 +10981,7 @@ function createPattern(ui, paint, pixelRatio) {
10888
10981
  }
10889
10982
  if (transform || scaleX !== 1 || scaleY !== 1) {
10890
10983
  if (!imageMatrix) {
10891
- imageMatrix = get$2();
10984
+ imageMatrix = get$1();
10892
10985
  if (transform)
10893
10986
  copy$1(imageMatrix, transform);
10894
10987
  }
@@ -10989,13 +11082,14 @@ function recycleImage(attrName, data) {
10989
11082
 
10990
11083
  const PaintImageModule = {
10991
11084
  image,
11085
+ checkImage,
11086
+ createPattern,
11087
+ recycleImage,
10992
11088
  createData,
11089
+ getPatternData,
10993
11090
  fillOrFitMode,
10994
11091
  clipMode,
10995
- repeatMode,
10996
- createPattern,
10997
- checkImage,
10998
- recycleImage
11092
+ repeatMode
10999
11093
  };
11000
11094
 
11001
11095
  const { toPoint: toPoint$2 } = AroundHelper;
@@ -11025,8 +11119,8 @@ function applyStops(gradient, stops, opacity) {
11025
11119
  }
11026
11120
  }
11027
11121
 
11028
- const { getAngle: getAngle$1, getDistance: getDistance$1 } = PointHelper;
11029
- const { get: get$1, rotateOfOuter: rotateOfOuter$1, scaleOfOuter: scaleOfOuter$1 } = MatrixHelper;
11122
+ const { getAngle, getDistance: getDistance$1 } = PointHelper;
11123
+ const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
11030
11124
  const { toPoint: toPoint$1 } = AroundHelper;
11031
11125
  const realFrom$1 = {};
11032
11126
  const realTo$1 = {};
@@ -11034,23 +11128,35 @@ function radialGradient(paint, box) {
11034
11128
  let { from, to, type, opacity, blendMode, stretch } = paint;
11035
11129
  toPoint$1(from || 'center', box, realFrom$1);
11036
11130
  toPoint$1(to || 'bottom', box, realTo$1);
11037
- const { width, height } = box;
11038
- let transform;
11039
- if (width !== height || stretch) {
11040
- transform = get$1();
11041
- scaleOfOuter$1(transform, realFrom$1, width / height * (stretch || 1), 1);
11042
- rotateOfOuter$1(transform, realFrom$1, getAngle$1(realFrom$1, realTo$1) + 90);
11043
- }
11044
11131
  const style = Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$1(realFrom$1, realTo$1));
11045
11132
  applyStops(style, paint.stops, opacity);
11046
- const data = { type, style, transform };
11133
+ const data = { type, style };
11134
+ const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
11135
+ if (transform)
11136
+ data.transform = transform;
11047
11137
  if (blendMode)
11048
11138
  data.blendMode = blendMode;
11049
11139
  return data;
11050
11140
  }
11141
+ function getTransform(box, from, to, stretch, rotate90) {
11142
+ let transform;
11143
+ const { width, height } = box;
11144
+ if (width !== height || stretch) {
11145
+ const angle = getAngle(from, to);
11146
+ transform = get();
11147
+ if (rotate90) {
11148
+ scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
11149
+ rotateOfOuter(transform, from, angle + 90);
11150
+ }
11151
+ else {
11152
+ scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
11153
+ rotateOfOuter(transform, from, angle);
11154
+ }
11155
+ }
11156
+ return transform;
11157
+ }
11051
11158
 
11052
- const { getAngle, getDistance } = PointHelper;
11053
- const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
11159
+ const { getDistance } = PointHelper;
11054
11160
  const { toPoint } = AroundHelper;
11055
11161
  const realFrom = {};
11056
11162
  const realTo = {};
@@ -11058,20 +11164,12 @@ function conicGradient(paint, box) {
11058
11164
  let { from, to, type, opacity, blendMode, stretch } = paint;
11059
11165
  toPoint(from || 'center', box, realFrom);
11060
11166
  toPoint(to || 'bottom', box, realTo);
11061
- const { width, height } = box;
11062
- const transform = get();
11063
- const angle = getAngle(realFrom, realTo);
11064
- if (Platform.conicGradientRotate90) {
11065
- scaleOfOuter(transform, realFrom, width / height * (stretch || 1), 1);
11066
- rotateOfOuter(transform, realFrom, angle + 90);
11067
- }
11068
- else {
11069
- scaleOfOuter(transform, realFrom, 1, width / height * (stretch || 1));
11070
- rotateOfOuter(transform, realFrom, angle);
11071
- }
11072
11167
  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));
11073
11168
  applyStops(style, paint.stops, opacity);
11074
- const data = { type, style, transform };
11169
+ const data = { type, style };
11170
+ const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
11171
+ if (transform)
11172
+ data.transform = transform;
11075
11173
  if (blendMode)
11076
11174
  data.blendMode = blendMode;
11077
11175
  return data;
@@ -11080,7 +11178,8 @@ function conicGradient(paint, box) {
11080
11178
  const PaintGradientModule = {
11081
11179
  linearGradient,
11082
11180
  radialGradient,
11083
- conicGradient
11181
+ conicGradient,
11182
+ getTransform
11084
11183
  };
11085
11184
 
11086
11185
  const { copy, toOffsetOutBounds: toOffsetOutBounds$1 } = BoundsHelper;
@@ -11806,11 +11905,21 @@ const ExportModule = {
11806
11905
  resolve();
11807
11906
  this.running = false;
11808
11907
  };
11908
+ const { toURL } = Platform;
11909
+ const { download } = Platform.origin;
11910
+ const fileType = FileHelper.fileType(filename);
11809
11911
  if (filename === 'json') {
11810
11912
  return over({ data: leaf.toJSON() });
11811
11913
  }
11812
- else if (FileHelper.fileType(filename) === 'json') {
11813
- Platform.origin.download('data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(leaf.toJSON())), filename);
11914
+ else if (fileType === 'json') {
11915
+ download(toURL(JSON.stringify(leaf.toJSON()), 'text'), filename);
11916
+ return over({ data: true });
11917
+ }
11918
+ if (filename === 'svg') {
11919
+ return over({ data: leaf.toSVG() });
11920
+ }
11921
+ else if (fileType === 'svg') {
11922
+ download(toURL(leaf.toSVG(), 'svg'), filename);
11814
11923
  return over({ data: true });
11815
11924
  }
11816
11925
  const { leafer } = leaf;