leafer-ui 1.0.0-beta.9 → 1.0.0-rc.11

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