@leafer-ui/display 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/src/Polygon.ts CHANGED
@@ -1,16 +1,18 @@
1
- import { __Number } from '@leafer/interface'
2
- import { PathBounds, PathCommandDataHelper, dataProcessor, pathType, registerUI } from '@leafer/core'
1
+ import { INumber } from '@leafer/interface'
2
+ import { PathCommandDataHelper, dataProcessor, pathType, registerUI, rewrite, rewriteAble } from '@leafer/core'
3
3
 
4
4
  import { IPolygon, IPolygonData, IPolygonInputData } from '@leafer-ui/interface'
5
5
  import { PolygonData } from '@leafer-ui/data'
6
6
 
7
7
  import { UI } from './UI'
8
+ import { Line } from './Line'
8
9
 
9
10
 
10
11
  const { sin, cos, PI } = Math
11
12
  const { moveTo, lineTo, closePath, drawPoints } = PathCommandDataHelper
12
- const { toBounds } = PathBounds
13
+ const line = Line.prototype
13
14
 
15
+ @rewriteAble()
14
16
  @registerUI()
15
17
  export class Polygon extends UI implements IPolygon {
16
18
 
@@ -20,15 +22,13 @@ export class Polygon extends UI implements IPolygon {
20
22
  declare public __: IPolygonData
21
23
 
22
24
  @pathType(3)
23
- sides: number
25
+ public sides?: INumber
24
26
 
25
27
  @pathType()
26
- points: number[]
28
+ public points?: number[]
27
29
 
28
30
  @pathType(0)
29
- curve: boolean | number
30
-
31
- public get resizeable(): boolean { return !this.points }
31
+ public curve?: boolean | number
32
32
 
33
33
  constructor(data?: IPolygonInputData) {
34
34
  super(data)
@@ -58,22 +58,10 @@ export class Polygon extends UI implements IPolygon {
58
58
  closePath(path)
59
59
  }
60
60
 
61
+ @rewrite(line.__updateRenderPath)
62
+ public __updateRenderPath(): void { }
61
63
 
62
- public __updateRenderPath(): void {
63
- if (this.__.points && this.__.curve) {
64
- drawPoints(this.__.__pathForRender = [], this.__.points, this.__.curve, true)
65
- } else {
66
- super.__updateRenderPath()
67
- }
68
- }
69
-
70
- public __updateBoxBounds(): void {
71
- if (this.__.points) {
72
- toBounds(this.__.__pathForRender, this.__layout.boxBounds)
73
- this.__updateNaturalSize()
74
- } else {
75
- super.__updateBoxBounds()
76
- }
77
- }
64
+ @rewrite(line.__updateBoxBounds)
65
+ public __updateBoxBounds(): void { }
78
66
 
79
67
  }
package/src/Rect.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { IPathDrawer, IPathCommandData, __Number } from '@leafer/interface'
2
- import { dataProcessor, registerUI, useModule } from '@leafer/core'
1
+ import { dataProcessor, registerUI, rewriteAble, useModule } from '@leafer/core'
3
2
 
4
3
  import { IRect, IRectInputData, IRectData } from '@leafer-ui/interface'
5
4
  import { RectData } from '@leafer-ui/data'
@@ -9,8 +8,9 @@ import { UI } from './UI'
9
8
 
10
9
 
11
10
  @useModule(RectRender)
11
+ @rewriteAble()
12
12
  @registerUI()
13
- export class Rect extends UI implements IRect {
13
+ export class Rect extends UI implements IRect { // tip: rewrited Box
14
14
 
15
15
  public get __tag() { return 'Rect' }
16
16
 
@@ -21,12 +21,4 @@ export class Rect extends UI implements IRect {
21
21
  super(data)
22
22
  }
23
23
 
24
- public __drawPathByData(drawer: IPathDrawer, _data: IPathCommandData): void {
25
- const { width, height, cornerRadius } = this.__
26
- if (cornerRadius) {
27
- drawer.roundRect(0, 0, width, height, cornerRadius)
28
- } else {
29
- drawer.rect(0, 0, width, height)
30
- }
31
- }
32
24
  }
package/src/Star.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { __Number } from '@leafer/interface'
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'
@@ -20,10 +20,10 @@ export class Star extends UI implements IStar {
20
20
  declare public __: IStarData
21
21
 
22
22
  @pathType(5)
23
- public corners: __Number
23
+ public corners?: INumber
24
24
 
25
25
  @pathType(0.382)
26
- public innerRadius: __Number
26
+ public innerRadius?: INumber
27
27
 
28
28
  constructor(data?: IStarInputData) {
29
29
  super(data)
package/src/Text.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { ILeaferCanvas, IPathDrawer, IPathCommandData, __Boolean, __Number, __String } from '@leafer/interface'
2
- import { BoundsHelper, boundsType, dataProcessor, registerUI, affectStrokeBoundsType } from '@leafer/core'
1
+ import { ILeaferCanvas, IPathDrawer, IPathCommandData, IBoolean, INumber, IString, IBoundsData, IUnitData } from '@leafer/interface'
2
+ import { BoundsHelper, boundsType, surfaceType, dataProcessor, registerUI, affectStrokeBoundsType, dataType, 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, IStrokeAlign, IHitType, ITextWrap } from '@leafer-ui/interface'
5
5
  import { TextData, UnitConvert } from '@leafer-ui/data'
6
6
 
7
7
  import { TextConvert } from '@leafer-ui/external'
@@ -9,7 +9,7 @@ import { TextConvert } from '@leafer-ui/external'
9
9
  import { UI } from './UI'
10
10
 
11
11
 
12
- const { copyAndSpread, includes, spread } = BoundsHelper
12
+ const { copyAndSpread, includes, isSame, spread, setList } = BoundsHelper
13
13
 
14
14
  @registerUI()
15
15
  export class Text extends UI implements IText {
@@ -21,64 +21,76 @@ export class Text extends UI implements IText {
21
21
 
22
22
  // size
23
23
  @boundsType(0)
24
- declare public width: __Number
24
+ declare public width?: INumber
25
25
 
26
26
  @boundsType(0)
27
- declare public height: __Number
27
+ declare public height?: INumber
28
28
 
29
- @boundsType(0)
30
- public padding: number | number[]
29
+ @dataType(false)
30
+ public resizeFontSize?: IBoolean
31
+
32
+ @surfaceType('#000000')
33
+ declare public fill?: IFill
31
34
 
32
35
  @affectStrokeBoundsType('outside')
33
- declare public strokeAlign: IStrokeAlign
36
+ declare public strokeAlign?: IStrokeAlign
37
+
38
+ @hitType('all')
39
+ declare public hitFill?: IHitType
34
40
 
35
41
  @boundsType('')
36
- public text: __String
42
+ public text?: IString
37
43
 
38
44
  @boundsType('L')
39
- public fontFamily: __String
45
+ public fontFamily?: IString
40
46
 
41
47
  @boundsType(12)
42
- public fontSize: __Number
48
+ public fontSize?: INumber
43
49
 
44
50
  @boundsType('normal')
45
- public fontWeight: IFontWeight
51
+ public fontWeight?: IFontWeight
46
52
 
47
53
  @boundsType(false)
48
- public italic: __Boolean
54
+ public italic?: IBoolean
49
55
 
50
56
  @boundsType('none')
51
- public textCase: ITextCase
57
+ public textCase?: ITextCase
52
58
 
53
59
  @boundsType('none')
54
- public textDecoration: ITextDecoration
60
+ public textDecoration?: ITextDecoration
55
61
 
56
62
  @boundsType(0)
57
- public letterSpacing: __Number | IUnitData
63
+ public letterSpacing?: INumber | IUnitData
58
64
 
59
- @boundsType({ type: 'percent', value: 150 } as IUnitData)
60
- public lineHeight: __Number | IUnitData
65
+ @boundsType({ type: 'percent', value: 1.5 } as IUnitData)
66
+ public lineHeight?: INumber | IUnitData
61
67
 
62
68
  @boundsType(0)
63
- public paraIndent: __Number
69
+ public paraIndent?: INumber
64
70
 
65
71
  @boundsType(0)
66
- public paraSpacing: __Number
72
+ public paraSpacing?: INumber
67
73
 
68
74
  @boundsType('left')
69
- public textAlign: ITextAlign
75
+ public textAlign?: ITextAlign
70
76
 
71
77
  @boundsType('top')
72
- public verticalAlign: IVerticalAlign
78
+ public verticalAlign?: IVerticalAlign
79
+
80
+ @boundsType('normal')
81
+ public textWrap?: ITextWrap
73
82
 
74
83
  @boundsType('show')
75
- public textOverflow: IOverflow | string
84
+ public textOverflow?: IOverflow | string
85
+
86
+ public get editInner(): string { return 'TextEditor' }
76
87
 
77
88
  public get textDrawData(): ITextDrawData {
78
- this.__layout.checkUpdate()
89
+ this.__layout.update()
79
90
  return this.__.__textDrawData
80
91
  }
81
92
 
93
+
82
94
  constructor(data?: ITextInputData) {
83
95
  super(data)
84
96
  }
@@ -114,14 +126,19 @@ export class Text extends UI implements IText {
114
126
 
115
127
  const data = this.__
116
128
  const layout = this.__layout
117
- const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase } = data
129
+ const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data
130
+
131
+ const autoWidth = data.__autoWidth
132
+ const autoHeight = data.__autoHeight
118
133
 
119
134
  // compute
120
135
 
121
136
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize)
122
137
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize)
138
+ data.__padding = padding ? MathHelper.fourNumber(padding) : undefined
123
139
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2
124
140
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`
141
+ data.__clipText = textOverflow !== 'show' && !data.__autoSize
125
142
 
126
143
  this.__updateTextDrawData()
127
144
 
@@ -130,23 +147,37 @@ export class Text extends UI implements IText {
130
147
 
131
148
  if (data.__lineHeight < fontSize) spread(bounds, fontSize / 2)
132
149
 
133
- const width = data.__getInput('width')
134
- const height = data.__getInput('height')
135
-
136
- if (width && height) {
137
- super.__updateBoxBounds()
138
- } else {
139
- b.x = width ? 0 : bounds.x
140
- b.y = height ? 0 : bounds.y
141
- b.width = width ? width : bounds.width
142
- b.height = height ? height : bounds.height
150
+ if (autoWidth || autoHeight) {
151
+ b.x = autoWidth ? bounds.x : 0
152
+ b.y = autoHeight ? bounds.y : 0
153
+ b.width = autoWidth ? bounds.width : data.width
154
+ b.height = autoHeight ? bounds.height : data.height
155
+
156
+ if (padding) {
157
+ const [top, right, bottom, left] = data.__padding
158
+ if (autoWidth) {
159
+ b.x -= left
160
+ b.width += (right + left)
161
+ }
162
+ if (autoHeight) {
163
+ b.y -= top
164
+ b.height += (bottom + top)
165
+ }
166
+ }
143
167
  this.__updateNaturalSize()
168
+ } else {
169
+ super.__updateBoxBounds()
144
170
  }
145
171
 
172
+ if (italic) b.width += fontSize * 0.16
173
+
146
174
  const contentBounds = includes(b, bounds) ? b : bounds
147
- if (contentBounds !== layout.contentBounds) {
175
+ if (!isSame(contentBounds, layout.contentBounds)) {
148
176
  layout.contentBounds = contentBounds
149
177
  layout.renderChanged = true
178
+ setList(data.__textBoxBounds = {} as IBoundsData, [b, bounds])
179
+ } else {
180
+ data.__textBoxBounds = contentBounds
150
181
  }
151
182
 
152
183
  }
@@ -158,7 +189,7 @@ export class Text extends UI implements IText {
158
189
  }
159
190
 
160
191
  public __updateRenderBounds(): void {
161
- copyAndSpread(this.__layout.renderBounds, this.__layout.contentBounds, this.__layout.renderSpread)
192
+ copyAndSpread(this.__layout.renderBounds, this.__.__textBoxBounds, this.__layout.renderSpread)
162
193
  }
163
194
 
164
195
  }