@uvalib/web-components 1.6.0 → 1.8.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 (106) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +133 -12
  3. package/dist/base/states.d.ts +12 -0
  4. package/dist/base/states.js +33 -0
  5. package/dist/base/states.js.map +1 -0
  6. package/dist/base.css +15 -5
  7. package/dist/components/bento-box/BentoBox.js +1 -0
  8. package/dist/components/bento-box/BentoBox.js.map +1 -1
  9. package/dist/components/events-section/EventsSection.js +1 -0
  10. package/dist/components/events-section/EventsSection.js.map +1 -1
  11. package/dist/components/library-hours/hours-data.js +1 -1
  12. package/dist/components/library-hours/hours-data.js.map +1 -1
  13. package/dist/components/library-weekly-hours/LibraryWeeklyHours.js +1 -0
  14. package/dist/components/library-weekly-hours/LibraryWeeklyHours.js.map +1 -1
  15. package/dist/components/uvalib-card/UvalibCard.js +6 -0
  16. package/dist/components/uvalib-card/UvalibCard.js.map +1 -1
  17. package/dist/components/uvalib-combobox/UvalibCombobox.d.ts +27 -0
  18. package/dist/components/uvalib-combobox/UvalibCombobox.js +85 -1
  19. package/dist/components/uvalib-combobox/UvalibCombobox.js.map +1 -1
  20. package/dist/components/uvalib-contents/UvalibContents.js +5 -0
  21. package/dist/components/uvalib-contents/UvalibContents.js.map +1 -1
  22. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.d.ts +6 -0
  23. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js +10 -0
  24. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js.map +1 -1
  25. package/dist/components/uvalib-image-regions/UvalibImageRegions.d.ts +1 -0
  26. package/dist/components/uvalib-image-regions/UvalibImageRegions.js +4 -1
  27. package/dist/components/uvalib-image-regions/UvalibImageRegions.js.map +1 -1
  28. package/dist/components/uvalib-image-regions/regions.d.ts +6 -2
  29. package/dist/components/uvalib-image-regions/regions.js +6 -3
  30. package/dist/components/uvalib-image-regions/regions.js.map +1 -1
  31. package/dist/components/uvalib-lightbox/UvalibLightbox.d.ts +100 -7
  32. package/dist/components/uvalib-lightbox/UvalibLightbox.js +310 -83
  33. package/dist/components/uvalib-lightbox/UvalibLightbox.js.map +1 -1
  34. package/dist/components/uvalib-lightbox/compare.d.ts +48 -8
  35. package/dist/components/uvalib-lightbox/compare.js +226 -22
  36. package/dist/components/uvalib-lightbox/compare.js.map +1 -1
  37. package/dist/components/uvalib-map/UvalibMap.js +2 -2
  38. package/dist/components/uvalib-map/UvalibMap.js.map +1 -1
  39. package/dist/components/uvalib-metadata/UvalibMetadata.js +3 -0
  40. package/dist/components/uvalib-metadata/UvalibMetadata.js.map +1 -1
  41. package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js +3 -1
  42. package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js.map +1 -1
  43. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.d.ts +3 -3
  44. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js +16 -8
  45. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js.map +1 -1
  46. package/dist/components/uvalib-tag-list/UvalibTagList.d.ts +4 -1
  47. package/dist/components/uvalib-tag-list/UvalibTagList.js +9 -2
  48. package/dist/components/uvalib-tag-list/UvalibTagList.js.map +1 -1
  49. package/dist/custom-elements.json +596 -19
  50. package/dist/styles/message.js +4 -0
  51. package/dist/styles/message.js.map +1 -1
  52. package/dist/styles/result-list.js +25 -4
  53. package/dist/styles/result-list.js.map +1 -1
  54. package/dist/styles/results.js +17 -2
  55. package/dist/styles/results.js.map +1 -1
  56. package/dist-cdn/base.css +15 -5
  57. package/dist-cdn/bento-box.js +1 -0
  58. package/dist-cdn/bento-box.js.map +1 -1
  59. package/dist-cdn/chunks/{compare-D4VdaIJN.js → compare-C0nhByn7.js} +185 -56
  60. package/dist-cdn/chunks/compare-C0nhByn7.js.map +1 -0
  61. package/dist-cdn/chunks/{hours-data-Bw6vkIw7.js → hours-data-gMu5uT7H.js} +2 -2
  62. package/dist-cdn/chunks/hours-data-gMu5uT7H.js.map +1 -0
  63. package/dist-cdn/chunks/{library-weekly-hours-CrV3TlP5.js → library-weekly-hours-BJgxAyah.js} +3 -2
  64. package/dist-cdn/chunks/library-weekly-hours-BJgxAyah.js.map +1 -0
  65. package/dist-cdn/chunks/{regions-B8ExwUGP.js → regions-B-rOwa-v.js} +15 -15
  66. package/dist-cdn/chunks/regions-B-rOwa-v.js.map +1 -0
  67. package/dist-cdn/chunks/states-DGXGzcte.js +17 -0
  68. package/dist-cdn/chunks/states-DGXGzcte.js.map +1 -0
  69. package/dist-cdn/custom-elements.json +596 -19
  70. package/dist-cdn/events-section.js +1 -0
  71. package/dist-cdn/events-section.js.map +1 -1
  72. package/dist-cdn/library-hours-setup.js +1 -1
  73. package/dist-cdn/library-weekly-hours.js +1 -1
  74. package/dist-cdn/manifest.json +1 -1
  75. package/dist-cdn/site-hours-section.js +1 -1
  76. package/dist-cdn/skills/uvalib-web-components/SKILL.md +8 -6
  77. package/dist-cdn/skills/uvalib-web-components/reference/components.md +37 -6
  78. package/dist-cdn/uvalib-card.js +6 -0
  79. package/dist-cdn/uvalib-card.js.map +1 -1
  80. package/dist-cdn/uvalib-combobox.js +107 -68
  81. package/dist-cdn/uvalib-combobox.js.map +1 -1
  82. package/dist-cdn/uvalib-contents.js +5 -0
  83. package/dist-cdn/uvalib-contents.js.map +1 -1
  84. package/dist-cdn/uvalib-filter-drawer.js +27 -25
  85. package/dist-cdn/uvalib-filter-drawer.js.map +1 -1
  86. package/dist-cdn/uvalib-image-regions.js +4 -2
  87. package/dist-cdn/uvalib-image-regions.js.map +1 -1
  88. package/dist-cdn/uvalib-lightbox.js +230 -129
  89. package/dist-cdn/uvalib-lightbox.js.map +1 -1
  90. package/dist-cdn/uvalib-map.js +2 -2
  91. package/dist-cdn/uvalib-map.js.map +1 -1
  92. package/dist-cdn/uvalib-metadata.js +3 -0
  93. package/dist-cdn/uvalib-metadata.js.map +1 -1
  94. package/dist-cdn/uvalib-pagefind-search.js +2 -1
  95. package/dist-cdn/uvalib-pagefind-search.js.map +1 -1
  96. package/dist-cdn/uvalib-photo-grid.js +4 -5
  97. package/dist-cdn/uvalib-photo-grid.js.map +1 -1
  98. package/dist-cdn/uvalib-tag-list.js +21 -16
  99. package/dist-cdn/uvalib-tag-list.js.map +1 -1
  100. package/package.json +1 -1
  101. package/skills/uvalib-web-components/SKILL.md +8 -6
  102. package/skills/uvalib-web-components/reference/components.md +37 -6
  103. package/dist-cdn/chunks/compare-D4VdaIJN.js.map +0 -1
  104. package/dist-cdn/chunks/hours-data-Bw6vkIw7.js.map +0 -1
  105. package/dist-cdn/chunks/library-weekly-hours-CrV3TlP5.js.map +0 -1
  106. package/dist-cdn/chunks/regions-B8ExwUGP.js.map +0 -1
