@leafer/worker 1.11.2 → 1.12.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.
@@ -4056,16 +4056,27 @@ const ImageManager = {
4056
4056
  recycle(image) {
4057
4057
  image.use--;
4058
4058
  setTimeout(() => {
4059
- if (!image.use) I$1.recycledList.push(image);
4059
+ if (!image.use) {
4060
+ if (Platform.image.isLarge(image)) {
4061
+ if (image.url) Resource.remove(image.url);
4062
+ } else {
4063
+ image.clearLevels();
4064
+ I$1.recycledList.push(image);
4065
+ }
4066
+ }
4060
4067
  });
4061
4068
  },
4062
- clearRecycled() {
4069
+ recyclePaint(paint) {
4070
+ I$1.recycle(paint.image);
4071
+ },
4072
+ clearRecycled(force) {
4063
4073
  const list = I$1.recycledList;
4064
- if (list.length > I$1.maxRecycled) {
4065
- list.forEach(image => !image.use && image.url && Resource.remove(image.url));
4074
+ if (list.length > I$1.maxRecycled || force) {
4075
+ list.forEach(image => (!image.use || force) && image.url && Resource.remove(image.url));
4066
4076
  list.length = 0;
4067
4077
  }
4068
4078
  },
4079
+ clearLevels() {},
4069
4080
  hasAlphaPixel(config) {
4070
4081
  return FileHelper.alphaPixelTypes.some(item => I$1.isFormat(item, config));
4071
4082
  },
@@ -4080,7 +4091,7 @@ const ImageManager = {
4080
4091
  return false;
4081
4092
  },
4082
4093
  destroy() {
4083
- I$1.recycledList = [];
4094
+ this.clearRecycled(true);
4084
4095
  }
4085
4096
  };
4086
4097
 
@@ -4183,11 +4194,15 @@ class LeaferImage {
4183
4194
  Platform.image.setPatternTransform(pattern, transform, paint);
4184
4195
  return pattern;
4185
4196
  }
4197
+ clearLevels(_checkUse) {}
4186
4198
  destroy() {
4199
+ this.clearLevels();
4200
+ const {view: view} = this;
4201
+ if (view && view.close) view.close();
4187
4202
  this.config = {
4188
4203
  url: ""
4189
4204
  };
4190
- this.cache = null;
4205
+ this.cache = this.view = null;
4191
4206
  this.waitComplete.length = 0;
4192
4207
  }
4193
4208
  }
@@ -4936,10 +4951,53 @@ const BranchHelper = {
4936
4951
  if (exclude && exclude === branch) continue;
4937
4952
  updateBounds$4(branch);
4938
4953
  }
4954
+ },
4955
+ move(branch, x, y) {
4956
+ let w;
4957
+ const {children: children} = branch;
4958
+ for (let i = 0, len = children.length; i < len; i++) {
4959
+ branch = children[i];
4960
+ w = branch.__world;
4961
+ w.e += x;
4962
+ w.f += y;
4963
+ w.x += x;
4964
+ w.y += y;
4965
+ if (branch.isBranch) move$9(branch, x, y);
4966
+ }
4967
+ },
4968
+ scale(branch, x, y, scaleX, scaleY, a, b) {
4969
+ let w;
4970
+ const {children: children} = branch;
4971
+ const changeScaleX = scaleX - 1;
4972
+ const changeScaleY = scaleY - 1;
4973
+ for (let i = 0, len = children.length; i < len; i++) {
4974
+ branch = children[i];
4975
+ w = branch.__world;
4976
+ w.a *= scaleX;
4977
+ w.d *= scaleY;
4978
+ if (w.b || w.c) {
4979
+ w.b *= scaleX;
4980
+ w.c *= scaleY;
4981
+ }
4982
+ if (w.e === w.x && w.f === w.y) {
4983
+ w.x = w.e += (w.e - a) * changeScaleX + x;
4984
+ w.y = w.f += (w.f - b) * changeScaleY + y;
4985
+ } else {
4986
+ w.e += (w.e - a) * changeScaleX + x;
4987
+ w.f += (w.f - b) * changeScaleY + y;
4988
+ w.x += (w.x - a) * changeScaleX + x;
4989
+ w.y += (w.y - b) * changeScaleY + y;
4990
+ }
4991
+ w.width *= scaleX;
4992
+ w.height *= scaleY;
4993
+ w.scaleX *= scaleX;
4994
+ w.scaleY *= scaleY;
4995
+ if (branch.isBranch) scale$2(branch, x, y, scaleX, scaleY, a, b);
4996
+ }
4939
4997
  }
4940
4998
  };
4941
4999
 
