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