@leafer-ui/display 1.0.0-rc.2 → 1.0.0-rc.20
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 +8 -8
- package/src/Box.ts +23 -16
- package/src/Canvas.ts +14 -12
- package/src/Ellipse.ts +9 -6
- package/src/Frame.ts +7 -4
- package/src/Group.ts +23 -17
- package/src/Image.ts +6 -26
- package/src/Leafer.ts +443 -0
- package/src/Line.ts +14 -12
- package/src/Path.ts +3 -18
- package/src/Pen.ts +18 -8
- package/src/Polygon.ts +10 -18
- package/src/Rect.ts +3 -11
- package/src/Star.ts +3 -3
- package/src/Text.ts +55 -27
- package/src/UI.ts +216 -72
- package/src/index.ts +1 -0
- package/types/index.d.ts +204 -79
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/display",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.20",
|
|
4
4
|
"description": "@leafer-ui/display",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.0.0-rc.
|
|
26
|
-
"@leafer-ui/data": "1.0.0-rc.
|
|
27
|
-
"@leafer-ui/display-module": "1.0.0-rc.
|
|
28
|
-
"@leafer-ui/decorator": "1.0.0-rc.
|
|
29
|
-
"@leafer-ui/external": "1.0.0-rc.
|
|
25
|
+
"@leafer/core": "1.0.0-rc.20",
|
|
26
|
+
"@leafer-ui/data": "1.0.0-rc.20",
|
|
27
|
+
"@leafer-ui/display-module": "1.0.0-rc.20",
|
|
28
|
+
"@leafer-ui/decorator": "1.0.0-rc.20",
|
|
29
|
+
"@leafer-ui/external": "1.0.0-rc.20"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@leafer/interface": "1.0.0-rc.
|
|
33
|
-
"@leafer-ui/interface": "1.0.0-rc.
|
|
32
|
+
"@leafer/interface": "1.0.0-rc.20",
|
|
33
|
+
"@leafer-ui/interface": "1.0.0-rc.20"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/Box.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { ILeaferCanvas, IRenderOptions,
|
|
1
|
+
import { ILeaferCanvas, IRenderOptions, IBoundsData } from '@leafer/interface'
|
|
2
2
|
import { rewrite, rewriteAble, registerUI, BoundsHelper, dataProcessor, affectRenderBoundsType } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { IBox, IBoxData, IBoxInputData, IOverflow } from '@leafer-ui/interface'
|
|
5
|
+
import { BoxData } from '@leafer-ui/data'
|
|
5
6
|
|
|
6
7
|
import { Group } from './Group'
|
|
7
8
|
import { Rect } from './Rect'
|
|
8
|
-
import { BoxData } from '@leafer-ui/data'
|
|
9
|
-
|
|
10
9
|
|
|
11
10
|
const rect = Rect.prototype
|
|
12
11
|
const group = Group.prototype
|
|
@@ -19,17 +18,16 @@ export class Box extends Group implements IBox {
|
|
|
19
18
|
|
|
20
19
|
public get __tag() { return 'Box' }
|
|
21
20
|
|
|
21
|
+
public get isBranchLeaf(): boolean { return true }
|
|
22
|
+
|
|
22
23
|
@dataProcessor(BoxData)
|
|
23
24
|
declare public __: IBoxData
|
|
24
25
|
|
|
25
26
|
@affectRenderBoundsType('show')
|
|
26
27
|
declare public overflow: IOverflow
|
|
27
28
|
|
|
28
|
-
public get resizeable(): boolean { return true }
|
|
29
|
-
|
|
30
29
|
constructor(data?: IBoxInputData) {
|
|
31
30
|
super(data)
|
|
32
|
-
this.isBranchLeaf = true
|
|
33
31
|
this.__layout.renderChanged || this.__layout.renderChange()
|
|
34
32
|
}
|
|
35
33
|
|
|
@@ -40,15 +38,29 @@ export class Box extends Group implements IBox {
|
|
|
40
38
|
public __updateRectRenderSpread(): number { return 0 }
|
|
41
39
|
|
|
42
40
|
public __updateRenderSpread(): number {
|
|
43
|
-
|
|
44
|
-
this.__.__drawAfterFill = this.__.overflow === 'hide'
|
|
45
|
-
|
|
46
|
-
return width
|
|
41
|
+
const width = this.__updateRectRenderSpread()
|
|
42
|
+
const hide = this.__.__drawAfterFill = this.__.overflow === 'hide'
|
|
43
|
+
return (width || hide) ? width : -1
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
|
|
50
47
|
@rewrite(rect.__updateBoxBounds)
|
|
51
|
-
public
|
|
48
|
+
public __updateRectBoxBounds(): void { }
|
|
49
|
+
|
|
50
|
+
public __updateBoxBounds(): void {
|
|
51
|
+
const data = this.__
|
|
52
|
+
if (data.__autoSide && this.children.length) {
|
|
53
|
+
if (this.leafer) this.leafer.layouter.addExtra(this)
|
|
54
|
+
super.__updateBoxBounds()
|
|
55
|
+
if (!data.__autoSize) {
|
|
56
|
+
const b = this.__layout.boxBounds
|
|
57
|
+
if (!data.__autoWidth) b.x = 0, b.width = data.width
|
|
58
|
+
if (!data.__autoHeight) b.y = 0, b.height = data.height
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
this.__updateRectBoxBounds()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
52
64
|
|
|
53
65
|
@rewrite(rect.__updateStrokeBounds)
|
|
54
66
|
public __updateStrokeBounds(): void { }
|
|
@@ -63,7 +75,6 @@ export class Box extends Group implements IBox {
|
|
|
63
75
|
}
|
|
64
76
|
}
|
|
65
77
|
|
|
66
|
-
|
|
67
78
|
@rewrite(rect.__updateRenderBounds)
|
|
68
79
|
public __updateRectRenderBounds(): void { }
|
|
69
80
|
|
|
@@ -76,10 +87,6 @@ export class Box extends Group implements IBox {
|
|
|
76
87
|
}
|
|
77
88
|
|
|
78
89
|
|
|
79
|
-
@rewrite(rect.__drawPathByData)
|
|
80
|
-
public __drawPathByData(_drawer: IPathDrawer, _data: IPathCommandData): void { }
|
|
81
|
-
|
|
82
|
-
|
|
83
90
|
@rewrite(rect.__render)
|
|
84
91
|
public __renderRect(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
|
|
85
92
|
|
package/src/Canvas.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ILeaferCanvas, ILeaferCanvasConfig,
|
|
1
|
+
import { ILeaferCanvas, ILeaferCanvasConfig, INumber, IRenderOptions, IPointData, ICanvasContext2D, ICanvasContext2DSettings, IScreenSizeData, ISizeData, IHitType } from '@leafer/interface'
|
|
2
2
|
import { Creator, Matrix, Platform, dataProcessor, registerUI, hitType } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { ICanvas, ICanvasData, ICanvasInputData, IUI } from '@leafer-ui/interface'
|
|
5
|
-
import {
|
|
5
|
+
import { CanvasData } from '@leafer-ui/data'
|
|
6
|
+
import { resizeType } from '@leafer-ui/decorator'
|
|
6
7
|
|
|
7
8
|
import { Rect } from './Rect'
|
|
8
|
-
import { resizeType } from '@leafer-ui/decorator'
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
@registerUI()
|
|
@@ -13,21 +13,24 @@ export class Canvas extends Rect implements ICanvas {
|
|
|
13
13
|
|
|
14
14
|
public get __tag() { return 'Canvas' }
|
|
15
15
|
|
|
16
|
-
@dataProcessor(
|
|
16
|
+
@dataProcessor(CanvasData)
|
|
17
17
|
declare public __: ICanvasData
|
|
18
18
|
|
|
19
19
|
@resizeType(100)
|
|
20
|
-
declare public width:
|
|
20
|
+
declare public width: INumber
|
|
21
21
|
|
|
22
22
|
@resizeType(100)
|
|
23
|
-
declare public height:
|
|
23
|
+
declare public height: INumber
|
|
24
24
|
|
|
25
25
|
@resizeType(Platform.devicePixelRatio)
|
|
26
|
-
public pixelRatio:
|
|
26
|
+
declare public pixelRatio: INumber
|
|
27
27
|
|
|
28
28
|
@resizeType(true)
|
|
29
29
|
public smooth: boolean
|
|
30
30
|
|
|
31
|
+
@resizeType()
|
|
32
|
+
public contextSettings: ICanvasContext2DSettings
|
|
33
|
+
|
|
31
34
|
@hitType('all')
|
|
32
35
|
declare public hitFill: IHitType
|
|
33
36
|
|
|
@@ -43,18 +46,17 @@ export class Canvas extends Rect implements ICanvas {
|
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
public draw(ui: IUI, offset?: IPointData, scale?: number | IPointData, rotation?: number): void {
|
|
46
|
-
ui.__layout.
|
|
49
|
+
ui.__layout.update()
|
|
47
50
|
|
|
48
|
-
const matrix = new Matrix(ui.__world)
|
|
49
|
-
matrix.invert()
|
|
51
|
+
const matrix = new Matrix(ui.__world).invert()
|
|
50
52
|
|
|
51
53
|
const m = new Matrix()
|
|
52
54
|
if (offset) m.translate(offset.x, offset.y)
|
|
53
55
|
if (scale) typeof scale === 'number' ? m.scale(scale) : m.scale(scale.x, scale.y)
|
|
54
56
|
if (rotation) m.rotate(rotation)
|
|
55
|
-
matrix.
|
|
57
|
+
matrix.multiplyParent(m)
|
|
56
58
|
|
|
57
|
-
ui.__render(this.canvas, { matrix })
|
|
59
|
+
ui.__render(this.canvas, { matrix: matrix.withScale() })
|
|
58
60
|
this.paint()
|
|
59
61
|
}
|
|
60
62
|
|
package/src/Ellipse.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PathCommandDataHelper, dataProcessor, pathType, registerUI } from '@leafer/core'
|
|
1
|
+
import { INumber } from '@leafer/interface'
|
|
2
|
+
import { PathCommandDataHelper, Platform, dataProcessor, pathType, registerUI } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { IEllipse, IEllipseInputData, IEllipseData } from '@leafer-ui/interface'
|
|
5
5
|
import { EllipseData } from '@leafer-ui/data'
|
|
@@ -18,13 +18,13 @@ export class Ellipse extends UI implements IEllipse {
|
|
|
18
18
|
declare public __: IEllipseData
|
|
19
19
|
|
|
20
20
|
@pathType(0)
|
|
21
|
-
public innerRadius:
|
|
21
|
+
public innerRadius: INumber
|
|
22
22
|
|
|
23
23
|
@pathType(0)
|
|
24
|
-
public startAngle:
|
|
24
|
+
public startAngle: INumber
|
|
25
25
|
|
|
26
26
|
@pathType(0)
|
|
27
|
-
public endAngle:
|
|
27
|
+
public endAngle: INumber
|
|
28
28
|
|
|
29
29
|
constructor(data?: IEllipseInputData) {
|
|
30
30
|
super(data)
|
|
@@ -48,9 +48,12 @@ export class Ellipse extends UI implements IEllipse {
|
|
|
48
48
|
ellipse(path, rx, ry, rx * innerRadius, ry * innerRadius)
|
|
49
49
|
moveTo(path, width, ry)
|
|
50
50
|
}
|
|
51
|
-
ellipse(path, rx, ry, rx, ry, 0,
|
|
51
|
+
ellipse(path, rx, ry, rx, ry, 0, 360, 0, true)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
// fix node
|
|
55
|
+
if (Platform.ellipseToCurve) this.__.path = this.getPath(true)
|
|
56
|
+
|
|
54
57
|
} else {
|
|
55
58
|
|
|
56
59
|
if (startAngle || endAngle) {
|
package/src/Frame.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dataProcessor, registerUI, affectRenderBoundsType } from '@leafer/core'
|
|
1
|
+
import { dataProcessor, registerUI, affectRenderBoundsType, surfaceType } from '@leafer/core'
|
|
3
2
|
|
|
4
|
-
import { IFrame, IFrameData, IFrameInputData, IOverflow } from '@leafer-ui/interface'
|
|
3
|
+
import { IFrame, IFrameData, IFrameInputData, IFill, IOverflow } from '@leafer-ui/interface'
|
|
5
4
|
import { FrameData } from '@leafer-ui/data'
|
|
6
5
|
|
|
7
6
|
import { Box } from './Box'
|
|
@@ -12,14 +11,18 @@ export class Frame extends Box implements IFrame {
|
|
|
12
11
|
|
|
13
12
|
public get __tag() { return 'Frame' }
|
|
14
13
|
|
|
14
|
+
public get isFrame(): boolean { return true }
|
|
15
|
+
|
|
15
16
|
@dataProcessor(FrameData)
|
|
16
17
|
declare public __: IFrameData
|
|
17
18
|
|
|
19
|
+
@surfaceType('#FFFFFF')
|
|
20
|
+
declare public fill: IFill
|
|
21
|
+
|
|
18
22
|
@affectRenderBoundsType('hide')
|
|
19
23
|
declare public overflow: IOverflow
|
|
20
24
|
|
|
21
25
|
constructor(data?: IFrameInputData) {
|
|
22
26
|
super(data)
|
|
23
|
-
if (!this.__.fill) this.__.fill = '#FFFFFF'
|
|
24
27
|
}
|
|
25
28
|
}
|
package/src/Group.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IPickOptions, IPickResult, IPointData } from '@leafer/interface'
|
|
1
2
|
import { Branch, useModule, dataProcessor, registerUI, UICreator } from '@leafer/core'
|
|
2
3
|
|
|
3
4
|
import { IGroup, IGroupData, IGroupInputData, IUI, IUIInputData } from '@leafer-ui/interface'
|
|
@@ -8,38 +9,31 @@ import { UI } from './UI'
|
|
|
8
9
|
|
|
9
10
|
@useModule(Branch)
|
|
10
11
|
@registerUI()
|
|
11
|
-
export class Group extends UI implements IGroup {
|
|
12
|
+
export class Group extends UI implements IGroup { // tip: rewrited Box
|
|
12
13
|
|
|
13
14
|
public get __tag() { return 'Group' }
|
|
14
15
|
|
|
16
|
+
public get isBranch(): boolean { return true }
|
|
17
|
+
|
|
15
18
|
@dataProcessor(GroupData)
|
|
16
19
|
declare public __: IGroupData
|
|
17
20
|
|
|
18
21
|
declare public children: IUI[]
|
|
19
22
|
|
|
20
|
-
public get resizeable(): boolean { return false }
|
|
21
|
-
|
|
22
|
-
public set mask(child: IUI) {
|
|
23
|
-
if (this.__hasMask) this.__removeMask()
|
|
24
|
-
if (child) {
|
|
25
|
-
child.isMask = true
|
|
26
|
-
this.addAt(child, 0)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
public get mask(): IUI {
|
|
30
|
-
return this.children.find(item => item.isMask)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
23
|
constructor(data?: IGroupInputData) {
|
|
34
24
|
super(data)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public reset(data?: IGroupInputData): void {
|
|
35
28
|
this.__setBranch()
|
|
29
|
+
super.reset(data)
|
|
36
30
|
}
|
|
37
31
|
|
|
38
32
|
public __setBranch(): void {
|
|
39
|
-
this.isBranch = true
|
|
40
33
|
if (!this.children) this.children = []
|
|
41
34
|
}
|
|
42
35
|
|
|
36
|
+
|
|
43
37
|
// data
|
|
44
38
|
|
|
45
39
|
public set(data: IUIInputData): void {
|
|
@@ -47,13 +41,17 @@ export class Group extends UI implements IGroup {
|
|
|
47
41
|
const { children } = data
|
|
48
42
|
delete data.children
|
|
49
43
|
|
|
50
|
-
if (!this.children)
|
|
44
|
+
if (!this.children) {
|
|
45
|
+
this.__setBranch()
|
|
46
|
+
} else {
|
|
47
|
+
this.clear()
|
|
48
|
+
}
|
|
51
49
|
|
|
52
50
|
super.set(data)
|
|
53
51
|
|
|
54
52
|
let child: IUI
|
|
55
53
|
children.forEach(childData => {
|
|
56
|
-
child = UICreator.get(childData.tag, childData) as IUI
|
|
54
|
+
child = (childData as IUI).__ ? childData as IUI : UICreator.get(childData.tag, childData) as IUI
|
|
57
55
|
this.add(child)
|
|
58
56
|
})
|
|
59
57
|
|
|
@@ -70,6 +68,12 @@ export class Group extends UI implements IGroup {
|
|
|
70
68
|
return data
|
|
71
69
|
}
|
|
72
70
|
|
|
71
|
+
|
|
72
|
+
// hit rewrite
|
|
73
|
+
|
|
74
|
+
public pick(_hitPoint: IPointData, _options?: IPickOptions): IPickResult { return undefined }
|
|
75
|
+
|
|
76
|
+
|
|
73
77
|
// add
|
|
74
78
|
|
|
75
79
|
public addAt(child: IUI, index: number): void {
|
|
@@ -94,4 +98,6 @@ export class Group extends UI implements IGroup {
|
|
|
94
98
|
|
|
95
99
|
public removeAll(_destroy?: boolean): void { }
|
|
96
100
|
|
|
101
|
+
public clear(): void { }
|
|
102
|
+
|
|
97
103
|
}
|
package/src/Image.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ILeaferImage,
|
|
1
|
+
import { ILeaferImage, IString } from '@leafer/interface'
|
|
2
2
|
import { ImageEvent, boundsType, dataProcessor, registerUI } from '@leafer/core'
|
|
3
3
|
|
|
4
|
-
import { IImage, IImageInputData, IImageData
|
|
4
|
+
import { IImage, IImageInputData, IImageData } from '@leafer-ui/interface'
|
|
5
5
|
import { ImageData } from '@leafer-ui/data'
|
|
6
6
|
|
|
7
7
|
import { Rect } from './Rect'
|
|
@@ -16,7 +16,7 @@ export class Image extends Rect implements IImage {
|
|
|
16
16
|
declare public __: IImageData
|
|
17
17
|
|
|
18
18
|
@boundsType('')
|
|
19
|
-
public url:
|
|
19
|
+
public url: IString
|
|
20
20
|
|
|
21
21
|
public get ready(): boolean { return this.image ? this.image.ready : false }
|
|
22
22
|
|
|
@@ -24,29 +24,9 @@ export class Image extends Rect implements IImage {
|
|
|
24
24
|
|
|
25
25
|
constructor(data?: IImageInputData) {
|
|
26
26
|
super(data)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let update: boolean
|
|
32
|
-
|
|
33
|
-
const { url } = this
|
|
34
|
-
const fill = this.fill as IImagePaint
|
|
35
|
-
|
|
36
|
-
if (fill) {
|
|
37
|
-
if (fill.url !== url) update = true
|
|
38
|
-
} else {
|
|
39
|
-
if (url) update = true
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (update) {
|
|
43
|
-
if (this.image) this.image = null
|
|
44
|
-
this.fill = url ? { type: 'image', mode: 'strench', url } : undefined
|
|
45
|
-
this.once(ImageEvent.LOADED, (e) => this.image = e.image)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
super.__updateBoxBounds()
|
|
49
|
-
|
|
27
|
+
this.on(ImageEvent.LOADED, (e: ImageEvent) => {
|
|
28
|
+
if (e.attrName === 'fill' && e.attrValue.url === this.url) this.image = e.image
|
|
29
|
+
})
|
|
50
30
|
}
|
|
51
31
|
|
|
52
32
|
public destroy(): void {
|