@@ -2,9 +2,10 @@ import { a as e, f as t, i as n, l as r, m as i, n as a, o, p as s, r as c, t as
2
2
  import { a as u } from "./chunks/analytics-DTTihuBD.js";
3
3
  import { n as d, t as f } from "./chunks/inline-copy-BANQSMIR.js";
4
4
  import { n as p, r as m, t as h } from "./chunks/source-children-BHsDwCvL.js";
5
- import { t as g } from "./chunks/accessible-DJv7YOtS.js";
5
+ import { n as g, t as _ } from "./chunks/states-DGXGzcte.js";
6
+ import { t as v } from "./chunks/accessible-DJv7YOtS.js";
6
7
  // src/components/uvalib-tag-list/UvalibTagList.ts
7
- var _ = (e) => JSON.stringify(e, (e, t) => e === "nodes" ? void 0 : t), v = (e) => e?.trim() || void 0, y = (e) => `
8
+ var y = (e) => JSON.stringify(e, (e, t) => e === "nodes" ? void 0 : t), b = (e) => e?.trim() || void 0, x = (e) => `
8
9
  ${e} { display: block; }
9
10
  ${e} ul {
10
11
  display: flex;
@@ -36,11 +37,11 @@ var _ = (e) => JSON.stringify(e, (e, t) => e === "nodes" ? void 0 : t), v = (e)
36
37
  border: 0;
37
38
  }
38
39
  ${e}[hidden], ${e} [hidden] { display: none !important; }
39
- `, b = s(y(":host")), x = 0, S = class extends l {
40
+ `, S = s(x(":host")), C = 0, w = class extends l {
40
41
  static {
41
42
  this.styles = [
42
- g,
43
- b,
43
+ v,
44
+ S,
44
45
  t`
45
46
  :host {
46
47
  color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));
@@ -106,12 +107,12 @@ var _ = (e) => JSON.stringify(e, (e, t) => e === "nodes" ? void 0 : t), v = (e)
106
107
  ];
107
108
  }
108
109
  constructor() {
109
- super(), this.label = "", this.hideLabel = !1, this.trackLabel = !1, this.hrefTemplate = "", this.expanded = !1, this.childTags = [], this.uid = `uvalib-tag-list-${++x}`, this.warned = /* @__PURE__ */ new Set(), new h(this, () => this.lightDom, (e) => this.read(e));
110
+ super(), this.label = "", this.hideLabel = !1, this.trackLabel = !1, this.hrefTemplate = "", this.expanded = !1, this.childTags = [], this.uid = `uvalib-tag-list-${++C}`, this.warned = /* @__PURE__ */ new Set(), this.internals = _(this), new h(this, () => this.lightDom, (e) => this.read(e));
110
111
  }
111
112
  createRenderRoot() {
112
113
  let e = super.createRenderRoot();
113
114
  if (e instanceof ShadowRoot && this.noStyle) {
114
- let t = b.styleSheet;
115
+ let t = S.styleSheet;
115
116
  t && (e.adoptedStyleSheets = [t]);
116
117
  }
117
118
  return e;
@@ -119,7 +120,7 @@ var _ = (e) => JSON.stringify(e, (e, t) => e === "nodes" ? void 0 : t), v = (e)
119
120
  connectedCallback() {
120
121
  if (super.connectedCallback(), this.lightDom && this.noStyle) {
121
122
  let e = this.getRootNode();
122
- c(`${this.localName}::structure`, s(y(this.localName)), {
123
+ c(`${this.localName}::structure`, s(x(this.localName)), {
123
124
  root: e instanceof ShadowRoot || e instanceof Document ? e : void 0,
124
125
  scope: !1
125
126
  });
@@ -150,12 +151,12 @@ var _ = (e) => JSON.stringify(e, (e, t) => e === "nodes" ? void 0 : t), v = (e)
150
151
  let i = {
151
152
  label: e,
152
153
  ...d(r)
153
- }, a = r instanceof HTMLAnchorElement ? v(r.getAttribute("href")) : void 0;
154
+ }, a = r instanceof HTMLAnchorElement ? b(r.getAttribute("href")) : void 0;
154
155
  a !== void 0 && (i.href = a);
155
156
  let o = f(r.childNodes, this.ownerDocument);
156
157
  o.rich && (i.rich = o.key, i.nodes = o.nodes), t.push(i);
157
158
  }
158
- n && this.warnOnce("text", "ignoring tags with no text."), _(t) !== _(this.childTags) && (this.childTags = t);
159
+ n && this.warnOnce("text", "ignoring tags with no text."), y(t) !== y(this.childTags) && (this.childTags = t);
159
160
  }
160
161
  safe(e) {
161
162
  let t = m(e, this.ownerDocument.baseURI);
@@ -163,7 +164,7 @@ var _ = (e) => JSON.stringify(e, (e, t) => e === "nodes" ? void 0 : t), v = (e)
163
164
  }
164
165
  get tags() {
165
166
  let e = this.items ? this.items.filter((e) => p(e?.label)).map((e) => {
166
- let t = { label: p(e.label) }, n = v(e.href);
167
+ let t = { label: p(e.label) }, n = b(e.href);
167
168
  return n !== void 0 && (t.href = n), e.lang !== void 0 && (t.lang = e.lang), e.dir && (t.dir = e.dir), t;
168
169
  }) : this.childTags, t = this.hrefTemplate.trim();
169
170
  return e.map((e) => {
@@ -211,7 +212,11 @@ var _ = (e) => JSON.stringify(e, (e, t) => e === "nodes" ? void 0 : t), v = (e)
211
212
  ]);
212
213
  }
213
214
  updated(e) {
214
- super.updated(e), this.toggleAttribute("data-empty", !this.tags.length);
215
+ super.updated(e);
216
+ let t = this.tags;
217
+ this.toggleAttribute("data-empty", !t.length);
218
+ let n = this.max;
219
+ g(this.internals, "expanded", this.expanded && n > 0 && t.length > n);
215
220
  }
216
221
  renderTag(e, t) {
217
222
  let n = e.nodes ? e.nodes.map((e) => e.cloneNode(!0)) : e.label;
@@ -253,15 +258,15 @@ var _ = (e) => JSON.stringify(e, (e, t) => e === "nodes" ? void 0 : t), v = (e)
253
258
  }
254
259
  };
255
260
  // src/components/uvalib-tag-list/uvalib-tag-list.ts
256
- a([e({ type: String })], S.prototype, "label", void 0), a([e({
261
+ a([e({ type: String })], w.prototype, "label", void 0), a([e({
257
262
  type: Boolean,
258
263
  attribute: "hide-label"
259
- })], S.prototype, "hideLabel", void 0), a([e({
264
+ })], w.prototype, "hideLabel", void 0), a([e({
260
265
  type: Boolean,
261
266
  attribute: "track-label"
262
- })], S.prototype, "trackLabel", void 0), a([e({ type: Number })], S.prototype, "limit", void 0), a([e({
267
+ })], w.prototype, "trackLabel", void 0), a([e({ type: Number })], w.prototype, "limit", void 0), a([e({
263
268
  type: String,
264
269
  attribute: "href-template"
265
- })], S.prototype, "hrefTemplate", void 0), a([e({ attribute: !1 })], S.prototype, "items", void 0), a([n()], S.prototype, "expanded", void 0), a([n()], S.prototype, "childTags", void 0), i("uvalib-tag-list", S);
270
+ })], w.prototype, "hrefTemplate", void 0), a([e({ attribute: !1 })], w.prototype, "items", void 0), a([n()], w.prototype, "expanded", void 0), a([n()], w.prototype, "childTags", void 0), i("uvalib-tag-list", w);
266
271
 
267
272
  //# sourceMappingURL=uvalib-tag-list.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"uvalib-tag-list.js","names":["unsafeCSS","nothing","_decorate","property","state","n","i","r$1","b","define","__decorate","r","installLightDomStyles","UvalibElement","trackEvent","langDir","inlineCopy","normalize","safeHref","SourceChildren","accessible","keyOf","tags","k","v","hrefOf","h","structuralRules","host","shadowStructure","instances","UvalibTagList","nodes","root","sheet","node","changed","key","message","invalid","label","tag","href","copy","ok","source","template","t","out","a","index","go","text","A","max","collapsible","labelId","listId","toggleText"],"sources":["../src/components/uvalib-tag-list/UvalibTagList.ts","../src/components/uvalib-tag-list/uvalib-tag-list.ts"],"sourcesContent":["import { css, html, nothing, unsafeCSS, type PropertyValues } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { trackEvent } from '../../base/analytics.js';\nimport { inlineCopy, langDir } from '../../base/inline-copy.js';\nimport { normalize, safeHref, SourceChildren } from '../../base/source-children.js';\nimport { UvalibElement } from '../../base/UvalibElement.js';\nimport { installLightDomStyles } from '../../base/light-dom-styles.js';\nimport { accessible } from '../../styles/accessible.js';\n\n/** One tag: its visible text and, when it is a link, where it goes; `lang`/`dir` if they differ. */\nexport interface TagItem {\n label: string;\n href?: string;\n lang?: string;\n dir?: string;\n}\n\n/** A tag as read and drawn: `nodes` is a safe inline copy of a child's content, `rich` its key. */\ninterface Tag extends TagItem {\n rich?: string;\n nodes?: Node[];\n}\n\n/** Compare two reads, leaving out the copied nodes (their `rich` key stands for them). */\nconst keyOf = (tags: Tag[]) =>\n JSON.stringify(tags, (k, v: unknown) => (k === 'nodes' ? undefined : v));\n\n/** A blank href is no href (it would reload the page and skip `href-template`). */\nconst hrefOf = (h: string | null | undefined): string | undefined => {\n const t = h?.trim();\n return t ? t : undefined;\n};\n\n/**\n * Kept with `no-style`: the tags wrap in a row with gaps, no bullets, every link and the\n * toggle at least 24px with space around (WCAG 2.5.8), the hidden label stays hidden and\n * `[hidden]` hides. `host` is `:host` or the tag name.\n */\nconst structuralRules = (host: string) => `\n ${host} { display: block; }\n ${host} ul {\n display: flex;\n flex-wrap: wrap;\n gap: 0.5rem;\n list-style: none;\n margin: 0;\n padding: 0;\n }\n ${host} li { display: flex; max-width: 100%; min-width: 0; }\n ${host} :where(a.tag, .toggle) {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n min-height: 24px;\n min-width: 24px;\n }\n ${host} :where(.toggle) { margin-top: 0.5rem; }\n ${host} .visually-hidden {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border: 0;\n }\n ${host}[hidden], ${host} [hidden] { display: none !important; }\n`;\nconst shadowStructure = unsafeCSS(structuralRules(':host'));\n\nlet instances = 0;\n\n/**\n * A labelled list of keywords or subjects that wraps: each tag a link (for example a search\n * for that term) or plain text. Link tags are outlined pills in the link colour; plain tags\n * are filled chips (the card chip's colours), so a link never looks like a label. Every tag\n * and the toggle are at least 2rem (34px) tall and wide, 0.5rem apart.\n *\n * Give the tags as children: `<a href>` for a link, any other element (`<span>`) for plain\n * text. A child's `lang` and `dir` are kept, and so is inline markup inside it (`em`, `cite`,\n * `abbr`, `bdi`, a `span lang`…), copied element by element (never parsed as HTML). Or set\n * `href-template` (with `{tag}`, replaced by the URL-encoded text) to make every tag without\n * its own href a link; a blank href counts as none. Apps can set the `items` property\n * (`{ label, href?, lang?, dir? }`) instead; it wins over the children. Children with no text\n * are skipped with one warning.\n *\n * `label` names the list (shown above it, or visually hidden with `hide-label`); without one\n * a console warning is logged. `limit` shows that many tags and a “Show all N” button\n * (`aria-expanded`, `aria-controls`), which reveals the rest in place and keeps focus.\n *\n * Analytics never sends a tag's text (record tags can be user-submitted or machine-made), and\n * by default not the label either, which a template may fill from a record: the name is the\n * list's place among the tag lists on the page, `list N`. Add `track-label` when the label is\n * fixed text the page author wrote (“Subjects”), to send it instead.\n *\n * @tagname uvalib-tag-list\n * @fires uvalib-analytics-event - For `<site-analytics>`: a primary-button click on a tag link, `['uvalib-tag-list', 'tag-click', '<name>', <n>]` (n from 1, the tag's place in the list), and the toggle, `['uvalib-tag-list', 'show-all'|'show-fewer', '<name>']`. The name is `list N` (N from 1, the list's place among the tag lists in its document or shadow root), or with `track-label` the list's `label`; never the tag text or URL. Bubbles and is composed.\n * @fires uvalib-tag-list-navigate - A plain click on a tag link: `detail` is `{ href, tag, index }` (index from 0). Cancel it (`preventDefault()`) to route in the app; the click's default is then prevented. Bubbles and is composed.\n * @cssprop [--uva-blue-alt-300=#BFE7F7] - Plain tag background (the card chip's).\n * @cssprop [--uva-blue-alt-dark=#005679] - Plain tag text.\n * @cssprop --uva-color-link - Dark-mode role token: link tag text (else `--uva-brand-blue`).\n * @cssprop --uva-color-control-border - Dark-mode role token: link tag outline (else `--uva-grey`).\n * @cssprop --uva-color-text - Dark-mode role token: the label (else `--uva-grey-darkest`).\n * @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).\n */\nexport class UvalibTagList extends UvalibElement {\n static styles = [\n accessible,\n shadowStructure,\n css`\n :host {\n color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));\n }\n .label {\n display: block;\n margin-block-end: 0.5rem;\n font-weight: 600;\n }\n .tag {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n max-width: 100%;\n min-height: 2rem;\n min-width: 2rem;\n padding: 0.15rem 0.7rem;\n border: 1px solid transparent;\n border-radius: 999px;\n font-size: 0.875rem;\n line-height: 1.4;\n overflow-wrap: anywhere;\n }\n span.tag {\n background: var(--uva-blue-alt-300, #bfe7f7);\n color: var(--uva-blue-alt-dark, #005679);\n }\n a.tag {\n border-color: var(--uva-color-control-border, var(--uva-grey, #808080));\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n text-decoration: none;\n }\n a.tag:hover {\n border-color: currentColor;\n text-decoration: underline;\n }\n .toggle {\n min-height: 2rem;\n min-width: 2rem;\n padding: 0.15rem 0.35rem;\n border: 0;\n background: none;\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n font: inherit;\n font-size: 0.875rem;\n text-decoration: underline;\n cursor: pointer;\n }\n @media (forced-colors: active) {\n span.tag {\n border-color: CanvasText;\n }\n a.tag {\n border-color: LinkText;\n color: LinkText;\n }\n .toggle {\n color: ButtonText;\n }\n }\n `,\n ];\n\n /** The list's name: shown above the tags (and, with `track-label`, the analytics name). */\n @property({ type: String }) label = '';\n\n /** Hide the label visually; it still names the list. */\n @property({ type: Boolean, attribute: 'hide-label' }) hideLabel = false;\n\n /**\n * Send the label as the analytics name. Only for fixed text the page author wrote, never a\n * label filled from a record. Without it the name is `list N`.\n */\n @property({ type: Boolean, attribute: 'track-label' }) trackLabel = false;\n\n /** Show this many tags and a “Show all N” button. Zero or empty shows every tag. */\n @property({ type: Number }) limit?: number;\n\n /**\n * Href for tags without their own, with `{tag}` where the URL-encoded text goes, for\n * example `/search?q={tag}`. Empty: such tags are plain text.\n */\n @property({ type: String, attribute: 'href-template' }) hrefTemplate = '';\n\n /** The tags as data (`{ label, href?, lang?, dir? }`), for apps. Wins over the children while set. */\n @property({ attribute: false }) items?: TagItem[];\n\n /** Whether every tag is shown (after Show all). */\n @state() private expanded = false;\n /** The tags read from the children. */\n @state() private childTags: Tag[] = [];\n\n private readonly uid = `uvalib-tag-list-${++instances}`;\n private warned = new Set<string>();\n\n constructor() {\n super();\n // Light DOM: the children move to a hidden holder before every render, also when the\n // element is connected, moved or reconnected before its first update.\n new SourceChildren(\n this,\n () => this.lightDom,\n (nodes) => this.read(nodes),\n );\n }\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n const root = super.createRenderRoot();\n if (root instanceof ShadowRoot && this.noStyle) {\n const sheet = shadowStructure.styleSheet;\n if (sheet) root.adoptedStyleSheets = [sheet];\n }\n return root;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n if (this.lightDom && this.noStyle) {\n const node = this.getRootNode();\n installLightDomStyles(\n `${this.localName}::structure`,\n unsafeCSS(structuralRules(this.localName)),\n {\n root: node instanceof ShadowRoot || node instanceof Document ? node : undefined,\n scope: false,\n },\n );\n }\n }\n\n protected override firstUpdated(): void {\n if (!normalize(this.label))\n this.warnOnce('label', 'set label to name the list (for example “Subjects”).');\n }\n\n protected override willUpdate(changed: PropertyValues): void {\n if (changed.has('items') && this.items?.some((i) => !normalize(i?.label)))\n this.warnOnce('text', 'ignoring tags with no text.');\n }\n\n private warnOnce(key: string, message: string): void {\n if (this.warned.has(key)) return;\n this.warned.add(key);\n console.warn(`${this.localName}: ${message}`);\n }\n\n /** Read the tags from the source children. */\n private read(nodes: Node[]): void {\n const tags: Tag[] = [];\n let invalid = false;\n for (const n of nodes) {\n if (n.nodeType === Node.TEXT_NODE) {\n if (normalize(n.textContent)) invalid = true;\n continue;\n }\n if (!(n instanceof Element)) continue;\n const label = normalize(n.textContent);\n if (!label) {\n invalid = true;\n continue;\n }\n const tag: Tag = { label, ...langDir(n) };\n const href = n instanceof HTMLAnchorElement ? hrefOf(n.getAttribute('href')) : undefined;\n if (href !== undefined) tag.href = href;\n const copy = inlineCopy(n.childNodes, this.ownerDocument);\n if (copy.rich) {\n tag.rich = copy.key;\n tag.nodes = copy.nodes;\n }\n tags.push(tag);\n }\n if (invalid) this.warnOnce('text', 'ignoring tags with no text.');\n if (keyOf(tags) !== keyOf(this.childTags)) this.childTags = tags;\n }\n\n private safe(href: string): boolean {\n const ok = safeHref(href, this.ownerDocument.baseURI);\n if (!ok)\n this.warnOnce(\n 'href',\n 'showing a tag as text: its href is not http(s), mailto, tel or relative.',\n );\n return ok;\n }\n\n /** What is shown: `items` while set, else the children; hrefs from the template; unsafe ones dropped. */\n private get tags(): Tag[] {\n const source: Tag[] = this.items\n ? this.items\n .filter((i) => normalize(i?.label))\n .map((i) => {\n const t: Tag = { label: normalize(i.label) };\n const href = hrefOf(i.href);\n if (href !== undefined) t.href = href;\n if (i.lang !== undefined) t.lang = i.lang;\n if (i.dir) t.dir = i.dir;\n return t;\n })\n : this.childTags;\n const template = this.hrefTemplate.trim();\n return source.map((t) => {\n const href =\n t.href ??\n (template.includes('{tag}')\n ? template.replaceAll('{tag}', encodeURIComponent(t.label))\n : undefined);\n const out: Tag = { ...t };\n if (href !== undefined && this.safe(href)) out.href = href;\n else delete out.href;\n return out;\n });\n }\n\n /** The `limit`, when it hides anything: a positive whole number. */\n private get max(): number {\n const n = Math.trunc(this.limit ?? 0);\n return Number.isFinite(n) && n > 0 ? n : 0;\n }\n\n /** The analytics name: the label with `track-label`, else `list N` (this list's place in its root). */\n private get name(): string {\n const label = normalize(this.label);\n if (this.trackLabel && label) return label;\n const root = this.getRootNode() as Document | ShadowRoot;\n const lists = root.querySelectorAll ? [...root.querySelectorAll(this.localName)] : [];\n const i = lists.indexOf(this);\n return `list ${i < 0 ? 1 : i + 1}`;\n }\n\n private onClick(e: MouseEvent): void {\n const node = e.target instanceof Node ? e.target : null;\n const el = node instanceof Element ? node : node?.parentElement;\n const a = el?.closest('a[href]');\n if (!(a instanceof HTMLAnchorElement) || !this.renderRoot.contains(a)) return;\n if (e.defaultPrevented || e.button !== 0) return;\n const index = Number(a.dataset.index);\n trackEvent(this, ['uvalib-tag-list', 'tag-click', this.name, index + 1]);\n if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;\n const go = new CustomEvent('uvalib-tag-list-navigate', {\n detail: { href: a.getAttribute('href'), tag: normalize(a.textContent), index },\n bubbles: true,\n composed: true,\n cancelable: true,\n });\n if (!this.dispatchEvent(go)) e.preventDefault();\n }\n\n private toggle(): void {\n this.expanded = !this.expanded;\n trackEvent(this, ['uvalib-tag-list', this.expanded ? 'show-all' : 'show-fewer', this.name]);\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n this.toggleAttribute('data-empty', !this.tags.length);\n }\n\n private renderTag(t: Tag, i: number) {\n const text = t.nodes ? t.nodes.map((n) => n.cloneNode(true)) : t.label;\n return t.href !== undefined\n ? html`<a\n class=\"tag\"\n href=${t.href}\n data-index=${i}\n lang=${t.lang ?? nothing}\n dir=${t.dir ?? nothing}\n >${text}</a\n >`\n : html`<span class=\"tag\" lang=${t.lang ?? nothing} dir=${t.dir ?? nothing}>${text}</span>`;\n }\n\n protected override render() {\n const tags = this.tags;\n const max = this.max;\n const collapsible = max > 0 && tags.length > max;\n const label = normalize(this.label);\n const labelId = `${this.uid}-label`;\n const listId = `${this.uid}-list`;\n const toggleText = this.expanded ? 'Show fewer' : `Show all ${tags.length}`;\n // One wrapper, always rendered.\n return html`<div class=\"tag-list\" ?hidden=${!tags.length}>\n ${\n label\n ? html`<span id=${labelId} class=${this.hideLabel ? 'label visually-hidden' : 'label'}\n >${label}</span\n >`\n : nothing\n }\n <ul\n role=\"list\"\n id=${listId}\n aria-labelledby=${label ? labelId : nothing}\n @click=${this.onClick}\n >\n ${tags.map(\n (t, i) =>\n html`<li role=\"listitem\" ?hidden=${collapsible && !this.expanded && i >= max}>\n ${this.renderTag(t, i)}\n </li>`,\n )}\n </ul>\n ${\n collapsible\n ? html`<button\n type=\"button\"\n class=\"toggle\"\n aria-expanded=${this.expanded ? 'true' : 'false'}\n aria-controls=${listId}\n @click=${this.toggle}\n >\n ${toggleText}${label ? html`<span class=\"visually-hidden\"> ${label}</span>` : nothing}\n </button>`\n : nothing\n }\n </div>`;\n }\n}\n","import { define } from '../../base/define.js';\nimport { UvalibTagList } from './UvalibTagList.js';\n\ndefine('uvalib-tag-list', UvalibTagList);\n"],"mappings":";;;;;;AAwBA,IAAMqB,KAAS,MACb,KAAK,UAAUC,IAAO,GAAG,MAAgBC,MAAM,UAAU,KAAA,IAAYC,CAAE,GAGnEC,KAAU,MACJC,GAAG,KAAK,KACH,KAAA,GAQXC,KAAmB,MAAiB;IACtCC,EAAK;IACLA,EAAK;;;;;;;;IAQLA,EAAK;IACLA,EAAK;;;;;;;;IAQLA,EAAK;IACLA,EAAK;;;;;;;;;;;IAWLA,EAAK,YAAYA,EAAK;GAEpBC,IAAkB7B,EAAU2B,EAAgB,OAAO,CAAC,GAEtDG,IAAY,GAmCHC,IAAb,cAAmClB,EAAc;;EAC/B,KAAA,SAAA;GACdO;GACAS;GACA,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8DL;;CAkCA,cAAc;EAIZ,AAHA,MAAM,GAhC4B,KAAA,QAAA,IAG8B,KAAA,YAAA,IAME,KAAA,aAAA,IASG,KAAA,eAAA,IAM3C,KAAA,WAAA,IAEQ,KAAA,YAAA,CAAC,GAEd,KAAA,MAAA,mBAAmB,EAAEC,KAC3B,KAAA,yBAAA,IAAI,IAAY,GAM/B,IAAIX,EACF,YACM,KAAK,WACV,MAAU,KAAK,KAAKa,CAAK,CAC5B;CACF;CAEA,mBAAsE;EACpE,IAAMC,IAAO,MAAM,iBAAiB;EACpC,IAAIA,aAAgB,cAAc,KAAK,SAAS;GAC9C,IAAMC,IAAQL,EAAgB;GAC9B,AAAIK,MAAO,EAAK,qBAAqB,CAACA,CAAK;EAC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AA,GAAA4B,EAAA,WAAA,aAAA,KAAA,CAAA,GAMnD7B,EAAA,CAAAC,EAAS;CAAE,MAAM;CAAS,WAAW;AAAc,CAAC,CAAA,GAAA4B,EAAA,WAAA,cAAA,KAAA,CAAA,GAGpD7B,EAAA,CAAAC,EAAS,EAAE,MAAM,OAAO,CAAC,CAAA,GAAA4B,EAAA,WAAA,SAAA,KAAA,CAAA,GAMzB7B,EAAA,CAAAC,EAAS;CAAE,MAAM;CAAQ,WAAW;AAAgB,CAAC,CAAA,GAAA4B,EAAA,WAAA,gBAAA,KAAA,CAAA,GAGrD7B,EAAA,CAAAC,EAAS,EAAE,WAAW,GAAM,CAAC,CAAA,GAAA4B,EAAA,WAAA,SAAA,KAAA,CAAA,GAG7B7B,EAAA,CAAAE,EAAM,CAAA,GAAA2B,EAAA,WAAA,YAAA,KAAA,CAAA,GAEN7B,EAAA,CAAAE,EAAM,CAAA,GAAA2B,EAAA,WAAA,aAAA,KAAA,CAAA,GCxMTtB,EAAO,mBAAmBsB,CAAa"}
1
+ {"version":3,"file":"uvalib-tag-list.js","names":["unsafeCSS","nothing","_decorate","property","state","n","i","r$1","b","define","__decorate","r","installLightDomStyles","UvalibElement","trackEvent","langDir","inlineCopy","normalize","safeHref","SourceChildren","setState","attachStateInternals","accessible","keyOf","tags","k","v","hrefOf","h","structuralRules","host","shadowStructure","instances","UvalibTagList","nodes","root","sheet","node","changed","key","message","invalid","label","tag","href","copy","ok","source","template","t","out","a","index","go","max","text","A","collapsible","labelId","listId","toggleText"],"sources":["../src/components/uvalib-tag-list/UvalibTagList.ts","../src/components/uvalib-tag-list/uvalib-tag-list.ts"],"sourcesContent":["import { css, html, nothing, unsafeCSS, type PropertyValues } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { trackEvent } from '../../base/analytics.js';\nimport { inlineCopy, langDir } from '../../base/inline-copy.js';\nimport { normalize, safeHref, SourceChildren } from '../../base/source-children.js';\nimport { attachStateInternals, setState } from '../../base/states.js';\nimport { UvalibElement } from '../../base/UvalibElement.js';\nimport { installLightDomStyles } from '../../base/light-dom-styles.js';\nimport { accessible } from '../../styles/accessible.js';\n\n/** One tag: its visible text and, when it is a link, where it goes; `lang`/`dir` if they differ. */\nexport interface TagItem {\n label: string;\n href?: string;\n lang?: string;\n dir?: string;\n}\n\n/** A tag as read and drawn: `nodes` is a safe inline copy of a child's content, `rich` its key. */\ninterface Tag extends TagItem {\n rich?: string;\n nodes?: Node[];\n}\n\n/** Compare two reads, leaving out the copied nodes (their `rich` key stands for them). */\nconst keyOf = (tags: Tag[]) =>\n JSON.stringify(tags, (k, v: unknown) => (k === 'nodes' ? undefined : v));\n\n/** A blank href is no href (it would reload the page and skip `href-template`). */\nconst hrefOf = (h: string | null | undefined): string | undefined => {\n const t = h?.trim();\n return t ? t : undefined;\n};\n\n/**\n * Kept with `no-style`: the tags wrap in a row with gaps, no bullets, every link and the\n * toggle at least 24px with space around (WCAG 2.5.8), the hidden label stays hidden and\n * `[hidden]` hides. `host` is `:host` or the tag name.\n */\nconst structuralRules = (host: string) => `\n ${host} { display: block; }\n ${host} ul {\n display: flex;\n flex-wrap: wrap;\n gap: 0.5rem;\n list-style: none;\n margin: 0;\n padding: 0;\n }\n ${host} li { display: flex; max-width: 100%; min-width: 0; }\n ${host} :where(a.tag, .toggle) {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n min-height: 24px;\n min-width: 24px;\n }\n ${host} :where(.toggle) { margin-top: 0.5rem; }\n ${host} .visually-hidden {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border: 0;\n }\n ${host}[hidden], ${host} [hidden] { display: none !important; }\n`;\nconst shadowStructure = unsafeCSS(structuralRules(':host'));\n\nlet instances = 0;\n\n/**\n * A labelled list of keywords or subjects that wraps: each tag a link (for example a search\n * for that term) or plain text. Link tags are outlined pills in the link colour; plain tags\n * are filled chips (the card chip's colours), so a link never looks like a label. Every tag\n * and the toggle are at least 2rem (34px) tall and wide, 0.5rem apart.\n *\n * Give the tags as children: `<a href>` for a link, any other element (`<span>`) for plain\n * text. A child's `lang` and `dir` are kept, and so is inline markup inside it (`em`, `cite`,\n * `abbr`, `bdi`, a `span lang`…), copied element by element (never parsed as HTML). Or set\n * `href-template` (with `{tag}`, replaced by the URL-encoded text) to make every tag without\n * its own href a link; a blank href counts as none. Apps can set the `items` property\n * (`{ label, href?, lang?, dir? }`) instead; it wins over the children. Children with no text\n * are skipped with one warning.\n *\n * `label` names the list (shown above it, or visually hidden with `hide-label`); without one\n * a console warning is logged. `limit` shows that many tags and a “Show all N” button\n * (`aria-expanded`, `aria-controls`), which reveals the rest in place and keeps focus. Pages\n * can style the list while every tag is shown with `:state(expanded)`.\n *\n * Analytics never sends a tag's text (record tags can be user-submitted or machine-made), and\n * by default not the label either, which a template may fill from a record: the name is the\n * list's place among the tag lists on the page, `list N`. Add `track-label` when the label is\n * fixed text the page author wrote (“Subjects”), to send it instead.\n *\n * @tagname uvalib-tag-list\n * @fires uvalib-analytics-event - For `<site-analytics>`: a primary-button click on a tag link, `['uvalib-tag-list', 'tag-click', '<name>', <n>]` (n from 1, the tag's place in the list), and the toggle, `['uvalib-tag-list', 'show-all'|'show-fewer', '<name>']`. The name is `list N` (N from 1, the list's place among the tag lists in its document or shadow root), or with `track-label` the list's `label`; never the tag text or URL. Bubbles and is composed.\n * @fires uvalib-tag-list-navigate - A plain click on a tag link: `detail` is `{ href, tag, index }` (index from 0). Cancel it (`preventDefault()`) to route in the app; the click's default is then prevented. Bubbles and is composed.\n * @cssstate expanded - Show all was pressed: every tag is shown (the toggle's `aria-expanded=\"true\"`).\n * @cssprop [--uva-blue-alt-300=#BFE7F7] - Plain tag background (the card chip's).\n * @cssprop [--uva-blue-alt-dark=#005679] - Plain tag text.\n * @cssprop --uva-color-link - Dark-mode role token: link tag text (else `--uva-brand-blue`).\n * @cssprop --uva-color-control-border - Dark-mode role token: link tag outline (else `--uva-grey`).\n * @cssprop --uva-color-text - Dark-mode role token: the label (else `--uva-grey-darkest`).\n * @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).\n */\nexport class UvalibTagList extends UvalibElement {\n static styles = [\n accessible,\n shadowStructure,\n css`\n :host {\n color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));\n }\n .label {\n display: block;\n margin-block-end: 0.5rem;\n font-weight: 600;\n }\n .tag {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n max-width: 100%;\n min-height: 2rem;\n min-width: 2rem;\n padding: 0.15rem 0.7rem;\n border: 1px solid transparent;\n border-radius: 999px;\n font-size: 0.875rem;\n line-height: 1.4;\n overflow-wrap: anywhere;\n }\n span.tag {\n background: var(--uva-blue-alt-300, #bfe7f7);\n color: var(--uva-blue-alt-dark, #005679);\n }\n a.tag {\n border-color: var(--uva-color-control-border, var(--uva-grey, #808080));\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n text-decoration: none;\n }\n a.tag:hover {\n border-color: currentColor;\n text-decoration: underline;\n }\n .toggle {\n min-height: 2rem;\n min-width: 2rem;\n padding: 0.15rem 0.35rem;\n border: 0;\n background: none;\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n font: inherit;\n font-size: 0.875rem;\n text-decoration: underline;\n cursor: pointer;\n }\n @media (forced-colors: active) {\n span.tag {\n border-color: CanvasText;\n }\n a.tag {\n border-color: LinkText;\n color: LinkText;\n }\n .toggle {\n color: ButtonText;\n }\n }\n `,\n ];\n\n /** The list's name: shown above the tags (and, with `track-label`, the analytics name). */\n @property({ type: String }) label = '';\n\n /** Hide the label visually; it still names the list. */\n @property({ type: Boolean, attribute: 'hide-label' }) hideLabel = false;\n\n /**\n * Send the label as the analytics name. Only for fixed text the page author wrote, never a\n * label filled from a record. Without it the name is `list N`.\n */\n @property({ type: Boolean, attribute: 'track-label' }) trackLabel = false;\n\n /** Show this many tags and a “Show all N” button. Zero or empty shows every tag. */\n @property({ type: Number }) limit?: number;\n\n /**\n * Href for tags without their own, with `{tag}` where the URL-encoded text goes, for\n * example `/search?q={tag}`. Empty: such tags are plain text.\n */\n @property({ type: String, attribute: 'href-template' }) hrefTemplate = '';\n\n /** The tags as data (`{ label, href?, lang?, dir? }`), for apps. Wins over the children while set. */\n @property({ attribute: false }) items?: TagItem[];\n\n /** Whether every tag is shown (after Show all). */\n @state() private expanded = false;\n /** The tags read from the children. */\n @state() private childTags: Tag[] = [];\n\n private readonly uid = `uvalib-tag-list-${++instances}`;\n private warned = new Set<string>();\n private readonly internals = attachStateInternals(this);\n\n constructor() {\n super();\n // Light DOM: the children move to a hidden holder before every render, also when the\n // element is connected, moved or reconnected before its first update.\n new SourceChildren(\n this,\n () => this.lightDom,\n (nodes) => this.read(nodes),\n );\n }\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n const root = super.createRenderRoot();\n if (root instanceof ShadowRoot && this.noStyle) {\n const sheet = shadowStructure.styleSheet;\n if (sheet) root.adoptedStyleSheets = [sheet];\n }\n return root;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n if (this.lightDom && this.noStyle) {\n const node = this.getRootNode();\n installLightDomStyles(\n `${this.localName}::structure`,\n unsafeCSS(structuralRules(this.localName)),\n {\n root: node instanceof ShadowRoot || node instanceof Document ? node : undefined,\n scope: false,\n },\n );\n }\n }\n\n protected override firstUpdated(): void {\n if (!normalize(this.label))\n this.warnOnce('label', 'set label to name the list (for example “Subjects”).');\n }\n\n protected override willUpdate(changed: PropertyValues): void {\n if (changed.has('items') && this.items?.some((i) => !normalize(i?.label)))\n this.warnOnce('text', 'ignoring tags with no text.');\n }\n\n private warnOnce(key: string, message: string): void {\n if (this.warned.has(key)) return;\n this.warned.add(key);\n console.warn(`${this.localName}: ${message}`);\n }\n\n /** Read the tags from the source children. */\n private read(nodes: Node[]): void {\n const tags: Tag[] = [];\n let invalid = false;\n for (const n of nodes) {\n if (n.nodeType === Node.TEXT_NODE) {\n if (normalize(n.textContent)) invalid = true;\n continue;\n }\n if (!(n instanceof Element)) continue;\n const label = normalize(n.textContent);\n if (!label) {\n invalid = true;\n continue;\n }\n const tag: Tag = { label, ...langDir(n) };\n const href = n instanceof HTMLAnchorElement ? hrefOf(n.getAttribute('href')) : undefined;\n if (href !== undefined) tag.href = href;\n const copy = inlineCopy(n.childNodes, this.ownerDocument);\n if (copy.rich) {\n tag.rich = copy.key;\n tag.nodes = copy.nodes;\n }\n tags.push(tag);\n }\n if (invalid) this.warnOnce('text', 'ignoring tags with no text.');\n if (keyOf(tags) !== keyOf(this.childTags)) this.childTags = tags;\n }\n\n private safe(href: string): boolean {\n const ok = safeHref(href, this.ownerDocument.baseURI);\n if (!ok)\n this.warnOnce(\n 'href',\n 'showing a tag as text: its href is not http(s), mailto, tel or relative.',\n );\n return ok;\n }\n\n /** What is shown: `items` while set, else the children; hrefs from the template; unsafe ones dropped. */\n private get tags(): Tag[] {\n const source: Tag[] = this.items\n ? this.items\n .filter((i) => normalize(i?.label))\n .map((i) => {\n const t: Tag = { label: normalize(i.label) };\n const href = hrefOf(i.href);\n if (href !== undefined) t.href = href;\n if (i.lang !== undefined) t.lang = i.lang;\n if (i.dir) t.dir = i.dir;\n return t;\n })\n : this.childTags;\n const template = this.hrefTemplate.trim();\n return source.map((t) => {\n const href =\n t.href ??\n (template.includes('{tag}')\n ? template.replaceAll('{tag}', encodeURIComponent(t.label))\n : undefined);\n const out: Tag = { ...t };\n if (href !== undefined && this.safe(href)) out.href = href;\n else delete out.href;\n return out;\n });\n }\n\n /** The `limit`, when it hides anything: a positive whole number. */\n private get max(): number {\n const n = Math.trunc(this.limit ?? 0);\n return Number.isFinite(n) && n > 0 ? n : 0;\n }\n\n /** The analytics name: the label with `track-label`, else `list N` (this list's place in its root). */\n private get name(): string {\n const label = normalize(this.label);\n if (this.trackLabel && label) return label;\n const root = this.getRootNode() as Document | ShadowRoot;\n const lists = root.querySelectorAll ? [...root.querySelectorAll(this.localName)] : [];\n const i = lists.indexOf(this);\n return `list ${i < 0 ? 1 : i + 1}`;\n }\n\n private onClick(e: MouseEvent): void {\n const node = e.target instanceof Node ? e.target : null;\n const el = node instanceof Element ? node : node?.parentElement;\n const a = el?.closest('a[href]');\n if (!(a instanceof HTMLAnchorElement) || !this.renderRoot.contains(a)) return;\n if (e.defaultPrevented || e.button !== 0) return;\n const index = Number(a.dataset.index);\n trackEvent(this, ['uvalib-tag-list', 'tag-click', this.name, index + 1]);\n if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;\n const go = new CustomEvent('uvalib-tag-list-navigate', {\n detail: { href: a.getAttribute('href'), tag: normalize(a.textContent), index },\n bubbles: true,\n composed: true,\n cancelable: true,\n });\n if (!this.dispatchEvent(go)) e.preventDefault();\n }\n\n private toggle(): void {\n this.expanded = !this.expanded;\n trackEvent(this, ['uvalib-tag-list', this.expanded ? 'show-all' : 'show-fewer', this.name]);\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n const tags = this.tags;\n this.toggleAttribute('data-empty', !tags.length);\n const max = this.max;\n setState(this.internals, 'expanded', this.expanded && max > 0 && tags.length > max);\n }\n\n private renderTag(t: Tag, i: number) {\n const text = t.nodes ? t.nodes.map((n) => n.cloneNode(true)) : t.label;\n return t.href !== undefined\n ? html`<a\n class=\"tag\"\n href=${t.href}\n data-index=${i}\n lang=${t.lang ?? nothing}\n dir=${t.dir ?? nothing}\n >${text}</a\n >`\n : html`<span class=\"tag\" lang=${t.lang ?? nothing} dir=${t.dir ?? nothing}>${text}</span>`;\n }\n\n protected override render() {\n const tags = this.tags;\n const max = this.max;\n const collapsible = max > 0 && tags.length > max;\n const label = normalize(this.label);\n const labelId = `${this.uid}-label`;\n const listId = `${this.uid}-list`;\n const toggleText = this.expanded ? 'Show fewer' : `Show all ${tags.length}`;\n // One wrapper, always rendered.\n return html`<div class=\"tag-list\" ?hidden=${!tags.length}>\n ${\n label\n ? html`<span id=${labelId} class=${this.hideLabel ? 'label visually-hidden' : 'label'}\n >${label}</span\n >`\n : nothing\n }\n <ul\n role=\"list\"\n id=${listId}\n aria-labelledby=${label ? labelId : nothing}\n @click=${this.onClick}\n >\n ${tags.map(\n (t, i) =>\n html`<li role=\"listitem\" ?hidden=${collapsible && !this.expanded && i >= max}>\n ${this.renderTag(t, i)}\n </li>`,\n )}\n </ul>\n ${\n collapsible\n ? html`<button\n type=\"button\"\n class=\"toggle\"\n aria-expanded=${this.expanded ? 'true' : 'false'}\n aria-controls=${listId}\n @click=${this.toggle}\n >\n ${toggleText}${label ? html`<span class=\"visually-hidden\"> ${label}</span>` : nothing}\n </button>`\n : nothing\n }\n </div>`;\n }\n}\n","import { define } from '../../base/define.js';\nimport { UvalibTagList } from './UvalibTagList.js';\n\ndefine('uvalib-tag-list', UvalibTagList);\n"],"mappings":";;;;;;;AAyBA,IAAMuB,KAAS,MACb,KAAK,UAAUC,IAAO,GAAG,MAAgBC,MAAM,UAAU,KAAA,IAAYC,CAAE,GAGnEC,KAAU,MACJC,GAAG,KAAK,KACH,KAAA,GAQXC,KAAmB,MAAiB;IACtCC,EAAK;IACLA,EAAK;;;;;;;;IAQLA,EAAK;IACLA,EAAK;;;;;;;;IAQLA,EAAK;IACLA,EAAK;;;;;;;;;;;IAWLA,EAAK,YAAYA,EAAK;GAEpBC,IAAkB/B,EAAU6B,EAAgB,OAAO,CAAC,GAEtDG,IAAY,GAqCHC,IAAb,cAAmCpB,EAAc;;EAC/B,KAAA,SAAA;GACdS;GACAS;GACA,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8DL;;CAmCA,cAAc;EAIZ,AAHA,MAAM,GAjC4B,KAAA,QAAA,IAG8B,KAAA,YAAA,IAME,KAAA,aAAA,IASG,KAAA,eAAA,IAM3C,KAAA,WAAA,IAEQ,KAAA,YAAA,CAAC,GAEd,KAAA,MAAA,mBAAmB,EAAEC,KAC3B,KAAA,yBAAA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AKH,EAAI;gBACzE,KAAK,UAAUL,GAAG,CAAC,EAAE;kBAE7B,EAAE;;QAGFQ,IACI,CAAI;;;8BAGc,KAAK,WAAW,SAAS,QAAQ;8BACjCE,EAAO;uBACd,KAAK,OAAO;;gBAEnBC,IAAalB,IAAQ,CAAI,kCAAkCA,EAAM,WAAWzC,EAAQ;yBAExFA,EACL;;CAEL;AACF;;AAhQGC,EAAA,CAAAC,EAAS,EAAE,MAAM,OAAO,CAAC,CAAA,GAAA8B,EAAA,WAAA,SAAA,KAAA,CAAA,GAGzB/B,EAAA,CAAAC,EAAS;CAAE,MAAM;CAAS,WAAW;AAAa,CAAC,CAAA,GAAA8B,EAAA,WAAA,aAAA,KAAA,CAAA,GAMnD/B,EAAA,CAAAC,EAAS;CAAE,MAAM;CAAS,WAAW;AAAc,CAAC,CAAA,GAAA8B,EAAA,WAAA,cAAA,KAAA,CAAA,GAGpD/B,EAAA,CAAAC,EAAS,EAAE,MAAM,OAAO,CAAC,CAAA,GAAA8B,EAAA,WAAA,SAAA,KAAA,CAAA,GAMzB/B,EAAA,CAAAC,EAAS;CAAE,MAAM;CAAQ,WAAW;AAAgB,CAAC,CAAA,GAAA8B,EAAA,WAAA,gBAAA,KAAA,CAAA,GAGrD/B,EAAA,CAAAC,EAAS,EAAE,WAAW,GAAM,CAAC,CAAA,GAAA8B,EAAA,WAAA,SAAA,KAAA,CAAA,GAG7B/B,EAAA,CAAAE,EAAM,CAAA,GAAA6B,EAAA,WAAA,YAAA,KAAA,CAAA,GAEN/B,EAAA,CAAAE,EAAM,CAAA,GAAA6B,EAAA,WAAA,aAAA,KAAA,CAAA,GC3MTxB,EAAO,mBAAmBwB,CAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uvalib/web-components",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "UVA Library reusable web components",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -76,6 +76,7 @@ Theme only through the documented surface, never by reaching into internals:
76
76
 
77
77
  - Inherited `--uva-*` custom properties (colors such as `--uva-brand-blue`, `--uva-brand-orange`; `--uva-font-family`, `--uva-font-size-base`). Set them on `:root` or an ancestor of `<site-page>`. The full set is in `tokens.css`; per-component ones are in reference/components.md. Prefer the library's values; override only with a stated reason.
78
78
  - `::part()` in shadow mode. On a page, use `site-page::part(header)`, `site-page::part(footer)` and `site-page::part(main)` (`<site-page>` re-exports the header and footer parts; `site-header::part(header)` cannot reach through its shadow root). For a standalone `<site-header>` or `<site-footer>` use `site-header::part(header)` / `site-footer::part(footer)`. In light mode there are no shadow parts; style the elements with ordinary selectors.
79
+ - Custom states for runtime state, in shadow and light mode: `uvalib-combobox:state(open)`, `:state(invalid)`, `:state(loading)`; `uvalib-filter-drawer:state(modal)` (phone layout), `:state(open)`; `uvalib-lightbox:state(open)`; `uvalib-tag-list:state(expanded)`. Style them; never add or watch attributes for that state (there are none) or set it yourself (a page cannot). Browsers without custom states just never match.
79
80
  - Never pierce shadow roots with JS, depend on internal class names, or use `!important` to fight the chrome.
80
81
 
81
82
  ### Dark mode (opt-in)
@@ -594,10 +595,10 @@ A static site (11ty, Jekyll, a generated collection) that searches with [Pagefin
594
595
  For a results list of your own (a collection, a Virgo-like listing, a photo archive), use these instead of hand-made pills, counts and spinners. Classes are in `base.css`; the two elements load from `uvalib-tag-list.js` and `uvalib-results-count.js`.
595
596
 
596
597
  - Badges: `.uvalib-badge` (neutral) with `--category` (the card chip), `--count` (on media, inside `.uvalib-media`; several in `.uvalib-media__badges`), `--status` plus `--success` / `--warning` / `--danger` / `--info`, `--new`, and `--body` for body size. A status badge always says its state in words; an icon in it gets `aria-hidden="true"`. Inside `<uvalib-card>` use its `badge` and `chip` slots instead.
597
- - Toolbar: `.uvalib-toolbar` around `.uvalib-toolbar__field` (label over control; `--grow` takes the spare width), `.uvalib-toolbar__group` (`role="group"` with an `aria-label`, `.uvalib-button` toggles with `aria-pressed`) and `.uvalib-toolbar__summary`. It stacks on phones.
598
+ - Toolbar: `.uvalib-toolbar` around `.uvalib-toolbar__field` (label over control; `--grow` takes the spare width), `.uvalib-toolbar__group` (`role="group"` with an `aria-label`, `.uvalib-button` toggles with `aria-pressed`) and `.uvalib-toolbar__summary`. It stacks when it is itself 30em wide or less (a phone, a sidebar, a drawer): toolbar, result list and photo grid follow their own width (CSS size containers), so give one a width in a shrink-to-fit box.
598
599
  - `<uvalib-results-count shown total noun singular>`: the visible “Showing 48 of 3,694 shoots”, announced politely once it settles (1 s); never the first render, but the first count after an empty one (data loading) is. Leave `shown`/`total` unset while loading. Set `shown` and `total` after every filter change; do not add your own live region for the count. Not beside `<bento-box>` or `<uvalib-pagefind-search>`, which announce their own.
599
600
  - `<uvalib-tag-list label="Subjects" track-label limit="8" href-template="/search?q={tag}">` with `<a href>` or `<span>` children (or `items`): links are outlined pills, plain tags filled chips; a child's `lang`/`dir` and inline markup are kept; `limit` adds “Show all N”. Always set `label` (`hide-label` hides it visually). It reports tag clicks as `list N` and the tag's position, never the tag text; add `track-label` only when the label is fixed text you wrote, never one filled from a record.
600
- - Long result sets (hundreds or thousands of rows): `<ul class="uvalib-result-list">` of `<li class="uvalib-result">` rows holding `__meta` (badges, date), `__title` (the row's one link), `__snippet` (search terms in `<mark>`, drawn bold on `--uva-color-highlight`) and `__actions` (secondary buttons, each with a unique visually hidden name). Plain HTML, never a `<uvalib-card>` per row; rows skip rendering off screen (`content-visibility: auto`). A heading and a list per group for date order.
601
+ - Long result sets (hundreds or thousands of rows): `<ul class="uvalib-result-list">` of `<li class="uvalib-result">` rows holding `__meta` (badges, date), `__title` (the row's one link), `__snippet` (search terms in `<mark>`, drawn bold on `--uva-color-highlight`) and `__actions` (secondary buttons, each with a unique visually hidden name). Plain HTML, never a `<uvalib-card>` per row; rows skip rendering off screen (`content-visibility: auto`); the actions wrap below when the list itself is 40em or narrower. A heading and a list per group for date order.
601
602
  - No results: `.uvalib-empty-state` (decorative `__icon`, a heading, a sentence, one action). Loading: `.uvalib-skeleton` (give it a height, or `--media` for 3:2) and `.uvalib-skeleton-text` (one line), sized like what replaces them, inside an `aria-hidden="true"` container, with `aria-busy="true"` on the region while it loads.
602
603
 
603
604
  ```html snippet
@@ -719,11 +720,12 @@ Use these instead of a hand-built gallery or a carousel. There is no autoplay.
719
720
 
720
721
  - `<uvalib-lightbox>` from `uvalib-lightbox.js`: progressive enhancement over plain links. Wrap them (`<a href="full.jpg" data-caption="Page 2"><img alt="Page 2" width="1600" height="2000"></a>`), or point at links elsewhere with `selector="a.pb-image"`. Without JavaScript, and on a modified click, the link opens the image as before. A primary click opens a native `<dialog>` (`showModal()`): the caption names it, Close takes focus, focus returns to the trigger, Escape and the backdrop close it. With more than one image, Previous and Next and the arrow keys move through the set (wrapping; Left is previous in left-to-right), with a polite "3 of 13". Full size opens the original image in a new tab and says so in its accessible name. It is offered for an http(s) URL or a PNG, JPEG, GIF or WebP `data:` image, never an SVG `data:` URL. A IIIF Image API URL keeps its region and only the size becomes `!W,H` for the viewport; TIFF and JPEG2000 URLs are left as written. Full size stays the original href.
721
722
  - `url-param="photo"` keeps `?photo=<id>` in sync (the id is `data-id`, else `id`, else the IIIF identifier, else the position from 1): opening pushes a history entry, stepping replaces it, Back closes. On a hash route the parameter is written inside the hash. Opening from a URL that already has it is not an analytics event. With `spa="auto"`, that opening push may count as one Matomo page view.
722
- - Details: a child with `slot="details"` (`data-for` selects one item by id or position from 1; without it the details show for every image), or `data-details-id` on a link naming an element elsewhere. It is put back when the viewer moves on or closes.
723
+ - Details: a child with `slot="details"` (`data-for` selects one item by id or position from 1; without it the details show for every image), or `data-details-id` on a link naming an element elsewhere (it stays in the page, slotted in shadow mode, so ids, CSS and listeners keep working; late ones are shown). It is put back when the viewer moves on or closes.
724
+ - From the page: `open(idOrIndex)` (false if unknown) and `close({ focus })` (after deleting the open item; focus your heading); `uvalib-lightbox-open` (`{ id, index, restored }`) and `uvalib-lightbox-close` (`{ id, index, reason }`) report both. Never click the dialog's own Close.
723
725
  - `<uvalib-image-regions>` from `uvalib-image-regions.js`: numbered outlines on an image (people, objects, inscriptions) with a list of the same regions beside it. Write the page's own `<img width height alt>` and `<ol>` inside, each `<li data-xywh="percent:x,y,w,h">` (or pixels of the natural size, `160,120,320,240`; `image-width`/`image-height` for a IIIF derivative) holding the region's link and your own action buttons, which stay yours; or set `items` (`{ label, x, y, w, h, unit?, href?, description? }[]`). The list is the accessible route: the outlines are `aria-hidden`, not tab stops, and never the only place a name or action is; hovering or focusing an entry highlights its outline (thicker double outline and label) and back, and clicking an outline focuses its entry. `label` names the list. Listen for `uvalib-image-regions-activate` (an outline clicked, before its entry takes focus; `detail: { index, item, entry }`, `entry` the page's own `<li>`; cancelable, so the page can focus its own control in the entry, such as a "Who is this?" field) and `highlight`; never read the shadow DOM's outlines for it. Do not hand-build absolutely positioned outlines. It reports outline clicks itself (the list's label and the number, never a region's label).
724
- - Regions in the viewer: `data-regions` on a lightbox link (a JSON array, or `percent:10,20,30,40 Person 1; percent:55,15,20,30 Sign`), or the lightbox's `regions` callback (`({ element, id, href, index }) => regions`). The open image then shows the outlines, their list and a "Show regions" toggle; `regions-label` names the list. For your own buttons in each entry, `data-regions-list="<id>"` (or the `regionsList` callback) names a hidden `<ol>` of `<li data-xywh>` in the page: it is lent to the viewer (same nodes, your listeners and CSS keep working) and put back on close; give each action a unique name ("Confirm Tim Kaine").
725
- - Versions in the viewer: `data-versions='[{"label":"Original"},{"label":"AI colorization","href":"color.jpg","note":"The colours are an AI model’s guess."}]'` on a lightbox link (first entry = the link's image; or the `versions` callback) compares them over the photo, the comparison loaded on first use: Switch (default), Reveal (`compare="wipe"`, a divider: click the photo or the slider) or Fade; label AI versions as such and give them a `note`; `version-param` (with `url-param`) keeps `?version=wipe:40`; `uvalib-lightbox-version` reports changes.
726
- - `<uvalib-photo-grid>` from `uvalib-photo-grid.js`: justified rows. Each direct `<a href>` or `<button>` is one photo and stays a real control. The row is about 220px, and 140px at 767px and below, unless `row-height` is set (a bare number is pixels). Give each image `width` and `height` so the row does not jump when it loads. An image with no visible text gets a caption from its alt, and a repeated alt is cleared (the original is kept for a lightbox). A different alt is kept. Do not set an `aria-label` that differs from the visible text; the grid will not add a caption beside one. Generated "Photo N" captions renumber when the photos change order. A `<span slot="badge">` inside the item, or `data-badge` on it (“seq”, “3 photos”), is drawn over the thumbnail and stays in the accessible name; an existing `aria-label` gains the badge text. A grid inside a lightbox opens the viewer. The grid reports no analytics.
726
+ - Regions in the viewer: `data-regions` on a lightbox link (a JSON array, or `percent:10,20,30,40 Person 1; percent:55,15,20,30 Sign`), or the lightbox's `regions` callback (`({ element, id, href, index }) => regions`). The open image then shows the outlines, their list and a "Show regions" toggle; `regions-label` names the list. For your own buttons in each entry, `data-regions-list="<id>"` (or the `regionsList` callback) names a hidden `<ol>` of `<li data-xywh>` in the page: it is lent to the viewer (same nodes, your listeners and CSS keep working) and put back on close; give each action a unique name ("Confirm Tim Kaine"). In React, create that `<ol>` (and a details element) outside React and make it the `createPortal` target for the entries, never render it inside a portal (README "React and other frameworks").
727
+ - Versions in the viewer: `data-versions='[{"label":"Original"},{"label":"AI colorization","href":"color.jpg","note":"The colours are an AI model’s guess."}]'` on a lightbox link (first entry = the link's image; or the `versions` callback) compares them over the photo, the comparison loaded on first use: Switch (default), Reveal (`compare="wipe"`, a divider: click the photo or the slider) or Fade; label AI versions as such and give them a `note`; a version with a different framing (AI-expanded frame, whole plate, crop) gives `"frame": "percent:x,y,w,h"` (the original's box in it; pixels need its `width`/`height`) and is drawn at the original's scale around it (a crop's frame goes past it: `percent:-25,-25,150,150`); `data-version="1"` (the `version-param` format) opens a link on that version, the original still first; `version-param` (with `url-param`) keeps `?version=wipe:40`; `uvalib-lightbox-version` reports changes.
728
+ - `<uvalib-photo-grid>` from `uvalib-photo-grid.js`: justified rows. Each direct `<a href>` or `<button>` is one photo and stays a real control. The row is about 220px, and 140px when the grid itself is under 48rem (also in a sidebar), unless `row-height` is set (a bare number is pixels). Give each image `width` and `height` so the row does not jump when it loads. An image with no visible text gets a caption from its alt, and a repeated alt is cleared (the original is kept for a lightbox). A different alt is kept. Do not set an `aria-label` that differs from the visible text; the grid will not add a caption beside one. Generated "Photo N" captions renumber when the photos change order. A `<span slot="badge">` inside the item, or `data-badge` on it (“seq”, “3 photos”), is drawn over the thumbnail and stays in the accessible name; an existing `aria-label` gains the badge text. A grid inside a lightbox opens the viewer. The grid reports no analytics.
727
729
 
728
730
  ```html snippet
729
731
  <!doctype html>
@@ -775,7 +775,7 @@ A row of chips: a segmented control or single-select filter (`mode="single"`), f
775
775
 
776
776
  ## `<uvalib-combobox>`
777
777
 
778
- An editable text field that suggests values as you type, from a local list or a URL: a person, place or subject picker. It follows the WAI-ARIA APG “Editable Combobox With List Autocomplete”: a real `<input role="combobox">` and a `role="listbox"` popup under it. Suggestions come from the `items` property (`{ value, label?, description?, disabled? }` objects, or strings), from `<option>` children (directly or inside a `<datalist>`; the `label` attribute or text is the label, `data-description` the second line), or from `src`, a URL template with `{q}` (fetched 250 ms after the last keystroke once the text has `min-length` characters, default 1; a newer keystroke aborts the older request; the response is a JSON array of the same shape, or anything `transform(data, query)` turns into one). `items` wins over the children while set. Local suggestions match anywhere in the label, ignoring case and accents, those starting with the text first, then those with a word starting with it; at most `max-results` (default 50, 0 for all) are shown, which keeps a list of 16,000 people fast. The matched text is bold and underlined in a `<mark>`. Keys: Down opens the list on the first suggestion and moves (wrapping), Up opens on the last, Alt+Down opens without moving, Alt+Up closes, Enter chooses the active suggestion (and then does not submit the form; with none active, Enter submits as in any field), Escape closes the list and a second Escape clears the field, Home, End, Left and Right move the caret, and Tab leaves without choosing. A real clear button (“Clear <label>”, 44px, shown only with text) empties the field and returns focus to it. Free text is allowed: `value` is whatever is in the field, and `selected` the chosen suggestion (or null); typing after choosing clears it, and leaving the field with text that is exactly one suggestion's label chooses it. `must-choose` makes any other text invalid (“Choose one of the suggestions.”). The element is form-associated: with `name` it submits the chosen suggestion's value, or else the text, and a form reset restores the `value` attribute. `required` and `disabled` (also from a disabled fieldset) work as on an input. A polite status says “5 suggestions”, “50 of 1,234 suggestions”, “No suggestions”, “Loading suggestions” or “Couldn't load suggestions” half a second after the list settles (never on the first render); the popup shows the same notes visibly. A failed load never throws. Before it upgrades, `base.css` shows the label (from the attribute) and holds the field's height. A fallback `<input list>` child works as a plain field meanwhile; on upgrade its text, `name` and `placeholder` carry over, and it is disabled so it does not submit twice.
778
+ An editable text field that suggests values as you type, from a local list or a URL: a person, place or subject picker. It follows the WAI-ARIA APG “Editable Combobox With List Autocomplete”: a real `<input role="combobox">` and a `role="listbox"` popup under it. Suggestions come from the `items` property (`{ value, label?, description?, disabled? }` objects, or strings), from `<option>` children (directly or inside a `<datalist>`; the `label` attribute or text is the label, `data-description` the second line), or from `src`, a URL template with `{q}` (fetched 250 ms after the last keystroke once the text has `min-length` characters, default 1; a newer keystroke aborts the older request; the response is a JSON array of the same shape, or anything `transform(data, query)` turns into one). `items` wins over the children while set. Local suggestions match anywhere in the label, ignoring case and accents, those starting with the text first, then those with a word starting with it; at most `max-results` (default 50, 0 for all) are shown, which keeps a list of 16,000 people fast. The matched text is bold and underlined in a `<mark>`. Keys: Down opens the list on the first suggestion and moves (wrapping), Up opens on the last, Alt+Down opens without moving, Alt+Up closes, Enter chooses the active suggestion (and then does not submit the form; with none active, Enter submits as in any field), Escape closes the list and a second Escape clears the field, Home, End, Left and Right move the caret, and Tab leaves without choosing. A real clear button (“Clear <label>”, 44px, shown only with text) empties the field and returns focus to it. Free text is allowed: `value` is whatever is in the field, and `selected` the chosen suggestion (or null); typing after choosing clears it, and leaving the field with text that is exactly one suggestion's label chooses it. `must-choose` makes any other text invalid (“Choose one of the suggestions.”). The element is form-associated: with `name` it submits the chosen suggestion's value, or else the text, and a form reset restores the `value` attribute. `required` and `disabled` (also from a disabled fieldset) work as on an input. A polite status says “5 suggestions”, “50 of 1,234 suggestions”, “No suggestions”, “Loading suggestions” or “Couldn't load suggestions” half a second after the list settles (never on the first render); the popup shows the same notes visibly. A failed load never throws. Where the browser supports the Popover API and CSS anchor positioning, the popup is a manual popover in the top layer, anchored under the field and as wide as it (above it when there is no room below), so an ancestor with `overflow: hidden` or a scrolling panel never clips it. Elsewhere it is positioned under the field inside the element, as before. Pages can style the runtime state with `:state(open)`, `:state(invalid)` and `:state(loading)` (no attributes are added). Before it upgrades, `base.css` shows the label (from the attribute) and holds the field's height. A fallback `<input list>` child works as a plain field meanwhile; on upgrade its text, `name` and `placeholder` carry over, and it is disabled so it does not submit twice.
779
779
 
780
780
  ### Attributes
781
781
 
@@ -806,6 +806,14 @@ An editable text field that suggests values as you type, from a local list or a
806
806
  | `option` | Each suggestion. |
807
807
  | `description` | The hint under the field. |
808
808
 
809
+ ### CSS states
810
+
811
+ | State | Description |
812
+ |---|---|
813
+ | `:state(open)` | The popup is showing (suggestions or a note such as “No suggestions”). |
814
+ | `:state(invalid)` | The text was shown as invalid (`aria-invalid="true"`: `must-choose` text that is not a suggestion, after leaving the field or pressing Enter). |
815
+ | `:state(loading)` | Suggestions from `src` are loading. |
816
+
809
817
  ### Events
810
818
 
811
819
  | Event | Description |
@@ -1022,7 +1030,7 @@ A faceted-search filter: a fieldset of checkboxes (value plus result count), opt
1022
1030
 
1023
1031
  ## `<uvalib-filter-drawer>`
1024
1032
 
1025
- A search page's form and filters: a plain sidebar on wide screens, and on narrow ones a “Search and filters” button that opens them in a modal panel from the side. Put the page's search form, `<uvalib-filter>`s and other facets inside. Above `breakpoint` (default `48rem`) they are shown as written: no button, no dialog role. At and below it only the button is shown; it opens a native `<dialog>` (`showModal()`) with a visible heading (the `label`) and a 44px Close button, which takes focus. Escape, Close and a click on the backdrop close it, and focus returns to the button; widening the window past the breakpoint closes it and keeps focus where it was. While it is open the rest of the page, including `<site-page>`'s header, skip link and alerts, is inert (the browser's modal dialog), so focus cannot leave it except to the browser itself, and nothing else is announced. The children are the same nodes in both layouts (moved, never re-created): typed text, checked boxes, listeners and each filter's state are kept. Inert content is not announced, so results counts and status notices outside the panel would go silent while the visitor filters: name them in `live` (space-separated ids) and the drawer repeats what they announce in its own polite live region while it is open. `count` (the page's number of active filters) is shown on the button when above 0. The drawer never counts by itself: only the page knows which inputs are filters.
1033
+ A search page's form and filters: a plain sidebar on wide screens, and on narrow ones a “Search and filters” button that opens them in a modal panel from the side. Put the page's search form, `<uvalib-filter>`s and other facets inside. Above `breakpoint` (default `48rem`) they are shown as written: no button, no dialog role. At and below it only the button is shown; it opens a native `<dialog>` (`showModal()`) with a visible heading (the `label`) and a 44px Close button, which takes focus. Escape, Close and a click on the backdrop close it, and focus returns to the button; widening the window past the breakpoint closes it and keeps focus where it was. While it is open the rest of the page, including `<site-page>`'s header, skip link and alerts, is inert (the browser's modal dialog), so focus cannot leave it except to the browser itself, and nothing else is announced. The children are the same nodes in both layouts (moved, never re-created): typed text, checked boxes, listeners and each filter's state are kept. Inert content is not announced, so results counts and status notices outside the panel would go silent while the visitor filters: name them in `live` (space-separated ids) and the drawer repeats what they announce in its own polite live region while it is open. `count` (the page's number of active filters) is shown on the button when above 0. The drawer never counts by itself: only the page knows which inputs are filters. Pages can style the runtime layout with `:state(modal)` (at or below the breakpoint: the button and panel) and `:state(open)` (the panel is open).
1026
1034
 
1027
1035
  ### Attributes
1028
1036
 
@@ -1054,6 +1062,13 @@ A search page's form and filters: a plain sidebar on wide screens, and on narrow
1054
1062
  | `close` | The Close button. |
1055
1063
  | `body` | The wrapper of the children, in the sidebar or the panel. |
1056
1064
 
1065
+ ### CSS states
1066
+
1067
+ | State | Description |
1068
+ |---|---|
1069
+ | `:state(modal)` | The viewport is at or below the breakpoint: the button and panel, not the sidebar. |
1070
+ | `:state(open)` | The panel is open. |
1071
+
1057
1072
  ### Events
1058
1073
 
1059
1074
  | Event | Description |
@@ -1132,10 +1147,11 @@ An image with numbered region outlines (people, objects, inscriptions) and a lis
1132
1147
  | `--uva-color-link` | | Dark-mode role token: entry links (else `--uva-brand-blue`). |
1133
1148
  | `--uva-color-focus` | | Dark-mode role token: focus ring (else `--uva-brand-orange`). |
1134
1149
  | `--uva-color-text-muted` | | Dark-mode role token: descriptions (else #4b5563). |
1150
+ | `--uvalib-image-regions-inset` | | Where the outlines sit inside the image slot (an `inset` value, default 0): set by `<uvalib-lightbox>` when the slot holds versions with a wider framing, so the outlines stay on the original. |
1135
1151
 
1136
1152
  ## `<uvalib-lightbox>`
1137
1153
 
1138
- An accessible image viewer over a set of plain links. With JavaScript a primary click opens a modal dialog; without it (or with a modified click) the link opens the image as before. Wrap the links, or point at them with `selector` (for example `a.pb-image` on a reading page). There is no autoplay and no carousel. The dialog is labelled by the caption (`data-caption`, else the image alt, else the link text). Focus moves to Close on open and back to the trigger on close. Escape and a click on the backdrop close it. With more than one image, Previous and Next and the arrow keys move through the set (wrapping), and a polite “3 of 13” counter is shown. Full size opens the original image in a new tab. A IIIF Image API URL keeps its region; only the size becomes `!W,H` for the viewport. TIFF and JPEG2000 URLs are left as written. `url-param` (for example `photo`) keeps `?photo=<id>` in sync, including on a hash route (`#/text?photo=<id>`): opening pushes a history entry, stepping replaces it, and Back closes. Optional details: children with `slot="details"` (and `data-for` equal to the item's id or its position from 1; without `data-for` they show for every image), or `data-details-id` on a link pointing at an element elsewhere on the page. Either is shown inside the dialog and put back when the viewer moves on or closes. Optional regions (people, objects, inscriptions): `data-regions` on a link, a JSON array of `{ label, x, y, w, h, unit? }` or `xywh` values each followed by its label, separated by `;` (`percent:10,20,30,40 Person 1; percent:55,15,20,30 Sign`), or the `regions` callback. The open image then shows numbered outlines (`<uvalib-image-regions>`, loaded on first use) and a list of the regions beside it, with a "Show regions" toggle (`aria-pressed`) that hides the outlines. Pixel regions are measured in `data-image-width` × `data-image-height` when set (the viewer shows a resized IIIF image), else in the image's natural size. Or the page's own list, with its own buttons: `data-regions-list="<id>"` on a link (or the `regionsList` callback) names an `<ol>` or `<ul>` of `<li data-xywh>` anywhere in the page, usually `hidden`. While that image is open the list (the same nodes, so the page's listeners keep working) is the region list: in shadow mode it becomes a child of the lightbox slotted into the viewer, not moved into the shadow root, so the page's CSS still applies to it. When the image changes or the viewer closes it goes back where it was, `hidden` as before. It wins over `data-regions`. Optional versions of an image (an original scan and an AI colorization, a restoration, an infrared capture): `data-versions` on a link, a JSON array of `{ label, href?, note? }` whose first entry is the link's own image, or the `versions` callback. The viewer then compares them over the photo (loaded on first use): Switch (a segmented control), Reveal (a divider: click or tap the photo, or use the slider) or Fade (a slider), `compare` choosing the first. A version's `note` shows under the photo while it is visible, and the image's accessible name ends with the label of the version shown. `version-param` (with `url-param`) keeps the comparison in the address: `?version=2` (Switch, the version from 0), `?version=wipe:40` or `?version=fade:60` (the percentage of the other version shown; `wipe:40:2` compares the original with version 2).
1154
+ An accessible image viewer over a set of plain links. With JavaScript a primary click opens a modal dialog; without it (or with a modified click) the link opens the image as before. Wrap the links, or point at them with `selector` (for example `a.pb-image` on a reading page). There is no autoplay and no carousel. The dialog is labelled by the caption (`data-caption`, else the image alt, else the link text). Focus moves to Close on open and back to the trigger on close. Escape and a click on the backdrop close it. With more than one image, Previous and Next and the arrow keys move through the set (wrapping), and a polite “3 of 13” counter is shown. Full size opens the original image in a new tab. A IIIF Image API URL keeps its region; only the size becomes `!W,H` for the viewport. TIFF and JPEG2000 URLs are left as written. `url-param` (for example `photo`) keeps `?photo=<id>` in sync, including on a hash route (`#/text?photo=<id>`): opening pushes a history entry, stepping replaces it, and Back closes. Optional details: children with `slot="details"` (and `data-for` equal to the item's id or its position from 1; without `data-for` they show for every image), or `data-details-id` on a link pointing at an element elsewhere on the page. Either is shown inside the dialog and put back exactly (same place, `hidden` and `slot`) when the viewer moves on or closes. The `data-details-id` element stays in the page (in shadow mode it becomes a child of the lightbox slotted into the dialog), so `getElementById`, the page's CSS (except selectors through its old ancestors) and listeners keep working; nothing is cloned. Details that appear while their image is open (rendered after a fetch) are shown then. `open(idOrIndex)` and `close({ focus })` let the page open or close the viewer itself; `uvalib-lightbox-open` and `uvalib-lightbox-close` say when it did. Optional regions (people, objects, inscriptions): `data-regions` on a link, a JSON array of `{ label, x, y, w, h, unit? }` or `xywh` values each followed by its label, separated by `;` (`percent:10,20,30,40 Person 1; percent:55,15,20,30 Sign`), or the `regions` callback. The open image then shows numbered outlines (`<uvalib-image-regions>`, loaded on first use) and a list of the regions beside it, with a "Show regions" toggle (`aria-pressed`) that hides the outlines. Pixel regions are measured in `data-image-width` × `data-image-height` when set (the viewer shows a resized IIIF image), else in the image's natural size. Or the page's own list, with its own buttons: `data-regions-list="<id>"` on a link (or the `regionsList` callback) names an `<ol>` or `<ul>` of `<li data-xywh>` anywhere in the page, usually `hidden`. While that image is open the list (the same nodes, so the page's listeners keep working) is the region list: in shadow mode it becomes a child of the lightbox slotted into the viewer, not moved into the shadow root, so the page's CSS still applies to it. When the image changes or the viewer closes it goes back where it was, `hidden` as before. It wins over `data-regions`. Optional versions of an image (an original scan and an AI colorization, a restoration, an infrared capture): `data-versions` on a link, a JSON array of `{ label, href?, note? }` whose first entry is the link's own image, or the `versions` callback. The viewer then compares them over the photo (loaded on first use): Switch (a segmented control), Reveal (a divider: click or tap the photo, or use the slider) or Fade (a slider), `compare` choosing the first. A version's `note` shows under the photo while it is visible, and the image's accessible name ends with the label of the version shown. `version-param` (with `url-param`) keeps the comparison in the address: `?version=2` (Switch, the version from 0), `?version=wipe:40` or `?version=fade:60` (the percentage of the other version shown; `wipe:40:2` compares the original with version 2). `data-version` on a link (the same values) opens that image on that version, from a click, `open()` or Previous and Next; an address with `version-param` wins. A version with a different framing (an AI-expanded frame, a crop, the whole plate) gives `frame`, the original's box in it (`percent:x,y,w,h`, or pixels of its `width` × `height`): the viewer draws every version at the original's scale in one box, the original lined up, and regions stay on it. Pages can style the element while the viewer is open with `:state(open)`.
1139
1155
 
1140
1156
  ### Attributes
1141
1157
 
@@ -1169,10 +1185,19 @@ An accessible image viewer over a set of plain links. With JavaScript a primary
1169
1185
  | `regions` | The `<uvalib-image-regions>` around an image with regions. |
1170
1186
  | `compare` | The version comparison controls and notes under the photo. |
1171
1187
 
1188
+ ### CSS states
1189
+
1190
+ | State | Description |
1191
+ |---|---|
1192
+ | `:state(open)` | The viewer is open. |
1193
+
1172
1194
  ### Events
1173
1195
 
1174
1196
  | Event | Description |
1175
1197
  |---|---|
1198
+ | | |
1199
+ | `uvalib-lightbox-open` | The viewer opened (a click, `open()`, or restored from the address): `detail` is `{ id, index, restored }` (`index` from 0; `restored` true for the address, Back and Forward). Not fired when it moves to another image. Bubbles and is composed. |
1200
+ | `uvalib-lightbox-close` | The viewer closed: `detail` is `{ id, index, reason }`, the image shown and `reason` `close` (Close, Escape, the backdrop), `api` (`close()`), `history` (Back or Forward) or `empty` (the last image left the page). Not fired when the element is removed. Bubbles and is composed. |
1176
1201
  | `uvalib-lightbox-version` | The visitor changed the comparison (mode, version or position; once a slider settles): `detail` is `{ id, mode, index, value }` (`mode` `switch`, `wipe` or `fade`; `index` the version shown or compared, from 0; `value` the percentage of it shown, null for Switch). Not fired on open or for a comparison restored from the URL. Bubbles and is composed. |
1177
1202
  | `uvalib-analytics-event` | For `<site-analytics>`: `['uvalib-lightbox', 'open'\|'next'\|'previous'\|'full-size', 'image N', N]` (N from 1, the image's place in the set), and `['uvalib-lightbox', 'compare', 'switch'\|'wipe'\|'fade', N]` when the visitor changes a comparison (N the version's place from 1; once a slider settles). Never the URL, the caption or a version's label. Not fired for a viewer restored from the URL or from Back and Forward. Bubbles and is composed. |
1178
1203
 
@@ -1374,13 +1399,13 @@ Previous/next section links, as on a reading page, or a numbered page list. Prev
1374
1399
 
1375
1400
  ## `<uvalib-photo-grid>`
1376
1401
 
1377
- Justified rows of thumbnails. Each direct child that is a link or a button is one photo; its image keeps its shape from the `width` and `height` attributes, or from the loaded image, so the row does not jump when the picture arrives. The row is about 220px tall and shorter on a phone; `row-height` sets that height. Every item stays a real link or button. An image with no visible text gets a visible caption from its alt (the caption is then the accessible name, and a repeated alt is cleared). The original alt is kept in `data-uvalib-alt` so a lightbox still describes the picture. An item with no name at all is captioned “Photo N” and warned about once; that caption is renumbered when the photos change order. An `aria-label` is left as the name: the grid does not add a caption that would disagree with it. Put the grid inside `<uvalib-lightbox>` and a plain click opens the viewer. A badge sits on the thumbnail: `<span slot="badge">` inside the link or button, or `data-badge` on that item (for example “seq” or “3 photos”). It is read after the caption (“The Lawn, 3 photos”). When the item already has an `aria-label`, the badge is appended to that label (the author’s words stay in `data-uvalib-label`) and an alt that repeats those words is cleared. A badge does not replace the alt caption.
1402
+ Justified rows of thumbnails. Each direct child that is a link or a button is one photo; its image keeps its shape from the `width` and `height` attributes, or from the loaded image, so the row does not jump when the picture arrives. The row is about 220px tall and shorter when the grid is narrow (a phone, a sidebar); `row-height` sets that height. Every item stays a real link or button. An image with no visible text gets a visible caption from its alt (the caption is then the accessible name, and a repeated alt is cleared). The original alt is kept in `data-uvalib-alt` so a lightbox still describes the picture. An item with no name at all is captioned “Photo N” and warned about once; that caption is renumbered when the photos change order. An `aria-label` is left as the name: the grid does not add a caption that would disagree with it. Put the grid inside `<uvalib-lightbox>` and a plain click opens the viewer. A badge sits on the thumbnail: `<span slot="badge">` inside the link or button, or `data-badge` on that item (for example “seq” or “3 photos”). It is read after the caption (“The Lawn, 3 photos”). When the item already has an `aria-label`, the badge is appended to that label (the author’s words stay in `data-uvalib-label`) and an alt that repeats those words is cleared. A badge does not replace the alt caption.
1378
1403
 
1379
1404
  ### Attributes
1380
1405
 
1381
1406
  | Attribute | Type | Default | Description |
1382
1407
  |---|---|---|---|
1383
- | `row-height` | `string` | `''` | Row height. A bare number is pixels (`220` is 220px); `px`, `rem`, `em`, `vh`, `vw`, `vmin`, `vmax`, `ch` and `%` are kept. Empty uses 220px, or 140px when the viewport is 767px or narrower. |
1408
+ | `row-height` | `string` | `''` | Row height. A bare number is pixels (`220` is 220px); `px`, `rem`, `em`, `vh`, `vw`, `vmin`, `vmax`, `ch` and `%` are kept. Empty uses 220px, or 140px when the grid itself is narrower than 48rem (a phone, a sidebar, a drawer). |
1384
1409
  | `no-shadow-dom` | `boolean` | `false` | |
1385
1410
  | `no-style` | `boolean` | `false` | |
1386
1411
 
@@ -1474,7 +1499,7 @@ Tabs, as on library.virginia.edu: a row of buttons over one visible panel. Each
1474
1499
 
1475
1500
  ## `<uvalib-tag-list>`
1476
1501
 
1477
- A labelled list of keywords or subjects that wraps: each tag a link (for example a search for that term) or plain text. Link tags are outlined pills in the link colour; plain tags are filled chips (the card chip's colours), so a link never looks like a label. Every tag and the toggle are at least 2rem (34px) tall and wide, 0.5rem apart. Give the tags as children: `<a href>` for a link, any other element (`<span>`) for plain text. A child's `lang` and `dir` are kept, and so is inline markup inside it (`em`, `cite`, `abbr`, `bdi`, a `span lang`…), copied element by element (never parsed as HTML). Or set `href-template` (with `{tag}`, replaced by the URL-encoded text) to make every tag without its own href a link; a blank href counts as none. Apps can set the `items` property (`{ label, href?, lang?, dir? }`) instead; it wins over the children. Children with no text are skipped with one warning. `label` names the list (shown above it, or visually hidden with `hide-label`); without one a console warning is logged. `limit` shows that many tags and a “Show all N” button (`aria-expanded`, `aria-controls`), which reveals the rest in place and keeps focus. Analytics never sends a tag's text (record tags can be user-submitted or machine-made), and by default not the label either, which a template may fill from a record: the name is the list's place among the tag lists on the page, `list N`. Add `track-label` when the label is fixed text the page author wrote (“Subjects”), to send it instead.
1502
+ A labelled list of keywords or subjects that wraps: each tag a link (for example a search for that term) or plain text. Link tags are outlined pills in the link colour; plain tags are filled chips (the card chip's colours), so a link never looks like a label. Every tag and the toggle are at least 2rem (34px) tall and wide, 0.5rem apart. Give the tags as children: `<a href>` for a link, any other element (`<span>`) for plain text. A child's `lang` and `dir` are kept, and so is inline markup inside it (`em`, `cite`, `abbr`, `bdi`, a `span lang`…), copied element by element (never parsed as HTML). Or set `href-template` (with `{tag}`, replaced by the URL-encoded text) to make every tag without its own href a link; a blank href counts as none. Apps can set the `items` property (`{ label, href?, lang?, dir? }`) instead; it wins over the children. Children with no text are skipped with one warning. `label` names the list (shown above it, or visually hidden with `hide-label`); without one a console warning is logged. `limit` shows that many tags and a “Show all N” button (`aria-expanded`, `aria-controls`), which reveals the rest in place and keeps focus. Pages can style the list while every tag is shown with `:state(expanded)`. Analytics never sends a tag's text (record tags can be user-submitted or machine-made), and by default not the label either, which a template may fill from a record: the name is the list's place among the tag lists on the page, `list N`. Add `track-label` when the label is fixed text the page author wrote (“Subjects”), to send it instead.
1478
1503
 
1479
1504
  ### Attributes
1480
1505
 
@@ -1488,6 +1513,12 @@ A labelled list of keywords or subjects that wraps: each tag a link (for example
1488
1513
  | `no-shadow-dom` | `boolean` | `false` | |
1489
1514
  | `no-style` | `boolean` | `false` | |
1490
1515
 
1516
+ ### CSS states
1517
+
1518
+ | State | Description |
1519
+ |---|---|
1520
+ | `:state(expanded)` | Show all was pressed: every tag is shown (the toggle's `aria-expanded="true"`). |
1521
+
1491
1522
  ### Events
1492
1523
 
1493
1524
  | Event | Description |
@@ -1 +0,0 @@
1
- {"version":3,"file":"compare-D4VdaIJN.js","names":["unsafeCSS","nothing","b","A","r","trackEvent","MODES","MODE_NAMES","compareTiming","norm","s","clamp","n","structure","h","ACCENT","LINK","look","styled","install","root","host","opts","installLightDomStyles","text","sheet","nextId","Compare","rtl","k","d","key","index","slide","restore","raw","bad","out","o","v","label","href","m","param","mode","other","i","next","announce","fn","state","el","write","a","on","stack","l0","lk","base","top","layers","visible","notes","failed","seg","pressed","onClick","switching","panel","body","switchPanel","sliding","slot"],"sources":["../../src/components/uvalib-lightbox/compare.ts"],"sourcesContent":["/**\n * Versions of an image compared over the photo: Switch, Reveal (a wipe) and Fade. Loaded by\n * `<uvalib-lightbox>` the first time an open image has versions, so pages without them never\n * load it.\n */\nimport { html, nothing, unsafeCSS } from 'lit';\nimport { trackEvent } from '../../base/analytics.js';\nimport { installLightDomStyles } from '../../base/light-dom-styles.js';\n\nexport type CompareMode = 'switch' | 'wipe' | 'fade';\n\nconst MODES: CompareMode[] = ['switch', 'wipe', 'fade'];\nconst MODE_NAMES: Record<CompareMode, string> = {\n switch: 'Switch',\n wipe: 'Reveal',\n fade: 'Fade',\n};\n\n/** How long (ms) after the last slider or drag change it counts as settled. Tests shorten it. */\nexport const compareTiming = { settle: 400 };\n\ninterface Version {\n label: string;\n href: string;\n note: string;\n}\n\n/** What the lightbox lends the comparison. */\nexport interface CompareHost {\n el: HTMLElement;\n light: boolean;\n root: Node;\n noStyle: boolean;\n /** The `compare` attribute: the first mode. */\n mode(): string;\n /** The URL the viewer would load for `href` ('' when it may not be shown). */\n size(href: string): string;\n /** Write the comparison to `version-param` (replaceState). */\n write(value: string | null): void;\n update(): void;\n}\n\n/** The parts of a lightbox slide the comparison reads. */\nexport interface CompareSlide {\n id: string;\n href: string;\n versions: string | unknown[] | null;\n}\n\nconst norm = (s: unknown) => (typeof s === 'string' ? s.replace(/\\s+/g, ' ').trim() : '');\nconst clamp = (n: number) => Math.min(100, Math.max(0, Math.round(n)));\n\n/**\n * Kept with `no-style`: the stacked layers, the clip and fade, the divider and its handle\n * (white inside black, so it shows on any photo), the side labels and the control layout.\n * `h` is `:host` (shadow) or the tag (light DOM).\n */\nconst structure = (h: string) => `\n ${h} .stack { isolation: isolate; }\n ${h} .stack > img.top {\n position: absolute; inset: 0; width: 100%; height: 100%;\n max-width: none; max-height: none; margin: 0; opacity: 0; pointer-events: none;\n }\n ${h} .stack > img.top.on { opacity: 1; }\n ${h} .compare-fade > img.top.on { opacity: var(--uvalib-compare-opacity, 1); }\n ${h} .compare-wipe > img.top.on { clip-path: inset(0 calc(100% - var(--uvalib-compare, 50%)) 0 0); }\n ${h} .compare-wipe:dir(rtl) > img.top.on { clip-path: inset(0 0 0 calc(100% - var(--uvalib-compare, 50%))); }\n ${h} .compare-wipe { touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: col-resize; }\n ${h} .compare-wipe img { -webkit-user-drag: none; }\n ${h} .divider {\n position: absolute; inset-block: 0; inset-inline-start: var(--uvalib-compare, 50%);\n width: 0; pointer-events: none; forced-color-adjust: none;\n }\n ${h} .divider::before {\n content: ''; position: absolute; inset-block: 0; inset-inline-start: -2px; width: 4px;\n background: #fff; outline: 1px solid #000;\n }\n ${h} .handle {\n position: absolute; top: 50%; inset-inline-start: -22px; box-sizing: border-box;\n width: 44px; height: 44px; margin-top: -22px; border: 3px solid #000; border-radius: 50%;\n background: #fff; outline: 2px solid #fff;\n }\n ${h} .handle::before, ${h} .handle::after {\n content: ''; position: absolute; top: 50%; margin-top: -6px;\n border-block: 6px solid transparent;\n }\n ${h} .handle::before { left: 7px; border-right: 8px solid #000; }\n ${h} .handle::after { right: 7px; border-left: 8px solid #000; }\n ${h} .side {\n position: absolute; inset-block-end: 0.5rem; max-width: 40%; overflow: hidden;\n padding: 0.125rem 0.5rem; background: #000; color: #fff; outline: 1px solid #fff;\n font-size: 0.875rem; font-weight: 700; line-height: 1.3; white-space: nowrap;\n text-overflow: ellipsis; pointer-events: none; forced-color-adjust: none;\n }\n ${h} .side-start { inset-inline-start: 0.5rem; }\n ${h} .side-end { inset-inline-end: 0.5rem; }\n ${h} .compare { display: flex; flex-direction: column; gap: 0.5rem; margin-block-start: 0.75rem; }\n ${h} .compare-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }\n ${h} .mode-panels { display: grid; flex: 1 1 auto; min-width: 0; }\n ${h} .mode-panel { grid-area: 1 / 1; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }\n ${h} .mode-panel[data-off] { visibility: hidden; }\n ${h} .seg-group { display: flex; flex-wrap: wrap; }\n ${h} .slider { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.75rem; flex: 1 1 14rem; min-width: 0; }\n ${h} .slider input { flex: 1 1 8rem; min-width: 0; min-height: 44px; margin: 0; }\n ${h} .note { margin: 0; overflow-wrap: anywhere; }\n ${h} .note[data-off] { visibility: hidden; }\n ${h} .compare button.hold { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; touch-action: none; }\n @media (forced-colors: active) {\n ${h} .divider::before { background: CanvasText; outline-color: Canvas; }\n ${h} .handle { background: Canvas; border-color: Highlight; outline-color: Canvas; }\n ${h} .handle::before { border-right-color: CanvasText; }\n ${h} .handle::after { border-left-color: CanvasText; }\n ${h} .side { background: CanvasText; color: Canvas; outline-color: Canvas; }\n }\n`;\n\nconst ACCENT = 'var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b))';\nconst LINK = 'var(--uva-color-link, var(--uva-brand-blue, #232d4b))';\n\n/** The look: segmented buttons like `<uvalib-chip-group segmented>`, the slider's accent. */\nconst look = (h: string) => `\n ${h} .compare button.seg, ${h} .compare button.jump, ${h} .compare button.hold {\n display: inline-flex; align-items: center; justify-content: center;\n border: 1px solid var(--uva-color-control-border, var(--uva-grey, #808080));\n background: var(--uva-color-surface-raised, var(--uva-color-surface, #fff));\n color: ${LINK}; font-size: 0.9375rem; font-weight: 600; line-height: 1.3;\n }\n ${h} .seg-group > button + button { margin-inline-start: -1px; }\n ${h} .seg-group > button:first-child { border-start-start-radius: 0.3rem; border-end-start-radius: 0.3rem; }\n ${h} .seg-group > button:last-child { border-start-end-radius: 0.3rem; border-end-end-radius: 0.3rem; }\n ${h} .compare button.seg[aria-pressed='true'] {\n position: relative; border-color: ${ACCENT}; background: ${ACCENT};\n color: var(--uva-color-on-accent, #fff);\n }\n ${h} .compare button.seg[aria-pressed='true']::before {\n content: ''; box-sizing: border-box; width: 0.375rem; height: 0.75rem;\n margin-inline-end: 0.5rem; border: solid currentColor; border-width: 0 2px 2px 0;\n transform: translateY(-0.0625rem) rotate(45deg);\n }\n ${h} .compare button:hover { border-color: ${LINK}; }\n ${h} .compare button.seg[aria-pressed='true']:hover { border-color: ${ACCENT}; }\n ${h} .compare button.hold[data-held] { background: var(--uva-color-surface-hover, #f1f1f1); }\n ${h} .slider label { font-weight: 600; }\n ${h} .slider input { accent-color: ${ACCENT}; }\n ${h} .slider input:focus-visible {\n outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));\n outline-offset: 2px;\n }\n ${h} .note { font-size: 0.9375rem; line-height: 1.5; }\n @media (prefers-reduced-motion: no-preference) {\n ${h} .compare-switch > img.top { transition: opacity 0.2s ease; }\n }\n @media (forced-colors: active) {\n ${h} .compare button.seg, ${h} .compare button.jump, ${h} .compare button.hold { border-color: ButtonText; }\n ${h} .compare button.seg[aria-pressed='true'] { background: Highlight; color: HighlightText; border-color: Highlight; }\n }\n`;\n\n/** Shadow roots that already have the comparison's sheets. */\nconst styled = new WeakSet<Node>();\n\nfunction install(host: CompareHost): void {\n const root = host.root;\n if (host.light) {\n const opts = { root: root as Document | ShadowRoot, scope: false };\n installLightDomStyles(\n 'uvalib-lightbox::compare-structure',\n unsafeCSS(structure('uvalib-lightbox')),\n opts,\n );\n if (!host.noStyle)\n installLightDomStyles('uvalib-lightbox::compare', unsafeCSS(look('uvalib-lightbox')), opts);\n return;\n }\n if (!(root instanceof ShadowRoot) || styled.has(root)) return;\n styled.add(root);\n const text = structure(':host') + (host.noStyle ? '' : look(':host'));\n const sheet = unsafeCSS(text).styleSheet;\n if (sheet) root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];\n}\n\nlet nextId = 0;\n\n/**\n * The comparison for one lightbox. State: the mode, the version shown (Switch) or compared\n * with the original (Reveal, Fade), and the percentage of it shown. Another version's image\n * is requested the first time it is needed, and drawn (and announced) once it has loaded.\n */\nexport class Compare {\n private list: Version[] = [];\n private slideKey = '';\n private id = '';\n private warned = false;\n /** The mode the visitor (or the address) chose; else the lightbox's `compare`. */\n private chosen: CompareMode | null = null;\n mode: CompareMode = 'switch';\n /** The version compared with the original (Reveal, Fade), from 1. */\n private other = 1;\n /** The percentage of `other` shown (Reveal, Fade). */\n private value = 50;\n /** The version shown (Switch), from 0. */\n private shown = 0;\n private holding = false;\n private requested = new Set<number>();\n private ready = new Set<number>();\n private failed = new Set<number>();\n private message = '';\n private flip = false;\n private pendingAnnounce = false;\n private announceNext = false;\n private settleTimer = 0;\n private settled = '';\n private dragging = false;\n private dragEnd = 0;\n private readonly uid = `uvalib-compare-${++nextId}`;\n\n constructor(private readonly host: CompareHost) {\n install(host);\n }\n\n /** At least two usable versions. */\n get active(): boolean {\n return this.list.length > 1;\n }\n\n /** Follow the open image: a new one starts again (in the current mode); `restore` is the address's value. */\n sync(slide: CompareSlide, index: number, restore: string | null): void {\n const key = `${index}\\n${slide.href}\\n${JSON.stringify(slide.versions)}`;\n if (key !== this.slideKey) {\n this.reset();\n this.slideKey = key;\n this.id = slide.id;\n this.list = this.parse(slide);\n this.mode =\n this.chosen ??\n (MODES.includes(this.host.mode() as CompareMode)\n ? (this.host.mode() as CompareMode)\n : 'switch');\n this.value = this.mode === 'wipe' ? 50 : 0;\n this.need();\n this.settled = this.encode();\n }\n if (restore != null && this.active) this.restore(restore);\n }\n\n /** Forget the open image (the viewer closed): report a change still settling first. */\n reset(): void {\n // Its event and analytics, but not the address: that is the next image's now.\n if (this.settleTimer) this.settle(false);\n this.slideKey = '';\n this.list = [];\n this.other = 1;\n this.shown = 0;\n this.holding = false;\n this.dragging = false;\n this.requested = new Set();\n this.ready = new Set();\n this.failed = new Set();\n this.message = '';\n this.pendingAnnounce = false;\n }\n\n private parse(slide: CompareSlide): Version[] {\n let raw: unknown = slide.versions;\n let bad = false;\n if (typeof raw === 'string') {\n try {\n raw = JSON.parse(raw);\n } catch {\n raw = null;\n bad = true;\n }\n }\n const out: Version[] = [];\n if (Array.isArray(raw)) {\n raw.forEach((v: unknown, i) => {\n const o = v && typeof v === 'object' ? (v as Record<string, unknown>) : {};\n const label = norm(o.label) || (i === 0 ? 'Original' : '');\n const href = i === 0 ? slide.href : norm(o.href);\n if (label && href && this.host.size(href)) out.push({ label, href, note: norm(o.note) });\n else if (i === 0) out.length = 0;\n else bad = true;\n });\n } else bad = true;\n if (bad && !this.warned) {\n this.warned = true;\n console.warn(\n 'uvalib-lightbox: data-versions (or the versions callback) has entries without a label or a usable href; they are left out.',\n );\n }\n return out.length > 1 ? out : [];\n }\n\n /** `2`, `switch:2`, `wipe:40`, `fade:60`, `wipe:40:2` (the version compared, from 1). */\n private restore(param: string): void {\n const m = /^(?:(switch|wipe|fade):)?(\\d{1,3})(?::(\\d{1,3}))?$/.exec(param.trim().toLowerCase());\n if (!m) return;\n const mode = (m[1] ?? 'switch') as CompareMode;\n const n = Number(m[2]);\n if (mode === 'switch') {\n if (n >= this.list.length) return;\n this.shown = n;\n } else {\n const other = m[3] ? Number(m[3]) : 1;\n this.other = other >= 1 && other < this.list.length ? other : 1;\n this.value = clamp(n);\n }\n this.mode = this.chosen = mode;\n this.need();\n this.settled = this.encode();\n }\n\n private encode(): string {\n if (this.mode === 'switch') return String(this.shown);\n return `${this.mode}:${this.value}${this.other !== 1 ? `:${this.other}` : ''}`;\n }\n\n /** The version over the original: shown (Switch) or compared (Reveal, Fade). */\n private get top(): number {\n return this.mode === 'switch' ? this.shown : this.other;\n }\n\n /** The percentage of the top version asked for. */\n private get amount(): number {\n if (this.holding) return 0;\n if (this.mode === 'switch') return this.shown > 0 ? 100 : 0;\n return this.value;\n }\n\n /** The percentage of it on screen: none until its image has loaded. */\n private get seen(): number {\n return this.top > 0 && this.ready.has(this.top) ? this.amount : 0;\n }\n\n private label(i: number): string {\n return this.list[i]?.label ?? '';\n }\n\n /** Request the top version's image the first time it is needed. */\n private need(): void {\n if (this.amount > 0 && this.top > 0) this.requested.add(this.top);\n }\n\n // ------------------------------------------------------------ changes\n\n private set(v: number, announce: boolean): void {\n const next = clamp(v);\n if (next === this.value) return;\n this.value = next;\n this.need();\n this.host.update();\n this.announceNext ||= announce;\n window.clearTimeout(this.settleTimer);\n this.settleTimer = window.setTimeout(() => this.settle(), compareTiming.settle);\n }\n\n private change(fn: () => void): void {\n fn();\n this.need();\n this.host.update();\n this.announceNext = true;\n this.settle();\n }\n\n /** A visitor's change has settled: the event, analytics, the address and the announcement. */\n private settle(write = true): void {\n window.clearTimeout(this.settleTimer);\n this.settleTimer = 0;\n const state = this.encode();\n const announce = this.announceNext;\n this.announceNext = false;\n if (state === this.settled || !this.active) return;\n this.settled = state;\n const index = this.top;\n const el = this.host.el;\n el.dispatchEvent(\n new CustomEvent('uvalib-lightbox-version', {\n detail: {\n id: this.id,\n mode: this.mode,\n index,\n value: this.mode === 'switch' ? null : this.value,\n },\n bubbles: true,\n composed: true,\n }),\n );\n trackEvent(el, ['uvalib-lightbox', 'compare', this.mode, index + 1]);\n if (!write) return;\n this.host.write(state);\n if (!announce) return;\n if (this.amount > 0 && !this.ready.has(this.top)) this.pendingAnnounce = true;\n else this.say(this.stateText());\n }\n\n private say(text: string): void {\n this.pendingAnnounce = false;\n // A repeated message is still a change, so it is read again.\n this.flip = !this.flip;\n this.message = text + (this.flip ? ' ' : '');\n this.host.update();\n }\n\n private stateText(): string {\n const a = this.amount;\n if (a <= 0) return `${this.label(0)} shown`;\n if (a >= 100) return `${this.label(this.top)} shown`;\n return `${a}% ${this.label(this.top)}`;\n }\n\n private setMode(mode: CompareMode): void {\n if (mode === this.mode) return;\n this.change(() => {\n if (mode === 'switch') this.shown = this.value >= 50 ? this.other : 0;\n else if (this.mode === 'switch') {\n if (this.shown > 0) this.other = this.shown;\n this.value = mode === 'wipe' ? 50 : this.shown > 0 ? 100 : 0;\n }\n this.mode = this.chosen = mode;\n });\n }\n\n private hold(on: boolean): void {\n if (on === this.holding) return;\n this.holding = on;\n this.host.update();\n }\n\n private loaded(i: number): void {\n this.ready.add(i);\n this.host.update();\n if (this.pendingAnnounce && i === this.top) this.say(this.stateText());\n }\n\n private errored(i: number): void {\n this.failed.add(i);\n this.pendingAnnounce = false;\n this.say(`${this.label(i)} could not be loaded.`);\n }\n\n // ------------------------------------------------------------ input\n\n /** The `o` key held anywhere in the dialog shows the original. True when handled. */\n key(e: KeyboardEvent): boolean {\n if (!this.active || (e.key !== 'o' && e.key !== 'O') || e.altKey || e.ctrlKey || e.metaKey)\n return false;\n this.hold(e.type === 'keydown');\n return true;\n }\n\n /** A press on the photo in Reveal moves the divider there; a drag keeps moving it. */\n pointer(e: PointerEvent): void {\n if (!this.active || this.mode !== 'wipe') return;\n const stack = e.currentTarget as HTMLElement;\n if (e.type === 'pointerdown') {\n if (e.button !== 0 || !e.isPrimary) return;\n this.dragging = true;\n try {\n stack.setPointerCapture(e.pointerId);\n } catch {\n // A synthetic pointer cannot be captured; the press still moves the divider.\n }\n e.preventDefault();\n } else if (e.type !== 'pointermove') {\n if (this.dragging) this.dragEnd = performance.now();\n this.dragging = false;\n return;\n }\n if (!this.dragging) return;\n const r = stack.getBoundingClientRect();\n if (!r.width) return;\n const rtl = getComputedStyle(stack).direction === 'rtl';\n this.set(((rtl ? r.right - e.clientX : e.clientX - r.left) / r.width) * 100, true);\n }\n\n /** A drag that ended outside the photo must not count as a click on the backdrop. */\n dragged(): boolean {\n return this.dragging || performance.now() - this.dragEnd < 100;\n }\n\n private readonly onInput = (e: Event): void => {\n this.set(Number((e.target as HTMLInputElement).value), false);\n };\n\n /** Shift with an arrow, and Page Up / Page Down, move 10%. */\n private readonly onSliderKey = (e: KeyboardEvent): void => {\n const rtl = getComputedStyle(e.target as Element).direction === 'rtl';\n const k = e.key;\n let d = 0;\n if (k === 'PageUp') d = 10;\n else if (k === 'PageDown') d = -10;\n else if (e.shiftKey && (k === 'ArrowUp' || k === 'ArrowDown')) d = k === 'ArrowUp' ? 10 : -10;\n else if (e.shiftKey && (k === 'ArrowLeft' || k === 'ArrowRight'))\n d = (k === 'ArrowRight') !== rtl ? 10 : -10;\n if (!d) return;\n e.preventDefault();\n this.set(this.value + d, false);\n };\n\n private readonly onHold = (e: Event): void => {\n const t = e.type;\n if (t === 'keydown' || t === 'keyup') {\n const k = (e as KeyboardEvent).key;\n if (k !== ' ' && k !== 'Enter') return;\n this.hold(t === 'keydown');\n } else this.hold(t === 'pointerdown');\n };\n\n // ------------------------------------------------------------ render\n\n /** The image's accessible name ends with what is on screen. */\n alt(base: string): string {\n const a = this.seen;\n const l0 = this.label(0);\n const lk = this.label(this.top);\n const what =\n a <= 0\n ? l0\n : a >= 100\n ? lk\n : `${l0} and ${lk}, ${this.mode === 'wipe' ? 'compared side by side' : 'blended'}`;\n return `${base} (${what})`;\n }\n\n get stackClass(): string {\n return `compare-${this.mode}`;\n }\n\n get stackStyle(): string {\n const a = this.mode === 'switch' ? 100 : this.value;\n return `--uvalib-compare: ${a}%; --uvalib-compare-opacity: ${a / 100}`;\n }\n\n /** The other versions' images (each requested on first use), the divider and the side labels. */\n layers() {\n const top = this.top;\n const on = this.seen > 0;\n const layers = this.list.map((v, i) =>\n i === 0\n ? nothing\n : html`<img\n class=\"top ${i === top && on ? 'on' : ''}\"\n data-version=${i}\n alt=\"\"\n decoding=\"async\"\n draggable=\"false\"\n src=${this.requested.has(i) ? this.host.size(v.href) : nothing}\n @load=${() => this.loaded(i)}\n @error=${() => this.errored(i)}\n />`,\n );\n if (this.mode !== 'wipe') return layers;\n const a = this.seen;\n return html`${layers}\n <div class=\"divider\" aria-hidden=\"true\"><span class=\"handle\"></span></div>\n <span class=\"side side-start\" aria-hidden=\"true\" ?hidden=${a <= 0}>${this.label(top)}</span>\n <span class=\"side side-end\" aria-hidden=\"true\" ?hidden=${a >= 100}>${this.label(0)}</span>`;\n }\n\n /** Notes of the versions on screen, then the controls. `slot` puts them under regions' image. */\n controls(slot: string) {\n const a = this.seen;\n const top = this.top;\n // Every note keeps its line (hidden while its version is not on screen), so showing\n // another version never moves the photo or the controls.\n const visible = (i: number) => (i === 0 ? a < 100 : i === top && a > 0);\n const notes = this.list.map((v, i) =>\n v.note\n ? html`<p class=\"note\" ?data-off=${!visible(i)}><strong>${v.label}:</strong> ${v.note}</p>`\n : nothing,\n );\n const failed =\n this.failed.has(top) && this.amount > 0\n ? html`<p class=\"note\">${this.label(top)} could not be loaded.</p>`\n : nothing;\n const seg = (pressed: boolean, text: string, onClick: () => void) =>\n html`<button\n type=\"button\"\n class=\"seg\"\n aria-pressed=${pressed ? 'true' : 'false'}\n @click=${onClick}\n >\n ${text}\n </button>`;\n const l0 = this.label(0);\n const lk = this.label(this.other);\n // Both panels are always drawn, in one grid cell: the row is as tall as the taller one,\n // so changing mode never moves the photo (the dialog re-centres on any height change).\n // The other panel is inert and hidden, out of the tab order and the accessibility tree.\n const switching = this.mode === 'switch';\n const panel = (on: boolean, body: unknown) =>\n html`<div class=\"mode-panel\" ?inert=${!on} ?data-off=${!on}>${body}</div>`;\n const switchPanel = html`<div class=\"seg-group\" role=\"group\" aria-label=\"Version shown\">\n ${this.list.map((v, i) =>\n seg(this.shown === i, v.label, () => this.change(() => (this.shown = i))),\n )}\n </div>`;\n const sliding = html`${\n this.list.length > 2\n ? html`<div class=\"seg-group\" role=\"group\" aria-label=\"Compare ${l0} with\">\n ${this.list.map((v, i) =>\n i\n ? seg(this.other === i, v.label, () => this.change(() => (this.other = i)))\n : nothing,\n )}\n </div>`\n : nothing\n }\n <div class=\"slider\">\n <label for=${this.uid}>${this.mode === 'fade' ? 'Fade to' : 'Reveal'} ${lk}</label>\n <input\n id=${this.uid}\n type=\"range\"\n min=\"0\"\n max=\"100\"\n step=\"1\"\n .value=${String(this.value)}\n aria-valuetext=\"${this.value}% ${lk}\"\n @input=${this.onInput}\n @keydown=${this.onSliderKey}\n />\n </div>\n <div class=\"seg-group\" role=\"group\" aria-label=\"Jump to\">\n ${[\n [0, l0],\n [50, '50/50'],\n [100, lk],\n ].map(\n ([v, text]) =>\n html`<button\n type=\"button\"\n class=\"jump\"\n @click=${() => this.change(() => (this.value = v as number))}\n >\n ${text}\n </button>`,\n )}\n </div>\n <button\n type=\"button\"\n class=\"hold\"\n aria-keyshortcuts=\"O\"\n ?data-held=${this.holding}\n @pointerdown=${this.onHold}\n @pointerup=${this.onHold}\n @pointerleave=${this.onHold}\n @pointercancel=${this.onHold}\n @keydown=${this.onHold}\n @keyup=${this.onHold}\n @blur=${() => this.hold(false)}\n @contextmenu=${(e: Event) => e.preventDefault()}\n >\n Hold for ${l0}\n </button>`;\n return html`<div class=\"compare\" part=\"compare\" slot=${slot || nothing}>\n ${notes}${failed}\n <div class=\"compare-bar\">\n <div class=\"seg-group\" role=\"group\" aria-label=\"Compare versions\">\n ${MODES.map((m) => seg(this.mode === m, MODE_NAMES[m], () => this.setMode(m)))}\n </div>\n <div class=\"mode-panels\">${panel(switching, switchPanel)}${panel(!switching, sliding)}</div>\n </div>\n <p class=\"visually-hidden\" role=\"status\">${this.message}</p>\n </div>`;\n }\n\n /**\n * Full size, in every mode: the original and the version shown (Switch) or compared (Reveal,\n * Fade), each named. The same two links in every mode keep the toolbar's height, so changing\n * mode never moves the photo; and a visitor can always open the original at full size.\n */\n full(): { href: string; label: string }[] {\n const k = this.mode === 'switch' ? this.shown || this.other : this.other;\n return [0, k].map((i) => ({ href: this.list[i]!.href, label: this.label(i) }));\n }\n}\n"],"mappings":";;;AAWA,IAAMM,IAAuB;CAAC;CAAU;CAAQ;AAAM,GAChDC,IAA0C;CAC9C,QAAQ;CACR,MAAM;CACN,MAAM;AACR,GAGaC,IAAgB,EAAE,QAAQ,IAAI,GA8BrCC,KAAQ,MAAgB,OAAOC,KAAM,WAAWA,EAAE,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK,IAAI,IAChFC,KAAS,MAAc,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,KAAK,MAAMC,CAAC,CAAC,CAAC,GAO/DC,KAAa,MAAc;IAC7BC,EAAE;IACFA,EAAE;;;;IAIFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;;;;IAIFA,EAAE;;;;IAIFA,EAAE;;;;;IAKFA,EAAE,oBAAoBA,EAAE;;;;IAIxBA,EAAE;IACFA,EAAE;IACFA,EAAE;;;;;;IAMFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;;MAEAA,EAAE;MACFA,EAAE;MACFA,EAAE;MACFA,EAAE;MACFA,EAAE;;GAIFC,IAAS,8DACT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AAC,KAAK,OAAO;GAAE,MAAM,KAAK,KAAKzB,EAAE,CAAE;GAAM,OAAO,KAAK,MAAMA,CAAC;EAAE,EAAE;CAC/E;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hours-data-Bw6vkIw7.js","names":["fetchJsonWith","fetchJson$1","formatter","hoursEndpoints","hoursTiming","setHoursEndpoints","key","value","from","globalApplied","endpoints","fetchJson","url","orUndefined","v","parseLibraries","data","json","n","a","calId","uri","siteLink","node","librariesCache","loadLibraries","p","promise","hoursCache","HOURS_CACHE_MAX","loadHours","sorted","ids","b","to","hit","maxAge","out","c","lid","entry","sortLibraries","rank","l","libs","utc","y","m","d","iso","date","addDays","days","weekStart","fmt","options","longDate","shortDate","shortWeekday","fullDate","headingDate","weekHeadingDate","formatTime","time","ampm","formatDay","day","h","ALLOWED","DROPPED","SAFE_PROTOCOLS","safeHref","href","base","copyAllowed","doc","name","el","sanitizeHoursHtml","parsed","html"],"sources":["../../src/components/library-hours/hours-data.ts"],"sourcesContent":["// Shared data and formatting for the library-hours components. Internal: not exported from\n// the package entry (only the LibraryInfo and DayHours types are). No side effects on import.\n\nimport { fetchJson as fetchJsonWith } from '../../data/fetch-json.js';\nimport { TIME_ZONE, formatter, todayInNewYork } from '../../data/new-york.js';\n\n/** One day's hours from LibCal: a status and, when open, one or more ranges. */\nexport interface DayHours {\n /** `open`, `closed`, `24hours`, or another LibCal status, shown as is. */\n status: string;\n /** Opening ranges, LibCal's own text (`9:00am` to `12:00am`); `to` may be past midnight. */\n hours?: { from: string; to: string }[];\n}\n\n/** A library (or a space inside one) from the Drupal JSON:API, reduced to the fields used. */\nexport interface LibraryInfo {\n /** Drupal node UUID. */\n id: string;\n title: string;\n shortTitle?: string;\n slug?: string;\n /** LibCal calendar id. */\n calId?: number;\n /** `Library`, `space` or `other-professional`. */\n placeType?: string;\n priorityPlacement?: number;\n /** Site link, with Drupal's `internal:` prefix removed (other schemes are kept as is). */\n siteLink?: string;\n /** Drupal's processed `field_hours_information` HTML. Sanitise before display. */\n hoursInformation?: string;\n /** Parent library's node UUID. */\n parent?: string;\n}\n\n/** Hours per LibCal calendar id, each a map of `YYYY-MM-DD` to that day's hours. */\nexport type HoursByCalendar = Map<number, Record<string, DayHours>>;\n\n/** The two data URLs. */\nexport interface HoursEndpoints {\n /** The Drupal JSON:API library list (relative by default: same origin, no CORS). */\n libraries: string;\n /** LibCal hours, with `{ids}` for the comma-separated calendar ids; `from` / `to` are appended. */\n hours: string;\n}\n\n/**\n * Where the data comes from, shared by every hours element (and exposed to pages as the\n * elements' static `endpoints`). The LibCal key is LibCal's public client widget key\n * (already public in the live bundles). A page can also set `window.uvalibHoursEndpoints`\n * (`{ libraries?, hours? }`) before the elements' script runs; it is merged in at the\n * first fetch. Requests are cached by URL, so a change applies to the next load.\n */\nexport const hoursEndpoints: HoursEndpoints = {\n libraries: '/jsonapi/index/default_index?filter[type]=library&page[limit]=100',\n hours:\n 'https://cal.lib.virginia.edu/api/1.0/hours/{ids}?iid=863&key=e4b27d40b7099e8e392113da2f8bf30a',\n};\n\n/**\n * Fetch attempts, the delay between them (ms), each attempt's timeout (ms), and how often\n * elements check the date (ms).\n */\nexport const hoursTiming = { retries: 3, retryDelay: 1000, timeout: 10_000, tick: 60_000 };\n\ndeclare global {\n interface Window {\n /** Optional endpoint overrides for the library-hours elements, read at their first fetch. */\n uvalibHoursEndpoints?: Partial<HoursEndpoints>;\n }\n}\n\n/** Copy the known endpoint keys (strings only) from `from` into the shared endpoints. */\nexport function setHoursEndpoints(from: Partial<HoursEndpoints> | null | undefined): void {\n for (const key of ['libraries', 'hours'] as const) {\n const value = from?.[key];\n if (typeof value === 'string' && value) hoursEndpoints[key] = value;\n }\n}\n\nlet globalApplied = false;\n/** The endpoints to use now: the page's `window.uvalibHoursEndpoints` is merged in once. */\nfunction endpoints(): HoursEndpoints {\n if (!globalApplied) {\n globalApplied = true;\n setHoursEndpoints(globalThis.window?.uvalibHoursEndpoints);\n }\n return hoursEndpoints;\n}\n\nexport { TIME_ZONE, todayInNewYork };\n\n// --- fetching -------------------------------------------------------------------------\n\nconst fetchJson = (url: string) => fetchJsonWith(url, hoursTiming);\n\ninterface RawLibrary {\n id: string;\n attributes: {\n title: string;\n field_short_title?: string | null;\n field_slug?: string | null;\n field_libcal_id?: string | number | null;\n field_type_basic?: string | null;\n field_priority_placement?: number | null;\n field_library_site_link?: { uri?: string } | null;\n field_hours_information?: { processed?: string } | null;\n };\n relationships?: { field_parent?: { data?: { id?: string } | null } };\n}\n\nconst orUndefined = <T>(v: T | null | undefined): T | undefined => v ?? undefined;\n\n/** Reduce a JSON:API response to LibraryInfo, in response order. */\nexport function parseLibraries(json: unknown): LibraryInfo[] {\n const data = (json as { data?: RawLibrary[] } | null)?.data;\n if (!Array.isArray(data)) return [];\n return data\n .filter((n) => n?.id && n.attributes?.title)\n .map((n) => {\n const a = n.attributes;\n const calId = parseInt(String(a.field_libcal_id ?? ''), 10);\n const uri = a.field_library_site_link?.uri;\n return {\n id: n.id,\n title: a.title,\n shortTitle: orUndefined(a.field_short_title),\n slug: orUndefined(a.field_slug),\n calId: Number.isNaN(calId) ? undefined : calId,\n placeType: orUndefined(a.field_type_basic),\n priorityPlacement: orUndefined(a.field_priority_placement),\n siteLink: siteLink(uri),\n hoursInformation: orUndefined(a.field_hours_information?.processed),\n parent: orUndefined(n.relationships?.field_parent?.data?.id),\n };\n });\n}\n\n/**\n * A Drupal link field as an href: `internal:/rmc/` becomes `/rmc/` and `entity:node/807`\n * becomes `/node/807` (Drupal redirects it to the page's alias). Other `entity:` links have\n * no URL outside Drupal, so they are dropped.\n */\nfunction siteLink(uri: string | undefined): string | undefined {\n if (!uri) return undefined;\n if (uri.startsWith('internal:')) return uri.slice('internal:'.length) || undefined;\n const node = /^entity:node\\/(\\d+)$/.exec(uri);\n if (node) return `/node/${node[1]}`;\n return uri.startsWith('entity:') ? undefined : uri;\n}\n\nconst librariesCache = new Map<string, Promise<LibraryInfo[]>>();\n\n/** The library list, fetched once per page (per URL) and shared. A failure is not cached. */\nexport function loadLibraries(): Promise<LibraryInfo[]> {\n const url = endpoints().libraries;\n let p = librariesCache.get(url);\n if (!p) {\n const promise = fetchJson(url).then(parseLibraries);\n librariesCache.set(url, (p = promise));\n promise.catch(() => {\n if (librariesCache.get(url) === promise) librariesCache.delete(url);\n });\n }\n return p;\n}\n\ninterface CacheEntry {\n at: number;\n promise: Promise<HoursByCalendar>;\n}\nconst hoursCache = new Map<string, CacheEntry>();\nconst HOURS_CACHE_MAX = 50;\n\n/**\n * Hours for LibCal calendars `ids` from `from` to `to` (inclusive, `YYYY-MM-DD`, at most\n * 100 days). Identical requests share one fetch; a cached result older than `maxAge` ms is\n * fetched again. A failure is not cached.\n */\nexport function loadHours(\n ids: number[],\n from: string,\n to: string,\n maxAge = Infinity,\n): Promise<HoursByCalendar> {\n const sorted = [...new Set(ids)].sort((a, b) => a - b);\n if (!sorted.length) return Promise.resolve(new Map());\n const url =\n endpoints().hours.replace('{ids}', sorted.join(',')) +\n `&from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;\n const key = url;\n const hit = hoursCache.get(key);\n if (hit && performance.now() - hit.at <= maxAge) return hit.promise;\n const promise = fetchJson(url).then((json) => {\n const out: HoursByCalendar = new Map();\n if (Array.isArray(json)) {\n for (const c of json as { lid?: unknown; dates?: unknown }[]) {\n const lid = Number(c?.lid);\n if (Number.isFinite(lid) && c.dates && typeof c.dates === 'object')\n out.set(lid, c.dates as Record<string, DayHours>);\n }\n }\n return out;\n });\n const entry = { at: performance.now(), promise };\n hoursCache.delete(key);\n hoursCache.set(key, entry);\n if (hoursCache.size > HOURS_CACHE_MAX) hoursCache.delete(hoursCache.keys().next().value!);\n promise.catch(() => {\n if (hoursCache.get(key) === entry) hoursCache.delete(key);\n });\n return promise;\n}\n\n/** Forget the cached library list and hours (for tests). */\nexport function resetHoursCache(): void {\n librariesCache.clear();\n hoursCache.clear();\n globalApplied = false;\n}\n\n/** Libraries by priority placement (missing last), then title. Returns a new array. */\nexport function sortLibraries(libs: readonly LibraryInfo[]): LibraryInfo[] {\n const rank = (l: LibraryInfo) => l.priorityPlacement || Infinity;\n return [...libs].sort((a, b) => rank(a) - rank(b) || a.title.localeCompare(b.title));\n}\n\n// --- dates: all arithmetic on YYYY-MM-DD strings, in UTC -------------------------------\n\nconst utc = (iso: string): Date => {\n const [y, m, d] = iso.split('-').map(Number) as [number, number, number];\n return new Date(Date.UTC(y, m - 1, d));\n};\nconst iso = (date: Date): string => date.toISOString().slice(0, 10);\n\nexport function addDays(date: string, days: number): string {\n const d = utc(date);\n d.setUTCDate(d.getUTCDate() + days);\n return iso(d);\n}\n\n/** The Sunday on or before `date`. */\nexport function weekStart(date: string): string {\n return addDays(date, -utc(date).getUTCDay());\n}\n\nconst fmt = (key: string, options: Intl.DateTimeFormatOptions) => (date: string) =>\n formatter(key, { ...options, timeZone: 'UTC' }).format(utc(date));\n\n/** \"Monday, November 9\" */\nexport const longDate = fmt('long', { weekday: 'long', month: 'long', day: 'numeric' });\n/** \"Nov 9\" */\nexport const shortDate = fmt('short', { month: 'short', day: 'numeric' });\n/** \"Mon\" */\nexport const shortWeekday = fmt('weekday', { weekday: 'short' });\n/** \"Saturday, November 14, 2026\" */\nexport const fullDate = fmt('full', {\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n});\nconst headingDate = fmt('heading', { year: 'numeric', month: 'short', day: '2-digit' });\n/** \"Nov 08. 2026\": the live week heading's format, kept because Drupal's /hours shows it. */\nexport const weekHeadingDate = (date: string): string => headingDate(date).replace(',', '.');\n\n// --- hours text ----------------------------------------------------------------------\n\n/** `9:00am` → `9am`, `5:30pm` → `5:30pm`; anything else unchanged. */\nexport function formatTime(time: string): string {\n const m = /^(\\d+):(\\d+)\\s*(am|pm)$/i.exec(time.trim());\n if (!m) return time;\n const ampm = m[3]!.toLowerCase();\n return m[2] === '00' ? `${m[1]}${ampm}` : `${m[1]}:${m[2]}${ampm}`;\n}\n\n/** A day's hours as text: `9am - 6pm` (ranges joined by commas), `24 Hours`, `closed`, or ''. */\nexport function formatDay(day: DayHours | undefined): string {\n if (!day) return '';\n if (Array.isArray(day.hours) && day.hours.length)\n return day.hours.map((h) => `${formatTime(h.from)} - ${formatTime(h.to)}`).join(', ');\n return (day.status ?? '').replace('24hours', '24 Hours').replace('ByApp', 'By Appt').trim();\n}\n\n// --- HTML from Drupal ----------------------------------------------------------------\n\nconst ALLOWED = new Set(['a', 'p', 'br', 'strong', 'em']);\n/** Dropped with their content; any other element is unwrapped (its content kept). */\nconst DROPPED = new Set([\n 'script',\n 'style',\n 'template',\n 'iframe',\n 'object',\n 'embed',\n 'noscript',\n 'svg',\n 'math',\n 'title',\n 'textarea',\n 'select',\n 'img',\n 'video',\n 'audio',\n 'head',\n]);\nconst SAFE_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'tel:']);\n\nfunction safeHref(href: string, base: string): boolean {\n try {\n return SAFE_PROTOCOLS.has(new URL(href, base).protocol);\n } catch {\n return false;\n }\n}\n\nfunction copyAllowed(from: Node, to: Node, doc: Document): void {\n for (const node of from.childNodes) {\n if (node.nodeType === Node.TEXT_NODE) {\n to.appendChild(doc.createTextNode((node as Text).data));\n } else if (node.nodeType === Node.ELEMENT_NODE) {\n const name = (node as Element).localName;\n if (ALLOWED.has(name)) {\n const el = doc.createElement(name);\n const href = (node as Element).getAttribute('href');\n if (name === 'a' && href && safeHref(href, doc.baseURI)) el.setAttribute('href', href);\n copyAllowed(node, el, doc);\n to.appendChild(el);\n } else if (!DROPPED.has(name)) {\n copyAllowed(node, to, doc);\n }\n }\n }\n}\n\n/**\n * Drupal's hours HTML reduced to an allowlist (`a[href]` with an http(s), mailto, tel or\n * relative URL, `p`, `br`, `strong`, `em`), as new nodes owned by `doc`. It is parsed in an\n * inert document, so nothing in it runs or loads. The same walk is used in every browser\n * (rather than `setHTML` where available) so the output never differs between browsers.\n */\nexport function sanitizeHoursHtml(html: string, doc: Document = document): DocumentFragment {\n const out = doc.createDocumentFragment();\n let parsed: Document;\n try {\n parsed = new DOMParser().parseFromString(html, 'text/html');\n } catch {\n // For example a page enforcing Trusted Types: fall back to the text alone.\n out.append(doc.createTextNode(html.replace(/<[^>]*>/g, '')));\n return out;\n }\n copyAllowed(parsed.body, out, doc);\n return out;\n}\n"],"mappings":";;;AAoDA,IAAaG,IAAiC;CAC5C,WAAW;CACX,OACE;AACJ,GAMaC,IAAc;CAAE,SAAS;CAAG,YAAY;CAAM,SAAS;CAAQ,MAAM;AAAO;AAUzF,SAAgBC,EAAkB,GAAwD;CACxF,KAAK,IAAMC,KAAO,CAAC,aAAa,OAAO,GAAY;EACjD,IAAMC,IAAQC,IAAOF;EACrB,AAAI,OAAOC,KAAU,YAAYA,MAAO,EAAeD,KAAOC;CAChE;AACF;AAEA,IAAIE,IAAgB;AAEpB,SAASC,IAA4B;CAKnC,OAJKD,MACH,IAAgB,IAChBJ,EAAkB,WAAW,QAAQ,oBAAoB,IAEpDF;AACT;AAMA,IAAMQ,KAAa,MAAgBX,EAAcY,GAAKR,CAAW,GAiB3DS,KAAkB,MAA2CC,KAAK,KAAA;AAGxE,SAAgBC,EAAe,GAA8B;CAC3D,IAAMC,IAAQC,GAAyC;CAEvD,OADK,MAAM,QAAQD,CAAI,IAChBA,EACJ,QAAQ,MAAME,GAAG,MAAMA,EAAE,YAAY,KAAK,CAAC,CAC3C,KAAK,MAAM;EACV,IAAMC,IAAID,EAAE,YACNE,IAAQ,SAAS,OAAOD,EAAE,mBAAmB,EAAE,GAAG,EAAE,GACpDE,IAAMF,EAAE,yBAAyB;EACvC,OAAO;GACL,IAAID,EAAE;GACN,OAAOC,EAAE;GACT,YAAYN,EAAYM,EAAE,iBAAiB;GAC3C,MAAMN,EAAYM,EAAE,UAAU;GAC9B,OAAO,OAAO,MAAMC,CAAK,IAAI,KAAA,IAAYA;GACzC,WAAWP,EAAYM,EAAE,gBAAgB;GACzC,mBAAmBN,EAAYM,EAAE,wBAAwB;GACzD,UAAUG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