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