@techsio/storybook-better-a11y 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/699.js +15 -2
- package/dist/a11yRunner.d.ts.map +1 -1
- package/dist/apcaChecker.d.ts +1 -1
- package/dist/apcaChecker.d.ts.map +1 -1
- package/dist/manager.js +1 -1
- package/package.json +1 -1
package/dist/699.js
CHANGED
|
@@ -191,7 +191,7 @@ function isVisible(element) {
|
|
|
191
191
|
const computed = global.getComputedStyle(element);
|
|
192
192
|
return 'none' !== computed.display && 'hidden' !== computed.visibility && '0' !== computed.opacity;
|
|
193
193
|
}
|
|
194
|
-
async function runAPCACheck(context = apcaChecker_document, options = DEFAULT_APCA_OPTIONS) {
|
|
194
|
+
async function runAPCACheck(context = apcaChecker_document, options = DEFAULT_APCA_OPTIONS, excludeSelectors = []) {
|
|
195
195
|
const { APCAcontrast, sRGBtoY, fontLookupAPCA } = await import("apca-w3");
|
|
196
196
|
const apcaOptions = {
|
|
197
197
|
...DEFAULT_APCA_OPTIONS,
|
|
@@ -201,6 +201,16 @@ async function runAPCACheck(context = apcaChecker_document, options = DEFAULT_AP
|
|
|
201
201
|
const root = context instanceof Document ? context.body : context;
|
|
202
202
|
const textElements = root.querySelectorAll('p, span, div, h1, h2, h3, h4, h5, h6, a, button, label, td, th, li, input, textarea');
|
|
203
203
|
textElements.forEach((element)=>{
|
|
204
|
+
if (excludeSelectors.length > 0) {
|
|
205
|
+
const isExcluded = excludeSelectors.some((selector)=>{
|
|
206
|
+
try {
|
|
207
|
+
return null !== element.closest(selector);
|
|
208
|
+
} catch {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
if (isExcluded) return;
|
|
213
|
+
}
|
|
204
214
|
if (!isVisible(element) || !hasReadableText(element)) return;
|
|
205
215
|
const foreground = getComputedColor(element, 'color');
|
|
206
216
|
const background = getEffectiveBackgroundColor(element);
|
|
@@ -381,7 +391,10 @@ const run = async (input = DEFAULT_PARAMETERS, storyId)=>{
|
|
|
381
391
|
if (first instanceof Element) contextElement = first;
|
|
382
392
|
else if ('string' == typeof first) contextElement = a11yRunner_document.querySelector(first) || a11yRunner_document;
|
|
383
393
|
} else if ('string' == typeof context.include) contextElement = a11yRunner_document.querySelector(context.include) || a11yRunner_document;
|
|
384
|
-
const
|
|
394
|
+
const excludeSelectors = Array.isArray(context.exclude) ? context.exclude.filter((value)=>'string' == typeof value) : 'string' == typeof context.exclude ? [
|
|
395
|
+
context.exclude
|
|
396
|
+
] : [];
|
|
397
|
+
const apcaResult = await runAPCACheck(contextElement, input.apca, excludeSelectors);
|
|
385
398
|
if (apcaResult.nodes.length > 0) result.violations.push(apcaResult);
|
|
386
399
|
else result.passes.push(apcaResult);
|
|
387
400
|
const resultWithLinks = withLinkPaths(result, storyId);
|
package/dist/a11yRunner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a11yRunner.d.ts","sourceRoot":"","sources":["../src/a11yRunner.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAA4B,MAAM,UAAU,CAAC;AAMrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAiC/C,eAAO,MAAM,GAAG,GAAU,OAAO,cAAc,YAAqB,EAAE,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"a11yRunner.d.ts","sourceRoot":"","sources":["../src/a11yRunner.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAA4B,MAAM,UAAU,CAAC;AAMrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAiC/C,eAAO,MAAM,GAAG,GAAU,OAAO,cAAc,YAAqB,EAAE,SAAS,MAAM,wBAkHpF,CAAC"}
|
package/dist/apcaChecker.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ interface ApcaOptions {
|
|
|
8
8
|
/**
|
|
9
9
|
* Run APCA contrast checks on the document
|
|
10
10
|
*/
|
|
11
|
-
export declare function runAPCACheck(context?: Element | Document, options?: ApcaOptions): Promise<Result>;
|
|
11
|
+
export declare function runAPCACheck(context?: Element | Document, options?: ApcaOptions, excludeSelectors?: string[]): Promise<Result>;
|
|
12
12
|
export {};
|
|
13
13
|
//# sourceMappingURL=apcaChecker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apcaChecker.d.ts","sourceRoot":"","sources":["../src/apcaChecker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,UAAU,CAAC;AAYnD,KAAK,oBAAoB,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AACzD,KAAK,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,YAAY,GAAG,YAAY,CAAC;AAEnE,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AA8OD;;GAEG;AACH,wBAAsB,YAAY,CAChC,OAAO,GAAE,OAAO,GAAG,QAAmB,EACtC,OAAO,GAAE,WAAkC,
|
|
1
|
+
{"version":3,"file":"apcaChecker.d.ts","sourceRoot":"","sources":["../src/apcaChecker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,UAAU,CAAC;AAYnD,KAAK,oBAAoB,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AACzD,KAAK,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,YAAY,GAAG,YAAY,CAAC;AAEnE,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AA8OD;;GAEG;AACH,wBAAsB,YAAY,CAChC,OAAO,GAAE,OAAO,GAAG,QAAmB,EACtC,OAAO,GAAE,WAAkC,EAC3C,gBAAgB,GAAE,MAAM,EAAO,GAC9B,OAAO,CAAC,MAAM,CAAC,CA+KjB"}
|
package/dist/manager.js
CHANGED
|
@@ -1475,7 +1475,7 @@ const ColorIcon = styled.span({
|
|
|
1475
1475
|
height: 14,
|
|
1476
1476
|
width: 14
|
|
1477
1477
|
}, ({ $filter })=>({
|
|
1478
|
-
filter: filters[$filter]
|
|
1478
|
+
filter: filters[$filter]?.filter || 'none'
|
|
1479
1479
|
}), ({ theme })=>({
|
|
1480
1480
|
boxShadow: `${theme.appBorderColor} 0 0 0 1px inset`
|
|
1481
1481
|
}));
|