@leafer-ui/draw 1.0.0-rc.10

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.
package/lib/draw.cjs ADDED
@@ -0,0 +1,1806 @@
1
+ 'use strict';
2
+
3
+ var core = require('@leafer/core');
4
+
5
+ /******************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */
19
+ /* global Reflect, Promise, SuppressedError, Symbol */
20
+
21
+
22
+ function __decorate(decorators, target, key, desc) {
23
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
26
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
27
+ }
28
+
29
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
30
+ var e = new Error(message);
31
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
+ };
33
+
34
+ function effectType(defaultValue) {
35
+ return (target, key) => {
36
+ core.defineLeafAttr(target, key, defaultValue, {
37
+ set(value) {
38
+ this.__setAttr(key, value);
39
+ if (value)
40
+ this.__.__useEffect = true;
41
+ this.__layout.renderChanged || this.__layout.renderChange();
42
+ }
43
+ });
44
+ };
45
+ }
46
+ function resizeType(defaultValue) {
47
+ return (target, key) => {
48
+ core.defineLeafAttr(target, key, defaultValue, {
49
+ set(value) {
50
+ this.__setAttr(key, value);
51
+ this.__layout.boxChanged || this.__layout.boxChange();
52
+ this.__updateSize();
53
+ }
54
+ });
55
+ };
56
+ }
57
+
58
+ const TextConvert = {};
59
+ const ColorConvert = {};
60
+ const Paint = {};
61
+ const PaintImage = {};
62
+ const PaintGradient = {};
63
+ const Effect = {};
64
+ const Export = {};
65
+
66
+ const emptyPaint = {};
67
+ const debug$1 = core.Debug.get('UIData');
68
+ class UIData extends core.LeafData {
69
+ get __strokeWidth() {
70
+ const { strokeWidth, strokeWidthFixed } = this;
71
+ if (strokeWidthFixed) {
72
+ let { scaleX } = this.__leaf.__world;
73
+ if (scaleX < 0)
74
+ scaleX = -scaleX;
75
+ return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
76
+ }
77
+ else {
78
+ return strokeWidth;
79
+ }
80
+ }
81
+ get __autoWidth() { return !this._width; }
82
+ get __autoHeight() { return !this._height; }
83
+ get __autoBounds() { return !this._width && !this._height; }
84
+ setVisible(value) {
85
+ if (this.__leaf.leafer)
86
+ this.__leaf.leafer.watcher.hasVisible = true;
87
+ this._visible = value;
88
+ }
89
+ setWidth(value) {
90
+ if (value < 0) {
91
+ this._width = -value;
92
+ this.__leaf.scaleX *= -1;
93
+ debug$1.warn('width < 0, instead -scaleX ', this);
94
+ }
95
+ else {
96
+ this._width = value;
97
+ }
98
+ }
99
+ setHeight(value) {
100
+ if (value < 0) {
101
+ this._height = -value;
102
+ this.__leaf.scaleY *= -1;
103
+ debug$1.warn('height < 0, instead -scaleY', this);
104
+ }
105
+ else {
106
+ this._height = value;
107
+ }
108
+ }
109
+ setFill(value) {
110
+ if (this.__naturalWidth)
111
+ this.__naturalWidth = this.__naturalHeight = undefined;
112
+ if (typeof value === 'string' || !value) {
113
+ if (this.__isFills) {
114
+ this.__removeInput('fill');
115
+ PaintImage.recycleImage('fill', this);
116
+ this.__isFills = false;
117
+ if (this.__pixelFill)
118
+ this.__pixelFill = false;
119
+ }
120
+ this._fill = value;
121
+ }
122
+ else if (typeof value === 'object') {
123
+ this.__setInput('fill', value);
124
+ this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange();
125
+ this.__isFills = true;
126
+ this._fill || (this._fill = emptyPaint);
127
+ }
128
+ }
129
+ setStroke(value) {
130
+ if (typeof value === 'string' || !value) {
131
+ if (this.__isStrokes) {
132
+ this.__removeInput('stroke');
133
+ PaintImage.recycleImage('stroke', this);
134
+ this.__isStrokes = false;
135
+ if (this.__pixelStroke)
136
+ this.__pixelStroke = false;
137
+ }
138
+ this._stroke = value;
139
+ }
140
+ else if (typeof value === 'object') {
141
+ this.__setInput('stroke', value);
142
+ this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange();
143
+ this.__isStrokes = true;
144
+ this._stroke || (this._stroke = emptyPaint);
145
+ }
146
+ }
147
+ setShadow(value) {
148
+ this.__setInput('shadow', value);
149
+ if (value instanceof Array) {
150
+ if (value.some((item) => item.visible === false))
151
+ value = value.filter((item) => item.visible !== false);
152
+ this._shadow = value.length ? value : null;
153
+ }
154
+ else if (value) {
155
+ this._shadow = value.visible === false ? null : [value];
156
+ }
157
+ else {
158
+ this._shadow = null;
159
+ }
160
+ }
161
+ setInnerShadow(value) {
162
+ this.__setInput('innerShadow', value);
163
+ if (value instanceof Array) {
164
+ if (value.some((item) => item.visible === false))
165
+ value = value.filter((item) => item.visible !== false);
166
+ this._innerShadow = value.length ? value : null;
167
+ }
168
+ else if (value) {
169
+ this._innerShadow = value.visible === false ? null : [value];
170
+ }
171
+ else {
172
+ this._innerShadow = null;
173
+ }
174
+ }
175
+ __computePaint() {
176
+ const { fill, stroke } = this.__input;
177
+ if (fill)
178
+ Paint.compute('fill', this.__leaf);
179
+ if (stroke)
180
+ Paint.compute('stroke', this.__leaf);
181
+ this.__needComputePaint = false;
182
+ }
183
+ }
184
+ const UnitConvert = {
185
+ number(value, percentRefer) {
186
+ if (typeof value === 'object')
187
+ return value.type === 'percent' ? value.value / 100 * percentRefer : value.value;
188
+ return value;
189
+ }
190
+ };
191
+
192
+ class GroupData extends UIData {
193
+ }
194
+
195
+ class BoxData extends GroupData {
196
+ get __boxStroke() { return true; }
197
+ }
198
+
199
+ class LeaferData extends GroupData {
200
+ }
201
+
202
+ class FrameData extends BoxData {
203
+ }
204
+
205
+ class LineData extends UIData {
206
+ }
207
+
208
+ class ArrowData extends LineData {
209
+ }
210
+
211
+ class RectData extends UIData {
212
+ get __boxStroke() { return true; }
213
+ }
214
+
215
+ class EllipseData extends UIData {
216
+ get __boxStroke() { return true; }
217
+ }
218
+
219
+ class PolygonData extends UIData {
220
+ }
221
+
222
+ class StarData extends UIData {
223
+ }
224
+
225
+ const { parse } = core.PathConvert;
226
+ class PathData extends UIData {
227
+ setPath(value) {
228
+ if (typeof value === 'string') {
229
+ this.__setInput('path', value);
230
+ this._path = parse(value);
231
+ }
232
+ else {
233
+ if (this.__input)
234
+ this.__removeInput('path');
235
+ this._path = value;
236
+ }
237
+ }
238
+ }
239
+
240
+ class PenData extends GroupData {
241
+ }
242
+
243
+ const fontWeightMap = {
244
+ 'thin': 100,
245
+ 'extra-light': 200,
246
+ 'light': 300,
247
+ 'normal': 400,
248
+ 'medium': 500,
249
+ 'semi-bold': 600,
250
+ 'bold': 700,
251
+ 'extra-bold': 800,
252
+ 'black': 900
253
+ };
254
+ class TextData extends UIData {
255
+ setFontWeight(value) {
256
+ if (typeof value === 'string') {
257
+ this.__setInput('fontWeight', value);
258
+ this._fontWeight = fontWeightMap[value] || 400;
259
+ }
260
+ else {
261
+ if (this.__input)
262
+ this.__removeInput('fontWeight');
263
+ this._fontWeight = value;
264
+ }
265
+ }
266
+ }
267
+
268
+ class ImageData extends RectData {
269
+ setUrl(value) {
270
+ this.__setImageFill(value);
271
+ this._url = value;
272
+ }
273
+ __setImageFill(value) {
274
+ if (this.__leaf.image)
275
+ this.__leaf.image = null;
276
+ this.fill = value ? { type: 'image', mode: 'strench', url: value } : undefined;
277
+ }
278
+ __getData() {
279
+ const data = super.__getData();
280
+ delete data.fill;
281
+ return data;
282
+ }
283
+ __getInputData() {
284
+ const data = super.__getInputData();
285
+ delete data.fill;
286
+ return data;
287
+ }
288
+ }
289
+
290
+ class CanvasData extends RectData {
291
+ }
292
+
293
+ const UIBounds = {
294
+ __updateStrokeSpread() {
295
+ let width = 0, boxWidth = 0;
296
+ const { stroke, hitStroke, strokeAlign, strokeWidth } = this.__;
297
+ if ((stroke || hitStroke === 'all') && strokeWidth && strokeAlign !== 'inside') {
298
+ boxWidth = width = strokeAlign === 'center' ? strokeWidth / 2 : strokeWidth;
299
+ if (!this.__.__boxStroke) {
300
+ const { miterLimit, strokeCap } = this.__;
301
+ const miterLimitAddWidth = this.__tag !== 'Line' ? 1 / Math.sin(miterLimit * core.OneRadian / 2) * Math.sqrt(strokeWidth) - width : 0;
302
+ const storkeCapAddWidth = strokeCap === 'none' ? 0 : strokeWidth;
303
+ width += Math.max(miterLimitAddWidth, storkeCapAddWidth);
304
+ }
305
+ }
306
+ this.__layout.strokeBoxSpread = boxWidth;
307
+ return width;
308
+ },
309
+ __updateRenderSpread() {
310
+ let width = 0;
311
+ const { shadow, innerShadow, blur, backgroundBlur } = this.__;
312
+ if (shadow)
313
+ shadow.forEach(item => {
314
+ width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5);
315
+ });
316
+ if (blur)
317
+ width = Math.max(width, blur);
318
+ let shapeWidth = width = Math.ceil(width);
319
+ if (innerShadow)
320
+ innerShadow.forEach(item => {
321
+ shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5);
322
+ });
323
+ if (backgroundBlur)
324
+ shapeWidth = Math.max(shapeWidth, backgroundBlur);
325
+ this.__layout.renderShapeSpread = shapeWidth;
326
+ return width;
327
+ }
328
+ };
329
+
330
+ const UIRender = {
331
+ __updateChange() {
332
+ const data = this.__;
333
+ if (data.__useEffect) {
334
+ const { shadow, innerShadow, blur, backgroundBlur } = this.__;
335
+ data.__useEffect = !!(shadow || innerShadow || blur || backgroundBlur);
336
+ }
337
+ data.__checkSingle();
338
+ const complex = data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect;
339
+ if (complex) {
340
+ data.__complex = true;
341
+ }
342
+ else {
343
+ data.__complex && (data.__complex = false);
344
+ }
345
+ },
346
+ __drawFast(canvas, options) {
347
+ const { fill, stroke, __drawAfterFill } = this.__;
348
+ this.__drawRenderPath(canvas);
349
+ if (fill)
350
+ Paint.fill(fill, this, canvas);
351
+ if (__drawAfterFill)
352
+ this.__drawAfterFill(canvas, options);
353
+ if (stroke)
354
+ Paint.stroke(stroke, this, canvas);
355
+ },
356
+ __draw(canvas, options) {
357
+ if (this.__.__complex) {
358
+ const data = this.__;
359
+ if (data.__needComputePaint)
360
+ data.__computePaint();
361
+ const { fill, stroke, __drawAfterFill } = data;
362
+ this.__drawRenderPath(canvas);
363
+ if (data.__useEffect) {
364
+ const shape = Paint.shape(this, canvas, options);
365
+ this.__nowWorld = this.__getNowWorld(options);
366
+ const { shadow, innerShadow } = data;
367
+ if (shadow)
368
+ Effect.shadow(this, canvas, shape);
369
+ if (fill)
370
+ data.__isFills ? Paint.fills(fill, this, canvas) : Paint.fill(fill, this, canvas);
371
+ if (__drawAfterFill)
372
+ this.__drawAfterFill(canvas, options);
373
+ if (innerShadow)
374
+ Effect.innerShadow(this, canvas, shape);
375
+ if (stroke)
376
+ data.__isStrokes ? Paint.strokes(stroke, this, canvas) : Paint.stroke(stroke, this, canvas);
377
+ if (shape.worldCanvas)
378
+ shape.worldCanvas.recycle();
379
+ shape.canvas.recycle();
380
+ }
381
+ else {
382
+ if (fill)
383
+ data.__isFills ? Paint.fills(fill, this, canvas) : Paint.fill(fill, this, canvas);
384
+ if (__drawAfterFill)
385
+ this.__drawAfterFill(canvas, options);
386
+ if (stroke)
387
+ data.__isStrokes ? Paint.strokes(stroke, this, canvas) : Paint.stroke(stroke, this, canvas);
388
+ }
389
+ }
390
+ else {
391
+ this.__drawFast(canvas, options);
392
+ }
393
+ },
394
+ __renderShape(canvas, options) {
395
+ if (this.__worldOpacity) {
396
+ canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
397
+ const { fill, stroke } = this.__;
398
+ this.__drawRenderPath(canvas);
399
+ if (fill)
400
+ this.__.__pixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
401
+ if (stroke)
402
+ this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
403
+ }
404
+ }
405
+ };
406
+
407
+ const RectRender = {
408
+ __drawFast(canvas, options) {
409
+ const { width, height, fill, stroke, __drawAfterFill } = this.__;
410
+ if (fill) {
411
+ canvas.fillStyle = fill;
412
+ canvas.fillRect(0, 0, width, height);
413
+ }
414
+ if (__drawAfterFill)
415
+ this.__drawAfterFill(canvas, options);
416
+ if (stroke) {
417
+ const { strokeAlign, __strokeWidth } = this.__;
418
+ if (!__strokeWidth)
419
+ return;
420
+ canvas.setStroke(stroke, __strokeWidth, this.__);
421
+ const half = __strokeWidth / 2;
422
+ switch (strokeAlign) {
423
+ case 'center':
424
+ canvas.strokeRect(0, 0, width, height);
425
+ break;
426
+ case 'inside':
427
+ canvas.strokeRect(half, half, width - __strokeWidth, height - __strokeWidth);
428
+ break;
429
+ case 'outside':
430
+ canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
431
+ break;
432
+ }
433
+ }
434
+ }
435
+ };
436
+
437
+ var UI_1;
438
+ exports.UI = UI_1 = class UI extends core.Leaf {
439
+ get app() { return this.leafer && this.leafer.app; }
440
+ set scale(value) {
441
+ if (typeof value === 'number') {
442
+ this.scaleX = this.scaleY = value;
443
+ }
444
+ else {
445
+ this.scaleX = value.x;
446
+ this.scaleY = value.y;
447
+ }
448
+ }
449
+ get scale() {
450
+ const { scaleX, scaleY } = this;
451
+ return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX;
452
+ }
453
+ constructor(data) {
454
+ super(data);
455
+ }
456
+ reset(_data) { }
457
+ set(data) {
458
+ Object.assign(this, data);
459
+ }
460
+ get() {
461
+ return this.__.__getInputData();
462
+ }
463
+ createProxyData() { return undefined; }
464
+ find(_condition, _options) { return undefined; }
465
+ findOne(_condition, _options) { return undefined; }
466
+ getPath(curve, pathForRender) {
467
+ this.__layout.update();
468
+ let path = pathForRender ? this.__.__pathForRender : this.__.path;
469
+ if (!path) {
470
+ path = [];
471
+ const { width, height } = this.boxBounds;
472
+ if (width || height)
473
+ this.__drawPathByBox(new core.PathCreator(path));
474
+ }
475
+ return curve ? core.PathConvert.toCanvasData(path, true) : path;
476
+ }
477
+ getPathString(curve, pathForRender) {
478
+ return core.PathConvert.stringify(this.getPath(curve, pathForRender));
479
+ }
480
+ __onUpdateSize() {
481
+ if (this.__.__input) {
482
+ const data = this.__;
483
+ data.__needComputePaint = true;
484
+ if (data.lazy && this.leafer && !this.leafer.canvas.bounds.hit(this.__world))
485
+ return;
486
+ data.__computePaint();
487
+ }
488
+ }
489
+ __updateRenderPath() {
490
+ if (this.__.path) {
491
+ const data = this.__;
492
+ data.__pathForRender = data.cornerRadius ? core.PathCorner.smooth(data.path, data.cornerRadius, data.cornerSmoothing) : data.path;
493
+ }
494
+ }
495
+ __drawRenderPath(canvas) {
496
+ canvas.beginPath();
497
+ this.__drawPathByData(canvas, this.__.__pathForRender);
498
+ }
499
+ __drawPath(canvas) {
500
+ canvas.beginPath();
501
+ this.__drawPathByData(canvas, this.__.path);
502
+ }
503
+ __drawPathByData(_drawer, _data) { }
504
+ __drawPathByBox(drawer) {
505
+ const { x, y, width, height } = this.__layout.boxBounds;
506
+ if (this.__.cornerRadius) {
507
+ drawer.roundRect(x, y, width, height, this.__.cornerRadius);
508
+ }
509
+ else {
510
+ drawer.rect(x, y, width, height);
511
+ }
512
+ }
513
+ export(filename, options) {
514
+ return Export.export(this, filename, options);
515
+ }
516
+ clone() {
517
+ return UI_1.one(this.toJSON());
518
+ }
519
+ static one(data, x, y, width, height) {
520
+ return core.UICreator.get(data.tag || this.prototype.__tag, data, x, y, width, height);
521
+ }
522
+ destroy() {
523
+ this.fill = this.stroke = null;
524
+ super.destroy();
525
+ }
526
+ };
527
+ __decorate([
528
+ core.dataProcessor(UIData)
529
+ ], exports.UI.prototype, "__", void 0);
530
+ __decorate([
531
+ core.dataType('')
532
+ ], exports.UI.prototype, "id", void 0);
533
+ __decorate([
534
+ core.dataType('')
535
+ ], exports.UI.prototype, "name", void 0);
536
+ __decorate([
537
+ core.dataType('')
538
+ ], exports.UI.prototype, "className", void 0);
539
+ __decorate([
540
+ core.surfaceType('pass-through')
541
+ ], exports.UI.prototype, "blendMode", void 0);
542
+ __decorate([
543
+ core.opacityType(1)
544
+ ], exports.UI.prototype, "opacity", void 0);
545
+ __decorate([
546
+ core.opacityType(true)
547
+ ], exports.UI.prototype, "visible", void 0);
548
+ __decorate([
549
+ core.dataType(false)
550
+ ], exports.UI.prototype, "locked", void 0);
551
+ __decorate([
552
+ core.sortType(0)
553
+ ], exports.UI.prototype, "zIndex", void 0);
554
+ __decorate([
555
+ core.maskType(false)
556
+ ], exports.UI.prototype, "mask", void 0);
557
+ __decorate([
558
+ core.surfaceType('pixel')
559
+ ], exports.UI.prototype, "maskType", void 0);
560
+ __decorate([
561
+ core.eraserType(false)
562
+ ], exports.UI.prototype, "eraser", void 0);
563
+ __decorate([
564
+ core.positionType(0)
565
+ ], exports.UI.prototype, "x", void 0);
566
+ __decorate([
567
+ core.positionType(0)
568
+ ], exports.UI.prototype, "y", void 0);
569
+ __decorate([
570
+ core.boundsType(100)
571
+ ], exports.UI.prototype, "width", void 0);
572
+ __decorate([
573
+ core.boundsType(100)
574
+ ], exports.UI.prototype, "height", void 0);
575
+ __decorate([
576
+ core.scaleType(1)
577
+ ], exports.UI.prototype, "scaleX", void 0);
578
+ __decorate([
579
+ core.scaleType(1)
580
+ ], exports.UI.prototype, "scaleY", void 0);
581
+ __decorate([
582
+ core.rotationType(0)
583
+ ], exports.UI.prototype, "rotation", void 0);
584
+ __decorate([
585
+ core.rotationType(0)
586
+ ], exports.UI.prototype, "skewX", void 0);
587
+ __decorate([
588
+ core.rotationType(0)
589
+ ], exports.UI.prototype, "skewY", void 0);
590
+ __decorate([
591
+ core.autoLayoutType()
592
+ ], exports.UI.prototype, "around", void 0);
593
+ __decorate([
594
+ core.dataType(false)
595
+ ], exports.UI.prototype, "draggable", void 0);
596
+ __decorate([
597
+ core.dataType(false)
598
+ ], exports.UI.prototype, "editable", void 0);
599
+ __decorate([
600
+ core.dataType('size')
601
+ ], exports.UI.prototype, "editSize", void 0);
602
+ __decorate([
603
+ core.hitType(true)
604
+ ], exports.UI.prototype, "hittable", void 0);
605
+ __decorate([
606
+ core.hitType('path')
607
+ ], exports.UI.prototype, "hitFill", void 0);
608
+ __decorate([
609
+ core.strokeType('path')
610
+ ], exports.UI.prototype, "hitStroke", void 0);
611
+ __decorate([
612
+ core.hitType(false)
613
+ ], exports.UI.prototype, "hitBox", void 0);
614
+ __decorate([
615
+ core.hitType(true)
616
+ ], exports.UI.prototype, "hitChildren", void 0);
617
+ __decorate([
618
+ core.hitType(true)
619
+ ], exports.UI.prototype, "hitSelf", void 0);
620
+ __decorate([
621
+ core.hitType()
622
+ ], exports.UI.prototype, "hitRadius", void 0);
623
+ __decorate([
624
+ core.cursorType('')
625
+ ], exports.UI.prototype, "cursor", void 0);
626
+ __decorate([
627
+ core.surfaceType()
628
+ ], exports.UI.prototype, "fill", void 0);
629
+ __decorate([
630
+ core.strokeType()
631
+ ], exports.UI.prototype, "stroke", void 0);
632
+ __decorate([
633
+ core.strokeType('inside')
634
+ ], exports.UI.prototype, "strokeAlign", void 0);
635
+ __decorate([
636
+ core.strokeType(1)
637
+ ], exports.UI.prototype, "strokeWidth", void 0);
638
+ __decorate([
639
+ core.strokeType(false)
640
+ ], exports.UI.prototype, "strokeWidthFixed", void 0);
641
+ __decorate([
642
+ core.strokeType('none')
643
+ ], exports.UI.prototype, "strokeCap", void 0);
644
+ __decorate([
645
+ core.strokeType('miter')
646
+ ], exports.UI.prototype, "strokeJoin", void 0);
647
+ __decorate([
648
+ core.strokeType()
649
+ ], exports.UI.prototype, "dashPattern", void 0);
650
+ __decorate([
651
+ core.strokeType()
652
+ ], exports.UI.prototype, "dashOffset", void 0);
653
+ __decorate([
654
+ core.strokeType(10)
655
+ ], exports.UI.prototype, "miterLimit", void 0);
656
+ __decorate([
657
+ core.dataType(false)
658
+ ], exports.UI.prototype, "lazy", void 0);
659
+ __decorate([
660
+ core.strokeType('none')
661
+ ], exports.UI.prototype, "startArrow", void 0);
662
+ __decorate([
663
+ core.strokeType('none')
664
+ ], exports.UI.prototype, "endArrow", void 0);
665
+ __decorate([
666
+ core.pathType(0)
667
+ ], exports.UI.prototype, "cornerRadius", void 0);
668
+ __decorate([
669
+ core.pathType()
670
+ ], exports.UI.prototype, "cornerSmoothing", void 0);
671
+ __decorate([
672
+ effectType()
673
+ ], exports.UI.prototype, "shadow", void 0);
674
+ __decorate([
675
+ effectType()
676
+ ], exports.UI.prototype, "innerShadow", void 0);
677
+ __decorate([
678
+ effectType()
679
+ ], exports.UI.prototype, "blur", void 0);
680
+ __decorate([
681
+ effectType()
682
+ ], exports.UI.prototype, "backgroundBlur", void 0);
683
+ __decorate([
684
+ effectType()
685
+ ], exports.UI.prototype, "grayscale", void 0);
686
+ __decorate([
687
+ core.rewrite(core.Leaf.prototype.reset)
688
+ ], exports.UI.prototype, "reset", null);
689
+ __decorate([
690
+ core.rewrite(core.PathDrawer.drawPathByData)
691
+ ], exports.UI.prototype, "__drawPathByData", null);
692
+ exports.UI = UI_1 = __decorate([
693
+ core.useModule(UIBounds),
694
+ core.useModule(UIRender),
695
+ core.rewriteAble()
696
+ ], exports.UI);
697
+
698
+ exports.Group = class Group extends exports.UI {
699
+ get __tag() { return 'Group'; }
700
+ constructor(data) {
701
+ super(data);
702
+ this.__setBranch();
703
+ }
704
+ __setBranch() {
705
+ this.isBranch = true;
706
+ if (!this.children)
707
+ this.children = [];
708
+ }
709
+ set(data) {
710
+ if (data.children) {
711
+ const { children } = data;
712
+ delete data.children;
713
+ if (!this.children) {
714
+ this.__setBranch();
715
+ }
716
+ else {
717
+ this.removeAll(true);
718
+ }
719
+ super.set(data);
720
+ let child;
721
+ children.forEach(childData => {
722
+ child = core.UICreator.get(childData.tag, childData);
723
+ this.add(child);
724
+ });
725
+ data.children = children;
726
+ }
727
+ else {
728
+ super.set(data);
729
+ }
730
+ }
731
+ toJSON() {
732
+ const data = super.toJSON();
733
+ data.children = this.children.map(child => child.toJSON());
734
+ return data;
735
+ }
736
+ pick(_hitPoint, _options) { return undefined; }
737
+ addAt(child, index) {
738
+ this.add(child, index);
739
+ }
740
+ addAfter(child, after) {
741
+ this.add(child, this.children.indexOf(after) + 1);
742
+ }
743
+ addBefore(child, before) {
744
+ this.add(child, this.children.indexOf(before));
745
+ }
746
+ add(_child, _index) { }
747
+ addMany(..._children) { }
748
+ remove(_child, _destroy) { }
749
+ removeAll(_destroy) { }
750
+ clear() { }
751
+ };
752
+ __decorate([
753
+ core.dataProcessor(GroupData)
754
+ ], exports.Group.prototype, "__", void 0);
755
+ exports.Group = __decorate([
756
+ core.useModule(core.Branch),
757
+ core.registerUI()
758
+ ], exports.Group);
759
+
760
+ const debug = core.Debug.get('Leafer');
761
+ exports.Leafer = class Leafer extends exports.Group {
762
+ get __tag() { return 'Leafer'; }
763
+ get isApp() { return false; }
764
+ get app() { return this.parent || this; }
765
+ get imageReady() { return this.viewReady && core.ImageManager.isComplete; }
766
+ get layoutLocked() { return !this.layouter.running; }
767
+ get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
768
+ constructor(userConfig, data) {
769
+ super(data);
770
+ this.zoomLayer = this;
771
+ this.config = {
772
+ type: 'design',
773
+ start: true,
774
+ hittable: true,
775
+ smooth: true,
776
+ zoom: {
777
+ min: 0.02,
778
+ max: 256
779
+ },
780
+ move: {
781
+ holdSpaceKey: true,
782
+ holdMiddleKey: true,
783
+ dragOut: true,
784
+ autoDistance: 2
785
+ }
786
+ };
787
+ this.leafs = 0;
788
+ this.__eventIds = [];
789
+ this.__controllers = [];
790
+ this.__readyWait = [];
791
+ this.__viewReadyWait = [];
792
+ this.__viewCompletedWait = [];
793
+ this.__nextRenderWait = [];
794
+ this.userConfig = userConfig;
795
+ if (userConfig && (userConfig.view || userConfig.width))
796
+ this.init(userConfig);
797
+ }
798
+ init(userConfig, parentApp) {
799
+ if (this.canvas)
800
+ return;
801
+ this.__setLeafer(this);
802
+ if (userConfig)
803
+ core.DataHelper.assign(this.config, userConfig);
804
+ let start;
805
+ const { config } = this;
806
+ this.initType(config.type);
807
+ this.canvas = core.Creator.canvas(config);
808
+ this.__controllers.push(this.renderer = core.Creator.renderer(this, this.canvas, config), this.watcher = core.Creator.watcher(this, config), this.layouter = core.Creator.layouter(this, config));
809
+ if (this.isApp)
810
+ this.__setApp();
811
+ this.__checkAutoLayout(config);
812
+ this.view = this.canvas.view;
813
+ if (parentApp) {
814
+ this.__bindApp(parentApp);
815
+ start = parentApp.running;
816
+ }
817
+ else {
818
+ this.selector = core.Creator.selector(this);
819
+ this.interaction = core.Creator.interaction(this, this.canvas, this.selector, config);
820
+ if (this.interaction) {
821
+ this.__controllers.unshift(this.interaction);
822
+ this.hitCanvasManager = core.Creator.hitCanvasManager();
823
+ }
824
+ this.canvasManager = new core.CanvasManager();
825
+ start = config.start;
826
+ }
827
+ this.hittable = config.hittable;
828
+ this.fill = config.fill;
829
+ this.canvasManager.add(this.canvas);
830
+ this.__listenEvents();
831
+ if (start)
832
+ this.__startTimer = setTimeout(this.start.bind(this));
833
+ this.onInit();
834
+ }
835
+ onInit() { }
836
+ initType(_type) { }
837
+ set(data) {
838
+ if (!this.children) {
839
+ setTimeout(() => {
840
+ super.set(data);
841
+ });
842
+ }
843
+ else {
844
+ super.set(data);
845
+ }
846
+ }
847
+ start() {
848
+ clearTimeout(this.__startTimer);
849
+ if (!this.running && this.canvas) {
850
+ this.ready ? this.emitLeafer(core.LeaferEvent.RESTART) : this.emitLeafer(core.LeaferEvent.START);
851
+ this.__controllers.forEach(item => item.start());
852
+ if (!this.isApp)
853
+ this.renderer.render();
854
+ this.running = true;
855
+ }
856
+ }
857
+ stop() {
858
+ clearTimeout(this.__startTimer);
859
+ if (this.running && this.canvas) {
860
+ this.__controllers.forEach(item => item.stop());
861
+ this.running = false;
862
+ this.emitLeafer(core.LeaferEvent.STOP);
863
+ }
864
+ }
865
+ unlockLayout() {
866
+ this.layouter.start();
867
+ this.updateLayout();
868
+ }
869
+ lockLayout() {
870
+ this.updateLayout();
871
+ this.layouter.stop();
872
+ }
873
+ resize(size) {
874
+ const data = core.DataHelper.copyAttrs({}, size, core.canvasSizeAttrs);
875
+ Object.keys(data).forEach(key => this[key] = data[key]);
876
+ }
877
+ forceFullRender() {
878
+ this.forceRender();
879
+ }
880
+ forceRender(bounds) {
881
+ this.renderer.addBlock(new core.Bounds(bounds) || this.canvas.bounds);
882
+ if (this.viewReady)
883
+ this.renderer.update();
884
+ }
885
+ updateCursor(cursor) {
886
+ const i = this.interaction;
887
+ if (i)
888
+ cursor ? i.setCursor(cursor) : i.updateCursor();
889
+ }
890
+ __doResize(size) {
891
+ if (!this.canvas || this.canvas.isSameSize(size))
892
+ return;
893
+ const old = core.DataHelper.copyAttrs({}, this.canvas, core.canvasSizeAttrs);
894
+ this.canvas.resize(size);
895
+ this.__onResize(new core.ResizeEvent(size, old));
896
+ }
897
+ __onResize(event) {
898
+ this.emitEvent(event);
899
+ core.DataHelper.copyAttrs(this.__, event, core.canvasSizeAttrs);
900
+ setTimeout(() => { if (this.canvasManager)
901
+ this.canvasManager.clearRecycled(); }, 0);
902
+ }
903
+ __setApp() { }
904
+ __bindApp(app) {
905
+ this.selector = app.selector;
906
+ this.interaction = app.interaction;
907
+ this.canvasManager = app.canvasManager;
908
+ this.hitCanvasManager = app.hitCanvasManager;
909
+ }
910
+ __setLeafer(leafer) {
911
+ this.leafer = leafer;
912
+ this.isLeafer = !!leafer;
913
+ this.__level = 1;
914
+ }
915
+ setZoomLayer(zoomLayer) {
916
+ this.zoomLayer = zoomLayer;
917
+ }
918
+ __checkAutoLayout(config) {
919
+ if (!config.width || !config.height) {
920
+ this.autoLayout = new core.AutoBounds(config);
921
+ this.canvas.startAutoLayout(this.autoLayout, this.__onResize.bind(this));
922
+ }
923
+ }
924
+ __setAttr(attrName, newValue) {
925
+ if (this.canvas) {
926
+ if (core.canvasSizeAttrs.includes(attrName)) {
927
+ this.__changeCanvasSize(attrName, newValue);
928
+ }
929
+ else if (attrName === 'fill') {
930
+ this.__changeFill(newValue);
931
+ }
932
+ else if (attrName === 'hittable') {
933
+ this.canvas.hittable = newValue;
934
+ }
935
+ }
936
+ super.__setAttr(attrName, newValue);
937
+ }
938
+ __getAttr(attrName) {
939
+ if (this.canvas && core.canvasSizeAttrs.includes(attrName))
940
+ return this.canvas[attrName];
941
+ return super.__getAttr(attrName);
942
+ }
943
+ __changeCanvasSize(attrName, newValue) {
944
+ const data = core.DataHelper.copyAttrs({}, this.canvas, core.canvasSizeAttrs);
945
+ data[attrName] = this.config[attrName] = newValue;
946
+ if (newValue)
947
+ this.canvas.stopAutoLayout();
948
+ this.__doResize(data);
949
+ }
950
+ __changeFill(newValue) {
951
+ this.config.fill = newValue;
952
+ if (this.canvas.allowBackgroundColor) {
953
+ this.canvas.backgroundColor = newValue;
954
+ }
955
+ else {
956
+ this.forceFullRender();
957
+ }
958
+ }
959
+ __onCreated() {
960
+ this.created = true;
961
+ }
962
+ __onReady() {
963
+ if (this.ready)
964
+ return;
965
+ this.ready = true;
966
+ this.emitLeafer(core.LeaferEvent.BEFORE_READY);
967
+ this.emitLeafer(core.LeaferEvent.READY);
968
+ this.emitLeafer(core.LeaferEvent.AFTER_READY);
969
+ core.WaitHelper.run(this.__readyWait);
970
+ }
971
+ __onViewReady() {
972
+ if (this.viewReady)
973
+ return;
974
+ this.viewReady = true;
975
+ this.emitLeafer(core.LeaferEvent.VIEW_READY);
976
+ core.WaitHelper.run(this.__viewReadyWait);
977
+ }
978
+ __onNextRender() {
979
+ if (this.viewReady) {
980
+ core.WaitHelper.run(this.__nextRenderWait);
981
+ const { imageReady } = this;
982
+ if (imageReady && !this.viewCompleted)
983
+ this.__checkViewCompleted();
984
+ if (!imageReady)
985
+ this.viewCompleted = false;
986
+ }
987
+ }
988
+ __checkViewCompleted(emit = true) {
989
+ this.nextRender(() => {
990
+ if (this.imageReady) {
991
+ if (emit)
992
+ this.emitLeafer(core.LeaferEvent.VIEW_COMPLETED);
993
+ core.WaitHelper.run(this.__viewCompletedWait);
994
+ this.viewCompleted = true;
995
+ }
996
+ });
997
+ }
998
+ __onWatchData() {
999
+ if (this.watcher.childrenChanged && this.interaction) {
1000
+ this.nextRender(() => this.interaction.updateCursor());
1001
+ }
1002
+ }
1003
+ waitReady(item) {
1004
+ this.ready ? item() : this.__readyWait.push(item);
1005
+ }
1006
+ waitViewReady(item) {
1007
+ this.viewReady ? item() : this.__viewReadyWait.push(item);
1008
+ }
1009
+ waitViewCompleted(item) {
1010
+ this.__viewCompletedWait.push(item);
1011
+ if (this.viewCompleted) {
1012
+ this.__checkViewCompleted(false);
1013
+ }
1014
+ else {
1015
+ if (!this.running)
1016
+ this.start();
1017
+ }
1018
+ }
1019
+ nextRender(item, off) {
1020
+ const list = this.__nextRenderWait;
1021
+ if (off) {
1022
+ for (let i = 0; i < list.length; i++) {
1023
+ if (list[i] === item) {
1024
+ list.splice(i, 1);
1025
+ break;
1026
+ }
1027
+ }
1028
+ }
1029
+ else {
1030
+ list.push(item);
1031
+ }
1032
+ }
1033
+ __checkUpdateLayout() {
1034
+ this.__layout.update();
1035
+ }
1036
+ emitLeafer(type) {
1037
+ this.emitEvent(new core.LeaferEvent(type, this));
1038
+ }
1039
+ __listenEvents() {
1040
+ const runId = core.Run.start('FirstCreate ' + this.innerName);
1041
+ this.once(core.LeaferEvent.START, () => core.Run.end(runId));
1042
+ this.once(core.LayoutEvent.END, () => this.__onReady());
1043
+ this.once(core.RenderEvent.START, () => this.__onCreated());
1044
+ this.once(core.RenderEvent.END, () => this.__onViewReady());
1045
+ this.__eventIds.push(this.on_(core.WatchEvent.DATA, this.__onWatchData, this), this.on_(core.RenderEvent.NEXT, this.__onNextRender, this), this.on_(core.LayoutEvent.CHECK_UPDATE, this.__checkUpdateLayout, this));
1046
+ }
1047
+ __removeListenEvents() {
1048
+ this.off_(this.__eventIds);
1049
+ this.__eventIds.length = 0;
1050
+ }
1051
+ destroy() {
1052
+ setTimeout(() => {
1053
+ if (!this.destroyed) {
1054
+ try {
1055
+ this.stop();
1056
+ this.emitEvent(new core.LeaferEvent(core.LeaferEvent.END, this));
1057
+ this.__removeListenEvents();
1058
+ this.__controllers.forEach(item => {
1059
+ if (!(this.parent && item === this.interaction))
1060
+ item.destroy();
1061
+ });
1062
+ this.__controllers.length = 0;
1063
+ if (!this.parent) {
1064
+ if (this.selector)
1065
+ this.selector.destroy();
1066
+ if (this.hitCanvasManager)
1067
+ this.hitCanvasManager.destroy();
1068
+ this.canvasManager.destroy();
1069
+ }
1070
+ this.canvas.destroy();
1071
+ this.config.view = this.view = null;
1072
+ if (this.userConfig)
1073
+ this.userConfig.view = null;
1074
+ super.destroy();
1075
+ setTimeout(() => { core.ImageManager.clearRecycled(); }, 100);
1076
+ }
1077
+ catch (e) {
1078
+ debug.error(e);
1079
+ }
1080
+ }
1081
+ });
1082
+ }
1083
+ };
1084
+ __decorate([
1085
+ core.dataProcessor(LeaferData)
1086
+ ], exports.Leafer.prototype, "__", void 0);
1087
+ __decorate([
1088
+ core.boundsType()
1089
+ ], exports.Leafer.prototype, "pixelRatio", void 0);
1090
+ exports.Leafer = __decorate([
1091
+ core.registerUI()
1092
+ ], exports.Leafer);
1093
+
1094
+ exports.Rect = class Rect extends exports.UI {
1095
+ get __tag() { return 'Rect'; }
1096
+ constructor(data) {
1097
+ super(data);
1098
+ }
1099
+ __drawPathByData(_drawer, _data) { }
1100
+ };
1101
+ __decorate([
1102
+ core.dataProcessor(RectData)
1103
+ ], exports.Rect.prototype, "__", void 0);
1104
+ __decorate([
1105
+ core.rewrite(exports.UI.prototype.__drawPathByBox)
1106
+ ], exports.Rect.prototype, "__drawPathByData", null);
1107
+ exports.Rect = __decorate([
1108
+ core.useModule(RectRender),
1109
+ core.rewriteAble(),
1110
+ core.registerUI()
1111
+ ], exports.Rect);
1112
+
1113
+ const rect = exports.Rect.prototype;
1114
+ const group = exports.Group.prototype;
1115
+ const bounds = {};
1116
+ const { copy, add } = core.BoundsHelper;
1117
+ exports.Box = class Box extends exports.Group {
1118
+ get __tag() { return 'Box'; }
1119
+ constructor(data) {
1120
+ super(data);
1121
+ this.isBranchLeaf = true;
1122
+ this.__layout.renderChanged || this.__layout.renderChange();
1123
+ }
1124
+ __updateStrokeSpread() { return 0; }
1125
+ __updateRectRenderSpread() { return 0; }
1126
+ __updateRenderSpread() {
1127
+ let width = this.__updateRectRenderSpread() || super.__updateRenderSpread();
1128
+ this.__.__drawAfterFill = this.__.overflow === 'hide';
1129
+ if (!width)
1130
+ width = this.__.__drawAfterFill ? 0 : 1;
1131
+ return width;
1132
+ }
1133
+ __updateRectBoxBounds() { }
1134
+ __updateBoxBounds() {
1135
+ if (this.__.__autoBounds && this.children.length) {
1136
+ super.__updateBoxBounds();
1137
+ }
1138
+ else {
1139
+ this.__updateRectBoxBounds();
1140
+ }
1141
+ }
1142
+ __updateStrokeBounds() { }
1143
+ __updateRenderBounds() {
1144
+ this.__updateRectRenderBounds();
1145
+ if (!this.__.__drawAfterFill) {
1146
+ const { renderBounds } = this.__layout;
1147
+ copy(bounds, renderBounds);
1148
+ super.__updateRenderBounds();
1149
+ add(renderBounds, bounds);
1150
+ }
1151
+ }
1152
+ __updateRectRenderBounds() { }
1153
+ __updateRectChange() { }
1154
+ __updateChange() {
1155
+ super.__updateChange();
1156
+ this.__updateRectChange();
1157
+ }
1158
+ __drawPathByData(_drawer, _data) { }
1159
+ __renderRect(_canvas, _options) { }
1160
+ __renderGroup(_canvas, _options) { }
1161
+ __render(canvas, options) {
1162
+ if (this.__.__drawAfterFill) {
1163
+ this.__renderRect(canvas, options);
1164
+ }
1165
+ else {
1166
+ this.__renderRect(canvas, options);
1167
+ this.__renderGroup(canvas, options);
1168
+ }
1169
+ }
1170
+ __drawAfterFill(canvas, options) {
1171
+ canvas.save();
1172
+ canvas.clip();
1173
+ this.__renderGroup(canvas, options);
1174
+ canvas.restore();
1175
+ if (this.__.stroke)
1176
+ this.__drawRenderPath(canvas);
1177
+ }
1178
+ };
1179
+ __decorate([
1180
+ core.dataProcessor(BoxData)
1181
+ ], exports.Box.prototype, "__", void 0);
1182
+ __decorate([
1183
+ core.affectRenderBoundsType('show')
1184
+ ], exports.Box.prototype, "overflow", void 0);
1185
+ __decorate([
1186
+ core.rewrite(rect.__updateStrokeSpread)
1187
+ ], exports.Box.prototype, "__updateStrokeSpread", null);
1188
+ __decorate([
1189
+ core.rewrite(rect.__updateRenderSpread)
1190
+ ], exports.Box.prototype, "__updateRectRenderSpread", null);
1191
+ __decorate([
1192
+ core.rewrite(rect.__updateBoxBounds)
1193
+ ], exports.Box.prototype, "__updateRectBoxBounds", null);
1194
+ __decorate([
1195
+ core.rewrite(rect.__updateStrokeBounds)
1196
+ ], exports.Box.prototype, "__updateStrokeBounds", null);
1197
+ __decorate([
1198
+ core.rewrite(rect.__updateRenderBounds)
1199
+ ], exports.Box.prototype, "__updateRectRenderBounds", null);
1200
+ __decorate([
1201
+ core.rewrite(rect.__updateChange)
1202
+ ], exports.Box.prototype, "__updateRectChange", null);
1203
+ __decorate([
1204
+ core.rewrite(rect.__drawPathByData)
1205
+ ], exports.Box.prototype, "__drawPathByData", null);
1206
+ __decorate([
1207
+ core.rewrite(rect.__render)
1208
+ ], exports.Box.prototype, "__renderRect", null);
1209
+ __decorate([
1210
+ core.rewrite(group.__render)
1211
+ ], exports.Box.prototype, "__renderGroup", null);
1212
+ exports.Box = __decorate([
1213
+ core.rewriteAble(),
1214
+ core.registerUI()
1215
+ ], exports.Box);
1216
+
1217
+ exports.Frame = class Frame extends exports.Box {
1218
+ get __tag() { return 'Frame'; }
1219
+ constructor(data) {
1220
+ super(data);
1221
+ this.isFrame = true;
1222
+ }
1223
+ };
1224
+ __decorate([
1225
+ core.dataProcessor(FrameData)
1226
+ ], exports.Frame.prototype, "__", void 0);
1227
+ __decorate([
1228
+ core.surfaceType('#FFFFFF')
1229
+ ], exports.Frame.prototype, "fill", void 0);
1230
+ __decorate([
1231
+ core.affectRenderBoundsType('hide')
1232
+ ], exports.Frame.prototype, "overflow", void 0);
1233
+ exports.Frame = __decorate([
1234
+ core.registerUI()
1235
+ ], exports.Frame);
1236
+
1237
+ const { moveTo: moveTo$3, closePath: closePath$2, ellipse } = core.PathCommandDataHelper;
1238
+ exports.Ellipse = class Ellipse extends exports.UI {
1239
+ get __tag() { return 'Ellipse'; }
1240
+ constructor(data) {
1241
+ super(data);
1242
+ }
1243
+ __updatePath() {
1244
+ const { width, height, innerRadius, startAngle, endAngle } = this.__;
1245
+ const rx = width / 2, ry = height / 2;
1246
+ const path = this.__.path = [];
1247
+ if (innerRadius) {
1248
+ if (startAngle || endAngle) {
1249
+ if (innerRadius < 1)
1250
+ ellipse(path, rx, ry, rx * innerRadius, ry * innerRadius, 0, startAngle, endAngle, false);
1251
+ ellipse(path, rx, ry, rx, ry, 0, endAngle, startAngle, true);
1252
+ if (innerRadius < 1)
1253
+ closePath$2(path);
1254
+ }
1255
+ else {
1256
+ if (innerRadius < 1) {
1257
+ ellipse(path, rx, ry, rx * innerRadius, ry * innerRadius);
1258
+ moveTo$3(path, width, ry);
1259
+ }
1260
+ ellipse(path, rx, ry, rx, ry, 0, 360, 0, true);
1261
+ }
1262
+ if (core.Platform.ellipseToCurve)
1263
+ this.__.path = this.getPath(true);
1264
+ }
1265
+ else {
1266
+ if (startAngle || endAngle) {
1267
+ moveTo$3(path, rx, ry);
1268
+ ellipse(path, rx, ry, rx, ry, 0, startAngle, endAngle, false);
1269
+ closePath$2(path);
1270
+ }
1271
+ else {
1272
+ ellipse(path, rx, ry, rx, ry);
1273
+ }
1274
+ }
1275
+ }
1276
+ };
1277
+ __decorate([
1278
+ core.dataProcessor(EllipseData)
1279
+ ], exports.Ellipse.prototype, "__", void 0);
1280
+ __decorate([
1281
+ core.pathType(0)
1282
+ ], exports.Ellipse.prototype, "innerRadius", void 0);
1283
+ __decorate([
1284
+ core.pathType(0)
1285
+ ], exports.Ellipse.prototype, "startAngle", void 0);
1286
+ __decorate([
1287
+ core.pathType(0)
1288
+ ], exports.Ellipse.prototype, "endAngle", void 0);
1289
+ exports.Ellipse = __decorate([
1290
+ core.registerUI()
1291
+ ], exports.Ellipse);
1292
+
1293
+ const { moveTo: moveTo$2, lineTo: lineTo$2, drawPoints: drawPoints$1 } = core.PathCommandDataHelper;
1294
+ const { rotate, getAngle, getDistance, defaultPoint } = core.PointHelper;
1295
+ const { toBounds: toBounds$1 } = core.PathBounds;
1296
+ exports.Line = class Line extends exports.UI {
1297
+ get __tag() { return 'Line'; }
1298
+ get toPoint() {
1299
+ const { width, rotation } = this.__;
1300
+ const to = core.getPointData();
1301
+ if (width)
1302
+ to.x = width;
1303
+ if (rotation)
1304
+ rotate(to, rotation);
1305
+ return to;
1306
+ }
1307
+ set toPoint(value) {
1308
+ this.width = getDistance(defaultPoint, value);
1309
+ this.rotation = getAngle(defaultPoint, value);
1310
+ if (this.height)
1311
+ this.height = 0;
1312
+ }
1313
+ constructor(data) {
1314
+ super(data);
1315
+ }
1316
+ __updatePath() {
1317
+ const path = this.__.path = [];
1318
+ if (this.__.points) {
1319
+ drawPoints$1(path, this.__.points, false);
1320
+ }
1321
+ else {
1322
+ moveTo$2(path, 0, 0);
1323
+ lineTo$2(path, this.width, 0);
1324
+ }
1325
+ }
1326
+ __updateRenderPath() {
1327
+ if (this.__.points && this.__.curve) {
1328
+ drawPoints$1(this.__.__pathForRender = [], this.__.points, this.__.curve, this.__tag !== 'Line');
1329
+ }
1330
+ else {
1331
+ super.__updateRenderPath();
1332
+ }
1333
+ }
1334
+ __updateBoxBounds() {
1335
+ if (this.points) {
1336
+ toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
1337
+ }
1338
+ else {
1339
+ super.__updateBoxBounds();
1340
+ }
1341
+ }
1342
+ };
1343
+ __decorate([
1344
+ core.dataProcessor(LineData)
1345
+ ], exports.Line.prototype, "__", void 0);
1346
+ __decorate([
1347
+ core.affectStrokeBoundsType('center')
1348
+ ], exports.Line.prototype, "strokeAlign", void 0);
1349
+ __decorate([
1350
+ core.boundsType(0)
1351
+ ], exports.Line.prototype, "height", void 0);
1352
+ __decorate([
1353
+ core.pathType()
1354
+ ], exports.Line.prototype, "points", void 0);
1355
+ __decorate([
1356
+ core.pathType(0)
1357
+ ], exports.Line.prototype, "curve", void 0);
1358
+ exports.Line = __decorate([
1359
+ core.registerUI()
1360
+ ], exports.Line);
1361
+
1362
+ const { sin: sin$1, cos: cos$1, PI: PI$1 } = Math;
1363
+ const { moveTo: moveTo$1, lineTo: lineTo$1, closePath: closePath$1, drawPoints } = core.PathCommandDataHelper;
1364
+ const line = exports.Line.prototype;
1365
+ exports.Polygon = class Polygon extends exports.UI {
1366
+ get __tag() { return 'Polygon'; }
1367
+ constructor(data) {
1368
+ super(data);
1369
+ }
1370
+ __updatePath() {
1371
+ const path = this.__.path = [];
1372
+ if (this.__.points) {
1373
+ drawPoints(path, this.__.points, false, true);
1374
+ }
1375
+ else {
1376
+ const { width, height, sides } = this.__;
1377
+ const rx = width / 2, ry = height / 2;
1378
+ moveTo$1(path, rx, 0);
1379
+ for (let i = 1; i < sides; i++) {
1380
+ lineTo$1(path, rx + rx * sin$1((i * 2 * PI$1) / sides), ry - ry * cos$1((i * 2 * PI$1) / sides));
1381
+ }
1382
+ }
1383
+ closePath$1(path);
1384
+ }
1385
+ __updateRenderPath() { }
1386
+ __updateBoxBounds() { }
1387
+ };
1388
+ __decorate([
1389
+ core.dataProcessor(PolygonData)
1390
+ ], exports.Polygon.prototype, "__", void 0);
1391
+ __decorate([
1392
+ core.pathType(3)
1393
+ ], exports.Polygon.prototype, "sides", void 0);
1394
+ __decorate([
1395
+ core.pathType()
1396
+ ], exports.Polygon.prototype, "points", void 0);
1397
+ __decorate([
1398
+ core.pathType(0)
1399
+ ], exports.Polygon.prototype, "curve", void 0);
1400
+ __decorate([
1401
+ core.rewrite(line.__updateRenderPath)
1402
+ ], exports.Polygon.prototype, "__updateRenderPath", null);
1403
+ __decorate([
1404
+ core.rewrite(line.__updateBoxBounds)
1405
+ ], exports.Polygon.prototype, "__updateBoxBounds", null);
1406
+ exports.Polygon = __decorate([
1407
+ core.rewriteAble(),
1408
+ core.registerUI()
1409
+ ], exports.Polygon);
1410
+
1411
+ const { sin, cos, PI } = Math;
1412
+ const { moveTo, lineTo, closePath } = core.PathCommandDataHelper;
1413
+ exports.Star = class Star extends exports.UI {
1414
+ get __tag() { return 'Star'; }
1415
+ constructor(data) {
1416
+ super(data);
1417
+ }
1418
+ __updatePath() {
1419
+ const { width, height, corners, innerRadius } = this.__;
1420
+ const rx = width / 2, ry = height / 2;
1421
+ const path = this.__.path = [];
1422
+ moveTo(path, rx, 0);
1423
+ for (let i = 1; i < corners * 2; i++) {
1424
+ lineTo(path, rx + (i % 2 === 0 ? rx : rx * innerRadius) * sin((i * PI) / corners), ry - (i % 2 === 0 ? ry : ry * innerRadius) * cos((i * PI) / corners));
1425
+ }
1426
+ closePath(path);
1427
+ }
1428
+ };
1429
+ __decorate([
1430
+ core.dataProcessor(StarData)
1431
+ ], exports.Star.prototype, "__", void 0);
1432
+ __decorate([
1433
+ core.pathType(5)
1434
+ ], exports.Star.prototype, "corners", void 0);
1435
+ __decorate([
1436
+ core.pathType(0.382)
1437
+ ], exports.Star.prototype, "innerRadius", void 0);
1438
+ exports.Star = __decorate([
1439
+ core.registerUI()
1440
+ ], exports.Star);
1441
+
1442
+ exports.Image = class Image extends exports.Rect {
1443
+ get __tag() { return 'Image'; }
1444
+ get ready() { return this.image ? this.image.ready : false; }
1445
+ constructor(data) {
1446
+ super(data);
1447
+ this.on(core.ImageEvent.LOADED, (e) => {
1448
+ if (e.attrName === 'fill' && e.attrValue.url === this.url)
1449
+ this.image = e.image;
1450
+ });
1451
+ }
1452
+ destroy() {
1453
+ this.image = null;
1454
+ super.destroy();
1455
+ }
1456
+ };
1457
+ __decorate([
1458
+ core.dataProcessor(ImageData)
1459
+ ], exports.Image.prototype, "__", void 0);
1460
+ __decorate([
1461
+ core.boundsType('')
1462
+ ], exports.Image.prototype, "url", void 0);
1463
+ exports.Image = __decorate([
1464
+ core.registerUI()
1465
+ ], exports.Image);
1466
+
1467
+ exports.Canvas = class Canvas extends exports.Rect {
1468
+ get __tag() { return 'Canvas'; }
1469
+ constructor(data) {
1470
+ super(data);
1471
+ this.canvas = core.Creator.canvas(this.__);
1472
+ this.context = this.canvas.context;
1473
+ this.__.__drawAfterFill = true;
1474
+ }
1475
+ draw(ui, offset, scale, rotation) {
1476
+ ui.__layout.update();
1477
+ const matrix = new core.Matrix(ui.__world).invert();
1478
+ const m = new core.Matrix();
1479
+ if (offset)
1480
+ m.translate(offset.x, offset.y);
1481
+ if (scale)
1482
+ typeof scale === 'number' ? m.scale(scale) : m.scale(scale.x, scale.y);
1483
+ if (rotation)
1484
+ m.rotate(rotation);
1485
+ matrix.multiplyParent(m);
1486
+ ui.__render(this.canvas, { matrix: matrix.withScale() });
1487
+ this.paint();
1488
+ }
1489
+ paint() {
1490
+ this.forceUpdate('fill');
1491
+ }
1492
+ __drawAfterFill(canvas, _options) {
1493
+ const origin = this.canvas.view;
1494
+ const { width, height } = this;
1495
+ if (this.__.cornerRadius) {
1496
+ canvas.save();
1497
+ canvas.clip();
1498
+ canvas.drawImage(this.canvas.view, 0, 0, origin.width, origin.height, 0, 0, width, height);
1499
+ canvas.restore();
1500
+ }
1501
+ else {
1502
+ canvas.drawImage(this.canvas.view, 0, 0, origin.width, origin.height, 0, 0, width, height);
1503
+ }
1504
+ }
1505
+ __updateSize() {
1506
+ const { canvas } = this;
1507
+ if (canvas) {
1508
+ const { smooth } = this.__;
1509
+ if (canvas.smooth !== smooth)
1510
+ canvas.smooth = smooth;
1511
+ canvas.resize(this.__);
1512
+ }
1513
+ }
1514
+ destroy() {
1515
+ if (this.canvas) {
1516
+ this.canvas.destroy();
1517
+ this.canvas = null;
1518
+ this.context = null;
1519
+ }
1520
+ super.destroy();
1521
+ }
1522
+ };
1523
+ __decorate([
1524
+ core.dataProcessor(ImageData)
1525
+ ], exports.Canvas.prototype, "__", void 0);
1526
+ __decorate([
1527
+ resizeType(100)
1528
+ ], exports.Canvas.prototype, "width", void 0);
1529
+ __decorate([
1530
+ resizeType(100)
1531
+ ], exports.Canvas.prototype, "height", void 0);
1532
+ __decorate([
1533
+ resizeType(core.Platform.devicePixelRatio)
1534
+ ], exports.Canvas.prototype, "pixelRatio", void 0);
1535
+ __decorate([
1536
+ resizeType(true)
1537
+ ], exports.Canvas.prototype, "smooth", void 0);
1538
+ __decorate([
1539
+ core.hitType('all')
1540
+ ], exports.Canvas.prototype, "hitFill", void 0);
1541
+ exports.Canvas = __decorate([
1542
+ core.registerUI()
1543
+ ], exports.Canvas);
1544
+
1545
+ const { copyAndSpread, includes, spread, setList } = core.BoundsHelper;
1546
+ exports.Text = class Text extends exports.UI {
1547
+ get __tag() { return 'Text'; }
1548
+ get textDrawData() {
1549
+ this.__layout.update();
1550
+ return this.__.__textDrawData;
1551
+ }
1552
+ constructor(data) {
1553
+ super(data);
1554
+ }
1555
+ __drawHitPath(canvas) {
1556
+ const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
1557
+ canvas.beginPath();
1558
+ if (this.__.__letterSpacing < 0) {
1559
+ this.__drawPathByData(canvas);
1560
+ }
1561
+ else {
1562
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
1563
+ }
1564
+ }
1565
+ __drawPathByData(drawer, _data) {
1566
+ const { x, y, width, height } = this.__layout.boxBounds;
1567
+ drawer.rect(x, y, width, height);
1568
+ }
1569
+ __drawRenderPath(canvas) {
1570
+ canvas.font = this.__.__font;
1571
+ }
1572
+ __updateTextDrawData() {
1573
+ const data = this.__;
1574
+ data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
1575
+ }
1576
+ __updateBoxBounds() {
1577
+ const data = this.__;
1578
+ const layout = this.__layout;
1579
+ const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data;
1580
+ const autoWidth = data.__autoWidth;
1581
+ const autoHeight = data.__autoHeight;
1582
+ data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
1583
+ data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
1584
+ data.__padding = padding ? core.MathHelper.fourNumber(padding) : undefined;
1585
+ data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
1586
+ data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
1587
+ data.__clipText = textOverflow !== 'show' && !data.__autoBounds;
1588
+ this.__updateTextDrawData();
1589
+ const { bounds } = data.__textDrawData;
1590
+ const b = layout.boxBounds;
1591
+ if (data.__lineHeight < fontSize)
1592
+ spread(bounds, fontSize / 2);
1593
+ if (autoWidth || autoHeight) {
1594
+ b.x = autoWidth ? bounds.x : 0;
1595
+ b.y = autoHeight ? bounds.y : 0;
1596
+ b.width = autoWidth ? bounds.width : data.width;
1597
+ b.height = autoHeight ? bounds.height : data.height;
1598
+ if (padding) {
1599
+ const [top, right, bottom, left] = data.__padding;
1600
+ if (autoWidth) {
1601
+ b.x -= left;
1602
+ b.width += (right + left);
1603
+ }
1604
+ if (autoHeight) {
1605
+ b.y -= top;
1606
+ b.height += (bottom + top);
1607
+ }
1608
+ }
1609
+ this.__updateNaturalSize();
1610
+ }
1611
+ else {
1612
+ super.__updateBoxBounds();
1613
+ }
1614
+ const contentBounds = includes(b, bounds) ? b : bounds;
1615
+ if (contentBounds !== layout.contentBounds) {
1616
+ layout.contentBounds = contentBounds;
1617
+ layout.renderChanged = true;
1618
+ setList(data.__textBoxBounds = {}, [b, bounds]);
1619
+ }
1620
+ else {
1621
+ data.__textBoxBounds = contentBounds;
1622
+ }
1623
+ }
1624
+ __updateRenderSpread() {
1625
+ let width = super.__updateRenderSpread();
1626
+ if (!width)
1627
+ width = this.__layout.boxBounds === this.__layout.contentBounds ? 0 : 1;
1628
+ return width;
1629
+ }
1630
+ __updateRenderBounds() {
1631
+ copyAndSpread(this.__layout.renderBounds, this.__.__textBoxBounds, this.__layout.renderSpread);
1632
+ }
1633
+ };
1634
+ __decorate([
1635
+ core.dataProcessor(TextData)
1636
+ ], exports.Text.prototype, "__", void 0);
1637
+ __decorate([
1638
+ core.boundsType(0)
1639
+ ], exports.Text.prototype, "width", void 0);
1640
+ __decorate([
1641
+ core.boundsType(0)
1642
+ ], exports.Text.prototype, "height", void 0);
1643
+ __decorate([
1644
+ core.boundsType(0)
1645
+ ], exports.Text.prototype, "padding", void 0);
1646
+ __decorate([
1647
+ core.surfaceType('#000000')
1648
+ ], exports.Text.prototype, "fill", void 0);
1649
+ __decorate([
1650
+ core.affectStrokeBoundsType('outside')
1651
+ ], exports.Text.prototype, "strokeAlign", void 0);
1652
+ __decorate([
1653
+ core.hitType('all')
1654
+ ], exports.Text.prototype, "hitFill", void 0);
1655
+ __decorate([
1656
+ core.boundsType('')
1657
+ ], exports.Text.prototype, "text", void 0);
1658
+ __decorate([
1659
+ core.boundsType('L')
1660
+ ], exports.Text.prototype, "fontFamily", void 0);
1661
+ __decorate([
1662
+ core.boundsType(12)
1663
+ ], exports.Text.prototype, "fontSize", void 0);
1664
+ __decorate([
1665
+ core.boundsType('normal')
1666
+ ], exports.Text.prototype, "fontWeight", void 0);
1667
+ __decorate([
1668
+ core.boundsType(false)
1669
+ ], exports.Text.prototype, "italic", void 0);
1670
+ __decorate([
1671
+ core.boundsType('none')
1672
+ ], exports.Text.prototype, "textCase", void 0);
1673
+ __decorate([
1674
+ core.boundsType('none')
1675
+ ], exports.Text.prototype, "textDecoration", void 0);
1676
+ __decorate([
1677
+ core.boundsType(0)
1678
+ ], exports.Text.prototype, "letterSpacing", void 0);
1679
+ __decorate([
1680
+ core.boundsType({ type: 'percent', value: 150 })
1681
+ ], exports.Text.prototype, "lineHeight", void 0);
1682
+ __decorate([
1683
+ core.boundsType(0)
1684
+ ], exports.Text.prototype, "paraIndent", void 0);
1685
+ __decorate([
1686
+ core.boundsType(0)
1687
+ ], exports.Text.prototype, "paraSpacing", void 0);
1688
+ __decorate([
1689
+ core.boundsType('left')
1690
+ ], exports.Text.prototype, "textAlign", void 0);
1691
+ __decorate([
1692
+ core.boundsType('top')
1693
+ ], exports.Text.prototype, "verticalAlign", void 0);
1694
+ __decorate([
1695
+ core.boundsType('normal')
1696
+ ], exports.Text.prototype, "textWrap", void 0);
1697
+ __decorate([
1698
+ core.boundsType('show')
1699
+ ], exports.Text.prototype, "textOverflow", void 0);
1700
+ exports.Text = __decorate([
1701
+ core.registerUI()
1702
+ ], exports.Text);
1703
+
1704
+ const { toBounds } = core.PathBounds;
1705
+ exports.Path = class Path extends exports.UI {
1706
+ get __tag() { return 'Path'; }
1707
+ constructor(data) {
1708
+ super(data);
1709
+ }
1710
+ __updateBoxBounds() {
1711
+ toBounds(this.__.path, this.__layout.boxBounds);
1712
+ }
1713
+ };
1714
+ __decorate([
1715
+ core.dataProcessor(PathData)
1716
+ ], exports.Path.prototype, "__", void 0);
1717
+ __decorate([
1718
+ core.pathType()
1719
+ ], exports.Path.prototype, "path", void 0);
1720
+ __decorate([
1721
+ core.pathType()
1722
+ ], exports.Path.prototype, "windingRule", void 0);
1723
+ __decorate([
1724
+ core.affectStrokeBoundsType('center')
1725
+ ], exports.Path.prototype, "strokeAlign", void 0);
1726
+ exports.Path = __decorate([
1727
+ core.registerUI()
1728
+ ], exports.Path);
1729
+
1730
+ exports.Pen = class Pen extends exports.Group {
1731
+ get __tag() { return 'Pen'; }
1732
+ constructor(data) {
1733
+ super(data);
1734
+ }
1735
+ setStyle(data) {
1736
+ const path = this.pathElement = new exports.Path(data);
1737
+ this.pathStyle = data;
1738
+ this.path = path.path || (path.path = []);
1739
+ this.add(path);
1740
+ return this;
1741
+ }
1742
+ beginPath() {
1743
+ this.path.length = 0;
1744
+ this.paint();
1745
+ return this;
1746
+ }
1747
+ moveTo(_x, _y) { return this; }
1748
+ lineTo(_x, _y) { return this; }
1749
+ bezierCurveTo(_x1, _y1, _x2, _y2, _x, _y) { return this; }
1750
+ quadraticCurveTo(_x1, _y1, _x, _y) { return this; }
1751
+ closePath() { return this; }
1752
+ rect(_x, _y, _width, _height) { return this; }
1753
+ roundRect(_x, _y, _width, _height, _cornerRadius) { return this; }
1754
+ ellipse(_x, _y, _radiusX, _radiusY, _rotation, _startAngle, _endAngle, _anticlockwise) { return this; }
1755
+ arc(_x, _y, _radius, _startAngle, _endAngle, _anticlockwise) { return this; }
1756
+ arcTo(_x1, _y1, _x2, _y2, _radius) { return this; }
1757
+ drawEllipse(_x, _y, _radiusX, _radiusY, _rotation, _startAngle, _endAngle, _anticlockwise) { return this; }
1758
+ drawArc(_x, _y, _radius, _startAngle, _endAngle, _anticlockwise) { return this; }
1759
+ drawPoints(_points, _curve, _close) { return this; }
1760
+ paint() {
1761
+ this.pathElement.forceUpdate('path');
1762
+ }
1763
+ };
1764
+ __decorate([
1765
+ core.dataProcessor(PenData)
1766
+ ], exports.Pen.prototype, "__", void 0);
1767
+ exports.Pen = __decorate([
1768
+ core.useModule(core.PathCreator, ['beginPath']),
1769
+ core.registerUI()
1770
+ ], exports.Pen);
1771
+
1772
+ exports.ArrowData = ArrowData;
1773
+ exports.BoxData = BoxData;
1774
+ exports.CanvasData = CanvasData;
1775
+ exports.ColorConvert = ColorConvert;
1776
+ exports.Effect = Effect;
1777
+ exports.EllipseData = EllipseData;
1778
+ exports.Export = Export;
1779
+ exports.FrameData = FrameData;
1780
+ exports.GroupData = GroupData;
1781
+ exports.ImageData = ImageData;
1782
+ exports.LeaferData = LeaferData;
1783
+ exports.LineData = LineData;
1784
+ exports.Paint = Paint;
1785
+ exports.PaintGradient = PaintGradient;
1786
+ exports.PaintImage = PaintImage;
1787
+ exports.PathData = PathData;
1788
+ exports.PenData = PenData;
1789
+ exports.PolygonData = PolygonData;
1790
+ exports.RectData = RectData;
1791
+ exports.RectRender = RectRender;
1792
+ exports.StarData = StarData;
1793
+ exports.TextConvert = TextConvert;
1794
+ exports.TextData = TextData;
1795
+ exports.UIBounds = UIBounds;
1796
+ exports.UIData = UIData;
1797
+ exports.UIRender = UIRender;
1798
+ exports.UnitConvert = UnitConvert;
1799
+ exports.effectType = effectType;
1800
+ exports.resizeType = resizeType;
1801
+ Object.keys(core).forEach(function (k) {
1802
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1803
+ enumerable: true,
1804
+ get: function () { return core[k]; }
1805
+ });
1806
+ });