axe.d.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. // Type definitions for axe-core
  2. // Project: https://github.com/dequelabs/axe-core
  3. // Definitions by: Marcy Sutton <https://github.com/marcysutton>
  4. declare namespace axe {
  5. type ImpactValue = 'minor' | 'moderate' | 'serious' | 'critical' | null;
  6. type TagValue = string;
  7. type ReporterVersion = 'v1' | 'v2' | 'raw' | 'raw-env' | 'no-passes';
  8. type RunOnlyType = 'rule' | 'rules' | 'tag' | 'tags';
  9. type resultGroups = 'inapplicable' | 'passes' | 'incomplete' | 'violations';
  10. type AriaAttrsType =
  11. | 'boolean'
  12. | 'nmtoken'
  13. | 'mntokens'
  14. | 'idref'
  15. | 'idrefs'
  16. | 'string'
  17. | 'decimal'
  18. | 'int';
  19. type AriaRolesType = 'abstract' | 'widget' | 'structure' | 'landmark';
  20. type DpubRolesType =
  21. | 'section'
  22. | 'landmark'
  23. | 'link'
  24. | 'listitem'
  25. | 'img'
  26. | 'navigation'
  27. | 'note'
  28. | 'separator'
  29. | 'none'
  30. | 'sectionhead';
  31. type HtmlContentTypes =
  32. | 'flow'
  33. | 'sectioning'
  34. | 'heading'
  35. | 'phrasing'
  36. | 'embedded'
  37. | 'interactive';
  38. type ContextObject = {
  39. include?: string[] | string[][];
  40. exclude?: string[] | string[][];
  41. };
  42. type RunCallback = (error: Error, results: AxeResults) => void;
  43. type ElementContext = Node | string | ContextObject;
  44. interface TestEngine {
  45. name: string;
  46. version: string;
  47. }
  48. interface TestRunner {
  49. name: string;
  50. }
  51. interface TestEnvironment {
  52. userAgent: string;
  53. windowWidth: number;
  54. windowHeight: number;
  55. orientationAngle?: number;
  56. orientationType?: string;
  57. }
  58. interface RunOnly {
  59. type: RunOnlyType;
  60. values: TagValue[] | string[];
  61. }
  62. interface RuleObject {
  63. [key: string]: {
  64. enabled: boolean;
  65. };
  66. }
  67. interface RunOptions {
  68. runOnly?: RunOnly | TagValue[] | string[];
  69. rules?: RuleObject;
  70. reporter?: ReporterVersion;
  71. resultTypes?: resultGroups[];
  72. selectors?: boolean;
  73. ancestry?: boolean;
  74. xpath?: boolean;
  75. absolutePaths?: boolean;
  76. iframes?: boolean;
  77. elementRef?: boolean;
  78. frameWaitTime?: number;
  79. preload?: boolean;
  80. performanceTimer?: boolean;
  81. }
  82. interface AxeResults {
  83. toolOptions: RunOptions;
  84. testEngine: TestEngine;
  85. testRunner: TestRunner;
  86. testEnvironment: TestEnvironment;
  87. url: string;
  88. timestamp: string;
  89. passes: Result[];
  90. violations: Result[];
  91. incomplete: Result[];
  92. inapplicable: Result[];
  93. }
  94. interface Result {
  95. description: string;
  96. help: string;
  97. helpUrl: string;
  98. id: string;
  99. impact?: ImpactValue;
  100. tags: TagValue[];
  101. nodes: NodeResult[];
  102. }
  103. interface NodeResult {
  104. html: string;
  105. impact?: ImpactValue;
  106. target: string[];
  107. xpath?: string[];
  108. ancestry?: string[];
  109. any: CheckResult[];
  110. all: CheckResult[];
  111. none: CheckResult[];
  112. failureSummary?: string;
  113. element?: HTMLElement;
  114. }
  115. interface CheckResult {
  116. id: string;
  117. impact: string;
  118. message: string;
  119. data: any;
  120. relatedNodes?: RelatedNode[];
  121. }
  122. interface RelatedNode {
  123. target: string[];
  124. html: string;
  125. }
  126. interface RuleLocale {
  127. [key: string]: {
  128. description: string;
  129. help: string;
  130. };
  131. }
  132. interface CheckLocale {
  133. [key: string]: {
  134. pass: string | { [key: string]: string };
  135. fail: string | { [key: string]: string };
  136. incomplete: string | { [key: string]: string };
  137. };
  138. }
  139. interface Locale {
  140. lang?: string;
  141. rules?: RuleLocale;
  142. checks?: CheckLocale;
  143. }
  144. interface AriaAttrs {
  145. type: AriaAttrsType;
  146. values?: string[];
  147. allowEmpty?: boolean;
  148. global?: boolean;
  149. unsupported?: boolean;
  150. }
  151. interface AriaRoles {
  152. type: AriaRolesType | DpubRolesType;
  153. requiredContext?: string[];
  154. requiredOwned?: string[];
  155. requiredAttrs?: string[];
  156. allowedAttrs?: string[];
  157. nameFromContent?: boolean;
  158. unsupported?: boolean;
  159. }
  160. interface HtmlElmsVariant {
  161. contentTypes?: HtmlContentTypes[];
  162. allowedRoles: boolean | string[];
  163. noAriaAttrs?: boolean;
  164. shadowRoot?: boolean;
  165. implicitAttrs?: { [key: string]: string };
  166. namingMethods?: string[];
  167. }
  168. interface HtmlElms extends HtmlElmsVariant {
  169. variant?: { [key: string]: HtmlElmsVariant };
  170. }
  171. interface Standards {
  172. ariaAttrs?: { [key: string]: AriaAttrs };
  173. ariaRoles?: { [key: string]: AriaRoles };
  174. htmlElms?: { [key: string]: HtmlElms };
  175. cssColors?: { [key: string]: number[] };
  176. }
  177. interface Spec {
  178. branding?: {
  179. brand?: string;
  180. application?: string;
  181. };
  182. reporter?: ReporterVersion;
  183. checks?: Check[];
  184. rules?: Rule[];
  185. standards?: Standards;
  186. locale?: Locale;
  187. disableOtherRules?: boolean;
  188. axeVersion?: string;
  189. noHtml?: boolean;
  190. allowedOrigins?: string[];
  191. // Deprecated - do not use.
  192. ver?: string;
  193. }
  194. interface Check {
  195. id: string;
  196. evaluate?: Function | string;
  197. after?: Function | string;
  198. options?: any;
  199. matches?: string;
  200. enabled?: boolean;
  201. }
  202. interface Rule {
  203. id: string;
  204. selector?: string;
  205. impact?: ImpactValue;
  206. excludeHidden?: boolean;
  207. enabled?: boolean;
  208. pageLevel?: boolean;
  209. any?: string[];
  210. all?: string[];
  211. none?: string[];
  212. tags?: string[];
  213. matches?: string;
  214. }
  215. interface AxePlugin {
  216. id: string;
  217. run(...args: any[]): any;
  218. commands: {
  219. id: string;
  220. callback(...args: any[]): void;
  221. }[];
  222. cleanup?(callback: Function): void;
  223. }
  224. interface RuleMetadata {
  225. ruleId: string;
  226. description: string;
  227. help: string;
  228. helpUrl: string;
  229. tags: string[];
  230. }
  231. let version: string;
  232. let plugins: any;
  233. /**
  234. * Source string to use as an injected script in Selenium
  235. */
  236. let source: string;
  237. /**
  238. * Object for axe Results
  239. */
  240. var AxeResults: AxeResults;
  241. /**
  242. * Runs a number of rules against the provided HTML page and returns the resulting issue list
  243. *
  244. * @param {ElementContext} context Optional The `Context` specification object @see Context
  245. * @param {RunOptions} options Optional Options passed into rules or checks, temporarily modifying them.
  246. * @param {RunCallback} callback Optional The function to invoke when analysis is complete.
  247. * @returns {Promise<AxeResults>|void} If the callback was not defined, axe will return a Promise.
  248. */
  249. function run(context?: ElementContext): Promise<AxeResults>;
  250. function run(options: RunOptions): Promise<AxeResults>;
  251. function run(callback: (error: Error, results: AxeResults) => void): void;
  252. function run(context: ElementContext, callback: RunCallback): void;
  253. function run(options: RunOptions, callback: RunCallback): void;
  254. function run(
  255. context: ElementContext,
  256. options: RunOptions
  257. ): Promise<AxeResults>;
  258. function run(
  259. context: ElementContext,
  260. options: RunOptions,
  261. callback: RunCallback
  262. ): void;
  263. /**
  264. * Method for configuring the data format used by axe. Helpful for adding new
  265. * rules, which must be registered with the library to execute.
  266. * @param {Spec} Spec Object with valid `branding`, `reporter`, `checks` and `rules` data
  267. */
  268. function configure(spec: Spec): void;
  269. /**
  270. * Searches and returns rules that contain a tag in the list of tags.
  271. * @param {Array} tags Optional array of tags
  272. * @return {Array} Array of rules
  273. */
  274. function getRules(tags?: string[]): RuleMetadata[];
  275. /**
  276. * Restores the default axe configuration
  277. */
  278. function reset(): void;
  279. /**
  280. * Function to register a plugin configuration in document and its subframes
  281. * @param {Object} plugin A plugin configuration object
  282. */
  283. function registerPlugin(plugin: AxePlugin): void;
  284. /**
  285. * Function to clean up plugin configuration in document and its subframes
  286. */
  287. function cleanup(): void;
  288. /**
  289. * Set up alternative frame communication
  290. */
  291. function frameMessenger(frameMessenger: FrameMessenger): void;
  292. // axe.frameMessenger
  293. type FrameMessenger = {
  294. open: (topicHandler: TopicHandler) => Close | void;
  295. post: (
  296. frameWindow: Window,
  297. data: TopicData | ReplyData,
  298. replyHandler: ReplyHandler
  299. ) => void;
  300. };
  301. type Close = Function;
  302. type TopicHandler = (data: TopicData, responder?: Responder) => void;
  303. type ReplyHandler = (data: ReplyData, responder?: Responder) => void;
  304. type Responder = (
  305. message: any,
  306. keepalive: boolean,
  307. replyHandler: ReplyHandler
  308. ) => void;
  309. type TopicData = { topic: String } & ReplyData;
  310. type ReplyData = { channelId: String; message: any; keepAlive: Boolean };
  311. }
  312. export = axe;