leafer-draw 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.
package/dist/web.js CHANGED
@@ -2032,13 +2032,11 @@ var LeaferUI = (function (exports) {
2032
2032
  this.worldTransform = {};
2033
2033
  if (!config)
2034
2034
  config = minSize;
2035
- if (!config.pixelRatio)
2036
- config.pixelRatio = Platform.devicePixelRatio;
2037
2035
  this.manager = manager;
2038
2036
  this.innerId = IncrementId.create(IncrementId.CNAVAS);
2039
2037
  const { width, height, pixelRatio } = config;
2040
2038
  this.autoLayout = !width || !height;
2041
- this.size.pixelRatio = pixelRatio;
2039
+ this.size.pixelRatio = pixelRatio | Platform.devicePixelRatio;
2042
2040
  this.config = config;
2043
2041
  this.init();
2044
2042
  }
@@ -2235,7 +2233,7 @@ var LeaferUI = (function (exports) {
2235
2233
  tempBounds$1.ceil();
2236
2234
  }
2237
2235
  isSameSize(size) {
2238
- return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
2236
+ return this.width === size.width && this.height === size.height && (!size.pixelRatio || this.pixelRatio === size.pixelRatio);
2239
2237
  }
2240
2238
  getSameCanvas(useSameWorldTransform, useSameSmooth) {
2241
2239
  const canvas = this.manager ? this.manager.get(this.size) : Creator.canvas(Object.assign({}, this.size));
@@ -4073,13 +4071,10 @@ var LeaferUI = (function (exports) {
4073
4071
  if (defaultValue === undefined) {
4074
4072
  property.get = function () { return this[computedKey]; };
4075
4073
  }
4076
- else if (typeof defaultValue === 'object') {
4077
- const { clone } = DataHelper;
4074
+ else if (typeof defaultValue === 'function') {
4078
4075
  property.get = function () {
4079
4076
  let v = this[computedKey];
4080
- if (v === undefined)
4081
- this[computedKey] = v = clone(defaultValue);
4082
- return v;
4077
+ return v === undefined ? defaultValue(this.__leaf) : v;
4083
4078
  };
4084
4079
  }
4085
4080
  if (key === 'width') {
@@ -5725,10 +5720,10 @@ var LeaferUI = (function (exports) {
5725
5720
  static changeAttr(attrName, defaultValue, fn) {
5726
5721
  fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5727
5722
  }
5728
- static addAttr(attrName, defaultValue, fn) {
5723
+ static addAttr(attrName, defaultValue, fn, helpValue) {
5729
5724
  if (!fn)
5730
5725
  fn = boundsType;
5731
- fn(defaultValue)(this.prototype, attrName);
5726
+ fn(defaultValue, helpValue)(this.prototype, attrName);
5732
5727
  }
5733
5728
  __emitLifeEvent(type) {
5734
5729
  if (this.hasEvent(type))
@@ -6055,7 +6050,7 @@ var LeaferUI = (function (exports) {
6055
6050
  }
6056
6051
  }
6057
6052
 
6058
- const version = "1.4.2";
6053
+ const version = "1.5.1";
6059
6054
 
6060
6055
  const debug$4 = Debug.get('LeaferCanvas');
6061
6056
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6177,7 +6172,7 @@ var LeaferUI = (function (exports) {
6177
6172
  else {
6178
6173
  window.addEventListener('resize', this.windowListener = () => {
6179
6174
  const pixelRatio = Platform.devicePixelRatio;
6180
- if (this.pixelRatio !== pixelRatio) {
6175
+ if (!this.config.pixelRatio && this.pixelRatio !== pixelRatio) {
6181
6176
  const { width, height } = this;
6182
6177
  this.emitResize({ width, height, pixelRatio });
6183
6178
  }
@@ -6194,7 +6189,7 @@ var LeaferUI = (function (exports) {
6194
6189
  checkAutoBounds(parentSize) {
6195
6190
  const view = this.view;
6196
6191
  const { x, y, width, height } = this.autoBounds.getBoundsFrom(parentSize);
6197
- const size = { width, height, pixelRatio: Platform.devicePixelRatio };
6192
+ const size = { width, height, pixelRatio: this.config.pixelRatio ? this.pixelRatio : Platform.devicePixelRatio };
6198
6193
  if (!this.isSameSize(size)) {
6199
6194
  const { style } = view;
6200
6195
  style.marginLeft = x + 'px';
@@ -6966,7 +6961,11 @@ var LeaferUI = (function (exports) {
6966
6961
  setStyleName() { return Plugin.need('state'); },
6967
6962
  set() { return Plugin.need('state'); }
6968
6963
  };
6969
- const Transition = {};
6964
+ const Transition = {
6965
+ list: {},
6966
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6967
+ get(attrName) { return Transition.list[attrName]; }
6968
+ };
6970
6969
 
6971
6970
  const { parse, objectToCanvasData } = PathConvert;
6972
6971
  const emptyPaint = {};
@@ -7390,9 +7389,6 @@ var LeaferUI = (function (exports) {
7390
7389
  this.__drawPathByBox(pen);
7391
7390
  return pen;
7392
7391
  }
7393
- get editConfig() { return undefined; }
7394
- get editOuter() { return ''; }
7395
- get editInner() { return ''; }
7396
7392
  constructor(data) {
7397
7393
  super(data);
7398
7394
  }
@@ -7474,8 +7470,11 @@ var LeaferUI = (function (exports) {
7474
7470
  export(_filename, _options) {
7475
7471
  return Plugin.need('export');
7476
7472
  }
7473
+ syncExport(_filename, _options) {
7474
+ return Plugin.need('export');
7475
+ }
7477
7476
  clone(data) {
7478
- const json = this.toJSON();
7477
+ const json = DataHelper.clone(this.toJSON());
7479
7478
  if (data)
7480
7479
  Object.assign(json, data);
7481
7480
  return UI_1.one(json);
@@ -7774,7 +7773,7 @@ var LeaferUI = (function (exports) {
7774
7773
  get layoutLocked() { return !this.layouter.running; }
7775
7774
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7776
7775
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7777
- get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
7776
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7778
7777
  constructor(userConfig, data) {
7779
7778
  super(data);
7780
7779
  this.config = {
@@ -8076,6 +8075,10 @@ var LeaferUI = (function (exports) {
8076
8075
  getPagePointByClient(clientPoint, updateClient) {
8077
8076
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8078
8077
  }
8078
+ getClientPointByWorld(worldPoint) {
8079
+ const { x, y } = this.clientBounds;
8080
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
8081
+ }
8079
8082
  updateClientBounds() {
8080
8083
  this.canvas && this.canvas.updateClientBounds();
8081
8084
  }
@@ -10111,13 +10114,14 @@ var LeaferUI = (function (exports) {
10111
10114
  }
10112
10115
 
10113
10116
  function layoutText(drawData, style) {
10114
- const { rows, bounds } = drawData;
10117
+ const { rows, bounds } = drawData, countRows = rows.length;
10115
10118
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
10116
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
10119
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
10117
10120
  let starY = __baseLine;
10118
10121
  if (__clipText && realHeight > height) {
10119
10122
  realHeight = Math.max(height, __lineHeight);
10120
- drawData.overflow = rows.length;
10123
+ if (countRows > 1)
10124
+ drawData.overflow = countRows;
10121
10125
  }
10122
10126
  else if (height || autoSizeAlign) {
10123
10127
  switch (verticalAlign) {
@@ -10129,7 +10133,7 @@ var LeaferUI = (function (exports) {
10129
10133
  }
10130
10134
  starY += y;
10131
10135
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
10132
- for (let i = 0, len = rows.length; i < len; i++) {
10136
+ for (let i = 0, len = countRows; i < len; i++) {
10133
10137
  row = rows[i];
10134
10138
  row.x = x;
10135
10139
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -10198,7 +10202,7 @@ var LeaferUI = (function (exports) {
10198
10202
  if (i === end && charRight < right) {
10199
10203
  break;
10200
10204
  }
10201
- else if (charRight < right && char.char !== ' ') {
10205
+ else if ((charRight < right && char.char !== ' ') || !i) {
10202
10206
  row.data.splice(i + 1);
10203
10207
  row.width -= char.width;
10204
10208
  break;