@leafer/interface 1.0.0-beta.15 → 1.0.0-beta.16

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 (42) hide show
  1. package/package.json +2 -1
  2. package/src/app/IApp.ts +6 -0
  3. package/src/app/ILeafer.ts +103 -0
  4. package/src/canvas/ICanvas.ts +334 -0
  5. package/src/canvas/ICanvasManager.ts +10 -0
  6. package/src/canvas/IHitCanvasManager.ts +9 -0
  7. package/src/canvas/ILeaferCanvas.ts +205 -0
  8. package/src/canvas/ISkiaCanvas.ts +20 -0
  9. package/src/control/IControl.ts +5 -0
  10. package/src/data/IData.ts +28 -0
  11. package/src/data/ILeafData.ts +27 -0
  12. package/src/data/IList.ts +45 -0
  13. package/src/display/IBranch.ts +10 -0
  14. package/src/display/ILeaf.ts +385 -0
  15. package/src/display/IView.ts +10 -0
  16. package/src/display/module/IBranchRender.ts +10 -0
  17. package/src/display/module/ILeafBounds.ts +23 -0
  18. package/src/display/module/ILeafDataProxy.ts +10 -0
  19. package/src/display/module/ILeafEventer.ts +18 -0
  20. package/src/display/module/ILeafHit.ts +12 -0
  21. package/src/display/module/ILeafMask.ts +12 -0
  22. package/src/display/module/ILeafMatrix.ts +8 -0
  23. package/src/display/module/ILeafRender.ts +16 -0
  24. package/src/event/IEvent.ts +111 -0
  25. package/src/event/IEventer.ts +43 -0
  26. package/src/event/IUIEvent.ts +88 -0
  27. package/src/file/IFileType.ts +2 -0
  28. package/src/function/IFunction.ts +13 -0
  29. package/src/image/IImageManager.ts +18 -0
  30. package/src/image/ILeaferImage.ts +43 -0
  31. package/src/interaction/IInteraction.ts +106 -0
  32. package/src/layout/ILeafLayout.ts +94 -0
  33. package/src/layouter/ILayouter.ts +60 -0
  34. package/src/math/IMath.ts +182 -0
  35. package/src/path/IPathCommand.ts +50 -0
  36. package/src/path/IPathDrawer.ts +41 -0
  37. package/src/platform/IPlatform.ts +49 -0
  38. package/src/plugin/IPlugin.ts +10 -0
  39. package/src/renderer/IRenderer.ts +53 -0
  40. package/src/selector/ISelector.ts +35 -0
  41. package/src/task/ITaskProcessor.ts +44 -0
  42. package/src/watcher/IWatcher.ts +34 -0
