@leafer-draw/node 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node.cjs +1162 -1052
- package/dist/node.esm.js +1146 -1046
- 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,23 @@ 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
869
|
const nowWorld = ui.__nowWorld;
|
|
879
|
-
let bounds, fitMatrix, shapeBounds, worldCanvas;
|
|
880
|
-
let { scaleX, scaleY } = nowWorld;
|
|
881
|
-
if (scaleX < 0)
|
|
882
|
-
|
|
883
|
-
if (scaleY < 0)
|
|
884
|
-
scaleY = -scaleY;
|
|
870
|
+
let bounds, matrix, fitMatrix, shapeBounds, worldCanvas;
|
|
871
|
+
let {scaleX: scaleX, scaleY: scaleY} = nowWorld;
|
|
872
|
+
if (scaleX < 0) scaleX = -scaleX;
|
|
873
|
+
if (scaleY < 0) scaleY = -scaleY;
|
|
885
874
|
if (current.bounds.includes(nowWorld)) {
|
|
886
875
|
worldCanvas = canvas;
|
|
887
876
|
bounds = shapeBounds = nowWorld;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
const
|
|
891
|
-
const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [spread * scaleY, spread * scaleX]) : current.bounds, nowWorld);
|
|
877
|
+
} else {
|
|
878
|
+
const {renderShapeSpread: spread} = ui.__layout;
|
|
879
|
+
const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [ spread * scaleY, spread * scaleX ]) : current.bounds, nowWorld);
|
|
892
880
|
fitMatrix = current.bounds.getFitMatrix(worldClipBounds);
|
|
893
|
-
let {
|
|
881
|
+
let {a: fitScaleX, d: fitScaleY} = fitMatrix;
|
|
894
882
|
if (fitMatrix.a < 1) {
|
|
895
883
|
worldCanvas = current.getSameCanvas();
|
|
896
884
|
ui.__renderShape(worldCanvas, options);
|
|
@@ -899,28 +887,39 @@ function shape(ui, current, options) {
|
|
|
899
887
|
}
|
|
900
888
|
shapeBounds = getOuterOf(nowWorld, fitMatrix);
|
|
901
889
|
bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f);
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
890
|
+
const userMatrix = options.matrix;
|
|
891
|
+
if (userMatrix) {
|
|
892
|
+
matrix = new core.Matrix(fitMatrix);
|
|
893
|
+
matrix.multiply(userMatrix);
|
|
894
|
+
fitScaleX *= userMatrix.scaleX;
|
|
895
|
+
fitScaleY *= userMatrix.scaleY;
|
|
896
|
+
} else matrix = fitMatrix;
|
|
897
|
+
matrix.withScale(fitScaleX, fitScaleY);
|
|
898
|
+
options = Object.assign(Object.assign({}, options), {
|
|
899
|
+
matrix: matrix
|
|
900
|
+
});
|
|
909
901
|
}
|
|
910
902
|
ui.__renderShape(canvas, options);
|
|
911
903
|
return {
|
|
912
|
-
canvas
|
|
913
|
-
|
|
904
|
+
canvas: canvas,
|
|
905
|
+
matrix: matrix,
|
|
906
|
+
fitMatrix: fitMatrix,
|
|
907
|
+
bounds: bounds,
|
|
908
|
+
worldCanvas: worldCanvas,
|
|
909
|
+
shapeBounds: shapeBounds,
|
|
910
|
+
scaleX: scaleX,
|
|
911
|
+
scaleY: scaleY
|
|
914
912
|
};
|
|
915
913
|
}
|
|
916
914
|
|
|
917
915
|
let recycleMap;
|
|
918
|
-
|
|
916
|
+
|
|
917
|
+
const {stintSet: stintSet} = core.DataHelper, {hasTransparent: hasTransparent$1} = draw.ColorConvert;
|
|
918
|
+
|
|
919
919
|
function compute(attrName, ui) {
|
|
920
920
|
const data = ui.__, leafPaints = [];
|
|
921
921
|
let paints = data.__input[attrName], isAlphaPixel, isTransparent;
|
|
922
|
-
if (!(paints
|
|
923
|
-
paints = [paints];
|
|
922
|
+
if (!core.isArray(paints)) paints = [ paints ];
|
|
924
923
|
recycleMap = draw.PaintImage.recycleImage(attrName, data);
|
|
925
924
|
let maxChildStrokeWidth;
|
|
926
925
|
for (let i = 0, len = paints.length, item; i < len; i++) {
|
|
@@ -928,206 +927,222 @@ function compute(attrName, ui) {
|
|
|
928
927
|
leafPaints.push(item);
|
|
929
928
|
if (item.strokeStyle) {
|
|
930
929
|
maxChildStrokeWidth || (maxChildStrokeWidth = 1);
|
|
931
|
-
if (item.strokeStyle.strokeWidth)
|
|
932
|
-
maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
930
|
+
if (item.strokeStyle.strokeWidth) maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
933
931
|
}
|
|
934
932
|
}
|
|
935
933
|
}
|
|
936
|
-
data[
|
|
934
|
+
data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
|
|
937
935
|
if (leafPaints.length) {
|
|
938
936
|
if (leafPaints.every(item => item.isTransparent)) {
|
|
939
|
-
if (leafPaints.some(item => item.image))
|
|
940
|
-
isAlphaPixel = true;
|
|
937
|
+
if (leafPaints.some(item => item.image)) isAlphaPixel = true;
|
|
941
938
|
isTransparent = true;
|
|
942
939
|
}
|
|
943
940
|
}
|
|
944
|
-
if (attrName ===
|
|
945
|
-
stintSet(data,
|
|
946
|
-
stintSet(data,
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
stintSet(data,
|
|
950
|
-
stintSet(data,
|
|
951
|
-
stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth);
|
|
941
|
+
if (attrName === "fill") {
|
|
942
|
+
stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
|
|
943
|
+
stintSet(data, "__isTransparentFill", isTransparent);
|
|
944
|
+
} else {
|
|
945
|
+
stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
|
|
946
|
+
stintSet(data, "__isTransparentStroke", isTransparent);
|
|
947
|
+
stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
|
|
952
948
|
}
|
|
953
949
|
}
|
|
950
|
+
|
|
954
951
|
function getLeafPaint(attrName, paint, ui) {
|
|
955
|
-
if (
|
|
956
|
-
return undefined;
|
|
952
|
+
if (!core.isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
|
|
957
953
|
let data;
|
|
958
|
-
const { boxBounds
|
|
954
|
+
const {boxBounds: boxBounds} = ui.__layout;
|
|
959
955
|
switch (paint.type) {
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
956
|
+
case "image":
|
|
957
|
+
data = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
|
|
958
|
+
break;
|
|
959
|
+
|
|
960
|
+
case "linear":
|
|
961
|
+
data = draw.PaintGradient.linearGradient(paint, boxBounds);
|
|
962
|
+
break;
|
|
963
|
+
|
|
964
|
+
case "radial":
|
|
965
|
+
data = draw.PaintGradient.radialGradient(paint, boxBounds);
|
|
966
|
+
break;
|
|
967
|
+
|
|
968
|
+
case "angular":
|
|
969
|
+
data = draw.PaintGradient.conicGradient(paint, boxBounds);
|
|
970
|
+
break;
|
|
971
|
+
|
|
972
|
+
case "solid":
|
|
973
|
+
const {type: type, color: color, opacity: opacity} = paint;
|
|
974
|
+
data = {
|
|
975
|
+
type: type,
|
|
976
|
+
style: draw.ColorConvert.string(color, opacity)
|
|
977
|
+
};
|
|
978
|
+
break;
|
|
979
|
+
|
|
980
|
+
default:
|
|
981
|
+
if (!core.isUndefined(paint.r)) data = {
|
|
982
|
+
type: "solid",
|
|
983
|
+
style: draw.ColorConvert.string(paint)
|
|
984
|
+
};
|
|
979
985
|
}
|
|
980
986
|
if (data) {
|
|
981
|
-
if (
|
|
982
|
-
data.isTransparent = true;
|
|
987
|
+
if (core.isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
|
|
983
988
|
if (paint.style) {
|
|
984
|
-
if (paint.style.strokeWidth === 0)
|
|
985
|
-
return undefined;
|
|
989
|
+
if (paint.style.strokeWidth === 0) return undefined;
|
|
986
990
|
data.strokeStyle = paint.style;
|
|
987
991
|
}
|
|
988
|
-
if (paint.
|
|
989
|
-
|
|
992
|
+
if (paint.editing) data.editing = paint.editing;
|
|
993
|
+
if (paint.blendMode) data.blendMode = paint.blendMode;
|
|
990
994
|
}
|
|
991
995
|
return data;
|
|
992
996
|
}
|
|
993
997
|
|
|
994
998
|
const PaintModule = {
|
|
995
|
-
compute,
|
|
996
|
-
fill,
|
|
997
|
-
fills,
|
|
998
|
-
fillPathOrText,
|
|
999
|
-
fillText,
|
|
1000
|
-
stroke,
|
|
1001
|
-
strokes,
|
|
1002
|
-
strokeText,
|
|
1003
|
-
drawTextStroke,
|
|
1004
|
-
shape
|
|
999
|
+
compute: compute,
|
|
1000
|
+
fill: fill,
|
|
1001
|
+
fills: fills,
|
|
1002
|
+
fillPathOrText: fillPathOrText,
|
|
1003
|
+
fillText: fillText,
|
|
1004
|
+
stroke: stroke,
|
|
1005
|
+
strokes: strokes,
|
|
1006
|
+
strokeText: strokeText,
|
|
1007
|
+
drawTextStroke: drawTextStroke,
|
|
1008
|
+
shape: shape
|
|
1005
1009
|
};
|
|
1006
1010
|
|
|
1007
1011
|
let origin = {}, tempMatrix = core.getMatrixData();
|
|
1008
|
-
|
|
1012
|
+
|
|
1013
|
+
const {get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = core.MatrixHelper;
|
|
1014
|
+
|
|
1009
1015
|
function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
1010
1016
|
const transform = get$3();
|
|
1011
1017
|
translate$1(transform, box.x + x, box.y + y);
|
|
1012
1018
|
scaleHelper(transform, scaleX, scaleY);
|
|
1013
|
-
if (rotation)
|
|
1014
|
-
|
|
1019
|
+
if (rotation) rotateOfOuter$1(transform, {
|
|
1020
|
+
x: box.x + box.width / 2,
|
|
1021
|
+
y: box.y + box.height / 2
|
|
1022
|
+
}, rotation);
|
|
1015
1023
|
data.transform = transform;
|
|
1016
1024
|
}
|
|
1025
|
+
|
|
1017
1026
|
function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
|
|
1018
1027
|
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);
|
|
1028
|
+
layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
|
|
1026
1029
|
if (clipSize) {
|
|
1027
1030
|
tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
|
|
1028
1031
|
multiplyParent(transform, tempMatrix);
|
|
1029
1032
|
}
|
|
1030
1033
|
data.transform = transform;
|
|
1031
1034
|
}
|
|
1032
|
-
|
|
1035
|
+
|
|
1036
|
+
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
|
|
1033
1037
|
const transform = get$3();
|
|
1034
|
-
if (
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1038
|
+
if (freeTransform) {
|
|
1039
|
+
layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
|
|
1040
|
+
} else {
|
|
1041
|
+
if (rotation) {
|
|
1042
|
+
if (align === "center") {
|
|
1043
|
+
rotateOfOuter$1(transform, {
|
|
1044
|
+
x: width / 2,
|
|
1045
|
+
y: height / 2
|
|
1046
|
+
}, rotation);
|
|
1047
|
+
} else {
|
|
1048
|
+
rotate(transform, rotation);
|
|
1049
|
+
switch (rotation) {
|
|
1050
|
+
case 90:
|
|
1042
1051
|
translate$1(transform, height, 0);
|
|
1043
1052
|
break;
|
|
1044
|
-
|
|
1053
|
+
|
|
1054
|
+
case 180:
|
|
1045
1055
|
translate$1(transform, width, height);
|
|
1046
1056
|
break;
|
|
1047
|
-
|
|
1057
|
+
|
|
1058
|
+
case 270:
|
|
1048
1059
|
translate$1(transform, 0, width);
|
|
1049
1060
|
break;
|
|
1061
|
+
}
|
|
1050
1062
|
}
|
|
1051
1063
|
}
|
|
1064
|
+
origin.x = box.x + x;
|
|
1065
|
+
origin.y = box.y + y;
|
|
1066
|
+
translate$1(transform, origin.x, origin.y);
|
|
1067
|
+
if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
|
|
1052
1068
|
}
|
|
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
1069
|
data.transform = transform;
|
|
1059
1070
|
}
|
|
1060
1071
|
|
|
1061
|
-
|
|
1062
|
-
|
|
1072
|
+
function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
|
|
1073
|
+
if (rotation) rotate(transform, rotation);
|
|
1074
|
+
if (skew) skewHelper(transform, skew.x, skew.y);
|
|
1075
|
+
if (scaleX) scaleHelper(transform, scaleX, scaleY);
|
|
1076
|
+
translate$1(transform, box.x + x, box.y + y);
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
const {get: get$2, translate: translate} = core.MatrixHelper;
|
|
1080
|
+
|
|
1081
|
+
const tempBox = new core.Bounds;
|
|
1082
|
+
|
|
1063
1083
|
const tempScaleData = {};
|
|
1084
|
+
|
|
1064
1085
|
const tempImage = {};
|
|
1086
|
+
|
|
1065
1087
|
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;
|
|
1088
|
+
const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
|
|
1089
|
+
if (changeful) leafPaint.changeful = changeful;
|
|
1090
|
+
if (sync) leafPaint.sync = sync;
|
|
1091
|
+
if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
|
|
1075
1092
|
leafPaint.data = getPatternData(paint, box, image);
|
|
1076
1093
|
}
|
|
1094
|
+
|
|
1077
1095
|
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;
|
|
1096
|
+
if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
|
|
1097
|
+
if (paint.mode === "strench") paint.mode = "stretch";
|
|
1098
|
+
let {width: width, height: height} = image;
|
|
1099
|
+
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
1100
|
const sameBox = box.width === width && box.height === height;
|
|
1085
|
-
const data = {
|
|
1086
|
-
|
|
1101
|
+
const data = {
|
|
1102
|
+
mode: mode
|
|
1103
|
+
};
|
|
1104
|
+
const swapSize = align !== "center" && (rotation || 0) % 180 === 90;
|
|
1087
1105
|
core.BoundsHelper.set(tempImage, 0, 0, swapSize ? height : width, swapSize ? width : height);
|
|
1088
1106
|
let scaleX, scaleY;
|
|
1089
|
-
if (!mode || mode ===
|
|
1107
|
+
if (!mode || mode === "cover" || mode === "fit") {
|
|
1090
1108
|
if (!sameBox || rotation) {
|
|
1091
|
-
scaleX = scaleY = core.BoundsHelper.getFitScale(box, tempImage, mode !==
|
|
1109
|
+
scaleX = scaleY = core.BoundsHelper.getFitScale(box, tempImage, mode !== "fit");
|
|
1092
1110
|
core.BoundsHelper.put(box, image, align, scaleX, false, tempImage);
|
|
1093
1111
|
core.BoundsHelper.scale(tempImage, scaleX, scaleY, true);
|
|
1094
1112
|
}
|
|
1095
|
-
}
|
|
1096
|
-
else {
|
|
1113
|
+
} else {
|
|
1097
1114
|
if (scale || size) {
|
|
1098
1115
|
core.MathHelper.getScaleData(scale, size, image, tempScaleData);
|
|
1099
1116
|
scaleX = tempScaleData.scaleX;
|
|
1100
1117
|
scaleY = tempScaleData.scaleY;
|
|
1101
1118
|
}
|
|
1102
|
-
if (align) {
|
|
1103
|
-
if (scaleX)
|
|
1104
|
-
|
|
1105
|
-
core.AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
|
|
1119
|
+
if (align || gap || repeat) {
|
|
1120
|
+
if (scaleX) core.BoundsHelper.scale(tempImage, scaleX, scaleY, true);
|
|
1121
|
+
if (align) core.AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
|
|
1106
1122
|
}
|
|
1107
1123
|
}
|
|
1108
|
-
if (offset)
|
|
1109
|
-
core.PointHelper.move(tempImage, offset);
|
|
1124
|
+
if (offset) core.PointHelper.move(tempImage, offset);
|
|
1110
1125
|
switch (mode) {
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1126
|
+
case "stretch":
|
|
1127
|
+
if (!sameBox) width = box.width, height = box.height;
|
|
1128
|
+
break;
|
|
1129
|
+
|
|
1130
|
+
case "normal":
|
|
1131
|
+
case "clip":
|
|
1132
|
+
if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
|
|
1133
|
+
break;
|
|
1134
|
+
|
|
1135
|
+
case "repeat":
|
|
1136
|
+
if (!sameBox || scaleX || rotation || skew) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
|
|
1137
|
+
if (!repeat) data.repeat = "repeat";
|
|
1138
|
+
const count = core.isObject(repeat);
|
|
1139
|
+
if (gap || count) data.gap = getGapData(gap, count && repeat, tempImage.width, tempImage.height, box);
|
|
1140
|
+
break;
|
|
1141
|
+
|
|
1142
|
+
case "fit":
|
|
1143
|
+
case "cover":
|
|
1144
|
+
default:
|
|
1145
|
+
if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
|
|
1131
1146
|
}
|
|
1132
1147
|
if (!data.transform) {
|
|
1133
1148
|
if (box.x || box.y) {
|
|
@@ -1135,49 +1150,69 @@ function getPatternData(paint, box, image) {
|
|
|
1135
1150
|
translate(data.transform, box.x, box.y);
|
|
1136
1151
|
}
|
|
1137
1152
|
}
|
|
1138
|
-
if (scaleX && mode !==
|
|
1153
|
+
if (scaleX && mode !== "stretch") {
|
|
1139
1154
|
data.scaleX = scaleX;
|
|
1140
1155
|
data.scaleY = scaleY;
|
|
1141
1156
|
}
|
|
1142
1157
|
data.width = width;
|
|
1143
1158
|
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';
|
|
1159
|
+
if (opacity) data.opacity = opacity;
|
|
1160
|
+
if (filters) data.filters = filters;
|
|
1161
|
+
if (repeat) data.repeat = core.isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
|
|
1150
1162
|
return data;
|
|
1151
1163
|
}
|
|
1152
1164
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1165
|
+
function getGapData(gap, repeat, width, height, box) {
|
|
1166
|
+
let xGap, yGap;
|
|
1167
|
+
if (core.isObject(gap)) xGap = gap.x, yGap = gap.y; else xGap = yGap = gap;
|
|
1168
|
+
return {
|
|
1169
|
+
x: getGapValue(xGap, width, box.width, repeat && repeat.x),
|
|
1170
|
+
y: getGapValue(yGap, height, box.height, repeat && repeat.y)
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
function getGapValue(gap, size, totalSize, rows) {
|
|
1175
|
+
const auto = core.isString(gap) || rows;
|
|
1176
|
+
const remain = rows ? totalSize - rows * size : totalSize % size;
|
|
1177
|
+
const value = auto ? remain / ((rows || Math.floor(totalSize / size)) - 1) : gap;
|
|
1178
|
+
return gap === "auto" ? value < 0 ? 0 : value : value;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
let cache, box = new core.Bounds;
|
|
1182
|
+
|
|
1183
|
+
const {isSame: isSame} = core.BoundsHelper;
|
|
1184
|
+
|
|
1155
1185
|
function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
1156
1186
|
let leafPaint, event;
|
|
1157
1187
|
const image = core.ImageManager.get(paint);
|
|
1158
1188
|
if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
|
|
1159
1189
|
leafPaint = cache.leafPaint;
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1190
|
+
} else {
|
|
1191
|
+
leafPaint = {
|
|
1192
|
+
type: paint.type,
|
|
1193
|
+
image: image
|
|
1194
|
+
};
|
|
1195
|
+
if (image.hasAlphaPixel) leafPaint.isTransparent = true;
|
|
1196
|
+
cache = image.use > 1 ? {
|
|
1197
|
+
leafPaint: leafPaint,
|
|
1198
|
+
paint: paint,
|
|
1199
|
+
boxBounds: box.set(boxBounds)
|
|
1200
|
+
} : null;
|
|
1201
|
+
}
|
|
1202
|
+
if (firstUse || image.loading) event = {
|
|
1203
|
+
image: image,
|
|
1204
|
+
attrName: attrName,
|
|
1205
|
+
attrValue: paint
|
|
1206
|
+
};
|
|
1169
1207
|
if (image.ready) {
|
|
1170
1208
|
checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
|
|
1171
1209
|
if (firstUse) {
|
|
1172
1210
|
onLoad(ui, event);
|
|
1173
1211
|
onLoadSuccess(ui, event);
|
|
1174
1212
|
}
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
onLoadError(ui, event, image.error);
|
|
1179
|
-
}
|
|
1180
|
-
else {
|
|
1213
|
+
} else if (image.error) {
|
|
1214
|
+
if (firstUse) onLoadError(ui, event, image.error);
|
|
1215
|
+
} else {
|
|
1181
1216
|
if (firstUse) {
|
|
1182
1217
|
ignoreRender(ui, true);
|
|
1183
1218
|
onLoad(ui, event);
|
|
@@ -1186,79 +1221,84 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
|
1186
1221
|
ignoreRender(ui, false);
|
|
1187
1222
|
if (!ui.destroyed) {
|
|
1188
1223
|
if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
|
|
1189
|
-
if (image.hasAlphaPixel)
|
|
1190
|
-
|
|
1191
|
-
ui.forceUpdate('surface');
|
|
1224
|
+
if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
|
|
1225
|
+
ui.forceUpdate("surface");
|
|
1192
1226
|
}
|
|
1193
1227
|
onLoadSuccess(ui, event);
|
|
1194
1228
|
}
|
|
1195
1229
|
leafPaint.loadId = undefined;
|
|
1196
|
-
},
|
|
1230
|
+
}, error => {
|
|
1197
1231
|
ignoreRender(ui, false);
|
|
1198
1232
|
onLoadError(ui, event, error);
|
|
1199
1233
|
leafPaint.loadId = undefined;
|
|
1200
1234
|
});
|
|
1201
1235
|
if (ui.placeholderColor) {
|
|
1202
|
-
if (!ui.placeholderDelay)
|
|
1203
|
-
image.
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
ui.forceUpdate('surface');
|
|
1209
|
-
}
|
|
1210
|
-
}, ui.placeholderDelay);
|
|
1236
|
+
if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
|
|
1237
|
+
if (!image.ready) {
|
|
1238
|
+
image.isPlacehold = true;
|
|
1239
|
+
ui.forceUpdate("surface");
|
|
1240
|
+
}
|
|
1241
|
+
}, ui.placeholderDelay);
|
|
1211
1242
|
}
|
|
1212
1243
|
}
|
|
1213
1244
|
return leafPaint;
|
|
1214
1245
|
}
|
|
1246
|
+
|
|
1215
1247
|
function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
|
|
1216
|
-
if (attrName ===
|
|
1248
|
+
if (attrName === "fill" && !ui.__.__naturalWidth) {
|
|
1217
1249
|
const data = ui.__;
|
|
1218
1250
|
data.__naturalWidth = image.width / data.pixelRatio;
|
|
1219
1251
|
data.__naturalHeight = image.height / data.pixelRatio;
|
|
1220
1252
|
if (data.__autoSide) {
|
|
1221
|
-
ui.forceUpdate(
|
|
1253
|
+
ui.forceUpdate("width");
|
|
1222
1254
|
if (ui.__proxyData) {
|
|
1223
|
-
ui.setProxyAttr(
|
|
1224
|
-
ui.setProxyAttr(
|
|
1255
|
+
ui.setProxyAttr("width", data.width);
|
|
1256
|
+
ui.setProxyAttr("height", data.height);
|
|
1225
1257
|
}
|
|
1226
1258
|
return false;
|
|
1227
1259
|
}
|
|
1228
1260
|
}
|
|
1229
|
-
if (!leafPaint.data)
|
|
1230
|
-
createData(leafPaint, image, paint, boxBounds);
|
|
1261
|
+
if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
|
|
1231
1262
|
return true;
|
|
1232
1263
|
}
|
|
1264
|
+
|
|
1233
1265
|
function onLoad(ui, event) {
|
|
1234
1266
|
emit(ui, core.ImageEvent.LOAD, event);
|
|
1235
1267
|
}
|
|
1268
|
+
|
|
1236
1269
|
function onLoadSuccess(ui, event) {
|
|
1237
1270
|
emit(ui, core.ImageEvent.LOADED, event);
|
|
1238
1271
|
}
|
|
1272
|
+
|
|
1239
1273
|
function onLoadError(ui, event, error) {
|
|
1240
1274
|
event.error = error;
|
|
1241
|
-
ui.forceUpdate(
|
|
1275
|
+
ui.forceUpdate("surface");
|
|
1242
1276
|
emit(ui, core.ImageEvent.ERROR, event);
|
|
1243
1277
|
}
|
|
1278
|
+
|
|
1244
1279
|
function emit(ui, type, data) {
|
|
1245
|
-
if (ui.hasEvent(type))
|
|
1246
|
-
ui.emitEvent(new core.ImageEvent(type, data));
|
|
1280
|
+
if (ui.hasEvent(type)) ui.emitEvent(new core.ImageEvent(type, data));
|
|
1247
1281
|
}
|
|
1282
|
+
|
|
1248
1283
|
function ignoreRender(ui, value) {
|
|
1249
|
-
const { leafer
|
|
1250
|
-
if (leafer && leafer.viewReady)
|
|
1251
|
-
leafer.renderer.ignore = value;
|
|
1284
|
+
const {leafer: leafer} = ui;
|
|
1285
|
+
if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
|
|
1252
1286
|
}
|
|
1253
1287
|
|
|
1254
|
-
const {
|
|
1255
|
-
|
|
1288
|
+
const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
|
|
1289
|
+
|
|
1290
|
+
const {floor: floor, max: max, abs: abs} = Math;
|
|
1291
|
+
|
|
1256
1292
|
function createPattern(ui, paint, pixelRatio) {
|
|
1257
|
-
let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1258
|
-
const id = scaleX +
|
|
1293
|
+
let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1294
|
+
const id = scaleX + "-" + scaleY + "-" + pixelRatio;
|
|
1259
1295
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1260
|
-
const { image, data } = paint;
|
|
1261
|
-
let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
|
|
1296
|
+
const {image: image, data: data} = paint;
|
|
1297
|
+
let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
|
|
1298
|
+
scaleX *= pixelRatio;
|
|
1299
|
+
scaleY *= pixelRatio;
|
|
1300
|
+
const xGap = gap && gap.x * scaleX;
|
|
1301
|
+
const yGap = gap && gap.y * scaleY;
|
|
1262
1302
|
if (sx) {
|
|
1263
1303
|
sx = abs(sx);
|
|
1264
1304
|
sy = abs(sy);
|
|
@@ -1268,23 +1308,18 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1268
1308
|
scaleX *= sx;
|
|
1269
1309
|
scaleY *= sy;
|
|
1270
1310
|
}
|
|
1271
|
-
scaleX *= pixelRatio;
|
|
1272
|
-
scaleY *= pixelRatio;
|
|
1273
1311
|
width *= scaleX;
|
|
1274
1312
|
height *= scaleY;
|
|
1275
1313
|
const size = width * height;
|
|
1276
1314
|
if (!repeat) {
|
|
1277
|
-
if (size > core.Platform.image.maxCacheSize)
|
|
1278
|
-
return false;
|
|
1315
|
+
if (size > core.Platform.image.maxCacheSize) return false;
|
|
1279
1316
|
}
|
|
1280
1317
|
let maxSize = core.Platform.image.maxPatternSize;
|
|
1281
1318
|
if (!image.isSVG) {
|
|
1282
1319
|
const imageSize = image.width * image.height;
|
|
1283
|
-
if (maxSize > imageSize)
|
|
1284
|
-
maxSize = imageSize;
|
|
1320
|
+
if (maxSize > imageSize) maxSize = imageSize;
|
|
1285
1321
|
}
|
|
1286
|
-
if (size > maxSize)
|
|
1287
|
-
imageScale = Math.sqrt(size / maxSize);
|
|
1322
|
+
if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
|
|
1288
1323
|
if (imageScale) {
|
|
1289
1324
|
scaleX /= imageScale;
|
|
1290
1325
|
scaleY /= imageScale;
|
|
@@ -1298,65 +1333,62 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1298
1333
|
if (transform || scaleX !== 1 || scaleY !== 1) {
|
|
1299
1334
|
if (!imageMatrix) {
|
|
1300
1335
|
imageMatrix = get$1();
|
|
1301
|
-
if (transform)
|
|
1302
|
-
copy$1(imageMatrix, transform);
|
|
1336
|
+
if (transform) copy$1(imageMatrix, transform);
|
|
1303
1337
|
}
|
|
1304
1338
|
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1305
1339
|
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1340
|
+
if (imageMatrix) {
|
|
1341
|
+
const canvasWidth = width + (xGap || 0), canvasHeight = height + (yGap || 0);
|
|
1342
|
+
scale(imageMatrix, canvasWidth / max(floor(canvasWidth), 1), canvasHeight / max(floor(canvasHeight), 1));
|
|
1343
|
+
}
|
|
1344
|
+
const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap);
|
|
1345
|
+
const pattern = image.getPattern(canvas, repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
|
|
1308
1346
|
paint.style = pattern;
|
|
1309
1347
|
paint.patternId = id;
|
|
1310
1348
|
return true;
|
|
1311
|
-
}
|
|
1312
|
-
else {
|
|
1349
|
+
} else {
|
|
1313
1350
|
return false;
|
|
1314
1351
|
}
|
|
1315
1352
|
}
|
|
1316
1353
|
|
|
1317
1354
|
function checkImage(ui, canvas, paint, allowDraw) {
|
|
1318
|
-
const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1319
|
-
const { pixelRatio
|
|
1320
|
-
if (!data ||
|
|
1355
|
+
const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1356
|
+
const {pixelRatio: pixelRatio} = canvas, {data: data} = paint;
|
|
1357
|
+
if (!data || paint.patternId === scaleX + "-" + scaleY + "-" + pixelRatio && !draw.Export.running) {
|
|
1321
1358
|
return false;
|
|
1322
|
-
}
|
|
1323
|
-
else {
|
|
1359
|
+
} else {
|
|
1324
1360
|
if (allowDraw) {
|
|
1325
1361
|
if (data.repeat) {
|
|
1326
1362
|
allowDraw = false;
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
let { width, height } = data;
|
|
1363
|
+
} else {
|
|
1364
|
+
if (!(paint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
|
|
1365
|
+
let {width: width, height: height} = data;
|
|
1331
1366
|
width *= scaleX * pixelRatio;
|
|
1332
1367
|
height *= scaleY * pixelRatio;
|
|
1333
1368
|
if (data.scaleX) {
|
|
1334
1369
|
width *= data.scaleX;
|
|
1335
1370
|
height *= data.scaleY;
|
|
1336
1371
|
}
|
|
1337
|
-
allowDraw =
|
|
1372
|
+
allowDraw = width * height > core.Platform.image.maxCacheSize;
|
|
1338
1373
|
}
|
|
1339
1374
|
}
|
|
1340
1375
|
}
|
|
1341
1376
|
if (allowDraw) {
|
|
1342
1377
|
if (ui.__.__isFastShadow) {
|
|
1343
|
-
canvas.fillStyle = paint.style ||
|
|
1378
|
+
canvas.fillStyle = paint.style || "#000";
|
|
1344
1379
|
canvas.fill();
|
|
1345
1380
|
}
|
|
1346
1381
|
drawImage(ui, canvas, paint, data);
|
|
1347
1382
|
return true;
|
|
1348
|
-
}
|
|
1349
|
-
else {
|
|
1383
|
+
} else {
|
|
1350
1384
|
if (!paint.style || paint.sync || draw.Export.running) {
|
|
1351
1385
|
createPattern(ui, paint, pixelRatio);
|
|
1352
|
-
}
|
|
1353
|
-
else {
|
|
1386
|
+
} else {
|
|
1354
1387
|
if (!paint.patternTask) {
|
|
1355
|
-
paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*
|
|
1388
|
+
paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
|
|
1356
1389
|
paint.patternTask = null;
|
|
1357
|
-
if (canvas.bounds.hit(ui.__nowWorld))
|
|
1358
|
-
|
|
1359
|
-
ui.forceUpdate('surface');
|
|
1390
|
+
if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
|
|
1391
|
+
ui.forceUpdate("surface");
|
|
1360
1392
|
}), 300);
|
|
1361
1393
|
}
|
|
1362
1394
|
}
|
|
@@ -1364,39 +1396,35 @@ function checkImage(ui, canvas, paint, allowDraw) {
|
|
|
1364
1396
|
}
|
|
1365
1397
|
}
|
|
1366
1398
|
}
|
|
1399
|
+
|
|
1367
1400
|
function drawImage(ui, canvas, paint, data) {
|
|
1368
1401
|
canvas.save();
|
|
1369
1402
|
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);
|
|
1403
|
+
if (paint.blendMode) canvas.blendMode = paint.blendMode;
|
|
1404
|
+
if (data.opacity) canvas.opacity *= data.opacity;
|
|
1405
|
+
if (data.transform) canvas.transform(data.transform);
|
|
1376
1406
|
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
|
|
1377
1407
|
canvas.restore();
|
|
1378
1408
|
}
|
|
1379
1409
|
|
|
1380
1410
|
function recycleImage(attrName, data) {
|
|
1381
|
-
const paints = data[
|
|
1382
|
-
if (paints
|
|
1411
|
+
const paints = data["_" + attrName];
|
|
1412
|
+
if (core.isArray(paints)) {
|
|
1383
1413
|
let paint, image, recycleMap, input, url;
|
|
1384
1414
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
1385
1415
|
paint = paints[i];
|
|
1386
1416
|
image = paint.image;
|
|
1387
1417
|
url = image && image.url;
|
|
1388
1418
|
if (url) {
|
|
1389
|
-
if (!recycleMap)
|
|
1390
|
-
recycleMap = {};
|
|
1419
|
+
if (!recycleMap) recycleMap = {};
|
|
1391
1420
|
recycleMap[url] = true;
|
|
1392
1421
|
core.ImageManager.recycle(image);
|
|
1393
1422
|
if (image.loading) {
|
|
1394
1423
|
if (!input) {
|
|
1395
|
-
input =
|
|
1396
|
-
if (!(input
|
|
1397
|
-
input = [input];
|
|
1424
|
+
input = data.__input && data.__input[attrName] || [];
|
|
1425
|
+
if (!core.isArray(input)) input = [ input ];
|
|
1398
1426
|
}
|
|
1399
|
-
image.unload(paints[i].loadId, !input.some(
|
|
1427
|
+
image.unload(paints[i].loadId, !input.some(item => item.url === url));
|
|
1400
1428
|
}
|
|
1401
1429
|
}
|
|
1402
1430
|
}
|
|
@@ -1406,75 +1434,85 @@ function recycleImage(attrName, data) {
|
|
|
1406
1434
|
}
|
|
1407
1435
|
|
|
1408
1436
|
const PaintImageModule = {
|
|
1409
|
-
image,
|
|
1410
|
-
checkImage,
|
|
1411
|
-
createPattern,
|
|
1412
|
-
recycleImage,
|
|
1413
|
-
createData,
|
|
1414
|
-
getPatternData,
|
|
1415
|
-
fillOrFitMode,
|
|
1416
|
-
clipMode,
|
|
1417
|
-
repeatMode
|
|
1437
|
+
image: image,
|
|
1438
|
+
checkImage: checkImage,
|
|
1439
|
+
createPattern: createPattern,
|
|
1440
|
+
recycleImage: recycleImage,
|
|
1441
|
+
createData: createData,
|
|
1442
|
+
getPatternData: getPatternData,
|
|
1443
|
+
fillOrFitMode: fillOrFitMode,
|
|
1444
|
+
clipMode: clipMode,
|
|
1445
|
+
repeatMode: repeatMode
|
|
1418
1446
|
};
|
|
1419
1447
|
|
|
1420
|
-
const {
|
|
1448
|
+
const {toPoint: toPoint$2} = core.AroundHelper, {hasTransparent: hasTransparent} = draw.ColorConvert;
|
|
1449
|
+
|
|
1421
1450
|
const realFrom$2 = {};
|
|
1451
|
+
|
|
1422
1452
|
const realTo$2 = {};
|
|
1453
|
+
|
|
1423
1454
|
function linearGradient(paint, box) {
|
|
1424
|
-
let { from, to, type, opacity } = paint;
|
|
1425
|
-
toPoint$2(from ||
|
|
1426
|
-
toPoint$2(to ||
|
|
1455
|
+
let {from: from, to: to, type: type, opacity: opacity} = paint;
|
|
1456
|
+
toPoint$2(from || "top", box, realFrom$2);
|
|
1457
|
+
toPoint$2(to || "bottom", box, realTo$2);
|
|
1427
1458
|
const style = core.Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
|
|
1428
|
-
const data = {
|
|
1459
|
+
const data = {
|
|
1460
|
+
type: type,
|
|
1461
|
+
style: style
|
|
1462
|
+
};
|
|
1429
1463
|
applyStops(data, style, paint.stops, opacity);
|
|
1430
1464
|
return data;
|
|
1431
1465
|
}
|
|
1466
|
+
|
|
1432
1467
|
function applyStops(data, gradient, stops, opacity) {
|
|
1433
1468
|
if (stops) {
|
|
1434
1469
|
let stop, color, offset, isTransparent;
|
|
1435
1470
|
for (let i = 0, len = stops.length; i < len; i++) {
|
|
1436
1471
|
stop = stops[i];
|
|
1437
|
-
if (
|
|
1438
|
-
|
|
1439
|
-
else
|
|
1440
|
-
offset = stop.offset, color = draw.ColorConvert.string(stop.color, opacity);
|
|
1472
|
+
if (core.isString(stop)) offset = i / (len - 1), color = draw.ColorConvert.string(stop, opacity); else offset = stop.offset,
|
|
1473
|
+
color = draw.ColorConvert.string(stop.color, opacity);
|
|
1441
1474
|
gradient.addColorStop(offset, color);
|
|
1442
|
-
if (!isTransparent && hasTransparent(color))
|
|
1443
|
-
isTransparent = true;
|
|
1475
|
+
if (!isTransparent && hasTransparent(color)) isTransparent = true;
|
|
1444
1476
|
}
|
|
1445
|
-
if (isTransparent)
|
|
1446
|
-
data.isTransparent = true;
|
|
1477
|
+
if (isTransparent) data.isTransparent = true;
|
|
1447
1478
|
}
|
|
1448
1479
|
}
|
|
1449
1480
|
|
|
1450
|
-
const { getAngle, getDistance: getDistance$1
|
|
1451
|
-
|
|
1452
|
-
const {
|
|
1481
|
+
const {getAngle: getAngle, getDistance: getDistance$1} = core.PointHelper;
|
|
1482
|
+
|
|
1483
|
+
const {get: get, rotateOfOuter: rotateOfOuter, scaleOfOuter: scaleOfOuter} = core.MatrixHelper;
|
|
1484
|
+
|
|
1485
|
+
const {toPoint: toPoint$1} = core.AroundHelper;
|
|
1486
|
+
|
|
1453
1487
|
const realFrom$1 = {};
|
|
1488
|
+
|
|
1454
1489
|
const realTo$1 = {};
|
|
1490
|
+
|
|
1455
1491
|
function radialGradient(paint, box) {
|
|
1456
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1457
|
-
toPoint$1(from ||
|
|
1458
|
-
toPoint$1(to ||
|
|
1492
|
+
let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
|
|
1493
|
+
toPoint$1(from || "center", box, realFrom$1);
|
|
1494
|
+
toPoint$1(to || "bottom", box, realTo$1);
|
|
1459
1495
|
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 = {
|
|
1496
|
+
const data = {
|
|
1497
|
+
type: type,
|
|
1498
|
+
style: style
|
|
1499
|
+
};
|
|
1461
1500
|
applyStops(data, style, paint.stops, opacity);
|
|
1462
1501
|
const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
|
|
1463
|
-
if (transform)
|
|
1464
|
-
data.transform = transform;
|
|
1502
|
+
if (transform) data.transform = transform;
|
|
1465
1503
|
return data;
|
|
1466
1504
|
}
|
|
1505
|
+
|
|
1467
1506
|
function getTransform(box, from, to, stretch, rotate90) {
|
|
1468
1507
|
let transform;
|
|
1469
|
-
const { width, height } = box;
|
|
1508
|
+
const {width: width, height: height} = box;
|
|
1470
1509
|
if (width !== height || stretch) {
|
|
1471
1510
|
const angle = getAngle(from, to);
|
|
1472
1511
|
transform = get();
|
|
1473
1512
|
if (rotate90) {
|
|
1474
1513
|
scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
|
|
1475
1514
|
rotateOfOuter(transform, from, angle + 90);
|
|
1476
|
-
}
|
|
1477
|
-
else {
|
|
1515
|
+
} else {
|
|
1478
1516
|
scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
|
|
1479
1517
|
rotateOfOuter(transform, from, angle);
|
|
1480
1518
|
}
|
|
@@ -1482,81 +1520,94 @@ function getTransform(box, from, to, stretch, rotate90) {
|
|
|
1482
1520
|
return transform;
|
|
1483
1521
|
}
|
|
1484
1522
|
|
|
1485
|
-
const { getDistance
|
|
1486
|
-
|
|
1523
|
+
const {getDistance: getDistance} = core.PointHelper;
|
|
1524
|
+
|
|
1525
|
+
const {toPoint: toPoint} = core.AroundHelper;
|
|
1526
|
+
|
|
1487
1527
|
const realFrom = {};
|
|
1528
|
+
|
|
1488
1529
|
const realTo = {};
|
|
1530
|
+
|
|
1489
1531
|
function conicGradient(paint, box) {
|
|
1490
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1491
|
-
toPoint(from ||
|
|
1492
|
-
toPoint(to ||
|
|
1532
|
+
let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
|
|
1533
|
+
toPoint(from || "center", box, realFrom);
|
|
1534
|
+
toPoint(to || "bottom", box, realTo);
|
|
1493
1535
|
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 = {
|
|
1536
|
+
const data = {
|
|
1537
|
+
type: type,
|
|
1538
|
+
style: style
|
|
1539
|
+
};
|
|
1495
1540
|
applyStops(data, style, paint.stops, opacity);
|
|
1496
1541
|
const transform = getTransform(box, realFrom, realTo, stretch || 1, core.Platform.conicGradientRotate90);
|
|
1497
|
-
if (transform)
|
|
1498
|
-
data.transform = transform;
|
|
1542
|
+
if (transform) data.transform = transform;
|
|
1499
1543
|
return data;
|
|
1500
1544
|
}
|
|
1501
1545
|
|
|
1502
1546
|
const PaintGradientModule = {
|
|
1503
|
-
linearGradient,
|
|
1504
|
-
radialGradient,
|
|
1505
|
-
conicGradient,
|
|
1506
|
-
getTransform
|
|
1547
|
+
linearGradient: linearGradient,
|
|
1548
|
+
radialGradient: radialGradient,
|
|
1549
|
+
conicGradient: conicGradient,
|
|
1550
|
+
getTransform: getTransform
|
|
1507
1551
|
};
|
|
1508
1552
|
|
|
1509
|
-
const { copy, toOffsetOutBounds: toOffsetOutBounds$1
|
|
1553
|
+
const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = core.BoundsHelper;
|
|
1554
|
+
|
|
1510
1555
|
const tempBounds = {};
|
|
1556
|
+
|
|
1511
1557
|
const offsetOutBounds$1 = {};
|
|
1558
|
+
|
|
1512
1559
|
function shadow(ui, current, shape) {
|
|
1513
1560
|
let copyBounds, spreadScale;
|
|
1514
|
-
const {
|
|
1515
|
-
const { shadow
|
|
1516
|
-
const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
|
|
1561
|
+
const {__nowWorld: nowWorld, __layout: __layout} = ui;
|
|
1562
|
+
const {shadow: shadow} = ui.__;
|
|
1563
|
+
const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
|
|
1517
1564
|
const other = current.getSameCanvas();
|
|
1518
1565
|
const end = shadow.length - 1;
|
|
1519
1566
|
toOffsetOutBounds$1(bounds, offsetOutBounds$1);
|
|
1520
1567
|
shadow.forEach((item, index) => {
|
|
1521
|
-
|
|
1522
|
-
|
|
1568
|
+
let otherScale = 1;
|
|
1569
|
+
if (item.scaleFixed) {
|
|
1570
|
+
const sx = Math.abs(nowWorld.scaleX);
|
|
1571
|
+
if (sx > 1) otherScale = 1 / sx;
|
|
1572
|
+
}
|
|
1573
|
+
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));
|
|
1574
|
+
spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
|
|
1523
1575
|
drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
|
|
1524
1576
|
copyBounds = bounds;
|
|
1525
1577
|
if (item.box) {
|
|
1526
1578
|
other.restore();
|
|
1527
1579
|
other.save();
|
|
1528
1580
|
if (worldCanvas) {
|
|
1529
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
1581
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
1530
1582
|
copyBounds = nowWorld;
|
|
1531
1583
|
}
|
|
1532
|
-
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
1584
|
+
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
|
|
1533
1585
|
}
|
|
1534
1586
|
core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1535
|
-
if (end && index < end)
|
|
1536
|
-
other.clearWorld(copyBounds, true);
|
|
1587
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
1537
1588
|
});
|
|
1538
1589
|
other.recycle(copyBounds);
|
|
1539
1590
|
}
|
|
1591
|
+
|
|
1540
1592
|
function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
1541
|
-
const { bounds, shapeBounds } = shape;
|
|
1593
|
+
const {bounds: bounds, shapeBounds: shapeBounds} = shape;
|
|
1542
1594
|
if (core.Platform.fullImageShadow) {
|
|
1543
1595
|
copy(tempBounds, canvas.bounds);
|
|
1544
|
-
tempBounds.x +=
|
|
1545
|
-
tempBounds.y +=
|
|
1596
|
+
tempBounds.x += outBounds.x - shapeBounds.x;
|
|
1597
|
+
tempBounds.y += outBounds.y - shapeBounds.y;
|
|
1546
1598
|
if (spreadScale) {
|
|
1547
|
-
const {
|
|
1548
|
-
tempBounds.x -= (bounds.x + (
|
|
1549
|
-
tempBounds.y -= (bounds.y + (
|
|
1599
|
+
const {fitMatrix: fitMatrix} = shape;
|
|
1600
|
+
tempBounds.x -= (bounds.x + (fitMatrix ? fitMatrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
|
|
1601
|
+
tempBounds.y -= (bounds.y + (fitMatrix ? fitMatrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
|
|
1550
1602
|
tempBounds.width *= spreadScale;
|
|
1551
1603
|
tempBounds.height *= spreadScale;
|
|
1552
1604
|
}
|
|
1553
1605
|
canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
|
|
1554
|
-
}
|
|
1555
|
-
else {
|
|
1606
|
+
} else {
|
|
1556
1607
|
if (spreadScale) {
|
|
1557
1608
|
copy(tempBounds, outBounds);
|
|
1558
|
-
tempBounds.x -=
|
|
1559
|
-
tempBounds.y -=
|
|
1609
|
+
tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
|
|
1610
|
+
tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
|
|
1560
1611
|
tempBounds.width *= spreadScale;
|
|
1561
1612
|
tempBounds.height *= spreadScale;
|
|
1562
1613
|
}
|
|
@@ -1564,174 +1615,184 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
|
1564
1615
|
}
|
|
1565
1616
|
}
|
|
1566
1617
|
|
|
1567
|
-
const { toOffsetOutBounds
|
|
1618
|
+
const {toOffsetOutBounds: toOffsetOutBounds} = core.BoundsHelper;
|
|
1619
|
+
|
|
1568
1620
|
const offsetOutBounds = {};
|
|
1621
|
+
|
|
1569
1622
|
function innerShadow(ui, current, shape) {
|
|
1570
1623
|
let copyBounds, spreadScale;
|
|
1571
|
-
const {
|
|
1572
|
-
const { innerShadow
|
|
1573
|
-
const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
|
|
1624
|
+
const {__nowWorld: nowWorld, __layout: __layout} = ui;
|
|
1625
|
+
const {innerShadow: innerShadow} = ui.__;
|
|
1626
|
+
const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
|
|
1574
1627
|
const other = current.getSameCanvas();
|
|
1575
1628
|
const end = innerShadow.length - 1;
|
|
1576
1629
|
toOffsetOutBounds(bounds, offsetOutBounds);
|
|
1577
1630
|
innerShadow.forEach((item, index) => {
|
|
1631
|
+
let otherScale = 1;
|
|
1632
|
+
if (item.scaleFixed) {
|
|
1633
|
+
const sx = Math.abs(nowWorld.scaleX);
|
|
1634
|
+
if (sx > 1) otherScale = 1 / sx;
|
|
1635
|
+
}
|
|
1578
1636
|
other.save();
|
|
1579
|
-
other.setWorldShadow(
|
|
1580
|
-
spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) : 0;
|
|
1637
|
+
other.setWorldShadow(offsetOutBounds.offsetX + item.x * scaleX * otherScale, offsetOutBounds.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale);
|
|
1638
|
+
spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
|
|
1581
1639
|
drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
|
|
1582
1640
|
other.restore();
|
|
1583
1641
|
if (worldCanvas) {
|
|
1584
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
1585
|
-
other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
1642
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
1643
|
+
other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
|
|
1586
1644
|
copyBounds = nowWorld;
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out');
|
|
1645
|
+
} else {
|
|
1646
|
+
other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
|
|
1590
1647
|
copyBounds = bounds;
|
|
1591
1648
|
}
|
|
1592
|
-
other.fillWorld(copyBounds, draw.ColorConvert.string(item.color),
|
|
1649
|
+
other.fillWorld(copyBounds, draw.ColorConvert.string(item.color), "source-in");
|
|
1593
1650
|
core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1594
|
-
if (end && index < end)
|
|
1595
|
-
other.clearWorld(copyBounds, true);
|
|
1651
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
1596
1652
|
});
|
|
1597
1653
|
other.recycle(copyBounds);
|
|
1598
1654
|
}
|
|
1599
1655
|
|
|
1600
1656
|
function blur(ui, current, origin) {
|
|
1601
|
-
const { blur
|
|
1657
|
+
const {blur: blur} = ui.__;
|
|
1602
1658
|
origin.setWorldBlur(blur * ui.__nowWorld.a);
|
|
1603
1659
|
origin.copyWorldToInner(current, ui.__nowWorld, ui.__layout.renderBounds);
|
|
1604
|
-
origin.filter =
|
|
1660
|
+
origin.filter = "none";
|
|
1605
1661
|
}
|
|
1606
1662
|
|
|
1607
|
-
function backgroundBlur(_ui, _current, _shape) {
|
|
1608
|
-
}
|
|
1663
|
+
function backgroundBlur(_ui, _current, _shape) {}
|
|
1609
1664
|
|
|
1610
1665
|
const EffectModule = {
|
|
1611
|
-
shadow,
|
|
1612
|
-
innerShadow,
|
|
1613
|
-
blur,
|
|
1614
|
-
backgroundBlur
|
|
1666
|
+
shadow: shadow,
|
|
1667
|
+
innerShadow: innerShadow,
|
|
1668
|
+
blur: blur,
|
|
1669
|
+
backgroundBlur: backgroundBlur
|
|
1615
1670
|
};
|
|
1616
1671
|
|
|
1617
|
-
const { excludeRenderBounds
|
|
1618
|
-
|
|
1672
|
+
const {excludeRenderBounds: excludeRenderBounds} = core.LeafBoundsHelper;
|
|
1673
|
+
|
|
1674
|
+
let usedGrayscaleAlpha;
|
|
1675
|
+
|
|
1676
|
+
draw.Group.prototype.__renderMask = function(canvas, options) {
|
|
1619
1677
|
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
1620
|
-
const { children
|
|
1678
|
+
const {children: children} = this;
|
|
1621
1679
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
1622
1680
|
child = children[i], mask = child.__.mask;
|
|
1623
1681
|
if (mask) {
|
|
1624
1682
|
if (currentMask) {
|
|
1625
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1683
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
1626
1684
|
maskCanvas = contentCanvas = null;
|
|
1627
1685
|
}
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
currentMask = 'path';
|
|
1686
|
+
maskOpacity = child.__.opacity;
|
|
1687
|
+
usedGrayscaleAlpha = false;
|
|
1688
|
+
if (mask === "path" || mask === "clipping-path") {
|
|
1689
|
+
if (maskOpacity < 1) {
|
|
1690
|
+
currentMask = "opacity-path";
|
|
1691
|
+
if (!contentCanvas) contentCanvas = getCanvas(canvas);
|
|
1692
|
+
} else {
|
|
1693
|
+
currentMask = "path";
|
|
1637
1694
|
canvas.save();
|
|
1638
1695
|
}
|
|
1639
1696
|
child.__clip(contentCanvas || canvas, options);
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
if (!
|
|
1644
|
-
maskCanvas = getCanvas(canvas);
|
|
1645
|
-
if (!contentCanvas)
|
|
1646
|
-
contentCanvas = getCanvas(canvas);
|
|
1697
|
+
} else {
|
|
1698
|
+
currentMask = mask === "grayscale" ? "grayscale" : "alpha";
|
|
1699
|
+
if (!maskCanvas) maskCanvas = getCanvas(canvas);
|
|
1700
|
+
if (!contentCanvas) contentCanvas = getCanvas(canvas);
|
|
1647
1701
|
child.__render(maskCanvas, options);
|
|
1648
1702
|
}
|
|
1649
|
-
if (mask ===
|
|
1650
|
-
excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
1703
|
+
if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
1651
1704
|
continue;
|
|
1652
1705
|
}
|
|
1706
|
+
const childBlendMode = maskOpacity === 1 && child.__.__blendMode;
|
|
1707
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, false);
|
|
1653
1708
|
excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
|
|
1709
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, childBlendMode, false);
|
|
1654
1710
|
}
|
|
1655
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1711
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
1656
1712
|
};
|
|
1657
|
-
|
|
1713
|
+
|
|
1714
|
+
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity, blendMode, recycle) {
|
|
1658
1715
|
switch (maskMode) {
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1716
|
+
case "grayscale":
|
|
1717
|
+
if (!usedGrayscaleAlpha) usedGrayscaleAlpha = true, maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
|
|
1718
|
+
|
|
1719
|
+
case "alpha":
|
|
1720
|
+
usePixelMask(leaf, canvas, contentCanvas, maskCanvas, blendMode, recycle);
|
|
1721
|
+
break;
|
|
1722
|
+
|
|
1723
|
+
case "opacity-path":
|
|
1724
|
+
copyContent(leaf, canvas, contentCanvas, maskOpacity, blendMode, recycle);
|
|
1725
|
+
break;
|
|
1726
|
+
|
|
1727
|
+
case "path":
|
|
1728
|
+
if (recycle) canvas.restore();
|
|
1669
1729
|
}
|
|
1670
1730
|
}
|
|
1731
|
+
|
|
1671
1732
|
function getCanvas(canvas) {
|
|
1672
1733
|
return canvas.getSameCanvas(false, true);
|
|
1673
1734
|
}
|
|
1674
|
-
|
|
1735
|
+
|
|
1736
|
+
function usePixelMask(leaf, canvas, content, mask, blendMode, recycle) {
|
|
1675
1737
|
const realBounds = leaf.__nowWorld;
|
|
1676
1738
|
content.resetTransform();
|
|
1677
1739
|
content.opacity = 1;
|
|
1678
1740
|
content.useMask(mask, realBounds);
|
|
1679
|
-
mask.recycle(realBounds);
|
|
1680
|
-
copyContent(leaf, canvas, content, 1);
|
|
1741
|
+
if (recycle) mask.recycle(realBounds);
|
|
1742
|
+
copyContent(leaf, canvas, content, 1, blendMode, recycle);
|
|
1681
1743
|
}
|
|
1682
|
-
|
|
1744
|
+
|
|
1745
|
+
function copyContent(leaf, canvas, content, maskOpacity, blendMode, recycle) {
|
|
1683
1746
|
const realBounds = leaf.__nowWorld;
|
|
1684
1747
|
canvas.resetTransform();
|
|
1685
1748
|
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('|'));
|
|
1749
|
+
canvas.copyWorld(content, realBounds, undefined, blendMode);
|
|
1750
|
+
recycle ? content.recycle(realBounds) : content.clearWorld(realBounds, true);
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
const money = "¥¥$€££¢¢";
|
|
1754
|
+
|
|
1755
|
+
const letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
|
|
1756
|
+
|
|
1757
|
+
const langBefore = "《(「〈『〖【〔{┌<‘“=" + money;
|
|
1758
|
+
|
|
1759
|
+
const langAfter = "》)」〉』〗】〕}┐>’”!?,、。:;‰";
|
|
1760
|
+
|
|
1761
|
+
const langSymbol = "≮≯≈≠=…";
|
|
1762
|
+
|
|
1763
|
+
const langBreak$1 = "—/~|┆·";
|
|
1764
|
+
|
|
1765
|
+
const beforeChar = "{[(<'\"" + langBefore;
|
|
1766
|
+
|
|
1767
|
+
const afterChar = ">)]}%!?,.:;'\"" + langAfter;
|
|
1768
|
+
|
|
1769
|
+
const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
|
|
1770
|
+
|
|
1771
|
+
const breakChar = "- " + langBreak$1;
|
|
1772
|
+
|
|
1773
|
+
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 ] ];
|
|
1774
|
+
|
|
1775
|
+
const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
|
|
1776
|
+
|
|
1723
1777
|
function mapChar(str) {
|
|
1724
1778
|
const map = {};
|
|
1725
|
-
str.split(
|
|
1779
|
+
str.split("").forEach(char => map[char] = true);
|
|
1726
1780
|
return map;
|
|
1727
1781
|
}
|
|
1782
|
+
|
|
1728
1783
|
const letterMap = mapChar(letter);
|
|
1784
|
+
|
|
1729
1785
|
const beforeMap = mapChar(beforeChar);
|
|
1786
|
+
|
|
1730
1787
|
const afterMap = mapChar(afterChar);
|
|
1788
|
+
|
|
1731
1789
|
const symbolMap = mapChar(symbolChar);
|
|
1790
|
+
|
|
1732
1791
|
const breakMap = mapChar(breakChar);
|
|
1792
|
+
|
|
1733
1793
|
var CharType;
|
|
1734
|
-
|
|
1794
|
+
|
|
1795
|
+
(function(CharType) {
|
|
1735
1796
|
CharType[CharType["Letter"] = 0] = "Letter";
|
|
1736
1797
|
CharType[CharType["Single"] = 1] = "Single";
|
|
1737
1798
|
CharType[CharType["Before"] = 2] = "Before";
|
|
@@ -1739,179 +1800,175 @@ var CharType;
|
|
|
1739
1800
|
CharType[CharType["Symbol"] = 4] = "Symbol";
|
|
1740
1801
|
CharType[CharType["Break"] = 5] = "Break";
|
|
1741
1802
|
})(CharType || (CharType = {}));
|
|
1742
|
-
|
|
1803
|
+
|
|
1804
|
+
const {Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1} = CharType;
|
|
1805
|
+
|
|
1743
1806
|
function getCharType(char) {
|
|
1744
1807
|
if (letterMap[char]) {
|
|
1745
1808
|
return Letter$1;
|
|
1746
|
-
}
|
|
1747
|
-
else if (breakMap[char]) {
|
|
1809
|
+
} else if (breakMap[char]) {
|
|
1748
1810
|
return Break$1;
|
|
1749
|
-
}
|
|
1750
|
-
else if (beforeMap[char]) {
|
|
1811
|
+
} else if (beforeMap[char]) {
|
|
1751
1812
|
return Before$1;
|
|
1752
|
-
}
|
|
1753
|
-
else if (afterMap[char]) {
|
|
1813
|
+
} else if (afterMap[char]) {
|
|
1754
1814
|
return After$1;
|
|
1755
|
-
}
|
|
1756
|
-
else if (symbolMap[char]) {
|
|
1815
|
+
} else if (symbolMap[char]) {
|
|
1757
1816
|
return Symbol$1;
|
|
1758
|
-
}
|
|
1759
|
-
else if (cjkReg.test(char)) {
|
|
1817
|
+
} else if (cjkReg.test(char)) {
|
|
1760
1818
|
return Single$1;
|
|
1761
|
-
}
|
|
1762
|
-
else {
|
|
1819
|
+
} else {
|
|
1763
1820
|
return Letter$1;
|
|
1764
1821
|
}
|
|
1765
1822
|
}
|
|
1766
1823
|
|
|
1767
1824
|
const TextRowHelper = {
|
|
1768
1825
|
trimRight(row) {
|
|
1769
|
-
const { words
|
|
1826
|
+
const {words: words} = row;
|
|
1770
1827
|
let trimRight = 0, len = words.length, char;
|
|
1771
1828
|
for (let i = len - 1; i > -1; i--) {
|
|
1772
1829
|
char = words[i].data[0];
|
|
1773
|
-
if (char.char ===
|
|
1830
|
+
if (char.char === " ") {
|
|
1774
1831
|
trimRight++;
|
|
1775
1832
|
row.width -= char.width;
|
|
1776
|
-
}
|
|
1777
|
-
else {
|
|
1833
|
+
} else {
|
|
1778
1834
|
break;
|
|
1779
1835
|
}
|
|
1780
1836
|
}
|
|
1781
|
-
if (trimRight)
|
|
1782
|
-
words.splice(len - trimRight, trimRight);
|
|
1837
|
+
if (trimRight) words.splice(len - trimRight, trimRight);
|
|
1783
1838
|
}
|
|
1784
1839
|
};
|
|
1785
1840
|
|
|
1786
1841
|
function getTextCase(char, textCase, firstChar) {
|
|
1787
1842
|
switch (textCase) {
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1843
|
+
case "title":
|
|
1844
|
+
return firstChar ? char.toUpperCase() : char;
|
|
1845
|
+
|
|
1846
|
+
case "upper":
|
|
1847
|
+
return char.toUpperCase();
|
|
1848
|
+
|
|
1849
|
+
case "lower":
|
|
1850
|
+
return char.toLowerCase();
|
|
1851
|
+
|
|
1852
|
+
default:
|
|
1853
|
+
return char;
|
|
1796
1854
|
}
|
|
1797
1855
|
}
|
|
1798
1856
|
|
|
1799
|
-
const { trimRight
|
|
1800
|
-
|
|
1857
|
+
const {trimRight: trimRight} = TextRowHelper;
|
|
1858
|
+
|
|
1859
|
+
const {Letter: Letter, Single: Single, Before: Before, After: After, Symbol: Symbol, Break: Break} = CharType;
|
|
1860
|
+
|
|
1801
1861
|
let word, row, wordWidth, rowWidth, realWidth;
|
|
1862
|
+
|
|
1802
1863
|
let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
|
|
1864
|
+
|
|
1803
1865
|
let textDrawData, rows = [], bounds, findMaxWidth;
|
|
1866
|
+
|
|
1804
1867
|
function createRows(drawData, content, style) {
|
|
1805
1868
|
textDrawData = drawData;
|
|
1806
1869
|
rows = drawData.rows;
|
|
1807
1870
|
bounds = drawData.bounds;
|
|
1808
1871
|
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 ||
|
|
1872
|
+
const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
|
|
1873
|
+
const {canvas: canvas} = core.Platform;
|
|
1874
|
+
const {width: width, height: height} = bounds;
|
|
1875
|
+
const charMode = width || height || __letterSpacing || textCase !== "none";
|
|
1813
1876
|
if (charMode) {
|
|
1814
|
-
const wrap = style.textWrap !==
|
|
1815
|
-
const breakAll = style.textWrap ===
|
|
1877
|
+
const wrap = style.textWrap !== "none";
|
|
1878
|
+
const breakAll = style.textWrap === "break";
|
|
1816
1879
|
paraStart = true;
|
|
1817
1880
|
lastCharType = null;
|
|
1818
1881
|
startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
|
|
1819
|
-
word = {
|
|
1820
|
-
|
|
1821
|
-
|
|
1882
|
+
word = {
|
|
1883
|
+
data: []
|
|
1884
|
+
}, row = {
|
|
1885
|
+
words: []
|
|
1886
|
+
};
|
|
1887
|
+
if (__letterSpacing) content = [ ...content ];
|
|
1822
1888
|
for (let i = 0, len = content.length; i < len; i++) {
|
|
1823
1889
|
char = content[i];
|
|
1824
|
-
if (char ===
|
|
1825
|
-
if (wordWidth)
|
|
1826
|
-
addWord();
|
|
1890
|
+
if (char === "\n") {
|
|
1891
|
+
if (wordWidth) addWord();
|
|
1827
1892
|
row.paraEnd = true;
|
|
1828
1893
|
addRow();
|
|
1829
1894
|
paraStart = true;
|
|
1830
|
-
}
|
|
1831
|
-
else {
|
|
1895
|
+
} else {
|
|
1832
1896
|
charType = getCharType(char);
|
|
1833
|
-
if (charType === Letter && textCase !==
|
|
1834
|
-
char = getTextCase(char, textCase, !wordWidth);
|
|
1897
|
+
if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
|
|
1835
1898
|
charWidth = canvas.measureText(char).width;
|
|
1836
1899
|
if (__letterSpacing) {
|
|
1837
|
-
if (__letterSpacing < 0)
|
|
1838
|
-
charSize = charWidth;
|
|
1900
|
+
if (__letterSpacing < 0) charSize = charWidth;
|
|
1839
1901
|
charWidth += __letterSpacing;
|
|
1840
1902
|
}
|
|
1841
|
-
langBreak =
|
|
1842
|
-
afterBreak = (
|
|
1903
|
+
langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
|
|
1904
|
+
afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
|
|
1843
1905
|
realWidth = paraStart && paraIndent ? width - paraIndent : width;
|
|
1844
1906
|
if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
|
|
1845
1907
|
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();
|
|
1908
|
+
if (wordWidth) addWord();
|
|
1909
|
+
if (rowWidth) addRow();
|
|
1910
|
+
} else {
|
|
1911
|
+
if (!afterBreak) afterBreak = charType === Letter && lastCharType == After;
|
|
1912
|
+
if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || wordWidth + charWidth > realWidth) {
|
|
1913
|
+
if (wordWidth) addWord();
|
|
1914
|
+
if (rowWidth) addRow();
|
|
1915
|
+
} else {
|
|
1916
|
+
if (rowWidth) addRow();
|
|
1863
1917
|
}
|
|
1864
1918
|
}
|
|
1865
1919
|
}
|
|
1866
|
-
if (char ===
|
|
1867
|
-
else {
|
|
1920
|
+
if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
|
|
1868
1921
|
if (charType === Break) {
|
|
1869
|
-
if (char ===
|
|
1870
|
-
addWord();
|
|
1922
|
+
if (char === " " && wordWidth) addWord();
|
|
1871
1923
|
addChar(char, charWidth);
|
|
1872
1924
|
addWord();
|
|
1873
|
-
}
|
|
1874
|
-
|
|
1875
|
-
if (wordWidth)
|
|
1876
|
-
addWord();
|
|
1925
|
+
} else if (langBreak || afterBreak) {
|
|
1926
|
+
if (wordWidth) addWord();
|
|
1877
1927
|
addChar(char, charWidth);
|
|
1878
|
-
}
|
|
1879
|
-
else {
|
|
1928
|
+
} else {
|
|
1880
1929
|
addChar(char, charWidth);
|
|
1881
1930
|
}
|
|
1882
1931
|
}
|
|
1883
1932
|
lastCharType = charType;
|
|
1884
1933
|
}
|
|
1885
1934
|
}
|
|
1886
|
-
if (wordWidth)
|
|
1887
|
-
|
|
1888
|
-
if (rowWidth)
|
|
1889
|
-
addRow();
|
|
1935
|
+
if (wordWidth) addWord();
|
|
1936
|
+
if (rowWidth) addRow();
|
|
1890
1937
|
rows.length > 0 && (rows[rows.length - 1].paraEnd = true);
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
|
-
content.split('\n').forEach(content => {
|
|
1938
|
+
} else {
|
|
1939
|
+
content.split("\n").forEach(content => {
|
|
1894
1940
|
textDrawData.paraNumber++;
|
|
1895
1941
|
rowWidth = canvas.measureText(content).width;
|
|
1896
|
-
rows.push({
|
|
1897
|
-
|
|
1898
|
-
|
|
1942
|
+
rows.push({
|
|
1943
|
+
x: paraIndent || 0,
|
|
1944
|
+
text: content,
|
|
1945
|
+
width: rowWidth,
|
|
1946
|
+
paraStart: true
|
|
1947
|
+
});
|
|
1948
|
+
if (findMaxWidth) setMaxWidth();
|
|
1899
1949
|
});
|
|
1900
1950
|
}
|
|
1901
1951
|
}
|
|
1952
|
+
|
|
1902
1953
|
function addChar(char, width) {
|
|
1903
|
-
if (charSize && !startCharSize)
|
|
1904
|
-
|
|
1905
|
-
|
|
1954
|
+
if (charSize && !startCharSize) startCharSize = charSize;
|
|
1955
|
+
word.data.push({
|
|
1956
|
+
char: char,
|
|
1957
|
+
width: width
|
|
1958
|
+
});
|
|
1906
1959
|
wordWidth += width;
|
|
1907
1960
|
}
|
|
1961
|
+
|
|
1908
1962
|
function addWord() {
|
|
1909
1963
|
rowWidth += wordWidth;
|
|
1910
1964
|
word.width = wordWidth;
|
|
1911
1965
|
row.words.push(word);
|
|
1912
|
-
word = {
|
|
1966
|
+
word = {
|
|
1967
|
+
data: []
|
|
1968
|
+
};
|
|
1913
1969
|
wordWidth = 0;
|
|
1914
1970
|
}
|
|
1971
|
+
|
|
1915
1972
|
function addRow() {
|
|
1916
1973
|
if (paraStart) {
|
|
1917
1974
|
textDrawData.paraNumber++;
|
|
@@ -1924,52 +1981,53 @@ function addRow() {
|
|
|
1924
1981
|
startCharSize = 0;
|
|
1925
1982
|
}
|
|
1926
1983
|
row.width = rowWidth;
|
|
1927
|
-
if (bounds.width)
|
|
1928
|
-
trimRight(row);
|
|
1929
|
-
else if (findMaxWidth)
|
|
1930
|
-
setMaxWidth();
|
|
1984
|
+
if (bounds.width) trimRight(row); else if (findMaxWidth) setMaxWidth();
|
|
1931
1985
|
rows.push(row);
|
|
1932
|
-
row = {
|
|
1986
|
+
row = {
|
|
1987
|
+
words: []
|
|
1988
|
+
};
|
|
1933
1989
|
rowWidth = 0;
|
|
1934
1990
|
}
|
|
1991
|
+
|
|
1935
1992
|
function setMaxWidth() {
|
|
1936
|
-
if (rowWidth > (textDrawData.maxWidth || 0))
|
|
1937
|
-
textDrawData.maxWidth = rowWidth;
|
|
1993
|
+
if (rowWidth > (textDrawData.maxWidth || 0)) textDrawData.maxWidth = rowWidth;
|
|
1938
1994
|
}
|
|
1939
1995
|
|
|
1940
1996
|
const CharMode = 0;
|
|
1997
|
+
|
|
1941
1998
|
const WordMode = 1;
|
|
1999
|
+
|
|
1942
2000
|
const TextMode = 2;
|
|
2001
|
+
|
|
1943
2002
|
function layoutChar(drawData, style, width, _height) {
|
|
1944
|
-
const { rows
|
|
1945
|
-
const { textAlign, paraIndent, letterSpacing } = style;
|
|
2003
|
+
const {rows: rows} = drawData;
|
|
2004
|
+
const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
|
|
1946
2005
|
let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
|
|
1947
2006
|
rows.forEach(row => {
|
|
1948
2007
|
if (row.words) {
|
|
1949
2008
|
indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
|
|
1950
|
-
addWordWidth =
|
|
1951
|
-
mode =
|
|
1952
|
-
if (row.isOverflow && !letterSpacing)
|
|
1953
|
-
row.textMode = true;
|
|
2009
|
+
addWordWidth = width && (textAlign === "justify" || textAlign === "both") && wordsLength > 1 ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
|
|
2010
|
+
mode = letterSpacing || row.isOverflow ? CharMode : addWordWidth > .01 ? WordMode : TextMode;
|
|
2011
|
+
if (row.isOverflow && !letterSpacing) row.textMode = true;
|
|
1954
2012
|
if (mode === TextMode) {
|
|
1955
2013
|
row.x += indentWidth;
|
|
1956
2014
|
toTextChar$1(row);
|
|
1957
|
-
}
|
|
1958
|
-
else {
|
|
2015
|
+
} else {
|
|
1959
2016
|
row.x += indentWidth;
|
|
1960
2017
|
charX = row.x;
|
|
1961
2018
|
row.data = [];
|
|
1962
2019
|
row.words.forEach((word, index) => {
|
|
1963
2020
|
if (mode === WordMode) {
|
|
1964
|
-
wordChar = {
|
|
2021
|
+
wordChar = {
|
|
2022
|
+
char: "",
|
|
2023
|
+
x: charX
|
|
2024
|
+
};
|
|
1965
2025
|
charX = toWordChar(word.data, charX, wordChar);
|
|
1966
|
-
if (row.isOverflow || wordChar.char !==
|
|
1967
|
-
|
|
1968
|
-
}
|
|
1969
|
-
else {
|
|
2026
|
+
if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
|
|
2027
|
+
} else {
|
|
1970
2028
|
charX = toChar(word.data, charX, row.data, row.isOverflow);
|
|
1971
2029
|
}
|
|
1972
|
-
if (addWordWidth && (!row.paraEnd || textAlign ===
|
|
2030
|
+
if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
|
|
1973
2031
|
charX += addWordWidth;
|
|
1974
2032
|
row.width += addWordWidth;
|
|
1975
2033
|
}
|
|
@@ -1979,14 +2037,16 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
1979
2037
|
}
|
|
1980
2038
|
});
|
|
1981
2039
|
}
|
|
2040
|
+
|
|
1982
2041
|
function toTextChar$1(row) {
|
|
1983
|
-
row.text =
|
|
2042
|
+
row.text = "";
|
|
1984
2043
|
row.words.forEach(word => {
|
|
1985
2044
|
word.data.forEach(char => {
|
|
1986
2045
|
row.text += char.char;
|
|
1987
2046
|
});
|
|
1988
2047
|
});
|
|
1989
2048
|
}
|
|
2049
|
+
|
|
1990
2050
|
function toWordChar(data, charX, wordChar) {
|
|
1991
2051
|
data.forEach(char => {
|
|
1992
2052
|
wordChar.char += char.char;
|
|
@@ -1994,9 +2054,10 @@ function toWordChar(data, charX, wordChar) {
|
|
|
1994
2054
|
});
|
|
1995
2055
|
return charX;
|
|
1996
2056
|
}
|
|
2057
|
+
|
|
1997
2058
|
function toChar(data, charX, rowData, isOverflow) {
|
|
1998
2059
|
data.forEach(char => {
|
|
1999
|
-
if (isOverflow || char.char !==
|
|
2060
|
+
if (isOverflow || char.char !== " ") {
|
|
2000
2061
|
char.x = charX;
|
|
2001
2062
|
rowData.push(char);
|
|
2002
2063
|
}
|
|
@@ -2006,38 +2067,39 @@ function toChar(data, charX, rowData, isOverflow) {
|
|
|
2006
2067
|
}
|
|
2007
2068
|
|
|
2008
2069
|
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);
|
|
2070
|
+
const {rows: rows, bounds: bounds} = drawData, countRows = rows.length;
|
|
2071
|
+
const {__lineHeight: __lineHeight, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __clipText: __clipText, textAlign: textAlign, verticalAlign: verticalAlign, paraSpacing: paraSpacing, autoSizeAlign: autoSizeAlign} = style;
|
|
2072
|
+
let {x: x, y: y, width: width, height: height} = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
|
|
2012
2073
|
let starY = __baseLine;
|
|
2013
2074
|
if (__clipText && realHeight > height) {
|
|
2014
2075
|
realHeight = Math.max(height, __lineHeight);
|
|
2015
|
-
if (countRows > 1)
|
|
2016
|
-
|
|
2017
|
-
}
|
|
2018
|
-
else if (height || autoSizeAlign) {
|
|
2076
|
+
if (countRows > 1) drawData.overflow = countRows;
|
|
2077
|
+
} else if (height || autoSizeAlign) {
|
|
2019
2078
|
switch (verticalAlign) {
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2079
|
+
case "middle":
|
|
2080
|
+
y += (height - realHeight) / 2;
|
|
2081
|
+
break;
|
|
2082
|
+
|
|
2083
|
+
case "bottom":
|
|
2084
|
+
y += height - realHeight;
|
|
2024
2085
|
}
|
|
2025
2086
|
}
|
|
2026
2087
|
starY += y;
|
|
2027
|
-
let row, rowX, rowWidth, layoutWidth =
|
|
2088
|
+
let row, rowX, rowWidth, layoutWidth = width || autoSizeAlign ? width : drawData.maxWidth;
|
|
2028
2089
|
for (let i = 0, len = countRows; i < len; i++) {
|
|
2029
2090
|
row = rows[i];
|
|
2030
2091
|
row.x = x;
|
|
2031
|
-
if (row.width < width ||
|
|
2092
|
+
if (row.width < width || row.width > width && !__clipText) {
|
|
2032
2093
|
switch (textAlign) {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2094
|
+
case "center":
|
|
2095
|
+
row.x += (layoutWidth - row.width) / 2;
|
|
2096
|
+
break;
|
|
2097
|
+
|
|
2098
|
+
case "right":
|
|
2099
|
+
row.x += layoutWidth - row.width;
|
|
2037
2100
|
}
|
|
2038
2101
|
}
|
|
2039
|
-
if (row.paraStart && paraSpacing && i > 0)
|
|
2040
|
-
starY += paraSpacing;
|
|
2102
|
+
if (row.paraStart && paraSpacing && i > 0) starY += paraSpacing;
|
|
2041
2103
|
row.y = starY;
|
|
2042
2104
|
starY += __lineHeight;
|
|
2043
2105
|
if (drawData.overflow > i && starY > realHeight) {
|
|
@@ -2051,19 +2113,15 @@ function layoutText(drawData, style) {
|
|
|
2051
2113
|
rowWidth = -row.width + style.fontSize + __letterSpacing;
|
|
2052
2114
|
rowX -= rowWidth;
|
|
2053
2115
|
rowWidth += style.fontSize;
|
|
2054
|
-
}
|
|
2055
|
-
else {
|
|
2116
|
+
} else {
|
|
2056
2117
|
rowWidth -= __letterSpacing;
|
|
2057
2118
|
}
|
|
2058
2119
|
}
|
|
2059
|
-
if (rowX < bounds.x)
|
|
2060
|
-
|
|
2061
|
-
if (rowWidth > bounds.width)
|
|
2062
|
-
bounds.width = rowWidth;
|
|
2120
|
+
if (rowX < bounds.x) bounds.x = rowX;
|
|
2121
|
+
if (rowWidth > bounds.width) bounds.width = rowWidth;
|
|
2063
2122
|
if (__clipText && width && width < rowWidth) {
|
|
2064
2123
|
row.isOverflow = true;
|
|
2065
|
-
if (!drawData.overflow)
|
|
2066
|
-
drawData.overflow = rows.length;
|
|
2124
|
+
if (!drawData.overflow) drawData.overflow = rows.length;
|
|
2067
2125
|
}
|
|
2068
2126
|
}
|
|
2069
2127
|
bounds.y = y;
|
|
@@ -2071,20 +2129,16 @@ function layoutText(drawData, style) {
|
|
|
2071
2129
|
}
|
|
2072
2130
|
|
|
2073
2131
|
function clipText(drawData, style, x, width) {
|
|
2074
|
-
if (!width)
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
let { textOverflow } = style;
|
|
2132
|
+
if (!width) return;
|
|
2133
|
+
const {rows: rows, overflow: overflow} = drawData;
|
|
2134
|
+
let {textOverflow: textOverflow} = style;
|
|
2078
2135
|
rows.splice(overflow);
|
|
2079
|
-
if (textOverflow && textOverflow !==
|
|
2080
|
-
if (textOverflow ===
|
|
2081
|
-
textOverflow = '';
|
|
2082
|
-
else if (textOverflow === 'ellipsis')
|
|
2083
|
-
textOverflow = '...';
|
|
2136
|
+
if (textOverflow && textOverflow !== "show") {
|
|
2137
|
+
if (textOverflow === "hide") textOverflow = ""; else if (textOverflow === "ellipsis") textOverflow = "...";
|
|
2084
2138
|
let char, charRight;
|
|
2085
2139
|
const ellipsisWidth = textOverflow ? core.Platform.canvas.measureText(textOverflow).width : 0;
|
|
2086
2140
|
const right = x + width - ellipsisWidth;
|
|
2087
|
-
const list = style.textWrap ===
|
|
2141
|
+
const list = style.textWrap === "none" ? rows : [ rows[overflow - 1] ];
|
|
2088
2142
|
list.forEach(row => {
|
|
2089
2143
|
if (row.isOverflow && row.data) {
|
|
2090
2144
|
let end = row.data.length - 1;
|
|
@@ -2093,8 +2147,7 @@ function clipText(drawData, style, x, width) {
|
|
|
2093
2147
|
charRight = char.x + char.width;
|
|
2094
2148
|
if (i === end && charRight < right) {
|
|
2095
2149
|
break;
|
|
2096
|
-
}
|
|
2097
|
-
else if ((charRight < right && char.char !== ' ') || !i) {
|
|
2150
|
+
} else if (charRight < right && char.char !== " " || !i) {
|
|
2098
2151
|
row.data.splice(i + 1);
|
|
2099
2152
|
row.width -= char.width;
|
|
2100
2153
|
break;
|
|
@@ -2102,15 +2155,18 @@ function clipText(drawData, style, x, width) {
|
|
|
2102
2155
|
row.width -= char.width;
|
|
2103
2156
|
}
|
|
2104
2157
|
row.width += ellipsisWidth;
|
|
2105
|
-
row.data.push({
|
|
2106
|
-
|
|
2107
|
-
|
|
2158
|
+
row.data.push({
|
|
2159
|
+
char: textOverflow,
|
|
2160
|
+
x: charRight
|
|
2161
|
+
});
|
|
2162
|
+
if (row.textMode) toTextChar(row);
|
|
2108
2163
|
}
|
|
2109
2164
|
});
|
|
2110
2165
|
}
|
|
2111
2166
|
}
|
|
2167
|
+
|
|
2112
2168
|
function toTextChar(row) {
|
|
2113
|
-
row.text =
|
|
2169
|
+
row.text = "";
|
|
2114
2170
|
row.data.forEach(char => {
|
|
2115
2171
|
row.text += char.char;
|
|
2116
2172
|
});
|
|
@@ -2119,121 +2175,123 @@ function toTextChar(row) {
|
|
|
2119
2175
|
|
|
2120
2176
|
function decorationText(drawData, style) {
|
|
2121
2177
|
let type;
|
|
2122
|
-
const { fontSize, textDecoration } = style;
|
|
2178
|
+
const {fontSize: fontSize, textDecoration: textDecoration} = style;
|
|
2123
2179
|
drawData.decorationHeight = fontSize / 11;
|
|
2124
|
-
if (
|
|
2180
|
+
if (core.isObject(textDecoration)) {
|
|
2125
2181
|
type = textDecoration.type;
|
|
2126
|
-
if (textDecoration.color)
|
|
2127
|
-
|
|
2128
|
-
}
|
|
2129
|
-
else
|
|
2130
|
-
type = textDecoration;
|
|
2182
|
+
if (textDecoration.color) drawData.decorationColor = draw.ColorConvert.string(textDecoration.color);
|
|
2183
|
+
} else type = textDecoration;
|
|
2131
2184
|
switch (type) {
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2185
|
+
case "under":
|
|
2186
|
+
drawData.decorationY = [ fontSize * .15 ];
|
|
2187
|
+
break;
|
|
2188
|
+
|
|
2189
|
+
case "delete":
|
|
2190
|
+
drawData.decorationY = [ -fontSize * .35 ];
|
|
2191
|
+
break;
|
|
2192
|
+
|
|
2193
|
+
case "under-delete":
|
|
2194
|
+
drawData.decorationY = [ fontSize * .15, -fontSize * .35 ];
|
|
2140
2195
|
}
|
|
2141
2196
|
}
|
|
2142
2197
|
|
|
2143
|
-
const { top, right, bottom, left } = core.Direction4;
|
|
2198
|
+
const {top: top, right: right, bottom: bottom, left: left} = core.Direction4;
|
|
2199
|
+
|
|
2144
2200
|
function getDrawData(content, style) {
|
|
2145
|
-
if (
|
|
2146
|
-
content = String(content);
|
|
2201
|
+
if (!core.isString(content)) content = String(content);
|
|
2147
2202
|
let x = 0, y = 0;
|
|
2148
|
-
let width = style.__getInput(
|
|
2149
|
-
let height = style.__getInput(
|
|
2150
|
-
const { textDecoration, __font, __padding: padding
|
|
2203
|
+
let width = style.__getInput("width") || 0;
|
|
2204
|
+
let height = style.__getInput("height") || 0;
|
|
2205
|
+
const {textDecoration: textDecoration, __font: __font, __padding: padding} = style;
|
|
2151
2206
|
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];
|
|
2207
|
+
if (width) x = padding[left], width -= padding[right] + padding[left]; else if (!style.autoSizeAlign) x = padding[left];
|
|
2208
|
+
if (height) y = padding[top], height -= padding[top] + padding[bottom]; else if (!style.autoSizeAlign) y = padding[top];
|
|
2160
2209
|
}
|
|
2161
2210
|
const drawData = {
|
|
2162
|
-
bounds: {
|
|
2211
|
+
bounds: {
|
|
2212
|
+
x: x,
|
|
2213
|
+
y: y,
|
|
2214
|
+
width: width,
|
|
2215
|
+
height: height
|
|
2216
|
+
},
|
|
2163
2217
|
rows: [],
|
|
2164
2218
|
paraNumber: 0,
|
|
2165
2219
|
font: core.Platform.canvas.font = __font
|
|
2166
2220
|
};
|
|
2167
2221
|
createRows(drawData, content, style);
|
|
2168
|
-
if (padding)
|
|
2169
|
-
padAutoText(padding, drawData, style, width, height);
|
|
2222
|
+
if (padding) padAutoText(padding, drawData, style, width, height);
|
|
2170
2223
|
layoutText(drawData, style);
|
|
2171
2224
|
layoutChar(drawData, style, width);
|
|
2172
|
-
if (drawData.overflow)
|
|
2173
|
-
|
|
2174
|
-
if (textDecoration !== 'none')
|
|
2175
|
-
decorationText(drawData, style);
|
|
2225
|
+
if (drawData.overflow) clipText(drawData, style, x, width);
|
|
2226
|
+
if (textDecoration !== "none") decorationText(drawData, style);
|
|
2176
2227
|
return drawData;
|
|
2177
2228
|
}
|
|
2229
|
+
|
|
2178
2230
|
function padAutoText(padding, drawData, style, width, height) {
|
|
2179
2231
|
if (!width && style.autoSizeAlign) {
|
|
2180
2232
|
switch (style.textAlign) {
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2233
|
+
case "left":
|
|
2234
|
+
offsetText(drawData, "x", padding[left]);
|
|
2235
|
+
break;
|
|
2236
|
+
|
|
2237
|
+
case "right":
|
|
2238
|
+
offsetText(drawData, "x", -padding[right]);
|
|
2185
2239
|
}
|
|
2186
2240
|
}
|
|
2187
2241
|
if (!height && style.autoSizeAlign) {
|
|
2188
2242
|
switch (style.verticalAlign) {
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2243
|
+
case "top":
|
|
2244
|
+
offsetText(drawData, "y", padding[top]);
|
|
2245
|
+
break;
|
|
2246
|
+
|
|
2247
|
+
case "bottom":
|
|
2248
|
+
offsetText(drawData, "y", -padding[bottom]);
|
|
2193
2249
|
}
|
|
2194
2250
|
}
|
|
2195
2251
|
}
|
|
2252
|
+
|
|
2196
2253
|
function offsetText(drawData, attrName, value) {
|
|
2197
|
-
const { bounds, rows } = drawData;
|
|
2254
|
+
const {bounds: bounds, rows: rows} = drawData;
|
|
2198
2255
|
bounds[attrName] += value;
|
|
2199
|
-
for (let i = 0; i < rows.length; i++)
|
|
2200
|
-
rows[i][attrName] += value;
|
|
2256
|
+
for (let i = 0; i < rows.length; i++) rows[i][attrName] += value;
|
|
2201
2257
|
}
|
|
2202
2258
|
|
|
2203
2259
|
const TextConvertModule = {
|
|
2204
|
-
getDrawData
|
|
2260
|
+
getDrawData: getDrawData
|
|
2205
2261
|
};
|
|
2206
2262
|
|
|
2207
2263
|
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;
|
|
2264
|
+
const doOpacity = core.isNumber(opacity) && opacity < 1;
|
|
2265
|
+
if (core.isString(color)) {
|
|
2266
|
+
if (doOpacity && draw.ColorConvert.object) color = draw.ColorConvert.object(color); else return color;
|
|
2214
2267
|
}
|
|
2215
|
-
let a = color.a
|
|
2216
|
-
if (doOpacity)
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
|
|
2268
|
+
let a = core.isUndefined(color.a) ? 1 : color.a;
|
|
2269
|
+
if (doOpacity) a *= opacity;
|
|
2270
|
+
const rgb = color.r + "," + color.g + "," + color.b;
|
|
2271
|
+
return a === 1 ? "rgb(" + rgb + ")" : "rgba(" + rgb + "," + a + ")";
|
|
2220
2272
|
}
|
|
2221
2273
|
|
|
2222
2274
|
const ColorConvertModule = {
|
|
2223
|
-
string
|
|
2275
|
+
string: string
|
|
2224
2276
|
};
|
|
2225
2277
|
|
|
2226
2278
|
Object.assign(draw.TextConvert, TextConvertModule);
|
|
2279
|
+
|
|
2227
2280
|
Object.assign(draw.ColorConvert, ColorConvertModule);
|
|
2281
|
+
|
|
2228
2282
|
Object.assign(draw.Paint, PaintModule);
|
|
2283
|
+
|
|
2229
2284
|
Object.assign(draw.PaintImage, PaintImageModule);
|
|
2285
|
+
|
|
2230
2286
|
Object.assign(draw.PaintGradient, PaintGradientModule);
|
|
2287
|
+
|
|
2231
2288
|
Object.assign(draw.Effect, EffectModule);
|
|
2232
2289
|
|
|
2233
|
-
const { setPoint, addPoint, toBounds } = draw.TwoPointBoundsHelper;
|
|
2290
|
+
const {setPoint: setPoint, addPoint: addPoint, toBounds: toBounds} = draw.TwoPointBoundsHelper;
|
|
2291
|
+
|
|
2234
2292
|
function getTrimBounds(canvas) {
|
|
2235
|
-
const { width, height } = canvas.view;
|
|
2236
|
-
const { data
|
|
2293
|
+
const {width: width, height: height} = canvas.view;
|
|
2294
|
+
const {data: data} = canvas.context.getImageData(0, 0, width, height);
|
|
2237
2295
|
let x, y, pointBounds, index = 0;
|
|
2238
2296
|
for (let i = 0; i < data.length; i += 4) {
|
|
2239
2297
|
if (data[i + 3] !== 0) {
|
|
@@ -2243,7 +2301,7 @@ function getTrimBounds(canvas) {
|
|
|
2243
2301
|
}
|
|
2244
2302
|
index++;
|
|
2245
2303
|
}
|
|
2246
|
-
const bounds = new draw.Bounds
|
|
2304
|
+
const bounds = new draw.Bounds;
|
|
2247
2305
|
if (pointBounds) {
|
|
2248
2306
|
toBounds(pointBounds, bounds);
|
|
2249
2307
|
bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
@@ -2257,64 +2315,80 @@ const ExportModule = {
|
|
|
2257
2315
|
let result;
|
|
2258
2316
|
try {
|
|
2259
2317
|
const fileType = draw.FileHelper.fileType(filename);
|
|
2260
|
-
const isDownload = filename.includes(
|
|
2318
|
+
const isDownload = filename.includes(".");
|
|
2261
2319
|
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
|
-
|
|
2320
|
+
const {toURL: toURL} = draw.Platform;
|
|
2321
|
+
const {download: download} = draw.Platform.origin;
|
|
2322
|
+
if (fileType === "json") {
|
|
2323
|
+
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), "text"), filename);
|
|
2324
|
+
result = {
|
|
2325
|
+
data: isDownload ? true : leaf.toJSON(options.json)
|
|
2326
|
+
};
|
|
2327
|
+
} else if (fileType === "svg") {
|
|
2328
|
+
isDownload && download(toURL(leaf.toSVG(), "svg"), filename);
|
|
2329
|
+
result = {
|
|
2330
|
+
data: isDownload ? true : leaf.toSVG()
|
|
2331
|
+
};
|
|
2332
|
+
} else {
|
|
2273
2333
|
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
|
|
2334
|
+
const {worldTransform: worldTransform, isLeafer: isLeafer, leafer: leafer, isFrame: isFrame} = leaf;
|
|
2335
|
+
const {slice: slice, clip: clip, trim: trim, screenshot: screenshot, padding: padding, onCanvas: onCanvas} = options;
|
|
2336
|
+
const smooth = draw.isUndefined(options.smooth) ? leafer ? leafer.config.smooth : true : options.smooth;
|
|
2277
2337
|
const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
|
|
2278
|
-
const fill =
|
|
2279
|
-
const needFill = draw.FileHelper.isOpaqueImage(filename) || fill, matrix = new draw.Matrix
|
|
2338
|
+
const fill = isLeafer && screenshot ? draw.isUndefined(options.fill) ? leaf.fill : options.fill : options.fill;
|
|
2339
|
+
const needFill = draw.FileHelper.isOpaqueImage(filename) || fill, matrix = new draw.Matrix;
|
|
2280
2340
|
if (screenshot) {
|
|
2281
|
-
renderBounds = screenshot === true ?
|
|
2282
|
-
}
|
|
2283
|
-
|
|
2284
|
-
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
2341
|
+
renderBounds = screenshot === true ? isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds : screenshot;
|
|
2342
|
+
} else {
|
|
2343
|
+
let relative = options.relative || (isLeafer ? "inner" : "local");
|
|
2285
2344
|
scaleX = worldTransform.scaleX;
|
|
2286
2345
|
scaleY = worldTransform.scaleY;
|
|
2287
2346
|
switch (relative) {
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2347
|
+
case "inner":
|
|
2348
|
+
matrix.set(worldTransform);
|
|
2349
|
+
break;
|
|
2350
|
+
|
|
2351
|
+
case "local":
|
|
2352
|
+
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
2353
|
+
scaleX /= leaf.scaleX;
|
|
2354
|
+
scaleY /= leaf.scaleY;
|
|
2355
|
+
break;
|
|
2356
|
+
|
|
2357
|
+
case "world":
|
|
2358
|
+
scaleX = 1;
|
|
2359
|
+
scaleY = 1;
|
|
2360
|
+
break;
|
|
2361
|
+
|
|
2362
|
+
case "page":
|
|
2363
|
+
relative = leafer || leaf;
|
|
2364
|
+
|
|
2365
|
+
default:
|
|
2366
|
+
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
2367
|
+
const l = relative.worldTransform;
|
|
2368
|
+
scaleX /= scaleX / l.scaleX;
|
|
2369
|
+
scaleY /= scaleY / l.scaleY;
|
|
2307
2370
|
}
|
|
2308
|
-
renderBounds = leaf.getBounds(
|
|
2371
|
+
renderBounds = leaf.getBounds("render", relative);
|
|
2309
2372
|
}
|
|
2310
|
-
const scaleData = {
|
|
2373
|
+
const scaleData = {
|
|
2374
|
+
scaleX: 1,
|
|
2375
|
+
scaleY: 1
|
|
2376
|
+
};
|
|
2311
2377
|
draw.MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2312
2378
|
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
|
-
|
|
2379
|
+
let {x: x, y: y, width: width, height: height} = new draw.Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2380
|
+
if (clip) x += clip.x, y += clip.y, width = clip.width, height = clip.height;
|
|
2381
|
+
const renderOptions = {
|
|
2382
|
+
exporting: true,
|
|
2383
|
+
matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY)
|
|
2384
|
+
};
|
|
2385
|
+
let canvas = draw.Creator.canvas({
|
|
2386
|
+
width: Math.floor(width),
|
|
2387
|
+
height: Math.floor(height),
|
|
2388
|
+
pixelRatio: pixelRatio,
|
|
2389
|
+
smooth: smooth,
|
|
2390
|
+
contextSettings: contextSettings
|
|
2391
|
+
});
|
|
2318
2392
|
let sliceLeaf;
|
|
2319
2393
|
if (slice) {
|
|
2320
2394
|
sliceLeaf = leaf;
|
|
@@ -2323,144 +2397,180 @@ const ExportModule = {
|
|
|
2323
2397
|
renderOptions.bounds = canvas.bounds;
|
|
2324
2398
|
}
|
|
2325
2399
|
canvas.save();
|
|
2326
|
-
if (isFrame && fill
|
|
2327
|
-
const oldFill = leaf.get(
|
|
2328
|
-
leaf.fill =
|
|
2400
|
+
if (isFrame && !draw.isUndefined(fill)) {
|
|
2401
|
+
const oldFill = leaf.get("fill");
|
|
2402
|
+
leaf.fill = "";
|
|
2329
2403
|
leaf.__render(canvas, renderOptions);
|
|
2330
2404
|
leaf.fill = oldFill;
|
|
2331
|
-
}
|
|
2332
|
-
else {
|
|
2405
|
+
} else {
|
|
2333
2406
|
leaf.__render(canvas, renderOptions);
|
|
2334
2407
|
}
|
|
2335
2408
|
canvas.restore();
|
|
2336
|
-
if (sliceLeaf)
|
|
2337
|
-
sliceLeaf.__updateWorldOpacity();
|
|
2409
|
+
if (sliceLeaf) sliceLeaf.__updateWorldOpacity();
|
|
2338
2410
|
if (trim) {
|
|
2339
2411
|
trimBounds = getTrimBounds(canvas);
|
|
2340
|
-
const old = canvas, { width, height } = trimBounds;
|
|
2341
|
-
const config = {
|
|
2412
|
+
const old = canvas, {width: width, height: height} = trimBounds;
|
|
2413
|
+
const config = {
|
|
2414
|
+
x: 0,
|
|
2415
|
+
y: 0,
|
|
2416
|
+
width: width,
|
|
2417
|
+
height: height,
|
|
2418
|
+
pixelRatio: pixelRatio
|
|
2419
|
+
};
|
|
2342
2420
|
canvas = draw.Creator.canvas(config);
|
|
2343
2421
|
canvas.copyWorld(old, trimBounds, config);
|
|
2422
|
+
old.destroy();
|
|
2344
2423
|
}
|
|
2345
2424
|
if (padding) {
|
|
2346
2425
|
const [top, right, bottom, left] = draw.MathHelper.fourNumber(padding);
|
|
2347
|
-
const old = canvas, { width, height } = old;
|
|
2348
|
-
canvas = draw.Creator.canvas({
|
|
2349
|
-
|
|
2426
|
+
const old = canvas, {width: width, height: height} = old;
|
|
2427
|
+
canvas = draw.Creator.canvas({
|
|
2428
|
+
width: width + left + right,
|
|
2429
|
+
height: height + top + bottom,
|
|
2430
|
+
pixelRatio: pixelRatio
|
|
2431
|
+
});
|
|
2432
|
+
canvas.copyWorld(old, old.bounds, {
|
|
2433
|
+
x: left,
|
|
2434
|
+
y: top,
|
|
2435
|
+
width: width,
|
|
2436
|
+
height: height
|
|
2437
|
+
});
|
|
2438
|
+
old.destroy();
|
|
2350
2439
|
}
|
|
2351
|
-
if (needFill)
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2440
|
+
if (needFill) canvas.fillWorld(canvas.bounds, fill || "#FFFFFF", "destination-over");
|
|
2441
|
+
if (onCanvas) onCanvas(canvas);
|
|
2442
|
+
const data = filename === "canvas" ? canvas : canvas.export(filename, options);
|
|
2443
|
+
result = {
|
|
2444
|
+
data: data,
|
|
2445
|
+
width: canvas.pixelWidth,
|
|
2446
|
+
height: canvas.pixelHeight,
|
|
2447
|
+
renderBounds: renderBounds,
|
|
2448
|
+
trimBounds: trimBounds
|
|
2449
|
+
};
|
|
2357
2450
|
}
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
|
-
|
|
2451
|
+
} catch (error) {
|
|
2452
|
+
result = {
|
|
2453
|
+
data: "",
|
|
2454
|
+
error: error
|
|
2455
|
+
};
|
|
2361
2456
|
}
|
|
2362
2457
|
draw.Export.running = false;
|
|
2363
2458
|
return result;
|
|
2364
2459
|
},
|
|
2365
2460
|
export(leaf, filename, options) {
|
|
2366
2461
|
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);
|
|
2462
|
+
return addTask(success => new Promise(resolve => {
|
|
2463
|
+
const getResult = () => __awaiter(this, void 0, void 0, function*() {
|
|
2464
|
+
if (!draw.Resource.isComplete) return draw.Platform.requestRender(getResult);
|
|
2371
2465
|
const result = draw.Export.syncExport(leaf, filename, options);
|
|
2372
|
-
if (result.data instanceof Promise)
|
|
2373
|
-
result.data = yield result.data;
|
|
2466
|
+
if (result.data instanceof Promise) result.data = yield result.data;
|
|
2374
2467
|
success(result);
|
|
2375
2468
|
resolve();
|
|
2376
2469
|
});
|
|
2377
2470
|
leaf.updateLayout();
|
|
2378
2471
|
checkLazy(leaf);
|
|
2379
|
-
const { leafer
|
|
2380
|
-
if (leafer)
|
|
2381
|
-
leafer.waitViewCompleted(getResult);
|
|
2382
|
-
else
|
|
2383
|
-
getResult();
|
|
2472
|
+
const {leafer: leafer} = leaf;
|
|
2473
|
+
if (leafer) leafer.waitViewCompleted(getResult); else getResult();
|
|
2384
2474
|
}));
|
|
2385
2475
|
}
|
|
2386
2476
|
};
|
|
2477
|
+
|
|
2387
2478
|
let tasker;
|
|
2479
|
+
|
|
2388
2480
|
function addTask(task) {
|
|
2389
|
-
if (!tasker)
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2481
|
+
if (!tasker) tasker = new draw.TaskProcessor;
|
|
2482
|
+
return new Promise(resolve => {
|
|
2483
|
+
tasker.add(() => __awaiter(this, void 0, void 0, function*() {
|
|
2484
|
+
return yield task(resolve);
|
|
2485
|
+
}), {
|
|
2486
|
+
parallel: false
|
|
2487
|
+
});
|
|
2393
2488
|
});
|
|
2394
2489
|
}
|
|
2490
|
+
|
|
2395
2491
|
function checkLazy(leaf) {
|
|
2396
|
-
if (leaf.__.__needComputePaint)
|
|
2397
|
-
|
|
2398
|
-
if (leaf.isBranch)
|
|
2399
|
-
leaf.children.forEach(child => checkLazy(child));
|
|
2492
|
+
if (leaf.__.__needComputePaint) leaf.__.__computePaint();
|
|
2493
|
+
if (leaf.isBranch) leaf.children.forEach(child => checkLazy(child));
|
|
2400
2494
|
}
|
|
2401
2495
|
|
|
2402
2496
|
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);
|
|
2497
|
+
|
|
2498
|
+
const debug = draw.Debug.get("@leafer-in/export");
|
|
2499
|
+
|
|
2500
|
+
canvas.export = function(filename, options) {
|
|
2501
|
+
const {quality: quality, blob: blob} = draw.FileHelper.getExportOptions(options);
|
|
2502
|
+
if (filename.includes(".")) return this.saveAs(filename, quality); else if (blob) return this.toBlob(filename, quality); else return this.toDataURL(filename, quality);
|
|
2412
2503
|
};
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2504
|
+
|
|
2505
|
+
canvas.toBlob = function(type, quality) {
|
|
2506
|
+
return new Promise(resolve => {
|
|
2507
|
+
draw.Platform.origin.canvasToBolb(this.view, type, quality).then(blob => {
|
|
2416
2508
|
resolve(blob);
|
|
2417
|
-
}).catch(
|
|
2509
|
+
}).catch(e => {
|
|
2418
2510
|
debug.error(e);
|
|
2419
2511
|
resolve(null);
|
|
2420
2512
|
});
|
|
2421
2513
|
});
|
|
2422
2514
|
};
|
|
2423
|
-
|
|
2515
|
+
|
|
2516
|
+
canvas.toDataURL = function(type, quality) {
|
|
2424
2517
|
return draw.Platform.origin.canvasToDataURL(this.view, type, quality);
|
|
2425
2518
|
};
|
|
2426
|
-
|
|
2427
|
-
|
|
2519
|
+
|
|
2520
|
+
canvas.saveAs = function(filename, quality) {
|
|
2521
|
+
return new Promise(resolve => {
|
|
2428
2522
|
draw.Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
|
|
2429
2523
|
resolve(true);
|
|
2430
|
-
}).catch(
|
|
2524
|
+
}).catch(e => {
|
|
2431
2525
|
debug.error(e);
|
|
2432
2526
|
resolve(false);
|
|
2433
2527
|
});
|
|
2434
2528
|
});
|
|
2435
2529
|
};
|
|
2436
2530
|
|
|
2437
|
-
draw.Plugin.add(
|
|
2531
|
+
draw.Plugin.add("export");
|
|
2532
|
+
|
|
2438
2533
|
Object.assign(draw.Export, ExportModule);
|
|
2439
|
-
|
|
2534
|
+
|
|
2535
|
+
draw.UI.prototype.export = function(filename, options) {
|
|
2440
2536
|
return draw.Export.export(this, filename, options);
|
|
2441
2537
|
};
|
|
2442
|
-
|
|
2538
|
+
|
|
2539
|
+
draw.UI.prototype.syncExport = function(filename, options) {
|
|
2443
2540
|
return draw.Export.syncExport(this, filename, options);
|
|
2444
2541
|
};
|
|
2445
2542
|
|
|
2446
2543
|
Object.defineProperty(exports, "LeaferImage", {
|
|
2447
2544
|
enumerable: true,
|
|
2448
|
-
get: function
|
|
2545
|
+
get: function() {
|
|
2546
|
+
return core.LeaferImage;
|
|
2547
|
+
}
|
|
2449
2548
|
});
|
|
2549
|
+
|
|
2450
2550
|
exports.Layouter = Layouter;
|
|
2551
|
+
|
|
2451
2552
|
exports.LeaferCanvas = LeaferCanvas;
|
|
2553
|
+
|
|
2452
2554
|
exports.Renderer = Renderer;
|
|
2555
|
+
|
|
2453
2556
|
exports.Watcher = Watcher;
|
|
2557
|
+
|
|
2454
2558
|
exports.useCanvas = useCanvas;
|
|
2455
|
-
|
|
2456
|
-
|
|
2559
|
+
|
|
2560
|
+
Object.keys(core).forEach(function(k) {
|
|
2561
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
2457
2562
|
enumerable: true,
|
|
2458
|
-
get: function
|
|
2563
|
+
get: function() {
|
|
2564
|
+
return core[k];
|
|
2565
|
+
}
|
|
2459
2566
|
});
|
|
2460
2567
|
});
|
|
2461
|
-
|
|
2462
|
-
|
|
2568
|
+
|
|
2569
|
+
Object.keys(draw).forEach(function(k) {
|
|
2570
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
2463
2571
|
enumerable: true,
|
|
2464
|
-
get: function
|
|
2572
|
+
get: function() {
|
|
2573
|
+
return draw[k];
|
|
2574
|
+
}
|
|
2465
2575
|
});
|
|
2466
2576
|
});
|