4942
- const {pushAllChildBranch: pushAllChildBranch$1, pushAllBranchStack: pushAllBranchStack, updateBoundsByBranchStack: updateBoundsByBranchStack} = BranchHelper;
5000
+ const {pushAllChildBranch: pushAllChildBranch$1, pushAllBranchStack: pushAllBranchStack, updateBoundsByBranchStack: updateBoundsByBranchStack, move: move$9, scale: scale$2} = BranchHelper;
4943
5001
 
4944
5002
  const WaitHelper = {
4945
5003
  run(wait) {
@@ -5966,6 +6024,7 @@ const LeafBounds = {
5966
6024
  const LeafRender = {
5967
6025
  __render(canvas, options) {
5968
6026
  if (options.shape) return this.__renderShape(canvas, options);
6027
+ if (options.cellList && !options.cellList.has(this)) return;
5969
6028
  if (this.__worldOpacity) {
5970
6029
  const data = this.__;
5971
6030
  if (data.bright && !options.topRendering) return options.topList.add(this);
@@ -6502,10 +6561,10 @@ let Leaf = class Leaf {
6502
6561
  hit(_world, _hitRadius) {
6503
6562
  return true;
6504
6563
  }
6505
- __hitWorld(_point) {
6564
+ __hitWorld(_point, _forceHitFill) {
6506
6565
  return true;
6507
6566
  }
6508
- __hit(_local) {
6567
+ __hit(_local, _forceHitFill) {
6509
6568
  return true;
6510
6569
  }
6511
6570
  __hitFill(_inner) {
@@ -6864,7 +6923,7 @@ class LeafLevelList {
6864
6923
  }
6865
6924
  }
6866
6925
 
6867
- const version = "1.11.2";
6926
+ const version = "1.12.1";
6868
6927
 
6869
6928
  class LeaferCanvas extends LeaferCanvasBase {
6870
6929
  get allowBackgroundColor() {
@@ -6981,7 +7040,7 @@ class Watcher {
6981
7040
  return this.hasAdd || this.hasRemove || this.hasVisible;
6982
7041
  }
6983
7042
  get updatedList() {
6984
- if (this.hasRemove) {
7043
+ if (this.hasRemove && this.config.usePartLayout) {
6985
7044
  const updatedList = new LeafList;
6986
7045
  this.__updatedList.list.forEach(item => {
6987
7046
  if (item.leafer) updatedList.add(item);
@@ -7016,16 +7075,18 @@ class Watcher {
7016
7075
  if (this.running) this.target.emit(RenderEvent.REQUEST);
7017
7076
  }
7018
7077
  __onAttrChange(event) {
7019
- this.__updatedList.add(event.target);
7078
+ if (this.config.usePartLayout) this.__updatedList.add(event.target);
7020
7079
  this.update();
7021
7080
  }
7022
7081
  __onChildEvent(event) {
7023
- if (event.type === ChildEvent.ADD) {
7024
- this.hasAdd = true;
7025
- this.__pushChild(event.child);
7026
- } else {
7027
- this.hasRemove = true;
7028
- this.__updatedList.add(event.parent);
7082
+ if (this.config.usePartLayout) {
7083
+ if (event.type === ChildEvent.ADD) {
7084
+ this.hasAdd = true;
7085
+ this.__pushChild(event.child);
7086
+ } else {
7087
+ this.hasRemove = true;
7088
+ this.__updatedList.add(event.parent);
7089
+ }
7029
7090
  }
7030
7091
  this.update();
7031
7092
  }
@@ -7142,7 +7203,9 @@ const debug$7 = Debug.get("Layouter");
7142
7203
  class Layouter {
7143
7204
  constructor(target, userConfig) {
7144
7205
  this.totalTimes = 0;
7145
- this.config = {};
7206
+ this.config = {
7207
+ usePartLayout: true
7208
+ };
7146
7209
  this.__levelList = new LeafLevelList;
7147
7210
  this.target = target;
7148
7211
  if (userConfig) this.config = DataHelper.default(userConfig, this.config);
@@ -7187,7 +7250,7 @@ class Layouter {
7187
7250
  this.totalTimes++;
7188
7251
  this.layouting = true;
7189
7252
  this.target.emit(WatchEvent.REQUEST);
7190
- if (this.totalTimes > 1) {
7253
+ if (this.totalTimes > 1 && this.config.usePartLayout) {
7191
7254
  this.partLayout();
7192
7255
  } else {
7193
7256
  this.fullLayout();
@@ -7304,7 +7367,7 @@ class Renderer {
7304
7367
  }
7305
7368
  update(change = true) {
7306
7369
  if (!this.changed) this.changed = change;
7307
- this.__requestRender();
7370
+ if (!this.requestTime) this.__requestRender();
7308
7371
  }
7309
7372
  requestLayout() {
7310
7373
  this.target.emit(LayoutEvent.REQUEST);
@@ -7411,7 +7474,7 @@ class Renderer {
7411
7474
  Run.end(t);
7412
7475
  }
7413
7476
  __render(bounds, realBounds) {
7414
- const {canvas: canvas} = this, includes = bounds.includes(this.target.__world), options = includes ? {
7477
+ const {canvas: canvas, target: target} = this, includes = bounds.includes(target.__world), options = includes ? {
7415
7478
  includes: includes
7416
7479
  } : {
7417
7480
  bounds: bounds,
@@ -7419,12 +7482,16 @@ class Renderer {
7419
7482
  };
7420
7483
  if (this.needFill) canvas.fillWorld(bounds, this.config.fill);
7421
7484
  if (Debug.showRepaint) Debug.drawRepaint(canvas, bounds);
7422
- Platform.render(this.target, canvas, options);
7485
+ if (this.config.useCellRender) options.cellList = this.getCellList();
7486
+ Platform.render(target, canvas, options);
7423
7487
  this.renderBounds = realBounds = realBounds || bounds;
7424
7488
  this.renderOptions = options;
7425
7489
  this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
7426
7490
  canvas.updateRender(realBounds);
7427
7491
  }
7492
+ getCellList() {
7493
+ return undefined;
7494
+ }
7428
7495
  addBlock(block) {
7429
7496
  if (!this.updateBlocks) this.updateBlocks = [];
7430
7497
  this.updateBlocks.push(block);
@@ -7639,7 +7706,7 @@ class Picker {
7639
7706
  hit = child.__.hitRadius ? true : hitRadiusPoint$1(child.__world, point);
7640
7707
  if (child.isBranch) {
7641
7708
  if (hit || child.__ignoreHitWorld) {
7642
- if (child.isBranchLeaf && child.__.__clipAfterFill && !child.__hitWorld(point)) continue;
7709
+ if (child.isBranchLeaf && child.__.__clipAfterFill && !child.__hitWorld(point, true)) continue;
7643
7710
  if (child.topChildren) this.eachFind(child.topChildren, false);
7644
7711
  this.eachFind(child.children, child.__onlyHitMask);
7645
7712
  if (child.isBranchLeaf) this.hitChild(child, point);
@@ -8081,6 +8148,11 @@ class TextData extends UIData {
8081
8148
  }
8082
8149
  this._boxStyle = value;
8083
8150
  }
8151
+ __getInputData(names, options) {
8152
+ const data = super.__getInputData(names, options);
8153
+ if (data.textEditing) delete data.textEditing;
8154
+ return data;
8155
+ }
8084
8156
  }
8085
8157
 
8086
8158
  class ImageData extends RectData {
@@ -10953,7 +11025,7 @@ leaf$1.hit = function(worldPoint, hitRadius = 0) {
10953
11025
  }) : this.__hitWorld(worldRadiusPoint);
10954
11026
  };
10955
11027
 
10956
- leaf$1.__hitWorld = function(point) {
11028
+ leaf$1.__hitWorld = function(point, forceHitFill) {
10957
11029
  const data = this.__;
10958
11030
  if (!data.hitSelf) return false;
10959
11031
  const world = this.__world, layout = this.__layout;
@@ -10971,7 +11043,7 @@ leaf$1.__hitWorld = function(point) {
10971
11043
  this.__updateHitCanvas();
10972
11044
  if (!layout.boundsChanged) layout.hitCanvasChanged = false;
10973
11045
  }
10974
- return this.__hit(inner);
11046
+ return this.__hit(inner, forceHitFill);
10975
11047
  };
10976
11048
 
10977
11049
  leaf$1.__hitFill = function(inner) {
@@ -11038,12 +11110,12 @@ ui$5.__updateHitCanvas = function() {
11038
11110
  h.setStrokeOptions(data);
11039
11111
  };
11040
11112
 
11041
- ui$5.__hit = function(inner) {
11113
+ ui$5.__hit = function(inner, forceHitFill) {
11042
11114
  if (this.__box && this.__box.__hit(inner)) return true;
11043
11115
  const data = this.__;
11044
11116
  if (data.__isHitPixel && this.__hitPixel(inner)) return true;
11045
11117
  const {hitFill: hitFill} = data;
11046
- const needHitFillPath = (data.fill || data.__isCanvas) && (hitFill === "path" || hitFill === "pixel" && !(data.__isAlphaPixelFill || data.__isCanvas)) || hitFill === "all";
11118
+ const needHitFillPath = (data.fill || data.__isCanvas) && (hitFill === "path" || hitFill === "pixel" && !(data.__isAlphaPixelFill || data.__isCanvas)) || hitFill === "all" || forceHitFill;
11047
11119
  if (needHitFillPath && this.__hitFill(inner)) return true;
11048
11120
  const {hitStroke: hitStroke, __maxStrokeWidth: strokeWidth} = data;
11049
11121
  const needHitStrokePath = data.stroke && (hitStroke === "path" || hitStroke === "pixel" && !data.__isAlphaPixelStroke) || hitStroke === "all";
@@ -11420,6 +11492,7 @@ function getLeafPaint(attrName, paint, ui) {
11420
11492
  const {boxBounds: boxBounds} = ui.__layout;
11421
11493
  switch (paint.type) {
11422
11494
  case "image":
11495
+ if (!paint.url) return undefined;
11423
11496
  leafPaint = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
11424
11497
  break;
11425
11498
 
@@ -11760,7 +11833,7 @@ function layout$3(transform, box, x, y, scaleX, scaleY, rotation, skew) {
11760
11833
  translate(transform, box.x + x, box.y + y);
11761
11834
  }
11762
11835
 
11763
- const {get: get$1, scale: scale$2, copy: copy$4} = MatrixHelper;
11836
+ const {get: get$1, scale: scale$1, copy: copy$4} = MatrixHelper;
11764
11837
 
11765
11838
  const {getFloorScale: getFloorScale} = MathHelper, {abs: abs$6} = Math;
11766
11839
 
@@ -11792,7 +11865,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
11792
11865
  scaleY *= getFloorScale(height + (yGap || 0));
11793
11866
  imageMatrix = get$1();
11794
11867
  if (transform) copy$4(imageMatrix, transform);
11795
- scale$2(imageMatrix, 1 / scaleX, 1 / scaleY);
11868
+ scale$1(imageMatrix, 1 / scaleX, 1 / scaleY);
11796
11869
  }
11797
11870
  const imageCanvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth);
11798
11871
  const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
@@ -11824,7 +11897,7 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
11824
11897
  if (data.repeat) {
11825
11898
  drawImage = false;
11826
11899
  } else if (!(originPaint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
11827
- drawImage = Platform.image.isLarge(image, scaleX, scaleY);
11900
+ drawImage = Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096;
11828
11901
  }
11829
11902
  }
11830
11903
  if (drawImage) {
@@ -11883,7 +11956,7 @@ function recycleImage(attrName, data) {
11883
11956
  if (url) {
11884
11957
  if (!recycleMap) recycleMap = {};
11885
11958
  recycleMap[url] = true;
11886
- ImageManager.recycle(image);
11959
+ ImageManager.recyclePaint(paint);
11887
11960
  if (image.loading) {
11888
11961
  if (!input) {
11889
11962
  input = data.__input && data.__input[attrName] || [];
@@ -12901,7 +12974,7 @@ function mergeConfigAttr() {
12901
12974
 
12902
12975
  const {abs: abs$4} = Math;
12903
12976
 
12904
- const {copy: copy$2, scale: scale$1} = MatrixHelper;
12977
+ const {copy: copy$2} = MatrixHelper;
12905
12978
 
12906
12979
  const {setListWithFn: setListWithFn} = BoundsHelper;
12907
12980
 
@@ -12945,19 +13018,10 @@ class Stroker extends UI {
12945
13018
  const aScaleX = abs$4(worldTransform.scaleX), aScaleY = abs$4(worldTransform.scaleY);
12946
13019
  copy$2(matrix$1, worldTransform);
12947
13020
  matrix$1.half = strokeWidth % 2;
12948
- if (aScaleX !== aScaleY) {
12949
- scale$1(matrix$1, 1 / aScaleX, 1 / aScaleY);
12950
- canvas.setWorld(matrix$1, options.matrix);
12951
- canvas.beginPath();
12952
- data.strokeWidth = strokeWidth;
12953
- const {x: x, y: y, width: width, height: height} = leaf.__layout.boxBounds;
12954
- canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
12955
- } else {
12956
- canvas.setWorld(matrix$1, options.matrix);
12957
- canvas.beginPath();
12958
- if (leaf.__.__useArrow) leaf.__drawPath(canvas); else leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
12959
- data.strokeWidth = strokeWidth / abs$4(worldTransform.scaleX);
12960
- }
13021
+ canvas.setWorld(matrix$1, options.matrix);
13022
+ canvas.beginPath();
13023
+ if (leaf.__.__useArrow) leaf.__drawPath(canvas); else leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
13024
+ data.strokeWidth = strokeWidth / Math.max(aScaleX, aScaleY);
12961
13025
  if (stroke) isString(stroke) ? Paint.stroke(stroke, this, canvas, options) : Paint.strokes(stroke, this, canvas, options);
12962
13026
  if (fill) isString(fill) ? Paint.fill(fill, this, canvas, options) : Paint.fills(fill, this, canvas, options);
12963
13027
  }