@leafer-ui/display 1.0.0-alpha.2 → 1.0.0-alpha.23

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 CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@leafer-ui/display",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.23",
4
4
  "description": "@leafer-ui/display",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
7
  "main": "src/index.ts",
8
- "files": ["src"],
8
+ "files": [
9
+ "src"
10
+ ],
9
11
  "repository": {
10
12
  "type": "git",
11
13
  "url": "https://github.com/leaferjs/ui.git"
@@ -13,18 +15,17 @@
13
15
  "homepage": "https://github.com/leaferjs/ui/tree/main/packages/display",
14
16
  "bugs": "https://github.com/leaferjs/ui/issues",
15
17
  "keywords": [
16
- "leaferui",
17
18
  "leafer-ui",
18
19
  "leaferjs"
19
20
  ],
20
21
  "dependencies": {
21
- "@leafer/core": "1.0.0-alpha.1",
22
- "@leafer-ui/data": "1.0.0-alpha.1",
23
- "@leafer-ui/display-module": "1.0.0-alpha.1",
24
- "@leafer-ui/decorator": "1.0.0-alpha.1"
22
+ "@leafer/core": "1.0.0-alpha.23",
23
+ "@leafer-ui/data": "1.0.0-alpha.23",
24
+ "@leafer-ui/display-module": "1.0.0-alpha.23",
25
+ "@leafer-ui/decorator": "1.0.0-alpha.23"
25
26
  },
26
27
  "devDependencies": {
27
- "@leafer/interface": "1.0.0-alpha.1",
28
- "@leafer-ui/interface": "1.0.0-alpha.1"
28
+ "@leafer/interface": "1.0.0-alpha.23",
29
+ "@leafer-ui/interface": "1.0.0-alpha.23"
29
30
  }
30
31
  }
package/src/Ellipse.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { __Number } from '@leafer/interface'
1
2
  import { PathCreator, OneRadian, dataProcessor, pathType, registerUI } from '@leafer/core'
2
3
 
3
4
  import { IEllipse, IEllipseInputData, IEllipseData } from '@leafer-ui/interface'
@@ -13,17 +14,19 @@ const { begin, moveTo, close, ellipse } = PathCreator
13
14
  @registerUI()
