@leafer-draw/worker 1.0.0 → 1.0.2

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