@leafer-ui/node 1.0.0-beta.9 → 1.0.0-rc.11

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