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