@leafer-ui/miniapp 1.0.0-beta.9 → 1.0.0-rc.3

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