@leafer-draw/worker 1.8.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/worker.cjs +1014 -951
- package/dist/worker.esm.js +999 -946
- package/dist/worker.esm.min.js +1 -1
- package/dist/worker.esm.min.js.map +1 -1
- package/dist/worker.js +4190 -4656
- 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 +4833 -4491
- 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,117 +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
681
|
if (item.transform || item.scaleFixed) {
|
|
701
682
|
canvas.save();
|
|
702
|
-
if (item.transform)
|
|
703
|
-
canvas.transform(item.transform);
|
|
683
|
+
if (item.transform) canvas.transform(item.transform);
|
|
704
684
|
if (item.scaleFixed) {
|
|
705
|
-
const { scaleX, scaleY } = ui.getRenderScaleData(true);
|
|
706
|
-
canvas.scale(1 / scaleX, 1 / scaleY);
|
|
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);
|
|
707
687
|
}
|
|
708
|
-
if (item.blendMode)
|
|
709
|
-
canvas.blendMode = item.blendMode;
|
|
688
|
+
if (item.blendMode) canvas.blendMode = item.blendMode;
|
|
710
689
|
fillPathOrText(ui, canvas);
|
|
711
690
|
canvas.restore();
|
|
712
|
-
}
|
|
713
|
-
else {
|
|
691
|
+
} else {
|
|
714
692
|
if (item.blendMode) {
|
|
715
693
|
canvas.saveBlendMode(item.blendMode);
|
|
716
694
|
fillPathOrText(ui, canvas);
|
|
717
695
|
canvas.restoreBlendMode();
|
|
718
|
-
}
|
|
719
|
-
else
|
|
720
|
-
fillPathOrText(ui, canvas);
|
|
696
|
+
} else fillPathOrText(ui, canvas);
|
|
721
697
|
}
|
|
722
698
|
}
|
|
723
699
|
}
|
|
700
|
+
|
|
724
701
|
function fillPathOrText(ui, canvas) {
|
|
725
|
-
ui.__.__font ? fillText(ui, canvas) :
|
|
702
|
+
ui.__.__font ? fillText(ui, canvas) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
|
|
726
703
|
}
|
|
727
704
|
|
|
728
705
|
function strokeText(stroke, ui, canvas) {
|
|
729
706
|
switch (ui.__.strokeAlign) {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
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;
|
|
739
718
|
}
|
|
740
719
|
}
|
|
720
|
+
|
|
741
721
|
function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
|
|
742
722
|
const data = ui.__;
|
|
743
|
-
if (
|
|
723
|
+
if (core.isObject(stroke)) {
|
|
744
724
|
drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
|
|
745
|
-
}
|
|
746
|
-
else {
|
|
725
|
+
} else {
|
|
747
726
|
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
748
727
|
drawTextStroke(ui, canvas);
|
|
749
728
|
}
|
|
750
729
|
}
|
|
730
|
+
|
|
751
731
|
function drawAlign(stroke, align, ui, canvas) {
|
|
752
732
|
const out = canvas.getSameCanvas(true, true);
|
|
753
733
|
out.font = ui.__.__font;
|
|
754
734
|
drawCenter$1(stroke, 2, ui, out);
|
|
755
|
-
out.blendMode = align ===
|
|
735
|
+
out.blendMode = align === "outside" ? "destination-out" : "destination-in";
|
|
756
736
|
fillText(ui, out);
|
|
757
|
-
out.blendMode =
|
|
737
|
+
out.blendMode = "normal";
|
|
758
738
|
core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
|
|
759
739
|
out.recycle(ui.__nowWorld);
|
|
760
740
|
}
|
|
741
|
+
|
|
761
742
|
function drawTextStroke(ui, canvas) {
|
|
762
743
|
let row, data = ui.__.__textDrawData;
|
|
763
|
-
const { rows, decorationY } = data;
|
|
744
|
+
const {rows: rows, decorationY: decorationY} = data;
|
|
764
745
|
for (let i = 0, len = rows.length; i < len; i++) {
|
|
765
746
|
row = rows[i];
|
|
766
|
-
if (row.text)
|
|
767
|
-
canvas.strokeText(
|
|
768
|
-
|
|
769
|
-
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
|
+
});
|
|
770
750
|
}
|
|
771
751
|
if (decorationY) {
|
|
772
|
-
const { decorationHeight
|
|
752
|
+
const {decorationHeight: decorationHeight} = data;
|
|
773
753
|
rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
|
|
774
754
|
}
|
|
775
755
|
}
|
|
756
|
+
|
|
776
757
|
function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
|
|
777
758
|
let item;
|
|
778
|
-
const data = ui.__, { __hasMultiStrokeStyle
|
|
759
|
+
const data = ui.__, {__hasMultiStrokeStyle: __hasMultiStrokeStyle} = data;
|
|
779
760
|
__hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
|
|
780
761
|
for (let i = 0, len = strokes.length; i < len; i++) {
|
|
781
762
|
item = strokes[i];
|
|
782
|
-
if (item.image && draw.PaintImage.checkImage(ui, canvas, item, false))
|
|
783
|
-
continue;
|
|
763
|
+
if (item.image && draw.PaintImage.checkImage(ui, canvas, item, false)) continue;
|
|
784
764
|
if (item.style) {
|
|
785
765
|
if (__hasMultiStrokeStyle) {
|
|
786
|
-
const { strokeStyle
|
|
766
|
+
const {strokeStyle: strokeStyle} = item;
|
|
787
767
|
strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
|
|
788
|
-
}
|
|
789
|
-
else
|
|
790
|
-
canvas.strokeStyle = item.style;
|
|
768
|
+
} else canvas.strokeStyle = item.style;
|
|
791
769
|
if (item.blendMode) {
|
|
792
770
|
canvas.saveBlendMode(item.blendMode);
|
|
793
771
|
isText ? drawTextStroke(ui, canvas) : canvas.stroke();
|
|
794
772
|
canvas.restoreBlendMode();
|
|
795
|
-
}
|
|
796
|
-
else {
|
|
773
|
+
} else {
|
|
797
774
|
isText ? drawTextStroke(ui, canvas) : canvas.stroke();
|
|
798
775
|
}
|
|
799
776
|
}
|
|
@@ -802,53 +779,54 @@ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
|
|
|
802
779
|
|
|
803
780
|
function stroke(stroke, ui, canvas) {
|
|
804
781
|
const data = ui.__;
|
|
805
|
-
if (!data.__strokeWidth)
|
|
806
|
-
return;
|
|
782
|
+
if (!data.__strokeWidth) return;
|
|
807
783
|
if (data.__font) {
|
|
808
784
|
strokeText(stroke, ui, canvas);
|
|
809
|
-
}
|
|
810
|
-
else {
|
|
785
|
+
} else {
|
|
811
786
|
switch (data.strokeAlign) {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
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;
|
|
821
798
|
}
|
|
822
799
|
}
|
|
823
800
|
}
|
|
801
|
+
|
|
824
802
|
function strokes(strokes, ui, canvas) {
|
|
825
803
|
stroke(strokes, ui, canvas);
|
|
826
804
|
}
|
|
805
|
+
|
|
827
806
|
function drawCenter(stroke, strokeWidthScale, ui, canvas) {
|
|
828
807
|
const data = ui.__;
|
|
829
|
-
if (
|
|
808
|
+
if (core.isObject(stroke)) {
|
|
830
809
|
drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
|
|
831
|
-
}
|
|
832
|
-
else {
|
|
810
|
+
} else {
|
|
833
811
|
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
834
812
|
canvas.stroke();
|
|
835
813
|
}
|
|
836
|
-
if (data.__useArrow)
|
|
837
|
-
draw.Paint.strokeArrow(stroke, ui, canvas);
|
|
814
|
+
if (data.__useArrow) draw.Paint.strokeArrow(stroke, ui, canvas);
|
|
838
815
|
}
|
|
816
|
+
|
|
839
817
|
function drawInside(stroke, ui, canvas) {
|
|
840
818
|
canvas.save();
|
|
841
819
|
canvas.clipUI(ui);
|
|
842
820
|
drawCenter(stroke, 2, ui, canvas);
|
|
843
821
|
canvas.restore();
|
|
844
822
|
}
|
|
823
|
+
|
|
845
824
|
function drawOutside(stroke, ui, canvas) {
|
|
846
825
|
const data = ui.__;
|
|
847
826
|
if (data.__fillAfterStroke) {
|
|
848
827
|
drawCenter(stroke, 2, ui, canvas);
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
const { renderBounds } = ui.__layout;
|
|
828
|
+
} else {
|
|
829
|
+
const {renderBounds: renderBounds} = ui.__layout;
|
|
852
830
|
const out = canvas.getSameCanvas(true, true);
|
|
853
831
|
ui.__drawRenderPath(out);
|
|
854
832
|
drawCenter(stroke, 2, ui, out);
|
|
@@ -859,25 +837,27 @@ function drawOutside(stroke, ui, canvas) {
|
|
|
859
837
|
}
|
|
860
838
|
}
|
|
861
839
|
|
|
862
|
-
const { getSpread, getOuterOf, getByMove, getIntersectData } = core.BoundsHelper;
|
|
840
|
+
const {getSpread: getSpread, getOuterOf: getOuterOf, getByMove: getByMove, getIntersectData: getIntersectData} = core.BoundsHelper;
|
|
841
|
+
|
|
863
842
|
function shape(ui, current, options) {
|
|
864
843
|
const canvas = current.getSameCanvas();
|
|
865
|
-
const nowWorld = ui.__nowWorld;
|
|
866
|
-
let bounds, fitMatrix, shapeBounds, worldCanvas;
|
|
867
|
-
let { scaleX, scaleY } =
|
|
868
|
-
if (
|
|
869
|
-
scaleX = -scaleX;
|
|
870
|
-
if (scaleY < 0)
|
|
871
|
-
scaleY = -scaleY;
|
|
872
|
-
if (current.bounds.includes(nowWorld)) {
|
|
844
|
+
const nowWorld = ui.__nowWorld, currentBounds = current.bounds;
|
|
845
|
+
let bounds, matrix, fitMatrix, shapeBounds, worldCanvas;
|
|
846
|
+
let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
|
|
847
|
+
if (currentBounds.includes(nowWorld)) {
|
|
873
848
|
worldCanvas = canvas;
|
|
874
849
|
bounds = shapeBounds = nowWorld;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
850
|
+
} else {
|
|
851
|
+
const {renderShapeSpread: spread} = ui.__layout;
|
|
852
|
+
let worldClipBounds;
|
|
853
|
+
if (core.Platform.fullImageShadow) {
|
|
854
|
+
worldClipBounds = nowWorld;
|
|
855
|
+
} else {
|
|
856
|
+
const spreadBounds = spread ? getSpread(currentBounds, scaleX === scaleY ? spread * scaleX : [ spread * scaleY, spread * scaleX ]) : currentBounds;
|
|
857
|
+
worldClipBounds = getIntersectData(spreadBounds, nowWorld);
|
|
858
|
+
}
|
|
859
|
+
fitMatrix = currentBounds.getFitMatrix(worldClipBounds);
|
|
860
|
+
let {a: fitScaleX, d: fitScaleY} = fitMatrix;
|
|
881
861
|
if (fitMatrix.a < 1) {
|
|
882
862
|
worldCanvas = current.getSameCanvas();
|
|
883
863
|
ui.__renderShape(worldCanvas, options);
|
|
@@ -886,28 +866,39 @@ function shape(ui, current, options) {
|
|
|
886
866
|
}
|
|
887
867
|
shapeBounds = getOuterOf(nowWorld, fitMatrix);
|
|
888
868
|
bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f);
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
869
|
+
const userMatrix = options.matrix;
|
|
870
|
+
if (userMatrix) {
|
|
871
|
+
matrix = new core.Matrix(fitMatrix);
|
|
872
|
+
matrix.multiply(userMatrix);
|
|
873
|
+
fitScaleX *= userMatrix.scaleX;
|
|
874
|
+
fitScaleY *= userMatrix.scaleY;
|
|
875
|
+
} else matrix = fitMatrix;
|
|
876
|
+
matrix.withScale(fitScaleX, fitScaleY);
|
|
877
|
+
options = Object.assign(Object.assign({}, options), {
|
|
878
|
+
matrix: matrix
|
|
879
|
+
});
|
|
896
880
|
}
|
|
897
881
|
ui.__renderShape(canvas, options);
|
|
898
882
|
return {
|
|
899
|
-
canvas
|
|
900
|
-
|
|
883
|
+
canvas: canvas,
|
|
884
|
+
matrix: matrix,
|
|
885
|
+
fitMatrix: fitMatrix,
|
|
886
|
+
bounds: bounds,
|
|
887
|
+
worldCanvas: worldCanvas,
|
|
888
|
+
shapeBounds: shapeBounds,
|
|
889
|
+
scaleX: scaleX,
|
|
890
|
+
scaleY: scaleY
|
|
901
891
|
};
|
|
902
892
|
}
|
|
903
893
|
|
|
904
894
|
let recycleMap;
|
|
905
|
-
|
|
895
|
+
|
|
896
|
+
const {stintSet: stintSet} = core.DataHelper, {hasTransparent: hasTransparent$1} = draw.ColorConvert;
|
|
897
|
+
|
|
906
898
|
function compute(attrName, ui) {
|
|
907
899
|
const data = ui.__, leafPaints = [];
|
|
908
900
|
let paints = data.__input[attrName], isAlphaPixel, isTransparent;
|
|
909
|
-
if (!(paints
|
|
910
|
-
paints = [paints];
|
|
901
|
+
if (!core.isArray(paints)) paints = [ paints ];
|
|
911
902
|
recycleMap = draw.PaintImage.recycleImage(attrName, data);
|
|
912
903
|
let maxChildStrokeWidth;
|
|
913
904
|
for (let i = 0, len = paints.length, item; i < len; i++) {
|
|
@@ -915,206 +906,222 @@ function compute(attrName, ui) {
|
|
|
915
906
|
leafPaints.push(item);
|
|
916
907
|
if (item.strokeStyle) {
|
|
917
908
|
maxChildStrokeWidth || (maxChildStrokeWidth = 1);
|
|
918
|
-
if (item.strokeStyle.strokeWidth)
|
|
919
|
-
maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
909
|
+
if (item.strokeStyle.strokeWidth) maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
920
910
|
}
|
|
921
911
|
}
|
|
922
912
|
}
|
|
923
|
-
data[
|
|
913
|
+
data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
|
|
924
914
|
if (leafPaints.length) {
|
|
925
915
|
if (leafPaints.every(item => item.isTransparent)) {
|
|
926
|
-
if (leafPaints.some(item => item.image))
|
|
927
|
-
isAlphaPixel = true;
|
|
916
|
+
if (leafPaints.some(item => item.image)) isAlphaPixel = true;
|
|
928
917
|
isTransparent = true;
|
|
929
918
|
}
|
|
930
919
|
}
|
|
931
|
-
if (attrName ===
|
|
932
|
-
stintSet(data,
|
|
933
|
-
stintSet(data,
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
stintSet(data,
|
|
937
|
-
stintSet(data,
|
|
938
|
-
stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth);
|
|
920
|
+
if (attrName === "fill") {
|
|
921
|
+
stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
|
|
922
|
+
stintSet(data, "__isTransparentFill", isTransparent);
|
|
923
|
+
} else {
|
|
924
|
+
stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
|
|
925
|
+
stintSet(data, "__isTransparentStroke", isTransparent);
|
|
926
|
+
stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
|
|
939
927
|
}
|
|
940
928
|
}
|
|
929
|
+
|
|
941
930
|
function getLeafPaint(attrName, paint, ui) {
|
|
942
|
-
if (
|
|
943
|
-
return undefined;
|
|
931
|
+
if (!core.isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
|
|
944
932
|
let data;
|
|
945
|
-
const { boxBounds
|
|
933
|
+
const {boxBounds: boxBounds} = ui.__layout;
|
|
946
934
|
switch (paint.type) {
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
935
|
+
case "image":
|
|
936
|
+
data = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
|
|
937
|
+
break;
|
|
938
|
+
|
|
939
|
+
case "linear":
|
|
940
|
+
data = draw.PaintGradient.linearGradient(paint, boxBounds);
|
|
941
|
+
break;
|
|
942
|
+
|
|
943
|
+
case "radial":
|
|
944
|
+
data = draw.PaintGradient.radialGradient(paint, boxBounds);
|
|
945
|
+
break;
|
|
946
|
+
|
|
947
|
+
case "angular":
|
|
948
|
+
data = draw.PaintGradient.conicGradient(paint, boxBounds);
|
|
949
|
+
break;
|
|
950
|
+
|
|
951
|
+
case "solid":
|
|
952
|
+
const {type: type, color: color, opacity: opacity} = paint;
|
|
953
|
+
data = {
|
|
954
|
+
type: type,
|
|
955
|
+
style: draw.ColorConvert.string(color, opacity)
|
|
956
|
+
};
|
|
957
|
+
break;
|
|
958
|
+
|
|
959
|
+
default:
|
|
960
|
+
if (!core.isUndefined(paint.r)) data = {
|
|
961
|
+
type: "solid",
|
|
962
|
+
style: draw.ColorConvert.string(paint)
|
|
963
|
+
};
|
|
966
964
|
}
|
|
967
965
|
if (data) {
|
|
968
|
-
if (
|
|
969
|
-
data.isTransparent = true;
|
|
966
|
+
if (core.isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
|
|
970
967
|
if (paint.style) {
|
|
971
|
-
if (paint.style.strokeWidth === 0)
|
|
972
|
-
return undefined;
|
|
968
|
+
if (paint.style.strokeWidth === 0) return undefined;
|
|
973
969
|
data.strokeStyle = paint.style;
|
|
974
970
|
}
|
|
975
|
-
if (paint.
|
|
976
|
-
|
|
971
|
+
if (paint.editing) data.editing = paint.editing;
|
|
972
|
+
if (paint.blendMode) data.blendMode = paint.blendMode;
|
|
977
973
|
}
|
|
978
974
|
return data;
|
|
979
975
|
}
|
|
980
976
|
|
|
981
977
|
const PaintModule = {
|
|
982
|
-
compute,
|
|
983
|
-
fill,
|
|
984
|
-
fills,
|
|
985
|
-
fillPathOrText,
|
|
986
|
-
fillText,
|
|
987
|
-
stroke,
|
|
988
|
-
strokes,
|
|
989
|
-
strokeText,
|
|
990
|
-
drawTextStroke,
|
|
991
|
-
shape
|
|
978
|
+
compute: compute,
|
|
979
|
+
fill: fill,
|
|
980
|
+
fills: fills,
|
|
981
|
+
fillPathOrText: fillPathOrText,
|
|
982
|
+
fillText: fillText,
|
|
983
|
+
stroke: stroke,
|
|
984
|
+
strokes: strokes,
|
|
985
|
+
strokeText: strokeText,
|
|
986
|
+
drawTextStroke: drawTextStroke,
|
|
987
|
+
shape: shape
|
|
992
988
|
};
|
|
993
989
|
|
|
994
990
|
let origin = {}, tempMatrix = core.getMatrixData();
|
|
995
|
-
|
|
991
|
+
|
|
992
|
+
const {get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = core.MatrixHelper;
|
|
993
|
+
|
|
996
994
|
function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
997
995
|
const transform = get$3();
|
|
998
996
|
translate$1(transform, box.x + x, box.y + y);
|
|
999
997
|
scaleHelper(transform, scaleX, scaleY);
|
|
1000
|
-
if (rotation)
|
|
1001
|
-
|
|
998
|
+
if (rotation) rotateOfOuter$1(transform, {
|
|
999
|
+
x: box.x + box.width / 2,
|
|
1000
|
+
y: box.y + box.height / 2
|
|
1001
|
+
}, rotation);
|
|
1002
1002
|
data.transform = transform;
|
|
1003
1003
|
}
|
|
1004
|
+
|
|
1004
1005
|
function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
|
|
1005
1006
|
const transform = get$3();
|
|
1006
|
-
|
|
1007
|
-
rotate(transform, rotation);
|
|
1008
|
-
if (skew)
|
|
1009
|
-
skewHelper(transform, skew.x, skew.y);
|
|
1010
|
-
if (scaleX)
|
|
1011
|
-
scaleHelper(transform, scaleX, scaleY);
|
|
1012
|
-
translate$1(transform, box.x + x, box.y + y);
|
|
1007
|
+
layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
|
|
1013
1008
|
if (clipSize) {
|
|
1014
1009
|
tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
|
|
1015
1010
|
multiplyParent(transform, tempMatrix);
|
|
1016
1011
|
}
|
|
1017
1012
|
data.transform = transform;
|
|
1018
1013
|
}
|
|
1019
|
-
|
|
1014
|
+
|
|
1015
|
+
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
|
|
1020
1016
|
const transform = get$3();
|
|
1021
|
-
if (
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1017
|
+
if (freeTransform) {
|
|
1018
|
+
layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
|
|
1019
|
+
} else {
|
|
1020
|
+
if (rotation) {
|
|
1021
|
+
if (align === "center") {
|
|
1022
|
+
rotateOfOuter$1(transform, {
|
|
1023
|
+
x: width / 2,
|
|
1024
|
+
y: height / 2
|
|
1025
|
+
}, rotation);
|
|
1026
|
+
} else {
|
|
1027
|
+
rotate(transform, rotation);
|
|
1028
|
+
switch (rotation) {
|
|
1029
|
+
case 90:
|
|
1029
1030
|
translate$1(transform, height, 0);
|
|
1030
1031
|
break;
|
|
1031
|
-
|
|
1032
|
+
|
|
1033
|
+
case 180:
|
|
1032
1034
|
translate$1(transform, width, height);
|
|
1033
1035
|
break;
|
|
1034
|
-
|
|
1036
|
+
|
|
1037
|
+
case 270:
|
|
1035
1038
|
translate$1(transform, 0, width);
|
|
1036
1039
|
break;
|
|
1040
|
+
}
|
|
1037
1041
|
}
|
|
1038
1042
|
}
|
|
1043
|
+
origin.x = box.x + x;
|
|
1044
|
+
origin.y = box.y + y;
|
|
1045
|
+
translate$1(transform, origin.x, origin.y);
|
|
1046
|
+
if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
|
|
1039
1047
|
}
|
|
1040
|
-
origin.x = box.x + x;
|
|
1041
|
-
origin.y = box.y + y;
|
|
1042
|
-
translate$1(transform, origin.x, origin.y);
|
|
1043
|
-
if (scaleX)
|
|
1044
|
-
scaleOfOuter$1(transform, origin, scaleX, scaleY);
|
|
1045
1048
|
data.transform = transform;
|
|
1046
1049
|
}
|
|
1047
1050
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1051
|
+
function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
|
|
1052
|
+
if (rotation) rotate(transform, rotation);
|
|
1053
|
+
if (skew) skewHelper(transform, skew.x, skew.y);
|
|
1054
|
+
if (scaleX) scaleHelper(transform, scaleX, scaleY);
|
|
1055
|
+
translate$1(transform, box.x + x, box.y + y);
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
const {get: get$2, translate: translate} = core.MatrixHelper;
|
|
1059
|
+
|
|
1060
|
+
const tempBox = new core.Bounds;
|
|
1061
|
+
|
|
1050
1062
|
const tempScaleData = {};
|
|
1063
|
+
|
|
1051
1064
|
const tempImage = {};
|
|
1065
|
+
|
|
1052
1066
|
function createData(leafPaint, image, paint, box) {
|
|
1053
|
-
const { changeful, sync
|
|
1054
|
-
if (changeful)
|
|
1055
|
-
|
|
1056
|
-
if (
|
|
1057
|
-
leafPaint.sync = sync;
|
|
1058
|
-
if (editing)
|
|
1059
|
-
leafPaint.editing = editing;
|
|
1060
|
-
if (scaleFixed)
|
|
1061
|
-
leafPaint.scaleFixed = scaleFixed;
|
|
1067
|
+
const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
|
|
1068
|
+
if (changeful) leafPaint.changeful = changeful;
|
|
1069
|
+
if (sync) leafPaint.sync = sync;
|
|
1070
|
+
if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
|
|
1062
1071
|
leafPaint.data = getPatternData(paint, box, image);
|
|
1063
1072
|
}
|
|
1073
|
+
|
|
1064
1074
|
function getPatternData(paint, box, image) {
|
|
1065
|
-
if (paint.padding)
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
let { width, height } = image;
|
|
1070
|
-
const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, repeat, filters } = paint;
|
|
1075
|
+
if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
|
|
1076
|
+
if (paint.mode === "strench") paint.mode = "stretch";
|
|
1077
|
+
let {width: width, height: height} = image;
|
|
1078
|
+
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;
|
|
1071
1079
|
const sameBox = box.width === width && box.height === height;
|
|
1072
|
-
const data = {
|
|
1073
|
-
|
|
1080
|
+
const data = {
|
|
1081
|
+
mode: mode
|
|
1082
|
+
};
|
|
1083
|
+
const swapSize = align !== "center" && (rotation || 0) % 180 === 90;
|
|
1074
1084
|
core.BoundsHelper.set(tempImage, 0, 0, swapSize ? height : width, swapSize ? width : height);
|
|
1075
1085
|
let scaleX, scaleY;
|
|
1076
|
-
if (!mode || mode ===
|
|
1086
|
+
if (!mode || mode === "cover" || mode === "fit") {
|
|
1077
1087
|
if (!sameBox || rotation) {
|
|
1078
|
-
scaleX = scaleY = core.BoundsHelper.getFitScale(box, tempImage, mode !==
|
|
1088
|
+
scaleX = scaleY = core.BoundsHelper.getFitScale(box, tempImage, mode !== "fit");
|
|
1079
1089
|
core.BoundsHelper.put(box, image, align, scaleX, false, tempImage);
|
|
1080
1090
|
core.BoundsHelper.scale(tempImage, scaleX, scaleY, true);
|
|
1081
1091
|
}
|
|
1082
|
-
}
|
|
1083
|
-
else {
|
|
1092
|
+
} else {
|
|
1084
1093
|
if (scale || size) {
|
|
1085
1094
|
core.MathHelper.getScaleData(scale, size, image, tempScaleData);
|
|
1086
1095
|
scaleX = tempScaleData.scaleX;
|
|
1087
1096
|
scaleY = tempScaleData.scaleY;
|
|
1088
1097
|
}
|
|
1089
|
-
if (align) {
|
|
1090
|
-
if (scaleX)
|
|
1091
|
-
|
|
1092
|
-
core.AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
|
|
1098
|
+
if (align || gap || repeat) {
|
|
1099
|
+
if (scaleX) core.BoundsHelper.scale(tempImage, scaleX, scaleY, true);
|
|
1100
|
+
if (align) core.AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
|
|
1093
1101
|
}
|
|
1094
1102
|
}
|
|
1095
|
-
if (offset)
|
|
1096
|
-
core.PointHelper.move(tempImage, offset);
|
|
1103
|
+
if (offset) core.PointHelper.move(tempImage, offset);
|
|
1097
1104
|
switch (mode) {
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1105
|
+
case "stretch":
|
|
1106
|
+
if (!sameBox) width = box.width, height = box.height;
|
|
1107
|
+
break;
|
|
1108
|
+
|
|
1109
|
+
case "normal":
|
|
1110
|
+
case "clip":
|
|
1111
|
+
if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
|
|
1112
|
+
break;
|
|
1113
|
+
|
|
1114
|
+
case "repeat":
|
|
1115
|
+
if (!sameBox || scaleX || rotation || skew) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
|
|
1116
|
+
if (!repeat) data.repeat = "repeat";
|
|
1117
|
+
const count = core.isObject(repeat);
|
|
1118
|
+
if (gap || count) data.gap = getGapData(gap, count && repeat, tempImage.width, tempImage.height, box);
|
|
1119
|
+
break;
|
|
1120
|
+
|
|
1121
|
+
case "fit":
|
|
1122
|
+
case "cover":
|
|
1123
|
+
default:
|
|
1124
|
+
if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
|
|
1118
1125
|
}
|
|
1119
1126
|
if (!data.transform) {
|
|
1120
1127
|
if (box.x || box.y) {
|
|
@@ -1122,49 +1129,69 @@ function getPatternData(paint, box, image) {
|
|
|
1122
1129
|
translate(data.transform, box.x, box.y);
|
|
1123
1130
|
}
|
|
1124
1131
|
}
|
|
1125
|
-
if (scaleX && mode !==
|
|
1132
|
+
if (scaleX && mode !== "stretch") {
|
|
1126
1133
|
data.scaleX = scaleX;
|
|
1127
1134
|
data.scaleY = scaleY;
|
|
1128
1135
|
}
|
|
1129
1136
|
data.width = width;
|
|
1130
1137
|
data.height = height;
|
|
1131
|
-
if (opacity)
|
|
1132
|
-
|
|
1133
|
-
if (
|
|
1134
|
-
data.filters = filters;
|
|
1135
|
-
if (repeat)
|
|
1136
|
-
data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
|
|
1138
|
+
if (opacity) data.opacity = opacity;
|
|
1139
|
+
if (filters) data.filters = filters;
|
|
1140
|
+
if (repeat) data.repeat = core.isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
|
|
1137
1141
|
return data;
|
|
1138
1142
|
}
|
|
1139
1143
|
|
|
1140
|
-
|
|
1141
|
-
|
|
1144
|
+
function getGapData(gap, repeat, width, height, box) {
|
|
1145
|
+
let xGap, yGap;
|
|
1146
|
+
if (core.isObject(gap)) xGap = gap.x, yGap = gap.y; else xGap = yGap = gap;
|
|
1147
|
+
return {
|
|
1148
|
+
x: getGapValue(xGap, width, box.width, repeat && repeat.x),
|
|
1149
|
+
y: getGapValue(yGap, height, box.height, repeat && repeat.y)
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
function getGapValue(gap, size, totalSize, rows) {
|
|
1154
|
+
const auto = core.isString(gap) || rows;
|
|
1155
|
+
const remain = rows ? totalSize - rows * size : totalSize % size;
|
|
1156
|
+
const value = auto ? remain / ((rows || Math.floor(totalSize / size)) - 1) : gap;
|
|
1157
|
+
return gap === "auto" ? value < 0 ? 0 : value : value;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
let cache, box = new core.Bounds;
|
|
1161
|
+
|
|
1162
|
+
const {isSame: isSame} = core.BoundsHelper;
|
|
1163
|
+
|
|
1142
1164
|
function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
1143
1165
|
let leafPaint, event;
|
|
1144
1166
|
const image = core.ImageManager.get(paint);
|
|
1145
1167
|
if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
|
|
1146
1168
|
leafPaint = cache.leafPaint;
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1169
|
+
} else {
|
|
1170
|
+
leafPaint = {
|
|
1171
|
+
type: paint.type,
|
|
1172
|
+
image: image
|
|
1173
|
+
};
|
|
1174
|
+
if (image.hasAlphaPixel) leafPaint.isTransparent = true;
|
|
1175
|
+
cache = image.use > 1 ? {
|
|
1176
|
+
leafPaint: leafPaint,
|
|
1177
|
+
paint: paint,
|
|
1178
|
+
boxBounds: box.set(boxBounds)
|
|
1179
|
+
} : null;
|
|
1180
|
+
}
|
|
1181
|
+
if (firstUse || image.loading) event = {
|
|
1182
|
+
image: image,
|
|
1183
|
+
attrName: attrName,
|
|
1184
|
+
attrValue: paint
|
|
1185
|
+
};
|
|
1156
1186
|
if (image.ready) {
|
|
1157
1187
|
checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
|
|
1158
1188
|
if (firstUse) {
|
|
1159
1189
|
onLoad(ui, event);
|
|
1160
1190
|
onLoadSuccess(ui, event);
|
|
1161
1191
|
}
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
onLoadError(ui, event, image.error);
|
|
1166
|
-
}
|
|
1167
|
-
else {
|
|
1192
|
+
} else if (image.error) {
|
|
1193
|
+
if (firstUse) onLoadError(ui, event, image.error);
|
|
1194
|
+
} else {
|
|
1168
1195
|
if (firstUse) {
|
|
1169
1196
|
ignoreRender(ui, true);
|
|
1170
1197
|
onLoad(ui, event);
|
|
@@ -1173,79 +1200,84 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
|
1173
1200
|
ignoreRender(ui, false);
|
|
1174
1201
|
if (!ui.destroyed) {
|
|
1175
1202
|
if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
|
|
1176
|
-
if (image.hasAlphaPixel)
|
|
1177
|
-
|
|
1178
|
-
ui.forceUpdate('surface');
|
|
1203
|
+
if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
|
|
1204
|
+
ui.forceUpdate("surface");
|
|
1179
1205
|
}
|
|
1180
1206
|
onLoadSuccess(ui, event);
|
|
1181
1207
|
}
|
|
1182
1208
|
leafPaint.loadId = undefined;
|
|
1183
|
-
},
|
|
1209
|
+
}, error => {
|
|
1184
1210
|
ignoreRender(ui, false);
|
|
1185
1211
|
onLoadError(ui, event, error);
|
|
1186
1212
|
leafPaint.loadId = undefined;
|
|
1187
1213
|
});
|
|
1188
1214
|
if (ui.placeholderColor) {
|
|
1189
|
-
if (!ui.placeholderDelay)
|
|
1190
|
-
image.
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
ui.forceUpdate('surface');
|
|
1196
|
-
}
|
|
1197
|
-
}, ui.placeholderDelay);
|
|
1215
|
+
if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
|
|
1216
|
+
if (!image.ready) {
|
|
1217
|
+
image.isPlacehold = true;
|
|
1218
|
+
ui.forceUpdate("surface");
|
|
1219
|
+
}
|
|
1220
|
+
}, ui.placeholderDelay);
|
|
1198
1221
|
}
|
|
1199
1222
|
}
|
|
1200
1223
|
return leafPaint;
|
|
1201
1224
|
}
|
|
1225
|
+
|
|
1202
1226
|
function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
|
|
1203
|
-
if (attrName ===
|
|
1227
|
+
if (attrName === "fill" && !ui.__.__naturalWidth) {
|
|
1204
1228
|
const data = ui.__;
|
|
1205
1229
|
data.__naturalWidth = image.width / data.pixelRatio;
|
|
1206
1230
|
data.__naturalHeight = image.height / data.pixelRatio;
|
|
1207
1231
|
if (data.__autoSide) {
|
|
1208
|
-
ui.forceUpdate(
|
|
1232
|
+
ui.forceUpdate("width");
|
|
1209
1233
|
if (ui.__proxyData) {
|
|
1210
|
-
ui.setProxyAttr(
|
|
1211
|
-
ui.setProxyAttr(
|
|
1234
|
+
ui.setProxyAttr("width", data.width);
|
|
1235
|
+
ui.setProxyAttr("height", data.height);
|
|
1212
1236
|
}
|
|
1213
1237
|
return false;
|
|
1214
1238
|
}
|
|
1215
1239
|
}
|
|
1216
|
-
if (!leafPaint.data)
|
|
1217
|
-
createData(leafPaint, image, paint, boxBounds);
|
|
1240
|
+
if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
|
|
1218
1241
|
return true;
|
|
1219
1242
|
}
|
|
1243
|
+
|
|
1220
1244
|
function onLoad(ui, event) {
|
|
1221
1245
|
emit(ui, core.ImageEvent.LOAD, event);
|
|
1222
1246
|
}
|
|
1247
|
+
|
|
1223
1248
|
function onLoadSuccess(ui, event) {
|
|
1224
1249
|
emit(ui, core.ImageEvent.LOADED, event);
|
|
1225
1250
|
}
|
|
1251
|
+
|
|
1226
1252
|
function onLoadError(ui, event, error) {
|
|
1227
1253
|
event.error = error;
|
|
1228
|
-
ui.forceUpdate(
|
|
1254
|
+
ui.forceUpdate("surface");
|
|
1229
1255
|
emit(ui, core.ImageEvent.ERROR, event);
|
|
1230
1256
|
}
|
|
1257
|
+
|
|
1231
1258
|
function emit(ui, type, data) {
|
|
1232
|
-
if (ui.hasEvent(type))
|
|
1233
|
-
ui.emitEvent(new core.ImageEvent(type, data));
|
|
1259
|
+
if (ui.hasEvent(type)) ui.emitEvent(new core.ImageEvent(type, data));
|
|
1234
1260
|
}
|
|
1261
|
+
|
|
1235
1262
|
function ignoreRender(ui, value) {
|
|
1236
|
-
const { leafer
|
|
1237
|
-
if (leafer && leafer.viewReady)
|
|
1238
|
-
leafer.renderer.ignore = value;
|
|
1263
|
+
const {leafer: leafer} = ui;
|
|
1264
|
+
if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
|
|
1239
1265
|
}
|
|
1240
1266
|
|
|
1241
|
-
const {
|
|
1242
|
-
|
|
1267
|
+
const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
|
|
1268
|
+
|
|
1269
|
+
const {floor: floor, max: max, abs: abs} = Math;
|
|
1270
|
+
|
|
1243
1271
|
function createPattern(ui, paint, pixelRatio) {
|
|
1244
|
-
let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1245
|
-
const id = scaleX +
|
|
1272
|
+
let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1273
|
+
const id = scaleX + "-" + scaleY + "-" + pixelRatio;
|
|
1246
1274
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1247
|
-
const { image, data } = paint;
|
|
1248
|
-
let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
|
|
1275
|
+
const {image: image, data: data} = paint;
|
|
1276
|
+
let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
|
|
1277
|
+
scaleX *= pixelRatio;
|
|
1278
|
+
scaleY *= pixelRatio;
|
|
1279
|
+
const xGap = gap && gap.x * scaleX;
|
|
1280
|
+
const yGap = gap && gap.y * scaleY;
|
|
1249
1281
|
if (sx) {
|
|
1250
1282
|
sx = abs(sx);
|
|
1251
1283
|
sy = abs(sy);
|
|
@@ -1255,23 +1287,18 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1255
1287
|
scaleX *= sx;
|
|
1256
1288
|
scaleY *= sy;
|
|
1257
1289
|
}
|
|
1258
|
-
scaleX *= pixelRatio;
|
|
1259
|
-
scaleY *= pixelRatio;
|
|
1260
1290
|
width *= scaleX;
|
|
1261
1291
|
height *= scaleY;
|
|
1262
1292
|
const size = width * height;
|
|
1263
1293
|
if (!repeat) {
|
|
1264
|
-
if (size > core.Platform.image.maxCacheSize)
|
|
1265
|
-
return false;
|
|
1294
|
+
if (size > core.Platform.image.maxCacheSize) return false;
|
|
1266
1295
|
}
|
|
1267
1296
|
let maxSize = core.Platform.image.maxPatternSize;
|
|
1268
1297
|
if (!image.isSVG) {
|
|
1269
1298
|
const imageSize = image.width * image.height;
|
|
1270
|
-
if (maxSize > imageSize)
|
|
1271
|
-
maxSize = imageSize;
|
|
1299
|
+
if (maxSize > imageSize) maxSize = imageSize;
|
|
1272
1300
|
}
|
|
1273
|
-
if (size > maxSize)
|
|
1274
|
-
imageScale = Math.sqrt(size / maxSize);
|
|
1301
|
+
if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
|
|
1275
1302
|
if (imageScale) {
|
|
1276
1303
|
scaleX /= imageScale;
|
|
1277
1304
|
scaleY /= imageScale;
|
|
@@ -1285,97 +1312,95 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1285
1312
|
if (transform || scaleX !== 1 || scaleY !== 1) {
|
|
1286
1313
|
if (!imageMatrix) {
|
|
1287
1314
|
imageMatrix = get$1();
|
|
1288
|
-
if (transform)
|
|
1289
|
-
copy$1(imageMatrix, transform);
|
|
1315
|
+
if (transform) copy$1(imageMatrix, transform);
|
|
1290
1316
|
}
|
|
1291
1317
|
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1292
1318
|
}
|
|
1293
|
-
|
|
1294
|
-
|
|
1319
|
+
if (imageMatrix) {
|
|
1320
|
+
const canvasWidth = width + (xGap || 0), canvasHeight = height + (yGap || 0);
|
|
1321
|
+
scale(imageMatrix, canvasWidth / max(floor(canvasWidth), 1), canvasHeight / max(floor(canvasHeight), 1));
|
|
1322
|
+
}
|
|
1323
|
+
const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap);
|
|
1324
|
+
const pattern = image.getPattern(canvas, repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
|
|
1295
1325
|
paint.style = pattern;
|
|
1296
1326
|
paint.patternId = id;
|
|
1297
1327
|
return true;
|
|
1298
|
-
}
|
|
1299
|
-
else {
|
|
1328
|
+
} else {
|
|
1300
1329
|
return false;
|
|
1301
1330
|
}
|
|
1302
1331
|
}
|
|
1303
1332
|
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
function
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1333
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
1334
|
+
function adopt(value) {
|
|
1335
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
1336
|
+
resolve(value);
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
1340
|
+
function fulfilled(value) {
|
|
1341
|
+
try {
|
|
1342
|
+
step(generator.next(value));
|
|
1343
|
+
} catch (e) {
|
|
1344
|
+
reject(e);
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
function rejected(value) {
|
|
1348
|
+
try {
|
|
1349
|
+
step(generator["throw"](value));
|
|
1350
|
+
} catch (e) {
|
|
1351
|
+
reject(e);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
function step(result) {
|
|
1355
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
1356
|
+
}
|
|
1357
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
1362
|
+
var e = new Error(message);
|
|
1363
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1334
1364
|
};
|
|
1335
1365
|
|
|
1336
1366
|
function checkImage(ui, canvas, paint, allowDraw) {
|
|
1337
|
-
const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1338
|
-
const { pixelRatio
|
|
1339
|
-
if (!data ||
|
|
1367
|
+
const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1368
|
+
const {pixelRatio: pixelRatio} = canvas, {data: data} = paint;
|
|
1369
|
+
if (!data || paint.patternId === scaleX + "-" + scaleY + "-" + pixelRatio && !draw.Export.running) {
|
|
1340
1370
|
return false;
|
|
1341
|
-
}
|
|
1342
|
-
else {
|
|
1371
|
+
} else {
|
|
1343
1372
|
if (allowDraw) {
|
|
1344
1373
|
if (data.repeat) {
|
|
1345
1374
|
allowDraw = false;
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
let { width, height } = data;
|
|
1375
|
+
} else {
|
|
1376
|
+
if (!(paint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
|
|
1377
|
+
let {width: width, height: height} = data;
|
|
1350
1378
|
width *= scaleX * pixelRatio;
|
|
1351
1379
|
height *= scaleY * pixelRatio;
|
|
1352
1380
|
if (data.scaleX) {
|
|
1353
1381
|
width *= data.scaleX;
|
|
1354
1382
|
height *= data.scaleY;
|
|
1355
1383
|
}
|
|
1356
|
-
allowDraw =
|
|
1384
|
+
allowDraw = width * height > core.Platform.image.maxCacheSize;
|
|
1357
1385
|
}
|
|
1358
1386
|
}
|
|
1359
1387
|
}
|
|
1360
1388
|
if (allowDraw) {
|
|
1361
1389
|
if (ui.__.__isFastShadow) {
|
|
1362
|
-
canvas.fillStyle = paint.style ||
|
|
1390
|
+
canvas.fillStyle = paint.style || "#000";
|
|
1363
1391
|
canvas.fill();
|
|
1364
1392
|
}
|
|
1365
1393
|
drawImage(ui, canvas, paint, data);
|
|
1366
1394
|
return true;
|
|
1367
|
-
}
|
|
1368
|
-
else {
|
|
1395
|
+
} else {
|
|
1369
1396
|
if (!paint.style || paint.sync || draw.Export.running) {
|
|
1370
1397
|
createPattern(ui, paint, pixelRatio);
|
|
1371
|
-
}
|
|
1372
|
-
else {
|
|
1398
|
+
} else {
|
|
1373
1399
|
if (!paint.patternTask) {
|
|
1374
|
-
paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*
|
|
1400
|
+
paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
|
|
1375
1401
|
paint.patternTask = null;
|
|
1376
|
-
if (canvas.bounds.hit(ui.__nowWorld))
|
|
1377
|
-
|
|
1378
|
-
ui.forceUpdate('surface');
|
|
1402
|
+
if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
|
|
1403
|
+
ui.forceUpdate("surface");
|
|
1379
1404
|
}), 300);
|
|
1380
1405
|
}
|
|
1381
1406
|
}
|
|
@@ -1383,39 +1408,35 @@ function checkImage(ui, canvas, paint, allowDraw) {
|
|
|
1383
1408
|
}
|
|
1384
1409
|
}
|
|
1385
1410
|
}
|
|
1411
|
+
|
|
1386
1412
|
function drawImage(ui, canvas, paint, data) {
|
|
1387
1413
|
canvas.save();
|
|
1388
1414
|
canvas.clipUI(ui);
|
|
1389
|
-
if (paint.blendMode)
|
|
1390
|
-
|
|
1391
|
-
if (data.
|
|
1392
|
-
canvas.opacity *= data.opacity;
|
|
1393
|
-
if (data.transform)
|
|
1394
|
-
canvas.transform(data.transform);
|
|
1415
|
+
if (paint.blendMode) canvas.blendMode = paint.blendMode;
|
|
1416
|
+
if (data.opacity) canvas.opacity *= data.opacity;
|
|
1417
|
+
if (data.transform) canvas.transform(data.transform);
|
|
1395
1418
|
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
|
|
1396
1419
|
canvas.restore();
|
|
1397
1420
|
}
|
|
1398
1421
|
|
|
1399
1422
|
function recycleImage(attrName, data) {
|
|
1400
|
-
const paints = data[
|
|
1401
|
-
if (paints
|
|
1423
|
+
const paints = data["_" + attrName];
|
|
1424
|
+
if (core.isArray(paints)) {
|
|
1402
1425
|
let paint, image, recycleMap, input, url;
|
|
1403
1426
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
1404
1427
|
paint = paints[i];
|
|
1405
1428
|
image = paint.image;
|
|
1406
1429
|
url = image && image.url;
|
|
1407
1430
|
if (url) {
|
|
1408
|
-
if (!recycleMap)
|
|
1409
|
-
recycleMap = {};
|
|
1431
|
+
if (!recycleMap) recycleMap = {};
|
|
1410
1432
|
recycleMap[url] = true;
|
|
1411
1433
|
core.ImageManager.recycle(image);
|
|
1412
1434
|
if (image.loading) {
|
|
1413
1435
|
if (!input) {
|
|
1414
|
-
input =
|
|
1415
|
-
if (!(input
|
|
1416
|
-
input = [input];
|
|
1436
|
+
input = data.__input && data.__input[attrName] || [];
|
|
1437
|
+
if (!core.isArray(input)) input = [ input ];
|
|
1417
1438
|
}
|
|
1418
|
-
image.unload(paints[i].loadId, !input.some(
|
|
1439
|
+
image.unload(paints[i].loadId, !input.some(item => item.url === url));
|
|
1419
1440
|
}
|
|
1420
1441
|
}
|
|
1421
1442
|
}
|
|
@@ -1425,75 +1446,85 @@ function recycleImage(attrName, data) {
|
|
|
1425
1446
|
}
|
|
1426
1447
|
|
|
1427
1448
|
const PaintImageModule = {
|
|
1428
|
-
image,
|
|
1429
|
-
checkImage,
|
|
1430
|
-
createPattern,
|
|
1431
|
-
recycleImage,
|
|
1432
|
-
createData,
|
|
1433
|
-
getPatternData,
|
|
1434
|
-
fillOrFitMode,
|
|
1435
|
-
clipMode,
|
|
1436
|
-
repeatMode
|
|
1449
|
+
image: image,
|
|
1450
|
+
checkImage: checkImage,
|
|
1451
|
+
createPattern: createPattern,
|
|
1452
|
+
recycleImage: recycleImage,
|
|
1453
|
+
createData: createData,
|
|
1454
|
+
getPatternData: getPatternData,
|
|
1455
|
+
fillOrFitMode: fillOrFitMode,
|
|
1456
|
+
clipMode: clipMode,
|
|
1457
|
+
repeatMode: repeatMode
|
|
1437
1458
|
};
|
|
1438
1459
|
|
|
1439
|
-
const {
|
|
1460
|
+
const {toPoint: toPoint$2} = core.AroundHelper, {hasTransparent: hasTransparent} = draw.ColorConvert;
|
|
1461
|
+
|
|
1440
1462
|
const realFrom$2 = {};
|
|
1463
|
+
|
|
1441
1464
|
const realTo$2 = {};
|
|
1465
|
+
|
|
1442
1466
|
function linearGradient(paint, box) {
|
|
1443
|
-
let { from, to, type, opacity } = paint;
|
|
1444
|
-
toPoint$2(from ||
|
|
1445
|
-
toPoint$2(to ||
|
|
1467
|
+
let {from: from, to: to, type: type, opacity: opacity} = paint;
|
|
1468
|
+
toPoint$2(from || "top", box, realFrom$2);
|
|
1469
|
+
toPoint$2(to || "bottom", box, realTo$2);
|
|
1446
1470
|
const style = core.Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
|
|
1447
|
-
const data = {
|
|
1471
|
+
const data = {
|
|
1472
|
+
type: type,
|
|
1473
|
+
style: style
|
|
1474
|
+
};
|
|
1448
1475
|
applyStops(data, style, paint.stops, opacity);
|
|
1449
1476
|
return data;
|
|
1450
1477
|
}
|
|
1478
|
+
|
|
1451
1479
|
function applyStops(data, gradient, stops, opacity) {
|
|
1452
1480
|
if (stops) {
|
|
1453
1481
|
let stop, color, offset, isTransparent;
|
|
1454
1482
|
for (let i = 0, len = stops.length; i < len; i++) {
|
|
1455
1483
|
stop = stops[i];
|
|
1456
|
-
if (
|
|
1457
|
-
|
|
1458
|
-
else
|
|
1459
|
-
offset = stop.offset, color = draw.ColorConvert.string(stop.color, opacity);
|
|
1484
|
+
if (core.isString(stop)) offset = i / (len - 1), color = draw.ColorConvert.string(stop, opacity); else offset = stop.offset,
|
|
1485
|
+
color = draw.ColorConvert.string(stop.color, opacity);
|
|
1460
1486
|
gradient.addColorStop(offset, color);
|
|
1461
|
-
if (!isTransparent && hasTransparent(color))
|
|
1462
|
-
isTransparent = true;
|
|
1487
|
+
if (!isTransparent && hasTransparent(color)) isTransparent = true;
|
|
1463
1488
|
}
|
|
1464
|
-
if (isTransparent)
|
|
1465
|
-
data.isTransparent = true;
|
|
1489
|
+
if (isTransparent) data.isTransparent = true;
|
|
1466
1490
|
}
|
|
1467
1491
|
}
|
|
1468
1492
|
|
|
1469
|
-
const { getAngle, getDistance: getDistance$1
|
|
1470
|
-
|
|
1471
|
-
const {
|
|
1493
|
+
const {getAngle: getAngle, getDistance: getDistance$1} = core.PointHelper;
|
|
1494
|
+
|
|
1495
|
+
const {get: get, rotateOfOuter: rotateOfOuter, scaleOfOuter: scaleOfOuter} = core.MatrixHelper;
|
|
1496
|
+
|
|
1497
|
+
const {toPoint: toPoint$1} = core.AroundHelper;
|
|
1498
|
+
|
|
1472
1499
|
const realFrom$1 = {};
|
|
1500
|
+
|
|
1473
1501
|
const realTo$1 = {};
|
|
1502
|
+
|
|
1474
1503
|
function radialGradient(paint, box) {
|
|
1475
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1476
|
-
toPoint$1(from ||
|
|
1477
|
-
toPoint$1(to ||
|
|
1504
|
+
let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
|
|
1505
|
+
toPoint$1(from || "center", box, realFrom$1);
|
|
1506
|
+
toPoint$1(to || "bottom", box, realTo$1);
|
|
1478
1507
|
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));
|
|
1479
|
-
const data = {
|
|
1508
|
+
const data = {
|
|
1509
|
+
type: type,
|
|
1510
|
+
style: style
|
|
1511
|
+
};
|
|
1480
1512
|
applyStops(data, style, paint.stops, opacity);
|
|
1481
1513
|
const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
|
|
1482
|
-
if (transform)
|
|
1483
|
-
data.transform = transform;
|
|
1514
|
+
if (transform) data.transform = transform;
|
|
1484
1515
|
return data;
|
|
1485
1516
|
}
|
|
1517
|
+
|
|
1486
1518
|
function getTransform(box, from, to, stretch, rotate90) {
|
|
1487
1519
|
let transform;
|
|
1488
|
-
const { width, height } = box;
|
|
1520
|
+
const {width: width, height: height} = box;
|
|
1489
1521
|
if (width !== height || stretch) {
|
|
1490
1522
|
const angle = getAngle(from, to);
|
|
1491
1523
|
transform = get();
|
|
1492
1524
|
if (rotate90) {
|
|
1493
1525
|
scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
|
|
1494
1526
|
rotateOfOuter(transform, from, angle + 90);
|
|
1495
|
-
}
|
|
1496
|
-
else {
|
|
1527
|
+
} else {
|
|
1497
1528
|
scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
|
|
1498
1529
|
rotateOfOuter(transform, from, angle);
|
|
1499
1530
|
}
|
|
@@ -1501,81 +1532,94 @@ function getTransform(box, from, to, stretch, rotate90) {
|
|
|
1501
1532
|
return transform;
|
|
1502
1533
|
}
|
|
1503
1534
|
|
|
1504
|
-
const { getDistance
|
|
1505
|
-
|
|
1535
|
+
const {getDistance: getDistance} = core.PointHelper;
|
|
1536
|
+
|
|
1537
|
+
const {toPoint: toPoint} = core.AroundHelper;
|
|
1538
|
+
|
|
1506
1539
|
const realFrom = {};
|
|
1540
|
+
|
|
1507
1541
|
const realTo = {};
|
|
1542
|
+
|
|
1508
1543
|
function conicGradient(paint, box) {
|
|
1509
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1510
|
-
toPoint(from ||
|
|
1511
|
-
toPoint(to ||
|
|
1544
|
+
let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
|
|
1545
|
+
toPoint(from || "center", box, realFrom);
|
|
1546
|
+
toPoint(to || "bottom", box, realTo);
|
|
1512
1547
|
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));
|
|
1513
|
-
const data = {
|
|
1548
|
+
const data = {
|
|
1549
|
+
type: type,
|
|
1550
|
+
style: style
|
|
1551
|
+
};
|
|
1514
1552
|
applyStops(data, style, paint.stops, opacity);
|
|
1515
1553
|
const transform = getTransform(box, realFrom, realTo, stretch || 1, core.Platform.conicGradientRotate90);
|
|
1516
|
-
if (transform)
|
|
1517
|
-
data.transform = transform;
|
|
1554
|
+
if (transform) data.transform = transform;
|
|
1518
1555
|
return data;
|
|
1519
1556
|
}
|
|
1520
1557
|
|
|
1521
1558
|
const PaintGradientModule = {
|
|
1522
|
-
linearGradient,
|
|
1523
|
-
radialGradient,
|
|
1524
|
-
conicGradient,
|
|
1525
|
-
getTransform
|
|
1559
|
+
linearGradient: linearGradient,
|
|
1560
|
+
radialGradient: radialGradient,
|
|
1561
|
+
conicGradient: conicGradient,
|
|
1562
|
+
getTransform: getTransform
|
|
1526
1563
|
};
|
|
1527
1564
|
|
|
1528
|
-
const { copy, toOffsetOutBounds: toOffsetOutBounds$1
|
|
1565
|
+
const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = core.BoundsHelper;
|
|
1566
|
+
|
|
1529
1567
|
const tempBounds = {};
|
|
1568
|
+
|
|
1530
1569
|
const offsetOutBounds$1 = {};
|
|
1570
|
+
|
|
1531
1571
|
function shadow(ui, current, shape) {
|
|
1532
1572
|
let copyBounds, spreadScale;
|
|
1533
|
-
const {
|
|
1534
|
-
const { shadow
|
|
1535
|
-
const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
|
|
1573
|
+
const {__nowWorld: nowWorld, __layout: __layout} = ui;
|
|
1574
|
+
const {shadow: shadow} = ui.__;
|
|
1575
|
+
const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
|
|
1536
1576
|
const other = current.getSameCanvas();
|
|
1537
1577
|
const end = shadow.length - 1;
|
|
1538
1578
|
toOffsetOutBounds$1(bounds, offsetOutBounds$1);
|
|
1539
1579
|
shadow.forEach((item, index) => {
|
|
1540
|
-
|
|
1541
|
-
|
|
1580
|
+
let otherScale = 1;
|
|
1581
|
+
if (item.scaleFixed) {
|
|
1582
|
+
const sx = Math.abs(nowWorld.scaleX);
|
|
1583
|
+
if (sx > 1) otherScale = 1 / sx;
|
|
1584
|
+
}
|
|
1585
|
+
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));
|
|
1586
|
+
spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
|
|
1542
1587
|
drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
|
|
1543
1588
|
copyBounds = bounds;
|
|
1544
1589
|
if (item.box) {
|
|
1545
1590
|
other.restore();
|
|
1546
1591
|
other.save();
|
|
1547
1592
|
if (worldCanvas) {
|
|
1548
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
1593
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
1549
1594
|
copyBounds = nowWorld;
|
|
1550
1595
|
}
|
|
1551
|
-
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
1596
|
+
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
|
|
1552
1597
|
}
|
|
1553
1598
|
core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1554
|
-
if (end && index < end)
|
|
1555
|
-
other.clearWorld(copyBounds, true);
|
|
1599
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
1556
1600
|
});
|
|
1557
1601
|
other.recycle(copyBounds);
|
|
1558
1602
|
}
|
|
1603
|
+
|
|
1559
1604
|
function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
1560
|
-
const { bounds, shapeBounds } = shape;
|
|
1605
|
+
const {bounds: bounds, shapeBounds: shapeBounds} = shape;
|
|
1561
1606
|
if (core.Platform.fullImageShadow) {
|
|
1562
1607
|
copy(tempBounds, canvas.bounds);
|
|
1563
|
-
tempBounds.x +=
|
|
1564
|
-
tempBounds.y +=
|
|
1608
|
+
tempBounds.x += outBounds.x - shapeBounds.x;
|
|
1609
|
+
tempBounds.y += outBounds.y - shapeBounds.y;
|
|
1565
1610
|
if (spreadScale) {
|
|
1566
|
-
const {
|
|
1567
|
-
tempBounds.x -= (bounds.x + (
|
|
1568
|
-
tempBounds.y -= (bounds.y + (
|
|
1611
|
+
const {fitMatrix: fitMatrix} = shape;
|
|
1612
|
+
tempBounds.x -= (bounds.x + (fitMatrix ? fitMatrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
|
|
1613
|
+
tempBounds.y -= (bounds.y + (fitMatrix ? fitMatrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
|
|
1569
1614
|
tempBounds.width *= spreadScale;
|
|
1570
1615
|
tempBounds.height *= spreadScale;
|
|
1571
1616
|
}
|
|
1572
1617
|
canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
|
|
1573
|
-
}
|
|
1574
|
-
else {
|
|
1618
|
+
} else {
|
|
1575
1619
|
if (spreadScale) {
|
|
1576
1620
|
copy(tempBounds, outBounds);
|
|
1577
|
-
tempBounds.x -=
|
|
1578
|
-
tempBounds.y -=
|
|
1621
|
+
tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
|
|
1622
|
+
tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
|
|
1579
1623
|
tempBounds.width *= spreadScale;
|
|
1580
1624
|
tempBounds.height *= spreadScale;
|
|
1581
1625
|
}
|
|
@@ -1583,174 +1627,184 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
|
1583
1627
|
}
|
|
1584
1628
|
}
|
|
1585
1629
|
|
|
1586
|
-
const { toOffsetOutBounds
|
|
1630
|
+
const {toOffsetOutBounds: toOffsetOutBounds} = core.BoundsHelper;
|
|
1631
|
+
|
|
1587
1632
|
const offsetOutBounds = {};
|
|
1633
|
+
|
|
1588
1634
|
function innerShadow(ui, current, shape) {
|
|
1589
1635
|
let copyBounds, spreadScale;
|
|
1590
|
-
const {
|
|
1591
|
-
const { innerShadow
|
|
1592
|
-
const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
|
|
1636
|
+
const {__nowWorld: nowWorld, __layout: __layout} = ui;
|
|
1637
|
+
const {innerShadow: innerShadow} = ui.__;
|
|
1638
|
+
const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
|
|
1593
1639
|
const other = current.getSameCanvas();
|
|
1594
1640
|
const end = innerShadow.length - 1;
|
|
1595
1641
|
toOffsetOutBounds(bounds, offsetOutBounds);
|
|
1596
1642
|
innerShadow.forEach((item, index) => {
|
|
1643
|
+
let otherScale = 1;
|
|
1644
|
+
if (item.scaleFixed) {
|
|
1645
|
+
const sx = Math.abs(nowWorld.scaleX);
|
|
1646
|
+
if (sx > 1) otherScale = 1 / sx;
|
|
1647
|
+
}
|
|
1597
1648
|
other.save();
|
|
1598
|
-
other.setWorldShadow(
|
|
1599
|
-
spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) : 0;
|
|
1649
|
+
other.setWorldShadow(offsetOutBounds.offsetX + item.x * scaleX * otherScale, offsetOutBounds.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale);
|
|
1650
|
+
spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
|
|
1600
1651
|
drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
|
|
1601
1652
|
other.restore();
|
|
1602
1653
|
if (worldCanvas) {
|
|
1603
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
1604
|
-
other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
1654
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
1655
|
+
other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
|
|
1605
1656
|
copyBounds = nowWorld;
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out');
|
|
1657
|
+
} else {
|
|
1658
|
+
other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
|
|
1609
1659
|
copyBounds = bounds;
|
|
1610
1660
|
}
|
|
1611
|
-
other.fillWorld(copyBounds, draw.ColorConvert.string(item.color),
|
|
1661
|
+
other.fillWorld(copyBounds, draw.ColorConvert.string(item.color), "source-in");
|
|
1612
1662
|
core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1613
|
-
if (end && index < end)
|
|
1614
|
-
other.clearWorld(copyBounds, true);
|
|
1663
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
1615
1664
|
});
|
|
1616
1665
|
other.recycle(copyBounds);
|
|
1617
1666
|
}
|
|
1618
1667
|
|
|
1619
1668
|
function blur(ui, current, origin) {
|
|
1620
|
-
const { blur
|
|
1669
|
+
const {blur: blur} = ui.__;
|
|
1621
1670
|
origin.setWorldBlur(blur * ui.__nowWorld.a);
|
|
1622
1671
|
origin.copyWorldToInner(current, ui.__nowWorld, ui.__layout.renderBounds);
|
|
1623
|
-
origin.filter =
|
|
1672
|
+
origin.filter = "none";
|
|
1624
1673
|
}
|
|
1625
1674
|
|
|
1626
|
-
function backgroundBlur(_ui, _current, _shape) {
|
|
1627
|
-
}
|
|
1675
|
+
function backgroundBlur(_ui, _current, _shape) {}
|
|
1628
1676
|
|
|
1629
1677
|
const EffectModule = {
|
|
1630
|
-
shadow,
|
|
1631
|
-
innerShadow,
|
|
1632
|
-
blur,
|
|
1633
|
-
backgroundBlur
|
|
1678
|
+
shadow: shadow,
|
|
1679
|
+
innerShadow: innerShadow,
|
|
1680
|
+
blur: blur,
|
|
1681
|
+
backgroundBlur: backgroundBlur
|
|
1634
1682
|
};
|
|
1635
1683
|
|
|
1636
|
-
const { excludeRenderBounds
|
|
1637
|
-
|
|
1684
|
+
const {excludeRenderBounds: excludeRenderBounds} = core.LeafBoundsHelper;
|
|
1685
|
+
|
|
1686
|
+
let usedGrayscaleAlpha;
|
|
1687
|
+
|
|
1688
|
+
draw.Group.prototype.__renderMask = function(canvas, options) {
|
|
1638
1689
|
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
1639
|
-
const { children
|
|
1690
|
+
const {children: children} = this;
|
|
1640
1691
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
1641
1692
|
child = children[i], mask = child.__.mask;
|
|
1642
1693
|
if (mask) {
|
|
1643
1694
|
if (currentMask) {
|
|
1644
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1695
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
1645
1696
|
maskCanvas = contentCanvas = null;
|
|
1646
1697
|
}
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
currentMask = 'path';
|
|
1698
|
+
maskOpacity = child.__.opacity;
|
|
1699
|
+
usedGrayscaleAlpha = false;
|
|
1700
|
+
if (mask === "path" || mask === "clipping-path") {
|
|
1701
|
+
if (maskOpacity < 1) {
|
|
1702
|
+
currentMask = "opacity-path";
|
|
1703
|
+
if (!contentCanvas) contentCanvas = getCanvas(canvas);
|
|
1704
|
+
} else {
|
|
1705
|
+
currentMask = "path";
|
|
1656
1706
|
canvas.save();
|
|
1657
1707
|
}
|
|
1658
1708
|
child.__clip(contentCanvas || canvas, options);
|
|
1659
|
-
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
if (!
|
|
1663
|
-
maskCanvas = getCanvas(canvas);
|
|
1664
|
-
if (!contentCanvas)
|
|
1665
|
-
contentCanvas = getCanvas(canvas);
|
|
1709
|
+
} else {
|
|
1710
|
+
currentMask = mask === "grayscale" ? "grayscale" : "alpha";
|
|
1711
|
+
if (!maskCanvas) maskCanvas = getCanvas(canvas);
|
|
1712
|
+
if (!contentCanvas) contentCanvas = getCanvas(canvas);
|
|
1666
1713
|
child.__render(maskCanvas, options);
|
|
1667
1714
|
}
|
|
1668
|
-
if (mask ===
|
|
1669
|
-
excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
1715
|
+
if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
1670
1716
|
continue;
|
|
1671
1717
|
}
|
|
1718
|
+
const childBlendMode = maskOpacity === 1 && child.__.__blendMode;
|
|
1719
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, false);
|
|
1672
1720
|
excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
|
|
1721
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, childBlendMode, false);
|
|
1673
1722
|
}
|
|
1674
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1723
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
1675
1724
|
};
|
|
1676
|
-
|
|
1725
|
+
|
|
1726
|
+
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity, blendMode, recycle) {
|
|
1677
1727
|
switch (maskMode) {
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1728
|
+
case "grayscale":
|
|
1729
|
+
if (!usedGrayscaleAlpha) usedGrayscaleAlpha = true, maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
|
|
1730
|
+
|
|
1731
|
+
case "alpha":
|
|
1732
|
+
usePixelMask(leaf, canvas, contentCanvas, maskCanvas, blendMode, recycle);
|
|
1733
|
+
break;
|
|
1734
|
+
|
|
1735
|
+
case "opacity-path":
|
|
1736
|
+
copyContent(leaf, canvas, contentCanvas, maskOpacity, blendMode, recycle);
|
|
1737
|
+
break;
|
|
1738
|
+
|
|
1739
|
+
case "path":
|
|
1740
|
+
if (recycle) canvas.restore();
|
|
1688
1741
|
}
|
|
1689
1742
|
}
|
|
1743
|
+
|
|
1690
1744
|
function getCanvas(canvas) {
|
|
1691
1745
|
return canvas.getSameCanvas(false, true);
|
|
1692
1746
|
}
|
|
1693
|
-
|
|
1747
|
+
|
|
1748
|
+
function usePixelMask(leaf, canvas, content, mask, blendMode, recycle) {
|
|
1694
1749
|
const realBounds = leaf.__nowWorld;
|
|
1695
1750
|
content.resetTransform();
|
|
1696
1751
|
content.opacity = 1;
|
|
1697
1752
|
content.useMask(mask, realBounds);
|
|
1698
|
-
mask.recycle(realBounds);
|
|
1699
|
-
copyContent(leaf, canvas, content, 1);
|
|
1753
|
+
if (recycle) mask.recycle(realBounds);
|
|
1754
|
+
copyContent(leaf, canvas, content, 1, blendMode, recycle);
|
|
1700
1755
|
}
|
|
1701
|
-
|
|
1756
|
+
|
|
1757
|
+
function copyContent(leaf, canvas, content, maskOpacity, blendMode, recycle) {
|
|
1702
1758
|
const realBounds = leaf.__nowWorld;
|
|
1703
1759
|
canvas.resetTransform();
|
|
1704
1760
|
canvas.opacity = maskOpacity;
|
|
1705
|
-
canvas.copyWorld(content, realBounds);
|
|
1706
|
-
content.recycle(realBounds);
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
const money =
|
|
1710
|
-
|
|
1711
|
-
const
|
|
1712
|
-
|
|
1713
|
-
const
|
|
1714
|
-
|
|
1715
|
-
const
|
|
1716
|
-
|
|
1717
|
-
const
|
|
1718
|
-
|
|
1719
|
-
const
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
[0x31C0, 0x31EF],
|
|
1734
|
-
[0x3200, 0x32FF],
|
|
1735
|
-
[0x3300, 0x33FF],
|
|
1736
|
-
[0xF900, 0xFAFF],
|
|
1737
|
-
[0xFE30, 0xFE4F],
|
|
1738
|
-
[0x1F200, 0x1F2FF],
|
|
1739
|
-
[0x2F800, 0x2FA1F],
|
|
1740
|
-
];
|
|
1741
|
-
const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join('|'));
|
|
1761
|
+
canvas.copyWorld(content, realBounds, undefined, blendMode);
|
|
1762
|
+
recycle ? content.recycle(realBounds) : content.clearWorld(realBounds, true);
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
const money = "¥¥$€££¢¢";
|
|
1766
|
+
|
|
1767
|
+
const letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
|
|
1768
|
+
|
|
1769
|
+
const langBefore = "《(「〈『〖【〔{┌<‘“=" + money;
|
|
1770
|
+
|
|
1771
|
+
const langAfter = "》)」〉』〗】〕}┐>’”!?,、。:;‰";
|
|
1772
|
+
|
|
1773
|
+
const langSymbol = "≮≯≈≠=…";
|
|
1774
|
+
|
|
1775
|
+
const langBreak$1 = "—/~|┆·";
|
|
1776
|
+
|
|
1777
|
+
const beforeChar = "{[(<'\"" + langBefore;
|
|
1778
|
+
|
|
1779
|
+
const afterChar = ">)]}%!?,.:;'\"" + langAfter;
|
|
1780
|
+
|
|
1781
|
+
const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
|
|
1782
|
+
|
|
1783
|
+
const breakChar = "- " + langBreak$1;
|
|
1784
|
+
|
|
1785
|
+
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 ] ];
|
|
1786
|
+
|
|
1787
|
+
const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
|
|
1788
|
+
|
|
1742
1789
|
function mapChar(str) {
|
|
1743
1790
|
const map = {};
|
|
1744
|
-
str.split(
|
|
1791
|
+
str.split("").forEach(char => map[char] = true);
|
|
1745
1792
|
return map;
|
|
1746
1793
|
}
|
|
1794
|
+
|
|
1747
1795
|
const letterMap = mapChar(letter);
|
|
1796
|
+
|
|
1748
1797
|
const beforeMap = mapChar(beforeChar);
|
|
1798
|
+
|
|
1749
1799
|
const afterMap = mapChar(afterChar);
|
|
1800
|
+
|
|
1750
1801
|
const symbolMap = mapChar(symbolChar);
|
|
1802
|
+
|
|
1751
1803
|
const breakMap = mapChar(breakChar);
|
|
1804
|
+
|
|
1752
1805
|
var CharType;
|
|
1753
|
-
|
|
1806
|
+
|
|
1807
|
+
(function(CharType) {
|
|
1754
1808
|
CharType[CharType["Letter"] = 0] = "Letter";
|
|
1755
1809
|
CharType[CharType["Single"] = 1] = "Single";
|
|
1756
1810
|
CharType[CharType["Before"] = 2] = "Before";
|
|
@@ -1758,179 +1812,175 @@ var CharType;
|
|
|
1758
1812
|
CharType[CharType["Symbol"] = 4] = "Symbol";
|
|
1759
1813
|
CharType[CharType["Break"] = 5] = "Break";
|
|
1760
1814
|
})(CharType || (CharType = {}));
|
|
1761
|
-
|
|
1815
|
+
|
|
1816
|
+
const {Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1} = CharType;
|
|
1817
|
+
|
|
1762
1818
|
function getCharType(char) {
|
|
1763
1819
|
if (letterMap[char]) {
|
|
1764
1820
|
return Letter$1;
|
|
1765
|
-
}
|
|
1766
|
-
else if (breakMap[char]) {
|
|
1821
|
+
} else if (breakMap[char]) {
|
|
1767
1822
|
return Break$1;
|
|
1768
|
-
}
|
|
1769
|
-
else if (beforeMap[char]) {
|
|
1823
|
+
} else if (beforeMap[char]) {
|
|
1770
1824
|
return Before$1;
|
|
1771
|
-
}
|
|
1772
|
-
else if (afterMap[char]) {
|
|
1825
|
+
} else if (afterMap[char]) {
|
|
1773
1826
|
return After$1;
|
|
1774
|
-
}
|
|
1775
|
-
else if (symbolMap[char]) {
|
|
1827
|
+
} else if (symbolMap[char]) {
|
|
1776
1828
|
return Symbol$1;
|
|
1777
|
-
}
|
|
1778
|
-
else if (cjkReg.test(char)) {
|
|
1829
|
+
} else if (cjkReg.test(char)) {
|
|
1779
1830
|
return Single$1;
|
|
1780
|
-
}
|
|
1781
|
-
else {
|
|
1831
|
+
} else {
|
|
1782
1832
|
return Letter$1;
|
|
1783
1833
|
}
|
|
1784
1834
|
}
|
|
1785
1835
|
|
|
1786
1836
|
const TextRowHelper = {
|
|
1787
1837
|
trimRight(row) {
|
|
1788
|
-
const { words
|
|
1838
|
+
const {words: words} = row;
|
|
1789
1839
|
let trimRight = 0, len = words.length, char;
|
|
1790
1840
|
for (let i = len - 1; i > -1; i--) {
|
|
1791
1841
|
char = words[i].data[0];
|
|
1792
|
-
if (char.char ===
|
|
1842
|
+
if (char.char === " ") {
|
|
1793
1843
|
trimRight++;
|
|
1794
1844
|
row.width -= char.width;
|
|
1795
|
-
}
|
|
1796
|
-
else {
|
|
1845
|
+
} else {
|
|
1797
1846
|
break;
|
|
1798
1847
|
}
|
|
1799
1848
|
}
|
|
1800
|
-
if (trimRight)
|
|
1801
|
-
words.splice(len - trimRight, trimRight);
|
|
1849
|
+
if (trimRight) words.splice(len - trimRight, trimRight);
|
|
1802
1850
|
}
|
|
1803
1851
|
};
|
|
1804
1852
|
|
|
1805
1853
|
function getTextCase(char, textCase, firstChar) {
|
|
1806
1854
|
switch (textCase) {
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1855
|
+
case "title":
|
|
1856
|
+
return firstChar ? char.toUpperCase() : char;
|
|
1857
|
+
|
|
1858
|
+
case "upper":
|
|
1859
|
+
return char.toUpperCase();
|
|
1860
|
+
|
|
1861
|
+
case "lower":
|
|
1862
|
+
return char.toLowerCase();
|
|
1863
|
+
|
|
1864
|
+
default:
|
|
1865
|
+
return char;
|
|
1815
1866
|
}
|
|
1816
1867
|
}
|
|
1817
1868
|
|
|
1818
|
-
const { trimRight
|
|
1819
|
-
|
|
1869
|
+
const {trimRight: trimRight} = TextRowHelper;
|
|
1870
|
+
|
|
1871
|
+
const {Letter: Letter, Single: Single, Before: Before, After: After, Symbol: Symbol, Break: Break} = CharType;
|
|
1872
|
+
|
|
1820
1873
|
let word, row, wordWidth, rowWidth, realWidth;
|
|
1874
|
+
|
|
1821
1875
|
let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
|
|
1876
|
+
|
|
1822
1877
|
let textDrawData, rows = [], bounds, findMaxWidth;
|
|
1878
|
+
|
|
1823
1879
|
function createRows(drawData, content, style) {
|
|
1824
1880
|
textDrawData = drawData;
|
|
1825
1881
|
rows = drawData.rows;
|
|
1826
1882
|
bounds = drawData.bounds;
|
|
1827
1883
|
findMaxWidth = !bounds.width && !style.autoSizeAlign;
|
|
1828
|
-
const { __letterSpacing, paraIndent, textCase } = style;
|
|
1829
|
-
const { canvas
|
|
1830
|
-
const { width, height } = bounds;
|
|
1831
|
-
const charMode = width || height || __letterSpacing ||
|
|
1884
|
+
const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
|
|
1885
|
+
const {canvas: canvas} = core.Platform;
|
|
1886
|
+
const {width: width, height: height} = bounds;
|
|
1887
|
+
const charMode = width || height || __letterSpacing || textCase !== "none";
|
|
1832
1888
|
if (charMode) {
|
|
1833
|
-
const wrap = style.textWrap !==
|
|
1834
|
-
const breakAll = style.textWrap ===
|
|
1889
|
+
const wrap = style.textWrap !== "none";
|
|
1890
|
+
const breakAll = style.textWrap === "break";
|
|
1835
1891
|
paraStart = true;
|
|
1836
1892
|
lastCharType = null;
|
|
1837
1893
|
startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
|
|
1838
|
-
word = {
|
|
1839
|
-
|
|
1840
|
-
|
|
1894
|
+
word = {
|
|
1895
|
+
data: []
|
|
1896
|
+
}, row = {
|
|
1897
|
+
words: []
|
|
1898
|
+
};
|
|
1899
|
+
if (__letterSpacing) content = [ ...content ];
|
|
1841
1900
|
for (let i = 0, len = content.length; i < len; i++) {
|
|
1842
1901
|
char = content[i];
|
|
1843
|
-
if (char ===
|
|
1844
|
-
if (wordWidth)
|
|
1845
|
-
addWord();
|
|
1902
|
+
if (char === "\n") {
|
|
1903
|
+
if (wordWidth) addWord();
|
|
1846
1904
|
row.paraEnd = true;
|
|
1847
1905
|
addRow();
|
|
1848
1906
|
paraStart = true;
|
|
1849
|
-
}
|
|
1850
|
-
else {
|
|
1907
|
+
} else {
|
|
1851
1908
|
charType = getCharType(char);
|
|
1852
|
-
if (charType === Letter && textCase !==
|
|
1853
|
-
char = getTextCase(char, textCase, !wordWidth);
|
|
1909
|
+
if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
|
|
1854
1910
|
charWidth = canvas.measureText(char).width;
|
|
1855
1911
|
if (__letterSpacing) {
|
|
1856
|
-
if (__letterSpacing < 0)
|
|
1857
|
-
charSize = charWidth;
|
|
1912
|
+
if (__letterSpacing < 0) charSize = charWidth;
|
|
1858
1913
|
charWidth += __letterSpacing;
|
|
1859
1914
|
}
|
|
1860
|
-
langBreak =
|
|
1861
|
-
afterBreak = (
|
|
1915
|
+
langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
|
|
1916
|
+
afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
|
|
1862
1917
|
realWidth = paraStart && paraIndent ? width - paraIndent : width;
|
|
1863
1918
|
if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
|
|
1864
1919
|
if (breakAll) {
|
|
1865
|
-
if (wordWidth)
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
if (wordWidth)
|
|
1875
|
-
addWord();
|
|
1876
|
-
if (rowWidth)
|
|
1877
|
-
addRow();
|
|
1878
|
-
}
|
|
1879
|
-
else {
|
|
1880
|
-
if (rowWidth)
|
|
1881
|
-
addRow();
|
|
1920
|
+
if (wordWidth) addWord();
|
|
1921
|
+
if (rowWidth) addRow();
|
|
1922
|
+
} else {
|
|
1923
|
+
if (!afterBreak) afterBreak = charType === Letter && lastCharType == After;
|
|
1924
|
+
if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || wordWidth + charWidth > realWidth) {
|
|
1925
|
+
if (wordWidth) addWord();
|
|
1926
|
+
if (rowWidth) addRow();
|
|
1927
|
+
} else {
|
|
1928
|
+
if (rowWidth) addRow();
|
|
1882
1929
|
}
|
|
1883
1930
|
}
|
|
1884
1931
|
}
|
|
1885
|
-
if (char ===
|
|
1886
|
-
else {
|
|
1932
|
+
if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
|
|
1887
1933
|
if (charType === Break) {
|
|
1888
|
-
if (char ===
|
|
1889
|
-
addWord();
|
|
1934
|
+
if (char === " " && wordWidth) addWord();
|
|
1890
1935
|
addChar(char, charWidth);
|
|
1891
1936
|
addWord();
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1894
|
-
if (wordWidth)
|
|
1895
|
-
addWord();
|
|
1937
|
+
} else if (langBreak || afterBreak) {
|
|
1938
|
+
if (wordWidth) addWord();
|
|
1896
1939
|
addChar(char, charWidth);
|
|
1897
|
-
}
|
|
1898
|
-
else {
|
|
1940
|
+
} else {
|
|
1899
1941
|
addChar(char, charWidth);
|
|
1900
1942
|
}
|
|
1901
1943
|
}
|
|
1902
1944
|
lastCharType = charType;
|
|
1903
1945
|
}
|
|
1904
1946
|
}
|
|
1905
|
-
if (wordWidth)
|
|
1906
|
-
|
|
1907
|
-
if (rowWidth)
|
|
1908
|
-
addRow();
|
|
1947
|
+
if (wordWidth) addWord();
|
|
1948
|
+
if (rowWidth) addRow();
|
|
1909
1949
|
rows.length > 0 && (rows[rows.length - 1].paraEnd = true);
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
|
-
content.split('\n').forEach(content => {
|
|
1950
|
+
} else {
|
|
1951
|
+
content.split("\n").forEach(content => {
|
|
1913
1952
|
textDrawData.paraNumber++;
|
|
1914
1953
|
rowWidth = canvas.measureText(content).width;
|
|
1915
|
-
rows.push({
|
|
1916
|
-
|
|
1917
|
-
|
|
1954
|
+
rows.push({
|
|
1955
|
+
x: paraIndent || 0,
|
|
1956
|
+
text: content,
|
|
1957
|
+
width: rowWidth,
|
|
1958
|
+
paraStart: true
|
|
1959
|
+
});
|
|
1960
|
+
if (findMaxWidth) setMaxWidth();
|
|
1918
1961
|
});
|
|
1919
1962
|
}
|
|
1920
1963
|
}
|
|
1964
|
+
|
|
1921
1965
|
function addChar(char, width) {
|
|
1922
|
-
if (charSize && !startCharSize)
|
|
1923
|
-
|
|
1924
|
-
|
|
1966
|
+
if (charSize && !startCharSize) startCharSize = charSize;
|
|
1967
|
+
word.data.push({
|
|
1968
|
+
char: char,
|
|
1969
|
+
width: width
|
|
1970
|
+
});
|
|
1925
1971
|
wordWidth += width;
|
|
1926
1972
|
}
|
|
1973
|
+
|
|
1927
1974
|
function addWord() {
|
|
1928
1975
|
rowWidth += wordWidth;
|
|
1929
1976
|
word.width = wordWidth;
|
|
1930
1977
|
row.words.push(word);
|
|
1931
|
-
word = {
|
|
1978
|
+
word = {
|
|
1979
|
+
data: []
|
|
1980
|
+
};
|
|
1932
1981
|
wordWidth = 0;
|
|
1933
1982
|
}
|
|
1983
|
+
|
|
1934
1984
|
function addRow() {
|
|
1935
1985
|
if (paraStart) {
|
|
1936
1986
|
textDrawData.paraNumber++;
|
|
@@ -1943,52 +1993,53 @@ function addRow() {
|
|
|
1943
1993
|
startCharSize = 0;
|
|
1944
1994
|
}
|
|
1945
1995
|
row.width = rowWidth;
|
|
1946
|
-
if (bounds.width)
|
|
1947
|
-
trimRight(row);
|
|
1948
|
-
else if (findMaxWidth)
|
|
1949
|
-
setMaxWidth();
|
|
1996
|
+
if (bounds.width) trimRight(row); else if (findMaxWidth) setMaxWidth();
|
|
1950
1997
|
rows.push(row);
|
|
1951
|
-
row = {
|
|
1998
|
+
row = {
|
|
1999
|
+
words: []
|
|
2000
|
+
};
|
|
1952
2001
|
rowWidth = 0;
|
|
1953
2002
|
}
|
|
2003
|
+
|
|
1954
2004
|
function setMaxWidth() {
|
|
1955
|
-
if (rowWidth > (textDrawData.maxWidth || 0))
|
|
1956
|
-
textDrawData.maxWidth = rowWidth;
|
|
2005
|
+
if (rowWidth > (textDrawData.maxWidth || 0)) textDrawData.maxWidth = rowWidth;
|
|
1957
2006
|
}
|
|
1958
2007
|
|
|
1959
2008
|
const CharMode = 0;
|
|
2009
|
+
|
|
1960
2010
|
const WordMode = 1;
|
|
2011
|
+
|
|
1961
2012
|
const TextMode = 2;
|
|
2013
|
+
|
|
1962
2014
|
function layoutChar(drawData, style, width, _height) {
|
|
1963
|
-
const { rows
|
|
1964
|
-
const { textAlign, paraIndent, letterSpacing } = style;
|
|
2015
|
+
const {rows: rows} = drawData;
|
|
2016
|
+
const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
|
|
1965
2017
|
let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
|
|
1966
2018
|
rows.forEach(row => {
|
|
1967
2019
|
if (row.words) {
|
|
1968
2020
|
indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
|
|
1969
|
-
addWordWidth =
|
|
1970
|
-
mode =
|
|
1971
|
-
if (row.isOverflow && !letterSpacing)
|
|
1972
|
-
row.textMode = true;
|
|
2021
|
+
addWordWidth = width && (textAlign === "justify" || textAlign === "both") && wordsLength > 1 ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
|
|
2022
|
+
mode = letterSpacing || row.isOverflow ? CharMode : addWordWidth > .01 ? WordMode : TextMode;
|
|
2023
|
+
if (row.isOverflow && !letterSpacing) row.textMode = true;
|
|
1973
2024
|
if (mode === TextMode) {
|
|
1974
2025
|
row.x += indentWidth;
|
|
1975
2026
|
toTextChar$1(row);
|
|
1976
|
-
}
|
|
1977
|
-
else {
|
|
2027
|
+
} else {
|
|
1978
2028
|
row.x += indentWidth;
|
|
1979
2029
|
charX = row.x;
|
|
1980
2030
|
row.data = [];
|
|
1981
2031
|
row.words.forEach((word, index) => {
|
|
1982
2032
|
if (mode === WordMode) {
|
|
1983
|
-
wordChar = {
|
|
2033
|
+
wordChar = {
|
|
2034
|
+
char: "",
|
|
2035
|
+
x: charX
|
|
2036
|
+
};
|
|
1984
2037
|
charX = toWordChar(word.data, charX, wordChar);
|
|
1985
|
-
if (row.isOverflow || wordChar.char !==
|
|
1986
|
-
|
|
1987
|
-
}
|
|
1988
|
-
else {
|
|
2038
|
+
if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
|
|
2039
|
+
} else {
|
|
1989
2040
|
charX = toChar(word.data, charX, row.data, row.isOverflow);
|
|
1990
2041
|
}
|
|
1991
|
-
if (addWordWidth && (!row.paraEnd || textAlign ===
|
|
2042
|
+
if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
|
|
1992
2043
|
charX += addWordWidth;
|
|
1993
2044
|
row.width += addWordWidth;
|
|
1994
2045
|
}
|
|
@@ -1998,14 +2049,16 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
1998
2049
|
}
|
|
1999
2050
|
});
|
|
2000
2051
|
}
|
|
2052
|
+
|
|
2001
2053
|
function toTextChar$1(row) {
|
|
2002
|
-
row.text =
|
|
2054
|
+
row.text = "";
|
|
2003
2055
|
row.words.forEach(word => {
|
|
2004
2056
|
word.data.forEach(char => {
|
|
2005
2057
|
row.text += char.char;
|
|
2006
2058
|
});
|
|
2007
2059
|
});
|
|
2008
2060
|
}
|
|
2061
|
+
|
|
2009
2062
|
function toWordChar(data, charX, wordChar) {
|
|
2010
2063
|
data.forEach(char => {
|
|
2011
2064
|
wordChar.char += char.char;
|
|
@@ -2013,9 +2066,10 @@ function toWordChar(data, charX, wordChar) {
|
|
|
2013
2066
|
});
|
|
2014
2067
|
return charX;
|
|
2015
2068
|
}
|
|
2069
|
+
|
|
2016
2070
|
function toChar(data, charX, rowData, isOverflow) {
|
|
2017
2071
|
data.forEach(char => {
|
|
2018
|
-
if (isOverflow || char.char !==
|
|
2072
|
+
if (isOverflow || char.char !== " ") {
|
|
2019
2073
|
char.x = charX;
|
|
2020
2074
|
rowData.push(char);
|
|
2021
2075
|
}
|
|
@@ -2025,38 +2079,39 @@ function toChar(data, charX, rowData, isOverflow) {
|
|
|
2025
2079
|
}
|
|
2026
2080
|
|
|
2027
2081
|
function layoutText(drawData, style) {
|
|
2028
|
-
const { rows, bounds } = drawData, countRows = rows.length;
|
|
2029
|
-
const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
|
|
2030
|
-
let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
|
|
2082
|
+
const {rows: rows, bounds: bounds} = drawData, countRows = rows.length;
|
|
2083
|
+
const {__lineHeight: __lineHeight, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __clipText: __clipText, textAlign: textAlign, verticalAlign: verticalAlign, paraSpacing: paraSpacing, autoSizeAlign: autoSizeAlign} = style;
|
|
2084
|
+
let {x: x, y: y, width: width, height: height} = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
|
|
2031
2085
|
let starY = __baseLine;
|
|
2032
2086
|
if (__clipText && realHeight > height) {
|
|
2033
2087
|
realHeight = Math.max(height, __lineHeight);
|
|
2034
|
-
if (countRows > 1)
|
|
2035
|
-
|
|
2036
|
-
}
|
|
2037
|
-
else if (height || autoSizeAlign) {
|
|
2088
|
+
if (countRows > 1) drawData.overflow = countRows;
|
|
2089
|
+
} else if (height || autoSizeAlign) {
|
|
2038
2090
|
switch (verticalAlign) {
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2091
|
+
case "middle":
|
|
2092
|
+
y += (height - realHeight) / 2;
|
|
2093
|
+
break;
|
|
2094
|
+
|
|
2095
|
+
case "bottom":
|
|
2096
|
+
y += height - realHeight;
|
|
2043
2097
|
}
|
|
2044
2098
|
}
|
|
2045
2099
|
starY += y;
|
|
2046
|
-
let row, rowX, rowWidth, layoutWidth =
|
|
2100
|
+
let row, rowX, rowWidth, layoutWidth = width || autoSizeAlign ? width : drawData.maxWidth;
|
|
2047
2101
|
for (let i = 0, len = countRows; i < len; i++) {
|
|
2048
2102
|
row = rows[i];
|
|
2049
2103
|
row.x = x;
|
|
2050
|
-
if (row.width < width ||
|
|
2104
|
+
if (row.width < width || row.width > width && !__clipText) {
|
|
2051
2105
|
switch (textAlign) {
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2106
|
+
case "center":
|
|
2107
|
+
row.x += (layoutWidth - row.width) / 2;
|
|
2108
|
+
break;
|
|
2109
|
+
|
|
2110
|
+
case "right":
|
|
2111
|
+
row.x += layoutWidth - row.width;
|
|
2056
2112
|
}
|
|
2057
2113
|
}
|
|
2058
|
-
if (row.paraStart && paraSpacing && i > 0)
|
|
2059
|
-
starY += paraSpacing;
|
|
2114
|
+
if (row.paraStart && paraSpacing && i > 0) starY += paraSpacing;
|
|
2060
2115
|
row.y = starY;
|
|
2061
2116
|
starY += __lineHeight;
|
|
2062
2117
|
if (drawData.overflow > i && starY > realHeight) {
|
|
@@ -2070,19 +2125,15 @@ function layoutText(drawData, style) {
|
|
|
2070
2125
|
rowWidth = -row.width + style.fontSize + __letterSpacing;
|
|
2071
2126
|
rowX -= rowWidth;
|
|
2072
2127
|
rowWidth += style.fontSize;
|
|
2073
|
-
}
|
|
2074
|
-
else {
|
|
2128
|
+
} else {
|
|
2075
2129
|
rowWidth -= __letterSpacing;
|
|
2076
2130
|
}
|
|
2077
2131
|
}
|
|
2078
|
-
if (rowX < bounds.x)
|
|
2079
|
-
|
|
2080
|
-
if (rowWidth > bounds.width)
|
|
2081
|
-
bounds.width = rowWidth;
|
|
2132
|
+
if (rowX < bounds.x) bounds.x = rowX;
|
|
2133
|
+
if (rowWidth > bounds.width) bounds.width = rowWidth;
|
|
2082
2134
|
if (__clipText && width && width < rowWidth) {
|
|
2083
2135
|
row.isOverflow = true;
|
|
2084
|
-
if (!drawData.overflow)
|
|
2085
|
-
drawData.overflow = rows.length;
|
|
2136
|
+
if (!drawData.overflow) drawData.overflow = rows.length;
|
|
2086
2137
|
}
|
|
2087
2138
|
}
|
|
2088
2139
|
bounds.y = y;
|
|
@@ -2090,20 +2141,16 @@ function layoutText(drawData, style) {
|
|
|
2090
2141
|
}
|
|
2091
2142
|
|
|
2092
2143
|
function clipText(drawData, style, x, width) {
|
|
2093
|
-
if (!width)
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
let { textOverflow } = style;
|
|
2144
|
+
if (!width) return;
|
|
2145
|
+
const {rows: rows, overflow: overflow} = drawData;
|
|
2146
|
+
let {textOverflow: textOverflow} = style;
|
|
2097
2147
|
rows.splice(overflow);
|
|
2098
|
-
if (textOverflow && textOverflow !==
|
|
2099
|
-
if (textOverflow ===
|
|
2100
|
-
textOverflow = '';
|
|
2101
|
-
else if (textOverflow === 'ellipsis')
|
|
2102
|
-
textOverflow = '...';
|
|
2148
|
+
if (textOverflow && textOverflow !== "show") {
|
|
2149
|
+
if (textOverflow === "hide") textOverflow = ""; else if (textOverflow === "ellipsis") textOverflow = "...";
|
|
2103
2150
|
let char, charRight;
|
|
2104
2151
|
const ellipsisWidth = textOverflow ? core.Platform.canvas.measureText(textOverflow).width : 0;
|
|
2105
2152
|
const right = x + width - ellipsisWidth;
|
|
2106
|
-
const list = style.textWrap ===
|
|
2153
|
+
const list = style.textWrap === "none" ? rows : [ rows[overflow - 1] ];
|
|
2107
2154
|
list.forEach(row => {
|
|
2108
2155
|
if (row.isOverflow && row.data) {
|
|
2109
2156
|
let end = row.data.length - 1;
|
|
@@ -2112,8 +2159,7 @@ function clipText(drawData, style, x, width) {
|
|
|
2112
2159
|
charRight = char.x + char.width;
|
|
2113
2160
|
if (i === end && charRight < right) {
|
|
2114
2161
|
break;
|
|
2115
|
-
}
|
|
2116
|
-
else if ((charRight < right && char.char !== ' ') || !i) {
|
|
2162
|
+
} else if (charRight < right && char.char !== " " || !i) {
|
|
2117
2163
|
row.data.splice(i + 1);
|
|
2118
2164
|
row.width -= char.width;
|
|
2119
2165
|
break;
|
|
@@ -2121,15 +2167,18 @@ function clipText(drawData, style, x, width) {
|
|
|
2121
2167
|
row.width -= char.width;
|
|
2122
2168
|
}
|
|
2123
2169
|
row.width += ellipsisWidth;
|
|
2124
|
-
row.data.push({
|
|
2125
|
-
|
|
2126
|
-
|
|
2170
|
+
row.data.push({
|
|
2171
|
+
char: textOverflow,
|
|
2172
|
+
x: charRight
|
|
2173
|
+
});
|
|
2174
|
+
if (row.textMode) toTextChar(row);
|
|
2127
2175
|
}
|
|
2128
2176
|
});
|
|
2129
2177
|
}
|
|
2130
2178
|
}
|
|
2179
|
+
|
|
2131
2180
|
function toTextChar(row) {
|
|
2132
|
-
row.text =
|
|
2181
|
+
row.text = "";
|
|
2133
2182
|
row.data.forEach(char => {
|
|
2134
2183
|
row.text += char.char;
|
|
2135
2184
|
});
|
|
@@ -2138,137 +2187,151 @@ function toTextChar(row) {
|
|
|
2138
2187
|
|
|
2139
2188
|
function decorationText(drawData, style) {
|
|
2140
2189
|
let type;
|
|
2141
|
-
const { fontSize, textDecoration } = style;
|
|
2190
|
+
const {fontSize: fontSize, textDecoration: textDecoration} = style;
|
|
2142
2191
|
drawData.decorationHeight = fontSize / 11;
|
|
2143
|
-
if (
|
|
2192
|
+
if (core.isObject(textDecoration)) {
|
|
2144
2193
|
type = textDecoration.type;
|
|
2145
|
-
if (textDecoration.color)
|
|
2146
|
-
|
|
2147
|
-
}
|
|
2148
|
-
else
|
|
2149
|
-
type = textDecoration;
|
|
2194
|
+
if (textDecoration.color) drawData.decorationColor = draw.ColorConvert.string(textDecoration.color);
|
|
2195
|
+
} else type = textDecoration;
|
|
2150
2196
|
switch (type) {
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2197
|
+
case "under":
|
|
2198
|
+
drawData.decorationY = [ fontSize * .15 ];
|
|
2199
|
+
break;
|
|
2200
|
+
|
|
2201
|
+
case "delete":
|
|
2202
|
+
drawData.decorationY = [ -fontSize * .35 ];
|
|
2203
|
+
break;
|
|
2204
|
+
|
|
2205
|
+
case "under-delete":
|
|
2206
|
+
drawData.decorationY = [ fontSize * .15, -fontSize * .35 ];
|
|
2159
2207
|
}
|
|
2160
2208
|
}
|
|
2161
2209
|
|
|
2162
|
-
const { top, right, bottom, left } = core.Direction4;
|
|
2210
|
+
const {top: top, right: right, bottom: bottom, left: left} = core.Direction4;
|
|
2211
|
+
|
|
2163
2212
|
function getDrawData(content, style) {
|
|
2164
|
-
if (
|
|
2165
|
-
content = String(content);
|
|
2213
|
+
if (!core.isString(content)) content = String(content);
|
|
2166
2214
|
let x = 0, y = 0;
|
|
2167
|
-
let width = style.__getInput(
|
|
2168
|
-
let height = style.__getInput(
|
|
2169
|
-
const { textDecoration, __font, __padding: padding
|
|
2215
|
+
let width = style.__getInput("width") || 0;
|
|
2216
|
+
let height = style.__getInput("height") || 0;
|
|
2217
|
+
const {textDecoration: textDecoration, __font: __font, __padding: padding} = style;
|
|
2170
2218
|
if (padding) {
|
|
2171
|
-
if (width)
|
|
2172
|
-
|
|
2173
|
-
else if (!style.autoSizeAlign)
|
|
2174
|
-
x = padding[left];
|
|
2175
|
-
if (height)
|
|
2176
|
-
y = padding[top], height -= (padding[top] + padding[bottom]);
|
|
2177
|
-
else if (!style.autoSizeAlign)
|
|
2178
|
-
y = padding[top];
|
|
2219
|
+
if (width) x = padding[left], width -= padding[right] + padding[left]; else if (!style.autoSizeAlign) x = padding[left];
|
|
2220
|
+
if (height) y = padding[top], height -= padding[top] + padding[bottom]; else if (!style.autoSizeAlign) y = padding[top];
|
|
2179
2221
|
}
|
|
2180
2222
|
const drawData = {
|
|
2181
|
-
bounds: {
|
|
2223
|
+
bounds: {
|
|
2224
|
+
x: x,
|
|
2225
|
+
y: y,
|
|
2226
|
+
width: width,
|
|
2227
|
+
height: height
|
|
2228
|
+
},
|
|
2182
2229
|
rows: [],
|
|
2183
2230
|
paraNumber: 0,
|
|
2184
2231
|
font: core.Platform.canvas.font = __font
|
|
2185
2232
|
};
|
|
2186
2233
|
createRows(drawData, content, style);
|
|
2187
|
-
if (padding)
|
|
2188
|
-
padAutoText(padding, drawData, style, width, height);
|
|
2234
|
+
if (padding) padAutoText(padding, drawData, style, width, height);
|
|
2189
2235
|
layoutText(drawData, style);
|
|
2190
2236
|
layoutChar(drawData, style, width);
|
|
2191
|
-
if (drawData.overflow)
|
|
2192
|
-
|
|
2193
|
-
if (textDecoration !== 'none')
|
|
2194
|
-
decorationText(drawData, style);
|
|
2237
|
+
if (drawData.overflow) clipText(drawData, style, x, width);
|
|
2238
|
+
if (textDecoration !== "none") decorationText(drawData, style);
|
|
2195
2239
|
return drawData;
|
|
2196
2240
|
}
|
|
2241
|
+
|
|
2197
2242
|
function padAutoText(padding, drawData, style, width, height) {
|
|
2198
2243
|
if (!width && style.autoSizeAlign) {
|
|
2199
2244
|
switch (style.textAlign) {
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2245
|
+
case "left":
|
|
2246
|
+
offsetText(drawData, "x", padding[left]);
|
|
2247
|
+
break;
|
|
2248
|
+
|
|
2249
|
+
case "right":
|
|
2250
|
+
offsetText(drawData, "x", -padding[right]);
|
|
2204
2251
|
}
|
|
2205
2252
|
}
|
|
2206
2253
|
if (!height && style.autoSizeAlign) {
|
|
2207
2254
|
switch (style.verticalAlign) {
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2255
|
+
case "top":
|
|
2256
|
+
offsetText(drawData, "y", padding[top]);
|
|
2257
|
+
break;
|
|
2258
|
+
|
|
2259
|
+
case "bottom":
|
|
2260
|
+
offsetText(drawData, "y", -padding[bottom]);
|
|
2212
2261
|
}
|
|
2213
2262
|
}
|
|
2214
2263
|
}
|
|
2264
|
+
|
|
2215
2265
|
function offsetText(drawData, attrName, value) {
|
|
2216
|
-
const { bounds, rows } = drawData;
|
|
2266
|
+
const {bounds: bounds, rows: rows} = drawData;
|
|
2217
2267
|
bounds[attrName] += value;
|
|
2218
|
-
for (let i = 0; i < rows.length; i++)
|
|
2219
|
-
rows[i][attrName] += value;
|
|
2268
|
+
for (let i = 0; i < rows.length; i++) rows[i][attrName] += value;
|
|
2220
2269
|
}
|
|
2221
2270
|
|
|
2222
2271
|
const TextConvertModule = {
|
|
2223
|
-
getDrawData
|
|
2272
|
+
getDrawData: getDrawData
|
|
2224
2273
|
};
|
|
2225
2274
|
|
|
2226
2275
|
function string(color, opacity) {
|
|
2227
|
-
const doOpacity =
|
|
2228
|
-
if (
|
|
2229
|
-
if (doOpacity && draw.ColorConvert.object)
|
|
2230
|
-
color = draw.ColorConvert.object(color);
|
|
2231
|
-
else
|
|
2232
|
-
return color;
|
|
2276
|
+
const doOpacity = core.isNumber(opacity) && opacity < 1;
|
|
2277
|
+
if (core.isString(color)) {
|
|
2278
|
+
if (doOpacity && draw.ColorConvert.object) color = draw.ColorConvert.object(color); else return color;
|
|
2233
2279
|
}
|
|
2234
|
-
let a = color.a
|
|
2235
|
-
if (doOpacity)
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
|
|
2280
|
+
let a = core.isUndefined(color.a) ? 1 : color.a;
|
|
2281
|
+
if (doOpacity) a *= opacity;
|
|
2282
|
+
const rgb = color.r + "," + color.g + "," + color.b;
|
|
2283
|
+
return a === 1 ? "rgb(" + rgb + ")" : "rgba(" + rgb + "," + a + ")";
|
|
2239
2284
|
}
|
|
2240
2285
|
|
|
2241
2286
|
const ColorConvertModule = {
|
|
2242
|
-
string
|
|
2287
|
+
string: string
|
|
2243
2288
|
};
|
|
2244
2289
|
|
|
2245
2290
|
Object.assign(draw.TextConvert, TextConvertModule);
|
|
2291
|
+
|
|
2246
2292
|
Object.assign(draw.ColorConvert, ColorConvertModule);
|
|
2293
|
+
|
|
2247
2294
|
Object.assign(draw.Paint, PaintModule);
|
|
2295
|
+
|
|
2248
2296
|
Object.assign(draw.PaintImage, PaintImageModule);
|
|
2297
|
+
|
|
2249
2298
|
Object.assign(draw.PaintGradient, PaintGradientModule);
|
|
2299
|
+
|
|
2250
2300
|
Object.assign(draw.Effect, EffectModule);
|
|
2251
2301
|
|
|
2252
2302
|
useCanvas();
|
|
2253
2303
|
|
|
2254
2304
|
Object.defineProperty(exports, "LeaferImage", {
|
|
2255
2305
|
enumerable: true,
|
|
2256
|
-
get: function
|
|
2306
|
+
get: function() {
|
|
2307
|
+
return core.LeaferImage;
|
|
2308
|
+
}
|
|
2257
2309
|
});
|
|
2310
|
+
|
|
2258
2311
|
exports.Layouter = Layouter;
|
|
2312
|
+
|
|
2259
2313
|
exports.LeaferCanvas = LeaferCanvas;
|
|
2314
|
+
|
|
2260
2315
|
exports.Renderer = Renderer;
|
|
2316
|
+
|
|
2261
2317
|
exports.Watcher = Watcher;
|
|
2318
|
+
|
|
2262
2319
|
exports.useCanvas = useCanvas;
|
|
2263
|
-
|
|
2264
|
-
|
|
2320
|
+
|
|
2321
|
+
Object.keys(core).forEach(function(k) {
|
|
2322
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
2265
2323
|
enumerable: true,
|
|
2266
|
-
get: function
|
|
2324
|
+
get: function() {
|
|
2325
|
+
return core[k];
|
|
2326
|
+
}
|
|
2267
2327
|
});
|
|
2268
2328
|
});
|
|
2269
|
-
|
|
2270
|
-
|
|
2329
|
+
|
|
2330
|
+
Object.keys(draw).forEach(function(k) {
|
|
2331
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
2271
2332
|
enumerable: true,
|
|
2272
|
-
get: function
|
|
2333
|
+
get: function() {
|
|
2334
|
+
return draw[k];
|
|
2335
|
+
}
|
|
2273
2336
|
});
|
|
2274
2337
|
});
|