@leafer-editor/worker 1.0.0-rc.28 → 1.0.0

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/worker.js CHANGED
@@ -1558,7 +1558,7 @@ var LeaferUI = (function (exports) {
1558
1558
  if (this.__input && this.__input[name] !== undefined)
1559
1559
  this.__input[name] = undefined;
1560
1560
  }
1561
- __getInputData(names) {
1561
+ __getInputData(names, options) {
1562
1562
  const data = {};
1563
1563
  if (names) {
1564
1564
  if (names instanceof Array) {
@@ -1585,6 +1585,12 @@ var LeaferUI = (function (exports) {
1585
1585
  }
1586
1586
  }
1587
1587
  }
1588
+ if (options) {
1589
+ if (options.matrix) {
1590
+ const { a, b, c, d, e, f } = this.__leaf.__localMatrix;
1591
+ data.matrix = { a, b, c, d, e, f };
1592
+ }
1593
+ }
1588
1594
  return data;
1589
1595
  }
1590
1596
  __setMiddle(name, value) {
@@ -5203,11 +5209,13 @@ var LeaferUI = (function (exports) {
5203
5209
  setAttr(name, value) { this[name] = value; }
5204
5210
  getAttr(name) { return this[name]; }
5205
5211
  getComputedAttr(name) { return this.__[name]; }
5206
- toJSON() {
5207
- return this.__.__getInputData();
5212
+ toJSON(options) {
5213
+ if (options)
5214
+ this.__layout.update();
5215
+ return this.__.__getInputData(null, options);
5208
5216
  }
5209
- toString() {
5210
- return JSON.stringify(this.toJSON());
5217
+ toString(options) {
5218
+ return JSON.stringify(this.toJSON(options));
5211
5219
  }
5212
5220
  toSVG() { return undefined; }
5213
5221
  __SVG(_data) { }
@@ -5280,14 +5288,6 @@ var LeaferUI = (function (exports) {
5280
5288
  return this.__world;
5281
5289
  }
5282
5290
  }
5283
- getWorld(attrName) {
5284
- this.__layout.update();
5285
- if (attrName === 'x')
5286
- return this.__world.e;
5287
- if (attrName === 'y')
5288
- return this.__world.f;
5289
- return this.getLayoutBounds()[attrName];
5290
- }
5291
5291
  getTransform(relative) {
5292
5292
  return this.__layout.getTransform(relative || 'local');
5293
5293
  }
@@ -5408,14 +5408,8 @@ var LeaferUI = (function (exports) {
5408
5408
  this.scaleY *= scaleY;
5409
5409
  }
5410
5410
  __scaleResize(_scaleX, _scaleY) { }
5411
- resizeWidth(width) {
5412
- const scale = width / this.__localBoxBounds.width;
5413
- this.scaleResize(scale, this.__.lockRatio ? scale : 1);
5414
- }
5415
- resizeHeight(height) {
5416
- const scale = height / this.__localBoxBounds.height;
5417
- this.scaleResize(this.__.lockRatio ? scale : 1, scale);
5418
- }
5411
+ resizeWidth(_width) { }
5412
+ resizeHeight(_height) { }
5419
5413
  __hitWorld(_point) { return true; }
5420
5414
  __hit(_local) { return true; }
5421
5415
  __hitFill(_inner) { return true; }
@@ -5766,7 +5760,7 @@ var LeaferUI = (function (exports) {
5766
5760
  }
5767
5761
  }
5768
5762
 
5769
- const version = "1.0.0-rc.27";
5763
+ const version = "1.0.0-rc.30";
5770
5764
  const inviteCode = {};
5771
5765
 
5772
5766
  class LeaferCanvas extends LeaferCanvasBase {
@@ -7577,9 +7571,9 @@ var LeaferUI = (function (exports) {
7577
7571
  super.set(data);
7578
7572
  }
7579
7573
  }
7580
- toJSON() {
7581
- const data = super.toJSON();
7582
- data.children = this.children.map(child => child.toJSON());
7574
+ toJSON(options) {
7575
+ const data = super.toJSON(options);
7576
+ data.children = this.children.map(child => child.toJSON(options));
7583
7577
  return data;
7584
7578
  }
7585
7579
  pick(_hitPoint, _options) { return undefined; }
@@ -7746,6 +7740,8 @@ var LeaferUI = (function (exports) {
7746
7740
  __onResize(event) {
7747
7741
  this.emitEvent(event);
7748
7742
  DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
7743
+ if (!event.width || !event.height)
7744
+ debug$4.warn('w = 0 or h = 0');
7749
7745
  setTimeout(() => { if (this.canvasManager)
7750
7746
  this.canvasManager.clearRecycled(); }, 0);
7751
7747
  }
@@ -7769,6 +7765,8 @@ var LeaferUI = (function (exports) {
7769
7765
  __setAttr(attrName, newValue) {
7770
7766
  if (this.canvas) {
7771
7767
  if (canvasSizeAttrs.includes(attrName)) {
7768
+ if (!newValue)
7769
+ debug$4.warn(attrName + ' is 0');
7772
7770
  this.__changeCanvasSize(attrName, newValue);
7773
7771
  }
7774
7772
  else if (attrName === 'fill') {
@@ -9541,7 +9539,7 @@ var LeaferUI = (function (exports) {
9541
9539
  }
9542
9540
  function emitEvent(leaf, type, data, capture, excludePath) {
9543
9541
  if (leaf.destroyed)
9544
- return true;
9542
+ return false;
9545
9543
  if (leaf.__.hitSelf && !exclude(leaf, excludePath)) {
9546
9544
  if (State.updateEventStyle)
9547
9545
  State.updateEventStyle(leaf, type);
@@ -9643,9 +9641,7 @@ var LeaferUI = (function (exports) {
9643
9641
  this.tapWait();
9644
9642
  this.longPressWait(data);
9645
9643
  }
9646
- else if (PointerButton.right(data)) {
9647
- this.waitMenuTap = true;
9648
- }
9644
+ this.waitMenuTap = PointerButton.right(data);
9649
9645
  this.dragger.setDragData(data);
9650
9646
  if (!this.isHoldRightKey)
9651
9647
  this.updateCursor(data);
@@ -10063,8 +10059,8 @@ var LeaferUI = (function (exports) {
10063
10059
 
10064
10060
  const { toInnerRadiusPointOf, copy: copy$5, setRadius } = PointHelper;
10065
10061
  const inner = {};
10066
- const leaf = exports.Leaf.prototype;
10067
- leaf.__hitWorld = function (point) {
10062
+ const leaf$1 = exports.Leaf.prototype;
10063
+ leaf$1.__hitWorld = function (point) {
10068
10064
  if (!this.__.hitSelf)
10069
10065
  return false;
10070
10066
  if (this.__.hitRadius) {
@@ -10087,10 +10083,10 @@ var LeaferUI = (function (exports) {
10087
10083
  }
10088
10084
  return this.__hit(inner);
10089
10085
  };
10090
- leaf.__hitFill = function (inner) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitFill(inner, this.__.windingRule); };
10091
- leaf.__hitStroke = function (inner, strokeWidth) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitStroke(inner, strokeWidth); };
10092
- leaf.__hitPixel = function (inner) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitPixel(inner, this.__layout.renderBounds, this.__hitCanvas.hitScale); };
10093
- leaf.__drawHitPath = function (canvas) { if (canvas)
10086
+ leaf$1.__hitFill = function (inner) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitFill(inner, this.__.windingRule); };
10087
+ leaf$1.__hitStroke = function (inner, strokeWidth) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitStroke(inner, strokeWidth); };
10088
+ leaf$1.__hitPixel = function (inner) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitPixel(inner, this.__layout.renderBounds, this.__hitCanvas.hitScale); };
10089
+ leaf$1.__drawHitPath = function (canvas) { if (canvas)
10094
10090
  this.__drawRenderPath(canvas); };
10095
10091
 
10096
10092
  const matrix$2 = new Matrix();
@@ -11537,7 +11533,9 @@ var LeaferUI = (function (exports) {
11537
11533
  bounds.height = realHeight;
11538
11534
  }
11539
11535
 
11540
- function clipText(drawData, style) {
11536
+ function clipText(drawData, style, x, width) {
11537
+ if (!width)
11538
+ return;
11541
11539
  const { rows, overflow } = drawData;
11542
11540
  let { textOverflow } = style;
11543
11541
  rows.splice(overflow);
@@ -11548,7 +11546,7 @@ var LeaferUI = (function (exports) {
11548
11546
  textOverflow = '...';
11549
11547
  let char, charRight;
11550
11548
  const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
11551
- const right = style.x + style.width - ellipsisWidth;
11549
+ const right = x + width - ellipsisWidth;
11552
11550
  const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
11553
11551
  list.forEach(row => {
11554
11552
  if (row.isOverflow && row.data) {
@@ -11624,7 +11622,7 @@ var LeaferUI = (function (exports) {
11624
11622
  layoutText(drawData, style);
11625
11623
  layoutChar(drawData, style, width);
11626
11624
  if (drawData.overflow)
11627
- clipText(drawData, style);
11625
+ clipText(drawData, style, x, width);
11628
11626
  if (textDecoration !== 'none')
11629
11627
  decorationText(drawData, style);
11630
11628
  return drawData;
@@ -11695,6 +11693,8 @@ var LeaferUI = (function (exports) {
11695
11693
  const ExportModule = {
11696
11694
  export(leaf, filename, options) {
11697
11695
  this.running = true;
11696
+ const fileType = FileHelper.fileType(filename);
11697
+ options = FileHelper.getExportOptions(options);
11698
11698
  return addTask((success) => new Promise((resolve) => {
11699
11699
  const over = (result) => {
11700
11700
  success(result);
@@ -11703,12 +11703,11 @@ var LeaferUI = (function (exports) {
11703
11703
  };
11704
11704
  const { toURL } = Platform;
11705
11705
  const { download } = Platform.origin;
11706
- const fileType = FileHelper.fileType(filename);
11707
11706
  if (filename === 'json') {
11708
- return over({ data: leaf.toJSON() });
11707
+ return over({ data: leaf.toJSON(options.json) });
11709
11708
  }
11710
11709
  else if (fileType === 'json') {
11711
- download(toURL(JSON.stringify(leaf.toJSON()), 'text'), filename);
11710
+ download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
11712
11711
  return over({ data: true });
11713
11712
  }
11714
11713
  if (filename === 'svg') {
@@ -11722,7 +11721,6 @@ var LeaferUI = (function (exports) {
11722
11721
  if (leafer) {
11723
11722
  checkLazy(leaf);
11724
11723
  leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
11725
- options = FileHelper.getExportOptions(options);
11726
11724
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
11727
11725
  const { worldTransform, isLeafer, isFrame } = leaf;
11728
11726
  const { slice, trim, onCanvas } = options;
@@ -11993,7 +11991,8 @@ var LeaferUI = (function (exports) {
11993
11991
  }
11994
11992
  }
11995
11993
 
11996
- exports.Leaf.prototype.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
11994
+ const leaf = exports.Leaf.prototype;
11995
+ leaf.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
11997
11996
  const data = this;
11998
11997
  if (noResize || (data.editConfig && data.editConfig.editSize === 'scale')) {
11999
11998
  data.scaleX *= scaleX;
@@ -12007,9 +12006,17 @@ var LeaferUI = (function (exports) {
12007
12006
  this.__scaleResize(scaleX, scaleY);
12008
12007
  }
12009
12008
  };
12010
- exports.Leaf.prototype.__scaleResize = function (scaleX, scaleY) {
12009
+ leaf.__scaleResize = function (scaleX, scaleY) {
12011
12010
  scaleResize(this, scaleX, scaleY);
12012
12011
  };
12012
+ leaf.resizeWidth = function (width) {
12013
+ const scale = width / this.getBounds('box', 'local').width;
12014
+ this.scaleOf(this.__layout.boxBounds, scale, this.__.lockRatio ? scale : 1, true);
12015
+ };
12016
+ leaf.resizeHeight = function (height) {
12017
+ const scale = height / this.getBounds('box', 'local').height;
12018
+ this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
12019
+ };
12013
12020
  exports.Text.prototype.__scaleResize = function (scaleX, scaleY) {
12014
12021
  if (this.__.__autoSize && (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size'))) {
12015
12022
  scaleResizeFontSize(this, scaleX, scaleY);
@@ -12788,8 +12795,11 @@ var LeaferUI = (function (exports) {
12788
12795
  return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
12789
12796
  }
12790
12797
  onSelect(e) {
12791
- if (e.oldList.length === 1)
12792
- e.oldList[0].syncEventer = this.app.interaction.bottomList = null;
12798
+ if (e.oldList.length === 1) {
12799
+ e.oldList[0].syncEventer = null;
12800
+ if (this.app)
12801
+ this.app.interaction.bottomList = null;
12802
+ }
12793
12803
  }
12794
12804
  onDragStart(e) {
12795
12805
  this.dragging = true;
@@ -12895,6 +12905,30 @@ var LeaferUI = (function (exports) {
12895
12905
  }
12896
12906
  }
12897
12907
 
12908
+ class EditMask extends exports.UI {
12909
+ constructor(editor) {
12910
+ super();
12911
+ this.editor = editor;
12912
+ this.hittable = false;
12913
+ }
12914
+ __draw(canvas, options) {
12915
+ const { editor } = this;
12916
+ const { mask } = editor.mergeConfig;
12917
+ if (mask && editor.list.length) {
12918
+ const { rect } = editor.editBox;
12919
+ const { width, height } = rect.__;
12920
+ canvas.resetTransform();
12921
+ canvas.fillWorld(canvas.bounds, mask);
12922
+ canvas.setWorld(rect.__world, options.matrix);
12923
+ canvas.clearRect(0, 0, width, height);
12924
+ }
12925
+ }
12926
+ destroy() {
12927
+ this.editor = null;
12928
+ super.destroy();
12929
+ }
12930
+ }
12931
+
12898
12932
  const filterStyle = `
12899
12933
  <feOffset dy="1"/>
12900
12934
  <feGaussianBlur stdDeviation="1.5"/>
@@ -13133,10 +13167,11 @@ ${filterStyle}
13133
13167
  this.editBox = new EditBox(this);
13134
13168
  this.editToolList = {};
13135
13169
  this.selector = new EditSelect(this);
13170
+ this.editMask = new EditMask(this);
13136
13171
  this.targetEventIds = [];
13137
13172
  if (userConfig)
13138
13173
  this.config = DataHelper.default(userConfig, this.config);
13139
- this.addMany(this.selector, this.editBox);
13174
+ this.addMany(this.editMask, this.selector, this.editBox);
13140
13175
  }
13141
13176
  select(target) {
13142
13177
  this.target = target;