leafer-ui 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/README.md +3 -7
- package/dist/web.cjs +27 -327
- package/dist/web.esm.js +28 -329
- package/dist/web.esm.min.js +1 -1
- package/dist/web.js +166 -459
- package/dist/web.min.cjs +1 -1
- package/dist/web.min.js +1 -1
- package/dist/web.module.js +166 -460
- package/dist/web.module.min.js +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -24,21 +24,17 @@
|
|
|
24
24
|
|
|
25
25
|
跟随官网教程步骤(文档底部有下一步引导按钮)从浅到深的学习,动手调试每一段示例代码。
|
|
26
26
|
|
|
27
|
-
[3. 开发一个画龙点睛的小游戏](https://leaferjs.com/ui/contest/guide.html)
|
|
28
|
-
|
|
29
|
-
给你一条会飞的龙,看你能做出什么好玩的小游戏分享给我们 ◠‿◠
|
|
30
|
-
|
|
31
27
|
## 快速安装
|
|
32
28
|
|
|
33
29
|
🚀 想马上在产品中使用,请安装 [leafer-ui](https://leaferjs.com/ui/guide/install/ui/start.html),开始你的探索之旅。
|
|
34
30
|
|
|
35
31
|
## 场景包
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
高效绘图场景,推荐直接安装更轻量的 [leafer-draw](https://leaferjs.com/ui/guide/install/draw/start.html) (51KB min+gzip)。
|
|
38
34
|
|
|
39
|
-
|
|
35
|
+
游戏开发场景,推荐直接安装更省心的 [leafer-game](https://leaferjs.com/ui/guide/install/game/start.html),已集成了游戏相关插件。
|
|
40
36
|
|
|
41
|
-
|
|
37
|
+
图形编辑场景,推荐直接安装更省心的 [leafer-editor](https://leaferjs.com/ui/guide/install/editor/start.html),已集成了图形编辑器相关插件。
|
|
42
38
|
|
|
43
39
|
## 互动交流
|
|
44
40
|
|
package/dist/web.cjs
CHANGED
|
@@ -4,7 +4,7 @@ var core = require('@leafer/core');
|
|
|
4
4
|
var core$1 = require('@leafer-ui/core');
|
|
5
5
|
var draw = require('@leafer-ui/draw');
|
|
6
6
|
|
|
7
|
-
const debug$
|
|
7
|
+
const debug$2 = core.Debug.get('LeaferCanvas');
|
|
8
8
|
class LeaferCanvas extends core.LeaferCanvasBase {
|
|
9
9
|
set zIndex(zIndex) {
|
|
10
10
|
const { style } = this.view;
|
|
@@ -76,7 +76,7 @@ class LeaferCanvas extends core.LeaferCanvasBase {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
else {
|
|
79
|
-
debug$
|
|
79
|
+
debug$2.error(`no id: ${inputView}`);
|
|
80
80
|
this.__createView();
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -94,7 +94,8 @@ class LeaferCanvas extends core.LeaferCanvasBase {
|
|
|
94
94
|
this.view.height = Math.ceil(height * pixelRatio);
|
|
95
95
|
}
|
|
96
96
|
updateClientBounds() {
|
|
97
|
-
|
|
97
|
+
if (this.view.parentElement)
|
|
98
|
+
this.clientBounds = this.view.getBoundingClientRect();
|
|
98
99
|
}
|
|
99
100
|
startAutoLayout(autoBounds, listener) {
|
|
100
101
|
this.resizeListener = listener;
|
|
@@ -113,7 +114,7 @@ class LeaferCanvas extends core.LeaferCanvasBase {
|
|
|
113
114
|
}
|
|
114
115
|
else {
|
|
115
116
|
this.checkAutoBounds(this.view);
|
|
116
|
-
debug$
|
|
117
|
+
debug$2.warn('no parent');
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
120
|
catch (_a) {
|
|
@@ -449,7 +450,7 @@ class LayoutBlockData {
|
|
|
449
450
|
}
|
|
450
451
|
|
|
451
452
|
const { updateAllMatrix, updateAllChange } = core.LeafHelper;
|
|
452
|
-
const debug$
|
|
453
|
+
const debug$1 = core.Debug.get('Layouter');
|
|
453
454
|
class Layouter {
|
|
454
455
|
constructor(target, userConfig) {
|
|
455
456
|
this.totalTimes = 0;
|
|
@@ -484,7 +485,7 @@ class Layouter {
|
|
|
484
485
|
target.emitEvent(new core.LayoutEvent(core.LayoutEvent.END, this.layoutedBlocks, this.times));
|
|
485
486
|
}
|
|
486
487
|
catch (e) {
|
|
487
|
-
debug$
|
|
488
|
+
debug$1.error(e);
|
|
488
489
|
}
|
|
489
490
|
this.layoutedBlocks = null;
|
|
490
491
|
}
|
|
@@ -498,9 +499,9 @@ class Layouter {
|
|
|
498
499
|
}
|
|
499
500
|
layoutOnce() {
|
|
500
501
|
if (this.layouting)
|
|
501
|
-
return debug$
|
|
502
|
+
return debug$1.warn('layouting');
|
|
502
503
|
if (this.times > 3)
|
|
503
|
-
return debug$
|
|
504
|
+
return debug$1.warn('layout max times');
|
|
504
505
|
this.times++;
|
|
505
506
|
this.totalTimes++;
|
|
506
507
|
this.layouting = true;
|
|
@@ -604,7 +605,7 @@ class Layouter {
|
|
|
604
605
|
}
|
|
605
606
|
}
|
|
606
607
|
|
|
607
|
-
const debug
|
|
608
|
+
const debug = core.Debug.get('Renderer');
|
|
608
609
|
class Renderer {
|
|
609
610
|
get needFill() { return !!(!this.canvas.allowBackgroundColor && this.config.fill); }
|
|
610
611
|
constructor(target, canvas, userConfig) {
|
|
@@ -642,7 +643,7 @@ class Renderer {
|
|
|
642
643
|
const { target } = this;
|
|
643
644
|
this.times = 0;
|
|
644
645
|
this.totalBounds = new core.Bounds();
|
|
645
|
-
debug
|
|
646
|
+
debug.log(target.innerName, '--->');
|
|
646
647
|
try {
|
|
647
648
|
if (!target.isApp)
|
|
648
649
|
target.app.emit(core.RenderEvent.CHILD_START, target);
|
|
@@ -653,9 +654,9 @@ class Renderer {
|
|
|
653
654
|
}
|
|
654
655
|
catch (e) {
|
|
655
656
|
this.rendering = false;
|
|
656
|
-
debug
|
|
657
|
+
debug.error(e);
|
|
657
658
|
}
|
|
658
|
-
debug
|
|
659
|
+
debug.log('-------------|');
|
|
659
660
|
}
|
|
660
661
|
renderAgain() {
|
|
661
662
|
if (this.rendering) {
|
|
@@ -667,9 +668,9 @@ class Renderer {
|
|
|
667
668
|
}
|
|
668
669
|
renderOnce(callback) {
|
|
669
670
|
if (this.rendering)
|
|
670
|
-
return debug
|
|
671
|
+
return debug.warn('rendering');
|
|
671
672
|
if (this.times > 3)
|
|
672
|
-
return debug
|
|
673
|
+
return debug.warn('render max times');
|
|
673
674
|
this.times++;
|
|
674
675
|
this.totalTimes++;
|
|
675
676
|
this.rendering = true;
|
|
@@ -706,7 +707,7 @@ class Renderer {
|
|
|
706
707
|
partRender() {
|
|
707
708
|
const { canvas, updateBlocks: list } = this;
|
|
708
709
|
if (!list)
|
|
709
|
-
return debug
|
|
710
|
+
return debug.warn('PartRender: need update attr');
|
|
710
711
|
this.mergeBlocks();
|
|
711
712
|
list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty())
|
|
712
713
|
this.clipRender(block); });
|
|
@@ -809,7 +810,7 @@ class Renderer {
|
|
|
809
810
|
empty = (!leaf.__world.width || !leaf.__world.height);
|
|
810
811
|
if (empty) {
|
|
811
812
|
if (!leaf.isLeafer)
|
|
812
|
-
debug
|
|
813
|
+
debug.tip(leaf.innerName, ': empty');
|
|
813
814
|
empty = (!leaf.isBranch || leaf.isBranchLeaf);
|
|
814
815
|
}
|
|
815
816
|
return empty;
|
|
@@ -975,143 +976,26 @@ class Picker {
|
|
|
975
976
|
}
|
|
976
977
|
}
|
|
977
978
|
|
|
978
|
-
const { Yes, NoAndSkip, YesAndSkip } = core.Answer;
|
|
979
|
-
const idCondition = {}, classNameCondition = {}, tagCondition = {};
|
|
980
979
|
class Selector {
|
|
981
980
|
constructor(target, userConfig) {
|
|
982
981
|
this.config = {};
|
|
983
|
-
this.innerIdMap = {};
|
|
984
|
-
this.idMap = {};
|
|
985
|
-
this.methods = {
|
|
986
|
-
id: (leaf, name) => leaf.id === name ? (this.target && (this.idMap[name] = leaf), 1) : 0,
|
|
987
|
-
innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.target && (this.innerIdMap[innerId] = leaf), 1) : 0,
|
|
988
|
-
className: (leaf, name) => leaf.className === name ? 1 : 0,
|
|
989
|
-
tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
|
|
990
|
-
tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
|
|
991
|
-
};
|
|
992
|
-
this.target = target;
|
|
993
982
|
if (userConfig)
|
|
994
983
|
this.config = core.DataHelper.default(userConfig, this.config);
|
|
995
|
-
this.picker = new Picker(target, this);
|
|
996
|
-
|
|
997
|
-
this.__listenEvents();
|
|
998
|
-
}
|
|
999
|
-
getBy(condition, branch, one, options) {
|
|
1000
|
-
switch (typeof condition) {
|
|
1001
|
-
case 'number':
|
|
1002
|
-
const leaf = this.getByInnerId(condition, branch);
|
|
1003
|
-
return one ? leaf : (leaf ? [leaf] : []);
|
|
1004
|
-
case 'string':
|
|
1005
|
-
switch (condition[0]) {
|
|
1006
|
-
case '#':
|
|
1007
|
-
idCondition.id = condition.substring(1), condition = idCondition;
|
|
1008
|
-
break;
|
|
1009
|
-
case '.':
|
|
1010
|
-
classNameCondition.className = condition.substring(1), condition = classNameCondition;
|
|
1011
|
-
break;
|
|
1012
|
-
default:
|
|
1013
|
-
tagCondition.tag = condition, condition = tagCondition;
|
|
1014
|
-
}
|
|
1015
|
-
case 'object':
|
|
1016
|
-
if (condition.id !== undefined) {
|
|
1017
|
-
const leaf = this.getById(condition.id, branch);
|
|
1018
|
-
return one ? leaf : (leaf ? [leaf] : []);
|
|
1019
|
-
}
|
|
1020
|
-
else if (condition.tag) {
|
|
1021
|
-
const { tag } = condition, isArray = tag instanceof Array;
|
|
1022
|
-
return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? core.DataHelper.toMap(tag) : tag);
|
|
1023
|
-
}
|
|
1024
|
-
else {
|
|
1025
|
-
return this.getByMethod(this.methods.className, branch, one, condition.className);
|
|
1026
|
-
}
|
|
1027
|
-
case 'function':
|
|
1028
|
-
return this.getByMethod(condition, branch, one, options);
|
|
1029
|
-
}
|
|
984
|
+
this.picker = new Picker(this.target = target, this);
|
|
985
|
+
this.finder = core.Creator.finder && core.Creator.finder();
|
|
1030
986
|
}
|
|
1031
987
|
getByPoint(hitPoint, hitRadius, options) {
|
|
1032
|
-
if (core.Platform.
|
|
1033
|
-
this.target.
|
|
988
|
+
if (core.Platform.backgrounder && this.target)
|
|
989
|
+
this.target.updateLayout();
|
|
1034
990
|
return this.picker.getByPoint(hitPoint, hitRadius, options);
|
|
1035
991
|
}
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
if (cache)
|
|
1039
|
-
return cache;
|
|
1040
|
-
this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
|
|
1041
|
-
return this.findLeaf;
|
|
1042
|
-
}
|
|
1043
|
-
getById(id, branch) {
|
|
1044
|
-
const cache = this.idMap[id];
|
|
1045
|
-
if (cache && core.LeafHelper.hasParent(cache, branch || this.target))
|
|
1046
|
-
return cache;
|
|
1047
|
-
this.eachFind(this.toChildren(branch), this.methods.id, null, id);
|
|
1048
|
-
return this.findLeaf;
|
|
1049
|
-
}
|
|
1050
|
-
getByClassName(className, branch) {
|
|
1051
|
-
return this.getByMethod(this.methods.className, branch, false, className);
|
|
1052
|
-
}
|
|
1053
|
-
getByTag(tag, branch) {
|
|
1054
|
-
return this.getByMethod(this.methods.tag, branch, false, tag);
|
|
1055
|
-
}
|
|
1056
|
-
getByMethod(method, branch, one, options) {
|
|
1057
|
-
const list = one ? null : [];
|
|
1058
|
-
this.eachFind(this.toChildren(branch), method, list, options);
|
|
1059
|
-
return list || this.findLeaf;
|
|
1060
|
-
}
|
|
1061
|
-
eachFind(children, method, list, options) {
|
|
1062
|
-
let child, result;
|
|
1063
|
-
for (let i = 0, len = children.length; i < len; i++) {
|
|
1064
|
-
child = children[i];
|
|
1065
|
-
result = method(child, options);
|
|
1066
|
-
if (result === Yes || result === YesAndSkip) {
|
|
1067
|
-
if (list) {
|
|
1068
|
-
list.push(child);
|
|
1069
|
-
}
|
|
1070
|
-
else {
|
|
1071
|
-
this.findLeaf = child;
|
|
1072
|
-
return;
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
if (child.isBranch && result < NoAndSkip)
|
|
1076
|
-
this.eachFind(child.children, method, list, options);
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
toChildren(branch) {
|
|
1080
|
-
this.findLeaf = null;
|
|
1081
|
-
return [branch || this.target];
|
|
1082
|
-
}
|
|
1083
|
-
__onRemoveChild(event) {
|
|
1084
|
-
const { id, innerId } = event.child;
|
|
1085
|
-
if (this.idMap[id])
|
|
1086
|
-
delete this.idMap[id];
|
|
1087
|
-
if (this.innerIdMap[innerId])
|
|
1088
|
-
delete this.innerIdMap[innerId];
|
|
1089
|
-
}
|
|
1090
|
-
__checkIdChange(event) {
|
|
1091
|
-
if (event.attrName === 'id') {
|
|
1092
|
-
const id = event.oldValue;
|
|
1093
|
-
if (this.idMap[id])
|
|
1094
|
-
delete this.idMap[id];
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
__listenEvents() {
|
|
1098
|
-
this.__eventIds = [
|
|
1099
|
-
this.target.on_(core.ChildEvent.REMOVE, this.__onRemoveChild, this),
|
|
1100
|
-
this.target.on_(core.PropertyEvent.CHANGE, this.__checkIdChange, this)
|
|
1101
|
-
];
|
|
1102
|
-
}
|
|
1103
|
-
__removeListenEvents() {
|
|
1104
|
-
this.target.off_(this.__eventIds);
|
|
1105
|
-
this.__eventIds.length = 0;
|
|
992
|
+
getBy(condition, branch, one, options) {
|
|
993
|
+
return this.finder ? this.finder.getBy(condition, branch, one, options) : core.Plugin.need('find');
|
|
1106
994
|
}
|
|
1107
995
|
destroy() {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
this.
|
|
1111
|
-
this.findLeaf = null;
|
|
1112
|
-
this.innerIdMap = {};
|
|
1113
|
-
this.idMap = {};
|
|
1114
|
-
}
|
|
996
|
+
this.picker.destroy();
|
|
997
|
+
if (this.finder)
|
|
998
|
+
this.finder.destroy();
|
|
1115
999
|
}
|
|
1116
1000
|
}
|
|
1117
1001
|
|
|
@@ -2938,197 +2822,12 @@ const ColorConvertModule = {
|
|
|
2938
2822
|
string
|
|
2939
2823
|
};
|
|
2940
2824
|
|
|
2941
|
-
const { setPoint, addPoint, toBounds } = core.TwoPointBoundsHelper;
|
|
2942
|
-
function getTrimBounds(canvas) {
|
|
2943
|
-
const { width, height } = canvas.view;
|
|
2944
|
-
const { data } = canvas.context.getImageData(0, 0, width, height);
|
|
2945
|
-
let x, y, pointBounds, index = 0;
|
|
2946
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
2947
|
-
if (data[i + 3] !== 0) {
|
|
2948
|
-
x = index % width;
|
|
2949
|
-
y = (index - x) / width;
|
|
2950
|
-
pointBounds ? addPoint(pointBounds, x, y) : setPoint(pointBounds = {}, x, y);
|
|
2951
|
-
}
|
|
2952
|
-
index++;
|
|
2953
|
-
}
|
|
2954
|
-
const bounds = new core.Bounds();
|
|
2955
|
-
toBounds(pointBounds, bounds);
|
|
2956
|
-
return bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
2957
|
-
}
|
|
2958
|
-
|
|
2959
|
-
const ExportModule = {
|
|
2960
|
-
export(leaf, filename, options) {
|
|
2961
|
-
this.running = true;
|
|
2962
|
-
const fileType = core.FileHelper.fileType(filename);
|
|
2963
|
-
const isDownload = filename.includes('.');
|
|
2964
|
-
options = core.FileHelper.getExportOptions(options);
|
|
2965
|
-
return addTask((success) => new Promise((resolve) => {
|
|
2966
|
-
const over = (result) => {
|
|
2967
|
-
success(result);
|
|
2968
|
-
resolve();
|
|
2969
|
-
this.running = false;
|
|
2970
|
-
};
|
|
2971
|
-
const { toURL } = core.Platform;
|
|
2972
|
-
const { download } = core.Platform.origin;
|
|
2973
|
-
if (fileType === 'json') {
|
|
2974
|
-
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
2975
|
-
return over({ data: isDownload ? true : leaf.toJSON(options.json) });
|
|
2976
|
-
}
|
|
2977
|
-
if (fileType === 'svg') {
|
|
2978
|
-
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2979
|
-
return over({ data: isDownload ? true : leaf.toSVG() });
|
|
2980
|
-
}
|
|
2981
|
-
const { leafer } = leaf;
|
|
2982
|
-
if (leafer) {
|
|
2983
|
-
checkLazy(leaf);
|
|
2984
|
-
leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
|
|
2985
|
-
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2986
|
-
const { worldTransform, isLeafer, isFrame } = leaf;
|
|
2987
|
-
const { slice, trim, onCanvas } = options;
|
|
2988
|
-
const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
|
|
2989
|
-
const contextSettings = options.contextSettings || leafer.config.contextSettings;
|
|
2990
|
-
const screenshot = options.screenshot || leaf.isApp;
|
|
2991
|
-
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
2992
|
-
const needFill = core.FileHelper.isOpaqueImage(filename) || fill, matrix = new core.Matrix();
|
|
2993
|
-
if (screenshot) {
|
|
2994
|
-
renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
|
|
2995
|
-
}
|
|
2996
|
-
else {
|
|
2997
|
-
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
2998
|
-
scaleX = worldTransform.scaleX;
|
|
2999
|
-
scaleY = worldTransform.scaleY;
|
|
3000
|
-
switch (relative) {
|
|
3001
|
-
case 'inner':
|
|
3002
|
-
matrix.set(worldTransform);
|
|
3003
|
-
break;
|
|
3004
|
-
case 'local':
|
|
3005
|
-
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
3006
|
-
scaleX /= leaf.scaleX;
|
|
3007
|
-
scaleY /= leaf.scaleY;
|
|
3008
|
-
break;
|
|
3009
|
-
case 'world':
|
|
3010
|
-
scaleX = 1;
|
|
3011
|
-
scaleY = 1;
|
|
3012
|
-
break;
|
|
3013
|
-
case 'page':
|
|
3014
|
-
relative = leaf.leafer;
|
|
3015
|
-
default:
|
|
3016
|
-
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
3017
|
-
const l = relative.worldTransform;
|
|
3018
|
-
scaleX /= scaleX / l.scaleX;
|
|
3019
|
-
scaleY /= scaleY / l.scaleY;
|
|
3020
|
-
}
|
|
3021
|
-
renderBounds = leaf.getBounds('render', relative);
|
|
3022
|
-
}
|
|
3023
|
-
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
3024
|
-
core.MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
3025
|
-
let pixelRatio = options.pixelRatio || 1;
|
|
3026
|
-
if (leaf.isApp) {
|
|
3027
|
-
scaleData.scaleX *= pixelRatio;
|
|
3028
|
-
scaleData.scaleY *= pixelRatio;
|
|
3029
|
-
pixelRatio = leaf.app.pixelRatio;
|
|
3030
|
-
}
|
|
3031
|
-
const { x, y, width, height } = new core.Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
3032
|
-
const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
|
|
3033
|
-
let canvas = core.Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
|
|
3034
|
-
let sliceLeaf;
|
|
3035
|
-
if (slice) {
|
|
3036
|
-
sliceLeaf = leaf;
|
|
3037
|
-
sliceLeaf.__worldOpacity = 0;
|
|
3038
|
-
leaf = leafer;
|
|
3039
|
-
renderOptions.bounds = canvas.bounds;
|
|
3040
|
-
}
|
|
3041
|
-
canvas.save();
|
|
3042
|
-
if (isFrame && fill !== undefined) {
|
|
3043
|
-
const oldFill = leaf.get('fill');
|
|
3044
|
-
leaf.fill = '';
|
|
3045
|
-
leaf.__render(canvas, renderOptions);
|
|
3046
|
-
leaf.fill = oldFill;
|
|
3047
|
-
}
|
|
3048
|
-
else {
|
|
3049
|
-
leaf.__render(canvas, renderOptions);
|
|
3050
|
-
}
|
|
3051
|
-
canvas.restore();
|
|
3052
|
-
if (sliceLeaf)
|
|
3053
|
-
sliceLeaf.__updateWorldOpacity();
|
|
3054
|
-
if (trim) {
|
|
3055
|
-
trimBounds = getTrimBounds(canvas);
|
|
3056
|
-
const old = canvas, { width, height } = trimBounds;
|
|
3057
|
-
const config = { x: 0, y: 0, width, height, pixelRatio };
|
|
3058
|
-
canvas = core.Creator.canvas(config);
|
|
3059
|
-
canvas.copyWorld(old, trimBounds, config);
|
|
3060
|
-
}
|
|
3061
|
-
if (needFill)
|
|
3062
|
-
canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
|
|
3063
|
-
if (onCanvas)
|
|
3064
|
-
onCanvas(canvas);
|
|
3065
|
-
const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
|
|
3066
|
-
over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
|
|
3067
|
-
}));
|
|
3068
|
-
}
|
|
3069
|
-
else {
|
|
3070
|
-
over({ data: false });
|
|
3071
|
-
}
|
|
3072
|
-
}));
|
|
3073
|
-
}
|
|
3074
|
-
};
|
|
3075
|
-
let tasker;
|
|
3076
|
-
function addTask(task) {
|
|
3077
|
-
if (!tasker)
|
|
3078
|
-
tasker = new core.TaskProcessor();
|
|
3079
|
-
return new Promise((resolve) => {
|
|
3080
|
-
tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
|
|
3081
|
-
});
|
|
3082
|
-
}
|
|
3083
|
-
function checkLazy(leaf) {
|
|
3084
|
-
if (leaf.__.__needComputePaint)
|
|
3085
|
-
leaf.__.__computePaint();
|
|
3086
|
-
if (leaf.isBranch)
|
|
3087
|
-
leaf.children.forEach(child => checkLazy(child));
|
|
3088
|
-
}
|
|
3089
|
-
|
|
3090
|
-
const canvas = core.LeaferCanvasBase.prototype;
|
|
3091
|
-
const debug = core.Debug.get('@leafer-ui/export');
|
|
3092
|
-
canvas.export = function (filename, options) {
|
|
3093
|
-
const { quality, blob } = core.FileHelper.getExportOptions(options);
|
|
3094
|
-
if (filename.includes('.'))
|
|
3095
|
-
return this.saveAs(filename, quality);
|
|
3096
|
-
else if (blob)
|
|
3097
|
-
return this.toBlob(filename, quality);
|
|
3098
|
-
else
|
|
3099
|
-
return this.toDataURL(filename, quality);
|
|
3100
|
-
};
|
|
3101
|
-
canvas.toBlob = function (type, quality) {
|
|
3102
|
-
return new Promise((resolve) => {
|
|
3103
|
-
core.Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
|
|
3104
|
-
resolve(blob);
|
|
3105
|
-
}).catch((e) => {
|
|
3106
|
-
debug.error(e);
|
|
3107
|
-
resolve(null);
|
|
3108
|
-
});
|
|
3109
|
-
});
|
|
3110
|
-
};
|
|
3111
|
-
canvas.toDataURL = function (type, quality) {
|
|
3112
|
-
return core.Platform.origin.canvasToDataURL(this.view, type, quality);
|
|
3113
|
-
};
|
|
3114
|
-
canvas.saveAs = function (filename, quality) {
|
|
3115
|
-
return new Promise((resolve) => {
|
|
3116
|
-
core.Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
|
|
3117
|
-
resolve(true);
|
|
3118
|
-
}).catch((e) => {
|
|
3119
|
-
debug.error(e);
|
|
3120
|
-
resolve(false);
|
|
3121
|
-
});
|
|
3122
|
-
});
|
|
3123
|
-
};
|
|
3124
|
-
|
|
3125
2825
|
Object.assign(draw.TextConvert, TextConvertModule);
|
|
3126
2826
|
Object.assign(draw.ColorConvert, ColorConvertModule);
|
|
3127
2827
|
Object.assign(draw.Paint, PaintModule);
|
|
3128
2828
|
Object.assign(draw.PaintImage, PaintImageModule);
|
|
3129
2829
|
Object.assign(draw.PaintGradient, PaintGradientModule);
|
|
3130
2830
|
Object.assign(draw.Effect, EffectModule);
|
|
3131
|
-
Object.assign(draw.Export, ExportModule);
|
|
3132
2831
|
|
|
3133
2832
|
Object.assign(core.Creator, {
|
|
3134
2833
|
interaction: (target, canvas, selector, options) => new Interaction(target, canvas, selector, options),
|
|
@@ -3144,6 +2843,7 @@ Object.defineProperty(exports, "LeaferImage", {
|
|
|
3144
2843
|
exports.Interaction = Interaction;
|
|
3145
2844
|
exports.Layouter = Layouter;
|
|
3146
2845
|
exports.LeaferCanvas = LeaferCanvas;
|
|
2846
|
+
exports.Picker = Picker;
|
|
3147
2847
|
exports.Renderer = Renderer;
|
|
3148
2848
|
exports.Selector = Selector;
|
|
3149
2849
|
exports.Watcher = Watcher;
|