@leafer-ui/node 1.8.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 +1244 -1106
- package/dist/node.esm.js +1226 -1100
- 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, getMatrixData, 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,117 +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
894
|
if (item.transform || item.scaleFixed) {
|
|
873
895
|
canvas.save();
|
|
874
|
-
if (item.transform)
|
|
875
|
-
canvas.transform(item.transform);
|
|
896
|
+
if (item.transform) canvas.transform(item.transform);
|
|
876
897
|
if (item.scaleFixed) {
|
|
877
|
-
const { scaleX, scaleY } = ui.getRenderScaleData(true);
|
|
878
|
-
canvas.scale(1 / scaleX, 1 / scaleY);
|
|
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);
|
|
879
900
|
}
|
|
880
|
-
if (item.blendMode)
|
|
881
|
-
canvas.blendMode = item.blendMode;
|
|
901
|
+
if (item.blendMode) canvas.blendMode = item.blendMode;
|
|
882
902
|
fillPathOrText(ui, canvas);
|
|
883
903
|
canvas.restore();
|
|
884
|
-
}
|
|
885
|
-
else {
|
|
904
|
+
} else {
|
|
886
905
|
if (item.blendMode) {
|
|
887
906
|
canvas.saveBlendMode(item.blendMode);
|
|
888
907
|
fillPathOrText(ui, canvas);
|
|
889
908
|
canvas.restoreBlendMode();
|
|
890
|
-
}
|
|
891
|
-
else
|
|
892
|
-
fillPathOrText(ui, canvas);
|
|
909
|
+
} else fillPathOrText(ui, canvas);
|
|
893
910
|
}
|
|
894
911
|
}
|
|
895
912
|
}
|
|
913
|
+
|
|
896
914
|
function fillPathOrText(ui, canvas) {
|
|
897
|
-
ui.__.__font ? fillText(ui, canvas) :
|
|
915
|
+
ui.__.__font ? fillText(ui, canvas) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
|
|
898
916
|
}
|
|
899
917
|
|
|
900
918
|
function strokeText(stroke, ui, canvas) {
|
|
901
919
|
switch (ui.__.strokeAlign) {
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
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;
|
|
911
931
|
}
|
|
912
932
|
}
|
|
933
|
+
|
|
913
934
|
function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
|
|
914
935
|
const data = ui.__;
|
|
915
|
-
if (
|
|
936
|
+
if (isObject(stroke)) {
|
|
916
937
|
drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
|
|
917
|
-
}
|
|
918
|
-
else {
|
|
938
|
+
} else {
|
|
919
939
|
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
920
940
|
drawTextStroke(ui, canvas);
|
|
921
941
|
}
|
|
922
942
|
}
|
|
943
|
+
|
|
923
944
|
function drawAlign(stroke, align, ui, canvas) {
|
|
924
945
|
const out = canvas.getSameCanvas(true, true);
|
|
925
946
|
out.font = ui.__.__font;
|
|
926
947
|
drawCenter$1(stroke, 2, ui, out);
|
|
927
|
-
out.blendMode = align ===
|
|
948
|
+
out.blendMode = align === "outside" ? "destination-out" : "destination-in";
|
|
928
949
|
fillText(ui, out);
|
|
929
|
-
out.blendMode =
|
|
950
|
+
out.blendMode = "normal";
|
|
930
951
|
LeafHelper.copyCanvasByWorld(ui, canvas, out);
|
|
931
952
|
out.recycle(ui.__nowWorld);
|
|
932
953
|
}
|
|
954
|
+
|
|
933
955
|
function drawTextStroke(ui, canvas) {
|
|
934
956
|
let row, data = ui.__.__textDrawData;
|
|
935
|
-
const { rows, decorationY } = data;
|
|
957
|
+
const {rows: rows, decorationY: decorationY} = data;
|
|
936
958
|
for (let i = 0, len = rows.length; i < len; i++) {
|
|
937
959
|
row = rows[i];
|
|
938
|
-
if (row.text)
|
|
939
|
-
canvas.strokeText(
|
|
940
|
-
|
|
941
|
-
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
|
+
});
|
|
942
963
|
}
|
|
943
964
|
if (decorationY) {
|
|
944
|
-
const { decorationHeight
|
|
965
|
+
const {decorationHeight: decorationHeight} = data;
|
|
945
966
|
rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
|
|
946
967
|
}
|
|
947
968
|
}
|
|
969
|
+
|
|
948
970
|
function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
|
|
949
971
|
let item;
|
|
950
|
-
const data = ui.__, { __hasMultiStrokeStyle
|
|
972
|
+
const data = ui.__, {__hasMultiStrokeStyle: __hasMultiStrokeStyle} = data;
|
|
951
973
|
__hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
|
|
952
974
|
for (let i = 0, len = strokes.length; i < len; i++) {
|
|
953
975
|
item = strokes[i];
|
|
954
|
-
if (item.image && PaintImage.checkImage(ui, canvas, item, false))
|
|
955
|
-
continue;
|
|
976
|
+
if (item.image && PaintImage.checkImage(ui, canvas, item, false)) continue;
|
|
956
977
|
if (item.style) {
|
|
957
978
|
if (__hasMultiStrokeStyle) {
|
|
958
|
-
const { strokeStyle
|
|
979
|
+
const {strokeStyle: strokeStyle} = item;
|
|
959
980
|
strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
|
|
960
|
-
}
|
|
961
|
-
else
|
|
962
|
-
canvas.strokeStyle = item.style;
|
|
981
|
+
} else canvas.strokeStyle = item.style;
|
|
963
982
|
if (item.blendMode) {
|
|
964
983
|
canvas.saveBlendMode(item.blendMode);
|
|
965
984
|
isText ? drawTextStroke(ui, canvas) : canvas.stroke();
|
|
966
985
|
canvas.restoreBlendMode();
|
|
967
|
-
}
|
|
968
|
-
else {
|
|
986
|
+
} else {
|
|
969
987
|
isText ? drawTextStroke(ui, canvas) : canvas.stroke();
|
|
970
988
|
}
|
|
971
989
|
}
|
|
@@ -974,53 +992,54 @@ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
|
|
|
974
992
|
|
|
975
993
|
function stroke(stroke, ui, canvas) {
|
|
976
994
|
const data = ui.__;
|
|
977
|
-
if (!data.__strokeWidth)
|
|
978
|
-
return;
|
|
995
|
+
if (!data.__strokeWidth) return;
|
|
979
996
|
if (data.__font) {
|
|
980
997
|
strokeText(stroke, ui, canvas);
|
|
981
|
-
}
|
|
982
|
-
else {
|
|
998
|
+
} else {
|
|
983
999
|
switch (data.strokeAlign) {
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
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;
|
|
993
1011
|
}
|
|
994
1012
|
}
|
|
995
1013
|
}
|
|
1014
|
+
|
|
996
1015
|
function strokes(strokes, ui, canvas) {
|
|
997
1016
|
stroke(strokes, ui, canvas);
|
|
998
1017
|
}
|
|
1018
|
+
|
|
999
1019
|
function drawCenter(stroke, strokeWidthScale, ui, canvas) {
|
|
1000
1020
|
const data = ui.__;
|
|
1001
|
-
if (
|
|
1021
|
+
if (isObject(stroke)) {
|
|
1002
1022
|
drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
|
|
1003
|
-
}
|
|
1004
|
-
else {
|
|
1023
|
+
} else {
|
|
1005
1024
|
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
1006
1025
|
canvas.stroke();
|
|
1007
1026
|
}
|
|
1008
|
-
if (data.__useArrow)
|
|
1009
|
-
Paint.strokeArrow(stroke, ui, canvas);
|
|
1027
|
+
if (data.__useArrow) Paint.strokeArrow(stroke, ui, canvas);
|
|
1010
1028
|
}
|
|
1029
|
+
|
|
1011
1030
|
function drawInside(stroke, ui, canvas) {
|
|
1012
1031
|
canvas.save();
|
|
1013
1032
|
canvas.clipUI(ui);
|
|
1014
1033
|
drawCenter(stroke, 2, ui, canvas);
|
|
1015
1034
|
canvas.restore();
|
|
1016
1035
|
}
|
|
1036
|
+
|
|
1017
1037
|
function drawOutside(stroke, ui, canvas) {
|
|
1018
1038
|
const data = ui.__;
|
|
1019
1039
|
if (data.__fillAfterStroke) {
|
|
1020
1040
|
drawCenter(stroke, 2, ui, canvas);
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
const { renderBounds } = ui.__layout;
|
|
1041
|
+
} else {
|
|
1042
|
+
const {renderBounds: renderBounds} = ui.__layout;
|
|
1024
1043
|
const out = canvas.getSameCanvas(true, true);
|
|
1025
1044
|
ui.__drawRenderPath(out);
|
|
1026
1045
|
drawCenter(stroke, 2, ui, out);
|
|
@@ -1031,25 +1050,23 @@ function drawOutside(stroke, ui, canvas) {
|
|
|
1031
1050
|
}
|
|
1032
1051
|
}
|
|
1033
1052
|
|
|
1034
|
-
const { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper;
|
|
1053
|
+
const {getSpread: getSpread, getOuterOf: getOuterOf, getByMove: getByMove, getIntersectData: getIntersectData} = BoundsHelper;
|
|
1054
|
+
|
|
1035
1055
|
function shape(ui, current, options) {
|
|
1036
1056
|
const canvas = current.getSameCanvas();
|
|
1037
1057
|
const nowWorld = ui.__nowWorld;
|
|
1038
|
-
let bounds, fitMatrix, shapeBounds, worldCanvas;
|
|
1039
|
-
let { scaleX, scaleY } = nowWorld;
|
|
1040
|
-
if (scaleX < 0)
|
|
1041
|
-
|
|
1042
|
-
if (scaleY < 0)
|
|
1043
|
-
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;
|
|
1044
1062
|
if (current.bounds.includes(nowWorld)) {
|
|
1045
1063
|
worldCanvas = canvas;
|
|
1046
1064
|
bounds = shapeBounds = nowWorld;
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
const
|
|
1050
|
-
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);
|
|
1051
1068
|
fitMatrix = current.bounds.getFitMatrix(worldClipBounds);
|
|
1052
|
-
let {
|
|
1069
|
+
let {a: fitScaleX, d: fitScaleY} = fitMatrix;
|
|
1053
1070
|
if (fitMatrix.a < 1) {
|
|
1054
1071
|
worldCanvas = current.getSameCanvas();
|
|
1055
1072
|
ui.__renderShape(worldCanvas, options);
|
|
@@ -1058,28 +1075,39 @@ function shape(ui, current, options) {
|
|
|
1058
1075
|
}
|
|
1059
1076
|
shapeBounds = getOuterOf(nowWorld, fitMatrix);
|
|
1060
1077
|
bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f);
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
fitMatrix
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
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
|
+
});
|
|
1068
1089
|
}
|
|
1069
1090
|
ui.__renderShape(canvas, options);
|
|
1070
1091
|
return {
|
|
1071
|
-
canvas
|
|
1072
|
-
|
|
1092
|
+
canvas: canvas,
|
|
1093
|
+
matrix: matrix,
|
|
1094
|
+
fitMatrix: fitMatrix,
|
|
1095
|
+
bounds: bounds,
|
|
1096
|
+
worldCanvas: worldCanvas,
|
|
1097
|
+
shapeBounds: shapeBounds,
|
|
1098
|
+
scaleX: scaleX,
|
|
1099
|
+
scaleY: scaleY
|
|
1073
1100
|
};
|
|
1074
1101
|
}
|
|
1075
1102
|
|
|
1076
1103
|
let recycleMap;
|
|
1077
|
-
|
|
1104
|
+
|
|
1105
|
+
const {stintSet: stintSet} = DataHelper, {hasTransparent: hasTransparent$1} = ColorConvert;
|
|
1106
|
+
|
|
1078
1107
|
function compute(attrName, ui) {
|
|
1079
1108
|
const data = ui.__, leafPaints = [];
|
|
1080
1109
|
let paints = data.__input[attrName], isAlphaPixel, isTransparent;
|
|
1081
|
-
if (!(paints
|
|
1082
|
-
paints = [paints];
|
|
1110
|
+
if (!isArray(paints)) paints = [ paints ];
|
|
1083
1111
|
recycleMap = PaintImage.recycleImage(attrName, data);
|
|
1084
1112
|
let maxChildStrokeWidth;
|
|
1085
1113
|
for (let i = 0, len = paints.length, item; i < len; i++) {
|
|
@@ -1087,206 +1115,222 @@ function compute(attrName, ui) {
|
|
|
1087
1115
|
leafPaints.push(item);
|
|
1088
1116
|
if (item.strokeStyle) {
|
|
1089
1117
|
maxChildStrokeWidth || (maxChildStrokeWidth = 1);
|
|
1090
|
-
if (item.strokeStyle.strokeWidth)
|
|
1091
|
-
maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
1118
|
+
if (item.strokeStyle.strokeWidth) maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
1092
1119
|
}
|
|
1093
1120
|
}
|
|
1094
1121
|
}
|
|
1095
|
-
data[
|
|
1122
|
+
data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
|
|
1096
1123
|
if (leafPaints.length) {
|
|
1097
1124
|
if (leafPaints.every(item => item.isTransparent)) {
|
|
1098
|
-
if (leafPaints.some(item => item.image))
|
|
1099
|
-
isAlphaPixel = true;
|
|
1125
|
+
if (leafPaints.some(item => item.image)) isAlphaPixel = true;
|
|
1100
1126
|
isTransparent = true;
|
|
1101
1127
|
}
|
|
1102
1128
|
}
|
|
1103
|
-
if (attrName ===
|
|
1104
|
-
stintSet(data,
|
|
1105
|
-
stintSet(data,
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
stintSet(data,
|
|
1109
|
-
stintSet(data,
|
|
1110
|
-
stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth);
|
|
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);
|
|
1111
1136
|
}
|
|
1112
1137
|
}
|
|
1138
|
+
|
|
1113
1139
|
function getLeafPaint(attrName, paint, ui) {
|
|
1114
|
-
if (
|
|
1115
|
-
return undefined;
|
|
1140
|
+
if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
|
|
1116
1141
|
let data;
|
|
1117
|
-
const { boxBounds
|
|
1142
|
+
const {boxBounds: boxBounds} = ui.__layout;
|
|
1118
1143
|
switch (paint.type) {
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
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
|
+
};
|
|
1138
1173
|
}
|
|
1139
1174
|
if (data) {
|
|
1140
|
-
if (
|
|
1141
|
-
data.isTransparent = true;
|
|
1175
|
+
if (isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
|
|
1142
1176
|
if (paint.style) {
|
|
1143
|
-
if (paint.style.strokeWidth === 0)
|
|
1144
|
-
return undefined;
|
|
1177
|
+
if (paint.style.strokeWidth === 0) return undefined;
|
|
1145
1178
|
data.strokeStyle = paint.style;
|
|
1146
1179
|
}
|
|
1147
|
-
if (paint.
|
|
1148
|
-
|
|
1180
|
+
if (paint.editing) data.editing = paint.editing;
|
|
1181
|
+
if (paint.blendMode) data.blendMode = paint.blendMode;
|
|
1149
1182
|
}
|
|
1150
1183
|
return data;
|
|
1151
1184
|
}
|
|
1152
1185
|
|
|
1153
1186
|
const PaintModule = {
|
|
1154
|
-
compute,
|
|
1155
|
-
fill,
|
|
1156
|
-
fills,
|
|
1157
|
-
fillPathOrText,
|
|
1158
|
-
fillText,
|
|
1159
|
-
stroke,
|
|
1160
|
-
strokes,
|
|
1161
|
-
strokeText,
|
|
1162
|
-
drawTextStroke,
|
|
1163
|
-
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
|
|
1164
1197
|
};
|
|
1165
1198
|
|
|
1166
1199
|
let origin = {}, tempMatrix = getMatrixData();
|
|
1167
|
-
|
|
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
|
+
|
|
1168
1203
|
function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
1169
1204
|
const transform = get$3();
|
|
1170
1205
|
translate$1(transform, box.x + x, box.y + y);
|
|
1171
1206
|
scaleHelper(transform, scaleX, scaleY);
|
|
1172
|
-
if (rotation)
|
|
1173
|
-
|
|
1207
|
+
if (rotation) rotateOfOuter$1(transform, {
|
|
1208
|
+
x: box.x + box.width / 2,
|
|
1209
|
+
y: box.y + box.height / 2
|
|
1210
|
+
}, rotation);
|
|
1174
1211
|
data.transform = transform;
|
|
1175
1212
|
}
|
|
1213
|
+
|
|
1176
1214
|
function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
|
|
1177
1215
|
const transform = get$3();
|
|
1178
|
-
|
|
1179
|
-
rotate(transform, rotation);
|
|
1180
|
-
if (skew)
|
|
1181
|
-
skewHelper(transform, skew.x, skew.y);
|
|
1182
|
-
if (scaleX)
|
|
1183
|
-
scaleHelper(transform, scaleX, scaleY);
|
|
1184
|
-
translate$1(transform, box.x + x, box.y + y);
|
|
1216
|
+
layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
|
|
1185
1217
|
if (clipSize) {
|
|
1186
1218
|
tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
|
|
1187
1219
|
multiplyParent(transform, tempMatrix);
|
|
1188
1220
|
}
|
|
1189
1221
|
data.transform = transform;
|
|
1190
1222
|
}
|
|
1191
|
-
|
|
1223
|
+
|
|
1224
|
+
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
|
|
1192
1225
|
const transform = get$3();
|
|
1193
|
-
if (
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
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:
|
|
1201
1239
|
translate$1(transform, height, 0);
|
|
1202
1240
|
break;
|
|
1203
|
-
|
|
1241
|
+
|
|
1242
|
+
case 180:
|
|
1204
1243
|
translate$1(transform, width, height);
|
|
1205
1244
|
break;
|
|
1206
|
-
|
|
1245
|
+
|
|
1246
|
+
case 270:
|
|
1207
1247
|
translate$1(transform, 0, width);
|
|
1208
1248
|
break;
|
|
1249
|
+
}
|
|
1209
1250
|
}
|
|
1210
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);
|
|
1211
1256
|
}
|
|
1212
|
-
origin.x = box.x + x;
|
|
1213
|
-
origin.y = box.y + y;
|
|
1214
|
-
translate$1(transform, origin.x, origin.y);
|
|
1215
|
-
if (scaleX)
|
|
1216
|
-
scaleOfOuter$1(transform, origin, scaleX, scaleY);
|
|
1217
1257
|
data.transform = transform;
|
|
1218
1258
|
}
|
|
1219
1259
|
|
|
1220
|
-
|
|
1221
|
-
|
|
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
|
+
|
|
1222
1271
|
const tempScaleData = {};
|
|
1272
|
+
|
|
1223
1273
|
const tempImage = {};
|
|
1274
|
+
|
|
1224
1275
|
function createData(leafPaint, image, paint, box) {
|
|
1225
|
-
const { changeful, sync
|
|
1226
|
-
if (changeful)
|
|
1227
|
-
|
|
1228
|
-
if (
|
|
1229
|
-
leafPaint.sync = sync;
|
|
1230
|
-
if (editing)
|
|
1231
|
-
leafPaint.editing = editing;
|
|
1232
|
-
if (scaleFixed)
|
|
1233
|
-
leafPaint.scaleFixed = scaleFixed;
|
|
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;
|
|
1234
1280
|
leafPaint.data = getPatternData(paint, box, image);
|
|
1235
1281
|
}
|
|
1282
|
+
|
|
1236
1283
|
function getPatternData(paint, box, image) {
|
|
1237
|
-
if (paint.padding)
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
let { width, height } = image;
|
|
1242
|
-
const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, 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;
|
|
1243
1288
|
const sameBox = box.width === width && box.height === height;
|
|
1244
|
-
const data = {
|
|
1245
|
-
|
|
1289
|
+
const data = {
|
|
1290
|
+
mode: mode
|
|
1291
|
+
};
|
|
1292
|
+
const swapSize = align !== "center" && (rotation || 0) % 180 === 90;
|
|
1246
1293
|
BoundsHelper.set(tempImage, 0, 0, swapSize ? height : width, swapSize ? width : height);
|
|
1247
1294
|
let scaleX, scaleY;
|
|
1248
|
-
if (!mode || mode ===
|
|
1295
|
+
if (!mode || mode === "cover" || mode === "fit") {
|
|
1249
1296
|
if (!sameBox || rotation) {
|
|
1250
|
-
scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !==
|
|
1297
|
+
scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !== "fit");
|
|
1251
1298
|
BoundsHelper.put(box, image, align, scaleX, false, tempImage);
|
|
1252
1299
|
BoundsHelper.scale(tempImage, scaleX, scaleY, true);
|
|
1253
1300
|
}
|
|
1254
|
-
}
|
|
1255
|
-
else {
|
|
1301
|
+
} else {
|
|
1256
1302
|
if (scale || size) {
|
|
1257
1303
|
MathHelper.getScaleData(scale, size, image, tempScaleData);
|
|
1258
1304
|
scaleX = tempScaleData.scaleX;
|
|
1259
1305
|
scaleY = tempScaleData.scaleY;
|
|
1260
1306
|
}
|
|
1261
|
-
if (align) {
|
|
1262
|
-
if (scaleX)
|
|
1263
|
-
|
|
1264
|
-
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);
|
|
1265
1310
|
}
|
|
1266
1311
|
}
|
|
1267
|
-
if (offset)
|
|
1268
|
-
PointHelper.move(tempImage, offset);
|
|
1312
|
+
if (offset) PointHelper.move(tempImage, offset);
|
|
1269
1313
|
switch (mode) {
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
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);
|
|
1290
1334
|
}
|
|
1291
1335
|
if (!data.transform) {
|
|
1292
1336
|
if (box.x || box.y) {
|
|
@@ -1294,49 +1338,69 @@ function getPatternData(paint, box, image) {
|
|
|
1294
1338
|
translate(data.transform, box.x, box.y);
|
|
1295
1339
|
}
|
|
1296
1340
|
}
|
|
1297
|
-
if (scaleX && mode !==
|
|
1341
|
+
if (scaleX && mode !== "stretch") {
|
|
1298
1342
|
data.scaleX = scaleX;
|
|
1299
1343
|
data.scaleY = scaleY;
|
|
1300
1344
|
}
|
|
1301
1345
|
data.width = width;
|
|
1302
1346
|
data.height = height;
|
|
1303
|
-
if (opacity)
|
|
1304
|
-
|
|
1305
|
-
if (
|
|
1306
|
-
data.filters = filters;
|
|
1307
|
-
if (repeat)
|
|
1308
|
-
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";
|
|
1309
1350
|
return data;
|
|
1310
1351
|
}
|
|
1311
1352
|
|
|
1312
|
-
|
|
1313
|
-
|
|
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
|
+
|
|
1314
1373
|
function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
1315
1374
|
let leafPaint, event;
|
|
1316
1375
|
const image = ImageManager.get(paint);
|
|
1317
1376
|
if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
|
|
1318
1377
|
leafPaint = cache.leafPaint;
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
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
|
+
};
|
|
1328
1395
|
if (image.ready) {
|
|
1329
1396
|
checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
|
|
1330
1397
|
if (firstUse) {
|
|
1331
1398
|
onLoad(ui, event);
|
|
1332
1399
|
onLoadSuccess(ui, event);
|
|
1333
1400
|
}
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
onLoadError(ui, event, image.error);
|
|
1338
|
-
}
|
|
1339
|
-
else {
|
|
1401
|
+
} else if (image.error) {
|
|
1402
|
+
if (firstUse) onLoadError(ui, event, image.error);
|
|
1403
|
+
} else {
|
|
1340
1404
|
if (firstUse) {
|
|
1341
1405
|
ignoreRender(ui, true);
|
|
1342
1406
|
onLoad(ui, event);
|
|
@@ -1345,79 +1409,84 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
|
1345
1409
|
ignoreRender(ui, false);
|
|
1346
1410
|
if (!ui.destroyed) {
|
|
1347
1411
|
if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
|
|
1348
|
-
if (image.hasAlphaPixel)
|
|
1349
|
-
|
|
1350
|
-
ui.forceUpdate('surface');
|
|
1412
|
+
if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
|
|
1413
|
+
ui.forceUpdate("surface");
|
|
1351
1414
|
}
|
|
1352
1415
|
onLoadSuccess(ui, event);
|
|
1353
1416
|
}
|
|
1354
1417
|
leafPaint.loadId = undefined;
|
|
1355
|
-
},
|
|
1418
|
+
}, error => {
|
|
1356
1419
|
ignoreRender(ui, false);
|
|
1357
1420
|
onLoadError(ui, event, error);
|
|
1358
1421
|
leafPaint.loadId = undefined;
|
|
1359
1422
|
});
|
|
1360
1423
|
if (ui.placeholderColor) {
|
|
1361
|
-
if (!ui.placeholderDelay)
|
|
1362
|
-
image.
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
ui.forceUpdate('surface');
|
|
1368
|
-
}
|
|
1369
|
-
}, 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);
|
|
1370
1430
|
}
|
|
1371
1431
|
}
|
|
1372
1432
|
return leafPaint;
|
|
1373
1433
|
}
|
|
1434
|
+
|
|
1374
1435
|
function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
|
|
1375
|
-
if (attrName ===
|
|
1436
|
+
if (attrName === "fill" && !ui.__.__naturalWidth) {
|
|
1376
1437
|
const data = ui.__;
|
|
1377
1438
|
data.__naturalWidth = image.width / data.pixelRatio;
|
|
1378
1439
|
data.__naturalHeight = image.height / data.pixelRatio;
|
|
1379
1440
|
if (data.__autoSide) {
|
|
1380
|
-
ui.forceUpdate(
|
|
1441
|
+
ui.forceUpdate("width");
|
|
1381
1442
|
if (ui.__proxyData) {
|
|
1382
|
-
ui.setProxyAttr(
|
|
1383
|
-
ui.setProxyAttr(
|
|
1443
|
+
ui.setProxyAttr("width", data.width);
|
|
1444
|
+
ui.setProxyAttr("height", data.height);
|
|
1384
1445
|
}
|
|
1385
1446
|
return false;
|
|
1386
1447
|
}
|
|
1387
1448
|
}
|
|
1388
|
-
if (!leafPaint.data)
|
|
1389
|
-
createData(leafPaint, image, paint, boxBounds);
|
|
1449
|
+
if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
|
|
1390
1450
|
return true;
|
|
1391
1451
|
}
|
|
1452
|
+
|
|
1392
1453
|
function onLoad(ui, event) {
|
|
1393
1454
|
emit(ui, ImageEvent.LOAD, event);
|
|
1394
1455
|
}
|
|
1456
|
+
|
|
1395
1457
|
function onLoadSuccess(ui, event) {
|
|
1396
1458
|
emit(ui, ImageEvent.LOADED, event);
|
|
1397
1459
|
}
|
|
1460
|
+
|
|
1398
1461
|
function onLoadError(ui, event, error) {
|
|
1399
1462
|
event.error = error;
|
|
1400
|
-
ui.forceUpdate(
|
|
1463
|
+
ui.forceUpdate("surface");
|
|
1401
1464
|
emit(ui, ImageEvent.ERROR, event);
|
|
1402
1465
|
}
|
|
1466
|
+
|
|
1403
1467
|
function emit(ui, type, data) {
|
|
1404
|
-
if (ui.hasEvent(type))
|
|
1405
|
-
ui.emitEvent(new ImageEvent(type, data));
|
|
1468
|
+
if (ui.hasEvent(type)) ui.emitEvent(new ImageEvent(type, data));
|
|
1406
1469
|
}
|
|
1470
|
+
|
|
1407
1471
|
function ignoreRender(ui, value) {
|
|
1408
|
-
const { leafer
|
|
1409
|
-
if (leafer && leafer.viewReady)
|
|
1410
|
-
leafer.renderer.ignore = value;
|
|
1472
|
+
const {leafer: leafer} = ui;
|
|
1473
|
+
if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
|
|
1411
1474
|
}
|
|
1412
1475
|
|
|
1413
|
-
const {
|
|
1414
|
-
|
|
1476
|
+
const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
|
|
1477
|
+
|
|
1478
|
+
const {floor: floor, max: max, abs: abs} = Math;
|
|
1479
|
+
|
|
1415
1480
|
function createPattern(ui, paint, pixelRatio) {
|
|
1416
|
-
let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1417
|
-
const id = scaleX +
|
|
1481
|
+
let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1482
|
+
const id = scaleX + "-" + scaleY + "-" + pixelRatio;
|
|
1418
1483
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1419
|
-
const { image, data } = paint;
|
|
1420
|
-
let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
|
|
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;
|
|
1421
1490
|
if (sx) {
|
|
1422
1491
|
sx = abs(sx);
|
|
1423
1492
|
sy = abs(sy);
|
|
@@ -1427,23 +1496,18 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1427
1496
|
scaleX *= sx;
|
|
1428
1497
|
scaleY *= sy;
|
|
1429
1498
|
}
|
|
1430
|
-
scaleX *= pixelRatio;
|
|
1431
|
-
scaleY *= pixelRatio;
|
|
1432
1499
|
width *= scaleX;
|
|
1433
1500
|
height *= scaleY;
|
|
1434
1501
|
const size = width * height;
|
|
1435
1502
|
if (!repeat) {
|
|
1436
|
-
if (size > Platform.image.maxCacheSize)
|
|
1437
|
-
return false;
|
|
1503
|
+
if (size > Platform.image.maxCacheSize) return false;
|
|
1438
1504
|
}
|
|
1439
1505
|
let maxSize = Platform.image.maxPatternSize;
|
|
1440
1506
|
if (!image.isSVG) {
|
|
1441
1507
|
const imageSize = image.width * image.height;
|
|
1442
|
-
if (maxSize > imageSize)
|
|
1443
|
-
maxSize = imageSize;
|
|
1508
|
+
if (maxSize > imageSize) maxSize = imageSize;
|
|
1444
1509
|
}
|
|
1445
|
-
if (size > maxSize)
|
|
1446
|
-
imageScale = Math.sqrt(size / maxSize);
|
|
1510
|
+
if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
|
|
1447
1511
|
if (imageScale) {
|
|
1448
1512
|
scaleX /= imageScale;
|
|
1449
1513
|
scaleY /= imageScale;
|
|
@@ -1457,65 +1521,62 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1457
1521
|
if (transform || scaleX !== 1 || scaleY !== 1) {
|
|
1458
1522
|
if (!imageMatrix) {
|
|
1459
1523
|
imageMatrix = get$1();
|
|
1460
|
-
if (transform)
|
|
1461
|
-
copy$1(imageMatrix, transform);
|
|
1524
|
+
if (transform) copy$1(imageMatrix, transform);
|
|
1462
1525
|
}
|
|
1463
1526
|
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1464
1527
|
}
|
|
1465
|
-
|
|
1466
|
-
|
|
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);
|
|
1467
1534
|
paint.style = pattern;
|
|
1468
1535
|
paint.patternId = id;
|
|
1469
1536
|
return true;
|
|
1470
|
-
}
|
|
1471
|
-
else {
|
|
1537
|
+
} else {
|
|
1472
1538
|
return false;
|
|
1473
1539
|
}
|
|
1474
1540
|
}
|
|
1475
1541
|
|
|
1476
1542
|
function checkImage(ui, canvas, paint, allowDraw) {
|
|
1477
|
-
const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1478
|
-
const { pixelRatio
|
|
1479
|
-
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) {
|
|
1480
1546
|
return false;
|
|
1481
|
-
}
|
|
1482
|
-
else {
|
|
1547
|
+
} else {
|
|
1483
1548
|
if (allowDraw) {
|
|
1484
1549
|
if (data.repeat) {
|
|
1485
1550
|
allowDraw = false;
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
let { width, height } = data;
|
|
1551
|
+
} else {
|
|
1552
|
+
if (!(paint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || Export.running)) {
|
|
1553
|
+
let {width: width, height: height} = data;
|
|
1490
1554
|
width *= scaleX * pixelRatio;
|
|
1491
1555
|
height *= scaleY * pixelRatio;
|
|
1492
1556
|
if (data.scaleX) {
|
|
1493
1557
|
width *= data.scaleX;
|
|
1494
1558
|
height *= data.scaleY;
|
|
1495
1559
|
}
|
|
1496
|
-
allowDraw =
|
|
1560
|
+
allowDraw = width * height > Platform.image.maxCacheSize;
|
|
1497
1561
|
}
|
|
1498
1562
|
}
|
|
1499
1563
|
}
|
|
1500
1564
|
if (allowDraw) {
|
|
1501
1565
|
if (ui.__.__isFastShadow) {
|
|
1502
|
-
canvas.fillStyle = paint.style ||
|
|
1566
|
+
canvas.fillStyle = paint.style || "#000";
|
|
1503
1567
|
canvas.fill();
|
|
1504
1568
|
}
|
|
1505
1569
|
drawImage(ui, canvas, paint, data);
|
|
1506
1570
|
return true;
|
|
1507
|
-
}
|
|
1508
|
-
else {
|
|
1571
|
+
} else {
|
|
1509
1572
|
if (!paint.style || paint.sync || Export.running) {
|
|
1510
1573
|
createPattern(ui, paint, pixelRatio);
|
|
1511
|
-
}
|
|
1512
|
-
else {
|
|
1574
|
+
} else {
|
|
1513
1575
|
if (!paint.patternTask) {
|
|
1514
|
-
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*() {
|
|
1515
1577
|
paint.patternTask = null;
|
|
1516
|
-
if (canvas.bounds.hit(ui.__nowWorld))
|
|
1517
|
-
|
|
1518
|
-
ui.forceUpdate('surface');
|
|
1578
|
+
if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
|
|
1579
|
+
ui.forceUpdate("surface");
|
|
1519
1580
|
}), 300);
|
|
1520
1581
|
}
|
|
1521
1582
|
}
|
|
@@ -1523,39 +1584,35 @@ function checkImage(ui, canvas, paint, allowDraw) {
|
|
|
1523
1584
|
}
|
|
1524
1585
|
}
|
|
1525
1586
|
}
|
|
1587
|
+
|
|
1526
1588
|
function drawImage(ui, canvas, paint, data) {
|
|
1527
1589
|
canvas.save();
|
|
1528
1590
|
canvas.clipUI(ui);
|
|
1529
|
-
if (paint.blendMode)
|
|
1530
|
-
|
|
1531
|
-
if (data.
|
|
1532
|
-
canvas.opacity *= data.opacity;
|
|
1533
|
-
if (data.transform)
|
|
1534
|
-
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);
|
|
1535
1594
|
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
|
|
1536
1595
|
canvas.restore();
|
|
1537
1596
|
}
|
|
1538
1597
|
|
|
1539
1598
|
function recycleImage(attrName, data) {
|
|
1540
|
-
const paints = data[
|
|
1541
|
-
if (paints
|
|
1599
|
+
const paints = data["_" + attrName];
|
|
1600
|
+
if (isArray(paints)) {
|
|
1542
1601
|
let paint, image, recycleMap, input, url;
|
|
1543
1602
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
1544
1603
|
paint = paints[i];
|
|
1545
1604
|
image = paint.image;
|
|
1546
1605
|
url = image && image.url;
|
|
1547
1606
|
if (url) {
|
|
1548
|
-
if (!recycleMap)
|
|
1549
|
-
recycleMap = {};
|
|
1607
|
+
if (!recycleMap) recycleMap = {};
|
|
1550
1608
|
recycleMap[url] = true;
|
|
1551
1609
|
ImageManager.recycle(image);
|
|
1552
1610
|
if (image.loading) {
|
|
1553
1611
|
if (!input) {
|
|
1554
|
-
input =
|
|
1555
|
-
if (!(input
|
|
1556
|
-
input = [input];
|
|
1612
|
+
input = data.__input && data.__input[attrName] || [];
|
|
1613
|
+
if (!isArray(input)) input = [ input ];
|
|
1557
1614
|
}
|
|
1558
|
-
image.unload(paints[i].loadId, !input.some(
|
|
1615
|
+
image.unload(paints[i].loadId, !input.some(item => item.url === url));
|
|
1559
1616
|
}
|
|
1560
1617
|
}
|
|
1561
1618
|
}
|
|
@@ -1565,75 +1622,85 @@ function recycleImage(attrName, data) {
|
|
|
1565
1622
|
}
|
|
1566
1623
|
|
|
1567
1624
|
const PaintImageModule = {
|
|
1568
|
-
image,
|
|
1569
|
-
checkImage,
|
|
1570
|
-
createPattern,
|
|
1571
|
-
recycleImage,
|
|
1572
|
-
createData,
|
|
1573
|
-
getPatternData,
|
|
1574
|
-
fillOrFitMode,
|
|
1575
|
-
clipMode,
|
|
1576
|
-
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
|
|
1577
1634
|
};
|
|
1578
1635
|
|
|
1579
|
-
const {
|
|
1636
|
+
const {toPoint: toPoint$2} = AroundHelper, {hasTransparent: hasTransparent} = ColorConvert;
|
|
1637
|
+
|
|
1580
1638
|
const realFrom$2 = {};
|
|
1639
|
+
|
|
1581
1640
|
const realTo$2 = {};
|
|
1641
|
+
|
|
1582
1642
|
function linearGradient(paint, box) {
|
|
1583
|
-
let { from, to, type, opacity } = paint;
|
|
1584
|
-
toPoint$2(from ||
|
|
1585
|
-
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);
|
|
1586
1646
|
const style = Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
|
|
1587
|
-
const data = {
|
|
1647
|
+
const data = {
|
|
1648
|
+
type: type,
|
|
1649
|
+
style: style
|
|
1650
|
+
};
|
|
1588
1651
|
applyStops(data, style, paint.stops, opacity);
|
|
1589
1652
|
return data;
|
|
1590
1653
|
}
|
|
1654
|
+
|
|
1591
1655
|
function applyStops(data, gradient, stops, opacity) {
|
|
1592
1656
|
if (stops) {
|
|
1593
1657
|
let stop, color, offset, isTransparent;
|
|
1594
1658
|
for (let i = 0, len = stops.length; i < len; i++) {
|
|
1595
1659
|
stop = stops[i];
|
|
1596
|
-
if (
|
|
1597
|
-
|
|
1598
|
-
else
|
|
1599
|
-
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);
|
|
1600
1662
|
gradient.addColorStop(offset, color);
|
|
1601
|
-
if (!isTransparent && hasTransparent(color))
|
|
1602
|
-
isTransparent = true;
|
|
1663
|
+
if (!isTransparent && hasTransparent(color)) isTransparent = true;
|
|
1603
1664
|
}
|
|
1604
|
-
if (isTransparent)
|
|
1605
|
-
data.isTransparent = true;
|
|
1665
|
+
if (isTransparent) data.isTransparent = true;
|
|
1606
1666
|
}
|
|
1607
1667
|
}
|
|
1608
1668
|
|
|
1609
|
-
const { getAngle, getDistance: getDistance$1
|
|
1610
|
-
|
|
1611
|
-
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
|
+
|
|
1612
1675
|
const realFrom$1 = {};
|
|
1676
|
+
|
|
1613
1677
|
const realTo$1 = {};
|
|
1678
|
+
|
|
1614
1679
|
function radialGradient(paint, box) {
|
|
1615
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1616
|
-
toPoint$1(from ||
|
|
1617
|
-
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);
|
|
1618
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));
|
|
1619
|
-
const data = {
|
|
1684
|
+
const data = {
|
|
1685
|
+
type: type,
|
|
1686
|
+
style: style
|
|
1687
|
+
};
|
|
1620
1688
|
applyStops(data, style, paint.stops, opacity);
|
|
1621
1689
|
const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
|
|
1622
|
-
if (transform)
|
|
1623
|
-
data.transform = transform;
|
|
1690
|
+
if (transform) data.transform = transform;
|
|
1624
1691
|
return data;
|
|
1625
1692
|
}
|
|
1693
|
+
|
|
1626
1694
|
function getTransform(box, from, to, stretch, rotate90) {
|
|
1627
1695
|
let transform;
|
|
1628
|
-
const { width, height } = box;
|
|
1696
|
+
const {width: width, height: height} = box;
|
|
1629
1697
|
if (width !== height || stretch) {
|
|
1630
1698
|
const angle = getAngle(from, to);
|
|
1631
1699
|
transform = get();
|
|
1632
1700
|
if (rotate90) {
|
|
1633
1701
|
scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
|
|
1634
1702
|
rotateOfOuter(transform, from, angle + 90);
|
|
1635
|
-
}
|
|
1636
|
-
else {
|
|
1703
|
+
} else {
|
|
1637
1704
|
scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
|
|
1638
1705
|
rotateOfOuter(transform, from, angle);
|
|
1639
1706
|
}
|
|
@@ -1641,81 +1708,94 @@ function getTransform(box, from, to, stretch, rotate90) {
|
|
|
1641
1708
|
return transform;
|
|
1642
1709
|
}
|
|
1643
1710
|
|
|
1644
|
-
const { getDistance
|
|
1645
|
-
|
|
1711
|
+
const {getDistance: getDistance} = PointHelper;
|
|
1712
|
+
|
|
1713
|
+
const {toPoint: toPoint} = AroundHelper;
|
|
1714
|
+
|
|
1646
1715
|
const realFrom = {};
|
|
1716
|
+
|
|
1647
1717
|
const realTo = {};
|
|
1718
|
+
|
|
1648
1719
|
function conicGradient(paint, box) {
|
|
1649
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1650
|
-
toPoint(from ||
|
|
1651
|
-
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);
|
|
1652
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));
|
|
1653
|
-
const data = {
|
|
1724
|
+
const data = {
|
|
1725
|
+
type: type,
|
|
1726
|
+
style: style
|
|
1727
|
+
};
|
|
1654
1728
|
applyStops(data, style, paint.stops, opacity);
|
|
1655
1729
|
const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
|
|
1656
|
-
if (transform)
|
|
1657
|
-
data.transform = transform;
|
|
1730
|
+
if (transform) data.transform = transform;
|
|
1658
1731
|
return data;
|
|
1659
1732
|
}
|
|
1660
1733
|
|
|
1661
1734
|
const PaintGradientModule = {
|
|
1662
|
-
linearGradient,
|
|
1663
|
-
radialGradient,
|
|
1664
|
-
conicGradient,
|
|
1665
|
-
getTransform
|
|
1735
|
+
linearGradient: linearGradient,
|
|
1736
|
+
radialGradient: radialGradient,
|
|
1737
|
+
conicGradient: conicGradient,
|
|
1738
|
+
getTransform: getTransform
|
|
1666
1739
|
};
|
|
1667
1740
|
|
|
1668
|
-
const { copy, toOffsetOutBounds: toOffsetOutBounds$1
|
|
1741
|
+
const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = BoundsHelper;
|
|
1742
|
+
|
|
1669
1743
|
const tempBounds = {};
|
|
1744
|
+
|
|
1670
1745
|
const offsetOutBounds$1 = {};
|
|
1746
|
+
|
|
1671
1747
|
function shadow(ui, current, shape) {
|
|
1672
1748
|
let copyBounds, spreadScale;
|
|
1673
|
-
const {
|
|
1674
|
-
const { shadow
|
|
1675
|
-
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;
|
|
1676
1752
|
const other = current.getSameCanvas();
|
|
1677
1753
|
const end = shadow.length - 1;
|
|
1678
1754
|
toOffsetOutBounds$1(bounds, offsetOutBounds$1);
|
|
1679
1755
|
shadow.forEach((item, index) => {
|
|
1680
|
-
|
|
1681
|
-
|
|
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;
|
|
1682
1763
|
drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
|
|
1683
1764
|
copyBounds = bounds;
|
|
1684
1765
|
if (item.box) {
|
|
1685
1766
|
other.restore();
|
|
1686
1767
|
other.save();
|
|
1687
1768
|
if (worldCanvas) {
|
|
1688
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
1769
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
1689
1770
|
copyBounds = nowWorld;
|
|
1690
1771
|
}
|
|
1691
|
-
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
1772
|
+
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
|
|
1692
1773
|
}
|
|
1693
1774
|
LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1694
|
-
if (end && index < end)
|
|
1695
|
-
other.clearWorld(copyBounds, true);
|
|
1775
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
1696
1776
|
});
|
|
1697
1777
|
other.recycle(copyBounds);
|
|
1698
1778
|
}
|
|
1779
|
+
|
|
1699
1780
|
function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
1700
|
-
const { bounds, shapeBounds } = shape;
|
|
1781
|
+
const {bounds: bounds, shapeBounds: shapeBounds} = shape;
|
|
1701
1782
|
if (Platform.fullImageShadow) {
|
|
1702
1783
|
copy(tempBounds, canvas.bounds);
|
|
1703
|
-
tempBounds.x +=
|
|
1704
|
-
tempBounds.y +=
|
|
1784
|
+
tempBounds.x += outBounds.x - shapeBounds.x;
|
|
1785
|
+
tempBounds.y += outBounds.y - shapeBounds.y;
|
|
1705
1786
|
if (spreadScale) {
|
|
1706
|
-
const {
|
|
1707
|
-
tempBounds.x -= (bounds.x + (
|
|
1708
|
-
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);
|
|
1709
1790
|
tempBounds.width *= spreadScale;
|
|
1710
1791
|
tempBounds.height *= spreadScale;
|
|
1711
1792
|
}
|
|
1712
1793
|
canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
|
|
1713
|
-
}
|
|
1714
|
-
else {
|
|
1794
|
+
} else {
|
|
1715
1795
|
if (spreadScale) {
|
|
1716
1796
|
copy(tempBounds, outBounds);
|
|
1717
|
-
tempBounds.x -=
|
|
1718
|
-
tempBounds.y -=
|
|
1797
|
+
tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
|
|
1798
|
+
tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
|
|
1719
1799
|
tempBounds.width *= spreadScale;
|
|
1720
1800
|
tempBounds.height *= spreadScale;
|
|
1721
1801
|
}
|
|
@@ -1723,174 +1803,184 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
|
1723
1803
|
}
|
|
1724
1804
|
}
|
|
1725
1805
|
|
|
1726
|
-
const { toOffsetOutBounds
|
|
1806
|
+
const {toOffsetOutBounds: toOffsetOutBounds} = BoundsHelper;
|
|
1807
|
+
|
|
1727
1808
|
const offsetOutBounds = {};
|
|
1809
|
+
|
|
1728
1810
|
function innerShadow(ui, current, shape) {
|
|
1729
1811
|
let copyBounds, spreadScale;
|
|
1730
|
-
const {
|
|
1731
|
-
const { innerShadow
|
|
1732
|
-
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;
|
|
1733
1815
|
const other = current.getSameCanvas();
|
|
1734
1816
|
const end = innerShadow.length - 1;
|
|
1735
1817
|
toOffsetOutBounds(bounds, offsetOutBounds);
|
|
1736
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
|
+
}
|
|
1737
1824
|
other.save();
|
|
1738
|
-
other.setWorldShadow(
|
|
1739
|
-
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;
|
|
1740
1827
|
drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
|
|
1741
1828
|
other.restore();
|
|
1742
1829
|
if (worldCanvas) {
|
|
1743
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
1744
|
-
other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
1830
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
1831
|
+
other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
|
|
1745
1832
|
copyBounds = nowWorld;
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1748
|
-
other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out');
|
|
1833
|
+
} else {
|
|
1834
|
+
other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
|
|
1749
1835
|
copyBounds = bounds;
|
|
1750
1836
|
}
|
|
1751
|
-
other.fillWorld(copyBounds, ColorConvert.string(item.color),
|
|
1837
|
+
other.fillWorld(copyBounds, ColorConvert.string(item.color), "source-in");
|
|
1752
1838
|
LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1753
|
-
if (end && index < end)
|
|
1754
|
-
other.clearWorld(copyBounds, true);
|
|
1839
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
1755
1840
|
});
|
|
1756
1841
|
other.recycle(copyBounds);
|
|
1757
1842
|
}
|
|
1758
1843
|
|
|
1759
1844
|
function blur(ui, current, origin) {
|
|
1760
|
-
const { blur
|
|
1845
|
+
const {blur: blur} = ui.__;
|
|
1761
1846
|
origin.setWorldBlur(blur * ui.__nowWorld.a);
|
|
1762
1847
|
origin.copyWorldToInner(current, ui.__nowWorld, ui.__layout.renderBounds);
|
|
1763
|
-
origin.filter =
|
|
1848
|
+
origin.filter = "none";
|
|
1764
1849
|
}
|
|
1765
1850
|
|
|
1766
|
-
function backgroundBlur(_ui, _current, _shape) {
|
|
1767
|
-
}
|
|
1851
|
+
function backgroundBlur(_ui, _current, _shape) {}
|
|
1768
1852
|
|
|
1769
1853
|
const EffectModule = {
|
|
1770
|
-
shadow,
|
|
1771
|
-
innerShadow,
|
|
1772
|
-
blur,
|
|
1773
|
-
backgroundBlur
|
|
1854
|
+
shadow: shadow,
|
|
1855
|
+
innerShadow: innerShadow,
|
|
1856
|
+
blur: blur,
|
|
1857
|
+
backgroundBlur: backgroundBlur
|
|
1774
1858
|
};
|
|
1775
1859
|
|
|
1776
|
-
const { excludeRenderBounds
|
|
1777
|
-
|
|
1860
|
+
const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper;
|
|
1861
|
+
|
|
1862
|
+
let usedGrayscaleAlpha;
|
|
1863
|
+
|
|
1864
|
+
Group.prototype.__renderMask = function(canvas, options) {
|
|
1778
1865
|
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
1779
|
-
const { children
|
|
1866
|
+
const {children: children} = this;
|
|
1780
1867
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
1781
1868
|
child = children[i], mask = child.__.mask;
|
|
1782
1869
|
if (mask) {
|
|
1783
1870
|
if (currentMask) {
|
|
1784
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1871
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
1785
1872
|
maskCanvas = contentCanvas = null;
|
|
1786
1873
|
}
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
}
|
|
1794
|
-
|
|
1795
|
-
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";
|
|
1796
1882
|
canvas.save();
|
|
1797
1883
|
}
|
|
1798
1884
|
child.__clip(contentCanvas || canvas, options);
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
if (!
|
|
1803
|
-
maskCanvas = getCanvas(canvas);
|
|
1804
|
-
if (!contentCanvas)
|
|
1805
|
-
contentCanvas = getCanvas(canvas);
|
|
1885
|
+
} else {
|
|
1886
|
+
currentMask = mask === "grayscale" ? "grayscale" : "alpha";
|
|
1887
|
+
if (!maskCanvas) maskCanvas = getCanvas(canvas);
|
|
1888
|
+
if (!contentCanvas) contentCanvas = getCanvas(canvas);
|
|
1806
1889
|
child.__render(maskCanvas, options);
|
|
1807
1890
|
}
|
|
1808
|
-
if (mask ===
|
|
1809
|
-
excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
1891
|
+
if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
1810
1892
|
continue;
|
|
1811
1893
|
}
|
|
1894
|
+
const childBlendMode = maskOpacity === 1 && child.__.__blendMode;
|
|
1895
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, false);
|
|
1812
1896
|
excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
|
|
1897
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, childBlendMode, false);
|
|
1813
1898
|
}
|
|
1814
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1899
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
1815
1900
|
};
|
|
1816
|
-
|
|
1901
|
+
|
|
1902
|
+
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity, blendMode, recycle) {
|
|
1817
1903
|
switch (maskMode) {
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
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();
|
|
1828
1917
|
}
|
|
1829
1918
|
}
|
|
1919
|
+
|
|
1830
1920
|
function getCanvas(canvas) {
|
|
1831
1921
|
return canvas.getSameCanvas(false, true);
|
|
1832
1922
|
}
|
|
1833
|
-
|
|
1923
|
+
|
|
1924
|
+
function usePixelMask(leaf, canvas, content, mask, blendMode, recycle) {
|
|
1834
1925
|
const realBounds = leaf.__nowWorld;
|
|
1835
1926
|
content.resetTransform();
|
|
1836
1927
|
content.opacity = 1;
|
|
1837
1928
|
content.useMask(mask, realBounds);
|
|
1838
|
-
mask.recycle(realBounds);
|
|
1839
|
-
copyContent(leaf, canvas, content, 1);
|
|
1929
|
+
if (recycle) mask.recycle(realBounds);
|
|
1930
|
+
copyContent(leaf, canvas, content, 1, blendMode, recycle);
|
|
1840
1931
|
}
|
|
1841
|
-
|
|
1932
|
+
|
|
1933
|
+
function copyContent(leaf, canvas, content, maskOpacity, blendMode, recycle) {
|
|
1842
1934
|
const realBounds = leaf.__nowWorld;
|
|
1843
1935
|
canvas.resetTransform();
|
|
1844
1936
|
canvas.opacity = maskOpacity;
|
|
1845
|
-
canvas.copyWorld(content, realBounds);
|
|
1846
|
-
content.recycle(realBounds);
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
const money =
|
|
1850
|
-
|
|
1851
|
-
const
|
|
1852
|
-
|
|
1853
|
-
const
|
|
1854
|
-
|
|
1855
|
-
const
|
|
1856
|
-
|
|
1857
|
-
const
|
|
1858
|
-
|
|
1859
|
-
const
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
[0x31C0, 0x31EF],
|
|
1874
|
-
[0x3200, 0x32FF],
|
|
1875
|
-
[0x3300, 0x33FF],
|
|
1876
|
-
[0xF900, 0xFAFF],
|
|
1877
|
-
[0xFE30, 0xFE4F],
|
|
1878
|
-
[0x1F200, 0x1F2FF],
|
|
1879
|
-
[0x2F800, 0x2FA1F],
|
|
1880
|
-
];
|
|
1881
|
-
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
|
+
|
|
1882
1965
|
function mapChar(str) {
|
|
1883
1966
|
const map = {};
|
|
1884
|
-
str.split(
|
|
1967
|
+
str.split("").forEach(char => map[char] = true);
|
|
1885
1968
|
return map;
|
|
1886
1969
|
}
|
|
1970
|
+
|
|
1887
1971
|
const letterMap = mapChar(letter);
|
|
1972
|
+
|
|
1888
1973
|
const beforeMap = mapChar(beforeChar);
|
|
1974
|
+
|
|
1889
1975
|
const afterMap = mapChar(afterChar);
|
|
1976
|
+
|
|
1890
1977
|
const symbolMap = mapChar(symbolChar);
|
|
1978
|
+
|
|
1891
1979
|
const breakMap = mapChar(breakChar);
|
|
1980
|
+
|
|
1892
1981
|
var CharType;
|
|
1893
|
-
|
|
1982
|
+
|
|
1983
|
+
(function(CharType) {
|
|
1894
1984
|
CharType[CharType["Letter"] = 0] = "Letter";
|
|
1895
1985
|
CharType[CharType["Single"] = 1] = "Single";
|
|
1896
1986
|
CharType[CharType["Before"] = 2] = "Before";
|
|
@@ -1898,179 +1988,175 @@ var CharType;
|
|
|
1898
1988
|
CharType[CharType["Symbol"] = 4] = "Symbol";
|
|
1899
1989
|
CharType[CharType["Break"] = 5] = "Break";
|
|
1900
1990
|
})(CharType || (CharType = {}));
|
|
1901
|
-
|
|
1991
|
+
|
|
1992
|
+
const {Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1} = CharType;
|
|
1993
|
+
|
|
1902
1994
|
function getCharType(char) {
|
|
1903
1995
|
if (letterMap[char]) {
|
|
1904
1996
|
return Letter$1;
|
|
1905
|
-
}
|
|
1906
|
-
else if (breakMap[char]) {
|
|
1997
|
+
} else if (breakMap[char]) {
|
|
1907
1998
|
return Break$1;
|
|
1908
|
-
}
|
|
1909
|
-
else if (beforeMap[char]) {
|
|
1999
|
+
} else if (beforeMap[char]) {
|
|
1910
2000
|
return Before$1;
|
|
1911
|
-
}
|
|
1912
|
-
else if (afterMap[char]) {
|
|
2001
|
+
} else if (afterMap[char]) {
|
|
1913
2002
|
return After$1;
|
|
1914
|
-
}
|
|
1915
|
-
else if (symbolMap[char]) {
|
|
2003
|
+
} else if (symbolMap[char]) {
|
|
1916
2004
|
return Symbol$1;
|
|
1917
|
-
}
|
|
1918
|
-
else if (cjkReg.test(char)) {
|
|
2005
|
+
} else if (cjkReg.test(char)) {
|
|
1919
2006
|
return Single$1;
|
|
1920
|
-
}
|
|
1921
|
-
else {
|
|
2007
|
+
} else {
|
|
1922
2008
|
return Letter$1;
|
|
1923
2009
|
}
|
|
1924
2010
|
}
|
|
1925
2011
|
|
|
1926
2012
|
const TextRowHelper = {
|
|
1927
2013
|
trimRight(row) {
|
|
1928
|
-
const { words
|
|
2014
|
+
const {words: words} = row;
|
|
1929
2015
|
let trimRight = 0, len = words.length, char;
|
|
1930
2016
|
for (let i = len - 1; i > -1; i--) {
|
|
1931
2017
|
char = words[i].data[0];
|
|
1932
|
-
if (char.char ===
|
|
2018
|
+
if (char.char === " ") {
|
|
1933
2019
|
trimRight++;
|
|
1934
2020
|
row.width -= char.width;
|
|
1935
|
-
}
|
|
1936
|
-
else {
|
|
2021
|
+
} else {
|
|
1937
2022
|
break;
|
|
1938
2023
|
}
|
|
1939
2024
|
}
|
|
1940
|
-
if (trimRight)
|
|
1941
|
-
words.splice(len - trimRight, trimRight);
|
|
2025
|
+
if (trimRight) words.splice(len - trimRight, trimRight);
|
|
1942
2026
|
}
|
|
1943
2027
|
};
|
|
1944
2028
|
|
|
1945
2029
|
function getTextCase(char, textCase, firstChar) {
|
|
1946
2030
|
switch (textCase) {
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
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;
|
|
1955
2042
|
}
|
|
1956
2043
|
}
|
|
1957
2044
|
|
|
1958
|
-
const { trimRight
|
|
1959
|
-
|
|
2045
|
+
const {trimRight: trimRight} = TextRowHelper;
|
|
2046
|
+
|
|
2047
|
+
const {Letter: Letter, Single: Single, Before: Before, After: After, Symbol: Symbol, Break: Break} = CharType;
|
|
2048
|
+
|
|
1960
2049
|
let word, row, wordWidth, rowWidth, realWidth;
|
|
2050
|
+
|
|
1961
2051
|
let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
|
|
2052
|
+
|
|
1962
2053
|
let textDrawData, rows = [], bounds, findMaxWidth;
|
|
2054
|
+
|
|
1963
2055
|
function createRows(drawData, content, style) {
|
|
1964
2056
|
textDrawData = drawData;
|
|
1965
2057
|
rows = drawData.rows;
|
|
1966
2058
|
bounds = drawData.bounds;
|
|
1967
2059
|
findMaxWidth = !bounds.width && !style.autoSizeAlign;
|
|
1968
|
-
const { __letterSpacing, paraIndent, textCase } = style;
|
|
1969
|
-
const { canvas
|
|
1970
|
-
const { width, height } = bounds;
|
|
1971
|
-
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";
|
|
1972
2064
|
if (charMode) {
|
|
1973
|
-
const wrap = style.textWrap !==
|
|
1974
|
-
const breakAll = style.textWrap ===
|
|
2065
|
+
const wrap = style.textWrap !== "none";
|
|
2066
|
+
const breakAll = style.textWrap === "break";
|
|
1975
2067
|
paraStart = true;
|
|
1976
2068
|
lastCharType = null;
|
|
1977
2069
|
startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
|
|
1978
|
-
word = {
|
|
1979
|
-
|
|
1980
|
-
|
|
2070
|
+
word = {
|
|
2071
|
+
data: []
|
|
2072
|
+
}, row = {
|
|
2073
|
+
words: []
|
|
2074
|
+
};
|
|
2075
|
+
if (__letterSpacing) content = [ ...content ];
|
|
1981
2076
|
for (let i = 0, len = content.length; i < len; i++) {
|
|
1982
2077
|
char = content[i];
|
|
1983
|
-
if (char ===
|
|
1984
|
-
if (wordWidth)
|
|
1985
|
-
addWord();
|
|
2078
|
+
if (char === "\n") {
|
|
2079
|
+
if (wordWidth) addWord();
|
|
1986
2080
|
row.paraEnd = true;
|
|
1987
2081
|
addRow();
|
|
1988
2082
|
paraStart = true;
|
|
1989
|
-
}
|
|
1990
|
-
else {
|
|
2083
|
+
} else {
|
|
1991
2084
|
charType = getCharType(char);
|
|
1992
|
-
if (charType === Letter && textCase !==
|
|
1993
|
-
char = getTextCase(char, textCase, !wordWidth);
|
|
2085
|
+
if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
|
|
1994
2086
|
charWidth = canvas.measureText(char).width;
|
|
1995
2087
|
if (__letterSpacing) {
|
|
1996
|
-
if (__letterSpacing < 0)
|
|
1997
|
-
charSize = charWidth;
|
|
2088
|
+
if (__letterSpacing < 0) charSize = charWidth;
|
|
1998
2089
|
charWidth += __letterSpacing;
|
|
1999
2090
|
}
|
|
2000
|
-
langBreak =
|
|
2001
|
-
afterBreak = (
|
|
2091
|
+
langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
|
|
2092
|
+
afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
|
|
2002
2093
|
realWidth = paraStart && paraIndent ? width - paraIndent : width;
|
|
2003
2094
|
if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
|
|
2004
2095
|
if (breakAll) {
|
|
2005
|
-
if (wordWidth)
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
if (wordWidth)
|
|
2015
|
-
addWord();
|
|
2016
|
-
if (rowWidth)
|
|
2017
|
-
addRow();
|
|
2018
|
-
}
|
|
2019
|
-
else {
|
|
2020
|
-
if (rowWidth)
|
|
2021
|
-
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();
|
|
2022
2105
|
}
|
|
2023
2106
|
}
|
|
2024
2107
|
}
|
|
2025
|
-
if (char ===
|
|
2026
|
-
else {
|
|
2108
|
+
if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
|
|
2027
2109
|
if (charType === Break) {
|
|
2028
|
-
if (char ===
|
|
2029
|
-
addWord();
|
|
2110
|
+
if (char === " " && wordWidth) addWord();
|
|
2030
2111
|
addChar(char, charWidth);
|
|
2031
2112
|
addWord();
|
|
2032
|
-
}
|
|
2033
|
-
|
|
2034
|
-
if (wordWidth)
|
|
2035
|
-
addWord();
|
|
2113
|
+
} else if (langBreak || afterBreak) {
|
|
2114
|
+
if (wordWidth) addWord();
|
|
2036
2115
|
addChar(char, charWidth);
|
|
2037
|
-
}
|
|
2038
|
-
else {
|
|
2116
|
+
} else {
|
|
2039
2117
|
addChar(char, charWidth);
|
|
2040
2118
|
}
|
|
2041
2119
|
}
|
|
2042
2120
|
lastCharType = charType;
|
|
2043
2121
|
}
|
|
2044
2122
|
}
|
|
2045
|
-
if (wordWidth)
|
|
2046
|
-
|
|
2047
|
-
if (rowWidth)
|
|
2048
|
-
addRow();
|
|
2123
|
+
if (wordWidth) addWord();
|
|
2124
|
+
if (rowWidth) addRow();
|
|
2049
2125
|
rows.length > 0 && (rows[rows.length - 1].paraEnd = true);
|
|
2050
|
-
}
|
|
2051
|
-
|
|
2052
|
-
content.split('\n').forEach(content => {
|
|
2126
|
+
} else {
|
|
2127
|
+
content.split("\n").forEach(content => {
|
|
2053
2128
|
textDrawData.paraNumber++;
|
|
2054
2129
|
rowWidth = canvas.measureText(content).width;
|
|
2055
|
-
rows.push({
|
|
2056
|
-
|
|
2057
|
-
|
|
2130
|
+
rows.push({
|
|
2131
|
+
x: paraIndent || 0,
|
|
2132
|
+
text: content,
|
|
2133
|
+
width: rowWidth,
|
|
2134
|
+
paraStart: true
|
|
2135
|
+
});
|
|
2136
|
+
if (findMaxWidth) setMaxWidth();
|
|
2058
2137
|
});
|
|
2059
2138
|
}
|
|
2060
2139
|
}
|
|
2140
|
+
|
|
2061
2141
|
function addChar(char, width) {
|
|
2062
|
-
if (charSize && !startCharSize)
|
|
2063
|
-
|
|
2064
|
-
|
|
2142
|
+
if (charSize && !startCharSize) startCharSize = charSize;
|
|
2143
|
+
word.data.push({
|
|
2144
|
+
char: char,
|
|
2145
|
+
width: width
|
|
2146
|
+
});
|
|
2065
2147
|
wordWidth += width;
|
|
2066
2148
|
}
|
|
2149
|
+
|
|
2067
2150
|
function addWord() {
|
|
2068
2151
|
rowWidth += wordWidth;
|
|
2069
2152
|
word.width = wordWidth;
|
|
2070
2153
|
row.words.push(word);
|
|
2071
|
-
word = {
|
|
2154
|
+
word = {
|
|
2155
|
+
data: []
|
|
2156
|
+
};
|
|
2072
2157
|
wordWidth = 0;
|
|
2073
2158
|
}
|
|
2159
|
+
|
|
2074
2160
|
function addRow() {
|
|
2075
2161
|
if (paraStart) {
|
|
2076
2162
|
textDrawData.paraNumber++;
|
|
@@ -2083,52 +2169,53 @@ function addRow() {
|
|
|
2083
2169
|
startCharSize = 0;
|
|
2084
2170
|
}
|
|
2085
2171
|
row.width = rowWidth;
|
|
2086
|
-
if (bounds.width)
|
|
2087
|
-
trimRight(row);
|
|
2088
|
-
else if (findMaxWidth)
|
|
2089
|
-
setMaxWidth();
|
|
2172
|
+
if (bounds.width) trimRight(row); else if (findMaxWidth) setMaxWidth();
|
|
2090
2173
|
rows.push(row);
|
|
2091
|
-
row = {
|
|
2174
|
+
row = {
|
|
2175
|
+
words: []
|
|
2176
|
+
};
|
|
2092
2177
|
rowWidth = 0;
|
|
2093
2178
|
}
|
|
2179
|
+
|
|
2094
2180
|
function setMaxWidth() {
|
|
2095
|
-
if (rowWidth > (textDrawData.maxWidth || 0))
|
|
2096
|
-
textDrawData.maxWidth = rowWidth;
|
|
2181
|
+
if (rowWidth > (textDrawData.maxWidth || 0)) textDrawData.maxWidth = rowWidth;
|
|
2097
2182
|
}
|
|
2098
2183
|
|
|
2099
2184
|
const CharMode = 0;
|
|
2185
|
+
|
|
2100
2186
|
const WordMode = 1;
|
|
2187
|
+
|
|
2101
2188
|
const TextMode = 2;
|
|
2189
|
+
|
|
2102
2190
|
function layoutChar(drawData, style, width, _height) {
|
|
2103
|
-
const { rows
|
|
2104
|
-
const { textAlign, paraIndent, letterSpacing } = style;
|
|
2191
|
+
const {rows: rows} = drawData;
|
|
2192
|
+
const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
|
|
2105
2193
|
let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
|
|
2106
2194
|
rows.forEach(row => {
|
|
2107
2195
|
if (row.words) {
|
|
2108
2196
|
indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
|
|
2109
|
-
addWordWidth =
|
|
2110
|
-
mode =
|
|
2111
|
-
if (row.isOverflow && !letterSpacing)
|
|
2112
|
-
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;
|
|
2113
2200
|
if (mode === TextMode) {
|
|
2114
2201
|
row.x += indentWidth;
|
|
2115
2202
|
toTextChar$1(row);
|
|
2116
|
-
}
|
|
2117
|
-
else {
|
|
2203
|
+
} else {
|
|
2118
2204
|
row.x += indentWidth;
|
|
2119
2205
|
charX = row.x;
|
|
2120
2206
|
row.data = [];
|
|
2121
2207
|
row.words.forEach((word, index) => {
|
|
2122
2208
|
if (mode === WordMode) {
|
|
2123
|
-
wordChar = {
|
|
2209
|
+
wordChar = {
|
|
2210
|
+
char: "",
|
|
2211
|
+
x: charX
|
|
2212
|
+
};
|
|
2124
2213
|
charX = toWordChar(word.data, charX, wordChar);
|
|
2125
|
-
if (row.isOverflow || wordChar.char !==
|
|
2126
|
-
|
|
2127
|
-
}
|
|
2128
|
-
else {
|
|
2214
|
+
if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
|
|
2215
|
+
} else {
|
|
2129
2216
|
charX = toChar(word.data, charX, row.data, row.isOverflow);
|
|
2130
2217
|
}
|
|
2131
|
-
if (addWordWidth && (!row.paraEnd || textAlign ===
|
|
2218
|
+
if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
|
|
2132
2219
|
charX += addWordWidth;
|
|
2133
2220
|
row.width += addWordWidth;
|
|
2134
2221
|
}
|
|
@@ -2138,14 +2225,16 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
2138
2225
|
}
|
|
2139
2226
|
});
|
|
2140
2227
|
}
|
|
2228
|
+
|
|
2141
2229
|
function toTextChar$1(row) {
|
|
2142
|
-
row.text =
|
|
2230
|
+
row.text = "";
|
|
2143
2231
|
row.words.forEach(word => {
|
|
2144
2232
|
word.data.forEach(char => {
|
|
2145
2233
|
row.text += char.char;
|
|
2146
2234
|
});
|
|
2147
2235
|
});
|
|
2148
2236
|
}
|
|
2237
|
+
|
|
2149
2238
|
function toWordChar(data, charX, wordChar) {
|
|
2150
2239
|
data.forEach(char => {
|
|
2151
2240
|
wordChar.char += char.char;
|
|
@@ -2153,9 +2242,10 @@ function toWordChar(data, charX, wordChar) {
|
|
|
2153
2242
|
});
|
|
2154
2243
|
return charX;
|
|
2155
2244
|
}
|
|
2245
|
+
|
|
2156
2246
|
function toChar(data, charX, rowData, isOverflow) {
|
|
2157
2247
|
data.forEach(char => {
|
|
2158
|
-
if (isOverflow || char.char !==
|
|
2248
|
+
if (isOverflow || char.char !== " ") {
|
|
2159
2249
|
char.x = charX;
|
|
2160
2250
|
rowData.push(char);
|
|
2161
2251
|
}
|
|
@@ -2165,38 +2255,39 @@ function toChar(data, charX, rowData, isOverflow) {
|
|
|
2165
2255
|
}
|
|
2166
2256
|
|
|
2167
2257
|
function layoutText(drawData, style) {
|
|
2168
|
-
const { rows, bounds } = drawData, countRows = rows.length;
|
|
2169
|
-
const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
|
|
2170
|
-
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);
|
|
2171
2261
|
let starY = __baseLine;
|
|
2172
2262
|
if (__clipText && realHeight > height) {
|
|
2173
2263
|
realHeight = Math.max(height, __lineHeight);
|
|
2174
|
-
if (countRows > 1)
|
|
2175
|
-
|
|
2176
|
-
}
|
|
2177
|
-
else if (height || autoSizeAlign) {
|
|
2264
|
+
if (countRows > 1) drawData.overflow = countRows;
|
|
2265
|
+
} else if (height || autoSizeAlign) {
|
|
2178
2266
|
switch (verticalAlign) {
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2267
|
+
case "middle":
|
|
2268
|
+
y += (height - realHeight) / 2;
|
|
2269
|
+
break;
|
|
2270
|
+
|
|
2271
|
+
case "bottom":
|
|
2272
|
+
y += height - realHeight;
|
|
2183
2273
|
}
|
|
2184
2274
|
}
|
|
2185
2275
|
starY += y;
|
|
2186
|
-
let row, rowX, rowWidth, layoutWidth =
|
|
2276
|
+
let row, rowX, rowWidth, layoutWidth = width || autoSizeAlign ? width : drawData.maxWidth;
|
|
2187
2277
|
for (let i = 0, len = countRows; i < len; i++) {
|
|
2188
2278
|
row = rows[i];
|
|
2189
2279
|
row.x = x;
|
|
2190
|
-
if (row.width < width ||
|
|
2280
|
+
if (row.width < width || row.width > width && !__clipText) {
|
|
2191
2281
|
switch (textAlign) {
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2282
|
+
case "center":
|
|
2283
|
+
row.x += (layoutWidth - row.width) / 2;
|
|
2284
|
+
break;
|
|
2285
|
+
|
|
2286
|
+
case "right":
|
|
2287
|
+
row.x += layoutWidth - row.width;
|
|
2196
2288
|
}
|
|
2197
2289
|
}
|
|
2198
|
-
if (row.paraStart && paraSpacing && i > 0)
|
|
2199
|
-
starY += paraSpacing;
|
|
2290
|
+
if (row.paraStart && paraSpacing && i > 0) starY += paraSpacing;
|
|
2200
2291
|
row.y = starY;
|
|
2201
2292
|
starY += __lineHeight;
|
|
2202
2293
|
if (drawData.overflow > i && starY > realHeight) {
|
|
@@ -2210,19 +2301,15 @@ function layoutText(drawData, style) {
|
|
|
2210
2301
|
rowWidth = -row.width + style.fontSize + __letterSpacing;
|
|
2211
2302
|
rowX -= rowWidth;
|
|
2212
2303
|
rowWidth += style.fontSize;
|
|
2213
|
-
}
|
|
2214
|
-
else {
|
|
2304
|
+
} else {
|
|
2215
2305
|
rowWidth -= __letterSpacing;
|
|
2216
2306
|
}
|
|
2217
2307
|
}
|
|
2218
|
-
if (rowX < bounds.x)
|
|
2219
|
-
|
|
2220
|
-
if (rowWidth > bounds.width)
|
|
2221
|
-
bounds.width = rowWidth;
|
|
2308
|
+
if (rowX < bounds.x) bounds.x = rowX;
|
|
2309
|
+
if (rowWidth > bounds.width) bounds.width = rowWidth;
|
|
2222
2310
|
if (__clipText && width && width < rowWidth) {
|
|
2223
2311
|
row.isOverflow = true;
|
|
2224
|
-
if (!drawData.overflow)
|
|
2225
|
-
drawData.overflow = rows.length;
|
|
2312
|
+
if (!drawData.overflow) drawData.overflow = rows.length;
|
|
2226
2313
|
}
|
|
2227
2314
|
}
|
|
2228
2315
|
bounds.y = y;
|
|
@@ -2230,20 +2317,16 @@ function layoutText(drawData, style) {
|
|
|
2230
2317
|
}
|
|
2231
2318
|
|
|
2232
2319
|
function clipText(drawData, style, x, width) {
|
|
2233
|
-
if (!width)
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
let { textOverflow } = style;
|
|
2320
|
+
if (!width) return;
|
|
2321
|
+
const {rows: rows, overflow: overflow} = drawData;
|
|
2322
|
+
let {textOverflow: textOverflow} = style;
|
|
2237
2323
|
rows.splice(overflow);
|
|
2238
|
-
if (textOverflow && textOverflow !==
|
|
2239
|
-
if (textOverflow ===
|
|
2240
|
-
textOverflow = '';
|
|
2241
|
-
else if (textOverflow === 'ellipsis')
|
|
2242
|
-
textOverflow = '...';
|
|
2324
|
+
if (textOverflow && textOverflow !== "show") {
|
|
2325
|
+
if (textOverflow === "hide") textOverflow = ""; else if (textOverflow === "ellipsis") textOverflow = "...";
|
|
2243
2326
|
let char, charRight;
|
|
2244
2327
|
const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
|
|
2245
2328
|
const right = x + width - ellipsisWidth;
|
|
2246
|
-
const list = style.textWrap ===
|
|
2329
|
+
const list = style.textWrap === "none" ? rows : [ rows[overflow - 1] ];
|
|
2247
2330
|
list.forEach(row => {
|
|
2248
2331
|
if (row.isOverflow && row.data) {
|
|
2249
2332
|
let end = row.data.length - 1;
|
|
@@ -2252,8 +2335,7 @@ function clipText(drawData, style, x, width) {
|
|
|
2252
2335
|
charRight = char.x + char.width;
|
|
2253
2336
|
if (i === end && charRight < right) {
|
|
2254
2337
|
break;
|
|
2255
|
-
}
|
|
2256
|
-
else if ((charRight < right && char.char !== ' ') || !i) {
|
|
2338
|
+
} else if (charRight < right && char.char !== " " || !i) {
|
|
2257
2339
|
row.data.splice(i + 1);
|
|
2258
2340
|
row.width -= char.width;
|
|
2259
2341
|
break;
|
|
@@ -2261,15 +2343,18 @@ function clipText(drawData, style, x, width) {
|
|
|
2261
2343
|
row.width -= char.width;
|
|
2262
2344
|
}
|
|
2263
2345
|
row.width += ellipsisWidth;
|
|
2264
|
-
row.data.push({
|
|
2265
|
-
|
|
2266
|
-
|
|
2346
|
+
row.data.push({
|
|
2347
|
+
char: textOverflow,
|
|
2348
|
+
x: charRight
|
|
2349
|
+
});
|
|
2350
|
+
if (row.textMode) toTextChar(row);
|
|
2267
2351
|
}
|
|
2268
2352
|
});
|
|
2269
2353
|
}
|
|
2270
2354
|
}
|
|
2355
|
+
|
|
2271
2356
|
function toTextChar(row) {
|
|
2272
|
-
row.text =
|
|
2357
|
+
row.text = "";
|
|
2273
2358
|
row.data.forEach(char => {
|
|
2274
2359
|
row.text += char.char;
|
|
2275
2360
|
});
|
|
@@ -2278,121 +2363,123 @@ function toTextChar(row) {
|
|
|
2278
2363
|
|
|
2279
2364
|
function decorationText(drawData, style) {
|
|
2280
2365
|
let type;
|
|
2281
|
-
const { fontSize, textDecoration } = style;
|
|
2366
|
+
const {fontSize: fontSize, textDecoration: textDecoration} = style;
|
|
2282
2367
|
drawData.decorationHeight = fontSize / 11;
|
|
2283
|
-
if (
|
|
2368
|
+
if (isObject(textDecoration)) {
|
|
2284
2369
|
type = textDecoration.type;
|
|
2285
|
-
if (textDecoration.color)
|
|
2286
|
-
|
|
2287
|
-
}
|
|
2288
|
-
else
|
|
2289
|
-
type = textDecoration;
|
|
2370
|
+
if (textDecoration.color) drawData.decorationColor = ColorConvert.string(textDecoration.color);
|
|
2371
|
+
} else type = textDecoration;
|
|
2290
2372
|
switch (type) {
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
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 ];
|
|
2299
2383
|
}
|
|
2300
2384
|
}
|
|
2301
2385
|
|
|
2302
|
-
const { top, right, bottom, left } = Direction4;
|
|
2386
|
+
const {top: top, right: right, bottom: bottom, left: left} = Direction4;
|
|
2387
|
+
|
|
2303
2388
|
function getDrawData(content, style) {
|
|
2304
|
-
if (
|
|
2305
|
-
content = String(content);
|
|
2389
|
+
if (!isString(content)) content = String(content);
|
|
2306
2390
|
let x = 0, y = 0;
|
|
2307
|
-
let width = style.__getInput(
|
|
2308
|
-
let height = style.__getInput(
|
|
2309
|
-
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;
|
|
2310
2394
|
if (padding) {
|
|
2311
|
-
if (width)
|
|
2312
|
-
|
|
2313
|
-
else if (!style.autoSizeAlign)
|
|
2314
|
-
x = padding[left];
|
|
2315
|
-
if (height)
|
|
2316
|
-
y = padding[top], height -= (padding[top] + padding[bottom]);
|
|
2317
|
-
else if (!style.autoSizeAlign)
|
|
2318
|
-
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];
|
|
2319
2397
|
}
|
|
2320
2398
|
const drawData = {
|
|
2321
|
-
bounds: {
|
|
2399
|
+
bounds: {
|
|
2400
|
+
x: x,
|
|
2401
|
+
y: y,
|
|
2402
|
+
width: width,
|
|
2403
|
+
height: height
|
|
2404
|
+
},
|
|
2322
2405
|
rows: [],
|
|
2323
2406
|
paraNumber: 0,
|
|
2324
2407
|
font: Platform.canvas.font = __font
|
|
2325
2408
|
};
|
|
2326
2409
|
createRows(drawData, content, style);
|
|
2327
|
-
if (padding)
|
|
2328
|
-
padAutoText(padding, drawData, style, width, height);
|
|
2410
|
+
if (padding) padAutoText(padding, drawData, style, width, height);
|
|
2329
2411
|
layoutText(drawData, style);
|
|
2330
2412
|
layoutChar(drawData, style, width);
|
|
2331
|
-
if (drawData.overflow)
|
|
2332
|
-
|
|
2333
|
-
if (textDecoration !== 'none')
|
|
2334
|
-
decorationText(drawData, style);
|
|
2413
|
+
if (drawData.overflow) clipText(drawData, style, x, width);
|
|
2414
|
+
if (textDecoration !== "none") decorationText(drawData, style);
|
|
2335
2415
|
return drawData;
|
|
2336
2416
|
}
|
|
2417
|
+
|
|
2337
2418
|
function padAutoText(padding, drawData, style, width, height) {
|
|
2338
2419
|
if (!width && style.autoSizeAlign) {
|
|
2339
2420
|
switch (style.textAlign) {
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2421
|
+
case "left":
|
|
2422
|
+
offsetText(drawData, "x", padding[left]);
|
|
2423
|
+
break;
|
|
2424
|
+
|
|
2425
|
+
case "right":
|
|
2426
|
+
offsetText(drawData, "x", -padding[right]);
|
|
2344
2427
|
}
|
|
2345
2428
|
}
|
|
2346
2429
|
if (!height && style.autoSizeAlign) {
|
|
2347
2430
|
switch (style.verticalAlign) {
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2431
|
+
case "top":
|
|
2432
|
+
offsetText(drawData, "y", padding[top]);
|
|
2433
|
+
break;
|
|
2434
|
+
|
|
2435
|
+
case "bottom":
|
|
2436
|
+
offsetText(drawData, "y", -padding[bottom]);
|
|
2352
2437
|
}
|
|
2353
2438
|
}
|
|
2354
2439
|
}
|
|
2440
|
+
|
|
2355
2441
|
function offsetText(drawData, attrName, value) {
|
|
2356
|
-
const { bounds, rows } = drawData;
|
|
2442
|
+
const {bounds: bounds, rows: rows} = drawData;
|
|
2357
2443
|
bounds[attrName] += value;
|
|
2358
|
-
for (let i = 0; i < rows.length; i++)
|
|
2359
|
-
rows[i][attrName] += value;
|
|
2444
|
+
for (let i = 0; i < rows.length; i++) rows[i][attrName] += value;
|
|
2360
2445
|
}
|
|
2361
2446
|
|
|
2362
2447
|
const TextConvertModule = {
|
|
2363
|
-
getDrawData
|
|
2448
|
+
getDrawData: getDrawData
|
|
2364
2449
|
};
|
|
2365
2450
|
|
|
2366
2451
|
function string(color, opacity) {
|
|
2367
|
-
const doOpacity =
|
|
2368
|
-
if (
|
|
2369
|
-
if (doOpacity && ColorConvert.object)
|
|
2370
|
-
color = ColorConvert.object(color);
|
|
2371
|
-
else
|
|
2372
|
-
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;
|
|
2373
2455
|
}
|
|
2374
|
-
let a = color.a
|
|
2375
|
-
if (doOpacity)
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
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 + ")";
|
|
2379
2460
|
}
|
|
2380
2461
|
|
|
2381
2462
|
const ColorConvertModule = {
|
|
2382
|
-
string
|
|
2463
|
+
string: string
|
|
2383
2464
|
};
|
|
2384
2465
|
|
|
2385
2466
|
Object.assign(TextConvert, TextConvertModule);
|
|
2467
|
+
|
|
2386
2468
|
Object.assign(ColorConvert, ColorConvertModule);
|
|
2469
|
+
|
|
2387
2470
|
Object.assign(Paint, PaintModule);
|
|
2471
|
+
|
|
2388
2472
|
Object.assign(PaintImage, PaintImageModule);
|
|
2473
|
+
|
|
2389
2474
|
Object.assign(PaintGradient, PaintGradientModule);
|
|
2475
|
+
|
|
2390
2476
|
Object.assign(Effect, EffectModule);
|
|
2391
2477
|
|
|
2392
|
-
const { setPoint, addPoint, toBounds } = TwoPointBoundsHelper;
|
|
2478
|
+
const {setPoint: setPoint, addPoint: addPoint, toBounds: toBounds} = TwoPointBoundsHelper;
|
|
2479
|
+
|
|
2393
2480
|
function getTrimBounds(canvas) {
|
|
2394
|
-
const { width, height } = canvas.view;
|
|
2395
|
-
const { data
|
|
2481
|
+
const {width: width, height: height} = canvas.view;
|
|
2482
|
+
const {data: data} = canvas.context.getImageData(0, 0, width, height);
|
|
2396
2483
|
let x, y, pointBounds, index = 0;
|
|
2397
2484
|
for (let i = 0; i < data.length; i += 4) {
|
|
2398
2485
|
if (data[i + 3] !== 0) {
|
|
@@ -2402,7 +2489,7 @@ function getTrimBounds(canvas) {
|
|
|
2402
2489
|
}
|
|
2403
2490
|
index++;
|
|
2404
2491
|
}
|
|
2405
|
-
const bounds = new Bounds$1
|
|
2492
|
+
const bounds = new Bounds$1;
|
|
2406
2493
|
if (pointBounds) {
|
|
2407
2494
|
toBounds(pointBounds, bounds);
|
|
2408
2495
|
bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
@@ -2416,64 +2503,80 @@ const ExportModule = {
|
|
|
2416
2503
|
let result;
|
|
2417
2504
|
try {
|
|
2418
2505
|
const fileType = FileHelper$1.fileType(filename);
|
|
2419
|
-
const isDownload = filename.includes(
|
|
2506
|
+
const isDownload = filename.includes(".");
|
|
2420
2507
|
options = FileHelper$1.getExportOptions(options);
|
|
2421
|
-
const { toURL
|
|
2422
|
-
const { download
|
|
2423
|
-
if (fileType ===
|
|
2424
|
-
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)),
|
|
2425
|
-
result = {
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
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 {
|
|
2432
2521
|
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2433
|
-
const { worldTransform, isLeafer, leafer, isFrame } = leaf;
|
|
2434
|
-
const { slice, clip, trim, screenshot, padding, onCanvas } = options;
|
|
2435
|
-
const smooth = options.smooth
|
|
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;
|
|
2436
2525
|
const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
|
|
2437
|
-
const fill =
|
|
2438
|
-
const needFill = FileHelper$1.isOpaqueImage(filename) || fill, matrix = new Matrix
|
|
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;
|
|
2439
2528
|
if (screenshot) {
|
|
2440
|
-
renderBounds = screenshot === true ?
|
|
2441
|
-
}
|
|
2442
|
-
|
|
2443
|
-
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
2529
|
+
renderBounds = screenshot === true ? isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds : screenshot;
|
|
2530
|
+
} else {
|
|
2531
|
+
let relative = options.relative || (isLeafer ? "inner" : "local");
|
|
2444
2532
|
scaleX = worldTransform.scaleX;
|
|
2445
2533
|
scaleY = worldTransform.scaleY;
|
|
2446
2534
|
switch (relative) {
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2535
|
+
case "inner":
|
|
2536
|
+
matrix.set(worldTransform);
|
|
2537
|
+
break;
|
|
2538
|
+
|
|
2539
|
+
case "local":
|
|
2540
|
+
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
2541
|
+
scaleX /= leaf.scaleX;
|
|
2542
|
+
scaleY /= leaf.scaleY;
|
|
2543
|
+
break;
|
|
2544
|
+
|
|
2545
|
+
case "world":
|
|
2546
|
+
scaleX = 1;
|
|
2547
|
+
scaleY = 1;
|
|
2548
|
+
break;
|
|
2549
|
+
|
|
2550
|
+
case "page":
|
|
2551
|
+
relative = leafer || leaf;
|
|
2552
|
+
|
|
2553
|
+
default:
|
|
2554
|
+
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
2555
|
+
const l = relative.worldTransform;
|
|
2556
|
+
scaleX /= scaleX / l.scaleX;
|
|
2557
|
+
scaleY /= scaleY / l.scaleY;
|
|
2466
2558
|
}
|
|
2467
|
-
renderBounds = leaf.getBounds(
|
|
2559
|
+
renderBounds = leaf.getBounds("render", relative);
|
|
2468
2560
|
}
|
|
2469
|
-
const scaleData = {
|
|
2561
|
+
const scaleData = {
|
|
2562
|
+
scaleX: 1,
|
|
2563
|
+
scaleY: 1
|
|
2564
|
+
};
|
|
2470
2565
|
MathHelper$1.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2471
2566
|
let pixelRatio = options.pixelRatio || 1;
|
|
2472
|
-
let { x, y, width, height } = new Bounds$1(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2473
|
-
if (clip)
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
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
|
+
});
|
|
2477
2580
|
let sliceLeaf;
|
|
2478
2581
|
if (slice) {
|
|
2479
2582
|
sliceLeaf = leaf;
|
|
@@ -2482,130 +2585,153 @@ const ExportModule = {
|
|
|
2482
2585
|
renderOptions.bounds = canvas.bounds;
|
|
2483
2586
|
}
|
|
2484
2587
|
canvas.save();
|
|
2485
|
-
if (isFrame && fill
|
|
2486
|
-
const oldFill = leaf.get(
|
|
2487
|
-
leaf.fill =
|
|
2588
|
+
if (isFrame && !isUndefined$1(fill)) {
|
|
2589
|
+
const oldFill = leaf.get("fill");
|
|
2590
|
+
leaf.fill = "";
|
|
2488
2591
|
leaf.__render(canvas, renderOptions);
|
|
2489
2592
|
leaf.fill = oldFill;
|
|
2490
|
-
}
|
|
2491
|
-
else {
|
|
2593
|
+
} else {
|
|
2492
2594
|
leaf.__render(canvas, renderOptions);
|
|
2493
2595
|
}
|
|
2494
2596
|
canvas.restore();
|
|
2495
|
-
if (sliceLeaf)
|
|
2496
|
-
sliceLeaf.__updateWorldOpacity();
|
|
2597
|
+
if (sliceLeaf) sliceLeaf.__updateWorldOpacity();
|
|
2497
2598
|
if (trim) {
|
|
2498
2599
|
trimBounds = getTrimBounds(canvas);
|
|
2499
|
-
const old = canvas, { width, height } = trimBounds;
|
|
2500
|
-
const config = {
|
|
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
|
+
};
|
|
2501
2608
|
canvas = Creator$1.canvas(config);
|
|
2502
2609
|
canvas.copyWorld(old, trimBounds, config);
|
|
2610
|
+
old.destroy();
|
|
2503
2611
|
}
|
|
2504
2612
|
if (padding) {
|
|
2505
2613
|
const [top, right, bottom, left] = MathHelper$1.fourNumber(padding);
|
|
2506
|
-
const old = canvas, { width, height } = old;
|
|
2507
|
-
canvas = Creator$1.canvas({
|
|
2508
|
-
|
|
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();
|
|
2509
2627
|
}
|
|
2510
|
-
if (needFill)
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
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
|
+
};
|
|
2516
2638
|
}
|
|
2517
|
-
}
|
|
2518
|
-
|
|
2519
|
-
|
|
2639
|
+
} catch (error) {
|
|
2640
|
+
result = {
|
|
2641
|
+
data: "",
|
|
2642
|
+
error: error
|
|
2643
|
+
};
|
|
2520
2644
|
}
|
|
2521
2645
|
Export.running = false;
|
|
2522
2646
|
return result;
|
|
2523
2647
|
},
|
|
2524
2648
|
export(leaf, filename, options) {
|
|
2525
2649
|
Export.running = true;
|
|
2526
|
-
return addTask(
|
|
2527
|
-
const getResult = () => __awaiter(this, void 0, void 0, function*
|
|
2528
|
-
if (!Resource.isComplete)
|
|
2529
|
-
return Platform$1.requestRender(getResult);
|
|
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);
|
|
2530
2653
|
const result = Export.syncExport(leaf, filename, options);
|
|
2531
|
-
if (result.data instanceof Promise)
|
|
2532
|
-
result.data = yield result.data;
|
|
2654
|
+
if (result.data instanceof Promise) result.data = yield result.data;
|
|
2533
2655
|
success(result);
|
|
2534
2656
|
resolve();
|
|
2535
2657
|
});
|
|
2536
2658
|
leaf.updateLayout();
|
|
2537
2659
|
checkLazy(leaf);
|
|
2538
|
-
const { leafer
|
|
2539
|
-
if (leafer)
|
|
2540
|
-
leafer.waitViewCompleted(getResult);
|
|
2541
|
-
else
|
|
2542
|
-
getResult();
|
|
2660
|
+
const {leafer: leafer} = leaf;
|
|
2661
|
+
if (leafer) leafer.waitViewCompleted(getResult); else getResult();
|
|
2543
2662
|
}));
|
|
2544
2663
|
}
|
|
2545
2664
|
};
|
|
2665
|
+
|
|
2546
2666
|
let tasker;
|
|
2667
|
+
|
|
2547
2668
|
function addTask(task) {
|
|
2548
|
-
if (!tasker)
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
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
|
+
});
|
|
2552
2676
|
});
|
|
2553
2677
|
}
|
|
2678
|
+
|
|
2554
2679
|
function checkLazy(leaf) {
|
|
2555
|
-
if (leaf.__.__needComputePaint)
|
|
2556
|
-
|
|
2557
|
-
if (leaf.isBranch)
|
|
2558
|
-
leaf.children.forEach(child => checkLazy(child));
|
|
2680
|
+
if (leaf.__.__needComputePaint) leaf.__.__computePaint();
|
|
2681
|
+
if (leaf.isBranch) leaf.children.forEach(child => checkLazy(child));
|
|
2559
2682
|
}
|
|
2560
2683
|
|
|
2561
2684
|
const canvas = LeaferCanvasBase$1.prototype;
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
else if (blob)
|
|
2568
|
-
return this.toBlob(filename, quality);
|
|
2569
|
-
else
|
|
2570
|
-
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);
|
|
2571
2691
|
};
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2692
|
+
|
|
2693
|
+
canvas.toBlob = function(type, quality) {
|
|
2694
|
+
return new Promise(resolve => {
|
|
2695
|
+
Platform$1.origin.canvasToBolb(this.view, type, quality).then(blob => {
|
|
2575
2696
|
resolve(blob);
|
|
2576
|
-
}).catch(
|
|
2697
|
+
}).catch(e => {
|
|
2577
2698
|
debug.error(e);
|
|
2578
2699
|
resolve(null);
|
|
2579
2700
|
});
|
|
2580
2701
|
});
|
|
2581
2702
|
};
|
|
2582
|
-
|
|
2703
|
+
|
|
2704
|
+
canvas.toDataURL = function(type, quality) {
|
|
2583
2705
|
return Platform$1.origin.canvasToDataURL(this.view, type, quality);
|
|
2584
2706
|
};
|
|
2585
|
-
|
|
2586
|
-
|
|
2707
|
+
|
|
2708
|
+
canvas.saveAs = function(filename, quality) {
|
|
2709
|
+
return new Promise(resolve => {
|
|
2587
2710
|
Platform$1.origin.canvasSaveAs(this.view, filename, quality).then(() => {
|
|
2588
2711
|
resolve(true);
|
|
2589
|
-
}).catch(
|
|
2712
|
+
}).catch(e => {
|
|
2590
2713
|
debug.error(e);
|
|
2591
2714
|
resolve(false);
|
|
2592
2715
|
});
|
|
2593
2716
|
});
|
|
2594
2717
|
};
|
|
2595
2718
|
|
|
2596
|
-
Plugin$1.add(
|
|
2719
|
+
Plugin$1.add("export");
|
|
2720
|
+
|
|
2597
2721
|
Object.assign(Export, ExportModule);
|
|
2598
|
-
|
|
2722
|
+
|
|
2723
|
+
UI.prototype.export = function(filename, options) {
|
|
2599
2724
|
return Export.export(this, filename, options);
|
|
2600
2725
|
};
|
|
2601
|
-
|
|
2726
|
+
|
|
2727
|
+
UI.prototype.syncExport = function(filename, options) {
|
|
2602
2728
|
return Export.syncExport(this, filename, options);
|
|
2603
2729
|
};
|
|
2604
2730
|
|
|
2605
2731
|
Object.assign(Creator, {
|
|
2606
|
-
interaction: (target, canvas, selector, options) =>
|
|
2732
|
+
interaction: (target, canvas, selector, options) => new InteractionBase(target, canvas, selector, options),
|
|
2607
2733
|
hitCanvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
2608
|
-
hitCanvasManager: () => new HitCanvasManager
|
|
2734
|
+
hitCanvasManager: () => new HitCanvasManager
|
|
2609
2735
|
});
|
|
2610
2736
|
|
|
2611
2737
|
export { Layouter, LeaferCanvas, Picker, Renderer, Selector, Watcher, useCanvas };
|