@leafer-editor/worker 1.2.2 → 1.3.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
@@ -1405,21 +1405,24 @@ var LeaferUI = (function (exports) {
1405
1405
  };
1406
1406
  const R = Run;
1407
1407
 
1408
+ const check = [];
1408
1409
  const Plugin = {
1409
1410
  list: {},
1410
- add(name) {
1411
+ add(name, ...needPlugins) {
1411
1412
  this.list[name] = true;
1413
+ check.push(...needPlugins);
1412
1414
  },
1413
- check(name, tip) {
1415
+ has(name, tip) {
1414
1416
  const rs = this.list[name];
1415
1417
  if (!rs && tip)
1416
1418
  this.need(name);
1417
1419
  return rs;
1418
1420
  },
1419
1421
  need(name) {
1420
- console.error('need plugin: @leafer-in/' + name);
1422
+ console.error('need plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name);
1421
1423
  }
1422
1424
  };
1425
+ setTimeout(() => check.forEach(name => Plugin.has(name, true)));
1423
1426
 
1424
1427
  const debug$g = Debug.get('UICreator');
1425
1428
  const UICreator = {
@@ -4811,7 +4814,6 @@ var LeaferUI = (function (exports) {
4811
4814
  }
4812
4815
  }
4813
4816
  }
4814
- LayoutEvent.CHECK_UPDATE = 'layout.check_update';
4815
4817
  LayoutEvent.REQUEST = 'layout.request';
4816
4818
  LayoutEvent.START = 'layout.start';
4817
4819
  LayoutEvent.BEFORE = 'layout.before';
@@ -6008,7 +6010,7 @@ var LeaferUI = (function (exports) {
6008
6010
  }
6009
6011
  }
6010
6012
 
6011
- const version = "1.2.2";
6013
+ const version = "1.3.0";
6012
6014
 
6013
6015
  class LeaferCanvas extends LeaferCanvasBase {
6014
6016
  get allowBackgroundColor() { return true; }
@@ -6076,6 +6078,7 @@ var LeaferUI = (function (exports) {
6076
6078
  }
6077
6079
  Platform.name = 'web';
6078
6080
  Platform.isWorker = true;
6081
+ Platform.backgrounder = true;
6079
6082
  Platform.requestRender = function (render) { requestAnimationFrame(render); };
6080
6083
  defineKey(Platform, 'devicePixelRatio', { get() { return 1; } });
6081
6084
  const { userAgent } = navigator;
@@ -6808,143 +6811,26 @@ var LeaferUI = (function (exports) {
6808
6811
  }
6809
6812
  }
6810
6813
 
6811
- const { Yes: Yes$1, NoAndSkip: NoAndSkip$1, YesAndSkip: YesAndSkip$1 } = exports.Answer;
6812
- const idCondition = {}, classNameCondition = {}, tagCondition = {};
6813
6814
  class Selector {
6814
6815
  constructor(target, userConfig) {
6815
6816
  this.config = {};
6816
- this.innerIdMap = {};
6817
- this.idMap = {};
6818
- this.methods = {
6819
- id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,
6820
- innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,
6821
- className: (leaf, name) => leaf.className === name ? 1 : 0,
6822
- tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
6823
- tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
6824
- };
6825
- this.target = target;
6826
6817
  if (userConfig)
6827
6818
  this.config = DataHelper.default(userConfig, this.config);
6828
- this.picker = new Picker(target, this);
6829
- if (target)
6830
- this.__listenEvents();
6831
- }
6832
- getBy(condition, branch, one, options) {
6833
- switch (typeof condition) {
6834
- case 'number':
6835
- const leaf = this.getByInnerId(condition, branch);
6836
- return one ? leaf : (leaf ? [leaf] : []);
6837
- case 'string':
6838
- switch (condition[0]) {
6839
- case '#':
6840
- idCondition.id = condition.substring(1), condition = idCondition;
6841
- break;
6842
- case '.':
6843
- classNameCondition.className = condition.substring(1), condition = classNameCondition;
6844
- break;
6845
- default:
6846
- tagCondition.tag = condition, condition = tagCondition;
6847
- }
6848
- case 'object':
6849
- if (condition.id !== undefined) {
6850
- const leaf = this.getById(condition.id, branch);
6851
- return one ? leaf : (leaf ? [leaf] : []);
6852
- }
6853
- else if (condition.tag) {
6854
- const { tag } = condition, isArray = tag instanceof Array;
6855
- return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag);
6856
- }
6857
- else {
6858
- return this.getByMethod(this.methods.className, branch, one, condition.className);
6859
- }
6860
- case 'function':
6861
- return this.getByMethod(condition, branch, one, options);
6862
- }
6819
+ this.picker = new Picker(this.target = target, this);
6820
+ this.finder = Creator.finder && Creator.finder();
6863
6821
  }
6864
6822
  getByPoint(hitPoint, hitRadius, options) {
6865
- if (Platform.name === 'node' && this.target)
6866
- this.target.emit(LayoutEvent.CHECK_UPDATE);
6823
+ if (Platform.backgrounder && this.target)
6824
+ this.target.updateLayout();
6867
6825
  return this.picker.getByPoint(hitPoint, hitRadius, options);
6868
6826
  }
6869
- getByInnerId(innerId, branch) {
6870
- const cache = this.innerIdMap[innerId];
6871
- if (cache)
6872
- return cache;
6873
- this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
6874
- return this.findLeaf;
6875
- }
6876
- getById(id, branch) {
6877
- const cache = this.idMap[id];
6878
- if (cache && LeafHelper.hasParent(cache, branch || this.target))
6879
- return cache;
6880
- this.eachFind(this.toChildren(branch), this.methods.id, null, id);
6881
- return this.findLeaf;
6882
- }
6883
- getByClassName(className, branch) {
6884
- return this.getByMethod(this.methods.className, branch, false, className);
6885
- }
6886
- getByTag(tag, branch) {
6887
- return this.getByMethod(this.methods.tag, branch, false, tag);
6888
- }
6889
- getByMethod(method, branch, one, options) {
6890
- const list = one ? null : [];
6891
- this.eachFind(this.toChildren(branch), method, list, options);
6892
- return list || this.findLeaf;
6893
- }
6894
- eachFind(children, method, list, options) {
6895
- let child, result;
6896
- for (let i = 0, len = children.length; i < len; i++) {
6897
- child = children[i];
6898
- result = method(child, options);
6899
- if (result === Yes$1 || result === YesAndSkip$1) {
6900
- if (list) {
6901
- list.push(child);
6902
- }
6903
- else {
6904
- this.findLeaf = child;
6905
- return;
6906
- }
6907
- }
6908
- if (child.isBranch && result < NoAndSkip$1)
6909
- this.eachFind(child.children, method, list, options);
6910
- }
6911
- }
6912
- toChildren(branch) {
6913
- this.findLeaf = null;
6914
- return [branch || this.target];
6915
- }
6916
- __onRemoveChild(event) {
6917
- const { id, innerId } = event.child;
6918
- if (this.idMap[id])
6919
- delete this.idMap[id];
6920
- if (this.innerIdMap[innerId])
6921
- delete this.innerIdMap[innerId];
6922
- }
6923
- __checkIdChange(event) {
6924
- if (event.attrName === 'id') {
6925
- const id = event.oldValue;
6926
- if (this.idMap[id])
6927
- delete this.idMap[id];
6928
- }
6929
- }
6930
- __listenEvents() {
6931
- this.__eventIds = [
6932
- this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),
6933
- this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)
6934
- ];
6935
- }
6936
- __removeListenEvents() {
6937
- this.target.off_(this.__eventIds);
6938
- this.__eventIds.length = 0;
6827
+ getBy(condition, branch, one, options) {
6828
+ return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need('find');
6939
6829
  }
6940
6830
  destroy() {
6941
- if (this.__eventIds.length) {
6942
- this.__removeListenEvents();
6943
- this.picker.destroy();
6944
- this.findLeaf = null;
6945
- this.innerIdMap = {};
6946
- this.idMap = {};
6947
- }
6831
+ this.picker.destroy();
6832
+ if (this.finder)
6833
+ this.finder.destroy();
6948
6834
  }
6949
6835
  }
6950
6836
 
@@ -7440,25 +7326,27 @@ var LeaferUI = (function (exports) {
7440
7326
  }
7441
7327
  reset(_data) { }
7442
7328
  set(data, transition) {
7443
- if (transition) {
7444
- if (transition === 'temp') {
7445
- this.lockNormalStyle = true;
7446
- Object.assign(this, data);
7447
- this.lockNormalStyle = false;
7329
+ if (data) {
7330
+ if (transition) {
7331
+ if (transition === 'temp') {
7332
+ this.lockNormalStyle = true;
7333
+ Object.assign(this, data);
7334
+ this.lockNormalStyle = false;
7335
+ }
7336
+ else
7337
+ this.animate(data, transition);
7448
7338
  }
7449
7339
  else
7450
- this.animate(data, transition);
7340
+ Object.assign(this, data);
7451
7341
  }
7452
- else
7453
- Object.assign(this, data);
7454
7342
  }
7455
7343
  get(name) {
7456
7344
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
7457
7345
  }
7458
7346
  createProxyData() { return undefined; }
7459
- find(_condition, _options) { return undefined; }
7347
+ find(_condition, _options) { return Plugin.need('find'); }
7460
7348
  findTag(tag) { return this.find({ tag }); }
7461
- findOne(_condition, _options) { return undefined; }
7349
+ findOne(_condition, _options) { return Plugin.need('find'); }
7462
7350
  findId(id) { return this.findOne({ id }); }
7463
7351
  getPath(curve, pathForRender) {
7464
7352
  this.__layout.update();
@@ -7510,9 +7398,9 @@ var LeaferUI = (function (exports) {
7510
7398
  animate(_keyframe, _options, _type, _isTemp) {
7511
7399
  return Plugin.need('animate');
7512
7400
  }
7513
- killAnimate(_type) { }
7514
- export(filename, options) {
7515
- return Export.export(this, filename, options);
7401
+ killAnimate(_type, _killStyle) { }
7402
+ export(_filename, _options) {
7403
+ return Plugin.need('export');
7516
7404
  }
7517
7405
  clone(data) {
7518
7406
  const json = this.toJSON();
@@ -7758,16 +7646,18 @@ var LeaferUI = (function (exports) {
7758
7646
  this.children = [];
7759
7647
  }
7760
7648
  set(data, transition) {
7761
- if (data.children) {
7762
- const { children } = data;
7763
- delete data.children;
7764
- this.children ? this.clear() : this.__setBranch();
7765
- super.set(data, transition);
7766
- children.forEach(child => this.add(child));
7767
- data.children = children;
7649
+ if (data) {
7650
+ if (data.children) {
7651
+ const { children } = data;
7652
+ delete data.children;
7653
+ this.children ? this.clear() : this.__setBranch();
7654
+ super.set(data, transition);
7655
+ children.forEach(child => this.add(child));
7656
+ data.children = children;
7657
+ }
7658
+ else
7659
+ super.set(data, transition);
7768
7660
  }
7769
- else
7770
- super.set(data, transition);
7771
7661
  }
7772
7662
  toJSON(options) {
7773
7663
  const data = super.toJSON(options);
@@ -8105,9 +7995,6 @@ var LeaferUI = (function (exports) {
8105
7995
  this.canvas && this.canvas.updateClientBounds();
8106
7996
  }
8107
7997
  receiveEvent(_event) { }
8108
- __checkUpdateLayout() {
8109
- this.__layout.update();
8110
- }
8111
7998
  emitLeafer(type) {
8112
7999
  this.emitEvent(new LeaferEvent(type, this));
8113
8000
  }
@@ -8118,7 +8005,7 @@ var LeaferUI = (function (exports) {
8118
8005
  this.once(LayoutEvent.END, () => this.__onReady());
8119
8006
  this.once(RenderEvent.START, () => this.__onCreated());
8120
8007
  this.once(RenderEvent.END, () => this.__onViewReady());
8121
- this.__eventIds.push(this.on_(WatchEvent.DATA, this.__onWatchData, this), this.on_(RenderEvent.NEXT, this.__onNextRender, this), this.on_(LayoutEvent.CHECK_UPDATE, this.__checkUpdateLayout, this));
8008
+ this.__eventIds.push(this.on_(WatchEvent.DATA, this.__onWatchData, this), this.on_(RenderEvent.NEXT, this.__onNextRender, this));
8122
8009
  }
8123
8010
  __removeListenEvents() {
8124
8011
  this.off_(this.__eventIds);
@@ -8183,7 +8070,7 @@ var LeaferUI = (function (exports) {
8183
8070
  ], exports.Rect);
8184
8071
 
8185
8072
  const { copy: copy$6, add, includes: includes$1 } = BoundsHelper;
8186
- const rect$1 = exports.Rect.prototype, group$1 = exports.Group.prototype;
8073
+ const rect$1 = exports.Rect.prototype, group = exports.Group.prototype;
8187
8074
  const childrenRenderBounds = {};
8188
8075
  exports.Box = class Box extends exports.Group {
8189
8076
  get __tag() { return 'Box'; }
@@ -8293,7 +8180,7 @@ var LeaferUI = (function (exports) {
8293
8180
  rewrite(rect$1.__render)
8294
8181
  ], exports.Box.prototype, "__renderRect", null);
8295
8182
  __decorate([
8296
- rewrite(group$1.__render)
8183
+ rewrite(group.__render)
8297
8184
  ], exports.Box.prototype, "__renderGroup", null);
8298
8185
  exports.Box = __decorate([
8299
8186
  rewriteAble(),
@@ -8774,6 +8661,9 @@ var LeaferUI = (function (exports) {
8774
8661
  __decorate([
8775
8662
  boundsType(0)
8776
8663
  ], exports.Text.prototype, "paraSpacing", void 0);
8664
+ __decorate([
8665
+ boundsType('x')
8666
+ ], exports.Text.prototype, "writingMode", void 0);
8777
8667
  __decorate([
8778
8668
  boundsType('left')
8779
8669
  ], exports.Text.prototype, "textAlign", void 0);
@@ -8960,8 +8850,8 @@ var LeaferUI = (function (exports) {
8960
8850
  this.children.forEach(leafer => leafer.resize(event));
8961
8851
  super.__onResize(event);
8962
8852
  }
8963
- __checkUpdateLayout() {
8964
- this.children.forEach(leafer => leafer.__layout.update());
8853
+ updateLayout() {
8854
+ this.children.forEach(leafer => leafer.updateLayout());
8965
8855
  }
8966
8856
  __getChildConfig(userConfig) {
8967
8857
  let config = Object.assign({}, this.config);
@@ -10038,8 +9928,8 @@ var LeaferUI = (function (exports) {
10038
9928
  this.__drawRenderPath(canvas); };
10039
9929
 
10040
9930
  const matrix$2 = new Matrix();
10041
- const ui$3 = exports.UI.prototype;
10042
- ui$3.__updateHitCanvas = function () {
9931
+ const ui$2 = exports.UI.prototype;
9932
+ ui$2.__updateHitCanvas = function () {
10043
9933
  const data = this.__, { hitCanvasManager } = this.leafer;
10044
9934
  const isHitPixelFill = (data.__pixelFill || data.__isCanvas) && data.hitFill === 'pixel';
10045
9935
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
@@ -10066,7 +9956,7 @@ var LeaferUI = (function (exports) {
10066
9956
  this.__drawHitPath(h);
10067
9957
  h.setStrokeOptions(data);
10068
9958
  };
10069
- ui$3.__hit = function (inner) {
9959
+ ui$2.__hit = function (inner) {
10070
9960
  if (Platform.name === 'miniapp')
10071
9961
  this.__drawHitPath(this.__hitCanvas);
10072
9962
  const data = this.__;
@@ -10106,31 +9996,23 @@ var LeaferUI = (function (exports) {
10106
9996
  return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
10107
9997
  };
10108
9998
 
10109
- const ui$2 = exports.UI.prototype, rect = exports.Rect.prototype, box$1 = exports.Box.prototype;
9999
+ const ui$1 = exports.UI.prototype, rect = exports.Rect.prototype, box$1 = exports.Box.prototype;
10110
10000
  rect.__updateHitCanvas = box$1.__updateHitCanvas = function () {
10111
10001
  if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
10112
- ui$2.__updateHitCanvas.call(this);
10002
+ ui$1.__updateHitCanvas.call(this);
10113
10003
  else if (this.__hitCanvas)
10114
10004
  this.__hitCanvas = null;
10115
10005
  };
10116
10006
  rect.__hitFill = box$1.__hitFill = function (inner) {
10117
- return this.__hitCanvas ? ui$2.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
10007
+ return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
10118
10008
  };
10119
10009
 
10120
- const ui$1 = exports.UI.prototype, group = exports.Group.prototype;
10121
10010
  function getSelector(ui) {
10122
10011
  return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()));
10123
10012
  }
10124
- ui$1.find = function (condition, options) {
10125
- return getSelector(this).getBy(condition, this, false, options);
10126
- };
10127
- ui$1.findOne = function (condition, options) {
10128
- return getSelector(this).getBy(condition, this, true, options);
10129
- };
10130
- group.pick = function (hitPoint, options) {
10131
- this.__layout.update();
10132
- if (!options)
10133
- options = {};
10013
+ exports.Group.prototype.pick = function (hitPoint, options) {
10014
+ this.leafer || this.updateLayout();
10015
+ options || (options = emptyData);
10134
10016
  return getSelector(this).getByPoint(hitPoint, options.hitRadius || 0, Object.assign(Object.assign({}, options), { target: this }));
10135
10017
  };
10136
10018
 
@@ -11634,197 +11516,12 @@ var LeaferUI = (function (exports) {
11634
11516
  string
11635
11517
  };
11636
11518
 
11637
- const { setPoint: setPoint$2, addPoint, toBounds } = TwoPointBoundsHelper;
11638
- function getTrimBounds(canvas) {
11639
- const { width, height } = canvas.view;
11640
- const { data } = canvas.context.getImageData(0, 0, width, height);
11641
- let x, y, pointBounds, index = 0;
11642
- for (let i = 0; i < data.length; i += 4) {
11643
- if (data[i + 3] !== 0) {
11644
- x = index % width;
11645
- y = (index - x) / width;
11646
- pointBounds ? addPoint(pointBounds, x, y) : setPoint$2(pointBounds = {}, x, y);
11647
- }
11648
- index++;
11649
- }
11650
- const bounds = new Bounds();
11651
- toBounds(pointBounds, bounds);
11652
- return bounds.scale(1 / canvas.pixelRatio).ceil();
11653
- }
11654
-
11655
- const ExportModule = {
11656
- export(leaf, filename, options) {
11657
- this.running = true;
11658
- const fileType = FileHelper.fileType(filename);
11659
- const isDownload = filename.includes('.');
11660
- options = FileHelper.getExportOptions(options);
11661
- return addTask((success) => new Promise((resolve) => {
11662
- const over = (result) => {
11663
- success(result);
11664
- resolve();
11665
- this.running = false;
11666
- };
11667
- const { toURL } = Platform;
11668
- const { download } = Platform.origin;
11669
- if (fileType === 'json') {
11670
- isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
11671
- return over({ data: isDownload ? true : leaf.toJSON(options.json) });
11672
- }
11673
- if (fileType === 'svg') {
11674
- isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
11675
- return over({ data: isDownload ? true : leaf.toSVG() });
11676
- }
11677
- const { leafer } = leaf;
11678
- if (leafer) {
11679
- checkLazy(leaf);
11680
- leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
11681
- let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
11682
- const { worldTransform, isLeafer, isFrame } = leaf;
11683
- const { slice, trim, onCanvas } = options;
11684
- const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
11685
- const contextSettings = options.contextSettings || leafer.config.contextSettings;
11686
- const screenshot = options.screenshot || leaf.isApp;
11687
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
11688
- const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
11689
- if (screenshot) {
11690
- renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
11691
- }
11692
- else {
11693
- let relative = options.relative || (isLeafer ? 'inner' : 'local');
11694
- scaleX = worldTransform.scaleX;
11695
- scaleY = worldTransform.scaleY;
11696
- switch (relative) {
11697
- case 'inner':
11698
- matrix.set(worldTransform);
11699
- break;
11700
- case 'local':
11701
- matrix.set(worldTransform).divide(leaf.localTransform);
11702
- scaleX /= leaf.scaleX;
11703
- scaleY /= leaf.scaleY;
11704
- break;
11705
- case 'world':
11706
- scaleX = 1;
11707
- scaleY = 1;
11708
- break;
11709
- case 'page':
11710
- relative = leaf.leafer;
11711
- default:
11712
- matrix.set(worldTransform).divide(leaf.getTransform(relative));
11713
- const l = relative.worldTransform;
11714
- scaleX /= scaleX / l.scaleX;
11715
- scaleY /= scaleY / l.scaleY;
11716
- }
11717
- renderBounds = leaf.getBounds('render', relative);
11718
- }
11719
- const scaleData = { scaleX: 1, scaleY: 1 };
11720
- MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
11721
- let pixelRatio = options.pixelRatio || 1;
11722
- if (leaf.isApp) {
11723
- scaleData.scaleX *= pixelRatio;
11724
- scaleData.scaleY *= pixelRatio;
11725
- pixelRatio = leaf.app.pixelRatio;
11726
- }
11727
- const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
11728
- const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
11729
- let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
11730
- let sliceLeaf;
11731
- if (slice) {
11732
- sliceLeaf = leaf;
11733
- sliceLeaf.__worldOpacity = 0;
11734
- leaf = leafer;
11735
- renderOptions.bounds = canvas.bounds;
11736
- }
11737
- canvas.save();
11738
- if (isFrame && fill !== undefined) {
11739
- const oldFill = leaf.get('fill');
11740
- leaf.fill = '';
11741
- leaf.__render(canvas, renderOptions);
11742
- leaf.fill = oldFill;
11743
- }
11744
- else {
11745
- leaf.__render(canvas, renderOptions);
11746
- }
11747
- canvas.restore();
11748
- if (sliceLeaf)
11749
- sliceLeaf.__updateWorldOpacity();
11750
- if (trim) {
11751
- trimBounds = getTrimBounds(canvas);
11752
- const old = canvas, { width, height } = trimBounds;
11753
- const config = { x: 0, y: 0, width, height, pixelRatio };
11754
- canvas = Creator.canvas(config);
11755
- canvas.copyWorld(old, trimBounds, config);
11756
- }
11757
- if (needFill)
11758
- canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
11759
- if (onCanvas)
11760
- onCanvas(canvas);
11761
- const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
11762
- over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
11763
- }));
11764
- }
11765
- else {
11766
- over({ data: false });
11767
- }
11768
- }));
11769
- }
11770
- };
11771
- let tasker;
11772
- function addTask(task) {
11773
- if (!tasker)
11774
- tasker = new TaskProcessor();
11775
- return new Promise((resolve) => {
11776
- tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
11777
- });
11778
- }
11779
- function checkLazy(leaf) {
11780
- if (leaf.__.__needComputePaint)
11781
- leaf.__.__computePaint();
11782
- if (leaf.isBranch)
11783
- leaf.children.forEach(child => checkLazy(child));
11784
- }
11785
-
11786
- const canvas = LeaferCanvasBase.prototype;
11787
- const debug$2 = Debug.get('@leafer-ui/export');
11788
- canvas.export = function (filename, options) {
11789
- const { quality, blob } = FileHelper.getExportOptions(options);
11790
- if (filename.includes('.'))
11791
- return this.saveAs(filename, quality);
11792
- else if (blob)
11793
- return this.toBlob(filename, quality);
11794
- else
11795
- return this.toDataURL(filename, quality);
11796
- };
11797
- canvas.toBlob = function (type, quality) {
11798
- return new Promise((resolve) => {
11799
- Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
11800
- resolve(blob);
11801
- }).catch((e) => {
11802
- debug$2.error(e);
11803
- resolve(null);
11804
- });
11805
- });
11806
- };
11807
- canvas.toDataURL = function (type, quality) {
11808
- return Platform.origin.canvasToDataURL(this.view, type, quality);
11809
- };
11810
- canvas.saveAs = function (filename, quality) {
11811
- return new Promise((resolve) => {
11812
- Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
11813
- resolve(true);
11814
- }).catch((e) => {
11815
- debug$2.error(e);
11816
- resolve(false);
11817
- });
11818
- });
11819
- };
11820
-
11821
11519
  Object.assign(TextConvert, TextConvertModule);
11822
11520
  Object.assign(ColorConvert, ColorConvertModule);
11823
11521
  Object.assign(Paint, PaintModule);
11824
11522
  Object.assign(PaintImage, PaintImageModule);
11825
11523
  Object.assign(PaintGradient, PaintGradientModule);
11826
11524
  Object.assign(Effect, EffectModule);
11827
- Object.assign(Export, ExportModule);
11828
11525
 
11829
11526
  Object.assign(Creator, {
11830
11527
  interaction: (target, canvas, selector, options) => new InteractionBase(target, canvas, selector, options),
@@ -12969,7 +12666,7 @@ ${filterStyle}
12969
12666
  }
12970
12667
  };
12971
12668
 
12972
- const debug$1 = Debug.get('EditToolCreator');
12669
+ const debug$2 = Debug.get('EditToolCreator');
12973
12670
  function registerEditTool() {
12974
12671
  return (target) => {
12975
12672
  EditToolCreator.register(target);
@@ -12980,7 +12677,7 @@ ${filterStyle}
12980
12677
  list: {},
12981
12678
  register(EditTool) {
12982
12679
  const { tag } = EditTool.prototype;
12983
- list$1[tag] && debug$1.repeat(tag);
12680
+ list$1[tag] && debug$2.repeat(tag);
12984
12681
  list$1[tag] = EditTool;
12985
12682
  },
12986
12683
  get(tag, editor) {
@@ -13097,7 +12794,7 @@ ${filterStyle}
13097
12794
  if (userConfig)
13098
12795
  this.config = DataHelper.default(userConfig, this.config);
13099
12796
  this.addMany(this.editMask, this.selector, this.editBox);
13100
- if (!Plugin.check('resize', true))
12797
+ if (!Plugin.has('resize'))
13101
12798
  this.config.editSize = 'scale';
13102
12799
  }
13103
12800
  select(target) {
@@ -13890,7 +13587,7 @@ ${filterStyle}
13890
13587
 
13891
13588
  Plugin.add('resize');
13892
13589
 
13893
- Plugin.add('editor');
13590
+ Plugin.add('editor', 'resize');
13894
13591
  Creator.editor = function (options) { return new Editor(options); };
13895
13592
  dataType(false)(exports.Box.prototype, 'textBox');
13896
13593
  defineKey(exports.UI.prototype, 'editOuter', {
@@ -13971,11 +13668,11 @@ ${filterStyle}
13971
13668
  });
13972
13669
  }
13973
13670
 
13974
- const debug = Debug.get('LeaferTypeCreator');
13671
+ const debug$1 = Debug.get('LeaferTypeCreator');
13975
13672
  const LeaferTypeCreator = {
13976
13673
  list: {},
13977
13674
  register(name, fn) {
13978
- list[name] && debug.repeat(name);
13675
+ list[name] && debug$1.repeat(name);
13979
13676
  list[name] = fn;
13980
13677
  },
13981
13678
  run(name, leafer) {
@@ -14500,17 +14197,17 @@ ${filterStyle}
14500
14197
  switch (command) {
14501
14198
  case M$1:
14502
14199
  case L$1:
14503
- setPoint$1(data, i + 1, x, y, scaleX, scaleY, rotation, origin);
14200
+ setPoint$2(data, i + 1, x, y, scaleX, scaleY, rotation, origin);
14504
14201
  i += 3;
14505
14202
  break;
14506
14203
  case C$1:
14507
14204
  for (j = 1; j < 6; j += 2)
14508
- setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14205
+ setPoint$2(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14509
14206
  i += 7;
14510
14207
  break;
14511
14208
  case Q$1:
14512
14209
  for (j = 1; j < 4; j += 2)
14513
- setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14210
+ setPoint$2(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14514
14211
  i += 5;
14515
14212
  break;
14516
14213
  case O$1:
@@ -14531,7 +14228,7 @@ ${filterStyle}
14531
14228
  PathMatrixHelper.layout(data, 0, 0, 1, 1, rotation, center);
14532
14229
  }
14533
14230
  };
14534
- function setPoint$1(data, startIndex, x, y, scaleX, scaleY, rotation, origin) {
14231
+ function setPoint$2(data, startIndex, x, y, scaleX, scaleY, rotation, origin) {
14535
14232
  copyFrom$1(point, data[startIndex], data[startIndex + 1]);
14536
14233
  if (rotation)
14537
14234
  rotate$1(point, rotation, origin);
@@ -14697,7 +14394,7 @@ ${filterStyle}
14697
14394
  break;
14698
14395
  }
14699
14396
  if (index)
14700
- setPoint(path, last, index);
14397
+ setPoint$1(path, last, index);
14701
14398
  }
14702
14399
  }
14703
14400
  }
@@ -14711,7 +14408,7 @@ ${filterStyle}
14711
14408
  copyFrom(from, data[startIndex], data[startIndex + 1]);
14712
14409
  copyFrom(to, data[startIndex + 2], data[startIndex + 3]);
14713
14410
  }
14714
- function setPoint(data, point, startIndex) {
14411
+ function setPoint$1(data, point, startIndex) {
14715
14412
  data[startIndex] = point.x;
14716
14413
  data[startIndex + 1] = point.y;
14717
14414
  }
@@ -14734,6 +14431,195 @@ ${filterStyle}
14734
14431
  arrowType('none')(ui, 'endArrow');
14735
14432
  Object.assign(PathArrow, PathArrowModule);
14736
14433
 
14434
+ const { setPoint, addPoint, toBounds } = TwoPointBoundsHelper;
14435
+ function getTrimBounds(canvas) {
14436
+ const { width, height } = canvas.view;
14437
+ const { data } = canvas.context.getImageData(0, 0, width, height);
14438
+ let x, y, pointBounds, index = 0;
14439
+ for (let i = 0; i < data.length; i += 4) {
14440
+ if (data[i + 3] !== 0) {
14441
+ x = index % width;
14442
+ y = (index - x) / width;
14443
+ pointBounds ? addPoint(pointBounds, x, y) : setPoint(pointBounds = {}, x, y);
14444
+ }
14445
+ index++;
14446
+ }
14447
+ const bounds = new Bounds();
14448
+ toBounds(pointBounds, bounds);
14449
+ return bounds.scale(1 / canvas.pixelRatio).ceil();
14450
+ }
14451
+
14452
+ const ExportModule = {
14453
+ export(leaf, filename, options) {
14454
+ this.running = true;
14455
+ const fileType = FileHelper.fileType(filename);
14456
+ const isDownload = filename.includes('.');
14457
+ options = FileHelper.getExportOptions(options);
14458
+ return addTask((success) => new Promise((resolve) => {
14459
+ const over = (result) => {
14460
+ success(result);
14461
+ resolve();
14462
+ this.running = false;
14463
+ };
14464
+ const { toURL } = Platform;
14465
+ const { download } = Platform.origin;
14466
+ if (fileType === 'json') {
14467
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
14468
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
14469
+ }
14470
+ if (fileType === 'svg') {
14471
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
14472
+ return over({ data: isDownload ? true : leaf.toSVG() });
14473
+ }
14474
+ const { leafer } = leaf;
14475
+ if (leafer) {
14476
+ checkLazy(leaf);
14477
+ leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
14478
+ let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
14479
+ const { worldTransform, isLeafer, isFrame } = leaf;
14480
+ const { slice, trim, onCanvas } = options;
14481
+ const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
14482
+ const contextSettings = options.contextSettings || leafer.config.contextSettings;
14483
+ const screenshot = options.screenshot || leaf.isApp;
14484
+ const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
14485
+ const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
14486
+ if (screenshot) {
14487
+ renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
14488
+ }
14489
+ else {
14490
+ let relative = options.relative || (isLeafer ? 'inner' : 'local');
14491
+ scaleX = worldTransform.scaleX;
14492
+ scaleY = worldTransform.scaleY;
14493
+ switch (relative) {
14494
+ case 'inner':
14495
+ matrix.set(worldTransform);
14496
+ break;
14497
+ case 'local':
14498
+ matrix.set(worldTransform).divide(leaf.localTransform);
14499
+ scaleX /= leaf.scaleX;
14500
+ scaleY /= leaf.scaleY;
14501
+ break;
14502
+ case 'world':
14503
+ scaleX = 1;
14504
+ scaleY = 1;
14505
+ break;
14506
+ case 'page':
14507
+ relative = leaf.leafer;
14508
+ default:
14509
+ matrix.set(worldTransform).divide(leaf.getTransform(relative));
14510
+ const l = relative.worldTransform;
14511
+ scaleX /= scaleX / l.scaleX;
14512
+ scaleY /= scaleY / l.scaleY;
14513
+ }
14514
+ renderBounds = leaf.getBounds('render', relative);
14515
+ }
14516
+ const scaleData = { scaleX: 1, scaleY: 1 };
14517
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
14518
+ let pixelRatio = options.pixelRatio || 1;
14519
+ if (leaf.isApp) {
14520
+ scaleData.scaleX *= pixelRatio;
14521
+ scaleData.scaleY *= pixelRatio;
14522
+ pixelRatio = leaf.app.pixelRatio;
14523
+ }
14524
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
14525
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
14526
+ let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
14527
+ let sliceLeaf;
14528
+ if (slice) {
14529
+ sliceLeaf = leaf;
14530
+ sliceLeaf.__worldOpacity = 0;
14531
+ leaf = leafer;
14532
+ renderOptions.bounds = canvas.bounds;
14533
+ }
14534
+ canvas.save();
14535
+ if (isFrame && fill !== undefined) {
14536
+ const oldFill = leaf.get('fill');
14537
+ leaf.fill = '';
14538
+ leaf.__render(canvas, renderOptions);
14539
+ leaf.fill = oldFill;
14540
+ }
14541
+ else {
14542
+ leaf.__render(canvas, renderOptions);
14543
+ }
14544
+ canvas.restore();
14545
+ if (sliceLeaf)
14546
+ sliceLeaf.__updateWorldOpacity();
14547
+ if (trim) {
14548
+ trimBounds = getTrimBounds(canvas);
14549
+ const old = canvas, { width, height } = trimBounds;
14550
+ const config = { x: 0, y: 0, width, height, pixelRatio };
14551
+ canvas = Creator.canvas(config);
14552
+ canvas.copyWorld(old, trimBounds, config);
14553
+ }
14554
+ if (needFill)
14555
+ canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
14556
+ if (onCanvas)
14557
+ onCanvas(canvas);
14558
+ const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
14559
+ over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
14560
+ }));
14561
+ }
14562
+ else {
14563
+ over({ data: false });
14564
+ }
14565
+ }));
14566
+ }
14567
+ };
14568
+ let tasker;
14569
+ function addTask(task) {
14570
+ if (!tasker)
14571
+ tasker = new TaskProcessor();
14572
+ return new Promise((resolve) => {
14573
+ tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
14574
+ });
14575
+ }
14576
+ function checkLazy(leaf) {
14577
+ if (leaf.__.__needComputePaint)
14578
+ leaf.__.__computePaint();
14579
+ if (leaf.isBranch)
14580
+ leaf.children.forEach(child => checkLazy(child));
14581
+ }
14582
+
14583
+ const canvas = LeaferCanvasBase.prototype;
14584
+ const debug = Debug.get('@leafer-in/export');
14585
+ canvas.export = function (filename, options) {
14586
+ const { quality, blob } = FileHelper.getExportOptions(options);
14587
+ if (filename.includes('.'))
14588
+ return this.saveAs(filename, quality);
14589
+ else if (blob)
14590
+ return this.toBlob(filename, quality);
14591
+ else
14592
+ return this.toDataURL(filename, quality);
14593
+ };
14594
+ canvas.toBlob = function (type, quality) {
14595
+ return new Promise((resolve) => {
14596
+ Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
14597
+ resolve(blob);
14598
+ }).catch((e) => {
14599
+ debug.error(e);
14600
+ resolve(null);
14601
+ });
14602
+ });
14603
+ };
14604
+ canvas.toDataURL = function (type, quality) {
14605
+ return Platform.origin.canvasToDataURL(this.view, type, quality);
14606
+ };
14607
+ canvas.saveAs = function (filename, quality) {
14608
+ return new Promise((resolve) => {
14609
+ Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
14610
+ resolve(true);
14611
+ }).catch((e) => {
14612
+ debug.error(e);
14613
+ resolve(false);
14614
+ });
14615
+ });
14616
+ };
14617
+
14618
+ Object.assign(Export, ExportModule);
14619
+ exports.UI.prototype.export = function (filename, options) {
14620
+ return Export.export(this, filename, options);
14621
+ };
14622
+
14737
14623
  const textCaseMap = {
14738
14624
  'none': 'none',
14739
14625
  'title': 'capitalize',
@@ -14936,8 +14822,7 @@ ${filterStyle}
14936
14822
  registerInnerEditor()
14937
14823
  ], exports.TextEditor);
14938
14824
 
14939
- Plugin.add('text-editor');
14940
- setTimeout(() => Plugin.check('editor', true));
14825
+ Plugin.add('text-editor', 'editor');
14941
14826
 
14942
14827
  class HTMLTextData extends ImageData {
14943
14828
  setText(value) {
@@ -15102,6 +14987,7 @@ ${filterStyle}
15102
14987
  exports.PathNumberCommandLengthMap = PathNumberCommandLengthMap;
15103
14988
  exports.PathNumberCommandMap = PathNumberCommandMap;
15104
14989
  exports.PenData = PenData;
14990
+ exports.Picker = Picker;
15105
14991
  exports.Platform = Platform;
15106
14992
  exports.Plugin = Plugin;
15107
14993
  exports.Point = Point;