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