@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.
@@ -1555,7 +1555,7 @@ class LeafData {
1555
1555
  if (this.__input && this.__input[name] !== undefined)
1556
1556
  this.__input[name] = undefined;
1557
1557
  }
1558
- __getInputData(names) {
1558
+ __getInputData(names, options) {
1559
1559
  const data = {};
1560
1560
  if (names) {
1561
1561
  if (names instanceof Array) {
@@ -1582,6 +1582,12 @@ class LeafData {
1582
1582
  }
1583
1583
  }
1584
1584
  }
1585
+ if (options) {
1586
+ if (options.matrix) {
1587
+ const { a, b, c, d, e, f } = this.__leaf.__localMatrix;
1588
+ data.matrix = { a, b, c, d, e, f };
1589
+ }
1590
+ }
1585
1591
  return data;
1586
1592
  }
1587
1593
  __setMiddle(name, value) {
@@ -5200,11 +5206,13 @@ let Leaf = class Leaf {
5200
5206
  setAttr(name, value) { this[name] = value; }
5201
5207
  getAttr(name) { return this[name]; }
5202
5208
  getComputedAttr(name) { return this.__[name]; }
5203
- toJSON() {
5204
- return this.__.__getInputData();
5209
+ toJSON(options) {
5210
+ if (options)
5211
+ this.__layout.update();
5212
+ return this.__.__getInputData(null, options);
5205
5213
  }
5206
- toString() {
5207
- return JSON.stringify(this.toJSON());
5214
+ toString(options) {
5215
+ return JSON.stringify(this.toJSON(options));
5208
5216
  }
5209
5217
  toSVG() { return undefined; }
5210
5218
  __SVG(_data) { }
@@ -5277,14 +5285,6 @@ let Leaf = class Leaf {
5277
5285
  return this.__world;
5278
5286
  }
5279
5287
  }
5280
- getWorld(attrName) {
5281
- this.__layout.update();
5282
- if (attrName === 'x')
5283
- return this.__world.e;
5284
- if (attrName === 'y')
5285
- return this.__world.f;
5286
- return this.getLayoutBounds()[attrName];
5287
- }
5288
5288
  getTransform(relative) {
5289
5289
  return this.__layout.getTransform(relative || 'local');
5290
5290
  }
@@ -5405,14 +5405,8 @@ let Leaf = class Leaf {
5405
5405
  this.scaleY *= scaleY;
5406
5406
  }
5407
5407
  __scaleResize(_scaleX, _scaleY) { }
5408
- resizeWidth(width) {
5409
- const scale = width / this.__localBoxBounds.width;
5410
- this.scaleResize(scale, this.__.lockRatio ? scale : 1);
5411
- }
5412
- resizeHeight(height) {
5413
- const scale = height / this.__localBoxBounds.height;
5414
- this.scaleResize(this.__.lockRatio ? scale : 1, scale);
5415
- }
5408
+ resizeWidth(_width) { }
5409
+ resizeHeight(_height) { }
5416
5410
  __hitWorld(_point) { return true; }
5417
5411
  __hit(_local) { return true; }
5418
5412
  __hitFill(_inner) { return true; }
@@ -5763,7 +5757,7 @@ class LeafLevelList {
5763
5757
  }
5764
5758
  }
5765
5759
 
5766
- const version = "1.0.0-rc.27";
5760
+ const version = "1.0.0-rc.30";
5767
5761
  const inviteCode = {};
5768
5762
 
5769
5763
  class LeaferCanvas extends LeaferCanvasBase {
@@ -7574,9 +7568,9 @@ let Group = class Group extends UI {
7574
7568
  super.set(data);
7575
7569
  }
7576
7570
  }
7577
- toJSON() {
7578
- const data = super.toJSON();
7579
- data.children = this.children.map(child => child.toJSON());
7571
+ toJSON(options) {
7572
+ const data = super.toJSON(options);
7573
+ data.children = this.children.map(child => child.toJSON(options));
7580
7574
  return data;
7581
7575
  }
7582
7576
  pick(_hitPoint, _options) { return undefined; }
@@ -7743,6 +7737,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7743
7737
  __onResize(event) {
7744
7738
  this.emitEvent(event);
7745
7739
  DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
7740
+ if (!event.width || !event.height)
7741
+ debug$4.warn('w = 0 or h = 0');
7746
7742
  setTimeout(() => { if (this.canvasManager)
7747
7743
  this.canvasManager.clearRecycled(); }, 0);
7748
7744
  }
@@ -7766,6 +7762,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7766
7762
  __setAttr(attrName, newValue) {
7767
7763
  if (this.canvas) {
7768
7764
  if (canvasSizeAttrs.includes(attrName)) {
7765
+ if (!newValue)
7766
+ debug$4.warn(attrName + ' is 0');
7769
7767
  this.__changeCanvasSize(attrName, newValue);
7770
7768
  }
7771
7769
  else if (attrName === 'fill') {
@@ -9538,7 +9536,7 @@ function emitAppChildren(leaf, type, data, capture, excludePath) {
9538
9536
  }
9539
9537
  function emitEvent(leaf, type, data, capture, excludePath) {
9540
9538
  if (leaf.destroyed)
9541
- return true;
9539
+ return false;
9542
9540
  if (leaf.__.hitSelf && !exclude(leaf, excludePath)) {
9543
9541
  if (State.updateEventStyle)
9544
9542
  State.updateEventStyle(leaf, type);
@@ -9640,9 +9638,7 @@ class InteractionBase {
9640
9638
  this.tapWait();
9641
9639
  this.longPressWait(data);
9642
9640
  }
9643
- else if (PointerButton.right(data)) {
9644
- this.waitMenuTap = true;
9645
- }
9641
+ this.waitMenuTap = PointerButton.right(data);
9646
9642
  this.dragger.setDragData(data);
9647
9643
  if (!this.isHoldRightKey)
9648
9644
  this.updateCursor(data);
@@ -10060,8 +10056,8 @@ class HitCanvasManager extends CanvasManager {
10060
10056
 
10061
10057
  const { toInnerRadiusPointOf, copy: copy$5, setRadius } = PointHelper;
10062
10058
  const inner = {};
10063
- const leaf = Leaf.prototype;
10064
- leaf.__hitWorld = function (point) {
10059
+ const leaf$1 = Leaf.prototype;
10060
+ leaf$1.__hitWorld = function (point) {
10065
10061
  if (!this.__.hitSelf)
10066
10062
  return false;
10067
10063
  if (this.__.hitRadius) {
@@ -10084,10 +10080,10 @@ leaf.__hitWorld = function (point) {
10084
10080
  }
10085
10081
  return this.__hit(inner);
10086
10082
  };
10087
- leaf.__hitFill = function (inner) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitFill(inner, this.__.windingRule); };
10088
- leaf.__hitStroke = function (inner, strokeWidth) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitStroke(inner, strokeWidth); };
10089
- 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); };
10090
- leaf.__drawHitPath = function (canvas) { if (canvas)
10083
+ leaf$1.__hitFill = function (inner) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitFill(inner, this.__.windingRule); };
10084
+ leaf$1.__hitStroke = function (inner, strokeWidth) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitStroke(inner, strokeWidth); };
10085
+ 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); };
10086
+ leaf$1.__drawHitPath = function (canvas) { if (canvas)
10091
10087
  this.__drawRenderPath(canvas); };
10092
10088
 
10093
10089
  const matrix$2 = new Matrix();
@@ -11534,7 +11530,9 @@ function layoutText(drawData, style) {
11534
11530
  bounds.height = realHeight;
11535
11531
  }
11536
11532
 
11537
- function clipText(drawData, style) {
11533
+ function clipText(drawData, style, x, width) {
11534
+ if (!width)
11535
+ return;
11538
11536
  const { rows, overflow } = drawData;
11539
11537
  let { textOverflow } = style;
11540
11538
  rows.splice(overflow);
@@ -11545,7 +11543,7 @@ function clipText(drawData, style) {
11545
11543
  textOverflow = '...';
11546
11544
  let char, charRight;
11547
11545
  const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
11548
- const right = style.x + style.width - ellipsisWidth;
11546
+ const right = x + width - ellipsisWidth;
11549
11547
  const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
11550
11548
  list.forEach(row => {
11551
11549
  if (row.isOverflow && row.data) {
@@ -11621,7 +11619,7 @@ function getDrawData(content, style) {
11621
11619
  layoutText(drawData, style);
11622
11620
  layoutChar(drawData, style, width);
11623
11621
  if (drawData.overflow)
11624
- clipText(drawData, style);
11622
+ clipText(drawData, style, x, width);
11625
11623
  if (textDecoration !== 'none')
11626
11624
  decorationText(drawData, style);
11627
11625
  return drawData;
@@ -11692,6 +11690,8 @@ function getTrimBounds(canvas) {
11692
11690
  const ExportModule = {
11693
11691
  export(leaf, filename, options) {
11694
11692
  this.running = true;
11693
+ const fileType = FileHelper.fileType(filename);
11694
+ options = FileHelper.getExportOptions(options);
11695
11695
  return addTask((success) => new Promise((resolve) => {
11696
11696
  const over = (result) => {
11697
11697
  success(result);
@@ -11700,12 +11700,11 @@ const ExportModule = {
11700
11700
  };
11701
11701
  const { toURL } = Platform;
11702
11702
  const { download } = Platform.origin;
11703
- const fileType = FileHelper.fileType(filename);
11704
11703
  if (filename === 'json') {
11705
- return over({ data: leaf.toJSON() });
11704
+ return over({ data: leaf.toJSON(options.json) });
11706
11705
  }
11707
11706
  else if (fileType === 'json') {
11708
- download(toURL(JSON.stringify(leaf.toJSON()), 'text'), filename);
11707
+ download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
11709
11708
  return over({ data: true });
11710
11709
  }
11711
11710
  if (filename === 'svg') {
@@ -11719,7 +11718,6 @@ const ExportModule = {
11719
11718
  if (leafer) {
11720
11719
  checkLazy(leaf);
11721
11720
  leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
11722
- options = FileHelper.getExportOptions(options);
11723
11721
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
11724
11722
  const { worldTransform, isLeafer, isFrame } = leaf;
11725
11723
  const { slice, trim, onCanvas } = options;
@@ -11990,7 +11988,8 @@ function scaleResizeGroup(group, scaleX, scaleY) {
11990
11988
  }
11991
11989
  }
11992
11990
 
11993
- Leaf.prototype.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
11991
+ const leaf = Leaf.prototype;
11992
+ leaf.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
11994
11993
  const data = this;
11995
11994
  if (noResize || (data.editConfig && data.editConfig.editSize === 'scale')) {
11996
11995
  data.scaleX *= scaleX;
@@ -12004,9 +12003,17 @@ Leaf.prototype.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
12004
12003
  this.__scaleResize(scaleX, scaleY);
12005
12004
  }
12006
12005
  };
12007
- Leaf.prototype.__scaleResize = function (scaleX, scaleY) {
12006
+ leaf.__scaleResize = function (scaleX, scaleY) {
12008
12007
  scaleResize(this, scaleX, scaleY);
12009
12008
  };
12009
+ leaf.resizeWidth = function (width) {
12010
+ const scale = width / this.getBounds('box', 'local').width;
12011
+ this.scaleOf(this.__layout.boxBounds, scale, this.__.lockRatio ? scale : 1, true);
12012
+ };
12013
+ leaf.resizeHeight = function (height) {
12014
+ const scale = height / this.getBounds('box', 'local').height;
12015
+ this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
12016
+ };
12010
12017
  Text.prototype.__scaleResize = function (scaleX, scaleY) {
12011
12018
  if (this.__.__autoSize && (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size'))) {
12012
12019
  scaleResizeFontSize(this, scaleX, scaleY);
@@ -12785,8 +12792,11 @@ class EditBox extends Group {
12785
12792
  return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
12786
12793
  }
12787
12794
  onSelect(e) {
12788
- if (e.oldList.length === 1)
12789
- e.oldList[0].syncEventer = this.app.interaction.bottomList = null;
12795
+ if (e.oldList.length === 1) {
12796
+ e.oldList[0].syncEventer = null;
12797
+ if (this.app)
12798
+ this.app.interaction.bottomList = null;
12799
+ }
12790
12800
  }
12791
12801
  onDragStart(e) {
12792
12802
  this.dragging = true;
@@ -12892,6 +12902,30 @@ class EditBox extends Group {
12892
12902
  }
12893
12903
  }
12894
12904
 
12905
+ class EditMask extends UI {
12906
+ constructor(editor) {
12907
+ super();
12908
+ this.editor = editor;
12909
+ this.hittable = false;
12910
+ }
12911
+ __draw(canvas, options) {
12912
+ const { editor } = this;
12913
+ const { mask } = editor.mergeConfig;
12914
+ if (mask && editor.list.length) {
12915
+ const { rect } = editor.editBox;
12916
+ const { width, height } = rect.__;
12917
+ canvas.resetTransform();
12918
+ canvas.fillWorld(canvas.bounds, mask);
12919
+ canvas.setWorld(rect.__world, options.matrix);
12920
+ canvas.clearRect(0, 0, width, height);
12921
+ }
12922
+ }
12923
+ destroy() {
12924
+ this.editor = null;
12925
+ super.destroy();
12926
+ }
12927
+ }
12928
+
12895
12929
  const filterStyle = `
12896
12930
  <feOffset dy="1"/>
12897
12931
  <feGaussianBlur stdDeviation="1.5"/>
@@ -13130,10 +13164,11 @@ class Editor extends Group {
13130
13164
  this.editBox = new EditBox(this);
13131
13165
  this.editToolList = {};
13132
13166
  this.selector = new EditSelect(this);
13167
+ this.editMask = new EditMask(this);
13133
13168
  this.targetEventIds = [];
13134
13169
  if (userConfig)
13135
13170
  this.config = DataHelper.default(userConfig, this.config);
13136
- this.addMany(this.selector, this.editBox);
13171
+ this.addMany(this.editMask, this.selector, this.editBox);
13137
13172
  }
13138
13173
  select(target) {
13139
13174
  this.target = target;