@uvalib/web-components 1.1.1 → 1.3.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 (252) hide show
  1. package/CHANGELOG.md +140 -0
  2. package/README.md +1310 -80
  3. package/dist/analytics.d.ts +10 -0
  4. package/dist/analytics.js +9 -0
  5. package/dist/analytics.js.map +1 -0
  6. package/dist/base/UvalibElement.js +8 -5
  7. package/dist/base/UvalibElement.js.map +1 -1
  8. package/dist/base/analytics-state.d.ts +7 -0
  9. package/dist/base/analytics-state.js.map +1 -1
  10. package/dist/base/light-dom-styles.d.ts +13 -0
  11. package/dist/base/light-dom-styles.js +26 -0
  12. package/dist/base/light-dom-styles.js.map +1 -1
  13. package/dist/base/search-tracker.d.ts +57 -0
  14. package/dist/base/search-tracker.js +51 -0
  15. package/dist/base/search-tracker.js.map +1 -0
  16. package/dist/base/url-param.d.ts +23 -0
  17. package/dist/base/url-param.js +49 -0
  18. package/dist/base/url-param.js.map +1 -0
  19. package/dist/base.css +562 -2
  20. package/dist/base.d.ts +2 -0
  21. package/dist/base.js +1 -0
  22. package/dist/base.js.map +1 -1
  23. package/dist/components/site-analytics/SiteAnalytics.d.ts +20 -1
  24. package/dist/components/site-analytics/SiteAnalytics.js +93 -12
  25. package/dist/components/site-analytics/SiteAnalytics.js.map +1 -1
  26. package/dist/components/site-page/SitePage.d.ts +23 -0
  27. package/dist/components/site-page/SitePage.js +77 -0
  28. package/dist/components/site-page/SitePage.js.map +1 -1
  29. package/dist/components/uvalib-back-to-top/UvalibBackToTop.d.ts +58 -0
  30. package/dist/components/uvalib-back-to-top/UvalibBackToTop.js +250 -0
  31. package/dist/components/uvalib-back-to-top/UvalibBackToTop.js.map +1 -0
  32. package/dist/components/uvalib-back-to-top/uvalib-back-to-top.d.ts +1 -0
  33. package/dist/components/uvalib-back-to-top/uvalib-back-to-top.js +4 -0
  34. package/dist/components/uvalib-back-to-top/uvalib-back-to-top.js.map +1 -0
  35. package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.d.ts +14 -0
  36. package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.js +56 -4
  37. package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.js.map +1 -1
  38. package/dist/components/uvalib-card/UvalibCard.d.ts +19 -5
  39. package/dist/components/uvalib-card/UvalibCard.js +112 -9
  40. package/dist/components/uvalib-card/UvalibCard.js.map +1 -1
  41. package/dist/components/uvalib-chip-group/UvalibChipGroup.d.ts +178 -0
  42. package/dist/components/uvalib-chip-group/UvalibChipGroup.js +817 -0
  43. package/dist/components/uvalib-chip-group/UvalibChipGroup.js.map +1 -0
  44. package/dist/components/uvalib-chip-group/uvalib-chip-group.d.ts +1 -0
  45. package/dist/components/uvalib-chip-group/uvalib-chip-group.js +4 -0
  46. package/dist/components/uvalib-chip-group/uvalib-chip-group.js.map +1 -0
  47. package/dist/components/uvalib-combobox/UvalibCombobox.d.ts +212 -0
  48. package/dist/components/uvalib-combobox/UvalibCombobox.js +1088 -0
  49. package/dist/components/uvalib-combobox/UvalibCombobox.js.map +1 -0
  50. package/dist/components/uvalib-combobox/uvalib-combobox.d.ts +1 -0
  51. package/dist/components/uvalib-combobox/uvalib-combobox.js +4 -0
  52. package/dist/components/uvalib-combobox/uvalib-combobox.js.map +1 -0
  53. package/dist/components/uvalib-contents/UvalibContents.d.ts +53 -0
  54. package/dist/components/uvalib-contents/UvalibContents.js +202 -3
  55. package/dist/components/uvalib-contents/UvalibContents.js.map +1 -1
  56. package/dist/components/uvalib-date-histogram/UvalibDateHistogram.d.ts +187 -0
  57. package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js +1452 -0
  58. package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js.map +1 -0
  59. package/dist/components/uvalib-date-histogram/uvalib-date-histogram.d.ts +1 -0
  60. package/dist/components/uvalib-date-histogram/uvalib-date-histogram.js +4 -0
  61. package/dist/components/uvalib-date-histogram/uvalib-date-histogram.js.map +1 -0
  62. package/dist/components/uvalib-date-range/UvalibDateRange.d.ts +6 -0
  63. package/dist/components/uvalib-date-range/UvalibDateRange.js +23 -0
  64. package/dist/components/uvalib-date-range/UvalibDateRange.js.map +1 -1
  65. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.d.ts +113 -0
  66. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js +589 -0
  67. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js.map +1 -0
  68. package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.d.ts +1 -0
  69. package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.js +4 -0
  70. package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.js.map +1 -0
  71. package/dist/components/uvalib-image-regions/UvalibImageRegions.d.ts +130 -0
  72. package/dist/components/uvalib-image-regions/UvalibImageRegions.js +658 -0
  73. package/dist/components/uvalib-image-regions/UvalibImageRegions.js.map +1 -0
  74. package/dist/components/uvalib-image-regions/regions.d.ts +57 -0
  75. package/dist/components/uvalib-image-regions/regions.js +117 -0
  76. package/dist/components/uvalib-image-regions/regions.js.map +1 -0
  77. package/dist/components/uvalib-image-regions/uvalib-image-regions.d.ts +1 -0
  78. package/dist/components/uvalib-image-regions/uvalib-image-regions.js +4 -0
  79. package/dist/components/uvalib-image-regions/uvalib-image-regions.js.map +1 -0
  80. package/dist/components/uvalib-lightbox/UvalibLightbox.d.ts +40 -0
  81. package/dist/components/uvalib-lightbox/UvalibLightbox.js +152 -17
  82. package/dist/components/uvalib-lightbox/UvalibLightbox.js.map +1 -1
  83. package/dist/components/uvalib-lightbox/media.d.ts +1 -18
  84. package/dist/components/uvalib-lightbox/media.js +1 -42
  85. package/dist/components/uvalib-lightbox/media.js.map +1 -1
  86. package/dist/components/uvalib-map/UvalibMap.d.ts +182 -0
  87. package/dist/components/uvalib-map/UvalibMap.js +1001 -0
  88. package/dist/components/uvalib-map/UvalibMap.js.map +1 -0
  89. package/dist/components/uvalib-map/uvalib-map.d.ts +1 -0
  90. package/dist/components/uvalib-map/uvalib-map.js +4 -0
  91. package/dist/components/uvalib-map/uvalib-map.js.map +1 -0
  92. package/dist/components/uvalib-metadata/UvalibMetadata.d.ts +39 -2
  93. package/dist/components/uvalib-metadata/UvalibMetadata.js +214 -8
  94. package/dist/components/uvalib-metadata/UvalibMetadata.js.map +1 -1
  95. package/dist/components/uvalib-pager/UvalibPager.d.ts +77 -4
  96. package/dist/components/uvalib-pager/UvalibPager.js +270 -8
  97. package/dist/components/uvalib-pager/UvalibPager.js.map +1 -1
  98. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.d.ts +27 -1
  99. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js +192 -26
  100. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js.map +1 -1
  101. package/dist/components/uvalib-results-count/UvalibResultsCount.d.ts +62 -0
  102. package/dist/components/uvalib-results-count/UvalibResultsCount.js +208 -0
  103. package/dist/components/uvalib-results-count/UvalibResultsCount.js.map +1 -0
  104. package/dist/components/uvalib-results-count/uvalib-results-count.d.ts +1 -0
  105. package/dist/components/uvalib-results-count/uvalib-results-count.js +4 -0
  106. package/dist/components/uvalib-results-count/uvalib-results-count.js.map +1 -0
  107. package/dist/components/uvalib-tabs/UvalibTabs.d.ts +127 -0
  108. package/dist/components/uvalib-tabs/UvalibTabs.js +821 -0
  109. package/dist/components/uvalib-tabs/UvalibTabs.js.map +1 -0
  110. package/dist/components/uvalib-tabs/uvalib-tabs.d.ts +1 -0
  111. package/dist/components/uvalib-tabs/uvalib-tabs.js +4 -0
  112. package/dist/components/uvalib-tabs/uvalib-tabs.js.map +1 -0
  113. package/dist/components/uvalib-tag-list/UvalibTagList.d.ts +89 -0
  114. package/dist/components/uvalib-tag-list/UvalibTagList.js +411 -0
  115. package/dist/components/uvalib-tag-list/UvalibTagList.js.map +1 -0
  116. package/dist/components/uvalib-tag-list/uvalib-tag-list.d.ts +1 -0
  117. package/dist/components/uvalib-tag-list/uvalib-tag-list.js +4 -0
  118. package/dist/components/uvalib-tag-list/uvalib-tag-list.js.map +1 -0
  119. package/dist/custom-elements.json +14007 -3497
  120. package/dist/index.d.ts +16 -0
  121. package/dist/index.js +10 -0
  122. package/dist/index.js.map +1 -1
  123. package/dist/pagefind.css +4 -0
  124. package/dist/styles/base.js +154 -1
  125. package/dist/styles/base.js.map +1 -1
  126. package/dist/styles/color-scheme.js +9 -0
  127. package/dist/styles/color-scheme.js.map +1 -1
  128. package/dist/styles/controls.js +8 -0
  129. package/dist/styles/controls.js.map +1 -1
  130. package/dist/styles/hidden.d.ts +2 -0
  131. package/dist/styles/hidden.js +51 -0
  132. package/dist/styles/hidden.js.map +1 -0
  133. package/dist/styles/message.d.ts +1 -0
  134. package/dist/styles/message.js +82 -0
  135. package/dist/styles/message.js.map +1 -0
  136. package/dist/styles/pagefind.js +4 -0
  137. package/dist/styles/pagefind.js.map +1 -1
  138. package/dist/styles/result-list.d.ts +1 -0
  139. package/dist/styles/result-list.js +111 -0
  140. package/dist/styles/result-list.js.map +1 -0
  141. package/dist/styles/results.d.ts +1 -0
  142. package/dist/styles/results.js +242 -0
  143. package/dist/styles/results.js.map +1 -0
  144. package/dist/testing/index.d.ts +110 -0
  145. package/dist/testing/index.js +100 -0
  146. package/dist/testing/index.js.map +1 -0
  147. package/dist/testing/lighthouse-rules.d.ts +10 -0
  148. package/dist/testing/lighthouse-rules.js +44 -0
  149. package/dist/testing/lighthouse-rules.js.map +1 -0
  150. package/dist/tokens.css +9 -0
  151. package/dist-cdn/analytics.js +32 -0
  152. package/dist-cdn/analytics.js.map +1 -0
  153. package/dist-cdn/base.css +562 -2
  154. package/dist-cdn/bento-box.js +3 -3
  155. package/dist-cdn/chunks/{SiteAnalytics-Cm-FyhYS.js → SiteAnalytics-B9gu5aGO.js} +59 -30
  156. package/dist-cdn/chunks/SiteAnalytics-B9gu5aGO.js.map +1 -0
  157. package/dist-cdn/chunks/{UvalibElement-BnI-eRRR.js → UvalibElement-pGONDAwB.js} +108 -101
  158. package/dist-cdn/chunks/UvalibElement-pGONDAwB.js.map +1 -0
  159. package/dist-cdn/chunks/{accessible-GqhVn5_H.js → accessible-DJv7YOtS.js} +2 -2
  160. package/dist-cdn/chunks/{accessible-GqhVn5_H.js.map → accessible-DJv7YOtS.js.map} +1 -1
  161. package/dist-cdn/chunks/analytics-state-Ce8DKe4F.js.map +1 -1
  162. package/dist-cdn/chunks/base-BI8h0Gf3.js +281 -0
  163. package/dist-cdn/chunks/base-BI8h0Gf3.js.map +1 -0
  164. package/dist-cdn/chunks/inline-copy-BANQSMIR.js +69 -0
  165. package/dist-cdn/chunks/inline-copy-BANQSMIR.js.map +1 -0
  166. package/dist-cdn/chunks/{library-weekly-hours-COE7Vv6V.js → library-weekly-hours-CrV3TlP5.js} +3 -3
  167. package/dist-cdn/chunks/{library-weekly-hours-COE7Vv6V.js.map → library-weekly-hours-CrV3TlP5.js.map} +1 -1
  168. package/dist-cdn/chunks/regions-B8ExwUGP.js +86 -0
  169. package/dist-cdn/chunks/regions-B8ExwUGP.js.map +1 -0
  170. package/dist-cdn/chunks/{repeat-CIFUYkyh.js → repeat-m5Zd_QeP.js} +2 -2
  171. package/dist-cdn/chunks/{repeat-CIFUYkyh.js.map → repeat-m5Zd_QeP.js.map} +1 -1
  172. package/dist-cdn/chunks/{site-header-C9V7Wuw2.js → site-header-DYRMpdBj.js} +13 -4
  173. package/dist-cdn/chunks/site-header-DYRMpdBj.js.map +1 -0
  174. package/dist-cdn/chunks/{site-main-nav-AaxZ9rQf.js → site-main-nav-DURrQMal.js} +3 -3
  175. package/dist-cdn/chunks/{site-main-nav-AaxZ9rQf.js.map → site-main-nav-DURrQMal.js.map} +1 -1
  176. package/dist-cdn/chunks/source-children-BHsDwCvL.js +53 -0
  177. package/dist-cdn/chunks/source-children-BHsDwCvL.js.map +1 -0
  178. package/dist-cdn/chunks/{static-html-1mTAG6nS.js → static-html-C1rhtCHu.js} +2 -2
  179. package/dist-cdn/chunks/{static-html-1mTAG6nS.js.map → static-html-C1rhtCHu.js.map} +1 -1
  180. package/dist-cdn/chunks/url-param-C1sk_F1d.js +28 -0
  181. package/dist-cdn/chunks/url-param-C1sk_F1d.js.map +1 -0
  182. package/dist-cdn/custom-elements.json +14007 -3497
  183. package/dist-cdn/events-section.js +3 -3
  184. package/dist-cdn/library-hours-setup.js +2 -2
  185. package/dist-cdn/library-weekly-hours.js +1 -1
  186. package/dist-cdn/manifest.json +15 -2
  187. package/dist-cdn/pagefind.css +4 -0
  188. package/dist-cdn/site-alerts.js +4 -4
  189. package/dist-cdn/site-analytics.js +2 -2
  190. package/dist-cdn/site-footer.js +2 -2
  191. package/dist-cdn/site-header.js +1 -1
  192. package/dist-cdn/site-hours-section.js +4 -4
  193. package/dist-cdn/site-main-nav.js +1 -1
  194. package/dist-cdn/site-page.js +56 -11
  195. package/dist-cdn/site-page.js.map +1 -1
  196. package/dist-cdn/site-style.js +2 -2
  197. package/dist-cdn/skills/uvalib-web-components/SKILL.md +269 -24
  198. package/dist-cdn/skills/uvalib-web-components/reference/accessibility-testing.md +34 -2
  199. package/dist-cdn/skills/uvalib-web-components/reference/components.md +514 -13
  200. package/dist-cdn/skills/uvalib-web-components/reference/snippets.md +1 -1
  201. package/dist-cdn/tokens.css +9 -0
  202. package/dist-cdn/uvalib-analytics.js +2 -2
  203. package/dist-cdn/uvalib-back-to-top.js +156 -0
  204. package/dist-cdn/uvalib-back-to-top.js.map +1 -0
  205. package/dist-cdn/uvalib-breadcrumbs.js +31 -11
  206. package/dist-cdn/uvalib-breadcrumbs.js.map +1 -1
  207. package/dist-cdn/uvalib-card-grid.js +1 -1
  208. package/dist-cdn/uvalib-card.js +97 -23
  209. package/dist-cdn/uvalib-card.js.map +1 -1
  210. package/dist-cdn/uvalib-chip-group.js +535 -0
  211. package/dist-cdn/uvalib-chip-group.js.map +1 -0
  212. package/dist-cdn/uvalib-combobox.js +667 -0
  213. package/dist-cdn/uvalib-combobox.js.map +1 -0
  214. package/dist-cdn/uvalib-contents.js +102 -23
  215. package/dist-cdn/uvalib-contents.js.map +1 -1
  216. package/dist-cdn/uvalib-date-histogram.js +960 -0
  217. package/dist-cdn/uvalib-date-histogram.js.map +1 -0
  218. package/dist-cdn/uvalib-date-range.js +14 -2
  219. package/dist-cdn/uvalib-date-range.js.map +1 -1
  220. package/dist-cdn/uvalib-filter-drawer.js +355 -0
  221. package/dist-cdn/uvalib-filter-drawer.js.map +1 -0
  222. package/dist-cdn/uvalib-filter.js +3 -3
  223. package/dist-cdn/uvalib-image-regions.js +447 -0
  224. package/dist-cdn/uvalib-image-regions.js.map +1 -0
  225. package/dist-cdn/uvalib-lightbox.js +145 -78
  226. package/dist-cdn/uvalib-lightbox.js.map +1 -1
  227. package/dist-cdn/uvalib-map.js +471 -0
  228. package/dist-cdn/uvalib-map.js.map +1 -0
  229. package/dist-cdn/uvalib-metadata.js +152 -25
  230. package/dist-cdn/uvalib-metadata.js.map +1 -1
  231. package/dist-cdn/uvalib-pager.js +164 -18
  232. package/dist-cdn/uvalib-pager.js.map +1 -1
  233. package/dist-cdn/uvalib-photo-grid.js +123 -21
  234. package/dist-cdn/uvalib-photo-grid.js.map +1 -1
  235. package/dist-cdn/uvalib-results-count.js +101 -0
  236. package/dist-cdn/uvalib-results-count.js.map +1 -0
  237. package/dist-cdn/uvalib-tabs.js +436 -0
  238. package/dist-cdn/uvalib-tabs.js.map +1 -0
  239. package/dist-cdn/uvalib-tag-list.js +267 -0
  240. package/dist-cdn/uvalib-tag-list.js.map +1 -0
  241. package/package.json +66 -3
  242. package/skills/uvalib-web-components/SKILL.md +269 -24
  243. package/skills/uvalib-web-components/reference/accessibility-testing.md +34 -2
  244. package/skills/uvalib-web-components/reference/components.md +514 -13
  245. package/skills/uvalib-web-components/reference/snippets.md +1 -1
  246. package/dist-cdn/chunks/SiteAnalytics-Cm-FyhYS.js.map +0 -1
  247. package/dist-cdn/chunks/UvalibElement-BnI-eRRR.js.map +0 -1
  248. package/dist-cdn/chunks/base-CAFQWnZG.js +0 -128
  249. package/dist-cdn/chunks/base-CAFQWnZG.js.map +0 -1
  250. package/dist-cdn/chunks/site-header-C9V7Wuw2.js.map +0 -1
  251. package/dist-cdn/chunks/source-children-RuAec527.js +0 -119
  252. package/dist-cdn/chunks/source-children-RuAec527.js.map +0 -1
