leafer-draw 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/web.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
  const debug$4 = Debug.get('LeaferCanvas');
6080
6134
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6495,7 +6549,6 @@ var LeaferUI = (function (exports) {
6495
6549
  }
6496
6550
 
6497
6551
  const { worldBounds } = LeafBoundsHelper;
6498
- const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
6499
6552
  class LayoutBlockData {
6500
6553
  constructor(list) {
6501
6554
  this.updatedBounds = new Bounds();
@@ -6509,13 +6562,7 @@ var LeaferUI = (function (exports) {
6509
6562
  this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
6510
6563
  }
6511
6564
  setAfter() {
6512
- const { list } = this.updatedList;
6513
- if (list.some(leaf => leaf.noBounds)) {
6514
- this.afterBounds.set(bigBounds);
6515
- }
6516
- else {
6517
- this.afterBounds.setListWithFn(list, worldBounds);
6518
- }
6565
+ this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
6519
6566
  this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
6520
6567
  }
6521
6568
  merge(data) {
@@ -6717,6 +6764,22 @@ var LeaferUI = (function (exports) {
6717
6764
  requestLayout() {
6718
6765
  this.target.emit(LayoutEvent.REQUEST);
6719
6766
  }
6767
+ checkRender() {
6768
+ if (this.running) {
6769
+ const { target } = this;
6770
+ if (target.isApp) {
6771
+ target.emit(RenderEvent.CHILD_START, target);
6772
+ target.children.forEach(leafer => {
6773
+ leafer.renderer.FPS = this.FPS;
6774
+ leafer.renderer.checkRender();
6775
+ });
6776
+ target.emit(RenderEvent.CHILD_END, target);
6777
+ }
6778
+ if (this.changed && this.canvas.view)
6779
+ this.render();
6780
+ this.target.emit(RenderEvent.NEXT);
6781
+ }
6782
+ }
6720
6783
  render(callback) {
6721
6784
  if (!(this.running && this.canvas.view))
6722
6785
  return this.update();
@@ -6725,8 +6788,6 @@ var LeaferUI = (function (exports) {
6725
6788
  this.totalBounds = new Bounds();
6726
6789
  debug$2.log(target.innerName, '--->');
6727
6790
  try {
6728
- if (!target.isApp)
6729
- target.app.emit(RenderEvent.CHILD_START, target);
6730
6791
  this.emitRender(RenderEvent.START);
6731
6792
  this.renderOnce(callback);
6732
6793
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -6794,20 +6855,12 @@ var LeaferUI = (function (exports) {
6794
6855
  }
6795
6856
  clipRender(block) {
6796
6857
  const t = Run.start('PartRender');
6797
- const { canvas } = this;
6798
- const bounds = block.getIntersect(canvas.bounds);
6799
- const includes = block.includes(this.target.__world);
6800
- const realBounds = new Bounds(bounds);
6858
+ const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
6801
6859
  canvas.save();
6802
- if (includes && !Debug.showRepaint) {
6803
- canvas.clear();
6804
- }
6805
- else {
6806
- bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
6807
- canvas.clearWorld(bounds, true);
6808
- canvas.clipWorld(bounds, true);
6809
- }
6810
- this.__render(bounds, includes, realBounds);
6860
+ bounds.spread(Renderer.clipSpread).ceil();
6861
+ canvas.clearWorld(bounds, true);
6862
+ canvas.clipWorld(bounds, true);
6863
+ this.__render(bounds, realBounds);
6811
6864
  canvas.restore();
6812
6865
  Run.end(t);
6813
6866
  }
@@ -6816,28 +6869,22 @@ var LeaferUI = (function (exports) {
6816
6869
  const { canvas } = this;
6817
6870
  canvas.save();
6818
6871
  canvas.clear();
6819
- this.__render(canvas.bounds, true);
6872
+ this.__render(canvas.bounds);
6820
6873
  canvas.restore();
6821
6874
  Run.end(t);
6822
6875
  }
6823
- __render(bounds, includes, realBounds) {
6824
- const options = bounds.includes(this.target.__world) ? { includes } : { bounds, includes };
6876
+ __render(bounds, realBounds) {
6877
+ const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
6825
6878
  if (this.needFill)
6826
- this.canvas.fillWorld(bounds, this.config.fill);
6879
+ canvas.fillWorld(bounds, this.config.fill);
6827
6880
  if (Debug.showRepaint)
6828
- this.canvas.strokeWorld(bounds, 'red');
6829
- this.target.__render(this.canvas, options);
6881
+ Debug.drawRepaint(canvas, bounds);
6882
+ this.target.__render(canvas, options);
6830
6883
  this.renderBounds = realBounds = realBounds || bounds;
6831
6884
  this.renderOptions = options;
6832
6885
  this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
6833
- if (Debug.showHitView)
6834
- this.renderHitView(options);
6835
- if (Debug.showBoundsView)
6836
- this.renderBoundsView(options);
6837
- this.canvas.updateRender(realBounds);
6838
- }
6839
- renderHitView(_options) { }
6840
- renderBoundsView(_options) { }
6886
+ canvas.updateRender(realBounds);
6887
+ }
6841
6888
  addBlock(block) {
6842
6889
  if (!this.updateBlocks)
6843
6890
  this.updateBlocks = [];
@@ -6853,17 +6900,16 @@ var LeaferUI = (function (exports) {
6853
6900
  }
6854
6901
  }
6855
6902
  __requestRender() {
6856
- if (this.requestTime)
6903
+ const target = this.target;
6904
+ if (this.requestTime || !target)
6857
6905
  return;
6906
+ if (target.parentApp)
6907
+ return target.parentApp.requestRender(false);
6858
6908
  const requestTime = this.requestTime = Date.now();
6859
6909
  Platform.requestRender(() => {
6860
6910
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
6861
6911
  this.requestTime = 0;
6862
- if (this.running) {
6863
- if (this.changed && this.canvas.view)
6864
- this.render();
6865
- this.target.emit(RenderEvent.NEXT);
6866
- }
6912
+ this.checkRender();
6867
6913
  });
6868
6914
  }
6869
6915
  __onResize(e) {
@@ -6921,6 +6967,7 @@ var LeaferUI = (function (exports) {
6921
6967
  }
6922
6968
  }
6923
6969
  }
6970
+ Renderer.clipSpread = 10;
6924
6971
 
6925
6972
  Object.assign(Creator, {
6926
6973
  watcher: (target, options) => new Watcher(target, options),
@@ -7009,6 +7056,7 @@ var LeaferUI = (function (exports) {
7009
7056
  return strokeWidth;
7010
7057
  }
7011
7058
  get __hasStroke() { return this.stroke && this.strokeWidth; }
7059
+ get __hasHalf() { const t = this; return (t.stroke && t.strokeAlign === 'center' && t.strokeWidth % 2) || undefined; }
7012
7060
  get __hasMultiPaint() {
7013
7061
  const t = this;
7014
7062
  if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
@@ -7053,14 +7101,14 @@ var LeaferUI = (function (exports) {
7053
7101
  this.__removeInput('fill');
7054
7102
  PaintImage.recycleImage('fill', this);
7055
7103
  this.__isFills = false;
7056
- if (this.__pixelFill)
7057
- this.__pixelFill = false;
7104
+ this.__pixelFill && (this.__pixelFill = false);
7058
7105
  }
7059
7106
  this._fill = value;
7060
7107
  }
7061
7108
  else if (typeof value === 'object') {
7062
7109
  this.__setInput('fill', value);
7063
- this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange();
7110
+ const layout = this.__leaf.__layout;
7111
+ layout.boxChanged || layout.boxChange();
7064
7112
  this.__isFills = true;
7065
7113
  this._fill || (this._fill = emptyPaint);
7066
7114
  }
@@ -7071,14 +7119,14 @@ var LeaferUI = (function (exports) {
7071
7119
  this.__removeInput('stroke');
7072
7120
  PaintImage.recycleImage('stroke', this);
7073
7121
  this.__isStrokes = false;
7074
- if (this.__pixelStroke)
7075
- this.__pixelStroke = false;
7122
+ this.__pixelStroke && (this.__pixelStroke = false);
7076
7123
  }
7077
7124
  this._stroke = value;
7078
7125
  }
7079
7126
  else if (typeof value === 'object') {
7080
7127
  this.__setInput('stroke', value);
7081
- this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange();
7128
+ const layout = this.__leaf.__layout;
7129
+ layout.boxChanged || layout.boxChange();
7082
7130
  this.__isStrokes = true;
7083
7131
  this._stroke || (this._stroke = emptyPaint);
7084
7132
  }
@@ -7193,6 +7241,31 @@ var LeaferUI = (function (exports) {
7193
7241
  this._fontWeight = value;
7194
7242
  }
7195
7243
  }
7244
+ setBoxStyle(value) {
7245
+ let t = this.__leaf, box = t.__box;
7246
+ if (value) {
7247
+ const { boxStyle } = this;
7248
+ if (box)
7249
+ for (let key in boxStyle)
7250
+ box[key] = undefined;
7251
+ else
7252
+ box = t.__box = UICreator.get('Rect', 0);
7253
+ const layout = t.__layout, boxLayout = box.__layout;
7254
+ if (!boxStyle)
7255
+ box.parent = t, box.__world = t.__world, boxLayout.boxBounds = layout.boxBounds;
7256
+ box.set(value);
7257
+ if (boxLayout.strokeChanged)
7258
+ layout.strokeChange();
7259
+ if (boxLayout.renderChanged)
7260
+ layout.renderChange();
7261
+ box.__updateChange();
7262
+ }
7263
+ else if (box) {
7264
+ t.__box = box.parent = null;
7265
+ box.destroy();
7266
+ }
7267
+ this._boxStyle = value;
7268
+ }
7196
7269
  }
7197
7270
 
7198
7271
  class ImageData extends RectData {
@@ -7230,7 +7303,7 @@ var LeaferUI = (function (exports) {
7230
7303
  const UIBounds = {
7231
7304
  __updateStrokeSpread() {
7232
7305
  let width = 0, boxWidth = 0;
7233
- const data = this.__, { strokeAlign, strokeWidth } = data;
7306
+ const data = this.__, { strokeAlign, strokeWidth } = data, box = this.__box;
7234
7307
  if ((data.stroke || data.hitStroke === 'all') && strokeWidth && strokeAlign !== 'inside') {
7235
7308
  boxWidth = width = strokeAlign === 'center' ? strokeWidth / 2 : strokeWidth;
7236
7309
  if (!data.__boxStroke) {
@@ -7241,6 +7314,10 @@ var LeaferUI = (function (exports) {
7241
7314
  }
7242
7315
  if (data.__useArrow)
7243
7316
  width += strokeWidth * 5;
7317
+ if (box) {
7318
+ width = Math.max(box.__layout.strokeSpread = box.__updateStrokeSpread(), width);
7319
+ boxWidth = box.__layout.strokeBoxSpread;
7320
+ }
7244
7321
  this.__layout.strokeBoxSpread = boxWidth;
7245
7322
  return width;
7246
7323
  },
@@ -7259,25 +7336,26 @@ var LeaferUI = (function (exports) {
7259
7336
  if (backgroundBlur)
7260
7337
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
7261
7338
  this.__layout.renderShapeSpread = shapeWidth;
7262
- return width + (this.__layout.strokeSpread || 0);
7339
+ width += this.__layout.strokeSpread || 0;
7340
+ return this.__box ? Math.max(this.__box.__updateRenderSpread(), width) : width;
7263
7341
  }
7264
7342
  };
7265
7343
 
7266
7344
  const UIRender = {
7267
7345
  __updateChange() {
7268
- const data = this.__;
7346
+ const data = this.__, w = this.__world;
7269
7347
  if (data.__useEffect) {
7270
7348
  const { shadow, innerShadow, blur, backgroundBlur, filter } = this.__;
7271
7349
  data.__useEffect = !!(shadow || innerShadow || blur || backgroundBlur || filter);
7272
7350
  }
7351
+ const half = data.__hasHalf;
7352
+ w.half !== half && (w.half = half);
7273
7353
  data.__checkSingle();
7274
7354
  const complex = data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect;
7275
- if (complex) {
7355
+ if (complex)
7276
7356
  data.__complex = true;
7277
- }
7278
- else {
7357
+ else
7279
7358
  data.__complex && (data.__complex = false);
7280
- }
7281
7359
  },
7282
7360
  __drawFast(canvas, options) {
7283
7361
  drawFast(this, canvas, options);
@@ -7364,10 +7442,11 @@ var LeaferUI = (function (exports) {
7364
7442
 
7365
7443
  const RectRender = {
7366
7444
  __drawFast(canvas, options) {
7367
- let { width, height, fill, stroke, __drawAfterFill } = this.__;
7445
+ let { x, y, width, height } = this.__layout.boxBounds;
7446
+ const { fill, stroke, __drawAfterFill } = this.__;
7368
7447
  if (fill) {
7369
7448
  canvas.fillStyle = fill;
7370
- canvas.fillRect(0, 0, width, height);
7449
+ canvas.fillRect(x, y, width, height);
7371
7450
  }
7372
7451
  if (__drawAfterFill)
7373
7452
  this.__drawAfterFill(canvas, options);
@@ -7386,14 +7465,14 @@ var LeaferUI = (function (exports) {
7386
7465
  if (width < 0 || height < 0) {
7387
7466
  canvas.save();
7388
7467
  this.__clip(canvas, options);
7389
- canvas.strokeRect(half, half, width, height);
7468
+ canvas.strokeRect(x + half, y + half, width, height);
7390
7469
  canvas.restore();
7391
7470
  }
7392
7471
  else
7393
- canvas.strokeRect(half, half, width, height);
7472
+ canvas.strokeRect(x + half, y + half, width, height);
7394
7473
  break;
7395
7474
  case 'outside':
7396
- canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
7475
+ canvas.strokeRect(x - half, y - half, width + __strokeWidth, height + __strokeWidth);
7397
7476
  break;
7398
7477
  }
7399
7478
  }
@@ -7549,6 +7628,12 @@ var LeaferUI = (function (exports) {
7549
7628
  __decorate([
7550
7629
  surfaceType(false)
7551
7630
  ], exports.UI.prototype, "locked", void 0);
7631
+ __decorate([
7632
+ surfaceType(false)
7633
+ ], exports.UI.prototype, "dim", void 0);
7634
+ __decorate([
7635
+ surfaceType(false)
7636
+ ], exports.UI.prototype, "dimskip", void 0);
7552
7637
  __decorate([
7553
7638
  sortType(0)
7554
7639
  ], exports.UI.prototype, "zIndex", void 0);
@@ -7810,7 +7895,7 @@ var LeaferUI = (function (exports) {
7810
7895
  start: true,
7811
7896
  hittable: true,
7812
7897
  smooth: true,
7813
- lazySpeard: 100
7898
+ lazySpeard: 100,
7814
7899
  };
7815
7900
  this.leafs = 0;
7816
7901
  this.__eventIds = [];
@@ -8234,13 +8319,13 @@ var LeaferUI = (function (exports) {
8234
8319
  super.__updateRenderBounds();
8235
8320
  copy$2(childrenRenderBounds, renderBounds);
8236
8321
  this.__updateRectRenderBounds();
8237
- isOverflow = !includes$1(renderBounds, childrenRenderBounds);
8322
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
8238
8323
  if (isOverflow && this.__.overflow !== 'hide')
8239
8324
  add(renderBounds, childrenRenderBounds);
8240
8325
  }
8241
8326
  else
8242
8327
  this.__updateRectRenderBounds();
8243
- !this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow);
8328
+ this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8244
8329
  }
8245
8330
  __updateRectRenderBounds() { }
8246
8331
  __updateRectChange() { }
@@ -8648,33 +8733,13 @@ var LeaferUI = (function (exports) {
8648
8733
  registerUI()
8649
8734
  ], exports.Canvas);
8650
8735
 
8651
- const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8736
+ const { copyAndSpread, includes, spread, setList } = BoundsHelper;
8652
8737
  exports.Text = class Text extends exports.UI {
8653
8738
  get __tag() { return 'Text'; }
8654
- get textDrawData() {
8655
- this.__layout.update();
8656
- return this.__.__textDrawData;
8657
- }
8739
+ get textDrawData() { this.updateLayout(); return this.__.__textDrawData; }
8658
8740
  constructor(data) {
8659
8741
  super(data);
8660
8742
  }
8661
- __drawHitPath(canvas) {
8662
- const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8663
- canvas.beginPath();
8664
- if (this.__.__letterSpacing < 0) {
8665
- this.__drawPathByData(canvas);
8666
- }
8667
- else {
8668
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8669
- }
8670
- }
8671
- __drawPathByData(drawer, _data) {
8672
- const { x, y, width, height } = this.__layout.boxBounds;
8673
- drawer.rect(x, y, width, height);
8674
- }
8675
- __drawRenderPath(canvas) {
8676
- canvas.font = this.__.__font;
8677
- }
8678
8743
  __updateTextDrawData() {
8679
8744
  const data = this.__;
8680
8745
  const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data;
@@ -8691,15 +8756,16 @@ var LeaferUI = (function (exports) {
8691
8756
  const layout = this.__layout;
8692
8757
  const { fontSize, italic, padding, __autoWidth: autoWidth, __autoHeight: autoHeight } = data;
8693
8758
  this.__updateTextDrawData();
8694
- const { bounds } = data.__textDrawData;
8759
+ const { bounds: contentBounds } = data.__textDrawData;
8695
8760
  const b = layout.boxBounds;
8761
+ layout.contentBounds = contentBounds;
8696
8762
  if (data.__lineHeight < fontSize)
8697
- spread(bounds, fontSize / 2);
8763
+ spread(contentBounds, fontSize / 2);
8698
8764
  if (autoWidth || autoHeight) {
8699
- b.x = autoWidth ? bounds.x : 0;
8700
- b.y = autoHeight ? bounds.y : 0;
8701
- b.width = autoWidth ? bounds.width : data.width;
8702
- b.height = autoHeight ? bounds.height : data.height;
8765
+ b.x = autoWidth ? contentBounds.x : 0;
8766
+ b.y = autoHeight ? contentBounds.y : 0;
8767
+ b.width = autoWidth ? contentBounds.width : data.width;
8768
+ b.height = autoHeight ? contentBounds.height : data.height;
8703
8769
  if (padding) {
8704
8770
  const [top, right, bottom, left] = data.__padding;
8705
8771
  if (autoWidth)
@@ -8713,23 +8779,45 @@ var LeaferUI = (function (exports) {
8713
8779
  super.__updateBoxBounds();
8714
8780
  if (italic)
8715
8781
  b.width += fontSize * 0.16;
8716
- const contentBounds = includes(b, bounds) ? b : bounds;
8717
- if (!isSame$1(contentBounds, layout.contentBounds)) {
8718
- layout.contentBounds = contentBounds;
8719
- layout.renderChanged = true;
8720
- setList(data.__textBoxBounds = {}, [b, bounds]);
8721
- }
8782
+ const isOverflow = !includes(b, contentBounds) || undefined;
8783
+ if (isOverflow)
8784
+ setList(data.__textBoxBounds = {}, [b, contentBounds]), layout.renderChanged = true;
8722
8785
  else
8723
- data.__textBoxBounds = contentBounds;
8786
+ data.__textBoxBounds = b;
8787
+ this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8788
+ }
8789
+ __onUpdateSize() {
8790
+ if (this.__box)
8791
+ this.__box.__onUpdateSize();
8792
+ super.__onUpdateSize();
8724
8793
  }
8725
8794
  __updateRenderSpread() {
8726
8795
  let width = super.__updateRenderSpread();
8727
8796
  if (!width)
8728
- width = this.__layout.boxBounds === this.__layout.contentBounds ? 0 : 1;
8797
+ width = this.isOverflow ? 1 : 0;
8729
8798
  return width;
8730
8799
  }
8731
8800
  __updateRenderBounds() {
8732
- copyAndSpread(this.__layout.renderBounds, this.__.__textBoxBounds, this.__layout.renderSpread);
8801
+ const { renderBounds, renderSpread } = this.__layout;
8802
+ copyAndSpread(renderBounds, this.__.__textBoxBounds, renderSpread);
8803
+ if (this.__box)
8804
+ this.__box.__layout.renderBounds = renderBounds;
8805
+ }
8806
+ __drawRenderPath(canvas) {
8807
+ canvas.font = this.__.__font;
8808
+ }
8809
+ __draw(canvas, options, originCanvas) {
8810
+ const box = this.__box;
8811
+ if (box)
8812
+ box.__nowWorld = this.__nowWorld, box.__draw(canvas, options, originCanvas);
8813
+ if (this.textEditing && !Export.running)
8814
+ return;
8815
+ super.__draw(canvas, options, originCanvas);
8816
+ }
8817
+ destroy() {
8818
+ if (this.boxStyle)
8819
+ this.boxStyle = null;
8820
+ super.destroy();
8733
8821
  }
8734
8822
  };
8735
8823
  __decorate([
@@ -8741,6 +8829,9 @@ var LeaferUI = (function (exports) {
8741
8829
  __decorate([
8742
8830
  boundsType(0)
8743
8831
  ], exports.Text.prototype, "height", void 0);
8832
+ __decorate([
8833
+ surfaceType()
8834
+ ], exports.Text.prototype, "boxStyle", void 0);
8744
8835
  __decorate([
8745
8836
  dataType(false)
8746
8837
  ], exports.Text.prototype, "resizeFontSize", void 0);
@@ -9226,9 +9317,11 @@ var LeaferUI = (function (exports) {
9226
9317
  const tempPoint = {};
9227
9318
  const tempScaleData = {};
9228
9319
  function createData(leafPaint, image, paint, box) {
9229
- const { blendMode, sync } = paint;
9320
+ const { blendMode, changeful, sync } = paint;
9230
9321
  if (blendMode)
9231
9322
  leafPaint.blendMode = blendMode;
9323
+ if (changeful)
9324
+ leafPaint.changeful = changeful;
9232
9325
  if (sync)
9233
9326
  leafPaint.sync = sync;
9234
9327
  leafPaint.data = getPatternData(paint, box, image);
@@ -9461,40 +9554,32 @@ var LeaferUI = (function (exports) {
9461
9554
  }
9462
9555
 
9463
9556
  const { abs } = Math;
9464
- function checkImage(ui, canvas, paint, allowPaint) {
9557
+ function checkImage(ui, canvas, paint, allowDraw) {
9465
9558
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
9466
- const { pixelRatio } = canvas;
9467
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
9559
+ const { pixelRatio } = canvas, { data } = paint;
9560
+ if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
9468
9561
  return false;
9469
9562
  }
9470
9563
  else {
9471
- const { data } = paint;
9472
- if (allowPaint) {
9473
- if (!data.repeat) {
9474
- let { width, height } = data;
9475
- width *= abs(scaleX) * pixelRatio;
9476
- height *= abs(scaleY) * pixelRatio;
9477
- if (data.scaleX) {
9478
- width *= data.scaleX;
9479
- height *= data.scaleY;
9480
- }
9481
- allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
9564
+ if (allowDraw) {
9565
+ if (data.repeat) {
9566
+ allowDraw = false;
9482
9567
  }
9483
9568
  else {
9484
- allowPaint = false;
9569
+ if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
9570
+ let { width, height } = data;
9571
+ width *= abs(scaleX) * pixelRatio;
9572
+ height *= abs(scaleY) * pixelRatio;
9573
+ if (data.scaleX) {
9574
+ width *= data.scaleX;
9575
+ height *= data.scaleY;
9576
+ }
9577
+ allowDraw = (width * height > Platform.image.maxCacheSize);
9578
+ }
9485
9579
  }
9486
9580
  }
9487
- if (allowPaint) {
9488
- canvas.save();
9489
- ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9490
- if (paint.blendMode)
9491
- canvas.blendMode = paint.blendMode;
9492
- if (data.opacity)
9493
- canvas.opacity *= data.opacity;
9494
- if (data.transform)
9495
- canvas.transform(data.transform);
9496
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
9497
- canvas.restore();
9581
+ if (allowDraw) {
9582
+ drawImage(ui, canvas, paint, data);
9498
9583
  return true;
9499
9584
  }
9500
9585
  else {
@@ -9515,13 +9600,26 @@ var LeaferUI = (function (exports) {
9515
9600
  }
9516
9601
  }
9517
9602
  }
9603
+ function drawImage(ui, canvas, paint, data) {
9604
+ canvas.save();
9605
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9606
+ if (paint.blendMode)
9607
+ canvas.blendMode = paint.blendMode;
9608
+ if (data.opacity)
9609
+ canvas.opacity *= data.opacity;
9610
+ if (data.transform)
9611
+ canvas.transform(data.transform);
9612
+ canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
9613
+ canvas.restore();
9614
+ }
9518
9615
 
9519
9616
  function recycleImage(attrName, data) {
9520
9617
  const paints = data['_' + attrName];
9521
9618
  if (paints instanceof Array) {
9522
- let image, recycleMap, input, url;
9619
+ let paint, image, recycleMap, input, url;
9523
9620
  for (let i = 0, len = paints.length; i < len; i++) {
9524
- image = paints[i].image;
9621
+ paint = paints[i];
9622
+ image = paint.image;
9525
9623
  url = image && image.url;
9526
9624
  if (url) {
9527
9625
  if (!recycleMap)
@@ -9536,8 +9634,6 @@ var LeaferUI = (function (exports) {
9536
9634
  }
9537
9635
  image.unload(paints[i].loadId, !input.some((item) => item.url === url));
9538
9636
  }
9539
- else
9540
- paints[i].style = null;
9541
9637
  }
9542
9638
  }
9543
9639
  return recycleMap;
@@ -9716,7 +9812,7 @@ var LeaferUI = (function (exports) {
9716
9812
  const offsetOutBounds = {};
9717
9813
  function innerShadow(ui, current, shape) {
9718
9814
  let copyBounds, spreadScale;
9719
- const { __nowWorld: nowWorld, __layout: __layout } = ui;
9815
+ const { __nowWorld: nowWorld, __layout } = ui;
9720
9816
  const { innerShadow } = ui.__;
9721
9817
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
9722
9818
  const other = current.getSameCanvas();