leafer-ui 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/web.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$1.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$1.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
  const debug$5 = Debug.get('LeaferCanvas');
6060
6060
  class LeaferCanvas extends LeaferCanvasBase {
@@ -7122,7 +7122,11 @@ var LeaferUI = (function (exports) {
7122
7122
  setStyleName() { return Plugin.need('state'); },
7123
7123
  set() { return Plugin.need('state'); }
7124
7124
  };
7125
- const Transition = {};
7125
+ const Transition = {
7126
+ list: {},
7127
+ register(attrName, fn) { Transition.list[attrName] = fn; },
7128
+ get(attrName) { return Transition.list[attrName]; }
7129
+ };
7126
7130
 
7127
7131
  const { parse, objectToCanvasData } = PathConvert;
7128
7132
  const emptyPaint = {};
@@ -7546,9 +7550,6 @@ var LeaferUI = (function (exports) {
7546
7550
  this.__drawPathByBox(pen);
7547
7551
  return pen;
7548
7552
  }
7549
- get editConfig() { return undefined; }
7550
- get editOuter() { return ''; }
7551
- get editInner() { return ''; }
7552
7553
  constructor(data) {
7553
7554
  super(data);
7554
7555
  }
@@ -7630,8 +7631,11 @@ var LeaferUI = (function (exports) {
7630
7631
  export(_filename, _options) {
7631
7632
  return Plugin.need('export');
7632
7633
  }
7634
+ syncExport(_filename, _options) {
7635
+ return Plugin.need('export');
7636
+ }
7633
7637
  clone(data) {
7634
- const json = this.toJSON();
7638
+ const json = DataHelper.clone(this.toJSON());
7635
7639
  if (data)
7636
7640
  Object.assign(json, data);
7637
7641
  return UI_1.one(json);
@@ -7930,7 +7934,7 @@ var LeaferUI = (function (exports) {
7930
7934
  get layoutLocked() { return !this.layouter.running; }
7931
7935
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7932
7936
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7933
- get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
7937
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7934
7938
  constructor(userConfig, data) {
7935
7939
  super(data);
7936
7940
  this.config = {
@@ -8232,6 +8236,10 @@ var LeaferUI = (function (exports) {
8232
8236
  getPagePointByClient(clientPoint, updateClient) {
8233
8237
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8234
8238
  }
8239
+ getClientPointByWorld(worldPoint) {
8240
+ const { x, y } = this.clientBounds;
8241
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
8242
+ }
8235
8243
  updateClientBounds() {
8236
8244
  this.canvas && this.canvas.updateClientBounds();
8237
8245
  }
@@ -10200,8 +10208,6 @@ var LeaferUI = (function (exports) {
10200
10208
  h.setStrokeOptions(data);
10201
10209
  };
10202
10210
  ui$1.__hit = function (inner) {
10203
- if (Platform.name === 'miniapp')
10204
- this.__drawHitPath(this.__hitCanvas);
10205
10211
  const data = this.__;
10206
10212
  if (data.__isHitPixel && this.__hitPixel(inner))
10207
10213
  return true;
@@ -11865,13 +11871,14 @@ var LeaferUI = (function (exports) {
11865
11871
  }
11866
11872
 
11867
11873
  function layoutText(drawData, style) {
11868
- const { rows, bounds } = drawData;
11874
+ const { rows, bounds } = drawData, countRows = rows.length;
11869
11875
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
11870
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11876
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11871
11877
  let starY = __baseLine;
11872
11878
  if (__clipText && realHeight > height) {
11873
11879
  realHeight = Math.max(height, __lineHeight);
11874
- drawData.overflow = rows.length;
11880
+ if (countRows > 1)
11881
+ drawData.overflow = countRows;
11875
11882
  }
11876
11883
  else if (height || autoSizeAlign) {
11877
11884
  switch (verticalAlign) {
@@ -11883,7 +11890,7 @@ var LeaferUI = (function (exports) {
11883
11890
  }
11884
11891
  starY += y;
11885
11892
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
11886
- for (let i = 0, len = rows.length; i < len; i++) {
11893
+ for (let i = 0, len = countRows; i < len; i++) {
11887
11894
  row = rows[i];
11888
11895
  row.x = x;
11889
11896
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -11952,7 +11959,7 @@ var LeaferUI = (function (exports) {
11952
11959
  if (i === end && charRight < right) {
11953
11960
  break;
11954
11961
  }
11955
- else if (charRight < right && char.char !== ' ') {
11962
+ else if ((charRight < right && char.char !== ' ') || !i) {
11956
11963
  row.data.splice(i + 1);
11957
11964
  row.width -= char.width;
11958
11965
  break;