@leafer-game/worker 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 true; }
@@ -6428,7 +6441,8 @@ class Renderer {
6428
6441
  this.totalBounds = new Bounds();
6429
6442
  debug$5.log(target.innerName, '--->');
6430
6443
  try {
6431
- target.app.emit(RenderEvent.CHILD_START, target);
6444
+ if (!target.isApp)
6445
+ target.app.emit(RenderEvent.CHILD_START, target);
6432
6446
  this.emitRender(RenderEvent.START);
6433
6447
  this.renderOnce(callback);
6434
6448
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -6982,6 +6996,12 @@ class UIData extends LeafData {
6982
6996
  return strokeWidth;
6983
6997
  }
6984
6998
  get __hasStroke() { return this.stroke && this.strokeWidth; }
6999
+ get __hasMultiPaint() {
7000
+ const t = this;
7001
+ if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
7002
+ return true;
7003
+ return t.fill && this.__hasStroke;
7004
+ }
6985
7005
  get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6986
7006
  get __autoWidth() { return !this._width; }
6987
7007
  get __autoHeight() { return !this._height; }
@@ -7351,9 +7371,8 @@ const RectRender = {
7351
7371
  canvas.strokeRect(half, half, width, height);
7352
7372
  canvas.restore();
7353
7373
  }
7354
- else {
7374
+ else
7355
7375
  canvas.strokeRect(half, half, width, height);
7356
- }
7357
7376
  break;
7358
7377
  case 'outside':
7359
7378
  canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
@@ -7383,11 +7402,15 @@ let UI = UI_1 = class UI extends Leaf {
7383
7402
  super(data);
7384
7403
  }
7385
7404
  reset(_data) { }
7386
- set(data, isTemp) {
7387
- if (isTemp) {
7388
- this.lockNormalStyle = true;
7389
- Object.assign(this, data);
7390
- this.lockNormalStyle = false;
7405
+ set(data, transition) {
7406
+ if (transition) {
7407
+ if (transition === 'temp') {
7408
+ this.lockNormalStyle = true;
7409
+ Object.assign(this, data);
7410
+ this.lockNormalStyle = false;
7411
+ }
7412
+ else
7413
+ this.animate(data, transition);
7391
7414
  }
7392
7415
  else
7393
7416
  Object.assign(this, data);
@@ -7578,6 +7601,15 @@ __decorate([
7578
7601
  __decorate([
7579
7602
  boundsType(0)
7580
7603
  ], UI.prototype, "padding", void 0);
7604
+ __decorate([
7605
+ boundsType(false)
7606
+ ], UI.prototype, "lockRatio", void 0);
7607
+ __decorate([
7608
+ boundsType()
7609
+ ], UI.prototype, "widthRange", void 0);
7610
+ __decorate([
7611
+ boundsType()
7612
+ ], UI.prototype, "heightRange", void 0);
7581
7613
  __decorate([
7582
7614
  dataType(false)
7583
7615
  ], UI.prototype, "draggable", void 0);
@@ -7688,17 +7720,17 @@ let Group = class Group extends UI {
7688
7720
  if (!this.children)
7689
7721
  this.children = [];
7690
7722
  }
7691
- set(data, isTemp) {
7723
+ set(data, transition) {
7692
7724
  if (data.children) {
7693
7725
  const { children } = data;
7694
7726
  delete data.children;
7695
7727
  this.children ? this.clear() : this.__setBranch();
7696
- super.set(data, isTemp);
7728
+ super.set(data, transition);
7697
7729
  children.forEach(child => this.add(child));
7698
7730
  data.children = children;
7699
7731
  }
7700
7732
  else
7701
- super.set(data, isTemp);
7733
+ super.set(data, transition);
7702
7734
  }
7703
7735
  toJSON(options) {
7704
7736
  const data = super.toJSON(options);
@@ -7811,8 +7843,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7811
7843
  }
7812
7844
  onInit() { }
7813
7845
  initType(_type) { }
7814
- set(data) {
7815
- this.waitInit(() => { super.set(data); });
7846
+ set(data, transition) {
7847
+ this.waitInit(() => { super.set(data, transition); });
7816
7848
  }
7817
7849
  start() {
7818
7850
  clearTimeout(this.__startTimer);
@@ -7869,8 +7901,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7869
7901
  __onResize(event) {
7870
7902
  this.emitEvent(event);
7871
7903
  DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
7872
- if (!event.width || !event.height)
7873
- debug$3.warn('w = 0 or h = 0');
7874
7904
  setTimeout(() => { if (this.canvasManager)
7875
7905
  this.canvasManager.clearRecycled(); }, 0);
7876
7906
  }
@@ -8195,9 +8225,6 @@ __decorate([
8195
8225
  __decorate([
8196
8226
  dataType(false)
8197
8227
  ], Box.prototype, "resizeChildren", void 0);
8198
- __decorate([
8199
- dataType(false)
8200
- ], Box.prototype, "textBox", void 0);
8201
8228
  __decorate([
8202
8229
  affectRenderBoundsType('show')
8203
8230
  ], Box.prototype, "overflow", void 0);
@@ -8307,7 +8334,7 @@ Ellipse = __decorate([
8307
8334
  ], Ellipse);
8308
8335
 
8309
8336
  const { moveTo: moveTo$2, lineTo: lineTo$2, drawPoints: drawPoints$1 } = PathCommandDataHelper;
8310
- const { rotate: rotate$1, getAngle: getAngle$1, getDistance: getDistance$2, defaultPoint } = PointHelper;
8337
+ const { rotate: rotate$1, getAngle: getAngle$1, getDistance: getDistance$3, defaultPoint } = PointHelper;
8311
8338
  const { toBounds: toBounds$1 } = PathBounds;
8312
8339
  let Line = class Line extends UI {
8313
8340
  get __tag() { return 'Line'; }
@@ -8321,7 +8348,7 @@ let Line = class Line extends UI {
8321
8348
  return to;
8322
8349
  }
8323
8350
  set toPoint(value) {
8324
- this.width = getDistance$2(defaultPoint, value);
8351
+ this.width = getDistance$3(defaultPoint, value);
8325
8352
  this.rotation = getAngle$1(defaultPoint, value);
8326
8353
  if (this.height)
8327
8354
  this.height = 0;
@@ -8952,19 +8979,13 @@ class UIEvent extends Event {
8952
8979
  Object.assign(this, params);
8953
8980
  }
8954
8981
  getBoxPoint(relative) {
8955
- if (!relative)
8956
- relative = this.current;
8957
- return relative.getBoxPoint(this);
8982
+ return (relative || this.current).getBoxPoint(this);
8958
8983
  }
8959
8984
  getInnerPoint(relative) {
8960
- if (!relative)
8961
- relative = this.current;
8962
- return relative.getInnerPoint(this);
8985
+ return (relative || this.current).getInnerPoint(this);
8963
8986
  }
8964
8987
  getLocalPoint(relative) {
8965
- if (!relative)
8966
- relative = this.current;
8967
- return relative.getLocalPoint(this);
8988
+ return (relative || this.current).getLocalPoint(this);
8968
8989
  }
8969
8990
  getPagePoint() {
8970
8991
  return this.current.getPagePoint(this);
@@ -9012,10 +9033,8 @@ let DragEvent = class DragEvent extends PointerEvent {
9012
9033
  this.data = data;
9013
9034
  }
9014
9035
  static getValidMove(leaf, start, total) {
9015
- const { draggable, dragBounds, x, y } = leaf;
9016
- const move = leaf.getLocalPoint(total, null, true);
9017
- move.x += start.x - x;
9018
- move.y += start.y - y;
9036
+ const { draggable, dragBounds } = leaf, move = leaf.getLocalPoint(total, null, true);
9037
+ PointHelper.move(move, start.x - leaf.x, start.y - leaf.y);
9019
9038
  if (dragBounds)
9020
9039
  this.getMoveInDragBounds(leaf.__local, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true);
9021
9040
  if (draggable === 'x')
@@ -9025,8 +9044,7 @@ let DragEvent = class DragEvent extends PointerEvent {
9025
9044
  return move;
9026
9045
  }
9027
9046
  static getMoveInDragBounds(childBox, dragBounds, move, change) {
9028
- const x = childBox.x + move.x, y = childBox.y + move.y;
9029
- const right = x + childBox.width, bottom = y + childBox.height;
9047
+ const x = childBox.x + move.x, y = childBox.y + move.y, right = x + childBox.width, bottom = y + childBox.height;
9030
9048
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
9031
9049
  if (!change)
9032
9050
  move = Object.assign({}, move);
@@ -9078,9 +9096,7 @@ let DragEvent = class DragEvent extends PointerEvent {
9078
9096
  return this.getLocalMove(relative, true);
9079
9097
  }
9080
9098
  getPageBounds() {
9081
- const total = this.getPageTotal();
9082
- const start = this.getPagePoint();
9083
- const bounds = {};
9099
+ const total = this.getPageTotal(), start = this.getPagePoint(), bounds = {};
9084
9100
  BoundsHelper.set(bounds, start.x - total.x, start.y - total.y, total.x, total.y);
9085
9101
  BoundsHelper.unsign(bounds);
9086
9102
  return bounds;
@@ -9198,7 +9214,8 @@ const debug$2 = Debug.get('LeaferTypeCreator');
9198
9214
  const LeaferTypeCreator = {
9199
9215
  list: {},
9200
9216
  register(name, fn) {
9201
- list[name] ? debug$2.repeat(name) : list[name] = fn;
9217
+ list[name] && debug$2.repeat(name);
9218
+ list[name] = fn;
9202
9219
  },
9203
9220
  run(name, leafer) {
9204
9221
  const fn = list[name];
@@ -10467,6 +10484,8 @@ function stroke(stroke, ui, canvas) {
10467
10484
  case 'center':
10468
10485
  canvas.setStroke(stroke, __strokeWidth, options);
10469
10486
  canvas.stroke();
10487
+ if (options.__useArrow)
10488
+ strokeArrow(ui, canvas);
10470
10489
  break;
10471
10490
  case 'inside':
10472
10491
  canvas.save();
@@ -10504,6 +10523,8 @@ function strokes(strokes, ui, canvas) {
10504
10523
  case 'center':
10505
10524
  canvas.setStroke(undefined, __strokeWidth, options);
10506
10525
  drawStrokesStyle(strokes, false, ui, canvas);
10526
+ if (options.__useArrow)
10527
+ strokeArrow(ui, canvas);
10507
10528
  break;
10508
10529
  case 'inside':
10509
10530
  canvas.save();
@@ -10529,6 +10550,14 @@ function strokes(strokes, ui, canvas) {
10529
10550
  }
10530
10551
  }
10531
10552
  }
10553
+ function strokeArrow(ui, canvas) {
10554
+ if (ui.__.dashPattern) {
10555
+ canvas.beginPath();
10556
+ ui.__drawPathByData(canvas, ui.__.__pathForArrow);
10557
+ canvas.dashPattern = null;
10558
+ canvas.stroke();
10559
+ }
10560
+ }
10532
10561
 
10533
10562
  const { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper;
10534
10563
  function shape(ui, current, options) {
@@ -11031,7 +11060,7 @@ function applyStops(gradient, stops, opacity) {
11031
11060
  }
11032
11061
  }
11033
11062
 
11034
- const { getAngle, getDistance: getDistance$1 } = PointHelper;
11063
+ const { getAngle, getDistance: getDistance$2 } = PointHelper;
11035
11064
  const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
11036
11065
  const { toPoint: toPoint$1 } = AroundHelper;
11037
11066
  const realFrom$1 = {};
@@ -11040,7 +11069,7 @@ function radialGradient(paint, box) {
11040
11069
  let { from, to, type, opacity, blendMode, stretch } = paint;
11041
11070
  toPoint$1(from || 'center', box, realFrom$1);
11042
11071
  toPoint$1(to || 'bottom', box, realTo$1);
11043
- const style = Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$1(realFrom$1, realTo$1));
11072
+ const style = Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$2(realFrom$1, realTo$1));
11044
11073
  applyStops(style, paint.stops, opacity);
11045
11074
  const data = { type, style };
11046
11075
  const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
@@ -11068,7 +11097,7 @@ function getTransform(box, from, to, stretch, rotate90) {
11068
11097
  return transform;
11069
11098
  }
11070
11099
 
11071
- const { getDistance } = PointHelper;
11100
+ const { getDistance: getDistance$1 } = PointHelper;
11072
11101
  const { toPoint } = AroundHelper;
11073
11102
  const realFrom = {};
11074
11103
  const realTo = {};
@@ -11076,7 +11105,7 @@ function conicGradient(paint, box) {
11076
11105
  let { from, to, type, opacity, blendMode, stretch } = paint;
11077
11106
  toPoint(from || 'center', box, realFrom);
11078
11107
  toPoint(to || 'bottom', box, realTo);
11079
- 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));
11108
+ 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));
11080
11109
  applyStops(style, paint.stops, opacity);
11081
11110
  const data = { type, style };
11082
11111
  const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
@@ -11214,16 +11243,16 @@ const EffectModule = {
11214
11243
 
11215
11244
  const { excludeRenderBounds } = LeafBoundsHelper;
11216
11245
  Group.prototype.__renderMask = function (canvas, options) {
11217
- let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
11246
+ let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
11218
11247
  const { children } = this;
11219
11248
  for (let i = 0, len = children.length; i < len; i++) {
11220
- child = children[i];
11221
- if (child.__.mask) {
11249
+ child = children[i], mask = child.__.mask;
11250
+ if (mask) {
11222
11251
  if (currentMask) {
11223
11252
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
11224
11253
  maskCanvas = contentCanvas = null;
11225
11254
  }
11226
- if (child.__.mask === 'path') {
11255
+ if (mask === 'path' || mask === 'clipping-path') {
11227
11256
  if (child.opacity < 1) {
11228
11257
  currentMask = 'opacity-path';
11229
11258
  maskOpacity = child.opacity;
@@ -11237,14 +11266,14 @@ Group.prototype.__renderMask = function (canvas, options) {
11237
11266
  child.__clip(contentCanvas || canvas, options);
11238
11267
  }
11239
11268
  else {
11240
- currentMask = 'alpha';
11269
+ currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
11241
11270
  if (!maskCanvas)
11242
11271
  maskCanvas = getCanvas(canvas);
11243
11272
  if (!contentCanvas)
11244
11273
  contentCanvas = getCanvas(canvas);
11245
11274
  child.__render(maskCanvas, options);
11246
11275
  }
11247
- if (child.__.mask !== 'clipping')
11276
+ if (!(mask === 'clipping' || mask === 'clipping-path'))
11248
11277
  continue;
11249
11278
  }
11250
11279
  if (excludeRenderBounds(child, options))
@@ -11255,6 +11284,8 @@ Group.prototype.__renderMask = function (canvas, options) {
11255
11284
  };
11256
11285
  function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
11257
11286
  switch (maskMode) {
11287
+ case 'grayscale':
11288
+ maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
11258
11289
  case 'alpha':
11259
11290
  usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
11260
11291
  break;
@@ -11959,15 +11990,12 @@ const canvas = LeaferCanvasBase.prototype;
11959
11990
  const debug = Debug.get('@leafer-ui/export');
11960
11991
  canvas.export = function (filename, options) {
11961
11992
  const { quality, blob } = FileHelper.getExportOptions(options);
11962
- if (filename.includes('.')) {
11993
+ if (filename.includes('.'))
11963
11994
  return this.saveAs(filename, quality);
11964
- }
11965
- else if (blob) {
11995
+ else if (blob)
11966
11996
  return this.toBlob(filename, quality);
11967
- }
11968
- else {
11997
+ else
11969
11998
  return this.toDataURL(filename, quality);
11970
- }
11971
11999
  };
11972
12000
  canvas.toBlob = function (type, quality) {
11973
12001
  return new Promise((resolve) => {
@@ -12056,15 +12084,18 @@ let Robot = class Robot extends UI {
12056
12084
  if (typeof action === 'number') {
12057
12085
  this.now = action;
12058
12086
  }
12059
- else if (action instanceof Array) {
12060
- const { length } = action;
12087
+ else if (typeof action === 'object') {
12088
+ const isArray = action instanceof Array;
12089
+ const keyframes = isArray ? action : action.keyframes;
12090
+ this.__action = isArray ? undefined : action;
12091
+ const { length } = keyframes;
12061
12092
  if (length > 1) {
12062
- const start = this.now = action[0], end = action[action.length - 1];
12093
+ const start = this.now = keyframes[0], end = keyframes[keyframes.length - 1];
12063
12094
  this.play();
12064
12095
  this.__runAction(start, end);
12065
12096
  }
12066
12097
  else if (length)
12067
- this.now = action[0];
12098
+ this.now = keyframes[0];
12068
12099
  }
12069
12100
  }
12070
12101
  __loadRobot(frame, start, end) {
@@ -12092,16 +12123,26 @@ let Robot = class Robot extends UI {
12092
12123
  this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
12093
12124
  }
12094
12125
  __runAction(start, end) {
12126
+ let { FPS, loop, __action: a } = this;
12127
+ if (a) {
12128
+ if (a.FPS)
12129
+ FPS = a.FPS;
12130
+ if (a.loop !== undefined)
12131
+ loop = a.loop;
12132
+ }
12095
12133
  this.__timer = setTimeout(() => {
12096
12134
  if (this.running) {
12097
- if (this.now === end)
12135
+ if (this.now === end) {
12136
+ if (!loop)
12137
+ return this.stop();
12098
12138
  this.now = start;
12139
+ }
12099
12140
  else
12100
12141
  this.now++;
12101
12142
  this.__updateRobotBounds();
12102
12143
  }
12103
12144
  this.__runAction(start, end);
12104
- }, 1000 / this.FPS);
12145
+ }, 1000 / FPS);
12105
12146
  }
12106
12147
  __updateRobotBounds() {
12107
12148
  const { nowFrame } = this;
@@ -12214,7 +12255,7 @@ function updateStyle(leaf, style, type) {
12214
12255
  const fromStyle = transition ? getFromStyle(leaf, style) : undefined;
12215
12256
  leaf.killAnimate('transition');
12216
12257
  if (normalStyle)
12217
- leaf.set(normalStyle, true);
12258
+ leaf.set(normalStyle, 'temp');
12218
12259
  const statesStyle = getStyle(leaf);
12219
12260
  if (statesStyle) {
12220
12261
  const { animation } = statesStyle;
@@ -12228,14 +12269,14 @@ function updateStyle(leaf, style, type) {
12228
12269
  delete statesStyle.animation;
12229
12270
  }
12230
12271
  leaf.normalStyle = filterStyle(statesStyle, leaf);
12231
- leaf.set(statesStyle, true);
12272
+ leaf.set(statesStyle, 'temp');
12232
12273
  }
12233
12274
  else {
12234
12275
  leaf.normalStyle = undefined;
12235
12276
  }
12236
12277
  if (transition) {
12237
12278
  const toStyle = filterStyle(fromStyle, leaf);
12238
- leaf.set(fromStyle, true);
12279
+ leaf.set(fromStyle, 'temp');
12239
12280
  leaf.animate([fromStyle, toStyle], transition, 'transition', true);
12240
12281
  }
12241
12282
  leaf.__layout.stateStyleChanged = false;
@@ -12697,7 +12738,8 @@ let Animate = class Animate extends Eventer {
12697
12738
  return;
12698
12739
  if (typeof time === 'object')
12699
12740
  time = UnitConvert.number(time, this.duration);
12700
- time /= this.speed;
12741
+ if (time)
12742
+ time /= this.speed;
12701
12743
  if (!this.started || time < this.time)
12702
12744
  this.start(true);
12703
12745
  this.time = time;
@@ -12932,7 +12974,7 @@ let Animate = class Animate extends Eventer {
12932
12974
  this.emit(AnimateEvent.UPDATE, this);
12933
12975
  }
12934
12976
  setStyle(style) {
12935
- this.target.set(style, this.isTemp);
12977
+ this.target.set(style, this.isTemp ? 'temp' : false);
12936
12978
  }
12937
12979
  clearTimer(fn) {
12938
12980
  if (this.timer) {
@@ -13308,6 +13350,9 @@ const TransitionList = {
13308
13350
  from = fourNumber(from), to = fourNumber(to);
13309
13351
  return from.map((f, i) => number(f, to[i], t));
13310
13352
  },
13353
+ text(from, to, t) {
13354
+ return (typeof from === 'number' || typeof to === 'number') ? MathHelper.float(number(from, to, t), Math.max(getDecimalLen(from), getDecimalLen(to))) : to;
13355
+ },
13311
13356
  shadow,
13312
13357
  innerShadow: shadow
13313
13358
  };
@@ -13316,6 +13361,10 @@ const TransitionModule = {
13316
13361
  number,
13317
13362
  color
13318
13363
  };
13364
+ function getDecimalLen(num) {
13365
+ const decimal = String(num).split('.')[1];
13366
+ return decimal ? decimal.length : 0;
13367
+ }
13319
13368
  function value(from, to, t) {
13320
13369
  return (typeof from === 'number' && typeof to === 'number') ? from + (to - from) * t : to;
13321
13370
  }
@@ -13384,23 +13433,40 @@ const gaussNodes = [0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.97
13384
13433
  const gaussWeights = [0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443];
13385
13434
  const { sqrt } = Math;
13386
13435
  const HighBezierHelper = {
13387
- getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY) {
13388
- let distance = 0, t1, t2, d1X, d1Y, d2X, d2Y;
13436
+ getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, t = 1) {
13437
+ let distance = 0, t1, t2, d1X, d1Y, d2X, d2Y, half = t / 2;
13389
13438
  for (let i = 0; i < gaussNodes.length; i++) {
13390
- t1 = 0.5 * (1 + gaussNodes[i]);
13391
- t2 = 0.5 * (1 - gaussNodes[i]);
13439
+ t1 = half * (1 + gaussNodes[i]);
13440
+ t2 = half * (1 - gaussNodes[i]);
13392
13441
  d1X = getDerivative(t1, fromX, x1, x2, toX);
13393
13442
  d1Y = getDerivative(t1, fromY, y1, y2, toY);
13394
13443
  d2X = getDerivative(t2, fromX, x1, x2, toX);
13395
13444
  d2Y = getDerivative(t2, fromY, y1, y2, toY);
13396
13445
  distance += gaussWeights[i] * (sqrt(d1X * d1X + d1Y * d1Y) + sqrt(d2X * d2X + d2Y * d2Y));
13397
13446
  }
13398
- return distance * 0.5;
13447
+ return distance * half;
13399
13448
  },
13400
13449
  getDerivative(t, fromV, v1, v2, toV) {
13401
13450
  const o = 1 - t;
13402
13451
  return 3 * o * o * (v1 - fromV) + 6 * o * t * (v2 - v1) + 3 * t * t * (toV - v2);
13403
13452
  },
13453
+ getRotation(t, fromX, fromY, x1, y1, x2, y2, toX, toY) {
13454
+ const dx = getDerivative(t, fromX, x1, x2, toX);
13455
+ const dy = getDerivative(t, fromY, y1, y2, toY);
13456
+ return Math.atan2(dy, dx) / OneRadian;
13457
+ },
13458
+ getT(distance, totalDistance, fromX, fromY, x1, y1, x2, y2, toX, toY, precision = 1) {
13459
+ let low = 0, high = 1, middle = distance / totalDistance, realPrecision = precision / totalDistance / 3;
13460
+ if (middle >= 1)
13461
+ return 1;
13462
+ if (middle <= 0)
13463
+ return 0;
13464
+ while (high - low > realPrecision) {
13465
+ getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, middle) < distance ? low = middle : high = middle;
13466
+ middle = (low + high) / 2;
13467
+ }
13468
+ return middle;
13469
+ },
13404
13470
  cut(data, t, fromX, fromY, x1, y1, x2, y2, toX, toY) {
13405
13471
  const o = 1 - t;
13406
13472
  const ax = o * fromX + t * x1, ay = o * fromY + t * y1;
@@ -13412,7 +13478,7 @@ const HighBezierHelper = {
13412
13478
  data.push(PathCommandMap.C, ax, ay, bx, by, cx, cy);
13413
13479
  }
13414
13480
  };
13415
- const { getDerivative } = HighBezierHelper;
13481
+ const { getDerivative, getDistance } = HighBezierHelper;
13416
13482
 
13417
13483
  const { M, L, C, Z } = PathCommandMap;
13418
13484
  const tempPoint = {}, tempFrom = {};
@@ -13480,11 +13546,12 @@ const HighCurveHelper = {
13480
13546
  }
13481
13547
  return { total, segments, data };
13482
13548
  },
13483
- getDistancePoint(distanceData, motionDistance) {
13549
+ getDistancePoint(distanceData, motionDistance, motionPrecision) {
13484
13550
  const { segments, data } = distanceData;
13485
13551
  motionDistance = UnitConvert.number(motionDistance, distanceData.total);
13486
13552
  let total = 0, distance, to = {};
13487
13553
  let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
13554
+ let x1, y1, x2, y2, t;
13488
13555
  const len = data.length;
13489
13556
  while (i < len) {
13490
13557
  command = data[i];
@@ -13514,11 +13581,10 @@ const HighCurveHelper = {
13514
13581
  toY = data[i + 6];
13515
13582
  distance = segments[index];
13516
13583
  if (total + distance > motionDistance) {
13517
- const x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13518
- motionDistance -= total;
13519
- BezierHelper.getPointAndSet(motionDistance / distance, x, y, x1, y1, x2, y2, toX, toY, to);
13520
- BezierHelper.getPointAndSet(Math.max(0, motionDistance - 0.1) / distance, x, y, x1, y1, x2, y2, toX, toY, tempFrom);
13521
- to.rotation = PointHelper.getAngle(tempFrom, to);
13584
+ x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13585
+ t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13586
+ BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
13587
+ to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY);
13522
13588
  return to;
13523
13589
  }
13524
13590
  x = toX;
@@ -13535,11 +13601,12 @@ const HighCurveHelper = {
13535
13601
  }
13536
13602
  return to;
13537
13603
  },
13538
- getDistancePath(distanceData, motionDistance) {
13604
+ getDistancePath(distanceData, motionDistance, motionPrecision) {
13539
13605
  const { segments, data } = distanceData, path = [];
13540
13606
  motionDistance = UnitConvert.number(motionDistance, distanceData.total);
13541
13607
  let total = 0, distance, to = {};
13542
13608
  let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
13609
+ let x1, y1, x2, y2, t;
13543
13610
  const len = data.length;
13544
13611
  while (i < len) {
13545
13612
  command = data[i];
@@ -13566,12 +13633,13 @@ const HighCurveHelper = {
13566
13633
  path.push(command, x, y);
13567
13634
  break;
13568
13635
  case C:
13569
- const x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13636
+ x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13570
13637
  toX = data[i + 5];
13571
13638
  toY = data[i + 6];
13572
13639
  distance = segments[index];
13573
13640
  if (total + distance > motionDistance) {
13574
- HighBezierHelper.cut(path, (motionDistance - total) / distance, x, y, x1, y1, x2, y2, toX, toY);
13641
+ t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13642
+ HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
13575
13643
  return path;
13576
13644
  }
13577
13645
  x = toX;
@@ -13620,6 +13688,7 @@ const ui = UI.prototype;
13620
13688
  const { updateMatrix, updateAllMatrix } = LeafHelper;
13621
13689
  const { updateBounds } = BranchHelper;
13622
13690
  motionPathType()(ui, 'motionPath');
13691
+ motionPathType(1)(ui, 'motionPrecision');
13623
13692
  motionPathType()(ui, 'motion');
13624
13693
  motionPathType(true)(ui, 'motionRotation');
13625
13694
  ui.getMotionPathData = function () {
@@ -13630,7 +13699,7 @@ ui.getMotionPoint = function (motionDistance) {
13630
13699
  const data = getMotionPathData(path);
13631
13700
  if (!data.total)
13632
13701
  return {};
13633
- const point = HighCurveHelper.getDistancePoint(data, motionDistance);
13702
+ const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision);
13634
13703
  MatrixHelper.toOuterPoint(path.localTransform, point);
13635
13704
  const { motionRotation } = this;
13636
13705
  if (motionRotation === false)
@@ -13670,7 +13739,7 @@ function updateMotion(leaf) {
13670
13739
  if (leaf.motionPath) {
13671
13740
  const data = getMotionPathData(leaf);
13672
13741
  if (data.total)
13673
- leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion);
13742
+ leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision);
13674
13743
  }
13675
13744
  else {
13676
13745
  leaf.set(leaf.getMotionPoint(motion));