@leafer-draw/worker 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/worker.js CHANGED
@@ -3638,7 +3638,12 @@ var LeaferUI = (function (exports) {
3638
3638
  return R.map[key];
3639
3639
  },
3640
3640
  remove(key) {
3641
- delete R.map[key];
3641
+ const r = R.map[key];
3642
+ if (r) {
3643
+ if (r.destroy)
3644
+ r.destroy();
3645
+ delete R.map[key];
3646
+ }
3642
3647
  },
3643
3648
  loadImage(key, format) {
3644
3649
  return new Promise((resolve, reject) => {
@@ -3664,6 +3669,7 @@ var LeaferUI = (function (exports) {
3664
3669
  const R = Resource;
3665
3670
 
3666
3671
  const ImageManager = {
3672
+ maxRecycled: 100,
3667
3673
  recycledList: [],
3668
3674
  patternTasker: new TaskProcessor(),
3669
3675
  get(config) {
@@ -3680,13 +3686,8 @@ var LeaferUI = (function (exports) {
3680
3686
  },
3681
3687
  clearRecycled() {
3682
3688
  const list = I.recycledList;
3683
- if (list.length > 100) {
3684
- list.forEach(image => {
3685
- if (!image.use && image.url) {
3686
- Resource.remove(image.url);
3687
- image.destroy();
3688
- }
3689
- });
3689
+ if (list.length > I.maxRecycled) {
3690
+ list.forEach(image => (!image.use && image.url) && Resource.remove(image.url));
3690
3691
  list.length = 0;
3691
3692
  }
3692
3693
  },
@@ -4072,12 +4073,11 @@ var LeaferUI = (function (exports) {
4072
4073
  if (defaultValue === undefined) {
4073
4074
  property.get = function () { return this[computedKey]; };
4074
4075
  }
4075
- else if (typeof defaultValue === 'object') {
4076
- const { clone } = DataHelper;
4076
+ else if (typeof defaultValue === 'function') {
4077
4077
  property.get = function () {
4078
4078
  let v = this[computedKey];
4079
4079
  if (v === undefined)
4080
- this[computedKey] = v = clone(defaultValue);
4080
+ this[computedKey] = v = defaultValue(this.__leaf);
4081
4081
  return v;
4082
4082
  };
4083
4083
  }
@@ -5724,10 +5724,10 @@ var LeaferUI = (function (exports) {
5724
5724
  static changeAttr(attrName, defaultValue, fn) {
5725
5725
  fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5726
5726
  }
5727
- static addAttr(attrName, defaultValue, fn) {
5727
+ static addAttr(attrName, defaultValue, fn, helpValue) {
5728
5728
  if (!fn)
5729
5729
  fn = boundsType;
5730
- fn(defaultValue)(this.prototype, attrName);
5730
+ fn(defaultValue, helpValue)(this.prototype, attrName);
5731
5731
  }
5732
5732
  __emitLifeEvent(type) {
5733
5733
  if (this.hasEvent(type))
@@ -6054,7 +6054,7 @@ var LeaferUI = (function (exports) {
6054
6054
  }
6055
6055
  }
6056
6056
 
6057
- const version = "1.4.1";
6057
+ const version = "1.5.0";
6058
6058
 
6059
6059
  class LeaferCanvas extends LeaferCanvasBase {
6060
6060
  get allowBackgroundColor() { return true; }
@@ -6784,7 +6784,11 @@ var LeaferUI = (function (exports) {
6784
6784
  setStyleName() { return Plugin.need('state'); },
6785
6785
  set() { return Plugin.need('state'); }
6786
6786
  };
6787
- const Transition = {};
6787
+ const Transition = {
6788
+ list: {},
6789
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6790
+ get(attrName) { return Transition.list[attrName]; }
6791
+ };
6788
6792
 
6789
6793
  const { parse, objectToCanvasData } = PathConvert;
6790
6794
  const emptyPaint = {};
@@ -7208,9 +7212,6 @@ var LeaferUI = (function (exports) {
7208
7212
  this.__drawPathByBox(pen);
7209
7213
  return pen;
7210
7214
  }
7211
- get editConfig() { return undefined; }
7212
- get editOuter() { return ''; }
7213
- get editInner() { return ''; }
7214
7215
  constructor(data) {
7215
7216
  super(data);
7216
7217
  }
@@ -7292,8 +7293,11 @@ var LeaferUI = (function (exports) {
7292
7293
  export(_filename, _options) {
7293
7294
  return Plugin.need('export');
7294
7295
  }
7296
+ syncExport(_filename, _options) {
7297
+ return Plugin.need('export');
7298
+ }
7295
7299
  clone(data) {
7296
- const json = this.toJSON();
7300
+ const json = DataHelper.clone(this.toJSON());
7297
7301
  if (data)
7298
7302
  Object.assign(json, data);
7299
7303
  return UI_1.one(json);
@@ -7592,7 +7596,7 @@ var LeaferUI = (function (exports) {
7592
7596
  get layoutLocked() { return !this.layouter.running; }
7593
7597
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7594
7598
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7595
- get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
7599
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7596
7600
  constructor(userConfig, data) {
7597
7601
  super(data);
7598
7602
  this.config = {
@@ -7894,6 +7898,10 @@ var LeaferUI = (function (exports) {
7894
7898
  getPagePointByClient(clientPoint, updateClient) {
7895
7899
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
7896
7900
  }
7901
+ getClientPointByWorld(worldPoint) {
7902
+ const { x, y } = this.clientBounds;
7903
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
7904
+ }
7897
7905
  updateClientBounds() {
7898
7906
  this.canvas && this.canvas.updateClientBounds();
7899
7907
  }
@@ -9929,13 +9937,14 @@ var LeaferUI = (function (exports) {
9929
9937
  }
9930
9938
 
9931
9939
  function layoutText(drawData, style) {
9932
- const { rows, bounds } = drawData;
9940
+ const { rows, bounds } = drawData, countRows = rows.length;
9933
9941
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
9934
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9942
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9935
9943
  let starY = __baseLine;
9936
9944
  if (__clipText && realHeight > height) {
9937
9945
  realHeight = Math.max(height, __lineHeight);
9938
- drawData.overflow = rows.length;
9946
+ if (countRows > 1)
9947
+ drawData.overflow = countRows;
9939
9948
  }
9940
9949
  else if (height || autoSizeAlign) {
9941
9950
  switch (verticalAlign) {
@@ -9947,7 +9956,7 @@ var LeaferUI = (function (exports) {
9947
9956
  }
9948
9957
  starY += y;
9949
9958
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
9950
- for (let i = 0, len = rows.length; i < len; i++) {
9959
+ for (let i = 0, len = countRows; i < len; i++) {
9951
9960
  row = rows[i];
9952
9961
  row.x = x;
9953
9962
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -10016,7 +10025,7 @@ var LeaferUI = (function (exports) {
10016
10025
  if (i === end && charRight < right) {
10017
10026
  break;
10018
10027
  }
10019
- else if (charRight < right && char.char !== ' ') {
10028
+ else if ((charRight < right && char.char !== ' ') || !i) {
10020
10029
  row.data.splice(i + 1);
10021
10030
  row.width -= char.width;
10022
10031
  break;