@@ -0,0 +1,182 @@
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): IPoint
14
+
15
+ toInnerOf(matrix: IMatrixData, to?: IPointData): IPoint
16
+ toOuterOf(matrix: IMatrixData, to?: IPointData): IPoint
17
+
18
+ getCenter(to: IPointData): IPointData
19
+ getDistance(to: IPointData): number
20
+ getAngle(to: IPointData): number
21
+ getAtan2(to: IPointData): number
22
+
23
+ reset(): void
24
+ }
25
+
26
+ export interface IRadiusPointData extends IPointData {
27
+ radiusX: number
28
+ radiusY: number
29
+ }
30
+
31
+ export interface ISizeData {
32
+ width: number
33
+ height: number
34
+ }
35
+ export interface ISize extends ISizeData {
36
+
37
+ }
38
+
39
+ export interface IScreenSizeData extends ISizeData {
40
+ pixelRatio?: number
41
+ }
42
+
43
+ export interface IBoundsData extends IPointData, ISizeData { }
44
+
45
+ export interface IOffsetBoundsData extends IBoundsData {
46
+ offsetX: number
47
+ offsetY: number
48
+ }
49
+
50
+ export interface IBoundsDataHandle {
51
+ (target: any): IBoundsData
52
+ }
53
+
54
+ export interface IBounds extends IBoundsData {
55
+ set(x?: number, y?: number, width?: number, height?: number): void
56
+ copy(bounds: IBoundsData): IBounds
57
+ clone(): IBounds
58
+
59
+ scale(scaleX: number, scaleY?: number): IBounds
60
+ toOuterOf(matrix: IMatrixData, to?: IBoundsData): IBounds
61
+ getFitMatrix(put: IBoundsData): IMatrix
62
+
63
+ spread(size: number): IBounds
64
+ ceil(): IBounds
65
+ unsign(): IBounds
66
+
67
+ add(bounds: IBoundsData): IBounds
68
+ addList(boundsList: IBounds[]): IBounds
69
+ setByList(boundsList: IBounds[], addMode?: boolean): IBounds
70
+ addListWithHandle(list: IObject[], boundsDataHandle: IBoundsDataHandle): IBounds
71
+ setByListWithHandle(list: IObject[], boundsDataHandle: IBoundsDataHandle, addMode: boolean): IBounds
72
+ setByPoints(points: IPointData[]): IBounds
73
+
74
+ hitPoint(point: IPointData, pointMatrix?: IMatrixData): boolean
75
+ hitRadiusPoint(point: IRadiusPointData, pointMatrix?: IMatrixWithLayoutData): boolean
76
+ hit(bounds: IBoundsData, boundsMatrix?: IMatrixData): boolean
77
+ includes(bounds: IBoundsData, boundsMatrix?: IMatrixData): boolean
78
+
79
+ intersect(bounds: IBoundsData, boundsMatrix?: IMatrixData): IBounds
80
+ getIntersect(bounds: IBoundsData, boundsMatrix?: IMatrixData): IBounds
81
+
82
+ isSame(bounds: IBoundsData): boolean
83
+ isEmpty(): boolean
84
+ reset(): void
85
+ }
86
+
87
+ export interface ITwoPointBoundsData {
88
+ minX: number
89
+ minY: number
90
+ maxX: number
91
+ maxY: number
92
+ }
93
+
94
+ export interface ITwoPointBounds extends ITwoPointBoundsData {
95
+ addPoint(x: number, y: number): void
96
+ addBounds(x: number, y: number, width: number, height: number): void
97
+ add(pointBounds: ITwoPointBoundsData): void
98
+ }
99
+
100
+
101
+ export interface IAutoBoundsData {
102
+ top?: number
103
+ right?: number
104
+ bottom?: number
105
+ left?: number
106
+
107
+ width?: number
108
+ height?: number
109
+ }
110
+
111
+
112
+ export interface IAutoBounds extends IAutoBoundsData {
113
+ set(top?: number, right?: number, bottom?: number, left?: number, width?: number, height?: number): void
114
+ copy(auto: IAutoBoundsData): void
115
+ getBoundsFrom(parent: ISizeData): IBounds
116
+ }
117
+
118
+
119
+ export interface IMatrixData {
120
+ a: number
121
+ b: number
122
+ c: number
123
+ d: number
124
+ e: number
125
+ f: number
126
+ }
127
+
128
+ export interface IMatrixDecompositionData {
129
+ x: number
130
+ y: number
131
+ scaleX: number
132
+ scaleY: number
133
+ rotation: number
134
+ skewX: number
135
+ skewY: number
136
+ }
137
+
138
+ export type IMatrixDecompositionAttr =
139
+ | 'x'
140
+ | 'y'
141
+ | 'scaleX'
142
+ | 'scaleY'
143
+ | 'rotation'
144
+ | 'skewX'
145
+ | 'skewY'
146
+
147
+ export interface IMatrix extends IMatrixData {
148
+ set(a: number, b: number, c: number, d: number, e: number, f: number): void
149
+ copy(matrix: IMatrixData): IMatrix
150
+ clone(): IMatrix
151
+
152
+ translate(x: number, y: number): IMatrix
153
+ translateInner(x: number, y: number): IMatrix
154
+
155
+ scale(x: number, y?: number): IMatrix
156
+ scaleOfOuter(origin: IPointData, x: number, y?: number): IMatrix
157
+ scaleOfInner(origin: IPointData, x: number, y?: number): IMatrix
158
+
159
+ rotate(angle: number): IMatrix
160
+ rotateOfOuter(origin: IPointData, angle: number): IMatrix
161
+ rotateOfInner(origin: IPointData, angle: number): IMatrix
162
+
163
+ skew(x: number, y?: number): IMatrix
164
+ skewOfOuter(origin: IPointData, x: number, y?: number): IMatrix
165
+ skewOfInner(origin: IPointData, x: number, y?: number): IMatrix
166
+
167
+ multiply(matrix: IMatrixData): IMatrix
168
+ divide(matrix: IMatrixData): IMatrix
169
+ preMultiply(matrix: IMatrixData): IMatrix
170
+ invert(): IMatrix
171
+
172
+ toOuterPoint(inner: IPointData, to?: IPointData, distance?: boolean): void
173
+ toInnerPoint(outer: IPointData, to?: IPointData, distance?: boolean): void
174
+
175
+ decompose(): IMatrixDecompositionData
176
+
177
+ reset(): void
178
+ }
179
+
180
+ export interface IMatrixWithBoundsData extends IMatrixData, IBoundsData { }
181
+
182
+ export interface IMatrixWithLayoutData extends IMatrixData, IMatrixDecompositionData, 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 anticlockwise = 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, anticlockwise]
44
+ export type ArcCommandData = [Command, x, y, radius, startAngle, endAngle, anticlockwise]
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,41 @@
1
+ import { IPathCommandData } from './IPathCommand'
2
+ export interface IPathDrawer {
3
+ beginPath?(): void
4
+
5
+ moveTo(x: number, y: number): void
6
+ lineTo(x: number, y: number): void
7
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void
8
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
9
+ closePath(): void
10
+
11
+ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void
12
+ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
13
+ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void
14
+
15
+ rect(x: number, y: number, width: number, height: number): void
16
+ roundRect(x: number, y: number, width: number, height: number, radius?: number | number[]): void
17
+ }
18
+
19
+ export interface IPathCreator {
20
+ path: IPathCommandData
21
+
22
+ beginPath(): IPathCreator
23
+
24
+ moveTo(x: number, y: number): IPathCreator
25
+ lineTo(x: number, y: number): IPathCreator
26
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): IPathCreator
27
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): IPathCreator
28
+ closePath(): IPathCreator
29
+
30
+ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): IPathCreator
31
+ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): IPathCreator
32
+ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean): IPathCreator
33
+
34
+ rect(x: number, y: number, width: number, height: number): IPathCreator
35
+ roundRect(x: number, y: number, width: number, height: number, radius?: number | number[]): IPathCreator
36
+
37
+ // new
38
+ drawEllipse(x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): IPathCreator
39
+ drawArc(x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): IPathCreator
40
+ drawPoints(points: number[], curve?: boolean | number, close?: boolean): IPathCreator
41
+ }
@@ -0,0 +1,49 @@
1
+ import { IFunction } from '../function/IFunction'
2
+ import { ILeaferCanvas } from '../canvas/ILeaferCanvas'
3
+ import { ILeaf } from '../display/ILeaf'
4
+ import { IExportFileType, IExportImageType } from '../file/IFileType'
5
+ import { IBoundsData, ISizeData } from '../math/IMath'
6
+ import { IObject } from '../data/IData'
7
+
8
+ export interface IPlatform {
9
+ name?: 'web' | 'node' | 'miniapp'
10
+ os?: 'Mac' | 'Windows' | 'Linux'
11
+ requestRender?(render: IFunction): void
12
+ canvas?: ILeaferCanvas
13
+ isWorker?: boolean
14
+ isMobile?: boolean
15
+ devicePixelRatio?: number
16
+ intWheelDeltaY?: boolean // firefox / Windows need
17
+ conicGradientSupport?: boolean
18
+ conicGradientRotate90?: boolean // firefox need rotate
19
+ fullImageShadow?: boolean // safari need
20
+ syncDomFont?: boolean // firefox need
21
+ layout?(target: ILeaf): void
22
+ realtimeLayout?: boolean
23
+ origin?: {
24
+ createCanvas(width: number, height: number, format?: 'svg' | 'pdf'): any
25
+ canvasToDataURL(canvas: any, type?: IExportImageType, quality?: number): string | Promise<string>
26
+ canvasToBolb(canvas: any, type?: IExportFileType, quality?: number): Promise<any>
27
+ canvasSaveAs(canvas: any, filename: string, quality?: number): Promise<void>
28
+ loadImage(url: string): Promise<any>
29
+ noRepeat?: string // fix: 微信小程序 createPattern 直接使用 no-repeat 有bug,导致无法显示
30
+ },
31
+ miniapp?: IMiniapp
32
+ imageSuffix?: string // 需要带上后缀区分dom中image标签的缓存,否则会导致浏览器缓存跨域问题
33
+ }
34
+
35
+
36
+ export interface IMiniappSelect extends IObject { }
37
+
38
+ export interface IMiniappSizeView extends ISizeData {
39
+ view: any
40
+ }
41
+
42
+ export interface IMiniapp {
43
+ select(name: string): IMiniappSelect
44
+ getBounds(select: IMiniappSelect): Promise<IBoundsData>
45
+ getSizeView(select: IMiniappSelect): Promise<IMiniappSizeView>
46
+ onWindowResize(fun: IFunction): void
47
+ offWindowResize(fun: IFunction): void
48
+ saveToAlbum(path: string): Promise<any>
49
+ }
@@ -0,0 +1,10 @@
1
+ import { ILeafer } from '../app/ILeafer'
2
+ import { IObject } from '../data/IData'
3
+
4
+ export interface IPlugin extends IObject {
5
+ name?: string
6
+ importVersion: string
7
+ import: string[]
8
+ run(LeaferUI: IObject, config: IObject): void
9
+ onLeafer?(leafer: ILeafer): void
10
+ }
@@ -0,0 +1,53 @@
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 { IControl } from '../control/IControl'
6
+
7
+ export interface IRenderOptions {
8
+ bounds?: IBounds,
9
+ hideBounds?: IBounds,
10
+ matrix?: IMatrix,
11
+ inCamera?: boolean
12
+ }
13
+
14
+ export interface IRendererConfig {
15
+ usePartRender?: boolean
16
+ maxFPS?: number
17
+ fill?: string
18
+ }
19
+
20
+ export interface IRenderer extends IControl {
21
+ target: ILeaf
22
+ canvas: ILeaferCanvas
23
+ updateBlocks: IBounds[]
24
+
25
+ FPS: number
26
+ totalTimes: number
27
+ times: number
28
+
29
+ running: boolean
30
+ rendering: boolean
31
+
32
+ waitAgain: boolean
33
+ changed: boolean
34
+
35
+ config: IRendererConfig
36
+
37
+ update(): void
38
+
39
+ requestLayout(): void
40
+
41
+ render(callback?: IFunction): void
42
+ renderAgain(): void
43
+ renderOnce(callback?: IFunction): void
44
+ partRender(): void
45
+ clipRender(bounds: IBounds): void
46
+ fullRender(): void
47
+
48
+ renderHitView(options: IRenderOptions): void
49
+ renderBoundsView(options: IRenderOptions): void
50
+
51
+ addBlock(block: IBounds): void
52
+ mergeBlocks(): void
53
+ }
@@ -0,0 +1,35 @@
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
+ name?: string
13
+ through?: boolean
14
+ exclude?: ILeafList
15
+ ignoreHittable?: boolean
16
+ }
17
+
18
+ export interface ISelectorConfig {
19
+
20
+ }
21
+
22
+ export interface ISelector {
23
+ target: ILeaf
24
+
25
+ config: ISelectorConfig
26
+
27
+ getByPoint(hitPoint: IPointData, hitRadius: number, options?: ISelectPathOptions): ISelectPathResult
28
+
29
+ find(name: number | string, branch?: ILeaf): ILeaf | ILeaf[]
30
+ getByInnerId(name: number, branch?: ILeaf): ILeaf
31
+ getById(name: string, branch?: ILeaf): ILeaf
32
+ getByClassName(name: string, branch?: ILeaf): ILeaf[]
33
+ getByTagName(name: string, branch?: ILeaf): ILeaf[]
34
+ destroy(): void
35
+ }
@@ -0,0 +1,44 @@
1
+ import { IFunction } from '../function/IFunction'
2
+
3
+ export interface ITaskProcessorConfig {
4
+ onComplete?: IFunction
5
+ onTask?: IFunction
6
+ onError?: IFunction
7
+ parallel?: number
8
+ }
9
+
10
+ export interface ITaskProcessor {
11
+ config: ITaskProcessorConfig
12
+ running: boolean
13
+ isComplete: boolean
14
+ percent: number
15
+ total: number
16
+ index: number
17
+ finishedIndex: number
18
+ remain: number
19
+ start(): void
20
+ pause(): void
21
+ resume(): void
22
+ skip(): void
23
+ stop(): void
24
+ add(taskCallback: IFunction, options?: ITaskOptions | number): ITaskItem
25
+ destroy(): void
26
+ }
27
+
28
+ export interface ITaskItem {
29
+ parent: ITaskProcessor
30
+ parallel: boolean
31
+ isComplete: boolean
32
+ isCancel: boolean
33
+ time: number
34
+ run(): Promise<void>
35
+ complete(): void
36
+ cancel(): void
37
+ }
38
+
39
+ export interface ITaskOptions {
40
+ start?: boolean // default true
41
+ time?: number // default 1
42
+ parallel?: boolean // default true
43
+ delay?: number // default 0
44
+ }
@@ -0,0 +1,34 @@
1
+ import { ILeaf } from '../display/ILeaf'
2
+ import { ILeafList } from '../data/IList'
3
+ import { IControl } from '../control/IControl'
4
+
5
+ export interface IWatchEventData {
6
+ updatedList: ILeafList
7
+ }
8
+
9
+ export interface IWatcherConfig {
10
+
11
+ }
12
+
13
+ export interface IWatcher extends IControl {
14
+ target: ILeaf
15
+
16
+ totalTimes: number
17
+
18
+ disabled: boolean
19
+ running: boolean
20
+ changed: boolean
21
+
22
+ hasVisible: boolean
23
+ hasAdd: boolean
24
+ hasRemove: boolean
25
+ readonly childrenChanged: boolean
26
+
27
+ config: IWatcherConfig
28
+
29
+ updatedList: ILeafList
30
+
31
+ disable(): void
32
+
33
+ update(): void
34
+ }