14
15
  export class Ellipse extends UI implements IEllipse {
15
16
 
17
+ public get __tag() { return 'Ellipse' }
18
+
16
19
  @dataProcessor(EllipseData)
17
20
  public __: IEllipseData
18
21
 
19
22
  @pathType(0)
20
- public innerRadius: number
23
+ public innerRadius: __Number
21
24
 
22
25
  @pathType(0)
23
- public startAngle: number
26
+ public startAngle: __Number
24
27
 
25
28
  @pathType(0)
26
- public endAngle: number
29
+ public endAngle: __Number
27
30
 
28
31
  constructor(data?: IEllipseInputData) {
29
32
  super(data)
@@ -39,12 +42,14 @@ export class Ellipse extends UI implements IEllipse {
39
42
  if (innerRadius) {
40
43
 
41
44
  if (startAngle || endAngle) {
42
- ellipse(rx, ry, rx * (1 - innerRadius), ry * (1 - innerRadius), 0, startAngle * OneRadian, endAngle * OneRadian, false)
45
+ if (innerRadius < 1) ellipse(rx, ry, rx * innerRadius, ry * innerRadius, 0, startAngle * OneRadian, endAngle * OneRadian, false)
43
46
  ellipse(rx, ry, rx, ry, 0, endAngle * OneRadian, startAngle * OneRadian, true)
44
- close()
47
+ if (innerRadius < 1) close()
45
48
  } else {
46
- ellipse(rx, ry, rx * (1 - innerRadius), ry * (1 - innerRadius), 0, 0, 2 * PI, false)
47
- moveTo(width, ry)
49
+ if (innerRadius < 1) {
50
+ ellipse(rx, ry, rx * innerRadius, ry * innerRadius, 0, 0, 2 * PI, false)
51
+ moveTo(width, ry)
52
+ }
48
53
  ellipse(rx, ry, rx, ry, 0, 0, 2 * PI, true)
49
54
  }
50
55
 
package/src/Frame.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaferCanvas, IRenderOptions, ICanvasDrawPath, IBoundsData, IPathCommandData } from '@leafer/interface'
1
+ import { ILeaferCanvas, IRenderOptions, IPathDrawer, IBoundsData, IPathCommandData, __Boolean } from '@leafer/interface'
2
2
  import { BoundsHelper, dataProcessor, boundsType, rewrite, useModule, rewriteAble, registerUI } from '@leafer/core'
3
3
 
4
4
  import { IFrame, IFrameData, IFrameInputData } from '@leafer-ui/interface'
@@ -20,11 +20,13 @@ const { copy, add } = BoundsHelper
20
20
  @registerUI()
21
21
  export class Frame extends Group implements IFrame {
22
22
 
23
+ public get __tag() { return 'Frame' }
24
+
23
25
  @dataProcessor(FrameData)
24
26
  public __: IFrameData
25
27
 
26
28
  @boundsType(true)
27
- public clip: boolean
29
+ public clip: __Boolean
28
30
 
29
31
  constructor(data?: IFrameInputData) {
30
32
  super(data)
@@ -33,7 +35,7 @@ export class Frame extends Group implements IFrame {
33
35
  }
34
36
 
35
37
  @rewrite(rect.__drawPathByData)
36
- public __drawPathByData(drawer: ICanvasDrawPath, data: IPathCommandData): void { }
38
+ public __drawPathByData(_drawer: IPathDrawer, _data: IPathCommandData): void { }
37
39
 
38
40
  public __updateBoxBounds(): void {
39
41
  this.__updateRectBoxBounds()
@@ -45,12 +47,12 @@ export class Frame extends Group implements IFrame {
45
47
  }
46
48
  }
47
49
 
48
- public __updateEventBounds(): void {
49
- this.__updateRectEventBounds()
50
+ public __updateStrokeBounds(): void {
51
+ this.__updateRectStrokeBounds()
50
52
  if (!this.__.clip) {
51
- const { eventBounds } = this.__layout
53
+ const { strokeBounds: eventBounds } = this.__layout
52
54
  copy(bounds, eventBounds)
53
- super.__updateEventBounds()
55
+ super.__updateStrokeBounds()
54
56
  add(eventBounds, bounds)
55
57
  }
56
58
  }
@@ -68,17 +70,17 @@ export class Frame extends Group implements IFrame {
68
70
  @rewrite(rect.__updateBoxBounds)
69
71
  public __updateRectBoxBounds(): void { }
70
72
 
71
- @rewrite(rect.__updateEventBounds)
72
- public __updateRectEventBounds(): void { }
73
+ @rewrite(rect.__updateStrokeBounds)
74
+ public __updateRectStrokeBounds(): void { }
73
75
 
74
76
  @rewrite(rect.__updateRenderBounds)
75
77
  public __updateRectRenderBounds(): void { }
76
78
 
77
79
 
78
80
  @rewrite(rect.__render)
79
- public __renderRect(canvas: ILeaferCanvas, options: IRenderOptions): void { }
81
+ public __renderRect(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
80
82
 
81
83
  @rewrite(group.__render)
82
- public __renderGroup(canvas: ILeaferCanvas, options: IRenderOptions): void { }
84
+ public __renderGroup(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
83
85
 
84
86
  }
package/src/Group.ts CHANGED
@@ -10,23 +10,30 @@ import { UI } from './UI'
10
10
  @registerUI()
11
11
  export class Group extends UI implements IGroup {
12
12
 
13
+ public get __tag() { return 'Group' }
14
+
13
15
  @dataProcessor(GroupData)
14
16
  public __: IGroupData
15
17
 
16
18
  public children: IUI[]
17
19
 
20
+ public set mask(child: IUI) {
21
+ if (this.__hasMask) this.__removeMask()
22
+ if (child) {
23
+ child.isMask = true
24
+ this.addAt(child, 0)
25
+ }
26
+ }
27
+ public get mask(): IUI {
28
+ return this.children.find(item => item.isMask)
29
+ }
30
+
18
31
  constructor(data?: IGroupInputData) {
19
32
  super(data)
20
33
  this.__isBranch = true
21
34
  this.children = []
22
35
  }
23
36
 
24
- public __updatePath(): void {
25
-
26
- }
27
-
28
- public add(child: IUI, index?: number): void { } // Branch rewrite
29
-
30
37
  public addAt(child: IUI, index: number): void {
31
38
  this.add(child, index)
32
39
  }
@@ -39,6 +46,26 @@ export class Group extends UI implements IGroup {
39
46
  this.add(child, this.children.indexOf(before))
40
47
  }
41
48
 
42
- public remove(child?: IUI): void { } // Branch rewrite
49
+ // Branch rewrite
50
+
51
+ public add(_child: IUI, _index?: number): void { }
43
52
 
53
+ public remove(_child?: IUI): void { }
54
+
55
+ protected __removeMask(child?: IUI): void {
56
+ if (child) {
57
+ child.isMask = false
58
+ this.remove(child)
59
+ } else {
60
+ const { children } = this
61
+ for (let i = 0, len = children.length; i < len; i++) {
62
+ child = children[i]
63
+ if (child.isMask) {
64
+ child.isMask = false
65
+ this.remove(child)
66
+ len--, i--
67
+ }
68
+ }
69
+ }
70
+ }
44
71
  }
package/src/Image.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { boundsType, dataProcessor, registerUI } from '@leafer/core'
1
+ import { ILeaferImage, __String } from '@leafer/interface'
2
+ import { ImageEvent, boundsType, dataProcessor, registerUI } from '@leafer/core'
2
3
 
3
- import { IImage, IImageInputData, IImageData } from '@leafer-ui/interface'
4
+ import { IImage, IImageInputData, IImageData, IImagePaint } from '@leafer-ui/interface'
4
5
  import { ImageData } from '@leafer-ui/data'
5
6
 
6
7
  import { Rect } from './Rect'
@@ -9,17 +10,42 @@ import { Rect } from './Rect'
9
10
  @registerUI()
10
11
  export class Image extends Rect implements IImage {
11
12
 
13
+ public get __tag() { return 'Image' }
14
+
12
15
  @dataProcessor(ImageData)
13
16
  public __: IImageData
14
17
 
15
18
  @boundsType('')
16
- public url: string
19
+ public url: __String
17
20
 
18
- @boundsType('')
19
- public thumb: string
21
+ public get ready(): boolean { return this.image?.ready }
22
+
23
+ public image: ILeaferImage
20
24
 
21
25
  constructor(data?: IImageInputData) {
22
26
  super(data)
23
27
  }
24
28
 
29
+ public __updateBoxBounds(): void {
30
+
31
+ let update: boolean
32
+
33
+ const { url } = this
34
+ const fills = this.fill as IImagePaint[]
35
+ if (fills) {
36
+ if (fills[0].url !== url) update = true
37
+ } else {
38
+ if (url) update = true
39
+ }
40
+
41
+ if (update) {
42
+ if (this.image) this.image = null
43
+ this.fill = { type: 'image', mode: 'strench', url }
44
+ this.once(ImageEvent.LOADED, (e) => this.image = e.image)
45
+ }
46
+
47
+ super.__updateBoxBounds()
48
+
49
+ }
50
+
25
51
  }
package/src/Line.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { __Number, IPointData, ITwoPointBoundsData } from '@leafer/interface'
2
- import { PathCreator, PointHelper, TwoPointBoundsHelper, boundsType, dataProcessor, registerUI } from '@leafer/core'
1
+ import { IPointData, ITwoPointBoundsData, __Number } from '@leafer/interface'
2
+ import { PathCreator, PointHelper, TwoPointBoundsHelper, boundsType, affectEventBoundsType, dataProcessor, registerUI } from '@leafer/core'
3
3
 
4
- import { ILine, ILineData, ILineInputData } from '@leafer-ui/interface'
4
+ import { ILine, ILineData, ILineInputData, IStrokeAlign } from '@leafer-ui/interface'
5
5
  import { LineData } from '@leafer-ui/data'
6
6
 
7
7
  import { UI } from './UI'
@@ -17,26 +17,28 @@ const pointBounds = {} as ITwoPointBoundsData
17
17
  @registerUI()
18
18
  export class Line extends UI implements ILine {
19
19
 
20
+ public get __tag() { return 'Line' }
21
+
20
22
  @dataProcessor(LineData)
21
23
  public __: ILineData
22
24
 
23
25
  @boundsType()
24
26
  public rotation: __Number
25
27
 
28
+ @affectEventBoundsType('center')
29
+ public strokeAlign: IStrokeAlign
26
30
 
27
- protected __to: IPointData
31
+ protected __toPoint: IPointData
28
32
 
29
33
  public get toPoint(): IPointData {
30
- if (this.__to && !this.__layout.boxBoundsChanged) return this.__to
34
+ if (this.__toPoint && !this.__layout.boxBoundsChanged) return this.__toPoint
31
35
 
32
- const { width, height, rotation } = this.__
36
+ const { width, rotation } = this.__
33
37
  const to: IPointData = { x: 0, y: 0 }
34
38
 
35
39
  if (width) to.x = width
36
- if (height) to.y = height
37
-
38
40
  if (rotation) rotate(to, rotation)
39
- this.__to = to
41
+ this.__toPoint = to
40
42
 
41
43
  return to
42
44
  }
@@ -64,7 +66,7 @@ export class Line extends UI implements ILine {
64
66
 
65
67
  public __updateBoxBounds(): void {
66
68
  setPoint(pointBounds, 0, 0)
67
- addPoint(pointBounds, this.__to.x, this.__to.y)
69
+ addPoint(pointBounds, this.__toPoint.x, this.__toPoint.y)
68
70
  toBounds(pointBounds, this.__layout.boxBounds)
69
71
  }
70
72
 
package/src/Path.ts CHANGED
@@ -1,21 +1,19 @@
1
- import { ITwoPointBoundsData, ILeaferCanvas, IPathCommandData } from '@leafer/interface'
2
- import { PathHelper, TwoPointBoundsHelper, dataProcessor, pathType, registerUI } from '@leafer/core'
1
+ import { ILeaferCanvas, IPathCommandData, IWindingRule } from '@leafer/interface'
2
+ import { PathHelper, dataProcessor, pathType, affectEventBoundsType, registerUI } from '@leafer/core'
3
3
 
4
- import { IPath, IPathData, IPathInputData, IWindingRule, IPathString } from '@leafer-ui/interface'
4
+ import { IPath, IPathData, IPathInputData, IPathString, IStrokeAlign } from '@leafer-ui/interface'
5
5
  import { PathData } from '@leafer-ui/data'
6
6
 
7
7
  import { UI } from './UI'
8
8
 
9
9
 
10
- const { toTwoPointBounds } = PathHelper
11
- const { toBounds } = TwoPointBoundsHelper
12
-
13
- const pointBounds = {} as ITwoPointBoundsData
14
-
10
+ const { toBounds } = PathHelper
15
11
 
16
12
  @registerUI()
17
13
  export class Path extends UI implements IPath {
18
14
 
15
+ public get __tag() { return 'Path' }
16
+
19
17
  @dataProcessor(PathData)
20
18
  public __: IPathData
21
19
 
@@ -25,6 +23,9 @@ export class Path extends UI implements IPath {
25
23
  @pathType()
26
24
  public windingRule: IWindingRule
27
25
 
26
+ @affectEventBoundsType('center')
27
+ public strokeAlign: IStrokeAlign
28
+
28
29
  constructor(data?: IPathInputData) {
29
30
  super(data)
30
31
  }
@@ -35,8 +36,7 @@ export class Path extends UI implements IPath {
35
36
  }
36
37
 
37
38
  public __updateBoxBounds(): void {
38
- toTwoPointBounds(this.__.path, pointBounds)
39
- toBounds(pointBounds, this.__layout.boxBounds)
39
+ toBounds(this.__.path, this.__layout.boxBounds)
40
40
  }
41
41
 
42
42
  }
package/src/Polygon.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { __Number } from '@leafer/interface'
1
2
  import { PathCreator, dataProcessor, pathType, registerUI } from '@leafer/core'
2
3
 
3
4
  import { IPolygon, IPolygonData, IPolygonInputData } from '@leafer-ui/interface'
@@ -13,6 +14,8 @@ const { begin, moveTo, lineTo, close } = PathCreator
13
14
  @registerUI()
14
15
  export class Polygon extends UI implements IPolygon {
15
16
 
17
+ public get __tag() { return 'Polygon' }
18
+
16
19
  @dataProcessor(PolygonData)
17
20
  public __: IPolygonData
18
21
 
package/src/Rect.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ICanvasDrawPath, IPathCommandData } from '@leafer/interface'
1
+ import { IPathDrawer, IPathCommandData, __Number } from '@leafer/interface'
2
2
  import { dataProcessor, registerUI, useModule } from '@leafer/core'
3
3
 
4
4
  import { IRect, IRectInputData, IRectData } from '@leafer-ui/interface'
@@ -12,6 +12,8 @@ import { UI } from './UI'
12
12
  @registerUI()
13
13
  export class Rect extends UI implements IRect {
14
14
 
15
+ public get __tag() { return 'Rect' }
16
+
15
17
  @dataProcessor(RectData)
16
18
  public __: IRectData
17
19
 
@@ -19,12 +21,10 @@ export class Rect extends UI implements IRect {
19
21
  super(data)
20
22
  }
21
23
 
22
- public __updatePath(): void { }
23
-
24
- public __drawPathByData(drawer: ICanvasDrawPath, data: IPathCommandData): void {
25
- const { width, height, borderRadius } = this.__
26
- if (borderRadius) {
27
- drawer.roundRect(0, 0, width, height, borderRadius)
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
28
  } else {
29
29
  drawer.rect(0, 0, width, height)
30
30
  }
package/src/Star.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { __Number } from '@leafer/interface'
1
2
  import { PathCreator, dataProcessor, pathType, registerUI } from '@leafer/core'
2
3
 
3
4
  import { IStar, IStarData, IStarInputData } from '@leafer-ui/interface'
@@ -13,14 +14,16 @@ const { begin, moveTo, lineTo, close } = PathCreator
13
14
  @registerUI()
14
15
  export class Star extends UI implements IStar {
15
16
 
17
+ public get __tag() { return 'Star' }
18
+
16
19
  @dataProcessor(StarData)
17
20
  public __: IStarData
18
21
 
19
22
  @pathType(5)
20
- public points: number
23
+ public points: __Number
21
24
 
22
- @pathType(0.38)
23
- public innerRadius: number
25
+ @pathType(0.382)
26
+ public innerRadius: __Number
24
27
 
25
28
  constructor(data?: IStarInputData) {
26
29
  super(data)
package/src/Text.ts CHANGED
@@ -1,78 +1,101 @@
1
- import { ICanvasDrawPath, IPathCommandData } from '@leafer/interface'
2
- import { Platform, boundsType, dataProcessor, registerUI, useModule } from '@leafer/core'
1
+ import { IPathDrawer, IPathCommandData, __Boolean, __Number, __String } from '@leafer/interface'
2
+ import { boundsType, dataProcessor, registerUI, surfaceType, useModule } from '@leafer/core'
3
3
 
4
- import { IText, IFontWeight, ITextCase, ITextDecoration, IPercent, ITextData, ITextInputData } from '@leafer-ui/interface'
4
+ import { IText, IFontWeight, ITextCase, ITextDecoration, IPercent, ITextData, ITextInputData, ITextAlign, IVerticalAlign, ITextDrawData } from '@leafer-ui/interface'
5
5
  import { TextData } from '@leafer-ui/data'
6
6
  import { TextRender } from '@leafer-ui/display-module'
7
+ import { TextConvert } from '@leafer-ui/text'
7
8
 
8
9
  import { UI } from './UI'
9
10
 
10
-
11
11
  @useModule(TextRender)
12
12
  @registerUI()
13
13
  export class Text extends UI implements IText {
14
14
 
15
+ public get __tag() { return 'Text' }
16
+
15
17
  @dataProcessor(TextData)
16
18
  public __: ITextData
17
19
 
20
+ // size
21
+ @boundsType(undefined)
22
+ public width: __Number
23
+
24
+ @boundsType(undefined)
25
+ public height: __Number
26
+
18
27
  @boundsType('')
19
- public content: string
28
+ public content: __String
20
29
 
21
30
  @boundsType('arial')
22
- public fontFamily: string
31
+ public fontFamily: __String
23
32
 
24
33
  @boundsType(12)
25
- public fontSize: number
34
+ public fontSize: __Number
26
35
 
27
36
  @boundsType('normal')
28
37
  public fontWeight: IFontWeight
29
38
 
30
39
  @boundsType(false)
31
- public italic: boolean
40
+ public italic: __Boolean
32
41
 
33
42
  @boundsType('normal')
34
43
  public textCase: ITextCase
35
44
 
36
- @boundsType('normal')
45
+ @boundsType('none')
37
46
  public textDecoration: ITextDecoration
38
47
 
39
48
  @boundsType()
40
- public letterSpacing: number | IPercent
49
+ public letterSpacing: __Number | IPercent
41
50
 
42
- @boundsType()
43
- public lineHeight: number | IPercent
51
+ @boundsType(1)
52
+ public lineHeight: __Number | IPercent
44
53
 
45
54
  @boundsType()
46
- public paragraphIndent: number
55
+ public paragraphIndent: __Number
47
56
 
48
57
  @boundsType()
49
- public paragraphSpacing: number
58
+ public paragraphSpacing: __Number
50
59
 
51
- constructor(data?: ITextInputData) {
52
- super(data)
53
- }
60
+ @surfaceType('left')
61
+ public textAlign: ITextAlign
62
+
63
+ @surfaceType('top')
64
+ public verticalAlign: IVerticalAlign
54
65
 
55
- public __updatePath(): void {
66
+ public get realWidth(): number { return this.textDrawData.width }
56
67
 
68
+ public get realHeight(): number { return this.textDrawData.height }
69
+
70
+ public get textDrawData(): ITextDrawData {
71
+ this.__updateTextDrawData()
72
+ return this.__.__textDrawData
73
+ }
74
+
75
+ constructor(data?: ITextInputData) {
76
+ super(data)
57
77
  }
58
78
 
59
- public __drawPathByData(drawer: ICanvasDrawPath, data: IPathCommandData): void {
79
+ public __drawPathByData(drawer: IPathDrawer, _data: IPathCommandData): void {
60
80
  const { width, height } = this.__
61
81
  drawer.rect(0, 0, width, height)
62
82
  }
63
83
 
84
+ public __updateTextDrawData(): void {
85
+ this.__.__textDrawData || (this.__.__textDrawData = TextConvert.getDrawData(this.__.content, this.__))
86
+ }
87
+
64
88
  public __updateBoxBounds(): void {
65
- const { fontFamily, fontSize, fontWeight, italic, textCase, lineHeight } = this.__
66
- const b = this.__layout.boxBounds
67
89
 
68
- this.__.__font = Platform.canvas.font = `${italic ? 'italic' : ''} ${textCase === 'small-caps' ? 'small-caps' : 'normal'} ${fontWeight ? fontWeight : 'normal'} ${fontSize}px/${lineHeight ? lineHeight : fontSize}px ${fontFamily}`
69
- const width = Platform.canvas.measureText(this.content).width
70
- const height = fontSize
90
+ this.__updateTextDrawData()
91
+
92
+ const { width, height, __textDrawData: data } = this.__
93
+ const b = this.__layout.boxBounds
71
94
 
72
- b.x = 0
73
- b.y = -fontSize * 0.75
74
- b.width = width
75
- b.height = height
95
+ b.x = width ? 0 : data.x || 0
96
+ b.y = height ? 0 : data.y || 0
97
+ b.width = width ? Math.max(width, data.width) : data.width
98
+ b.height = height ? Math.max(height, data.height) : data.height
76
99
  }
77
100
 
78
101
  }
package/src/UI.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { ILeaferCanvas, ICanvasDrawPath, IPathCommandData, __Number, __Boolean, __String, IMatrixData, IBoundsData } from '@leafer/interface'
2
- import { Leaf, PathHelper, affectEventBoundsType, surfaceType, dataType, positionType, boundsType, pathType, scaleType, rotationType, opacityType, sortType, dataProcessor, useModule, rewrite, rewriteAble } from '@leafer/core'
1
+ import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType, __Number, __Boolean, __String } from '@leafer/interface'
2
+ import { Leaf, PathHelper, affectEventBoundsType, surfaceType, dataType, positionType, boundsType, pathType, scaleType, rotationType, opacityType, sortType, maskType, dataProcessor, useModule, rewrite, rewriteAble, UICreator } from '@leafer/core'
3
3
 
4
- import { IUI, IShadowEffect, IBlurEffect, IPaint, IStrokeAlign, IStrokeJoin, IStrokeCap, IBlendMode, IPaintString, IDashPatternString, IShadowString, IGrayscaleEffect, IUIData, IGroup, IBorderWidthString, IBorderRadiusString } from '@leafer-ui/interface'
4
+ import { IUI, IShadowEffect, IBlurEffect, IPaint, IStrokeAlign, IStrokeJoin, IStrokeCap, IBlendMode, IPaintString, IDashPatternString, IShadowString, IGrayscaleEffect, IUIData, IGroup, IStrokeWidthString, ICornerRadiusString, IUITagInputData, IUIInputData } from '@leafer-ui/interface'
5
5
  import { effectType } from '@leafer-ui/decorator'
6
6
 
7
7
  import { UIData } from '@leafer-ui/data'
8
8
  import { UIBounds, UIHit, UIRender } from '@leafer-ui/display-module'
9
9
 
10
+ import { Paint } from '@leafer-ui/external'
11
+
10
12
 
11
13
  @useModule(UIBounds)
12
14
  @useModule(UIHit)
@@ -18,7 +20,6 @@ export class UI extends Leaf implements IUI {
18
20
  @dataProcessor(UIData)
19
21
  public __: IUIData
20
22
 
21
- public root?: IGroup
22
23
  public parent?: IGroup
23
24
 
24
25
  // ---
@@ -35,15 +36,24 @@ export class UI extends Leaf implements IUI {
35
36
 
36
37
 
37
38
  // layer
39
+ @surfaceType() // "pass-through"
40
+ public blendMode: IBlendMode
41
+
38
42
  @opacityType(1)
39
43
  public opacity: __Number
40
44
 
41
45
  @opacityType(true)
42
46
  public visible: __Boolean
43
47
 
48
+ @maskType(false)
49
+ public isMask: __Boolean
50
+
44
51
  @sortType(0)
45
52
  public zIndex: __Number
46
53
 
54
+ @dataType()
55
+ public locked: __Boolean
56
+
47
57
 
48
58
  // position
49
59
  @positionType(0)
@@ -79,46 +89,38 @@ export class UI extends Leaf implements IUI {
79
89
  @rotationType(0)
80
90
  public skewY: __Number
81
91
 
92
+
93
+ @dataType(false)
82
94
  public draggable: __Boolean
83
95
 
84
- // ---
96
+ // hit
97
+ @dataType(true)
98
+ public hittable: __Boolean
85
99
 
100
+ @dataType('visible')
101
+ public hitType: IHitType
86
102
 
87
- // layer
103
+ @dataType(true)
104
+ public hitChildren: __Boolean
88
105
 
89
- @surfaceType() // "pass-through"
90
- public blendMode: IBlendMode
106
+ // ---
91
107
 
92
- @boundsType()
93
- public mask: __Boolean
94
-
95
- @dataType()
96
- public locked: __Boolean
97
108
 
98
109
  // fill
99
110
 
100
111
  @surfaceType()
101
112
  public fill: IPaint | IPaint[] | IPaintString
102
113
 
103
- // border
104
-
105
- @pathType()
106
- public borderRadius: __Number | __Number[] | IBorderRadiusString
107
-
108
- @affectEventBoundsType(1)
109
- public borderWidth: __Number | __Number[] | IBorderWidthString
110
-
111
-
112
114
  // stroke
113
115
 
114
116
  @affectEventBoundsType()
115
117
  public stroke: IPaint | IPaint[] | IPaintString
116
118
 
117
- @affectEventBoundsType('center')
119
+ @affectEventBoundsType('inside')
118
120
  public strokeAlign: IStrokeAlign
119
121
 
120
122
  @affectEventBoundsType(1)
121
- public strokeWidth: __Number
123
+ public strokeWidth: number | number[] | IStrokeWidthString
122
124
 
123
125
  @surfaceType('none')
124
126
  public strokeCap: IStrokeCap
@@ -139,7 +141,7 @@ export class UI extends Leaf implements IUI {
139
141
  // corner
140
142
 
141
143
  @pathType()
142
- public cornerRadius: __Number
144
+ public cornerRadius: number | number[] | ICornerRadiusString
143
145
 
144
146
  @pathType()
145
147
  public cornerSmoothing: __Number
@@ -162,28 +164,37 @@ export class UI extends Leaf implements IUI {
162
164
  public grayscale: __Number | IGrayscaleEffect
163
165
 
164
166
 
165
- // now transform
166
-
167
- public get worldTransform(): IMatrixData { return this.__layout.getTransform('world') }
168
-
169
- public get relativeTransform(): IMatrixData { return this.__layout.getTransform('relative') }
167
+ constructor(data?: IUIInputData) {
168
+ super(data)
169
+ }
170
170
 
171
- // now bounds
172
171
 
173
- public get worldBoxBounds(): IBoundsData { return this.__layout.getBounds('world', 'box') }
172
+ public set(data: IUITagInputData): void {
173
+ Object.assign(this, data)
174
+ }
174
175
 
175
- public get worldRenderBounds(): IBoundsData { return this.__layout.getBounds('world', 'render') }
176
+ public get(): IUITagInputData {
177
+ return this.__.__getInputData()
178
+ }
176
179
 
180
+ public __onUpdateSize(): void {
181
+ if (this.__.__input) {
182
+ const { fill, stroke } = this.__.__input
183
+ if (fill) Paint.computeFill(this)
184
+ if (stroke) Paint.computeStroke(this)
185
+ }
186
+ }
177
187
 
178
188
  public __updateRenderPath(): void {
179
- const { __: data } = this
180
- const { cornerRadius, path } = data
181
- data.__renderPath = cornerRadius && path ? PathHelper.applyCorner(path, cornerRadius, data.cornerSmoothing) : path
189
+ if (this.__.path) {
190
+ const { __: data } = this
191
+ data.__pathForRender = data.cornerRadius ? PathHelper.smoothCorner(data.path, data.cornerRadius, data.cornerSmoothing) : data.path
192
+ }
182
193
  }
183
194
 
184
195
  public __drawRenderPath(canvas: ILeaferCanvas): void {
185
196
  canvas.beginPath()
186
- this.__drawPathByData(canvas, this.__.__renderPath)
197
+ this.__drawPathByData(canvas, this.__.__pathForRender)
187
198
  }
188
199
 
189
200
  public __drawPath(canvas: ILeaferCanvas): void {
@@ -192,6 +203,10 @@ export class UI extends Leaf implements IUI {
192
203
  }
193
204
 
194
205
  @rewrite(PathHelper.drawData)
195
- public __drawPathByData(drawer: ICanvasDrawPath, data: IPathCommandData): void { }
206
+ public __drawPathByData(_drawer: IPathDrawer, _data: IPathCommandData): void { }
207
+
208
+ static one(data: IUITagInputData, x?: number, y?: number, width?: number, height?: number): IUI {
209
+ return UICreator.get(data.tag || this.prototype.__tag, data, x, y, width, height) as IUI
210
+ }
196
211
 
197
212
  }
package/src/Vector.ts CHANGED
@@ -9,6 +9,8 @@ import { Group } from './Group'
9
9
  @registerUI()
10
10
  export class Vector extends Group implements IVector {
11
11
 
12
+ public get __tag() { return 'Vector' }
13
+
12
14
  @dataProcessor(VectorData)
13
15
  public __: IVectorData
14
16