@leafer-draw/miniapp 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 false; }
@@ -6921,7 +6916,11 @@ const State = {
6921
6916
  setStyleName() { return Plugin.need('state'); },
6922
6917
  set() { return Plugin.need('state'); }
6923
6918
  };
6924
- const Transition = {};
6919
+ const Transition = {
6920
+ list: {},
6921
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6922
+ get(attrName) { return Transition.list[attrName]; }
6923
+ };
6925
6924
 
6926
6925
  const { parse, objectToCanvasData } = PathConvert;
6927
6926
  const emptyPaint = {};
@@ -7345,9 +7344,6 @@ let UI = UI_1 = class UI extends Leaf {
7345
7344
  this.__drawPathByBox(pen);
7346
7345
  return pen;
7347
7346
  }
7348
- get editConfig() { return undefined; }
7349
- get editOuter() { return ''; }
7350
- get editInner() { return ''; }
7351
7347
  constructor(data) {
7352
7348
  super(data);
7353
7349
  }
@@ -7429,8 +7425,11 @@ let UI = UI_1 = class UI extends Leaf {
7429
7425
  export(_filename, _options) {
7430
7426
  return Plugin.need('export');
7431
7427
  }
7428
+ syncExport(_filename, _options) {
7429
+ return Plugin.need('export');
7430
+ }
7432
7431
  clone(data) {
7433
- const json = this.toJSON();
7432
+ const json = DataHelper.clone(this.toJSON());
7434
7433
  if (data)
7435
7434
  Object.assign(json, data);
7436
7435
  return UI_1.one(json);
@@ -7729,7 +7728,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7729
7728
  get layoutLocked() { return !this.layouter.running; }
7730
7729
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7731
7730
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7732
- get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
7731
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7733
7732
  constructor(userConfig, data) {
7734
7733
  super(data);
7735
7734
  this.config = {
@@ -8031,6 +8030,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8031
8030
  getPagePointByClient(clientPoint, updateClient) {
8032
8031
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8033
8032
  }
8033
+ getClientPointByWorld(worldPoint) {
8034
+ const { x, y } = this.clientBounds;
8035
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
8036
+ }
8034
8037
  updateClientBounds() {
8035
8038
  this.canvas && this.canvas.updateClientBounds();
8036
8039
  }
@@ -10066,13 +10069,14 @@ function toChar(data, charX, rowData, isOverflow) {
10066
10069
  }
10067
10070
 
10068
10071
  function layoutText(drawData, style) {
10069
- const { rows, bounds } = drawData;
10072
+ const { rows, bounds } = drawData, countRows = rows.length;
10070
10073
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
10071
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
10074
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
10072
10075
  let starY = __baseLine;
10073
10076
  if (__clipText && realHeight > height) {
10074
10077
  realHeight = Math.max(height, __lineHeight);
10075
- drawData.overflow = rows.length;
10078
+ if (countRows > 1)
10079
+ drawData.overflow = countRows;
10076
10080
  }
10077
10081
  else if (height || autoSizeAlign) {
10078
10082
  switch (verticalAlign) {
@@ -10084,7 +10088,7 @@ function layoutText(drawData, style) {
10084
10088
  }
10085
10089
  starY += y;
10086
10090
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
10087
- for (let i = 0, len = rows.length; i < len; i++) {
10091
+ for (let i = 0, len = countRows; i < len; i++) {
10088
10092
  row = rows[i];
10089
10093
  row.x = x;
10090
10094
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -10153,7 +10157,7 @@ function clipText(drawData, style, x, width) {
10153
10157
  if (i === end && charRight < right) {
10154
10158
  break;
10155
10159
  }
10156
- else if (charRight < right && char.char !== ' ') {
10160
+ else if ((charRight < right && char.char !== ' ') || !i) {
10157
10161
  row.data.splice(i + 1);
10158
10162
  row.width -= char.width;
10159
10163
  break;