leafer-draw 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.
@@ -3635,7 +3635,12 @@ const Resource = {
3635
3635
  return R.map[key];
3636
3636
  },
3637
3637
  remove(key) {
3638
- delete R.map[key];
3638
+ const r = R.map[key];
3639
+ if (r) {
3640
+ if (r.destroy)
3641
+ r.destroy();
3642
+ delete R.map[key];
3643
+ }
3639
3644
  },
3640
3645
  loadImage(key, format) {
3641
3646
  return new Promise((resolve, reject) => {
@@ -3661,6 +3666,7 @@ const Resource = {
3661
3666
  const R = Resource;
3662
3667
 
3663
3668
  const ImageManager = {
3669
+ maxRecycled: 100,
3664
3670
  recycledList: [],
3665
3671
  patternTasker: new TaskProcessor(),
3666
3672
  get(config) {
@@ -3677,13 +3683,8 @@ const ImageManager = {
3677
3683
  },
3678
3684
  clearRecycled() {
3679
3685
  const list = I.recycledList;
3680
- if (list.length > 100) {
3681
- list.forEach(image => {
3682
- if (!image.use && image.url) {
3683
- Resource.remove(image.url);
3684
- image.destroy();
3685
- }
3686
- });
3686
+ if (list.length > I.maxRecycled) {
3687
+ list.forEach(image => (!image.use && image.url) && Resource.remove(image.url));
3687
3688
  list.length = 0;
3688
3689
  }
3689
3690
  },
@@ -4069,12 +4070,11 @@ function defineDataProcessor(target, key, defaultValue) {
4069
4070
  if (defaultValue === undefined) {
4070
4071
  property.get = function () { return this[computedKey]; };
4071
4072
  }
4072
- else if (typeof defaultValue === 'object') {
4073
- const { clone } = DataHelper;
4073
+ else if (typeof defaultValue === 'function') {
4074
4074
  property.get = function () {
4075
4075
  let v = this[computedKey];
4076
4076
  if (v === undefined)
4077
- this[computedKey] = v = clone(defaultValue);
4077
+ this[computedKey] = v = defaultValue(this.__leaf);
4078
4078
  return v;
4079
4079
  };
4080
4080
  }
@@ -5721,10 +5721,10 @@ let Leaf = class Leaf {
5721
5721
  static changeAttr(attrName, defaultValue, fn) {
5722
5722
  fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5723
5723
  }
5724
- static addAttr(attrName, defaultValue, fn) {
5724
+ static addAttr(attrName, defaultValue, fn, helpValue) {
5725
5725
  if (!fn)
5726
5726
  fn = boundsType;
5727
- fn(defaultValue)(this.prototype, attrName);
5727
+ fn(defaultValue, helpValue)(this.prototype, attrName);
5728
5728
  }
5729
5729
  __emitLifeEvent(type) {
5730
5730
  if (this.hasEvent(type))
@@ -6051,7 +6051,7 @@ class LeafLevelList {
6051
6051
  }
6052
6052
  }
6053
6053
 
6054
- const version = "1.4.1";
6054
+ const version = "1.5.0";
6055
6055
 
6056
6056
  const debug$4 = Debug.get('LeaferCanvas');
6057
6057
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6962,7 +6962,11 @@ const State = {
6962
6962
  setStyleName() { return Plugin.need('state'); },
6963
6963
  set() { return Plugin.need('state'); }
6964
6964
  };
6965
- const Transition = {};
6965
+ const Transition = {
6966
+ list: {},
6967
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6968
+ get(attrName) { return Transition.list[attrName]; }
6969
+ };
6966
6970
 
6967
6971
  const { parse, objectToCanvasData } = PathConvert;
6968
6972
  const emptyPaint = {};
@@ -7386,9 +7390,6 @@ let UI = UI_1 = class UI extends Leaf {
7386
7390
  this.__drawPathByBox(pen);
7387
7391
  return pen;
7388
7392
  }
7389
- get editConfig() { return undefined; }
7390
- get editOuter() { return ''; }
7391
- get editInner() { return ''; }
7392
7393
  constructor(data) {
7393
7394
  super(data);
7394
7395
  }
@@ -7470,8 +7471,11 @@ let UI = UI_1 = class UI extends Leaf {
7470
7471
  export(_filename, _options) {
7471
7472
  return Plugin.need('export');
7472
7473
  }
7474
+ syncExport(_filename, _options) {
7475
+ return Plugin.need('export');
7476
+ }
7473
7477
  clone(data) {
7474
- const json = this.toJSON();
7478
+ const json = DataHelper.clone(this.toJSON());
7475
7479
  if (data)
7476
7480
  Object.assign(json, data);
7477
7481
  return UI_1.one(json);
@@ -7770,7 +7774,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7770
7774
  get layoutLocked() { return !this.layouter.running; }
7771
7775
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7772
7776
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7773
- get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
7777
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7774
7778
  constructor(userConfig, data) {
7775
7779
  super(data);
7776
7780
  this.config = {
@@ -8072,6 +8076,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8072
8076
  getPagePointByClient(clientPoint, updateClient) {
8073
8077
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8074
8078
  }
8079
+ getClientPointByWorld(worldPoint) {
8080
+ const { x, y } = this.clientBounds;
8081
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
8082
+ }
8075
8083
  updateClientBounds() {
8076
8084
  this.canvas && this.canvas.updateClientBounds();
8077
8085
  }
@@ -10107,13 +10115,14 @@ function toChar(data, charX, rowData, isOverflow) {
10107
10115
  }
10108
10116
 
10109
10117
  function layoutText(drawData, style) {
10110
- const { rows, bounds } = drawData;
10118
+ const { rows, bounds } = drawData, countRows = rows.length;
10111
10119
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
10112
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
10120
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
10113
10121
  let starY = __baseLine;
10114
10122
  if (__clipText && realHeight > height) {
10115
10123
  realHeight = Math.max(height, __lineHeight);
10116
- drawData.overflow = rows.length;
10124
+ if (countRows > 1)
10125
+ drawData.overflow = countRows;
10117
10126
  }
10118
10127
  else if (height || autoSizeAlign) {
10119
10128
  switch (verticalAlign) {
@@ -10125,7 +10134,7 @@ function layoutText(drawData, style) {
10125
10134
  }
10126
10135
  starY += y;
10127
10136
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
10128
- for (let i = 0, len = rows.length; i < len; i++) {
10137
+ for (let i = 0, len = countRows; i < len; i++) {
10129
10138
  row = rows[i];
10130
10139
  row.x = x;
10131
10140
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -10194,7 +10203,7 @@ function clipText(drawData, style, x, width) {
10194
10203
  if (i === end && charRight < right) {
10195
10204
  break;
10196
10205
  }
10197
- else if (charRight < right && char.char !== ' ') {
10206
+ else if ((charRight < right && char.char !== ' ') || !i) {
10198
10207
  row.data.splice(i + 1);
10199
10208
  row.width -= char.width;
10200
10209
  break;