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