@leafer-draw/worker 1.0.1 → 1.0.3

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