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