@leafer-draw/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.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.recycledList.push(image);
4065
+ }
4066
+ }
4060
4067
  });
4061
4068
  },
4062
- clearRecycled() {
4069
+ recyclePaint(paint) {
4070
+ I.recycle(paint.image);
4071
+ },
4072
+ clearRecycled(force) {
4063
4073
  const list = I.recycledList;
4064
- if (list.length > I.maxRecycled) {
4065
- list.forEach(image => !image.use && image.url && Resource.remove(image.url));
4074
+ if (list.length > I.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.isFormat(item, config));
4071
4082
  },
@@ -4080,7 +4091,7 @@ const ImageManager = {
4080
4091
  return false;
4081
4092
  },
4082
4093
  destroy() {
4083
- I.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$3(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$3(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$1(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$3, scale: scale$1} = 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$3 = 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);
@@ -7885,6 +7952,11 @@ class TextData extends UIData {
7885
7952
  }
7886
7953
  this._boxStyle = value;
7887
7954
  }
7955
+ __getInputData(names, options) {
7956
+ const data = super.__getInputData(names, options);
7957
+ if (data.textEditing) delete data.textEditing;
7958
+ return data;
7959
+ }
7888
7960
  }
7889
7961
 
7890
7962
  class ImageData extends RectData {
@@ -9731,6 +9803,7 @@ function getLeafPaint(attrName, paint, ui) {
9731
9803
  const {boxBounds: boxBounds} = ui.__layout;
9732
9804
  switch (paint.type) {
9733
9805
  case "image":
9806
+ if (!paint.url) return undefined;
9734
9807
  leafPaint = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
9735
9808
  break;
9736
9809
 
@@ -10135,7 +10208,7 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
10135
10208
  if (data.repeat) {
10136
10209
  drawImage = false;
10137
10210
  } else if (!(originPaint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
10138
- drawImage = Platform.image.isLarge(image, scaleX, scaleY);
10211
+ drawImage = Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096;
10139
10212
  }
10140
10213
  }
10141
10214
  if (drawImage) {
@@ -10194,7 +10267,7 @@ function recycleImage(attrName, data) {
10194
10267
  if (url) {
10195
10268
  if (!recycleMap) recycleMap = {};
10196
10269
  recycleMap[url] = true;
10197
- ImageManager.recycle(image);
10270
+ ImageManager.recyclePaint(paint);
10198
10271
  if (image.loading) {
10199
10272
  if (!input) {
10200
10273
  input = data.__input && data.__input[attrName] || [];