@leafer-ui/node 1.0.0-beta.8 → 1.0.0-rc.10

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