@uvalib/web-components 0.0.0-stage → 1.0.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.
Files changed (254) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/README.md +1164 -2
  3. package/bin/install-skill.mjs +139 -0
  4. package/dist/base/UvalibElement.d.ts +21 -0
  5. package/dist/base/UvalibElement.js +68 -0
  6. package/dist/base/UvalibElement.js.map +1 -0
  7. package/dist/base/analytics.d.ts +44 -0
  8. package/dist/base/analytics.js +59 -0
  9. package/dist/base/analytics.js.map +1 -0
  10. package/dist/base/color-scheme.d.ts +93 -0
  11. package/dist/base/color-scheme.js +267 -0
  12. package/dist/base/color-scheme.js.map +1 -0
  13. package/dist/base/define.d.ts +2 -0
  14. package/dist/base/define.js +6 -0
  15. package/dist/base/define.js.map +1 -0
  16. package/dist/base/heading-level.d.ts +12 -0
  17. package/dist/base/heading-level.js +52 -0
  18. package/dist/base/heading-level.js.map +1 -0
  19. package/dist/base/light-dom-styles.d.ts +18 -0
  20. package/dist/base/light-dom-styles.js +134 -0
  21. package/dist/base/light-dom-styles.js.map +1 -0
  22. package/dist/base.css +30 -0
  23. package/dist/base.d.ts +5 -0
  24. package/dist/base.js +5 -0
  25. package/dist/base.js.map +1 -0
  26. package/dist/components/bento-box/ArticlesSection.d.ts +19 -0
  27. package/dist/components/bento-box/ArticlesSection.js +22 -0
  28. package/dist/components/bento-box/ArticlesSection.js.map +1 -0
  29. package/dist/components/bento-box/BentoBox.d.ts +85 -0
  30. package/dist/components/bento-box/BentoBox.js +366 -0
  31. package/dist/components/bento-box/BentoBox.js.map +1 -0
  32. package/dist/components/bento-box/BentoSection.d.ts +115 -0
  33. package/dist/components/bento-box/BentoSection.js +468 -0
  34. package/dist/components/bento-box/BentoSection.js.map +1 -0
  35. package/dist/components/bento-box/CatalogSection.d.ts +18 -0
  36. package/dist/components/bento-box/CatalogSection.js +19 -0
  37. package/dist/components/bento-box/CatalogSection.js.map +1 -0
  38. package/dist/components/bento-box/LibGuidesSection.d.ts +24 -0
  39. package/dist/components/bento-box/LibGuidesSection.js +73 -0
  40. package/dist/components/bento-box/LibGuidesSection.js.map +1 -0
  41. package/dist/components/bento-box/VirgoSection.d.ts +19 -0
  42. package/dist/components/bento-box/VirgoSection.js +58 -0
  43. package/dist/components/bento-box/VirgoSection.js.map +1 -0
  44. package/dist/components/bento-box/WebsiteSection.d.ts +25 -0
  45. package/dist/components/bento-box/WebsiteSection.js +40 -0
  46. package/dist/components/bento-box/WebsiteSection.js.map +1 -0
  47. package/dist/components/bento-box/bento-box.d.ts +1 -0
  48. package/dist/components/bento-box/bento-box.js +13 -0
  49. package/dist/components/bento-box/bento-box.js.map +1 -0
  50. package/dist/components/bento-box/bento-data.d.ts +147 -0
  51. package/dist/components/bento-box/bento-data.js +422 -0
  52. package/dist/components/bento-box/bento-data.js.map +1 -0
  53. package/dist/components/events-section/EventsSection.d.ts +91 -0
  54. package/dist/components/events-section/EventsSection.js +435 -0
  55. package/dist/components/events-section/EventsSection.js.map +1 -0
  56. package/dist/components/events-section/events-data.d.ts +90 -0
  57. package/dist/components/events-section/events-data.js +174 -0
  58. package/dist/components/events-section/events-data.js.map +1 -0
  59. package/dist/components/events-section/events-section.d.ts +1 -0
  60. package/dist/components/events-section/events-section.js +4 -0
  61. package/dist/components/events-section/events-section.js.map +1 -0
  62. package/dist/components/library-hours/hours-data.d.ts +104 -0
  63. package/dist/components/library-hours/hours-data.js +267 -0
  64. package/dist/components/library-hours/hours-data.js.map +1 -0
  65. package/dist/components/library-hours-setup/LibraryHoursSetup.d.ts +21 -0
  66. package/dist/components/library-hours-setup/LibraryHoursSetup.js +59 -0
  67. package/dist/components/library-hours-setup/LibraryHoursSetup.js.map +1 -0
  68. package/dist/components/library-hours-setup/library-hours-setup.d.ts +1 -0
  69. package/dist/components/library-hours-setup/library-hours-setup.js +5 -0
  70. package/dist/components/library-hours-setup/library-hours-setup.js.map +1 -0
  71. package/dist/components/library-weekly-hours/LibraryWeeklyHours.d.ts +107 -0
  72. package/dist/components/library-weekly-hours/LibraryWeeklyHours.js +502 -0
  73. package/dist/components/library-weekly-hours/LibraryWeeklyHours.js.map +1 -0
  74. package/dist/components/library-weekly-hours/library-weekly-hours.d.ts +1 -0
  75. package/dist/components/library-weekly-hours/library-weekly-hours.js +4 -0
  76. package/dist/components/library-weekly-hours/library-weekly-hours.js.map +1 -0
  77. package/dist/components/link.d.ts +2 -0
  78. package/dist/components/link.js +7 -0
  79. package/dist/components/link.js.map +1 -0
  80. package/dist/components/site-analytics/SiteAnalytics.d.ts +44 -0
  81. package/dist/components/site-analytics/SiteAnalytics.js +161 -0
  82. package/dist/components/site-analytics/SiteAnalytics.js.map +1 -0
  83. package/dist/components/site-analytics/SiteAnalyticsMixin.d.ts +8 -0
  84. package/dist/components/site-analytics/SiteAnalyticsMixin.js +22 -0
  85. package/dist/components/site-analytics/SiteAnalyticsMixin.js.map +1 -0
  86. package/dist/components/site-analytics/site-analytics.d.ts +1 -0
  87. package/dist/components/site-analytics/site-analytics.js +4 -0
  88. package/dist/components/site-analytics/site-analytics.js.map +1 -0
  89. package/dist/components/site-footer/SiteFooter.d.ts +34 -0
  90. package/dist/components/site-footer/SiteFooter.js +275 -0
  91. package/dist/components/site-footer/SiteFooter.js.map +1 -0
  92. package/dist/components/site-footer/icons.d.ts +4 -0
  93. package/dist/components/site-footer/icons.js +7 -0
  94. package/dist/components/site-footer/icons.js.map +1 -0
  95. package/dist/components/site-footer/site-footer.d.ts +1 -0
  96. package/dist/components/site-footer/site-footer.js +4 -0
  97. package/dist/components/site-footer/site-footer.js.map +1 -0
  98. package/dist/components/site-header/SiteHeader.d.ts +154 -0
  99. package/dist/components/site-header/SiteHeader.js +845 -0
  100. package/dist/components/site-header/SiteHeader.js.map +1 -0
  101. package/dist/components/site-header/site-header.d.ts +1 -0
  102. package/dist/components/site-header/site-header.js +12 -0
  103. package/dist/components/site-header/site-header.js.map +1 -0
  104. package/dist/components/site-hours-section/SiteHoursSection.d.ts +63 -0
  105. package/dist/components/site-hours-section/SiteHoursSection.js +243 -0
  106. package/dist/components/site-hours-section/SiteHoursSection.js.map +1 -0
  107. package/dist/components/site-hours-section/site-hours-section.d.ts +1 -0
  108. package/dist/components/site-hours-section/site-hours-section.js +4 -0
  109. package/dist/components/site-hours-section/site-hours-section.js.map +1 -0
  110. package/dist/components/site-main-nav/SiteMainNav.d.ts +136 -0
  111. package/dist/components/site-main-nav/SiteMainNav.js +678 -0
  112. package/dist/components/site-main-nav/SiteMainNav.js.map +1 -0
  113. package/dist/components/site-main-nav/main-nav-data.d.ts +5 -0
  114. package/dist/components/site-main-nav/main-nav-data.js +90 -0
  115. package/dist/components/site-main-nav/main-nav-data.js.map +1 -0
  116. package/dist/components/site-main-nav/main-nav-items.d.ts +49 -0
  117. package/dist/components/site-main-nav/main-nav-items.js +138 -0
  118. package/dist/components/site-main-nav/main-nav-items.js.map +1 -0
  119. package/dist/components/site-main-nav/site-main-nav.d.ts +1 -0
  120. package/dist/components/site-main-nav/site-main-nav.js +4 -0
  121. package/dist/components/site-main-nav/site-main-nav.js.map +1 -0
  122. package/dist/components/site-page/SitePage.d.ts +145 -0
  123. package/dist/components/site-page/SitePage.js +480 -0
  124. package/dist/components/site-page/SitePage.js.map +1 -0
  125. package/dist/components/site-page/alerts.d.ts +24 -0
  126. package/dist/components/site-page/alerts.js +78 -0
  127. package/dist/components/site-page/alerts.js.map +1 -0
  128. package/dist/components/site-page/site-page.d.ts +1 -0
  129. package/dist/components/site-page/site-page.js +7 -0
  130. package/dist/components/site-page/site-page.js.map +1 -0
  131. package/dist/components/site-style/SiteStyle.d.ts +37 -0
  132. package/dist/components/site-style/SiteStyle.js +76 -0
  133. package/dist/components/site-style/SiteStyle.js.map +1 -0
  134. package/dist/components/site-style/site-style.d.ts +1 -0
  135. package/dist/components/site-style/site-style.js +4 -0
  136. package/dist/components/site-style/site-style.js.map +1 -0
  137. package/dist/components/uvalib-analytics/UvalibAnalytics.d.ts +10 -0
  138. package/dist/components/uvalib-analytics/UvalibAnalytics.js +11 -0
  139. package/dist/components/uvalib-analytics/UvalibAnalytics.js.map +1 -0
  140. package/dist/components/uvalib-analytics/UvalibAnalyticsMixin.d.ts +13 -0
  141. package/dist/components/uvalib-analytics/UvalibAnalyticsMixin.js +25 -0
  142. package/dist/components/uvalib-analytics/UvalibAnalyticsMixin.js.map +1 -0
  143. package/dist/components/uvalib-analytics/uvalib-analytics.d.ts +1 -0
  144. package/dist/components/uvalib-analytics/uvalib-analytics.js +4 -0
  145. package/dist/components/uvalib-analytics/uvalib-analytics.js.map +1 -0
  146. package/dist/components/uvalib-date-range/UvalibDateRange.d.ts +46 -0
  147. package/dist/components/uvalib-date-range/UvalibDateRange.js +339 -0
  148. package/dist/components/uvalib-date-range/UvalibDateRange.js.map +1 -0
  149. package/dist/components/uvalib-date-range/uvalib-date-range.d.ts +1 -0
  150. package/dist/components/uvalib-date-range/uvalib-date-range.js +4 -0
  151. package/dist/components/uvalib-date-range/uvalib-date-range.js.map +1 -0
  152. package/dist/components/uvalib-filter/UvalibFilter.d.ts +73 -0
  153. package/dist/components/uvalib-filter/UvalibFilter.js +279 -0
  154. package/dist/components/uvalib-filter/UvalibFilter.js.map +1 -0
  155. package/dist/components/uvalib-filter/uvalib-filter.d.ts +1 -0
  156. package/dist/components/uvalib-filter/uvalib-filter.js +4 -0
  157. package/dist/components/uvalib-filter/uvalib-filter.js.map +1 -0
  158. package/dist/custom-elements.json +15178 -0
  159. package/dist/data/fetch-json.d.ts +28 -0
  160. package/dist/data/fetch-json.js +43 -0
  161. package/dist/data/fetch-json.js.map +1 -0
  162. package/dist/data/new-york.d.ts +5 -0
  163. package/dist/data/new-york.js +23 -0
  164. package/dist/data/new-york.js.map +1 -0
  165. package/dist/data/sites.d.ts +12 -0
  166. package/dist/data/sites.js +89 -0
  167. package/dist/data/sites.js.map +1 -0
  168. package/dist/index.d.ts +33 -0
  169. package/dist/index.js +22 -0
  170. package/dist/index.js.map +1 -0
  171. package/dist/styles/accessible.d.ts +1 -0
  172. package/dist/styles/accessible.js +37 -0
  173. package/dist/styles/accessible.js.map +1 -0
  174. package/dist/styles/base.d.ts +2 -0
  175. package/dist/styles/base.js +41 -0
  176. package/dist/styles/base.js.map +1 -0
  177. package/dist/styles/color-scheme.d.ts +1 -0
  178. package/dist/styles/color-scheme.js +81 -0
  179. package/dist/styles/color-scheme.js.map +1 -0
  180. package/dist/styles/tokens.d.ts +1 -0
  181. package/dist/styles/tokens.js +85 -0
  182. package/dist/styles/tokens.js.map +1 -0
  183. package/dist/styles/w3-subset.d.ts +1 -0
  184. package/dist/styles/w3-subset.js +33 -0
  185. package/dist/styles/w3-subset.js.map +1 -0
  186. package/dist/tokens.css +152 -0
  187. package/dist-cdn/base.css +30 -0
  188. package/dist-cdn/bento-box.js +1023 -0
  189. package/dist-cdn/bento-box.js.map +1 -0
  190. package/dist-cdn/chunks/SiteAnalytics-T1Wx3lsb.js +174 -0
  191. package/dist-cdn/chunks/SiteAnalytics-T1Wx3lsb.js.map +1 -0
  192. package/dist-cdn/chunks/UvalibElement-BnI-eRRR.js +695 -0
  193. package/dist-cdn/chunks/UvalibElement-BnI-eRRR.js.map +1 -0
  194. package/dist-cdn/chunks/accessible-GqhVn5_H.js +40 -0
  195. package/dist-cdn/chunks/accessible-GqhVn5_H.js.map +1 -0
  196. package/dist-cdn/chunks/analytics-C8D8n_wt.js +55 -0
  197. package/dist-cdn/chunks/analytics-C8D8n_wt.js.map +1 -0
  198. package/dist-cdn/chunks/base-DCGd2Oii.js +117 -0
  199. package/dist-cdn/chunks/base-DCGd2Oii.js.map +1 -0
  200. package/dist-cdn/chunks/fetch-json-Cyqv-gLU.js +25 -0
  201. package/dist-cdn/chunks/fetch-json-Cyqv-gLU.js.map +1 -0
  202. package/dist-cdn/chunks/heading-level-DIuNS44-.js +31 -0
  203. package/dist-cdn/chunks/heading-level-DIuNS44-.js.map +1 -0
  204. package/dist-cdn/chunks/hours-data-Bw6vkIw7.js +181 -0
  205. package/dist-cdn/chunks/hours-data-Bw6vkIw7.js.map +1 -0
  206. package/dist-cdn/chunks/library-weekly-hours-ByQ8ugxh.js +346 -0
  207. package/dist-cdn/chunks/library-weekly-hours-ByQ8ugxh.js.map +1 -0
  208. package/dist-cdn/chunks/link-DbJSwj16.js +7 -0
  209. package/dist-cdn/chunks/link-DbJSwj16.js.map +1 -0
  210. package/dist-cdn/chunks/new-york-DkcnqvJ4.js +18 -0
  211. package/dist-cdn/chunks/new-york-DkcnqvJ4.js.map +1 -0
  212. package/dist-cdn/chunks/repeat-CIFUYkyh.js +101 -0
  213. package/dist-cdn/chunks/repeat-CIFUYkyh.js.map +1 -0
  214. package/dist-cdn/chunks/site-header-BwDkZ2LL.js +802 -0
  215. package/dist-cdn/chunks/site-header-BwDkZ2LL.js.map +1 -0
  216. package/dist-cdn/chunks/site-main-nav-BLAAunnr.js +605 -0
  217. package/dist-cdn/chunks/site-main-nav-BLAAunnr.js.map +1 -0
  218. package/dist-cdn/chunks/static-html-1mTAG6nS.js +22 -0
  219. package/dist-cdn/chunks/static-html-1mTAG6nS.js.map +1 -0
  220. package/dist-cdn/custom-elements.json +15178 -0
  221. package/dist-cdn/events-section.js +401 -0
  222. package/dist-cdn/events-section.js.map +1 -0
  223. package/dist-cdn/library-hours-setup.js +28 -0
  224. package/dist-cdn/library-hours-setup.js.map +1 -0
  225. package/dist-cdn/library-weekly-hours.js +1 -0
  226. package/dist-cdn/manifest.json +23 -0
  227. package/dist-cdn/site-analytics.js +6 -0
  228. package/dist-cdn/site-analytics.js.map +1 -0
  229. package/dist-cdn/site-footer.js +267 -0
  230. package/dist-cdn/site-footer.js.map +1 -0
  231. package/dist-cdn/site-header.js +1 -0
  232. package/dist-cdn/site-hours-section.js +145 -0
  233. package/dist-cdn/site-hours-section.js.map +1 -0
  234. package/dist-cdn/site-main-nav.js +1 -0
  235. package/dist-cdn/site-page.js +317 -0
  236. package/dist-cdn/site-page.js.map +1 -0
  237. package/dist-cdn/site-style.js +42 -0
  238. package/dist-cdn/site-style.js.map +1 -0
  239. package/dist-cdn/skills/uvalib-web-components/SKILL.md +276 -0
  240. package/dist-cdn/skills/uvalib-web-components/reference/components.md +631 -0
  241. package/dist-cdn/skills/uvalib-web-components/reference/migration.md +52 -0
  242. package/dist-cdn/skills/uvalib-web-components/reference/snippets.md +147 -0
  243. package/dist-cdn/tokens.css +152 -0
  244. package/dist-cdn/uvalib-analytics.js +6 -0
  245. package/dist-cdn/uvalib-analytics.js.map +1 -0
  246. package/dist-cdn/uvalib-date-range.js +262 -0
  247. package/dist-cdn/uvalib-date-range.js.map +1 -0
  248. package/dist-cdn/uvalib-filter.js +184 -0
  249. package/dist-cdn/uvalib-filter.js.map +1 -0
  250. package/package.json +152 -4
  251. package/skills/uvalib-web-components/SKILL.md +276 -0
  252. package/skills/uvalib-web-components/reference/components.md +631 -0
  253. package/skills/uvalib-web-components/reference/migration.md +52 -0
  254. package/skills/uvalib-web-components/reference/snippets.md +147 -0
