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