-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
170 lines (141 loc) · 2.93 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
export enum Action {
MOVE = 'MOVE',
RESIZE_TL = 'RESIZE_TL',
RESIZE_TR = 'RESIZE_TR',
RESIZE_BR = 'RESIZE_BR',
RESIZE_BL = 'RESIZE_BL',
}
export interface IClassNames {
applyButton: string[]
body: string[]
cancelButton: string[]
container: string[]
footer: string[]
handlerMove: string[]
handlerResizeBottomLeft: string[]
handlerResizeBottomRight: string[]
handlerResizeTopLeft: string[]
handlerResizeTopRight: string[]
header: string[]
portal: string[]
portalArea: string[]
preview: string[]
previewImage: string[]
root: string[]
sourceImage: string[]
}
export interface IConfig {
/**
* Initial position of portal center at frame [Left: number, Top: number] | 'center'
*/
portalPosition: InitialPortalPosition
/**
* Initial Portal size
*/
portalSize: number
/**
* Frame padding
*/
framePadding: number
/**
* Result image compression
*/
compression: number
/**
* Result image Quality (logarithm base of compressed image width and height)
*/
quality: number
/**
* Result image type
*/
type: ResultImageType
/**
* Apply Button label
*/
applyButtonLabel: string
/**
* Cancel Button label
*/
cancelButtonLabel: string
}
export type EmittedPortalProps = {
X: number
Y: number
top: number
left: number
size: number
}
export type PortalProps = {
left: number
top: number
size: number
}
export type FrameProps = {
left: number
top: number
width: number
height: number
}
export interface IState {
/**
* Crop portal action type
*/
action: Action | null
/**
* Open file name
*/
fileName: string
/**
* Source base64 string
*/
sourceBase64: string
/**
* Source image height
*/
sourceHeight: number
/**
* Source image height
*/
sourceWidth: number
/**
* Rendered Frame prop
*/
frame: FrameProps
/**
* Crop portal props
*/
portal: PortalProps
/**
* On mouse down emitted props
*/
emitted: EmittedPortalProps
/**
* Instance config
*/
config: IConfig
/**
* Css class names
*/
css?: IClassNames
}
export type FileChangeEvent<T = EventTarget> = {
target: T
} & Event
/**
* Initial position of portal center [Left, Top] | 'center'
*/
export type InitialPortalPosition = [number, number] | 'center'
export type ResultImageType = 'jpeg' | 'png'
export type HqCropperInstance = {
open: () => void
}
export type ListenerAction<T> = (value: T, target: IState, prop: string) => void
export type Listener<T> = {
id: string
action: ListenerAction<T>
}
export type CreateState = {
getState: () => IState
setState: (state: Partial<IState>) => void
subscribe: <T>(prop: string, action: ListenerAction<T>) => string
}