@leafer-ui/display 1.0.0-beta.9 → 1.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -9
- package/src/Arrow.ts +27 -0
- package/src/Box.ts +13 -6
- package/src/Canvas.ts +10 -11
- package/src/Ellipse.ts +10 -7
- package/src/Frame.ts +8 -6
- package/src/Group.ts +58 -18
- package/src/Image.ts +7 -27
- package/src/Leafer.ts +417 -0
- package/src/Line.ts +38 -22
- package/src/Path.ts +2 -2
- package/src/Pen.ts +7 -5
- package/src/Polygon.ts +35 -12
- package/src/Rect.ts +7 -11
- package/src/Star.ts +7 -7
- package/src/Text.ts +65 -28
- package/src/UI.ts +166 -57
- package/src/index.ts +1 -0
- package/types/index.d.ts +368 -0
package/src/Star.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INumber } from '@leafer/interface'
|
|
2
2
|
import { PathCommandDataHelper, dataProcessor, pathType, registerUI } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { IStar, IStarData, IStarInputData } from '@leafer-ui/interface'
|
|
@@ -17,13 +17,13 @@ export class Star extends UI implements IStar {
|
|
|
17
17
|
public get __tag() { return 'Star' }
|
|
18
18
|
|
|
19
19
|
@dataProcessor(StarData)
|
|
20
|
-
public __: IStarData
|
|
20
|
+
declare public __: IStarData
|
|
21
21
|
|
|
22
22
|
@pathType(5)
|
|
23
|
-
public
|
|
23
|
+
public corners: INumber
|
|
24
24
|
|
|
25
25
|
@pathType(0.382)
|
|
26
|
-
public innerRadius:
|
|
26
|
+
public innerRadius: INumber
|
|
27
27
|
|
|
28
28
|
constructor(data?: IStarInputData) {
|
|
29
29
|
super(data)
|
|
@@ -31,14 +31,14 @@ export class Star extends UI implements IStar {
|
|
|
31
31
|
|
|
32
32
|
public __updatePath() {
|
|
33
33
|
|
|
34
|
-
const { width, height,
|
|
34
|
+
const { width, height, corners, innerRadius } = this.__
|
|
35
35
|
const rx = width / 2, ry = height / 2
|
|
36
36
|
|
|
37
37
|
const path: number[] = this.__.path = []
|
|
38
38
|
moveTo(path, rx, 0)
|
|
39
39
|
|
|
40
|
-
for (let i = 1; i <
|
|
41
|
-
lineTo(path, rx + (i % 2 === 0 ? rx : rx * innerRadius) * sin((i * PI) /
|
|
40
|
+
for (let i = 1; i < corners * 2; i++) {
|
|
41
|
+
lineTo(path, rx + (i % 2 === 0 ? rx : rx * innerRadius) * sin((i * PI) / corners), ry - (i % 2 === 0 ? ry : ry * innerRadius) * cos((i * PI) / corners))
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
closePath(path)
|
package/src/Text.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { ILeaferCanvas, IPathDrawer, IPathCommandData,
|
|
2
|
-
import { BoundsHelper, boundsType, dataProcessor, registerUI, affectStrokeBoundsType } from '@leafer/core'
|
|
1
|
+
import { ILeaferCanvas, IPathDrawer, IPathCommandData, IBoolean, INumber, IString, IBoundsData } from '@leafer/interface'
|
|
2
|
+
import { BoundsHelper, boundsType, surfaceType, dataProcessor, registerUI, affectStrokeBoundsType, hitType, MathHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
|
-
import { IText, IFontWeight, ITextCase, ITextDecoration, ITextData, ITextInputData, ITextAlign, IVerticalAlign, ITextDrawData, IOverflow, IUnitData, IStrokeAlign } from '@leafer-ui/interface'
|
|
4
|
+
import { IFill, IText, IFontWeight, ITextCase, ITextDecoration, ITextData, ITextInputData, ITextAlign, IVerticalAlign, ITextDrawData, IOverflow, IUnitData, IStrokeAlign, IHitType, ITextWrap } from '@leafer-ui/interface'
|
|
5
5
|
import { TextData, UnitConvert } from '@leafer-ui/data'
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
import { TextConvert } from '@leafer-ui/external'
|
|
7
8
|
|
|
8
9
|
import { UI } from './UI'
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
const { copyAndSpread, includes, spread } = BoundsHelper
|
|
12
|
+
const { copyAndSpread, includes, spread, setList } = BoundsHelper
|
|
12
13
|
|
|
13
14
|
@registerUI()
|
|
14
15
|
export class Text extends UI implements IText {
|
|
@@ -16,35 +17,41 @@ export class Text extends UI implements IText {
|
|
|
16
17
|
public get __tag() { return 'Text' }
|
|
17
18
|
|
|
18
19
|
@dataProcessor(TextData)
|
|
19
|
-
public __: ITextData
|
|
20
|
+
declare public __: ITextData
|
|
20
21
|
|
|
21
22
|
// size
|
|
22
23
|
@boundsType(0)
|
|
23
|
-
public width:
|
|
24
|
+
declare public width: INumber
|
|
24
25
|
|
|
25
26
|
@boundsType(0)
|
|
26
|
-
public height:
|
|
27
|
+
declare public height: INumber
|
|
27
28
|
|
|
28
29
|
@boundsType(0)
|
|
29
30
|
public padding: number | number[]
|
|
30
31
|
|
|
32
|
+
@surfaceType('#000000')
|
|
33
|
+
declare public fill: IFill
|
|
34
|
+
|
|
31
35
|
@affectStrokeBoundsType('outside')
|
|
32
|
-
public strokeAlign: IStrokeAlign
|
|
36
|
+
declare public strokeAlign: IStrokeAlign
|
|
37
|
+
|
|
38
|
+
@hitType('all')
|
|
39
|
+
declare public hitFill: IHitType
|
|
33
40
|
|
|
34
41
|
@boundsType('')
|
|
35
|
-
public text:
|
|
42
|
+
public text: IString
|
|
36
43
|
|
|
37
44
|
@boundsType('L')
|
|
38
|
-
public fontFamily:
|
|
45
|
+
public fontFamily: IString
|
|
39
46
|
|
|
40
47
|
@boundsType(12)
|
|
41
|
-
public fontSize:
|
|
48
|
+
public fontSize: INumber
|
|
42
49
|
|
|
43
50
|
@boundsType('normal')
|
|
44
51
|
public fontWeight: IFontWeight
|
|
45
52
|
|
|
46
53
|
@boundsType(false)
|
|
47
|
-
public italic:
|
|
54
|
+
public italic: IBoolean
|
|
48
55
|
|
|
49
56
|
@boundsType('none')
|
|
50
57
|
public textCase: ITextCase
|
|
@@ -53,16 +60,16 @@ export class Text extends UI implements IText {
|
|
|
53
60
|
public textDecoration: ITextDecoration
|
|
54
61
|
|
|
55
62
|
@boundsType(0)
|
|
56
|
-
public letterSpacing:
|
|
63
|
+
public letterSpacing: INumber | IUnitData
|
|
57
64
|
|
|
58
65
|
@boundsType({ type: 'percent', value: 150 } as IUnitData)
|
|
59
|
-
public lineHeight:
|
|
66
|
+
public lineHeight: INumber | IUnitData
|
|
60
67
|
|
|
61
68
|
@boundsType(0)
|
|
62
|
-
public paraIndent:
|
|
69
|
+
public paraIndent: INumber
|
|
63
70
|
|
|
64
71
|
@boundsType(0)
|
|
65
|
-
public paraSpacing:
|
|
72
|
+
public paraSpacing: INumber
|
|
66
73
|
|
|
67
74
|
@boundsType('left')
|
|
68
75
|
public textAlign: ITextAlign
|
|
@@ -70,11 +77,14 @@ export class Text extends UI implements IText {
|
|
|
70
77
|
@boundsType('top')
|
|
71
78
|
public verticalAlign: IVerticalAlign
|
|
72
79
|
|
|
80
|
+
@boundsType('normal')
|
|
81
|
+
public textWrap: ITextWrap
|
|
82
|
+
|
|
73
83
|
@boundsType('show')
|
|
74
84
|
public textOverflow: IOverflow | string
|
|
75
85
|
|
|
76
86
|
public get textDrawData(): ITextDrawData {
|
|
77
|
-
this.__layout.
|
|
87
|
+
this.__layout.update()
|
|
78
88
|
return this.__.__textDrawData
|
|
79
89
|
}
|
|
80
90
|
|
|
@@ -84,11 +94,17 @@ export class Text extends UI implements IText {
|
|
|
84
94
|
|
|
85
95
|
public __drawHitPath(canvas: ILeaferCanvas): void {
|
|
86
96
|
const { __lineHeight, __baseLine, __textDrawData: data } = this.__
|
|
97
|
+
|
|
87
98
|
canvas.beginPath()
|
|
88
|
-
|
|
99
|
+
|
|
100
|
+
if (this.__.__letterSpacing < 0) {
|
|
101
|
+
this.__drawPathByData(canvas)
|
|
102
|
+
} else {
|
|
103
|
+
data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight))
|
|
104
|
+
}
|
|
89
105
|
}
|
|
90
106
|
|
|
91
|
-
public __drawPathByData(drawer: IPathDrawer, _data
|
|
107
|
+
public __drawPathByData(drawer: IPathDrawer, _data?: IPathCommandData): void {
|
|
92
108
|
const { x, y, width, height } = this.__layout.boxBounds
|
|
93
109
|
drawer.rect(x, y, width, height)
|
|
94
110
|
}
|
|
@@ -107,14 +123,19 @@ export class Text extends UI implements IText {
|
|
|
107
123
|
|
|
108
124
|
const data = this.__
|
|
109
125
|
const layout = this.__layout
|
|
110
|
-
const {
|
|
126
|
+
const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data
|
|
127
|
+
|
|
128
|
+
const autoWidth = data.__autoWidth
|
|
129
|
+
const autoHeight = data.__autoHeight
|
|
111
130
|
|
|
112
131
|
// compute
|
|
113
132
|
|
|
114
133
|
data.__lineHeight = UnitConvert.number(lineHeight, fontSize)
|
|
115
134
|
data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize)
|
|
135
|
+
data.__padding = padding ? MathHelper.fourNumber(padding) : undefined
|
|
116
136
|
data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2
|
|
117
137
|
data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`
|
|
138
|
+
data.__clipText = textOverflow !== 'show' && !data.__autoBounds
|
|
118
139
|
|
|
119
140
|
this.__updateTextDrawData()
|
|
120
141
|
|
|
@@ -123,19 +144,35 @@ export class Text extends UI implements IText {
|
|
|
123
144
|
|
|
124
145
|
if (data.__lineHeight < fontSize) spread(bounds, fontSize / 2)
|
|
125
146
|
|
|
126
|
-
if (
|
|
127
|
-
|
|
147
|
+
if (autoWidth || autoHeight) {
|
|
148
|
+
b.x = autoWidth ? bounds.x : 0
|
|
149
|
+
b.y = autoHeight ? bounds.y : 0
|
|
150
|
+
b.width = autoWidth ? bounds.width : data.width
|
|
151
|
+
b.height = autoHeight ? bounds.height : data.height
|
|
152
|
+
|
|
153
|
+
if (padding) {
|
|
154
|
+
const [top, right, bottom, left] = data.__padding
|
|
155
|
+
if (autoWidth) {
|
|
156
|
+
b.x -= left
|
|
157
|
+
b.width += (right + left)
|
|
158
|
+
}
|
|
159
|
+
if (autoHeight) {
|
|
160
|
+
b.y -= top
|
|
161
|
+
b.height += (bottom + top)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
this.__updateNaturalSize()
|
|
128
165
|
} else {
|
|
129
|
-
|
|
130
|
-
b.y = height ? 0 : bounds.y
|
|
131
|
-
b.width = width ? width : bounds.width
|
|
132
|
-
b.height = height ? height : bounds.height
|
|
166
|
+
super.__updateBoxBounds()
|
|
133
167
|
}
|
|
134
168
|
|
|
135
169
|
const contentBounds = includes(b, bounds) ? b : bounds
|
|
136
170
|
if (contentBounds !== layout.contentBounds) {
|
|
137
171
|
layout.contentBounds = contentBounds
|
|
138
172
|
layout.renderChanged = true
|
|
173
|
+
setList(data.__textBoxBounds = {} as IBoundsData, [b, bounds])
|
|
174
|
+
} else {
|
|
175
|
+
data.__textBoxBounds = contentBounds
|
|
139
176
|
}
|
|
140
177
|
|
|
141
178
|
}
|
|
@@ -147,7 +184,7 @@ export class Text extends UI implements IText {
|
|
|
147
184
|
}
|
|
148
185
|
|
|
149
186
|
public __updateRenderBounds(): void {
|
|
150
|
-
copyAndSpread(this.__layout.renderBounds, this.
|
|
187
|
+
copyAndSpread(this.__layout.renderBounds, this.__.__textBoxBounds, this.__layout.renderSpread)
|
|
151
188
|
}
|
|
152
189
|
|
|
153
190
|
}
|
package/src/UI.ts
CHANGED
|
@@ -1,37 +1,46 @@
|
|
|
1
|
-
import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType,
|
|
2
|
-
import { Leaf, PathDrawer, surfaceType, dataType, positionType, boundsType, pathType, scaleType, rotationType, opacityType, sortType, maskType, dataProcessor, useModule, rewrite, rewriteAble, UICreator, PathCorner, hitType, strokeType, PathConvert, eraserType } from '@leafer/core'
|
|
1
|
+
import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType, INumber, IBoolean, IString, IPathString, IExportFileType, IPointData, ICursorType, IMaskType, IAround } from '@leafer/interface'
|
|
2
|
+
import { Leaf, PathDrawer, surfaceType, dataType, positionType, boundsType, pathType, scaleType, rotationType, opacityType, sortType, maskType, dataProcessor, useModule, rewrite, rewriteAble, UICreator, PathCorner, hitType, strokeType, PathConvert, eraserType, cursorType, autoLayoutType, PathCreator } from '@leafer/core'
|
|
3
3
|
|
|
4
|
-
import { IUI, IShadowEffect, IBlurEffect,
|
|
4
|
+
import { IUI, IShadowEffect, IBlurEffect, IStrokeAlign, IStrokeJoin, IStrokeCap, IBlendMode, IDashPatternString, IShadowString, IGrayscaleEffect, IUIData, IGroup, IStrokeWidthString, ICornerRadiusString, IUIInputData, IExportOptions, IExportResult, IFill, IStroke, IArrowType, IFindUIMethod, IEditSize, ILeafer } from '@leafer-ui/interface'
|
|
5
5
|
import { effectType } from '@leafer-ui/decorator'
|
|
6
6
|
|
|
7
7
|
import { UIData } from '@leafer-ui/data'
|
|
8
|
-
import { UIBounds,
|
|
8
|
+
import { UIBounds, UIRender } from '@leafer-ui/display-module'
|
|
9
9
|
|
|
10
|
-
import { Export
|
|
10
|
+
import { Export } from '@leafer-ui/external'
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
@useModule(UIBounds)
|
|
14
|
-
@useModule(UIHit)
|
|
15
14
|
@useModule(UIRender)
|
|
16
15
|
@rewriteAble()
|
|
17
16
|
export class UI extends Leaf implements IUI {
|
|
18
17
|
|
|
19
18
|
@dataProcessor(UIData)
|
|
20
|
-
public __: IUIData
|
|
19
|
+
declare public __: IUIData
|
|
21
20
|
|
|
22
|
-
public
|
|
21
|
+
declare public proxyData: IUIInputData // need rewrite getter
|
|
22
|
+
declare public __proxyData?: IUIInputData
|
|
23
|
+
|
|
24
|
+
public get app(): ILeafer { return this.leafer && this.leafer.app }
|
|
25
|
+
|
|
26
|
+
declare public leafer?: ILeafer
|
|
27
|
+
declare public parent?: IGroup
|
|
28
|
+
|
|
29
|
+
public isFrame?: boolean
|
|
30
|
+
|
|
31
|
+
declare public children?: IUI[]
|
|
23
32
|
|
|
24
33
|
// ---
|
|
25
34
|
|
|
26
35
|
// id
|
|
27
36
|
@dataType('')
|
|
28
|
-
public id:
|
|
37
|
+
public id: IString
|
|
29
38
|
|
|
30
39
|
@dataType('')
|
|
31
|
-
public name:
|
|
40
|
+
public name: IString
|
|
32
41
|
|
|
33
42
|
@dataType('')
|
|
34
|
-
public className:
|
|
43
|
+
public className: IString
|
|
35
44
|
|
|
36
45
|
|
|
37
46
|
// layer
|
|
@@ -39,63 +48,79 @@ export class UI extends Leaf implements IUI {
|
|
|
39
48
|
public blendMode: IBlendMode
|
|
40
49
|
|
|
41
50
|
@opacityType(1)
|
|
42
|
-
public opacity:
|
|
51
|
+
public opacity: INumber
|
|
43
52
|
|
|
44
53
|
@opacityType(true)
|
|
45
|
-
public visible:
|
|
54
|
+
public visible: IBoolean
|
|
46
55
|
|
|
47
|
-
@
|
|
48
|
-
public
|
|
49
|
-
|
|
50
|
-
@eraserType(false)
|
|
51
|
-
public isEraser?: __Boolean
|
|
56
|
+
@dataType(false)
|
|
57
|
+
public locked: IBoolean
|
|
52
58
|
|
|
53
59
|
@sortType(0)
|
|
54
|
-
public zIndex:
|
|
60
|
+
public zIndex: INumber
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
|
|
63
|
+
@maskType(false)
|
|
64
|
+
public mask: IBoolean
|
|
65
|
+
|
|
66
|
+
@surfaceType('pixel')
|
|
67
|
+
public maskType: IMaskType
|
|
68
|
+
|
|
69
|
+
@eraserType(false)
|
|
70
|
+
public eraser: IBoolean
|
|
58
71
|
|
|
59
72
|
|
|
60
73
|
// position
|
|
61
74
|
@positionType(0)
|
|
62
|
-
public x:
|
|
75
|
+
public x: INumber
|
|
63
76
|
|
|
64
77
|
@positionType(0)
|
|
65
|
-
public y:
|
|
78
|
+
public y: INumber
|
|
66
79
|
|
|
67
80
|
// size
|
|
68
81
|
@boundsType(100)
|
|
69
|
-
public width:
|
|
82
|
+
public width: INumber
|
|
70
83
|
|
|
71
84
|
@boundsType(100)
|
|
72
|
-
public height:
|
|
85
|
+
public height: INumber
|
|
73
86
|
|
|
74
87
|
// scale
|
|
75
88
|
@scaleType(1)
|
|
76
|
-
public scaleX:
|
|
89
|
+
public scaleX: INumber
|
|
77
90
|
|
|
78
91
|
@scaleType(1)
|
|
79
|
-
public scaleY:
|
|
92
|
+
public scaleY: INumber
|
|
80
93
|
|
|
81
94
|
// rotate
|
|
82
95
|
@rotationType(0)
|
|
83
|
-
public rotation:
|
|
96
|
+
public rotation: INumber
|
|
84
97
|
|
|
85
98
|
// skew
|
|
86
99
|
@rotationType(0)
|
|
87
|
-
public skewX:
|
|
100
|
+
public skewX: INumber
|
|
88
101
|
|
|
89
102
|
@rotationType(0)
|
|
90
|
-
public skewY:
|
|
103
|
+
public skewY: INumber
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@autoLayoutType()
|
|
107
|
+
public around: IAround
|
|
91
108
|
|
|
92
109
|
|
|
93
110
|
@dataType(false)
|
|
94
|
-
public draggable:
|
|
111
|
+
public draggable: IBoolean
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@dataType(false)
|
|
115
|
+
public editable: IBoolean
|
|
116
|
+
|
|
117
|
+
@dataType('size')
|
|
118
|
+
public editSize?: IEditSize
|
|
119
|
+
|
|
95
120
|
|
|
96
121
|
// hit
|
|
97
122
|
@hitType(true)
|
|
98
|
-
public hittable:
|
|
123
|
+
public hittable: IBoolean
|
|
99
124
|
|
|
100
125
|
@hitType('path')
|
|
101
126
|
public hitFill: IHitType
|
|
@@ -103,11 +128,20 @@ export class UI extends Leaf implements IUI {
|
|
|
103
128
|
@strokeType('path')
|
|
104
129
|
public hitStroke: IHitType
|
|
105
130
|
|
|
131
|
+
@hitType(false)
|
|
132
|
+
public hitBox: IBoolean
|
|
133
|
+
|
|
106
134
|
@hitType(true)
|
|
107
|
-
public hitChildren:
|
|
135
|
+
public hitChildren: IBoolean
|
|
108
136
|
|
|
109
137
|
@hitType(true)
|
|
110
|
-
public hitSelf:
|
|
138
|
+
public hitSelf: IBoolean
|
|
139
|
+
|
|
140
|
+
@hitType()
|
|
141
|
+
public hitRadius: INumber
|
|
142
|
+
|
|
143
|
+
@cursorType('')
|
|
144
|
+
public cursor: ICursorType | ICursorType[]
|
|
111
145
|
|
|
112
146
|
// ---
|
|
113
147
|
|
|
@@ -115,18 +149,21 @@ export class UI extends Leaf implements IUI {
|
|
|
115
149
|
// fill
|
|
116
150
|
|
|
117
151
|
@surfaceType()
|
|
118
|
-
public fill:
|
|
152
|
+
public fill: IFill
|
|
119
153
|
|
|
120
154
|
// stroke
|
|
121
155
|
|
|
122
156
|
@strokeType()
|
|
123
|
-
public stroke:
|
|
157
|
+
public stroke: IStroke
|
|
124
158
|
|
|
125
159
|
@strokeType('inside')
|
|
126
160
|
public strokeAlign: IStrokeAlign
|
|
127
161
|
|
|
128
162
|
@strokeType(1)
|
|
129
|
-
public strokeWidth:
|
|
163
|
+
public strokeWidth: INumber | INumber[] | IStrokeWidthString
|
|
164
|
+
|
|
165
|
+
@strokeType(false)
|
|
166
|
+
public strokeWidthFixed: IBoolean
|
|
130
167
|
|
|
131
168
|
@strokeType('none')
|
|
132
169
|
public strokeCap: IStrokeCap
|
|
@@ -135,22 +172,34 @@ export class UI extends Leaf implements IUI {
|
|
|
135
172
|
public strokeJoin: IStrokeJoin
|
|
136
173
|
|
|
137
174
|
@strokeType()
|
|
138
|
-
public dashPattern:
|
|
175
|
+
public dashPattern: INumber[] | IDashPatternString
|
|
139
176
|
|
|
140
177
|
@strokeType()
|
|
141
|
-
public dashOffset:
|
|
178
|
+
public dashOffset: INumber
|
|
142
179
|
|
|
143
180
|
@strokeType(10)
|
|
144
|
-
public miterLimit:
|
|
181
|
+
public miterLimit: INumber
|
|
182
|
+
|
|
183
|
+
// load
|
|
184
|
+
|
|
185
|
+
@dataType(false)
|
|
186
|
+
public lazy: IBoolean // load image / compute paint
|
|
187
|
+
|
|
188
|
+
// arrow
|
|
189
|
+
|
|
190
|
+
@strokeType('none')
|
|
191
|
+
public startArrow: IArrowType
|
|
145
192
|
|
|
193
|
+
@strokeType('none')
|
|
194
|
+
public endArrow: IArrowType
|
|
146
195
|
|
|
147
196
|
// corner
|
|
148
197
|
|
|
149
|
-
@pathType()
|
|
198
|
+
@pathType(0)
|
|
150
199
|
public cornerRadius: number | number[] | ICornerRadiusString
|
|
151
200
|
|
|
152
201
|
@pathType()
|
|
153
|
-
public cornerSmoothing:
|
|
202
|
+
public cornerSmoothing: INumber
|
|
154
203
|
|
|
155
204
|
// effect
|
|
156
205
|
|
|
@@ -161,13 +210,28 @@ export class UI extends Leaf implements IUI {
|
|
|
161
210
|
public innerShadow: IShadowEffect | IShadowEffect[] | IShadowString
|
|
162
211
|
|
|
163
212
|
@effectType()
|
|
164
|
-
public blur:
|
|
213
|
+
public blur: INumber | IBlurEffect
|
|
165
214
|
|
|
166
215
|
@effectType()
|
|
167
|
-
public backgroundBlur:
|
|
216
|
+
public backgroundBlur: INumber | IBlurEffect
|
|
168
217
|
|
|
169
218
|
@effectType()
|
|
170
|
-
public grayscale:
|
|
219
|
+
public grayscale: INumber | IGrayscaleEffect
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
public set scale(value: INumber | IPointData) {
|
|
223
|
+
if (typeof value === 'number') {
|
|
224
|
+
this.scaleX = this.scaleY = value
|
|
225
|
+
} else {
|
|
226
|
+
this.scaleX = value.x
|
|
227
|
+
this.scaleY = value.y
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public get scale(): INumber | IPointData {
|
|
232
|
+
const { scaleX, scaleY } = this
|
|
233
|
+
return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX
|
|
234
|
+
}
|
|
171
235
|
|
|
172
236
|
|
|
173
237
|
constructor(data?: IUIInputData) {
|
|
@@ -175,37 +239,60 @@ export class UI extends Leaf implements IUI {
|
|
|
175
239
|
}
|
|
176
240
|
|
|
177
241
|
|
|
178
|
-
|
|
242
|
+
// data
|
|
243
|
+
|
|
244
|
+
@rewrite(Leaf.prototype.reset)
|
|
245
|
+
public reset(_data?: IUIInputData): void { }
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
public set(data: IUIInputData): void {
|
|
179
249
|
Object.assign(this, data)
|
|
180
250
|
}
|
|
181
251
|
|
|
182
|
-
public get():
|
|
252
|
+
public get(): IUIInputData {
|
|
183
253
|
return this.__.__getInputData()
|
|
184
254
|
}
|
|
185
255
|
|
|
256
|
+
public createProxyData(): IUIInputData { return undefined }
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
// hit rewrite
|
|
260
|
+
|
|
261
|
+
public find(_condition: number | string | IFindUIMethod, _options?: any): IUI[] { return undefined }
|
|
186
262
|
|
|
187
|
-
public
|
|
188
|
-
|
|
189
|
-
|
|
263
|
+
public findOne(_condition: number | string | IFindUIMethod, _options?: any): IUI { return undefined }
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
// path
|
|
267
|
+
|
|
268
|
+
public getPath(curve?: boolean, pathForRender?: boolean): IPathCommandData {
|
|
269
|
+
this.__layout.update()
|
|
270
|
+
let path = pathForRender ? this.__.__pathForRender : this.__.path
|
|
271
|
+
if (!path) {
|
|
272
|
+
path = []
|
|
273
|
+
const { width, height } = this.boxBounds
|
|
274
|
+
if (width || height) this.__drawPathByBox(new PathCreator(path))
|
|
275
|
+
}
|
|
190
276
|
return curve ? PathConvert.toCanvasData(path, true) : path
|
|
191
277
|
}
|
|
192
278
|
|
|
193
|
-
public getPathString(curve?: boolean): IPathString {
|
|
194
|
-
return PathConvert.stringify(this.getPath(curve))
|
|
279
|
+
public getPathString(curve?: boolean, pathForRender?: boolean): IPathString {
|
|
280
|
+
return PathConvert.stringify(this.getPath(curve, pathForRender))
|
|
195
281
|
}
|
|
196
282
|
|
|
197
283
|
|
|
198
284
|
public __onUpdateSize(): void {
|
|
199
285
|
if (this.__.__input) {
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
if (
|
|
286
|
+
const data = this.__
|
|
287
|
+
data.__needComputePaint = true
|
|
288
|
+
if (data.lazy && this.leafer && !this.leafer.canvas.bounds.hit(this.__world)) return
|
|
289
|
+
data.__computePaint()
|
|
203
290
|
}
|
|
204
291
|
}
|
|
205
292
|
|
|
206
293
|
public __updateRenderPath(): void {
|
|
207
294
|
if (this.__.path) {
|
|
208
|
-
const
|
|
295
|
+
const data = this.__
|
|
209
296
|
data.__pathForRender = data.cornerRadius ? PathCorner.smooth(data.path, data.cornerRadius, data.cornerSmoothing) : data.path
|
|
210
297
|
}
|
|
211
298
|
}
|
|
@@ -223,12 +310,34 @@ export class UI extends Leaf implements IUI {
|
|
|
223
310
|
@rewrite(PathDrawer.drawPathByData)
|
|
224
311
|
public __drawPathByData(_drawer: IPathDrawer, _data: IPathCommandData): void { }
|
|
225
312
|
|
|
313
|
+
public __drawPathByBox(drawer: IPathDrawer): void {
|
|
314
|
+
const { x, y, width, height } = this.__layout.boxBounds
|
|
315
|
+
if (this.__.cornerRadius) {
|
|
316
|
+
drawer.roundRect(x, y, width, height, this.__.cornerRadius)
|
|
317
|
+
} else {
|
|
318
|
+
drawer.rect(x, y, width, height)
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
// create
|
|
324
|
+
|
|
226
325
|
public export(filename: IExportFileType | string, options?: IExportOptions | number | boolean): Promise<IExportResult> {
|
|
227
326
|
return Export.export(this, filename, options)
|
|
228
327
|
}
|
|
229
328
|
|
|
230
|
-
|
|
329
|
+
public clone(): IUI {
|
|
330
|
+
return UI.one(this.toJSON())
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
static one(data: IUIInputData, x?: number, y?: number, width?: number, height?: number): IUI {
|
|
231
334
|
return UICreator.get(data.tag || this.prototype.__tag, data, x, y, width, height) as IUI
|
|
232
335
|
}
|
|
233
336
|
|
|
337
|
+
|
|
338
|
+
public destroy(): void {
|
|
339
|
+
this.fill = this.stroke = null
|
|
340
|
+
super.destroy()
|
|
341
|
+
}
|
|
342
|
+
|
|
234
343
|
}
|