@uvalib/web-components 0.0.0-stage → 1.0.1
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 +172 -0
- package/README.md +1164 -2
- package/bin/install-skill.mjs +139 -0
- package/dist/base/UvalibElement.d.ts +21 -0
- package/dist/base/UvalibElement.js +68 -0
- package/dist/base/UvalibElement.js.map +1 -0
- package/dist/base/analytics.d.ts +44 -0
- package/dist/base/analytics.js +59 -0
- package/dist/base/analytics.js.map +1 -0
- package/dist/base/color-scheme.d.ts +93 -0
- package/dist/base/color-scheme.js +267 -0
- package/dist/base/color-scheme.js.map +1 -0
- package/dist/base/define.d.ts +2 -0
- package/dist/base/define.js +6 -0
- package/dist/base/define.js.map +1 -0
- package/dist/base/heading-level.d.ts +12 -0
- package/dist/base/heading-level.js +52 -0
- package/dist/base/heading-level.js.map +1 -0
- package/dist/base/light-dom-styles.d.ts +18 -0
- package/dist/base/light-dom-styles.js +134 -0
- package/dist/base/light-dom-styles.js.map +1 -0
- package/dist/base.css +30 -0
- package/dist/base.d.ts +5 -0
- package/dist/base.js +5 -0
- package/dist/base.js.map +1 -0
- package/dist/components/bento-box/ArticlesSection.d.ts +19 -0
- package/dist/components/bento-box/ArticlesSection.js +22 -0
- package/dist/components/bento-box/ArticlesSection.js.map +1 -0
- package/dist/components/bento-box/BentoBox.d.ts +85 -0
- package/dist/components/bento-box/BentoBox.js +366 -0
- package/dist/components/bento-box/BentoBox.js.map +1 -0
- package/dist/components/bento-box/BentoSection.d.ts +115 -0
- package/dist/components/bento-box/BentoSection.js +486 -0
- package/dist/components/bento-box/BentoSection.js.map +1 -0
- package/dist/components/bento-box/CatalogSection.d.ts +18 -0
- package/dist/components/bento-box/CatalogSection.js +19 -0
- package/dist/components/bento-box/CatalogSection.js.map +1 -0
- package/dist/components/bento-box/LibGuidesSection.d.ts +24 -0
- package/dist/components/bento-box/LibGuidesSection.js +73 -0
- package/dist/components/bento-box/LibGuidesSection.js.map +1 -0
- package/dist/components/bento-box/VirgoSection.d.ts +19 -0
- package/dist/components/bento-box/VirgoSection.js +58 -0
- package/dist/components/bento-box/VirgoSection.js.map +1 -0
- package/dist/components/bento-box/WebsiteSection.d.ts +25 -0
- package/dist/components/bento-box/WebsiteSection.js +40 -0
- package/dist/components/bento-box/WebsiteSection.js.map +1 -0
- package/dist/components/bento-box/bento-box.d.ts +1 -0
- package/dist/components/bento-box/bento-box.js +13 -0
- package/dist/components/bento-box/bento-box.js.map +1 -0
- package/dist/components/bento-box/bento-data.d.ts +147 -0
- package/dist/components/bento-box/bento-data.js +422 -0
- package/dist/components/bento-box/bento-data.js.map +1 -0
- package/dist/components/events-section/EventsSection.d.ts +91 -0
- package/dist/components/events-section/EventsSection.js +435 -0
- package/dist/components/events-section/EventsSection.js.map +1 -0
- package/dist/components/events-section/events-data.d.ts +90 -0
- package/dist/components/events-section/events-data.js +174 -0
- package/dist/components/events-section/events-data.js.map +1 -0
- package/dist/components/events-section/events-section.d.ts +1 -0
- package/dist/components/events-section/events-section.js +4 -0
- package/dist/components/events-section/events-section.js.map +1 -0
- package/dist/components/library-hours/hours-data.d.ts +104 -0
- package/dist/components/library-hours/hours-data.js +267 -0
- package/dist/components/library-hours/hours-data.js.map +1 -0
- package/dist/components/library-hours-setup/LibraryHoursSetup.d.ts +21 -0
- package/dist/components/library-hours-setup/LibraryHoursSetup.js +59 -0
- package/dist/components/library-hours-setup/LibraryHoursSetup.js.map +1 -0
- package/dist/components/library-hours-setup/library-hours-setup.d.ts +1 -0
- package/dist/components/library-hours-setup/library-hours-setup.js +5 -0
- package/dist/components/library-hours-setup/library-hours-setup.js.map +1 -0
- package/dist/components/library-weekly-hours/LibraryWeeklyHours.d.ts +107 -0
- package/dist/components/library-weekly-hours/LibraryWeeklyHours.js +502 -0
- package/dist/components/library-weekly-hours/LibraryWeeklyHours.js.map +1 -0
- package/dist/components/library-weekly-hours/library-weekly-hours.d.ts +1 -0
- package/dist/components/library-weekly-hours/library-weekly-hours.js +4 -0
- package/dist/components/library-weekly-hours/library-weekly-hours.js.map +1 -0
- package/dist/components/link.d.ts +2 -0
- package/dist/components/link.js +7 -0
- package/dist/components/link.js.map +1 -0
- package/dist/components/site-analytics/SiteAnalytics.d.ts +44 -0
- package/dist/components/site-analytics/SiteAnalytics.js +161 -0
- package/dist/components/site-analytics/SiteAnalytics.js.map +1 -0
- package/dist/components/site-analytics/SiteAnalyticsMixin.d.ts +8 -0
- package/dist/components/site-analytics/SiteAnalyticsMixin.js +22 -0
- package/dist/components/site-analytics/SiteAnalyticsMixin.js.map +1 -0
- package/dist/components/site-analytics/site-analytics.d.ts +1 -0
- package/dist/components/site-analytics/site-analytics.js +4 -0
- package/dist/components/site-analytics/site-analytics.js.map +1 -0
- package/dist/components/site-footer/SiteFooter.d.ts +34 -0
- package/dist/components/site-footer/SiteFooter.js +275 -0
- package/dist/components/site-footer/SiteFooter.js.map +1 -0
- package/dist/components/site-footer/icons.d.ts +4 -0
- package/dist/components/site-footer/icons.js +7 -0
- package/dist/components/site-footer/icons.js.map +1 -0
- package/dist/components/site-footer/site-footer.d.ts +1 -0
- package/dist/components/site-footer/site-footer.js +4 -0
- package/dist/components/site-footer/site-footer.js.map +1 -0
- package/dist/components/site-header/SiteHeader.d.ts +154 -0
- package/dist/components/site-header/SiteHeader.js +845 -0
- package/dist/components/site-header/SiteHeader.js.map +1 -0
- package/dist/components/site-header/site-header.d.ts +1 -0
- package/dist/components/site-header/site-header.js +12 -0
- package/dist/components/site-header/site-header.js.map +1 -0
- package/dist/components/site-hours-section/SiteHoursSection.d.ts +63 -0
- package/dist/components/site-hours-section/SiteHoursSection.js +243 -0
- package/dist/components/site-hours-section/SiteHoursSection.js.map +1 -0
- package/dist/components/site-hours-section/site-hours-section.d.ts +1 -0
- package/dist/components/site-hours-section/site-hours-section.js +4 -0
- package/dist/components/site-hours-section/site-hours-section.js.map +1 -0
- package/dist/components/site-main-nav/SiteMainNav.d.ts +136 -0
- package/dist/components/site-main-nav/SiteMainNav.js +678 -0
- package/dist/components/site-main-nav/SiteMainNav.js.map +1 -0
- package/dist/components/site-main-nav/main-nav-data.d.ts +5 -0
- package/dist/components/site-main-nav/main-nav-data.js +90 -0
- package/dist/components/site-main-nav/main-nav-data.js.map +1 -0
- package/dist/components/site-main-nav/main-nav-items.d.ts +49 -0
- package/dist/components/site-main-nav/main-nav-items.js +138 -0
- package/dist/components/site-main-nav/main-nav-items.js.map +1 -0
- package/dist/components/site-main-nav/site-main-nav.d.ts +1 -0
- package/dist/components/site-main-nav/site-main-nav.js +4 -0
- package/dist/components/site-main-nav/site-main-nav.js.map +1 -0
- package/dist/components/site-page/SitePage.d.ts +145 -0
- package/dist/components/site-page/SitePage.js +480 -0
- package/dist/components/site-page/SitePage.js.map +1 -0
- package/dist/components/site-page/alerts.d.ts +24 -0
- package/dist/components/site-page/alerts.js +78 -0
- package/dist/components/site-page/alerts.js.map +1 -0
- package/dist/components/site-page/site-page.d.ts +1 -0
- package/dist/components/site-page/site-page.js +7 -0
- package/dist/components/site-page/site-page.js.map +1 -0
- package/dist/components/site-style/SiteStyle.d.ts +37 -0
- package/dist/components/site-style/SiteStyle.js +76 -0
- package/dist/components/site-style/SiteStyle.js.map +1 -0
- package/dist/components/site-style/site-style.d.ts +1 -0
- package/dist/components/site-style/site-style.js +4 -0
- package/dist/components/site-style/site-style.js.map +1 -0
- package/dist/components/uvalib-analytics/UvalibAnalytics.d.ts +10 -0
- package/dist/components/uvalib-analytics/UvalibAnalytics.js +11 -0
- package/dist/components/uvalib-analytics/UvalibAnalytics.js.map +1 -0
- package/dist/components/uvalib-analytics/UvalibAnalyticsMixin.d.ts +13 -0
- package/dist/components/uvalib-analytics/UvalibAnalyticsMixin.js +25 -0
- package/dist/components/uvalib-analytics/UvalibAnalyticsMixin.js.map +1 -0
- package/dist/components/uvalib-analytics/uvalib-analytics.d.ts +1 -0
- package/dist/components/uvalib-analytics/uvalib-analytics.js +4 -0
- package/dist/components/uvalib-analytics/uvalib-analytics.js.map +1 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.d.ts +46 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js +339 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js.map +1 -0
- package/dist/components/uvalib-date-range/uvalib-date-range.d.ts +1 -0
- package/dist/components/uvalib-date-range/uvalib-date-range.js +4 -0
- package/dist/components/uvalib-date-range/uvalib-date-range.js.map +1 -0
- package/dist/components/uvalib-filter/UvalibFilter.d.ts +73 -0
- package/dist/components/uvalib-filter/UvalibFilter.js +279 -0
- package/dist/components/uvalib-filter/UvalibFilter.js.map +1 -0
- package/dist/components/uvalib-filter/uvalib-filter.d.ts +1 -0
- package/dist/components/uvalib-filter/uvalib-filter.js +4 -0
- package/dist/components/uvalib-filter/uvalib-filter.js.map +1 -0
- package/dist/custom-elements.json +15178 -0
- package/dist/data/fetch-json.d.ts +28 -0
- package/dist/data/fetch-json.js +43 -0
- package/dist/data/fetch-json.js.map +1 -0
- package/dist/data/new-york.d.ts +5 -0
- package/dist/data/new-york.js +23 -0
- package/dist/data/new-york.js.map +1 -0
- package/dist/data/sites.d.ts +12 -0
- package/dist/data/sites.js +89 -0
- package/dist/data/sites.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/accessible.d.ts +1 -0
- package/dist/styles/accessible.js +37 -0
- package/dist/styles/accessible.js.map +1 -0
- package/dist/styles/base.d.ts +2 -0
- package/dist/styles/base.js +41 -0
- package/dist/styles/base.js.map +1 -0
- package/dist/styles/color-scheme.d.ts +1 -0
- package/dist/styles/color-scheme.js +81 -0
- package/dist/styles/color-scheme.js.map +1 -0
- package/dist/styles/tokens.d.ts +1 -0
- package/dist/styles/tokens.js +85 -0
- package/dist/styles/tokens.js.map +1 -0
- package/dist/styles/w3-subset.d.ts +1 -0
- package/dist/styles/w3-subset.js +33 -0
- package/dist/styles/w3-subset.js.map +1 -0
- package/dist/tokens.css +152 -0
- package/dist-cdn/base.css +30 -0
- package/dist-cdn/bento-box.js +1035 -0
- package/dist-cdn/bento-box.js.map +1 -0
- package/dist-cdn/chunks/SiteAnalytics-T1Wx3lsb.js +174 -0
- package/dist-cdn/chunks/SiteAnalytics-T1Wx3lsb.js.map +1 -0
- package/dist-cdn/chunks/UvalibElement-BnI-eRRR.js +695 -0
- package/dist-cdn/chunks/UvalibElement-BnI-eRRR.js.map +1 -0
- package/dist-cdn/chunks/accessible-GqhVn5_H.js +40 -0
- package/dist-cdn/chunks/accessible-GqhVn5_H.js.map +1 -0
- package/dist-cdn/chunks/analytics-C8D8n_wt.js +55 -0
- package/dist-cdn/chunks/analytics-C8D8n_wt.js.map +1 -0
- package/dist-cdn/chunks/base-DCGd2Oii.js +117 -0
- package/dist-cdn/chunks/base-DCGd2Oii.js.map +1 -0
- package/dist-cdn/chunks/fetch-json-Cyqv-gLU.js +25 -0
- package/dist-cdn/chunks/fetch-json-Cyqv-gLU.js.map +1 -0
- package/dist-cdn/chunks/heading-level-DIuNS44-.js +31 -0
- package/dist-cdn/chunks/heading-level-DIuNS44-.js.map +1 -0
- package/dist-cdn/chunks/hours-data-Bw6vkIw7.js +181 -0
- package/dist-cdn/chunks/hours-data-Bw6vkIw7.js.map +1 -0
- package/dist-cdn/chunks/library-weekly-hours-ByQ8ugxh.js +346 -0
- package/dist-cdn/chunks/library-weekly-hours-ByQ8ugxh.js.map +1 -0
- package/dist-cdn/chunks/link-DbJSwj16.js +7 -0
- package/dist-cdn/chunks/link-DbJSwj16.js.map +1 -0
- package/dist-cdn/chunks/new-york-DkcnqvJ4.js +18 -0
- package/dist-cdn/chunks/new-york-DkcnqvJ4.js.map +1 -0
- package/dist-cdn/chunks/repeat-CIFUYkyh.js +101 -0
- package/dist-cdn/chunks/repeat-CIFUYkyh.js.map +1 -0
- package/dist-cdn/chunks/site-header-BwDkZ2LL.js +802 -0
- package/dist-cdn/chunks/site-header-BwDkZ2LL.js.map +1 -0
- package/dist-cdn/chunks/site-main-nav-BLAAunnr.js +605 -0
- package/dist-cdn/chunks/site-main-nav-BLAAunnr.js.map +1 -0
- package/dist-cdn/chunks/static-html-1mTAG6nS.js +22 -0
- package/dist-cdn/chunks/static-html-1mTAG6nS.js.map +1 -0
- package/dist-cdn/custom-elements.json +15178 -0
- package/dist-cdn/events-section.js +401 -0
- package/dist-cdn/events-section.js.map +1 -0
- package/dist-cdn/library-hours-setup.js +28 -0
- package/dist-cdn/library-hours-setup.js.map +1 -0
- package/dist-cdn/library-weekly-hours.js +1 -0
- package/dist-cdn/manifest.json +23 -0
- package/dist-cdn/site-analytics.js +6 -0
- package/dist-cdn/site-analytics.js.map +1 -0
- package/dist-cdn/site-footer.js +267 -0
- package/dist-cdn/site-footer.js.map +1 -0
- package/dist-cdn/site-header.js +1 -0
- package/dist-cdn/site-hours-section.js +145 -0
- package/dist-cdn/site-hours-section.js.map +1 -0
- package/dist-cdn/site-main-nav.js +1 -0
- package/dist-cdn/site-page.js +317 -0
- package/dist-cdn/site-page.js.map +1 -0
- package/dist-cdn/site-style.js +42 -0
- package/dist-cdn/site-style.js.map +1 -0
- package/dist-cdn/skills/uvalib-web-components/SKILL.md +276 -0
- package/dist-cdn/skills/uvalib-web-components/reference/components.md +631 -0
- package/dist-cdn/skills/uvalib-web-components/reference/migration.md +74 -0
- package/dist-cdn/skills/uvalib-web-components/reference/snippets.md +147 -0
- package/dist-cdn/tokens.css +152 -0
- package/dist-cdn/uvalib-analytics.js +6 -0
- package/dist-cdn/uvalib-analytics.js.map +1 -0
- package/dist-cdn/uvalib-date-range.js +262 -0
- package/dist-cdn/uvalib-date-range.js.map +1 -0
- package/dist-cdn/uvalib-filter.js +184 -0
- package/dist-cdn/uvalib-filter.js.map +1 -0
- package/package.json +152 -4
- package/skills/uvalib-web-components/SKILL.md +276 -0
- package/skills/uvalib-web-components/reference/components.md +631 -0
- package/skills/uvalib-web-components/reference/migration.md +74 -0
- package/skills/uvalib-web-components/reference/snippets.md +147 -0
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html, css, unsafeCSS } from 'lit';
|
|
8
|
+
import { property, state } from 'lit/decorators.js';
|
|
9
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
10
|
+
import { trackEvent } from '../../base/analytics.js';
|
|
11
|
+
import { UvalibElement } from '../../base/UvalibElement.js';
|
|
12
|
+
import { installLightDomStyles } from '../../base/light-dom-styles.js';
|
|
13
|
+
import { accessible } from '../../styles/accessible.js';
|
|
14
|
+
import { siteLink } from '../link.js';
|
|
15
|
+
import { MAIN_NAV_SNAPSHOT } from './main-nav-data.js';
|
|
16
|
+
import { loadMainNavItems, normalizeItems, readItemsMarkup, } from './main-nav-items.js';
|
|
17
|
+
/** Light-DOM instances share the document id space, so every instance numbers its own ids. */
|
|
18
|
+
let navCounter = 0;
|
|
19
|
+
const MAIN_NAV = 'main-nav';
|
|
20
|
+
const isSourceChild = (n) => n instanceof Element && n.getAttribute('slot') === MAIN_NAV;
|
|
21
|
+
/** Attributes of the source markup that change what the nav renders. */
|
|
22
|
+
const SOURCE_ATTRS = ['href', 'slot'];
|
|
23
|
+
/**
|
|
24
|
+
* Focus rings: inset (as on the live site) so an open panel or a neighbour never covers
|
|
25
|
+
* them; orange on white, brand blue where the background is grey (hover, the open group),
|
|
26
|
+
* so the ring keeps 3:1 contrast.
|
|
27
|
+
*/
|
|
28
|
+
const FOCUS_RULES = `
|
|
29
|
+
.toggle:focus-visible,
|
|
30
|
+
.top-link:focus-visible,
|
|
31
|
+
.panel a:focus-visible {
|
|
32
|
+
outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
|
|
33
|
+
outline-offset: -4px;
|
|
34
|
+
}
|
|
35
|
+
.toggle[aria-expanded='true']:focus-visible,
|
|
36
|
+
.toggle:hover:focus-visible,
|
|
37
|
+
.top-link:hover:focus-visible,
|
|
38
|
+
.panel a:hover:focus-visible {
|
|
39
|
+
outline-color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
const focusRules = unsafeCSS(FOCUS_RULES);
|
|
43
|
+
/** The focus rules scoped to `tag`, for the unlayered light-mode sheet. */
|
|
44
|
+
const lightFocusRules = (tag) => unsafeCSS(FOCUS_RULES.replace(/(^|,)\s*\./gm, `$1 ${tag} .`));
|
|
45
|
+
/** A URL reduced to what "the same page" means here: host (without `www.`) and path. */
|
|
46
|
+
function pageKey(href, base) {
|
|
47
|
+
try {
|
|
48
|
+
const u = new URL(href, base);
|
|
49
|
+
return `${u.host.replace(/^www\./, '')}${u.pathname.replace(/\/+$/, '')}`;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const hashOf = (href, base) => {
|
|
56
|
+
try {
|
|
57
|
+
return new URL(href, base).hash;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The UVA Library main navigation (About, Using the Library, Research & teaching support,
|
|
65
|
+
* Get help), as on library.virginia.edu, following the WAI-ARIA disclosure navigation
|
|
66
|
+
* pattern: one `<nav>` landmark; each group is a `<button aria-expanded aria-controls>`
|
|
67
|
+
* followed by its list of links, and an entry with no group is a plain link. Click, Enter or
|
|
68
|
+
* Space toggles a group and only one is open at a time; Escape closes it and returns focus to
|
|
69
|
+
* its button; arrow keys, Home and End move between the buttons and between a panel's links,
|
|
70
|
+
* and ArrowDown on an open button moves into its panel. In the `bar` layout a panel also closes
|
|
71
|
+
* when focus leaves the nav or on a pointer press outside it. There is no hover-to-open.
|
|
72
|
+
*
|
|
73
|
+
* The items come from, in order of precedence: a `<nav slot="main-nav">` child holding
|
|
74
|
+
* `<ul><li><a href>…</a></li></ul>` (a direct link) or `<li><span>Group</span><ul><li><a href>…`
|
|
75
|
+
* (a group), kept hidden and watched for changes; the `items` property; JSON at `items-src`;
|
|
76
|
+
* and the snapshot of the live menu bundled with the component (see `pnpm sync:main-nav`).
|
|
77
|
+
* Invalid entries are skipped and levels deeper than two are flattened, each with one console
|
|
78
|
+
* warning. Relative hrefs are joined to `root-link-domain`; absolute ones are kept, and
|
|
79
|
+
* fragment-only ones (`#…`, a hash route) stay on this page. A plain click on a link closes
|
|
80
|
+
* the open group.
|
|
81
|
+
*
|
|
82
|
+
* The link for the current page (`current`, default the page location, followed through
|
|
83
|
+
* same-document navigations; host and path, ignoring the query, the hash, a trailing slash
|
|
84
|
+
* and a leading `www.`) gets `aria-current="page"`, and its group button
|
|
85
|
+
* `aria-current="true"`, shown bold with a thick underline. Of links that differ only by
|
|
86
|
+
* hash, the one with the page's hash is marked, else the one without a hash; if every one
|
|
87
|
+
* has a hash, the first is marked while the page has none, and none for a hash none has.
|
|
88
|
+
*
|
|
89
|
+
* `<site-header>` renders it: as a row under the logo on wide screens and as an accordion in
|
|
90
|
+
* the Menu popover on narrow ones.
|
|
91
|
+
*
|
|
92
|
+
* @tagname site-main-nav
|
|
93
|
+
* @slot main-nav - Optional `<nav>` (or `<ul>`) whose list replaces the menu: `<li><a href>` for a direct link, `<li><span>Group</span><ul><li><a href>…</a></li></ul></li>` for a group. It is never shown itself; in light mode it is moved into a hidden holder.
|
|
94
|
+
* @fires site-main-nav-error - `items-src` could not be loaded: both attempts failed (network error, a 10 s timeout per attempt, or no valid entries), after about 21 s at worst; the nav shows the bundled snapshot. `detail` is `{ src, message }`. Bubbles and is composed.
|
|
95
|
+
* @fires uvalib-analytics-event - For `<site-analytics>`: a group was opened, `['site-main-nav', 'menu-open', <the group's label>]` (not on close). Bubbles and is composed.
|
|
96
|
+
* @cssprop [--uva-grey-darkest=#2b2b2b] - Top-level button colour.
|
|
97
|
+
* @cssprop [--uva-brand-blue=#232d4b] - Bar bottom border, chevrons, panel links, and the hover and expanded button text.
|
|
98
|
+
* @cssprop [--uva-grey-100=#dadada] - Hover and expanded button background, and panel link hover background.
|
|
99
|
+
* @cssprop [--uva-brand-orange=#e57200] - Focus ring colour, and the underline of the current page's link and group (also bold, with a 3px underline).
|
|
100
|
+
* @cssprop [--uva-font-family=franklin-gothic-urw, Arial, Helvetica, sans-serif] - Font family.
|
|
101
|
+
* @cssprop --uva-color-text - Dark-mode role token: top-level button text (else `--uva-grey-darkest`).
|
|
102
|
+
* @cssprop --uva-color-link - Dark-mode role token: chevrons, panel links, hover text and the focus ring over hover (else `--uva-brand-blue`).
|
|
103
|
+
* @cssprop --uva-color-surface-hover - Dark-mode role token: hover and open-group background (else `--uva-grey-100`).
|
|
104
|
+
* @cssprop --uva-color-surface-raised - Dark-mode role token: bar and panel background (else #ffffff).
|
|
105
|
+
* @cssprop --uva-color-accent-bg - Dark-mode role token: bar bottom rule (else `--uva-brand-blue`).
|
|
106
|
+
* @cssprop --uva-color-shadow - Dark-mode role token: panel shadow colour (else rgba(0, 0, 0, 0.2)).
|
|
107
|
+
* @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).
|
|
108
|
+
* @cssprop --uva-color-current - Dark-mode role token: current-page underline (else `--uva-brand-orange`).
|
|
109
|
+
*/
|
|
110
|
+
export class SiteMainNav extends UvalibElement {
|
|
111
|
+
constructor() {
|
|
112
|
+
super(...arguments);
|
|
113
|
+
/** Accessible name of the navigation landmark. */
|
|
114
|
+
this.label = 'Main';
|
|
115
|
+
this.rootLinkDomain = 'https://www.library.virginia.edu';
|
|
116
|
+
/** `bar` (a row of buttons with floating panels) or `accordion` (stacked, panels in flow). */
|
|
117
|
+
this.layout = 'bar';
|
|
118
|
+
/** Items from slotted markup, or null when there is none. */
|
|
119
|
+
this.slotItems = null;
|
|
120
|
+
/** Items loaded from `items-src`. */
|
|
121
|
+
this.fetched = null;
|
|
122
|
+
/** Index of the open group. */
|
|
123
|
+
this.open = null;
|
|
124
|
+
this.propItems = null;
|
|
125
|
+
this.warned = new Set();
|
|
126
|
+
this.idBase = `main-nav-${++navCounter}`;
|
|
127
|
+
/** Same-document navigation: re-mark the current page when `current` is not set. */
|
|
128
|
+
this.onLocationChange = () => {
|
|
129
|
+
if (!this.current)
|
|
130
|
+
this.requestUpdate();
|
|
131
|
+
};
|
|
132
|
+
this.listeningLocation = false;
|
|
133
|
+
this.onOutsidePointer = (e) => {
|
|
134
|
+
const nav = this.navEl;
|
|
135
|
+
if (nav && !e.composedPath().includes(nav))
|
|
136
|
+
this.setOpen(null);
|
|
137
|
+
};
|
|
138
|
+
this.listening = false;
|
|
139
|
+
}
|
|
140
|
+
static { this.styles = [
|
|
141
|
+
accessible,
|
|
142
|
+
css `
|
|
143
|
+
:host {
|
|
144
|
+
display: block;
|
|
145
|
+
font-family: var(--uva-font-family, franklin-gothic-urw, Arial, Helvetica, sans-serif);
|
|
146
|
+
font-size: 17px;
|
|
147
|
+
line-height: 1.5;
|
|
148
|
+
}
|
|
149
|
+
:host([hidden]) {
|
|
150
|
+
display: none;
|
|
151
|
+
}
|
|
152
|
+
ul {
|
|
153
|
+
list-style: none;
|
|
154
|
+
margin: 0;
|
|
155
|
+
padding: 0;
|
|
156
|
+
}
|
|
157
|
+
.panel[hidden] {
|
|
158
|
+
display: none;
|
|
159
|
+
}
|
|
160
|
+
.toggle,
|
|
161
|
+
.top-link {
|
|
162
|
+
display: flex;
|
|
163
|
+
align-items: center;
|
|
164
|
+
box-sizing: border-box;
|
|
165
|
+
margin: 0;
|
|
166
|
+
border: 0;
|
|
167
|
+
border-radius: 0;
|
|
168
|
+
background: transparent;
|
|
169
|
+
color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));
|
|
170
|
+
font: inherit;
|
|
171
|
+
font-weight: 500;
|
|
172
|
+
line-height: 1.5;
|
|
173
|
+
text-align: start;
|
|
174
|
+
text-decoration: none;
|
|
175
|
+
cursor: pointer;
|
|
176
|
+
}
|
|
177
|
+
/* Chevron: a rotated border box, turned over when expanded. */
|
|
178
|
+
.toggle::after {
|
|
179
|
+
content: '';
|
|
180
|
+
flex: none;
|
|
181
|
+
inline-size: 0.5em;
|
|
182
|
+
block-size: 0.5em;
|
|
183
|
+
margin-inline-start: 0.75em;
|
|
184
|
+
border-style: solid;
|
|
185
|
+
border-color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));
|
|
186
|
+
border-width: 0 1px 1px 0;
|
|
187
|
+
transform: translateY(-0.15em) rotate(45deg);
|
|
188
|
+
}
|
|
189
|
+
.toggle[aria-expanded='true']::after {
|
|
190
|
+
transform: translateY(0.15em) rotate(-135deg);
|
|
191
|
+
}
|
|
192
|
+
/* Grey for hover and the open group only, never for focus: the orange focus ring
|
|
193
|
+
would fall below 3:1 against it. */
|
|
194
|
+
.toggle:hover,
|
|
195
|
+
.toggle[aria-expanded='true'],
|
|
196
|
+
.top-link:hover {
|
|
197
|
+
background-color: var(--uva-color-surface-hover, var(--uva-grey-100, #dadada));
|
|
198
|
+
color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));
|
|
199
|
+
}
|
|
200
|
+
.panel a {
|
|
201
|
+
display: block;
|
|
202
|
+
color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));
|
|
203
|
+
font-weight: 400;
|
|
204
|
+
text-decoration: underline;
|
|
205
|
+
}
|
|
206
|
+
.panel a:hover {
|
|
207
|
+
background-color: var(--uva-color-surface-hover, var(--uva-grey-100, #dadada));
|
|
208
|
+
text-decoration: none;
|
|
209
|
+
}
|
|
210
|
+
${focusRules}
|
|
211
|
+
/* Current page, and the group holding it: bold with a thick underline, not colour alone. */
|
|
212
|
+
[aria-current]:not([aria-current='false']),
|
|
213
|
+
.panel a[aria-current]:not([aria-current='false']):hover {
|
|
214
|
+
font-weight: 700;
|
|
215
|
+
text-decoration-line: underline;
|
|
216
|
+
text-decoration-thickness: 3px;
|
|
217
|
+
text-decoration-color: var(--uva-color-current, var(--uva-brand-orange, #e57200));
|
|
218
|
+
text-underline-offset: 0.3em;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* Bar: a full-width row with the brand-blue rule, content capped at 1600px. */
|
|
222
|
+
.bar {
|
|
223
|
+
border-bottom: 5px solid var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b));
|
|
224
|
+
background: var(--uva-color-surface-raised, #ffffff);
|
|
225
|
+
}
|
|
226
|
+
.bar > ul {
|
|
227
|
+
display: flex;
|
|
228
|
+
flex-wrap: wrap;
|
|
229
|
+
box-sizing: border-box;
|
|
230
|
+
max-inline-size: 1600px;
|
|
231
|
+
margin-inline: auto;
|
|
232
|
+
padding-inline: 16px;
|
|
233
|
+
}
|
|
234
|
+
.bar > ul > li {
|
|
235
|
+
position: relative;
|
|
236
|
+
display: flex;
|
|
237
|
+
}
|
|
238
|
+
.bar .toggle,
|
|
239
|
+
.bar .top-link {
|
|
240
|
+
padding: 11.5px 17px;
|
|
241
|
+
}
|
|
242
|
+
.bar .panel {
|
|
243
|
+
position: absolute;
|
|
244
|
+
top: 100%;
|
|
245
|
+
inset-inline-start: 0;
|
|
246
|
+
z-index: 1000;
|
|
247
|
+
box-sizing: border-box;
|
|
248
|
+
inline-size: max-content;
|
|
249
|
+
min-inline-size: 100%;
|
|
250
|
+
max-inline-size: 20rem;
|
|
251
|
+
background: var(--uva-color-surface-raised, #ffffff);
|
|
252
|
+
border-radius: 0 0 4px 4px;
|
|
253
|
+
box-shadow: 0 8px 16px var(--uva-color-shadow, rgba(0, 0, 0, 0.2));
|
|
254
|
+
/* Invisible normally; forced colors paint it, so the panel keeps an edge. */
|
|
255
|
+
outline: 1px solid transparent;
|
|
256
|
+
}
|
|
257
|
+
.bar .panel a {
|
|
258
|
+
padding: 8.5px 17px;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/* Accordion (the header's narrow-screen Menu popover): full-width rows, panels in flow. */
|
|
262
|
+
.accordion .toggle,
|
|
263
|
+
.accordion .top-link {
|
|
264
|
+
inline-size: 100%;
|
|
265
|
+
justify-content: space-between;
|
|
266
|
+
padding: 0.375rem 0.5rem;
|
|
267
|
+
}
|
|
268
|
+
.accordion .toggle::after {
|
|
269
|
+
margin-inline-end: 0.25em;
|
|
270
|
+
}
|
|
271
|
+
.accordion .panel {
|
|
272
|
+
position: static;
|
|
273
|
+
padding-inline-start: 1rem;
|
|
274
|
+
}
|
|
275
|
+
.accordion .panel a {
|
|
276
|
+
padding: 0.375rem 0.5rem;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/* Forced colors drop backgrounds and shadows: outline the open group and hovered
|
|
280
|
+
controls instead. */
|
|
281
|
+
@media (forced-colors: active) {
|
|
282
|
+
.toggle[aria-expanded='true']:not(:focus-visible),
|
|
283
|
+
.toggle:hover:not(:focus-visible),
|
|
284
|
+
.top-link:hover:not(:focus-visible),
|
|
285
|
+
.panel a:hover:not(:focus-visible) {
|
|
286
|
+
outline: 1px solid CanvasText;
|
|
287
|
+
outline-offset: -1px;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
`,
|
|
291
|
+
]; }
|
|
292
|
+
/**
|
|
293
|
+
* Light mode: the focus rules again, unlayered. A page's own accessibility sheet (which
|
|
294
|
+
* `<site-page>` installs unlayered) would otherwise beat the layered component rules.
|
|
295
|
+
*/
|
|
296
|
+
installLightStyles(root) {
|
|
297
|
+
super.installLightStyles(root);
|
|
298
|
+
installLightDomStyles(`${this.localName}-focus`, [lightFocusRules(this.localName)], {
|
|
299
|
+
root,
|
|
300
|
+
scope: false,
|
|
301
|
+
layer: false,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
connectedCallback() {
|
|
305
|
+
super.connectedCallback();
|
|
306
|
+
// Read the markup before the first render where it is already there (no second update);
|
|
307
|
+
// the observer catches markup parsed or added later.
|
|
308
|
+
this.syncSource();
|
|
309
|
+
this.listenLocation(true);
|
|
310
|
+
// Reconnected while a group was open: watch for outside presses again.
|
|
311
|
+
this.listenOutside(this.open !== null && this.layout === 'bar');
|
|
312
|
+
}
|
|
313
|
+
disconnectedCallback() {
|
|
314
|
+
super.disconnectedCallback();
|
|
315
|
+
this.observer?.disconnect();
|
|
316
|
+
this.listenOutside(false);
|
|
317
|
+
this.listenLocation(false);
|
|
318
|
+
}
|
|
319
|
+
locationTargets() {
|
|
320
|
+
const win = this.ownerDocument.defaultView;
|
|
321
|
+
if (!win)
|
|
322
|
+
return [];
|
|
323
|
+
const nav = win.navigation;
|
|
324
|
+
return [
|
|
325
|
+
{ target: win, type: 'popstate' },
|
|
326
|
+
{ target: win, type: 'hashchange' },
|
|
327
|
+
...(nav ? [{ target: nav, type: 'currententrychange' }] : []),
|
|
328
|
+
];
|
|
329
|
+
}
|
|
330
|
+
listenLocation(on) {
|
|
331
|
+
if (on === this.listeningLocation)
|
|
332
|
+
return;
|
|
333
|
+
this.listeningLocation = on;
|
|
334
|
+
for (const { target, type } of this.locationTargets()) {
|
|
335
|
+
if (on)
|
|
336
|
+
target.addEventListener(type, this.onLocationChange);
|
|
337
|
+
else
|
|
338
|
+
target.removeEventListener(type, this.onLocationChange);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
warnOnce(kind, what) {
|
|
342
|
+
if (this.warned.has(kind))
|
|
343
|
+
return;
|
|
344
|
+
this.warned.add(kind);
|
|
345
|
+
console.warn(kind === 'invalid'
|
|
346
|
+
? `${this.localName}: ignoring invalid ${what} entries (each needs a label, and an href or links).`
|
|
347
|
+
: `${this.localName}: ${what} nests deeper than two levels; the deeper links are shown in their group.`);
|
|
348
|
+
}
|
|
349
|
+
use(result, what) {
|
|
350
|
+
if (result.invalid)
|
|
351
|
+
this.warnOnce('invalid', what);
|
|
352
|
+
if (result.flattened)
|
|
353
|
+
this.warnOnce('flattened', what);
|
|
354
|
+
return result.items.length ? result.items : null;
|
|
355
|
+
}
|
|
356
|
+
/** Light mode: move `slot="main-nav"` children into a hidden holder this element owns. */
|
|
357
|
+
adoptSource() {
|
|
358
|
+
const moved = [...this.children].filter(isSourceChild);
|
|
359
|
+
if (moved.length && !this.holder) {
|
|
360
|
+
this.holder = document.createElement('div');
|
|
361
|
+
this.holder.hidden = true;
|
|
362
|
+
this.holder.className = 'main-nav-source';
|
|
363
|
+
}
|
|
364
|
+
if (this.holder) {
|
|
365
|
+
this.holder.append(...moved);
|
|
366
|
+
if (this.holder.parentNode !== this)
|
|
367
|
+
this.append(this.holder);
|
|
368
|
+
}
|
|
369
|
+
return this.holder ? [...this.holder.children] : [];
|
|
370
|
+
}
|
|
371
|
+
/** Read the `slot="main-nav"` markup, render it, and watch it for changes. */
|
|
372
|
+
syncSource() {
|
|
373
|
+
const sources = this.lightDom ? this.adoptSource() : [...this.children].filter(isSourceChild);
|
|
374
|
+
let next = null;
|
|
375
|
+
if (sources.length) {
|
|
376
|
+
const raw = sources.flatMap((s, i) => (i === 0 ? readItemsMarkup(s) : [{}]));
|
|
377
|
+
next = this.use(normalizeItems(raw), 'slot="main-nav"');
|
|
378
|
+
}
|
|
379
|
+
// Only a real change re-renders.
|
|
380
|
+
if (JSON.stringify(next) !== JSON.stringify(this.slotItems))
|
|
381
|
+
this.slotItems = next;
|
|
382
|
+
this.observer ??= new MutationObserver(() => this.syncSource());
|
|
383
|
+
this.observer.disconnect();
|
|
384
|
+
const content = {
|
|
385
|
+
attributes: true,
|
|
386
|
+
attributeFilter: SOURCE_ATTRS,
|
|
387
|
+
characterData: true,
|
|
388
|
+
childList: true,
|
|
389
|
+
subtree: true,
|
|
390
|
+
};
|
|
391
|
+
if (this.lightDom) {
|
|
392
|
+
this.observer.observe(this, { childList: true });
|
|
393
|
+
if (this.holder)
|
|
394
|
+
this.observer.observe(this.holder, content);
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
// Shadow mode: the host's children are only the source markup.
|
|
398
|
+
this.observer.observe(this, content);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
willUpdate(changed) {
|
|
402
|
+
if (changed.has('items')) {
|
|
403
|
+
this.propItems = this.items == null ? null : this.use(normalizeItems(this.items), 'items');
|
|
404
|
+
}
|
|
405
|
+
if (changed.has('itemsSrc') && this.fetchedFor !== this.itemsSrc) {
|
|
406
|
+
this.fetched = null;
|
|
407
|
+
this.fetchedFor = undefined;
|
|
408
|
+
}
|
|
409
|
+
const src = this.itemsSrc;
|
|
410
|
+
// Fetch only when items-src is what would be shown. The result arrives asynchronously.
|
|
411
|
+
if (src && !this.slotItems && !this.propItems && this.fetchedFor !== src) {
|
|
412
|
+
this.fetchedFor = src;
|
|
413
|
+
loadMainNavItems(src).then((result) => {
|
|
414
|
+
if (this.itemsSrc !== src)
|
|
415
|
+
return;
|
|
416
|
+
this.fetched = this.use(result, 'items-src');
|
|
417
|
+
}, (error) => {
|
|
418
|
+
if (this.itemsSrc !== src)
|
|
419
|
+
return;
|
|
420
|
+
this.dispatchEvent(new CustomEvent('site-main-nav-error', {
|
|
421
|
+
detail: { src, message: error instanceof Error ? error.message : String(error) },
|
|
422
|
+
bubbles: true,
|
|
423
|
+
composed: true,
|
|
424
|
+
}));
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
// A different menu: the open index would point at another group, so close it.
|
|
428
|
+
const key = JSON.stringify(this.shown);
|
|
429
|
+
if (this.shownKey !== undefined && key !== this.shownKey)
|
|
430
|
+
this.open = null;
|
|
431
|
+
this.shownKey = key;
|
|
432
|
+
}
|
|
433
|
+
updated(changed) {
|
|
434
|
+
if (changed.has('open') || changed.has('layout')) {
|
|
435
|
+
this.listenOutside(this.isConnected && this.open !== null && this.layout === 'bar');
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
/** The items shown, by precedence. */
|
|
439
|
+
get shown() {
|
|
440
|
+
return this.slotItems ?? this.propItems ?? this.fetched ?? MAIN_NAV_SNAPSHOT;
|
|
441
|
+
}
|
|
442
|
+
// --- behaviour ----------------------------------------------------------------------
|
|
443
|
+
get navEl() {
|
|
444
|
+
return this.renderRoot.querySelector('nav.main-nav');
|
|
445
|
+
}
|
|
446
|
+
/** The top-level buttons and direct links, in order. */
|
|
447
|
+
get tops() {
|
|
448
|
+
const nav = this.navEl;
|
|
449
|
+
return nav
|
|
450
|
+
? [...nav.querySelectorAll(':scope > ul > li > :is(.toggle, .top-link)')]
|
|
451
|
+
: [];
|
|
452
|
+
}
|
|
453
|
+
setOpen(index) {
|
|
454
|
+
this.open = index;
|
|
455
|
+
}
|
|
456
|
+
onToggle(index) {
|
|
457
|
+
const opening = this.open !== index;
|
|
458
|
+
this.setOpen(opening ? index : null);
|
|
459
|
+
const label = this.shown[index]?.label;
|
|
460
|
+
if (opening && label)
|
|
461
|
+
trackEvent(this, ['site-main-nav', 'menu-open', label]);
|
|
462
|
+
}
|
|
463
|
+
listenOutside(on) {
|
|
464
|
+
if (on === this.listening)
|
|
465
|
+
return;
|
|
466
|
+
this.listening = on;
|
|
467
|
+
const doc = this.ownerDocument;
|
|
468
|
+
if (on)
|
|
469
|
+
doc.addEventListener('pointerdown', this.onOutsidePointer, true);
|
|
470
|
+
else
|
|
471
|
+
doc.removeEventListener('pointerdown', this.onOutsidePointer, true);
|
|
472
|
+
}
|
|
473
|
+
onFocusOut(e) {
|
|
474
|
+
if (this.layout !== 'bar' || this.open === null)
|
|
475
|
+
return;
|
|
476
|
+
const to = e.relatedTarget;
|
|
477
|
+
// A null relatedTarget (a click on nothing focusable) is left to the pointerdown check.
|
|
478
|
+
if (to && !this.navEl?.contains(to))
|
|
479
|
+
this.setOpen(null);
|
|
480
|
+
}
|
|
481
|
+
/** Arrow keys, Home and End over `nodes`, from `index` (as the live site's script does). */
|
|
482
|
+
move(e, nodes, index) {
|
|
483
|
+
let to;
|
|
484
|
+
switch (e.key) {
|
|
485
|
+
case 'ArrowUp':
|
|
486
|
+
case 'ArrowLeft':
|
|
487
|
+
to = Math.max(0, index - 1);
|
|
488
|
+
break;
|
|
489
|
+
case 'ArrowDown':
|
|
490
|
+
case 'ArrowRight':
|
|
491
|
+
to = Math.min(nodes.length - 1, index + 1);
|
|
492
|
+
break;
|
|
493
|
+
case 'Home':
|
|
494
|
+
to = 0;
|
|
495
|
+
break;
|
|
496
|
+
case 'End':
|
|
497
|
+
to = nodes.length - 1;
|
|
498
|
+
break;
|
|
499
|
+
default:
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
e.preventDefault();
|
|
503
|
+
nodes[to]?.focus();
|
|
504
|
+
}
|
|
505
|
+
onKeyDown(e) {
|
|
506
|
+
if (e.altKey || e.ctrlKey || e.metaKey)
|
|
507
|
+
return;
|
|
508
|
+
const target = e.target;
|
|
509
|
+
const tops = this.tops;
|
|
510
|
+
const top = tops.indexOf(target);
|
|
511
|
+
const open = this.open;
|
|
512
|
+
const openButton = open === null ? null : this.toggleAt(open);
|
|
513
|
+
if (top >= 0) {
|
|
514
|
+
if (e.key === 'Escape') {
|
|
515
|
+
if (open === null)
|
|
516
|
+
return; // nothing to close: let a surrounding popover handle it
|
|
517
|
+
e.preventDefault();
|
|
518
|
+
this.setOpen(null);
|
|
519
|
+
}
|
|
520
|
+
else if (e.key === 'ArrowDown' && openButton === target) {
|
|
521
|
+
e.preventDefault();
|
|
522
|
+
this.panelOf(openButton)?.querySelector('a')?.focus();
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
this.move(e, tops, top);
|
|
526
|
+
}
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
const panel = target.closest('.panel');
|
|
530
|
+
if (!panel || !openButton || this.panelOf(openButton) !== panel)
|
|
531
|
+
return;
|
|
532
|
+
if (e.key === 'Escape') {
|
|
533
|
+
e.preventDefault();
|
|
534
|
+
this.setOpen(null);
|
|
535
|
+
openButton.focus();
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const links = [...panel.querySelectorAll('a')];
|
|
539
|
+
this.move(e, links, links.indexOf(target));
|
|
540
|
+
}
|
|
541
|
+
toggleAt(index) {
|
|
542
|
+
return (this.navEl?.querySelector(`[aria-controls="${this.panelId(index)}"]`) ?? null);
|
|
543
|
+
}
|
|
544
|
+
/** A group button's panel: the list right after it, whose id it controls. */
|
|
545
|
+
panelOf(button) {
|
|
546
|
+
const next = button.nextElementSibling;
|
|
547
|
+
return next && next.id === button.getAttribute('aria-controls') ? next : null;
|
|
548
|
+
}
|
|
549
|
+
panelId(index) {
|
|
550
|
+
return `${this.idBase}-${index}`;
|
|
551
|
+
}
|
|
552
|
+
// --- rendering ----------------------------------------------------------------------
|
|
553
|
+
/** The one link to mark current: same host and path; then the same hash; then no hash. */
|
|
554
|
+
currentHref(hrefs) {
|
|
555
|
+
const here = this.current || this.ownerDocument.defaultView?.location.href || '';
|
|
556
|
+
const base = this.ownerDocument.baseURI;
|
|
557
|
+
const key = pageKey(here, base);
|
|
558
|
+
if (!key)
|
|
559
|
+
return null;
|
|
560
|
+
const matches = hrefs.filter((h) => pageKey(h, base) === key);
|
|
561
|
+
const hash = hashOf(here, base);
|
|
562
|
+
return (matches.find((h) => hash && hashOf(h, base) === hash) ??
|
|
563
|
+
matches.find((h) => !hashOf(h, base)) ??
|
|
564
|
+
// Every match has a hash: with no hash of its own the page is theirs, so the first is
|
|
565
|
+
// marked; a hash none of them has (a hash route the menu does not list) marks none.
|
|
566
|
+
(hash ? null : matches[0]) ??
|
|
567
|
+
null);
|
|
568
|
+
}
|
|
569
|
+
/** A link's href: fragment-only (`#…`) stays on this page; others go through siteLink. */
|
|
570
|
+
resolve(href) {
|
|
571
|
+
return href.startsWith('#') ? href : siteLink(this.rootLinkDomain, href);
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* A plain click on a link closes the open group, so a single-page app that handles the
|
|
575
|
+
* navigation in place does not leave the panel open. Modified clicks (a new tab or
|
|
576
|
+
* window) keep it open.
|
|
577
|
+
*/
|
|
578
|
+
onClick(e) {
|
|
579
|
+
if (this.open === null || e.button !== 0)
|
|
580
|
+
return;
|
|
581
|
+
if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey)
|
|
582
|
+
return;
|
|
583
|
+
if (e.composedPath().some((n) => n instanceof Element && n.localName === 'a')) {
|
|
584
|
+
this.setOpen(null);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
render() {
|
|
588
|
+
const items = this.shown.map((item) => ({
|
|
589
|
+
label: item.label,
|
|
590
|
+
href: item.items ? undefined : this.resolve(item.href),
|
|
591
|
+
items: item.items?.map((l) => ({ label: l.label, href: this.resolve(l.href) })),
|
|
592
|
+
}));
|
|
593
|
+
const all = items.flatMap((i) => (i.items ? i.items.map((l) => l.href) : [i.href]));
|
|
594
|
+
const current = this.currentHref(all);
|
|
595
|
+
const mark = (href) => (href === current ? 'page' : undefined);
|
|
596
|
+
let marked = false;
|
|
597
|
+
return html `<nav
|
|
598
|
+
class="main-nav ${this.layout === 'accordion' ? 'accordion' : 'bar'}"
|
|
599
|
+
aria-label=${this.label}
|
|
600
|
+
@keydown=${this.onKeyDown}
|
|
601
|
+
@focusout=${this.onFocusOut}
|
|
602
|
+
@click=${this.onClick}
|
|
603
|
+
>
|
|
604
|
+
<ul>
|
|
605
|
+
${items.map((item, i) => {
|
|
606
|
+
if (!item.items) {
|
|
607
|
+
const cur = !marked && mark(item.href);
|
|
608
|
+
if (cur)
|
|
609
|
+
marked = true;
|
|
610
|
+
return html `<li>
|
|
611
|
+
<a class="top-link" href=${item.href} aria-current=${ifDefined(cur || undefined)}
|
|
612
|
+
>${item.label}</a
|
|
613
|
+
>
|
|
614
|
+
</li>`;
|
|
615
|
+
}
|
|
616
|
+
const id = this.panelId(i);
|
|
617
|
+
const expanded = this.open === i;
|
|
618
|
+
const has = !marked && item.items.some((l) => l.href === current);
|
|
619
|
+
let linkMarked = false;
|
|
620
|
+
if (has)
|
|
621
|
+
marked = true;
|
|
622
|
+
return html `<li>
|
|
623
|
+
<button
|
|
624
|
+
type="button"
|
|
625
|
+
class="toggle"
|
|
626
|
+
aria-expanded=${expanded ? 'true' : 'false'}
|
|
627
|
+
aria-controls=${id}
|
|
628
|
+
aria-current=${ifDefined(has ? 'true' : undefined)}
|
|
629
|
+
@click=${() => this.onToggle(i)}
|
|
630
|
+
>
|
|
631
|
+
${item.label}
|
|
632
|
+
</button>
|
|
633
|
+
<ul class="panel" id=${id} ?hidden=${!expanded}>
|
|
634
|
+
${item.items.map((l) => {
|
|
635
|
+
const cur = has && !linkMarked && l.href === current;
|
|
636
|
+
if (cur)
|
|
637
|
+
linkMarked = true;
|
|
638
|
+
return html `<li>
|
|
639
|
+
<a href=${l.href} aria-current=${ifDefined(cur ? 'page' : undefined)}
|
|
640
|
+
>${l.label}</a
|
|
641
|
+
>
|
|
642
|
+
</li>`;
|
|
643
|
+
})}
|
|
644
|
+
</ul>
|
|
645
|
+
</li>`;
|
|
646
|
+
})}
|
|
647
|
+
</ul>
|
|
648
|
+
</nav>`;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
__decorate([
|
|
652
|
+
property({ type: String })
|
|
653
|
+
], SiteMainNav.prototype, "label", void 0);
|
|
654
|
+
__decorate([
|
|
655
|
+
property({ type: String, attribute: 'root-link-domain' })
|
|
656
|
+
], SiteMainNav.prototype, "rootLinkDomain", void 0);
|
|
657
|
+
__decorate([
|
|
658
|
+
property({ type: String, attribute: 'items-src' })
|
|
659
|
+
], SiteMainNav.prototype, "itemsSrc", void 0);
|
|
660
|
+
__decorate([
|
|
661
|
+
property({ type: String })
|
|
662
|
+
], SiteMainNav.prototype, "layout", void 0);
|
|
663
|
+
__decorate([
|
|
664
|
+
property({ type: String })
|
|
665
|
+
], SiteMainNav.prototype, "current", void 0);
|
|
666
|
+
__decorate([
|
|
667
|
+
property({ attribute: false })
|
|
668
|
+
], SiteMainNav.prototype, "items", void 0);
|
|
669
|
+
__decorate([
|
|
670
|
+
state()
|
|
671
|
+
], SiteMainNav.prototype, "slotItems", void 0);
|
|
672
|
+
__decorate([
|
|
673
|
+
state()
|
|
674
|
+
], SiteMainNav.prototype, "fetched", void 0);
|
|
675
|
+
__decorate([
|
|
676
|
+
state()
|
|
677
|
+
], SiteMainNav.prototype, "open", void 0);
|
|
678
|
+
//# sourceMappingURL=SiteMainNav.js.map
|