forked from qq15725/modern-screenshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.ts
128 lines (105 loc) · 2.18 KB
/
context.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
import type { Options } from './options'
export type Request = {
type: 'image' | 'text'
resolve?: (response: string) => void
reject?: (error: Error) => void
response: Promise<string>
}
export interface InternalContext<T extends Node> {
/**
* FLAG
*/
__CONTEXT__: true
/**
* Logger
*/
log: {
time: (label: string) => void
timeEnd: (label: string) => void
warn: (...args: any[]) => void
}
/**
* Node
*/
node: T
/**
* Owner document
*/
ownerDocument?: Document
/**
* Owner window
*/
ownerWindow?: Window
/**
* DPI
*
* scale === 1 ? null : 96 * scale
*/
dpi: number | null
/**
* The `style` element under the root `svg` element
*/
svgStyleElement?: HTMLStyleElement
/**
* The `defs` element under the root `svg` element
*/
svgDefsElement?: SVGDefsElement
/**
* The `svgStyleElement` class styles
*
* Map<cssText, class[]>
*/
svgStyles: Map<string, string[]>
/**
* The map of default `getComputedStyle` for all tagnames
*/
defaultComputedStyles: Map<string, Map<string, any>>
/**
* The IFrame sandbox used to get the `defaultComputedStyles`
*/
sandbox?: HTMLIFrameElement
/**
* Web Workers
*/
workers: Worker[]
/**
* The set of `font-family` values for all cloned elements
*/
fontFamilies: Set<string>
/**
* Map<CssUrl, DataUrl>
*/
fontCssTexts: Map<string, string>
/**
* `headers.accept` to use when `window.fetch` fetches images
*/
acceptOfImage: string
/**
* All requests for `fetch`
*/
requests: Map<string, Request>
/**
* Canvas multiple draw image fix svg+xml image decoding in Safari and Firefox
*/
drawImageCount: number
/**
* Wait for all tasks embedded in
*/
tasks: Promise<void>[]
/**
* Automatically destroy context
*/
autoDestruct: boolean
/**
* Is enable
*
* @param key
*/
isEnable: (key: string) => boolean
/**
* To get the node style set by the user
*/
currentNodeStyle?: Map<string, [string, string]>
currentParentNodeStyle?: Map<string, [string, string]>
}
export type Context<T extends Node = Node> = InternalContext<T> & Required<Options>