leafer-ui 1.0.0-rc.27 → 1.0.0-rc.28

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
@@ -14,8 +14,15 @@ var LeaferUI = (function (exports) {
14
14
  hitCanvasSize: 100,
15
15
  maxCacheSize: 2560 * 1600,
16
16
  maxPatternSize: 4096 * 2160,
17
- suffix: '',
18
- crossOrigin: 'anonymous'
17
+ crossOrigin: 'anonymous',
18
+ getRealURL(url) {
19
+ const { prefix, suffix } = Platform.image;
20
+ if (suffix && !url.startsWith('data:') && !url.startsWith('blob:'))
21
+ url += (url.includes("?") ? "&" : "?") + suffix;
22
+ if (prefix && url[0] === '/')
23
+ url = prefix + url;
24
+ return url;
25
+ }
19
26
  }
20
27
  };
21
28
 
@@ -5129,6 +5136,7 @@ var LeaferUI = (function (exports) {
5129
5136
  get __worldFlipped() { return this.__world.scaleX < 0 || this.__world.scaleY < 0; }
5130
5137
  get __onlyHitMask() { return this.__hasMask && !this.__.hitChildren; }
5131
5138
  get __ignoreHitWorld() { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren; }
5139
+ get __inLazyBounds() { const { leafer } = this; return leafer && leafer.created && leafer.lazyBounds.hit(this.__world); }
5132
5140
  get pathInputed() { return this.__.__pathInputed; }
5133
5141
  constructor(data) {
5134
5142
  this.innerId = create(LEAF);
@@ -5213,6 +5221,9 @@ var LeaferUI = (function (exports) {
5213
5221
  findOne(_condition, _options) { return undefined; }
5214
5222
  findId(_id) { return undefined; }
5215
5223
  focus(_value) { }
5224
+ updateLayout() {
5225
+ this.__layout.update();
5226
+ }
5216
5227
  forceUpdate(attrName) {
5217
5228
  if (attrName === undefined)
5218
5229
  attrName = 'width';
@@ -5222,8 +5233,8 @@ var LeaferUI = (function (exports) {
5222
5233
  this.__[attrName] = value === undefined ? null : undefined;
5223
5234
  this[attrName] = value;
5224
5235
  }
5225
- updateLayout() {
5226
- this.__layout.update();
5236
+ forceRender(_bounds) {
5237
+ this.forceUpdate('surface');
5227
5238
  }
5228
5239
  __updateWorldMatrix() { }
5229
5240
  __updateLocalMatrix() { }
@@ -5760,6 +5771,24 @@ var LeaferUI = (function (exports) {
5760
5771
 
5761
5772
  const debug$7 = Debug.get('LeaferCanvas');
5762
5773
  class LeaferCanvas extends LeaferCanvasBase {
5774
+ set zIndex(zIndex) {
5775
+ const { style } = this.view;
5776
+ style.zIndex = zIndex;
5777
+ this.setAbsolute(this.view);
5778
+ }
5779
+ set childIndex(index) {
5780
+ const { view, parentView } = this;
5781
+ if (view && parentView) {
5782
+ const beforeNode = parentView.children[index];
5783
+ if (beforeNode) {
5784
+ this.setAbsolute(beforeNode);
5785
+ parentView.insertBefore(view, beforeNode);
5786
+ }
5787
+ else {
5788
+ parentView.appendChild(beforeNode);
5789
+ }
5790
+ }
5791
+ }
5763
5792
  init() {
5764
5793
  const { view } = this.config;
5765
5794
  view ? this.__createViewFrom(view) : this.__createView();
@@ -5804,9 +5833,7 @@ var LeaferUI = (function (exports) {
5804
5833
  this.__createView();
5805
5834
  const view = this.view;
5806
5835
  if (parent.hasChildNodes()) {
5807
- const { style } = view;
5808
- style.position = 'absolute';
5809
- style.top = style.left = '0px';
5836
+ this.setAbsolute(view);
5810
5837
  parent.style.position || (parent.style.position = 'relative');
5811
5838
  }
5812
5839
  parent.appendChild(view);
@@ -5817,6 +5844,11 @@ var LeaferUI = (function (exports) {
5817
5844
  this.__createView();
5818
5845
  }
5819
5846
  }
5847
+ setAbsolute(view) {
5848
+ const { style } = view;
5849
+ style.position = 'absolute';
5850
+ style.top = style.left = '0px';
5851
+ }
5820
5852
  updateViewSize() {
5821
5853
  const { width, height, pixelRatio } = this;
5822
5854
  const { style } = this.view;
@@ -5936,16 +5968,14 @@ var LeaferUI = (function (exports) {
5936
5968
  loadImage(src) {
5937
5969
  return new Promise((resolve, reject) => {
5938
5970
  const img = new Image();
5939
- const { suffix, crossOrigin } = Platform.image;
5971
+ const { crossOrigin } = Platform.image;
5940
5972
  if (crossOrigin) {
5941
5973
  img.setAttribute('crossOrigin', crossOrigin);
5942
5974
  img.crossOrigin = crossOrigin;
5943
5975
  }
5944
5976
  img.onload = () => { resolve(img); };
5945
5977
  img.onerror = (e) => { reject(e); };
5946
- if (suffix && !src.startsWith('data:') && !src.startsWith('blob:'))
5947
- src += (src.includes("?") ? "&" : "?") + suffix;
5948
- img.src = src;
5978
+ img.src = Platform.image.getRealURL(src);
5949
5979
  });
5950
5980
  }
5951
5981
  };
@@ -7345,7 +7375,7 @@ var LeaferUI = (function (exports) {
7345
7375
  __onUpdateSize() {
7346
7376
  if (this.__.__input) {
7347
7377
  const data = this.__;
7348
- (data.lazy && this.leafer && this.leafer.created && !this.leafer.lazyBounds.hit(this.__world)) ? data.__needComputePaint = true : data.__computePaint();
7378
+ (data.lazy && !this.__inLazyBounds && !Export.running) ? data.__needComputePaint = true : data.__computePaint();
7349
7379
  }
7350
7380
  }
7351
7381
  __updateRenderPath() {
@@ -7903,6 +7933,10 @@ var LeaferUI = (function (exports) {
7903
7933
  if (!this.parent)
7904
7934
  this.canvas.hittable = newValue;
7905
7935
  }
7936
+ else if (attrName === 'zIndex') {
7937
+ this.canvas.zIndex = newValue;
7938
+ setTimeout(() => this.parent && this.parent.__updateSortChildren());
7939
+ }
7906
7940
  }
7907
7941
  return super.__setAttr(attrName, newValue);
7908
7942
  }
@@ -8521,7 +8555,7 @@ var LeaferUI = (function (exports) {
8521
8555
  __drawAfterFill(canvas, _options) {
8522
8556
  const origin = this.canvas.view;
8523
8557
  const { width, height } = this;
8524
- if (this.__.cornerRadius) {
8558
+ if (this.__.cornerRadius || this.pathInputed) {
8525
8559
  canvas.save();
8526
8560
  canvas.clip();
8527
8561
  canvas.drawImage(this.canvas.view, 0, 0, origin.width, origin.height, 0, 0, width, height);
@@ -8863,15 +8897,17 @@ var LeaferUI = (function (exports) {
8863
8897
  this.add(leafer);
8864
8898
  return leafer;
8865
8899
  }
8866
- add(leafer) {
8900
+ add(leafer, index) {
8867
8901
  if (!leafer.view) {
8868
8902
  if (this.realCanvas && !this.canvas.bounds) {
8869
- setTimeout(() => this.add(leafer), 10);
8903
+ setTimeout(() => this.add(leafer, index), 10);
8870
8904
  return;
8871
8905
  }
8872
8906
  leafer.init(this.__getChildConfig(leafer.userConfig), this);
8873
8907
  }
8874
- super.add(leafer);
8908
+ super.add(leafer, index);
8909
+ if (index !== undefined)
8910
+ leafer.canvas.childIndex = index;
8875
8911
  this.__listenChildEvents(leafer);
8876
8912
  }
8877
8913
  __onPropertyChange() {
@@ -9218,13 +9254,15 @@ var LeaferUI = (function (exports) {
9218
9254
  };
9219
9255
  const { list, register } = LeaferTypeCreator;
9220
9256
  register('draw', () => { });
9257
+ register('custom', () => { });
9221
9258
  register('design', addInteractionWindow);
9222
9259
  register('document', document$1);
9223
9260
 
9224
- exports.Leafer.prototype.initType = function (type) {
9261
+ const leafer = exports.Leafer.prototype;
9262
+ leafer.initType = function (type) {
9225
9263
  LeaferTypeCreator.run(type, this);
9226
9264
  };
9227
- exports.Leafer.prototype.getValidMove = function (moveX, moveY) {
9265
+ leafer.getValidMove = function (moveX, moveY) {
9228
9266
  const { scroll, disabled } = this.app.config.move;
9229
9267
  if (scroll) {
9230
9268
  if (Math.abs(moveX) > Math.abs(moveY))
@@ -9254,7 +9292,7 @@ var LeaferUI = (function (exports) {
9254
9292
  }
9255
9293
  return { x: disabled ? 0 : moveX, y: disabled ? 0 : moveY };
9256
9294
  };
9257
- exports.Leafer.prototype.getValidScale = function (changeScale) {
9295
+ leafer.getValidScale = function (changeScale) {
9258
9296
  const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale);
9259
9297
  if (absScale < min)
9260
9298
  changeScale = min / scaleX;
@@ -9710,7 +9748,7 @@ var LeaferUI = (function (exports) {
9710
9748
  swipeDistance: 20,
9711
9749
  preventDefaultMenu: true
9712
9750
  },
9713
- cursor: {},
9751
+ cursor: true,
9714
9752
  keyEvent: true
9715
9753
  };
9716
9754
 
@@ -10023,7 +10061,7 @@ var LeaferUI = (function (exports) {
10023
10061
  this.hoverData = data;
10024
10062
  }
10025
10063
  updateCursor(data) {
10026
- if (this.config.cursor.stop || !this.config.pointer.hover)
10064
+ if (!this.config.cursor || !this.config.pointer.hover)
10027
10065
  return;
10028
10066
  if (!data) {
10029
10067
  this.updateHoverData();
@@ -11272,7 +11310,7 @@ var LeaferUI = (function (exports) {
11272
11310
  width *= data.scaleX;
11273
11311
  height *= data.scaleY;
11274
11312
  }
11275
- allowPaint = width * height > Platform.image.maxCacheSize;
11313
+ allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
11276
11314
  }
11277
11315
  else {
11278
11316
  allowPaint = false;
@@ -11784,7 +11822,8 @@ var LeaferUI = (function (exports) {
11784
11822
  if (breakAll) {
11785
11823
  if (wordWidth)
11786
11824
  addWord();
11787
- addRow();
11825
+ if (rowWidth)
11826
+ addRow();
11788
11827
  }
11789
11828
  else {
11790
11829
  if (!afterBreak)
@@ -11792,10 +11831,12 @@ var LeaferUI = (function (exports) {
11792
11831
  if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
11793
11832
  if (wordWidth)
11794
11833
  addWord();
11795
- addRow();
11834
+ if (rowWidth)
11835
+ addRow();
11796
11836
  }
11797
11837
  else {
11798
- addRow();
11838
+ if (rowWidth)
11839
+ addRow();
11799
11840
  }
11800
11841
  }
11801
11842
  }
@@ -12181,6 +12222,7 @@ var LeaferUI = (function (exports) {
12181
12222
  }
12182
12223
  const { leafer } = leaf;
12183
12224
  if (leafer) {
12225
+ checkLazy(leaf);
12184
12226
  leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
12185
12227
  options = FileHelper.getExportOptions(options);
12186
12228
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
@@ -12188,6 +12230,8 @@ var LeaferUI = (function (exports) {
12188
12230
  const { slice, trim, onCanvas } = options;
12189
12231
  let scale = options.scale || 1;
12190
12232
  let pixelRatio = options.pixelRatio || 1;
12233
+ const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
12234
+ const contextSettings = options.contextSettings || leafer.config.contextSettings;
12191
12235
  if (leaf.isApp) {
12192
12236
  scale *= pixelRatio;
12193
12237
  pixelRatio = leaf.app.pixelRatio;
@@ -12226,7 +12270,7 @@ var LeaferUI = (function (exports) {
12226
12270
  renderBounds = leaf.getBounds('render', relative);
12227
12271
  }
12228
12272
  const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
12229
- let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio });
12273
+ let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
12230
12274
  const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
12231
12275
  if (slice) {
12232
12276
  leaf = leafer;
@@ -12272,6 +12316,12 @@ var LeaferUI = (function (exports) {
12272
12316
  tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
12273
12317
  });
12274
12318
  }
12319
+ function checkLazy(leaf) {
12320
+ if (leaf.__.__needComputePaint)
12321
+ leaf.__.__computePaint();
12322
+ if (leaf.isBranch)
12323
+ leaf.children.forEach(child => checkLazy(child));
12324
+ }
12275
12325
 
12276
12326
  const canvas = LeaferCanvasBase.prototype;
12277
12327
  const debug = Debug.get('@leafer-ui/export');
@@ -12437,6 +12487,7 @@ var LeaferUI = (function (exports) {
12437
12487
  exports.WaitHelper = WaitHelper;
12438
12488
  exports.WatchEvent = WatchEvent;
12439
12489
  exports.Watcher = Watcher;
12490
+ exports.addInteractionWindow = addInteractionWindow;
12440
12491
  exports.affectRenderBoundsType = affectRenderBoundsType;
12441
12492
  exports.affectStrokeBoundsType = affectStrokeBoundsType;
12442
12493
  exports.arrowType = arrowType;