@leafer-draw/node 1.8.0 → 1.9.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.
- package/dist/node.cjs +1169 -1055
- package/dist/node.esm.js +1153 -1049
- package/dist/node.esm.min.js +1 -1
- package/dist/node.esm.min.js.map +1 -1
- package/dist/node.min.cjs +1 -1
- package/dist/node.min.cjs.map +1 -1
- package/package.json +10 -10
package/dist/node.cjs
CHANGED
|
@@ -1,43 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var core = require(
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
step(
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var core = require("@leafer/core");
|
|
4
|
+
|
|
5
|
+
var fs = require("fs");
|
|
6
|
+
|
|
7
|
+
var draw = require("@leafer-ui/draw");
|
|
8
|
+
|
|
9
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
10
|
+
function adopt(value) {
|
|
11
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
12
|
+
resolve(value);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
16
|
+
function fulfilled(value) {
|
|
17
|
+
try {
|
|
18
|
+
step(generator.next(value));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
reject(e);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function rejected(value) {
|
|
24
|
+
try {
|
|
25
|
+
step(generator["throw"](value));
|
|
26
|
+
} catch (e) {
|
|
27
|
+
reject(e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function step(result) {
|
|
31
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
32
|
+
}
|
|
33
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
38
|
+
var e = new Error(message);
|
|
39
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
37
40
|
};
|
|
38
41
|
|
|
39
42
|
class LeaferCanvas extends core.LeaferCanvasBase {
|
|
40
|
-
get allowBackgroundColor() {
|
|
43
|
+
get allowBackgroundColor() {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
41
46
|
init() {
|
|
42
47
|
this.__createView();
|
|
43
48
|
this.__createContext();
|
|
@@ -51,84 +56,114 @@ class LeaferCanvas extends core.LeaferCanvasBase {
|
|
|
51
56
|
this.view = core.Platform.origin.createCanvas(1, 1);
|
|
52
57
|
}
|
|
53
58
|
updateViewSize() {
|
|
54
|
-
const { width, height, pixelRatio } = this;
|
|
59
|
+
const {width: width, height: height, pixelRatio: pixelRatio} = this;
|
|
55
60
|
this.view.width = Math.ceil(width * pixelRatio);
|
|
56
61
|
this.view.height = Math.ceil(height * pixelRatio);
|
|
57
62
|
this.clientBounds = this.bounds;
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
const { mineType, fileType } = core.FileHelper;
|
|
66
|
+
const {mineType: mineType, fileType: fileType} = core.FileHelper;
|
|
67
|
+
|
|
62
68
|
Object.assign(core.Creator, {
|
|
63
69
|
canvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
64
|
-
image:
|
|
70
|
+
image: options => new core.LeaferImage(options)
|
|
65
71
|
});
|
|
72
|
+
|
|
66
73
|
function useCanvas(canvasType, power) {
|
|
67
74
|
core.Platform.canvasType = canvasType;
|
|
68
75
|
if (!core.Platform.origin) {
|
|
69
|
-
if (canvasType ===
|
|
70
|
-
const { Canvas, loadImage } = power;
|
|
76
|
+
if (canvasType === "skia") {
|
|
77
|
+
const {Canvas: Canvas, loadImage: loadImage} = power;
|
|
71
78
|
core.Platform.origin = {
|
|
72
79
|
createCanvas: (width, height, format) => new Canvas(width, height, format),
|
|
73
|
-
canvasToDataURL: (canvas, type, quality) => canvas.toDataURLSync(type, {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
canvasToDataURL: (canvas, type, quality) => canvas.toDataURLSync(type, {
|
|
81
|
+
quality: quality
|
|
82
|
+
}),
|
|
83
|
+
canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, {
|
|
84
|
+
quality: quality
|
|
85
|
+
}),
|
|
86
|
+
canvasSaveAs: (canvas, filename, quality) => canvas.saveAs(filename, {
|
|
87
|
+
quality: quality
|
|
88
|
+
}),
|
|
89
|
+
download(_url, _filename) {
|
|
90
|
+
return undefined;
|
|
91
|
+
},
|
|
92
|
+
loadImage(src) {
|
|
93
|
+
return loadImage(core.Platform.image.getRealURL(src));
|
|
94
|
+
}
|
|
78
95
|
};
|
|
79
96
|
core.Platform.roundRectPatch = true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const { Canvas, loadImage } = power;
|
|
97
|
+
} else if (canvasType === "napi") {
|
|
98
|
+
const {Canvas: Canvas, loadImage: loadImage} = power;
|
|
83
99
|
core.Platform.origin = {
|
|
84
100
|
createCanvas: (width, height, format) => new Canvas(width, height, format),
|
|
85
101
|
canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
|
|
86
|
-
canvasToBolb: (canvas, type, quality) => __awaiter(this, void 0, void 0, function*
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
102
|
+
canvasToBolb: (canvas, type, quality) => __awaiter(this, void 0, void 0, function*() {
|
|
103
|
+
return canvas.toBuffer(mineType(type), quality);
|
|
104
|
+
}),
|
|
105
|
+
canvasSaveAs: (canvas, filename, quality) => __awaiter(this, void 0, void 0, function*() {
|
|
106
|
+
return fs.writeFileSync(filename, canvas.toBuffer(mineType(fileType(filename)), quality));
|
|
107
|
+
}),
|
|
108
|
+
download(_url, _filename) {
|
|
109
|
+
return undefined;
|
|
110
|
+
},
|
|
111
|
+
loadImage(src) {
|
|
112
|
+
return loadImage(core.Platform.image.getRealURL(src));
|
|
113
|
+
}
|
|
90
114
|
};
|
|
91
115
|
}
|
|
92
116
|
core.Platform.ellipseToCurve = true;
|
|
93
117
|
core.Platform.event = {
|
|
94
|
-
stopDefault(_origin) {
|
|
95
|
-
stopNow(_origin) {
|
|
96
|
-
stop(_origin) {
|
|
118
|
+
stopDefault(_origin) {},
|
|
119
|
+
stopNow(_origin) {},
|
|
120
|
+
stop(_origin) {}
|
|
97
121
|
};
|
|
98
122
|
core.Platform.canvas = core.Creator.canvas();
|
|
99
123
|
}
|
|
100
124
|
}
|
|
101
|
-
|
|
125
|
+
|
|
126
|
+
core.Platform.name = "node";
|
|
127
|
+
|
|
102
128
|
core.Platform.backgrounder = true;
|
|
103
|
-
|
|
104
|
-
core.
|
|
129
|
+
|
|
130
|
+
core.Platform.requestRender = function(render) {
|
|
131
|
+
setTimeout(render, 16);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
core.defineKey(core.Platform, "devicePixelRatio", {
|
|
135
|
+
get() {
|
|
136
|
+
return 1;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
105
140
|
core.Platform.conicGradientSupport = true;
|
|
106
141
|
|
|
107
142
|
class Watcher {
|
|
108
|
-
get childrenChanged() {
|
|
143
|
+
get childrenChanged() {
|
|
144
|
+
return this.hasAdd || this.hasRemove || this.hasVisible;
|
|
145
|
+
}
|
|
109
146
|
get updatedList() {
|
|
110
147
|
if (this.hasRemove) {
|
|
111
|
-
const updatedList = new core.LeafList
|
|
112
|
-
this.__updatedList.list.forEach(item => {
|
|
113
|
-
updatedList.add(item);
|
|
148
|
+
const updatedList = new core.LeafList;
|
|
149
|
+
this.__updatedList.list.forEach(item => {
|
|
150
|
+
if (item.leafer) updatedList.add(item);
|
|
151
|
+
});
|
|
114
152
|
return updatedList;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
153
|
+
} else {
|
|
117
154
|
return this.__updatedList;
|
|
118
155
|
}
|
|
119
156
|
}
|
|
120
157
|
constructor(target, userConfig) {
|
|
121
158
|
this.totalTimes = 0;
|
|
122
159
|
this.config = {};
|
|
123
|
-
this.__updatedList = new core.LeafList
|
|
160
|
+
this.__updatedList = new core.LeafList;
|
|
124
161
|
this.target = target;
|
|
125
|
-
if (userConfig)
|
|
126
|
-
this.config = core.DataHelper.default(userConfig, this.config);
|
|
162
|
+
if (userConfig) this.config = core.DataHelper.default(userConfig, this.config);
|
|
127
163
|
this.__listenEvents();
|
|
128
164
|
}
|
|
129
165
|
start() {
|
|
130
|
-
if (this.disabled)
|
|
131
|
-
return;
|
|
166
|
+
if (this.disabled) return;
|
|
132
167
|
this.running = true;
|
|
133
168
|
}
|
|
134
169
|
stop() {
|
|
@@ -141,8 +176,7 @@ class Watcher {
|
|
|
141
176
|
}
|
|
142
177
|
update() {
|
|
143
178
|
this.changed = true;
|
|
144
|
-
if (this.running)
|
|
145
|
-
this.target.emit(core.RenderEvent.REQUEST);
|
|
179
|
+
if (this.running) this.target.emit(core.RenderEvent.REQUEST);
|
|
146
180
|
}
|
|
147
181
|
__onAttrChange(event) {
|
|
148
182
|
this.__updatedList.add(event.target);
|
|
@@ -152,8 +186,7 @@ class Watcher {
|
|
|
152
186
|
if (event.type === core.ChildEvent.ADD) {
|
|
153
187
|
this.hasAdd = true;
|
|
154
188
|
this.__pushChild(event.child);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
189
|
+
} else {
|
|
157
190
|
this.hasRemove = true;
|
|
158
191
|
this.__updatedList.add(event.parent);
|
|
159
192
|
}
|
|
@@ -161,28 +194,22 @@ class Watcher {
|
|
|
161
194
|
}
|
|
162
195
|
__pushChild(child) {
|
|
163
196
|
this.__updatedList.add(child);
|
|
164
|
-
if (child.isBranch)
|
|
165
|
-
this.__loopChildren(child);
|
|
197
|
+
if (child.isBranch) this.__loopChildren(child);
|
|
166
198
|
}
|
|
167
199
|
__loopChildren(parent) {
|
|
168
|
-
const { children
|
|
169
|
-
for (let i = 0, len = children.length; i < len; i++)
|
|
170
|
-
this.__pushChild(children[i]);
|
|
200
|
+
const {children: children} = parent;
|
|
201
|
+
for (let i = 0, len = children.length; i < len; i++) this.__pushChild(children[i]);
|
|
171
202
|
}
|
|
172
203
|
__onRquestData() {
|
|
173
|
-
this.target.emitEvent(new core.WatchEvent(core.WatchEvent.DATA, {
|
|
174
|
-
|
|
204
|
+
this.target.emitEvent(new core.WatchEvent(core.WatchEvent.DATA, {
|
|
205
|
+
updatedList: this.updatedList
|
|
206
|
+
}));
|
|
207
|
+
this.__updatedList = new core.LeafList;
|
|
175
208
|
this.totalTimes++;
|
|
176
209
|
this.changed = this.hasVisible = this.hasRemove = this.hasAdd = false;
|
|
177
210
|
}
|
|
178
211
|
__listenEvents() {
|
|
179
|
-
this.__eventIds = [
|
|
180
|
-
this.target.on_([
|
|
181
|
-
[core.PropertyEvent.CHANGE, this.__onAttrChange, this],
|
|
182
|
-
[[core.ChildEvent.ADD, core.ChildEvent.REMOVE], this.__onChildEvent, this],
|
|
183
|
-
[core.WatchEvent.REQUEST, this.__onRquestData, this]
|
|
184
|
-
])
|
|
185
|
-
];
|
|
212
|
+
this.__eventIds = [ this.target.on_([ [ core.PropertyEvent.CHANGE, this.__onAttrChange, this ], [ [ core.ChildEvent.ADD, core.ChildEvent.REMOVE ], this.__onChildEvent, this ], [ core.WatchEvent.REQUEST, this.__onRquestData, this ] ]) ];
|
|
186
213
|
}
|
|
187
214
|
__removeListenEvents() {
|
|
188
215
|
this.target.off_(this.__eventIds);
|
|
@@ -196,8 +223,10 @@ class Watcher {
|
|
|
196
223
|
}
|
|
197
224
|
}
|
|
198
225
|
|
|
199
|
-
const {
|
|
200
|
-
|
|
226
|
+
const {updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateChange: updateOneChange} = core.LeafHelper;
|
|
227
|
+
|
|
228
|
+
const {pushAllChildBranch: pushAllChildBranch, pushAllParent: pushAllParent} = core.BranchHelper;
|
|
229
|
+
|
|
201
230
|
function updateMatrix(updateList, levelList) {
|
|
202
231
|
let layout;
|
|
203
232
|
updateList.list.forEach(leaf => {
|
|
@@ -206,19 +235,17 @@ function updateMatrix(updateList, levelList) {
|
|
|
206
235
|
if (layout.matrixChanged) {
|
|
207
236
|
updateAllMatrix$1(leaf, true);
|
|
208
237
|
levelList.add(leaf);
|
|
209
|
-
if (leaf.isBranch)
|
|
210
|
-
pushAllChildBranch(leaf, levelList);
|
|
238
|
+
if (leaf.isBranch) pushAllChildBranch(leaf, levelList);
|
|
211
239
|
pushAllParent(leaf, levelList);
|
|
212
|
-
}
|
|
213
|
-
else if (layout.boundsChanged) {
|
|
240
|
+
} else if (layout.boundsChanged) {
|
|
214
241
|
levelList.add(leaf);
|
|
215
|
-
if (leaf.isBranch)
|
|
216
|
-
leaf.__tempNumber = 0;
|
|
242
|
+
if (leaf.isBranch) leaf.__tempNumber = 0;
|
|
217
243
|
pushAllParent(leaf, levelList);
|
|
218
244
|
}
|
|
219
245
|
}
|
|
220
246
|
});
|
|
221
247
|
}
|
|
248
|
+
|
|
222
249
|
function updateBounds(boundsList) {
|
|
223
250
|
let list, branch, children;
|
|
224
251
|
boundsList.sort(true);
|
|
@@ -238,18 +265,19 @@ function updateBounds(boundsList) {
|
|
|
238
265
|
}
|
|
239
266
|
});
|
|
240
267
|
}
|
|
268
|
+
|
|
241
269
|
function updateChange(updateList) {
|
|
242
270
|
updateList.list.forEach(updateOneChange);
|
|
243
271
|
}
|
|
244
272
|
|
|
245
|
-
const { worldBounds
|
|
273
|
+
const {worldBounds: worldBounds} = core.LeafBoundsHelper;
|
|
274
|
+
|
|
246
275
|
class LayoutBlockData {
|
|
247
276
|
constructor(list) {
|
|
248
|
-
this.updatedBounds = new core.Bounds
|
|
249
|
-
this.beforeBounds = new core.Bounds
|
|
250
|
-
this.afterBounds = new core.Bounds
|
|
251
|
-
if (list
|
|
252
|
-
list = new core.LeafList(list);
|
|
277
|
+
this.updatedBounds = new core.Bounds;
|
|
278
|
+
this.beforeBounds = new core.Bounds;
|
|
279
|
+
this.afterBounds = new core.Bounds;
|
|
280
|
+
if (core.isArray(list)) list = new core.LeafList(list);
|
|
253
281
|
this.updatedList = list;
|
|
254
282
|
}
|
|
255
283
|
setBefore() {
|
|
@@ -257,7 +285,7 @@ class LayoutBlockData {
|
|
|
257
285
|
}
|
|
258
286
|
setAfter() {
|
|
259
287
|
this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
|
|
260
|
-
this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
|
|
288
|
+
this.updatedBounds.setList([ this.beforeBounds, this.afterBounds ]);
|
|
261
289
|
}
|
|
262
290
|
merge(data) {
|
|
263
291
|
this.updatedList.addList(data.updatedList.list);
|
|
@@ -270,21 +298,21 @@ class LayoutBlockData {
|
|
|
270
298
|
}
|
|
271
299
|
}
|
|
272
300
|
|
|
273
|
-
const { updateAllMatrix, updateAllChange } = core.LeafHelper;
|
|
274
|
-
|
|
301
|
+
const {updateAllMatrix: updateAllMatrix, updateAllChange: updateAllChange} = core.LeafHelper;
|
|
302
|
+
|
|
303
|
+
const debug$2 = core.Debug.get("Layouter");
|
|
304
|
+
|
|
275
305
|
class Layouter {
|
|
276
306
|
constructor(target, userConfig) {
|
|
277
307
|
this.totalTimes = 0;
|
|
278
308
|
this.config = {};
|
|
279
|
-
this.__levelList = new core.LeafLevelList
|
|
309
|
+
this.__levelList = new core.LeafLevelList;
|
|
280
310
|
this.target = target;
|
|
281
|
-
if (userConfig)
|
|
282
|
-
this.config = core.DataHelper.default(userConfig, this.config);
|
|
311
|
+
if (userConfig) this.config = core.DataHelper.default(userConfig, this.config);
|
|
283
312
|
this.__listenEvents();
|
|
284
313
|
}
|
|
285
314
|
start() {
|
|
286
|
-
if (this.disabled)
|
|
287
|
-
return;
|
|
315
|
+
if (this.disabled) return;
|
|
288
316
|
this.running = true;
|
|
289
317
|
}
|
|
290
318
|
stop() {
|
|
@@ -296,16 +324,14 @@ class Layouter {
|
|
|
296
324
|
this.disabled = true;
|
|
297
325
|
}
|
|
298
326
|
layout() {
|
|
299
|
-
if (this.layouting || !this.running)
|
|
300
|
-
|
|
301
|
-
const { target } = this;
|
|
327
|
+
if (this.layouting || !this.running) return;
|
|
328
|
+
const {target: target} = this;
|
|
302
329
|
this.times = 0;
|
|
303
330
|
try {
|
|
304
331
|
target.emit(core.LayoutEvent.START);
|
|
305
332
|
this.layoutOnce();
|
|
306
333
|
target.emitEvent(new core.LayoutEvent(core.LayoutEvent.END, this.layoutedBlocks, this.times));
|
|
307
|
-
}
|
|
308
|
-
catch (e) {
|
|
334
|
+
} catch (e) {
|
|
309
335
|
debug$2.error(e);
|
|
310
336
|
}
|
|
311
337
|
this.layoutedBlocks = null;
|
|
@@ -313,24 +339,20 @@ class Layouter {
|
|
|
313
339
|
layoutAgain() {
|
|
314
340
|
if (this.layouting) {
|
|
315
341
|
this.waitAgain = true;
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
342
|
+
} else {
|
|
318
343
|
this.layoutOnce();
|
|
319
344
|
}
|
|
320
345
|
}
|
|
321
346
|
layoutOnce() {
|
|
322
|
-
if (this.layouting)
|
|
323
|
-
|
|
324
|
-
if (this.times > 3)
|
|
325
|
-
return debug$2.warn('layout max times');
|
|
347
|
+
if (this.layouting) return debug$2.warn("layouting");
|
|
348
|
+
if (this.times > 3) return debug$2.warn("layout max times");
|
|
326
349
|
this.times++;
|
|
327
350
|
this.totalTimes++;
|
|
328
351
|
this.layouting = true;
|
|
329
352
|
this.target.emit(core.WatchEvent.REQUEST);
|
|
330
353
|
if (this.totalTimes > 1) {
|
|
331
354
|
this.partLayout();
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
355
|
+
} else {
|
|
334
356
|
this.fullLayout();
|
|
335
357
|
}
|
|
336
358
|
this.layouting = false;
|
|
@@ -341,11 +363,10 @@ class Layouter {
|
|
|
341
363
|
}
|
|
342
364
|
partLayout() {
|
|
343
365
|
var _a;
|
|
344
|
-
if (!((_a = this.__updatedList) === null || _a === void 0 ? void 0 : _a.length))
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
const {
|
|
348
|
-
const { BEFORE, LAYOUT, AFTER } = core.LayoutEvent;
|
|
366
|
+
if (!((_a = this.__updatedList) === null || _a === void 0 ? void 0 : _a.length)) return;
|
|
367
|
+
const t = core.Run.start("PartLayout");
|
|
368
|
+
const {target: target, __updatedList: updateList} = this;
|
|
369
|
+
const {BEFORE: BEFORE, LAYOUT: LAYOUT, AFTER: AFTER} = core.LayoutEvent;
|
|
349
370
|
const blocks = this.getBlocks(updateList);
|
|
350
371
|
blocks.forEach(item => item.setBefore());
|
|
351
372
|
target.emitEvent(new core.LayoutEvent(BEFORE, blocks, this.times));
|
|
@@ -354,8 +375,7 @@ class Layouter {
|
|
|
354
375
|
updateMatrix(updateList, this.__levelList);
|
|
355
376
|
updateBounds(this.__levelList);
|
|
356
377
|
updateChange(updateList);
|
|
357
|
-
if (this.extraBlock)
|
|
358
|
-
blocks.push(this.extraBlock);
|
|
378
|
+
if (this.extraBlock) blocks.push(this.extraBlock);
|
|
359
379
|
blocks.forEach(item => item.setAfter());
|
|
360
380
|
target.emitEvent(new core.LayoutEvent(LAYOUT, blocks, this.times));
|
|
361
381
|
target.emitEvent(new core.LayoutEvent(AFTER, blocks, this.times));
|
|
@@ -365,13 +385,15 @@ class Layouter {
|
|
|
365
385
|
core.Run.end(t);
|
|
366
386
|
}
|
|
367
387
|
fullLayout() {
|
|
368
|
-
const t = core.Run.start(
|
|
369
|
-
const { target
|
|
370
|
-
const { BEFORE, LAYOUT, AFTER } = core.LayoutEvent;
|
|
388
|
+
const t = core.Run.start("FullLayout");
|
|
389
|
+
const {target: target} = this;
|
|
390
|
+
const {BEFORE: BEFORE, LAYOUT: LAYOUT, AFTER: AFTER} = core.LayoutEvent;
|
|
371
391
|
const blocks = this.getBlocks(new core.LeafList(target));
|
|
372
392
|
target.emitEvent(new core.LayoutEvent(BEFORE, blocks, this.times));
|
|
373
393
|
Layouter.fullLayout(target);
|
|
374
|
-
blocks.forEach(item => {
|
|
394
|
+
blocks.forEach(item => {
|
|
395
|
+
item.setAfter();
|
|
396
|
+
});
|
|
375
397
|
target.emitEvent(new core.LayoutEvent(LAYOUT, blocks, this.times));
|
|
376
398
|
target.emitEvent(new core.LayoutEvent(AFTER, blocks, this.times));
|
|
377
399
|
this.addBlocks(blocks);
|
|
@@ -379,15 +401,12 @@ class Layouter {
|
|
|
379
401
|
}
|
|
380
402
|
static fullLayout(target) {
|
|
381
403
|
updateAllMatrix(target, true);
|
|
382
|
-
if (target.isBranch)
|
|
383
|
-
core.BranchHelper.updateBounds(target);
|
|
384
|
-
else
|
|
385
|
-
core.LeafHelper.updateBounds(target);
|
|
404
|
+
if (target.isBranch) core.BranchHelper.updateBounds(target); else core.LeafHelper.updateBounds(target);
|
|
386
405
|
updateAllChange(target);
|
|
387
406
|
}
|
|
388
407
|
addExtra(leaf) {
|
|
389
408
|
if (!this.__updatedList.has(leaf)) {
|
|
390
|
-
const { updatedList, beforeBounds } = this.extraBlock || (this.extraBlock = new LayoutBlockData([]));
|
|
409
|
+
const {updatedList: updatedList, beforeBounds: beforeBounds} = this.extraBlock || (this.extraBlock = new LayoutBlockData([]));
|
|
391
410
|
updatedList.length ? beforeBounds.add(leaf.__world) : beforeBounds.set(leaf.__world);
|
|
392
411
|
updatedList.add(leaf);
|
|
393
412
|
}
|
|
@@ -396,7 +415,7 @@ class Layouter {
|
|
|
396
415
|
return new LayoutBlockData(data);
|
|
397
416
|
}
|
|
398
417
|
getBlocks(list) {
|
|
399
|
-
return [this.createBlock(list)];
|
|
418
|
+
return [ this.createBlock(list) ];
|
|
400
419
|
}
|
|
401
420
|
addBlocks(current) {
|
|
402
421
|
this.layoutedBlocks ? this.layoutedBlocks.push(...current) : this.layoutedBlocks = current;
|
|
@@ -405,13 +424,7 @@ class Layouter {
|
|
|
405
424
|
this.__updatedList = event.data.updatedList;
|
|
406
425
|
}
|
|
407
426
|
__listenEvents() {
|
|
408
|
-
this.__eventIds = [
|
|
409
|
-
this.target.on_([
|
|
410
|
-
[core.LayoutEvent.REQUEST, this.layout, this],
|
|
411
|
-
[core.LayoutEvent.AGAIN, this.layoutAgain, this],
|
|
412
|
-
[core.WatchEvent.DATA, this.__onReceiveWatchData, this]
|
|
413
|
-
])
|
|
414
|
-
];
|
|
427
|
+
this.__eventIds = [ this.target.on_([ [ core.LayoutEvent.REQUEST, this.layout, this ], [ core.LayoutEvent.AGAIN, this.layoutAgain, this ], [ core.WatchEvent.DATA, this.__onReceiveWatchData, this ] ]) ];
|
|
415
428
|
}
|
|
416
429
|
__removeListenEvents() {
|
|
417
430
|
this.target.off_(this.__eventIds);
|
|
@@ -425,9 +438,12 @@ class Layouter {
|
|
|
425
438
|
}
|
|
426
439
|
}
|
|
427
440
|
|
|
428
|
-
const debug$1 = core.Debug.get(
|
|
441
|
+
const debug$1 = core.Debug.get("Renderer");
|
|
442
|
+
|
|
429
443
|
class Renderer {
|
|
430
|
-
get needFill() {
|
|
444
|
+
get needFill() {
|
|
445
|
+
return !!(!this.canvas.allowBackgroundColor && this.config.fill);
|
|
446
|
+
}
|
|
431
447
|
constructor(target, canvas, userConfig) {
|
|
432
448
|
this.FPS = 60;
|
|
433
449
|
this.totalTimes = 0;
|
|
@@ -438,8 +454,7 @@ class Renderer {
|
|
|
438
454
|
};
|
|
439
455
|
this.target = target;
|
|
440
456
|
this.canvas = canvas;
|
|
441
|
-
if (userConfig)
|
|
442
|
-
this.config = core.DataHelper.default(userConfig, this.config);
|
|
457
|
+
if (userConfig) this.config = core.DataHelper.default(userConfig, this.config);
|
|
443
458
|
this.__listenEvents();
|
|
444
459
|
}
|
|
445
460
|
start() {
|
|
@@ -450,8 +465,7 @@ class Renderer {
|
|
|
450
465
|
this.running = false;
|
|
451
466
|
}
|
|
452
467
|
update(change = true) {
|
|
453
|
-
if (!this.changed)
|
|
454
|
-
this.changed = change;
|
|
468
|
+
if (!this.changed) this.changed = change;
|
|
455
469
|
this.__requestRender();
|
|
456
470
|
}
|
|
457
471
|
requestLayout() {
|
|
@@ -459,7 +473,7 @@ class Renderer {
|
|
|
459
473
|
}
|
|
460
474
|
checkRender() {
|
|
461
475
|
if (this.running) {
|
|
462
|
-
const { target
|
|
476
|
+
const {target: target} = this;
|
|
463
477
|
if (target.isApp) {
|
|
464
478
|
target.emit(core.RenderEvent.CHILD_START, target);
|
|
465
479
|
target.children.forEach(leafer => {
|
|
@@ -468,54 +482,47 @@ class Renderer {
|
|
|
468
482
|
});
|
|
469
483
|
target.emit(core.RenderEvent.CHILD_END, target);
|
|
470
484
|
}
|
|
471
|
-
if (this.changed && this.canvas.view)
|
|
472
|
-
this.render();
|
|
485
|
+
if (this.changed && this.canvas.view) this.render();
|
|
473
486
|
this.target.emit(core.RenderEvent.NEXT);
|
|
474
487
|
}
|
|
475
488
|
}
|
|
476
489
|
render(callback) {
|
|
477
|
-
if (!(this.running && this.canvas.view))
|
|
478
|
-
|
|
479
|
-
const { target } = this;
|
|
490
|
+
if (!(this.running && this.canvas.view)) return this.update();
|
|
491
|
+
const {target: target} = this;
|
|
480
492
|
this.times = 0;
|
|
481
|
-
this.totalBounds = new core.Bounds
|
|
482
|
-
debug$1.log(target.innerName,
|
|
493
|
+
this.totalBounds = new core.Bounds;
|
|
494
|
+
debug$1.log(target.innerName, "---\x3e");
|
|
483
495
|
try {
|
|
484
496
|
this.emitRender(core.RenderEvent.START);
|
|
485
497
|
this.renderOnce(callback);
|
|
486
498
|
this.emitRender(core.RenderEvent.END, this.totalBounds);
|
|
487
499
|
core.ImageManager.clearRecycled();
|
|
488
|
-
}
|
|
489
|
-
catch (e) {
|
|
500
|
+
} catch (e) {
|
|
490
501
|
this.rendering = false;
|
|
491
502
|
debug$1.error(e);
|
|
492
503
|
}
|
|
493
|
-
debug$1.log(
|
|
504
|
+
debug$1.log("-------------|");
|
|
494
505
|
}
|
|
495
506
|
renderAgain() {
|
|
496
507
|
if (this.rendering) {
|
|
497
508
|
this.waitAgain = true;
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
509
|
+
} else {
|
|
500
510
|
this.renderOnce();
|
|
501
511
|
}
|
|
502
512
|
}
|
|
503
513
|
renderOnce(callback) {
|
|
504
|
-
if (this.rendering)
|
|
505
|
-
|
|
506
|
-
if (this.times > 3)
|
|
507
|
-
return debug$1.warn('render max times');
|
|
514
|
+
if (this.rendering) return debug$1.warn("rendering");
|
|
515
|
+
if (this.times > 3) return debug$1.warn("render max times");
|
|
508
516
|
this.times++;
|
|
509
517
|
this.totalTimes++;
|
|
510
518
|
this.rendering = true;
|
|
511
519
|
this.changed = false;
|
|
512
|
-
this.renderBounds = new core.Bounds
|
|
520
|
+
this.renderBounds = new core.Bounds;
|
|
513
521
|
this.renderOptions = {};
|
|
514
522
|
if (callback) {
|
|
515
523
|
this.emitRender(core.RenderEvent.BEFORE);
|
|
516
524
|
callback();
|
|
517
|
-
}
|
|
518
|
-
else {
|
|
525
|
+
} else {
|
|
519
526
|
this.requestLayout();
|
|
520
527
|
if (this.ignore) {
|
|
521
528
|
this.ignore = this.rendering = false;
|
|
@@ -524,8 +531,7 @@ class Renderer {
|
|
|
524
531
|
this.emitRender(core.RenderEvent.BEFORE);
|
|
525
532
|
if (this.config.usePartRender && this.totalTimes > 1) {
|
|
526
533
|
this.partRender();
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
534
|
+
} else {
|
|
529
535
|
this.fullRender();
|
|
530
536
|
}
|
|
531
537
|
}
|
|
@@ -539,16 +545,16 @@ class Renderer {
|
|
|
539
545
|
}
|
|
540
546
|
}
|
|
541
547
|
partRender() {
|
|
542
|
-
const { canvas, updateBlocks: list
|
|
543
|
-
if (!list)
|
|
544
|
-
return;
|
|
548
|
+
const {canvas: canvas, updateBlocks: list} = this;
|
|
549
|
+
if (!list) return;
|
|
545
550
|
this.mergeBlocks();
|
|
546
|
-
list.forEach(block => {
|
|
547
|
-
this.clipRender(block);
|
|
551
|
+
list.forEach(block => {
|
|
552
|
+
if (canvas.bounds.hit(block) && !block.isEmpty()) this.clipRender(block);
|
|
553
|
+
});
|
|
548
554
|
}
|
|
549
555
|
clipRender(block) {
|
|
550
|
-
const t = core.Run.start(
|
|
551
|
-
const { canvas
|
|
556
|
+
const t = core.Run.start("PartRender");
|
|
557
|
+
const {canvas: canvas} = this, bounds = block.getIntersect(canvas.bounds), realBounds = new core.Bounds(bounds);
|
|
552
558
|
canvas.save();
|
|
553
559
|
bounds.spread(Renderer.clipSpread).ceil();
|
|
554
560
|
canvas.clearWorld(bounds, true);
|
|
@@ -558,8 +564,8 @@ class Renderer {
|
|
|
558
564
|
core.Run.end(t);
|
|
559
565
|
}
|
|
560
566
|
fullRender() {
|
|
561
|
-
const t = core.Run.start(
|
|
562
|
-
const { canvas
|
|
567
|
+
const t = core.Run.start("FullRender");
|
|
568
|
+
const {canvas: canvas} = this;
|
|
563
569
|
canvas.save();
|
|
564
570
|
canvas.clear();
|
|
565
571
|
this.__render(canvas.bounds);
|
|
@@ -567,11 +573,14 @@ class Renderer {
|
|
|
567
573
|
core.Run.end(t);
|
|
568
574
|
}
|
|
569
575
|
__render(bounds, realBounds) {
|
|
570
|
-
const { canvas
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
576
|
+
const {canvas: canvas} = this, includes = bounds.includes(this.target.__world), options = includes ? {
|
|
577
|
+
includes: includes
|
|
578
|
+
} : {
|
|
579
|
+
bounds: bounds,
|
|
580
|
+
includes: includes
|
|
581
|
+
};
|
|
582
|
+
if (this.needFill) canvas.fillWorld(bounds, this.config.fill);
|
|
583
|
+
if (core.Debug.showRepaint) core.Debug.drawRepaint(canvas, bounds);
|
|
575
584
|
this.target.__render(canvas, options);
|
|
576
585
|
this.renderBounds = realBounds = realBounds || bounds;
|
|
577
586
|
this.renderOptions = options;
|
|
@@ -579,14 +588,13 @@ class Renderer {
|
|
|
579
588
|
canvas.updateRender(realBounds);
|
|
580
589
|
}
|
|
581
590
|
addBlock(block) {
|
|
582
|
-
if (!this.updateBlocks)
|
|
583
|
-
this.updateBlocks = [];
|
|
591
|
+
if (!this.updateBlocks) this.updateBlocks = [];
|
|
584
592
|
this.updateBlocks.push(block);
|
|
585
593
|
}
|
|
586
594
|
mergeBlocks() {
|
|
587
|
-
const {
|
|
595
|
+
const {updateBlocks: list} = this;
|
|
588
596
|
if (list) {
|
|
589
|
-
const bounds = new core.Bounds
|
|
597
|
+
const bounds = new core.Bounds;
|
|
590
598
|
bounds.setList(list);
|
|
591
599
|
list.length = 0;
|
|
592
600
|
list.push(bounds);
|
|
@@ -594,26 +602,23 @@ class Renderer {
|
|
|
594
602
|
}
|
|
595
603
|
__requestRender() {
|
|
596
604
|
const target = this.target;
|
|
597
|
-
if (this.requestTime || !target)
|
|
598
|
-
|
|
599
|
-
if (target.parentApp)
|
|
600
|
-
return target.parentApp.requestRender(false);
|
|
605
|
+
if (this.requestTime || !target) return;
|
|
606
|
+
if (target.parentApp) return target.parentApp.requestRender(false);
|
|
601
607
|
const requestTime = this.requestTime = Date.now();
|
|
602
608
|
core.Platform.requestRender(() => {
|
|
603
|
-
this.FPS = Math.min(60, Math.ceil(
|
|
609
|
+
this.FPS = Math.min(60, Math.ceil(1e3 / (Date.now() - requestTime)));
|
|
604
610
|
this.requestTime = 0;
|
|
605
611
|
this.checkRender();
|
|
606
612
|
});
|
|
607
613
|
}
|
|
608
614
|
__onResize(e) {
|
|
609
|
-
if (this.canvas.unreal)
|
|
610
|
-
return;
|
|
615
|
+
if (this.canvas.unreal) return;
|
|
611
616
|
if (e.bigger || !e.samePixelRatio) {
|
|
612
|
-
const { width, height } = e.old;
|
|
617
|
+
const {width: width, height: height} = e.old;
|
|
613
618
|
const bounds = new core.Bounds(0, 0, width, height);
|
|
614
619
|
if (!bounds.includes(this.target.__world) || this.needFill || !e.samePixelRatio) {
|
|
615
620
|
this.addBlock(this.canvas.bounds);
|
|
616
|
-
this.target.forceUpdate(
|
|
621
|
+
this.target.forceUpdate("surface");
|
|
617
622
|
return;
|
|
618
623
|
}
|
|
619
624
|
}
|
|
@@ -621,34 +626,24 @@ class Renderer {
|
|
|
621
626
|
this.update();
|
|
622
627
|
}
|
|
623
628
|
__onLayoutEnd(event) {
|
|
624
|
-
if (event.data)
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
empty = (!leaf.isBranch || leaf.isBranchLeaf);
|
|
634
|
-
}
|
|
635
|
-
return empty;
|
|
636
|
-
});
|
|
637
|
-
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
|
|
629
|
+
if (event.data) event.data.map(item => {
|
|
630
|
+
let empty;
|
|
631
|
+
if (item.updatedList) item.updatedList.list.some(leaf => {
|
|
632
|
+
empty = !leaf.__world.width || !leaf.__world.height;
|
|
633
|
+
if (empty) {
|
|
634
|
+
if (!leaf.isLeafer) debug$1.tip(leaf.innerName, ": empty");
|
|
635
|
+
empty = !leaf.isBranch || leaf.isBranchLeaf;
|
|
636
|
+
}
|
|
637
|
+
return empty;
|
|
638
638
|
});
|
|
639
|
+
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
|
|
640
|
+
});
|
|
639
641
|
}
|
|
640
642
|
emitRender(type, bounds, options) {
|
|
641
643
|
this.target.emitEvent(new core.RenderEvent(type, this.times, bounds, options));
|
|
642
644
|
}
|
|
643
645
|
__listenEvents() {
|
|
644
|
-
this.__eventIds = [
|
|
645
|
-
this.target.on_([
|
|
646
|
-
[core.RenderEvent.REQUEST, this.update, this],
|
|
647
|
-
[core.LayoutEvent.END, this.__onLayoutEnd, this],
|
|
648
|
-
[core.RenderEvent.AGAIN, this.renderAgain, this],
|
|
649
|
-
[core.ResizeEvent.RESIZE, this.__onResize, this]
|
|
650
|
-
])
|
|
651
|
-
];
|
|
646
|
+
this.__eventIds = [ this.target.on_([ [ core.RenderEvent.REQUEST, this.update, this ], [ core.LayoutEvent.END, this.__onLayoutEnd, this ], [ core.RenderEvent.AGAIN, this.renderAgain, this ], [ core.ResizeEvent.RESIZE, this.__onResize, this ] ]) ];
|
|
652
647
|
}
|
|
653
648
|
__removeListenEvents() {
|
|
654
649
|
this.target.off_(this.__eventIds);
|
|
@@ -661,6 +656,7 @@ class Renderer {
|
|
|
661
656
|
}
|
|
662
657
|
}
|
|
663
658
|
}
|
|
659
|
+
|
|
664
660
|
Renderer.clipSpread = 10;
|
|
665
661
|
|
|
666
662
|
Object.assign(core.Creator, {
|
|
@@ -670,24 +666,22 @@ Object.assign(core.Creator, {
|
|
|
670
666
|
selector: (_target, _options) => undefined,
|
|
671
667
|
interaction: (_target, _canvas, _selector, _options) => undefined
|
|
672
668
|
});
|
|
669
|
+
|
|
673
670
|
core.Platform.layout = Layouter.fullLayout;
|
|
674
671
|
|
|
675
672
|
function fillText(ui, canvas) {
|
|
676
|
-
const data = ui.__, { rows, decorationY } = data.__textDrawData;
|
|
677
|
-
if (data.__isPlacehold && data.placeholderColor)
|
|
678
|
-
canvas.fillStyle = data.placeholderColor;
|
|
673
|
+
const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
|
|
674
|
+
if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
|
|
679
675
|
let row;
|
|
680
676
|
for (let i = 0, len = rows.length; i < len; i++) {
|
|
681
677
|
row = rows[i];
|
|
682
|
-
if (row.text)
|
|
683
|
-
canvas.fillText(
|
|
684
|
-
|
|
685
|
-
row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
|
|
678
|
+
if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
|
|
679
|
+
canvas.fillText(charData.char, charData.x, row.y);
|
|
680
|
+
});
|
|
686
681
|
}
|
|
687
682
|
if (decorationY) {
|
|
688
|
-
const { decorationColor, decorationHeight } = data.__textDrawData;
|
|
689
|
-
if (decorationColor)
|
|
690
|
-
canvas.fillStyle = decorationColor;
|
|
683
|
+
const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
|
|
684
|
+
if (decorationColor) canvas.fillStyle = decorationColor;
|
|
691
685
|
rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
|
|
692
686
|
}
|
|
693
687
|
}
|
|
@@ -696,117 +690,112 @@ function fill(fill, ui, canvas) {
|
|
|
696
690
|
canvas.fillStyle = fill;
|
|
697
691
|
fillPathOrText(ui, canvas);
|
|
698
692
|
}
|
|
693
|
+
|
|
699
694
|
function fills(fills, ui, canvas) {
|
|
700
695
|
let item;
|
|
701
696
|
for (let i = 0, len = fills.length; i < len; i++) {
|
|
702
697
|
item = fills[i];
|
|
703
698
|
if (item.image) {
|
|
704
|
-
if (draw.PaintImage.checkImage(ui, canvas, item, !ui.__.__font))
|
|
705
|
-
continue;
|
|
699
|
+
if (draw.PaintImage.checkImage(ui, canvas, item, !ui.__.__font)) continue;
|
|
706
700
|
if (!item.style) {
|
|
707
|
-
if (!i && item.image.isPlacehold)
|
|
708
|
-
ui.drawImagePlaceholder(canvas, item.image);
|
|
701
|
+
if (!i && item.image.isPlacehold) ui.drawImagePlaceholder(canvas, item.image);
|
|
709
702
|
continue;
|
|
710
703
|
}
|
|
711
704
|
}
|
|
712
705
|
canvas.fillStyle = item.style;
|
|
713
706
|
if (item.transform || item.scaleFixed) {
|
|
714
707
|
canvas.save();
|
|
715
|
-
if (item.transform)
|
|
716
|
-
canvas.transform(item.transform);
|
|
708
|
+
if (item.transform) canvas.transform(item.transform);
|
|
717
709
|
if (item.scaleFixed) {
|
|
718
|
-
const { scaleX, scaleY } = ui.getRenderScaleData(true);
|
|
719
|
-
canvas.scale(1 / scaleX, 1 / scaleY);
|
|
710
|
+
const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
|
|
711
|
+
if (item.scaleFixed === true || item.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
|
|
720
712
|
}
|
|
721
|
-
if (item.blendMode)
|
|
722
|
-
canvas.blendMode = item.blendMode;
|
|
713
|
+
if (item.blendMode) canvas.blendMode = item.blendMode;
|
|
723
714
|
fillPathOrText(ui, canvas);
|
|
724
715
|
canvas.restore();
|
|
725
|
-
}
|
|
726
|
-
else {
|
|
716
|
+
} else {
|
|
727
717
|
if (item.blendMode) {
|
|
728
718
|
canvas.saveBlendMode(item.blendMode);
|
|
729
719
|
fillPathOrText(ui, canvas);
|
|
730
720
|
canvas.restoreBlendMode();
|
|
731
|
-
}
|
|
732
|
-
else
|
|
733
|
-
fillPathOrText(ui, canvas);
|
|
721
|
+
} else fillPathOrText(ui, canvas);
|
|
734
722
|
}
|
|
735
723
|
}
|
|
736
724
|
}
|
|
725
|
+
|
|
737
726
|
function fillPathOrText(ui, canvas) {
|
|
738
|
-
ui.__.__font ? fillText(ui, canvas) :
|
|
727
|
+
ui.__.__font ? fillText(ui, canvas) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
|
|
739
728
|
}
|
|
740
729
|
|
|
741
730
|
function strokeText(stroke, ui, canvas) {
|
|
742
731
|
switch (ui.__.strokeAlign) {
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
732
|
+
case "center":
|
|
733
|
+
drawCenter$1(stroke, 1, ui, canvas);
|
|
734
|
+
break;
|
|
735
|
+
|
|
736
|
+
case "inside":
|
|
737
|
+
drawAlign(stroke, "inside", ui, canvas);
|
|
738
|
+
break;
|
|
739
|
+
|
|
740
|
+
case "outside":
|
|
741
|
+
ui.__.__fillAfterStroke ? drawCenter$1(stroke, 2, ui, canvas) : drawAlign(stroke, "outside", ui, canvas);
|
|
742
|
+
break;
|
|
752
743
|
}
|
|
753
744
|
}
|
|
745
|
+
|
|
754
746
|
function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
|
|
755
747
|
const data = ui.__;
|
|
756
|
-
if (
|
|
748
|
+
if (core.isObject(stroke)) {
|
|
757
749
|
drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
|
|
758
|
-
}
|
|
759
|
-
else {
|
|
750
|
+
} else {
|
|
760
751
|
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
761
752
|
drawTextStroke(ui, canvas);
|
|
762
753
|
}
|
|
763
754
|
}
|
|
755
|
+
|
|
764
756
|
function drawAlign(stroke, align, ui, canvas) {
|
|
765
757
|
const out = canvas.getSameCanvas(true, true);
|
|
766
758
|
out.font = ui.__.__font;
|
|
767
759
|
drawCenter$1(stroke, 2, ui, out);
|
|
768
|
-
out.blendMode = align ===
|
|
760
|
+
out.blendMode = align === "outside" ? "destination-out" : "destination-in";
|
|
769
761
|
fillText(ui, out);
|
|
770
|
-
out.blendMode =
|
|
762
|
+
out.blendMode = "normal";
|
|
771
763
|
core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
|
|
772
764
|
out.recycle(ui.__nowWorld);
|
|
773
765
|
}
|
|
766
|
+
|
|
774
767
|
function drawTextStroke(ui, canvas) {
|
|
775
768
|
let row, data = ui.__.__textDrawData;
|
|
776
|
-
const { rows, decorationY } = data;
|
|
769
|
+
const {rows: rows, decorationY: decorationY} = data;
|
|
777
770
|
for (let i = 0, len = rows.length; i < len; i++) {
|
|
778
771
|
row = rows[i];
|
|
779
|
-
if (row.text)
|
|
780
|
-
canvas.strokeText(
|
|
781
|
-
|
|
782
|
-
row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
|
|
772
|
+
if (row.text) canvas.strokeText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
|
|
773
|
+
canvas.strokeText(charData.char, charData.x, row.y);
|
|
774
|
+
});
|
|
783
775
|
}
|
|
784
776
|
if (decorationY) {
|
|
785
|
-
const { decorationHeight
|
|
777
|
+
const {decorationHeight: decorationHeight} = data;
|
|
786
778
|
rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
|
|
787
779
|
}
|
|
788
780
|
}
|
|
781
|
+
|
|
789
782
|
function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
|
|
790
783
|
let item;
|
|
791
|
-
const data = ui.__, { __hasMultiStrokeStyle
|
|
784
|
+
const data = ui.__, {__hasMultiStrokeStyle: __hasMultiStrokeStyle} = data;
|
|
792
785
|
__hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
|
|
793
786
|
for (let i = 0, len = strokes.length; i < len; i++) {
|
|
794
787
|
item = strokes[i];
|
|
795
|
-
if (item.image && draw.PaintImage.checkImage(ui, canvas, item, false))
|
|
796
|
-
continue;
|
|
788
|
+
if (item.image && draw.PaintImage.checkImage(ui, canvas, item, false)) continue;
|
|
797
789
|
if (item.style) {
|
|
798
790
|
if (__hasMultiStrokeStyle) {
|
|
799
|
-
const { strokeStyle
|
|
791
|
+
const {strokeStyle: strokeStyle} = item;
|
|
800
792
|
strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
|
|
801
|
-
}
|
|
802
|
-
else
|
|
803
|
-
canvas.strokeStyle = item.style;
|
|
793
|
+
} else canvas.strokeStyle = item.style;
|
|
804
794
|
if (item.blendMode) {
|
|
805
795
|
canvas.saveBlendMode(item.blendMode);
|
|
806
796
|
isText ? drawTextStroke(ui, canvas) : canvas.stroke();
|
|
807
797
|
canvas.restoreBlendMode();
|
|
808
|
-
}
|
|
809
|
-
else {
|
|
798
|
+
} else {
|
|
810
799
|
isText ? drawTextStroke(ui, canvas) : canvas.stroke();
|
|
811
800
|
}
|
|
812
801
|
}
|
|
@@ -815,53 +804,54 @@ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
|
|
|
815
804
|
|
|
816
805
|
function stroke(stroke, ui, canvas) {
|
|
817
806
|
const data = ui.__;
|
|
818
|
-
if (!data.__strokeWidth)
|
|
819
|
-
return;
|
|
807
|
+
if (!data.__strokeWidth) return;
|
|
820
808
|
if (data.__font) {
|
|
821
809
|
strokeText(stroke, ui, canvas);
|
|
822
|
-
}
|
|
823
|
-
else {
|
|
810
|
+
} else {
|
|
824
811
|
switch (data.strokeAlign) {
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
812
|
+
case "center":
|
|
813
|
+
drawCenter(stroke, 1, ui, canvas);
|
|
814
|
+
break;
|
|
815
|
+
|
|
816
|
+
case "inside":
|
|
817
|
+
drawInside(stroke, ui, canvas);
|
|
818
|
+
break;
|
|
819
|
+
|
|
820
|
+
case "outside":
|
|
821
|
+
drawOutside(stroke, ui, canvas);
|
|
822
|
+
break;
|
|
834
823
|
}
|
|
835
824
|
}
|
|
836
825
|
}
|
|
826
|
+
|
|
837
827
|
function strokes(strokes, ui, canvas) {
|
|
838
828
|
stroke(strokes, ui, canvas);
|
|
839
829
|
}
|
|
830
|
+
|
|
840
831
|
function drawCenter(stroke, strokeWidthScale, ui, canvas) {
|
|
841
832
|
const data = ui.__;
|
|
842
|
-
if (
|
|
833
|
+
if (core.isObject(stroke)) {
|
|
843
834
|
drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
|
|
844
|
-
}
|
|
845
|
-
else {
|
|
835
|
+
} else {
|
|
846
836
|
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
847
837
|
canvas.stroke();
|
|
848
838
|
}
|
|
849
|
-
if (data.__useArrow)
|
|
850
|
-
draw.Paint.strokeArrow(stroke, ui, canvas);
|
|
839
|
+
if (data.__useArrow) draw.Paint.strokeArrow(stroke, ui, canvas);
|
|
851
840
|
}
|
|
841
|
+
|
|
852
842
|
function drawInside(stroke, ui, canvas) {
|
|
853
843
|
canvas.save();
|
|
854
844
|
canvas.clipUI(ui);
|
|
855
845
|
drawCenter(stroke, 2, ui, canvas);
|
|
856
846
|
canvas.restore();
|
|
857
847
|
}
|
|
848
|
+
|
|
858
849
|
function drawOutside(stroke, ui, canvas) {
|
|
859
850
|
const data = ui.__;
|
|
860
851
|
if (data.__fillAfterStroke) {
|
|
861
852
|
drawCenter(stroke, 2, ui, canvas);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
const { renderBounds } = ui.__layout;
|
|
853
|
+
} else {
|
|
854
|
+
const {renderBounds: renderBounds} = ui.__layout;
|
|
865
855
|
const out = canvas.getSameCanvas(true, true);
|
|
866
856
|
ui.__drawRenderPath(out);
|
|
867
857
|
drawCenter(stroke, 2, ui, out);
|
|
@@ -872,25 +862,27 @@ function drawOutside(stroke, ui, canvas) {
|
|
|
872
862
|
}
|
|
873
863
|
}
|
|
874
864
|
|
|
875
|
-
const { getSpread, getOuterOf, getByMove, getIntersectData } = core.BoundsHelper;
|
|
865
|
+
const {getSpread: getSpread, getOuterOf: getOuterOf, getByMove: getByMove, getIntersectData: getIntersectData} = core.BoundsHelper;
|
|
866
|
+
|
|
876
867
|
function shape(ui, current, options) {
|
|
877
868
|
const canvas = current.getSameCanvas();
|
|
878
|
-
const nowWorld = ui.__nowWorld;
|
|
879
|
-
let bounds, fitMatrix, shapeBounds, worldCanvas;
|
|
880
|
-
let { scaleX, scaleY } =
|
|
881
|
-
if (
|
|
882
|
-
scaleX = -scaleX;
|
|
883
|
-
if (scaleY < 0)
|
|
884
|
-
scaleY = -scaleY;
|
|
885
|
-
if (current.bounds.includes(nowWorld)) {
|
|
869
|
+
const nowWorld = ui.__nowWorld, currentBounds = current.bounds;
|
|
870
|
+
let bounds, matrix, fitMatrix, shapeBounds, worldCanvas;
|
|
871
|
+
let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
|
|
872
|
+
if (currentBounds.includes(nowWorld)) {
|
|
886
873
|
worldCanvas = canvas;
|
|
887
874
|
bounds = shapeBounds = nowWorld;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
875
|
+
} else {
|
|
876
|
+
const {renderShapeSpread: spread} = ui.__layout;
|
|
877
|
+
let worldClipBounds;
|
|
878
|
+
if (core.Platform.fullImageShadow) {
|
|
879
|
+
worldClipBounds = nowWorld;
|
|
880
|
+
} else {
|
|
881
|
+
const spreadBounds = spread ? getSpread(currentBounds, scaleX === scaleY ? spread * scaleX : [ spread * scaleY, spread * scaleX ]) : currentBounds;
|
|
882
|
+
worldClipBounds = getIntersectData(spreadBounds, nowWorld);
|
|
883
|
+
}
|
|
884
|
+
fitMatrix = currentBounds.getFitMatrix(worldClipBounds);
|
|
885
|
+
let {a: fitScaleX, d: fitScaleY} = fitMatrix;
|
|
894
886
|
if (fitMatrix.a < 1) {
|
|
895
887
|
worldCanvas = current.getSameCanvas();
|
|
896
888
|
ui.__renderShape(worldCanvas, options);
|
|
@@ -899,28 +891,39 @@ function shape(ui, current, options) {
|
|
|
899
891
|
}
|
|
900
892
|
shapeBounds = getOuterOf(nowWorld, fitMatrix);
|
|
901
893
|
bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f);
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
894
|
+
const userMatrix = options.matrix;
|
|
895
|
+
if (userMatrix) {
|
|
896
|
+
matrix = new core.Matrix(fitMatrix);
|
|
897
|
+
matrix.multiply(userMatrix);
|
|
898
|
+
fitScaleX *= userMatrix.scaleX;
|
|
899
|
+
fitScaleY *= userMatrix.scaleY;
|
|
900
|
+
} else matrix = fitMatrix;
|
|
901
|
+
matrix.withScale(fitScaleX, fitScaleY);
|
|
902
|
+
options = Object.assign(Object.assign({}, options), {
|
|
903
|
+
matrix: matrix
|
|
904
|
+
});
|
|
909
905
|
}
|
|
910
906
|
ui.__renderShape(canvas, options);
|
|
911
907
|
return {
|
|
912
|
-
canvas
|
|
913
|
-
|
|
908
|
+
canvas: canvas,
|
|
909
|
+
matrix: matrix,
|
|
910
|
+
fitMatrix: fitMatrix,
|
|
911
|
+
bounds: bounds,
|
|
912
|
+
worldCanvas: worldCanvas,
|
|
913
|
+
shapeBounds: shapeBounds,
|
|
914
|
+
scaleX: scaleX,
|
|
915
|
+
scaleY: scaleY
|
|
914
916
|
};
|
|
915
917
|
}
|
|
916
918
|
|
|
917
919
|
let recycleMap;
|
|
918
|
-
|
|
920
|
+
|
|
921
|
+
const {stintSet: stintSet} = core.DataHelper, {hasTransparent: hasTransparent$1} = draw.ColorConvert;
|
|
922
|
+
|
|
919
923
|
function compute(attrName, ui) {
|
|
920
924
|
const data = ui.__, leafPaints = [];
|
|
921
925
|
let paints = data.__input[attrName], isAlphaPixel, isTransparent;
|
|
922
|
-
if (!(paints
|
|
923
|
-
paints = [paints];
|
|
926
|
+
if (!core.isArray(paints)) paints = [ paints ];
|
|
924
927
|
recycleMap = draw.PaintImage.recycleImage(attrName, data);
|
|
925
928
|
let maxChildStrokeWidth;
|
|
926
929
|
for (let i = 0, len = paints.length, item; i < len; i++) {
|
|
@@ -928,206 +931,222 @@ function compute(attrName, ui) {
|
|
|
928
931
|
leafPaints.push(item);
|
|
929
932
|
if (item.strokeStyle) {
|
|
930
933
|
maxChildStrokeWidth || (maxChildStrokeWidth = 1);
|
|
931
|
-
if (item.strokeStyle.strokeWidth)
|
|
932
|
-
maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
934
|
+
if (item.strokeStyle.strokeWidth) maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
933
935
|
}
|
|
934
936
|
}
|
|
935
937
|
}
|
|
936
|
-
data[
|
|
938
|
+
data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
|
|
937
939
|
if (leafPaints.length) {
|
|
938
940
|
if (leafPaints.every(item => item.isTransparent)) {
|
|
939
|
-
if (leafPaints.some(item => item.image))
|
|
940
|
-
isAlphaPixel = true;
|
|
941
|
+
if (leafPaints.some(item => item.image)) isAlphaPixel = true;
|
|
941
942
|
isTransparent = true;
|
|
942
943
|
}
|
|
943
944
|
}
|
|
944
|
-
if (attrName ===
|
|
945
|
-
stintSet(data,
|
|
946
|
-
stintSet(data,
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
stintSet(data,
|
|
950
|
-
stintSet(data,
|
|
951
|
-
stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth);
|
|
945
|
+
if (attrName === "fill") {
|
|
946
|
+
stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
|
|
947
|
+
stintSet(data, "__isTransparentFill", isTransparent);
|
|
948
|
+
} else {
|
|
949
|
+
stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
|
|
950
|
+
stintSet(data, "__isTransparentStroke", isTransparent);
|
|
951
|
+
stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
|
|
952
952
|
}
|
|
953
953
|
}
|
|
954
|
+
|
|
954
955
|
function getLeafPaint(attrName, paint, ui) {
|
|
955
|
-
if (
|
|
956
|
-
return undefined;
|
|
956
|
+
if (!core.isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
|
|
957
957
|
let data;
|
|
958
|
-
const { boxBounds
|
|
958
|
+
const {boxBounds: boxBounds} = ui.__layout;
|
|
959
959
|
switch (paint.type) {
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
960
|
+
case "image":
|
|
961
|
+
data = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
|
|
962
|
+
break;
|
|
963
|
+
|
|
964
|
+
case "linear":
|
|
965
|
+
data = draw.PaintGradient.linearGradient(paint, boxBounds);
|
|
966
|
+
break;
|
|
967
|
+
|
|
968
|
+
case "radial":
|
|
969
|
+
data = draw.PaintGradient.radialGradient(paint, boxBounds);
|
|
970
|
+
break;
|
|
971
|
+
|
|
972
|
+
case "angular":
|
|
973
|
+
data = draw.PaintGradient.conicGradient(paint, boxBounds);
|
|
974
|
+
break;
|
|
975
|
+
|
|
976
|
+
case "solid":
|
|
977
|
+
const {type: type, color: color, opacity: opacity} = paint;
|
|
978
|
+
data = {
|
|
979
|
+
type: type,
|
|
980
|
+
style: draw.ColorConvert.string(color, opacity)
|
|
981
|
+
};
|
|
982
|
+
break;
|
|
983
|
+
|
|
984
|
+
default:
|
|
985
|
+
if (!core.isUndefined(paint.r)) data = {
|
|
986
|
+
type: "solid",
|
|
987
|
+
style: draw.ColorConvert.string(paint)
|
|
988
|
+
};
|
|
979
989
|
}
|
|
980
990
|
if (data) {
|
|
981
|
-
if (
|
|
982
|
-
data.isTransparent = true;
|
|
991
|
+
if (core.isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
|
|
983
992
|
if (paint.style) {
|
|
984
|
-
if (paint.style.strokeWidth === 0)
|
|
985
|
-
return undefined;
|
|
993
|
+
if (paint.style.strokeWidth === 0) return undefined;
|
|
986
994
|
data.strokeStyle = paint.style;
|
|
987
995
|
}
|
|
988
|
-
if (paint.
|
|
989
|
-
|
|
996
|
+
if (paint.editing) data.editing = paint.editing;
|
|
997
|
+
if (paint.blendMode) data.blendMode = paint.blendMode;
|
|
990
998
|
}
|
|
991
999
|
return data;
|
|
992
1000
|
}
|
|
993
1001
|
|
|
994
1002
|
const PaintModule = {
|
|
995
|
-
compute,
|
|
996
|
-
fill,
|
|
997
|
-
fills,
|
|
998
|
-
fillPathOrText,
|
|
999
|
-
fillText,
|
|
1000
|
-
stroke,
|
|
1001
|
-
strokes,
|
|
1002
|
-
strokeText,
|
|
1003
|
-
drawTextStroke,
|
|
1004
|
-
shape
|
|
1003
|
+
compute: compute,
|
|
1004
|
+
fill: fill,
|
|
1005
|
+
fills: fills,
|
|
1006
|
+
fillPathOrText: fillPathOrText,
|
|
1007
|
+
fillText: fillText,
|
|
1008
|
+
stroke: stroke,
|
|
1009
|
+
strokes: strokes,
|
|
1010
|
+
strokeText: strokeText,
|
|
1011
|
+
drawTextStroke: drawTextStroke,
|
|
1012
|
+
shape: shape
|
|
1005
1013
|
};
|
|
1006
1014
|
|
|
1007
1015
|
let origin = {}, tempMatrix = core.getMatrixData();
|
|
1008
|
-
|
|
1016
|
+
|
|
1017
|
+
const {get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = core.MatrixHelper;
|
|
1018
|
+
|
|
1009
1019
|
function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
1010
1020
|
const transform = get$3();
|
|
1011
1021
|
translate$1(transform, box.x + x, box.y + y);
|
|
1012
1022
|
scaleHelper(transform, scaleX, scaleY);
|
|
1013
|
-
if (rotation)
|
|
1014
|
-
|
|
1023
|
+
if (rotation) rotateOfOuter$1(transform, {
|
|
1024
|
+
x: box.x + box.width / 2,
|
|
1025
|
+
y: box.y + box.height / 2
|
|
1026
|
+
}, rotation);
|
|
1015
1027
|
data.transform = transform;
|
|
1016
1028
|
}
|
|
1029
|
+
|
|
1017
1030
|
function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
|
|
1018
1031
|
const transform = get$3();
|
|
1019
|
-
|
|
1020
|
-
rotate(transform, rotation);
|
|
1021
|
-
if (skew)
|
|
1022
|
-
skewHelper(transform, skew.x, skew.y);
|
|
1023
|
-
if (scaleX)
|
|
1024
|
-
scaleHelper(transform, scaleX, scaleY);
|
|
1025
|
-
translate$1(transform, box.x + x, box.y + y);
|
|
1032
|
+
layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
|
|
1026
1033
|
if (clipSize) {
|
|
1027
1034
|
tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
|
|
1028
1035
|
multiplyParent(transform, tempMatrix);
|
|
1029
1036
|
}
|
|
1030
1037
|
data.transform = transform;
|
|
1031
1038
|
}
|
|
1032
|
-
|
|
1039
|
+
|
|
1040
|
+
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
|
|
1033
1041
|
const transform = get$3();
|
|
1034
|
-
if (
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
+
if (freeTransform) {
|
|
1043
|
+
layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
|
|
1044
|
+
} else {
|
|
1045
|
+
if (rotation) {
|
|
1046
|
+
if (align === "center") {
|
|
1047
|
+
rotateOfOuter$1(transform, {
|
|
1048
|
+
x: width / 2,
|
|
1049
|
+
y: height / 2
|
|
1050
|
+
}, rotation);
|
|
1051
|
+
} else {
|
|
1052
|
+
rotate(transform, rotation);
|
|
1053
|
+
switch (rotation) {
|
|
1054
|
+
case 90:
|
|
1042
1055
|
translate$1(transform, height, 0);
|
|
1043
1056
|
break;
|
|
1044
|
-
|
|
1057
|
+
|
|
1058
|
+
case 180:
|
|
1045
1059
|
translate$1(transform, width, height);
|
|
1046
1060
|
break;
|
|
1047
|
-
|
|
1061
|
+
|
|
1062
|
+
case 270:
|
|
1048
1063
|
translate$1(transform, 0, width);
|
|
1049
1064
|
break;
|
|
1065
|
+
}
|
|
1050
1066
|
}
|
|
1051
1067
|
}
|
|
1068
|
+
origin.x = box.x + x;
|
|
1069
|
+
origin.y = box.y + y;
|
|
1070
|
+
translate$1(transform, origin.x, origin.y);
|
|
1071
|
+
if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
|
|
1052
1072
|
}
|
|
1053
|
-
origin.x = box.x + x;
|
|
1054
|
-
origin.y = box.y + y;
|
|
1055
|
-
translate$1(transform, origin.x, origin.y);
|
|
1056
|
-
if (scaleX)
|
|
1057
|
-
scaleOfOuter$1(transform, origin, scaleX, scaleY);
|
|
1058
1073
|
data.transform = transform;
|
|
1059
1074
|
}
|
|
1060
1075
|
|
|
1061
|
-
|
|
1062
|
-
|
|
1076
|
+
function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
|
|
1077
|
+
if (rotation) rotate(transform, rotation);
|
|
1078
|
+
if (skew) skewHelper(transform, skew.x, skew.y);
|
|
1079
|
+
if (scaleX) scaleHelper(transform, scaleX, scaleY);
|
|
1080
|
+
translate$1(transform, box.x + x, box.y + y);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
const {get: get$2, translate: translate} = core.MatrixHelper;
|
|
1084
|
+
|
|
1085
|
+
const tempBox = new core.Bounds;
|
|
1086
|
+
|
|
1063
1087
|
const tempScaleData = {};
|
|
1088
|
+
|
|
1064
1089
|
const tempImage = {};
|
|
1090
|
+
|
|
1065
1091
|
function createData(leafPaint, image, paint, box) {
|
|
1066
|
-
const { changeful, sync
|
|
1067
|
-
if (changeful)
|
|
1068
|
-
|
|
1069
|
-
if (
|
|
1070
|
-
leafPaint.sync = sync;
|
|
1071
|
-
if (editing)
|
|
1072
|
-
leafPaint.editing = editing;
|
|
1073
|
-
if (scaleFixed)
|
|
1074
|
-
leafPaint.scaleFixed = scaleFixed;
|
|
1092
|
+
const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
|
|
1093
|
+
if (changeful) leafPaint.changeful = changeful;
|
|
1094
|
+
if (sync) leafPaint.sync = sync;
|
|
1095
|
+
if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
|
|
1075
1096
|
leafPaint.data = getPatternData(paint, box, image);
|
|
1076
1097
|
}
|
|
1098
|
+
|
|
1077
1099
|
function getPatternData(paint, box, image) {
|
|
1078
|
-
if (paint.padding)
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
let { width, height } = image;
|
|
1083
|
-
const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, repeat, filters } = paint;
|
|
1100
|
+
if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
|
|
1101
|
+
if (paint.mode === "strench") paint.mode = "stretch";
|
|
1102
|
+
let {width: width, height: height} = image;
|
|
1103
|
+
const {opacity: opacity, mode: mode, align: align, offset: offset, scale: scale, size: size, rotation: rotation, skew: skew, clipSize: clipSize, repeat: repeat, gap: gap, filters: filters} = paint;
|
|
1084
1104
|
const sameBox = box.width === width && box.height === height;
|
|
1085
|
-
const data = {
|
|
1086
|
-
|
|
1105
|
+
const data = {
|
|
1106
|
+
mode: mode
|
|
1107
|
+
};
|
|
1108
|
+
const swapSize = align !== "center" && (rotation || 0) % 180 === 90;
|
|
1087
1109
|
core.BoundsHelper.set(tempImage, 0, 0, swapSize ? height : width, swapSize ? width : height);
|
|
1088
1110
|
let scaleX, scaleY;
|
|
1089
|
-
if (!mode || mode ===
|
|
1111
|
+
if (!mode || mode === "cover" || mode === "fit") {
|
|
1090
1112
|
if (!sameBox || rotation) {
|
|
1091
|
-
scaleX = scaleY = core.BoundsHelper.getFitScale(box, tempImage, mode !==
|
|
1113
|
+
scaleX = scaleY = core.BoundsHelper.getFitScale(box, tempImage, mode !== "fit");
|
|
1092
1114
|
core.BoundsHelper.put(box, image, align, scaleX, false, tempImage);
|
|
1093
1115
|
core.BoundsHelper.scale(tempImage, scaleX, scaleY, true);
|
|
1094
1116
|
}
|
|
1095
|
-
}
|
|
1096
|
-
else {
|
|
1117
|
+
} else {
|
|
1097
1118
|
if (scale || size) {
|
|
1098
1119
|
core.MathHelper.getScaleData(scale, size, image, tempScaleData);
|
|
1099
1120
|
scaleX = tempScaleData.scaleX;
|
|
1100
1121
|
scaleY = tempScaleData.scaleY;
|
|
1101
1122
|
}
|
|
1102
|
-
if (align) {
|
|
1103
|
-
if (scaleX)
|
|
1104
|
-
|
|
1105
|
-
core.AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
|
|
1123
|
+
if (align || gap || repeat) {
|
|
1124
|
+
if (scaleX) core.BoundsHelper.scale(tempImage, scaleX, scaleY, true);
|
|
1125
|
+
if (align) core.AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
|
|
1106
1126
|
}
|
|
1107
1127
|
}
|
|
1108
|
-
if (offset)
|
|
1109
|
-
core.PointHelper.move(tempImage, offset);
|
|
1128
|
+
if (offset) core.PointHelper.move(tempImage, offset);
|
|
1110
1129
|
switch (mode) {
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1130
|
+
case "stretch":
|
|
1131
|
+
if (!sameBox) width = box.width, height = box.height;
|
|
1132
|
+
break;
|
|
1133
|
+
|
|
1134
|
+
case "normal":
|
|
1135
|
+
case "clip":
|
|
1136
|
+
if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
|
|
1137
|
+
break;
|
|
1138
|
+
|
|
1139
|
+
case "repeat":
|
|
1140
|
+
if (!sameBox || scaleX || rotation || skew) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
|
|
1141
|
+
if (!repeat) data.repeat = "repeat";
|
|
1142
|
+
const count = core.isObject(repeat);
|
|
1143
|
+
if (gap || count) data.gap = getGapData(gap, count && repeat, tempImage.width, tempImage.height, box);
|
|
1144
|
+
break;
|
|
1145
|
+
|
|
1146
|
+
case "fit":
|
|
1147
|
+
case "cover":
|
|
1148
|
+
default:
|
|
1149
|
+
if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
|
|
1131
1150
|
}
|
|
1132
1151
|
if (!data.transform) {
|
|
1133
1152
|
if (box.x || box.y) {
|
|
@@ -1135,49 +1154,69 @@ function getPatternData(paint, box, image) {
|
|
|
1135
1154
|
translate(data.transform, box.x, box.y);
|
|
1136
1155
|
}
|
|
1137
1156
|
}
|
|
1138
|
-
if (scaleX && mode !==
|
|
1157
|
+
if (scaleX && mode !== "stretch") {
|
|
1139
1158
|
data.scaleX = scaleX;
|
|
1140
1159
|
data.scaleY = scaleY;
|
|
1141
1160
|
}
|
|
1142
1161
|
data.width = width;
|
|
1143
1162
|
data.height = height;
|
|
1144
|
-
if (opacity)
|
|
1145
|
-
|
|
1146
|
-
if (
|
|
1147
|
-
data.filters = filters;
|
|
1148
|
-
if (repeat)
|
|
1149
|
-
data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
|
|
1163
|
+
if (opacity) data.opacity = opacity;
|
|
1164
|
+
if (filters) data.filters = filters;
|
|
1165
|
+
if (repeat) data.repeat = core.isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
|
|
1150
1166
|
return data;
|
|
1151
1167
|
}
|
|
1152
1168
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1169
|
+
function getGapData(gap, repeat, width, height, box) {
|
|
1170
|
+
let xGap, yGap;
|
|
1171
|
+
if (core.isObject(gap)) xGap = gap.x, yGap = gap.y; else xGap = yGap = gap;
|
|
1172
|
+
return {
|
|
1173
|
+
x: getGapValue(xGap, width, box.width, repeat && repeat.x),
|
|
1174
|
+
y: getGapValue(yGap, height, box.height, repeat && repeat.y)
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
function getGapValue(gap, size, totalSize, rows) {
|
|
1179
|
+
const auto = core.isString(gap) || rows;
|
|
1180
|
+
const remain = rows ? totalSize - rows * size : totalSize % size;
|
|
1181
|
+
const value = auto ? remain / ((rows || Math.floor(totalSize / size)) - 1) : gap;
|
|
1182
|
+
return gap === "auto" ? value < 0 ? 0 : value : value;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
let cache, box = new core.Bounds;
|
|
1186
|
+
|
|
1187
|
+
const {isSame: isSame} = core.BoundsHelper;
|
|
1188
|
+
|
|
1155
1189
|
function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
1156
1190
|
let leafPaint, event;
|
|
1157
1191
|
const image = core.ImageManager.get(paint);
|
|
1158
1192
|
if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
|
|
1159
1193
|
leafPaint = cache.leafPaint;
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1194
|
+
} else {
|
|
1195
|
+
leafPaint = {
|
|
1196
|
+
type: paint.type,
|
|
1197
|
+
image: image
|
|
1198
|
+
};
|
|
1199
|
+
if (image.hasAlphaPixel) leafPaint.isTransparent = true;
|
|
1200
|
+
cache = image.use > 1 ? {
|
|
1201
|
+
leafPaint: leafPaint,
|
|
1202
|
+
paint: paint,
|
|
1203
|
+
boxBounds: box.set(boxBounds)
|
|
1204
|
+
} : null;
|
|
1205
|
+
}
|
|
1206
|
+
if (firstUse || image.loading) event = {
|
|
1207
|
+
image: image,
|
|
1208
|
+
attrName: attrName,
|
|
1209
|
+
attrValue: paint
|
|
1210
|
+
};
|
|
1169
1211
|
if (image.ready) {
|
|
1170
1212
|
checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
|
|
1171
1213
|
if (firstUse) {
|
|
1172
1214
|
onLoad(ui, event);
|
|
1173
1215
|
onLoadSuccess(ui, event);
|
|
1174
1216
|
}
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
onLoadError(ui, event, image.error);
|
|
1179
|
-
}
|
|
1180
|
-
else {
|
|
1217
|
+
} else if (image.error) {
|
|
1218
|
+
if (firstUse) onLoadError(ui, event, image.error);
|
|
1219
|
+
} else {
|
|
1181
1220
|
if (firstUse) {
|
|
1182
1221
|
ignoreRender(ui, true);
|
|
1183
1222
|
onLoad(ui, event);
|
|
@@ -1186,79 +1225,84 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
|
1186
1225
|
ignoreRender(ui, false);
|
|
1187
1226
|
if (!ui.destroyed) {
|
|
1188
1227
|
if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
|
|
1189
|
-
if (image.hasAlphaPixel)
|
|
1190
|
-
|
|
1191
|
-
ui.forceUpdate('surface');
|
|
1228
|
+
if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
|
|
1229
|
+
ui.forceUpdate("surface");
|
|
1192
1230
|
}
|
|
1193
1231
|
onLoadSuccess(ui, event);
|
|
1194
1232
|
}
|
|
1195
1233
|
leafPaint.loadId = undefined;
|
|
1196
|
-
},
|
|
1234
|
+
}, error => {
|
|
1197
1235
|
ignoreRender(ui, false);
|
|
1198
1236
|
onLoadError(ui, event, error);
|
|
1199
1237
|
leafPaint.loadId = undefined;
|
|
1200
1238
|
});
|
|
1201
1239
|
if (ui.placeholderColor) {
|
|
1202
|
-
if (!ui.placeholderDelay)
|
|
1203
|
-
image.
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
ui.forceUpdate('surface');
|
|
1209
|
-
}
|
|
1210
|
-
}, ui.placeholderDelay);
|
|
1240
|
+
if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
|
|
1241
|
+
if (!image.ready) {
|
|
1242
|
+
image.isPlacehold = true;
|
|
1243
|
+
ui.forceUpdate("surface");
|
|
1244
|
+
}
|
|
1245
|
+
}, ui.placeholderDelay);
|
|
1211
1246
|
}
|
|
1212
1247
|
}
|
|
1213
1248
|
return leafPaint;
|
|
1214
1249
|
}
|
|
1250
|
+
|
|
1215
1251
|
function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
|
|
1216
|
-
if (attrName ===
|
|
1252
|
+
if (attrName === "fill" && !ui.__.__naturalWidth) {
|
|
1217
1253
|
const data = ui.__;
|
|
1218
1254
|
data.__naturalWidth = image.width / data.pixelRatio;
|
|
1219
1255
|
data.__naturalHeight = image.height / data.pixelRatio;
|
|
1220
1256
|
if (data.__autoSide) {
|
|
1221
|
-
ui.forceUpdate(
|
|
1257
|
+
ui.forceUpdate("width");
|
|
1222
1258
|
if (ui.__proxyData) {
|
|
1223
|
-
ui.setProxyAttr(
|
|
1224
|
-
ui.setProxyAttr(
|
|
1259
|
+
ui.setProxyAttr("width", data.width);
|
|
1260
|
+
ui.setProxyAttr("height", data.height);
|
|
1225
1261
|
}
|
|
1226
1262
|
return false;
|
|
1227
1263
|
}
|
|
1228
1264
|
}
|
|
1229
|
-
if (!leafPaint.data)
|
|
1230
|
-
createData(leafPaint, image, paint, boxBounds);
|
|
1265
|
+
if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
|
|
1231
1266
|
return true;
|
|
1232
1267
|
}
|
|
1268
|
+
|
|
1233
1269
|
function onLoad(ui, event) {
|
|
1234
1270
|
emit(ui, core.ImageEvent.LOAD, event);
|
|
1235
1271
|
}
|
|
1272
|
+
|
|
1236
1273
|
function onLoadSuccess(ui, event) {
|
|
1237
1274
|
emit(ui, core.ImageEvent.LOADED, event);
|
|
1238
1275
|
}
|
|
1276
|
+
|
|
1239
1277
|
function onLoadError(ui, event, error) {
|
|
1240
1278
|
event.error = error;
|
|
1241
|
-
ui.forceUpdate(
|
|
1279
|
+
ui.forceUpdate("surface");
|
|
1242
1280
|
emit(ui, core.ImageEvent.ERROR, event);
|
|
1243
1281
|
}
|
|
1282
|
+
|
|
1244
1283
|
function emit(ui, type, data) {
|
|
1245
|
-
if (ui.hasEvent(type))
|
|
1246
|
-
ui.emitEvent(new core.ImageEvent(type, data));
|
|
1284
|
+
if (ui.hasEvent(type)) ui.emitEvent(new core.ImageEvent(type, data));
|
|
1247
1285
|
}
|
|
1286
|
+
|
|
1248
1287
|
function ignoreRender(ui, value) {
|
|
1249
|
-
const { leafer
|
|
1250
|
-
if (leafer && leafer.viewReady)
|
|
1251
|
-
leafer.renderer.ignore = value;
|
|
1288
|
+
const {leafer: leafer} = ui;
|
|
1289
|
+
if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
|
|
1252
1290
|
}
|
|
1253
1291
|
|
|
1254
|
-
const {
|
|
1255
|
-
|
|
1292
|
+
const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
|
|
1293
|
+
|
|
1294
|
+
const {floor: floor, max: max, abs: abs} = Math;
|
|
1295
|
+
|
|
1256
1296
|
function createPattern(ui, paint, pixelRatio) {
|
|
1257
|
-
let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1258
|
-
const id = scaleX +
|
|
1297
|
+
let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1298
|
+
const id = scaleX + "-" + scaleY + "-" + pixelRatio;
|
|
1259
1299
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1260
|
-
const { image, data } = paint;
|
|
1261
|
-
let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
|
|
1300
|
+
const {image: image, data: data} = paint;
|
|
1301
|
+
let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
|
|
1302
|
+
scaleX *= pixelRatio;
|
|
1303
|
+
scaleY *= pixelRatio;
|
|
1304
|
+
const xGap = gap && gap.x * scaleX;
|
|
1305
|
+
const yGap = gap && gap.y * scaleY;
|
|
1262
1306
|
if (sx) {
|
|
1263
1307
|
sx = abs(sx);
|
|
1264
1308
|
sy = abs(sy);
|
|
@@ -1268,23 +1312,18 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1268
1312
|
scaleX *= sx;
|
|
1269
1313
|
scaleY *= sy;
|
|
1270
1314
|
}
|
|
1271
|
-
scaleX *= pixelRatio;
|
|
1272
|
-
scaleY *= pixelRatio;
|
|
1273
1315
|
width *= scaleX;
|
|
1274
1316
|
height *= scaleY;
|
|
1275
1317
|
const size = width * height;
|
|
1276
1318
|
if (!repeat) {
|
|
1277
|
-
if (size > core.Platform.image.maxCacheSize)
|
|
1278
|
-
return false;
|
|
1319
|
+
if (size > core.Platform.image.maxCacheSize) return false;
|
|
1279
1320
|
}
|
|
1280
1321
|
let maxSize = core.Platform.image.maxPatternSize;
|
|
1281
1322
|
if (!image.isSVG) {
|
|
1282
1323
|
const imageSize = image.width * image.height;
|
|
1283
|
-
if (maxSize > imageSize)
|
|
1284
|
-
maxSize = imageSize;
|
|
1324
|
+
if (maxSize > imageSize) maxSize = imageSize;
|
|
1285
1325
|
}
|
|
1286
|
-
if (size > maxSize)
|
|
1287
|
-
imageScale = Math.sqrt(size / maxSize);
|
|
1326
|
+
if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
|
|
1288
1327
|
if (imageScale) {
|
|
1289
1328
|
scaleX /= imageScale;
|
|
1290
1329
|
scaleY /= imageScale;
|
|
@@ -1298,65 +1337,62 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1298
1337
|
if (transform || scaleX !== 1 || scaleY !== 1) {
|
|
1299
1338
|
if (!imageMatrix) {
|
|
1300
1339
|
imageMatrix = get$1();
|
|
1301
|
-
if (transform)
|
|
1302
|
-
copy$1(imageMatrix, transform);
|
|
1340
|
+
if (transform) copy$1(imageMatrix, transform);
|
|
1303
1341
|
}
|
|
1304
1342
|
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1305
1343
|
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1344
|
+
if (imageMatrix) {
|
|
1345
|
+
const canvasWidth = width + (xGap || 0), canvasHeight = height + (yGap || 0);
|
|
1346
|
+
scale(imageMatrix, canvasWidth / max(floor(canvasWidth), 1), canvasHeight / max(floor(canvasHeight), 1));
|
|
1347
|
+
}
|
|
1348
|
+
const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap);
|
|
1349
|
+
const pattern = image.getPattern(canvas, repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
|
|
1308
1350
|
paint.style = pattern;
|
|
1309
1351
|
paint.patternId = id;
|
|
1310
1352
|
return true;
|
|
1311
|
-
}
|
|
1312
|
-
else {
|
|
1353
|
+
} else {
|
|
1313
1354
|
return false;
|
|
1314
1355
|
}
|
|
1315
1356
|
}
|
|
1316
1357
|
|
|
1317
1358
|
function checkImage(ui, canvas, paint, allowDraw) {
|
|
1318
|
-
const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1319
|
-
const { pixelRatio
|
|
1320
|
-
if (!data ||
|
|
1359
|
+
const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1360
|
+
const {pixelRatio: pixelRatio} = canvas, {data: data} = paint;
|
|
1361
|
+
if (!data || paint.patternId === scaleX + "-" + scaleY + "-" + pixelRatio && !draw.Export.running) {
|
|
1321
1362
|
return false;
|
|
1322
|
-
}
|
|
1323
|
-
else {
|
|
1363
|
+
} else {
|
|
1324
1364
|
if (allowDraw) {
|
|
1325
1365
|
if (data.repeat) {
|
|
1326
1366
|
allowDraw = false;
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
let { width, height } = data;
|
|
1367
|
+
} else {
|
|
1368
|
+
if (!(paint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
|
|
1369
|
+
let {width: width, height: height} = data;
|
|
1331
1370
|
width *= scaleX * pixelRatio;
|
|
1332
1371
|
height *= scaleY * pixelRatio;
|
|
1333
1372
|
if (data.scaleX) {
|
|
1334
1373
|
width *= data.scaleX;
|
|
1335
1374
|
height *= data.scaleY;
|
|
1336
1375
|
}
|
|
1337
|
-
allowDraw =
|
|
1376
|
+
allowDraw = width * height > core.Platform.image.maxCacheSize;
|
|
1338
1377
|
}
|
|
1339
1378
|
}
|
|
1340
1379
|
}
|
|
1341
1380
|
if (allowDraw) {
|
|
1342
1381
|
if (ui.__.__isFastShadow) {
|
|
1343
|
-
canvas.fillStyle = paint.style ||
|
|
1382
|
+
canvas.fillStyle = paint.style || "#000";
|
|
1344
1383
|
canvas.fill();
|
|
1345
1384
|
}
|
|
1346
1385
|
drawImage(ui, canvas, paint, data);
|
|
1347
1386
|
return true;
|
|
1348
|
-
}
|
|
1349
|
-
else {
|
|
1387
|
+
} else {
|
|
1350
1388
|
if (!paint.style || paint.sync || draw.Export.running) {
|
|
1351
1389
|
createPattern(ui, paint, pixelRatio);
|
|
1352
|
-
}
|
|
1353
|
-
else {
|
|
1390
|
+
} else {
|
|
1354
1391
|
if (!paint.patternTask) {
|
|
1355
|
-
paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*
|
|
1392
|
+
paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
|
|
1356
1393
|
paint.patternTask = null;
|
|
1357
|
-
if (canvas.bounds.hit(ui.__nowWorld))
|
|
1358
|
-
|
|
1359
|
-
ui.forceUpdate('surface');
|
|
1394
|
+
if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
|
|
1395
|
+
ui.forceUpdate("surface");
|
|
1360
1396
|
}), 300);
|
|
1361
1397
|
}
|
|
1362
1398
|
}
|
|
@@ -1364,39 +1400,35 @@ function checkImage(ui, canvas, paint, allowDraw) {
|
|
|
1364
1400
|
}
|
|
1365
1401
|
}
|
|
1366
1402
|
}
|
|
1403
|
+
|
|
1367
1404
|
function drawImage(ui, canvas, paint, data) {
|
|
1368
1405
|
canvas.save();
|
|
1369
1406
|
canvas.clipUI(ui);
|
|
1370
|
-
if (paint.blendMode)
|
|
1371
|
-
|
|
1372
|
-
if (data.
|
|
1373
|
-
canvas.opacity *= data.opacity;
|
|
1374
|
-
if (data.transform)
|
|
1375
|
-
canvas.transform(data.transform);
|
|
1407
|
+
if (paint.blendMode) canvas.blendMode = paint.blendMode;
|
|
1408
|
+
if (data.opacity) canvas.opacity *= data.opacity;
|
|
1409
|
+
if (data.transform) canvas.transform(data.transform);
|
|
1376
1410
|
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
|
|
1377
1411
|
canvas.restore();
|
|
1378
1412
|
}
|
|
1379
1413
|
|
|
1380
1414
|
function recycleImage(attrName, data) {
|
|
1381
|
-
const paints = data[
|
|
1382
|
-
if (paints
|
|
1415
|
+
const paints = data["_" + attrName];
|
|
1416
|
+
if (core.isArray(paints)) {
|
|
1383
1417
|
let paint, image, recycleMap, input, url;
|
|
1384
1418
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
1385
1419
|
paint = paints[i];
|
|
1386
1420
|
image = paint.image;
|
|
1387
1421
|
url = image && image.url;
|
|
1388
1422
|
if (url) {
|
|
1389
|
-
if (!recycleMap)
|
|
1390
|
-
recycleMap = {};
|
|
1423
|
+
if (!recycleMap) recycleMap = {};
|
|
1391
1424
|
recycleMap[url] = true;
|
|
1392
1425
|
core.ImageManager.recycle(image);
|
|
1393
1426
|
if (image.loading) {
|
|
1394
1427
|
if (!input) {
|
|
1395
|
-
input =
|
|
1396
|
-
if (!(input
|
|
1397
|
-
input = [input];
|
|
1428
|
+
input = data.__input && data.__input[attrName] || [];
|
|
1429
|
+
if (!core.isArray(input)) input = [ input ];
|
|
1398
1430
|
}
|
|
1399
|
-
image.unload(paints[i].loadId, !input.some(
|
|
1431
|
+
image.unload(paints[i].loadId, !input.some(item => item.url === url));
|
|
1400
1432
|
}
|
|
1401
1433
|
}
|
|
1402
1434
|
}
|
|
@@ -1406,75 +1438,85 @@ function recycleImage(attrName, data) {
|
|
|
1406
1438
|
}
|
|
1407
1439
|
|
|
1408
1440
|
const PaintImageModule = {
|
|
1409
|
-
image,
|
|
1410
|
-
checkImage,
|
|
1411
|
-
createPattern,
|
|
1412
|
-
recycleImage,
|
|
1413
|
-
createData,
|
|
1414
|
-
getPatternData,
|
|
1415
|
-
fillOrFitMode,
|
|
1416
|
-
clipMode,
|
|
1417
|
-
repeatMode
|
|
1441
|
+
image: image,
|
|
1442
|
+
checkImage: checkImage,
|
|
1443
|
+
createPattern: createPattern,
|
|
1444
|
+
recycleImage: recycleImage,
|
|
1445
|
+
createData: createData,
|
|
1446
|
+
getPatternData: getPatternData,
|
|
1447
|
+
fillOrFitMode: fillOrFitMode,
|
|
1448
|
+
clipMode: clipMode,
|
|
1449
|
+
repeatMode: repeatMode
|
|
1418
1450
|
};
|
|
1419
1451
|
|
|
1420
|
-
const {
|
|
1452
|
+
const {toPoint: toPoint$2} = core.AroundHelper, {hasTransparent: hasTransparent} = draw.ColorConvert;
|
|
1453
|
+
|
|
1421
1454
|
const realFrom$2 = {};
|
|
1455
|
+
|
|
1422
1456
|
const realTo$2 = {};
|
|
1457
|
+
|
|
1423
1458
|
function linearGradient(paint, box) {
|
|
1424
|
-
let { from, to, type, opacity } = paint;
|
|
1425
|
-
toPoint$2(from ||
|
|
1426
|
-
toPoint$2(to ||
|
|
1459
|
+
let {from: from, to: to, type: type, opacity: opacity} = paint;
|
|
1460
|
+
toPoint$2(from || "top", box, realFrom$2);
|
|
1461
|
+
toPoint$2(to || "bottom", box, realTo$2);
|
|
1427
1462
|
const style = core.Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
|
|
1428
|
-
const data = {
|
|
1463
|
+
const data = {
|
|
1464
|
+
type: type,
|
|
1465
|
+
style: style
|
|
1466
|
+
};
|
|
1429
1467
|
applyStops(data, style, paint.stops, opacity);
|
|
1430
1468
|
return data;
|
|
1431
1469
|
}
|
|
1470
|
+
|
|
1432
1471
|
function applyStops(data, gradient, stops, opacity) {
|
|
1433
1472
|
if (stops) {
|
|
1434
1473
|
let stop, color, offset, isTransparent;
|
|
1435
1474
|
for (let i = 0, len = stops.length; i < len; i++) {
|
|
1436
1475
|
stop = stops[i];
|
|
1437
|
-
if (
|
|
1438
|
-
|
|
1439
|
-
else
|
|
1440
|
-
offset = stop.offset, color = draw.ColorConvert.string(stop.color, opacity);
|
|
1476
|
+
if (core.isString(stop)) offset = i / (len - 1), color = draw.ColorConvert.string(stop, opacity); else offset = stop.offset,
|
|
1477
|
+
color = draw.ColorConvert.string(stop.color, opacity);
|
|
1441
1478
|
gradient.addColorStop(offset, color);
|
|
1442
|
-
if (!isTransparent && hasTransparent(color))
|
|
1443
|
-
isTransparent = true;
|
|
1479
|
+
if (!isTransparent && hasTransparent(color)) isTransparent = true;
|
|
1444
1480
|
}
|
|
1445
|
-
if (isTransparent)
|
|
1446
|
-
data.isTransparent = true;
|
|
1481
|
+
if (isTransparent) data.isTransparent = true;
|
|
1447
1482
|
}
|
|
1448
1483
|
}
|
|
1449
1484
|
|
|
1450
|
-
const { getAngle, getDistance: getDistance$1
|
|
1451
|
-
|
|
1452
|
-
const {
|
|
1485
|
+
const {getAngle: getAngle, getDistance: getDistance$1} = core.PointHelper;
|
|
1486
|
+
|
|
1487
|
+
const {get: get, rotateOfOuter: rotateOfOuter, scaleOfOuter: scaleOfOuter} = core.MatrixHelper;
|
|
1488
|
+
|
|
1489
|
+
const {toPoint: toPoint$1} = core.AroundHelper;
|
|
1490
|
+
|
|
1453
1491
|
const realFrom$1 = {};
|
|
1492
|
+
|
|
1454
1493
|
const realTo$1 = {};
|
|
1494
|
+
|
|
1455
1495
|
function radialGradient(paint, box) {
|
|
1456
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1457
|
-
toPoint$1(from ||
|
|
1458
|
-
toPoint$1(to ||
|
|
1496
|
+
let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
|
|
1497
|
+
toPoint$1(from || "center", box, realFrom$1);
|
|
1498
|
+
toPoint$1(to || "bottom", box, realTo$1);
|
|
1459
1499
|
const style = core.Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$1(realFrom$1, realTo$1));
|
|
1460
|
-
const data = {
|
|
1500
|
+
const data = {
|
|
1501
|
+
type: type,
|
|
1502
|
+
style: style
|
|
1503
|
+
};
|
|
1461
1504
|
applyStops(data, style, paint.stops, opacity);
|
|
1462
1505
|
const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
|
|
1463
|
-
if (transform)
|
|
1464
|
-
data.transform = transform;
|
|
1506
|
+
if (transform) data.transform = transform;
|
|
1465
1507
|
return data;
|
|
1466
1508
|
}
|
|
1509
|
+
|
|
1467
1510
|
function getTransform(box, from, to, stretch, rotate90) {
|
|
1468
1511
|
let transform;
|
|
1469
|
-
const { width, height } = box;
|
|
1512
|
+
const {width: width, height: height} = box;
|
|
1470
1513
|
if (width !== height || stretch) {
|
|
1471
1514
|
const angle = getAngle(from, to);
|
|
1472
1515
|
transform = get();
|
|
1473
1516
|
if (rotate90) {
|
|
1474
1517
|
scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
|
|
1475
1518
|
rotateOfOuter(transform, from, angle + 90);
|
|
1476
|
-
}
|
|
1477
|
-
else {
|
|
1519
|
+
} else {
|
|
1478
1520
|
scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
|
|
1479
1521
|
rotateOfOuter(transform, from, angle);
|
|
1480
1522
|
}
|
|
@@ -1482,81 +1524,94 @@ function getTransform(box, from, to, stretch, rotate90) {
|
|
|
1482
1524
|
return transform;
|
|
1483
1525
|
}
|
|
1484
1526
|
|
|
1485
|
-
const { getDistance
|
|
1486
|
-
|
|
1527
|
+
const {getDistance: getDistance} = core.PointHelper;
|
|
1528
|
+
|
|
1529
|
+
const {toPoint: toPoint} = core.AroundHelper;
|
|
1530
|
+
|
|
1487
1531
|
const realFrom = {};
|
|
1532
|
+
|
|
1488
1533
|
const realTo = {};
|
|
1534
|
+
|
|
1489
1535
|
function conicGradient(paint, box) {
|
|
1490
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1491
|
-
toPoint(from ||
|
|
1492
|
-
toPoint(to ||
|
|
1536
|
+
let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
|
|
1537
|
+
toPoint(from || "center", box, realFrom);
|
|
1538
|
+
toPoint(to || "bottom", box, realTo);
|
|
1493
1539
|
const style = core.Platform.conicGradientSupport ? core.Platform.canvas.createConicGradient(0, realFrom.x, realFrom.y) : core.Platform.canvas.createRadialGradient(realFrom.x, realFrom.y, 0, realFrom.x, realFrom.y, getDistance(realFrom, realTo));
|
|
1494
|
-
const data = {
|
|
1540
|
+
const data = {
|
|
1541
|
+
type: type,
|
|
1542
|
+
style: style
|
|
1543
|
+
};
|
|
1495
1544
|
applyStops(data, style, paint.stops, opacity);
|
|
1496
1545
|
const transform = getTransform(box, realFrom, realTo, stretch || 1, core.Platform.conicGradientRotate90);
|
|
1497
|
-
if (transform)
|
|
1498
|
-
data.transform = transform;
|
|
1546
|
+
if (transform) data.transform = transform;
|
|
1499
1547
|
return data;
|
|
1500
1548
|
}
|
|
1501
1549
|
|
|
1502
1550
|
const PaintGradientModule = {
|
|
1503
|
-
linearGradient,
|
|
1504
|
-
radialGradient,
|
|
1505
|
-
conicGradient,
|
|
1506
|
-
getTransform
|
|
1551
|
+
linearGradient: linearGradient,
|
|
1552
|
+
radialGradient: radialGradient,
|
|
1553
|
+
conicGradient: conicGradient,
|
|
1554
|
+
getTransform: getTransform
|
|
1507
1555
|
};
|
|
1508
1556
|
|
|
1509
|
-
const { copy, toOffsetOutBounds: toOffsetOutBounds$1
|
|
1557
|
+
const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = core.BoundsHelper;
|
|
1558
|
+
|
|
1510
1559
|
const tempBounds = {};
|
|
1560
|
+
|
|
1511
1561
|
const offsetOutBounds$1 = {};
|
|
1562
|
+
|
|
1512
1563
|
function shadow(ui, current, shape) {
|
|
1513
1564
|
let copyBounds, spreadScale;
|
|
1514
|
-
const {
|
|
1515
|
-
const { shadow
|
|
1516
|
-
const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
|
|
1565
|
+
const {__nowWorld: nowWorld, __layout: __layout} = ui;
|
|
1566
|
+
const {shadow: shadow} = ui.__;
|
|
1567
|
+
const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
|
|
1517
1568
|
const other = current.getSameCanvas();
|
|
1518
1569
|
const end = shadow.length - 1;
|
|
1519
1570
|
toOffsetOutBounds$1(bounds, offsetOutBounds$1);
|
|
1520
1571
|
shadow.forEach((item, index) => {
|
|
1521
|
-
|
|
1522
|
-
|
|
1572
|
+
let otherScale = 1;
|
|
1573
|
+
if (item.scaleFixed) {
|
|
1574
|
+
const sx = Math.abs(nowWorld.scaleX);
|
|
1575
|
+
if (sx > 1) otherScale = 1 / sx;
|
|
1576
|
+
}
|
|
1577
|
+
other.setWorldShadow(offsetOutBounds$1.offsetX + item.x * scaleX * otherScale, offsetOutBounds$1.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale, draw.ColorConvert.string(item.color));
|
|
1578
|
+
spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
|
|
1523
1579
|
drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
|
|
1524
1580
|
copyBounds = bounds;
|
|
1525
1581
|
if (item.box) {
|
|
1526
1582
|
other.restore();
|
|
1527
1583
|
other.save();
|
|
1528
1584
|
if (worldCanvas) {
|
|
1529
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
1585
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
1530
1586
|
copyBounds = nowWorld;
|
|
1531
1587
|
}
|
|
1532
|
-
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
1588
|
+
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
|
|
1533
1589
|
}
|
|
1534
1590
|
core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1535
|
-
if (end && index < end)
|
|
1536
|
-
other.clearWorld(copyBounds, true);
|
|
1591
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
1537
1592
|
});
|
|
1538
1593
|
other.recycle(copyBounds);
|
|
1539
1594
|
}
|
|
1595
|
+
|
|
1540
1596
|
function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
1541
|
-
const { bounds, shapeBounds } = shape;
|
|
1597
|
+
const {bounds: bounds, shapeBounds: shapeBounds} = shape;
|
|
1542
1598
|
if (core.Platform.fullImageShadow) {
|
|
1543
1599
|
copy(tempBounds, canvas.bounds);
|
|
1544
|
-
tempBounds.x +=
|
|
1545
|
-
tempBounds.y +=
|
|
1600
|
+
tempBounds.x += outBounds.x - shapeBounds.x;
|
|
1601
|
+
tempBounds.y += outBounds.y - shapeBounds.y;
|
|
1546
1602
|
if (spreadScale) {
|
|
1547
|
-
const {
|
|
1548
|
-
tempBounds.x -= (bounds.x + (
|
|
1549
|
-
tempBounds.y -= (bounds.y + (
|
|
1603
|
+
const {fitMatrix: fitMatrix} = shape;
|
|
1604
|
+
tempBounds.x -= (bounds.x + (fitMatrix ? fitMatrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
|
|
1605
|
+
tempBounds.y -= (bounds.y + (fitMatrix ? fitMatrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
|
|
1550
1606
|
tempBounds.width *= spreadScale;
|
|
1551
1607
|
tempBounds.height *= spreadScale;
|
|
1552
1608
|
}
|
|
1553
1609
|
canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
|
|
1554
|
-
}
|
|
1555
|
-
else {
|
|
1610
|
+
} else {
|
|
1556
1611
|
if (spreadScale) {
|
|
1557
1612
|
copy(tempBounds, outBounds);
|
|
1558
|
-
tempBounds.x -=
|
|
1559
|
-
tempBounds.y -=
|
|
1613
|
+
tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
|
|
1614
|
+
tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
|
|
1560
1615
|
tempBounds.width *= spreadScale;
|
|
1561
1616
|
tempBounds.height *= spreadScale;
|
|
1562
1617
|
}
|
|
@@ -1564,174 +1619,184 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
|
1564
1619
|
}
|
|
1565
1620
|
}
|
|
1566
1621
|
|
|
1567
|
-
const { toOffsetOutBounds
|
|
1622
|
+
const {toOffsetOutBounds: toOffsetOutBounds} = core.BoundsHelper;
|
|
1623
|
+
|
|
1568
1624
|
const offsetOutBounds = {};
|
|
1625
|
+
|
|
1569
1626
|
function innerShadow(ui, current, shape) {
|
|
1570
1627
|
let copyBounds, spreadScale;
|
|
1571
|
-
const {
|
|
1572
|
-
const { innerShadow
|
|
1573
|
-
const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
|
|
1628
|
+
const {__nowWorld: nowWorld, __layout: __layout} = ui;
|
|
1629
|
+
const {innerShadow: innerShadow} = ui.__;
|
|
1630
|
+
const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
|
|
1574
1631
|
const other = current.getSameCanvas();
|
|
1575
1632
|
const end = innerShadow.length - 1;
|
|
1576
1633
|
toOffsetOutBounds(bounds, offsetOutBounds);
|
|
1577
1634
|
innerShadow.forEach((item, index) => {
|
|
1635
|
+
let otherScale = 1;
|
|
1636
|
+
if (item.scaleFixed) {
|
|
1637
|
+
const sx = Math.abs(nowWorld.scaleX);
|
|
1638
|
+
if (sx > 1) otherScale = 1 / sx;
|
|
1639
|
+
}
|
|
1578
1640
|
other.save();
|
|
1579
|
-
other.setWorldShadow(
|
|
1580
|
-
spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) : 0;
|
|
1641
|
+
other.setWorldShadow(offsetOutBounds.offsetX + item.x * scaleX * otherScale, offsetOutBounds.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale);
|
|
1642
|
+
spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
|
|
1581
1643
|
drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
|
|
1582
1644
|
other.restore();
|
|
1583
1645
|
if (worldCanvas) {
|
|
1584
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
1585
|
-
other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
1646
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
1647
|
+
other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
|
|
1586
1648
|
copyBounds = nowWorld;
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out');
|
|
1649
|
+
} else {
|
|
1650
|
+
other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
|
|
1590
1651
|
copyBounds = bounds;
|
|
1591
1652
|
}
|
|
1592
|
-
other.fillWorld(copyBounds, draw.ColorConvert.string(item.color),
|
|
1653
|
+
other.fillWorld(copyBounds, draw.ColorConvert.string(item.color), "source-in");
|
|
1593
1654
|
core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1594
|
-
if (end && index < end)
|
|
1595
|
-
other.clearWorld(copyBounds, true);
|
|
1655
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
1596
1656
|
});
|
|
1597
1657
|
other.recycle(copyBounds);
|
|
1598
1658
|
}
|
|
1599
1659
|
|
|
1600
1660
|
function blur(ui, current, origin) {
|
|
1601
|
-
const { blur
|
|
1661
|
+
const {blur: blur} = ui.__;
|
|
1602
1662
|
origin.setWorldBlur(blur * ui.__nowWorld.a);
|
|
1603
1663
|
origin.copyWorldToInner(current, ui.__nowWorld, ui.__layout.renderBounds);
|
|
1604
|
-
origin.filter =
|
|
1664
|
+
origin.filter = "none";
|
|
1605
1665
|
}
|
|
1606
1666
|
|
|
1607
|
-
function backgroundBlur(_ui, _current, _shape) {
|
|
1608
|
-
}
|
|
1667
|
+
function backgroundBlur(_ui, _current, _shape) {}
|
|
1609
1668
|
|
|
1610
1669
|
const EffectModule = {
|
|
1611
|
-
shadow,
|
|
1612
|
-
innerShadow,
|
|
1613
|
-
blur,
|
|
1614
|
-
backgroundBlur
|
|
1670
|
+
shadow: shadow,
|
|
1671
|
+
innerShadow: innerShadow,
|
|
1672
|
+
blur: blur,
|
|
1673
|
+
backgroundBlur: backgroundBlur
|
|
1615
1674
|
};
|
|
1616
1675
|
|
|
1617
|
-
const { excludeRenderBounds
|
|
1618
|
-
|
|
1676
|
+
const {excludeRenderBounds: excludeRenderBounds} = core.LeafBoundsHelper;
|
|
1677
|
+
|
|
1678
|
+
let usedGrayscaleAlpha;
|
|
1679
|
+
|
|
1680
|
+
draw.Group.prototype.__renderMask = function(canvas, options) {
|
|
1619
1681
|
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
1620
|
-
const { children
|
|
1682
|
+
const {children: children} = this;
|
|
1621
1683
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
1622
1684
|
child = children[i], mask = child.__.mask;
|
|
1623
1685
|
if (mask) {
|
|
1624
1686
|
if (currentMask) {
|
|
1625
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1687
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
1626
1688
|
maskCanvas = contentCanvas = null;
|
|
1627
1689
|
}
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
currentMask = 'path';
|
|
1690
|
+
maskOpacity = child.__.opacity;
|
|
1691
|
+
usedGrayscaleAlpha = false;
|
|
1692
|
+
if (mask === "path" || mask === "clipping-path") {
|
|
1693
|
+
if (maskOpacity < 1) {
|
|
1694
|
+
currentMask = "opacity-path";
|
|
1695
|
+
if (!contentCanvas) contentCanvas = getCanvas(canvas);
|
|
1696
|
+
} else {
|
|
1697
|
+
currentMask = "path";
|
|
1637
1698
|
canvas.save();
|
|
1638
1699
|
}
|
|
1639
1700
|
child.__clip(contentCanvas || canvas, options);
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
if (!
|
|
1644
|
-
maskCanvas = getCanvas(canvas);
|
|
1645
|
-
if (!contentCanvas)
|
|
1646
|
-
contentCanvas = getCanvas(canvas);
|
|
1701
|
+
} else {
|
|
1702
|
+
currentMask = mask === "grayscale" ? "grayscale" : "alpha";
|
|
1703
|
+
if (!maskCanvas) maskCanvas = getCanvas(canvas);
|
|
1704
|
+
if (!contentCanvas) contentCanvas = getCanvas(canvas);
|
|
1647
1705
|
child.__render(maskCanvas, options);
|
|
1648
1706
|
}
|
|
1649
|
-
if (mask ===
|
|
1650
|
-
excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
1707
|
+
if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
1651
1708
|
continue;
|
|
1652
1709
|
}
|
|
1710
|
+
const childBlendMode = maskOpacity === 1 && child.__.__blendMode;
|
|
1711
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, false);
|
|
1653
1712
|
excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
|
|
1713
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, childBlendMode, false);
|
|
1654
1714
|
}
|
|
1655
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1715
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
1656
1716
|
};
|
|
1657
|
-
|
|
1717
|
+
|
|
1718
|
+
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity, blendMode, recycle) {
|
|
1658
1719
|
switch (maskMode) {
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1720
|
+
case "grayscale":
|
|
1721
|
+
if (!usedGrayscaleAlpha) usedGrayscaleAlpha = true, maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
|
|
1722
|
+
|
|
1723
|
+
case "alpha":
|
|
1724
|
+
usePixelMask(leaf, canvas, contentCanvas, maskCanvas, blendMode, recycle);
|
|
1725
|
+
break;
|
|
1726
|
+
|
|
1727
|
+
case "opacity-path":
|
|
1728
|
+
copyContent(leaf, canvas, contentCanvas, maskOpacity, blendMode, recycle);
|
|
1729
|
+
break;
|
|
1730
|
+
|
|
1731
|
+
case "path":
|
|
1732
|
+
if (recycle) canvas.restore();
|
|
1669
1733
|
}
|
|
1670
1734
|
}
|
|
1735
|
+
|
|
1671
1736
|
function getCanvas(canvas) {
|
|
1672
1737
|
return canvas.getSameCanvas(false, true);
|
|
1673
1738
|
}
|
|
1674
|
-
|
|
1739
|
+
|
|
1740
|
+
function usePixelMask(leaf, canvas, content, mask, blendMode, recycle) {
|
|
1675
1741
|
const realBounds = leaf.__nowWorld;
|
|
1676
1742
|
content.resetTransform();
|
|
1677
1743
|
content.opacity = 1;
|
|
1678
1744
|
content.useMask(mask, realBounds);
|
|
1679
|
-
mask.recycle(realBounds);
|
|
1680
|
-
copyContent(leaf, canvas, content, 1);
|
|
1745
|
+
if (recycle) mask.recycle(realBounds);
|
|
1746
|
+
copyContent(leaf, canvas, content, 1, blendMode, recycle);
|
|
1681
1747
|
}
|
|
1682
|
-
|
|
1748
|
+
|
|
1749
|
+
function copyContent(leaf, canvas, content, maskOpacity, blendMode, recycle) {
|
|
1683
1750
|
const realBounds = leaf.__nowWorld;
|
|
1684
1751
|
canvas.resetTransform();
|
|
1685
1752
|
canvas.opacity = maskOpacity;
|
|
1686
|
-
canvas.copyWorld(content, realBounds);
|
|
1687
|
-
content.recycle(realBounds);
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
const money =
|
|
1691
|
-
|
|
1692
|
-
const
|
|
1693
|
-
|
|
1694
|
-
const
|
|
1695
|
-
|
|
1696
|
-
const
|
|
1697
|
-
|
|
1698
|
-
const
|
|
1699
|
-
|
|
1700
|
-
const
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
[0x31C0, 0x31EF],
|
|
1715
|
-
[0x3200, 0x32FF],
|
|
1716
|
-
[0x3300, 0x33FF],
|
|
1717
|
-
[0xF900, 0xFAFF],
|
|
1718
|
-
[0xFE30, 0xFE4F],
|
|
1719
|
-
[0x1F200, 0x1F2FF],
|
|
1720
|
-
[0x2F800, 0x2FA1F],
|
|
1721
|
-
];
|
|
1722
|
-
const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join('|'));
|
|
1753
|
+
canvas.copyWorld(content, realBounds, undefined, blendMode);
|
|
1754
|
+
recycle ? content.recycle(realBounds) : content.clearWorld(realBounds, true);
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
const money = "¥¥$€££¢¢";
|
|
1758
|
+
|
|
1759
|
+
const letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
|
|
1760
|
+
|
|
1761
|
+
const langBefore = "《(「〈『〖【〔{┌<‘“=" + money;
|
|
1762
|
+
|
|
1763
|
+
const langAfter = "》)」〉』〗】〕}┐>’”!?,、。:;‰";
|
|
1764
|
+
|
|
1765
|
+
const langSymbol = "≮≯≈≠=…";
|
|
1766
|
+
|
|
1767
|
+
const langBreak$1 = "—/~|┆·";
|
|
1768
|
+
|
|
1769
|
+
const beforeChar = "{[(<'\"" + langBefore;
|
|
1770
|
+
|
|
1771
|
+
const afterChar = ">)]}%!?,.:;'\"" + langAfter;
|
|
1772
|
+
|
|
1773
|
+
const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
|
|
1774
|
+
|
|
1775
|
+
const breakChar = "- " + langBreak$1;
|
|
1776
|
+
|
|
1777
|
+
const cjkRangeList = [ [ 19968, 40959 ], [ 13312, 19903 ], [ 131072, 173791 ], [ 173824, 177983 ], [ 177984, 178207 ], [ 178208, 183983 ], [ 183984, 191471 ], [ 196608, 201551 ], [ 201552, 205743 ], [ 11904, 12031 ], [ 12032, 12255 ], [ 12272, 12287 ], [ 12288, 12351 ], [ 12736, 12783 ], [ 12800, 13055 ], [ 13056, 13311 ], [ 63744, 64255 ], [ 65072, 65103 ], [ 127488, 127743 ], [ 194560, 195103 ] ];
|
|
1778
|
+
|
|
1779
|
+
const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
|
|
1780
|
+
|
|
1723
1781
|
function mapChar(str) {
|
|
1724
1782
|
const map = {};
|
|
1725
|
-
str.split(
|
|
1783
|
+
str.split("").forEach(char => map[char] = true);
|
|
1726
1784
|
return map;
|
|
1727
1785
|
}
|
|
1786
|
+
|
|
1728
1787
|
const letterMap = mapChar(letter);
|
|
1788
|
+
|
|
1729
1789
|
const beforeMap = mapChar(beforeChar);
|
|
1790
|
+
|
|
1730
1791
|
const afterMap = mapChar(afterChar);
|
|
1792
|
+
|
|
1731
1793
|
const symbolMap = mapChar(symbolChar);
|
|
1794
|
+
|
|
1732
1795
|
const breakMap = mapChar(breakChar);
|
|
1796
|
+
|
|
1733
1797
|
var CharType;
|
|
1734
|
-
|
|
1798
|
+
|
|
1799
|
+
(function(CharType) {
|
|
1735
1800
|
CharType[CharType["Letter"] = 0] = "Letter";
|
|
1736
1801
|
CharType[CharType["Single"] = 1] = "Single";
|
|
1737
1802
|
CharType[CharType["Before"] = 2] = "Before";
|
|
@@ -1739,179 +1804,175 @@ var CharType;
|
|
|
1739
1804
|
CharType[CharType["Symbol"] = 4] = "Symbol";
|
|
1740
1805
|
CharType[CharType["Break"] = 5] = "Break";
|
|
1741
1806
|
})(CharType || (CharType = {}));
|
|
1742
|
-
|
|
1807
|
+
|
|
1808
|
+
const {Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1} = CharType;
|
|
1809
|
+
|
|
1743
1810
|
function getCharType(char) {
|
|
1744
1811
|
if (letterMap[char]) {
|
|
1745
1812
|
return Letter$1;
|
|
1746
|
-
}
|
|
1747
|
-
else if (breakMap[char]) {
|
|
1813
|
+
} else if (breakMap[char]) {
|
|
1748
1814
|
return Break$1;
|
|
1749
|
-
}
|
|
1750
|
-
else if (beforeMap[char]) {
|
|
1815
|
+
} else if (beforeMap[char]) {
|
|
1751
1816
|
return Before$1;
|
|
1752
|
-
}
|
|
1753
|
-
else if (afterMap[char]) {
|
|
1817
|
+
} else if (afterMap[char]) {
|
|
1754
1818
|
return After$1;
|
|
1755
|
-
}
|
|
1756
|
-
else if (symbolMap[char]) {
|
|
1819
|
+
} else if (symbolMap[char]) {
|
|
1757
1820
|
return Symbol$1;
|
|
1758
|
-
}
|
|
1759
|
-
else if (cjkReg.test(char)) {
|
|
1821
|
+
} else if (cjkReg.test(char)) {
|
|
1760
1822
|
return Single$1;
|
|
1761
|
-
}
|
|
1762
|
-
else {
|
|
1823
|
+
} else {
|
|
1763
1824
|
return Letter$1;
|
|
1764
1825
|
}
|
|
1765
1826
|
}
|
|
1766
1827
|
|
|
1767
1828
|
const TextRowHelper = {
|
|
1768
1829
|
trimRight(row) {
|
|
1769
|
-
const { words
|
|
1830
|
+
const {words: words} = row;
|
|
1770
1831
|
let trimRight = 0, len = words.length, char;
|
|
1771
1832
|
for (let i = len - 1; i > -1; i--) {
|
|
1772
1833
|
char = words[i].data[0];
|
|
1773
|
-
if (char.char ===
|
|
1834
|
+
if (char.char === " ") {
|
|
1774
1835
|
trimRight++;
|
|
1775
1836
|
row.width -= char.width;
|
|
1776
|
-
}
|
|
1777
|
-
else {
|
|
1837
|
+
} else {
|
|
1778
1838
|
break;
|
|
1779
1839
|
}
|
|
1780
1840
|
}
|
|
1781
|
-
if (trimRight)
|
|
1782
|
-
words.splice(len - trimRight, trimRight);
|
|
1841
|
+
if (trimRight) words.splice(len - trimRight, trimRight);
|
|
1783
1842
|
}
|
|
1784
1843
|
};
|
|
1785
1844
|
|
|
1786
1845
|
function getTextCase(char, textCase, firstChar) {
|
|
1787
1846
|
switch (textCase) {
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1847
|
+
case "title":
|
|
1848
|
+
return firstChar ? char.toUpperCase() : char;
|
|
1849
|
+
|
|
1850
|
+
case "upper":
|
|
1851
|
+
return char.toUpperCase();
|
|
1852
|
+
|
|
1853
|
+
case "lower":
|
|
1854
|
+
return char.toLowerCase();
|
|
1855
|
+
|
|
1856
|
+
default:
|
|
1857
|
+
return char;
|
|
1796
1858
|
}
|
|
1797
1859
|
}
|
|
1798
1860
|
|
|
1799
|
-
const { trimRight
|
|
1800
|
-
|
|
1861
|
+
const {trimRight: trimRight} = TextRowHelper;
|
|
1862
|
+
|
|
1863
|
+
const {Letter: Letter, Single: Single, Before: Before, After: After, Symbol: Symbol, Break: Break} = CharType;
|
|
1864
|
+
|
|
1801
1865
|
let word, row, wordWidth, rowWidth, realWidth;
|
|
1866
|
+
|
|
1802
1867
|
let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
|
|
1868
|
+
|
|
1803
1869
|
let textDrawData, rows = [], bounds, findMaxWidth;
|
|
1870
|
+
|
|
1804
1871
|
function createRows(drawData, content, style) {
|
|
1805
1872
|
textDrawData = drawData;
|
|
1806
1873
|
rows = drawData.rows;
|
|
1807
1874
|
bounds = drawData.bounds;
|
|
1808
1875
|
findMaxWidth = !bounds.width && !style.autoSizeAlign;
|
|
1809
|
-
const { __letterSpacing, paraIndent, textCase } = style;
|
|
1810
|
-
const { canvas
|
|
1811
|
-
const { width, height } = bounds;
|
|
1812
|
-
const charMode = width || height || __letterSpacing ||
|
|
1876
|
+
const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
|
|
1877
|
+
const {canvas: canvas} = core.Platform;
|
|
1878
|
+
const {width: width, height: height} = bounds;
|
|
1879
|
+
const charMode = width || height || __letterSpacing || textCase !== "none";
|
|
1813
1880
|
if (charMode) {
|
|
1814
|
-
const wrap = style.textWrap !==
|
|
1815
|
-
const breakAll = style.textWrap ===
|
|
1881
|
+
const wrap = style.textWrap !== "none";
|
|
1882
|
+
const breakAll = style.textWrap === "break";
|
|
1816
1883
|
paraStart = true;
|
|
1817
1884
|
lastCharType = null;
|
|
1818
1885
|
startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
|
|
1819
|
-
word = {
|
|
1820
|
-
|
|
1821
|
-
|
|
1886
|
+
word = {
|
|
1887
|
+
data: []
|
|
1888
|
+
}, row = {
|
|
1889
|
+
words: []
|
|
1890
|
+
};
|
|
1891
|
+
if (__letterSpacing) content = [ ...content ];
|
|
1822
1892
|
for (let i = 0, len = content.length; i < len; i++) {
|
|
1823
1893
|
char = content[i];
|
|
1824
|
-
if (char ===
|
|
1825
|
-
if (wordWidth)
|
|
1826
|
-
addWord();
|
|
1894
|
+
if (char === "\n") {
|
|
1895
|
+
if (wordWidth) addWord();
|
|
1827
1896
|
row.paraEnd = true;
|
|
1828
1897
|
addRow();
|
|
1829
1898
|
paraStart = true;
|
|
1830
|
-
}
|
|
1831
|
-
else {
|
|
1899
|
+
} else {
|
|
1832
1900
|
charType = getCharType(char);
|
|
1833
|
-
if (charType === Letter && textCase !==
|
|
1834
|
-
char = getTextCase(char, textCase, !wordWidth);
|
|
1901
|
+
if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
|
|
1835
1902
|
charWidth = canvas.measureText(char).width;
|
|
1836
1903
|
if (__letterSpacing) {
|
|
1837
|
-
if (__letterSpacing < 0)
|
|
1838
|
-
charSize = charWidth;
|
|
1904
|
+
if (__letterSpacing < 0) charSize = charWidth;
|
|
1839
1905
|
charWidth += __letterSpacing;
|
|
1840
1906
|
}
|
|
1841
|
-
langBreak =
|
|
1842
|
-
afterBreak = (
|
|
1907
|
+
langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
|
|
1908
|
+
afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
|
|
1843
1909
|
realWidth = paraStart && paraIndent ? width - paraIndent : width;
|
|
1844
1910
|
if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
|
|
1845
1911
|
if (breakAll) {
|
|
1846
|
-
if (wordWidth)
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
if (wordWidth)
|
|
1856
|
-
addWord();
|
|
1857
|
-
if (rowWidth)
|
|
1858
|
-
addRow();
|
|
1859
|
-
}
|
|
1860
|
-
else {
|
|
1861
|
-
if (rowWidth)
|
|
1862
|
-
addRow();
|
|
1912
|
+
if (wordWidth) addWord();
|
|
1913
|
+
if (rowWidth) addRow();
|
|
1914
|
+
} else {
|
|
1915
|
+
if (!afterBreak) afterBreak = charType === Letter && lastCharType == After;
|
|
1916
|
+
if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || wordWidth + charWidth > realWidth) {
|
|
1917
|
+
if (wordWidth) addWord();
|
|
1918
|
+
if (rowWidth) addRow();
|
|
1919
|
+
} else {
|
|
1920
|
+
if (rowWidth) addRow();
|
|
1863
1921
|
}
|
|
1864
1922
|
}
|
|
1865
1923
|
}
|
|
1866
|
-
if (char ===
|
|
1867
|
-
else {
|
|
1924
|
+
if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
|
|
1868
1925
|
if (charType === Break) {
|
|
1869
|
-
if (char ===
|
|
1870
|
-
addWord();
|
|
1926
|
+
if (char === " " && wordWidth) addWord();
|
|
1871
1927
|
addChar(char, charWidth);
|
|
1872
1928
|
addWord();
|
|
1873
|
-
}
|
|
1874
|
-
|
|
1875
|
-
if (wordWidth)
|
|
1876
|
-
addWord();
|
|
1929
|
+
} else if (langBreak || afterBreak) {
|
|
1930
|
+
if (wordWidth) addWord();
|
|
1877
1931
|
addChar(char, charWidth);
|
|
1878
|
-
}
|
|
1879
|
-
else {
|
|
1932
|
+
} else {
|
|
1880
1933
|
addChar(char, charWidth);
|
|
1881
1934
|
}
|
|
1882
1935
|
}
|
|
1883
1936
|
lastCharType = charType;
|
|
1884
1937
|
}
|
|
1885
1938
|
}
|
|
1886
|
-
if (wordWidth)
|
|
1887
|
-
|
|
1888
|
-
if (rowWidth)
|
|
1889
|
-
addRow();
|
|
1939
|
+
if (wordWidth) addWord();
|
|
1940
|
+
if (rowWidth) addRow();
|
|
1890
1941
|
rows.length > 0 && (rows[rows.length - 1].paraEnd = true);
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
|
-
content.split('\n').forEach(content => {
|
|
1942
|
+
} else {
|
|
1943
|
+
content.split("\n").forEach(content => {
|
|
1894
1944
|
textDrawData.paraNumber++;
|
|
1895
1945
|
rowWidth = canvas.measureText(content).width;
|
|
1896
|
-
rows.push({
|
|
1897
|
-
|
|
1898
|
-
|
|
1946
|
+
rows.push({
|
|
1947
|
+
x: paraIndent || 0,
|
|
1948
|
+
text: content,
|
|
1949
|
+
width: rowWidth,
|
|
1950
|
+
paraStart: true
|
|
1951
|
+
});
|
|
1952
|
+
if (findMaxWidth) setMaxWidth();
|
|
1899
1953
|
});
|
|
1900
1954
|
}
|
|
1901
1955
|
}
|
|
1956
|
+
|
|
1902
1957
|
function addChar(char, width) {
|
|
1903
|
-
if (charSize && !startCharSize)
|
|
1904
|
-
|
|
1905
|
-
|
|
1958
|
+
if (charSize && !startCharSize) startCharSize = charSize;
|
|
1959
|
+
word.data.push({
|
|
1960
|
+
char: char,
|
|
1961
|
+
width: width
|
|
1962
|
+
});
|
|
1906
1963
|
wordWidth += width;
|
|
1907
1964
|
}
|
|
1965
|
+
|
|
1908
1966
|
function addWord() {
|
|
1909
1967
|
rowWidth += wordWidth;
|
|
1910
1968
|
word.width = wordWidth;
|
|
1911
1969
|
row.words.push(word);
|
|
1912
|
-
word = {
|
|
1970
|
+
word = {
|
|
1971
|
+
data: []
|
|
1972
|
+
};
|
|
1913
1973
|
wordWidth = 0;
|
|
1914
1974
|
}
|
|
1975
|
+
|
|
1915
1976
|
function addRow() {
|
|
1916
1977
|
if (paraStart) {
|
|
1917
1978
|
textDrawData.paraNumber++;
|
|
@@ -1924,52 +1985,53 @@ function addRow() {
|
|
|
1924
1985
|
startCharSize = 0;
|
|
1925
1986
|
}
|
|
1926
1987
|
row.width = rowWidth;
|
|
1927
|
-
if (bounds.width)
|
|
1928
|
-
trimRight(row);
|
|
1929
|
-
else if (findMaxWidth)
|
|
1930
|
-
setMaxWidth();
|
|
1988
|
+
if (bounds.width) trimRight(row); else if (findMaxWidth) setMaxWidth();
|
|
1931
1989
|
rows.push(row);
|
|
1932
|
-
row = {
|
|
1990
|
+
row = {
|
|
1991
|
+
words: []
|
|
1992
|
+
};
|
|
1933
1993
|
rowWidth = 0;
|
|
1934
1994
|
}
|
|
1995
|
+
|
|
1935
1996
|
function setMaxWidth() {
|
|
1936
|
-
if (rowWidth > (textDrawData.maxWidth || 0))
|
|
1937
|
-
textDrawData.maxWidth = rowWidth;
|
|
1997
|
+
if (rowWidth > (textDrawData.maxWidth || 0)) textDrawData.maxWidth = rowWidth;
|
|
1938
1998
|
}
|
|
1939
1999
|
|
|
1940
2000
|
const CharMode = 0;
|
|
2001
|
+
|
|
1941
2002
|
const WordMode = 1;
|
|
2003
|
+
|
|
1942
2004
|
const TextMode = 2;
|
|
2005
|
+
|
|
1943
2006
|
function layoutChar(drawData, style, width, _height) {
|
|
1944
|
-
const { rows
|
|
1945
|
-
const { textAlign, paraIndent, letterSpacing } = style;
|
|
2007
|
+
const {rows: rows} = drawData;
|
|
2008
|
+
const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
|
|
1946
2009
|
let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
|
|
1947
2010
|
rows.forEach(row => {
|
|
1948
2011
|
if (row.words) {
|
|
1949
2012
|
indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
|
|
1950
|
-
addWordWidth =
|
|
1951
|
-
mode =
|
|
1952
|
-
if (row.isOverflow && !letterSpacing)
|
|
1953
|
-
row.textMode = true;
|
|
2013
|
+
addWordWidth = width && (textAlign === "justify" || textAlign === "both") && wordsLength > 1 ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
|
|
2014
|
+
mode = letterSpacing || row.isOverflow ? CharMode : addWordWidth > .01 ? WordMode : TextMode;
|
|
2015
|
+
if (row.isOverflow && !letterSpacing) row.textMode = true;
|
|
1954
2016
|
if (mode === TextMode) {
|
|
1955
2017
|
row.x += indentWidth;
|
|
1956
2018
|
toTextChar$1(row);
|
|
1957
|
-
}
|
|
1958
|
-
else {
|
|
2019
|
+
} else {
|
|
1959
2020
|
row.x += indentWidth;
|
|
1960
2021
|
charX = row.x;
|
|
1961
2022
|
row.data = [];
|
|
1962
2023
|
row.words.forEach((word, index) => {
|
|
1963
2024
|
if (mode === WordMode) {
|
|
1964
|
-
wordChar = {
|
|
2025
|
+
wordChar = {
|
|
2026
|
+
char: "",
|
|
2027
|
+
x: charX
|
|
2028
|
+
};
|
|
1965
2029
|
charX = toWordChar(word.data, charX, wordChar);
|
|
1966
|
-
if (row.isOverflow || wordChar.char !==
|
|
1967
|
-
|
|
1968
|
-
}
|
|
1969
|
-
else {
|
|
2030
|
+
if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
|
|
2031
|
+
} else {
|
|
1970
2032
|
charX = toChar(word.data, charX, row.data, row.isOverflow);
|
|
1971
2033
|
}
|
|
1972
|
-
if (addWordWidth && (!row.paraEnd || textAlign ===
|
|
2034
|
+
if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
|
|
1973
2035
|
charX += addWordWidth;
|
|
1974
2036
|
row.width += addWordWidth;
|
|
1975
2037
|
}
|
|
@@ -1979,14 +2041,16 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
1979
2041
|
}
|
|
1980
2042
|
});
|
|
1981
2043
|
}
|
|
2044
|
+
|
|
1982
2045
|
function toTextChar$1(row) {
|
|
1983
|
-
row.text =
|
|
2046
|
+
row.text = "";
|
|
1984
2047
|
row.words.forEach(word => {
|
|
1985
2048
|
word.data.forEach(char => {
|
|
1986
2049
|
row.text += char.char;
|
|
1987
2050
|
});
|
|
1988
2051
|
});
|
|
1989
2052
|
}
|
|
2053
|
+
|
|
1990
2054
|
function toWordChar(data, charX, wordChar) {
|
|
1991
2055
|
data.forEach(char => {
|
|
1992
2056
|
wordChar.char += char.char;
|
|
@@ -1994,9 +2058,10 @@ function toWordChar(data, charX, wordChar) {
|
|
|
1994
2058
|
});
|
|
1995
2059
|
return charX;
|
|
1996
2060
|
}
|
|
2061
|
+
|
|
1997
2062
|
function toChar(data, charX, rowData, isOverflow) {
|
|
1998
2063
|
data.forEach(char => {
|
|
1999
|
-
if (isOverflow || char.char !==
|
|
2064
|
+
if (isOverflow || char.char !== " ") {
|
|
2000
2065
|
char.x = charX;
|
|
2001
2066
|
rowData.push(char);
|
|
2002
2067
|
}
|
|
@@ -2006,38 +2071,39 @@ function toChar(data, charX, rowData, isOverflow) {
|
|
|
2006
2071
|
}
|
|
2007
2072
|
|
|
2008
2073
|
function layoutText(drawData, style) {
|
|
2009
|
-
const { rows, bounds } = drawData, countRows = rows.length;
|
|
2010
|
-
const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
|
|
2011
|
-
let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
|
|
2074
|
+
const {rows: rows, bounds: bounds} = drawData, countRows = rows.length;
|
|
2075
|
+
const {__lineHeight: __lineHeight, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __clipText: __clipText, textAlign: textAlign, verticalAlign: verticalAlign, paraSpacing: paraSpacing, autoSizeAlign: autoSizeAlign} = style;
|
|
2076
|
+
let {x: x, y: y, width: width, height: height} = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
|
|
2012
2077
|
let starY = __baseLine;
|
|
2013
2078
|
if (__clipText && realHeight > height) {
|
|
2014
2079
|
realHeight = Math.max(height, __lineHeight);
|
|
2015
|
-
if (countRows > 1)
|
|
2016
|
-
|
|
2017
|
-
}
|
|
2018
|
-
else if (height || autoSizeAlign) {
|
|
2080
|
+
if (countRows > 1) drawData.overflow = countRows;
|
|
2081
|
+
} else if (height || autoSizeAlign) {
|
|
2019
2082
|
switch (verticalAlign) {
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2083
|
+
case "middle":
|
|
2084
|
+
y += (height - realHeight) / 2;
|
|
2085
|
+
break;
|
|
2086
|
+
|
|
2087
|
+
case "bottom":
|
|
2088
|
+
y += height - realHeight;
|
|
2024
2089
|
}
|
|
2025
2090
|
}
|
|
2026
2091
|
starY += y;
|
|
2027
|
-
let row, rowX, rowWidth, layoutWidth =
|
|
2092
|
+
let row, rowX, rowWidth, layoutWidth = width || autoSizeAlign ? width : drawData.maxWidth;
|
|
2028
2093
|
for (let i = 0, len = countRows; i < len; i++) {
|
|
2029
2094
|
row = rows[i];
|
|
2030
2095
|
row.x = x;
|
|
2031
|
-
if (row.width < width ||
|
|
2096
|
+
if (row.width < width || row.width > width && !__clipText) {
|
|
2032
2097
|
switch (textAlign) {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2098
|
+
case "center":
|
|
2099
|
+
row.x += (layoutWidth - row.width) / 2;
|
|
2100
|
+
break;
|
|
2101
|
+
|
|
2102
|
+
case "right":
|
|
2103
|
+
row.x += layoutWidth - row.width;
|
|
2037
2104
|
}
|
|
2038
2105
|
}
|
|
2039
|
-
if (row.paraStart && paraSpacing && i > 0)
|
|
2040
|
-
starY += paraSpacing;
|
|
2106
|
+
if (row.paraStart && paraSpacing && i > 0) starY += paraSpacing;
|
|
2041
2107
|
row.y = starY;
|
|
2042
2108
|
starY += __lineHeight;
|
|
2043
2109
|
if (drawData.overflow > i && starY > realHeight) {
|
|
@@ -2051,19 +2117,15 @@ function layoutText(drawData, style) {
|
|
|
2051
2117
|
rowWidth = -row.width + style.fontSize + __letterSpacing;
|
|
2052
2118
|
rowX -= rowWidth;
|
|
2053
2119
|
rowWidth += style.fontSize;
|
|
2054
|
-
}
|
|
2055
|
-
else {
|
|
2120
|
+
} else {
|
|
2056
2121
|
rowWidth -= __letterSpacing;
|
|
2057
2122
|
}
|
|
2058
2123
|
}
|
|
2059
|
-
if (rowX < bounds.x)
|
|
2060
|
-
|
|
2061
|
-
if (rowWidth > bounds.width)
|
|
2062
|
-
bounds.width = rowWidth;
|
|
2124
|
+
if (rowX < bounds.x) bounds.x = rowX;
|
|
2125
|
+
if (rowWidth > bounds.width) bounds.width = rowWidth;
|
|
2063
2126
|
if (__clipText && width && width < rowWidth) {
|
|
2064
2127
|
row.isOverflow = true;
|
|
2065
|
-
if (!drawData.overflow)
|
|
2066
|
-
drawData.overflow = rows.length;
|
|
2128
|
+
if (!drawData.overflow) drawData.overflow = rows.length;
|
|
2067
2129
|
}
|
|
2068
2130
|
}
|
|
2069
2131
|
bounds.y = y;
|
|
@@ -2071,20 +2133,16 @@ function layoutText(drawData, style) {
|
|
|
2071
2133
|
}
|
|
2072
2134
|
|
|
2073
2135
|
function clipText(drawData, style, x, width) {
|
|
2074
|
-
if (!width)
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
let { textOverflow } = style;
|
|
2136
|
+
if (!width) return;
|
|
2137
|
+
const {rows: rows, overflow: overflow} = drawData;
|
|
2138
|
+
let {textOverflow: textOverflow} = style;
|
|
2078
2139
|
rows.splice(overflow);
|
|
2079
|
-
if (textOverflow && textOverflow !==
|
|
2080
|
-
if (textOverflow ===
|
|
2081
|
-
textOverflow = '';
|
|
2082
|
-
else if (textOverflow === 'ellipsis')
|
|
2083
|
-
textOverflow = '...';
|
|
2140
|
+
if (textOverflow && textOverflow !== "show") {
|
|
2141
|
+
if (textOverflow === "hide") textOverflow = ""; else if (textOverflow === "ellipsis") textOverflow = "...";
|
|
2084
2142
|
let char, charRight;
|
|
2085
2143
|
const ellipsisWidth = textOverflow ? core.Platform.canvas.measureText(textOverflow).width : 0;
|
|
2086
2144
|
const right = x + width - ellipsisWidth;
|
|
2087
|
-
const list = style.textWrap ===
|
|
2145
|
+
const list = style.textWrap === "none" ? rows : [ rows[overflow - 1] ];
|
|
2088
2146
|
list.forEach(row => {
|
|
2089
2147
|
if (row.isOverflow && row.data) {
|
|
2090
2148
|
let end = row.data.length - 1;
|
|
@@ -2093,8 +2151,7 @@ function clipText(drawData, style, x, width) {
|
|
|
2093
2151
|
charRight = char.x + char.width;
|
|
2094
2152
|
if (i === end && charRight < right) {
|
|
2095
2153
|
break;
|
|
2096
|
-
}
|
|
2097
|
-
else if ((charRight < right && char.char !== ' ') || !i) {
|
|
2154
|
+
} else if (charRight < right && char.char !== " " || !i) {
|
|
2098
2155
|
row.data.splice(i + 1);
|
|
2099
2156
|
row.width -= char.width;
|
|
2100
2157
|
break;
|
|
@@ -2102,15 +2159,18 @@ function clipText(drawData, style, x, width) {
|
|
|
2102
2159
|
row.width -= char.width;
|
|
2103
2160
|
}
|
|
2104
2161
|
row.width += ellipsisWidth;
|
|
2105
|
-
row.data.push({
|
|
2106
|
-
|
|
2107
|
-
|
|
2162
|
+
row.data.push({
|
|
2163
|
+
char: textOverflow,
|
|
2164
|
+
x: charRight
|
|
2165
|
+
});
|
|
2166
|
+
if (row.textMode) toTextChar(row);
|
|
2108
2167
|
}
|
|
2109
2168
|
});
|
|
2110
2169
|
}
|
|
2111
2170
|
}
|
|
2171
|
+
|
|
2112
2172
|
function toTextChar(row) {
|
|
2113
|
-
row.text =
|
|
2173
|
+
row.text = "";
|
|
2114
2174
|
row.data.forEach(char => {
|
|
2115
2175
|
row.text += char.char;
|
|
2116
2176
|
});
|
|
@@ -2119,121 +2179,123 @@ function toTextChar(row) {
|
|
|
2119
2179
|
|
|
2120
2180
|
function decorationText(drawData, style) {
|
|
2121
2181
|
let type;
|
|
2122
|
-
const { fontSize, textDecoration } = style;
|
|
2182
|
+
const {fontSize: fontSize, textDecoration: textDecoration} = style;
|
|
2123
2183
|
drawData.decorationHeight = fontSize / 11;
|
|
2124
|
-
if (
|
|
2184
|
+
if (core.isObject(textDecoration)) {
|
|
2125
2185
|
type = textDecoration.type;
|
|
2126
|
-
if (textDecoration.color)
|
|
2127
|
-
|
|
2128
|
-
}
|
|
2129
|
-
else
|
|
2130
|
-
type = textDecoration;
|
|
2186
|
+
if (textDecoration.color) drawData.decorationColor = draw.ColorConvert.string(textDecoration.color);
|
|
2187
|
+
} else type = textDecoration;
|
|
2131
2188
|
switch (type) {
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2189
|
+
case "under":
|
|
2190
|
+
drawData.decorationY = [ fontSize * .15 ];
|
|
2191
|
+
break;
|
|
2192
|
+
|
|
2193
|
+
case "delete":
|
|
2194
|
+
drawData.decorationY = [ -fontSize * .35 ];
|
|
2195
|
+
break;
|
|
2196
|
+
|
|
2197
|
+
case "under-delete":
|
|
2198
|
+
drawData.decorationY = [ fontSize * .15, -fontSize * .35 ];
|
|
2140
2199
|
}
|
|
2141
2200
|
}
|
|
2142
2201
|
|
|
2143
|
-
const { top, right, bottom, left } = core.Direction4;
|
|
2202
|
+
const {top: top, right: right, bottom: bottom, left: left} = core.Direction4;
|
|
2203
|
+
|
|
2144
2204
|
function getDrawData(content, style) {
|
|
2145
|
-
if (
|
|
2146
|
-
content = String(content);
|
|
2205
|
+
if (!core.isString(content)) content = String(content);
|
|
2147
2206
|
let x = 0, y = 0;
|
|
2148
|
-
let width = style.__getInput(
|
|
2149
|
-
let height = style.__getInput(
|
|
2150
|
-
const { textDecoration, __font, __padding: padding
|
|
2207
|
+
let width = style.__getInput("width") || 0;
|
|
2208
|
+
let height = style.__getInput("height") || 0;
|
|
2209
|
+
const {textDecoration: textDecoration, __font: __font, __padding: padding} = style;
|
|
2151
2210
|
if (padding) {
|
|
2152
|
-
if (width)
|
|
2153
|
-
|
|
2154
|
-
else if (!style.autoSizeAlign)
|
|
2155
|
-
x = padding[left];
|
|
2156
|
-
if (height)
|
|
2157
|
-
y = padding[top], height -= (padding[top] + padding[bottom]);
|
|
2158
|
-
else if (!style.autoSizeAlign)
|
|
2159
|
-
y = padding[top];
|
|
2211
|
+
if (width) x = padding[left], width -= padding[right] + padding[left]; else if (!style.autoSizeAlign) x = padding[left];
|
|
2212
|
+
if (height) y = padding[top], height -= padding[top] + padding[bottom]; else if (!style.autoSizeAlign) y = padding[top];
|
|
2160
2213
|
}
|
|
2161
2214
|
const drawData = {
|
|
2162
|
-
bounds: {
|
|
2215
|
+
bounds: {
|
|
2216
|
+
x: x,
|
|
2217
|
+
y: y,
|
|
2218
|
+
width: width,
|
|
2219
|
+
height: height
|
|
2220
|
+
},
|
|
2163
2221
|
rows: [],
|
|
2164
2222
|
paraNumber: 0,
|
|
2165
2223
|
font: core.Platform.canvas.font = __font
|
|
2166
2224
|
};
|
|
2167
2225
|
createRows(drawData, content, style);
|
|
2168
|
-
if (padding)
|
|
2169
|
-
padAutoText(padding, drawData, style, width, height);
|
|
2226
|
+
if (padding) padAutoText(padding, drawData, style, width, height);
|
|
2170
2227
|
layoutText(drawData, style);
|
|
2171
2228
|
layoutChar(drawData, style, width);
|
|
2172
|
-
if (drawData.overflow)
|
|
2173
|
-
|
|
2174
|
-
if (textDecoration !== 'none')
|
|
2175
|
-
decorationText(drawData, style);
|
|
2229
|
+
if (drawData.overflow) clipText(drawData, style, x, width);
|
|
2230
|
+
if (textDecoration !== "none") decorationText(drawData, style);
|
|
2176
2231
|
return drawData;
|
|
2177
2232
|
}
|
|
2233
|
+
|
|
2178
2234
|
function padAutoText(padding, drawData, style, width, height) {
|
|
2179
2235
|
if (!width && style.autoSizeAlign) {
|
|
2180
2236
|
switch (style.textAlign) {
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2237
|
+
case "left":
|
|
2238
|
+
offsetText(drawData, "x", padding[left]);
|
|
2239
|
+
break;
|
|
2240
|
+
|
|
2241
|
+
case "right":
|
|
2242
|
+
offsetText(drawData, "x", -padding[right]);
|
|
2185
2243
|
}
|
|
2186
2244
|
}
|
|
2187
2245
|
if (!height && style.autoSizeAlign) {
|
|
2188
2246
|
switch (style.verticalAlign) {
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2247
|
+
case "top":
|
|
2248
|
+
offsetText(drawData, "y", padding[top]);
|
|
2249
|
+
break;
|
|
2250
|
+
|
|
2251
|
+
case "bottom":
|
|
2252
|
+
offsetText(drawData, "y", -padding[bottom]);
|
|
2193
2253
|
}
|
|
2194
2254
|
}
|
|
2195
2255
|
}
|
|
2256
|
+
|
|
2196
2257
|
function offsetText(drawData, attrName, value) {
|
|
2197
|
-
const { bounds, rows } = drawData;
|
|
2258
|
+
const {bounds: bounds, rows: rows} = drawData;
|
|
2198
2259
|
bounds[attrName] += value;
|
|
2199
|
-
for (let i = 0; i < rows.length; i++)
|
|
2200
|
-
rows[i][attrName] += value;
|
|
2260
|
+
for (let i = 0; i < rows.length; i++) rows[i][attrName] += value;
|
|
2201
2261
|
}
|
|
2202
2262
|
|
|
2203
2263
|
const TextConvertModule = {
|
|
2204
|
-
getDrawData
|
|
2264
|
+
getDrawData: getDrawData
|
|
2205
2265
|
};
|
|
2206
2266
|
|
|
2207
2267
|
function string(color, opacity) {
|
|
2208
|
-
const doOpacity =
|
|
2209
|
-
if (
|
|
2210
|
-
if (doOpacity && draw.ColorConvert.object)
|
|
2211
|
-
color = draw.ColorConvert.object(color);
|
|
2212
|
-
else
|
|
2213
|
-
return color;
|
|
2268
|
+
const doOpacity = core.isNumber(opacity) && opacity < 1;
|
|
2269
|
+
if (core.isString(color)) {
|
|
2270
|
+
if (doOpacity && draw.ColorConvert.object) color = draw.ColorConvert.object(color); else return color;
|
|
2214
2271
|
}
|
|
2215
|
-
let a = color.a
|
|
2216
|
-
if (doOpacity)
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
|
|
2272
|
+
let a = core.isUndefined(color.a) ? 1 : color.a;
|
|
2273
|
+
if (doOpacity) a *= opacity;
|
|
2274
|
+
const rgb = color.r + "," + color.g + "," + color.b;
|
|
2275
|
+
return a === 1 ? "rgb(" + rgb + ")" : "rgba(" + rgb + "," + a + ")";
|
|
2220
2276
|
}
|
|
2221
2277
|
|
|
2222
2278
|
const ColorConvertModule = {
|
|
2223
|
-
string
|
|
2279
|
+
string: string
|
|
2224
2280
|
};
|
|
2225
2281
|
|
|
2226
2282
|
Object.assign(draw.TextConvert, TextConvertModule);
|
|
2283
|
+
|
|
2227
2284
|
Object.assign(draw.ColorConvert, ColorConvertModule);
|
|
2285
|
+
|
|
2228
2286
|
Object.assign(draw.Paint, PaintModule);
|
|
2287
|
+
|
|
2229
2288
|
Object.assign(draw.PaintImage, PaintImageModule);
|
|
2289
|
+
|
|
2230
2290
|
Object.assign(draw.PaintGradient, PaintGradientModule);
|
|
2291
|
+
|
|
2231
2292
|
Object.assign(draw.Effect, EffectModule);
|
|
2232
2293
|
|
|
2233
|
-
const { setPoint, addPoint, toBounds } = draw.TwoPointBoundsHelper;
|
|
2294
|
+
const {setPoint: setPoint, addPoint: addPoint, toBounds: toBounds} = draw.TwoPointBoundsHelper;
|
|
2295
|
+
|
|
2234
2296
|
function getTrimBounds(canvas) {
|
|
2235
|
-
const { width, height } = canvas.view;
|
|
2236
|
-
const { data
|
|
2297
|
+
const {width: width, height: height} = canvas.view;
|
|
2298
|
+
const {data: data} = canvas.context.getImageData(0, 0, width, height);
|
|
2237
2299
|
let x, y, pointBounds, index = 0;
|
|
2238
2300
|
for (let i = 0; i < data.length; i += 4) {
|
|
2239
2301
|
if (data[i + 3] !== 0) {
|
|
@@ -2243,7 +2305,7 @@ function getTrimBounds(canvas) {
|
|
|
2243
2305
|
}
|
|
2244
2306
|
index++;
|
|
2245
2307
|
}
|
|
2246
|
-
const bounds = new draw.Bounds
|
|
2308
|
+
const bounds = new draw.Bounds;
|
|
2247
2309
|
if (pointBounds) {
|
|
2248
2310
|
toBounds(pointBounds, bounds);
|
|
2249
2311
|
bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
@@ -2257,64 +2319,80 @@ const ExportModule = {
|
|
|
2257
2319
|
let result;
|
|
2258
2320
|
try {
|
|
2259
2321
|
const fileType = draw.FileHelper.fileType(filename);
|
|
2260
|
-
const isDownload = filename.includes(
|
|
2322
|
+
const isDownload = filename.includes(".");
|
|
2261
2323
|
options = draw.FileHelper.getExportOptions(options);
|
|
2262
|
-
const { toURL
|
|
2263
|
-
const { download
|
|
2264
|
-
if (fileType ===
|
|
2265
|
-
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)),
|
|
2266
|
-
result = {
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2324
|
+
const {toURL: toURL} = draw.Platform;
|
|
2325
|
+
const {download: download} = draw.Platform.origin;
|
|
2326
|
+
if (fileType === "json") {
|
|
2327
|
+
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), "text"), filename);
|
|
2328
|
+
result = {
|
|
2329
|
+
data: isDownload ? true : leaf.toJSON(options.json)
|
|
2330
|
+
};
|
|
2331
|
+
} else if (fileType === "svg") {
|
|
2332
|
+
isDownload && download(toURL(leaf.toSVG(), "svg"), filename);
|
|
2333
|
+
result = {
|
|
2334
|
+
data: isDownload ? true : leaf.toSVG()
|
|
2335
|
+
};
|
|
2336
|
+
} else {
|
|
2273
2337
|
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2274
|
-
const { worldTransform, isLeafer, leafer, isFrame } = leaf;
|
|
2275
|
-
const { slice, clip, trim, screenshot, padding, onCanvas } = options;
|
|
2276
|
-
const smooth = options.smooth
|
|
2338
|
+
const {worldTransform: worldTransform, isLeafer: isLeafer, leafer: leafer, isFrame: isFrame} = leaf;
|
|
2339
|
+
const {slice: slice, clip: clip, trim: trim, screenshot: screenshot, padding: padding, onCanvas: onCanvas} = options;
|
|
2340
|
+
const smooth = draw.isUndefined(options.smooth) ? leafer ? leafer.config.smooth : true : options.smooth;
|
|
2277
2341
|
const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
|
|
2278
|
-
const fill =
|
|
2279
|
-
const needFill = draw.FileHelper.isOpaqueImage(filename) || fill, matrix = new draw.Matrix
|
|
2342
|
+
const fill = isLeafer && screenshot ? draw.isUndefined(options.fill) ? leaf.fill : options.fill : options.fill;
|
|
2343
|
+
const needFill = draw.FileHelper.isOpaqueImage(filename) || fill, matrix = new draw.Matrix;
|
|
2280
2344
|
if (screenshot) {
|
|
2281
|
-
renderBounds = screenshot === true ?
|
|
2282
|
-
}
|
|
2283
|
-
|
|
2284
|
-
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
2345
|
+
renderBounds = screenshot === true ? isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds : screenshot;
|
|
2346
|
+
} else {
|
|
2347
|
+
let relative = options.relative || (isLeafer ? "inner" : "local");
|
|
2285
2348
|
scaleX = worldTransform.scaleX;
|
|
2286
2349
|
scaleY = worldTransform.scaleY;
|
|
2287
2350
|
switch (relative) {
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2351
|
+
case "inner":
|
|
2352
|
+
matrix.set(worldTransform);
|
|
2353
|
+
break;
|
|
2354
|
+
|
|
2355
|
+
case "local":
|
|
2356
|
+
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
2357
|
+
scaleX /= leaf.scaleX;
|
|
2358
|
+
scaleY /= leaf.scaleY;
|
|
2359
|
+
break;
|
|
2360
|
+
|
|
2361
|
+
case "world":
|
|
2362
|
+
scaleX = 1;
|
|
2363
|
+
scaleY = 1;
|
|
2364
|
+
break;
|
|
2365
|
+
|
|
2366
|
+
case "page":
|
|
2367
|
+
relative = leafer || leaf;
|
|
2368
|
+
|
|
2369
|
+
default:
|
|
2370
|
+
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
2371
|
+
const l = relative.worldTransform;
|
|
2372
|
+
scaleX /= scaleX / l.scaleX;
|
|
2373
|
+
scaleY /= scaleY / l.scaleY;
|
|
2307
2374
|
}
|
|
2308
|
-
renderBounds = leaf.getBounds(
|
|
2375
|
+
renderBounds = leaf.getBounds("render", relative);
|
|
2309
2376
|
}
|
|
2310
|
-
const scaleData = {
|
|
2377
|
+
const scaleData = {
|
|
2378
|
+
scaleX: 1,
|
|
2379
|
+
scaleY: 1
|
|
2380
|
+
};
|
|
2311
2381
|
draw.MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2312
2382
|
let pixelRatio = options.pixelRatio || 1;
|
|
2313
|
-
let { x, y, width, height } = new draw.Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2314
|
-
if (clip)
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2383
|
+
let {x: x, y: y, width: width, height: height} = new draw.Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2384
|
+
if (clip) x += clip.x, y += clip.y, width = clip.width, height = clip.height;
|
|
2385
|
+
const renderOptions = {
|
|
2386
|
+
exporting: true,
|
|
2387
|
+
matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY)
|
|
2388
|
+
};
|
|
2389
|
+
let canvas = draw.Creator.canvas({
|
|
2390
|
+
width: Math.floor(width),
|
|
2391
|
+
height: Math.floor(height),
|
|
2392
|
+
pixelRatio: pixelRatio,
|
|
2393
|
+
smooth: smooth,
|
|
2394
|
+
contextSettings: contextSettings
|
|
2395
|
+
});
|
|
2318
2396
|
let sliceLeaf;
|
|
2319
2397
|
if (slice) {
|
|
2320
2398
|
sliceLeaf = leaf;
|
|
@@ -2323,144 +2401,180 @@ const ExportModule = {
|
|
|
2323
2401
|
renderOptions.bounds = canvas.bounds;
|
|
2324
2402
|
}
|
|
2325
2403
|
canvas.save();
|
|
2326
|
-
if (isFrame && fill
|
|
2327
|
-
const oldFill = leaf.get(
|
|
2328
|
-
leaf.fill =
|
|
2404
|
+
if (isFrame && !draw.isUndefined(fill)) {
|
|
2405
|
+
const oldFill = leaf.get("fill");
|
|
2406
|
+
leaf.fill = "";
|
|
2329
2407
|
leaf.__render(canvas, renderOptions);
|
|
2330
2408
|
leaf.fill = oldFill;
|
|
2331
|
-
}
|
|
2332
|
-
else {
|
|
2409
|
+
} else {
|
|
2333
2410
|
leaf.__render(canvas, renderOptions);
|
|
2334
2411
|
}
|
|
2335
2412
|
canvas.restore();
|
|
2336
|
-
if (sliceLeaf)
|
|
2337
|
-
sliceLeaf.__updateWorldOpacity();
|
|
2413
|
+
if (sliceLeaf) sliceLeaf.__updateWorldOpacity();
|
|
2338
2414
|
if (trim) {
|
|
2339
2415
|
trimBounds = getTrimBounds(canvas);
|
|
2340
|
-
const old = canvas, { width, height } = trimBounds;
|
|
2341
|
-
const config = {
|
|
2416
|
+
const old = canvas, {width: width, height: height} = trimBounds;
|
|
2417
|
+
const config = {
|
|
2418
|
+
x: 0,
|
|
2419
|
+
y: 0,
|
|
2420
|
+
width: width,
|
|
2421
|
+
height: height,
|
|
2422
|
+
pixelRatio: pixelRatio
|
|
2423
|
+
};
|
|
2342
2424
|
canvas = draw.Creator.canvas(config);
|
|
2343
2425
|
canvas.copyWorld(old, trimBounds, config);
|
|
2426
|
+
old.destroy();
|
|
2344
2427
|
}
|
|
2345
2428
|
if (padding) {
|
|
2346
2429
|
const [top, right, bottom, left] = draw.MathHelper.fourNumber(padding);
|
|
2347
|
-
const old = canvas, { width, height } = old;
|
|
2348
|
-
canvas = draw.Creator.canvas({
|
|
2349
|
-
|
|
2430
|
+
const old = canvas, {width: width, height: height} = old;
|
|
2431
|
+
canvas = draw.Creator.canvas({
|
|
2432
|
+
width: width + left + right,
|
|
2433
|
+
height: height + top + bottom,
|
|
2434
|
+
pixelRatio: pixelRatio
|
|
2435
|
+
});
|
|
2436
|
+
canvas.copyWorld(old, old.bounds, {
|
|
2437
|
+
x: left,
|
|
2438
|
+
y: top,
|
|
2439
|
+
width: width,
|
|
2440
|
+
height: height
|
|
2441
|
+
});
|
|
2442
|
+
old.destroy();
|
|
2350
2443
|
}
|
|
2351
|
-
if (needFill)
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2444
|
+
if (needFill) canvas.fillWorld(canvas.bounds, fill || "#FFFFFF", "destination-over");
|
|
2445
|
+
if (onCanvas) onCanvas(canvas);
|
|
2446
|
+
const data = filename === "canvas" ? canvas : canvas.export(filename, options);
|
|
2447
|
+
result = {
|
|
2448
|
+
data: data,
|
|
2449
|
+
width: canvas.pixelWidth,
|
|
2450
|
+
height: canvas.pixelHeight,
|
|
2451
|
+
renderBounds: renderBounds,
|
|
2452
|
+
trimBounds: trimBounds
|
|
2453
|
+
};
|
|
2357
2454
|
}
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
|
-
|
|
2455
|
+
} catch (error) {
|
|
2456
|
+
result = {
|
|
2457
|
+
data: "",
|
|
2458
|
+
error: error
|
|
2459
|
+
};
|
|
2361
2460
|
}
|
|
2362
2461
|
draw.Export.running = false;
|
|
2363
2462
|
return result;
|
|
2364
2463
|
},
|
|
2365
2464
|
export(leaf, filename, options) {
|
|
2366
2465
|
draw.Export.running = true;
|
|
2367
|
-
return addTask(
|
|
2368
|
-
const getResult = () => __awaiter(this, void 0, void 0, function*
|
|
2369
|
-
if (!draw.Resource.isComplete)
|
|
2370
|
-
return draw.Platform.requestRender(getResult);
|
|
2466
|
+
return addTask(success => new Promise(resolve => {
|
|
2467
|
+
const getResult = () => __awaiter(this, void 0, void 0, function*() {
|
|
2468
|
+
if (!draw.Resource.isComplete) return draw.Platform.requestRender(getResult);
|
|
2371
2469
|
const result = draw.Export.syncExport(leaf, filename, options);
|
|
2372
|
-
if (result.data instanceof Promise)
|
|
2373
|
-
result.data = yield result.data;
|
|
2470
|
+
if (result.data instanceof Promise) result.data = yield result.data;
|
|
2374
2471
|
success(result);
|
|
2375
2472
|
resolve();
|
|
2376
2473
|
});
|
|
2377
2474
|
leaf.updateLayout();
|
|
2378
2475
|
checkLazy(leaf);
|
|
2379
|
-
const { leafer
|
|
2380
|
-
if (leafer)
|
|
2381
|
-
leafer.waitViewCompleted(getResult);
|
|
2382
|
-
else
|
|
2383
|
-
getResult();
|
|
2476
|
+
const {leafer: leafer} = leaf;
|
|
2477
|
+
if (leafer) leafer.waitViewCompleted(getResult); else getResult();
|
|
2384
2478
|
}));
|
|
2385
2479
|
}
|
|
2386
2480
|
};
|
|
2481
|
+
|
|
2387
2482
|
let tasker;
|
|
2483
|
+
|
|
2388
2484
|
function addTask(task) {
|
|
2389
|
-
if (!tasker)
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2485
|
+
if (!tasker) tasker = new draw.TaskProcessor;
|
|
2486
|
+
return new Promise(resolve => {
|
|
2487
|
+
tasker.add(() => __awaiter(this, void 0, void 0, function*() {
|
|
2488
|
+
return yield task(resolve);
|
|
2489
|
+
}), {
|
|
2490
|
+
parallel: false
|
|
2491
|
+
});
|
|
2393
2492
|
});
|
|
2394
2493
|
}
|
|
2494
|
+
|
|
2395
2495
|
function checkLazy(leaf) {
|
|
2396
|
-
if (leaf.__.__needComputePaint)
|
|
2397
|
-
|
|
2398
|
-
if (leaf.isBranch)
|
|
2399
|
-
leaf.children.forEach(child => checkLazy(child));
|
|
2496
|
+
if (leaf.__.__needComputePaint) leaf.__.__computePaint();
|
|
2497
|
+
if (leaf.isBranch) leaf.children.forEach(child => checkLazy(child));
|
|
2400
2498
|
}
|
|
2401
2499
|
|
|
2402
2500
|
const canvas = draw.LeaferCanvasBase.prototype;
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
else if (blob)
|
|
2409
|
-
return this.toBlob(filename, quality);
|
|
2410
|
-
else
|
|
2411
|
-
return this.toDataURL(filename, quality);
|
|
2501
|
+
|
|
2502
|
+
const debug = draw.Debug.get("@leafer-in/export");
|
|
2503
|
+
|
|
2504
|
+
canvas.export = function(filename, options) {
|
|
2505
|
+
const {quality: quality, blob: blob} = draw.FileHelper.getExportOptions(options);
|
|
2506
|
+
if (filename.includes(".")) return this.saveAs(filename, quality); else if (blob) return this.toBlob(filename, quality); else return this.toDataURL(filename, quality);
|
|
2412
2507
|
};
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2508
|
+
|
|
2509
|
+
canvas.toBlob = function(type, quality) {
|
|
2510
|
+
return new Promise(resolve => {
|
|
2511
|
+
draw.Platform.origin.canvasToBolb(this.view, type, quality).then(blob => {
|
|
2416
2512
|
resolve(blob);
|
|
2417
|
-
}).catch(
|
|
2513
|
+
}).catch(e => {
|
|
2418
2514
|
debug.error(e);
|
|
2419
2515
|
resolve(null);
|
|
2420
2516
|
});
|
|
2421
2517
|
});
|
|
2422
2518
|
};
|
|
2423
|
-
|
|
2519
|
+
|
|
2520
|
+
canvas.toDataURL = function(type, quality) {
|
|
2424
2521
|
return draw.Platform.origin.canvasToDataURL(this.view, type, quality);
|
|
2425
2522
|
};
|
|
2426
|
-
|
|
2427
|
-
|
|
2523
|
+
|
|
2524
|
+
canvas.saveAs = function(filename, quality) {
|
|
2525
|
+
return new Promise(resolve => {
|
|
2428
2526
|
draw.Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
|
|
2429
2527
|
resolve(true);
|
|
2430
|
-
}).catch(
|
|
2528
|
+
}).catch(e => {
|
|
2431
2529
|
debug.error(e);
|
|
2432
2530
|
resolve(false);
|
|
2433
2531
|
});
|
|
2434
2532
|
});
|
|
2435
2533
|
};
|
|
2436
2534
|
|
|
2437
|
-
draw.Plugin.add(
|
|
2535
|
+
draw.Plugin.add("export");
|
|
2536
|
+
|
|
2438
2537
|
Object.assign(draw.Export, ExportModule);
|
|
2439
|
-
|
|
2538
|
+
|
|
2539
|
+
draw.UI.prototype.export = function(filename, options) {
|
|
2440
2540
|
return draw.Export.export(this, filename, options);
|
|
2441
2541
|
};
|
|
2442
|
-
|
|
2542
|
+
|
|
2543
|
+
draw.UI.prototype.syncExport = function(filename, options) {
|
|
2443
2544
|
return draw.Export.syncExport(this, filename, options);
|
|
2444
2545
|
};
|
|
2445
2546
|
|
|
2446
2547
|
Object.defineProperty(exports, "LeaferImage", {
|
|
2447
2548
|
enumerable: true,
|
|
2448
|
-
get: function
|
|
2549
|
+
get: function() {
|
|
2550
|
+
return core.LeaferImage;
|
|
2551
|
+
}
|
|
2449
2552
|
});
|
|
2553
|
+
|
|
2450
2554
|
exports.Layouter = Layouter;
|
|
2555
|
+
|
|
2451
2556
|
exports.LeaferCanvas = LeaferCanvas;
|
|
2557
|
+
|
|
2452
2558
|
exports.Renderer = Renderer;
|
|
2559
|
+
|
|
2453
2560
|
exports.Watcher = Watcher;
|
|
2561
|
+
|
|
2454
2562
|
exports.useCanvas = useCanvas;
|
|
2455
|
-
|
|
2456
|
-
|
|
2563
|
+
|
|
2564
|
+
Object.keys(core).forEach(function(k) {
|
|
2565
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
2457
2566
|
enumerable: true,
|
|
2458
|
-
get: function
|
|
2567
|
+
get: function() {
|
|
2568
|
+
return core[k];
|
|
2569
|
+
}
|
|
2459
2570
|
});
|
|
2460
2571
|
});
|
|
2461
|
-
|
|
2462
|
-
|
|
2572
|
+
|
|
2573
|
+
Object.keys(draw).forEach(function(k) {
|
|
2574
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
2463
2575
|
enumerable: true,
|
|
2464
|
-
get: function
|
|
2576
|
+
get: function() {
|
|
2577
|
+
return draw[k];
|
|
2578
|
+
}
|
|
2465
2579
|
});
|
|
2466
2580
|
});
|