-
Notifications
You must be signed in to change notification settings - Fork 1
/
axe.d.ts
611 lines (561 loc) · 16 KB
/
axe.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
// Type definitions for axe-core
// Project: https://github.com/dequelabs/axe-core
declare namespace axe {
type ImpactValue = 'minor' | 'moderate' | 'serious' | 'critical' | null;
type TagValue = string;
type ReporterVersion = 'v1' | 'v2' | 'raw' | 'rawEnv' | 'no-passes';
type RunOnlyType = 'rule' | 'rules' | 'tag' | 'tags';
type resultGroups = 'inapplicable' | 'passes' | 'incomplete' | 'violations';
type AriaAttrsType =
| 'boolean'
| 'nmtoken'
| 'mntokens'
| 'idref'
| 'idrefs'
| 'string'
| 'decimal'
| 'int';
type AriaRolesType = 'abstract' | 'widget' | 'structure' | 'landmark';
type DpubRolesType =
| 'section'
| 'landmark'
| 'link'
| 'listitem'
| 'img'
| 'navigation'
| 'note'
| 'separator'
| 'none'
| 'sectionhead';
type HtmlContentTypes =
| 'flow'
| 'sectioning'
| 'heading'
| 'phrasing'
| 'embedded'
| 'interactive';
// Array of length 2 or greater
type MultiArray<T> = [T, T, ...T[]];
// Selectors within a frame
type BaseSelector = string;
type ShadowDomSelector = MultiArray<BaseSelector>;
type CrossTreeSelector = BaseSelector | ShadowDomSelector;
type LabelledShadowDomSelector = { fromShadowDom: ShadowDomSelector };
// Cross-frame selectors
type FramesSelector = Array<CrossTreeSelector | LabelledShadowDomSelector>;
type UnlabelledFrameSelector = CrossTreeSelector[];
type LabelledFramesSelector = { fromFrames: MultiArray<FramesSelector[0]> };
/**
* @deprecated Use UnlabelledFrameSelector instead
*/
type CrossFrameSelector = UnlabelledFrameSelector;
// Context options
type Selector =
| Node
| BaseSelector
| LabelledShadowDomSelector
| LabelledFramesSelector;
type SelectorList = Array<Selector | FramesSelector> | NodeList;
type ContextObject =
| {
include: Selector | SelectorList;
exclude?: Selector | SelectorList;
}
| {
exclude: Selector | SelectorList;
include?: Selector | SelectorList;
};
type ElementContext = Selector | SelectorList | ContextObject;
type SerialSelector =
| BaseSelector
| LabelledShadowDomSelector
| LabelledFramesSelector;
type SerialFrameSelector = SerialSelector | FramesSelector;
type SerialSelectorList = Array<SerialFrameSelector>;
type SerialContextObject =
| {
include: SerialSelector | SerialSelectorList;
exclude?: SerialSelector | SerialSelectorList;
}
| {
exclude: SerialSelector | SerialSelectorList;
include?: SerialSelector | SerialSelectorList;
};
interface FrameContextObject {
include: UnlabelledFrameSelector[];
exclude: UnlabelledFrameSelector[];
}
type RunCallback<T = AxeResults> = (error: Error, results: T) => void;
interface TestEngine {
name: string;
version: string;
}
interface TestRunner {
name: string;
}
interface TestEnvironment {
userAgent: string;
windowWidth: number;
windowHeight: number;
orientationAngle?: number;
orientationType?: string;
}
interface RunOnly {
type: RunOnlyType;
values: TagValue[] | string[];
}
interface RuleObject {
[key: string]: {
enabled: boolean;
};
}
interface RunOptions {
runOnly?: RunOnly | TagValue[] | string[] | string;
rules?: RuleObject;
reporter?: ReporterVersion | string;
resultTypes?: resultGroups[];
selectors?: boolean;
ancestry?: boolean;
xpath?: boolean;
absolutePaths?: boolean;
iframes?: boolean;
elementRef?: boolean;
frameWaitTime?: number;
preload?: boolean;
performanceTimer?: boolean;
pingWaitTime?: number;
}
interface AxeResults extends EnvironmentData {
toolOptions: RunOptions;
passes: Result[];
violations: Result[];
incomplete: Result[];
inapplicable: Result[];
}
interface Result {
description: string;
help: string;
helpUrl: string;
id: string;
impact?: ImpactValue;
tags: TagValue[];
nodes: NodeResult[];
}
interface NodeResult {
html: string;
impact?: ImpactValue;
target: UnlabelledFrameSelector;
xpath?: string[];
ancestry?: UnlabelledFrameSelector;
any: CheckResult[];
all: CheckResult[];
none: CheckResult[];
failureSummary?: string;
element?: HTMLElement;
}
interface CheckResult {
id: string;
impact: string;
message: string;
data: any;
relatedNodes?: RelatedNode[];
}
interface RelatedNode {
html: string;
target: UnlabelledFrameSelector;
xpath?: string[];
ancestry?: UnlabelledFrameSelector;
element?: HTMLElement;
}
interface RuleLocale {
[key: string]: {
description: string;
help: string;
};
}
interface CheckMessages {
pass: string | { [key: string]: string };
fail: string | { [key: string]: string };
incomplete?: string | { [key: string]: string };
}
interface CheckLocale {
[key: string]: CheckMessages;
}
interface Locale {
lang?: string;
rules?: RuleLocale;
checks?: CheckLocale;
}
interface AriaAttrs {
type: AriaAttrsType;
values?: string[];
allowEmpty?: boolean;
global?: boolean;
unsupported?: boolean;
}
interface AriaRoles {
type: AriaRolesType | DpubRolesType;
requiredContext?: string[];
requiredOwned?: string[];
requiredAttrs?: string[];
allowedAttrs?: string[];
nameFromContent?: boolean;
unsupported?: boolean;
}
interface HtmlElmsVariant {
contentTypes?: HtmlContentTypes[];
allowedRoles: boolean | string[];
noAriaAttrs?: boolean;
shadowRoot?: boolean;
implicitAttrs?: { [key: string]: string };
namingMethods?: string[];
}
interface HtmlElms extends HtmlElmsVariant {
variant?: { [key: string]: HtmlElmsVariant };
}
interface Standards {
ariaAttrs?: { [key: string]: AriaAttrs };
ariaRoles?: { [key: string]: AriaRoles };
htmlElms?: { [key: string]: HtmlElms };
cssColors?: { [key: string]: number[] };
}
interface Spec {
branding?: string | Branding;
reporter?: ReporterVersion | string | AxeReporter;
checks?: Check[];
rules?: Rule[];
standards?: Standards;
locale?: Locale;
disableOtherRules?: boolean;
axeVersion?: string;
noHtml?: boolean;
allowedOrigins?: string[];
// Deprecated - do not use.
ver?: string;
}
/**
* @deprecated Use branding: string instead to set the application key in help URLs
*/
interface Branding {
brand?: string;
application?: string;
}
interface CheckHelper {
async: () => (result: boolean | undefined | Error) => void;
data: (data: unknown) => void;
relatedNodes: (nodes: Element[]) => void;
}
interface AfterResult {
id: string;
data?: unknown;
relatedNodes: SerialDqElement[];
result: boolean | undefined;
node: SerialDqElement;
}
interface Check {
id: string;
evaluate?:
| string
| ((
this: CheckHelper,
node: Element,
options: unknown,
virtualNode: VirtualNode
) => boolean | undefined | void);
after?:
| string
| ((results: AfterResult[], options: unknown) => AfterResult[]);
options?: any;
matches?: string;
enabled?: boolean;
metadata?: {
impact?: ImpactValue;
messages?: CheckMessages;
};
}
interface Rule {
id: string;
selector?: string;
impact?: ImpactValue;
excludeHidden?: boolean;
enabled?: boolean;
pageLevel?: boolean;
any?: string[];
all?: string[];
none?: string[];
tags?: string[];
matches?: string | ((node: Element, virtualNode: VirtualNode) => boolean);
reviewOnFail?: boolean;
actIds?: string[];
metadata?: Omit<RuleMetadata, 'ruleId' | 'tags' | 'actIds'>;
}
interface AxePlugin {
id: string;
run(...args: any[]): any;
commands: {
id: string;
callback(...args: any[]): void;
}[];
cleanup?(callback: Function): void;
}
interface RuleMetadata {
ruleId: string;
description: string;
help: string;
helpUrl: string;
tags: string[];
actIds?: string[];
}
interface SerialDqElement {
source: string;
nodeIndexes: number[];
selector: UnlabelledFrameSelector;
xpath: string[];
ancestry: UnlabelledFrameSelector;
}
interface DqElement extends SerialDqElement {
element: Element;
toJSON(): SerialDqElement;
mergeSpecs(
childSpec: SerialDqElement,
parentSpec: SerialDqElement
): SerialDqElement;
}
interface PartialRuleResult {
id: string;
result: 'inapplicable';
pageLevel: boolean;
impact: null;
nodes: Array<Record<string, unknown>>;
}
interface PartialResult {
frames: SerialDqElement[];
results: PartialRuleResult[];
environmentData?: EnvironmentData;
}
type PartialResults = Array<PartialResult | null>;
interface FrameContext {
frameSelector: CrossTreeSelector;
frameContext: FrameContextObject;
}
interface RawCheckResult extends Omit<CheckResult, 'relatedNodes'> {
relatedNodes?: Array<SerialDqElement | DqElement>;
}
interface RawNodeResult<T extends 'passed' | 'failed' | 'incomplete'> {
node: SerialDqElement | DqElement;
any: RawCheckResult[];
all: RawCheckResult[];
none: RawCheckResult[];
impact: ImpactValue | null;
result: T;
}
interface RawResult extends Omit<Result, 'nodes'> {
inapplicable: Array<never>;
passes: RawNodeResult<'passed'>[];
incomplete: RawNodeResult<'incomplete'>[];
violations: RawNodeResult<'failed'>[];
pageLevel: boolean;
result: 'failed' | 'passed' | 'incomplete' | 'inapplicable';
}
type AxeReporter<T = unknown> = (
rawResults: RawResult[],
option: RunOptions,
resolve: (report: T) => void,
reject: (error: Error) => void
) => void;
interface VirtualNode {
actualNode?: Node;
shadowId?: string;
children?: VirtualNode[];
parent?: VirtualNode;
attr(attr: string): string | null;
hasAttr(attr: string): boolean;
props: { [key: string]: unknown };
boundingClientRect: DOMRect;
}
interface Utils {
getFrameContexts: (
context?: ElementContext,
options?: RunOptions
) => FrameContext[];
shadowSelect: (selector: CrossTreeSelector) => Element | null;
shadowSelectAll: (selector: CrossTreeSelector) => Element[];
getStandards(): Required<Standards>;
DqElement: new (
elm: Element,
options?: { absolutePaths?: boolean }
) => DqElement;
uuid: (
options?: { random?: Uint8Array | Array<number> },
buf?: Uint8Array | Array<number>,
offset?: number
) => string | Uint8Array | Array<number>;
}
interface Aria {
getRoleType: (role: string | Element | VirtualNode | null) => string | null;
}
interface Dom {
isFocusable: (node: Element | VirtualNode) => boolean;
isNativelyFocusable: (node: Element | VirtualNode) => boolean;
}
type AccessibleTextOptions = {
inControlContext?: boolean;
inLabelledByContext?: boolean;
};
interface Text {
accessibleText: (
element: Element,
options?: AccessibleTextOptions
) => string;
}
interface Commons {
aria: Aria;
dom: Dom;
text: Text;
}
interface EnvironmentData {
testEngine: TestEngine;
testRunner: TestRunner;
testEnvironment: TestEnvironment;
url: string;
timestamp: string;
}
let version: string;
let plugins: any;
let utils: Utils;
let commons: Commons;
/**
* Source string to use as an injected script in Selenium
*/
let source: string;
/**
* Object for axe Results
*/
var AxeResults: AxeResults;
/**
* Runs a number of rules against the provided HTML page and returns the resulting issue list
*
* @param {ElementContext} context Optional The `Context` specification object @see Context
* @param {RunOptions} options Optional Options passed into rules or checks, temporarily modifying them.
* @param {RunCallback} callback Optional The function to invoke when analysis is complete.
* @returns {Promise<AxeResults>|void} If the callback was not defined, axe will return a Promise.
*/
function run<T = AxeResults>(context?: ElementContext): Promise<T>;
function run<T = AxeResults>(options: RunOptions): Promise<T>;
function run<T = AxeResults>(
callback: (error: Error, results: T) => void
): void;
function run<T = AxeResults>(
context: ElementContext,
callback: RunCallback<T>
): void;
function run<T = AxeResults>(
options: RunOptions,
callback: RunCallback<T>
): void;
function run<T = AxeResults>(
context: ElementContext,
options: RunOptions
): Promise<T>;
function run<T = AxeResults>(
context: ElementContext,
options: RunOptions,
callback: RunCallback<T>
): void;
/**
* Method for configuring the data format used by axe. Helpful for adding new
* rules, which must be registered with the library to execute.
* @param {Spec} Spec Object with valid `branding`, `reporter`, `checks` and `rules` data
*/
function configure(spec: Spec): void;
/**
* Run axe in the current window only
* @param {ElementContext} context Optional The `Context` specification object @see Context
* @param {RunOptions} options Optional Options passed into rules or checks, temporarily modifying them.
* @returns {Promise<PartialResult>} Partial result, for use in axe.finishRun.
*/
function runPartial(
context: ElementContext,
options: RunOptions
): Promise<PartialResult>;
/**
* Create a report from axe.runPartial results
* @param {PartialResult[]} partialResults Results from axe.runPartial, calls in different frames on the page.
* @param {RunOptions} options Optional Options passed into rules or checks, temporarily modifying them.
*/
function finishRun(
partialResults: PartialResults,
options: RunOptions
): Promise<AxeResults>;
/**
* Searches and returns rules that contain a tag in the list of tags.
* @param {Array} tags Optional array of tags
* @return {Array} Array of rules
*/
function getRules(tags?: string[]): RuleMetadata[];
/**
* Restores the default axe configuration
*/
function reset(): void;
/**
* Function to register a plugin configuration in document and its subframes
* @param {Object} plugin A plugin configuration object
*/
function registerPlugin(plugin: AxePlugin): void;
/**
* Function to clean up plugin configuration in document and its subframes
*/
function cleanup(): void;
/**
* Set up alternative frame communication
*/
function frameMessenger(frameMessenger: FrameMessenger): void;
/**
* Setup axe-core so axe.common functions can work properly.
*/
function setup(node?: Element | Document): VirtualNode;
/**
* Clean up axe-core tree and caches. `axe.run` will call this function at the end of the run so there's no need to call it yourself afterwards.
*/
function teardown(): void;
/**
* Check if a reporter is registered
*/
function hasReporter(reporterName: string): boolean;
/**
* Get a reporter based the name it is registered with
*/
function getReporter<T>(reporterName: string): AxeReporter<T>;
/**
* Register a new reporter, optionally setting it as the default
*/
function addReporter<T>(
reporterName: string,
reporter: AxeReporter<T>,
isDefault?: boolean
): void;
// axe.frameMessenger
type FrameMessenger = {
open: (topicHandler: TopicHandler) => Close | void;
post: (
frameWindow: Window,
data: TopicData,
replyHandler: ReplyHandler
) => boolean | void;
};
type Close = Function;
type TopicHandler = (data: TopicData, responder: Responder) => void;
type ReplyHandler = (
message: any | Error,
keepalive: boolean,
responder: Responder
) => void;
type Responder = (
message: any | Error,
keepalive?: boolean,
replyHandler?: ReplyHandler
) => void;
type TopicData = { topic: string } & ReplyData;
type ReplyData = { channelId: string; message: any; keepalive: boolean };
}
export = axe;