@leafer-draw/worker 1.4.2 → 1.5.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.
@@ -2029,13 +2029,11 @@ class LeaferCanvasBase extends Canvas$1 {
2029
2029
  this.worldTransform = {};
2030
2030
  if (!config)
2031
2031
  config = minSize;
2032
- if (!config.pixelRatio)
2033
- config.pixelRatio = Platform.devicePixelRatio;
2034
2032
  this.manager = manager;
2035
2033
  this.innerId = IncrementId.create(IncrementId.CNAVAS);
2036
2034
  const { width, height, pixelRatio } = config;
2037
2035
  this.autoLayout = !width || !height;
2038
- this.size.pixelRatio = pixelRatio;
2036
+ this.size.pixelRatio = pixelRatio | Platform.devicePixelRatio;
2039
2037
  this.config = config;
2040
2038
  this.init();
2041
2039
  }
@@ -2232,7 +2230,7 @@ class LeaferCanvasBase extends Canvas$1 {
2232
2230
  tempBounds$1.ceil();
2233
2231
  }
2234
2232
  isSameSize(size) {
2235
- return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
2233
+ return this.width === size.width && this.height === size.height && (!size.pixelRatio || this.pixelRatio === size.pixelRatio);
2236
2234
  }
2237
2235
  getSameCanvas(useSameWorldTransform, useSameSmooth) {
2238
2236
  const canvas = this.manager ? this.manager.get(this.size) : Creator.canvas(Object.assign({}, this.size));
@@ -4070,13 +4068,10 @@ function defineDataProcessor(target, key, defaultValue) {
4070
4068
  if (defaultValue === undefined) {
4071
4069
  property.get = function () { return this[computedKey]; };
4072
4070
  }
4073
- else if (typeof defaultValue === 'object') {
4074
- const { clone } = DataHelper;
4071
+ else if (typeof defaultValue === 'function') {
4075
4072
  property.get = function () {
4076
4073
  let v = this[computedKey];
4077
- if (v === undefined)
4078
- this[computedKey] = v = clone(defaultValue);
4079
- return v;
4074
+ return v === undefined ? defaultValue(this.__leaf) : v;
4080
4075
  };
4081
4076
  }
4082
4077
  if (key === 'width') {
@@ -5722,10 +5717,10 @@ let Leaf = class Leaf {
5722
5717
  static changeAttr(attrName, defaultValue, fn) {
5723
5718
  fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5724
5719
  }
5725
- static addAttr(attrName, defaultValue, fn) {
5720
+ static addAttr(attrName, defaultValue, fn, helpValue) {
5726
5721
  if (!fn)
5727
5722
  fn = boundsType;
5728
- fn(defaultValue)(this.prototype, attrName);
5723
+ fn(defaultValue, helpValue)(this.prototype, attrName);
5729
5724
  }
5730
5725
  __emitLifeEvent(type) {
5731
5726
  if (this.hasEvent(type))
@@ -6052,7 +6047,7 @@ class LeafLevelList {
6052
6047
  }
6053
6048
  }
6054
6049
 
6055
- const version = "1.4.2";
6050
+ const version = "1.5.1";
6056
6051
 
6057
6052
  class LeaferCanvas extends LeaferCanvasBase {
6058
6053
  get allowBackgroundColor() { return true; }
@@ -6782,7 +6777,11 @@ const State = {
6782
6777
  setStyleName() { return Plugin.need('state'); },
6783
6778
  set() { return Plugin.need('state'); }
6784
6779
  };
6785
- const Transition = {};
6780
+ const Transition = {
6781
+ list: {},
6782
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6783
+ get(attrName) { return Transition.list[attrName]; }
6784
+ };
6786
6785
 
6787
6786
  const { parse, objectToCanvasData } = PathConvert;
6788
6787
  const emptyPaint = {};
@@ -7206,9 +7205,6 @@ let UI = UI_1 = class UI extends Leaf {
7206
7205
  this.__drawPathByBox(pen);
7207
7206
  return pen;
7208
7207
  }
7209
- get editConfig() { return undefined; }
7210
- get editOuter() { return ''; }
7211
- get editInner() { return ''; }
7212
7208
  constructor(data) {
7213
7209
  super(data);
7214
7210
  }
@@ -7290,8 +7286,11 @@ let UI = UI_1 = class UI extends Leaf {
7290
7286
  export(_filename, _options) {
7291
7287
  return Plugin.need('export');
7292
7288
  }
7289
+ syncExport(_filename, _options) {
7290
+ return Plugin.need('export');
7291
+ }
7293
7292
  clone(data) {
7294
- const json = this.toJSON();
7293
+ const json = DataHelper.clone(this.toJSON());
7295
7294
  if (data)
7296
7295
  Object.assign(json, data);
7297
7296
  return UI_1.one(json);
@@ -7590,7 +7589,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7590
7589
  get layoutLocked() { return !this.layouter.running; }
7591
7590
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7592
7591
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7593
- get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
7592
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7594
7593
  constructor(userConfig, data) {
7595
7594
  super(data);
7596
7595
  this.config = {
@@ -7892,6 +7891,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7892
7891
  getPagePointByClient(clientPoint, updateClient) {
7893
7892
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
7894
7893
  }
7894
+ getClientPointByWorld(worldPoint) {
7895
+ const { x, y } = this.clientBounds;
7896
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
7897
+ }
7895
7898
  updateClientBounds() {
7896
7899
  this.canvas && this.canvas.updateClientBounds();
7897
7900
  }
@@ -9927,13 +9930,14 @@ function toChar(data, charX, rowData, isOverflow) {
9927
9930
  }
9928
9931
 
9929
9932
  function layoutText(drawData, style) {
9930
- const { rows, bounds } = drawData;
9933
+ const { rows, bounds } = drawData, countRows = rows.length;
9931
9934
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
9932
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9935
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9933
9936
  let starY = __baseLine;
9934
9937
  if (__clipText && realHeight > height) {
9935
9938
  realHeight = Math.max(height, __lineHeight);
9936
- drawData.overflow = rows.length;
9939
+ if (countRows > 1)
9940
+ drawData.overflow = countRows;
9937
9941
  }
9938
9942
  else if (height || autoSizeAlign) {
9939
9943
  switch (verticalAlign) {
@@ -9945,7 +9949,7 @@ function layoutText(drawData, style) {
9945
9949
  }
9946
9950
  starY += y;
9947
9951
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
9948
- for (let i = 0, len = rows.length; i < len; i++) {
9952
+ for (let i = 0, len = countRows; i < len; i++) {
9949
9953
  row = rows[i];
9950
9954
  row.x = x;
9951
9955
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -10014,7 +10018,7 @@ function clipText(drawData, style, x, width) {
10014
10018
  if (i === end && charRight < right) {
10015
10019
  break;
10016
10020
  }
10017
- else if (charRight < right && char.char !== ' ') {
10021
+ else if ((charRight < right && char.char !== ' ') || !i) {
10018
10022
  row.data.splice(i + 1);
10019
10023
  row.width -= char.width;
10020
10024
  break;