@leafer/interface 1.0.0-alpha.1

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.
Files changed (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/package.json +19 -0
  4. package/src/app/ILeafer.ts +74 -0
  5. package/src/app/ISupperLeafer.ts +5 -0
  6. package/src/canvas/ICanvas.ts +344 -0
  7. package/src/canvas/ICanvasManager.ts +10 -0
  8. package/src/canvas/ICanvasPathDrawer.ts +16 -0
  9. package/src/canvas/IHitCanvasManager.ts +10 -0
  10. package/src/canvas/ILeaferCanvas.ts +163 -0
  11. package/src/data/IData.ts +27 -0
  12. package/src/data/ILeafData.ts +17 -0
  13. package/src/data/IList.ts +45 -0
  14. package/src/display/IBranch.ts +9 -0
  15. package/src/display/ILeaf.ts +191 -0
  16. package/src/display/IView.ts +9 -0
  17. package/src/display/module/ILeafBounds.ts +21 -0
  18. package/src/display/module/ILeafDataProxy.ts +11 -0
  19. package/src/display/module/ILeafEventer.ts +18 -0
  20. package/src/display/module/ILeafHit.ts +10 -0
  21. package/src/display/module/ILeafMatrix.ts +8 -0
  22. package/src/display/module/ILeafRender.ts +17 -0
  23. package/src/event/IEvent.ts +89 -0
  24. package/src/event/IEventer.ts +43 -0
  25. package/src/event/IUIEvent.ts +69 -0
  26. package/src/function/IFunction.ts +13 -0
  27. package/src/image/IImageManager.ts +3 -0
  28. package/src/image/ILeaferImage.ts +8 -0
  29. package/src/index.ts +48 -0
  30. package/src/interaction/IInteraction.ts +53 -0
  31. package/src/layout/ILeafLayout.ts +87 -0
  32. package/src/layouter/ILayouter.ts +52 -0
  33. package/src/math/IMath.ts +141 -0
  34. package/src/path/IPathCommand.ts +50 -0
  35. package/src/platform/IPlatform.ts +7 -0
  36. package/src/plugin/IPlugin.ts +11 -0
  37. package/src/renderer/IRenderer.ts +37 -0
  38. package/src/selector/ISelector.ts +28 -0
  39. package/src/watcher/IWatcher.ts +25 -0
@@ -0,0 +1,53 @@
1
+ import { INumberFunction, IPointDataFunction } from '../function/IFunction'
2
+ import { IPointerEvent, IMoveEvent, IZoomEvent, IRotateEvent } from '../event/IUIEvent'
3
+ import { ILeaf } from '../display/ILeaf'
4
+ import { IPointData } from '../math/IMath'
5
+
6
+ export interface IInteraction {
7
+ target: ILeaf
8
+ config: IInteractionConfig
9
+ running: boolean
10
+
11
+ pointerMoveIgnore: boolean
12
+
13
+ start(): void
14
+ stop(): void
15
+
16
+ pointerDown(data: IPointerEvent): void
17
+ pointerMove(data: IPointerEvent): void
18
+ pointerUp(data: IPointerEvent): void
19
+ pointerCancel(): void
20
+
21
+ move(data: IMoveEvent): void
22
+ zoom(data: IZoomEvent): void
23
+ rotate(data: IRotateEvent): void
24
+
25
+ destroy(): void
26
+ }
27
+
28
+ export interface IInteractionConfig {
29
+ wheel?: IWheelConfig
30
+ pointer?: IPointerConfig
31
+
32
+ }
33
+
34
+ export interface IWheelConfig {
35
+ zoomMode?: boolean
36
+ zoomSpeed?: number // 取值范围 0 ~ 1, 默认0.5
37
+ moveSpeed?: number
38
+ rotateSpeed?: number // 取值范围 0 ~ 1, 默认0.5
39
+ delta?: IPointData
40
+ getScale?: INumberFunction
41
+ getMove?: IPointDataFunction
42
+ }
43
+
44
+ export interface IPointerConfig {
45
+ hitRadius?: number
46
+ through?: boolean
47
+ clickTime?: number
48
+ longPressTime?: number
49
+ transformTime?: number
50
+ dragDistance?: number
51
+ swipeDistance?: number
52
+ autoMoveDistance?: number
53
+ }
@@ -0,0 +1,87 @@
1
+ import { IBoundsData, IMatrixData } from '../math/IMath'
2
+ import { ILeaf } from '../display/ILeaf'
3
+
4
+ export type ILayoutLocationType = 'world' | 'relative' | 'local'
5
+ export type ILayoutBoundsType = 'content' | 'box' | 'event' | 'margin' | 'render'
6
+
7
+ export interface ILeafLayout {
8
+
9
+ leaf: ILeaf
10
+
11
+ useZoomProxy: boolean
12
+
13
+ // local
14
+
15
+ boxBounds: IBoundsData // | content + padding |
16
+ eventBounds: IBoundsData // | boxBounds + border |
17
+ renderBounds: IBoundsData // | eventBounds + shadow |
18
+
19
+ // auto layout
20
+ marginBounds: IBoundsData // | eventBounds + margin |
21
+ contentBounds: IBoundsData // | content |
22
+
23
+ // relative
24
+
25
+ //relativeBoxBounds: IBoundsData = leaf.__local
26
+ relativeEventBounds: IBoundsData
27
+ relativeRenderBounds: IBoundsData
28
+
29
+ // state
30
+
31
+ // matrix changed
32
+ matrixChanged: boolean
33
+ positionChanged: boolean // x, y
34
+ scaleChanged: boolean // scaleX scaleY
35
+ rotationChanged: boolean // rotaiton, skewX scaleY 数据更新
36
+
37
+ // bounds changed
38
+ boundsChanged: boolean
39
+
40
+ boxBoundsChanged: boolean
41
+ eventBoundsChanged: boolean
42
+ renderBoundsChanged: boolean
43
+
44
+ localBoxBoundsChanged: boolean // position
45
+
46
+ // face changed
47
+ surfaceChanged: boolean
48
+ opacityChanged: boolean
49
+
50
+ hitCanvasChanged: boolean
51
+
52
+ childrenSortChanged?: boolean
53
+
54
+ // keep state
55
+ affectScaleOrRotation: boolean
56
+ affectRotation: boolean
57
+ eventBoundsSpreadWidth: number
58
+ renderBoundsSpreadWidth: number
59
+ renderShapeBoundsSpreadWidth: number
60
+
61
+ update(): void
62
+
63
+ getTransform(type: ILayoutLocationType): IMatrixData
64
+ getBounds(type: ILayoutLocationType, boundsType: ILayoutBoundsType): IBoundsData
65
+
66
+ // 独立 / 引用 boxBounds
67
+ eventBoundsSpread(): void
68
+ renderBoundsSpread(): void
69
+ eventBoundsSpreadCancel(): void
70
+ renderBoundsSpreadCancel(): void
71
+
72
+ // bounds
73
+ boxBoundsChange(): void
74
+ eventBoundsChange(): void
75
+ renderBoundsChange(): void
76
+
77
+ // matrix
78
+ positionChange(): void
79
+ scaleChange(): void
80
+ rotationChange(): void
81
+
82
+ // face
83
+ surfaceChange(): void
84
+ opacityChange(): void
85
+
86
+ destroy(): void
87
+ }
@@ -0,0 +1,52 @@
1
+ import { IBounds } from '../math/IMath'
2
+ import { ILeaf } from '../display/ILeaf'
3
+ import { ILeafList } from '../data/IList'
4
+
5
+ export interface ILayoutChangedData {
6
+ matrixList: ILeaf[]
7
+ boundsList: ILeaf[]
8
+ surfaceList: ILeaf[]
9
+ }
10
+
11
+ export interface ILayoutBlockData {
12
+ updatedList: ILeafList
13
+ updatedBounds: IBounds
14
+
15
+ beforeBounds: IBounds
16
+ afterBounds: IBounds
17
+
18
+ setBefore?(): void
19
+ setAfter?(): void
20
+ merge?(data: ILayoutBlockData): void
21
+ destroy(): void
22
+ }
23
+
24
+ export interface IPartLayoutConfig {
25
+ maxBlocks?: number
26
+ maxTimes?: number
27
+ }
28
+
29
+ export interface ILayouterConfig {
30
+ partLayout?: IPartLayoutConfig
31
+ }
32
+
33
+ export interface ILayouter {
34
+ target: ILeaf
35
+ layoutedBlocks: ILayoutBlockData[]
36
+ totalTimes: number
37
+ times: number
38
+ config: ILayouterConfig
39
+ running: boolean
40
+
41
+ start(): void
42
+ stop(): void
43
+
44
+ createBlock(data: ILeafList | ILeaf[]): ILayoutBlockData
45
+ getBlocks(list: ILeafList): ILayoutBlockData[]
46
+ setBlocks(current: ILayoutBlockData[]): void
47
+
48
+ layout(): void
49
+ partLayout(): void
50
+ fullLayout(): void
51
+ destroy(): void
52
+ }
@@ -0,0 +1,141 @@
1
+ import { IObject } from '../data/IData'
2
+
3
+ export interface IPointData {
4
+ x: number
5
+ y: number
6
+ }
7
+
8
+ export interface IPoint extends IPointData {
9
+ set(x?: number, y?: number): void
10
+ copy(point: IPointData): IPoint
11
+ clone(): IPoint
12
+
13
+ rotate(angle: number, center?: IPointData): void
14
+
15
+ toLocal(matrix: IMatrixData): void
16
+ toWorld(matrix: IMatrixData): void
17
+
18
+ getCenter(to: IPointData): IPointData
19
+ getDistance(to: IPointData): number
20
+ getAngle(to: IPointData): number
21
+ getAtan2(to: IPointData): number
22
+ }
23
+
24
+ export interface IRadiusPointData extends IPointData {
25
+ radiusX: number
26
+ radiusY: number
27
+ }
28
+
29
+ export interface ISizeData {
30
+ width: number
31
+ height: number
32
+ }
33
+ export interface ISize extends ISizeData {
34
+
35
+ }
36
+
37
+ export interface IScreenSizeData extends ISizeData {
38
+ pixelRatio?: number
39
+ }
40
+
41
+ export interface IBoundsData extends IPointData, ISizeData { }
42
+
43
+ export interface IOffsetBoundsData extends IBoundsData {
44
+ offsetX: number
45
+ offsetY: number
46
+ }
47
+
48
+ export interface IBoundsDataHandle {
49
+ (target: any): IBoundsData
50
+ }
51
+
52
+ export interface IBounds extends IBoundsData {
53
+ set(x?: number, y?: number, width?: number, height?: number): void
54
+ copy(bounds: IBoundsData): IBounds
55
+ clone(): IBounds
56
+
57
+ timesMatrix(matrix: IMatrixData): IBounds
58
+ divideMatrix(matrix: IMatrixData): IBounds
59
+ getFitMatrix(put: IBoundsData): IMatrix
60
+ spread(size: number): void
61
+ ceil(): void
62
+
63
+ add(bounds: IBoundsData): void
64
+ addList(boundsList: IBounds[]): void
65
+ setByList(boundsList: IBounds[], addMode?: boolean): void
66
+ addListWithHandle(list: IObject[], boundsDataHandle: IBoundsDataHandle): void
67
+ setByListWithHandle(list: IObject[], boundsDataHandle: IBoundsDataHandle, addMode: boolean): void
68
+ setByBoundsTimesMatrix(fromBounds: IBoundsData, fromMatrix: IMatrixData): void
69
+ setByPoints(points: IPointData[]): void
70
+
71
+ hitPoint(point: IPointData, pointMatrix?: IMatrixData): boolean
72
+ hitRadiusPoint(point: IRadiusPointData, pointMatrix?: IMatrixData): boolean
73
+ hit(bounds: IBoundsData, boundsMatrix?: IMatrixData): boolean
74
+ includes(bounds: IBoundsData, boundsMatrix?: IMatrixData): boolean
75
+
76
+ getIntersect(bounds: IBoundsData, boundsMatrix?: IMatrixData): IBounds
77
+ setByIntersect(bounds: IBoundsData, boundsMatrix?: IMatrixData): void
78
+
79
+ isSame(bounds: IBoundsData): boolean
80
+ isEmpty(): boolean
81
+ empty(): void
82
+ }
83
+
84
+ export interface ITwoPointBoundsData {
85
+ minX: number
86
+ minY: number
87
+ maxX: number
88
+ maxY: number
89
+ }
90
+
91
+ export interface ITwoPointBounds extends ITwoPointBoundsData {
92
+ addPoint(x: number, y: number): void
93
+ add(pointBounds: ITwoPointBoundsData): void
94
+ }
95
+
96
+
97
+ export interface IAutoBoundsData {
98
+ top?: number
99
+ right?: number
100
+ bottom?: number
101
+ left?: number
102
+
103
+ width?: number
104
+ height?: number
105
+ }
106
+
107
+
108
+ export interface IAutoBounds extends IAutoBoundsData {
109
+ set(top?: number, right?: number, bottom?: number, left?: number, width?: number, height?: number): void
110
+ copy(auto: IAutoBoundsData): void
111
+ getBoundsFrom(parent: ISizeData): IBounds
112
+ }
113
+
114
+
115
+ export interface IMatrixData {
116
+ a: number
117
+ b: number
118
+ c: number
119
+ d: number
120
+ e: number
121
+ f: number
122
+ }
123
+ export interface IMatrix extends IMatrixData {
124
+ set(a: number, b: number, c: number, d: number, e: number, f: number): void
125
+ copy(matrix: IMatrixData): IMatrix
126
+ clone(): IMatrix
127
+
128
+ translate(x: number, y: number): IMatrix
129
+ scale(x: number, y?: number): IMatrix
130
+ rotate(angle: number): IMatrix
131
+
132
+ times(matrix: IMatrixData): void
133
+ divide(matrix: IMatrixData): void
134
+ invert(): void
135
+
136
+ toWorldPoint(local: IPointData, world?: IPointData): void
137
+ toLocalPoint(world: IPointData, local?: IPointData): void
138
+ }
139
+
140
+
141
+ export interface IMatrixWithBoundsData extends IMatrixData, IBoundsData { }
@@ -0,0 +1,50 @@
1
+ type Command = number
2
+ type x = number
3
+ type y = number
4
+ type x1 = number
5
+ type y1 = number
6
+ type x2 = number
7
+ type y2 = number
8
+ type radiusX = number
9
+ type radiusY = number
10
+ type xAxisRotation = number
11
+ type largeArcFlag = number
12
+ type sweepFlag = number
13
+
14
+
15
+ export type MCommandData = [Command, x, y]
16
+ export type HCommandData = [Command, x]
17
+ export type VCommandData = [Command, y]
18
+ export type LCommandData = MCommandData
19
+
20
+ export type CCommandData = [Command, x1, y1, x2, y2, x, y]
21
+ export type SCommandData = [Command, x2, y2, x, y]
22
+
23
+ export type QCommandData = [Command, x1, y1, x, y]
24
+ export type TCommandData = [Command, x, y]
25
+
26
+ export type ZCommandData = [Command]
27
+
28
+ export type ACommandData = [Command, radiusX, radiusY, xAxisRotation, largeArcFlag, sweepFlag, x, y]
29
+
30
+
31
+ // 非svg标准的canvas绘图命令
32
+ type width = number
33
+ type height = number
34
+ type rotation = number
35
+ type startAngle = number
36
+ type endAngle = number
37
+ type counterclockwise = boolean
38
+ type cornerRadius = number | number[]
39
+ type radius = number
40
+
41
+ export type RectCommandData = [Command, x, y, width, height]
42
+ export type RoundRectCommandData = [Command, x, y, width, height, cornerRadius]
43
+ export type EllipseCommandData = [Command, x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise]
44
+ export type ArcCommandData = [Command, x, y, radius, startAngle, endAngle, counterclockwise]
45
+ export type ArcToCommandData = [Command, x1, y1, x2, y2, radius]
46
+
47
+
48
+ export type CanvasPathCommand = 1 | 2 | 5 | 7 | 11 // M | L | C | Q | Z canvas可以绘制的命令
49
+
50
+ export type IPathCommandData = number[] // ...(MCommandData | LCommandData | CCommandData | QCommandData | ZCommandData)
@@ -0,0 +1,7 @@
1
+ import { IFunction } from '../function/IFunction'
2
+ import { ILeaferCanvas } from '../canvas/ILeaferCanvas'
3
+
4
+ export interface IPlatform {
5
+ requestRender?(render: IFunction): void
6
+ canvas?: ILeaferCanvas
7
+ }
@@ -0,0 +1,11 @@
1
+ import { IObject } from '../data/IData'
2
+
3
+ export interface IPlugin {
4
+ name: string
5
+ version: string
6
+ author: string
7
+ license: string
8
+ description: string
9
+ dependencies: string[]
10
+ run(params: IObject): void
11
+ }
@@ -0,0 +1,37 @@
1
+ import { ILeaferCanvas } from '../canvas/ILeaferCanvas'
2
+ import { ILeaf } from '../display/ILeaf'
3
+ import { IBounds, IMatrix } from '../math/IMath'
4
+ import { IFunction } from '../function/IFunction'
5
+ import { ILayoutBlockData } from '../layouter/ILayouter'
6
+
7
+ export interface IRenderOptions {
8
+ bounds?: IBounds,
9
+ hideBounds?: IBounds,
10
+ matrix?: IMatrix,
11
+ inCamera?: boolean
12
+ }
13
+
14
+ export interface IRendererConfig {
15
+ maxFPS?: number
16
+ }
17
+
18
+ export interface IRenderer {
19
+ canvas: ILeaferCanvas
20
+ target: ILeaf
21
+ layoutedBlocks: ILayoutBlockData[]
22
+ running: boolean
23
+ totalTimes: number
24
+ times: number
25
+ config: IRendererConfig
26
+
27
+ FPS: number
28
+
29
+ start(): void
30
+ stop(): void
31
+
32
+ requestLayout(): void
33
+ render(callback?: IFunction): void
34
+ clipRender(bounds: IBounds): void
35
+ fullRender(bounds?: IBounds): void
36
+ destroy(): void
37
+ }
@@ -0,0 +1,28 @@
1
+ import { ILeaf } from '../display/ILeaf'
2
+ import { ILeafList } from '../data/IList'
3
+ import { IPointData } from '../math/IMath'
4
+
5
+ export interface ISelectPathResult {
6
+ leaf: ILeaf
7
+ path: ILeafList
8
+ throughPath?: ILeafList
9
+ }
10
+
11
+ export interface ISelectPathOptions {
12
+ through?: boolean
13
+ exclude?: ILeafList
14
+ }
15
+
16
+ export interface ISelector {
17
+ target: ILeaf
18
+
19
+ defaultPath: ILeafList
20
+ getHitPointPath(hitPoint: IPointData, hitRadius: number, options?: ISelectPathOptions): ISelectPathResult
21
+
22
+ find(name: number | string, branch?: ILeaf): ILeaf | ILeaf[]
23
+ getByInnerId(name: number, branch?: ILeaf): ILeaf
24
+ getById(name: string, branch?: ILeaf): ILeaf
25
+ getByClassName(name: string, branch?: ILeaf): ILeaf[]
26
+ getByTagName(name: string, branch?: ILeaf): ILeaf[]
27
+ destroy(): void
28
+ }
@@ -0,0 +1,25 @@
1
+ import { ILeaf } from '../display/ILeaf'
2
+ import { ILeafList } from '../data/IList'
3
+
4
+ export interface IWatchEventData {
5
+ updatedList: ILeafList
6
+ }
7
+
8
+ export interface IWatcherConfig {
9
+
10
+ }
11
+
12
+ export interface IWatcher {
13
+ target: ILeaf
14
+ updatedList: ILeafList
15
+ totalTimes: number
16
+ config: IWatcherConfig
17
+ running: boolean
18
+ changed: boolean
19
+
20
+ start(): void
21
+ stop(): void
22
+
23
+ update(): void
24
+ destroy(): void
25
+ }