@leafer-editor/worker 1.2.2 → 1.3.1

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.
@@ -1402,21 +1402,24 @@ const Run = {
1402
1402
  };
1403
1403
  const R = Run;
1404
1404
 
1405
+ const check = [];
1405
1406
  const Plugin = {
1406
1407
  list: {},
1407
- add(name) {
1408
+ add(name, ...needPlugins) {
1408
1409
  this.list[name] = true;
1410
+ check.push(...needPlugins);
1409
1411
  },
1410
- check(name, tip) {
1412
+ has(name, tip) {
1411
1413
  const rs = this.list[name];
1412
1414
  if (!rs && tip)
1413
1415
  this.need(name);
1414
1416
  return rs;
1415
1417
  },
1416
1418
  need(name) {
1417
- console.error('need plugin: @leafer-in/' + name);
1419
+ console.error('need plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name);
1418
1420
  }
1419
1421
  };
1422
+ setTimeout(() => check.forEach(name => Plugin.has(name, true)));
1420
1423
 
1421
1424
  const debug$g = Debug.get('UICreator');
1422
1425
  const UICreator = {
@@ -4808,7 +4811,6 @@ class LayoutEvent extends Event {
4808
4811
  }
4809
4812
  }
4810
4813
  }
4811
- LayoutEvent.CHECK_UPDATE = 'layout.check_update';
4812
4814
  LayoutEvent.REQUEST = 'layout.request';
4813
4815
  LayoutEvent.START = 'layout.start';
4814
4816
  LayoutEvent.BEFORE = 'layout.before';
@@ -6005,7 +6007,7 @@ class LeafLevelList {
6005
6007
  }
6006
6008
  }
6007
6009
 
6008
- const version = "1.2.2";
6010
+ const version = "1.3.1";
6009
6011
 
6010
6012
  class LeaferCanvas extends LeaferCanvasBase {
6011
6013
  get allowBackgroundColor() { return true; }
@@ -6073,6 +6075,7 @@ function useCanvas(_canvasType, _power) {
6073
6075
  }
6074
6076
  Platform.name = 'web';
6075
6077
  Platform.isWorker = true;
6078
+ Platform.backgrounder = true;
6076
6079
  Platform.requestRender = function (render) { requestAnimationFrame(render); };
6077
6080
  defineKey(Platform, 'devicePixelRatio', { get() { return 1; } });
6078
6081
  const { userAgent } = navigator;
@@ -6805,143 +6808,26 @@ class Picker {
6805
6808
  }
6806
6809
  }
6807
6810
 
6808
- const { Yes: Yes$1, NoAndSkip: NoAndSkip$1, YesAndSkip: YesAndSkip$1 } = Answer;
6809
- const idCondition = {}, classNameCondition = {}, tagCondition = {};
6810
6811
  class Selector {
6811
6812
  constructor(target, userConfig) {
6812
6813
  this.config = {};
6813
- this.innerIdMap = {};
6814
- this.idMap = {};
6815
- this.methods = {
6816
- id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,
6817
- innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,
6818
- className: (leaf, name) => leaf.className === name ? 1 : 0,
6819
- tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
6820
- tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
6821
- };
6822
- this.target = target;
6823
6814
  if (userConfig)
6824
6815
  this.config = DataHelper.default(userConfig, this.config);
6825
- this.picker = new Picker(target, this);
6826
- if (target)
6827
- this.__listenEvents();
6828
- }
6829
- getBy(condition, branch, one, options) {
6830
- switch (typeof condition) {
6831
- case 'number':
6832
- const leaf = this.getByInnerId(condition, branch);
6833
- return one ? leaf : (leaf ? [leaf] : []);
6834
- case 'string':
6835
- switch (condition[0]) {
6836
- case '#':
6837
- idCondition.id = condition.substring(1), condition = idCondition;
6838
- break;
6839
- case '.':
6840
- classNameCondition.className = condition.substring(1), condition = classNameCondition;
6841
- break;
6842
- default:
6843
- tagCondition.tag = condition, condition = tagCondition;
6844
- }
6845
- case 'object':
6846
- if (condition.id !== undefined) {
6847
- const leaf = this.getById(condition.id, branch);
6848
- return one ? leaf : (leaf ? [leaf] : []);
6849
- }
6850
- else if (condition.tag) {
6851
- const { tag } = condition, isArray = tag instanceof Array;
6852
- return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag);
6853
- }
6854
- else {
6855
- return this.getByMethod(this.methods.className, branch, one, condition.className);
6856
- }
6857
- case 'function':
6858
- return this.getByMethod(condition, branch, one, options);
6859
- }
6816
+ this.picker = new Picker(this.target = target, this);
6817
+ this.finder = Creator.finder && Creator.finder();
6860
6818
  }
6861
6819
  getByPoint(hitPoint, hitRadius, options) {
6862
- if (Platform.name === 'node' && this.target)
6863
- this.target.emit(LayoutEvent.CHECK_UPDATE);
6820
+ if (Platform.backgrounder && this.target)
6821
+ this.target.updateLayout();
6864
6822
  return this.picker.getByPoint(hitPoint, hitRadius, options);
6865
6823
  }
6866
- getByInnerId(innerId, branch) {
6867
- const cache = this.innerIdMap[innerId];
6868
- if (cache)
6869
- return cache;
6870
- this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
6871
- return this.findLeaf;
6872
- }
6873
- getById(id, branch) {
6874
- const cache = this.idMap[id];
6875
- if (cache && LeafHelper.hasParent(cache, branch || this.target))
6876
- return cache;
6877
- this.eachFind(this.toChildren(branch), this.methods.id, null, id);
6878
- return this.findLeaf;
6879
- }
6880
- getByClassName(className, branch) {
6881
- return this.getByMethod(this.methods.className, branch, false, className);
6882
- }
6883
- getByTag(tag, branch) {
6884
- return this.getByMethod(this.methods.tag, branch, false, tag);
6885
- }
6886
- getByMethod(method, branch, one, options) {
6887
- const list = one ? null : [];
6888
- this.eachFind(this.toChildren(branch), method, list, options);
6889
- return list || this.findLeaf;
6890
- }
6891
- eachFind(children, method, list, options) {
6892
- let child, result;
6893
- for (let i = 0, len = children.length; i < len; i++) {
6894
- child = children[i];
6895
- result = method(child, options);
6896
- if (result === Yes$1 || result === YesAndSkip$1) {
6897
- if (list) {
6898
- list.push(child);
6899
- }
6900
- else {
6901
- this.findLeaf = child;
6902
- return;
6903
- }
6904
- }
6905
- if (child.isBranch && result < NoAndSkip$1)
6906
- this.eachFind(child.children, method, list, options);
6907
- }
6908
- }
6909
- toChildren(branch) {
6910
- this.findLeaf = null;
6911
- return [branch || this.target];
6912
- }
6913
- __onRemoveChild(event) {
6914
- const { id, innerId } = event.child;
6915
- if (this.idMap[id])
6916
- delete this.idMap[id];
6917
- if (this.innerIdMap[innerId])
6918
- delete this.innerIdMap[innerId];
6919
- }
6920
- __checkIdChange(event) {
6921
- if (event.attrName === 'id') {
6922
- const id = event.oldValue;
6923
- if (this.idMap[id])
6924
- delete this.idMap[id];
6925
- }
6926
- }
6927
- __listenEvents() {
6928
- this.__eventIds = [
6929
- this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),
6930
- this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)
6931
- ];
6932
- }
6933
- __removeListenEvents() {
6934
- this.target.off_(this.__eventIds);
6935
- this.__eventIds.length = 0;
6824
+ getBy(condition, branch, one, options) {
6825
+ return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need('find');
6936
6826
  }
6937
6827
  destroy() {
6938
- if (this.__eventIds.length) {
6939
- this.__removeListenEvents();
6940
- this.picker.destroy();
6941
- this.findLeaf = null;
6942
- this.innerIdMap = {};
6943
- this.idMap = {};
6944
- }
6828
+ this.picker.destroy();
6829
+ if (this.finder)
6830
+ this.finder.destroy();
6945
6831
  }
6946
6832
  }
