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