@uvalib/web-components 1.2.0 → 1.4.0
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/CHANGELOG.md +105 -0
- package/README.md +849 -47
- package/dist/analytics.d.ts +10 -0
- package/dist/analytics.js +9 -0
- package/dist/analytics.js.map +1 -0
- package/dist/base/UvalibElement.js +8 -5
- package/dist/base/UvalibElement.js.map +1 -1
- package/dist/base/analytics-state.d.ts +7 -0
- package/dist/base/analytics-state.js.map +1 -1
- package/dist/base/light-dom-styles.d.ts +13 -0
- package/dist/base/light-dom-styles.js +26 -0
- package/dist/base/light-dom-styles.js.map +1 -1
- package/dist/base/search-tracker.d.ts +57 -0
- package/dist/base/search-tracker.js +51 -0
- package/dist/base/search-tracker.js.map +1 -0
- package/dist/base.css +286 -14
- package/dist/base.d.ts +2 -0
- package/dist/base.js +1 -0
- package/dist/base.js.map +1 -1
- package/dist/components/site-analytics/SiteAnalytics.d.ts +20 -1
- package/dist/components/site-analytics/SiteAnalytics.js +93 -12
- package/dist/components/site-analytics/SiteAnalytics.js.map +1 -1
- package/dist/components/site-page/SitePage.d.ts +23 -0
- package/dist/components/site-page/SitePage.js +77 -0
- package/dist/components/site-page/SitePage.js.map +1 -1
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.d.ts +58 -0
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.js +250 -0
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.js.map +1 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.d.ts +1 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.js +4 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.js.map +1 -0
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.d.ts +14 -0
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.js +56 -4
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.js.map +1 -1
- package/dist/components/uvalib-chip-group/UvalibChipGroup.d.ts +25 -3
- package/dist/components/uvalib-chip-group/UvalibChipGroup.js +80 -10
- package/dist/components/uvalib-chip-group/UvalibChipGroup.js.map +1 -1
- package/dist/components/uvalib-combobox/UvalibCombobox.d.ts +212 -0
- package/dist/components/uvalib-combobox/UvalibCombobox.js +1088 -0
- package/dist/components/uvalib-combobox/UvalibCombobox.js.map +1 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.d.ts +1 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.js +4 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.js.map +1 -0
- package/dist/components/uvalib-contents/UvalibContents.d.ts +53 -0
- package/dist/components/uvalib-contents/UvalibContents.js +202 -3
- package/dist/components/uvalib-contents/UvalibContents.js.map +1 -1
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.d.ts +56 -17
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js +285 -81
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js.map +1 -1
- package/dist/components/uvalib-date-range/UvalibDateRange.d.ts +6 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js +23 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js.map +1 -1
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.d.ts +113 -0
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js +589 -0
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js.map +1 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.d.ts +1 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.js +4 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.js.map +1 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.d.ts +138 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.js +689 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.js.map +1 -0
- package/dist/components/uvalib-image-regions/regions.d.ts +57 -0
- package/dist/components/uvalib-image-regions/regions.js +117 -0
- package/dist/components/uvalib-image-regions/regions.js.map +1 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.d.ts +1 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.js +4 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.js.map +1 -0
- package/dist/components/uvalib-lightbox/UvalibLightbox.d.ts +79 -0
- package/dist/components/uvalib-lightbox/UvalibLightbox.js +295 -16
- package/dist/components/uvalib-lightbox/UvalibLightbox.js.map +1 -1
- package/dist/components/uvalib-map/UvalibMap.d.ts +251 -0
- package/dist/components/uvalib-map/UvalibMap.js +1395 -0
- package/dist/components/uvalib-map/UvalibMap.js.map +1 -0
- package/dist/components/uvalib-map/uvalib-map.d.ts +1 -0
- package/dist/components/uvalib-map/uvalib-map.js +4 -0
- package/dist/components/uvalib-map/uvalib-map.js.map +1 -0
- package/dist/components/uvalib-metadata/UvalibMetadata.d.ts +39 -2
- package/dist/components/uvalib-metadata/UvalibMetadata.js +214 -8
- package/dist/components/uvalib-metadata/UvalibMetadata.js.map +1 -1
- package/dist/components/uvalib-pager/UvalibPager.d.ts +22 -3
- package/dist/components/uvalib-pager/UvalibPager.js +42 -4
- package/dist/components/uvalib-pager/UvalibPager.js.map +1 -1
- package/dist/custom-elements.json +9641 -3131
- package/dist/index.d.ts +8 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/pagefind.css +4 -0
- package/dist/styles/base.js +119 -0
- package/dist/styles/base.js.map +1 -1
- package/dist/styles/color-scheme.js +5 -0
- package/dist/styles/color-scheme.js.map +1 -1
- package/dist/styles/controls.js +6 -0
- package/dist/styles/controls.js.map +1 -1
- package/dist/styles/hidden.d.ts +2 -0
- package/dist/styles/hidden.js +51 -0
- package/dist/styles/hidden.js.map +1 -0
- package/dist/styles/message.d.ts +1 -0
- package/dist/styles/message.js +82 -0
- package/dist/styles/message.js.map +1 -0
- package/dist/styles/pagefind.js +4 -0
- package/dist/styles/pagefind.js.map +1 -1
- package/dist/styles/result-list.d.ts +1 -0
- package/dist/styles/result-list.js +111 -0
- package/dist/styles/result-list.js.map +1 -0
- package/dist/styles/results.js +0 -15
- package/dist/styles/results.js.map +1 -1
- package/dist/testing/index.d.ts +110 -0
- package/dist/testing/index.js +100 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/lighthouse-rules.d.ts +10 -0
- package/dist/testing/lighthouse-rules.js +44 -0
- package/dist/testing/lighthouse-rules.js.map +1 -0
- package/dist/tokens.css +5 -0
- package/dist-cdn/analytics.js +32 -0
- package/dist-cdn/analytics.js.map +1 -0
- package/dist-cdn/base.css +286 -14
- package/dist-cdn/bento-box.js +3 -3
- package/dist-cdn/chunks/{SiteAnalytics-Cm-FyhYS.js → SiteAnalytics-B9gu5aGO.js} +59 -30
- package/dist-cdn/chunks/SiteAnalytics-B9gu5aGO.js.map +1 -0
- package/dist-cdn/chunks/{UvalibElement-BnI-eRRR.js → UvalibElement-pGONDAwB.js} +108 -101
- package/dist-cdn/chunks/UvalibElement-pGONDAwB.js.map +1 -0
- package/dist-cdn/chunks/{accessible-GqhVn5_H.js → accessible-DJv7YOtS.js} +2 -2
- package/dist-cdn/chunks/{accessible-GqhVn5_H.js.map → accessible-DJv7YOtS.js.map} +1 -1
- package/dist-cdn/chunks/analytics-state-Ce8DKe4F.js.map +1 -1
- package/dist-cdn/chunks/{base-p5pk0vb2.js → base-BI8h0Gf3.js} +121 -2
- package/dist-cdn/chunks/base-BI8h0Gf3.js.map +1 -0
- package/dist-cdn/chunks/{library-weekly-hours-COE7Vv6V.js → library-weekly-hours-CrV3TlP5.js} +3 -3
- package/dist-cdn/chunks/{library-weekly-hours-COE7Vv6V.js.map → library-weekly-hours-CrV3TlP5.js.map} +1 -1
- package/dist-cdn/chunks/regions-B8ExwUGP.js +86 -0
- package/dist-cdn/chunks/regions-B8ExwUGP.js.map +1 -0
- package/dist-cdn/chunks/{repeat-CIFUYkyh.js → repeat-m5Zd_QeP.js} +2 -2
- package/dist-cdn/chunks/{repeat-CIFUYkyh.js.map → repeat-m5Zd_QeP.js.map} +1 -1
- package/dist-cdn/chunks/{site-header-BlOYvQg1.js → site-header-DYRMpdBj.js} +9 -4
- package/dist-cdn/chunks/{site-header-BlOYvQg1.js.map → site-header-DYRMpdBj.js.map} +1 -1
- package/dist-cdn/chunks/{site-main-nav-AaxZ9rQf.js → site-main-nav-DURrQMal.js} +3 -3
- package/dist-cdn/chunks/{site-main-nav-AaxZ9rQf.js.map → site-main-nav-DURrQMal.js.map} +1 -1
- package/dist-cdn/chunks/{static-html-1mTAG6nS.js → static-html-C1rhtCHu.js} +2 -2
- package/dist-cdn/chunks/{static-html-1mTAG6nS.js.map → static-html-C1rhtCHu.js.map} +1 -1
- package/dist-cdn/custom-elements.json +9641 -3131
- package/dist-cdn/events-section.js +3 -3
- package/dist-cdn/library-hours-setup.js +2 -2
- package/dist-cdn/library-weekly-hours.js +1 -1
- package/dist-cdn/manifest.json +10 -2
- package/dist-cdn/pagefind.css +4 -0
- package/dist-cdn/site-alerts.js +4 -4
- package/dist-cdn/site-analytics.js +2 -2
- package/dist-cdn/site-footer.js +2 -2
- package/dist-cdn/site-header.js +1 -1
- package/dist-cdn/site-hours-section.js +4 -4
- package/dist-cdn/site-main-nav.js +1 -1
- package/dist-cdn/site-page.js +56 -11
- package/dist-cdn/site-page.js.map +1 -1
- package/dist-cdn/site-style.js +2 -2
- package/dist-cdn/skills/uvalib-web-components/SKILL.md +98 -13
- package/dist-cdn/skills/uvalib-web-components/reference/accessibility-testing.md +34 -2
- package/dist-cdn/skills/uvalib-web-components/reference/components.md +302 -14
- package/dist-cdn/skills/uvalib-web-components/reference/snippets.md +1 -1
- package/dist-cdn/tokens.css +5 -0
- package/dist-cdn/uvalib-analytics.js +2 -2
- package/dist-cdn/uvalib-back-to-top.js +156 -0
- package/dist-cdn/uvalib-back-to-top.js.map +1 -0
- package/dist-cdn/uvalib-breadcrumbs.js +31 -11
- package/dist-cdn/uvalib-breadcrumbs.js.map +1 -1
- package/dist-cdn/uvalib-card-grid.js +1 -1
- package/dist-cdn/uvalib-card.js +3 -3
- package/dist-cdn/uvalib-chip-group.js +53 -14
- package/dist-cdn/uvalib-chip-group.js.map +1 -1
- package/dist-cdn/uvalib-combobox.js +667 -0
- package/dist-cdn/uvalib-combobox.js.map +1 -0
- package/dist-cdn/uvalib-contents.js +100 -22
- package/dist-cdn/uvalib-contents.js.map +1 -1
- package/dist-cdn/uvalib-date-histogram.js +237 -127
- package/dist-cdn/uvalib-date-histogram.js.map +1 -1
- package/dist-cdn/uvalib-date-range.js +14 -2
- package/dist-cdn/uvalib-date-range.js.map +1 -1
- package/dist-cdn/uvalib-filter-drawer.js +355 -0
- package/dist-cdn/uvalib-filter-drawer.js.map +1 -0
- package/dist-cdn/uvalib-filter.js +3 -3
- package/dist-cdn/uvalib-image-regions.js +460 -0
- package/dist-cdn/uvalib-image-regions.js.map +1 -0
- package/dist-cdn/uvalib-lightbox.js +214 -59
- package/dist-cdn/uvalib-lightbox.js.map +1 -1
- package/dist-cdn/uvalib-map.js +667 -0
- package/dist-cdn/uvalib-map.js.map +1 -0
- package/dist-cdn/uvalib-metadata.js +150 -24
- package/dist-cdn/uvalib-metadata.js.map +1 -1
- package/dist-cdn/uvalib-pager.js +29 -17
- package/dist-cdn/uvalib-pager.js.map +1 -1
- package/dist-cdn/uvalib-photo-grid.js +2 -2
- package/dist-cdn/uvalib-results-count.js +2 -2
- package/dist-cdn/uvalib-tabs.js +2 -2
- package/dist-cdn/uvalib-tag-list.js +2 -2
- package/package.json +43 -1
- package/skills/uvalib-web-components/SKILL.md +98 -13
- package/skills/uvalib-web-components/reference/accessibility-testing.md +34 -2
- package/skills/uvalib-web-components/reference/components.md +302 -14
- package/skills/uvalib-web-components/reference/snippets.md +1 -1
- package/dist-cdn/chunks/SiteAnalytics-Cm-FyhYS.js.map +0 -1
- package/dist-cdn/chunks/UvalibElement-BnI-eRRR.js.map +0 -1
- package/dist-cdn/chunks/base-p5pk0vb2.js.map +0 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@uvalib/web-components/testing`: the accessibility and analytics test setup every library
|
|
3
|
+
* site needs, for Playwright (npm only; not in the CDN build). Nothing here imports Playwright:
|
|
4
|
+
* each helper takes your test's `page`. `strictAxe` needs `@axe-core/playwright` (an optional
|
|
5
|
+
* peer dependency), loaded only when it runs.
|
|
6
|
+
*/
|
|
7
|
+
import { LIGHTHOUSE_RULES, STRICT_AXE_TAGS } from './lighthouse-rules.js';
|
|
8
|
+
export { LIGHTHOUSE_RULES, STRICT_AXE_TAGS };
|
|
9
|
+
/** The parts of a Playwright `Route` these helpers use. */
|
|
10
|
+
export interface TestRoute {
|
|
11
|
+
request(): {
|
|
12
|
+
url(): string;
|
|
13
|
+
};
|
|
14
|
+
fulfill(response: {
|
|
15
|
+
status?: number;
|
|
16
|
+
contentType?: string;
|
|
17
|
+
body?: string;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/** The parts of a Playwright `Page` these helpers use (a Playwright `Page` is one). */
|
|
21
|
+
export interface TestPage {
|
|
22
|
+
evaluate<R, A>(fn: (arg: A) => R | Promise<R>, arg: A): Promise<R>;
|
|
23
|
+
waitForFunction<A>(fn: (arg: A) => unknown, arg: A, options?: {
|
|
24
|
+
timeout?: number;
|
|
25
|
+
}): Promise<unknown>;
|
|
26
|
+
route(url: (url: URL) => boolean, handler: (route: TestRoute) => unknown): Promise<unknown>;
|
|
27
|
+
addInitScript(script: {
|
|
28
|
+
content: string;
|
|
29
|
+
}): Promise<unknown>;
|
|
30
|
+
}
|
|
31
|
+
/** One axe violation, as `@axe-core/playwright` reports it (the fields used here). */
|
|
32
|
+
export interface AxeViolation {
|
|
33
|
+
id: string;
|
|
34
|
+
impact?: string | null;
|
|
35
|
+
help?: string;
|
|
36
|
+
nodes: {
|
|
37
|
+
target: unknown[];
|
|
38
|
+
}[];
|
|
39
|
+
}
|
|
40
|
+
/** An `@axe-core/playwright` `AxeBuilder` (the methods used here). */
|
|
41
|
+
export interface AxeBuilderLike {
|
|
42
|
+
options(options: object): AxeBuilderLike;
|
|
43
|
+
include(selector: string): AxeBuilderLike;
|
|
44
|
+
exclude(selector: string): AxeBuilderLike;
|
|
45
|
+
analyze(): Promise<{
|
|
46
|
+
violations: AxeViolation[];
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
/** The `AxeBuilder` class. */
|
|
50
|
+
export type AxeBuilderClass = new (options: {
|
|
51
|
+
page: never;
|
|
52
|
+
}) => AxeBuilderLike;
|
|
53
|
+
export interface WaitForUpgradeOptions {
|
|
54
|
+
/** The elements to wait for. Default `site-page`. */
|
|
55
|
+
selector?: string;
|
|
56
|
+
/** Milliseconds before giving up (Playwright's default otherwise). */
|
|
57
|
+
timeout?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Wait until every element matching `selector` (default `site-page`) is defined and has
|
|
61
|
+
* rendered (`updateComplete`), so tests see the upgraded page, not the markup before the
|
|
62
|
+
* components render. Returns at once when none is on the page.
|
|
63
|
+
*/
|
|
64
|
+
export declare function waitForUpgrade(page: TestPage, { selector, timeout }?: WaitForUpgradeOptions): Promise<void>;
|
|
65
|
+
export interface StrictAxeOptions {
|
|
66
|
+
/** Audit only these selectors (page-level rules then do not run). */
|
|
67
|
+
include?: string | string[];
|
|
68
|
+
/**
|
|
69
|
+
* Leave these out: third-party widgets you cannot change. Exclude the smallest selector,
|
|
70
|
+
* say why, and never the library's own elements.
|
|
71
|
+
*/
|
|
72
|
+
exclude?: string | string[];
|
|
73
|
+
/** The `AxeBuilder` class, when you import `@axe-core/playwright` yourself. */
|
|
74
|
+
AxeBuilder?: AxeBuilderClass;
|
|
75
|
+
/** What `waitForUpgrade` waits for first. Default `site-page`. */
|
|
76
|
+
upgrade?: WaitForUpgradeOptions;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* axe at least as strict as Lighthouse: the WCAG 2.0/2.1/2.2 A and AA and best-practice tags
|
|
80
|
+
* plus every rule Lighthouse turns on (`LIGHTHOUSE_RULES`), after `waitForUpgrade`. Returns
|
|
81
|
+
* axe's results; fail on every impact level, minor included:
|
|
82
|
+
* `expect(formatViolations((await strictAxe(page)).violations)).toEqual([])`.
|
|
83
|
+
*/
|
|
84
|
+
export declare function strictAxe(page: TestPage, { include, exclude, AxeBuilder, upgrade }?: StrictAxeOptions): Promise<{
|
|
85
|
+
violations: AxeViolation[];
|
|
86
|
+
}>;
|
|
87
|
+
/** Violations as one line each, `<impact> <rule>: <targets>`, for a readable failure. */
|
|
88
|
+
export declare function formatViolations(violations: AxeViolation[]): string[];
|
|
89
|
+
export interface StubMatomoOptions {
|
|
90
|
+
/**
|
|
91
|
+
* Give the page this Matomo site id: set as `matomo-id` on each `<site-page>` without one,
|
|
92
|
+
* and as `matomoid` on each `<site-analytics>` / `<uvalib-analytics>` without one, before
|
|
93
|
+
* they upgrade. Leave it out when the served page has its id already.
|
|
94
|
+
*/
|
|
95
|
+
siteId?: number | string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Keep Matomo off the network: any `…/matomo.js` is answered with an empty script (so
|
|
99
|
+
* `window._paq` stays the queue the page built, for `matomoQueue`) and any `…/matomo.php`
|
|
100
|
+
* with 204. With `siteId`, the page gets that Matomo id. Call it before `page.goto`.
|
|
101
|
+
*/
|
|
102
|
+
export declare function stubMatomo(page: TestPage, { siteId }?: StubMatomoOptions): Promise<void>;
|
|
103
|
+
/** One Matomo command, such as `['trackSiteSearch', 'rotunda', 'Keyword', 4]`. */
|
|
104
|
+
export type MatomoCommand = unknown[];
|
|
105
|
+
/**
|
|
106
|
+
* A copy of the page's Matomo queue (`window._paq`), empty when there is none; a function in
|
|
107
|
+
* it (a callback command) is `'[function]'`. With `stubMatomo` nothing replays the queue, so
|
|
108
|
+
* every page view, site search and event the page sent is there, in order.
|
|
109
|
+
*/
|
|
110
|
+
export declare function matomoQueue(page: TestPage): Promise<MatomoCommand[]>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@uvalib/web-components/testing`: the accessibility and analytics test setup every library
|
|
3
|
+
* site needs, for Playwright (npm only; not in the CDN build). Nothing here imports Playwright:
|
|
4
|
+
* each helper takes your test's `page`. `strictAxe` needs `@axe-core/playwright` (an optional
|
|
5
|
+
* peer dependency), loaded only when it runs.
|
|
6
|
+
*/
|
|
7
|
+
import { LIGHTHOUSE_RULES, STRICT_AXE_TAGS } from './lighthouse-rules.js';
|
|
8
|
+
export { LIGHTHOUSE_RULES, STRICT_AXE_TAGS };
|
|
9
|
+
/**
|
|
10
|
+
* Wait until every element matching `selector` (default `site-page`) is defined and has
|
|
11
|
+
* rendered (`updateComplete`), so tests see the upgraded page, not the markup before the
|
|
12
|
+
* components render. Returns at once when none is on the page.
|
|
13
|
+
*/
|
|
14
|
+
export async function waitForUpgrade(page, { selector = 'site-page', timeout } = {}) {
|
|
15
|
+
await page.waitForFunction((sel) => [...document.querySelectorAll(sel)].every((el) => !!customElements.get(el.localName)), selector, timeout === undefined ? {} : { timeout });
|
|
16
|
+
await page.evaluate((sel) => Promise.all([...document.querySelectorAll(sel)].map((el) => el.updateComplete)).then(() => undefined), selector);
|
|
17
|
+
}
|
|
18
|
+
const AXE_PACKAGE = '@axe-core/playwright';
|
|
19
|
+
async function loadAxeBuilder() {
|
|
20
|
+
let mod;
|
|
21
|
+
try {
|
|
22
|
+
// A variable specifier: the package is optional, and resolved only when strictAxe runs.
|
|
23
|
+
mod = (await import(/* @vite-ignore */ AXE_PACKAGE));
|
|
24
|
+
}
|
|
25
|
+
catch (cause) {
|
|
26
|
+
const code = cause.code;
|
|
27
|
+
if (code !== 'ERR_MODULE_NOT_FOUND' && code !== 'MODULE_NOT_FOUND')
|
|
28
|
+
throw cause;
|
|
29
|
+
throw new Error(`strictAxe needs ${AXE_PACKAGE}: install it (npm i -D ${AXE_PACKAGE}), ` +
|
|
30
|
+
'or pass its AxeBuilder class as { AxeBuilder }.', { cause });
|
|
31
|
+
}
|
|
32
|
+
let builder = (mod.default ?? mod.AxeBuilder);
|
|
33
|
+
if (builder && typeof builder !== 'function') {
|
|
34
|
+
const inner = builder;
|
|
35
|
+
builder = inner.default ?? inner.AxeBuilder;
|
|
36
|
+
}
|
|
37
|
+
if (typeof builder !== 'function')
|
|
38
|
+
throw new Error(`${AXE_PACKAGE} has no AxeBuilder export`);
|
|
39
|
+
return builder;
|
|
40
|
+
}
|
|
41
|
+
const list = (v) => v === undefined ? [] : Array.isArray(v) ? v : [v];
|
|
42
|
+
/**
|
|
43
|
+
* axe at least as strict as Lighthouse: the WCAG 2.0/2.1/2.2 A and AA and best-practice tags
|
|
44
|
+
* plus every rule Lighthouse turns on (`LIGHTHOUSE_RULES`), after `waitForUpgrade`. Returns
|
|
45
|
+
* axe's results; fail on every impact level, minor included:
|
|
46
|
+
* `expect(formatViolations((await strictAxe(page)).violations)).toEqual([])`.
|
|
47
|
+
*/
|
|
48
|
+
export async function strictAxe(page, { include, exclude, AxeBuilder, upgrade } = {}) {
|
|
49
|
+
await waitForUpgrade(page, upgrade);
|
|
50
|
+
const Builder = AxeBuilder ?? (await loadAxeBuilder());
|
|
51
|
+
let builder = new Builder({ page: page }).options({
|
|
52
|
+
runOnly: { type: 'tag', values: [...STRICT_AXE_TAGS] },
|
|
53
|
+
rules: Object.fromEntries(LIGHTHOUSE_RULES.map((id) => [id, { enabled: true }])),
|
|
54
|
+
});
|
|
55
|
+
for (const s of list(include))
|
|
56
|
+
builder = builder.include(s);
|
|
57
|
+
for (const s of list(exclude))
|
|
58
|
+
builder = builder.exclude(s);
|
|
59
|
+
return builder.analyze();
|
|
60
|
+
}
|
|
61
|
+
/** Violations as one line each, `<impact> <rule>: <targets>`, for a readable failure. */
|
|
62
|
+
export function formatViolations(violations) {
|
|
63
|
+
return violations.map((v) => `${v.impact ?? 'unknown'} ${v.id}: ${v.nodes.map((n) => n.target.join(' ')).join(', ')}`);
|
|
64
|
+
}
|
|
65
|
+
/** The init script `stubMatomo` adds for `siteId`. */
|
|
66
|
+
function siteIdScript(id) {
|
|
67
|
+
return `(() => {
|
|
68
|
+
const id = ${JSON.stringify(id)};
|
|
69
|
+
const set = () => {
|
|
70
|
+
for (const el of document.querySelectorAll('site-page:not([matomo-id])'))
|
|
71
|
+
el.setAttribute('matomo-id', id);
|
|
72
|
+
for (const el of document.querySelectorAll(
|
|
73
|
+
'site-analytics:not([matomoid]), uvalib-analytics:not([matomoid])',
|
|
74
|
+
))
|
|
75
|
+
el.setAttribute('matomoid', id);
|
|
76
|
+
};
|
|
77
|
+
new MutationObserver(set).observe(document, { childList: true, subtree: true });
|
|
78
|
+
})();`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Keep Matomo off the network: any `…/matomo.js` is answered with an empty script (so
|
|
82
|
+
* `window._paq` stays the queue the page built, for `matomoQueue`) and any `…/matomo.php`
|
|
83
|
+
* with 204. With `siteId`, the page gets that Matomo id. Call it before `page.goto`.
|
|
84
|
+
*/
|
|
85
|
+
export async function stubMatomo(page, { siteId } = {}) {
|
|
86
|
+
await page.route((url) => /\/matomo\.(js|php)$/.test(url.pathname), (route) => new URL(route.request().url()).pathname.endsWith('.js')
|
|
87
|
+
? route.fulfill({ status: 200, contentType: 'text/javascript', body: '' })
|
|
88
|
+
: route.fulfill({ status: 204, body: '' }));
|
|
89
|
+
if (siteId !== undefined)
|
|
90
|
+
await page.addInitScript({ content: siteIdScript(String(siteId)) });
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A copy of the page's Matomo queue (`window._paq`), empty when there is none; a function in
|
|
94
|
+
* it (a callback command) is `'[function]'`. With `stubMatomo` nothing replays the queue, so
|
|
95
|
+
* every page view, site search and event the page sent is there, in order.
|
|
96
|
+
*/
|
|
97
|
+
export async function matomoQueue(page) {
|
|
98
|
+
return page.evaluate((fn) => JSON.parse(JSON.stringify(window._paq ?? [], (_k, v) => typeof v === 'function' ? fn : v)), '[function]');
|
|
99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KAAK,CACd,CAAC,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EACjD,CAAC,KAAK,EAAE,EAAE,CACR,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;QACrD,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,iBAAiB,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QAC1E,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAC/C,CAAC;IACF,IAAI,MAAM,KAAK,SAAS;QAAE,MAAM,IAAI,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;AAChG,CAAC;AAKD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAc;IAC9C,OAAO,IAAI,CAAC,QAAQ,CAClB,CAAC,EAAU,EAAE,EAAE,CACb,IAAI,CAAC,KAAK,CACR,IAAI,CAAC,SAAS,CAAE,MAAwC,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAU,EAAE,EAAE,CACtF,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CACjC,CACiB,EACtB,YAAY,CACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The axe rules Lighthouse 12's accessibility audit turns on, on top of its `wcag2a` and
|
|
3
|
+
* `wcag2aa` tags (`core/gather/gatherers/accessibility.js`); some of them (`target-size`,
|
|
4
|
+
* `identical-links-same-purpose`, `table-fake-caption`, `td-has-header`) are off in a default
|
|
5
|
+
* axe run. Turning them all on makes an axe run at least as strict as Lighthouse.
|
|
6
|
+
* `test/testing.test.mjs` checks the list against the Lighthouse version `@lhci/cli` installs.
|
|
7
|
+
*/
|
|
8
|
+
export declare const LIGHTHOUSE_RULES: readonly string[];
|
|
9
|
+
/** The axe tags a strict run checks: WCAG 2.0, 2.1 and 2.2 A and AA, and best practices. */
|
|
10
|
+
export declare const STRICT_AXE_TAGS: readonly string[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The axe rules Lighthouse 12's accessibility audit turns on, on top of its `wcag2a` and
|
|
3
|
+
* `wcag2aa` tags (`core/gather/gatherers/accessibility.js`); some of them (`target-size`,
|
|
4
|
+
* `identical-links-same-purpose`, `table-fake-caption`, `td-has-header`) are off in a default
|
|
5
|
+
* axe run. Turning them all on makes an axe run at least as strict as Lighthouse.
|
|
6
|
+
* `test/testing.test.mjs` checks the list against the Lighthouse version `@lhci/cli` installs.
|
|
7
|
+
*/
|
|
8
|
+
export const LIGHTHOUSE_RULES = Object.freeze([
|
|
9
|
+
'accesskeys',
|
|
10
|
+
'aria-allowed-role',
|
|
11
|
+
'aria-conditional-attr',
|
|
12
|
+
'aria-deprecated-role',
|
|
13
|
+
'aria-dialog-name',
|
|
14
|
+
'aria-prohibited-attr',
|
|
15
|
+
'aria-text',
|
|
16
|
+
'aria-treeitem-name',
|
|
17
|
+
'empty-heading',
|
|
18
|
+
'heading-order',
|
|
19
|
+
'html-xml-lang-mismatch',
|
|
20
|
+
'identical-links-same-purpose',
|
|
21
|
+
'image-redundant-alt',
|
|
22
|
+
'input-button-name',
|
|
23
|
+
'label-content-name-mismatch',
|
|
24
|
+
'landmark-one-main',
|
|
25
|
+
'link-in-text-block',
|
|
26
|
+
'meta-viewport',
|
|
27
|
+
'select-name',
|
|
28
|
+
'skip-link',
|
|
29
|
+
'tabindex',
|
|
30
|
+
'table-duplicate-name',
|
|
31
|
+
'table-fake-caption',
|
|
32
|
+
'target-size',
|
|
33
|
+
'td-has-header',
|
|
34
|
+
]);
|
|
35
|
+
/** The axe tags a strict run checks: WCAG 2.0, 2.1 and 2.2 A and AA, and best practices. */
|
|
36
|
+
export const STRICT_AXE_TAGS = Object.freeze([
|
|
37
|
+
'wcag2a',
|
|
38
|
+
'wcag2aa',
|
|
39
|
+
'wcag21a',
|
|
40
|
+
'wcag21aa',
|
|
41
|
+
'wcag22aa',
|
|
42
|
+
'best-practice',
|
|
43
|
+
]);
|
|
44
|
+
//# sourceMappingURL=lighthouse-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lighthouse-rules.js","sourceRoot":"","sources":["../../src/testing/lighthouse-rules.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC/D,YAAY;IACZ,mBAAmB;IACnB,uBAAuB;IACvB,sBAAsB;IACtB,kBAAkB;IAClB,sBAAsB;IACtB,WAAW;IACX,oBAAoB;IACpB,eAAe;IACf,eAAe;IACf,wBAAwB;IACxB,8BAA8B;IAC9B,qBAAqB;IACrB,mBAAmB;IACnB,6BAA6B;IAC7B,mBAAmB;IACnB,oBAAoB;IACpB,eAAe;IACf,aAAa;IACb,WAAW;IACX,UAAU;IACV,sBAAsB;IACtB,oBAAoB;IACpB,aAAa;IACb,eAAe;CAChB,CAAC,CAAC;AAEH,4FAA4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC9D,QAAQ;IACR,SAAS;IACT,SAAS;IACT,UAAU;IACV,UAAU;IACV,eAAe;CAChB,CAAC,CAAC"}
|
package/dist/tokens.css
CHANGED
|
@@ -127,6 +127,11 @@
|
|
|
127
127
|
status badges read: text (--uva-color-alert-text) is 7:1 or more in both schemes. */
|
|
128
128
|
--uva-color-status-success-bg: light-dark(var(--uva-green-200, #ddefdc), #173d1c);
|
|
129
129
|
--uva-color-status-success-border: light-dark(var(--uva-green-A, #4e9737), #62bb46);
|
|
130
|
+
/* Highlighted search terms (<mark> in base.css's .uvalib-result__snippet):
|
|
131
|
+
library.virginia.edu's orange-200 with dark text (9.5:1), and a dark orange with white
|
|
132
|
+
text (7.6:1). */
|
|
133
|
+
--uva-color-highlight: light-dark(var(--uva-brand-orange-200, #ffc999), #854200);
|
|
134
|
+
--uva-color-on-highlight: light-dark(var(--uva-grey-darkest, #2b2b2b), #ffffff);
|
|
130
135
|
}
|
|
131
136
|
:root[data-uva-color-scheme='system'] {
|
|
132
137
|
color-scheme: light dark;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { a as e, o as t, r as n, t as r } from "./chunks/analytics-DTTihuBD.js";
|
|
2
|
+
// src/base/search-tracker.ts
|
|
3
|
+
var i = (e, t) => e.key ?? JSON.stringify([t, e.category ?? ""]), a = (e) => typeof e == "number" && Number.isFinite(e) && e >= 0 ? e : void 0;
|
|
4
|
+
function o(e = {}) {
|
|
5
|
+
let { element: n = document, debounce: r = 1e3 } = e, o, s, c = () => {
|
|
6
|
+
clearTimeout(s), s = void 0;
|
|
7
|
+
}, l = (e) => {
|
|
8
|
+
c();
|
|
9
|
+
let r = (e.query ?? "").trim();
|
|
10
|
+
if (!r) return;
|
|
11
|
+
let s = i(e, r);
|
|
12
|
+
s !== o && (o = s, t(n, r, e.category || void 0, a(e.count)));
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
typed(e) {
|
|
16
|
+
c(), (e.query ?? "").trim() && (s = setTimeout(() => l(e), r));
|
|
17
|
+
},
|
|
18
|
+
settled: l,
|
|
19
|
+
restored(e) {
|
|
20
|
+
c();
|
|
21
|
+
let t = (e.query ?? "").trim();
|
|
22
|
+
o = t ? i(e, t) : void 0;
|
|
23
|
+
},
|
|
24
|
+
cancel: c,
|
|
25
|
+
reset() {
|
|
26
|
+
o = void 0;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export { r as analyticsAllowed, o as createSearchTracker, n as trackContent, e as trackEvent, t as trackSearch };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.js","names":["trackEvent","trackSearch","trackContent","analyticsAllowed","keyOf","s","query","countOf","n","createSearchTracker","options","last","timer","cancel","send","key","element","debounce"],"sources":["../src/base/search-tracker.ts"],"sourcesContent":["import { trackSearch } from './analytics.js';\n\n/** One search, as the page's own search UI sees it. */\nexport interface TrackedSearch {\n /** What the visitor searched for. Trimmed; an empty query is never sent. */\n query: string;\n /** The number of results, 0 included. Leave it out when unknown. */\n count?: number;\n /** The search's category, a fixed label such as `Keyword` or `Meaning`. */\n category?: string;\n /**\n * What makes two searches the same: by default the query and the category. Pass the query\n * and the active filters (say `JSON.stringify([query, filters])`) when filters count too.\n */\n key?: string;\n}\n\n/** Options for `createSearchTracker`. */\nexport interface SearchTrackerOptions {\n /**\n * Where the search is reported from: the search UI's element, so a `no-analytics` ancestor\n * silences it. Default: `document`.\n */\n element?: EventTarget;\n /** How long a typed search must stay unchanged to count, in ms. Default 1000. */\n debounce?: number;\n}\n\n/** Decides when a page's own search UI sends a Matomo site search. */\nexport interface SearchTracker {\n /**\n * Search-as-you-type: the results for this query are showing. Sent once nothing else has\n * been typed for `debounce` ms; a later call replaces it.\n */\n typed(search: TrackedSearch): void;\n /**\n * A submitted or server-backed search whose results have arrived: sent now (any typed search\n * still waiting is dropped).\n */\n settled(search: TrackedSearch): void;\n /**\n * The search shown was not the visitor's new action: a page opened from a link with a query,\n * Back or Forward. Nothing is sent, and repeating that same search (Enter again) is not\n * counted either.\n */\n restored(search: TrackedSearch): void;\n /** Drop a typed search still waiting: the field was cleared, or the search failed. */\n cancel(): void;\n /** Forget the last search sent, so the same search counts again (say, after a clear). */\n reset(): void;\n}\n\nconst keyOf = (s: TrackedSearch, query: string): string =>\n s.key ?? JSON.stringify([query, s.category ?? '']);\n\nconst countOf = (n: number | undefined): number | undefined =>\n typeof n === 'number' && Number.isFinite(n) && n >= 0 ? n : undefined;\n\n/**\n * A tracker for a page's own search UI (not `<bento-box>` or `<uvalib-pagefind-search>`,\n * which report their own). It sends one Matomo site search (`trackSearch`, so the opt-outs\n * apply) per search the visitor settles on, with the result count and category, never twice\n * in a row for the same `key`. Call `typed` while the visitor types, `settled` when a\n * submitted search's results arrive, `restored` for a search from the URL or Back/Forward,\n * and `cancel` on a clear or an error. It sends the query only as Matomo's site-search\n * keyword, never in an event.\n */\nexport function createSearchTracker(options: SearchTrackerOptions = {}): SearchTracker {\n const { element = document, debounce = 1000 } = options;\n let last: string | undefined;\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const cancel = () => {\n clearTimeout(timer);\n timer = undefined;\n };\n\n const send = (s: TrackedSearch) => {\n cancel();\n const query = (s.query ?? '').trim();\n if (!query) return;\n const key = keyOf(s, query);\n if (key === last) return;\n last = key;\n trackSearch(element, query, s.category || undefined, countOf(s.count));\n };\n\n return {\n typed(s) {\n cancel();\n if (!(s.query ?? '').trim()) return;\n timer = setTimeout(() => send(s), debounce);\n },\n settled: send,\n restored(s) {\n cancel();\n const query = (s.query ?? '').trim();\n last = query ? keyOf(s, query) : undefined;\n },\n cancel,\n reset() {\n last = undefined;\n },\n };\n}\n"],"mappings":";;AAoDA,IAAMI,KAAS,GAAkB,MAC/BC,EAAE,OAAO,KAAK,UAAU,CAACC,GAAOD,EAAE,YAAY,EAAE,CAAC,GAE7CE,KAAW,MACf,OAAOC,KAAM,YAAY,OAAO,SAASA,CAAC,KAAKA,KAAK,IAAIA,IAAI,KAAA;AAW9D,SAAgBC,EAAoB,IAAgC,CAAC,GAAkB;CACrF,IAAM,EAAE,aAAU,UAAU,cAAW,QAASC,GAC5CC,GACAC,GAEEC,UAAe;EAEnB,AADA,aAAaD,CAAK,GAClB,IAAQ,KAAA;CACV,GAEME,KAAQ,MAAqB;EACjC,EAAO;EACP,IAAMR,KAASD,EAAE,SAAS,GAAA,CAAI,KAAK;EACnC,IAAI,CAACC,GAAO;EACZ,IAAMS,IAAMX,EAAMC,GAAGC,CAAK;EAC1B,AAAIS,MAAQJ,MACZ,IAAOI,GACPd,EAAYe,GAASV,GAAOD,EAAE,YAAY,KAAA,GAAWE,EAAQF,EAAE,KAAK,CAAC;CACvE;CAEA,OAAO;EACL,MAAM,GAAG;GAEP,AADAQ,EAAO,IACDR,EAAE,SAAS,GAAA,CAAI,KAAK,MAC1B,IAAQ,iBAAiBS,EAAKT,CAAC,GAAGY,CAAQ;EAC5C;EACA,SAASH;EACT,SAAS,GAAG;GACV,EAAO;GACP,IAAMR,KAASD,EAAE,SAAS,GAAA,CAAI,KAAK;GACnC,IAAOC,IAAQF,EAAMC,GAAGC,CAAK,IAAI,KAAA;EACnC;EACA;EACA,QAAQ;GACN,IAAO,KAAA;EACT;CACF;AACF"}
|