@@ -0,0 +1,845 @@
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, nothing } 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 { siteLink } from '../link.js';
13
+ import { accessible } from '../../styles/accessible.js';
14
+ import { ColorSchemeController } from '../../base/color-scheme.js';
15
+ import { normalizeItems, readItemsMarkup, } from '../site-main-nav/main-nav-items.js';
16
+ const ACCOUNT_URL = 'https://search.lib.virginia.edu/account';
17
+ const FULL_LINKS = [
18
+ { label: 'My account', path: ACCOUNT_URL },
19
+ { label: 'Ask a Librarian', path: '/askalibrarian' },
20
+ { label: 'Hours', path: '/hours' },
21
+ { label: 'Give', path: '/support-library' },
22
+ { label: 'Alerts', path: '/status#alerts' },
23
+ { label: 'Search', path: '/search' },
24
+ ];
25
+ const VENDOR_LINKS = FULL_LINKS.filter((l) => l.label === 'Ask a Librarian');
26
+ /** Light-DOM instances share the document id space, so each gets its own popover id. */
27
+ let menuCounter = 0;
28
+ /** Radio group names are per instance and per control (two controls per header). */
29
+ let schemeCounter = 0;
30
+ /** The reversed (white) library logo, for dark mode. Same aspect ratio as the navy one. */
31
+ export const DARK_LOGO_URL = 'https://static.lib.virginia.edu/files/downloads/LibraryLogos/UVALIB_primary_color_white_web.png';
32
+ const SCHEME_OPTIONS = [
33
+ { value: 'light', label: 'Light' },
34
+ { value: 'dark', label: 'Dark' },
35
+ { value: 'system', label: 'System' },
36
+ ];
37
+ const SITE_LINKS = 'site-links';
38
+ const isSiteLinksChild = (n) => n instanceof Element && n.getAttribute('slot') === SITE_LINKS;
39
+ const MAIN_NAV = 'main-nav';
40
+ const isMainNavChild = (n) => n instanceof Element && n.getAttribute('slot') === MAIN_NAV;
41
+ const ALERTS = 'alerts';
42
+ const isAlertsChild = (n) => n instanceof Element && n.getAttribute('slot') === ALERTS;
43
+ /** Attributes of a source anchor that change what the header renders. */
44
+ const LINK_ATTRS = ['href', 'aria-current', 'target', 'rel', 'hreflang'];
45
+ /** Swallows the popover accordion's copy of an `items-src` error the bar also reports. */
46
+ const stopEvent = (e) => e.stopPropagation();
47
+ /**
48
+ * UVA Library site header: logo, utility navigation, and a popover menu on narrow screens.
49
+ *
50
+ * A site can replace the library utility links (My account, Ask a Librarian, Hours, Give,
51
+ * Alerts, Search) with its own: give the header `<a slot="site-links" href="…">` children.
52
+ * They are shown, in order, in the inline nav and the Menu popover, with `href` as written
53
+ * (not joined to `root-link-domain`) and their `aria-current`, `target`, `rel` and
54
+ * `hreflang`. The source anchors themselves stay hidden. Children that are not `<a href>`
55
+ * with text (empty or whitespace-only text counts as none) are ignored with one console
56
+ * warning. The `vendor` variant ignores site links and keeps
57
+ * its own reduced link set.
58
+ *
59
+ * The full header also shows the UVA Library main navigation (`<site-main-nav>`): a row
60
+ * under the logo row on wide screens, and an accordion at the top of the Menu popover on
61
+ * narrow ones (992px and below), above the utility or site links. `no-main-nav` turns it
62
+ * off, leaving the header exactly as it was without it; the `vendor` variant never shows it.
63
+ * A `<nav slot="main-nav">` child replaces its links (see `<site-main-nav>`), and
64
+ * `main-nav-src` loads them from JSON; `main-nav-current` sets the URL marked current.
65
+ *
66
+ * `color-scheme-switch` opts in to dark mode (off by default; see the README's "Dark mode"):
67
+ * a Light / Dark / System radio group ("Theme") at the end of the utility-links row on wide
68
+ * screens and at the bottom of the Menu popover on narrow ones. The `vendor` variant, which
69
+ * has no Menu, shows it after its inline link, on a row of its own under the logo row on
70
+ * narrow screens. In dark mode the logo is the reversed (white) one.
71
+ *
72
+ * @tagname site-header
73
+ * @slot skip-link - Shadow mode only: optional skip link, rendered first inside `<header>` (`<site-page>` uses it).
74
+ * @slot alerts - Optional alert banner (`<site-page>` passes its `<uvalib-alerts show="header">`), shown as a full-bleed row at the very top of `<header>` (flush with its top and both edges, outside its padding), after the skip link and before the logo row. In light mode the children are moved to the start of `<header>`. The header never loads alerts itself.
75
+ * @slot main-nav - Optional `<nav>` whose `<ul>` replaces the main navigation's links in both layouts: `<li><a href>` for a direct link, `<li><span>Group</span><ul><li><a href>…</a></li></ul></li>` for a group. Invalid entries are skipped with one console warning. Never shown itself; in light mode it is moved into a hidden holder. Ignored with `no-main-nav` and by the `vendor` variant.
76
+ * @slot site-links - Optional `<a href>` elements with text that replace the library utility links in the inline nav and the Menu popover (ignored by the `vendor` variant). In light mode they are moved into a hidden holder.
77
+ * @csspart header - The `<header>` element.
78
+ * @fires site-main-nav-error - `main-nav-src` could not be loaded; the bundled main navigation is shown. `detail` is `{ src, message }`. Fired once, from the bar's `<site-main-nav>`; bubbles and is composed.
79
+ * @fires uvalib-analytics-event - For `<site-analytics>`: the visitor picked a colour scheme, `['site-header', 'color-scheme', 'light' | 'dark' | 'system']` (not the initial value), and the main navigation's menu opens (see `<site-main-nav>`). Bubbles and is composed.
80
+ * @cssprop [--uva-blue-alt-dark=#005679] - Utility link colour.
81
+ * @cssprop [--uva-grey-darkest=#2b2b2b] - Menu button colour.
82
+ * @cssprop [--uva-brand-orange=#e57200] - Focus ring colour (focus-visible outline), and the underline colour of an `aria-current` link (also bold, with a 3px underline).
83
+ * @cssprop [--uva-brand-blue=#232d4b] - Skip-link background for a skip link slotted into `skip-link` (shadow mode, shared accessibility sheet).
84
+ * @cssprop --uva-color-surface-raised - Dark-mode role token: header, Menu popover and theme control background (else #ffffff).
85
+ * @cssprop --uva-color-utility-link - Dark-mode role token: utility and site link colour (else `--uva-blue-alt-dark`).
86
+ * @cssprop --uva-color-text - Dark-mode role token: Menu button and theme control text (else `--uva-grey-darkest`).
87
+ * @cssprop --uva-color-border - Dark-mode role token: popover border and rules (else #ccc).
88
+ * @cssprop --uva-color-control-border - Dark-mode role token: theme control border (else `--uva-grey`, #808080).
89
+ * @cssprop --uva-color-accent-bg - Dark-mode role token: selected theme option and skip-link background (else `--uva-brand-blue`).
90
+ * @cssprop --uva-color-on-accent - Dark-mode role token: selected theme option and skip-link text (else #fff).
91
+ * @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).
92
+ * @cssprop --uva-color-current - Dark-mode role token: current-page underline (else `--uva-brand-orange`).
93
+ */
94
+ export class SiteHeader extends UvalibElement {
95
+ static { this.styles = [
96
+ accessible,
97
+ css `
98
+ :host {
99
+ display: block;
100
+ width: 100%;
101
+ }
102
+ /* Logo on the start, everything else on the end, as one row. A grid (not a wrapping
103
+ flex row) so an alerts row can span the top without changing where the logo row
104
+ breaks: flex wrapping decides lines on max-content sizes before anything shrinks. */
105
+ header {
106
+ display: grid;
107
+ grid-template-columns: auto minmax(0, 1fr);
108
+ align-items: start;
109
+ position: relative;
110
+ background-color: var(--uva-color-surface-raised, #ffffff);
111
+ --_pad-block: 0.5rem;
112
+ --_pad-inline: 16px; /* old: .w3-container 16px side padding */
113
+ padding: var(--_pad-block) var(--_pad-inline);
114
+ }
115
+ header > :not(.logo) {
116
+ grid-column: 2;
117
+ justify-self: end;
118
+ }
119
+ /* The alerts (slot="alerts") are a full-bleed row above the logo row, as in Virgo:
120
+ negative margins equal to the header's padding put them flush with the top and both
121
+ edges, and the bottom margin gives the logo row back its top padding. With no
122
+ alerts content they take no space, so the logo row is exactly where it was. */
123
+ ::slotted([slot='alerts']),
124
+ header > [slot='alerts'] {
125
+ grid-column: 1 / -1;
126
+ justify-self: stretch;
127
+ min-inline-size: 0;
128
+ margin: calc(-1 * var(--_pad-block)) calc(-1 * var(--_pad-inline)) var(--_pad-block);
129
+ }
130
+ .logo {
131
+ display: block;
132
+ text-decoration: none;
133
+ }
134
+ .logo img {
135
+ display: block;
136
+ max-width: 225px;
137
+ height: auto;
138
+ }
139
+ nav ul {
140
+ list-style-type: none;
141
+ margin: 0;
142
+ padding: 0;
143
+ }
144
+ /* Old nav hung from the top of the header below the default 1em list margin. */
145
+ nav.inline ul {
146
+ margin: 1em 0;
147
+ display: flex;
148
+ gap: 1.5rem;
149
+ }
150
+ a {
151
+ color: var(--uva-color-utility-link, var(--uva-blue-alt-dark, #005679));
152
+ }
153
+ /* Current page: bold with a thick underline, so it does not rely on colour alone. */
154
+ nav a[aria-current]:not([aria-current='false']) {
155
+ font-weight: 700;
156
+ text-decoration-line: underline;
157
+ text-decoration-thickness: 3px;
158
+ text-decoration-color: var(--uva-color-current, var(--uva-brand-orange, #e57200));
159
+ text-underline-offset: 0.3em;
160
+ }
161
+ .menu-toggle {
162
+ display: none;
163
+ align-items: center;
164
+ gap: 0.25rem;
165
+ background: none;
166
+ border: none;
167
+ color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));
168
+ font: inherit;
169
+ cursor: pointer;
170
+ }
171
+ /* Old shared sheet sized every inline svg at 17px. */
172
+ .menu-toggle svg {
173
+ width: 17px;
174
+ height: 17px;
175
+ }
176
+ [popover] {
177
+ position: fixed;
178
+ inset: auto;
179
+ /* Fallback offset (about the header height) for engines without anchor(). */
180
+ top: 4.75rem;
181
+ inset-inline-end: 1rem;
182
+ inline-size: min(80dvw, 24rem);
183
+ max-inline-size: calc(100dvw - 2rem);
184
+ block-size: fit-content;
185
+ max-block-size: calc(100dvh - 6rem);
186
+ overflow: auto;
187
+ box-sizing: border-box;
188
+ margin: 0.5rem 0 0;
189
+ padding: 0.5rem 1rem;
190
+ border: 1px solid var(--uva-color-border, #ccc);
191
+ background: var(--uva-color-surface-raised, #ffffff);
192
+ }
193
+ nav.menu li {
194
+ padding: 0.375rem 0;
195
+ }
196
+ /* The main navigation: a full-bleed row under the logo row, flush with the header's
197
+ bottom (its 5px rule is the header's bottom edge), 0.5rem below the logo row. */
198
+ header > site-main-nav.bar {
199
+ grid-column: 1 / -1;
200
+ justify-self: stretch;
201
+ min-inline-size: 0;
202
+ margin: var(--_pad-block) calc(-1 * var(--_pad-inline)) calc(-1 * var(--_pad-block));
203
+ }
204
+ /* Narrow screens: the main navigation leads the Menu popover, then a rule, then the
205
+ utility or site links. */
206
+ .menu-popover > site-main-nav + nav.menu > ul,
207
+ .menu-popover > .color-scheme {
208
+ margin-block-start: 0.5rem;
209
+ padding-block-start: 0.5rem;
210
+ border-block-start: 1px solid var(--uva-color-border, #ccc);
211
+ }
212
+ nav.menu {
213
+ display: contents;
214
+ }
215
+ @supports (top: anchor(--x bottom)) {
216
+ [popover] {
217
+ top: anchor(var(--menu-anchor) bottom);
218
+ }
219
+ }
220
+ /* One line: the links wrap within their own space, the control stays at the end. */
221
+ .utility-row {
222
+ display: flex;
223
+ align-items: center;
224
+ justify-content: flex-end;
225
+ column-gap: 1.5rem;
226
+ min-inline-size: 0;
227
+ }
228
+ .utility-row > nav.inline {
229
+ min-inline-size: 0;
230
+ }
231
+ .utility-row > nav.inline ul {
232
+ flex-wrap: wrap;
233
+ justify-content: flex-end;
234
+ row-gap: 0.25rem;
235
+ }
236
+ .utility-row > .color-scheme {
237
+ flex: none;
238
+ }
239
+ .color-scheme {
240
+ min-inline-size: 0;
241
+ margin: 0;
242
+ padding: 0;
243
+ border: 0;
244
+ color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));
245
+ }
246
+ .color-scheme legend {
247
+ padding: 0;
248
+ font-weight: 700;
249
+ }
250
+ .segments {
251
+ display: flex;
252
+ border: 1px solid var(--uva-color-control-border, var(--uva-grey, #808080));
253
+ border-radius: 0.3rem;
254
+ background: var(--uva-color-surface-raised, #ffffff);
255
+ }
256
+ .segments label {
257
+ position: relative;
258
+ display: flex;
259
+ flex: 1;
260
+ min-inline-size: 28px;
261
+ font-size: 0.875rem;
262
+ cursor: pointer;
263
+ }
264
+ .segments label + label {
265
+ border-inline-start: 1px solid var(--uva-color-control-border, var(--uva-grey, #808080));
266
+ }
267
+ .segment {
268
+ display: flex;
269
+ flex: 1;
270
+ align-items: center;
271
+ justify-content: center;
272
+ min-block-size: 28px;
273
+ padding: 0.125rem 0.625rem;
274
+ }
275
+ .segments input {
276
+ position: absolute;
277
+ inset: 0;
278
+ inline-size: 100%;
279
+ block-size: 100%;
280
+ margin: 0;
281
+ opacity: 0;
282
+ cursor: pointer;
283
+ }
284
+ .segments input:checked + .segment {
285
+ background: var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b));
286
+ color: var(--uva-color-on-accent, #ffffff);
287
+ font-weight: 700;
288
+ }
289
+ .segments input:focus-visible + .segment {
290
+ position: relative;
291
+ z-index: 1;
292
+ outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
293
+ outline-offset: 2px;
294
+ }
295
+ /* Floated, so it is not drawn into the fieldset's top border (the popover rule). */
296
+ .menu-popover > .color-scheme legend {
297
+ float: inline-start;
298
+ inline-size: 100%;
299
+ margin-block-end: 0.375rem;
300
+ }
301
+ .menu-popover > .color-scheme .segments {
302
+ clear: both;
303
+ }
304
+ @media (forced-colors: active) {
305
+ .segments input:checked + .segment {
306
+ forced-color-adjust: none;
307
+ background: Highlight;
308
+ color: HighlightText;
309
+ }
310
+ }
311
+ @media screen and (max-width: 992px) {
312
+ header:not(.vendor) nav.inline,
313
+ header:not(.vendor) .utility-row,
314
+ header > site-main-nav.bar {
315
+ display: none;
316
+ }
317
+ header.vendor .utility-row {
318
+ display: contents;
319
+ }
320
+ header.vendor .utility-row > nav.inline {
321
+ grid-column: 2;
322
+ justify-self: end;
323
+ }
324
+ header.vendor .utility-row > .color-scheme {
325
+ grid-column: 1 / -1;
326
+ justify-self: end;
327
+ margin-block-end: 0.5rem;
328
+ }
329
+ .menu-toggle {
330
+ display: inline-flex;
331
+ }
332
+ }
333
+ @media screen and (min-width: 993px) {
334
+ .menu-toggle,
335
+ [popover] {
336
+ display: none;
337
+ }
338
+ }
339
+ `,
340
+ ]; }
341
+ constructor() {
342
+ super();
343
+ this.rootLinkDomain = 'https://www.library.virginia.edu';
344
+ this.variant = 'full';
345
+ /** Hide the UVA Library main navigation (the row under the logo and the popover accordion). */
346
+ this.noMainNav = false;
347
+ /**
348
+ * Opt in to dark mode: the page follows the OS light or dark preference ("System"), and a
349
+ * Light / Dark / System control (at the end of the utility-links row on wide screens, at
350
+ * the bottom of the Menu popover on narrow ones) lets the visitor override it, remembered
351
+ * per site in localStorage (`uvalib-color-scheme`). Sets `data-uva-color-scheme` on the root
352
+ * element, and swaps in the reversed logo while dark. Ignored (the page stays light and no
353
+ * control is shown) in browsers without CSS `light-dark()`.
354
+ */
355
+ this.colorSchemeSwitch = false;
356
+ this.scheme = new ColorSchemeController(this, () => this.colorSchemeSwitch, () => this.noStyle);
357
+ this.schemeName = `uva-color-scheme-${++schemeCounter}`;
358
+ /** Main navigation items from `slot="main-nav"` markup, or null for the default. */
359
+ this.mainNavItems = null;
360
+ this.warnedMainNav = false;
361
+ /** The site's own links, or null to show the library utility links. */
362
+ this.siteLinks = null;
363
+ this.warnedInvalid = false;
364
+ /**
365
+ * A plain click on a link in the Menu popover closes it, so a single-page app that handles
366
+ * the navigation in place does not leave the menu open. Modified clicks (a new tab or
367
+ * window) keep it open.
368
+ */
369
+ this.onMenuLinkClick = (e) => {
370
+ if (e.button !== 0 || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey)
371
+ return;
372
+ const path = e.composedPath();
373
+ const link = path.findIndex((n) => n instanceof Element && n.localName === 'a');
374
+ const menu = path.findIndex((n) => n instanceof HTMLElement && n.id === this.menuId);
375
+ if (link < 0 || menu < link)
376
+ return;
377
+ const popover = path[menu];
378
+ if (popover.matches(':popover-open'))
379
+ popover.hidePopover();
380
+ };
381
+ this.addEventListener('click', this.onMenuLinkClick);
382
+ }
383
+ connectedCallback() {
384
+ super.connectedCallback();
385
+ // Reconnect after a disconnect; the first connect reads the links in firstUpdated().
386
+ if (this.hasUpdated)
387
+ this.syncChildren();
388
+ // The main-nav markup is read before the first render too, so it costs no second update.
389
+ else
390
+ this.syncMainNav();
391
+ }
392
+ disconnectedCallback() {
393
+ super.disconnectedCallback();
394
+ this.observer?.disconnect();
395
+ }
396
+ willUpdate(changed) {
397
+ if (!changed.has('colorSchemeSwitch'))
398
+ return;
399
+ const was = this.scheme.active;
400
+ this.scheme.sync();
401
+ // Light mode: turning dark mode on or off swaps the header template, and Lit clears
402
+ // everything after its start marker: the alerts moved into the old <header> and the
403
+ // hidden source holders. Move them before the marker; updated() re-adopts the alerts.
404
+ if (this.lightDom && this.hasUpdated && was !== this.scheme.active) {
405
+ const header = this.querySelector(':scope > header');
406
+ const keep = [...(header?.children ?? [])].filter(isAlertsChild);
407
+ for (const holder of [this.holder, this.mainNavHolder])
408
+ if (holder)
409
+ keep.push(holder);
410
+ this.prepend(...keep);
411
+ }
412
+ }
413
+ updated(changed) {
414
+ if (changed.has('colorSchemeSwitch') && this.hasUpdated)
415
+ this.adoptAlerts();
416
+ }
417
+ firstUpdated() {
418
+ this.syncChildren();
419
+ }
420
+ /** The navy logo, or the reversed (white) one while the page shows dark mode. */
421
+ logoSrc() {
422
+ return this.scheme.logoDark
423
+ ? DARK_LOGO_URL
424
+ : siteLink(this.rootLinkDomain, '/sites/default/files/2022-09/library_rgb.png');
425
+ }
426
+ onSchemeChange(e) {
427
+ const input = e.target;
428
+ if (!input.checked)
429
+ return;
430
+ this.scheme.choose(input.value);
431
+ trackEvent(this, ['site-header', 'color-scheme', input.value]);
432
+ }
433
+ /**
434
+ * The Light / Dark / System radio group. `inline` sits in the utility-links row, with its
435
+ * legend visually hidden; `menu` closes the Menu popover, legend shown. "System" names
436
+ * what it resolves to (the OS preference, whichever option is chosen), for screen readers.
437
+ * Each option's look is on the span after its radio (no `:has()`, which Firefox 120 lacks).
438
+ */
439
+ schemeControl(where) {
440
+ const { preference, systemDark } = this.scheme;
441
+ const hint = ` (currently ${systemDark ? 'dark' : 'light'})`;
442
+ const name = `${this.schemeName}-${where}`;
443
+ return html `<fieldset class="color-scheme ${where}">
444
+ <legend class=${where === 'inline' ? 'visually-hidden' : ''}>Theme</legend>
445
+ <div class="segments">
446
+ ${SCHEME_OPTIONS.map((o) => html `<label
447
+ ><input
448
+ type="radio"
449
+ name=${name}
450
+ value=${o.value}
451
+ .checked=${preference === o.value}
452
+ @change=${this.onSchemeChange}
453
+ /><span class="segment"
454
+ >${o.label}${o.value === 'system'
455
+ ? html `<span class="visually-hidden">${hint}</span>`
456
+ : nothing}</span
457
+ ></label
458
+ >`)}
459
+ </div>
460
+ </fieldset>`;
461
+ }
462
+ /** Light mode: place slotted alerts in `<header>`, then read the site links and main nav. */
463
+ syncChildren() {
464
+ this.adoptAlerts();
465
+ this.syncSources();
466
+ }
467
+ /** Read the site links and the main-nav markup, and watch both. */
468
+ syncSources() {
469
+ const sources = [...this.syncSiteLinks(), ...this.syncMainNav()];
470
+ this.watch(sources);
471
+ }
472
+ /**
473
+ * Shadow mode: the `slot="main-nav"` children, with a forwarded `<slot>` (from
474
+ * `<site-page>`) replaced by what is assigned to it. Needs no rendered slot.
475
+ */
476
+ get slottedMainNav() {
477
+ return [...this.children]
478
+ .filter(isMainNavChild)
479
+ .flatMap((k) => (k instanceof HTMLSlotElement ? k.assignedElements({ flatten: true }) : [k]));
480
+ }
481
+ /** Light mode: move `slot="main-nav"` children into their own hidden holder. */
482
+ adoptMainNav() {
483
+ const moved = [...this.children].filter(isMainNavChild);
484
+ if (moved.length && !this.mainNavHolder) {
485
+ this.mainNavHolder = document.createElement('div');
486
+ this.mainNavHolder.hidden = true;
487
+ this.mainNavHolder.className = 'main-nav-source';
488
+ }
489
+ if (this.mainNavHolder) {
490
+ this.mainNavHolder.append(...moved);
491
+ if (this.mainNavHolder.parentNode !== this)
492
+ this.append(this.mainNavHolder);
493
+ }
494
+ return this.mainNavHolder ? [...this.mainNavHolder.children] : [];
495
+ }
496
+ /** Read the `slot="main-nav"` markup once, for both main-nav instances. */
497
+ syncMainNav() {
498
+ const sources = this.lightDom ? this.adoptMainNav() : this.slottedMainNav;
499
+ if (!sources.length) {
500
+ if (this.mainNavItems)
501
+ this.mainNavItems = null;
502
+ return sources;
503
+ }
504
+ const raw = sources.flatMap((s, i) => (i === 0 ? readItemsMarkup(s) : [{}]));
505
+ const result = normalizeItems(raw);
506
+ if ((result.invalid || result.flattened) && !this.warnedMainNav) {
507
+ this.warnedMainNav = true;
508
+ console.warn(`${this.localName}: ignoring invalid slot="${MAIN_NAV}" entries (each needs a label, and an href or links; deeper levels are shown in their group).`);
509
+ }
510
+ const next = result.items.length ? result.items : null;
511
+ // Only a real change re-renders the header and both navs.
512
+ if (JSON.stringify(next) !== JSON.stringify(this.mainNavItems))
513
+ this.mainNavItems = next;
514
+ return sources;
515
+ }
516
+ /**
517
+ * Light mode has no slots: move `slot="alerts"` children to the start of `<header>`, after
518
+ * any alerts already there. That is before every Lit part in the header, so re-renders
519
+ * never touch them.
520
+ */
521
+ adoptAlerts() {
522
+ if (!this.lightDom)
523
+ return;
524
+ const header = this.querySelector(':scope > header');
525
+ const incoming = [...this.children].filter(isAlertsChild);
526
+ if (!header || !incoming.length)
527
+ return;
528
+ let ref = header.firstChild;
529
+ while (isAlertsChild(ref))
530
+ ref = ref.nextSibling;
531
+ for (const n of incoming)
532
+ header.insertBefore(n, ref);
533
+ }
534
+ /** Shadow mode: the elements assigned to the site-links slot, through forwarded slots. */
535
+ get slotted() {
536
+ const slot = this.renderRoot.querySelector(`slot[name="${SITE_LINKS}"]`);
537
+ return slot?.assignedElements({ flatten: true }) ?? [];
538
+ }
539
+ /** Light mode has no slots: move `slot="site-links"` children into the hidden holder. */
540
+ adoptSiteLinks() {
541
+ const moved = [...this.children].filter(isSiteLinksChild);
542
+ if (moved.length && !this.holder) {
543
+ this.holder = document.createElement('div');
544
+ this.holder.hidden = true;
545
+ this.holder.className = 'site-links-source';
546
+ }
547
+ if (this.holder) {
548
+ this.holder.append(...moved);
549
+ if (this.holder.parentNode !== this)
550
+ this.append(this.holder);
551
+ }
552
+ return this.holder ? [...this.holder.children] : [];
553
+ }
554
+ /** Read the source links and render them; returns the sources to watch. */
555
+ syncSiteLinks() {
556
+ const sources = this.lightDom ? this.adoptSiteLinks() : this.slotted;
557
+ const items = [];
558
+ let invalid = false;
559
+ for (const el of sources) {
560
+ const text = (el.textContent ?? '').replace(/\s+/g, ' ').trim();
561
+ // A link with no text would have no accessible name.
562
+ if (!(el instanceof HTMLAnchorElement) || !el.hasAttribute('href') || !text) {
563
+ invalid = true;
564
+ continue;
565
+ }
566
+ const attr = (name) => el.getAttribute(name) ?? undefined;
567
+ items.push({
568
+ href: el.getAttribute('href'),
569
+ text,
570
+ current: attr('aria-current'),
571
+ target: attr('target'),
572
+ rel: attr('rel'),
573
+ hreflang: attr('hreflang'),
574
+ });
575
+ }
576
+ if (invalid && !this.warnedInvalid) {
577
+ this.warnedInvalid = true;
578
+ console.warn(`${this.localName}: ignoring slot="${SITE_LINKS}" children that are not <a href> elements with text.`);
579
+ }
580
+ this.siteLinks = items.length ? items : null;
581
+ return sources;
582
+ }
583
+ /**
584
+ * Shadow mode: slotchange reports added and removed links, and the observer watches the
585
+ * assigned anchors' attributes and text. Light mode: the observer also watches the host
586
+ * for new children and the holder for removals.
587
+ */
588
+ watch(sources) {
589
+ this.observer ??= new MutationObserver(() => this.syncChildren());
590
+ this.observer.disconnect();
591
+ const content = {
592
+ attributes: true,
593
+ attributeFilter: LINK_ATTRS,
594
+ characterData: true,
595
+ childList: true,
596
+ subtree: true,
597
+ };
598
+ if (this.lightDom) {
599
+ this.observer.observe(this, { childList: true });
600
+ if (this.holder)
601
+ this.observer.observe(this.holder, content);
602
+ if (this.mainNavHolder)
603
+ this.observer.observe(this.mainNavHolder, { ...content, attributeFilter: ['href'] });
604
+ }
605
+ else {
606
+ for (const el of sources)
607
+ this.observer.observe(el, content);
608
+ }
609
+ }
610
+ onSourcesChange() {
611
+ this.syncSources();
612
+ }
613
+ get menuId() {
614
+ this._menuId ??= this.lightDom ? `utility-menu-${++menuCounter}` : 'utility-menu';
615
+ return this._menuId;
616
+ }
617
+ /**
618
+ * The header with dark mode on: the inline nav and the control share the utility row, the
619
+ * Menu popover ends with the control, and the logo follows the scheme. A template of its
620
+ * own, so the header without the switch renders exactly what it did before dark mode.
621
+ */
622
+ renderWithScheme(items, label, mainNav, mainNavEl) {
623
+ const root = this.rootLinkDomain;
624
+ const vendor = this.variant === 'vendor';
625
+ const id = this.menuId;
626
+ const anchor = `--${id}`;
627
+ const menu = html `<button
628
+ popovertarget=${id}
629
+ aria-controls=${id}
630
+ class="menu-toggle"
631
+ style="anchor-name: ${anchor}"
632
+ >
633
+ <svg
634
+ aria-hidden="true"
635
+ xmlns="http://www.w3.org/2000/svg"
636
+ width="28"
637
+ height="28"
638
+ viewBox="0 0 24 24"
639
+ fill="none"
640
+ stroke="currentColor"
641
+ stroke-width="2"
642
+ stroke-linecap="butt"
643
+ stroke-linejoin="bevel"
644
+ >
645
+ <line x1="3" y1="12" x2="21" y2="12"></line>
646
+ <line x1="3" y1="6" x2="21" y2="6"></line>
647
+ <line x1="3" y1="18" x2="21" y2="18"></line>
648
+ </svg>
649
+ Menu
650
+ </button>
651
+ <div id=${id} popover class="menu-popover" style="--menu-anchor: ${anchor}">
652
+ ${mainNav ? mainNavEl(true) : nothing}
653
+ <nav class="menu" aria-label=${`${label} menu`}>
654
+ <ul>
655
+ ${items}
656
+ </ul>
657
+ </nav>
658
+ ${this.schemeControl('menu')}
659
+ </div>
660
+ ${mainNav ? mainNavEl(false) : nothing}`;
661
+ return html `
662
+ <header part="header" class=${vendor ? 'vendor' : ''}>
663
+ ${this.lightDom ? nothing : html `<slot name="skip-link"></slot><slot name="alerts"></slot>`}
664
+ <a class="logo" href=${siteLink(root, '/')}
665
+ ><img src=${this.logoSrc()} alt="UVA Library home" width="304" height="69"
666
+ /></a>
667
+ <div class="utility-row">
668
+ <nav class="inline" aria-label=${label}>
669
+ <ul>
670
+ ${items}
671
+ </ul>
672
+ </nav>
673
+ ${this.schemeControl('inline')}
674
+ </div>
675
+ ${vendor ? nothing : menu}
676
+ </header>
677
+ ${this.lightDom
678
+ ? nothing
679
+ : html `<div hidden>
680
+ <slot name="site-links" @slotchange=${this.onSourcesChange}></slot>
681
+ </div>
682
+ <div hidden>
683
+ <slot name="main-nav" @slotchange=${this.onSourcesChange}></slot>
684
+ </div>`}
685
+ `;
686
+ }
687
+ render() {
688
+ const root = this.rootLinkDomain;
689
+ const vendor = this.variant === 'vendor';
690
+ const own = vendor ? null : this.siteLinks;
691
+ const items = own
692
+ ? own.map((l) => html `<li>
693
+ <a
694
+ href=${l.href}
695
+ aria-current=${ifDefined(l.current)}
696
+ target=${ifDefined(l.target)}
697
+ rel=${ifDefined(l.rel)}
698
+ hreflang=${ifDefined(l.hreflang)}
699
+ >${l.text}</a
700
+ >
701
+ </li>`)
702
+ : (vendor ? VENDOR_LINKS : FULL_LINKS).map((l) => html `<li><a href=${siteLink(root, l.path)}>${l.label}</a></li>`);
703
+ const label = own ? this.siteLinksLabel || 'Site' : 'Utility';
704
+ const id = this.menuId;
705
+ const anchor = `--${id}`;
706
+ const mainNav = !vendor && !this.noMainNav;
707
+ // Without the main navigation the header renders exactly what it did before it existed,
708
+ // whitespace included: these two templates are kept verbatim (prettier-ignore).
709
+ // prettier-ignore
710
+ const classic = html `<button
711
+ popovertarget=${id}
712
+ aria-controls=${id}
713
+ class="menu-toggle"
714
+ style="anchor-name: ${anchor}"
715
+ >
716
+ <svg
717
+ aria-hidden="true"
718
+ xmlns="http://www.w3.org/2000/svg"
719
+ width="28"
720
+ height="28"
721
+ viewBox="0 0 24 24"
722
+ fill="none"
723
+ stroke="currentColor"
724
+ stroke-width="2"
725
+ stroke-linecap="butt"
726
+ stroke-linejoin="bevel"
727
+ >
728
+ <line x1="3" y1="12" x2="21" y2="12"></line>
729
+ <line x1="3" y1="6" x2="21" y2="6"></line>
730
+ <line x1="3" y1="18" x2="21" y2="18"></line>
731
+ </svg>
732
+ Menu
733
+ </button>
734
+ <nav class="menu" aria-label=${`${label} menu`}>
735
+ <ul id=${id} popover style="--menu-anchor: ${anchor}">
736
+ ${items}
737
+ </ul>
738
+ </nav>`;
739
+ // prettier-ignore
740
+ const classicHidden = html `<div hidden>
741
+ <slot name="site-links" @slotchange=${this.onSourcesChange}></slot>
742
+ </div>`;
743
+ const mainNavEl = (accordion) => html `<site-main-nav
744
+ class=${accordion ? 'accordion' : 'bar'}
745
+ layout=${ifDefined(accordion ? 'accordion' : undefined)}
746
+ ?no-shadow-dom=${this.lightDom}
747
+ ?no-style=${this.noStyle}
748
+ label=${this.mainNavLabel || 'Main'}
749
+ root-link-domain=${root}
750
+ items-src=${ifDefined(this.mainNavSrc || undefined)}
751
+ current=${ifDefined(this.mainNavCurrent || undefined)}
752
+ .items=${this.mainNavItems ?? undefined}
753
+ @site-main-nav-error=${accordion ? stopEvent : nothing}
754
+ ></site-main-nav>`;
755
+ // With it: the Menu popover holds the accordion and then the utility links, and the bar
756
+ // is the header's last child, a row of its own.
757
+ const withMainNav = html `<button
758
+ popovertarget=${id}
759
+ aria-controls=${id}
760
+ class="menu-toggle"
761
+ style="anchor-name: ${anchor}"
762
+ >
763
+ <svg
764
+ aria-hidden="true"
765
+ xmlns="http://www.w3.org/2000/svg"
766
+ width="28"
767
+ height="28"
768
+ viewBox="0 0 24 24"
769
+ fill="none"
770
+ stroke="currentColor"
771
+ stroke-width="2"
772
+ stroke-linecap="butt"
773
+ stroke-linejoin="bevel"
774
+ >
775
+ <line x1="3" y1="12" x2="21" y2="12"></line>
776
+ <line x1="3" y1="6" x2="21" y2="6"></line>
777
+ <line x1="3" y1="18" x2="21" y2="18"></line>
778
+ </svg>
779
+ Menu
780
+ </button>
781
+ <div id=${id} popover class="menu-popover" style="--menu-anchor: ${anchor}">
782
+ ${mainNavEl(true)}
783
+ <nav class="menu" aria-label=${`${label} menu`}>
784
+ <ul>
785
+ ${items}
786
+ </ul>
787
+ </nav>
788
+ </div>
789
+ ${mainNavEl(false)}`;
790
+ const withMainNavHidden = html `<div hidden>
791
+ <slot name="site-links" @slotchange=${this.onSourcesChange}></slot>
792
+ </div>
793
+ <div hidden>
794
+ <slot name="main-nav" @slotchange=${this.onSourcesChange}></slot>
795
+ </div>`;
796
+ if (this.scheme.active)
797
+ return this.renderWithScheme(items, label, mainNav, mainNavEl);
798
+ return html `
799
+ <header part="header" class=${vendor ? 'vendor' : ''}>
800
+ ${this.lightDom ? nothing : html `<slot name="skip-link"></slot><slot name="alerts"></slot>`}
801
+ <a class="logo" href=${siteLink(root, '/')}
802
+ ><img src=${this.logoSrc()} alt="UVA Library home" width="304" height="69"
803
+ /></a>
804
+ <nav class="inline" aria-label=${label}>
805
+ <ul>
806
+ ${items}
807
+ </ul>
808
+ </nav>
809
+ ${vendor ? nothing : mainNav ? withMainNav : classic}
810
+ </header>
811
+ ${this.lightDom ? nothing : mainNav ? withMainNavHidden : classicHidden}
812
+ `;
813
+ }
814
+ }
815
+ __decorate([
816
+ property({ type: String, attribute: 'root-link-domain' })
817
+ ], SiteHeader.prototype, "rootLinkDomain", void 0);
818
+ __decorate([
819
+ property({ type: String, reflect: true })
820
+ ], SiteHeader.prototype, "variant", void 0);
821
+ __decorate([
822
+ property({ type: String, attribute: 'site-links-label' })
823
+ ], SiteHeader.prototype, "siteLinksLabel", void 0);
824
+ __decorate([
825
+ property({ type: Boolean, attribute: 'no-main-nav' })
826
+ ], SiteHeader.prototype, "noMainNav", void 0);
827
+ __decorate([
828
+ property({ type: String, attribute: 'main-nav-label' })
829
+ ], SiteHeader.prototype, "mainNavLabel", void 0);
830
+ __decorate([
831
+ property({ type: String, attribute: 'main-nav-src' })
832
+ ], SiteHeader.prototype, "mainNavSrc", void 0);
833
+ __decorate([
834
+ property({ type: String, attribute: 'main-nav-current' })
835
+ ], SiteHeader.prototype, "mainNavCurrent", void 0);
836
+ __decorate([
837
+ property({ type: Boolean, attribute: 'color-scheme-switch' })
838
+ ], SiteHeader.prototype, "colorSchemeSwitch", void 0);
839
+ __decorate([
840
+ state()
841
+ ], SiteHeader.prototype, "mainNavItems", void 0);
842
+ __decorate([
843
+ state()
844
+ ], SiteHeader.prototype, "siteLinks", void 0);
845
+ //# sourceMappingURL=SiteHeader.js.map