@leafer-ui/core 1.0.0-rc.2 → 1.0.0-rc.20

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