@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,111 @@
1
+ import { IEventer } from './IEventer'
2
+ import { IWatchEventData } from '../watcher/IWatcher'
3
+ import { ILayoutBlockData } from '../layouter/ILayouter'
4
+ import { ILeaf } from '../display/ILeaf'
5
+ import { IScreenSizeData, IPointData } from '../math/IMath'
6
+
7
+ export interface IEvent {
8
+ type?: string
9
+ target?: IEventTarget
10
+ current?: IEventTarget
11
+
12
+ bubbles?: boolean
13
+ phase?: number
14
+
15
+ isStopDefault?: boolean
16
+ isStop?: boolean
17
+ isStopNow?: boolean
18
+ stopDefault?(): void
19
+ stopNow?(): void
20
+ stop?(): void
21
+ }
22
+
23
+ export interface IEventTarget extends IEventer {
24
+
25
+ }
26
+
27
+ export interface ILeaferEvent {
28
+
29
+ }
30
+
31
+ export interface IRenderEvent {
32
+
33
+ }
34
+
35
+ export interface IAnimateEvent {
36
+
37
+ }
38
+
39
+ export interface IChildEvent extends IEvent {
40
+ parent?: ILeaf
41
+ child?: ILeaf
42
+ }
43
+
44
+ export interface IResizeEvent extends IEvent {
45
+ readonly width: number
46
+ readonly height: number
47
+ readonly pixelRatio: number
48
+
49
+ readonly bigger: boolean
50
+ readonly smaller: boolean
51
+ readonly samePixelRatio: boolean
52
+ readonly old: IScreenSizeData
53
+ }
54
+
55
+ export interface IResizeEventListener {
56
+ (event: IResizeEvent): void
57
+ }
58
+
59
+ export interface IUpdateEvent extends IEvent {
60
+
61
+ }
62
+
63
+ export interface IPropertyEvent extends IEvent {
64
+ readonly attrName: string
65
+ readonly oldValue: unknown
66
+ readonly newValue: unknown
67
+ }
68
+
69
+ export interface ILayoutEvent extends IEvent {
70
+ readonly data: ILayoutBlockData[]
71
+ readonly times: number
72
+ }
73
+
74
+ export interface IWatchEvent extends IEvent {
75
+ readonly data: IWatchEventData
76
+ }
77
+
78
+ export interface ITransformEventData {
79
+ x: number
80
+ y: number
81
+ scaleX: number
82
+ scaleY: number
83
+ rotation: number
84
+
85
+ readonly zooming: boolean
86
+ readonly moving: boolean
87
+ readonly rotating: boolean
88
+ readonly changing: boolean
89
+ }
90
+
91
+ export interface ITransformEvent extends IEvent, ITransformEventData {
92
+ readonly x: number
93
+ readonly y: number
94
+ readonly scaleX: number
95
+ readonly scaleY: number
96
+ readonly rotation: number
97
+ }
98
+ export type TransformMode = 'move' | 'zoom' | 'rotate'
99
+
100
+
101
+ export interface IMultiTouchData {
102
+ move: IPointData,
103
+ scale: number,
104
+ angle: number,
105
+ center: IPointData
106
+ }
107
+
108
+ export interface IKeepTouchData {
109
+ from: IPointData
110
+ to: IPointData
111
+ }
@@ -0,0 +1,43 @@
1
+ import { IEvent, IFunction, IObject } from '@leafer/interface'
2
+ import { ILeafEventer } from '../display/module/ILeafEventer'
3
+
4
+ export type IEventListener = IFunction
5
+
6
+ export interface IEventListenerOptions {
7
+ capture?: boolean
8
+ once?: boolean
9
+ }
10
+
11
+ export interface IEventListenerItem extends IEventListenerOptions {
12
+ listener: IEventListener
13
+ }
14
+
15
+ export interface IEventListenerMap {
16
+ [name: string]: IEventListenerItem[]
17
+ }
18
+
19
+ export interface IEventListenerId {
20
+ type: string | string[]
21
+ listener: IEventListener
22
+ options?: IEventListenerOptions | boolean
23
+ }
24
+
25
+ export type InnerId = number
26
+
27
+ export interface IEventer extends ILeafEventer {
28
+
29
+ readonly innerId: InnerId
30
+ __captureMap?: IEventListenerMap
31
+ __bubbleMap?: IEventListenerMap
32
+
33
+ on(type: string | string[], listener: IEventListener, options?: IEventListenerOptions | boolean): void
34
+ off(type: string | string[], listener: IEventListener, options?: IEventListenerOptions | boolean): void
35
+ on_(type: string | string[], listener: IEventListener, bind?: IObject, options?: IEventListenerOptions | boolean): IEventListenerId
36
+ off_(id: IEventListenerId | IEventListenerId[]): void
37
+ once(type: string | string[], listener: IEventListener): void
38
+ emit(type: string, event?: IEvent | IObject, capture?: boolean): void
39
+ emitEvent(event?: IEvent, capture?: boolean): void
40
+ hasEvent(type: string, capture?: boolean): boolean
41
+
42
+ destroy(): void
43
+ }
@@ -0,0 +1,88 @@
1
+ import { IObject } from '../data/IData'
2
+ import { ILeafList } from '../data/IList'
3
+ import { IEvent } from './IEvent'
4
+ import { ILeaferImage } from '../image/ILeaferImage'
5
+ import { ILeaf } from '../display/ILeaf'
6
+ import { IPointData } from '../math/IMath'
7
+
8
+ export interface IUIEvent extends IEvent {
9
+ x: number
10
+ y: number
11
+
12
+ altKey?: boolean
13
+ ctrlKey?: boolean
14
+ shiftKey?: boolean
15
+ metaKey?: boolean
16
+ readonly spaceKey?: boolean
17
+
18
+ readonly left?: boolean
19
+ readonly right?: boolean
20
+ readonly middle?: boolean
21
+ buttons?: number
22
+
23
+ path?: ILeafList
24
+ throughPath?: ILeafList // 穿透path,不受层级影响,从上到下只要碰撞到区域就算,一般点击的时候
25
+
26
+ origin?: IObject
27
+
28
+ getInner?(target?: ILeaf): IPointData
29
+ getLocal?(target?: ILeaf): IPointData
30
+ }
31
+
32
+
33
+ export interface IPointerEvent extends IUIEvent {
34
+ width?: number
35
+ height?: number
36
+ pointerType?: PointerType
37
+ pressure?: number
38
+ tangentialPressure?: number
39
+ tiltX?: number
40
+ tiltY?: number
41
+ twist?: number
42
+ }
43
+ export type PointerType = 'mouse' | 'pen' | 'touch'
44
+
45
+ export interface IDragEvent extends IPointerEvent {
46
+ moveX: number
47
+ moveY: number
48
+ totalX?: number
49
+ totalY?: number
50
+
51
+ getInnerMove?(target?: ILeaf): IPointData
52
+ getLocalMove?(target?: ILeaf): IPointData
53
+ getInnerTotal?(target?: ILeaf): IPointData
54
+ getLocalTotal?(target?: ILeaf): IPointData
55
+ }
56
+
57
+ export interface IDropEvent extends IPointerEvent {
58
+ list: ILeafList
59
+ data?: IObject
60
+ }
61
+
62
+ export interface IRotateEvent extends IUIEvent {
63
+ rotation: number
64
+ }
65
+
66
+ export interface IZoomEvent extends IUIEvent {
67
+ scale: number
68
+ }
69
+
70
+ export interface IMoveEvent extends IDragEvent {
71
+
72
+ }
73
+
74
+ export interface ISwipeEvent extends IDragEvent {
75
+
76
+ }
77
+
78
+ export interface IKeyEvent extends IUIEvent {
79
+ code?: string
80
+ key?: string
81
+ }
82
+
83
+ export interface IImageEvent extends IEvent {
84
+ image?: ILeaferImage
85
+ attrName?: string
86
+ attrValue?: IObject
87
+ error?: string | IObject
88
+ }
@@ -0,0 +1,2 @@
1
+ export type IExportImageType = 'jpg' | 'png' | 'webp'
2
+ export type IExportFileType = IExportImageType | 'svg' | 'pdf' | 'json'
@@ -0,0 +1,13 @@
1
+ import { IPointData } from '../math/IMath'
2
+
3
+ export interface IFunction {
4
+ (...arg: any): any
5
+ }
6
+
7
+ export interface INumberFunction {
8
+ (...arg: any): number
9
+ }
10
+
11
+ export interface IPointDataFunction {
12
+ (...arg: any): IPointData
13
+ }
@@ -0,0 +1,18 @@
1
+ import { ILeaferImage, ILeaferImageConfig } from './ILeaferImage'
2
+ import { ITaskProcessor } from '../task/ITaskProcessor'
3
+
4
+ interface ILeaferImageMap {
5
+ [name: string]: ILeaferImage
6
+ }
7
+
8
+ export interface IImageManager {
9
+ map: ILeaferImageMap
10
+ recycledList: ILeaferImage[]
11
+ tasker: ITaskProcessor
12
+ patternTasker: ITaskProcessor
13
+ readonly isComplete: boolean
14
+ get(config: ILeaferImageConfig): ILeaferImage
15
+ recycle(image: ILeaferImage): void
16
+ clearRecycled(): void
17
+ destroy(): void
18
+ }
@@ -0,0 +1,43 @@
1
+ import { IObject } from '../data/IData'
2
+ import { InnerId } from '../event/IEventer'
3
+ import { IExportFileType } from '../file/IFileType'
4
+
5
+ export interface ILeaferImageConfig {
6
+ url: string
7
+ thumb?: string
8
+ format?: IExportFileType
9
+ }
10
+
11
+ export interface ILeaferImageOnLoaded {
12
+ (image?: ILeaferImage): any
13
+ }
14
+
15
+ export interface ILeaferImageOnError {
16
+ (error?: string | IObject, image?: ILeaferImage): any
17
+ }
18
+
19
+ export interface ILeaferImage {
20
+ readonly innerId: InnerId
21
+ readonly url: string
22
+
23
+ view: unknown
24
+ width: number
25
+ height: number
26
+
27
+ isSVG: boolean
28
+
29
+ readonly completed: boolean
30
+ ready: boolean
31
+ error: IObject
32
+ loading: boolean
33
+
34
+ use: number
35
+ config: ILeaferImageConfig
36
+
37
+ load(onSuccess?: ILeaferImageOnLoaded, onError?: ILeaferImageOnError): number
38
+ unload(index: number, stopEvent?: boolean): void
39
+ getCanvas(width: number, height: number, opacity?: number, _filters?: IObject): unknown
40
+ destroy(): void
41
+ }
42
+
43
+ export type IImageStatus = 'wait' | 'thumb-loading' | 'thumb-success' | 'thumb-error' | 'loading' | 'success' | 'error'
@@ -0,0 +1,106 @@
1
+ import { INumberFunction, IPointDataFunction } from '../function/IFunction'
2
+ import { IPointerEvent, IMoveEvent, IZoomEvent, IRotateEvent, IUIEvent, IKeyEvent } from '../event/IUIEvent'
3
+ import { ILeaf, ICursorType } from '../display/ILeaf'
4
+ import { ILeafList } from '../data/IList'
5
+ import { IPointData } from '../math/IMath'
6
+ import { ISelector, ISelectPathOptions } from '../selector/ISelector'
7
+ import { IBounds } from '../math/IMath'
8
+ import { IControl } from '../control/IControl'
9
+ import { IKeepTouchData } from '../event/IEvent'
10
+ import { ILeaferCanvas } from '../canvas/ILeaferCanvas'
11
+ import { IObject } from '../data/IData'
12
+
13
+ export interface IInteraction extends IControl {
14
+ target: ILeaf
15
+ canvas: IInteractionCanvas
16
+ selector: ISelector
17
+
18
+ running: boolean
19
+ readonly dragging: boolean
20
+ readonly moveMode: boolean
21
+
22
+ config: IInteractionConfig
23
+
24
+ cursor: ICursorType | ICursorType[]
25
+ readonly hitRadius: number
26
+
27
+ shrinkCanvasBounds: IBounds
28
+
29
+ downData: IPointerEvent
30
+ hoverData: IPointerEvent
31
+ downTime: number
32
+
33
+ receive(event: any): void
34
+
35
+ pointerDown(data?: IPointerEvent, defaultPath?: boolean): void
36
+ pointerMove(data?: IPointerEvent): void
37
+ pointerMoveReal(data: IPointerEvent): void
38
+ pointerUp(data?: IPointerEvent): void
39
+ pointerCancel(): void
40
+
41
+ multiTouch(data: IUIEvent, list: IKeepTouchData[]): void
42
+
43
+ move(data: IMoveEvent): void
44
+ zoom(data: IZoomEvent): void
45
+ rotate(data: IRotateEvent): void
46
+
47
+ keyDown(data: IKeyEvent): void
48
+ keyUp(data: IKeyEvent): void
49
+
50
+ findPath(data: IPointerEvent, options?: ISelectPathOptions): ILeafList
51
+
52
+ updateDownData(data?: IPointerEvent): void
53
+ updateHoverData(data: IPointerEvent): void
54
+ updateCursor(hoverData?: IPointerEvent): void
55
+
56
+ emit(type: string, data: IUIEvent, path?: ILeafList, excludePath?: ILeafList): void
57
+ }
58
+
59
+ export interface IInteractionCanvas extends ILeaferCanvas {
60
+
61
+ }
62
+
63
+ export interface IInteractionConfig {
64
+ wheel?: IWheelConfig
65
+ pointer?: IPointerConfig
66
+ zoom?: IZoomConfig
67
+ move?: IMoveConfig
68
+ eventer?: IObject
69
+ }
70
+
71
+ export interface IZoomConfig {
72
+ min?: number
73
+ max?: number
74
+ }
75
+
76
+ export interface IMoveConfig {
77
+ holdSpaceKey?: boolean
78
+ dragEmpty?: boolean
79
+ dragOut?: boolean
80
+ autoDistance?: number
81
+ }
82
+
83
+ export interface IWheelConfig {
84
+ zoomMode?: boolean
85
+ zoomSpeed?: number // 取值范围 0 ~ 1, 默认0.5
86
+ moveSpeed?: number
87
+ rotateSpeed?: number // 取值范围 0 ~ 1, 默认0.5
88
+ delta?: IPointData // 以chrome为基准, 鼠标滚动一格的距离
89
+ getScale?: INumberFunction
90
+ getMove?: IPointDataFunction
91
+ preventDefault?: boolean
92
+ }
93
+
94
+ export interface IPointerConfig {
95
+ hitRadius?: number
96
+ through?: boolean
97
+ tapMore?: boolean
98
+ tapTime?: number
99
+ longPressTime?: number
100
+ transformTime?: number
101
+ dragHover?: boolean
102
+ dragDistance?: number
103
+ swipeDistance?: number
104
+ ignoreMove?: boolean // 性能优化字段, 控制move事件触发次数
105
+ preventDefault?: boolean
106
+ }
@@ -0,0 +1,94 @@
1
+ import { IBoundsData, IMatrixData } from '../math/IMath'
2
+ import { ILeaf } from '../display/ILeaf'
3
+
4
+ export type ILayoutLocationType = 'world' | 'local' | 'inner'
5
+ export type ILayoutBoundsType = 'content' | 'box' | 'stroke' | 'margin' | 'render'
6
+
7
+ export interface ILeafLayout {
8
+
9
+ leaf: ILeaf
10
+
11
+ useZoomProxy: boolean
12
+
13
+ // inner
14
+
15
+ boxBounds: IBoundsData // | content + padding |
16
+ strokeBounds: IBoundsData // | boxBounds + border |
17
+ renderBounds: IBoundsData // | strokeBounds + shadow |
18
+
19
+ // auto layout
20
+ marginBounds: IBoundsData // | strokeBounds + margin |
21
+ contentBounds: IBoundsData // | content |
22
+
23
+ // local
24
+
25
+ //localBoxBounds: IBoundsData = leaf.__local
26
+ localStrokeBounds: IBoundsData
27
+ localRenderBounds: IBoundsData
28
+
29
+ // state
30
+
31
+ // matrix changed
32
+ matrixChanged: boolean // include positionChanged scaleChanged skewChanged
33
+ positionChanged: boolean // x, y
34
+ originChanged?: boolean // originX originY
35
+ scaleChanged: boolean // scaleX scaleY
36
+ rotationChanged: boolean // rotaiton, skewX scaleY 数据更新
37
+
38
+ // bounds changed
39
+ boundsChanged: boolean
40
+
41
+ boxChanged: boolean
42
+ strokeChanged: boolean
43
+ renderChanged: boolean
44
+
45
+ localBoxChanged: boolean // position
46
+
47
+ // face changed
48
+ surfaceChanged: boolean
49
+ opacityChanged: boolean
50
+
51
+ hitCanvasChanged: boolean
52
+
53
+ childrenSortChanged?: boolean
54
+
55
+ // keep state
56
+ affectScaleOrRotation: boolean
57
+ affectRotation: boolean
58
+ affectChildrenSort?: boolean
59
+
60
+ strokeSpread: number
61
+ renderSpread: number
62
+ strokeBoxSpread: number
63
+ renderShapeSpread: number
64
+
65
+ checkUpdate(force?: boolean): void
66
+
67
+ getTransform(locationType: ILayoutLocationType): IMatrixData
68
+ getBounds(type: ILayoutBoundsType, locationType: ILayoutLocationType): IBoundsData
69
+
70
+ // 独立 / 引用 boxBounds
71
+ spreadStroke(): void
72
+ spreadRender(): void
73
+ spreadStrokeCancel(): void
74
+ spreadRenderCancel(): void
75
+
76
+ // bounds
77
+ boxChange(): void
78
+ localBoxChange(): void
79
+ strokeChange(): void
80
+ renderChange(): void
81
+
82
+ // matrix
83
+ positionChange(): void
84
+ scaleChange(): void
85
+ rotationChange(): void
86
+
87
+ // face
88
+ surfaceChange(): void
89
+ opacityChange(): void
90
+
91
+ childrenSortChange(): void
92
+
93
+ destroy(): void
94
+ }
@@ -0,0 +1,60 @@
1
+ import { IBounds } from '../math/IMath'
2
+ import { ILeaf } from '../display/ILeaf'
3
+ import { ILeafList } from '../data/IList'
4
+ import { IControl } from '../control/IControl'
5
+
6
+ export interface ILayoutChangedData {
7
+ matrixList: ILeaf[]
8
+ boundsList: ILeaf[]
9
+ surfaceList: ILeaf[]
10
+ }
11
+
12
+ export interface ILayoutBlockData {
13
+ updatedList: ILeafList
14
+ updatedBounds: IBounds
15
+
16
+ beforeBounds: IBounds
17
+ afterBounds: IBounds
18
+
19
+ setBefore?(): void
20
+ setAfter?(): void
21
+ merge?(data: ILayoutBlockData): void
22
+ destroy(): void
23
+ }
24
+
25
+ export interface IPartLayoutConfig {
26
+ maxBlocks?: number
27
+ maxTimes?: number
28
+ }
29
+
30
+ export interface ILayouterConfig {
31
+ partLayout?: IPartLayoutConfig
32
+ }
33
+
34
+ export interface ILayouter extends IControl {
35
+ target: ILeaf
36
+ layoutedBlocks: ILayoutBlockData[]
37
+
38
+ totalTimes: number
39
+ times: number
40
+
41
+ disabled: boolean
42
+ running: boolean
43
+ layouting: boolean
44
+
45
+ waitAgain: boolean
46
+
47
+ config: ILayouterConfig
48
+
49
+ disable(): void
50
+
51
+ layout(): void
52
+ layoutAgain(): void
53
+ layoutOnce(): void
54
+ partLayout(): void
55
+ fullLayout(): void
56
+
57
+ createBlock(data: ILeafList | ILeaf[]): ILayoutBlockData
58
+ getBlocks(list: ILeafList): ILayoutBlockData[]
59
+ addBlocks(current: ILayoutBlockData[]): void
60
+ }