@leafer-draw/worker 1.0.0-rc.26 → 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.
@@ -11,8 +11,15 @@ const Platform = {
11
11
  hitCanvasSize: 100,
12
12
  maxCacheSize: 2560 * 1600,
13
13
  maxPatternSize: 4096 * 2160,
14
- suffix: '',
15
- crossOrigin: 'anonymous'
14
+ crossOrigin: 'anonymous',
15
+ getRealURL(url) {
16
+ const { prefix, suffix } = Platform.image;
17
+ if (suffix && !url.startsWith('data:') && !url.startsWith('blob:'))
18
+ url += (url.includes("?") ? "&" : "?") + suffix;
19
+ if (prefix && url[0] === '/')
20
+ url = prefix + url;
21
+ return url;
22
+ }
16
23
  }
17
24
  };
18
25
 
@@ -5126,6 +5133,7 @@ let Leaf = class Leaf {
5126
5133
  get __worldFlipped() { return this.__world.scaleX < 0 || this.__world.scaleY < 0; }
5127
5134
  get __onlyHitMask() { return this.__hasMask && !this.__.hitChildren; }
5128
5135
  get __ignoreHitWorld() { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren; }
5136
+ get __inLazyBounds() { const { leafer } = this; return leafer && leafer.created && leafer.lazyBounds.hit(this.__world); }
5129
5137
  get pathInputed() { return this.__.__pathInputed; }
5130
5138
  constructor(data) {
5131
5139
  this.innerId = create(LEAF);
@@ -5189,6 +5197,9 @@ let Leaf = class Leaf {
5189
5197
  }
5190
5198
  set(_data) { }
5191
5199
  get(_name) { return undefined; }
5200
+ setAttr(name, value) { this[name] = value; }
5201
+ getAttr(name) { return this[name]; }
5202
+ getComputedAttr(name) { return this.__[name]; }
5192
5203
  toJSON() {
5193
5204
  return this.__.__getInputData();
5194
5205
  }
@@ -5207,6 +5218,9 @@ let Leaf = class Leaf {
5207
5218
  findOne(_condition, _options) { return undefined; }
5208
5219
  findId(_id) { return undefined; }
5209
5220
  focus(_value) { }
5221
+ updateLayout() {
5222
+ this.__layout.update();
5223
+ }
5210
5224
  forceUpdate(attrName) {
5211
5225
  if (attrName === undefined)
5212
5226
  attrName = 'width';
@@ -5216,8 +5230,8 @@ let Leaf = class Leaf {
5216
5230
  this.__[attrName] = value === undefined ? null : undefined;
5217
5231
  this[attrName] = value;
5218
5232
  }
5219
- updateLayout() {
5220
- this.__layout.update();
5233
+ forceRender(_bounds) {
5234
+ this.forceUpdate('surface');
5221
5235
  }
5222
5236
  __updateWorldMatrix() { }
5223
5237
  __updateLocalMatrix() { }
@@ -5749,7 +5763,7 @@ class LeafLevelList {
5749
5763
  }
5750
5764
  }
5751
5765
 
5752
- const version = "1.0.0-rc.26";
5766
+ const version = "1.0.0-rc.27";
5753
5767
  const inviteCode = {};
5754
5768
 
5755
5769
  class LeaferCanvas extends LeaferCanvasBase {
@@ -5798,10 +5812,8 @@ function useCanvas(_canvasType, _power) {
5798
5812
  download(_url, _filename) { return undefined; },
5799
5813
  loadImage(src) {
5800
5814
  return new Promise((resolve, reject) => {
5801
- if (!src.startsWith('data:') && Platform.image.suffix)
5802
- src += (src.includes("?") ? "&" : "?") + Platform.image.suffix;
5803
5815
  let req = new XMLHttpRequest();
5804
- req.open('GET', src, true);
5816
+ req.open('GET', Platform.image.getRealURL(src), true);
5805
5817
  req.responseType = "blob";
5806
5818
  req.onload = () => {
5807
5819
  createImageBitmap(req.response).then(img => {
@@ -6819,6 +6831,8 @@ const UIRender = {
6819
6831
  this.__drawRenderPath(canvas);
6820
6832
  if (fill && !ignoreFill)
6821
6833
  this.__.__pixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
6834
+ if (this.__.__isCanvas)
6835
+ this.__drawAfterFill(canvas, options);
6822
6836
  if (stroke && !ignoreStroke)
6823
6837
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
6824
6838
  }
@@ -6932,7 +6946,7 @@ let UI = UI_1 = class UI extends Leaf {
6932
6946
  __onUpdateSize() {
6933
6947
  if (this.__.__input) {
6934
6948
  const data = this.__;
6935
- (data.lazy && this.leafer && this.leafer.created && !this.leafer.lazyBounds.hit(this.__world)) ? data.__needComputePaint = true : data.__computePaint();
6949
+ (data.lazy && !this.__inLazyBounds && !Export.running) ? data.__needComputePaint = true : data.__computePaint();
6936
6950
  }
6937
6951
  }
6938
6952
  __updateRenderPath() {
@@ -7241,6 +7255,9 @@ __decorate([
7241
7255
  __decorate([
7242
7256
  dataType()
7243
7257
  ], UI.prototype, "disabledStyle", void 0);
7258
+ __decorate([
7259
+ dataType({})
7260
+ ], UI.prototype, "data", void 0);
7244
7261
  __decorate([
7245
7262
  rewrite(Leaf.prototype.reset)
7246
7263
  ], UI.prototype, "reset", null);
@@ -7487,6 +7504,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7487
7504
  if (!this.parent)
7488
7505
  this.canvas.hittable = newValue;
7489
7506
  }
7507
+ else if (attrName === 'zIndex') {
7508
+ this.canvas.zIndex = newValue;
7509
+ setTimeout(() => this.parent && this.parent.__updateSortChildren());
7510
+ }
7490
7511
  }
7491
7512
  return super.__setAttr(attrName, newValue);
7492
7513
  }
@@ -8083,7 +8104,7 @@ let Canvas = class Canvas extends Rect {
8083
8104
  super(data);
8084
8105
  this.canvas = Creator.canvas(this.__);
8085
8106
  this.context = this.canvas.context;
8086
- this.__.__drawAfterFill = true;
8107
+ this.__.__isCanvas = this.__.__drawAfterFill = true;
8087
8108
  }
8088
8109
  draw(ui, offset, scale, rotation) {
8089
8110
  ui.__layout.update();
@@ -8105,7 +8126,7 @@ let Canvas = class Canvas extends Rect {
8105
8126
  __drawAfterFill(canvas, _options) {
8106
8127
  const origin = this.canvas.view;
8107
8128
  const { width, height } = this;
8108
- if (this.__.cornerRadius) {
8129
+ if (this.__.cornerRadius || this.pathInputed) {
8109
8130
  canvas.save();
8110
8131
  canvas.clip();
8111
8132
  canvas.drawImage(this.canvas.view, 0, 0, origin.width, origin.height, 0, 0, width, height);
@@ -8151,9 +8172,6 @@ __decorate([
8151
8172
  __decorate([
8152
8173
  resizeType()
8153
8174
  ], Canvas.prototype, "contextSettings", void 0);
8154
- __decorate([
8155
- hitType('all')
8156
- ], Canvas.prototype, "hitFill", void 0);
8157
8175
  Canvas = __decorate([
8158
8176
  registerUI()
8159
8177
  ], Canvas);
@@ -8989,7 +9007,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
8989
9007
  width *= data.scaleX;
8990
9008
  height *= data.scaleY;
8991
9009
  }
8992
- allowPaint = width * height > Platform.image.maxCacheSize;
9010
+ allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running;
8993
9011
  }
8994
9012
  else {
8995
9013
  allowPaint = false;
@@ -9501,7 +9519,8 @@ function createRows(drawData, content, style) {
9501
9519
  if (breakAll) {
9502
9520
  if (wordWidth)
9503
9521
  addWord();
9504
- addRow();
9522
+ if (rowWidth)
9523
+ addRow();
9505
9524
  }
9506
9525
  else {
9507
9526
  if (!afterBreak)
@@ -9509,10 +9528,12 @@ function createRows(drawData, content, style) {
9509
9528
  if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
9510
9529
  if (wordWidth)
9511
9530
  addWord();
9512
- addRow();
9531
+ if (rowWidth)
9532
+ addRow();
9513
9533
  }
9514
9534
  else {
9515
- addRow();
9535
+ if (rowWidth)
9536
+ addRow();
9516
9537
  }
9517
9538
  }
9518
9539
  }
@@ -9898,6 +9919,7 @@ const ExportModule = {
9898
9919
  }
9899
9920
  const { leafer } = leaf;
9900
9921
  if (leafer) {
9922
+ checkLazy(leaf);
9901
9923
  leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
9902
9924
  options = FileHelper.getExportOptions(options);
9903
9925
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
@@ -9905,6 +9927,8 @@ const ExportModule = {
9905
9927
  const { slice, trim, onCanvas } = options;
9906
9928
  let scale = options.scale || 1;
9907
9929
  let pixelRatio = options.pixelRatio || 1;
9930
+ const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
9931
+ const contextSettings = options.contextSettings || leafer.config.contextSettings;
9908
9932
  if (leaf.isApp) {
9909
9933
  scale *= pixelRatio;
9910
9934
  pixelRatio = leaf.app.pixelRatio;
@@ -9943,7 +9967,7 @@ const ExportModule = {
9943
9967
  renderBounds = leaf.getBounds('render', relative);
9944
9968
  }
9945
9969
  const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
9946
- let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio });
9970
+ let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
9947
9971
  const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
9948
9972
  if (slice) {
9949
9973
  leaf = leafer;
@@ -9989,6 +10013,12 @@ function addTask(task) {
9989
10013
  tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
9990
10014
  });
9991
10015
  }
10016
+ function checkLazy(leaf) {
10017
+ if (leaf.__.__needComputePaint)
10018
+ leaf.__.__computePaint();
10019
+ if (leaf.isBranch)
10020
+ leaf.children.forEach(child => checkLazy(child));
10021
+ }
9992
10022
 
9993
10023
  const canvas = LeaferCanvasBase.prototype;
9994
10024
  const debug = Debug.get('@leafer-ui/export');