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