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