-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtypes.ts
More file actions
84 lines (75 loc) · 2.39 KB
/
Copy pathtypes.ts
File metadata and controls
84 lines (75 loc) · 2.39 KB
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
// Shared contract for the alt-text-scan plugin.
import type {Page} from 'playwright'
// The scanner's Finding shape. Mirrors the structure of
// accessibility-scanner/.github/actions/find/src/types.d.ts
export type Finding = {
scannerType: string
ruleId?: string
url: string
html?: string
problemShort: string
problemUrl: string
solutionShort: string
solutionLong?: string
screenshotId?: string
}
// The arguments the scanner passes to a plugin's default export.
export type PluginArgs = {
page: Page
addFinding: (finding: Finding) => Promise<void>
}
// Normalized representation of one <img> on the page.
export type ImageRecord = {
src: string | null
alt: string | null
role: string | null
ariaHidden: boolean
ariaLabel: string | null
ariaLabelledBy: string | null
outerHTML: string
boundingBox: BoundingBox | null
// Intrinsic (natural) pixel dimensions of the image bitmap, independent of
// CSS rendering.
naturalWidth: number
naturalHeight: number
linkContext: {href: string} | null
// True when the image's closest ancestor button exists. Used together with linkContext for "functional image" detection.
inButton: boolean
// Trimmed text content of an associated <figcaption>, if it exists.
figcaption: string | null
// Trimmed text content of the closest enclosing block-level element.
nearbyText: string | null
// Trimmed text of the page's <title>, used as topical context for the
// model-backed rule.
pageTitle: string | null
// Trimmed text of the nearest heading (h1–h6) preceding the image in
// document order, naming the section the image sits under.
sectionHeading: string | null
}
// Pixel position and size of an image in the page's rendered layout.
export type BoundingBox = {
x: number
y: number
width: number
height: number
}
// Input handed to every rule's evaluate() function.
export type RuleContext = {
url: string
images: ImageRecord[]
}
// What a rule emits per offending image. Translated to Finding in findings.ts.
export type RuleResult = {
image: ImageRecord
problemShort: string
solutionShort: string
solutionLong?: string
}
// A rule evaluates a RuleContext and returns its findings.
export type Rule = {
id: string
problemUrl: string
// Whether the rule runs when the consumer hasn't explicitly configured it.
defaultEnabled?: boolean
evaluate(ctx: RuleContext): RuleResult[] | Promise<RuleResult[]>
}