@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.cjs +7 -0
- package/dist/worker.esm.js +1 -0
- package/dist/worker.esm.min.js +1 -1
- package/dist/worker.js +296 -400
- package/dist/worker.min.cjs +1 -1
- package/dist/worker.min.js +1 -1
- package/dist/worker.module.js +296 -401
- package/dist/worker.module.min.js +1 -1
- package/package.json +14 -13
package/dist/worker.module.js
CHANGED
|
@@ -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
|
-
|
|
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 = {
|
|
@@ -2047,11 +2050,11 @@ class LeaferCanvasBase extends Canvas$1 {
|
|
|
2047
2050
|
toBlob(_type, _quality) { return undefined; }
|
|
2048
2051
|
toDataURL(_type, _quality) { return undefined; }
|
|
2049
2052
|
saveAs(_filename, _quality) { return undefined; }
|
|
2050
|
-
resize(size) {
|
|
2053
|
+
resize(size, safeResize = true) {
|
|
2051
2054
|
if (this.isSameSize(size))
|
|
2052
2055
|
return;
|
|
2053
2056
|
let takeCanvas;
|
|
2054
|
-
if (this.context && !this.unreal && this.width) {
|
|
2057
|
+
if (this.context && !this.unreal && safeResize && this.width) {
|
|
2055
2058
|
takeCanvas = this.getSameCanvas();
|
|
2056
2059
|
takeCanvas.copyWorld(this);
|
|
2057
2060
|
}
|
|
@@ -4253,18 +4256,21 @@ const LeafHelper = {
|
|
|
4253
4256
|
L$3.setTransform(t, matrix$3, resize);
|
|
4254
4257
|
},
|
|
4255
4258
|
setTransform(t, transform, resize) {
|
|
4256
|
-
const
|
|
4259
|
+
const data = t.__, originPoint = data.origin && L$3.getInnerOrigin(t, data.origin);
|
|
4260
|
+
const layout = getLayout(transform, originPoint, data.around && L$3.getInnerOrigin(t, data.around));
|
|
4257
4261
|
if (resize) {
|
|
4258
|
-
const scaleX = layout.scaleX / t.scaleX;
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
+
const scaleX = layout.scaleX / t.scaleX, scaleY = layout.scaleY / t.scaleY;
|
|
4263
|
+
delete layout.scaleX, delete layout.scaleY;
|
|
4264
|
+
if (originPoint) {
|
|
4265
|
+
BoundsHelper.scale(t.boxBounds, Math.abs(scaleX), Math.abs(scaleY));
|
|
4266
|
+
const changedPoint = L$3.getInnerOrigin(t, data.origin);
|
|
4267
|
+
PointHelper.move(layout, originPoint.x - changedPoint.x, originPoint.y - changedPoint.y);
|
|
4268
|
+
}
|
|
4262
4269
|
t.set(layout);
|
|
4263
|
-
t.scaleResize(scaleX, scaleY,
|
|
4270
|
+
t.scaleResize(scaleX, scaleY, false);
|
|
4264
4271
|
}
|
|
4265
|
-
else
|
|
4272
|
+
else
|
|
4266
4273
|
t.set(layout);
|
|
4267
|
-
}
|
|
4268
4274
|
},
|
|
4269
4275
|
getFlipTransform(t, axis) {
|
|
4270
4276
|
const m = getMatrixData();
|
|
@@ -4805,7 +4811,6 @@ class LayoutEvent extends Event {
|
|
|
4805
4811
|
}
|
|
4806
4812
|
}
|
|
4807
4813
|
}
|
|
4808
|
-
LayoutEvent.CHECK_UPDATE = 'layout.check_update';
|
|
4809
4814
|
LayoutEvent.REQUEST = 'layout.request';
|
|
4810
4815
|
LayoutEvent.START = 'layout.start';
|
|
4811
4816
|
LayoutEvent.BEFORE = 'layout.before';
|
|
@@ -4947,14 +4952,15 @@ class Eventer {
|
|
|
4947
4952
|
if (list) {
|
|
4948
4953
|
let item;
|
|
4949
4954
|
for (let i = 0, len = list.length; i < len; i++) {
|
|
4950
|
-
item = list[i]
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
+
if (item = list[i]) {
|
|
4956
|
+
item.listener(event);
|
|
4957
|
+
if (item.once) {
|
|
4958
|
+
this.off(type, item.listener, capture);
|
|
4959
|
+
i--, len--;
|
|
4960
|
+
}
|
|
4961
|
+
if (event && event.isStopNow)
|
|
4962
|
+
break;
|
|
4955
4963
|
}
|
|
4956
|
-
if (event && event.isStopNow)
|
|
4957
|
-
break;
|
|
4958
4964
|
}
|
|
4959
4965
|
}
|
|
4960
4966
|
this.syncEventer && this.syncEventer.emitEvent(event, capture);
|
|
@@ -6001,7 +6007,7 @@ class LeafLevelList {
|
|
|
6001
6007
|
}
|
|
6002
6008
|
}
|
|
6003
6009
|
|
|
6004
|
-
const version = "1.
|
|
6010
|
+
const version = "1.3.0";
|
|
6005
6011
|
|
|
6006
6012
|
class LeaferCanvas extends LeaferCanvasBase {
|
|
6007
6013
|
get allowBackgroundColor() { return true; }
|
|
@@ -6069,6 +6075,7 @@ function useCanvas(_canvasType, _power) {
|
|
|
6069
6075
|
}
|
|
6070
6076
|
Platform.name = 'web';
|
|
6071
6077
|
Platform.isWorker = true;
|
|
6078
|
+
Platform.backgrounder = true;
|
|
6072
6079
|
Platform.requestRender = function (render) { requestAnimationFrame(render); };
|
|
6073
6080
|
defineKey(Platform, 'devicePixelRatio', { get() { return 1; } });
|
|
6074
6081
|
const { userAgent } = navigator;
|
|
@@ -6801,143 +6808,26 @@ class Picker {
|
|
|
6801
6808
|
}
|
|
6802
6809
|
}
|
|
6803
6810
|
|
|
6804
|
-
const { Yes: Yes$1, NoAndSkip: NoAndSkip$1, YesAndSkip: YesAndSkip$1 } = Answer;
|
|
6805
|
-
const idCondition = {}, classNameCondition = {}, tagCondition = {};
|
|
6806
6811
|
class Selector {
|
|
6807
6812
|
constructor(target, userConfig) {
|
|
6808
6813
|
this.config = {};
|
|
6809
|
-
this.innerIdMap = {};
|
|
6810
|
-
this.idMap = {};
|
|
6811
|
-
this.methods = {
|
|
6812
|
-
id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,
|
|
6813
|
-
innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,
|
|
6814
|
-
className: (leaf, name) => leaf.className === name ? 1 : 0,
|
|
6815
|
-
tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
|
|
6816
|
-
tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
|
|
6817
|
-
};
|
|
6818
|
-
this.target = target;
|
|
6819
6814
|
if (userConfig)
|
|
6820
6815
|
this.config = DataHelper.default(userConfig, this.config);
|
|
6821
|
-
this.picker = new Picker(target, this);
|
|
6822
|
-
|
|
6823
|
-
this.__listenEvents();
|
|
6824
|
-
}
|
|
6825
|
-
getBy(condition, branch, one, options) {
|
|
6826
|
-
switch (typeof condition) {
|
|
6827
|
-
case 'number':
|
|
6828
|
-
const leaf = this.getByInnerId(condition, branch);
|
|
6829
|
-
return one ? leaf : (leaf ? [leaf] : []);
|
|
6830
|
-
case 'string':
|
|
6831
|
-
switch (condition[0]) {
|
|
6832
|
-
case '#':
|
|
6833
|
-
idCondition.id = condition.substring(1), condition = idCondition;
|
|
6834
|
-
break;
|
|
6835
|
-
case '.':
|
|
6836
|
-
classNameCondition.className = condition.substring(1), condition = classNameCondition;
|
|
6837
|
-
break;
|
|
6838
|
-
default:
|
|
6839
|
-
tagCondition.tag = condition, condition = tagCondition;
|
|
6840
|
-
}
|
|
6841
|
-
case 'object':
|
|
6842
|
-
if (condition.id !== undefined) {
|
|
6843
|
-
const leaf = this.getById(condition.id, branch);
|
|
6844
|
-
return one ? leaf : (leaf ? [leaf] : []);
|
|
6845
|
-
}
|
|
6846
|
-
else if (condition.tag) {
|
|
6847
|
-
const { tag } = condition, isArray = tag instanceof Array;
|
|
6848
|
-
return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag);
|
|
6849
|
-
}
|
|
6850
|
-
else {
|
|
6851
|
-
return this.getByMethod(this.methods.className, branch, one, condition.className);
|
|
6852
|
-
}
|
|
6853
|
-
case 'function':
|
|
6854
|
-
return this.getByMethod(condition, branch, one, options);
|
|
6855
|
-
}
|
|
6816
|
+
this.picker = new Picker(this.target = target, this);
|
|
6817
|
+
this.finder = Creator.finder && Creator.finder();
|
|
6856
6818
|
}
|
|
6857
6819
|
getByPoint(hitPoint, hitRadius, options) {
|
|
6858
|
-
if (Platform.
|
|
6859
|
-
this.target.
|
|
6820
|
+
if (Platform.backgrounder && this.target)
|
|
6821
|
+
this.target.updateLayout();
|
|
6860
6822
|
return this.picker.getByPoint(hitPoint, hitRadius, options);
|
|
6861
6823
|
}
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
if (cache)
|
|
6865
|
-
return cache;
|
|
6866
|
-
this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
|
|
6867
|
-
return this.findLeaf;
|
|
6868
|
-
}
|
|
6869
|
-
getById(id, branch) {
|
|
6870
|
-
const cache = this.idMap[id];
|
|
6871
|
-
if (cache && LeafHelper.hasParent(cache, branch || this.target))
|
|
6872
|
-
return cache;
|
|
6873
|
-
this.eachFind(this.toChildren(branch), this.methods.id, null, id);
|
|
6874
|
-
return this.findLeaf;
|
|
6875
|
-
}
|
|
6876
|
-
getByClassName(className, branch) {
|
|
6877
|
-
return this.getByMethod(this.methods.className, branch, false, className);
|
|
6878
|
-
}
|
|
6879
|
-
getByTag(tag, branch) {
|
|
6880
|
-
return this.getByMethod(this.methods.tag, branch, false, tag);
|
|
6881
|
-
}
|
|
6882
|
-
getByMethod(method, branch, one, options) {
|
|
6883
|
-
const list = one ? null : [];
|
|
6884
|
-
this.eachFind(this.toChildren(branch), method, list, options);
|
|
6885
|
-
return list || this.findLeaf;
|
|
6886
|
-
}
|
|
6887
|
-
eachFind(children, method, list, options) {
|
|
6888
|
-
let child, result;
|
|
6889
|
-
for (let i = 0, len = children.length; i < len; i++) {
|
|
6890
|
-
child = children[i];
|
|
6891
|
-
result = method(child, options);
|
|
6892
|
-
if (result === Yes$1 || result === YesAndSkip$1) {
|
|
6893
|
-
if (list) {
|
|
6894
|
-
list.push(child);
|
|
6895
|
-
}
|
|
6896
|
-
else {
|
|
6897
|
-
this.findLeaf = child;
|
|
6898
|
-
return;
|
|
6899
|
-
}
|
|
6900
|
-
}
|
|
6901
|
-
if (child.isBranch && result < NoAndSkip$1)
|
|
6902
|
-
this.eachFind(child.children, method, list, options);
|
|
6903
|
-
}
|
|
6904
|
-
}
|
|
6905
|
-
toChildren(branch) {
|
|
6906
|
-
this.findLeaf = null;
|
|
6907
|
-
return [branch || this.target];
|
|
6908
|
-
}
|
|
6909
|
-
__onRemoveChild(event) {
|
|
6910
|
-
const { id, innerId } = event.child;
|
|
6911
|
-
if (this.idMap[id])
|
|
6912
|
-
delete this.idMap[id];
|
|
6913
|
-
if (this.innerIdMap[innerId])
|
|
6914
|
-
delete this.innerIdMap[innerId];
|
|
6915
|
-
}
|
|
6916
|
-
__checkIdChange(event) {
|
|
6917
|
-
if (event.attrName === 'id') {
|
|
6918
|
-
const id = event.oldValue;
|
|
6919
|
-
if (this.idMap[id])
|
|
6920
|
-
delete this.idMap[id];
|
|
6921
|
-
}
|
|
6922
|
-
}
|
|
6923
|
-
__listenEvents() {
|
|
6924
|
-
this.__eventIds = [
|
|
6925
|
-
this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),
|
|
6926
|
-
this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)
|
|
6927
|
-
];
|
|
6928
|
-
}
|
|
6929
|
-
__removeListenEvents() {
|
|
6930
|
-
this.target.off_(this.__eventIds);
|
|
6931
|
-
this.__eventIds.length = 0;
|
|
6824
|
+
getBy(condition, branch, one, options) {
|
|
6825
|
+
return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need('find');
|
|
6932
6826
|
}
|
|
6933
6827
|
destroy() {
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
this.
|
|
6937
|
-
this.findLeaf = null;
|
|
6938
|
-
this.innerIdMap = {};
|
|
6939
|
-
this.idMap = {};
|
|
6940
|
-
}
|
|
6828
|
+
this.picker.destroy();
|
|
6829
|
+
if (this.finder)
|
|
6830
|
+
this.finder.destroy();
|
|
6941
6831
|
}
|
|
6942
6832
|
}
|
|
6943
6833
|
|
|
@@ -7433,25 +7323,27 @@ let UI = UI_1 = class UI extends Leaf {
|
|
|
7433
7323
|
}
|
|
7434
7324
|
reset(_data) { }
|
|
7435
7325
|
set(data, transition) {
|
|
7436
|
-
if (
|
|
7437
|
-
if (transition
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
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);
|
|
7441
7335
|
}
|
|
7442
7336
|
else
|
|
7443
|
-
|
|
7337
|
+
Object.assign(this, data);
|
|
7444
7338
|
}
|
|
7445
|
-
else
|
|
7446
|
-
Object.assign(this, data);
|
|
7447
7339
|
}
|
|
7448
7340
|
get(name) {
|
|
7449
7341
|
return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
|
|
7450
7342
|
}
|
|
7451
7343
|
createProxyData() { return undefined; }
|
|
7452
|
-
find(_condition, _options) { return
|
|
7344
|
+
find(_condition, _options) { return Plugin.need('find'); }
|
|
7453
7345
|
findTag(tag) { return this.find({ tag }); }
|
|
7454
|
-
findOne(_condition, _options) { return
|
|
7346
|
+
findOne(_condition, _options) { return Plugin.need('find'); }
|
|
7455
7347
|
findId(id) { return this.findOne({ id }); }
|
|
7456
7348
|
getPath(curve, pathForRender) {
|
|
7457
7349
|
this.__layout.update();
|
|
@@ -7503,9 +7395,9 @@ let UI = UI_1 = class UI extends Leaf {
|
|
|
7503
7395
|
animate(_keyframe, _options, _type, _isTemp) {
|
|
7504
7396
|
return Plugin.need('animate');
|
|
7505
7397
|
}
|
|
7506
|
-
killAnimate(_type) { }
|
|
7507
|
-
export(
|
|
7508
|
-
return
|
|
7398
|
+
killAnimate(_type, _killStyle) { }
|
|
7399
|
+
export(_filename, _options) {
|
|
7400
|
+
return Plugin.need('export');
|
|
7509
7401
|
}
|
|
7510
7402
|
clone(data) {
|
|
7511
7403
|
const json = this.toJSON();
|
|
@@ -7751,16 +7643,18 @@ let Group = class Group extends UI {
|
|
|
7751
7643
|
this.children = [];
|
|
7752
7644
|
}
|
|
7753
7645
|
set(data, transition) {
|
|
7754
|
-
if (data
|
|
7755
|
-
|
|
7756
|
-
|
|
7757
|
-
|
|
7758
|
-
|
|
7759
|
-
|
|
7760
|
-
|
|
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);
|
|
7761
7657
|
}
|
|
7762
|
-
else
|
|
7763
|
-
super.set(data, transition);
|
|
7764
7658
|
}
|
|
7765
7659
|
toJSON(options) {
|
|
7766
7660
|
const data = super.toJSON(options);
|
|
@@ -8023,6 +7917,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
|
|
|
8023
7917
|
this.requestRender();
|
|
8024
7918
|
}
|
|
8025
7919
|
}
|
|
7920
|
+
else
|
|
7921
|
+
this.requestRender();
|
|
8026
7922
|
}
|
|
8027
7923
|
__checkViewCompleted(emit = true) {
|
|
8028
7924
|
this.nextRender(() => {
|
|
@@ -8096,9 +7992,6 @@ let Leafer = Leafer_1 = class Leafer extends Group {
|
|
|
8096
7992
|
this.canvas && this.canvas.updateClientBounds();
|
|
8097
7993
|
}
|
|
8098
7994
|
receiveEvent(_event) { }
|
|
8099
|
-
__checkUpdateLayout() {
|
|
8100
|
-
this.__layout.update();
|
|
8101
|
-
}
|
|
8102
7995
|
emitLeafer(type) {
|
|
8103
7996
|
this.emitEvent(new LeaferEvent(type, this));
|
|
8104
7997
|
}
|
|
@@ -8109,7 +8002,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
|
|
|
8109
8002
|
this.once(LayoutEvent.END, () => this.__onReady());
|
|
8110
8003
|
this.once(RenderEvent.START, () => this.__onCreated());
|
|
8111
8004
|
this.once(RenderEvent.END, () => this.__onViewReady());
|
|
8112
|
-
this.__eventIds.push(this.on_(WatchEvent.DATA, this.__onWatchData, this), this.on_(RenderEvent.NEXT, this.__onNextRender, this)
|
|
8005
|
+
this.__eventIds.push(this.on_(WatchEvent.DATA, this.__onWatchData, this), this.on_(RenderEvent.NEXT, this.__onNextRender, this));
|
|
8113
8006
|
}
|
|
8114
8007
|
__removeListenEvents() {
|
|
8115
8008
|
this.off_(this.__eventIds);
|
|
@@ -8174,7 +8067,7 @@ Rect = __decorate([
|
|
|
8174
8067
|
], Rect);
|
|
8175
8068
|
|
|
8176
8069
|
const { copy: copy$6, add, includes: includes$1 } = BoundsHelper;
|
|
8177
|
-
const rect$1 = Rect.prototype, group
|
|
8070
|
+
const rect$1 = Rect.prototype, group = Group.prototype;
|
|
8178
8071
|
const childrenRenderBounds = {};
|
|
8179
8072
|
let Box = class Box extends Group {
|
|
8180
8073
|
get __tag() { return 'Box'; }
|
|
@@ -8284,7 +8177,7 @@ __decorate([
|
|
|
8284
8177
|
rewrite(rect$1.__render)
|
|
8285
8178
|
], Box.prototype, "__renderRect", null);
|
|
8286
8179
|
__decorate([
|
|
8287
|
-
rewrite(group
|
|
8180
|
+
rewrite(group.__render)
|
|
8288
8181
|
], Box.prototype, "__renderGroup", null);
|
|
8289
8182
|
Box = __decorate([
|
|
8290
8183
|
rewriteAble(),
|
|
@@ -8588,10 +8481,10 @@ let Canvas = class Canvas extends Rect {
|
|
|
8588
8481
|
__updateSize() {
|
|
8589
8482
|
const { canvas } = this;
|
|
8590
8483
|
if (canvas) {
|
|
8591
|
-
const { smooth } = this.__;
|
|
8484
|
+
const { smooth, safeResize } = this.__;
|
|
8485
|
+
canvas.resize(this.__, safeResize);
|
|
8592
8486
|
if (canvas.smooth !== smooth)
|
|
8593
8487
|
canvas.smooth = smooth;
|
|
8594
|
-
canvas.resize(this.__);
|
|
8595
8488
|
}
|
|
8596
8489
|
}
|
|
8597
8490
|
destroy() {
|
|
@@ -8617,6 +8510,9 @@ __decorate([
|
|
|
8617
8510
|
__decorate([
|
|
8618
8511
|
resizeType(true)
|
|
8619
8512
|
], Canvas.prototype, "smooth", void 0);
|
|
8513
|
+
__decorate([
|
|
8514
|
+
dataType(false)
|
|
8515
|
+
], Canvas.prototype, "safeResize", void 0);
|
|
8620
8516
|
__decorate([
|
|
8621
8517
|
resizeType()
|
|
8622
8518
|
], Canvas.prototype, "contextSettings", void 0);
|
|
@@ -8762,6 +8658,9 @@ __decorate([
|
|
|
8762
8658
|
__decorate([
|
|
8763
8659
|
boundsType(0)
|
|
8764
8660
|
], Text.prototype, "paraSpacing", void 0);
|
|
8661
|
+
__decorate([
|
|
8662
|
+
boundsType('x')
|
|
8663
|
+
], Text.prototype, "writingMode", void 0);
|
|
8765
8664
|
__decorate([
|
|
8766
8665
|
boundsType('left')
|
|
8767
8666
|
], Text.prototype, "textAlign", void 0);
|
|
@@ -8948,8 +8847,8 @@ let App = class App extends Leafer {
|
|
|
8948
8847
|
this.children.forEach(leafer => leafer.resize(event));
|
|
8949
8848
|
super.__onResize(event);
|
|
8950
8849
|
}
|
|
8951
|
-
|
|
8952
|
-
this.children.forEach(leafer => leafer.
|
|
8850
|
+
updateLayout() {
|
|
8851
|
+
this.children.forEach(leafer => leafer.updateLayout());
|
|
8953
8852
|
}
|
|
8954
8853
|
__getChildConfig(userConfig) {
|
|
8955
8854
|
let config = Object.assign({}, this.config);
|
|
@@ -10026,8 +9925,8 @@ leaf$1.__drawHitPath = function (canvas) { if (canvas)
|
|
|
10026
9925
|
this.__drawRenderPath(canvas); };
|
|
10027
9926
|
|
|
10028
9927
|
const matrix$2 = new Matrix();
|
|
10029
|
-
const ui$
|
|
10030
|
-
ui$
|
|
9928
|
+
const ui$2 = UI.prototype;
|
|
9929
|
+
ui$2.__updateHitCanvas = function () {
|
|
10031
9930
|
const data = this.__, { hitCanvasManager } = this.leafer;
|
|
10032
9931
|
const isHitPixelFill = (data.__pixelFill || data.__isCanvas) && data.hitFill === 'pixel';
|
|
10033
9932
|
const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
|
|
@@ -10054,7 +9953,7 @@ ui$3.__updateHitCanvas = function () {
|
|
|
10054
9953
|
this.__drawHitPath(h);
|
|
10055
9954
|
h.setStrokeOptions(data);
|
|
10056
9955
|
};
|
|
10057
|
-
ui$
|
|
9956
|
+
ui$2.__hit = function (inner) {
|
|
10058
9957
|
if (Platform.name === 'miniapp')
|
|
10059
9958
|
this.__drawHitPath(this.__hitCanvas);
|
|
10060
9959
|
const data = this.__;
|
|
@@ -10094,31 +9993,23 @@ ui$3.__hit = function (inner) {
|
|
|
10094
9993
|
return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
|
|
10095
9994
|
};
|
|
10096
9995
|
|
|
10097
|
-
const ui$
|
|
9996
|
+
const ui$1 = UI.prototype, rect = Rect.prototype, box$1 = Box.prototype;
|
|
10098
9997
|
rect.__updateHitCanvas = box$1.__updateHitCanvas = function () {
|
|
10099
9998
|
if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
|
|
10100
|
-
ui$
|
|
9999
|
+
ui$1.__updateHitCanvas.call(this);
|
|
10101
10000
|
else if (this.__hitCanvas)
|
|
10102
10001
|
this.__hitCanvas = null;
|
|
10103
10002
|
};
|
|
10104
10003
|
rect.__hitFill = box$1.__hitFill = function (inner) {
|
|
10105
|
-
return this.__hitCanvas ? ui$
|
|
10004
|
+
return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
|
|
10106
10005
|
};
|
|
10107
10006
|
|
|
10108
|
-
const ui$1 = UI.prototype, group = Group.prototype;
|
|
10109
10007
|
function getSelector(ui) {
|
|
10110
10008
|
return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()));
|
|
10111
10009
|
}
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
ui$1.findOne = function (condition, options) {
|
|
10116
|
-
return getSelector(this).getBy(condition, this, true, options);
|
|
10117
|
-
};
|
|
10118
|
-
group.pick = function (hitPoint, options) {
|
|
10119
|
-
this.__layout.update();
|
|
10120
|
-
if (!options)
|
|
10121
|
-
options = {};
|
|
10010
|
+
Group.prototype.pick = function (hitPoint, options) {
|
|
10011
|
+
this.leafer || this.updateLayout();
|
|
10012
|
+
options || (options = emptyData);
|
|
10122
10013
|
return getSelector(this).getByPoint(hitPoint, options.hitRadius || 0, Object.assign(Object.assign({}, options), { target: this }));
|
|
10123
10014
|
};
|
|
10124
10015
|
|
|
@@ -11622,197 +11513,12 @@ const ColorConvertModule = {
|
|
|
11622
11513
|
string
|
|
11623
11514
|
};
|
|
11624
11515
|
|
|
11625
|
-
const { setPoint: setPoint$2, addPoint, toBounds } = TwoPointBoundsHelper;
|
|
11626
|
-
function getTrimBounds(canvas) {
|
|
11627
|
-
const { width, height } = canvas.view;
|
|
11628
|
-
const { data } = canvas.context.getImageData(0, 0, width, height);
|
|
11629
|
-
let x, y, pointBounds, index = 0;
|
|
11630
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
11631
|
-
if (data[i + 3] !== 0) {
|
|
11632
|
-
x = index % width;
|
|
11633
|
-
y = (index - x) / width;
|
|
11634
|
-
pointBounds ? addPoint(pointBounds, x, y) : setPoint$2(pointBounds = {}, x, y);
|
|
11635
|
-
}
|
|
11636
|
-
index++;
|
|
11637
|
-
}
|
|
11638
|
-
const bounds = new Bounds();
|
|
11639
|
-
toBounds(pointBounds, bounds);
|
|
11640
|
-
return bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
11641
|
-
}
|
|
11642
|
-
|
|
11643
|
-
const ExportModule = {
|
|
11644
|
-
export(leaf, filename, options) {
|
|
11645
|
-
this.running = true;
|
|
11646
|
-
const fileType = FileHelper.fileType(filename);
|
|
11647
|
-
const isDownload = filename.includes('.');
|
|
11648
|
-
options = FileHelper.getExportOptions(options);
|
|
11649
|
-
return addTask((success) => new Promise((resolve) => {
|
|
11650
|
-
const over = (result) => {
|
|
11651
|
-
success(result);
|
|
11652
|
-
resolve();
|
|
11653
|
-
this.running = false;
|
|
11654
|
-
};
|
|
11655
|
-
const { toURL } = Platform;
|
|
11656
|
-
const { download } = Platform.origin;
|
|
11657
|
-
if (fileType === 'json') {
|
|
11658
|
-
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
11659
|
-
return over({ data: isDownload ? true : leaf.toJSON(options.json) });
|
|
11660
|
-
}
|
|
11661
|
-
if (fileType === 'svg') {
|
|
11662
|
-
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
11663
|
-
return over({ data: isDownload ? true : leaf.toSVG() });
|
|
11664
|
-
}
|
|
11665
|
-
const { leafer } = leaf;
|
|
11666
|
-
if (leafer) {
|
|
11667
|
-
checkLazy(leaf);
|
|
11668
|
-
leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
|
|
11669
|
-
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
11670
|
-
const { worldTransform, isLeafer, isFrame } = leaf;
|
|
11671
|
-
const { slice, trim, onCanvas } = options;
|
|
11672
|
-
const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
|
|
11673
|
-
const contextSettings = options.contextSettings || leafer.config.contextSettings;
|
|
11674
|
-
const screenshot = options.screenshot || leaf.isApp;
|
|
11675
|
-
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
11676
|
-
const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
|
|
11677
|
-
if (screenshot) {
|
|
11678
|
-
renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
|
|
11679
|
-
}
|
|
11680
|
-
else {
|
|
11681
|
-
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
11682
|
-
scaleX = worldTransform.scaleX;
|
|
11683
|
-
scaleY = worldTransform.scaleY;
|
|
11684
|
-
switch (relative) {
|
|
11685
|
-
case 'inner':
|
|
11686
|
-
matrix.set(worldTransform);
|
|
11687
|
-
break;
|
|
11688
|
-
case 'local':
|
|
11689
|
-
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
11690
|
-
scaleX /= leaf.scaleX;
|
|
11691
|
-
scaleY /= leaf.scaleY;
|
|
11692
|
-
break;
|
|
11693
|
-
case 'world':
|
|
11694
|
-
scaleX = 1;
|
|
11695
|
-
scaleY = 1;
|
|
11696
|
-
break;
|
|
11697
|
-
case 'page':
|
|
11698
|
-
relative = leaf.leafer;
|
|
11699
|
-
default:
|
|
11700
|
-
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
11701
|
-
const l = relative.worldTransform;
|
|
11702
|
-
scaleX /= scaleX / l.scaleX;
|
|
11703
|
-
scaleY /= scaleY / l.scaleY;
|
|
11704
|
-
}
|
|
11705
|
-
renderBounds = leaf.getBounds('render', relative);
|
|
11706
|
-
}
|
|
11707
|
-
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
11708
|
-
MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
11709
|
-
let pixelRatio = options.pixelRatio || 1;
|
|
11710
|
-
if (leaf.isApp) {
|
|
11711
|
-
scaleData.scaleX *= pixelRatio;
|
|
11712
|
-
scaleData.scaleY *= pixelRatio;
|
|
11713
|
-
pixelRatio = leaf.app.pixelRatio;
|
|
11714
|
-
}
|
|
11715
|
-
const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
11716
|
-
const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
|
|
11717
|
-
let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
|
|
11718
|
-
let sliceLeaf;
|
|
11719
|
-
if (slice) {
|
|
11720
|
-
sliceLeaf = leaf;
|
|
11721
|
-
sliceLeaf.__worldOpacity = 0;
|
|
11722
|
-
leaf = leafer;
|
|
11723
|
-
renderOptions.bounds = canvas.bounds;
|
|
11724
|
-
}
|
|
11725
|
-
canvas.save();
|
|
11726
|
-
if (isFrame && fill !== undefined) {
|
|
11727
|
-
const oldFill = leaf.get('fill');
|
|
11728
|
-
leaf.fill = '';
|
|
11729
|
-
leaf.__render(canvas, renderOptions);
|
|
11730
|
-
leaf.fill = oldFill;
|
|
11731
|
-
}
|
|
11732
|
-
else {
|
|
11733
|
-
leaf.__render(canvas, renderOptions);
|
|
11734
|
-
}
|
|
11735
|
-
canvas.restore();
|
|
11736
|
-
if (sliceLeaf)
|
|
11737
|
-
sliceLeaf.__updateWorldOpacity();
|
|
11738
|
-
if (trim) {
|
|
11739
|
-
trimBounds = getTrimBounds(canvas);
|
|
11740
|
-
const old = canvas, { width, height } = trimBounds;
|
|
11741
|
-
const config = { x: 0, y: 0, width, height, pixelRatio };
|
|
11742
|
-
canvas = Creator.canvas(config);
|
|
11743
|
-
canvas.copyWorld(old, trimBounds, config);
|
|
11744
|
-
}
|
|
11745
|
-
if (needFill)
|
|
11746
|
-
canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
|
|
11747
|
-
if (onCanvas)
|
|
11748
|
-
onCanvas(canvas);
|
|
11749
|
-
const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
|
|
11750
|
-
over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
|
|
11751
|
-
}));
|
|
11752
|
-
}
|
|
11753
|
-
else {
|
|
11754
|
-
over({ data: false });
|
|
11755
|
-
}
|
|
11756
|
-
}));
|
|
11757
|
-
}
|
|
11758
|
-
};
|
|
11759
|
-
let tasker;
|
|
11760
|
-
function addTask(task) {
|
|
11761
|
-
if (!tasker)
|
|
11762
|
-
tasker = new TaskProcessor();
|
|
11763
|
-
return new Promise((resolve) => {
|
|
11764
|
-
tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
|
|
11765
|
-
});
|
|
11766
|
-
}
|
|
11767
|
-
function checkLazy(leaf) {
|
|
11768
|
-
if (leaf.__.__needComputePaint)
|
|
11769
|
-
leaf.__.__computePaint();
|
|
11770
|
-
if (leaf.isBranch)
|
|
11771
|
-
leaf.children.forEach(child => checkLazy(child));
|
|
11772
|
-
}
|
|
11773
|
-
|
|
11774
|
-
const canvas = LeaferCanvasBase.prototype;
|
|
11775
|
-
const debug$2 = Debug.get('@leafer-ui/export');
|
|
11776
|
-
canvas.export = function (filename, options) {
|
|
11777
|
-
const { quality, blob } = FileHelper.getExportOptions(options);
|
|
11778
|
-
if (filename.includes('.'))
|
|
11779
|
-
return this.saveAs(filename, quality);
|
|
11780
|
-
else if (blob)
|
|
11781
|
-
return this.toBlob(filename, quality);
|
|
11782
|
-
else
|
|
11783
|
-
return this.toDataURL(filename, quality);
|
|
11784
|
-
};
|
|
11785
|
-
canvas.toBlob = function (type, quality) {
|
|
11786
|
-
return new Promise((resolve) => {
|
|
11787
|
-
Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
|
|
11788
|
-
resolve(blob);
|
|
11789
|
-
}).catch((e) => {
|
|
11790
|
-
debug$2.error(e);
|
|
11791
|
-
resolve(null);
|
|
11792
|
-
});
|
|
11793
|
-
});
|
|
11794
|
-
};
|
|
11795
|
-
canvas.toDataURL = function (type, quality) {
|
|
11796
|
-
return Platform.origin.canvasToDataURL(this.view, type, quality);
|
|
11797
|
-
};
|
|
11798
|
-
canvas.saveAs = function (filename, quality) {
|
|
11799
|
-
return new Promise((resolve) => {
|
|
11800
|
-
Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
|
|
11801
|
-
resolve(true);
|
|
11802
|
-
}).catch((e) => {
|
|
11803
|
-
debug$2.error(e);
|
|
11804
|
-
resolve(false);
|
|
11805
|
-
});
|
|
11806
|
-
});
|
|
11807
|
-
};
|
|
11808
|
-
|
|
11809
11516
|
Object.assign(TextConvert, TextConvertModule);
|
|
11810
11517
|
Object.assign(ColorConvert, ColorConvertModule);
|
|
11811
11518
|
Object.assign(Paint, PaintModule);
|
|
11812
11519
|
Object.assign(PaintImage, PaintImageModule);
|
|
11813
11520
|
Object.assign(PaintGradient, PaintGradientModule);
|
|
11814
11521
|
Object.assign(Effect, EffectModule);
|
|
11815
|
-
Object.assign(Export, ExportModule);
|
|
11816
11522
|
|
|
11817
11523
|
Object.assign(Creator, {
|
|
11818
11524
|
interaction: (target, canvas, selector, options) => new InteractionBase(target, canvas, selector, options),
|
|
@@ -12957,7 +12663,7 @@ const EditorHelper = {
|
|
|
12957
12663
|
}
|
|
12958
12664
|
};
|
|
12959
12665
|
|
|
12960
|
-
const debug$
|
|
12666
|
+
const debug$2 = Debug.get('EditToolCreator');
|
|
12961
12667
|
function registerEditTool() {
|
|
12962
12668
|
return (target) => {
|
|
12963
12669
|
EditToolCreator.register(target);
|
|
@@ -12968,7 +12674,7 @@ const EditToolCreator = {
|
|
|
12968
12674
|
list: {},
|
|
12969
12675
|
register(EditTool) {
|
|
12970
12676
|
const { tag } = EditTool.prototype;
|
|
12971
|
-
list$1[tag] && debug$
|
|
12677
|
+
list$1[tag] && debug$2.repeat(tag);
|
|
12972
12678
|
list$1[tag] = EditTool;
|
|
12973
12679
|
},
|
|
12974
12680
|
get(tag, editor) {
|
|
@@ -13085,7 +12791,7 @@ class Editor extends Group {
|
|
|
13085
12791
|
if (userConfig)
|
|
13086
12792
|
this.config = DataHelper.default(userConfig, this.config);
|
|
13087
12793
|
this.addMany(this.editMask, this.selector, this.editBox);
|
|
13088
|
-
if (!Plugin.
|
|
12794
|
+
if (!Plugin.has('resize'))
|
|
13089
12795
|
this.config.editSize = 'scale';
|
|
13090
12796
|
}
|
|
13091
12797
|
select(target) {
|
|
@@ -13878,7 +13584,7 @@ Box.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
|
13878
13584
|
|
|
13879
13585
|
Plugin.add('resize');
|
|
13880
13586
|
|
|
13881
|
-
Plugin.add('editor');
|
|
13587
|
+
Plugin.add('editor', 'resize');
|
|
13882
13588
|
Creator.editor = function (options) { return new Editor(options); };
|
|
13883
13589
|
dataType(false)(Box.prototype, 'textBox');
|
|
13884
13590
|
defineKey(UI.prototype, 'editOuter', {
|
|
@@ -13925,13 +13631,14 @@ function addViewport(leafer, mergeConfig, custom) {
|
|
|
13925
13631
|
}));
|
|
13926
13632
|
}
|
|
13927
13633
|
function addViewportConfig(leafer, mergeConfig) {
|
|
13928
|
-
|
|
13929
|
-
DataHelper.assign(leafer.config, mergeConfig);
|
|
13930
|
-
DataHelper.assign(leafer.config, {
|
|
13634
|
+
const viewportConfig = {
|
|
13931
13635
|
wheel: { preventDefault: true },
|
|
13932
13636
|
touch: { preventDefault: true },
|
|
13933
13637
|
pointer: { preventDefaultMenu: true }
|
|
13934
|
-
}
|
|
13638
|
+
};
|
|
13639
|
+
if (mergeConfig)
|
|
13640
|
+
DataHelper.assign(viewportConfig, mergeConfig);
|
|
13641
|
+
DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig);
|
|
13935
13642
|
}
|
|
13936
13643
|
|
|
13937
13644
|
function custom(leafer) {
|
|
@@ -13958,11 +13665,11 @@ function document$1(leafer) {
|
|
|
13958
13665
|
});
|
|
13959
13666
|
}
|
|
13960
13667
|
|
|
13961
|
-
const debug = Debug.get('LeaferTypeCreator');
|
|
13668
|
+
const debug$1 = Debug.get('LeaferTypeCreator');
|
|
13962
13669
|
const LeaferTypeCreator = {
|
|
13963
13670
|
list: {},
|
|
13964
13671
|
register(name, fn) {
|
|
13965
|
-
list[name] && debug.repeat(name);
|
|
13672
|
+
list[name] && debug$1.repeat(name);
|
|
13966
13673
|
list[name] = fn;
|
|
13967
13674
|
},
|
|
13968
13675
|
run(name, leafer) {
|
|
@@ -14487,17 +14194,17 @@ const PathMatrixHelper = {
|
|
|
14487
14194
|
switch (command) {
|
|
14488
14195
|
case M$1:
|
|
14489
14196
|
case L$1:
|
|
14490
|
-
setPoint$
|
|
14197
|
+
setPoint$2(data, i + 1, x, y, scaleX, scaleY, rotation, origin);
|
|
14491
14198
|
i += 3;
|
|
14492
14199
|
break;
|
|
14493
14200
|
case C$1:
|
|
14494
14201
|
for (j = 1; j < 6; j += 2)
|
|
14495
|
-
setPoint$
|
|
14202
|
+
setPoint$2(data, i + j, x, y, scaleX, scaleY, rotation, origin);
|
|
14496
14203
|
i += 7;
|
|
14497
14204
|
break;
|
|
14498
14205
|
case Q$1:
|
|
14499
14206
|
for (j = 1; j < 4; j += 2)
|
|
14500
|
-
setPoint$
|
|
14207
|
+
setPoint$2(data, i + j, x, y, scaleX, scaleY, rotation, origin);
|
|
14501
14208
|
i += 5;
|
|
14502
14209
|
break;
|
|
14503
14210
|
case O$1:
|
|
@@ -14518,7 +14225,7 @@ const PathMatrixHelper = {
|
|
|
14518
14225
|
PathMatrixHelper.layout(data, 0, 0, 1, 1, rotation, center);
|
|
14519
14226
|
}
|
|
14520
14227
|
};
|
|
14521
|
-
function setPoint$
|
|
14228
|
+
function setPoint$2(data, startIndex, x, y, scaleX, scaleY, rotation, origin) {
|
|
14522
14229
|
copyFrom$1(point, data[startIndex], data[startIndex + 1]);
|
|
14523
14230
|
if (rotation)
|
|
14524
14231
|
rotate$1(point, rotation, origin);
|
|
@@ -14684,7 +14391,7 @@ const PathArrowModule = {
|
|
|
14684
14391
|
break;
|
|
14685
14392
|
}
|
|
14686
14393
|
if (index)
|
|
14687
|
-
setPoint(path, last, index);
|
|
14394
|
+
setPoint$1(path, last, index);
|
|
14688
14395
|
}
|
|
14689
14396
|
}
|
|
14690
14397
|
}
|
|
@@ -14698,7 +14405,7 @@ function copyPoints(data, from, to, startIndex) {
|
|
|
14698
14405
|
copyFrom(from, data[startIndex], data[startIndex + 1]);
|
|
14699
14406
|
copyFrom(to, data[startIndex + 2], data[startIndex + 3]);
|
|
14700
14407
|
}
|
|
14701
|
-
function setPoint(data, point, startIndex) {
|
|
14408
|
+
function setPoint$1(data, point, startIndex) {
|
|
14702
14409
|
data[startIndex] = point.x;
|
|
14703
14410
|
data[startIndex + 1] = point.y;
|
|
14704
14411
|
}
|
|
@@ -14721,6 +14428,195 @@ arrowType('none')(ui, 'startArrow');
|
|
|
14721
14428
|
arrowType('none')(ui, 'endArrow');
|
|
14722
14429
|
Object.assign(PathArrow, PathArrowModule);
|
|
14723
14430
|
|
|
14431
|
+
const { setPoint, addPoint, toBounds } = TwoPointBoundsHelper;
|
|
14432
|
+
function getTrimBounds(canvas) {
|
|
14433
|
+
const { width, height } = canvas.view;
|
|
14434
|
+
const { data } = canvas.context.getImageData(0, 0, width, height);
|
|
14435
|
+
let x, y, pointBounds, index = 0;
|
|
14436
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
14437
|
+
if (data[i + 3] !== 0) {
|
|
14438
|
+
x = index % width;
|
|
14439
|
+
y = (index - x) / width;
|
|
14440
|
+
pointBounds ? addPoint(pointBounds, x, y) : setPoint(pointBounds = {}, x, y);
|
|
14441
|
+
}
|
|
14442
|
+
index++;
|
|
14443
|
+
}
|
|
14444
|
+
const bounds = new Bounds();
|
|
14445
|
+
toBounds(pointBounds, bounds);
|
|
14446
|
+
return bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
14447
|
+
}
|
|
14448
|
+
|
|
14449
|
+
const ExportModule = {
|
|
14450
|
+
export(leaf, filename, options) {
|
|
14451
|
+
this.running = true;
|
|
14452
|
+
const fileType = FileHelper.fileType(filename);
|
|
14453
|
+
const isDownload = filename.includes('.');
|
|
14454
|
+
options = FileHelper.getExportOptions(options);
|
|
14455
|
+
return addTask((success) => new Promise((resolve) => {
|
|
14456
|
+
const over = (result) => {
|
|
14457
|
+
success(result);
|
|
14458
|
+
resolve();
|
|
14459
|
+
this.running = false;
|
|
14460
|
+
};
|
|
14461
|
+
const { toURL } = Platform;
|
|
14462
|
+
const { download } = Platform.origin;
|
|
14463
|
+
if (fileType === 'json') {
|
|
14464
|
+
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
14465
|
+
return over({ data: isDownload ? true : leaf.toJSON(options.json) });
|
|
14466
|
+
}
|
|
14467
|
+
if (fileType === 'svg') {
|
|
14468
|
+
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
14469
|
+
return over({ data: isDownload ? true : leaf.toSVG() });
|
|
14470
|
+
}
|
|
14471
|
+
const { leafer } = leaf;
|
|
14472
|
+
if (leafer) {
|
|
14473
|
+
checkLazy(leaf);
|
|
14474
|
+
leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
|
|
14475
|
+
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
14476
|
+
const { worldTransform, isLeafer, isFrame } = leaf;
|
|
14477
|
+
const { slice, trim, onCanvas } = options;
|
|
14478
|
+
const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
|
|
14479
|
+
const contextSettings = options.contextSettings || leafer.config.contextSettings;
|
|
14480
|
+
const screenshot = options.screenshot || leaf.isApp;
|
|
14481
|
+
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
14482
|
+
const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
|
|
14483
|
+
if (screenshot) {
|
|
14484
|
+
renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
|
|
14485
|
+
}
|
|
14486
|
+
else {
|
|
14487
|
+
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
14488
|
+
scaleX = worldTransform.scaleX;
|
|
14489
|
+
scaleY = worldTransform.scaleY;
|
|
14490
|
+
switch (relative) {
|
|
14491
|
+
case 'inner':
|
|
14492
|
+
matrix.set(worldTransform);
|
|
14493
|
+
break;
|
|
14494
|
+
case 'local':
|
|
14495
|
+
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
14496
|
+
scaleX /= leaf.scaleX;
|
|
14497
|
+
scaleY /= leaf.scaleY;
|
|
14498
|
+
break;
|
|
14499
|
+
case 'world':
|
|
14500
|
+
scaleX = 1;
|
|
14501
|
+
scaleY = 1;
|
|
14502
|
+
break;
|
|
14503
|
+
case 'page':
|
|
14504
|
+
relative = leaf.leafer;
|
|
14505
|
+
default:
|
|
14506
|
+
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
14507
|
+
const l = relative.worldTransform;
|
|
14508
|
+
scaleX /= scaleX / l.scaleX;
|
|
14509
|
+
scaleY /= scaleY / l.scaleY;
|
|
14510
|
+
}
|
|
14511
|
+
renderBounds = leaf.getBounds('render', relative);
|
|
14512
|
+
}
|
|
14513
|
+
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
14514
|
+
MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
14515
|
+
let pixelRatio = options.pixelRatio || 1;
|
|
14516
|
+
if (leaf.isApp) {
|
|
14517
|
+
scaleData.scaleX *= pixelRatio;
|
|
14518
|
+
scaleData.scaleY *= pixelRatio;
|
|
14519
|
+
pixelRatio = leaf.app.pixelRatio;
|
|
14520
|
+
}
|
|
14521
|
+
const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
14522
|
+
const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
|
|
14523
|
+
let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
|
|
14524
|
+
let sliceLeaf;
|
|
14525
|
+
if (slice) {
|
|
14526
|
+
sliceLeaf = leaf;
|
|
14527
|
+
sliceLeaf.__worldOpacity = 0;
|
|
14528
|
+
leaf = leafer;
|
|
14529
|
+
renderOptions.bounds = canvas.bounds;
|
|
14530
|
+
}
|
|
14531
|
+
canvas.save();
|
|
14532
|
+
if (isFrame && fill !== undefined) {
|
|
14533
|
+
const oldFill = leaf.get('fill');
|
|
14534
|
+
leaf.fill = '';
|
|
14535
|
+
leaf.__render(canvas, renderOptions);
|
|
14536
|
+
leaf.fill = oldFill;
|
|
14537
|
+
}
|
|
14538
|
+
else {
|
|
14539
|
+
leaf.__render(canvas, renderOptions);
|
|
14540
|
+
}
|
|
14541
|
+
canvas.restore();
|
|
14542
|
+
if (sliceLeaf)
|
|
14543
|
+
sliceLeaf.__updateWorldOpacity();
|
|
14544
|
+
if (trim) {
|
|
14545
|
+
trimBounds = getTrimBounds(canvas);
|
|
14546
|
+
const old = canvas, { width, height } = trimBounds;
|
|
14547
|
+
const config = { x: 0, y: 0, width, height, pixelRatio };
|
|
14548
|
+
canvas = Creator.canvas(config);
|
|
14549
|
+
canvas.copyWorld(old, trimBounds, config);
|
|
14550
|
+
}
|
|
14551
|
+
if (needFill)
|
|
14552
|
+
canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
|
|
14553
|
+
if (onCanvas)
|
|
14554
|
+
onCanvas(canvas);
|
|
14555
|
+
const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
|
|
14556
|
+
over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
|
|
14557
|
+
}));
|
|
14558
|
+
}
|
|
14559
|
+
else {
|
|
14560
|
+
over({ data: false });
|
|
14561
|
+
}
|
|
14562
|
+
}));
|
|
14563
|
+
}
|
|
14564
|
+
};
|
|
14565
|
+
let tasker;
|
|
14566
|
+
function addTask(task) {
|
|
14567
|
+
if (!tasker)
|
|
14568
|
+
tasker = new TaskProcessor();
|
|
14569
|
+
return new Promise((resolve) => {
|
|
14570
|
+
tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
|
|
14571
|
+
});
|
|
14572
|
+
}
|
|
14573
|
+
function checkLazy(leaf) {
|
|
14574
|
+
if (leaf.__.__needComputePaint)
|
|
14575
|
+
leaf.__.__computePaint();
|
|
14576
|
+
if (leaf.isBranch)
|
|
14577
|
+
leaf.children.forEach(child => checkLazy(child));
|
|
14578
|
+
}
|
|
14579
|
+
|
|
14580
|
+
const canvas = LeaferCanvasBase.prototype;
|
|
14581
|
+
const debug = Debug.get('@leafer-in/export');
|
|
14582
|
+
canvas.export = function (filename, options) {
|
|
14583
|
+
const { quality, blob } = FileHelper.getExportOptions(options);
|
|
14584
|
+
if (filename.includes('.'))
|
|
14585
|
+
return this.saveAs(filename, quality);
|
|
14586
|
+
else if (blob)
|
|
14587
|
+
return this.toBlob(filename, quality);
|
|
14588
|
+
else
|
|
14589
|
+
return this.toDataURL(filename, quality);
|
|
14590
|
+
};
|
|
14591
|
+
canvas.toBlob = function (type, quality) {
|
|
14592
|
+
return new Promise((resolve) => {
|
|
14593
|
+
Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
|
|
14594
|
+
resolve(blob);
|
|
14595
|
+
}).catch((e) => {
|
|
14596
|
+
debug.error(e);
|
|
14597
|
+
resolve(null);
|
|
14598
|
+
});
|
|
14599
|
+
});
|
|
14600
|
+
};
|
|
14601
|
+
canvas.toDataURL = function (type, quality) {
|
|
14602
|
+
return Platform.origin.canvasToDataURL(this.view, type, quality);
|
|
14603
|
+
};
|
|
14604
|
+
canvas.saveAs = function (filename, quality) {
|
|
14605
|
+
return new Promise((resolve) => {
|
|
14606
|
+
Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
|
|
14607
|
+
resolve(true);
|
|
14608
|
+
}).catch((e) => {
|
|
14609
|
+
debug.error(e);
|
|
14610
|
+
resolve(false);
|
|
14611
|
+
});
|
|
14612
|
+
});
|
|
14613
|
+
};
|
|
14614
|
+
|
|
14615
|
+
Object.assign(Export, ExportModule);
|
|
14616
|
+
UI.prototype.export = function (filename, options) {
|
|
14617
|
+
return Export.export(this, filename, options);
|
|
14618
|
+
};
|
|
14619
|
+
|
|
14724
14620
|
const textCaseMap = {
|
|
14725
14621
|
'none': 'none',
|
|
14726
14622
|
'title': 'capitalize',
|
|
@@ -14923,8 +14819,7 @@ TextEditor = __decorate([
|
|
|
14923
14819
|
registerInnerEditor()
|
|
14924
14820
|
], TextEditor);
|
|
14925
14821
|
|
|
14926
|
-
Plugin.add('text-editor');
|
|
14927
|
-
setTimeout(() => Plugin.check('editor', true));
|
|
14822
|
+
Plugin.add('text-editor', 'editor');
|
|
14928
14823
|
|
|
14929
14824
|
class HTMLTextData extends ImageData {
|
|
14930
14825
|
setText(value) {
|
|
@@ -14986,4 +14881,4 @@ HTMLText = __decorate([
|
|
|
14986
14881
|
|
|
14987
14882
|
Plugin.add('html');
|
|
14988
14883
|
|
|
14989
|
-
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 };
|
|
14884
|
+
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, 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 };
|