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