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