@leafer-ui/display 1.0.0-beta.11 → 1.0.0-beta.15

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,12 +1,15 @@
1
1
  {
2
2
  "name": "@leafer-ui/display",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.15",
4
4
  "description": "@leafer-ui/display",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
7
  "main": "src/index.ts",
8
+ "types": "types/index.d.ts",
8
9
  "files": [
9
- "src"
10
+ "src",
11
+ "types",
12
+ "dist"
10
13
  ],
11
14
  "repository": {
12
15
  "type": "git",
@@ -19,14 +22,14 @@
19
22
  "leaferjs"
20
23
  ],
21
24
  "dependencies": {
22
- "@leafer/core": "1.0.0-beta.11",
23
- "@leafer-ui/data": "1.0.0-beta.11",
24
- "@leafer-ui/text": "1.0.0-beta.11",
25
- "@leafer-ui/display-module": "1.0.0-beta.11",
26
- "@leafer-ui/decorator": "1.0.0-beta.11"
25
+ "@leafer/core": "1.0.0-beta.15",
26
+ "@leafer-ui/data": "1.0.0-beta.15",
27
+ "@leafer-ui/display-module": "1.0.0-beta.15",
28
+ "@leafer-ui/decorator": "1.0.0-beta.15",
29
+ "@leafer-ui/external": "1.0.0-beta.15"
27
30
  },
28
31
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-beta.11",
30
- "@leafer-ui/interface": "1.0.0-beta.11"
32
+ "@leafer/interface": "1.0.0-beta.15",
33
+ "@leafer-ui/interface": "1.0.0-beta.15"
31
34
  }
32
35
  }
