forked from tophf/mpiv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.types.d.ts
247 lines (229 loc) · 6.54 KB
/
.types.d.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
Definitions for some types used in MPIV.
Can be loaded into various IDE so you would see hints and info.
https://definitelytyped.org/directory/tools.html
*/
declare namespace mpiv {
type Config = {
center: boolean
css: string
delay: number
fit: 'all' | 'large' | 'no' | ''
globalStatus: boolean
hosts: HostRule[]
imgtab: boolean
mute: boolean
preload: boolean
scale: number
scales: (string | number)[]
start: 'auto' | 'context' | 'ctrl'
uiBackgroundColor: string
uiBackgroundOpacity: number,
uiBorderColor: string,
uiBorderOpacity: number,
uiBorder: number,
uiFadein: boolean
uiShadowColor: string,
uiShadowOpacity: number,
uiShadow: number,
uiPadding: number,
uiMargin: number,
version: number
waitLoad: boolean
xhr: boolean
zoom: 'context' | 'wheel' | 'shift' | 'auto'
zoomOut: 'close' | 'stay' | 'auto'
zoomStep: number
};
type HostRule = {
// URL match using plain text and AdBlock-compatible special symbols ||, |, ^
u?: StringOrArrayOfStrings
/*
URL match using RegExp
- when "html" is true, the node's HTML is matched instead of URL
- when "u" is present, the "r" is checked only if "u" matched
*/
r?: RegExp
// caption extractor: CSS selector or a function
c?: string | CaptionFunction
// element match: CSS selector
e?: string
// gallery
g?: GalleryLoader | GalleryFunction
/*
remote element extractor: CSS selector
- applied to the DOM of the document downloaded from URL (note, "s" rule can change the URL)
- can be an array of selectors which will be checked in the specified order until matched (unlike CSS selector 'foo, bar' here you control the priority)
*/
q?: StringOrArrayOfStrings | QuerySelectorFunction
/*
URL substitution
- a string used in RegExp#replace like 'http://foo/bar$1/$2'
- an array of such strings, used in order until one succeeds
(failure means an HTTP error like "not found")
- a function that returns a string or an array of such strings
*/
s?: StringOrArrayOfStrings | SubstitutionFunction
// whether the resultant URL should be processed again so another rule would match it
follow?: boolean | BooleanFunction
// POST method should be used to make HTTP request
post?: boolean | BooleanFunction
// CSS selector for an element used to calculate the bounds of the hoverable area
rect?: string
// CSS to be added to the page
css?: string
// for generic rules: the result should be more than cfg.scale bigger than the original
distinct?: boolean
// shows the popup only when user activates it explicitly e.g. via a key
manual?: boolean
// Firefox-only fix needed with some obstinate hostings when opening image in a tab via "T" key
tabfix?: boolean
// spoof anti-hotlinking protection
xhr?: boolean
}
type AppInfo = RuleMatchInfo & PopupInfo
type RuleMatchInfo = {
gallery?: GalleryFunction
match: string[]
node: HTMLElement
post: boolean
rule: HostRule
url: string
urls?: string[]
xhr: boolean | 'data'
}
type PopupInfo = {
bar: Element
// buffering bar shown
bufBar: boolean
// buffering start time, ms
bufStart: number
caption: string
// video controls are shown
controlled: boolean
// clientX of the last mouse event
cx: number
// clientY of the last mouse event
cy: number
extras: {
// padding + border for left and right edges
inw: number,
// padding + border for top and bottom edges
inh: number,
// margin + outline for left and right edges
outw: number,
// margin + outline for top and bottom edges
outh: number,
// padding + margin + border + outlines for left and right edges
w: number,
// padding + margin + border + outlines for top and bottom edges
h: number,
// outline offset + thickness
o: number,
}
flipX: boolean
flipY: boolean
force: boolean
gIndex: number
gItems: GalleryItemsArray
gNum: number
imageUrl: StringOrArrayOfStrings
large: boolean
lazyUnload: boolean
// naturalHeight
nheight: number
// naturalWidth
nwidth: number
popup: HTMLImageElement | HTMLVideoElement
// true when 'load' event fired on the element
popupLoaded: boolean
// time, ms
preloadStart: number
// used by gallery to preload the next image
preloadUrl: string
rect: DOMRect
// is mouse still over PopupInfo.rect
rectHovered: boolean
req: { abort: VoidFunction }
rotate: number
scale: number
scales: number[]
// scale fit-to-window factor
scaleFit: number
// scale factor to use when zoom is enabled
scaleZoom: number
timer: number
timerBar: number
timerProgress: number
timerStatus: number
tooltip: { node: Node, text: string }
view: { w: number, h: number }
zoomed: boolean
zooming: boolean
};
type GalleryItem = {
url: StringOrArrayOfStrings
desc?: string
}
type GalleryItemsArray = GalleryItem[] & {
// e.g. let g=[GalleryItem, GalleryItem]; g.title='foo'
title?: string
//
index?: IndexFunction | string | number
}
type GalleryLoader = {
// CSS selector: entry (required to extract captions)
entry?: string
// CSS selector: image (relative to the entry element if "entry" is specified)
image?: string
// CSS selector: caption (relative to the entry element)
caption?: StringOrArrayOfStrings
// CSS selector: title of the gallery
title?: string
// function to transform URLs/captions/title
fix?: { (s: string, isURL: boolean): string }
}
type BooleanFunction = { (): boolean }
type CaptionFunction = {
(
text: string,
doc: Document,
node: Node,
rule: HostRule,
): string
}
type GalleryFunction = {
(
text: string,
doc: Document,
url: string,
m: string[],
rule: HostRule,
node: Node,
cb: { (items: GalleryItemsArray): void },
): GalleryItemsArray
}
type IndexFunction = {
(
items: GalleryItemsArray,
node: Node,
): string
}
type QuerySelectorFunction = {
(
text: string,
doc: Document,
node: Node,
rule: HostRule,
): StringOrArrayOfStrings
}
type SubstitutionFunction = {
(
m: string[],
node: Node,
rule: HostRule,
): StringOrArrayOfStrings
}
type StringOrArrayOfStrings = string | string[]
type VoidFunction = { (): void }
}