@leafer-ui/core 1.0.0-rc.3 → 1.0.0-rc.30

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,1834 +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
- }
973
- else {
974
- super.__updateRenderPath();
975
- }
976
- }
977
- __updateBoxBounds() {
978
- if (this.__.points) {
979
- toBounds$2(this.__.__pathForRender, this.__layout.boxBounds);
980
- this.__updateNaturalSize();
981
- }
982
- else {
983
- super.__updateBoxBounds();
984
- }
985
- }
986
- };
987
- __decorate([
988
- dataProcessor(PolygonData)
989
- ], Polygon.prototype, "__", void 0);
990
- __decorate([
991
- pathType(3)
992
- ], Polygon.prototype, "sides", void 0);
993
- __decorate([
994
- pathType()
995
- ], Polygon.prototype, "points", void 0);
996
- __decorate([
997
- pathType(0)
998
- ], Polygon.prototype, "curve", void 0);
999
- Polygon = __decorate([
1000
- registerUI()
1001
- ], Polygon);
1002
-
1003
- const { sin, cos, PI } = Math;
1004
- const { moveTo: moveTo$1, lineTo: lineTo$1, closePath } = PathCommandDataHelper;
1005
- let Star = class Star extends UI {
1006
- get __tag() { return 'Star'; }
1007
- constructor(data) {
1008
- super(data);
1009
- }
1010
- __updatePath() {
1011
- const { width, height, corners, innerRadius } = this.__;
1012
- const rx = width / 2, ry = height / 2;
1013
- const path = this.__.path = [];
1014
- moveTo$1(path, rx, 0);
1015
- for (let i = 1; i < corners * 2; i++) {
1016
- 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));
1017
- }
1018
- closePath(path);
1019
- }
1020
- };
1021
- __decorate([
1022
- dataProcessor(StarData)
1023
- ], Star.prototype, "__", void 0);
1024
- __decorate([
1025
- pathType(5)
1026
- ], Star.prototype, "corners", void 0);
1027
- __decorate([
1028
- pathType(0.382)
1029
- ], Star.prototype, "innerRadius", void 0);
1030
- Star = __decorate([
1031
- registerUI()
1032
- ], Star);
1033
-
1034
- const { moveTo, lineTo, drawPoints } = PathCommandDataHelper;
1035
- const { rotate, getAngle, getDistance, defaultPoint } = PointHelper;
1036
- const { toBounds: toBounds$1 } = PathBounds;
1037
- let Line = class Line extends UI {
1038
- get __tag() { return 'Line'; }
1039
- get resizeable() { return !this.points; }
1040
- get toPoint() {
1041
- const { width, rotation } = this.__;
1042
- const to = { x: 0, y: 0 };
1043
- if (width)
1044
- to.x = width;
1045
- if (rotation)
1046
- rotate(to, rotation);
1047
- return to;
1048
- }
1049
- set toPoint(value) {
1050
- this.width = getDistance(defaultPoint, value);
1051
- this.rotation = getAngle(defaultPoint, value);
1052
- if (this.height)
1053
- this.height = 0;
1054
- }
1055
- constructor(data) {
1056
- super(data);
1057
- }
1058
- __updatePath() {
1059
- const path = this.__.path = [];
1060
- if (this.__.points) {
1061
- drawPoints(path, this.__.points, false);
1062
- }
1063
- else {
1064
- moveTo(path, 0, 0);
1065
- lineTo(path, this.width, 0);
1066
- }
1067
- }
1068
- __updateRenderPath() {
1069
- if (this.__.points && this.__.curve) {
1070
- drawPoints(this.__.__pathForRender = [], this.__.points, this.__.curve, false);
1071
- }
1072
- else {
1073
- super.__updateRenderPath();
1074
- }
1075
- }
1076
- __updateBoxBounds() {
1077
- if (this.points) {
1078
- toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
1079
- this.__updateNaturalSize();
1080
- }
1081
- else {
1082
- super.__updateBoxBounds();
1083
- }
1084
- }
1085
- };
1086
- __decorate([
1087
- dataProcessor(LineData)
1088
- ], Line.prototype, "__", void 0);
1089
- __decorate([
1090
- affectStrokeBoundsType('center')
1091
- ], Line.prototype, "strokeAlign", void 0);
1092
- __decorate([
1093
- boundsType(0)
1094
- ], Line.prototype, "height", void 0);
1095
- __decorate([
1096
- pathType()
1097
- ], Line.prototype, "points", void 0);
1098
- __decorate([
1099
- pathType(0)
1100
- ], Line.prototype, "curve", void 0);
1101
- Line = __decorate([
1102
- registerUI()
1103
- ], Line);
1104
-
1105
- let Image = class Image extends Rect {
1106
- get __tag() { return 'Image'; }
1107
- get ready() { return this.image ? this.image.ready : false; }
1108
- constructor(data) {
1109
- super(data);
1110
- }
1111
- __updateBoxBounds() {
1112
- let update;
1113
- const { url } = this;
1114
- const fill = this.fill;
1115
- if (fill) {
1116
- if (fill.url !== url)
1117
- update = true;
1118
- }
1119
- else {
1120
- if (url)
1121
- update = true;
1122
- }
1123
- if (update) {
1124
- if (this.image)
1125
- this.image = null;
1126
- this.fill = url ? { type: 'image', mode: 'strench', url } : undefined;
1127
- this.once(ImageEvent.LOADED, (e) => this.image = e.image);
1128
- }
1129
- super.__updateBoxBounds();
1130
- }
1131
- destroy() {
1132
- this.image = null;
1133
- super.destroy();
1134
- }
1135
- };
1136
- __decorate([
1137
- dataProcessor(ImageData)
1138
- ], Image.prototype, "__", void 0);
1139
- __decorate([
1140
- boundsType('')
1141
- ], Image.prototype, "url", void 0);
1142
- Image = __decorate([
1143
- registerUI()
1144
- ], Image);
1145
-
1146
- let Canvas = class Canvas extends Rect {
1147
- get __tag() { return 'Canvas'; }
1148
- constructor(data) {
1149
- super(data);
1150
- this.canvas = Creator.canvas(this.__);
1151
- this.context = this.canvas.context;
1152
- this.__.__drawAfterFill = true;
1153
- }
1154
- draw(ui, offset, scale, rotation) {
1155
- ui.__layout.checkUpdate();
1156
- const matrix = new Matrix(ui.__world);
1157
- matrix.invert();
1158
- const m = new Matrix();
1159
- if (offset)
1160
- m.translate(offset.x, offset.y);
1161
- if (scale)
1162
- typeof scale === 'number' ? m.scale(scale) : m.scale(scale.x, scale.y);
1163
- if (rotation)
1164
- m.rotate(rotation);
1165
- matrix.preMultiply(m);
1166
- ui.__render(this.canvas, { matrix });
1167
- this.paint();
1168
- }
1169
- paint() {
1170
- this.forceUpdate('fill');
1171
- }
1172
- __drawAfterFill(canvas, _options) {
1173
- const origin = this.canvas.view;
1174
- const { width, height } = this;
1175
- if (this.__.cornerRadius) {
1176
- canvas.save();
1177
- canvas.clip();
1178
- canvas.drawImage(this.canvas.view, 0, 0, origin.width, origin.height, 0, 0, width, height);
1179
- canvas.restore();
1180
- }
1181
- else {
1182
- canvas.drawImage(this.canvas.view, 0, 0, origin.width, origin.height, 0, 0, width, height);
1183
- }
1184
- }
1185
- __updateSize() {
1186
- const { canvas } = this;
1187
- if (canvas) {
1188
- const { smooth } = this.__;
1189
- if (canvas.smooth !== smooth)
1190
- canvas.smooth = smooth;
1191
- canvas.resize(this.__);
1192
- }
1193
- }
1194
- destroy() {
1195
- if (this.canvas) {
1196
- this.canvas.destroy();
1197
- this.canvas = null;
1198
- this.context = null;
1199
- }
1200
- super.destroy();
1201
- }
1202
- };
1203
- __decorate([
1204
- dataProcessor(ImageData)
1205
- ], Canvas.prototype, "__", void 0);
1206
- __decorate([
1207
- resizeType(100)
1208
- ], Canvas.prototype, "width", void 0);
1209
- __decorate([
1210
- resizeType(100)
1211
- ], Canvas.prototype, "height", void 0);
1212
- __decorate([
1213
- resizeType(Platform.devicePixelRatio)
1214
- ], Canvas.prototype, "pixelRatio", void 0);
1215
- __decorate([
1216
- resizeType(true)
1217
- ], Canvas.prototype, "smooth", void 0);
1218
- __decorate([
1219
- hitType('all')
1220
- ], Canvas.prototype, "hitFill", void 0);
1221
- Canvas = __decorate([
1222
- registerUI()
1223
- ], Canvas);
1224
-
1225
- const { copyAndSpread, includes, spread } = BoundsHelper;
1226
- let Text = class Text extends UI {
1227
- get __tag() { return 'Text'; }
1228
- get textDrawData() {
1229
- this.__layout.checkUpdate();
1230
- return this.__.__textDrawData;
1231
- }
1232
- constructor(data) {
1233
- super(data);
1234
- }
1235
- __drawHitPath(canvas) {
1236
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
1237
- canvas.beginPath();
1238
- if (this.__.__letterSpacing < 0) {
1239
- this.__drawPathByData(canvas);
1240
- }
1241
- else {
1242
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
1243
- }
1244
- }
1245
- __drawPathByData(drawer, _data) {
1246
- const { x, y, width, height } = this.__layout.boxBounds;
1247
- drawer.rect(x, y, width, height);
1248
- }
1249
- __drawRenderPath(canvas) {
1250
- canvas.font = this.__.__font;
1251
- }
1252
- __updateTextDrawData() {
1253
- const data = this.__;
1254
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
1255
- }
1256
- __updateBoxBounds() {
1257
- const data = this.__;
1258
- const layout = this.__layout;
1259
- const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase } = data;
1260
- data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
1261
- data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
1262
- data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
1263
- data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
1264
- this.__updateTextDrawData();
1265
- const { bounds } = data.__textDrawData;
1266
- const b = layout.boxBounds;
1267
- if (data.__lineHeight < fontSize)
1268
- spread(bounds, fontSize / 2);
1269
- const width = data.__getInput('width');
1270
- const height = data.__getInput('height');
1271
- if (width && height) {
1272
- super.__updateBoxBounds();
1273
- }
1274
- else {
1275
- b.x = width ? 0 : bounds.x;
1276
- b.y = height ? 0 : bounds.y;
1277
- b.width = width ? width : bounds.width;
1278
- b.height = height ? height : bounds.height;
1279
- this.__updateNaturalSize();
1280
- }
1281
- const contentBounds = includes(b, bounds) ? b : bounds;
1282
- if (contentBounds !== layout.contentBounds) {
1283
- layout.contentBounds = contentBounds;
1284
- layout.renderChanged = true;
1285
- }
1286
- }
1287
- __updateRenderSpread() {
1288
- let width = super.__updateRenderSpread();
1289
- if (!width)
1290
- width = this.__layout.boxBounds === this.__layout.contentBounds ? 0 : 1;
1291
- return width;
1292
- }
1293
- __updateRenderBounds() {
1294
- copyAndSpread(this.__layout.renderBounds, this.__layout.contentBounds, this.__layout.renderSpread);
1295
- }
1296
- };
1297
- __decorate([
1298
- dataProcessor(TextData)
1299
- ], Text.prototype, "__", void 0);
1300
- __decorate([
1301
- boundsType(0)
1302
- ], Text.prototype, "width", void 0);
1303
- __decorate([
1304
- boundsType(0)
1305
- ], Text.prototype, "height", void 0);
1306
- __decorate([
1307
- boundsType(0)
1308
- ], Text.prototype, "padding", void 0);
1309
- __decorate([
1310
- affectStrokeBoundsType('outside')
1311
- ], Text.prototype, "strokeAlign", void 0);
1312
- __decorate([
1313
- boundsType('')
1314
- ], Text.prototype, "text", void 0);
1315
- __decorate([
1316
- boundsType('L')
1317
- ], Text.prototype, "fontFamily", void 0);
1318
- __decorate([
1319
- boundsType(12)
1320
- ], Text.prototype, "fontSize", void 0);
1321
- __decorate([
1322
- boundsType('normal')
1323
- ], Text.prototype, "fontWeight", void 0);
1324
- __decorate([
1325
- boundsType(false)
1326
- ], Text.prototype, "italic", void 0);
1327
- __decorate([
1328
- boundsType('none')
1329
- ], Text.prototype, "textCase", void 0);
1330
- __decorate([
1331
- boundsType('none')
1332
- ], Text.prototype, "textDecoration", void 0);
1333
- __decorate([
1334
- boundsType(0)
1335
- ], Text.prototype, "letterSpacing", void 0);
1336
- __decorate([
1337
- boundsType({ type: 'percent', value: 150 })
1338
- ], Text.prototype, "lineHeight", void 0);
1339
- __decorate([
1340
- boundsType(0)
1341
- ], Text.prototype, "paraIndent", void 0);
1342
- __decorate([
1343
- boundsType(0)
1344
- ], Text.prototype, "paraSpacing", void 0);
1345
- __decorate([
1346
- boundsType('left')
1347
- ], Text.prototype, "textAlign", void 0);
1348
- __decorate([
1349
- boundsType('top')
1350
- ], Text.prototype, "verticalAlign", void 0);
1351
- __decorate([
1352
- boundsType('show')
1353
- ], Text.prototype, "textOverflow", void 0);
1354
- Text = __decorate([
1355
- registerUI()
1356
- ], Text);
1357
-
1358
- const { toBounds } = PathBounds;
1359
- let Path = class Path extends UI {
1360
- get __tag() { return 'Path'; }
1361
- get resizeable() { return false; }
1362
- constructor(data) {
1363
- super(data);
1364
- }
1365
- __updateBoxBounds() {
1366
- toBounds(this.__.path, this.__layout.boxBounds);
1367
- this.__updateNaturalSize();
1368
- }
1369
- };
1370
- __decorate([
1371
- dataProcessor(PathData)
1372
- ], Path.prototype, "__", void 0);
1373
- __decorate([
1374
- pathType()
1375
- ], Path.prototype, "path", void 0);
1376
- __decorate([
1377
- pathType()
1378
- ], Path.prototype, "windingRule", void 0);
1379
- __decorate([
1380
- affectStrokeBoundsType('center')
1381
- ], Path.prototype, "strokeAlign", void 0);
1382
- Path = __decorate([
1383
- registerUI()
1384
- ], Path);
1385
-
1386
- let Pen = class Pen extends Group {
1387
- get __tag() { return 'Pen'; }
1388
- constructor(data) {
1389
- super(data);
1390
- }
1391
- setStyle(data) {
1392
- const path = this.pathElement = new Path(data);
1393
- this.pathStyle = data;
1394
- this.path = path.path || (path.path = []);
1395
- this.add(path);
1396
- return this;
1397
- }
1398
- beginPath() {
1399
- this.path.length = 0;
1400
- this.paint();
1401
- return this;
1402
- }
1403
- moveTo(_x, _y) { return this; }
1404
- lineTo(_x, _y) { return this; }
1405
- bezierCurveTo(_x1, _y1, _x2, _y2, _x, _y) { return this; }
1406
- quadraticCurveTo(_x1, _y1, _x, _y) { return this; }
1407
- closePath() { return this; }
1408
- rect(_x, _y, _width, _height) { return this; }
1409
- roundRect(_x, _y, _width, _height, _cornerRadius) { return this; }
1410
- ellipse(_x, _y, _radiusX, _radiusY, _rotation, _startAngle, _endAngle, _anticlockwise) { return this; }
1411
- arc(_x, _y, _radius, _startAngle, _endAngle, _anticlockwise) { return this; }
1412
- arcTo(_x1, _y1, _x2, _y2, _radius) { return this; }
1413
- drawEllipse(_x, _y, _radiusX, _radiusY, _rotation, _startAngle, _endAngle, _anticlockwise) { return this; }
1414
- drawArc(_x, _y, _radius, _startAngle, _endAngle, _anticlockwise) { return this; }
1415
- drawPoints(_points, _curve, _close) { return this; }
1416
- paint() {
1417
- this.pathElement.forceUpdate('path');
1418
- }
1419
- clear() {
1420
- this.removeAll(true);
1421
- }
1422
- };
1423
- __decorate([
1424
- dataProcessor(PenData)
1425
- ], Pen.prototype, "__", void 0);
1426
- Pen = __decorate([
1427
- useModule(PathCreator, ['beginPath']),
1428
- registerUI()
1429
- ], Pen);
1430
-
1431
- const debug = Debug.get('Leafer');
1432
- let Leafer = class Leafer extends Group {
1433
- get __tag() { return 'Leafer'; }
1434
- get isApp() { return false; }
1435
- get app() { return this.parent || this; }
1436
- constructor(userConfig, data) {
1437
- super(data);
1438
- this.zoomLayer = this;
1439
- this.moveLayer = this;
1440
- this.config = {
1441
- type: 'design',
1442
- start: true,
1443
- hittable: true,
1444
- smooth: true,
1445
- zoom: {
1446
- min: 0.02,
1447
- max: 256
1448
- },
1449
- move: {
1450
- holdSpaceKey: true,
1451
- dragOut: true,
1452
- autoDistance: 2
1453
- }
1454
- };
1455
- this.__eventIds = [];
1456
- this.__controllers = [];
1457
- this.__readyWait = [];
1458
- this.__viewReadyWait = [];
1459
- this.__viewCompletedWait = [];
1460
- this.__nextRenderWait = [];
1461
- this.userConfig = userConfig;
1462
- if (userConfig && (userConfig.view || userConfig.width))
1463
- this.init(userConfig);
1464
- }
1465
- init(userConfig, parentApp) {
1466
- if (this.canvas)
1467
- return;
1468
- this.__setLeafer(this);
1469
- if (userConfig)
1470
- DataHelper.assign(this.config, userConfig);
1471
- let start;
1472
- const { config } = this;
1473
- LeaferTypeCreator.run(config.type, this);
1474
- this.canvas = Creator.canvas(config);
1475
- this.__controllers.push(this.renderer = Creator.renderer(this, this.canvas, config), this.watcher = Creator.watcher(this, config), this.layouter = Creator.layouter(this, config));
1476
- if (this.isApp)
1477
- this.__setApp();
1478
- this.__checkAutoLayout(config);
1479
- this.view = this.canvas.view;
1480
- if (parentApp) {
1481
- this.__bindApp(parentApp);
1482
- start = parentApp.running;
1483
- }
1484
- else {
1485
- this.selector = Creator.selector(this);
1486
- this.__controllers.unshift(this.interaction = Creator.interaction(this, this.canvas, this.selector, config));
1487
- this.canvasManager = new CanvasManager();
1488
- this.hitCanvasManager = new HitCanvasManager();
1489
- start = config.start;
1490
- }
1491
- this.hittable = config.hittable;
1492
- this.fill = config.fill;
1493
- this.canvasManager.add(this.canvas);
1494
- this.__listenEvents();
1495
- if (start)
1496
- this.__startTimer = setTimeout(this.start.bind(this));
1497
- PluginManager.onLeafer(this);
1498
- }
1499
- set(data) {
1500
- if (!this.children) {
1501
- setTimeout(() => {
1502
- super.set(data);
1503
- });
1504
- }
1505
- else {
1506
- super.set(data);
1507
- }
1508
- }
1509
- start() {
1510
- clearTimeout(this.__startTimer);
1511
- if (!this.running && this.canvas) {
1512
- this.ready ? this.emitLeafer(LeaferEvent.RESTART) : this.emitLeafer(LeaferEvent.START);
1513
- this.__controllers.forEach(item => item.start());
1514
- if (!this.isApp)
1515
- this.renderer.render();
1516
- this.running = true;
1517
- }
1518
- }
1519
- stop() {
1520
- clearTimeout(this.__startTimer);
1521
- if (this.running && this.canvas) {
1522
- this.__controllers.forEach(item => item.stop());
1523
- this.running = false;
1524
- this.emitLeafer(LeaferEvent.STOP);
1525
- }
1526
- }
1527
- resize(size) {
1528
- const data = DataHelper.copyAttrs({}, size, canvasSizeAttrs);
1529
- Object.keys(data).forEach(key => this[key] = data[key]);
1530
- }
1531
- forceLayout() {
1532
- this.__layout.checkUpdate(true);
1533
- }
1534
- forceFullRender() {
1535
- this.renderer.addBlock(this.canvas.bounds);
1536
- if (this.viewReady)
1537
- this.renderer.update();
1538
- }
1539
- updateCursor() {
1540
- if (this.interaction)
1541
- this.interaction.updateCursor();
1542
- }
1543
- __doResize(size) {
1544
- if (!this.canvas || this.canvas.isSameSize(size))
1545
- return;
1546
- const old = DataHelper.copyAttrs({}, this.canvas, canvasSizeAttrs);
1547
- this.canvas.resize(size);
1548
- this.__onResize(new ResizeEvent(size, old));
1549
- }
1550
- __onResize(event) {
1551
- this.emitEvent(event);
1552
- DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
1553
- setTimeout(() => { if (this.canvasManager)
1554
- this.canvasManager.clearRecycled(); }, 0);
1555
- }
1556
- __setApp() { }
1557
- __bindApp(app) {
1558
- this.selector = app.selector;
1559
- this.interaction = app.interaction;
1560
- this.canvasManager = app.canvasManager;
1561
- this.hitCanvasManager = app.hitCanvasManager;
1562
- }
1563
- __setLeafer(leafer) {
1564
- this.leafer = leafer;
1565
- this.isLeafer = !!leafer;
1566
- this.__level = 1;
1567
- }
1568
- setZoomLayer(zoomLayer, moveLayer) {
1569
- this.zoomLayer = zoomLayer;
1570
- this.moveLayer = moveLayer || zoomLayer;
1571
- }
1572
- __checkAutoLayout(config) {
1573
- if (!config.width || !config.height) {
1574
- this.autoLayout = new AutoBounds(config);
1575
- this.canvas.startAutoLayout(this.autoLayout, this.__onResize.bind(this));
1576
- }
1577
- }
1578
- __setAttr(attrName, newValue) {
1579
- if (this.canvas) {
1580
- if (canvasSizeAttrs.includes(attrName)) {
1581
- this.__changeCanvasSize(attrName, newValue);
1582
- }
1583
- else if (attrName === 'fill') {
1584
- this.__changeFill(newValue);
1585
- }
1586
- else if (attrName === 'hittable') {
1587
- this.canvas.hittable = newValue;
1588
- }
1589
- }
1590
- super.__setAttr(attrName, newValue);
1591
- }
1592
- __getAttr(attrName) {
1593
- if (this.canvas && canvasSizeAttrs.includes(attrName))
1594
- return this.canvas[attrName];
1595
- return super.__getAttr(attrName);
1596
- }
1597
- __changeCanvasSize(attrName, newValue) {
1598
- const data = DataHelper.copyAttrs({}, this.canvas, canvasSizeAttrs);
1599
- data[attrName] = this.config[attrName] = newValue;
1600
- if (newValue)
1601
- this.canvas.stopAutoLayout();
1602
- this.__doResize(data);
1603
- }
1604
- __changeFill(newValue) {
1605
- this.config.fill = newValue;
1606
- if (this.canvas.allowBackgroundColor) {
1607
- this.canvas.backgroundColor = newValue;
1608
- }
1609
- else {
1610
- this.forceFullRender();
1611
- }
1612
- }
1613
- __onCreated() {
1614
- this.created = true;
1615
- }
1616
- __onReady() {
1617
- if (this.ready)
1618
- return;
1619
- this.ready = true;
1620
- this.emitLeafer(LeaferEvent.BEFORE_READY);
1621
- this.emitLeafer(LeaferEvent.READY);
1622
- this.emitLeafer(LeaferEvent.AFTER_READY);
1623
- WaitHelper.run(this.__readyWait);
1624
- }
1625
- __onViewReady() {
1626
- if (this.viewReady)
1627
- return;
1628
- this.viewReady = true;
1629
- this.emitLeafer(LeaferEvent.VIEW_READY);
1630
- WaitHelper.run(this.__viewReadyWait);
1631
- }
1632
- __onRenderEnd(_e) {
1633
- if (!this.viewReady)
1634
- this.__onViewReady();
1635
- const completed = this.__checkViewCompleted();
1636
- if (completed)
1637
- this.__onViewCompleted();
1638
- this.viewCompleted = completed;
1639
- WaitHelper.run(this.__nextRenderWait);
1640
- }
1641
- __checkViewCompleted() {
1642
- return this.viewReady && !this.watcher.changed && ImageManager.isComplete;
1643
- }
1644
- __onViewCompleted() {
1645
- if (!this.viewCompleted) {
1646
- this.emitLeafer(LeaferEvent.VIEW_COMPLETED);
1647
- WaitHelper.run(this.__viewCompletedWait);
1648
- }
1649
- }
1650
- __onWatchData() {
1651
- if (this.watcher.childrenChanged && this.interaction) {
1652
- this.nextRender(() => this.interaction.updateCursor());
1653
- }
1654
- }
1655
- waitReady(item) {
1656
- this.ready ? item() : this.__readyWait.push(item);
1657
- }
1658
- waitViewReady(item) {
1659
- this.viewReady ? item() : this.__viewReadyWait.push(item);
1660
- }
1661
- waitViewCompleted(item) {
1662
- if (this.viewCompleted) {
1663
- item();
1664
- }
1665
- else {
1666
- this.__viewCompletedWait.push(item);
1667
- if (!this.running)
1668
- this.start();
1669
- }
1670
- }
1671
- nextRender(item) {
1672
- if (this.watcher && !this.watcher.changed) {
1673
- item();
1674
- }
1675
- else {
1676
- this.__nextRenderWait.push(item);
1677
- }
1678
- }
1679
- __checkUpdateLayout() {
1680
- this.__layout.checkUpdate();
1681
- }
1682
- emitLeafer(type) {
1683
- this.emitEvent(new LeaferEvent(type, this));
1684
- }
1685
- __listenEvents() {
1686
- const runId = Run.start('FirstCreate ' + this.innerName);
1687
- this.once(LeaferEvent.START, () => Run.end(runId));
1688
- this.once(LayoutEvent.END, () => this.__onReady());
1689
- this.once(RenderEvent.START, () => this.__onCreated());
1690
- 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));
1691
- }
1692
- __removeListenEvents() {
1693
- this.off_(this.__eventIds);
1694
- this.__eventIds.length = 0;
1695
- }
1696
- destroy() {
1697
- setTimeout(() => {
1698
- if (!this.destroyed) {
1699
- try {
1700
- this.stop();
1701
- this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
1702
- this.__removeListenEvents();
1703
- this.__controllers.forEach(item => {
1704
- if (!(this.parent && item === this.interaction))
1705
- item.destroy();
1706
- });
1707
- this.__controllers.length = 0;
1708
- if (!this.parent) {
1709
- this.selector.destroy();
1710
- this.canvasManager.destroy();
1711
- this.hitCanvasManager.destroy();
1712
- }
1713
- this.canvas.destroy();
1714
- this.config.view = this.view = null;
1715
- if (this.userConfig)
1716
- this.userConfig.view = null;
1717
- super.destroy();
1718
- setTimeout(() => { ImageManager.clearRecycled(); }, 100);
1719
- }
1720
- catch (e) {
1721
- debug.error(e);
1722
- }
1723
- }
1724
- });
1725
- }
1726
- };
1727
- __decorate([
1728
- dataProcessor(LeaferData)
1729
- ], Leafer.prototype, "__", void 0);
1730
- __decorate([
1731
- boundsType()
1732
- ], Leafer.prototype, "pixelRatio", void 0);
1733
- Leafer = __decorate([
1734
- registerUI()
1735
- ], Leafer);
1736
-
1737
- let App = class App extends Leafer {
1738
- get __tag() { return 'App'; }
1739
- get isApp() { return true; }
1740
- __setApp() {
1741
- const { canvas } = this;
1742
- const { realCanvas, view } = this.config;
1743
- if (realCanvas || view === this.canvas.view || !canvas.parentView) {
1744
- this.realCanvas = true;
1745
- }
1746
- else {
1747
- canvas.unrealCanvas();
1748
- }
1749
- this.leafer = this;
1750
- this.watcher.disable();
1751
- this.layouter.disable();
1752
- this.__eventIds.push(this.on_(PropertyEvent.CHANGE, this.__onPropertyChange, this));
1753
- }
1754
- start() {
1755
- super.start();
1756
- this.children.forEach(leafer => { leafer.start(); });
1757
- }
1758
- stop() {
1759
- this.children.forEach(leafer => { leafer.stop(); });
1760
- super.stop();
1761
- }
1762
- addLeafer(merge) {
1763
- const leafer = new Leafer(merge);
1764
- this.add(leafer);
1765
- return leafer;
1766
- }
1767
- add(leafer) {
1768
- if (!leafer.view) {
1769
- if (this.realCanvas && !this.canvas.bounds) {
1770
- setTimeout(() => this.add(leafer), 10);
1771
- return;
1772
- }
1773
- leafer.init(this.__getChildConfig(leafer.userConfig), this);
1774
- }
1775
- super.add(leafer);
1776
- this.__listenChildEvents(leafer);
1777
- }
1778
- __onPropertyChange() {
1779
- if (Debug.showHitView)
1780
- this.children.forEach(leafer => { leafer.forceUpdate('surface'); });
1781
- }
1782
- __onCreated() {
1783
- this.created = this.children.every(child => child.created);
1784
- }
1785
- __onReady() {
1786
- if (this.children.every(child => child.ready))
1787
- super.__onReady();
1788
- }
1789
- __onViewReady() {
1790
- if (this.children.every(child => child.viewReady))
1791
- super.__onViewReady();
1792
- }
1793
- __checkViewCompleted() {
1794
- return this.children.every(item => item.viewCompleted);
1795
- }
1796
- __onChildRenderEnd(e) {
1797
- this.renderer.addBlock(e.renderBounds);
1798
- if (this.viewReady)
1799
- this.renderer.update();
1800
- }
1801
- __render(canvas, _options) {
1802
- this.children.forEach(leafer => { canvas.copyWorld(leafer.canvas); });
1803
- }
1804
- __onResize(event) {
1805
- this.children.forEach(leafer => { leafer.resize(event); });
1806
- super.__onResize(event);
1807
- }
1808
- __checkUpdateLayout() {
1809
- this.children.forEach(leafer => { leafer.__layout.checkUpdate(); });
1810
- }
1811
- __getChildConfig(userConfig) {
1812
- let config = Object.assign({}, this.config);
1813
- config.hittable = config.realCanvas = undefined;
1814
- if (userConfig)
1815
- DataHelper.assign(config, userConfig);
1816
- if (this.autoLayout)
1817
- DataHelper.copyAttrs(config, this, canvasSizeAttrs);
1818
- config.view = this.realCanvas ? undefined : this.view;
1819
- config.fill = undefined;
1820
- return config;
1821
- }
1822
- __listenChildEvents(leafer) {
1823
- leafer.once(LayoutEvent.END, () => this.__onReady());
1824
- leafer.once(RenderEvent.START, () => this.__onCreated());
1825
- leafer.once(RenderEvent.END, (e) => this.__onRenderEnd(e));
1826
- if (this.realCanvas)
1827
- this.__eventIds.push(leafer.on_(RenderEvent.END, this.__onChildRenderEnd, this));
1828
- }
1829
- };
1830
- App = __decorate([
1831
- registerUI()
1832
- ], App);
1833
-
1834
- 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 };