@leafer-game/miniapp 1.0.9 → 1.1.0

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.
@@ -108,7 +108,7 @@ const MathHelper = {
108
108
  return rotation - oldRotation;
109
109
  },
110
110
  float(num, maxLength) {
111
- const a = maxLength ? pow$2(10, maxLength) : 1000000000000;
111
+ const a = maxLength !== undefined ? pow$2(10, maxLength) : 1000000000000;
112
112
  num = round$3(num * a) / a;
113
113
  return num === -0 ? 0 : num;
114
114
  },
@@ -1411,14 +1411,13 @@ const UICreator = {
1411
1411
  list: {},
1412
1412
  register(UI) {
1413
1413
  const { __tag: tag } = UI.prototype;
1414
- if (list$2[tag]) {
1414
+ if (list$2[tag])
1415
1415
  debug$e.repeat(tag);
1416
- }
1417
- else {
1418
- list$2[tag] = UI;
1419
- }
1416
+ list$2[tag] = UI;
1420
1417
  },
1421
1418
  get(tag, data, x, y, width, height) {
1419
+ if (!list$2[tag])
1420
+ debug$e.error('not register ' + tag);
1422
1421
  const ui = new list$2[tag](data);
1423
1422
  if (x !== undefined) {
1424
1423
  ui.x = x;
@@ -1442,7 +1441,7 @@ const EventCreator = {
1442
1441
  Object.keys(Event).forEach(key => {
1443
1442
  name = Event[key];
1444
1443
  if (typeof name === 'string')
1445
- nameList[name] ? debug$d.repeat(name) : nameList[name] = Event;
1444
+ nameList[name] && debug$d.repeat(name), nameList[name] = Event;
1446
1445
  });
1447
1446
  },
1448
1447
  changeName(oldName, newName) {
@@ -1644,7 +1643,7 @@ class LeafData {
1644
1643
  const t = this;
1645
1644
  if (t.blendMode === 'pass-through') {
1646
1645
  const leaf = this.__leaf;
1647
- if ((t.opacity < 1 && leaf.isBranch) || leaf.__hasEraser || t.eraser) {
1646
+ if ((t.opacity < 1 && (leaf.isBranch || t.__hasMultiPaint)) || leaf.__hasEraser || t.eraser) {
1648
1647
  t.__single = true;
1649
1648
  }
1650
1649
  else if (t.__single) {
@@ -2042,8 +2041,9 @@ class LeaferCanvasBase extends Canvas$1 {
2042
2041
  takeCanvas = this.getSameCanvas();
2043
2042
  takeCanvas.copyWorld(this);
2044
2043
  }
2045
- DataHelper.copyAttrs(this.size, size, canvasSizeAttrs);
2046
- this.size.pixelRatio || (this.size.pixelRatio = 1);
2044
+ const s = this.size;
2045
+ DataHelper.copyAttrs(s, size, canvasSizeAttrs);
2046
+ canvasSizeAttrs.forEach(key => s[key] || (s[key] = 1));
2047
2047
  this.bounds = new Bounds(0, 0, this.width, this.height);
2048
2048
  if (this.context && !this.unreal) {
2049
2049
  this.updateViewSize();
@@ -2157,6 +2157,17 @@ class LeaferCanvasBase extends Canvas$1 {
2157
2157
  if (!onlyResetTransform)
2158
2158
  this.useWorldTransform();
2159
2159
  }
2160
+ useGrayscaleAlpha(bounds) {
2161
+ this.setTempBounds(bounds, true, true);
2162
+ let alpha, pixel;
2163
+ const { context } = this, imageData = context.getImageData(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height), { data } = imageData;
2164
+ for (let i = 0, len = data.length; i < len; i += 4) {
2165
+ pixel = data[i] * 0.299 + data[i + 1] * 0.587 + data[i + 2] * 0.114;
2166
+ if (alpha = data[i + 3])
2167
+ data[i + 3] = alpha === 255 ? pixel : alpha * (pixel / 255);
2168
+ }
2169
+ context.putImageData(imageData, tempBounds$1.x, tempBounds$1.y);
2170
+ }
2160
2171
  useMask(maskCanvas, fromBounds, toBounds) {
2161
2172
  this.copyWorld(maskCanvas, fromBounds, toBounds, 'destination-in');
2162
2173
  }
@@ -2167,7 +2178,7 @@ class LeaferCanvasBase extends Canvas$1 {
2167
2178
  if (blendMode)
2168
2179
  this.blendMode = blendMode;
2169
2180
  this.fillStyle = color;
2170
- tempBounds$1.set(bounds).scale(this.pixelRatio);
2181
+ this.setTempBounds(bounds);
2171
2182
  this.fillRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
2172
2183
  if (blendMode)
2173
2184
  this.blendMode = 'source-over';
@@ -2176,22 +2187,18 @@ class LeaferCanvasBase extends Canvas$1 {
2176
2187
  if (blendMode)
2177
2188
  this.blendMode = blendMode;
2178
2189
  this.strokeStyle = color;
2179
- tempBounds$1.set(bounds).scale(this.pixelRatio);
2190
+ this.setTempBounds(bounds);
2180
2191
  this.strokeRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
2181
2192
  if (blendMode)
2182
2193
  this.blendMode = 'source-over';
2183
2194
  }
2184
2195
  clearWorld(bounds, ceilPixel) {
2185
- tempBounds$1.set(bounds).scale(this.pixelRatio);
2186
- if (ceilPixel)
2187
- tempBounds$1.ceil();
2196
+ this.setTempBounds(bounds, ceilPixel);
2188
2197
  this.clearRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
2189
2198
  }
2190
2199
  clipWorld(bounds, ceilPixel) {
2191
2200
  this.beginPath();
2192
- tempBounds$1.set(bounds).scale(this.pixelRatio);
2193
- if (ceilPixel)
2194
- tempBounds$1.ceil();
2201
+ this.setTempBounds(bounds, ceilPixel);
2195
2202
  this.rect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
2196
2203
  this.clip();
2197
2204
  }
@@ -2199,6 +2206,14 @@ class LeaferCanvasBase extends Canvas$1 {
2199
2206
  const { pixelRatio } = this;
2200
2207
  this.clearRect(0, 0, this.width * pixelRatio + 2, this.height * pixelRatio + 2);
2201
2208
  }
2209
+ setTempBounds(bounds, ceil, intersect) {
2210
+ tempBounds$1.set(bounds);
2211
+ if (intersect)
2212
+ tempBounds$1.intersect(this.bounds);
2213
+ tempBounds$1.scale(this.pixelRatio);
2214
+ if (ceil)
2215
+ tempBounds$1.ceil();
2216
+ }
2202
2217
  isSameSize(size) {
2203
2218
  return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
2204
2219
  }
@@ -4150,20 +4165,17 @@ const LeafHelper = {
4150
4165
  }
4151
4166
  return true;
4152
4167
  },
4153
- moveWorld(t, x, y = 0, isInnerPoint) {
4168
+ moveWorld(t, x, y = 0, isInnerPoint, transition) {
4154
4169
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4155
4170
  isInnerPoint ? toOuterPoint$1(t.localTransform, local, local, true) : (t.parent && toInnerPoint$1(t.parent.worldTransform, local, local, true));
4156
- L$1.moveLocal(t, local.x, local.y);
4171
+ L$1.moveLocal(t, local.x, local.y, transition);
4157
4172
  },
4158
- moveLocal(t, x, y = 0) {
4159
- if (typeof x === 'object') {
4160
- t.x += x.x;
4161
- t.y += x.y;
4162
- }
4163
- else {
4164
- t.x += x;
4165
- t.y += y;
4166
- }
4173
+ moveLocal(t, x, y = 0, transition) {
4174
+ if (typeof x === 'object')
4175
+ y = x.y, x = x.x;
4176
+ x += t.x;
4177
+ y += t.y;
4178
+ transition ? t.animate({ x, y }, transition) : (t.x = x, t.y = y);
4167
4179
  },
4168
4180
  zoomOfWorld(t, origin, scaleX, scaleY, resize) {
4169
4181
  L$1.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
@@ -5212,13 +5224,14 @@ const BranchRender = {
5212
5224
  this.__.__checkSingle();
5213
5225
  },
5214
5226
  __render(canvas, options) {
5227
+ this.__nowWorld = this.__getNowWorld(options);
5215
5228
  if (this.__worldOpacity) {
5216
5229
  if (this.__.__single) {
5217
5230
  if (this.__.eraser === 'path')
5218
5231
  return this.__renderEraser(canvas, options);
5219
5232
  const tempCanvas = canvas.getSameCanvas(false, true);
5220
5233
  this.__renderBranch(tempCanvas, options);
5221
- const nowWorld = this.__getNowWorld(options);
5234
+ const nowWorld = this.__nowWorld;
5222
5235
  canvas.opacity = this.__.opacity;
5223
5236
  canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, this.__.__blendMode, true);
5224
5237
  tempCanvas.recycle(nowWorld);
@@ -5542,11 +5555,11 @@ let Leaf = class Leaf {
5542
5555
  transform(matrix, resize) {
5543
5556
  transform(this, matrix, resize);
5544
5557
  }
5545
- move(x, y) {
5546
- moveLocal(this, x, y);
5558
+ move(x, y, transition) {
5559
+ moveLocal(this, x, y, transition);
5547
5560
  }
5548
- moveInner(x, y) {
5549
- moveWorld(this, x, y, true);
5561
+ moveInner(x, y, transition) {
5562
+ moveWorld(this, x, y, true, transition);
5550
5563
  }
5551
5564
  scaleOf(origin, scaleX, scaleY, resize) {
5552
5565
  zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
@@ -5560,8 +5573,8 @@ let Leaf = class Leaf {
5560
5573
  transformWorld(worldTransform, resize) {
5561
5574
  transformWorld(this, worldTransform, resize);
5562
5575
  }
5563
- moveWorld(x, y) {
5564
- moveWorld(this, x, y);
5576
+ moveWorld(x, y, transition) {
5577
+ moveWorld(this, x, y, false, transition);
5565
5578
  }
5566
5579
  scaleOfWorld(worldOrigin, scaleX, scaleY, resize) {
5567
5580
  zoomOfWorld(this, worldOrigin, scaleX, scaleY, resize);
@@ -5959,7 +5972,7 @@ class LeafLevelList {
5959
5972
  }
5960
5973
  }
5961
5974
 
5962
- const version = "1.0.9";
5975
+ const version = "1.1.0";
5963
5976
 
5964
5977
  class LeaferCanvas extends LeaferCanvasBase {
5965
5978
  get allowBackgroundColor() { return false; }
@@ -6072,7 +6085,7 @@ function useCanvas(_canvasType, app) {
6072
6085
  Platform.origin = {
6073
6086
  createCanvas: (width, height, _format) => {
6074
6087
  const data = { type: '2d', width, height };
6075
- app.createOffscreenCanvas ? app.createOffscreenCanvas(data) : app.createOffScreenCanvas(data);
6088
+ return app.createOffscreenCanvas ? app.createOffscreenCanvas(data) : app.createOffScreenCanvas(data);
6076
6089
  },
6077
6090
  canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
6078
6091
  canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, { quality }),
@@ -6183,7 +6196,7 @@ function useCanvas(_canvasType, app) {
6183
6196
  }
6184
6197
  Platform.name = 'miniapp';
6185
6198
  Platform.requestRender = function (render) {
6186
- const { view } = (Platform.renderCanvas || Platform.canvas);
6199
+ const { view } = Platform.renderCanvas || Platform.canvas;
6187
6200
  view.requestAnimationFrame ? view.requestAnimationFrame(render) : setTimeout(render, 16);
6188
6201
  };
6189
6202
  defineKey(Platform, 'devicePixelRatio', { get() { return Math.max(1, wx.getSystemInfoSync().pixelRatio); } });
@@ -6568,7 +6581,8 @@ class Renderer {
6568
6581
  this.totalBounds = new Bounds();
6569
6582
  debug$5.log(target.innerName, '--->');
6570
6583
  try {
6571
- target.app.emit(RenderEvent.CHILD_START, target);
6584
+ if (!target.isApp)
6585
+ target.app.emit(RenderEvent.CHILD_START, target);
6572
6586
  this.emitRender(RenderEvent.START);
6573
6587
  this.renderOnce(callback);
6574
6588
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -7122,6 +7136,12 @@ class UIData extends LeafData {
7122
7136
  return strokeWidth;
7123
7137
  }
7124
7138
  get __hasStroke() { return this.stroke && this.strokeWidth; }
7139
+ get __hasMultiPaint() {
7140
+ const t = this;
7141
+ if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
7142
+ return true;
7143
+ return t.fill && this.__hasStroke;
7144
+ }
7125
7145
  get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
7126
7146
  get __autoWidth() { return !this._width; }
7127
7147
  get __autoHeight() { return !this._height; }
@@ -7491,9 +7511,8 @@ const RectRender = {
7491
7511
  canvas.strokeRect(half, half, width, height);
7492
7512
  canvas.restore();
7493
7513
  }
7494
- else {
7514
+ else
7495
7515
  canvas.strokeRect(half, half, width, height);
7496
- }
7497
7516
  break;
7498
7517
  case 'outside':
7499
7518
  canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
@@ -7523,11 +7542,15 @@ let UI = UI_1 = class UI extends Leaf {
7523
7542
  super(data);
7524
7543
  }
7525
7544
  reset(_data) { }
7526
- set(data, isTemp) {
7527
- if (isTemp) {
7528
- this.lockNormalStyle = true;
7529
- Object.assign(this, data);
7530
- this.lockNormalStyle = false;
7545
+ set(data, transition) {
7546
+ if (transition) {
7547
+ if (transition === 'temp') {
7548
+ this.lockNormalStyle = true;
7549
+ Object.assign(this, data);
7550
+ this.lockNormalStyle = false;
7551
+ }
7552
+ else
7553
+ this.animate(data, transition);
7531
7554
  }
7532
7555
  else
7533
7556
  Object.assign(this, data);
@@ -7718,6 +7741,15 @@ __decorate([
7718
7741
  __decorate([
7719
7742
  boundsType(0)
7720
7743
  ], UI.prototype, "padding", void 0);
7744
+ __decorate([
7745
+ boundsType(false)
7746
+ ], UI.prototype, "lockRatio", void 0);
7747
+ __decorate([
7748
+ boundsType()
7749
+ ], UI.prototype, "widthRange", void 0);
7750
+ __decorate([
7751
+ boundsType()
7752
+ ], UI.prototype, "heightRange", void 0);
7721
7753
  __decorate([
7722
7754
  dataType(false)
7723
7755
  ], UI.prototype, "draggable", void 0);
@@ -7828,17 +7860,17 @@ let Group = class Group extends UI {
7828
7860
  if (!this.children)
7829
7861
  this.children = [];
7830
7862
  }
7831
- set(data, isTemp) {
7863
+ set(data, transition) {
7832
7864
  if (data.children) {
7833
7865
  const { children } = data;
7834
7866
  delete data.children;
7835
7867
  this.children ? this.clear() : this.__setBranch();
7836
- super.set(data, isTemp);
7868
+ super.set(data, transition);
7837
7869
  children.forEach(child => this.add(child));
7838
7870
  data.children = children;
7839
7871
  }
7840
7872
  else
7841
- super.set(data, isTemp);
7873
+ super.set(data, transition);
7842
7874
  }
7843
7875
  toJSON(options) {
7844
7876
  const data = super.toJSON(options);
@@ -7951,8 +7983,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7951
7983
  }
7952
7984
  onInit() { }
7953
7985
  initType(_type) { }
7954
- set(data) {
7955
- this.waitInit(() => { super.set(data); });
7986
+ set(data, transition) {
7987
+ this.waitInit(() => { super.set(data, transition); });
7956
7988
  }
7957
7989
  start() {
7958
7990
  clearTimeout(this.__startTimer);
@@ -8009,8 +8041,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8009
8041
  __onResize(event) {
8010
8042
  this.emitEvent(event);
8011
8043
  DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
8012
- if (!event.width || !event.height)
8013
- debug$3.warn('w = 0 or h = 0');
8014
8044
  setTimeout(() => { if (this.canvasManager)
8015
8045
  this.canvasManager.clearRecycled(); }, 0);
8016
8046
  }
@@ -8335,9 +8365,6 @@ __decorate([
8335
8365
  __decorate([
8336
8366
  dataType(false)
8337
8367
  ], Box.prototype, "resizeChildren", void 0);
8338
- __decorate([
8339
- dataType(false)
8340
- ], Box.prototype, "textBox", void 0);
8341
8368
  __decorate([
8342
8369
  affectRenderBoundsType('show')
8343
8370
  ], Box.prototype, "overflow", void 0);
@@ -8447,7 +8474,7 @@ Ellipse = __decorate([
8447
8474
  ], Ellipse);
8448
8475
 
8449
8476
  const { moveTo: moveTo$2, lineTo: lineTo$2, drawPoints: drawPoints$1 } = PathCommandDataHelper;
8450
- const { rotate: rotate$1, getAngle: getAngle$1, getDistance: getDistance$2, defaultPoint } = PointHelper;
8477
+ const { rotate: rotate$1, getAngle: getAngle$1, getDistance: getDistance$3, defaultPoint } = PointHelper;
8451
8478
  const { toBounds: toBounds$1 } = PathBounds;
8452
8479
  let Line = class Line extends UI {
8453
8480
  get __tag() { return 'Line'; }
@@ -8461,7 +8488,7 @@ let Line = class Line extends UI {
8461
8488
  return to;
8462
8489
  }
8463
8490
  set toPoint(value) {
8464
- this.width = getDistance$2(defaultPoint, value);
8491
+ this.width = getDistance$3(defaultPoint, value);
8465
8492
  this.rotation = getAngle$1(defaultPoint, value);
8466
8493
  if (this.height)
8467
8494
  this.height = 0;
@@ -9092,19 +9119,13 @@ class UIEvent extends Event {
9092
9119
  Object.assign(this, params);
9093
9120
  }
9094
9121
  getBoxPoint(relative) {
9095
- if (!relative)
9096
- relative = this.current;
9097
- return relative.getBoxPoint(this);
9122
+ return (relative || this.current).getBoxPoint(this);
9098
9123
  }
9099
9124
  getInnerPoint(relative) {
9100
- if (!relative)
9101
- relative = this.current;
9102
- return relative.getInnerPoint(this);
9125
+ return (relative || this.current).getInnerPoint(this);
9103
9126
  }
9104
9127
  getLocalPoint(relative) {
9105
- if (!relative)
9106
- relative = this.current;
9107
- return relative.getLocalPoint(this);
9128
+ return (relative || this.current).getLocalPoint(this);
9108
9129
  }
9109
9130
  getPagePoint() {
9110
9131
  return this.current.getPagePoint(this);
@@ -9152,10 +9173,8 @@ let DragEvent = class DragEvent extends PointerEvent {
9152
9173
  this.data = data;
9153
9174
  }
9154
9175
  static getValidMove(leaf, start, total) {
9155
- const { draggable, dragBounds, x, y } = leaf;
9156
- const move = leaf.getLocalPoint(total, null, true);
9157
- move.x += start.x - x;
9158
- move.y += start.y - y;
9176
+ const { draggable, dragBounds } = leaf, move = leaf.getLocalPoint(total, null, true);
9177
+ PointHelper.move(move, start.x - leaf.x, start.y - leaf.y);
9159
9178
  if (dragBounds)
9160
9179
  this.getMoveInDragBounds(leaf.__local, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true);
9161
9180
  if (draggable === 'x')
@@ -9165,8 +9184,7 @@ let DragEvent = class DragEvent extends PointerEvent {
9165
9184
  return move;
9166
9185
  }
9167
9186
  static getMoveInDragBounds(childBox, dragBounds, move, change) {
9168
- const x = childBox.x + move.x, y = childBox.y + move.y;
9169
- const right = x + childBox.width, bottom = y + childBox.height;
9187
+ const x = childBox.x + move.x, y = childBox.y + move.y, right = x + childBox.width, bottom = y + childBox.height;
9170
9188
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
9171
9189
  if (!change)
9172
9190
  move = Object.assign({}, move);
@@ -9218,9 +9236,7 @@ let DragEvent = class DragEvent extends PointerEvent {
9218
9236
  return this.getLocalMove(relative, true);
9219
9237
  }
9220
9238
  getPageBounds() {
9221
- const total = this.getPageTotal();
9222
- const start = this.getPagePoint();
9223
- const bounds = {};
9239
+ const total = this.getPageTotal(), start = this.getPagePoint(), bounds = {};
9224
9240
  BoundsHelper.set(bounds, start.x - total.x, start.y - total.y, total.x, total.y);
9225
9241
  BoundsHelper.unsign(bounds);
9226
9242
  return bounds;
@@ -9338,7 +9354,8 @@ const debug$2 = Debug.get('LeaferTypeCreator');
9338
9354
  const LeaferTypeCreator = {
9339
9355
  list: {},
9340
9356
  register(name, fn) {
9341
- list[name] ? debug$2.repeat(name) : list[name] = fn;
9357
+ list[name] && debug$2.repeat(name);
9358
+ list[name] = fn;
9342
9359
  },
9343
9360
  run(name, leafer) {
9344
9361
  const fn = list[name];
@@ -10712,6 +10729,8 @@ function stroke(stroke, ui, canvas) {
10712
10729
  case 'center':
10713
10730
  canvas.setStroke(stroke, __strokeWidth, options);
10714
10731
  canvas.stroke();
10732
+ if (options.__useArrow)
10733
+ strokeArrow(ui, canvas);
10715
10734
  break;
10716
10735
  case 'inside':
10717
10736
  canvas.save();
@@ -10749,6 +10768,8 @@ function strokes(strokes, ui, canvas) {
10749
10768
  case 'center':
10750
10769
  canvas.setStroke(undefined, __strokeWidth, options);
10751
10770
  drawStrokesStyle(strokes, false, ui, canvas);
10771
+ if (options.__useArrow)
10772
+ strokeArrow(ui, canvas);
10752
10773
  break;
10753
10774
  case 'inside':
10754
10775
  canvas.save();
@@ -10774,6 +10795,14 @@ function strokes(strokes, ui, canvas) {
10774
10795
  }
10775
10796
  }
10776
10797
  }
10798
+ function strokeArrow(ui, canvas) {
10799
+ if (ui.__.dashPattern) {
10800
+ canvas.beginPath();
10801
+ ui.__drawPathByData(canvas, ui.__.__pathForArrow);
10802
+ canvas.dashPattern = null;
10803
+ canvas.stroke();
10804
+ }
10805
+ }
10777
10806
 
10778
10807
  const { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper;
10779
10808
  function shape(ui, current, options) {
@@ -11276,7 +11305,7 @@ function applyStops(gradient, stops, opacity) {
11276
11305
  }
11277
11306
  }
11278
11307
 
11279
- const { getAngle, getDistance: getDistance$1 } = PointHelper;
11308
+ const { getAngle, getDistance: getDistance$2 } = PointHelper;
11280
11309
  const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
11281
11310
  const { toPoint: toPoint$1 } = AroundHelper;
11282
11311
  const realFrom$1 = {};
@@ -11285,7 +11314,7 @@ function radialGradient(paint, box) {
11285
11314
  let { from, to, type, opacity, blendMode, stretch } = paint;
11286
11315
  toPoint$1(from || 'center', box, realFrom$1);
11287
11316
  toPoint$1(to || 'bottom', box, realTo$1);
11288
- const style = Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$1(realFrom$1, realTo$1));
11317
+ const style = Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$2(realFrom$1, realTo$1));
11289
11318
  applyStops(style, paint.stops, opacity);
11290
11319
  const data = { type, style };
11291
11320
  const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
@@ -11313,7 +11342,7 @@ function getTransform(box, from, to, stretch, rotate90) {
11313
11342
  return transform;
11314
11343
  }
11315
11344
 
11316
- const { getDistance } = PointHelper;
11345
+ const { getDistance: getDistance$1 } = PointHelper;
11317
11346
  const { toPoint } = AroundHelper;
11318
11347
  const realFrom = {};
11319
11348
  const realTo = {};
@@ -11321,7 +11350,7 @@ function conicGradient(paint, box) {
11321
11350
  let { from, to, type, opacity, blendMode, stretch } = paint;
11322
11351
  toPoint(from || 'center', box, realFrom);
11323
11352
  toPoint(to || 'bottom', box, realTo);
11324
- 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));
11353
+ 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$1(realFrom, realTo));
11325
11354
  applyStops(style, paint.stops, opacity);
11326
11355
  const data = { type, style };
11327
11356
  const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
@@ -11459,16 +11488,16 @@ const EffectModule = {
11459
11488
 
11460
11489
  const { excludeRenderBounds } = LeafBoundsHelper;
11461
11490
  Group.prototype.__renderMask = function (canvas, options) {
11462
- let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
11491
+ let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
11463
11492
  const { children } = this;
11464
11493
  for (let i = 0, len = children.length; i < len; i++) {
11465
- child = children[i];
11466
- if (child.__.mask) {
11494
+ child = children[i], mask = child.__.mask;
11495
+ if (mask) {
11467
11496
  if (currentMask) {
11468
11497
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
11469
11498
  maskCanvas = contentCanvas = null;
11470
11499
  }
11471
- if (child.__.mask === 'path') {
11500
+ if (mask === 'path' || mask === 'clipping-path') {
11472
11501
  if (child.opacity < 1) {
11473
11502
  currentMask = 'opacity-path';
11474
11503
  maskOpacity = child.opacity;
@@ -11482,14 +11511,14 @@ Group.prototype.__renderMask = function (canvas, options) {
11482
11511
  child.__clip(contentCanvas || canvas, options);
11483
11512
  }
11484
11513
  else {
11485
- currentMask = 'alpha';
11514
+ currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
11486
11515
  if (!maskCanvas)
11487
11516
  maskCanvas = getCanvas(canvas);
11488
11517
  if (!contentCanvas)
11489
11518
  contentCanvas = getCanvas(canvas);
11490
11519
  child.__render(maskCanvas, options);
11491
11520
  }
11492
- if (child.__.mask !== 'clipping')
11521
+ if (!(mask === 'clipping' || mask === 'clipping-path'))
11493
11522
  continue;
11494
11523
  }
11495
11524
  if (excludeRenderBounds(child, options))
@@ -11500,6 +11529,8 @@ Group.prototype.__renderMask = function (canvas, options) {
11500
11529
  };
11501
11530
  function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
11502
11531
  switch (maskMode) {
11532
+ case 'grayscale':
11533
+ maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
11503
11534
  case 'alpha':
11504
11535
  usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
11505
11536
  break;
@@ -12204,15 +12235,12 @@ const canvas = LeaferCanvasBase.prototype;
12204
12235
  const debug = Debug.get('@leafer-ui/export');
12205
12236
  canvas.export = function (filename, options) {
12206
12237
  const { quality, blob } = FileHelper.getExportOptions(options);
12207
- if (filename.includes('.')) {
12238
+ if (filename.includes('.'))
12208
12239
  return this.saveAs(filename, quality);
12209
- }
12210
- else if (blob) {
12240
+ else if (blob)
12211
12241
  return this.toBlob(filename, quality);
12212
- }
12213
- else {
12242
+ else
12214
12243
  return this.toDataURL(filename, quality);
12215
- }
12216
12244
  };
12217
12245
  canvas.toBlob = function (type, quality) {
12218
12246
  return new Promise((resolve) => {
@@ -12308,15 +12336,18 @@ let Robot = class Robot extends UI {
12308
12336
  if (typeof action === 'number') {
12309
12337
  this.now = action;
12310
12338
  }
12311
- else if (action instanceof Array) {
12312
- const { length } = action;
12339
+ else if (typeof action === 'object') {
12340
+ const isArray = action instanceof Array;
12341
+ const keyframes = isArray ? action : action.keyframes;
12342
+ this.__action = isArray ? undefined : action;
12343
+ const { length } = keyframes;
12313
12344
  if (length > 1) {
12314
- const start = this.now = action[0], end = action[action.length - 1];
12345
+ const start = this.now = keyframes[0], end = keyframes[keyframes.length - 1];
12315
12346
  this.play();
12316
12347
  this.__runAction(start, end);
12317
12348
  }
12318
12349
  else if (length)
12319
- this.now = action[0];
12350
+ this.now = keyframes[0];
12320
12351
  }
12321
12352
  }
12322
12353
  __loadRobot(frame, start, end) {
@@ -12344,16 +12375,26 @@ let Robot = class Robot extends UI {
12344
12375
  this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
12345
12376
  }
12346
12377
  __runAction(start, end) {
12378
+ let { FPS, loop, __action: a } = this;
12379
+ if (a) {
12380
+ if (a.FPS)
12381
+ FPS = a.FPS;
12382
+ if (a.loop !== undefined)
12383
+ loop = a.loop;
12384
+ }
12347
12385
  this.__timer = setTimeout(() => {
12348
12386
  if (this.running) {
12349
- if (this.now === end)
12387
+ if (this.now === end) {
12388
+ if (!loop)
12389
+ return this.stop();
12350
12390
  this.now = start;
12391
+ }
12351
12392
  else
12352
12393
  this.now++;
12353
12394
  this.__updateRobotBounds();
12354
12395
  }
12355
12396
  this.__runAction(start, end);
12356
- }, 1000 / this.FPS);
12397
+ }, 1000 / FPS);
12357
12398
  }
12358
12399
  __updateRobotBounds() {
12359
12400
  const { nowFrame } = this;
@@ -12466,7 +12507,7 @@ function updateStyle(leaf, style, type) {
12466
12507
  const fromStyle = transition ? getFromStyle(leaf, style) : undefined;
12467
12508
  leaf.killAnimate('transition');
12468
12509
  if (normalStyle)
12469
- leaf.set(normalStyle, true);
12510
+ leaf.set(normalStyle, 'temp');
12470
12511
  const statesStyle = getStyle(leaf);
12471
12512
  if (statesStyle) {
12472
12513
  const { animation } = statesStyle;
@@ -12480,14 +12521,14 @@ function updateStyle(leaf, style, type) {
12480
12521
  delete statesStyle.animation;
12481
12522
  }
12482
12523
  leaf.normalStyle = filterStyle(statesStyle, leaf);
12483
- leaf.set(statesStyle, true);
12524
+ leaf.set(statesStyle, 'temp');
12484
12525
  }
12485
12526
  else {
12486
12527
  leaf.normalStyle = undefined;
12487
12528
  }
12488
12529
  if (transition) {
12489
12530
  const toStyle = filterStyle(fromStyle, leaf);
12490
- leaf.set(fromStyle, true);
12531
+ leaf.set(fromStyle, 'temp');
12491
12532
  leaf.animate([fromStyle, toStyle], transition, 'transition', true);
12492
12533
  }
12493
12534
  leaf.__layout.stateStyleChanged = false;
@@ -12949,7 +12990,8 @@ let Animate = class Animate extends Eventer {
12949
12990
  return;
12950
12991
  if (typeof time === 'object')
12951
12992
  time = UnitConvert.number(time, this.duration);
12952
- time /= this.speed;
12993
+ if (time)
12994
+ time /= this.speed;
12953
12995
  if (!this.started || time < this.time)
12954
12996
  this.start(true);
12955
12997
  this.time = time;
@@ -13184,7 +13226,7 @@ let Animate = class Animate extends Eventer {
13184
13226
  this.emit(AnimateEvent.UPDATE, this);
13185
13227
  }
13186
13228
  setStyle(style) {
13187
- this.target.set(style, this.isTemp);
13229
+ this.target.set(style, this.isTemp ? 'temp' : false);
13188
13230
  }
13189
13231
  clearTimer(fn) {
13190
13232
  if (this.timer) {
@@ -13560,6 +13602,9 @@ const TransitionList = {
13560
13602
  from = fourNumber(from), to = fourNumber(to);
13561
13603
  return from.map((f, i) => number(f, to[i], t));
13562
13604
  },
13605
+ text(from, to, t) {
13606
+ return (typeof from === 'number' || typeof to === 'number') ? MathHelper.float(number(from, to, t), Math.max(getDecimalLen(from), getDecimalLen(to))) : to;
13607
+ },
13563
13608
  shadow,
13564
13609
  innerShadow: shadow
13565
13610
  };
@@ -13568,6 +13613,10 @@ const TransitionModule = {
13568
13613
  number,
13569
13614
  color
13570
13615
  };
13616
+ function getDecimalLen(num) {
13617
+ const decimal = String(num).split('.')[1];
13618
+ return decimal ? decimal.length : 0;
13619
+ }
13571
13620
  function value(from, to, t) {
13572
13621
  return (typeof from === 'number' && typeof to === 'number') ? from + (to - from) * t : to;
13573
13622
  }
@@ -13636,23 +13685,40 @@ const gaussNodes = [0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.97
13636
13685
  const gaussWeights = [0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443];
13637
13686
  const { sqrt } = Math;
13638
13687
  const HighBezierHelper = {
13639
- getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY) {
13640
- let distance = 0, t1, t2, d1X, d1Y, d2X, d2Y;
13688
+ getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, t = 1) {
13689
+ let distance = 0, t1, t2, d1X, d1Y, d2X, d2Y, half = t / 2;
13641
13690
  for (let i = 0; i < gaussNodes.length; i++) {
13642
- t1 = 0.5 * (1 + gaussNodes[i]);
13643
- t2 = 0.5 * (1 - gaussNodes[i]);
13691
+ t1 = half * (1 + gaussNodes[i]);
13692
+ t2 = half * (1 - gaussNodes[i]);
13644
13693
  d1X = getDerivative(t1, fromX, x1, x2, toX);
13645
13694
  d1Y = getDerivative(t1, fromY, y1, y2, toY);
13646
13695
  d2X = getDerivative(t2, fromX, x1, x2, toX);
13647
13696
  d2Y = getDerivative(t2, fromY, y1, y2, toY);
13648
13697
  distance += gaussWeights[i] * (sqrt(d1X * d1X + d1Y * d1Y) + sqrt(d2X * d2X + d2Y * d2Y));
13649
13698
  }
13650
- return distance * 0.5;
13699
+ return distance * half;
13651
13700
  },
13652
13701
  getDerivative(t, fromV, v1, v2, toV) {
13653
13702
  const o = 1 - t;
13654
13703
  return 3 * o * o * (v1 - fromV) + 6 * o * t * (v2 - v1) + 3 * t * t * (toV - v2);
13655
13704
  },
13705
+ getRotation(t, fromX, fromY, x1, y1, x2, y2, toX, toY) {
13706
+ const dx = getDerivative(t, fromX, x1, x2, toX);
13707
+ const dy = getDerivative(t, fromY, y1, y2, toY);
13708
+ return Math.atan2(dy, dx) / OneRadian;
13709
+ },
13710
+ getT(distance, totalDistance, fromX, fromY, x1, y1, x2, y2, toX, toY, precision = 1) {
13711
+ let low = 0, high = 1, middle = distance / totalDistance, realPrecision = precision / totalDistance / 3;
13712
+ if (middle >= 1)
13713
+ return 1;
13714
+ if (middle <= 0)
13715
+ return 0;
13716
+ while (high - low > realPrecision) {
13717
+ getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, middle) < distance ? low = middle : high = middle;
13718
+ middle = (low + high) / 2;
13719
+ }
13720
+ return middle;
13721
+ },
13656
13722
  cut(data, t, fromX, fromY, x1, y1, x2, y2, toX, toY) {
13657
13723
  const o = 1 - t;
13658
13724
  const ax = o * fromX + t * x1, ay = o * fromY + t * y1;
@@ -13664,7 +13730,7 @@ const HighBezierHelper = {
13664
13730
  data.push(PathCommandMap.C, ax, ay, bx, by, cx, cy);
13665
13731
  }
13666
13732
  };
13667
- const { getDerivative } = HighBezierHelper;
13733
+ const { getDerivative, getDistance } = HighBezierHelper;
13668
13734
 
13669
13735
  const { M, L, C, Z } = PathCommandMap;
13670
13736
  const tempPoint = {}, tempFrom = {};
@@ -13732,11 +13798,12 @@ const HighCurveHelper = {
13732
13798
  }
13733
13799
  return { total, segments, data };
13734
13800
  },
13735
- getDistancePoint(distanceData, motionDistance) {
13801
+ getDistancePoint(distanceData, motionDistance, motionPrecision) {
13736
13802
  const { segments, data } = distanceData;
13737
13803
  motionDistance = UnitConvert.number(motionDistance, distanceData.total);
13738
13804
  let total = 0, distance, to = {};
13739
13805
  let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
13806
+ let x1, y1, x2, y2, t;
13740
13807
  const len = data.length;
13741
13808
  while (i < len) {
13742
13809
  command = data[i];
@@ -13766,11 +13833,10 @@ const HighCurveHelper = {
13766
13833
  toY = data[i + 6];
13767
13834
  distance = segments[index];
13768
13835
  if (total + distance > motionDistance) {
13769
- const x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13770
- motionDistance -= total;
13771
- BezierHelper.getPointAndSet(motionDistance / distance, x, y, x1, y1, x2, y2, toX, toY, to);
13772
- BezierHelper.getPointAndSet(Math.max(0, motionDistance - 0.1) / distance, x, y, x1, y1, x2, y2, toX, toY, tempFrom);
13773
- to.rotation = PointHelper.getAngle(tempFrom, to);
13836
+ x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13837
+ t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13838
+ BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
13839
+ to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY);
13774
13840
  return to;
13775
13841
  }
13776
13842
  x = toX;
@@ -13787,11 +13853,12 @@ const HighCurveHelper = {
13787
13853
  }
13788
13854
  return to;
13789
13855
  },
13790
- getDistancePath(distanceData, motionDistance) {
13856
+ getDistancePath(distanceData, motionDistance, motionPrecision) {
13791
13857
  const { segments, data } = distanceData, path = [];
13792
13858
  motionDistance = UnitConvert.number(motionDistance, distanceData.total);
13793
13859
  let total = 0, distance, to = {};
13794
13860
  let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
13861
+ let x1, y1, x2, y2, t;
13795
13862
  const len = data.length;
13796
13863
  while (i < len) {
13797
13864
  command = data[i];
@@ -13818,12 +13885,13 @@ const HighCurveHelper = {
13818
13885
  path.push(command, x, y);
13819
13886
  break;
13820
13887
  case C:
13821
- const x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13888
+ x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13822
13889
  toX = data[i + 5];
13823
13890
  toY = data[i + 6];
13824
13891
  distance = segments[index];
13825
13892
  if (total + distance > motionDistance) {
13826
- HighBezierHelper.cut(path, (motionDistance - total) / distance, x, y, x1, y1, x2, y2, toX, toY);
13893
+ t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13894
+ HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
13827
13895
  return path;
13828
13896
  }
13829
13897
  x = toX;
@@ -13872,6 +13940,7 @@ const ui = UI.prototype;
13872
13940
  const { updateMatrix, updateAllMatrix } = LeafHelper;
13873
13941
  const { updateBounds } = BranchHelper;
13874
13942
  motionPathType()(ui, 'motionPath');
13943
+ motionPathType(1)(ui, 'motionPrecision');
13875
13944
  motionPathType()(ui, 'motion');
13876
13945
  motionPathType(true)(ui, 'motionRotation');
13877
13946
  ui.getMotionPathData = function () {
@@ -13882,7 +13951,7 @@ ui.getMotionPoint = function (motionDistance) {
13882
13951
  const data = getMotionPathData(path);
13883
13952
  if (!data.total)
13884
13953
  return {};
13885
- const point = HighCurveHelper.getDistancePoint(data, motionDistance);
13954
+ const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision);
13886
13955
  MatrixHelper.toOuterPoint(path.localTransform, point);
13887
13956
  const { motionRotation } = this;
13888
13957
  if (motionRotation === false)
@@ -13922,7 +13991,7 @@ function updateMotion(leaf) {
13922
13991
  if (leaf.motionPath) {
13923
13992
  const data = getMotionPathData(leaf);
13924
13993
  if (data.total)
13925
- leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion);
13994
+ leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision);
13926
13995
  }
13927
13996
  else {
13928
13997
  leaf.set(leaf.getMotionPoint(motion));