@leafer-editor/worker 1.2.1 → 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 = {
@@ -2050,11 +2053,11 @@ var LeaferUI = (function (exports) {
2050
2053
  toBlob(_type, _quality) { return undefined; }
2051
2054
  toDataURL(_type, _quality) { return undefined; }
2052
2055
  saveAs(_filename, _quality) { return undefined; }
2053
- resize(size) {
2056
+ resize(size, safeResize = true) {
2054
2057
  if (this.isSameSize(size))
2055
2058
  return;
2056
2059
  let takeCanvas;
2057
- if (this.context && !this.unreal && this.width) {
2060
+ if (this.context && !this.unreal && safeResize && this.width) {
2058
2061
  takeCanvas = this.getSameCanvas();
2059
2062
  takeCanvas.copyWorld(this);
2060
2063
  }
@@ -4256,18 +4259,21 @@ var LeaferUI = (function (exports) {
4256
4259
  L$3.setTransform(t, matrix$3, resize);
4257
4260
  },
4258
4261
  setTransform(t, transform, resize) {
4259
- const layout = getLayout(transform, t.origin && L$3.getInnerOrigin(t, t.origin), t.around && L$3.getInnerOrigin(t, t.around));
4262
+ const data = t.__, originPoint = data.origin && L$3.getInnerOrigin(t, data.origin);
4263
+ const layout = getLayout(transform, originPoint, data.around && L$3.getInnerOrigin(t, data.around));
4260
4264
  if (resize) {
4261
- const scaleX = layout.scaleX / t.scaleX;
4262
- const scaleY = layout.scaleY / t.scaleY;
4263
- delete layout.scaleX;
4264
- delete layout.scaleY;
4265
+ const scaleX = layout.scaleX / t.scaleX, scaleY = layout.scaleY / t.scaleY;
4266
+ delete layout.scaleX, delete layout.scaleY;
4267
+ if (originPoint) {
4268
+ BoundsHelper.scale(t.boxBounds, Math.abs(scaleX), Math.abs(scaleY));
4269
+ const changedPoint = L$3.getInnerOrigin(t, data.origin);
4270
+ PointHelper.move(layout, originPoint.x - changedPoint.x, originPoint.y - changedPoint.y);
4271
+ }
4265
4272
  t.set(layout);
4266
- t.scaleResize(scaleX, scaleY, resize !== true);
4273
+ t.scaleResize(scaleX, scaleY, false);
4267
4274
  }
4268
- else {
4275
+ else
4269
4276
  t.set(layout);
4270
- }
4271
4277
  },
4272
4278
  getFlipTransform(t, axis) {
4273
4279
  const m = getMatrixData();
@@ -4808,7 +4814,6 @@ var LeaferUI = (function (exports) {
4808
4814
  }
4809
4815
  }
4810
4816
  }
4811
- LayoutEvent.CHECK_UPDATE = 'layout.check_update';
4812
4817
  LayoutEvent.REQUEST = 'layout.request';
4813
4818
  LayoutEvent.START = 'layout.start';
4814
4819
  LayoutEvent.BEFORE = 'layout.before';
@@ -4950,14 +4955,15 @@ var LeaferUI = (function (exports) {
4950
4955
  if (list) {
4951
4956
  let item;
4952
4957
  for (let i = 0, len = list.length; i < len; i++) {
4953
- item = list[i];
4954
- item.listener(event);
4955
- if (item.once) {
4956
- this.off(type, item.listener, capture);
4957
- i--, len--;
4958
+ if (item = list[i]) {
4959
+ item.listener(event);
4960
+ if (item.once) {
4961
+ this.off(type, item.listener, capture);
4962
+ i--, len--;
4963
+ }
4964
+ if (event && event.isStopNow)
4965
+ break;
4958
4966
  }
4959
- if (event && event.isStopNow)
4960
- break;
4961
4967
  }
4962
4968
  }
4963
4969
  this.syncEventer && this.syncEventer.emitEvent(event, capture);
@@ -6004,7 +6010,7 @@ var LeaferUI = (function (exports) {
6004
6010
  }
6005
6011
  }
6006
6012
 
6007
- const version = "1.2.1";
6013
+ const version = "1.3.0";
6008
6014
 
6009
6015
  class LeaferCanvas extends LeaferCanvasBase {
6010
6016
  get allowBackgroundColor() { return true; }
@@ -6072,6 +6078,7 @@ var LeaferUI = (function (exports) {
6072
6078
  }
6073
6079
  Platform.name = 'web';
6074
6080
  Platform.isWorker = true;
6081
+ Platform.backgrounder = true;
6075
6082
  Platform.requestRender = function (render) { requestAnimationFrame(render); };
6076
6083
  defineKey(Platform, 'devicePixelRatio', { get() { return 1; } });
6077
6084
  const { userAgent } = navigator;
@@ -6804,143 +6811,26 @@ var LeaferUI = (function (exports) {
6804
6811
  }
6805
6812
  }
6806
6813
 
6807
- const { Yes: Yes$1, NoAndSkip: NoAndSkip$1, YesAndSkip: YesAndSkip$1 } = exports.Answer;
6808
- const idCondition = {}, classNameCondition = {}, tagCondition = {};
6809
6814
  class Selector {
6810
6815
  constructor(target, userConfig) {
6811
6816
  this.config = {};
6812
- this.innerIdMap = {};
6813
- this.idMap = {};
6814
- this.methods = {
6815
- id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,
6816
- innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,
6817
- className: (leaf, name) => leaf.className === name ? 1 : 0,
6818
- tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
6819
- tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
6820
- };
6821
- this.target = target;
6822
6817
  if (userConfig)
6823
6818
  this.config = DataHelper.default(userConfig, this.config);
6824
- this.picker = new Picker(target, this);
6825
- if (target)
6826
- this.__listenEvents();
6827
- }
6828
- getBy(condition, branch, one, options) {
6829
- switch (typeof condition) {
6830
- case 'number':
6831
- const leaf = this.getByInnerId(condition, branch);
6832
- return one ? leaf : (leaf ? [leaf] : []);
6833
- case 'string':
6834
- switch (condition[0]) {
6835
- case '#':
6836
- idCondition.id = condition.substring(1), condition = idCondition;
6837
- break;
6838
- case '.':
6839
- classNameCondition.className = condition.substring(1), condition = classNameCondition;
6840
- break;
6841
- default:
6842
- tagCondition.tag = condition, condition = tagCondition;
6843
- }
6844
- case 'object':
6845
- if (condition.id !== undefined) {
6846
- const leaf = this.getById(condition.id, branch);
6847
- return one ? leaf : (leaf ? [leaf] : []);
6848
- }
6849
- else if (condition.tag) {
6850
- const { tag } = condition, isArray = tag instanceof Array;
6851
- return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag);
6852
- }
6853
- else {
6854
- return this.getByMethod(this.methods.className, branch, one, condition.className);
6855
- }
6856
- case 'function':
6857
- return this.getByMethod(condition, branch, one, options);
6858
- }
6819
+ this.picker = new Picker(this.target = target, this);
6820
+ this.finder = Creator.finder && Creator.finder();
6859
6821
  }
6860
6822
  getByPoint(hitPoint, hitRadius, options) {
6861
- if (Platform.name === 'node' && this.target)
6862
- this.target.emit(LayoutEvent.CHECK_UPDATE);
6823
+ if (Platform.backgrounder && this.target)
6824
+ this.target.updateLayout();
6863
6825
  return this.picker.getByPoint(hitPoint, hitRadius, options);
6864
6826
  }
6865
- getByInnerId(innerId, branch) {
6866
- const cache = this.innerIdMap[innerId];
6867
- if (cache)
6868
- return cache;
6869
- this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
6870
- return this.findLeaf;
6871
- }
6872
- getById(id, branch) {
6873
- const cache = this.idMap[id];
6874
- if (cache && LeafHelper.hasParent(cache, branch || this.target))
6875
- return cache;
6876
- this.eachFind(this.toChildren(branch), this.methods.id, null, id);
6877
- return this.findLeaf;
6878
- }
6879
- getByClassName(className, branch) {
6880
- return this.getByMethod(this.methods.className, branch, false, className);
6881
- }
6882
- getByTag(tag, branch) {
6883
- return this.getByMethod(this.methods.tag, branch, false, tag);
6884
- }
6885
- getByMethod(method, branch, one, options) {
6886
- const list = one ? null : [];
6887
- this.eachFind(this.toChildren(branch), method, list, options);
6888
- return list || this.findLeaf;
6889
- }
6890
- eachFind(children, method, list, options) {
6891
- let child, result;
6892
- for (let i = 0, len = children.length; i < len; i++) {
6893
- child = children[i];
6894
- result = method(child, options);
6895
- if (result === Yes$1 || result === YesAndSkip$1) {
6896
- if (list) {
6897
- list.push(child);
6898
- }
6899
- else {
6900
- this.findLeaf = child;
6901
- return;
6902
- }
6903
- }
6904
- if (child.isBranch && result < NoAndSkip$1)
6905
- this.eachFind(child.children, method, list, options);
6906
- }
6907
- }
6908
- toChildren(branch) {
6909
- this.findLeaf = null;
6910
- return [branch || this.target];
6911
- }
6912
- __onRemoveChild(event) {
6913
- const { id, innerId } = event.child;
6914
- if (this.idMap[id])
6915
- delete this.idMap[id];
6916
- if (this.innerIdMap[innerId])
6917
- delete this.innerIdMap[innerId];
6918
- }
6919
- __checkIdChange(event) {
6920
- if (event.attrName === 'id') {
6921
- const id = event.oldValue;
6922
- if (this.idMap[id])
6923
- delete this.idMap[id];
6924
- }
6925
- }
6926
- __listenEvents() {
6927
- this.__eventIds = [
6928
- this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),
6929
- this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)
6930
- ];
6931
- }
6932
- __removeListenEvents() {
6933
- this.target.off_(this.__eventIds);
6934
- this.__eventIds.length = 0;
6827
+ getBy(condition, branch, one, options) {
6828
+ return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need('find');
6935
6829
  }
6936
6830
  destroy() {
6937
- if (this.__eventIds.length) {
6938
- this.__removeListenEvents();
6939
- this.picker.destroy();
6940
- this.findLeaf = null;
6941
- this.innerIdMap = {};
6942
- this.idMap = {};
6943
- }
6831
+ this.picker.destroy();
6832
+ if (this.finder)
6833
+ this.finder.destroy();
6944
6834
  }
6945
6835
  }
6946
6836
 
@@ -7436,25 +7326,27 @@ var LeaferUI = (function (exports) {
7436
7326
  }
7437
7327
  reset(_data) { }
7438
7328
  set(data, transition) {
7439
- if (transition) {
7440
- if (transition === 'temp') {
7441
- this.lockNormalStyle = true;
7442
- Object.assign(this, data);
7443
- 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);
7444
7338
  }
7445
7339
  else
7446
- this.animate(data, transition);
7340
+ Object.assign(this, data);
7447
7341
  }
7448
- else
7449
- Object.assign(this, data);
7450
7342
  }
7451
7343
  get(name) {
7452
7344
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
7453
7345
  }
7454
7346
  createProxyData() { return undefined; }
7455
- find(_condition, _options) { return undefined; }
7347
+ find(_condition, _options) { return Plugin.need('find'); }
7456
7348
  findTag(tag) { return this.find({ tag }); }
7457
- findOne(_condition, _options) { return undefined; }
7349
+ findOne(_condition, _options) { return Plugin.need('find'); }
7458
7350
  findId(id) { return this.findOne({ id }); }
7459
7351
  getPath(curve, pathForRender) {
7460
7352
  this.__layout.update();
@@ -7506,9 +7398,9 @@ var LeaferUI = (function (exports) {
7506
7398
  animate(_keyframe, _options, _type, _isTemp) {
7507
7399
  return Plugin.need('animate');
7508
7400
  }
7509
- killAnimate(_type) { }
7510
- export(filename, options) {
7511
- return Export.export(this, filename, options);
7401
+ killAnimate(_type, _killStyle) { }
7402
+ export(_filename, _options) {
7403
+ return Plugin.need('export');
7512
7404
  }
7513
7405
  clone(data) {
7514
7406
  const json = this.toJSON();
@@ -7754,16 +7646,18 @@ var LeaferUI = (function (exports) {
7754
7646
  this.children = [];
7755
7647
  }
7756
7648
  set(data, transition) {
7757
- if (data.children) {
7758
- const { children } = data;
7759
- delete data.children;
7760
- this.children ? this.clear() : this.__setBranch();
7761
- super.set(data, transition);
7762
- children.forEach(child => this.add(child));
7763
- 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);
7764
7660
  }
7765
- else
7766
- super.set(data, transition);
7767
7661
  }
7768
7662
  toJSON(options) {
7769
7663
  const data = super.toJSON(options);
@@ -8026,6 +7920,8 @@ var LeaferUI = (function (exports) {
8026
7920
  this.requestRender();
8027
7921
  }
8028
7922
  }
7923
+ else
7924
+ this.requestRender();
8029
7925
  }
8030
7926
  __checkViewCompleted(emit = true) {
8031
7927
  this.nextRender(() => {
@@ -8099,9 +7995,6 @@ var LeaferUI = (function (exports) {
8099
7995
  this.canvas && this.canvas.updateClientBounds();
8100
7996
  }
8101
7997
  receiveEvent(_event) { }
8102
- __checkUpdateLayout() {
8103
- this.__layout.update();
8104
- }
8105
7998
  emitLeafer(type) {
8106
7999
  this.emitEvent(new LeaferEvent(type, this));
8107
8000
  }
@@ -8112,7 +8005,7 @@ var LeaferUI = (function (exports) {
8112
8005
  this.once(LayoutEvent.END, () => this.__onReady());
8113
8006
  this.once(RenderEvent.START, () => this.__onCreated());
8114
8007
  this.once(RenderEvent.END, () => this.__onViewReady());
8115
- 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));
8116
8009
  }
8117
8010
  __removeListenEvents() {
8118
8011
  this.off_(this.__eventIds);
@@ -8177,7 +8070,7 @@ var LeaferUI = (function (exports) {
8177
8070
  ], exports.Rect);
8178
8071
 
8179
8072
  const { copy: copy$6, add, includes: includes$1 } = BoundsHelper;
8180
- const rect$1 = exports.Rect.prototype, group$1 = exports.Group.prototype;
8073
+ const rect$1 = exports.Rect.prototype, group = exports.Group.prototype;
8181
8074
  const childrenRenderBounds = {};
8182
8075
  exports.Box = class Box extends exports.Group {
8183
8076
  get __tag() { return 'Box'; }
@@ -8287,7 +8180,7 @@ var LeaferUI = (function (exports) {
8287
8180
  rewrite(rect$1.__render)
8288
8181
  ], exports.Box.prototype, "__renderRect", null);
8289
8182
  __decorate([
8290
- rewrite(group$1.__render)
8183
+ rewrite(group.__render)
8291
8184
  ], exports.Box.prototype, "__renderGroup", null);
8292
8185
  exports.Box = __decorate([
8293
8186
  rewriteAble(),
@@ -8591,10 +8484,10 @@ var LeaferUI = (function (exports) {
8591
8484
  __updateSize() {
8592
8485
  const { canvas } = this;
8593
8486
  if (canvas) {
8594
- const { smooth } = this.__;
8487
+ const { smooth, safeResize } = this.__;
8488
+ canvas.resize(this.__, safeResize);
8595
8489
  if (canvas.smooth !== smooth)
8596
8490
  canvas.smooth = smooth;
8597
- canvas.resize(this.__);
8598
8491
  }
8599
8492
  }
8600
8493
  destroy() {
@@ -8620,6 +8513,9 @@ var LeaferUI = (function (exports) {
8620
8513
  __decorate([
8621
8514
  resizeType(true)
8622
8515
  ], exports.Canvas.prototype, "smooth", void 0);
8516
+ __decorate([
8517
+ dataType(false)
8518
+ ], exports.Canvas.prototype, "safeResize", void 0);
8623
8519
  __decorate([
8624
8520
  resizeType()
8625
8521
  ], exports.Canvas.prototype, "contextSettings", void 0);
@@ -8765,6 +8661,9 @@ var LeaferUI = (function (exports) {
8765
8661
  __decorate([
8766
8662
  boundsType(0)
8767
8663
  ], exports.Text.prototype, "paraSpacing", void 0);
8664
+ __decorate([
8665
+ boundsType('x')
8666
+ ], exports.Text.prototype, "writingMode", void 0);
8768
8667
  __decorate([
8769
8668
  boundsType('left')
8770
8669
  ], exports.Text.prototype, "textAlign", void 0);
@@ -8951,8 +8850,8 @@ var LeaferUI = (function (exports) {
8951
8850
  this.children.forEach(leafer => leafer.resize(event));
8952
8851
  super.__onResize(event);
8953
8852
  }
8954
- __checkUpdateLayout() {
8955
- this.children.forEach(leafer => leafer.__layout.update());
8853
+ updateLayout() {
8854
+ this.children.forEach(leafer => leafer.updateLayout());
8956
8855
  }
8957
8856
  __getChildConfig(userConfig) {
8958
8857
  let config = Object.assign({}, this.config);
@@ -10029,8 +9928,8 @@ var LeaferUI = (function (exports) {
10029
9928
  this.__drawRenderPath(canvas); };
10030
9929
 
10031
9930
  const matrix$2 = new Matrix();
10032
- const ui$3 = exports.UI.prototype;
10033
- ui$3.__updateHitCanvas = function () {
9931
+ const ui$2 = exports.UI.prototype;
9932
+ ui$2.__updateHitCanvas = function () {
10034
9933
  const data = this.__, { hitCanvasManager } = this.leafer;
10035
9934
  const isHitPixelFill = (data.__pixelFill || data.__isCanvas) && data.hitFill === 'pixel';
10036
9935
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
@@ -10057,7 +9956,7 @@ var LeaferUI = (function (exports) {
10057
9956
  this.__drawHitPath(h);
10058
9957
  h.setStrokeOptions(data);
10059
9958
  };
10060
- ui$3.__hit = function (inner) {
9959
+ ui$2.__hit = function (inner) {
10061
9960
  if (Platform.name === 'miniapp')
10062
9961
  this.__drawHitPath(this.__hitCanvas);
10063
9962
  const data = this.__;
@@ -10097,31 +9996,23 @@ var LeaferUI = (function (exports) {
10097
9996
  return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
10098
9997
  };
10099
9998
 
10100
- 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;
10101
10000
  rect.__updateHitCanvas = box$1.__updateHitCanvas = function () {
10102
10001
  if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
10103
- ui$2.__updateHitCanvas.call(this);
10002
+ ui$1.__updateHitCanvas.call(this);
10104
10003
  else if (this.__hitCanvas)
10105
10004
  this.__hitCanvas = null;
10106
10005
  };
10107
10006
  rect.__hitFill = box$1.__hitFill = function (inner) {
10108
- 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);
10109
10008
  };
10110
10009
 
10111
- const ui$1 = exports.UI.prototype, group = exports.Group.prototype;
10112
10010
  function getSelector(ui) {
10113
10011
  return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()));
10114
10012
  }
10115
- ui$1.find = function (condition, options) {
10116
- return getSelector(this).getBy(condition, this, false, options);
10117
- };
10118
- ui$1.findOne = function (condition, options) {
10119
- return getSelector(this).getBy(condition, this, true, options);
10120
- };
10121
- group.pick = function (hitPoint, options) {
10122
- this.__layout.update();
10123
- if (!options)
10124
- options = {};
10013
+ exports.Group.prototype.pick = function (hitPoint, options) {
10014
+ this.leafer || this.updateLayout();
10015
+ options || (options = emptyData);
10125
10016
  return getSelector(this).getByPoint(hitPoint, options.hitRadius || 0, Object.assign(Object.assign({}, options), { target: this }));
10126
10017
  };
10127
10018
 
@@ -11625,197 +11516,12 @@ var LeaferUI = (function (exports) {
11625
11516
  string
11626
11517
  };
11627
11518
 
11628
- const { setPoint: setPoint$2, addPoint, toBounds } = TwoPointBoundsHelper;
11629
- function getTrimBounds(canvas) {
11630
- const { width, height } = canvas.view;
11631
- const { data } = canvas.context.getImageData(0, 0, width, height);
11632
- let x, y, pointBounds, index = 0;
11633
- for (let i = 0; i < data.length; i += 4) {
11634
- if (data[i + 3] !== 0) {
11635
- x = index % width;
11636
- y = (index - x) / width;
11637
- pointBounds ? addPoint(pointBounds, x, y) : setPoint$2(pointBounds = {}, x, y);
11638
- }
11639
- index++;
11640
- }
11641
- const bounds = new Bounds();
11642
- toBounds(pointBounds, bounds);
11643
- return bounds.scale(1 / canvas.pixelRatio).ceil();
11644
- }
11645
-
11646
- const ExportModule = {
11647
- export(leaf, filename, options) {
11648
- this.running = true;
11649
- const fileType = FileHelper.fileType(filename);
11650
- const isDownload = filename.includes('.');
11651
- options = FileHelper.getExportOptions(options);
11652
- return addTask((success) => new Promise((resolve) => {
11653
- const over = (result) => {
11654
- success(result);
11655
- resolve();
11656
- this.running = false;
11657
- };
11658
- const { toURL } = Platform;
11659
- const { download } = Platform.origin;
11660
- if (fileType === 'json') {
11661
- isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
11662
- return over({ data: isDownload ? true : leaf.toJSON(options.json) });
11663
- }
11664
- if (fileType === 'svg') {
11665
- isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
11666
- return over({ data: isDownload ? true : leaf.toSVG() });
11667
- }
11668
- const { leafer } = leaf;
11669
- if (leafer) {
11670
- checkLazy(leaf);
11671
- leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
11672
- let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
11673
- const { worldTransform, isLeafer, isFrame } = leaf;
11674
- const { slice, trim, onCanvas } = options;
11675
- const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
11676
- const contextSettings = options.contextSettings || leafer.config.contextSettings;
11677
- const screenshot = options.screenshot || leaf.isApp;
11678
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
11679
- const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
11680
- if (screenshot) {
11681
- renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
11682
- }
11683
- else {
11684
- let relative = options.relative || (isLeafer ? 'inner' : 'local');
11685
- scaleX = worldTransform.scaleX;
11686
- scaleY = worldTransform.scaleY;
11687
- switch (relative) {
11688
- case 'inner':
11689
- matrix.set(worldTransform);
11690
- break;
11691
- case 'local':
11692
- matrix.set(worldTransform).divide(leaf.localTransform);
11693
- scaleX /= leaf.scaleX;
11694
- scaleY /= leaf.scaleY;
11695
- break;
11696
- case 'world':
11697
- scaleX = 1;
11698
- scaleY = 1;
11699
- break;
11700
- case 'page':
11701
- relative = leaf.leafer;
11702
- default:
11703
- matrix.set(worldTransform).divide(leaf.getTransform(relative));
11704
- const l = relative.worldTransform;
11705
- scaleX /= scaleX / l.scaleX;
11706
- scaleY /= scaleY / l.scaleY;
11707
- }
11708
- renderBounds = leaf.getBounds('render', relative);
11709
- }
11710
- const scaleData = { scaleX: 1, scaleY: 1 };
11711
- MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
11712
- let pixelRatio = options.pixelRatio || 1;
11713
- if (leaf.isApp) {
11714
- scaleData.scaleX *= pixelRatio;
11715
- scaleData.scaleY *= pixelRatio;
11716
- pixelRatio = leaf.app.pixelRatio;
11717
- }
11718
- const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
11719
- const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
11720
- let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
11721
- let sliceLeaf;
11722
- if (slice) {
11723
- sliceLeaf = leaf;
11724
- sliceLeaf.__worldOpacity = 0;
11725
- leaf = leafer;
11726
- renderOptions.bounds = canvas.bounds;
11727
- }
11728
- canvas.save();
11729
- if (isFrame && fill !== undefined) {
11730
- const oldFill = leaf.get('fill');
11731
- leaf.fill = '';
11732
- leaf.__render(canvas, renderOptions);
11733
- leaf.fill = oldFill;
11734
- }
11735
- else {
11736
- leaf.__render(canvas, renderOptions);
11737
- }
11738
- canvas.restore();
11739
- if (sliceLeaf)
11740
- sliceLeaf.__updateWorldOpacity();
11741
- if (trim) {
11742
- trimBounds = getTrimBounds(canvas);
11743
- const old = canvas, { width, height } = trimBounds;
11744
- const config = { x: 0, y: 0, width, height, pixelRatio };
11745
- canvas = Creator.canvas(config);
11746
- canvas.copyWorld(old, trimBounds, config);
11747
- }
11748
- if (needFill)
11749
- canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
11750
- if (onCanvas)
11751
- onCanvas(canvas);
11752
- const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
11753
- over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
11754
- }));
11755
- }
11756
- else {
11757
- over({ data: false });
11758
- }
11759
- }));
11760
- }
11761
- };
11762
- let tasker;
11763
- function addTask(task) {
11764
- if (!tasker)
11765
- tasker = new TaskProcessor();
11766
- return new Promise((resolve) => {
11767
- tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
11768
- });
11769
- }
11770
- function checkLazy(leaf) {
11771
- if (leaf.__.__needComputePaint)
11772
- leaf.__.__computePaint();
11773
- if (leaf.isBranch)
11774
- leaf.children.forEach(child => checkLazy(child));
11775
- }
11776
-
11777
- const canvas = LeaferCanvasBase.prototype;
11778
- const debug$2 = Debug.get('@leafer-ui/export');
11779
- canvas.export = function (filename, options) {
11780
- const { quality, blob } = FileHelper.getExportOptions(options);
11781
- if (filename.includes('.'))
11782
- return this.saveAs(filename, quality);
11783
- else if (blob)
11784
- return this.toBlob(filename, quality);
11785
- else
11786
- return this.toDataURL(filename, quality);
11787
- };
11788
- canvas.toBlob = function (type, quality) {
11789
- return new Promise((resolve) => {
11790
- Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
11791
- resolve(blob);
11792
- }).catch((e) => {
11793
- debug$2.error(e);
11794
- resolve(null);
11795
- });
11796
- });
11797
- };
11798
- canvas.toDataURL = function (type, quality) {
11799
- return Platform.origin.canvasToDataURL(this.view, type, quality);
11800
- };
11801
- canvas.saveAs = function (filename, quality) {
11802
- return new Promise((resolve) => {
11803
- Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
11804
- resolve(true);
11805
- }).catch((e) => {
11806
- debug$2.error(e);
11807
- resolve(false);
11808
- });
11809
- });
11810
- };
11811
-
11812
11519
  Object.assign(TextConvert, TextConvertModule);
11813
11520
  Object.assign(ColorConvert, ColorConvertModule);
11814
11521
  Object.assign(Paint, PaintModule);
11815
11522
  Object.assign(PaintImage, PaintImageModule);
11816
11523
  Object.assign(PaintGradient, PaintGradientModule);
11817
11524
  Object.assign(Effect, EffectModule);
11818
- Object.assign(Export, ExportModule);
11819
11525
 
11820
11526
  Object.assign(Creator, {
11821
11527
  interaction: (target, canvas, selector, options) => new InteractionBase(target, canvas, selector, options),
@@ -12960,7 +12666,7 @@ ${filterStyle}
12960
12666
  }
12961
12667
  };
12962
12668
 
12963
- const debug$1 = Debug.get('EditToolCreator');
12669
+ const debug$2 = Debug.get('EditToolCreator');
12964
12670
  function registerEditTool() {
12965
12671
  return (target) => {
12966
12672
  EditToolCreator.register(target);
@@ -12971,7 +12677,7 @@ ${filterStyle}
12971
12677
  list: {},
12972
12678
  register(EditTool) {
12973
12679
  const { tag } = EditTool.prototype;
12974
- list$1[tag] && debug$1.repeat(tag);
12680
+ list$1[tag] && debug$2.repeat(tag);
12975
12681
  list$1[tag] = EditTool;
12976
12682
  },
12977
12683
  get(tag, editor) {
@@ -13088,7 +12794,7 @@ ${filterStyle}
13088
12794
  if (userConfig)
13089
12795
  this.config = DataHelper.default(userConfig, this.config);
13090
12796
  this.addMany(this.editMask, this.selector, this.editBox);
13091
- if (!Plugin.check('resize', true))
12797
+ if (!Plugin.has('resize'))
13092
12798
  this.config.editSize = 'scale';
13093
12799
  }
13094
12800
  select(target) {
@@ -13881,7 +13587,7 @@ ${filterStyle}
13881
13587
 
13882
13588
  Plugin.add('resize');
13883
13589
 
13884
- Plugin.add('editor');
13590
+ Plugin.add('editor', 'resize');
13885
13591
  Creator.editor = function (options) { return new Editor(options); };
13886
13592
  dataType(false)(exports.Box.prototype, 'textBox');
13887
13593
  defineKey(exports.UI.prototype, 'editOuter', {
@@ -13928,13 +13634,14 @@ ${filterStyle}
13928
13634
  }));
13929
13635
  }
13930
13636
  function addViewportConfig(leafer, mergeConfig) {
13931
- if (mergeConfig)
13932
- DataHelper.assign(leafer.config, mergeConfig);
13933
- DataHelper.assign(leafer.config, {
13637
+ const viewportConfig = {
13934
13638
  wheel: { preventDefault: true },
13935
13639
  touch: { preventDefault: true },
13936
13640
  pointer: { preventDefaultMenu: true }
13937
- }, leafer.userConfig);
13641
+ };
13642
+ if (mergeConfig)
13643
+ DataHelper.assign(viewportConfig, mergeConfig);
13644
+ DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig);
13938
13645
  }
13939
13646
 
13940
13647
  function custom(leafer) {
@@ -13961,11 +13668,11 @@ ${filterStyle}
13961
13668
  });
13962
13669
  }
13963
13670
 
13964
- const debug = Debug.get('LeaferTypeCreator');
13671
+ const debug$1 = Debug.get('LeaferTypeCreator');
13965
13672
  const LeaferTypeCreator = {
13966
13673
  list: {},
13967
13674
  register(name, fn) {
13968
- list[name] && debug.repeat(name);
13675
+ list[name] && debug$1.repeat(name);
13969
13676
  list[name] = fn;
13970
13677
  },
13971
13678
  run(name, leafer) {
@@ -14490,17 +14197,17 @@ ${filterStyle}
14490
14197
  switch (command) {
14491
14198
  case M$1:
14492
14199
  case L$1:
14493
- setPoint$1(data, i + 1, x, y, scaleX, scaleY, rotation, origin);
14200
+ setPoint$2(data, i + 1, x, y, scaleX, scaleY, rotation, origin);
14494
14201
  i += 3;
14495
14202
  break;
14496
14203
  case C$1:
14497
14204
  for (j = 1; j < 6; j += 2)
14498
- setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14205
+ setPoint$2(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14499
14206
  i += 7;
14500
14207
  break;
14501
14208
  case Q$1:
14502
14209
  for (j = 1; j < 4; j += 2)
14503
- setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14210
+ setPoint$2(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14504
14211
  i += 5;
14505
14212
  break;
14506
14213
  case O$1:
@@ -14521,7 +14228,7 @@ ${filterStyle}
14521
14228
  PathMatrixHelper.layout(data, 0, 0, 1, 1, rotation, center);
14522
14229
  }
14523
14230
  };
14524
- function setPoint$1(data, startIndex, x, y, scaleX, scaleY, rotation, origin) {
14231
+ function setPoint$2(data, startIndex, x, y, scaleX, scaleY, rotation, origin) {
14525
14232
  copyFrom$1(point, data[startIndex], data[startIndex + 1]);
14526
14233
  if (rotation)
14527
14234
  rotate$1(point, rotation, origin);
@@ -14687,7 +14394,7 @@ ${filterStyle}
14687
14394
  break;
14688
14395
  }
14689
14396
  if (index)
14690
- setPoint(path, last, index);
14397
+ setPoint$1(path, last, index);
14691
14398
  }
14692
14399
  }
14693
14400
  }
@@ -14701,7 +14408,7 @@ ${filterStyle}
14701
14408
  copyFrom(from, data[startIndex], data[startIndex + 1]);
14702
14409
  copyFrom(to, data[startIndex + 2], data[startIndex + 3]);
14703
14410
  }
14704
- function setPoint(data, point, startIndex) {
14411
+ function setPoint$1(data, point, startIndex) {
14705
14412
  data[startIndex] = point.x;
14706
14413
  data[startIndex + 1] = point.y;
14707
14414
  }
@@ -14724,6 +14431,195 @@ ${filterStyle}
14724
14431
  arrowType('none')(ui, 'endArrow');
14725
14432
  Object.assign(PathArrow, PathArrowModule);
14726
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
+
14727
14623
  const textCaseMap = {
14728
14624
  'none': 'none',
14729
14625
  'title': 'capitalize',
@@ -14926,8 +14822,7 @@ ${filterStyle}
14926
14822
  registerInnerEditor()
14927
14823
  ], exports.TextEditor);
14928
14824
 
14929
- Plugin.add('text-editor');
14930
- setTimeout(() => Plugin.check('editor', true));
14825
+ Plugin.add('text-editor', 'editor');
14931
14826
 
14932
14827
  class HTMLTextData extends ImageData {
14933
14828
  setText(value) {
@@ -15092,6 +14987,7 @@ ${filterStyle}
15092
14987
  exports.PathNumberCommandLengthMap = PathNumberCommandLengthMap;
15093
14988
  exports.PathNumberCommandMap = PathNumberCommandMap;
15094
14989
  exports.PenData = PenData;
14990
+ exports.Picker = Picker;
15095
14991
  exports.Platform = Platform;
15096
14992
  exports.Plugin = Plugin;
15097
14993
  exports.Point = Point;