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