@leafer-draw/miniapp 1.9.3 → 1.9.5

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.
@@ -54,7 +54,7 @@ function isUndefined(value) {
54
54
  }
55
55
 
56
56
  function isNull(value) {
57
- return value === undefined || value === null;
57
+ return value == null;
58
58
  }
59
59
 
60
60
  function isString(value) {
@@ -136,6 +136,9 @@ class LeafData {
136
136
  const {path: path} = this;
137
137
  return path && path.length === 6 && path[0] === 1;
138
138
  }
139
+ get __usePathBox() {
140
+ return this.__pathInputed;
141
+ }
139
142
  get __blendMode() {
140
143
  if (this.eraser && this.eraser !== "path") return "destination-out";
141
144
  const {blendMode: blendMode} = this;
@@ -304,6 +307,9 @@ const MathHelper = {
304
307
  num = round$3(num * a) / a;
305
308
  return num === -0 ? 0 : num;
306
309
  },
310
+ sign(num) {
311
+ return num < 0 ? -1 : 1;
312
+ },
307
313
  getScaleData(scale, size, originSize, scaleData) {
308
314
  if (!scaleData) scaleData = {};
309
315
  if (size) {
@@ -1131,13 +1137,13 @@ const AlignHelper = {
1131
1137
  }
1132
1138
  };
1133
1139
 
1134
- const {tempPointBounds: tempPointBounds$1, setPoint: setPoint$2, addPoint: addPoint$2, toBounds: toBounds$3} = TwoPointBoundsHelper;
1140
+ const {tempPointBounds: tempPointBounds$1, setPoint: setPoint$2, addPoint: addPoint$2, toBounds: toBounds$2} = TwoPointBoundsHelper;
1135
1141
 
1136
1142
  const {toOuterPoint: toOuterPoint$2} = MatrixHelper;
1137
1143
 
1138
1144
  const {float: float, fourNumber: fourNumber} = MathHelper;
1139
1145
 
1140
- const {floor: floor$2, ceil: ceil$1} = Math;
1146
+ const {floor: floor$2, ceil: ceil$2} = Math;
1141
1147
 
1142
1148
  let right$1, bottom$1, boundsRight, boundsBottom;
1143
1149
 
@@ -1266,7 +1272,7 @@ const BoundsHelper = {
1266
1272
  point.x = t.x;
1267
1273
  toOuterPoint$2(matrix, point, toPoint$4);
1268
1274
  addPoint$2(tempPointBounds$1, toPoint$4.x, toPoint$4.y);
1269
- toBounds$3(tempPointBounds$1, to);
1275
+ toBounds$2(tempPointBounds$1, to);
1270
1276
  }
1271
1277
  },
1272
1278
  toInnerOf(t, matrix, to) {
@@ -1304,8 +1310,8 @@ const BoundsHelper = {
1304
1310
  const {x: x, y: y} = t;
1305
1311
  t.x = floor$2(t.x);
1306
1312
  t.y = floor$2(t.y);
1307
- t.width = x > t.x ? ceil$1(t.width + x - t.x) : ceil$1(t.width);
1308
- t.height = y > t.y ? ceil$1(t.height + y - t.y) : ceil$1(t.height);
1313
+ t.width = x > t.x ? ceil$2(t.width + x - t.x) : ceil$2(t.width);
1314
+ t.height = y > t.y ? ceil$2(t.height + y - t.y) : ceil$2(t.height);
1309
1315
  },
1310
1316
  unsign(t) {
1311
1317
  if (t.width < 0) {
@@ -1365,7 +1371,7 @@ const BoundsHelper = {
1365
1371
  },
1366
1372
  setPoints(t, points) {
1367
1373
  points.forEach((point, index) => index === 0 ? setPoint$2(tempPointBounds$1, point.x, point.y) : addPoint$2(tempPointBounds$1, point.x, point.y));
1368
- toBounds$3(tempPointBounds$1, t);
1374
+ toBounds$2(tempPointBounds$1, t);
1369
1375
  },
1370
1376
  setPoint(t, point) {
1371
1377
  B.set(t, point.x, point.y);
@@ -2218,15 +2224,15 @@ class LeaferCanvasBase extends Canvas$1 {
2218
2224
  DataHelper.copyAttrs(s, size, canvasSizeAttrs);
2219
2225
  canvasSizeAttrs.forEach(key => s[key] || (s[key] = 1));
2220
2226
  this.bounds = new Bounds(0, 0, this.width, this.height);
2221
- if (this.context && !this.unreal) {
2222
- this.updateViewSize();
2223
- this.smooth = this.config.smooth;
2224
- }
2227
+ this.updateViewSize();
2225
2228
  this.updateClientBounds();
2226
- if (this.context && !this.unreal && takeCanvas) {
2227
- this.clearWorld(takeCanvas.bounds);
2228
- this.copyWorld(takeCanvas);
2229
- takeCanvas.recycle();
2229
+ if (this.context) {
2230
+ this.smooth = this.config.smooth;
2231
+ if (!this.unreal && takeCanvas) {
2232
+ this.clearWorld(takeCanvas.bounds);
2233
+ this.copyWorld(takeCanvas);
2234
+ takeCanvas.recycle();
2235
+ }
2230
2236
  }
2231
2237
  }
2232
2238
  updateViewSize() {}
@@ -2540,7 +2546,7 @@ const RectHelper = {
2540
2546
  }
2541
2547
  };
2542
2548
 
2543
- const {sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil, abs: abs$2, PI: PI$2, sqrt: sqrt$1, pow: pow} = Math;
2549
+ const {sin: sin$3, cos: cos$3, hypot: hypot, atan2: atan2$1, ceil: ceil$1, abs: abs$2, PI: PI$2, sqrt: sqrt$1, pow: pow} = Math;
2544
2550
 
2545
2551
  const {setPoint: setPoint$1, addPoint: addPoint$1} = TwoPointBoundsHelper;
2546
2552
 
@@ -2611,9 +2617,11 @@ const BezierHelper = {
2611
2617
  const CBy = toY - y1;
2612
2618
  let startRadian = atan2$1(BAy, BAx);
2613
2619
  let endRadian = atan2$1(CBy, CBx);
2620
+ const lenBA = hypot(BAx, BAy);
2621
+ const lenCB = hypot(CBx, CBy);
2614
2622
  let totalRadian = endRadian - startRadian;
2615
2623
  if (totalRadian < 0) totalRadian += PI2;
2616
- if (totalRadian === PI$2 || abs$2(BAx + BAy) < 1e-12 || abs$2(CBx + CBy) < 1e-12) {
2624
+ if (lenBA < 1e-12 || lenCB < 1e-12 || totalRadian < 1e-12 || abs$2(totalRadian - PI$2) < 1e-12) {
2617
2625
  if (data) data.push(L$6, x1, y1);
2618
2626
  if (setPointBounds) {
2619
2627
  setPoint$1(setPointBounds, fromX, fromY);
@@ -2646,7 +2654,7 @@ const BezierHelper = {
2646
2654
  let totalRadian = endRadian - startRadian;
2647
2655
  if (totalRadian < 0) totalRadian += PI2; else if (totalRadian > PI2) totalRadian -= PI2;
2648
2656
  if (anticlockwise) totalRadian -= PI2;
2649
- const parts = ceil(abs$2(totalRadian / PI_2));
2657
+ const parts = ceil$1(abs$2(totalRadian / PI_2));
2650
2658
  const partRadian = totalRadian / parts;
2651
2659
  const partRadian4Sin = sin$3(partRadian / 4);
2652
2660
  const control = 8 / 3 * partRadian4Sin * partRadian4Sin / sin$3(partRadian / 2);
@@ -3205,11 +3213,7 @@ class PathCreator {
3205
3213
  this.set(path);
3206
3214
  }
3207
3215
  set(path) {
3208
- if (path) {
3209
- this.__path = isString(path) ? PathHelper.parse(path) : path;
3210
- } else {
3211
- this.__path = [];
3212
- }
3216
+ this.__path = path ? isString(path) ? PathHelper.parse(path) : path : [];
3213
3217
  return this;
3214
3218
  }
3215
3219
  beginPath() {
@@ -3377,7 +3381,7 @@ const {M: M$1, L: L$2, C: C, Q: Q, Z: Z$1, N: N, D: D$1, X: X, G: G, F: F$1, O:
3377
3381
 
3378
3382
  const {toTwoPointBounds: toTwoPointBounds, toTwoPointBoundsByQuadraticCurve: toTwoPointBoundsByQuadraticCurve, arcTo: arcTo$1, arc: arc, ellipse: ellipse$1} = BezierHelper;
3379
3383
 
3380
- const {addPointBounds: addPointBounds, copy: copy$6, addPoint: addPoint, setPoint: setPoint, addBounds: addBounds, toBounds: toBounds$2} = TwoPointBoundsHelper;
3384
+ const {addPointBounds: addPointBounds, copy: copy$6, addPoint: addPoint, setPoint: setPoint, addBounds: addBounds, toBounds: toBounds$1} = TwoPointBoundsHelper;
3381
3385
 
3382
3386
  const debug$9 = Debug.get("PathBounds");
3383
3387
 
@@ -3392,7 +3396,7 @@ const setEndPoint = {};
3392
3396
  const PathBounds = {
3393
3397
  toBounds(data, setBounds) {
3394
3398
  PathBounds.toTwoPointBounds(data, setPointBounds);
3395
- toBounds$2(setPointBounds, setBounds);
3399
+ toBounds$1(setPointBounds, setBounds);
3396
3400
  },
3397
3401
  toTwoPointBounds(data, setPointBounds) {
3398
3402
  if (!data || !data.length) return setPoint(setPointBounds, 0, 0);
@@ -3579,14 +3583,18 @@ const PathCorner = {
3579
3583
  }
3580
3584
  };
3581
3585
 
3582
- PathHelper.creator = new PathCreator;
3586
+ function path(path) {
3587
+ return new PathCreator(path);
3588
+ }
3589
+
3590
+ const pen = path();
3591
+
3592
+ PathHelper.creator = path();
3583
3593
 
3584
3594
  PathHelper.parse = PathConvert.parse;
3585
3595
 
3586
3596
  PathHelper.convertToCanvasData = PathConvert.toCanvasData;
3587
3597
 
3588
- const pen = new PathCreator;
3589
-
3590
3598
  const {drawRoundRect: drawRoundRect} = RectHelper;
3591
3599
 
3592
3600
  function roundRect(drawer) {
@@ -3951,7 +3959,7 @@ const ImageManager = {
3951
3959
  return FileHelper.alphaPixelTypes.some(item => I.isFormat(item, config));
3952
3960
  },
3953
3961
  isFormat(format, config) {
3954
- if (config.format === format) return true;
3962
+ if (config.format) return config.format === format;
3955
3963
  const {url: url} = config;
3956
3964
  if (url.startsWith("data:")) {
3957
3965
  if (url.startsWith("data:" + FileHelper.mineType(format))) return true;
@@ -4045,7 +4053,7 @@ class LeaferImage {
4045
4053
  getFull(_filters) {
4046
4054
  return this.view;
4047
4055
  }
4048
- getCanvas(width, height, opacity, _filters, xGap, yGap) {
4056
+ getCanvas(width, height, opacity, _filters, xGap, yGap, smooth) {
4049
4057
  width || (width = this.width);
4050
4058
  height || (height = this.height);
4051
4059
  if (this.cache) {
@@ -4061,6 +4069,7 @@ class LeaferImage {
4061
4069
  const canvas = Platform.origin.createCanvas(max$1(floor$1(width + (xGap || 0)), 1), max$1(floor$1(height + (yGap || 0)), 1));
4062
4070
  const ctx = canvas.getContext("2d");
4063
4071
  if (opacity) ctx.globalAlpha = opacity;
4072
+ ctx.imageSmoothingEnabled = smooth === false ? false : true;
4064
4073
  ctx.drawImage(this.view, 0, 0, width, height);
4065
4074
  this.cache = this.use > 1 ? {
4066
4075
  data: canvas,
@@ -4102,7 +4111,7 @@ function createDescriptor(key, defaultValue) {
4102
4111
  return {
4103
4112
  get() {
4104
4113
  const v = this[privateKey];
4105
- return isUndefined(v) ? defaultValue : v;
4114
+ return v == null ? defaultValue : v;
4106
4115
  },
4107
4116
  set(value) {
4108
4117
  this[privateKey] = value;
@@ -4388,21 +4397,21 @@ function defineDataProcessor(target, key, defaultValue) {
4388
4397
  };
4389
4398
  } else if (typeof defaultValue === "function") {
4390
4399
  property.get = function() {
4391
- let v = this[computedKey];
4392
- return v === undefined ? defaultValue(this.__leaf) : v;
4400
+ const v = this[computedKey];
4401
+ return v == null ? defaultValue(this.__leaf) : v;
4393
4402
  };
4394
4403
  } else if (isObject(defaultValue)) {
4395
4404
  const isEmpty = isEmptyData(defaultValue);
4396
4405
  property.get = function() {
4397
- let v = this[computedKey];
4398
- return v === undefined ? this[computedKey] = isEmpty ? {} : DataHelper.clone(defaultValue) : v;
4406
+ const v = this[computedKey];
4407
+ return v == null ? this[computedKey] = isEmpty ? {} : DataHelper.clone(defaultValue) : v;
4399
4408
  };
4400
4409
  }
4401
4410
  const isBox = target.isBranchLeaf;
4402
4411
  if (key === "width") {
4403
4412
  property.get = function() {
4404
4413
  const v = this[computedKey];
4405
- if (v === undefined) {
4414
+ if (v == null) {
4406
4415
  const t = this, naturalWidth = t.__naturalWidth, leaf = t.__leaf;
4407
4416
  if (!defaultValue || leaf.pathInputed) return leaf.boxBounds.width;
4408
4417
  if (naturalWidth) return t._height && t.__useNaturalRatio ? t._height * naturalWidth / t.__naturalHeight : naturalWidth;
@@ -4412,7 +4421,7 @@ function defineDataProcessor(target, key, defaultValue) {
4412
4421
  } else if (key === "height") {
4413
4422
  property.get = function() {
4414
4423
  const v = this[computedKey];
4415
- if (v === undefined) {
4424
+ if (v == null) {
4416
4425
  const t = this, naturalHeight = t.__naturalHeight, leaf = t.__leaf;
4417
4426
  if (!defaultValue || leaf.pathInputed) return leaf.boxBounds.height;
4418
4427
  if (naturalHeight) return t._width && t.__useNaturalRatio ? t._width * naturalHeight / t.__naturalWidth : naturalHeight;
@@ -4712,8 +4721,9 @@ const L = LeafHelper;
4712
4721
 
4713
4722
  const {updateAllMatrix: updateAllMatrix$3, updateMatrix: updateMatrix$2, updateAllWorldOpacity: updateAllWorldOpacity, updateAllChange: updateAllChange$1, updateChange: updateChange$1} = L;
4714
4723
 
4715
- function getTempLocal(t, world) {
4716
- return t.parent ? PointHelper.tempToInnerOf(world, t.parent.scrollWorldTransform) : world;
4724
+ function getTempLocal(t, worldPoint) {
4725
+ t.updateLayout();
4726
+ return t.parent ? PointHelper.tempToInnerOf(worldPoint, t.parent.scrollWorldTransform) : worldPoint;
4717
4727
  }
4718
4728
 
4719
4729
  const LeafBoundsHelper = {
@@ -5172,7 +5182,7 @@ class LeafLayout {
5172
5182
  }
5173
5183
  boxChange() {
5174
5184
  this.boxChanged = true;
5175
- this.localBoxChanged || this.localBoxChange();
5185
+ this.localBoxChanged ? this.boundsChanged || (this.boundsChanged = true) : this.localBoxChange();
5176
5186
  this.hitCanvasChanged = true;
5177
5187
  }
5178
5188
  localBoxChange() {
@@ -5206,7 +5216,7 @@ class LeafLayout {
5206
5216
  }
5207
5217
  matrixChange() {
5208
5218
  this.matrixChanged = true;
5209
- this.localBoxChanged || this.localBoxChange();
5219
+ this.localBoxChanged ? this.boundsChanged || (this.boundsChanged = true) : this.localBoxChange();
5210
5220
  }
5211
5221
  surfaceChange() {
5212
5222
  this.surfaceChanged = true;
@@ -5731,7 +5741,7 @@ const {updateBounds: updateBounds$1} = BranchHelper;
5731
5741
 
5732
5742
  const {toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$3} = BoundsHelper;
5733
5743
 
5734
- const {toBounds: toBounds$1} = PathBounds;
5744
+ const {toBounds: toBounds} = PathBounds;
5735
5745
 
5736
5746
  const LeafBounds = {
5737
5747
  __updateWorldBounds() {
@@ -5803,8 +5813,8 @@ const LeafBounds = {
5803
5813
  __updateBoxBounds(_secondLayout, _bounds) {
5804
5814
  const b = this.__layout.boxBounds;
5805
5815
  const data = this.__;
5806
- if (data.__pathInputed) {
5807
- toBounds$1(data.path, b);
5816
+ if (data.__usePathBox) {
5817
+ toBounds(data.path, b);
5808
5818
  } else {
5809
5819
  b.x = 0;
5810
5820
  b.y = 0;
@@ -6272,10 +6282,10 @@ let Leaf = class Leaf {
6272
6282
  relative.innerToWorld(world, to, distance);
6273
6283
  world = to ? to : world;
6274
6284
  }
6275
- toInnerPoint(this.worldTransform, world, to, distance);
6285
+ toInnerPoint(this.scrollWorldTransform, world, to, distance);
6276
6286
  }
6277
6287
  innerToWorld(inner, to, distance, relative) {
6278
- toOuterPoint(this.worldTransform, inner, to, distance);
6288
+ toOuterPoint(this.scrollWorldTransform, inner, to, distance);
6279
6289
  if (relative) relative.worldToInner(to ? to : inner, null, distance);
6280
6290
  }
6281
6291
  getBoxPoint(world, relative, distance, change) {
@@ -6739,7 +6749,7 @@ class LeafLevelList {
6739
6749
  }
6740
6750
  }
6741
6751
 
6742
- const version = "1.9.3";
6752
+ const version = "1.9.5";
6743
6753
 
6744
6754
  class LeaferCanvas extends LeaferCanvasBase {
6745
6755
  get allowBackgroundColor() {
@@ -6793,6 +6803,7 @@ class LeaferCanvas extends LeaferCanvasBase {
6793
6803
  this.view = Platform.origin.createCanvas(1, 1);
6794
6804
  }
6795
6805
  updateViewSize() {
6806
+ if (this.unreal) return;
6796
6807
  const {width: width, height: height, pixelRatio: pixelRatio} = this;
6797
6808
  this.view.width = Math.ceil(width * pixelRatio);
6798
6809
  this.view.height = Math.ceil(height * pixelRatio);
@@ -6804,6 +6815,7 @@ class LeaferCanvas extends LeaferCanvasBase {
6804
6815
  });
6805
6816
  }
6806
6817
  startAutoLayout(autoBounds, listener) {
6818
+ if (this.resizeListener) return;
6807
6819
  this.resizeListener = listener;
6808
6820
  if (autoBounds) {
6809
6821
  this.checkSize = this.checkSize.bind(this);
@@ -7313,7 +7325,7 @@ class Renderer {
7313
7325
  this.times = 0;
7314
7326
  this.config = {
7315
7327
  usePartRender: true,
7316
- maxFPS: 60
7328
+ maxFPS: 120
7317
7329
  };
7318
7330
  this.target = target;
7319
7331
  this.canvas = canvas;
@@ -7468,11 +7480,15 @@ class Renderer {
7468
7480
  if (this.requestTime || !target) return;
7469
7481
  if (target.parentApp) return target.parentApp.requestRender(false);
7470
7482
  const requestTime = this.requestTime = Date.now();
7471
- Platform.requestRender(() => {
7472
- this.FPS = Math.min(60, Math.ceil(1e3 / (Date.now() - requestTime)));
7483
+ const render = () => {
7484
+ const nowFPS = 1e3 / (Date.now() - requestTime);
7485
+ const {maxFPS: maxFPS} = this.config;
7486
+ if (maxFPS && nowFPS > maxFPS - .5) return Platform.requestRender(render);
7487
+ this.FPS = Math.min(120, Math.ceil(nowFPS));
7473
7488
  this.requestTime = 0;
7474
7489
  this.checkRender();
7475
- });
7490
+ };
7491
+ Platform.requestRender(render);
7476
7492
  }
7477
7493
  __onResize(e) {
7478
7494
  if (this.canvas.unreal) return;
@@ -7515,7 +7531,8 @@ class Renderer {
7515
7531
  if (this.target) {
7516
7532
  this.stop();
7517
7533
  this.__removeListenEvents();
7518
- this.target = this.canvas = this.config = null;
7534
+ this.config = {};
7535
+ this.target = this.canvas = null;
7519
7536
  }
7520
7537
  }
7521
7538
  }
@@ -7823,7 +7840,11 @@ class LeaferData extends GroupData {
7823
7840
 
7824
7841
  class FrameData extends BoxData {}
7825
7842
 
7826
- class LineData extends UIData {}
7843
+ class LineData extends UIData {
7844
+ get __usePathBox() {
7845
+ return this.points || this.__pathInputed;
7846
+ }
7847
+ }
7827
7848
 
7828
7849
  class RectData extends UIData {
7829
7850
  get __boxStroke() {
@@ -7837,7 +7858,7 @@ class EllipseData extends UIData {
7837
7858
  }
7838
7859
  }
7839
7860
 
7840
- class PolygonData extends UIData {}
7861
+ class PolygonData extends LineData {}
7841
7862
 
7842
7863
  class StarData extends UIData {}
7843
7864
 
@@ -8147,20 +8168,9 @@ let UI = UI_1 = class UI extends Leaf {
8147
8168
  if (!path) this.__drawPathByBox(pen);
8148
8169
  return pen;
8149
8170
  }
8150
- constructor(data) {
8151
- super(data);
8152
- }
8153
8171
  reset(_data) {}
8154
- set(data, transition) {
8155
- if (data) {
8156
- if (transition) {
8157
- if (transition === "temp") {
8158
- this.lockNormalStyle = true;
8159
- Object.assign(this, data);
8160
- this.lockNormalStyle = false;
8161
- } else this.animate(data, transition);
8162
- } else Object.assign(this, data);
8163
- }
8172
+ set(data, _transition) {
8173
+ if (data) Object.assign(this, data);
8164
8174
  }
8165
8175
  get(name) {
8166
8176
  return isString(name) ? this.__.__getInput(name) : this.__.__getInputData(name);
@@ -8206,7 +8216,7 @@ let UI = UI_1 = class UI extends Leaf {
8206
8216
  const data = this.__;
8207
8217
  if (data.path) {
8208
8218
  data.__pathForRender = data.cornerRadius ? PathCorner.smooth(data.path, data.cornerRadius, data.cornerSmoothing) : data.path;
8209
- if (data.__useArrow) PathArrow.addArrows(this, !data.cornerRadius);
8219
+ if (data.__useArrow) PathArrow.addArrows(this);
8210
8220
  } else data.__pathForRender && (data.__pathForRender = undefined);
8211
8221
  }
8212
8222
  __drawRenderPath(canvas) {
@@ -8230,7 +8240,8 @@ let UI = UI_1 = class UI extends Leaf {
8230
8240
  drawImagePlaceholder(canvas, _image) {
8231
8241
  Paint.fill(this.__.placeholderColor, this, canvas);
8232
8242
  }
8233
- animate(_keyframe, _options, _type, _isTemp) {
8243
+ animate(keyframe, _options, _type, _isTemp) {
8244
+ this.set(keyframe);
8234
8245
  return Plugin.need("animate");
8235
8246
  }
8236
8247
  killAnimate(_type, _nextStyle) {}
@@ -8419,9 +8430,6 @@ let Group = class Group extends UI {
8419
8430
  get isBranch() {
8420
8431
  return true;
8421
8432
  }
8422
- constructor(data) {
8423
- super(data);
8424
- }
8425
8433
  reset(data) {
8426
8434
  this.__setBranch();
8427
8435
  super.reset(data);
@@ -8546,7 +8554,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8546
8554
  const canvas = this.canvas = Creator.canvas(config);
8547
8555
  this.__controllers.push(this.renderer = Creator.renderer(this, canvas, config), this.watcher = Creator.watcher(this, config), this.layouter = Creator.layouter(this, config));
8548
8556
  if (this.isApp) this.__setApp();
8549
- this.__checkAutoLayout(config, parentApp);
8557
+ this.__checkAutoLayout();
8550
8558
  this.view = canvas.view;
8551
8559
  if (!parentApp) {
8552
8560
  this.selector = Creator.selector(this);
@@ -8645,7 +8653,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8645
8653
  this.leafer = leafer;
8646
8654
  this.__level = 1;
8647
8655
  }
8648
- __checkAutoLayout(config, parentApp) {
8656
+ __checkAutoLayout() {
8657
+ const {config: config, parentApp: parentApp} = this;
8649
8658
  if (!parentApp) {
8650
8659
  if (!config.width || !config.height) this.autoLayout = new AutoBounds(config);
8651
8660
  this.canvas.startAutoLayout(this.autoLayout, this.__onResize.bind(this));
@@ -8671,9 +8680,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8671
8680
  return super.__getAttr(attrName);
8672
8681
  }
8673
8682
  __changeCanvasSize(attrName, newValue) {
8674
- const data = DataHelper.copyAttrs({}, this.canvas, canvasSizeAttrs);
8675
- data[attrName] = this.config[attrName] = newValue;
8676
- if (newValue) this.canvas.stopAutoLayout();
8683
+ const {config: config, canvas: canvas} = this;
8684
+ const data = DataHelper.copyAttrs({}, canvas, canvasSizeAttrs);
8685
+ data[attrName] = config[attrName] = newValue;
8686
+ config.width && config.height ? canvas.stopAutoLayout() : this.__checkAutoLayout();
8677
8687
  this.__doResize(data);
8678
8688
  }
8679
8689
  __changeFill(newValue) {
@@ -8820,9 +8830,9 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8820
8830
  if (!this.parent) {
8821
8831
  if (this.selector) this.selector.destroy();
8822
8832
  if (this.hitCanvasManager) this.hitCanvasManager.destroy();
8823
- this.canvasManager.destroy();
8833
+ if (this.canvasManager) this.canvasManager.destroy();
8824
8834
  }
8825
- this.canvas.destroy();
8835
+ if (this.canvas) this.canvas.destroy();
8826
8836
  this.config.view = this.view = this.parentApp = null;
8827
8837
  if (this.userConfig) this.userConfig.view = null;
8828
8838
  super.destroy();
@@ -8850,9 +8860,6 @@ let Rect = class Rect extends UI {
8850
8860
  get __tag() {
8851
8861
  return "Rect";
8852
8862
  }
8853
- constructor(data) {
8854
- super(data);
8855
- }
8856
8863
  };
8857
8864
 
8858
8865
  __decorate([ dataProcessor(RectData) ], Rect.prototype, "__", void 0);
@@ -8906,29 +8913,24 @@ let Box = class Box extends Group {
8906
8913
  }
8907
8914
  __updateStrokeBounds() {}
8908
8915
  __updateRenderBounds() {
8909
- let isOverflow;
8916
+ let isOverflow, isScrollMode;
8910
8917
  if (this.children.length) {
8911
- const data = this.__, layout = this.__layout, {renderBounds: renderBounds, boxBounds: boxBounds} = layout;
8918
+ const data = this.__, layout = this.__layout, {renderBounds: renderBounds, boxBounds: boxBounds} = layout, {overflow: overflow} = data;
8912
8919
  const childrenRenderBounds = layout.childrenRenderBounds || (layout.childrenRenderBounds = getBoundsData());
8913
8920
  super.__updateRenderBounds(childrenRenderBounds);
8914
- if (data.overflow.includes("scroll")) {
8921
+ if (isScrollMode = overflow.includes("scroll")) {
8915
8922
  add(childrenRenderBounds, boxBounds);
8916
8923
  scroll(childrenRenderBounds, data);
8917
8924
  }
8918
8925
  this.__updateRectRenderBounds();
8919
8926
  isOverflow = !includes$1(boxBounds, childrenRenderBounds);
8920
- if (isOverflow && data.overflow === "show") add(renderBounds, childrenRenderBounds);
8927
+ if (isOverflow && overflow === "show") add(renderBounds, childrenRenderBounds);
8921
8928
  } else this.__updateRectRenderBounds();
8922
8929
  DataHelper.stintSet(this, "isOverflow", isOverflow);
8923
- this.__checkScroll();
8930
+ this.__checkScroll(isScrollMode);
8924
8931
  }
8925
8932
  __updateRectRenderBounds() {}
8926
- __updateWorldBounds() {
8927
- if (this.hasScroller) this.__updateScroll();
8928
- super.__updateWorldBounds();
8929
- }
8930
- __checkScroll() {}
8931
- __updateScroll() {}
8933
+ __checkScroll(_isScrollMode) {}
8932
8934
  __updateRectChange() {}
8933
8935
  __updateChange() {
8934
8936
  super.__updateChange();
@@ -8989,9 +8991,6 @@ let Frame = class Frame extends Box {
8989
8991
  get isFrame() {
8990
8992
  return true;
8991
8993
  }
8992
- constructor(data) {
8993
- super(data);
8994
- }
8995
8994
  };
8996
8995
 
8997
8996
  __decorate([ dataProcessor(FrameData) ], Frame.prototype, "__", void 0);
@@ -9008,9 +9007,6 @@ let Ellipse = class Ellipse extends UI {
9008
9007
  get __tag() {
9009
9008
  return "Ellipse";
9010
9009
  }
9011
- constructor(data) {
9012
- super(data);
9013
- }
9014
9010
  __updatePath() {
9015
9011
  const {width: width, height: height, innerRadius: innerRadius, startAngle: startAngle, endAngle: endAngle} = this.__;
9016
9012
  const rx = width / 2, ry = height / 2;
@@ -9054,8 +9050,6 @@ const {moveTo: moveTo$2, lineTo: lineTo$2, drawPoints: drawPoints$1} = PathComma
9054
9050
 
9055
9051
  const {rotate: rotate$1, getAngle: getAngle$1, getDistance: getDistance$2, defaultPoint: defaultPoint} = PointHelper;
9056
9052
 
9057
- const {toBounds: toBounds} = PathBounds;
9058
-
9059
9053
  let Line = class Line extends UI {
9060
9054
  get __tag() {
9061
9055
  return "Line";
@@ -9072,31 +9066,16 @@ let Line = class Line extends UI {
9072
9066
  this.rotation = getAngle$1(defaultPoint, value);
9073
9067
  if (this.height) this.height = 0;
9074
9068
  }
9075
- constructor(data) {
9076
- super(data);
9077
- }
9078
9069
  __updatePath() {
9079
9070
  const data = this.__;
9080
9071
  const path = data.path = [];
9081
9072
  if (data.points) {
9082
- drawPoints$1(path, data.points, false, data.closed);
9073
+ drawPoints$1(path, data.points, data.curve, data.closed);
9083
9074
  } else {
9084
9075
  moveTo$2(path, 0, 0);
9085
9076
  lineTo$2(path, this.width, 0);
9086
9077
  }
9087
9078
  }
9088
- __updateRenderPath() {
9089
- const data = this.__;
9090
- if (!this.pathInputed && data.points && data.curve) {
9091
- drawPoints$1(data.__pathForRender = [], data.points, data.curve, data.closed);
9092
- if (data.__useArrow) PathArrow.addArrows(this, false);
9093
- } else super.__updateRenderPath();
9094
- }
9095
- __updateBoxBounds() {
9096
- if (this.points) {
9097
- toBounds(this.__.__pathForRender, this.__layout.boxBounds);
9098
- } else super.__updateBoxBounds();
9099
- }
9100
9079
  };
9101
9080
 
9102
9081
  __decorate([ dataProcessor(LineData) ], Line.prototype, "__", void 0);
@@ -9123,15 +9102,13 @@ let Polygon = class Polygon extends UI {
9123
9102
  get __tag() {
9124
9103
  return "Polygon";
9125
9104
  }
9126
- constructor(data) {
9127
- super(data);
9128
- }
9129
9105
  __updatePath() {
9130
- const path = this.__.path = [];
9131
- if (this.__.points) {
9132
- drawPoints(path, this.__.points, false, true);
9106
+ const data = this.__;
9107
+ const path = data.path = [];
9108
+ if (data.points) {
9109
+ drawPoints(path, data.points, data.curve, true);
9133
9110
  } else {
9134
- const {width: width, height: height, sides: sides} = this.__;
9111
+ const {width: width, height: height, sides: sides} = data;
9135
9112
  const rx = width / 2, ry = height / 2;
9136
9113
  moveTo$1(path, rx, 0);
9137
9114
  for (let i = 1; i < sides; i++) {
@@ -9166,9 +9143,6 @@ let Star = class Star extends UI {
9166
9143
  get __tag() {
9167
9144
  return "Star";
9168
9145
  }
9169
- constructor(data) {
9170
- super(data);
9171
- }
9172
9146
  __updatePath() {
9173
9147
  const {width: width, height: height, corners: corners, innerRadius: innerRadius} = this.__;
9174
9148
  const rx = width / 2, ry = height / 2;
@@ -9201,9 +9175,6 @@ let Image = class Image extends Rect {
9201
9175
  const {fill: fill} = this.__;
9202
9176
  return isArray(fill) && fill[0].image;
9203
9177
  }
9204
- constructor(data) {
9205
- super(data);
9206
- }
9207
9178
  };
9208
9179
 
9209
9180
  __decorate([ dataProcessor(ImageData) ], Image.prototype, "__", void 0);
@@ -9303,9 +9274,6 @@ let Text = class Text extends UI {
9303
9274
  this.updateLayout();
9304
9275
  return this.__.__textDrawData;
9305
9276
  }
9306
- constructor(data) {
9307
- super(data);
9308
- }
9309
9277
  __updateTextDrawData() {
9310
9278
  const data = this.__;
9311
9279
  const {lineHeight: lineHeight, letterSpacing: letterSpacing, fontFamily: fontFamily, fontSize: fontSize, fontWeight: fontWeight, italic: italic, textCase: textCase, textOverflow: textOverflow, padding: padding} = data;
@@ -9438,9 +9406,6 @@ let Path = class Path extends UI {
9438
9406
  get __tag() {
9439
9407
  return "Path";
9440
9408
  }
9441
- constructor(data) {
9442
- super(data);
9443
- }
9444
9409
  };
9445
9410
 
9446
9411
  __decorate([ dataProcessor(PathData) ], Path.prototype, "__", void 0);
@@ -9453,9 +9418,6 @@ let Pen = class Pen extends Group {
9453
9418
  get __tag() {
9454
9419
  return "Pen";
9455
9420
  }
9456
- constructor(data) {
9457
- super(data);
9458
- }
9459
9421
  setStyle(data) {
9460
9422
  const path = this.pathElement = new Path(data);
9461
9423
  this.pathStyle = data;
@@ -10151,7 +10113,7 @@ function ignoreRender(ui, value) {
10151
10113
 
10152
10114
  const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
10153
10115
 
10154
- const {floor: floor, max: max, abs: abs} = Math;
10116
+ const {floor: floor, ceil: ceil, max: max, abs: abs} = Math;
10155
10117
 
10156
10118
  function createPattern(ui, paint, pixelRatio) {
10157
10119
  let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
@@ -10161,8 +10123,6 @@ function createPattern(ui, paint, pixelRatio) {
10161
10123
  let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
10162
10124
  scaleX *= pixelRatio;
10163
10125
  scaleY *= pixelRatio;
10164
- const xGap = gap && gap.x * scaleX;
10165
- const yGap = gap && gap.y * scaleY;
10166
10126
  if (sx) {
10167
10127
  sx = abs(sx);
10168
10128
  sy = abs(sy);
@@ -10179,7 +10139,10 @@ function createPattern(ui, paint, pixelRatio) {
10179
10139
  if (size > Platform.image.maxCacheSize) return false;
10180
10140
  }
10181
10141
  let maxSize = Platform.image.maxPatternSize;
10182
- if (!image.isSVG) {
10142
+ if (image.isSVG) {
10143
+ const ws = width / image.width;
10144
+ if (ws > 1) imageScale = ws / ceil(ws);
10145
+ } else {
10183
10146
  const imageSize = image.width * image.height;
10184
10147
  if (maxSize > imageSize) maxSize = imageSize;
10185
10148
  }
@@ -10194,18 +10157,20 @@ function createPattern(ui, paint, pixelRatio) {
10194
10157
  scaleX /= sx;
10195
10158
  scaleY /= sy;
10196
10159
  }
10160
+ const xGap = gap && gap.x * scaleX;
10161
+ const yGap = gap && gap.y * scaleY;
10197
10162
  if (transform || scaleX !== 1 || scaleY !== 1) {
10163
+ const canvasWidth = width + (xGap || 0);
10164
+ const canvasHeight = height + (yGap || 0);
10165
+ scaleX /= canvasWidth / max(floor(canvasWidth), 1);
10166
+ scaleY /= canvasHeight / max(floor(canvasHeight), 1);
10198
10167
  if (!imageMatrix) {
10199
10168
  imageMatrix = get$1();
10200
10169
  if (transform) copy$1(imageMatrix, transform);
10201
10170
  }
10202
10171
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
10203
10172
  }
10204
- if (imageMatrix) {
10205
- const canvasWidth = width + (xGap || 0), canvasHeight = height + (yGap || 0);
10206
- scale(imageMatrix, canvasWidth / max(floor(canvasWidth), 1), canvasHeight / max(floor(canvasHeight), 1));
10207
- }
10208
- const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap);
10173
+ const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth);
10209
10174
  const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
10210
10175
  paint.style = pattern;
10211
10176
  paint.patternId = id;
@@ -11155,4 +11120,4 @@ try {
11155
11120
  if (wx) useCanvas("miniapp", wx);
11156
11121
  } catch (_a) {}
11157
11122
 
11158
- export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, DataHelper, Debug, Direction4, Direction9, DragBoundsHelper, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, Frame, FrameData, Group, GroupData, Image, ImageData, ImageEvent, ImageManager, IncrementId, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, Line, LineData, MathHelper, Matrix, MatrixHelper, MyImage, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Plugin, Point, PointHelper, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, Run, Star, StarData, State, StringNumberMap, TaskItem, TaskProcessor, Text, TextConvert, TextData, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, createAttr, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, extraPropertyEventMap, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isArray, isData, isEmptyData, isFinite, isNull, isNumber, isObject, isString, isUndefined, layoutProcessor, leaferTransformAttrMap, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, scrollType, sortType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix$1 as tempMatrix, tempPoint$2 as tempPoint, tryToNumber, useCanvas, useModule, version, visibleType, zoomLayerType };
11123
+ export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, DataHelper, Debug, Direction4, Direction9, DragBoundsHelper, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, Frame, FrameData, Group, GroupData, Image, ImageData, ImageEvent, ImageManager, IncrementId, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, Line, LineData, MathHelper, Matrix, MatrixHelper, MyImage, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Plugin, Point, PointHelper, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, Run, Star, StarData, State, StringNumberMap, TaskItem, TaskProcessor, Text, TextConvert, TextData, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, createAttr, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, extraPropertyEventMap, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isArray, isData, isEmptyData, isFinite, isNull, isNumber, isObject, isString, isUndefined, layoutProcessor, leaferTransformAttrMap, maskType, naturalBoundsType, opacityType, path, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, scrollType, sortType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix$1 as tempMatrix, tempPoint$2 as tempPoint, tryToNumber, useCanvas, useModule, version, visibleType, zoomLayerType };