package/src/Box.ts CHANGED
@@ -20,10 +20,12 @@ export class Box extends Group implements IBox {
20
20
  public get __tag() { return 'Box' }
21
21
 
22
22
  @dataProcessor(BoxData)
23
- public __: IBoxData
23
+ declare public __: IBoxData
24
24
 
25
25
  @affectRenderBoundsType('show')
26
- public overflow: IOverflow
26
+ declare public overflow: IOverflow
27
+
28
+ public get resizeable(): boolean { return true }
27
29
 
28
30
  constructor(data?: IBoxInputData) {
29
31
  super(data)
package/src/Canvas.ts CHANGED
@@ -14,13 +14,13 @@ export class Canvas extends Rect implements ICanvas {
14
14
  public get __tag() { return 'Canvas' }
15
15
 
16
16
  @dataProcessor(ImageData)
17
- public __: ICanvasData
17
+ declare public __: ICanvasData
18
18
 
19
19
  @resizeType(100)
20
- public width: __Number
20
+ declare public width: __Number
21
21
 
22
22
  @resizeType(100)
23
- public height: __Number
23
+ declare public height: __Number
24
24
 
25
25
  @resizeType(Platform.devicePixelRatio)
26
26
  public pixelRatio: __Number
@@ -29,7 +29,7 @@ export class Canvas extends Rect implements ICanvas {
29
29
  public smooth: boolean
30
30
 
31
31
  @hitType('all')
32
- public hitFill: IHitType
32
+ declare public hitFill: IHitType
33
33
 
34
34
  public canvas: ILeaferCanvas
35
35
 
package/src/Ellipse.ts CHANGED
@@ -15,7 +15,7 @@ export class Ellipse extends UI implements IEllipse {
15
15
  public get __tag() { return 'Ellipse' }
16
16
 
17
17
  @dataProcessor(EllipseData)
18
- public __: IEllipseData
18
+ declare public __: IEllipseData
19
19
 
20
20
  @pathType(0)
21
21
  public innerRadius: __Number
package/src/Frame.ts CHANGED
@@ -13,10 +13,10 @@ export class Frame extends Box implements IFrame {
13
13
  public get __tag() { return 'Frame' }
14
14
 
15
15
  @dataProcessor(FrameData)
16
- public __: IFrameData
16
+ declare public __: IFrameData
17
17
 
18
18
  @affectRenderBoundsType('hide')
19
- public overflow: IOverflow
19
+ declare public overflow: IOverflow
20
20
 
21
21
  constructor(data?: IFrameInputData) {
22
22
  super(data)
package/src/Group.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { Branch, useModule, dataProcessor, registerUI } from '@leafer/core'
1
+ import { Branch, useModule, dataProcessor, registerUI, UICreator } from '@leafer/core'
2
2
 
3
- import { IGroup, IGroupData, IGroupInputData, IUI } from '@leafer-ui/interface'
3
+ import { IGroup, IGroupData, IGroupInputData, IUI, IUIInputData } from '@leafer-ui/interface'
4
4
  import { GroupData } from '@leafer-ui/data'
5
5
 
6
6
  import { UI } from './UI'
@@ -13,9 +13,11 @@ export class Group extends UI implements IGroup {
13
13
  public get __tag() { return 'Group' }
14
14
 
15
15
  @dataProcessor(GroupData)
16
- public __: IGroupData
16
+ declare public __: IGroupData
17
17
 
18
- public children: IUI[]
18
+ declare public children: IUI[]
19
+
20
+ public get resizeable(): boolean { return false }
19
21
 
20
22
  public set mask(child: IUI) {
21
23
  if (this.__hasMask) this.__removeMask()
@@ -30,10 +32,46 @@ export class Group extends UI implements IGroup {
30
32
 
31
33
  constructor(data?: IGroupInputData) {
32
34
  super(data)
35
+ this.__setBranch()
36
+ }
37
+
38
+ public __setBranch(): void {
33
39
  this.isBranch = true
34
- this.children = []
40
+ if (!this.children) this.children = []
41
+ }
42
+
43
+ // data
44
+
45
+ public set(data: IUIInputData): void {
46
+ if (data.children) {
47
+ const { children } = data
48
+ delete data.children
49
+
50
+ if (!this.children) this.__setBranch()
51
+
52
+ super.set(data)
53
+
54
+ let child: IUI
55
+ children.forEach(childData => {
56
+ child = UICreator.get(childData.tag, childData) as IUI
57
+ this.add(child)
58
+ })
59
+
60
+ data.children = children
61
+
62
+ } else {
63
+ super.set(data)
64
+ }
35
65
  }
36
66
 
67
+ public toJSON(): IUIInputData {
68
+ const data = super.toJSON()
69
+ data.children = this.children.map(child => child.toJSON())
70
+ return data
71
+ }
72
+
73
+ // add
74
+
37
75
  public addAt(child: IUI, index: number): void {
38
76
  this.add(child, index)
39
77
  }
@@ -50,6 +88,8 @@ export class Group extends UI implements IGroup {
50
88
 
51
89
  public add(_child: IUI, _index?: number): void { }
52
90
 
91
+ public addMany(..._children: IUI[]): void { }
92
+
53
93
  public remove(_child?: IUI, _destroy?: boolean): void { }
54
94
 
55
95
  public removeAll(_destroy?: boolean): void { }
package/src/Image.ts CHANGED
@@ -13,7 +13,7 @@ export class Image extends Rect implements IImage {
13
13
  public get __tag() { return 'Image' }
14
14
 
15
15
  @dataProcessor(ImageData)
16
- public __: IImageData
16
+ declare public __: IImageData
17
17
 
18
18
  @boundsType('')
19
19
  public url: __String
package/src/Line.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { IPointData, ITwoPointBoundsData, __Number } from '@leafer/interface'
2
- import { PathCommandDataHelper, PointHelper, TwoPointBoundsHelper, boundsType, affectStrokeBoundsType, dataProcessor, registerUI } from '@leafer/core'
1
+ import { IPointData, __Number } from '@leafer/interface'
2
+ import { PathBounds, PathCommandDataHelper, PointHelper, boundsType, pathType, affectStrokeBoundsType, dataProcessor, registerUI } from '@leafer/core'
3
3
 
4
4
  import { ILine, ILineData, ILineInputData, IStrokeAlign } from '@leafer-ui/interface'
5
5
  import { LineData } from '@leafer-ui/data'
@@ -7,11 +7,9 @@ import { LineData } from '@leafer-ui/data'
7
7
  import { UI } from './UI'
8
8
 
9
9
 
10
- const { moveTo, lineTo } = PathCommandDataHelper
10
+ const { moveTo, lineTo, drawPoints } = PathCommandDataHelper
11
11
  const { rotate, getAngle, getDistance, defaultPoint } = PointHelper
12
- const { setPoint, addPoint, toBounds } = TwoPointBoundsHelper
13
-
14
- const pointBounds = {} as ITwoPointBoundsData
12
+ const { toBounds } = PathBounds
15
13
 
16
14
 
17
15
  @registerUI()
@@ -20,25 +18,29 @@ export class Line extends UI implements ILine {
20
18
  public get __tag() { return 'Line' }
21
19
 
22
20
  @dataProcessor(LineData)
23
- public __: ILineData
24
-
25
- @boundsType()
26
- public rotation: __Number
21
+ declare public __: ILineData
27
22
 
28
23
  @affectStrokeBoundsType('center')
29
- public strokeAlign: IStrokeAlign
24
+ declare public strokeAlign: IStrokeAlign
30
25
 
31
- protected __toPoint: IPointData
26
+ @boundsType(0)
27
+ declare public height: __Number
32
28
 
33
- public get toPoint(): IPointData {
34
- if (this.__toPoint && !this.__layout.boxChanged) return this.__toPoint
29
+ @pathType()
30
+ public points: number[]
31
+
32
+ @pathType(0)
33
+ public curve: boolean | number
35
34
 
35
+ public get resizeable(): boolean { return !this.points }
36
+
37
+
38
+ public get toPoint(): IPointData {
36
39
  const { width, rotation } = this.__
37
40
  const to: IPointData = { x: 0, y: 0 }
38
41
 
39
42
  if (width) to.x = width
40
43
  if (rotation) rotate(to, rotation)
41
- this.__toPoint = to
42
44
 
43
45
  return to
44
46
  }
@@ -57,16 +59,34 @@ export class Line extends UI implements ILine {
57
59
  public __updatePath(): void {
58
60
 
59
61
  const path: number[] = this.__.path = []
60
- moveTo(path, 0, 0)
61
62
 
62
- const to = this.toPoint
63
- lineTo(path, to.x, to.y)
63
+ if (this.__.points) {
64
+
65
+ drawPoints(path, this.__.points, false)
66
+
67
+ } else {
68
+
69
+ moveTo(path, 0, 0)
70
+ lineTo(path, this.width, 0)
71
+ }
72
+
73
+ }
74
+
75
+ public __updateRenderPath(): void {
76
+ if (this.__.points && this.__.curve) {
77
+ drawPoints(this.__.__pathForRender = [], this.__.points, this.__.curve, false)
78
+ } else {
79
+ super.__updateRenderPath()
80
+ }
64
81
  }
65
82
 
66
83
  public __updateBoxBounds(): void {
67
- setPoint(pointBounds, 0, 0)
68
- addPoint(pointBounds, this.__toPoint.x, this.__toPoint.y)
69
- toBounds(pointBounds, this.__layout.boxBounds)
84
+ if (this.points) {
85
+ toBounds(this.__.path, this.__layout.boxBounds)
86
+ this.__updateNaturalSize()
87
+ } else {
88
+ super.__updateBoxBounds()
89
+ }
70
90
  }
71
91
 
72
92
  }
package/src/Path.ts CHANGED
@@ -15,7 +15,7 @@ export class Path extends UI implements IPath {
15
15
  public get __tag() { return 'Path' }
16
16
 
17
17
  @dataProcessor(PathData)
18
- public __: IPathData
18
+ declare public __: IPathData
19
19
 
20
20
  @pathType()
21
21
  public path: IPathCommandData | IPathString
@@ -24,7 +24,9 @@ export class Path extends UI implements IPath {
24
24
  public windingRule: IWindingRule
25
25
 
26
26
  @affectStrokeBoundsType('center')
27
- public strokeAlign: IStrokeAlign
27
+ declare public strokeAlign: IStrokeAlign
28
+
29
+ public get resizeable(): boolean { return false }
28
30
 
29
31
  constructor(data?: IPathInputData) {
30
32
  super(data)
@@ -32,6 +34,7 @@ export class Path extends UI implements IPath {
32
34
 
33
35
  public __updateBoxBounds(): void {
34
36
  toBounds(this.__.path, this.__layout.boxBounds)
37
+ this.__updateNaturalSize()
35
38
  }
36
39
 
37
40
  }
package/src/Pen.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PathCreator, dataProcessor, registerUI, useModule } from '@leafer/core'
2
2
 
3
- import { IPenData, IPenInputData, IPathInputData, IPathCommandData, IPath } from '@leafer-ui/interface'
3
+ import { IPenData, IPenInputData, IPathInputData, IPathCommandData, IPath, IPen } from '@leafer-ui/interface'
4
4
  import { PenData } from '@leafer-ui/data'
5
5
 
6
6
  import { Group } from './Group'
@@ -9,12 +9,12 @@ import { Path } from './Path'
9
9
 
10
10
  @useModule(PathCreator, ['beginPath'])
11
11
  @registerUI()
12
- export class Pen extends Group {
12
+ export class Pen extends Group implements IPen {
13
13
 
14
14
  public get __tag() { return 'Pen' }
15
15
 
16
16
  @dataProcessor(PenData)
17
- public __: IPenData
17
+ declare public __: IPenData
18
18
 
19
19
  public pathElement: IPath
20
20
  public pathStyle: IPathInputData
@@ -66,13 +66,19 @@ export class Pen extends Group {
66
66
 
67
67
  // moveTo, then draw
68
68
 
69
- public moveToEllipse(_x: number, _y: number, _radiusX: number, _radiusY: number, _rotation?: number, _startAngle?: number, _endAngle?: number, _anticlockwise?: boolean): Pen { return this }
69
+ public drawEllipse(_x: number, _y: number, _radiusX: number, _radiusY: number, _rotation?: number, _startAngle?: number, _endAngle?: number, _anticlockwise?: boolean): Pen { return this }
70
70
 
71
- public moveToArc(_x: number, _y: number, _radius: number, _startAngle?: number, _endAngle?: number, _anticlockwise?: boolean): Pen { return this }
71
+ public drawArc(_x: number, _y: number, _radius: number, _startAngle?: number, _endAngle?: number, _anticlockwise?: boolean): Pen { return this }
72
+
73
+ public drawPoints(_points: number[], _curve?: boolean | number, _close?: boolean): Pen { return this }
72
74
 
73
75
 
74
76
  public paint(): void {
75
77
  this.pathElement.forceUpdate('path')
76
78
  }
77
79
 
80
+ public clear(): void {
81
+ this.removeAll(true)
82
+ }
83
+
78
84
  }
package/src/Polygon.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { __Number } from '@leafer/interface'
2
- import { PathCommandDataHelper, dataProcessor, pathType, registerUI } from '@leafer/core'
2
+ import { PathBounds, PathCommandDataHelper, dataProcessor, pathType, registerUI } from '@leafer/core'
3
3
 
4
4
  import { IPolygon, IPolygonData, IPolygonInputData } from '@leafer-ui/interface'
5
5
  import { PolygonData } from '@leafer-ui/data'
@@ -8,8 +8,8 @@ import { UI } from './UI'
8
8
 
9
9
 
10
10
  const { sin, cos, PI } = Math
11
- const { moveTo, lineTo, closePath } = PathCommandDataHelper
12
-
11
+ const { moveTo, lineTo, closePath, drawPoints } = PathCommandDataHelper
12
+ const { toBounds } = PathBounds
13
13
 
14
14
  @registerUI()
15
15
  export class Polygon extends UI implements IPolygon {
@@ -17,28 +17,59 @@ export class Polygon extends UI implements IPolygon {
17
17
  public get __tag() { return 'Polygon' }
18
18
 
19
19
  @dataProcessor(PolygonData)
20
- public __: IPolygonData
20
+ declare public __: IPolygonData
21
21
 
22
22
  @pathType(3)
23
23
  sides: number
24
24
 
25
+ @pathType()
26
+ points: number[]
27
+
28
+ @pathType(0)
29
+ curve: boolean | number
30
+
31
+ public get resizeable(): boolean { return !this.points }
32
+
25
33
  constructor(data?: IPolygonInputData) {
26
34
  super(data)
27
35
  }
28
36
 
29
37
  public __updatePath(): void {
30
38
 
31
- const { width, height, sides } = this.__
32
- const rx = width / 2, ry = height / 2
33
-
34
39
  const path: number[] = this.__.path = []
35
- moveTo(path, rx, 0)
36
40
 
37
- for (let i = 1; i < sides; i++) {
38
- lineTo(path, rx + rx * sin((i * 2 * PI) / sides), ry - ry * cos((i * 2 * PI) / sides))
41
+ if (this.__.points) {
42
+
43
+ drawPoints(path, this.__.points, false, true)
44
+
45
+ } else {
46
+
47
+ const { width, height, sides } = this.__
48
+ const rx = width / 2, ry = height / 2
49
+
50
+ moveTo(path, rx, 0)
51
+
52
+ for (let i = 1; i < sides; i++) {
53
+ lineTo(path, rx + rx * sin((i * 2 * PI) / sides), ry - ry * cos((i * 2 * PI) / sides))
54
+ }
55
+
39
56
  }
40
57
 
41
58
  closePath(path)
42
59
  }
43
60
 
61
+
62
+ public __updateRenderPath(): void {
63
+ if (this.__.points && this.__.curve) {
64
+ drawPoints(this.__.__pathForRender = [], this.__.points, this.__.curve, true)
65
+ this.__updateNaturalSize()
66
+ } else {
67
+ super.__updateRenderPath()
68
+ }
69
+ }
70
+
71
+ public __updateBoxBounds(): void {
72
+ this.__.points ? toBounds(this.__.path, this.__layout.boxBounds) : super.__updateBoxBounds()
73
+ }
74
+
44
75
  }
package/src/Rect.ts CHANGED
@@ -15,7 +15,7 @@ export class Rect extends UI implements IRect {
15
15
  public get __tag() { return 'Rect' }
16
16
 
17
17
  @dataProcessor(RectData)
18
- public __: IRectData
18
+ declare public __: IRectData
19
19
 
20
20
  constructor(data?: IRectInputData) {
21
21
  super(data)
package/src/Star.ts CHANGED
@@ -17,10 +17,10 @@ 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 points: __Number
23
+ public corners: __Number
24
24
 
25
25
  @pathType(0.382)
26
26
  public innerRadius: __Number
@@ -31,14 +31,14 @@ export class Star extends UI implements IStar {
31
31
 
32
32
  public __updatePath() {
33
33
 
34
- const { width, height, points, innerRadius } = this.__
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 < points * 2; i++) {
41
- lineTo(path, rx + (i % 2 === 0 ? rx : rx * innerRadius) * sin((i * PI) / points), ry - (i % 2 === 0 ? ry : ry * innerRadius) * cos((i * PI) / points))
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
@@ -3,7 +3,8 @@ import { BoundsHelper, boundsType, dataProcessor, registerUI, affectStrokeBounds
3
3
 
4
4
  import { IText, IFontWeight, ITextCase, ITextDecoration, ITextData, ITextInputData, ITextAlign, IVerticalAlign, ITextDrawData, IOverflow, IUnitData, IStrokeAlign } from '@leafer-ui/interface'
5
5
  import { TextData, UnitConvert } from '@leafer-ui/data'
6
- import { TextConvert } from '@leafer-ui/text'
6
+
7
+ import { TextConvert } from '@leafer-ui/external'
7
8
 
8
9
  import { UI } from './UI'
9
10
 
@@ -16,20 +17,20 @@ 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: __Number
24
+ declare public width: __Number
24
25
 
25
26
  @boundsType(0)
26
- public height: __Number
27
+ declare public height: __Number
27
28
 
28
29
  @boundsType(0)
29
30
  public padding: number | number[]
30
31
 
31
32
  @affectStrokeBoundsType('outside')
32
- public strokeAlign: IStrokeAlign
33
+ declare public strokeAlign: IStrokeAlign
33
34
 
34
35
  @boundsType('')
35
36
  public text: __String
@@ -84,11 +85,17 @@ export class Text extends UI implements IText {
84
85
 
85
86
  public __drawHitPath(canvas: ILeaferCanvas): void {
86
87
  const { __lineHeight, __baseLine, __textDrawData: data } = this.__
88
+
87
89
  canvas.beginPath()
88
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight))
90
+
91
+ if (this.__.__letterSpacing < 0) {
92
+ this.__drawPathByData(canvas)
93
+ } else {
94
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight))
95
+ }
89
96
  }
90
97
 
91
- public __drawPathByData(drawer: IPathDrawer, _data: IPathCommandData): void {
98
+ public __drawPathByData(drawer: IPathDrawer, _data?: IPathCommandData): void {
92
99
  const { x, y, width, height } = this.__layout.boxBounds
93
100
  drawer.rect(x, y, width, height)
94
101
  }
@@ -107,7 +114,7 @@ export class Text extends UI implements IText {
107
114
 
108
115
  const data = this.__
109
116
  const layout = this.__layout
110
- const { width, height, lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase } = data
117
+ const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase } = data
111
118
 
112
119
  // compute
113
120
 
@@ -123,6 +130,9 @@ export class Text extends UI implements IText {
123
130
 
124
131
  if (data.__lineHeight < fontSize) spread(bounds, fontSize / 2)
125
132
 
133
+ const width = data.__getInput('width')
134
+ const height = data.__getInput('height')
135
+
126
136
  if (width && height) {
127
137
  super.__updateBoxBounds()
128
138
  } else {
@@ -130,6 +140,7 @@ export class Text extends UI implements IText {
130
140
  b.y = height ? 0 : bounds.y
131
141
  b.width = width ? width : bounds.width
132
142
  b.height = height ? height : bounds.height
143
+ this.__updateNaturalSize()
133
144
  }
134
145
 
135
146
  const contentBounds = includes(b, bounds) ? b : bounds
package/src/UI.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType, __Number, __Boolean, __String, IPathString, IExportFileType } 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 } from '@leafer/core'
1
+ import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType, __Number, __Boolean, __String, IPathString, IExportFileType, IPointData, ICursorType, 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 } from '@leafer/core'
3
3
 
4
- import { IUI, IShadowEffect, IBlurEffect, IPaint, IStrokeAlign, IStrokeJoin, IStrokeCap, IBlendMode, IPaintString, IDashPatternString, IShadowString, IGrayscaleEffect, IUIData, IGroup, IStrokeWidthString, ICornerRadiusString, IUITagInputData, IUIInputData, IExportOptions, IExportResult } from '@leafer-ui/interface'
4
+ import { IUI, IShadowEffect, IBlurEffect, IPaint, IStrokeAlign, IStrokeJoin, IStrokeCap, IBlendMode, IPaintString, IDashPatternString, IShadowString, IGrayscaleEffect, IUIData, IGroup, IStrokeWidthString, ICornerRadiusString, IUIInputData, IUIBaseInputData, IExportOptions, IExportResult } from '@leafer-ui/interface'
5
5
  import { effectType } from '@leafer-ui/decorator'
6
6
 
7
7
  import { UIData } from '@leafer-ui/data'
@@ -17,9 +17,9 @@ import { Export, Paint } from '@leafer-ui/external'
17
17
  export class UI extends Leaf implements IUI {
18
18
 
19
19
  @dataProcessor(UIData)
20
- public __: IUIData
20
+ declare public __: IUIData
21
21
 
22
- public parent?: IGroup
22
+ declare public parent?: IGroup
23
23
 
24
24
  // ---
25
25
 
@@ -90,6 +90,10 @@ export class UI extends Leaf implements IUI {
90
90
  public skewY: __Number
91
91
 
92
92
 
93
+ @positionType()
94
+ public around: IAround
95
+
96
+
93
97
  @dataType(false)
94
98
  public draggable: __Boolean
95
99
 
@@ -109,6 +113,12 @@ export class UI extends Leaf implements IUI {
109
113
  @hitType(true)
110
114
  public hitSelf: __Boolean
111
115
 
116
+ @hitType()
117
+ public hitRadius: __Number
118
+
119
+ @cursorType('default')
120
+ public cursor: ICursorType | ICursorType[]
121
+
112
122
  // ---
113
123
 
114
124
 
@@ -170,16 +180,31 @@ export class UI extends Leaf implements IUI {
170
180
  public grayscale: __Number | IGrayscaleEffect
171
181
 
172
182
 
173
- constructor(data?: IUIInputData) {
183
+ public set scale(value: __Number | IPointData) {
184
+ if (typeof value === 'number') {
185
+ this.scaleX = this.scaleY = value
186
+ } else {
187
+ this.scaleX = value.x
188
+ this.scaleY = value.y
189
+ }
190
+ }
191
+
192
+ public get scale(): __Number | IPointData {
193
+ const { scaleX, scaleY } = this
194
+ return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX
195
+ }
196
+
197
+
198
+ constructor(data?: IUIBaseInputData) {
174
199
  super(data)
175
200
  }
176
201
 
177
202
 
178
- public set(data: IUITagInputData): void {
203
+ public set(data: IUIInputData): void {
179
204
  Object.assign(this, data)
180
205
  }
181
206
 
182
- public get(): IUITagInputData {
207
+ public get(): IUIInputData {
183
208
  return this.__.__getInputData()
184
209
  }
185
210
 
@@ -227,7 +252,11 @@ export class UI extends Leaf implements IUI {
227
252
  return Export.export(this, filename, options)
228
253
  }
229
254
 
230
- static one(data: IUITagInputData, x?: number, y?: number, width?: number, height?: number): IUI {
255
+ public clone(): IUI {
256
+ return UI.one(this.toJSON())
257
+ }
258
+
259
+ static one(data: IUIInputData, x?: number, y?: number, width?: number, height?: number): IUI {
231
260
  return UICreator.get(data.tag || this.prototype.__tag, data, x, y, width, height) as IUI
232
261
  }
233
262
 
@@ -0,0 +1,272 @@
1
+ import { __String, __Number, __Boolean, IAround, IHitType, ICursorType, IPointData, IPathCommandData, IPathString, ILeaferCanvas, IPathDrawer, IExportFileType, IRenderOptions, ILeaferImage, ICanvasContext2D, IWindingRule } from '@leafer/interface';
2
+ import { Leaf } from '@leafer/core';
3
+ import { IUI, IUIData, IGroup, IBlendMode, IPaint, IPaintString, IStrokeAlign, IStrokeWidthString, IStrokeCap, IStrokeJoin, IDashPatternString, ICornerRadiusString, IShadowEffect, IShadowString, IBlurEffect, IGrayscaleEffect, IUIBaseInputData, IUIInputData, IExportOptions, IExportResult, IGroupData, IGroupInputData, IBox, IBoxData, IOverflow, IBoxInputData, IFrame, IFrameData, IFrameInputData, IRect, IRectData, IRectInputData, IEllipse, IEllipseData, IEllipseInputData, IPolygon, IPolygonData, IPolygonInputData, IStar, IStarData, IStarInputData, ILine, ILineData, ILineInputData, IImage, IImageData, IImageInputData, ICanvas, ICanvasData, ICanvasInputData, IText, ITextData, IFontWeight, ITextCase, ITextDecoration, IUnitData, ITextAlign, IVerticalAlign, ITextDrawData, ITextInputData, IPath, IPathData, IPathString as IPathString$1, IPathInputData, IPen, IPenData, IPathCommandData as IPathCommandData$1, IPenInputData } from '@leafer-ui/interface';
4
+
5
+ declare class UI extends Leaf implements IUI {
6
+ __: IUIData;
7
+ parent?: IGroup;
8
+ id: __String;
9
+ name: __String;
10
+ className: __String;
11
+ blendMode: IBlendMode;
12
+ opacity: __Number;
13
+ visible: __Boolean;
14
+ isMask: __Boolean;
15
+ isEraser?: __Boolean;
16
+ zIndex: __Number;
17
+ locked: __Boolean;
18
+ x: __Number;
19
+ y: __Number;
20
+ width: __Number;
21
+ height: __Number;
22
+ scaleX: __Number;
23
+ scaleY: __Number;
24
+ rotation: __Number;
25
+ skewX: __Number;
26
+ skewY: __Number;
27
+ around: IAround;
28
+ draggable: __Boolean;
29
+ hittable: __Boolean;
30
+ hitFill: IHitType;
31
+ hitStroke: IHitType;
32
+ hitChildren: __Boolean;
33
+ hitSelf: __Boolean;
34
+ hitRadius: __Number;
35
+ cursor: ICursorType | ICursorType[];
36
+ fill: IPaint | IPaint[] | IPaintString;
37
+ stroke: IPaint | IPaint[] | IPaintString;
38
+ strokeAlign: IStrokeAlign;
39
+ strokeWidth: number | number[] | IStrokeWidthString;
40
+ strokeCap: IStrokeCap;
41
+ strokeJoin: IStrokeJoin;
42
+ dashPattern: __Number[] | IDashPatternString;
43
+ dashOffset: __Number;
44
+ miterLimit: __Number;
45
+ cornerRadius: number | number[] | ICornerRadiusString;
46
+ cornerSmoothing: __Number;
47
+ shadow: IShadowEffect | IShadowEffect[] | IShadowString;
48
+ innerShadow: IShadowEffect | IShadowEffect[] | IShadowString;
49
+ blur: __Number | IBlurEffect;
50
+ backgroundBlur: __Number | IBlurEffect;
51
+ grayscale: __Number | IGrayscaleEffect;
52
+ set scale(value: __Number | IPointData);
53
+ get scale(): __Number | IPointData;
54
+ constructor(data?: IUIBaseInputData);
55
+ set(data: IUIInputData): void;
56
+ get(): IUIInputData;
57
+ getPath(curve?: boolean): IPathCommandData;
58
+ getPathString(curve?: boolean): IPathString;
59
+ __onUpdateSize(): void;
60
+ __updateRenderPath(): void;
61
+ __drawRenderPath(canvas: ILeaferCanvas): void;
62
+ __drawPath(canvas: ILeaferCanvas): void;
63
+ __drawPathByData(_drawer: IPathDrawer, _data: IPathCommandData): void;
64
+ export(filename: IExportFileType | string, options?: IExportOptions | number | boolean): Promise<IExportResult>;
65
+ clone(): IUI;
66
+ static one(data: IUIInputData, x?: number, y?: number, width?: number, height?: number): IUI;
67
+ destroy(): void;
68
+ }
69
+
70
+ declare class Group extends UI implements IGroup {
71
+ get __tag(): string;
72
+ __: IGroupData;
73
+ children: IUI[];
74
+ get resizeable(): boolean;
75
+ set mask(child: IUI);
76
+ get mask(): IUI;
77
+ constructor(data?: IGroupInputData);
78
+ __setBranch(): void;
79
+ set(data: IUIInputData): void;
80
+ toJSON(): IUIInputData;
81
+ addAt(child: IUI, index: number): void;
82
+ addAfter(child: IUI, after: IUI): void;
83
+ addBefore(child: UI, before: IUI): void;
84
+ add(_child: IUI, _index?: number): void;
85
+ addMany(..._children: IUI[]): void;
86
+ remove(_child?: IUI, _destroy?: boolean): void;
87
+ removeAll(_destroy?: boolean): void;
88
+ }
89
+
90
+ declare class Box extends Group implements IBox {
91
+ get __tag(): string;
92
+ __: IBoxData;
93
+ overflow: IOverflow;
94
+ get resizeable(): boolean;
95
+ constructor(data?: IBoxInputData);
96
+ __updateStrokeSpread(): number;
97
+ __updateRectRenderSpread(): number;
98
+ __updateRenderSpread(): number;
99
+ __updateBoxBounds(): void;
100
+ __updateStrokeBounds(): void;
101
+ __updateRenderBounds(): void;
102
+ __updateRectRenderBounds(): void;
103
+ __updateRectChange(): void;
104
+ __updateChange(): void;
105
+ __drawPathByData(_drawer: IPathDrawer, _data: IPathCommandData): void;
106
+ __renderRect(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
107
+ __renderGroup(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
108
+ __render(canvas: ILeaferCanvas, options: IRenderOptions): void;
109
+ __drawAfterFill(canvas: ILeaferCanvas, options: IRenderOptions): void;
110
+ }
111
+
112
+ declare class Frame extends Box implements IFrame {
113
+ get __tag(): string;
114
+ __: IFrameData;
115
+ overflow: IOverflow;
116
+ constructor(data?: IFrameInputData);
117
+ }
118
+
119
+ declare class Rect extends UI implements IRect {
120
+ get __tag(): string;
121
+ __: IRectData;
122
+ constructor(data?: IRectInputData);
123
+ __drawPathByData(drawer: IPathDrawer, _data: IPathCommandData): void;
124
+ }
125
+
126
+ declare class Ellipse extends UI implements IEllipse {
127
+ get __tag(): string;
128
+ __: IEllipseData;
129
+ innerRadius: __Number;
130
+ startAngle: __Number;
131
+ endAngle: __Number;
132
+ constructor(data?: IEllipseInputData);
133
+ __updatePath(): void;
134
+ }
135
+
136
+ declare class Polygon extends UI implements IPolygon {
137
+ get __tag(): string;
138
+ __: IPolygonData;
139
+ sides: number;
140
+ points: number[];
141
+ curve: boolean | number;
142
+ get resizeable(): boolean;
143
+ constructor(data?: IPolygonInputData);
144
+ __updatePath(): void;
145
+ __updateRenderPath(): void;
146
+ __updateBoxBounds(): void;
147
+ }
148
+
149
+ declare class Star extends UI implements IStar {
150
+ get __tag(): string;
151
+ __: IStarData;
152
+ corners: __Number;
153
+ innerRadius: __Number;
154
+ constructor(data?: IStarInputData);
155
+ __updatePath(): void;
156
+ }
157
+
158
+ declare class Line extends UI implements ILine {
159
+ get __tag(): string;
160
+ __: ILineData;
161
+ strokeAlign: IStrokeAlign;
162
+ height: __Number;
163
+ points: number[];
164
+ curve: boolean | number;
165
+ get resizeable(): boolean;
166
+ get toPoint(): IPointData;
167
+ set toPoint(value: IPointData);
168
+ constructor(data?: ILineInputData);
169
+ __updatePath(): void;
170
+ __updateRenderPath(): void;
171
+ __updateBoxBounds(): void;
172
+ }
173
+
174
+ declare class Image extends Rect implements IImage {
175
+ get __tag(): string;
176
+ __: IImageData;
177
+ url: __String;
178
+ get ready(): boolean;
179
+ image: ILeaferImage;
180
+ constructor(data?: IImageInputData);
181
+ __updateBoxBounds(): void;
182
+ destroy(): void;
183
+ }
184
+
185
+ declare class Canvas extends Rect implements ICanvas {
186
+ get __tag(): string;
187
+ __: ICanvasData;
188
+ width: __Number;
189
+ height: __Number;
190
+ pixelRatio: __Number;
191
+ smooth: boolean;
192
+ hitFill: IHitType;
193
+ canvas: ILeaferCanvas;
194
+ context: ICanvasContext2D;
195
+ constructor(data?: ICanvasInputData);
196
+ draw(ui: IUI, offset?: IPointData, scale?: number | IPointData, rotation?: number): void;
197
+ paint(): void;
198
+ __drawAfterFill(canvas: ILeaferCanvas, _options: IRenderOptions): void;
199
+ __updateSize(): void;
200
+ destroy(): void;
201
+ }
202
+
203
+ declare class Text extends UI implements IText {
204
+ get __tag(): string;
205
+ __: ITextData;
206
+ width: __Number;
207
+ height: __Number;
208
+ padding: number | number[];
209
+ strokeAlign: IStrokeAlign;
210
+ text: __String;
211
+ fontFamily: __String;
212
+ fontSize: __Number;
213
+ fontWeight: IFontWeight;
214
+ italic: __Boolean;
215
+ textCase: ITextCase;
216
+ textDecoration: ITextDecoration;
217
+ letterSpacing: __Number | IUnitData;
218
+ lineHeight: __Number | IUnitData;
219
+ paraIndent: __Number;
220
+ paraSpacing: __Number;
221
+ textAlign: ITextAlign;
222
+ verticalAlign: IVerticalAlign;
223
+ textOverflow: IOverflow | string;
224
+ get textDrawData(): ITextDrawData;
225
+ constructor(data?: ITextInputData);
226
+ __drawHitPath(canvas: ILeaferCanvas): void;
227
+ __drawPathByData(drawer: IPathDrawer, _data?: IPathCommandData): void;
228
+ __drawRenderPath(canvas: ILeaferCanvas): void;
229
+ __updateTextDrawData(): void;
230
+ __updateBoxBounds(): void;
231
+ __updateRenderSpread(): number;
232
+ __updateRenderBounds(): void;
233
+ }
234
+
235
+ declare class Path extends UI implements IPath {
236
+ get __tag(): string;
237
+ __: IPathData;
238
+ path: IPathCommandData | IPathString$1;
239
+ windingRule: IWindingRule;
240
+ strokeAlign: IStrokeAlign;
241
+ get resizeable(): boolean;
242
+ constructor(data?: IPathInputData);
243
+ __updateBoxBounds(): void;
244
+ }
245
+
246
+ declare class Pen extends Group implements IPen {
247
+ get __tag(): string;
248
+ __: IPenData;
249
+ pathElement: IPath;
250
+ pathStyle: IPathInputData;
251
+ path: IPathCommandData$1;
252
+ constructor(data?: IPenInputData);
253
+ setStyle(data: IPathInputData): Pen;
254
+ beginPath(): Pen;
255
+ moveTo(_x: number, _y: number): Pen;
256
+ lineTo(_x: number, _y: number): Pen;
257
+ bezierCurveTo(_x1: number, _y1: number, _x2: number, _y2: number, _x: number, _y: number): Pen;
258
+ quadraticCurveTo(_x1: number, _y1: number, _x: number, _y: number): Pen;
259
+ closePath(): Pen;
260
+ rect(_x: number, _y: number, _width: number, _height: number): Pen;
261
+ roundRect(_x: number, _y: number, _width: number, _height: number, _cornerRadius: number | number[]): Pen;
262
+ ellipse(_x: number, _y: number, _radiusX: number, _radiusY: number, _rotation?: number, _startAngle?: number, _endAngle?: number, _anticlockwise?: boolean): Pen;
263
+ arc(_x: number, _y: number, _radius: number, _startAngle?: number, _endAngle?: number, _anticlockwise?: boolean): Pen;
264
+ arcTo(_x1: number, _y1: number, _x2: number, _y2: number, _radius: number): Pen;
265
+ drawEllipse(_x: number, _y: number, _radiusX: number, _radiusY: number, _rotation?: number, _startAngle?: number, _endAngle?: number, _anticlockwise?: boolean): Pen;
266
+ drawArc(_x: number, _y: number, _radius: number, _startAngle?: number, _endAngle?: number, _anticlockwise?: boolean): Pen;
267
+ drawPoints(_points: number[], _curve?: boolean | number, _close?: boolean): Pen;
268
+ paint(): void;
269
+ clear(): void;
270
+ }
271
+
272
+ export { Box, Canvas, Ellipse, Frame, Group, Image, Line, Path, Pen, Polygon, Rect, Star, Text, UI };