@@ -0,0 +1,817 @@
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 { css, html, nothing, svg, unsafeCSS } from 'lit';
8
+ import { property, state } from 'lit/decorators.js';
9
+ import { trackEvent } from '../../base/analytics.js';
10
+ import { UvalibElement } from '../../base/UvalibElement.js';
11
+ import { installLightDomStyles } from '../../base/light-dom-styles.js';
12
+ import { normalize, safeHref, SourceChildren } from '../../base/source-children.js';
13
+ import { accessible } from '../../styles/accessible.js';
14
+ import { hrefWithParam, paramFromLocation, usesHashParam, } from '../../base/url-param.js';
15
+ const TAG = 'uvalib-chip-group';
16
+ const MODES = new Set(['single', 'multi', 'links']);
17
+ /**
18
+ * Single-select changes within `settle` ms count as one: one analytics event (none when the
19
+ * visitor ends where they started) and one history entry. Tests may shorten it.
20
+ */
21
+ export const chipGroupTiming = { settle: 1000 };
22
+ let uid = 0;
23
+ /**
24
+ * Kept with `no-style`: the wrapping (or scrolling) row, each chip's target of at least 44px,
25
+ * the radio laid over its chip, the joined segments and the visually hidden text. `host` is
26
+ * `:host` or the tag.
27
+ */
28
+ const structuralRules = (host) => `
29
+ ${host} { display: flow-root; min-width: 0; max-width: 100%; }
30
+ ${host} .chips {
31
+ display: flex;
32
+ flex-wrap: wrap;
33
+ align-items: center;
34
+ gap: 0.25rem 0.5rem;
35
+ min-width: 0;
36
+ }
37
+ ${host} .chips.scroll {
38
+ flex-wrap: nowrap;
39
+ overflow-x: auto;
40
+ overscroll-behavior-x: contain;
41
+ padding: 0.375rem;
42
+ scroll-padding-inline: 2.5rem;
43
+ }
44
+ ${host} .chips.scroll > .chip { flex: none; }
45
+ ${host} .rail { position: relative; min-width: 0; }
46
+ ${host} .chips.segmented {
47
+ flex-wrap: nowrap;
48
+ column-gap: 0;
49
+ overflow-x: auto;
50
+ padding: 0.375rem;
51
+ }
52
+ /* The padding only keeps the focus ring inside the scroll box: the bar stays 44px tall. */
53
+ ${host} .chips.segmented:not(.scroll) { margin-block: -0.375rem; }
54
+ ${host} .chips.segmented:not(.scroll) > .chip { flex: 0 1 auto; min-width: 44px; }
55
+ ${host} .chips.segmented > .chip + .chip { margin-inline-start: -1px; }
56
+ ${host} .chip {
57
+ position: relative;
58
+ display: inline-flex;
59
+ align-items: center;
60
+ box-sizing: border-box;
61
+ min-width: 44px;
62
+ min-height: 44px;
63
+ max-width: 100%;
64
+ margin: 0;
65
+ padding: 0;
66
+ border: 0;
67
+ background: none;
68
+ color: inherit;
69
+ font: inherit;
70
+ text-align: start;
71
+ text-decoration: none;
72
+ cursor: pointer;
73
+ }
74
+ ${host} .chip input {
75
+ position: absolute;
76
+ inset: 0;
77
+ width: 100%;
78
+ height: 100%;
79
+ margin: 0;
80
+ opacity: 0;
81
+ cursor: inherit;
82
+ }
83
+ ${host} .face {
84
+ display: inline-flex;
85
+ flex: 1;
86
+ align-items: center;
87
+ justify-content: center;
88
+ gap: 0.375rem;
89
+ box-sizing: border-box;
90
+ min-width: 0;
91
+ min-height: 2.25rem;
92
+ overflow-wrap: break-word;
93
+ }
94
+ ${host} .text { min-width: 0; }
95
+ ${host} .check { flex: none; width: 1em; height: 1em; }
96
+ /* A key's colour is content, not look: kept with no-style. Its border is the chip's text
97
+ colour, which contrasts with the chip in every state (selected, disabled, dark). */
98
+ ${host} .swatch {
99
+ flex: none;
100
+ box-sizing: border-box;
101
+ width: 0.75em;
102
+ height: 0.75em;
103
+ border: 1px solid currentColor;
104
+ border-radius: 2px;
105
+ }
106
+ /* Forced colors would flatten the fill: the key keeps its colour (it matches the chart or
107
+ map) and its border stays the chip's system text colour. */
108
+ @media (forced-colors: active) {
109
+ ${host} .swatch { forced-color-adjust: none; }
110
+ }
111
+ ${host} .chip:focus-visible { outline: none; }
112
+ ${host} :is(.chip:focus-visible > .face, .chip input:focus-visible + .face) {
113
+ position: relative;
114
+ z-index: 1;
115
+ outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
116
+ outline-offset: 2px;
117
+ }
118
+ ${host} :is(.chip:disabled, .chip[aria-disabled='true'], .chip input:disabled) { cursor: not-allowed; }
119
+ ${host} .visually-hidden {
120
+ position: absolute;
121
+ width: 1px;
122
+ height: 1px;
123
+ margin: -1px;
124
+ padding: 0;
125
+ overflow: hidden;
126
+ clip: rect(0, 0, 0, 0);
127
+ white-space: nowrap;
128
+ border: 0;
129
+ }
130
+ ${host} .description { margin: 0.25rem 0 0; }
131
+ ${host}[hidden], ${host} [hidden] { display: none !important; }
132
+ `;
133
+ const shadowStructure = unsafeCSS(structuralRules(':host'));
134
+ const BORDER = 'var(--uva-color-control-border, var(--uva-grey, #808080))';
135
+ const LINK = 'var(--uva-color-link, var(--uva-brand-blue, #232d4b))';
136
+ const ACCENT = 'var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b))';
137
+ /** The tick on a selected chip, so the state never rests on colour alone. */
138
+ const CHECK = svg `<svg class="check" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M3 8.5l3.2 3.2L13 4.8" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
139
+ /** The visual target of each face: selected (a radio checked or a toggle pressed). */
140
+ const ON = unsafeCSS(".chip[aria-pressed='true'] > .face, .chip input:checked + .face");
141
+ /** Disabled and not selected (a selected disabled chip keeps the selected fill and text). */
142
+ const OFF_DISABLED = unsafeCSS(".chip:disabled:not([aria-pressed='true']) > .face, .chip[aria-disabled='true'] > .face, .chip input:disabled:not(:checked) + .face");
143
+ /** Hover, never on a disabled chip. */
144
+ const HOVER = unsafeCSS(".chip:not(:disabled, [aria-disabled='true']):hover > .face, .chip:hover input:not(:disabled) + .face");
145
+ const FOCUSED = unsafeCSS('.chip:focus-visible > .face, .chip input:focus-visible + .face');
146
+ /**
147
+ * A row of chips: a segmented control or single-select filter (`mode="single"`), filter chips
148
+ * that toggle (`mode="multi"`), or suggestion chips that go somewhere (`mode="links"`), as in
149
+ * a year rail with counts (“2005 213”), a sort toggle (“Most photos | Date | Title A–Z”) or
150
+ * “Try: snow on the Lawn”.
151
+ *
152
+ * Give the chips as children, `<button value="2005" data-count="213">2005</button>` (the
153
+ * value is the `value` attribute, else `data-value`, else the text; `disabled` disables), or
154
+ * `<a href>` in `links` mode, or set the `items` property (`{ value, label, count?, href?,
155
+ * disabled?, swatch? }`), which wins over the children while set. The chips follow later changes to
156
+ * the children.
157
+ *
158
+ * `single`: native radios drawn as chips, in a `role="radiogroup"` named by `label`. Tab
159
+ * enters the group at the selected chip, the arrow keys move and select (as any radio group),
160
+ * and `value` is the selected chip's value. `multi`: toggle buttons with `aria-pressed`, and
161
+ * `value` is an array (as an attribute, comma-separated). `links`: links, or buttons that fire
162
+ * `select`, with no selected state; a chip whose href is unsafe (`javascript:`) is plain text,
163
+ * and an empty href is a button.
164
+ *
165
+ * `data-swatch` (or `swatch` in `items`) is a CSS colour drawn as a small bordered square
166
+ * before the label, so the chips double as a chart's or map's colour key. It is decorative
167
+ * (`aria-hidden`) and never the only cue: the name stays the label. An invalid colour is
168
+ * ignored with one warning. In forced colors the square keeps its colour.
169
+ *
170
+ * A count is shown in a smaller muted span after the label and read as part of the name: “2005,
171
+ * 213 items”, with `count-label` in place of “items”. A selected chip is filled, keeps its
172
+ * border and shows a tick. Chips wrap on a narrow screen; `scroll` keeps them on one row that
173
+ * scrolls sideways, with its scrollbar shown and a fade at an edge with more chips. Each chip
174
+ * is a target at least 44px square. `segmented` joins the chips into one bar that does not
175
+ * wrap (a long label wraps inside its segment), like the header's Light / Dark / System control.
176
+ *
177
+ * `description` is a hint shown under the chips and tied to the group with
178
+ * `aria-describedby`, so it is read when focus enters the group (“Keyword matches your
179
+ * words…”). It is plain text in the element's own root, so it works in a closed shadow root.
180
+ *
181
+ * `url-param` (for example `year`) keeps the value in the address (`?year=2005`, a multi
182
+ * value comma-separated, inside the hash on a hash route). It is read on connect; the
183
+ * markup's `value` stands for the address without the parameter, and any other value is
184
+ * written, an empty one as `?year=`. Each change is one `pushState`: in `multi` at once, in
185
+ * `single` once the visitor settles (a second after the last change, so arrowing through a
186
+ * year rail adds one entry, none if it ends where it started). Back and Forward are followed
187
+ * and fire `change` with `restored: true`.
188
+ *
189
+ * @tagname uvalib-chip-group
190
+ * @fires change - The visitor changed the selection (`single`, `multi`), or Back or Forward changed it through `url-param`: `detail` is `{ value, restored? }` (a string in `single`, an array in `multi`; `restored` is true for Back and Forward). Not fired when the app sets `value`. Bubbles and is composed.
191
+ * @fires select - `links` mode: a chip was chosen. `detail` is `{ value, href? }`. For a link, a plain primary click fires it cancelable: cancel it (`preventDefault()`) to route in the app, and the click's default is prevented too. Bubbles and is composed.
192
+ * @fires uvalib-analytics-event - For `<site-analytics>`, on the visitor's actions only: `['uvalib-chip-group', 'change', '<label>: <chip label>', <count>?]` (in `single`, one second after the last change, for the chip then selected; in `multi`, for the chip toggled), and `['uvalib-chip-group', 'select', '<label>']` in `links` mode (never the chip or its URL). The count is sent when it is a number. Bubbles and is composed.
193
+ * @csspart swatch - The colour square before a chip's label (`data-swatch`, `swatch`).
194
+ * @cssprop --uva-color-surface-raised - Dark-mode role token: chip background (else #fff).
195
+ * @cssprop --uva-color-control-border - Dark-mode role token: chip border (else `--uva-grey`, #808080).
196
+ * @cssprop --uva-color-link - Dark-mode role token: chip text and hover border (else `--uva-brand-blue`).
197
+ * @cssprop --uva-color-text-muted - Dark-mode role token: the count and the description (else #4f4f4f).
198
+ * @cssprop --uva-color-accent-bg - Dark-mode role token: selected chip background and border (else `--uva-brand-blue`).
199
+ * @cssprop --uva-color-on-accent - Dark-mode role token: selected chip text (else #fff).
200
+ * @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).
201
+ * @cssprop --uva-color-surface - Dark-mode role token: the page background the scrolling row fades into at an edge with more chips (else #fff).
202
+ */
203
+ export class UvalibChipGroup extends UvalibElement {
204
+ static { this.styles = [
205
+ accessible,
206
+ shadowStructure,
207
+ css `
208
+ .face {
209
+ padding: 0.25rem 0.875rem;
210
+ border: 1px solid ${unsafeCSS(BORDER)};
211
+ border-radius: 999px;
212
+ background: var(--uva-color-surface-raised, #fff);
213
+ color: ${unsafeCSS(LINK)};
214
+ font-size: 0.875rem;
215
+ font-weight: 600;
216
+ line-height: 1.3;
217
+ }
218
+ .segmented .face {
219
+ padding-inline: 0.625rem;
220
+ border-radius: 0;
221
+ }
222
+ .segmented > .chip:first-child .face {
223
+ border-start-start-radius: 0.3rem;
224
+ border-end-start-radius: 0.3rem;
225
+ }
226
+ .segmented > .chip:last-child .face {
227
+ border-start-end-radius: 0.3rem;
228
+ border-end-end-radius: 0.3rem;
229
+ }
230
+ .description {
231
+ color: var(--uva-color-text-muted, #4f4f4f);
232
+ font-size: 0.875rem;
233
+ line-height: 1.5;
234
+ }
235
+ .count {
236
+ color: var(--uva-color-text-muted, #4f4f4f);
237
+ font-size: 0.8125rem;
238
+ font-weight: 400;
239
+ font-variant-numeric: tabular-nums;
240
+ }
241
+ ${HOVER} {
242
+ position: relative;
243
+ border-color: ${unsafeCSS(LINK)};
244
+ }
245
+ ${ON} {
246
+ position: relative;
247
+ border-color: ${unsafeCSS(ACCENT)};
248
+ background: ${unsafeCSS(ACCENT)};
249
+ color: var(--uva-color-on-accent, #fff);
250
+ }
251
+ .chip[aria-pressed='true'] .count,
252
+ .chip input:checked + .face .count {
253
+ color: inherit;
254
+ }
255
+ ${OFF_DISABLED} {
256
+ border-style: dashed;
257
+ color: var(--uva-color-text-muted, #4f4f4f);
258
+ }
259
+ /* One row that scrolls: the scrollbar stays visible, and the edge with more chips
260
+ fades out. */
261
+ .chips.scroll {
262
+ scrollbar-width: thin;
263
+ scrollbar-color: ${unsafeCSS(BORDER)} transparent;
264
+ }
265
+ .rail::before,
266
+ .rail::after {
267
+ content: '';
268
+ position: absolute;
269
+ inset-block: 0 0.75rem;
270
+ z-index: 2;
271
+ width: 2.5rem;
272
+ pointer-events: none;
273
+ opacity: 0;
274
+ }
275
+ .rail::before {
276
+ left: 0;
277
+ background: linear-gradient(to right, var(--uva-color-surface, #fff), transparent);
278
+ }
279
+ .rail::after {
280
+ right: 0;
281
+ background: linear-gradient(to left, var(--uva-color-surface, #fff), transparent);
282
+ }
283
+ .rail[data-more-left]::before,
284
+ .rail[data-more-right]::after {
285
+ opacity: 1;
286
+ }
287
+ @media (forced-colors: active) {
288
+ .face {
289
+ border-color: ButtonText;
290
+ color: ButtonText;
291
+ }
292
+ a.chip > .face {
293
+ border-color: LinkText;
294
+ color: LinkText;
295
+ }
296
+ ${HOVER} {
297
+ border-color: Highlight;
298
+ }
299
+ ${ON} {
300
+ forced-color-adjust: none;
301
+ border-color: Highlight;
302
+ background: Highlight;
303
+ color: HighlightText;
304
+ }
305
+ ${OFF_DISABLED} {
306
+ border-color: GrayText;
307
+ color: GrayText;
308
+ }
309
+ ${FOCUSED} {
310
+ outline-color: Highlight;
311
+ }
312
+ /* Forced colors keep gradients: a light fade would cover the edge chips. */
313
+ .rail::before,
314
+ .rail::after {
315
+ display: none;
316
+ }
317
+ }
318
+ `,
319
+ ]; }
320
+ constructor() {
321
+ super();
322
+ /** `single` (radios: one value), `multi` (toggles: an array of values) or `links`. */
323
+ this.mode = 'single';
324
+ /** The group's accessible name (required), also the first part of the analytics name. */
325
+ this.label = '';
326
+ /**
327
+ * A hint shown under the chips and read with the group when focus enters it
328
+ * (`aria-describedby` on the group). Plain text.
329
+ */
330
+ this.description = '';
331
+ /**
332
+ * The selection: a chip's value in `single`, an array of values in `multi` (as an
333
+ * attribute, comma-separated). Setting it does not fire `change`. Unused in `links`.
334
+ */
335
+ this.value = '';
336
+ /** The word after a count in each chip's accessible name: “2005, 213 items”. */
337
+ this.countLabel = 'items';
338
+ /** One row that scrolls sideways instead of wrapping. */
339
+ this.scrollRow = false;
340
+ /** Join the chips into one segmented bar. */
341
+ this.segmented = false;
342
+ /** Query parameter that keeps the value in the address, for example `year` → `?year=2005`. */
343
+ this.urlParam = '';
344
+ this.childItems = [];
345
+ /** `scroll`: whether more chips lie beyond the left and right edges. */
346
+ this.more = { left: false, right: false };
347
+ this.uid = `${TAG}-${++uid}`;
348
+ this.warned = new Set();
349
+ this.onPop = () => {
350
+ if (!this.urlParam || this.kind === 'links')
351
+ return;
352
+ this.cancel();
353
+ this.initial ??= Array.isArray(this.value) ? [...this.value] : this.value;
354
+ const v = this.urlValue() ?? this.initial ?? '';
355
+ const before = this.selected.join('\u0000');
356
+ this.value = Array.isArray(v) ? [...v] : v;
357
+ if (this.selected.join('\u0000') === before)
358
+ return;
359
+ this.emitChange(true);
360
+ };
361
+ /** `scroll`: which edges have more chips beyond them (in either writing direction). */
362
+ this.measure = () => {
363
+ const g = this.renderRoot.querySelector('.chips.scroll');
364
+ if (!g)
365
+ return;
366
+ const max = g.scrollWidth - g.clientWidth;
367
+ const x = Math.abs(g.scrollLeft);
368
+ const rtl = getComputedStyle(g).direction === 'rtl';
369
+ const before = x > 1;
370
+ const after = x < max - 1;
371
+ const more = { left: rtl ? after : before, right: rtl ? before : after };
372
+ if (more.left !== this.more.left || more.right !== this.more.right)
373
+ this.more = more;
374
+ };
375
+ new SourceChildren(this, () => this.lightDom, (nodes) => this.read(nodes));
376
+ }
377
+ createRenderRoot() {
378
+ const root = super.createRenderRoot();
379
+ if (root instanceof ShadowRoot && this.noStyle) {
380
+ const sheet = shadowStructure.styleSheet;
381
+ if (sheet)
382
+ root.adoptedStyleSheets = [sheet];
383
+ }
384
+ return root;
385
+ }
386
+ connectedCallback() {
387
+ super.connectedCallback();
388
+ if (this.lightDom && this.noStyle) {
389
+ const node = this.getRootNode();
390
+ installLightDomStyles(`${this.localName}::structure`, unsafeCSS(structuralRules(this.localName)), {
391
+ root: node instanceof ShadowRoot || node instanceof Document ? node : undefined,
392
+ scope: false,
393
+ });
394
+ }
395
+ window.addEventListener('popstate', this.onPop);
396
+ // Moved in the page: observe the scrolling row again.
397
+ if (this.hasUpdated)
398
+ this.requestUpdate();
399
+ }
400
+ disconnectedCallback() {
401
+ super.disconnectedCallback();
402
+ window.removeEventListener('popstate', this.onPop);
403
+ // Detached, it could not report through the page (nor honour an ancestor's
404
+ // no-analytics), and its address may belong to another route by now: drop it.
405
+ this.cancel();
406
+ this.resize?.disconnect();
407
+ this.observed = undefined;
408
+ }
409
+ willUpdate(changed) {
410
+ if (changed.has('urlParam') && this.urlParam)
411
+ this.readUrl();
412
+ if (changed.has('value') && this.value !== this.ownValue) {
413
+ // Set by the app (or read from the address): a pending change is no longer the visitor's.
414
+ this.cancel();
415
+ if (this.kind === 'multi' && !Array.isArray(this.value))
416
+ this.value = this.selected;
417
+ }
418
+ if (!this.label.trim())
419
+ this.warnOnce('label', 'set label: the group needs an accessible name.');
420
+ if (!MODES.has(this.mode))
421
+ this.warnOnce('mode', 'mode must be single, multi or links.');
422
+ }
423
+ warnOnce(kind, message) {
424
+ if (this.warned.has(kind))
425
+ return;
426
+ this.warned.add(kind);
427
+ console.warn(`${this.localName}: ${message}`);
428
+ }
429
+ get kind() {
430
+ return MODES.has(this.mode) ? this.mode : 'single';
431
+ }
432
+ /** Read the chips from the children: each element with text is one chip. */
433
+ read(nodes) {
434
+ const items = [];
435
+ for (const n of nodes) {
436
+ if (!(n instanceof Element))
437
+ continue;
438
+ const label = normalize(n.textContent);
439
+ if (!label) {
440
+ this.warnOnce('empty', 'ignoring chips with no text.');
441
+ continue;
442
+ }
443
+ const item = {
444
+ value: n.getAttribute('value') ?? n.getAttribute('data-value') ?? label,
445
+ label,
446
+ };
447
+ const count = n.getAttribute('data-count');
448
+ if (count !== null && count.trim())
449
+ item.count = count.trim();
450
+ if (n instanceof HTMLAnchorElement && n.hasAttribute('href'))
451
+ item.href = n.getAttribute('href');
452
+ if (n.hasAttribute('disabled') || n.getAttribute('aria-disabled') === 'true')
453
+ item.disabled = true;
454
+ const swatch = n.getAttribute('data-swatch');
455
+ if (swatch !== null)
456
+ item.swatch = swatch;
457
+ items.push(item);
458
+ }
459
+ // Only a real change re-renders.
460
+ if (JSON.stringify(items) !== JSON.stringify(this.childItems))
461
+ this.childItems = items;
462
+ }
463
+ /** What is shown: `items` while set, else the children; entries without a label left out. */
464
+ get chips() {
465
+ const source = this.items ?? this.childItems;
466
+ return source
467
+ .filter((i) => i && normalize(i.label))
468
+ .map((i) => ({
469
+ ...i,
470
+ label: normalize(i.label),
471
+ value: String(i.value ?? normalize(i.label)),
472
+ swatch: this.colour(i.swatch),
473
+ }));
474
+ }
475
+ /** A valid CSS colour, else nothing (one warning). Only ever set as a style property. */
476
+ colour(c) {
477
+ const v = typeof c === 'string' ? c.trim() : '';
478
+ if (!v && (c === undefined || c === null || c === ''))
479
+ return undefined;
480
+ if (v && CSS.supports('color', v))
481
+ return v;
482
+ this.warnOnce('swatch', `ignoring a swatch that is not a CSS colour: ${String(c)}`);
483
+ return undefined;
484
+ }
485
+ /** The selected values, whatever shape `value` has. */
486
+ get selected() {
487
+ const v = this.value;
488
+ if (Array.isArray(v))
489
+ return v.map(String);
490
+ if (v === null || v === undefined)
491
+ return [];
492
+ const s = String(v);
493
+ if (this.kind === 'multi')
494
+ return s
495
+ .split(',')
496
+ .map((x) => x.trim())
497
+ .filter(Boolean);
498
+ return [s];
499
+ }
500
+ get locale() {
501
+ return this.closest('[lang]')?.getAttribute('lang') || 'en';
502
+ }
503
+ formatCount(count) {
504
+ const n = typeof count === 'number' ? count : Number(String(count).replace(/,/g, ''));
505
+ if (typeof count === 'string' && !/^\s*[\d,]+(\.\d+)?\s*$/.test(count))
506
+ return count.trim();
507
+ if (!Number.isFinite(n))
508
+ return String(count);
509
+ try {
510
+ return n.toLocaleString(this.locale);
511
+ }
512
+ catch {
513
+ return n.toLocaleString('en');
514
+ }
515
+ }
516
+ numericCount(count) {
517
+ if (count === undefined)
518
+ return undefined;
519
+ if (typeof count === 'number')
520
+ return Number.isFinite(count) ? count : undefined;
521
+ // '' and ',' are not 0.
522
+ if (!/^\s*\d[\d,]*(\.\d+)?\s*$/.test(count))
523
+ return undefined;
524
+ return Number(count.replace(/,/g, ''));
525
+ }
526
+ /* ---------- the address ---------- */
527
+ loc() {
528
+ return { pathname: location.pathname, search: location.search, hash: location.hash };
529
+ }
530
+ urlValue() {
531
+ const loc = this.loc();
532
+ // A hash route keeps its parameter in the hash, even once the hash has no query left.
533
+ const raw = this.hashMode && !usesHashParam(loc.hash) ? null : paramFromLocation(loc, this.urlParam);
534
+ if (raw === null)
535
+ return null;
536
+ return this.kind === 'multi'
537
+ ? raw
538
+ .split(',')
539
+ .map((x) => x.trim())
540
+ .filter(Boolean)
541
+ : raw;
542
+ }
543
+ /** On connect (and a new `url-param`): the address wins over the markup, quietly. */
544
+ readUrl() {
545
+ this.initial ??= Array.isArray(this.value) ? [...this.value] : this.value;
546
+ this.hashMode ??= usesHashParam(location.hash);
547
+ const v = this.urlValue();
548
+ if (v !== null)
549
+ this.value = v;
550
+ }
551
+ /** The value as it is written in the address. */
552
+ encode(v) {
553
+ if (Array.isArray(v))
554
+ return v.join(',');
555
+ if (this.kind === 'multi')
556
+ return String(v ?? '')
557
+ .split(',')
558
+ .map((x) => x.trim())
559
+ .filter(Boolean)
560
+ .join(',');
561
+ return String(v ?? '');
562
+ }
563
+ /**
564
+ * Push the value into the address. The markup's value is the address without the
565
+ * parameter; any other value is written, an empty one as `?year=`.
566
+ */
567
+ writeUrl() {
568
+ if (!this.urlParam)
569
+ return;
570
+ this.initial ??= '';
571
+ this.hashMode ??= usesHashParam(location.hash);
572
+ const value = this.encode(this.selected);
573
+ const id = value === this.encode(this.initial) ? null : value;
574
+ const next = hrefWithParam(this.loc(), this.urlParam, id, this.hashMode, true);
575
+ const now = location.pathname + location.search + location.hash;
576
+ if (next === now)
577
+ return;
578
+ try {
579
+ history.pushState(history.state, '', next);
580
+ }
581
+ catch {
582
+ // A sandboxed document (an iframe srcdoc) cannot change its address.
583
+ }
584
+ }
585
+ /* ---------- events ---------- */
586
+ emitChange(restored = false) {
587
+ const value = this.kind === 'multi' ? this.selected : (this.selected[0] ?? '');
588
+ const detail = { value };
589
+ if (restored)
590
+ detail.restored = true;
591
+ this.dispatchEvent(new CustomEvent('change', { detail, bubbles: true, composed: true }));
592
+ }
593
+ send(item) {
594
+ const name = `${this.label.trim()}: ${item.label}`;
595
+ const count = this.numericCount(item.count);
596
+ trackEvent(this, count === undefined ? [TAG, 'change', name] : [TAG, 'change', name, count]);
597
+ }
598
+ /**
599
+ * Multi: report the toggled chip and write the address now. Single: once changes settle
600
+ * (arrowing through a year rail), report the chip then selected and push one history entry,
601
+ * unless the visitor ended where they started.
602
+ */
603
+ track(item, from) {
604
+ if (this.kind === 'multi') {
605
+ this.writeUrl();
606
+ this.send(item);
607
+ return;
608
+ }
609
+ this.pending = { from: this.pending?.from ?? from, item };
610
+ clearTimeout(this.timer);
611
+ this.timer = setTimeout(() => this.flush(), chipGroupTiming.settle);
612
+ }
613
+ flush() {
614
+ const p = this.pending;
615
+ this.cancel();
616
+ if (!p || p.item.value === p.from || this.selected[0] !== p.item.value)
617
+ return;
618
+ this.writeUrl();
619
+ this.send(p.item);
620
+ }
621
+ /** Forget a single-select change that has not settled, without reporting it. */
622
+ cancel() {
623
+ clearTimeout(this.timer);
624
+ this.timer = undefined;
625
+ this.pending = undefined;
626
+ }
627
+ onRadio(e, item) {
628
+ // The radio's own change event must not reach the page as this element's `change` (in
629
+ // light DOM it would bubble through the host).
630
+ e.stopPropagation();
631
+ const input = e.target;
632
+ if (!input.checked)
633
+ return;
634
+ const from = this.selected[0] ?? '';
635
+ this.value = this.ownValue = item.value;
636
+ this.track(item, from);
637
+ this.emitChange();
638
+ }
639
+ onToggle(item) {
640
+ const now = this.selected;
641
+ const on = now.includes(item.value);
642
+ this.value = this.ownValue = on ? now.filter((v) => v !== item.value) : [...now, item.value];
643
+ this.track(item, '');
644
+ this.emitChange();
645
+ }
646
+ onSelect(e, item, link) {
647
+ if (e.defaultPrevented || e.button !== 0)
648
+ return;
649
+ trackEvent(this, [TAG, 'select', this.label.trim()]);
650
+ if (link && (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey))
651
+ return;
652
+ const detail = { value: item.value };
653
+ if (link && item.href !== undefined)
654
+ detail.href = item.href;
655
+ const go = new CustomEvent('select', {
656
+ detail,
657
+ bubbles: true,
658
+ composed: true,
659
+ cancelable: link,
660
+ });
661
+ if (!this.dispatchEvent(go) && link)
662
+ e.preventDefault();
663
+ }
664
+ /* ---------- render ---------- */
665
+ face(item, on) {
666
+ const count = item.count === undefined ? '' : this.formatCount(item.count);
667
+ return html `<span class="face"
668
+ >${on ? CHECK : nothing}${item.swatch
669
+ ? html `<span
670
+ class="swatch"
671
+ part="swatch"
672
+ aria-hidden="true"
673
+ data-colour=${item.swatch}
674
+ ></span>`
675
+ : nothing}<span class="text">${item.label}</span>${count
676
+ ? html `<span class="visually-hidden">, </span><span class="count">${count}</span
677
+ ><span class="visually-hidden"> ${this.countLabel}</span>`
678
+ : nothing}</span
679
+ >`;
680
+ }
681
+ renderChip(item) {
682
+ const kind = this.kind;
683
+ if (kind === 'single') {
684
+ const on = this.selected[0] === item.value;
685
+ return html `<label class="chip"
686
+ ><input
687
+ type="radio"
688
+ name=${this.uid}
689
+ .value=${item.value}
690
+ .checked=${on}
691
+ ?disabled=${!!item.disabled}
692
+ @change=${(e) => this.onRadio(e, item)}
693
+ />${this.face(item, on)}</label
694
+ >`;
695
+ }
696
+ if (kind === 'multi') {
697
+ const on = this.selected.includes(item.value);
698
+ return html `<button
699
+ type="button"
700
+ class="chip"
701
+ aria-pressed=${on ? 'true' : 'false'}
702
+ ?disabled=${!!item.disabled}
703
+ @click=${() => this.onToggle(item)}
704
+ >
705
+ ${this.face(item, on)}
706
+ </button>`;
707
+ }
708
+ if (item.disabled)
709
+ return html `<span class="chip" role="link" aria-disabled="true"
710
+ >${this.face(item, false)}</span
711
+ >`;
712
+ const href = item.href?.trim();
713
+ if (href) {
714
+ if (safeHref(href, this.ownerDocument.baseURI))
715
+ return html `<a
716
+ class="chip"
717
+ href=${item.href}
718
+ @click=${(e) => this.onSelect(e, item, true)}
719
+ >${this.face(item, false)}</a
720
+ >`;
721
+ this.warnOnce('href', 'showing a chip as text: its href is not http(s), mailto, tel or relative.');
722
+ return html `<span class="chip">${this.face(item, false)}</span>`;
723
+ }
724
+ return html `<button
725
+ type="button"
726
+ class="chip"
727
+ @click=${(e) => this.onSelect(e, item, false)}
728
+ >
729
+ ${this.face(item, false)}
730
+ </button>`;
731
+ }
732
+ updated(changed) {
733
+ super.updated(changed);
734
+ // The checked colour is set as a style property, never written as CSS text.
735
+ for (const s of this.renderRoot.querySelectorAll('.chips .swatch'))
736
+ s.style.backgroundColor = s.dataset.colour;
737
+ const g = this.renderRoot.querySelector('.chips.scroll') ?? undefined;
738
+ if (g !== this.observed) {
739
+ this.resize?.disconnect();
740
+ this.observed = g;
741
+ if (g) {
742
+ this.resize ??= new ResizeObserver(() => this.measure());
743
+ this.resize.observe(g);
744
+ }
745
+ }
746
+ // New or changed chips can widen the row without resizing it.
747
+ if (g)
748
+ requestAnimationFrame(this.measure);
749
+ }
750
+ render() {
751
+ const chips = this.chips;
752
+ const classes = ['chips', this.scrollRow ? 'scroll' : '', this.segmented ? 'segmented' : '']
753
+ .filter(Boolean)
754
+ .join(' ');
755
+ const description = normalize(this.description);
756
+ const descId = `${this.uid}-description`;
757
+ const hint = description
758
+ ? html `<p class="description" id=${descId} ?hidden=${!chips.length}>${description}</p>`
759
+ : nothing;
760
+ const row = html `<div
761
+ class=${classes}
762
+ role=${this.kind === 'single' ? 'radiogroup' : 'group'}
763
+ aria-label=${this.label.trim() || nothing}
764
+ aria-describedby=${description ? descId : nothing}
765
+ ?hidden=${!chips.length}
766
+ @scroll=${this.scrollRow ? this.measure : nothing}
767
+ >
768
+ ${chips.map((item) => this.renderChip(item))}
769
+ </div>`;
770
+ if (!this.scrollRow)
771
+ return html `${row}${hint}`;
772
+ return html `<div
773
+ class="rail"
774
+ ?data-more-left=${this.more.left}
775
+ ?data-more-right=${this.more.right}
776
+ >
777
+ ${row}
778
+ </div>
779
+ ${hint}`;
780
+ }
781
+ }
782
+ __decorate([
783
+ property({ type: String, reflect: true })
784
+ ], UvalibChipGroup.prototype, "mode", void 0);
785
+ __decorate([
786
+ property({ type: String })
787
+ ], UvalibChipGroup.prototype, "label", void 0);
788
+ __decorate([
789
+ property({ type: String })
790
+ ], UvalibChipGroup.prototype, "description", void 0);
791
+ __decorate([
792
+ property({
793
+ converter: { fromAttribute: (v) => v ?? '' },
794
+ })
795
+ ], UvalibChipGroup.prototype, "value", void 0);
796
+ __decorate([
797
+ property({ attribute: false })
798
+ ], UvalibChipGroup.prototype, "items", void 0);
799
+ __decorate([
800
+ property({ type: String, attribute: 'count-label' })
801
+ ], UvalibChipGroup.prototype, "countLabel", void 0);
802
+ __decorate([
803
+ property({ type: Boolean, reflect: true, attribute: 'scroll' })
804
+ ], UvalibChipGroup.prototype, "scrollRow", void 0);
805
+ __decorate([
806
+ property({ type: Boolean, reflect: true })
807
+ ], UvalibChipGroup.prototype, "segmented", void 0);
808
+ __decorate([
809
+ property({ type: String, attribute: 'url-param' })
810
+ ], UvalibChipGroup.prototype, "urlParam", void 0);
811
+ __decorate([
812
+ state()
813
+ ], UvalibChipGroup.prototype, "childItems", void 0);
814
+ __decorate([
815
+ state()
816
+ ], UvalibChipGroup.prototype, "more", void 0);
817
+ //# sourceMappingURL=UvalibChipGroup.js.map