6947
6833
 
@@ -7437,25 +7323,27 @@ let UI = UI_1 = class UI extends Leaf {
7437
7323
  }
7438
7324
  reset(_data) { }
7439
7325
  set(data, transition) {
7440
- if (transition) {
7441
- if (transition === 'temp') {
7442
- this.lockNormalStyle = true;
7443
- Object.assign(this, data);
7444
- this.lockNormalStyle = false;
7326
+ if (data) {
7327
+ if (transition) {
7328
+ if (transition === 'temp') {
7329
+ this.lockNormalStyle = true;
7330
+ Object.assign(this, data);
7331
+ this.lockNormalStyle = false;
7332
+ }
7333
+ else
7334
+ this.animate(data, transition);
7445
7335
  }
7446
7336
  else
7447
- this.animate(data, transition);
7337
+ Object.assign(this, data);
7448
7338
  }
7449
- else
7450
- Object.assign(this, data);
7451
7339
  }
7452
7340
  get(name) {
7453
7341
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
7454
7342
  }
7455
7343
  createProxyData() { return undefined; }
7456
- find(_condition, _options) { return undefined; }
7344
+ find(_condition, _options) { return Plugin.need('find'); }
7457
7345
  findTag(tag) { return this.find({ tag }); }
7458
- findOne(_condition, _options) { return undefined; }
7346
+ findOne(_condition, _options) { return Plugin.need('find'); }
7459
7347
  findId(id) { return this.findOne({ id }); }
7460
7348
  getPath(curve, pathForRender) {
7461
7349
  this.__layout.update();
@@ -7507,9 +7395,9 @@ let UI = UI_1 = class UI extends Leaf {
7507
7395
  animate(_keyframe, _options, _type, _isTemp) {
7508
7396
  return Plugin.need('animate');
7509
7397
  }
7510
- killAnimate(_type) { }
7511
- export(filename, options) {
7512
- return Export.export(this, filename, options);
7398
+ killAnimate(_type, _killStyle) { }
7399
+ export(_filename, _options) {
7400
+ return Plugin.need('export');
7513
7401
  }
7514
7402
  clone(data) {
7515
7403
  const json = this.toJSON();
@@ -7755,16 +7643,18 @@ let Group = class Group extends UI {
7755
7643
  this.children = [];
7756
7644
  }
7757
7645
  set(data, transition) {
7758
- if (data.children) {
7759
- const { children } = data;
7760
- delete data.children;
7761
- this.children ? this.clear() : this.__setBranch();
7762
- super.set(data, transition);
7763
- children.forEach(child => this.add(child));
7764
- data.children = children;
7646
+ if (data) {
7647
+ if (data.children) {
7648
+ const { children } = data;
7649
+ delete data.children;
7650
+ this.children ? this.clear() : this.__setBranch();
7651
+ super.set(data, transition);
7652
+ children.forEach(child => this.add(child));
7653
+ data.children = children;
7654
+ }
7655
+ else
7656
+ super.set(data, transition);
7765
7657
  }
7766
- else
7767
- super.set(data, transition);
7768
7658
  }
7769
7659
  toJSON(options) {
7770
7660
  const data = super.toJSON(options);
@@ -8102,9 +7992,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8102
7992
  this.canvas && this.canvas.updateClientBounds();
8103
7993
  }
8104
7994
  receiveEvent(_event) { }
8105
- __checkUpdateLayout() {
8106
- this.__layout.update();
8107
- }
8108
7995
  emitLeafer(type) {
8109
7996
  this.emitEvent(new LeaferEvent(type, this));
8110
7997
  }
@@ -8115,7 +8002,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8115
8002
  this.once(LayoutEvent.END, () => this.__onReady());
8116
8003
  this.once(RenderEvent.START, () => this.__onCreated());
8117
8004
  this.once(RenderEvent.END, () => this.__onViewReady());
8118
- 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));
8005
+ this.__eventIds.push(this.on_(WatchEvent.DATA, this.__onWatchData, this), this.on_(RenderEvent.NEXT, this.__onNextRender, this));
8119
8006
  }
8120
8007
  __removeListenEvents() {
8121
8008
  this.off_(this.__eventIds);
@@ -8180,7 +8067,7 @@ Rect = __decorate([
8180
8067
  ], Rect);
8181
8068
 
8182
8069
  const { copy: copy$6, add, includes: includes$1 } = BoundsHelper;
8183
- const rect$1 = Rect.prototype, group$1 = Group.prototype;
8070
+ const rect$1 = Rect.prototype, group = Group.prototype;
8184
8071
  const childrenRenderBounds = {};
8185
8072
  let Box = class Box extends Group {
8186
8073
  get __tag() { return 'Box'; }
@@ -8290,7 +8177,7 @@ __decorate([
8290
8177
  rewrite(rect$1.__render)
8291
8178
  ], Box.prototype, "__renderRect", null);
8292
8179
  __decorate([
8293
- rewrite(group$1.__render)
8180
+ rewrite(group.__render)
8294
8181
  ], Box.prototype, "__renderGroup", null);
8295
8182
  Box = __decorate([
8296
8183
  rewriteAble(),
@@ -8771,6 +8658,9 @@ __decorate([
8771
8658
  __decorate([
8772
8659
  boundsType(0)
8773
8660
  ], Text.prototype, "paraSpacing", void 0);
8661
+ __decorate([
8662
+ boundsType('x')
8663
+ ], Text.prototype, "writingMode", void 0);
8774
8664
  __decorate([
8775
8665
  boundsType('left')
8776
8666
  ], Text.prototype, "textAlign", void 0);
@@ -8957,8 +8847,8 @@ let App = class App extends Leafer {
8957
8847
  this.children.forEach(leafer => leafer.resize(event));
8958
8848
  super.__onResize(event);
8959
8849
  }
8960
- __checkUpdateLayout() {
8961
- this.children.forEach(leafer => leafer.__layout.update());
8850
+ updateLayout() {
8851
+ this.children.forEach(leafer => leafer.updateLayout());
8962
8852
  }
8963
8853
  __getChildConfig(userConfig) {
8964
8854
  let config = Object.assign({}, this.config);
@@ -10114,21 +10004,13 @@ rect.__hitFill = box$1.__hitFill = function (inner) {
10114
10004
  return this.__hitCanvas ? ui$2.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
10115
10005
  };
10116
10006
 
10117
- const ui$1 = UI.prototype, group = Group.prototype;
10118
- function getSelector(ui) {
10007
+ function getSelector$1(ui) {
10119
10008
  return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()));
10120
10009
  }
10121
- ui$1.find = function (condition, options) {
10122
- return getSelector(this).getBy(condition, this, false, options);
10123
- };
10124
- ui$1.findOne = function (condition, options) {
10125
- return getSelector(this).getBy(condition, this, true, options);
10126
- };
10127
- group.pick = function (hitPoint, options) {
10128
- this.__layout.update();
10129
- if (!options)
10130
- options = {};
10131
- return getSelector(this).getByPoint(hitPoint, options.hitRadius || 0, Object.assign(Object.assign({}, options), { target: this }));
10010
+ Group.prototype.pick = function (hitPoint, options) {
10011
+ this.leafer || this.updateLayout();
10012
+ options || (options = emptyData);
10013
+ return getSelector$1(this).getByPoint(hitPoint, options.hitRadius || 0, Object.assign(Object.assign({}, options), { target: this }));
10132
10014
  };
10133
10015
 
10134
10016
  const canvas$1 = LeaferCanvasBase.prototype;
@@ -11631,257 +11513,72 @@ const ColorConvertModule = {
11631
11513
  string
11632
11514
  };
11633
11515
 
11634
- const { setPoint: setPoint$2, addPoint, toBounds } = TwoPointBoundsHelper;
11635
- function getTrimBounds(canvas) {
11636
- const { width, height } = canvas.view;
11637
- const { data } = canvas.context.getImageData(0, 0, width, height);
11638
- let x, y, pointBounds, index = 0;
11639
- for (let i = 0; i < data.length; i += 4) {
11640
- if (data[i + 3] !== 0) {
11641
- x = index % width;
11642
- y = (index - x) / width;
11643
- pointBounds ? addPoint(pointBounds, x, y) : setPoint$2(pointBounds = {}, x, y);
11644
- }
11645
- index++;
11516
+ Object.assign(TextConvert, TextConvertModule);
11517
+ Object.assign(ColorConvert, ColorConvertModule);
11518
+ Object.assign(Paint, PaintModule);
11519
+ Object.assign(PaintImage, PaintImageModule);
11520
+ Object.assign(PaintGradient, PaintGradientModule);
11521
+ Object.assign(Effect, EffectModule);
11522
+
11523
+ Object.assign(Creator, {
11524
+ interaction: (target, canvas, selector, options) => new InteractionBase(target, canvas, selector, options),
11525
+ hitCanvas: (options, manager) => new LeaferCanvas(options, manager),
11526
+ hitCanvasManager: () => new HitCanvasManager()
11527
+ });
11528
+ useCanvas();
11529
+
11530
+ function toList(value) {
11531
+ return value ? (value instanceof Array ? value : [value]) : [];
11532
+ }
11533
+ class EditorEvent extends Event {
11534
+ get list() { return toList(this.value); }
11535
+ get oldList() { return toList(this.oldValue); }
11536
+ constructor(type, data) {
11537
+ super(type);
11538
+ if (data)
11539
+ Object.assign(this, data);
11646
11540
  }
11647
- const bounds = new Bounds();
11648
- toBounds(pointBounds, bounds);
11649
- return bounds.scale(1 / canvas.pixelRatio).ceil();
11650
11541
  }
11542
+ EditorEvent.SELECT = 'editor.select';
11543
+ EditorEvent.HOVER = 'editor.hover';
11651
11544
 
11652
- const ExportModule = {
11653
- export(leaf, filename, options) {
11654
- this.running = true;
11655
- const fileType = FileHelper.fileType(filename);
11656
- const isDownload = filename.includes('.');
11657
- options = FileHelper.getExportOptions(options);
11658
- return addTask((success) => new Promise((resolve) => {
11659
- const over = (result) => {
11660
- success(result);
11661
- resolve();
11662
- this.running = false;
11663
- };
11664
- const { toURL } = Platform;
11665
- const { download } = Platform.origin;
11666
- if (fileType === 'json') {
11667
- isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
11668
- return over({ data: isDownload ? true : leaf.toJSON(options.json) });
11669
- }
11670
- if (fileType === 'svg') {
11671
- isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
11672
- return over({ data: isDownload ? true : leaf.toSVG() });
11673
- }
11674
- const { leafer } = leaf;
11675
- if (leafer) {
11676
- checkLazy(leaf);
11677
- leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
11678
- let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
11679
- const { worldTransform, isLeafer, isFrame } = leaf;
11680
- const { slice, trim, onCanvas } = options;
11681
- const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
11682
- const contextSettings = options.contextSettings || leafer.config.contextSettings;
11683
- const screenshot = options.screenshot || leaf.isApp;
11684
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
11685
- const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
11686
- if (screenshot) {
11687
- renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
11688
- }
11689
- else {
11690
- let relative = options.relative || (isLeafer ? 'inner' : 'local');
11691
- scaleX = worldTransform.scaleX;
11692
- scaleY = worldTransform.scaleY;
11693
- switch (relative) {
11694
- case 'inner':
11695
- matrix.set(worldTransform);
11696
- break;
11697
- case 'local':
11698
- matrix.set(worldTransform).divide(leaf.localTransform);
11699
- scaleX /= leaf.scaleX;
11700
- scaleY /= leaf.scaleY;
11701
- break;
11702
- case 'world':
11703
- scaleX = 1;
11704
- scaleY = 1;
11705
- break;
11706
- case 'page':
11707
- relative = leaf.leafer;
11708
- default:
11709
- matrix.set(worldTransform).divide(leaf.getTransform(relative));
11710
- const l = relative.worldTransform;
11711
- scaleX /= scaleX / l.scaleX;
11712
- scaleY /= scaleY / l.scaleY;
11713
- }
11714
- renderBounds = leaf.getBounds('render', relative);
11715
- }
11716
- const scaleData = { scaleX: 1, scaleY: 1 };
11717
- MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
11718
- let pixelRatio = options.pixelRatio || 1;
11719
- if (leaf.isApp) {
11720
- scaleData.scaleX *= pixelRatio;
11721
- scaleData.scaleY *= pixelRatio;
11722
- pixelRatio = leaf.app.pixelRatio;
11723
- }
11724
- const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
11725
- const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
11726
- let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
11727
- let sliceLeaf;
11728
- if (slice) {
11729
- sliceLeaf = leaf;
11730
- sliceLeaf.__worldOpacity = 0;
11731
- leaf = leafer;
11732
- renderOptions.bounds = canvas.bounds;
11733
- }
11734
- canvas.save();
11735
- if (isFrame && fill !== undefined) {
11736
- const oldFill = leaf.get('fill');
11737
- leaf.fill = '';
11738
- leaf.__render(canvas, renderOptions);
11739
- leaf.fill = oldFill;
11740
- }
11741
- else {
11742
- leaf.__render(canvas, renderOptions);
11743
- }
11744
- canvas.restore();
11745
- if (sliceLeaf)
11746
- sliceLeaf.__updateWorldOpacity();
11747
- if (trim) {
11748
- trimBounds = getTrimBounds(canvas);
11749
- const old = canvas, { width, height } = trimBounds;
11750
- const config = { x: 0, y: 0, width, height, pixelRatio };
11751
- canvas = Creator.canvas(config);
11752
- canvas.copyWorld(old, trimBounds, config);
11753
- }
11754
- if (needFill)
11755
- canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
11756
- if (onCanvas)
11757
- onCanvas(canvas);
11758
- const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
11759
- over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
11760
- }));
11761
- }
11762
- else {
11763
- over({ data: false });
11764
- }
11765
- }));
11766
- }
11767
- };
11768
- let tasker;
11769
- function addTask(task) {
11770
- if (!tasker)
11771
- tasker = new TaskProcessor();
11772
- return new Promise((resolve) => {
11773
- tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
11774
- });
11775
- }
11776
- function checkLazy(leaf) {
11777
- if (leaf.__.__needComputePaint)
11778
- leaf.__.__computePaint();
11779
- if (leaf.isBranch)
11780
- leaf.children.forEach(child => checkLazy(child));
11781
- }
11782
-
11783
- const canvas = LeaferCanvasBase.prototype;
11784
- const debug$2 = Debug.get('@leafer-ui/export');
11785
- canvas.export = function (filename, options) {
11786
- const { quality, blob } = FileHelper.getExportOptions(options);
11787
- if (filename.includes('.'))
11788
- return this.saveAs(filename, quality);
11789
- else if (blob)
11790
- return this.toBlob(filename, quality);
11791
- else
11792
- return this.toDataURL(filename, quality);
11793
- };
11794
- canvas.toBlob = function (type, quality) {
11795
- return new Promise((resolve) => {
11796
- Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
11797
- resolve(blob);
11798
- }).catch((e) => {
11799
- debug$2.error(e);
11800
- resolve(null);
11801
- });
11802
- });
11803
- };
11804
- canvas.toDataURL = function (type, quality) {
11805
- return Platform.origin.canvasToDataURL(this.view, type, quality);
11806
- };
11807
- canvas.saveAs = function (filename, quality) {
11808
- return new Promise((resolve) => {
11809
- Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
11810
- resolve(true);
11811
- }).catch((e) => {
11812
- debug$2.error(e);
11813
- resolve(false);
11814
- });
11815
- });
11816
- };
11817
-
11818
- Object.assign(TextConvert, TextConvertModule);
11819
- Object.assign(ColorConvert, ColorConvertModule);
11820
- Object.assign(Paint, PaintModule);
11821
- Object.assign(PaintImage, PaintImageModule);
11822
- Object.assign(PaintGradient, PaintGradientModule);
11823
- Object.assign(Effect, EffectModule);
11824
- Object.assign(Export, ExportModule);
11825
-
11826
- Object.assign(Creator, {
11827
- interaction: (target, canvas, selector, options) => new InteractionBase(target, canvas, selector, options),
11828
- hitCanvas: (options, manager) => new LeaferCanvas(options, manager),
11829
- hitCanvasManager: () => new HitCanvasManager()
11830
- });
11831
- useCanvas();
11832
-
11833
- function toList(value) {
11834
- return value ? (value instanceof Array ? value : [value]) : [];
11835
- }
11836
- class EditorEvent extends Event {
11837
- get list() { return toList(this.value); }
11838
- get oldList() { return toList(this.oldValue); }
11839
- constructor(type, data) {
11840
- super(type);
11841
- if (data)
11842
- Object.assign(this, data);
11843
- }
11844
- }
11845
- EditorEvent.SELECT = 'editor.select';
11846
- EditorEvent.HOVER = 'editor.hover';
11847
-
11848
- class EditorMoveEvent extends EditorEvent {
11849
- constructor(type, data) {
11850
- super(type, data);
11851
- }
11852
- }
11853
- EditorMoveEvent.MOVE = 'editor.move';
11854
-
11855
- class EditorScaleEvent extends EditorEvent {
11856
- constructor(type, data) {
11857
- super(type, data);
11858
- }
11859
- }
11860
- EditorScaleEvent.SCALE = 'editor.scale';
11861
-
11862
- class EditorRotateEvent extends EditorEvent {
11863
- constructor(type, data) {
11864
- super(type, data);
11865
- }
11866
- }
11867
- EditorRotateEvent.ROTATE = 'editor.rotate';
11868
-
11869
- class EditorSkewEvent extends EditorEvent {
11870
- constructor(type, data) {
11871
- super(type, data);
11872
- }
11873
- }
11874
- EditorSkewEvent.SKEW = 'editor.skew';
11875
-
11876
- function targetAttr(fn) {
11877
- return (target, key) => {
11878
- const privateKey = '_' + key;
11879
- defineKey(target, key, {
11880
- get() { return this[privateKey]; },
11881
- set(value) {
11882
- const old = this[privateKey];
11883
- if (old !== value)
11884
- this[privateKey] = value, fn(this, old);
11545
+ class EditorMoveEvent extends EditorEvent {
11546
+ constructor(type, data) {
11547
+ super(type, data);
11548
+ }
11549
+ }
11550
+ EditorMoveEvent.MOVE = 'editor.move';
11551
+
11552
+ class EditorScaleEvent extends EditorEvent {
11553
+ constructor(type, data) {
11554
+ super(type, data);
11555
+ }
11556
+ }
11557
+ EditorScaleEvent.SCALE = 'editor.scale';
11558
+
11559
+ class EditorRotateEvent extends EditorEvent {
11560
+ constructor(type, data) {
11561
+ super(type, data);
11562
+ }
11563
+ }
11564
+ EditorRotateEvent.ROTATE = 'editor.rotate';
11565
+
11566
+ class EditorSkewEvent extends EditorEvent {
11567
+ constructor(type, data) {
11568
+ super(type, data);
11569
+ }
11570
+ }
11571
+ EditorSkewEvent.SKEW = 'editor.skew';
11572
+
11573
+ function targetAttr(fn) {
11574
+ return (target, key) => {
11575
+ const privateKey = '_' + key;
11576
+ defineKey(target, key, {
11577
+ get() { return this[privateKey]; },
11578
+ set(value) {
11579
+ const old = this[privateKey];
11580
+ if (old !== value)
11581
+ this[privateKey] = value, fn(this, old);
11885
11582
  }
11886
11583
  });
11887
11584
  };
@@ -11985,7 +11682,7 @@ class SelectArea extends Group {
11985
11682
  }
11986
11683
  }
11987
11684
 
11988
- const { No, Yes, NoAndSkip, YesAndSkip } = Answer;
11685
+ const { No, Yes: Yes$1, NoAndSkip: NoAndSkip$1, YesAndSkip: YesAndSkip$1 } = Answer;
11989
11686
  const EditSelectHelper = {
11990
11687
  findOne(path) {
11991
11688
  return path.list.find((leaf) => leaf.editable);
@@ -11994,20 +11691,20 @@ const EditSelectHelper = {
11994
11691
  if (leaf.__.hittable && leaf.__.visible && !leaf.__.locked && bounds.hit(leaf.__world)) {
11995
11692
  if (leaf.__.editable) {
11996
11693
  if (leaf.isBranch && !leaf.__.hitChildren) {
11997
- return leaf.__.hitSelf ? YesAndSkip : NoAndSkip;
11694
+ return leaf.__.hitSelf ? YesAndSkip$1 : NoAndSkip$1;
11998
11695
  }
11999
11696
  else if (leaf.isFrame) {
12000
- return bounds.includes(leaf.__layout.boxBounds, leaf.__world) ? YesAndSkip : No;
11697
+ return bounds.includes(leaf.__layout.boxBounds, leaf.__world) ? YesAndSkip$1 : No;
12001
11698
  }
12002
11699
  else {
12003
11700
  if (bounds.hit(leaf.__layout.boxBounds, leaf.__world) && leaf.__.hitSelf)
12004
- return Yes;
11701
+ return Yes$1;
12005
11702
  }
12006
11703
  }
12007
11704
  return No;
12008
11705
  }
12009
11706
  else {
12010
- return leaf.isBranch ? NoAndSkip : No;
11707
+ return leaf.isBranch ? NoAndSkip$1 : No;
12011
11708
  }
12012
11709
  }
12013
11710
  };
@@ -12171,7 +11868,7 @@ class EditSelect extends Group {
12171
11868
  return target.leafer !== this.editor.leafer;
12172
11869
  }
12173
11870
  allowDrag(e) {
12174
- if (this.running && this.editor.mergeConfig.boxSelect && !e.target.draggable) {
11871
+ if (this.running && (this.editor.mergeConfig.boxSelect && Plugin.has('find')) && !e.target.draggable) {
12175
11872
  return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path));
12176
11873
  }
12177
11874
  else {
@@ -12966,7 +12663,7 @@ const EditorHelper = {
12966
12663
  }
12967
12664
  };
12968
12665
 
12969
- const debug$1 = Debug.get('EditToolCreator');
12666
+ const debug$2 = Debug.get('EditToolCreator');
12970
12667
  function registerEditTool() {
12971
12668
  return (target) => {
12972
12669
  EditToolCreator.register(target);
@@ -12977,7 +12674,7 @@ const EditToolCreator = {
12977
12674
  list: {},
12978
12675
  register(EditTool) {
12979
12676
  const { tag } = EditTool.prototype;
12980
- list$1[tag] && debug$1.repeat(tag);
12677
+ list$1[tag] && debug$2.repeat(tag);
12981
12678
  list$1[tag] = EditTool;
12982
12679
  },
12983
12680
  get(tag, editor) {
@@ -13094,7 +12791,7 @@ class Editor extends Group {
13094
12791
  if (userConfig)
13095
12792
  this.config = DataHelper.default(userConfig, this.config);
13096
12793
  this.addMany(this.editMask, this.selector, this.editBox);
13097
- if (!Plugin.check('resize', true))
12794
+ if (!Plugin.has('resize'))
13098
12795
  this.config.editSize = 'scale';
13099
12796
  }
13100
12797
  select(target) {
@@ -13887,7 +13584,153 @@ Box.prototype.__scaleResize = function (scaleX, scaleY) {
13887
13584
 
13888
13585
  Plugin.add('resize');
13889
13586
 
13890
- Plugin.add('editor');
13587
+ const { Yes, NoAndSkip, YesAndSkip } = Answer;
13588
+ const idCondition = {}, classNameCondition = {}, tagCondition = {};
13589
+ class Finder {
13590
+ constructor(target) {
13591
+ this.innerIdMap = {};
13592
+ this.idMap = {};
13593
+ this.methods = {
13594
+ id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,
13595
+ innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,
13596
+ className: (leaf, name) => leaf.className === name ? 1 : 0,
13597
+ tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
13598
+ tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
13599
+ };
13600
+ if (this.target = target)
13601
+ this.__listenEvents();
13602
+ }
13603
+ getBy(condition, branch, one, options) {
13604
+ switch (typeof condition) {
13605
+ case 'number':
13606
+ const leaf = this.getByInnerId(condition, branch);
13607
+ return one ? leaf : (leaf ? [leaf] : []);
13608
+ case 'string':
13609
+ switch (condition[0]) {
13610
+ case '#':
13611
+ idCondition.id = condition.substring(1), condition = idCondition;
13612
+ break;
13613
+ case '.':
13614
+ classNameCondition.className = condition.substring(1), condition = classNameCondition;
13615
+ break;
13616
+ default:
13617
+ tagCondition.tag = condition, condition = tagCondition;
13618
+ }
13619
+ case 'object':
13620
+ if (condition.id !== undefined) {
13621
+ const leaf = this.getById(condition.id, branch);
13622
+ return one ? leaf : (leaf ? [leaf] : []);
13623
+ }
13624
+ else if (condition.tag) {
13625
+ const { tag } = condition, isArray = tag instanceof Array;
13626
+ return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag);
13627
+ }
13628
+ else {
13629
+ return this.getByMethod(this.methods.className, branch, one, condition.className);
13630
+ }
13631
+ case 'function':
13632
+ return this.getByMethod(condition, branch, one, options);
13633
+ }
13634
+ }
13635
+ getByInnerId(innerId, branch) {
13636
+ const cache = this.innerIdMap[innerId];
13637
+ if (cache)
13638
+ return cache;
13639
+ this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
13640
+ return this.findLeaf;
13641
+ }
13642
+ getById(id, branch) {
13643
+ const cache = this.idMap[id];
13644
+ if (cache && LeafHelper.hasParent(cache, branch || this.target))
13645
+ return cache;
13646
+ this.eachFind(this.toChildren(branch), this.methods.id, null, id);
13647
+ return this.findLeaf;
13648
+ }
13649
+ getByClassName(className, branch) {
13650
+ return this.getByMethod(this.methods.className, branch, false, className);
13651
+ }
13652
+ getByTag(tag, branch) {
13653
+ return this.getByMethod(this.methods.tag, branch, false, tag);
13654
+ }
13655
+ getByMethod(method, branch, one, options) {
13656
+ const list = one ? null : [];
13657
+ this.eachFind(this.toChildren(branch), method, list, options);
13658
+ return list || this.findLeaf;
13659
+ }
13660
+ eachFind(children, method, list, options) {
13661
+ let child, result;
13662
+ for (let i = 0, len = children.length; i < len; i++) {
13663
+ child = children[i];
13664
+ result = method(child, options);
13665
+ if (result === Yes || result === YesAndSkip) {
13666
+ if (list) {
13667
+ list.push(child);
13668
+ }
13669
+ else {
13670
+ this.findLeaf = child;
13671
+ return;
13672
+ }
13673
+ }
13674
+ if (child.isBranch && result < NoAndSkip)
13675
+ this.eachFind(child.children, method, list, options);
13676
+ }
13677
+ }
13678
+ toChildren(branch) {
13679
+ this.findLeaf = null;
13680
+ return [branch || this.target];
13681
+ }
13682
+ __onRemoveChild(event) {
13683
+ const { id, innerId } = event.child;
13684
+ if (this.idMap[id])
13685
+ delete this.idMap[id];
13686
+ if (this.innerIdMap[innerId])
13687
+ delete this.innerIdMap[innerId];
13688
+ }
13689
+ __checkIdChange(event) {
13690
+ if (event.attrName === 'id') {
13691
+ const id = event.oldValue;
13692
+ if (this.idMap[id])
13693
+ delete this.idMap[id];
13694
+ }
13695
+ }
13696
+ __listenEvents() {
13697
+ this.__eventIds = [
13698
+ this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),
13699
+ this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)
13700
+ ];
13701
+ }
13702
+ __removeListenEvents() {
13703
+ this.target.off_(this.__eventIds);
13704
+ this.__eventIds.length = 0;
13705
+ }
13706
+ destroy() {
13707
+ const { __eventIds } = this;
13708
+ if (__eventIds && __eventIds.length) {
13709
+ this.__removeListenEvents();
13710
+ this.innerIdMap = {};
13711
+ this.idMap = {};
13712
+ }
13713
+ this.findLeaf = null;
13714
+ }
13715
+ }
13716
+
13717
+ const ui$1 = UI.prototype;
13718
+ function getSelector(ui) {
13719
+ return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()));
13720
+ }
13721
+ ui$1.find = function (condition, options) {
13722
+ return getSelector(this).getBy(condition, this, false, options);
13723
+ };
13724
+ ui$1.findOne = function (condition, options) {
13725
+ return getSelector(this).getBy(condition, this, true, options);
13726
+ };
13727
+
13728
+ Plugin.add('find');
13729
+ Creator.finder = function (target) {
13730
+ return new Finder(target);
13731
+ };
13732
+
13733
+ Plugin.add('editor', 'resize', 'find');
13891
13734
  Creator.editor = function (options) { return new Editor(options); };
13892
13735
  dataType(false)(Box.prototype, 'textBox');
13893
13736
  defineKey(UI.prototype, 'editOuter', {
@@ -13968,11 +13811,11 @@ function document$1(leafer) {
13968
13811
  });
13969
13812
  }
13970
13813
 
13971
- const debug = Debug.get('LeaferTypeCreator');
13814
+ const debug$1 = Debug.get('LeaferTypeCreator');
13972
13815
  const LeaferTypeCreator = {
13973
13816
  list: {},
13974
13817
  register(name, fn) {
13975
- list[name] && debug.repeat(name);
13818
+ list[name] && debug$1.repeat(name);
13976
13819
  list[name] = fn;
13977
13820
  },
13978
13821
  run(name, leafer) {
@@ -14497,17 +14340,17 @@ const PathMatrixHelper = {
14497
14340
  switch (command) {
14498
14341
  case M$1:
14499
14342
  case L$1:
14500
- setPoint$1(data, i + 1, x, y, scaleX, scaleY, rotation, origin);
14343
+ setPoint$2(data, i + 1, x, y, scaleX, scaleY, rotation, origin);
14501
14344
  i += 3;
14502
14345
  break;
14503
14346
  case C$1:
14504
14347
  for (j = 1; j < 6; j += 2)
14505
- setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14348
+ setPoint$2(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14506
14349
  i += 7;
14507
14350
  break;
14508
14351
  case Q$1:
14509
14352
  for (j = 1; j < 4; j += 2)
14510
- setPoint$1(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14353
+ setPoint$2(data, i + j, x, y, scaleX, scaleY, rotation, origin);
14511
14354
  i += 5;
14512
14355
  break;
14513
14356
  case O$1:
@@ -14528,7 +14371,7 @@ const PathMatrixHelper = {
14528
14371
  PathMatrixHelper.layout(data, 0, 0, 1, 1, rotation, center);
14529
14372
  }
14530
14373
  };
14531
- function setPoint$1(data, startIndex, x, y, scaleX, scaleY, rotation, origin) {
14374
+ function setPoint$2(data, startIndex, x, y, scaleX, scaleY, rotation, origin) {
14532
14375
  copyFrom$1(point, data[startIndex], data[startIndex + 1]);
14533
14376
  if (rotation)
14534
14377
  rotate$1(point, rotation, origin);
@@ -14694,7 +14537,7 @@ const PathArrowModule = {
14694
14537
  break;
14695
14538
  }
14696
14539
  if (index)
14697
- setPoint(path, last, index);
14540
+ setPoint$1(path, last, index);
14698
14541
  }
14699
14542
  }
14700
14543
  }
@@ -14708,7 +14551,7 @@ function copyPoints(data, from, to, startIndex) {
14708
14551
  copyFrom(from, data[startIndex], data[startIndex + 1]);
14709
14552
  copyFrom(to, data[startIndex + 2], data[startIndex + 3]);
14710
14553
  }
14711
- function setPoint(data, point, startIndex) {
14554
+ function setPoint$1(data, point, startIndex) {
14712
14555
  data[startIndex] = point.x;
14713
14556
  data[startIndex + 1] = point.y;
14714
14557
  }
@@ -14731,6 +14574,196 @@ arrowType('none')(ui, 'startArrow');
14731
14574
  arrowType('none')(ui, 'endArrow');
14732
14575
  Object.assign(PathArrow, PathArrowModule);
14733
14576
 
14577
+ const { setPoint, addPoint, toBounds } = TwoPointBoundsHelper;
14578
+ function getTrimBounds(canvas) {
14579
+ const { width, height } = canvas.view;
14580
+ const { data } = canvas.context.getImageData(0, 0, width, height);
14581
+ let x, y, pointBounds, index = 0;
14582
+ for (let i = 0; i < data.length; i += 4) {
14583
+ if (data[i + 3] !== 0) {
14584
+ x = index % width;
14585
+ y = (index - x) / width;
14586
+ pointBounds ? addPoint(pointBounds, x, y) : setPoint(pointBounds = {}, x, y);
14587
+ }
14588
+ index++;
14589
+ }
14590
+ const bounds = new Bounds();
14591
+ toBounds(pointBounds, bounds);
14592
+ return bounds.scale(1 / canvas.pixelRatio).ceil();
14593
+ }
14594
+
14595
+ const ExportModule = {
14596
+ export(leaf, filename, options) {
14597
+ this.running = true;
14598
+ const fileType = FileHelper.fileType(filename);
14599
+ const isDownload = filename.includes('.');
14600
+ options = FileHelper.getExportOptions(options);
14601
+ return addTask((success) => new Promise((resolve) => {
14602
+ const over = (result) => {
14603
+ success(result);
14604
+ resolve();
14605
+ this.running = false;
14606
+ };
14607
+ const { toURL } = Platform;
14608
+ const { download } = Platform.origin;
14609
+ if (fileType === 'json') {
14610
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
14611
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
14612
+ }
14613
+ if (fileType === 'svg') {
14614
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
14615
+ return over({ data: isDownload ? true : leaf.toSVG() });
14616
+ }
14617
+ const { leafer } = leaf;
14618
+ if (leafer) {
14619
+ checkLazy(leaf);
14620
+ leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
14621
+ let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
14622
+ const { worldTransform, isLeafer, isFrame } = leaf;
14623
+ const { slice, trim, onCanvas } = options;
14624
+ const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
14625
+ const contextSettings = options.contextSettings || leafer.config.contextSettings;
14626
+ const screenshot = options.screenshot || leaf.isApp;
14627
+ const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
14628
+ const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
14629
+ if (screenshot) {
14630
+ renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
14631
+ }
14632
+ else {
14633
+ let relative = options.relative || (isLeafer ? 'inner' : 'local');
14634
+ scaleX = worldTransform.scaleX;
14635
+ scaleY = worldTransform.scaleY;
14636
+ switch (relative) {
14637
+ case 'inner':
14638
+ matrix.set(worldTransform);
14639
+ break;
14640
+ case 'local':
14641
+ matrix.set(worldTransform).divide(leaf.localTransform);
14642
+ scaleX /= leaf.scaleX;
14643
+ scaleY /= leaf.scaleY;
14644
+ break;
14645
+ case 'world':
14646
+ scaleX = 1;
14647
+ scaleY = 1;
14648
+ break;
14649
+ case 'page':
14650
+ relative = leaf.leafer;
14651
+ default:
14652
+ matrix.set(worldTransform).divide(leaf.getTransform(relative));
14653
+ const l = relative.worldTransform;
14654
+ scaleX /= scaleX / l.scaleX;
14655
+ scaleY /= scaleY / l.scaleY;
14656
+ }
14657
+ renderBounds = leaf.getBounds('render', relative);
14658
+ }
14659
+ const scaleData = { scaleX: 1, scaleY: 1 };
14660
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
14661
+ let pixelRatio = options.pixelRatio || 1;
14662
+ if (leaf.isApp) {
14663
+ scaleData.scaleX *= pixelRatio;
14664
+ scaleData.scaleY *= pixelRatio;
14665
+ pixelRatio = leaf.app.pixelRatio;
14666
+ }
14667
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
14668
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
14669
+ let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
14670
+ let sliceLeaf;
14671
+ if (slice) {
14672
+ sliceLeaf = leaf;
14673
+ sliceLeaf.__worldOpacity = 0;
14674
+ leaf = leafer;
14675
+ renderOptions.bounds = canvas.bounds;
14676
+ }
14677
+ canvas.save();
14678
+ if (isFrame && fill !== undefined) {
14679
+ const oldFill = leaf.get('fill');
14680
+ leaf.fill = '';
14681
+ leaf.__render(canvas, renderOptions);
14682
+ leaf.fill = oldFill;
14683
+ }
14684
+ else {
14685
+ leaf.__render(canvas, renderOptions);
14686
+ }
14687
+ canvas.restore();
14688
+ if (sliceLeaf)
14689
+ sliceLeaf.__updateWorldOpacity();
14690
+ if (trim) {
14691
+ trimBounds = getTrimBounds(canvas);
14692
+ const old = canvas, { width, height } = trimBounds;
14693
+ const config = { x: 0, y: 0, width, height, pixelRatio };
14694
+ canvas = Creator.canvas(config);
14695
+ canvas.copyWorld(old, trimBounds, config);
14696
+ }
14697
+ if (needFill)
14698
+ canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
14699
+ if (onCanvas)
14700
+ onCanvas(canvas);
14701
+ const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
14702
+ over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
14703
+ }));
14704
+ }
14705
+ else {
14706
+ over({ data: false });
14707
+ }
14708
+ }));
14709
+ }
14710
+ };
14711
+ let tasker;
14712
+ function addTask(task) {
14713
+ if (!tasker)
14714
+ tasker = new TaskProcessor();
14715
+ return new Promise((resolve) => {
14716
+ tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
14717
+ });
14718
+ }
14719
+ function checkLazy(leaf) {
14720
+ if (leaf.__.__needComputePaint)
14721
+ leaf.__.__computePaint();
14722
+ if (leaf.isBranch)
14723
+ leaf.children.forEach(child => checkLazy(child));
14724
+ }
14725
+
14726
+ const canvas = LeaferCanvasBase.prototype;
14727
+ const debug = Debug.get('@leafer-in/export');
14728
+ canvas.export = function (filename, options) {
14729
+ const { quality, blob } = FileHelper.getExportOptions(options);
14730
+ if (filename.includes('.'))
14731
+ return this.saveAs(filename, quality);
14732
+ else if (blob)
14733
+ return this.toBlob(filename, quality);
14734
+ else
14735
+ return this.toDataURL(filename, quality);
14736
+ };
14737
+ canvas.toBlob = function (type, quality) {
14738
+ return new Promise((resolve) => {
14739
+ Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
14740
+ resolve(blob);
14741
+ }).catch((e) => {
14742
+ debug.error(e);
14743
+ resolve(null);
14744
+ });
14745
+ });
14746
+ };
14747
+ canvas.toDataURL = function (type, quality) {
14748
+ return Platform.origin.canvasToDataURL(this.view, type, quality);
14749
+ };
14750
+ canvas.saveAs = function (filename, quality) {
14751
+ return new Promise((resolve) => {
14752
+ Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
14753
+ resolve(true);
14754
+ }).catch((e) => {
14755
+ debug.error(e);
14756
+ resolve(false);
14757
+ });
14758
+ });
14759
+ };
14760
+
14761
+ Plugin.add('export');
14762
+ Object.assign(Export, ExportModule);
14763
+ UI.prototype.export = function (filename, options) {
14764
+ return Export.export(this, filename, options);
14765
+ };
14766
+
14734
14767
  const textCaseMap = {
14735
14768
  'none': 'none',
14736
14769
  'title': 'capitalize',
@@ -14933,8 +14966,7 @@ TextEditor = __decorate([
14933
14966
  registerInnerEditor()
14934
14967
  ], TextEditor);
14935
14968
 
14936
- Plugin.add('text-editor');
14937
- setTimeout(() => Plugin.check('editor', true));
14969
+ Plugin.add('text-editor', 'editor');
14938
14970
 
14939
14971
  class HTMLTextData extends ImageData {
14940
14972
  setText(value) {
@@ -14996,4 +15028,4 @@ HTMLText = __decorate([
14996
15028
 
14997
15029
  Plugin.add('html');
14998
15030
 
14999
- export { AlignHelper, Answer, App, AroundHelper, Arrow, ArrowData, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, Dragger, DropEvent, EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Frame, FrameData, Group, GroupData, HTMLText, HTMLTextData, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, LineEditTool, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, MyDragEvent, MyImage, MyPointerEvent, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathArrowModule, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathMatrixHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Plugin, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, RotateEvent, Run, ScrollBar, SelectArea, Selector, Star, StarData, State, StringNumberMap, Stroker, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TextEditor, Transformer, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, WheelEventHelper, ZoomEvent, addViewport, addViewportConfig, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isNull, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerEditTool, registerInnerEditor, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };
15031
+ export { AlignHelper, Answer, App, AroundHelper, Arrow, ArrowData, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, Dragger, DropEvent, EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Finder, Frame, FrameData, Group, GroupData, HTMLText, HTMLTextData, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, LineEditTool, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, MyDragEvent, MyImage, MyPointerEvent, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathArrowModule, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathMatrixHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Picker, Platform, Plugin, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, RotateEvent, Run, ScrollBar, SelectArea, Selector, Star, StarData, State, StringNumberMap, Stroker, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TextEditor, Transformer, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, WheelEventHelper, ZoomEvent, addViewport, addViewportConfig, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isNull, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerEditTool, registerInnerEditor, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };