@leafer-draw/worker 1.5.3 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/worker.js CHANGED
@@ -48,7 +48,7 @@ var LeaferUI = (function (exports) {
48
48
  };
49
49
  const I$1 = IncrementId;
50
50
 
51
- const { round, pow: pow$1, PI: PI$4 } = Math;
51
+ const { round: round$3, pow: pow$1, PI: PI$4 } = Math;
52
52
  const MathHelper = {
53
53
  within(value, min, max) {
54
54
  if (typeof min === 'object')
@@ -112,7 +112,7 @@ var LeaferUI = (function (exports) {
112
112
  },
113
113
  float(num, maxLength) {
114
114
  const a = maxLength !== undefined ? pow$1(10, maxLength) : 1000000000000;
115
- num = round(num * a) / a;
115
+ num = round$3(num * a) / a;
116
116
  return num === -0 ? 0 : num;
117
117
  },
118
118
  getScaleData(scale, size, originSize, scaleData) {
@@ -135,8 +135,15 @@ var LeaferUI = (function (exports) {
135
135
  scaleData.scaleX = scale.x;
136
136
  scaleData.scaleY = scale.y;
137
137
  }
138
+ },
139
+ randInt,
140
+ randColor(opacity) {
141
+ return `rgba(${randInt(255)},${randInt(255)},${randInt(255)},${opacity || 1})`;
138
142
  }
139
143
  };
144
+ function randInt(num) {
145
+ return Math.round(Math.random() * num);
146
+ }
140
147
  const OneRadian = PI$4 / 180;
141
148
  const PI2 = PI$4 * 2;
142
149
  const PI_2 = PI$4 / 2;
@@ -434,7 +441,7 @@ var LeaferUI = (function (exports) {
434
441
  const M$6 = MatrixHelper;
435
442
 
436
443
  const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
437
- const { sin: sin$4, cos: cos$4, abs: abs$4, sqrt: sqrt$2, atan2: atan2$2, min: min$1, PI: PI$3 } = Math;
444
+ const { sin: sin$4, cos: cos$4, abs: abs$4, sqrt: sqrt$2, atan2: atan2$2, min: min$1, round: round$2, PI: PI$3 } = Math;
438
445
  const PointHelper = {
439
446
  defaultPoint: getPointData(),
440
447
  tempPoint: {},
@@ -455,6 +462,10 @@ var LeaferUI = (function (exports) {
455
462
  t.x = x;
456
463
  t.y = y;
457
464
  },
465
+ round(t, halfPixel) {
466
+ t.x = halfPixel ? round$2(t.x - 0.5) + 0.5 : round$2(t.x);
467
+ t.y = halfPixel ? round$2(t.y - 0.5) + 0.5 : round$2(t.y);
468
+ },
458
469
  move(t, x, y) {
459
470
  t.x += x;
460
471
  t.y += y;
@@ -1320,6 +1331,7 @@ var LeaferUI = (function (exports) {
1320
1331
  'E': 1
1321
1332
  };
1322
1333
 
1334
+ const { randColor } = MathHelper;
1323
1335
  class Debug {
1324
1336
  constructor(name) {
1325
1337
  this.repeatMap = {};
@@ -1334,6 +1346,19 @@ var LeaferUI = (function (exports) {
1334
1346
  static set exclude(name) {
1335
1347
  this.excludeList = getNameList(name);
1336
1348
  }
1349
+ static drawRepaint(canvas, bounds) {
1350
+ const color = randColor();
1351
+ canvas.fillWorld(bounds, color.replace('1)', '.1)'));
1352
+ canvas.strokeWorld(bounds, color);
1353
+ }
1354
+ static drawBounds(leaf, canvas, _options) {
1355
+ const showHit = Debug.showBounds === 'hit', w = leaf.__nowWorld, color = randColor();
1356
+ if (showHit)
1357
+ canvas.setWorld(w), leaf.__drawHitPath(canvas), canvas.fillStyle = color.replace('1)', '.2)'), canvas.fill();
1358
+ canvas.resetTransform();
1359
+ canvas.setStroke(color, 2);
1360
+ showHit ? canvas.stroke() : canvas.strokeWorld(w, color);
1361
+ }
1337
1362
  log(...messages) {
1338
1363
  if (D$4.enable) {
1339
1364
  if (D$4.filterList.length && D$4.filterList.every(name => name !== this.name))
@@ -1420,7 +1445,7 @@ var LeaferUI = (function (exports) {
1420
1445
  return rs;
1421
1446
  },
1422
1447
  need(name) {
1423
- console.error('need plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name);
1448
+ console.error('please install plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name);
1424
1449
  }
1425
1450
  };
1426
1451
  setTimeout(() => check.forEach(name => Plugin.has(name, true)));
@@ -2020,7 +2045,7 @@ var LeaferUI = (function (exports) {
2020
2045
  contextMethod()
2021
2046
  ], Canvas.prototype, "strokeText", null);
2022
2047
 
2023
- const { copy: copy$8 } = MatrixHelper;
2048
+ const { copy: copy$8, multiplyParent: multiplyParent$3 } = MatrixHelper, { round: round$1 } = Math;
2024
2049
  const minSize = { width: 1, height: 1, pixelRatio: 1 };
2025
2050
  const canvasSizeAttrs = ['width', 'height', 'pixelRatio'];
2026
2051
  class LeaferCanvasBase extends Canvas {
@@ -2029,6 +2054,8 @@ var LeaferUI = (function (exports) {
2029
2054
  get pixelRatio() { return this.size.pixelRatio; }
2030
2055
  get pixelWidth() { return this.width * this.pixelRatio; }
2031
2056
  get pixelHeight() { return this.height * this.pixelRatio; }
2057
+ get pixelSnap() { return this.config.pixelSnap; }
2058
+ set pixelSnap(value) { this.config.pixelSnap = value; }
2032
2059
  get allowBackgroundColor() { return this.view && this.parentView; }
2033
2060
  constructor(config, manager) {
2034
2061
  super();
@@ -2089,15 +2116,22 @@ var LeaferUI = (function (exports) {
2089
2116
  stopAutoLayout() { }
2090
2117
  setCursor(_cursor) { }
2091
2118
  setWorld(matrix, parentMatrix) {
2092
- const { pixelRatio } = this;
2093
- const w = this.worldTransform;
2094
- if (parentMatrix) {
2095
- const { a, b, c, d, e, f } = parentMatrix;
2096
- this.setTransform(w.a = ((matrix.a * a) + (matrix.b * c)) * pixelRatio, w.b = ((matrix.a * b) + (matrix.b * d)) * pixelRatio, w.c = ((matrix.c * a) + (matrix.d * c)) * pixelRatio, w.d = ((matrix.c * b) + (matrix.d * d)) * pixelRatio, w.e = (((matrix.e * a) + (matrix.f * c) + e)) * pixelRatio, w.f = (((matrix.e * b) + (matrix.f * d) + f)) * pixelRatio);
2097
- }
2098
- else {
2099
- this.setTransform(w.a = matrix.a * pixelRatio, w.b = matrix.b * pixelRatio, w.c = matrix.c * pixelRatio, w.d = matrix.d * pixelRatio, w.e = matrix.e * pixelRatio, w.f = matrix.f * pixelRatio);
2119
+ const { pixelRatio, pixelSnap } = this, w = this.worldTransform;
2120
+ if (parentMatrix)
2121
+ multiplyParent$3(matrix, parentMatrix, w);
2122
+ w.a = matrix.a * pixelRatio;
2123
+ w.b = matrix.b * pixelRatio;
2124
+ w.c = matrix.c * pixelRatio;
2125
+ w.d = matrix.d * pixelRatio;
2126
+ w.e = matrix.e * pixelRatio;
2127
+ w.f = matrix.f * pixelRatio;
2128
+ if (pixelSnap) {
2129
+ if (matrix.half && (matrix.half * pixelRatio) % 2)
2130
+ w.e = round$1(w.e - 0.5) + 0.5, w.f = round$1(w.f - 0.5) + 0.5;
2131
+ else
2132
+ w.e = round$1(w.e), w.f = round$1(w.f);
2100
2133
  }
2134
+ this.setTransform(w.a, w.b, w.c, w.d, w.e, w.f);
2101
2135
  }
2102
2136
  useWorldTransform(worldTransform) {
2103
2137
  if (worldTransform)
@@ -2240,12 +2274,13 @@ var LeaferUI = (function (exports) {
2240
2274
  return this.width === size.width && this.height === size.height && (!size.pixelRatio || this.pixelRatio === size.pixelRatio);
2241
2275
  }
2242
2276
  getSameCanvas(useSameWorldTransform, useSameSmooth) {
2243
- const canvas = this.manager ? this.manager.get(this.size) : Creator.canvas(Object.assign({}, this.size));
2277
+ const { size, pixelSnap } = this, canvas = this.manager ? this.manager.get(size) : Creator.canvas(Object.assign({}, size));
2244
2278
  canvas.save();
2245
2279
  if (useSameWorldTransform)
2246
2280
  copy$8(canvas.worldTransform, this.worldTransform), canvas.useWorldTransform();
2247
2281
  if (useSameSmooth)
2248
2282
  canvas.smooth = this.smooth;
2283
+ canvas.pixelSnap !== pixelSnap && (canvas.pixelSnap = pixelSnap);
2249
2284
  return canvas;
2250
2285
  }
2251
2286
  recycle(clearBounds) {
@@ -3672,7 +3707,7 @@ var LeaferUI = (function (exports) {
3672
3707
  const R = Resource;
3673
3708
 
3674
3709
  const ImageManager = {
3675
- maxRecycled: 100,
3710
+ maxRecycled: 10,
3676
3711
  recycledList: [],
3677
3712
  patternTasker: new TaskProcessor(),
3678
3713
  get(config) {
@@ -4025,9 +4060,8 @@ var LeaferUI = (function (exports) {
4025
4060
  set(value) {
4026
4061
  if (this.__setAttr(key, value)) {
4027
4062
  this.__layout.hitCanvasChanged = true;
4028
- if (Debug.showHitView) {
4063
+ if (Debug.showBounds === 'hit')
4029
4064
  this.__layout.surfaceChanged || this.__layout.surfaceChange();
4030
- }
4031
4065
  if (this.leafer)
4032
4066
  this.leafer.updateCursor();
4033
4067
  }
@@ -4188,7 +4222,7 @@ var LeaferUI = (function (exports) {
4188
4222
  }
4189
4223
 
4190
4224
  const { copy: copy$6, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
4191
- const matrix = {};
4225
+ const matrix = {}, { round } = Math;
4192
4226
  const LeafHelper = {
4193
4227
  updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
4194
4228
  if (checkAutoLayout && leaf.__hasAutoLayout && leaf.__layout.matrixChanged)
@@ -4262,6 +4296,8 @@ var LeaferUI = (function (exports) {
4262
4296
  y = x.y, x = x.x;
4263
4297
  x += t.x;
4264
4298
  y += t.y;
4299
+ if (t.leafer && t.leafer.config.pointSnap)
4300
+ x = round(x), y = round(y);
4265
4301
  transition ? t.animate({ x, y }, transition) : (t.x = x, t.y = y);
4266
4302
  },
4267
4303
  zoomOfWorld(t, origin, scaleX, scaleY, resize, transition) {
@@ -4500,6 +4536,7 @@ var LeaferUI = (function (exports) {
4500
4536
  set contentBounds(bounds) { this._contentBounds = bounds; }
4501
4537
  get strokeBounds() { return this._strokeBounds || this.boxBounds; }
4502
4538
  get renderBounds() { return this._renderBounds || this.boxBounds; }
4539
+ set renderBounds(bounds) { this._renderBounds = bounds; }
4503
4540
  get localContentBounds() { toOuterOf$2(this.contentBounds, this.leaf.__localMatrix, this[localContent] || (this[localContent] = {})); return this[localContent]; }
4504
4541
  get localStrokeBounds() { return this._localStrokeBounds || this; }
4505
4542
  get localRenderBounds() { return this._localRenderBounds || this; }
@@ -4518,11 +4555,13 @@ var LeaferUI = (function (exports) {
4518
4555
  get height() { return this.boxBounds.height; }
4519
4556
  constructor(leaf) {
4520
4557
  this.leaf = leaf;
4521
- this.boxBounds = { x: 0, y: 0, width: 0, height: 0 };
4522
4558
  if (this.leaf.__local)
4523
4559
  this._localRenderBounds = this._localStrokeBounds = this.leaf.__local;
4524
- this.boxChange();
4525
- this.matrixChange();
4560
+ if (leaf.__world) {
4561
+ this.boxBounds = { x: 0, y: 0, width: 0, height: 0 };
4562
+ this.boxChange();
4563
+ this.matrixChange();
4564
+ }
4526
4565
  }
4527
4566
  createLocal() {
4528
4567
  const local = this.leaf.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 };
@@ -4854,6 +4893,9 @@ var LeaferUI = (function (exports) {
4854
4893
  }
4855
4894
  this.old = oldSize;
4856
4895
  }
4896
+ static isResizing(leaf) {
4897
+ return this.resizingKeys && this.resizingKeys[leaf.innerId] !== undefined;
4898
+ }
4857
4899
  }
4858
4900
  ResizeEvent.RESIZE = 'resize';
4859
4901
 
@@ -4896,6 +4938,7 @@ var LeaferUI = (function (exports) {
4896
4938
  }
4897
4939
  RenderEvent.REQUEST = 'render.request';
4898
4940
  RenderEvent.CHILD_START = 'render.child_start';
4941
+ RenderEvent.CHILD_END = 'render.child_end';
4899
4942
  RenderEvent.START = 'render.start';
4900
4943
  RenderEvent.BEFORE = 'render.before';
4901
4944
  RenderEvent.RENDER = 'render';
@@ -5275,24 +5318,27 @@ var LeaferUI = (function (exports) {
5275
5318
  const LeafRender = {
5276
5319
  __render(canvas, options) {
5277
5320
  if (this.__worldOpacity) {
5321
+ const data = this.__;
5278
5322
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5279
- canvas.opacity = this.__.opacity;
5323
+ canvas.opacity = options.dimOpacity && !data.dimskip ? data.opacity * options.dimOpacity : data.opacity;
5280
5324
  if (this.__.__single) {
5281
- if (this.__.eraser === 'path')
5325
+ if (data.eraser === 'path')
5282
5326
  return this.__renderEraser(canvas, options);
5283
5327
  const tempCanvas = canvas.getSameCanvas(true, true);
5284
5328
  this.__draw(tempCanvas, options, canvas);
5285
5329
  if (this.__worldFlipped) {
5286
- canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, this.__.__blendMode, true);
5330
+ canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, data.__blendMode, true);
5287
5331
  }
5288
5332
  else {
5289
- canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, this.__.__blendMode);
5333
+ canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, data.__blendMode);
5290
5334
  }
5291
5335
  tempCanvas.recycle(this.__nowWorld);
5292
5336
  }
5293
5337
  else {
5294
5338
  this.__draw(canvas, options);
5295
5339
  }
5340
+ if (Debug.showBounds)
5341
+ Debug.drawBounds(this, canvas, options);
5296
5342
  }
5297
5343
  },
5298
5344
  __clip(canvas, options) {
@@ -5322,14 +5368,19 @@ var LeaferUI = (function (exports) {
5322
5368
  __render(canvas, options) {
5323
5369
  this.__nowWorld = this.__getNowWorld(options);
5324
5370
  if (this.__worldOpacity) {
5325
- if (this.__.__single) {
5326
- if (this.__.eraser === 'path')
5371
+ const data = this.__;
5372
+ if (data.dim)
5373
+ options.dimOpacity = data.dim === true ? 0.2 : data.dim;
5374
+ else if (data.dimskip)
5375
+ options.dimOpacity && (options.dimOpacity = 0);
5376
+ if (data.__single) {
5377
+ if (data.eraser === 'path')
5327
5378
  return this.__renderEraser(canvas, options);
5328
5379
  const tempCanvas = canvas.getSameCanvas(false, true);
5329
5380
  this.__renderBranch(tempCanvas, options);
5330
5381
  const nowWorld = this.__nowWorld;
5331
- canvas.opacity = this.__.opacity;
5332
- canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, this.__.__blendMode, true);
5382
+ canvas.opacity = options.dimOpacity ? data.opacity * options.dimOpacity : data.opacity;
5383
+ canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, data.__blendMode, true);
5333
5384
  tempCanvas.recycle(nowWorld);
5334
5385
  }
5335
5386
  else {
@@ -5404,9 +5455,11 @@ var LeaferUI = (function (exports) {
5404
5455
  reset(data) {
5405
5456
  if (this.leafer)
5406
5457
  this.leafer.forceRender(this.__world);
5407
- this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1 };
5408
- if (data !== null)
5409
- this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 };
5458
+ if (data !== 0) {
5459
+ this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1 };
5460
+ if (data !== null)
5461
+ this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 };
5462
+ }
5410
5463
  this.__worldOpacity = 1;
5411
5464
  this.__ = new this.__DataProcessor(this);
5412
5465
  this.__layout = new this.__LayoutProcessor(this);
@@ -5542,9 +5595,10 @@ var LeaferUI = (function (exports) {
5542
5595
  if (options.matrix) {
5543
5596
  if (!this.__cameraWorld)
5544
5597
  this.__cameraWorld = {};
5545
- const cameraWorld = this.__cameraWorld;
5546
- multiplyParent(this.__world, options.matrix, cameraWorld, undefined, this.__world);
5598
+ const cameraWorld = this.__cameraWorld, world = this.__world;
5599
+ multiplyParent(world, options.matrix, cameraWorld, undefined, world);
5547
5600
  toOuterOf(this.__layout.renderBounds, cameraWorld, cameraWorld);
5601
+ cameraWorld.half !== world.half && (cameraWorld.half = world.half);
5548
5602
  return cameraWorld;
5549
5603
  }
5550
5604
  else {
@@ -5704,7 +5758,7 @@ var LeaferUI = (function (exports) {
5704
5758
  __updateHitCanvas() { }
5705
5759
  __render(_canvas, _options) { }
5706
5760
  __drawFast(_canvas, _options) { }
5707
- __draw(_canvas, _options) { }
5761
+ __draw(_canvas, _options, _originCanvas) { }
5708
5762
  __clip(_canvas, _options) { }
5709
5763
  __renderShape(_canvas, _options, _ignoreFill, _ignoreStroke) { }
5710
5764
  __updateWorldOpacity() { }
@@ -6074,7 +6128,7 @@ var LeaferUI = (function (exports) {
6074
6128
  }
6075
6129
  }
6076
6130
 
6077
- const version = "1.5.3";
6131
+ const version = "1.6.1";
6078
6132
 
6079
6133
  class LeaferCanvas extends LeaferCanvasBase {
6080
6134
  get allowBackgroundColor() { return true; }
@@ -6314,7 +6368,6 @@ var LeaferUI = (function (exports) {
6314
6368
  }
6315
6369
 
6316
6370
  const { worldBounds } = LeafBoundsHelper;
6317
- const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
6318
6371
  class LayoutBlockData {
6319
6372
  constructor(list) {
6320
6373
  this.updatedBounds = new Bounds();
@@ -6328,13 +6381,7 @@ var LeaferUI = (function (exports) {
6328
6381
  this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
6329
6382
  }
6330
6383
  setAfter() {
6331
- const { list } = this.updatedList;
6332
- if (list.some(leaf => leaf.noBounds)) {
6333
- this.afterBounds.set(bigBounds);
6334
- }
6335
- else {
6336
- this.afterBounds.setListWithFn(list, worldBounds);
6337
- }
6384
+ this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
6338
6385
  this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
6339
6386
  }
6340
6387
  merge(data) {
@@ -6536,6 +6583,22 @@ var LeaferUI = (function (exports) {
6536
6583
  requestLayout() {
6537
6584
  this.target.emit(LayoutEvent.REQUEST);
6538
6585
  }
6586
+ checkRender() {
6587
+ if (this.running) {
6588
+ const { target } = this;
6589
+ if (target.isApp) {
6590
+ target.emit(RenderEvent.CHILD_START, target);
6591
+ target.children.forEach(leafer => {
6592
+ leafer.renderer.FPS = this.FPS;
6593
+ leafer.renderer.checkRender();
6594
+ });
6595
+ target.emit(RenderEvent.CHILD_END, target);
6596
+ }
6597
+ if (this.changed && this.canvas.view)
6598
+ this.render();
6599
+ this.target.emit(RenderEvent.NEXT);
6600
+ }
6601
+ }
6539
6602
  render(callback) {
6540
6603
  if (!(this.running && this.canvas.view))
6541
6604
  return this.update();
@@ -6544,8 +6607,6 @@ var LeaferUI = (function (exports) {
6544
6607
  this.totalBounds = new Bounds();
6545
6608
  debug$2.log(target.innerName, '--->');
6546
6609
  try {
6547
- if (!target.isApp)
6548
- target.app.emit(RenderEvent.CHILD_START, target);
6549
6610
  this.emitRender(RenderEvent.START);
6550
6611
  this.renderOnce(callback);
6551
6612
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -6613,20 +6674,12 @@ var LeaferUI = (function (exports) {
6613
6674
  }
6614
6675
  clipRender(block) {
6615
6676
  const t = Run.start('PartRender');
6616
- const { canvas } = this;
6617
- const bounds = block.getIntersect(canvas.bounds);
6618
- const includes = block.includes(this.target.__world);
6619
- const realBounds = new Bounds(bounds);
6677
+ const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
6620
6678
  canvas.save();
6621
- if (includes && !Debug.showRepaint) {
6622
- canvas.clear();
6623
- }
6624
- else {
6625
- bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
6626
- canvas.clearWorld(bounds, true);
6627
- canvas.clipWorld(bounds, true);
6628
- }
6629
- this.__render(bounds, includes, realBounds);
6679
+ bounds.spread(Renderer.clipSpread).ceil();
6680
+ canvas.clearWorld(bounds, true);
6681
+ canvas.clipWorld(bounds, true);
6682
+ this.__render(bounds, realBounds);
6630
6683
  canvas.restore();
6631
6684
  Run.end(t);
6632
6685
  }
@@ -6635,28 +6688,22 @@ var LeaferUI = (function (exports) {
6635
6688
  const { canvas } = this;
6636
6689
  canvas.save();
6637
6690
  canvas.clear();
6638
- this.__render(canvas.bounds, true);
6691
+ this.__render(canvas.bounds);
6639
6692
  canvas.restore();
6640
6693
  Run.end(t);
6641
6694
  }
6642
- __render(bounds, includes, realBounds) {
6643
- const options = bounds.includes(this.target.__world) ? { includes } : { bounds, includes };
6695
+ __render(bounds, realBounds) {
6696
+ const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
6644
6697
  if (this.needFill)
6645
- this.canvas.fillWorld(bounds, this.config.fill);
6698
+ canvas.fillWorld(bounds, this.config.fill);
6646
6699
  if (Debug.showRepaint)
6647
- this.canvas.strokeWorld(bounds, 'red');
6648
- this.target.__render(this.canvas, options);
6700
+ Debug.drawRepaint(canvas, bounds);
6701
+ this.target.__render(canvas, options);
6649
6702
  this.renderBounds = realBounds = realBounds || bounds;
6650
6703
  this.renderOptions = options;
6651
6704
  this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
6652
- if (Debug.showHitView)
6653
- this.renderHitView(options);
6654
- if (Debug.showBoundsView)
6655
- this.renderBoundsView(options);
6656
- this.canvas.updateRender(realBounds);
6657
- }
6658
- renderHitView(_options) { }
6659
- renderBoundsView(_options) { }
6705
+ canvas.updateRender(realBounds);
6706
+ }
6660
6707
  addBlock(block) {
6661
6708
  if (!this.updateBlocks)
6662
6709
  this.updateBlocks = [];
@@ -6672,17 +6719,16 @@ var LeaferUI = (function (exports) {
6672
6719
  }
6673
6720
  }
6674
6721
  __requestRender() {
6675
- if (this.requestTime)
6722
+ const target = this.target;
6723
+ if (this.requestTime || !target)
6676
6724
  return;
6725
+ if (target.parentApp)
6726
+ return target.parentApp.requestRender(false);
6677
6727
  const requestTime = this.requestTime = Date.now();
6678
6728
  Platform.requestRender(() => {
6679
6729
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
6680
6730
  this.requestTime = 0;
6681
- if (this.running) {
6682
- if (this.changed && this.canvas.view)
6683
- this.render();
6684
- this.target.emit(RenderEvent.NEXT);
6685
- }
6731
+ this.checkRender();
6686
6732
  });
6687
6733
  }
6688
6734
  __onResize(e) {
@@ -6740,6 +6786,7 @@ var LeaferUI = (function (exports) {
6740
6786
  }
6741
6787
  }
6742
6788
  }
6789
+ Renderer.clipSpread = 10;
6743
6790
 
6744
6791
  Object.assign(Creator, {
6745
6792
  watcher: (target, options) => new Watcher(target, options),
@@ -6828,6 +6875,7 @@ var LeaferUI = (function (exports) {
6828
6875
  return strokeWidth;
6829
6876
  }
6830
6877
  get __hasStroke() { return this.stroke && this.strokeWidth; }
6878
+ get __hasHalf() { const t = this; return (t.stroke && t.strokeAlign === 'center' && t.strokeWidth % 2) || undefined; }
6831
6879
  get __hasMultiPaint() {
6832
6880
  const t = this;
6833
6881
  if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
@@ -6872,14 +6920,14 @@ var LeaferUI = (function (exports) {
6872
6920
  this.__removeInput('fill');
6873
6921
  PaintImage.recycleImage('fill', this);
6874
6922
  this.__isFills = false;
6875
- if (this.__pixelFill)
6876
- this.__pixelFill = false;
6923
+ this.__pixelFill && (this.__pixelFill = false);
6877
6924
  }
6878
6925
  this._fill = value;
6879
6926
  }
6880
6927
  else if (typeof value === 'object') {
6881
6928
  this.__setInput('fill', value);
6882
- this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange();
6929
+ const layout = this.__leaf.__layout;
6930
+ layout.boxChanged || layout.boxChange();
6883
6931
  this.__isFills = true;
6884
6932
  this._fill || (this._fill = emptyPaint);
6885
6933
  }
@@ -6890,14 +6938,14 @@ var LeaferUI = (function (exports) {
6890
6938
  this.__removeInput('stroke');
6891
6939
  PaintImage.recycleImage('stroke', this);
6892
6940
  this.__isStrokes = false;
6893
- if (this.__pixelStroke)
6894
- this.__pixelStroke = false;
6941
+ this.__pixelStroke && (this.__pixelStroke = false);
6895
6942
  }
6896
6943
  this._stroke = value;
6897
6944
  }
6898
6945
  else if (typeof value === 'object') {
6899
6946
  this.__setInput('stroke', value);
6900
- this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange();
6947
+ const layout = this.__leaf.__layout;
6948
+ layout.boxChanged || layout.boxChange();
6901
6949
  this.__isStrokes = true;
6902
6950
  this._stroke || (this._stroke = emptyPaint);
6903
6951
  }
@@ -7012,6 +7060,31 @@ var LeaferUI = (function (exports) {
7012
7060
  this._fontWeight = value;
7013
7061
  }
7014
7062
  }
7063
+ setBoxStyle(value) {
7064
+ let t = this.__leaf, box = t.__box;
7065
+ if (value) {
7066
+ const { boxStyle } = this;
7067
+ if (box)
7068
+ for (let key in boxStyle)
7069
+ box[key] = undefined;
7070
+ else
7071
+ box = t.__box = UICreator.get('Rect', 0);
7072
+ const layout = t.__layout, boxLayout = box.__layout;
7073
+ if (!boxStyle)
7074
+ box.parent = t, box.__world = t.__world, boxLayout.boxBounds = layout.boxBounds;
7075
+ box.set(value);
7076
+ if (boxLayout.strokeChanged)
7077
+ layout.strokeChange();
7078
+ if (boxLayout.renderChanged)
7079
+ layout.renderChange();
7080
+ box.__updateChange();
7081
+ }
7082
+ else if (box) {
7083
+ t.__box = box.parent = null;
7084
+ box.destroy();
7085
+ }
7086
+ this._boxStyle = value;
7087
+ }
7015
7088
  }
7016
7089
 
7017
7090
  class ImageData extends RectData {
@@ -7049,7 +7122,7 @@ var LeaferUI = (function (exports) {
7049
7122
  const UIBounds = {
7050
7123
  __updateStrokeSpread() {
7051
7124
  let width = 0, boxWidth = 0;
7052
- const data = this.__, { strokeAlign, strokeWidth } = data;
7125
+ const data = this.__, { strokeAlign, strokeWidth } = data, box = this.__box;
7053
7126
  if ((data.stroke || data.hitStroke === 'all') && strokeWidth && strokeAlign !== 'inside') {
7054
7127
  boxWidth = width = strokeAlign === 'center' ? strokeWidth / 2 : strokeWidth;
7055
7128
  if (!data.__boxStroke) {
@@ -7060,6 +7133,10 @@ var LeaferUI = (function (exports) {
7060
7133
  }
7061
7134
  if (data.__useArrow)
7062
7135
  width += strokeWidth * 5;
7136
+ if (box) {
7137
+ width = Math.max(box.__layout.strokeSpread = box.__updateStrokeSpread(), width);
7138
+ boxWidth = box.__layout.strokeBoxSpread;
7139
+ }
7063
7140
  this.__layout.strokeBoxSpread = boxWidth;
7064
7141
  return width;
7065
7142
  },
@@ -7078,25 +7155,26 @@ var LeaferUI = (function (exports) {
7078
7155
  if (backgroundBlur)
7079
7156
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
7080
7157
  this.__layout.renderShapeSpread = shapeWidth;
7081
- return width + (this.__layout.strokeSpread || 0);
7158
+ width += this.__layout.strokeSpread || 0;
7159
+ return this.__box ? Math.max(this.__box.__updateRenderSpread(), width) : width;
7082
7160
  }
7083
7161
  };
7084
7162
 
7085
7163
  const UIRender = {
7086
7164
  __updateChange() {
7087
- const data = this.__;
7165
+ const data = this.__, w = this.__world;
7088
7166
  if (data.__useEffect) {
7089
7167
  const { shadow, innerShadow, blur, backgroundBlur, filter } = this.__;
7090
7168
  data.__useEffect = !!(shadow || innerShadow || blur || backgroundBlur || filter);
7091
7169
  }
7170
+ const half = data.__hasHalf;
7171
+ w.half !== half && (w.half = half);
7092
7172
  data.__checkSingle();
7093
7173
  const complex = data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect;
7094
- if (complex) {
7174
+ if (complex)
7095
7175
  data.__complex = true;
7096
- }
7097
- else {
7176
+ else
7098
7177
  data.__complex && (data.__complex = false);
7099
- }
7100
7178
  },
7101
7179
  __drawFast(canvas, options) {
7102
7180
  drawFast(this, canvas, options);
@@ -7183,10 +7261,11 @@ var LeaferUI = (function (exports) {
7183
7261
 
7184
7262
  const RectRender = {
7185
7263
  __drawFast(canvas, options) {
7186
- let { width, height, fill, stroke, __drawAfterFill } = this.__;
7264
+ let { x, y, width, height } = this.__layout.boxBounds;
7265
+ const { fill, stroke, __drawAfterFill } = this.__;
7187
7266
  if (fill) {
7188
7267
  canvas.fillStyle = fill;
7189
- canvas.fillRect(0, 0, width, height);
7268
+ canvas.fillRect(x, y, width, height);
7190
7269
  }
7191
7270
  if (__drawAfterFill)
7192
7271
  this.__drawAfterFill(canvas, options);
@@ -7205,14 +7284,14 @@ var LeaferUI = (function (exports) {
7205
7284
  if (width < 0 || height < 0) {
7206
7285
  canvas.save();
7207
7286
  this.__clip(canvas, options);
7208
- canvas.strokeRect(half, half, width, height);
7287
+ canvas.strokeRect(x + half, y + half, width, height);
7209
7288
  canvas.restore();
7210
7289
  }
7211
7290
  else
7212
- canvas.strokeRect(half, half, width, height);
7291
+ canvas.strokeRect(x + half, y + half, width, height);
7213
7292
  break;
7214
7293
  case 'outside':
7215
- canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
7294
+ canvas.strokeRect(x - half, y - half, width + __strokeWidth, height + __strokeWidth);
7216
7295
  break;
7217
7296
  }
7218
7297
  }
@@ -7368,6 +7447,12 @@ var LeaferUI = (function (exports) {
7368
7447
  __decorate([
7369
7448
  surfaceType(false)
7370
7449
  ], exports.UI.prototype, "locked", void 0);
7450
+ __decorate([
7451
+ surfaceType(false)
7452
+ ], exports.UI.prototype, "dim", void 0);
7453
+ __decorate([
7454
+ surfaceType(false)
7455
+ ], exports.UI.prototype, "dimskip", void 0);
7371
7456
  __decorate([
7372
7457
  sortType(0)
7373
7458
  ], exports.UI.prototype, "zIndex", void 0);
@@ -7629,7 +7714,7 @@ var LeaferUI = (function (exports) {
7629
7714
  start: true,
7630
7715
  hittable: true,
7631
7716
  smooth: true,
7632
- lazySpeard: 100
7717
+ lazySpeard: 100,
7633
7718
  };
7634
7719
  this.leafs = 0;
7635
7720
  this.__eventIds = [];
@@ -8053,13 +8138,13 @@ var LeaferUI = (function (exports) {
8053
8138
  super.__updateRenderBounds();
8054
8139
  copy$2(childrenRenderBounds, renderBounds);
8055
8140
  this.__updateRectRenderBounds();
8056
- isOverflow = !includes$1(renderBounds, childrenRenderBounds);
8141
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
8057
8142
  if (isOverflow && this.__.overflow !== 'hide')
8058
8143
  add(renderBounds, childrenRenderBounds);
8059
8144
  }
8060
8145
  else
8061
8146
  this.__updateRectRenderBounds();
8062
- !this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow);
8147
+ this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8063
8148
  }
8064
8149
  __updateRectRenderBounds() { }
8065
8150
  __updateRectChange() { }
@@ -8467,33 +8552,13 @@ var LeaferUI = (function (exports) {
8467
8552
  registerUI()
8468
8553
  ], exports.Canvas);
8469
8554
 
8470
- const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8555
+ const { copyAndSpread, includes, spread, setList } = BoundsHelper;
8471
8556
  exports.Text = class Text extends exports.UI {
8472
8557
  get __tag() { return 'Text'; }
8473
- get textDrawData() {
8474
- this.__layout.update();
8475
- return this.__.__textDrawData;
8476
- }
8558
+ get textDrawData() { this.updateLayout(); return this.__.__textDrawData; }
8477
8559
  constructor(data) {
8478
8560
  super(data);
8479
8561
  }
8480
- __drawHitPath(canvas) {
8481
- const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8482
- canvas.beginPath();
8483
- if (this.__.__letterSpacing < 0) {
8484
- this.__drawPathByData(canvas);
8485
- }
8486
- else {
8487
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8488
- }
8489
- }
8490
- __drawPathByData(drawer, _data) {
8491
- const { x, y, width, height } = this.__layout.boxBounds;
8492
- drawer.rect(x, y, width, height);
8493
- }
8494
- __drawRenderPath(canvas) {
8495
- canvas.font = this.__.__font;
8496
- }
8497
8562
  __updateTextDrawData() {
8498
8563
  const data = this.__;
8499
8564
  const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data;
@@ -8510,15 +8575,16 @@ var LeaferUI = (function (exports) {
8510
8575
  const layout = this.__layout;
8511
8576
  const { fontSize, italic, padding, __autoWidth: autoWidth, __autoHeight: autoHeight } = data;
8512
8577
  this.__updateTextDrawData();
8513
- const { bounds } = data.__textDrawData;
8578
+ const { bounds: contentBounds } = data.__textDrawData;
8514
8579
  const b = layout.boxBounds;
8580
+ layout.contentBounds = contentBounds;
8515
8581
  if (data.__lineHeight < fontSize)
8516
- spread(bounds, fontSize / 2);
8582
+ spread(contentBounds, fontSize / 2);
8517
8583
  if (autoWidth || autoHeight) {
8518
- b.x = autoWidth ? bounds.x : 0;
8519
- b.y = autoHeight ? bounds.y : 0;
8520
- b.width = autoWidth ? bounds.width : data.width;
8521
- b.height = autoHeight ? bounds.height : data.height;
8584
+ b.x = autoWidth ? contentBounds.x : 0;
8585
+ b.y = autoHeight ? contentBounds.y : 0;
8586
+ b.width = autoWidth ? contentBounds.width : data.width;
8587
+ b.height = autoHeight ? contentBounds.height : data.height;
8522
8588
  if (padding) {
8523
8589
  const [top, right, bottom, left] = data.__padding;
8524
8590
  if (autoWidth)
@@ -8532,23 +8598,45 @@ var LeaferUI = (function (exports) {
8532
8598
  super.__updateBoxBounds();
8533
8599
  if (italic)
8534
8600
  b.width += fontSize * 0.16;
8535
- const contentBounds = includes(b, bounds) ? b : bounds;
8536
- if (!isSame$1(contentBounds, layout.contentBounds)) {
8537
- layout.contentBounds = contentBounds;
8538
- layout.renderChanged = true;
8539
- setList(data.__textBoxBounds = {}, [b, bounds]);
8540
- }
8601
+ const isOverflow = !includes(b, contentBounds) || undefined;
8602
+ if (isOverflow)
8603
+ setList(data.__textBoxBounds = {}, [b, contentBounds]), layout.renderChanged = true;
8541
8604
  else
8542
- data.__textBoxBounds = contentBounds;
8605
+ data.__textBoxBounds = b;
8606
+ this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8607
+ }
8608
+ __onUpdateSize() {
8609
+ if (this.__box)
8610
+ this.__box.__onUpdateSize();
8611
+ super.__onUpdateSize();
8543
8612
  }
8544
8613
  __updateRenderSpread() {
8545
8614
  let width = super.__updateRenderSpread();
8546
8615
  if (!width)
8547
- width = this.__layout.boxBounds === this.__layout.contentBounds ? 0 : 1;
8616
+ width = this.isOverflow ? 1 : 0;
8548
8617
  return width;
8549
8618
  }
8550
8619
  __updateRenderBounds() {
8551
- copyAndSpread(this.__layout.renderBounds, this.__.__textBoxBounds, this.__layout.renderSpread);
8620
+ const { renderBounds, renderSpread } = this.__layout;
8621
+ copyAndSpread(renderBounds, this.__.__textBoxBounds, renderSpread);
8622
+ if (this.__box)
8623
+ this.__box.__layout.renderBounds = renderBounds;
8624
+ }
8625
+ __drawRenderPath(canvas) {
8626
+ canvas.font = this.__.__font;
8627
+ }
8628
+ __draw(canvas, options, originCanvas) {
8629
+ const box = this.__box;
8630
+ if (box)
8631
+ box.__nowWorld = this.__nowWorld, box.__draw(canvas, options, originCanvas);
8632
+ if (this.textEditing && !Export.running)
8633
+ return;
8634
+ super.__draw(canvas, options, originCanvas);
8635
+ }
8636
+ destroy() {
8637
+ if (this.boxStyle)
8638
+ this.boxStyle = null;
8639
+ super.destroy();
8552
8640
  }
8553
8641
  };
8554
8642
  __decorate([
@@ -8560,6 +8648,9 @@ var LeaferUI = (function (exports) {
8560
8648
  __decorate([
8561
8649
  boundsType(0)
8562
8650
  ], exports.Text.prototype, "height", void 0);
8651
+ __decorate([
8652
+ surfaceType()
8653
+ ], exports.Text.prototype, "boxStyle", void 0);
8563
8654
  __decorate([
8564
8655
  dataType(false)
8565
8656
  ], exports.Text.prototype, "resizeFontSize", void 0);
@@ -9045,9 +9136,11 @@ var LeaferUI = (function (exports) {
9045
9136
  const tempPoint = {};
9046
9137
  const tempScaleData = {};
9047
9138
  function createData(leafPaint, image, paint, box) {
9048
- const { blendMode, sync } = paint;
9139
+ const { blendMode, changeful, sync } = paint;
9049
9140
  if (blendMode)
9050
9141
  leafPaint.blendMode = blendMode;
9142
+ if (changeful)
9143
+ leafPaint.changeful = changeful;
9051
9144
  if (sync)
9052
9145
  leafPaint.sync = sync;
9053
9146
  leafPaint.data = getPatternData(paint, box, image);
@@ -9280,40 +9373,32 @@ var LeaferUI = (function (exports) {
9280
9373
  }
9281
9374
 
9282
9375
  const { abs } = Math;
9283
- function checkImage(ui, canvas, paint, allowPaint) {
9376
+ function checkImage(ui, canvas, paint, allowDraw) {
9284
9377
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
9285
- const { pixelRatio } = canvas;
9286
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
9378
+ const { pixelRatio } = canvas, { data } = paint;
9379
+ if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
9287
9380
  return false;
9288
9381
  }
9289
9382
  else {
9290
- const { data } = paint;
9291
- if (allowPaint) {
9292
- if (!data.repeat) {
9293
- let { width, height } = data;
9294
- width *= abs(scaleX) * pixelRatio;
9295
- height *= abs(scaleY) * pixelRatio;
9296
- if (data.scaleX) {
9297
- width *= data.scaleX;
9298
- height *= data.scaleY;
9299
- }
9300
- allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
9383
+ if (allowDraw) {
9384
+ if (data.repeat) {
9385
+ allowDraw = false;
9301
9386
  }
9302
9387
  else {
9303
- allowPaint = false;
9388
+ if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
9389
+ let { width, height } = data;
9390
+ width *= abs(scaleX) * pixelRatio;
9391
+ height *= abs(scaleY) * pixelRatio;
9392
+ if (data.scaleX) {
9393
+ width *= data.scaleX;
9394
+ height *= data.scaleY;
9395
+ }
9396
+ allowDraw = (width * height > Platform.image.maxCacheSize);
9397
+ }
9304
9398
  }
9305
9399
  }
9306
- if (allowPaint) {
9307
- canvas.save();
9308
- ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9309
- if (paint.blendMode)
9310
- canvas.blendMode = paint.blendMode;
9311
- if (data.opacity)
9312
- canvas.opacity *= data.opacity;
9313
- if (data.transform)
9314
- canvas.transform(data.transform);
9315
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
9316
- canvas.restore();
9400
+ if (allowDraw) {
9401
+ drawImage(ui, canvas, paint, data);
9317
9402
  return true;
9318
9403
  }
9319
9404
  else {
@@ -9334,13 +9419,26 @@ var LeaferUI = (function (exports) {
9334
9419
  }
9335
9420
  }
9336
9421
  }
9422
+ function drawImage(ui, canvas, paint, data) {
9423
+ canvas.save();
9424
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9425
+ if (paint.blendMode)
9426
+ canvas.blendMode = paint.blendMode;
9427
+ if (data.opacity)
9428
+ canvas.opacity *= data.opacity;
9429
+ if (data.transform)
9430
+ canvas.transform(data.transform);
9431
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
9432
+ canvas.restore();
9433
+ }
9337
9434
 
9338
9435
  function recycleImage(attrName, data) {
9339
9436
  const paints = data['_' + attrName];
9340
9437
  if (paints instanceof Array) {
9341
- let image, recycleMap, input, url;
9438
+ let paint, image, recycleMap, input, url;
9342
9439
  for (let i = 0, len = paints.length; i < len; i++) {
9343
- image = paints[i].image;
9440
+ paint = paints[i];
9441
+ image = paint.image;
9344
9442
  url = image && image.url;
9345
9443
  if (url) {
9346
9444
  if (!recycleMap)
@@ -9355,8 +9453,6 @@ var LeaferUI = (function (exports) {
9355
9453
  }
9356
9454
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
9357
9455
  }
9358
- else
9359
- paints[i].style = null;
9360
9456
  }
9361
9457
  }
9362
9458
  return recycleMap;
@@ -9535,7 +9631,7 @@ var LeaferUI = (function (exports) {
9535
9631
  const offsetOutBounds = {};
9536
9632
  function innerShadow(ui, current, shape) {
9537
9633
  let copyBounds, spreadScale;
9538
- const { __nowWorld: nowWorld, __layout: __layout } = ui;
9634
+ const { __nowWorld: nowWorld, __layout } = ui;
9539
9635
  const { innerShadow } = ui.__;
9540
9636
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
9541
9637
  const other = current.getSameCanvas();