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