@uvalib/web-components 1.1.0 → 1.2.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 (111) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +563 -47
  3. package/dist/base/url-param.d.ts +23 -0
  4. package/dist/base/url-param.js +49 -0
  5. package/dist/base/url-param.js.map +1 -0
  6. package/dist/base.css +289 -1
  7. package/dist/components/uvalib-card/UvalibCard.d.ts +19 -5
  8. package/dist/components/uvalib-card/UvalibCard.js +112 -9
  9. package/dist/components/uvalib-card/UvalibCard.js.map +1 -1
  10. package/dist/components/uvalib-chip-group/UvalibChipGroup.d.ts +156 -0
  11. package/dist/components/uvalib-chip-group/UvalibChipGroup.js +747 -0
  12. package/dist/components/uvalib-chip-group/UvalibChipGroup.js.map +1 -0
  13. package/dist/components/uvalib-chip-group/uvalib-chip-group.d.ts +1 -0
  14. package/dist/components/uvalib-chip-group/uvalib-chip-group.js +4 -0
  15. package/dist/components/uvalib-chip-group/uvalib-chip-group.js.map +1 -0
  16. package/dist/components/uvalib-date-histogram/UvalibDateHistogram.d.ts +148 -0
  17. package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js +1248 -0
  18. package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js.map +1 -0
  19. package/dist/components/uvalib-date-histogram/uvalib-date-histogram.d.ts +1 -0
  20. package/dist/components/uvalib-date-histogram/uvalib-date-histogram.js +4 -0
  21. package/dist/components/uvalib-date-histogram/uvalib-date-histogram.js.map +1 -0
  22. package/dist/components/uvalib-lightbox/UvalibLightbox.js +8 -1
  23. package/dist/components/uvalib-lightbox/UvalibLightbox.js.map +1 -1
  24. package/dist/components/uvalib-lightbox/media.d.ts +1 -18
  25. package/dist/components/uvalib-lightbox/media.js +1 -42
  26. package/dist/components/uvalib-lightbox/media.js.map +1 -1
  27. package/dist/components/uvalib-pager/UvalibPager.d.ts +58 -4
  28. package/dist/components/uvalib-pager/UvalibPager.js +232 -8
  29. package/dist/components/uvalib-pager/UvalibPager.js.map +1 -1
  30. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.d.ts +27 -1
  31. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js +192 -26
  32. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js.map +1 -1
  33. package/dist/components/uvalib-results-count/UvalibResultsCount.d.ts +62 -0
  34. package/dist/components/uvalib-results-count/UvalibResultsCount.js +208 -0
  35. package/dist/components/uvalib-results-count/UvalibResultsCount.js.map +1 -0
  36. package/dist/components/uvalib-results-count/uvalib-results-count.d.ts +1 -0
  37. package/dist/components/uvalib-results-count/uvalib-results-count.js +4 -0
  38. package/dist/components/uvalib-results-count/uvalib-results-count.js.map +1 -0
  39. package/dist/components/uvalib-tabs/UvalibTabs.d.ts +127 -0
  40. package/dist/components/uvalib-tabs/UvalibTabs.js +821 -0
  41. package/dist/components/uvalib-tabs/UvalibTabs.js.map +1 -0
  42. package/dist/components/uvalib-tabs/uvalib-tabs.d.ts +1 -0
  43. package/dist/components/uvalib-tabs/uvalib-tabs.js +4 -0
  44. package/dist/components/uvalib-tabs/uvalib-tabs.js.map +1 -0
  45. package/dist/components/uvalib-tag-list/UvalibTagList.d.ts +89 -0
  46. package/dist/components/uvalib-tag-list/UvalibTagList.js +411 -0
  47. package/dist/components/uvalib-tag-list/UvalibTagList.js.map +1 -0
  48. package/dist/components/uvalib-tag-list/uvalib-tag-list.d.ts +1 -0
  49. package/dist/components/uvalib-tag-list/uvalib-tag-list.js +4 -0
  50. package/dist/components/uvalib-tag-list/uvalib-tag-list.js.map +1 -0
  51. package/dist/custom-elements.json +7140 -2630
  52. package/dist/index.d.ts +8 -0
  53. package/dist/index.js +5 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/styles/base.js +35 -1
  56. package/dist/styles/base.js.map +1 -1
  57. package/dist/styles/color-scheme.js +4 -0
  58. package/dist/styles/color-scheme.js.map +1 -1
  59. package/dist/styles/controls.js +2 -0
  60. package/dist/styles/controls.js.map +1 -1
  61. package/dist/styles/results.d.ts +1 -0
  62. package/dist/styles/results.js +257 -0
  63. package/dist/styles/results.js.map +1 -0
  64. package/dist/tokens.css +4 -0
  65. package/dist-cdn/base.css +289 -1
  66. package/dist-cdn/chunks/{base-CAFQWnZG.js → base-p5pk0vb2.js} +36 -2
  67. package/dist-cdn/chunks/{base-CAFQWnZG.js.map → base-p5pk0vb2.js.map} +1 -1
  68. package/dist-cdn/chunks/inline-copy-BANQSMIR.js +69 -0
  69. package/dist-cdn/chunks/inline-copy-BANQSMIR.js.map +1 -0
  70. package/dist-cdn/chunks/{site-header-C9V7Wuw2.js → site-header-BlOYvQg1.js} +5 -1
  71. package/dist-cdn/chunks/site-header-BlOYvQg1.js.map +1 -0
  72. package/dist-cdn/chunks/source-children-BHsDwCvL.js +53 -0
  73. package/dist-cdn/chunks/source-children-BHsDwCvL.js.map +1 -0
  74. package/dist-cdn/chunks/url-param-C1sk_F1d.js +28 -0
  75. package/dist-cdn/chunks/url-param-C1sk_F1d.js.map +1 -0
  76. package/dist-cdn/custom-elements.json +7140 -2630
  77. package/dist-cdn/manifest.json +7 -2
  78. package/dist-cdn/site-header.js +1 -1
  79. package/dist-cdn/site-page.js +2 -2
  80. package/dist-cdn/site-style.js +1 -1
  81. package/dist-cdn/skills/uvalib-web-components/SKILL.md +206 -19
  82. package/dist-cdn/skills/uvalib-web-components/reference/components.md +220 -6
  83. package/dist-cdn/tokens.css +4 -0
  84. package/dist-cdn/uvalib-card.js +94 -20
  85. package/dist-cdn/uvalib-card.js.map +1 -1
  86. package/dist-cdn/uvalib-chip-group.js +496 -0
  87. package/dist-cdn/uvalib-chip-group.js.map +1 -0
  88. package/dist-cdn/uvalib-contents.js +2 -1
  89. package/dist-cdn/uvalib-contents.js.map +1 -1
  90. package/dist-cdn/uvalib-date-histogram.js +850 -0
  91. package/dist-cdn/uvalib-date-histogram.js.map +1 -0
  92. package/dist-cdn/uvalib-lightbox.js +26 -48
  93. package/dist-cdn/uvalib-lightbox.js.map +1 -1
  94. package/dist-cdn/uvalib-metadata.js +2 -1
  95. package/dist-cdn/uvalib-metadata.js.map +1 -1
  96. package/dist-cdn/uvalib-pager.js +141 -7
  97. package/dist-cdn/uvalib-pager.js.map +1 -1
  98. package/dist-cdn/uvalib-photo-grid.js +121 -19
  99. package/dist-cdn/uvalib-photo-grid.js.map +1 -1
  100. package/dist-cdn/uvalib-results-count.js +101 -0
  101. package/dist-cdn/uvalib-results-count.js.map +1 -0
  102. package/dist-cdn/uvalib-tabs.js +436 -0
  103. package/dist-cdn/uvalib-tabs.js.map +1 -0
  104. package/dist-cdn/uvalib-tag-list.js +267 -0
  105. package/dist-cdn/uvalib-tag-list.js.map +1 -0
  106. package/package.json +24 -3
  107. package/skills/uvalib-web-components/SKILL.md +206 -19
  108. package/skills/uvalib-web-components/reference/components.md +220 -6
  109. package/dist-cdn/chunks/site-header-C9V7Wuw2.js.map +0 -1
  110. package/dist-cdn/chunks/source-children-RuAec527.js +0 -119
  111. package/dist-cdn/chunks/source-children-RuAec527.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"uvalib-lightbox.js","names":["unsafeCSS","nothing","_decorate","property","state","n","i","r$1","b","define","__decorate","r","installLightDomStyles","UvalibElement","trackEvent","accessible","REGION","ROTATION","QUALITY","BROWSER_IMAGE","DATA_IMAGE","parseIiif","url","href","base","parts","file","rotation","region","sizedIiifUrl","parsed","width","w","height","h","iiifIdentifier","viewportIiifSize","dpr","view","usableImageUrl","usesHashParam","hash","paramFromLocation","name","loc","q","hrefWithParam","hashMode","path","params","id","qs","normalize","s","structuralRules","host","shadowStructure","nextCaption","UvalibLightbox","_args","link","slides","queued","rtl","back","forward","root","sheet","mount","light","dialog","src","changed","node","next","current","at","found","detailRoots","noteDetails","a","el","candidates","push","owner","unique","pos","img","alt","text","caption","index","walk","already","delta","action","pushed","source","prev","mode","observer","trigger","again","active","slide","position","pool","add","item","f","want","key","keep","still","box","parent","full","shown","counter","A"],"sources":["../src/components/uvalib-lightbox/media.ts","../src/components/uvalib-lightbox/UvalibLightbox.ts","../src/components/uvalib-lightbox/uvalib-lightbox.ts"],"sourcesContent":["/** Location pieces the deep-link helpers read and write. `search` includes the leading `?`. */\nexport interface PageLocation {\n pathname: string;\n search: string;\n hash: string;\n}\n\nconst REGION = /^(full|square|max|pct:[^/]+|\\d+,\\d+,\\d+,\\d+)$/i;\nconst ROTATION = /^!?\\d+(\\.\\d+)?$/;\nconst QUALITY = /^(default|color|gray|grey|bitonal|native)\\.(jpe?g|png|gif|webp|tiff?|jp2)$/i;\n/** Formats a browser can paint. TIFF and JPEG2000 are left unchanged. */\nconst BROWSER_IMAGE = /\\.(jpe?g|png|gif|webp)$/i;\n/** Full size may offer these `data:` images. SVG is never one: it can carry a script. */\nconst DATA_IMAGE = /^image\\/(png|jpeg|gif|webp)($|[;,])/i;\n\nexport interface IiifRequest {\n url: URL;\n /** Path segments, with a leading `''` for an absolute path. */\n parts: string[];\n regionIndex: number;\n sizeIndex: number;\n}\n\n/**\n * A IIIF Image API request, recognised from the end of the path:\n * `/{region}/{size}/{rotation}/{quality}.{format}`. The identifier may contain slashes\n * and colons (`uva-lib:286686`). Anything else, including an image that merely lives\n * under a `/full/` folder, is not one.\n */\nexport function parseIiif(href: string, base: string): IiifRequest | null {\n let url: URL;\n try {\n url = new URL(href, base);\n } catch {\n return null;\n }\n if (url.protocol !== 'http:' && url.protocol !== 'https:') return null;\n const parts = url.pathname.split('/');\n if (parts.length < 5) return null;\n const file = parts[parts.length - 1] ?? '';\n const rotation = parts[parts.length - 2] ?? '';\n const region = parts[parts.length - 4] ?? '';\n if (!QUALITY.test(file) || !ROTATION.test(rotation) || !REGION.test(region)) return null;\n return { url, parts, regionIndex: parts.length - 4, sizeIndex: parts.length - 3 };\n}\n\n/**\n * The same image with only the size segment rewritten to `!w,h`, so the server sends a size\n * that fits `w` by `h` device pixels and does not scale the original up. The region stays\n * (a crop or `square` is kept). Returns null when `href` is not IIIF, and for a TIFF or\n * JPEG2000 request, which is left exactly as written.\n */\nexport function sizedIiifUrl(href: string, base: string, w: number, h: number): string | null {\n const parsed = parseIiif(href, base);\n if (!parsed) return null;\n const file = parsed.parts[parsed.parts.length - 1] ?? '';\n if (!BROWSER_IMAGE.test(file)) return null;\n const width = Math.max(1, Math.round(w));\n const height = Math.max(1, Math.round(h));\n parsed.parts[parsed.sizeIndex] = `!${width},${height}`;\n parsed.url.pathname = parsed.parts.join('/');\n return parsed.url.toString();\n}\n\n/** The IIIF identifier (the segment before the region), for a stable deep-link id. */\nexport function iiifIdentifier(href: string, base: string): string | null {\n const parsed = parseIiif(href, base);\n if (!parsed) return null;\n const id = parsed.parts[parsed.regionIndex - 1];\n return id || null;\n}\n\n/** CSS pixels of the viewport, in device pixels, capped so a request stays reasonable. */\nexport function viewportIiifSize(\n view: Pick<Window, 'innerWidth' | 'innerHeight' | 'devicePixelRatio'>,\n): {\n w: number;\n h: number;\n} {\n const dpr = Math.min(view.devicePixelRatio || 1, 2);\n const w = Math.max(1, Math.min(2000, Math.round((view.innerWidth || 800) * dpr)));\n const h = Math.max(1, Math.min(2000, Math.round((view.innerHeight || 600) * dpr)));\n return { w, h };\n}\n\n/**\n * Whether `href` may be offered as Full size: an http(s) URL (including a relative one), or\n * a `data:` image of type PNG, JPEG, GIF or WebP. SVG and every other scheme are refused.\n */\nexport function usableImageUrl(href: string, base: string): boolean {\n try {\n const url = new URL(href, base);\n if (url.protocol === 'http:' || url.protocol === 'https:') return true;\n if (url.protocol === 'data:') return DATA_IMAGE.test(url.pathname);\n return false;\n } catch {\n return false;\n }\n}\n\n/** A hash used as a route (`#/…`, `#!/…`) or that already carries a query string. */\nexport function usesHashParam(hash: string): boolean {\n return hash.startsWith('#/') || hash.startsWith('#!/') || hash.includes('?');\n}\n\n/** The deep-link id in `loc`, from the hash query on a hash route and the search string otherwise. */\nexport function paramFromLocation(loc: PageLocation, name: string): string | null {\n if (!name) return null;\n if (usesHashParam(loc.hash)) {\n const q = loc.hash.indexOf('?');\n const params = new URLSearchParams(q >= 0 ? loc.hash.slice(q + 1) : '');\n return params.get(name);\n }\n return new URLSearchParams(loc.search).get(name);\n}\n\n/**\n * `loc` with `name` set to `id`, or removed when `id` is null. Hash routes keep the param in\n * the hash (`#/text/d9?photo=2`) and leave `search` alone; every other URL uses `search` and\n * keeps the hash. The hash is written as text so a `?` in it is not percent-encoded.\n * `hashMode` forces the hash (or the search) when the caller is mid-rewrite and the hash no\n * longer shows that it was a route, as when `?photo=` was just removed from `#chapter?photo=1`.\n */\nexport function hrefWithParam(\n loc: PageLocation,\n name: string,\n id: string | null,\n hashMode?: boolean,\n): string {\n if (hashMode ?? usesHashParam(loc.hash)) {\n const q = loc.hash.indexOf('?');\n const path = q >= 0 ? loc.hash.slice(0, q) : loc.hash;\n const params = new URLSearchParams(q >= 0 ? loc.hash.slice(q + 1) : '');\n if (id) params.set(name, id);\n else params.delete(name);\n const qs = params.toString();\n return loc.pathname + loc.search + (qs ? `${path}?${qs}` : path);\n }\n const params = new URLSearchParams(loc.search);\n if (id) params.set(name, id);\n else params.delete(name);\n const qs = params.toString();\n return loc.pathname + (qs ? `?${qs}` : '') + loc.hash;\n}\n","import { css, html, nothing, unsafeCSS, type PropertyValues } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { trackEvent } from '../../base/analytics.js';\nimport { UvalibElement } from '../../base/UvalibElement.js';\nimport { installLightDomStyles } from '../../base/light-dom-styles.js';\nimport { accessible } from '../../styles/accessible.js';\nimport {\n hrefWithParam,\n iiifIdentifier,\n paramFromLocation,\n sizedIiifUrl,\n usableImageUrl,\n usesHashParam,\n viewportIiifSize,\n type PageLocation,\n} from './media.js';\n\n/** One image in the set, in document order. */\ninterface Slide {\n el: HTMLAnchorElement;\n /** Deep-link id: `data-id`, else the element's id, else the IIIF identifier, else the position. */\n id: string;\n /** The href as written. */\n href: string;\n caption: string;\n alt: string;\n /** `data-details-id`, when the slide has its own details element. */\n detailsId: string | null;\n}\n\nconst normalize = (s: unknown) =>\n String(s ?? '')\n .replace(/\\s+/g, ' ')\n .trim();\n\n/**\n * Kept with `no-style`: the triggers stay put, `[hidden]` hides, the dialog hugs its panel\n * (so a click outside it is the backdrop), controls are at least 44px, and the image stays\n * within the viewport. `host` is `:host` (shadow) or the tag (light DOM).\n */\nconst structuralRules = (host: string) => `\n ${host} { display: block; }\n ${host} .viewer { display: contents; }\n ${host} dialog {\n margin: auto;\n padding: 0;\n border: none;\n background: transparent;\n width: min(72rem, calc(100% - 2rem));\n max-height: calc(100% - 2rem);\n }\n ${host} .panel {\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n gap: 0.75rem;\n max-height: calc(100dvh - 2rem);\n overflow: auto;\n overscroll-behavior: contain;\n padding: 0.75rem;\n }\n ${host} .head, ${host} .toolbar {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: 0.5rem;\n }\n ${host} .head { justify-content: space-between; }\n ${host} .caption { margin: 0; min-width: 0; overflow-wrap: anywhere; }\n ${host} .figure { margin: 0; }\n ${host} dialog img { display: block; max-width: 100%; max-height: 70dvh; width: auto; height: auto; margin: auto; }\n ${host} .count, ${host} .status { margin: 0; }\n ${host} dialog button, ${host} dialog .full {\n box-sizing: border-box;\n min-width: 44px;\n min-height: 44px;\n padding: 0.5rem 0.75rem;\n font: inherit;\n }\n ${host} .details:empty { display: none; }\n ${host} > [slot=\"details\"] { display: none; }\n ${host}[hidden], ${host} [hidden] { display: none !important; }\n`;\nconst shadowStructure = unsafeCSS(structuralRules(':host'));\n\nlet nextCaption = 0;\n\n/**\n * An accessible image viewer over a set of plain links. With JavaScript a primary click opens\n * a modal dialog; without it (or with a modified click) the link opens the image as before.\n * Wrap the links, or point at them with `selector` (for example `a.pb-image` on a reading\n * page). There is no autoplay and no carousel.\n *\n * The dialog is labelled by the caption (`data-caption`, else the image alt, else the link\n * text). Focus moves to Close on open and back to the trigger on close. Escape and a click on\n * the backdrop close it. With more than one image, Previous and Next and the arrow keys move\n * through the set (wrapping), and a polite “3 of 13” counter is shown. Full size opens the\n * original image in a new tab. A IIIF Image API URL keeps its region; only the size becomes\n * `!W,H` for the viewport. TIFF and JPEG2000 URLs are left as written. `url-param` (for\n * example `photo`) keeps `?photo=<id>` in sync, including on a hash route\n * (`#/text?photo=<id>`): opening pushes a history entry, stepping replaces it, and\n * Back closes.\n *\n * Optional details: children with `slot=\"details\"` (and `data-for` equal to the item's id or\n * its position from 1; without `data-for` they show for every image), or `data-details-id` on\n * a link pointing at an element elsewhere on the page. Either is shown inside the dialog and\n * put back when the viewer moves on or closes.\n *\n * @tagname uvalib-lightbox\n * @slot - The image links. A plain click opens the viewer; without JavaScript they open the image.\n * @slot details - Details for the open image. `data-for` selects one item by its id or position (from 1); without it the details show for every image.\n * @csspart dialog - The modal dialog.\n * @csspart panel - The surface inside the dialog.\n * @csspart caption - The caption that names the dialog.\n * @csspart image - The image.\n * @csspart controls - Previous, Next, the counter and Full size.\n * @csspart details - The details panel.\n * @fires 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). Never the URL or the caption. Not fired for a viewer restored from the URL or from Back and Forward. Bubbles and is composed.\n * @cssprop --uva-color-surface-raised - Dark-mode role token: dialog surface (else `--uva-color-surface`, else #fff).\n * @cssprop --uva-color-surface - Dark-mode role token: the figure behind the image (else #fff).\n * @cssprop --uva-color-text - Dark-mode role token: text (else `--uva-grey-darkest`).\n * @cssprop --uva-color-shadow - Dark-mode role token: the backdrop scrim (else rgba(16, 23, 43, 0.72)).\n * @cssprop --uva-color-border - Dark-mode role token: dialog border (else `--uva-grey-100`).\n * @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).\n * @cssprop --uva-color-link - Dark-mode role token: Full size text when it is not the filled control (else `--uva-brand-blue`).\n * @cssprop --uva-color-accent-bg - Dark-mode role token: Close and Full size background (else `--uva-brand-blue`).\n * @cssprop --uva-color-on-accent - Text on those controls (else #fff).\n * @cssprop [--uva-brand-orange=#e57200] - Focus ring when `--uva-color-focus` is unset.\n * @cssprop [--uva-brand-blue=#232d4b] - Control background when `--uva-color-accent-bg` is unset.\n * @cssprop [--uva-grey-darkest=#2b2b2b] - Text when `--uva-color-text` is unset.\n * @cssprop [--uva-grey-100=#dadada] - Border when `--uva-color-border` is unset.\n */\nexport class UvalibLightbox extends UvalibElement {\n static styles = [\n accessible,\n shadowStructure,\n css`\n .panel {\n background: var(--uva-color-surface-raised, var(--uva-color-surface, #fff));\n color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));\n border: 1px solid var(--uva-color-border, var(--uva-grey-100, #dadada));\n }\n dialog::backdrop {\n background: var(--uva-color-shadow, rgba(16, 23, 43, 0.72));\n }\n .details a {\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n }\n .figure {\n background: var(--uva-color-surface, #fff);\n }\n .caption {\n font-size: 1.125rem;\n line-height: 1.4;\n font-weight: 600;\n }\n .count {\n font-variant-numeric: tabular-nums;\n }\n dialog button,\n dialog .full {\n padding: 0.5rem 0.75rem;\n border: 2px solid transparent;\n text-decoration: none;\n cursor: pointer;\n color: var(--uva-color-on-accent, #fff);\n background: var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b));\n }\n dialog button:focus-visible,\n dialog .full:focus-visible {\n outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));\n outline-offset: 2px;\n }\n dialog button.prev,\n dialog button.next {\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n background: var(--uva-color-surface, #fff);\n border-color: var(--uva-color-border, var(--uva-grey-100, #dadada));\n }\n .status {\n font-size: 1rem;\n }\n @media (prefers-reduced-motion: no-preference) {\n .panel {\n animation: uvalib-lightbox-in 0.15s ease;\n }\n }\n @media (prefers-reduced-motion: reduce) {\n dialog,\n dialog * {\n animation: none !important;\n transition: none !important;\n scroll-behavior: auto !important;\n }\n }\n @media (forced-colors: active) {\n .panel,\n dialog button,\n dialog .full {\n border: 1px solid CanvasText;\n }\n }\n @keyframes uvalib-lightbox-in {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n }\n `,\n ];\n\n /**\n * CSS selector for image links elsewhere in this root (the page, or the shadow root the\n * component sits in). Combined with any links inside the component. Example: `a.pb-image`.\n */\n @property({ type: String }) selector = '';\n\n /**\n * Query parameter kept in sync with the open image, for example `photo` → `?photo=<id>`.\n * The id is the link's `data-id`, else its `id`, else the IIIF identifier, else its position\n * from 1. On a hash route the parameter is written inside the hash. Empty: no deep link.\n */\n @property({ attribute: 'url-param' }) urlParam = '';\n\n @state() private slides: Slide[] = [];\n @state() private index = 0;\n @state() private open = false;\n @state() private status: 'loading' | 'ready' | 'error' = 'loading';\n @state() private fitW = 0;\n @state() private fitH = 0;\n\n private readonly captionId = `uvalib-lightbox-caption-${++nextCaption}`;\n /** Where the dialog is rendered. Light DOM renders here so the author's links stay put. */\n private mount?: HTMLElement;\n private trigger: HTMLAnchorElement | null = null;\n /** The open image pushed a history entry, so Back (and Close) returns to the page. */\n private historyPushed = false;\n /** The visitor closed the viewer; a later mutation must not reopen it from the URL. */\n private userClosed = false;\n /** Disconnect (and the dialog it closes) is not a visitor action, so it must not touch history. */\n private suppressClose = false;\n private warnedSelector = false;\n private lastSrc = '';\n private observer?: MutationObserver;\n private syncQueued = false;\n private resizeTimer = 0;\n /** A close event from the dialog we just shut must not dismiss the next open. */\n private ignoreClose = false;\n private dismissing = false;\n private revealTries = 0;\n private revealFrame = 0;\n private listened = false;\n /** The root `listen` bound, so disconnect can remove the listener after leaving a shadow root. */\n private listenRoot?: Document | ShadowRoot;\n /**\n * `dialog.close()` removes `open` now and fires `close` on a later task. The attribute\n * observer runs as a microtask, which is what a caller sees after `await updateComplete`.\n */\n private dialogObserver?: MutationObserver;\n private observedDialog?: HTMLDialogElement;\n /** `history.back()` from Close has not fired `popstate` yet. */\n private pendingBack = false;\n /** Whether that entry kept the parameter in the hash. The pop leaves a hash that may not say so. */\n private backInHash = false;\n /** An image chosen while that Back is still in flight, opened once the popstate arrives. */\n private queuedOpen: { i: number; slides: Slide[] } | null = null;\n /**\n * Set while a history traversal is opening the dialog. The traversal can close the\n * dialog it just showed; that close is not the visitor, so show it again.\n */\n private reopenGuard = false;\n /** Details elements moved into the dialog, and where they go back to. */\n private parked: { el: HTMLElement; parent: Node; next: ChildNode | null; hidden: boolean }[] = [];\n private parkedKey = '';\n\n /** Shadow mode follows the base class. Light mode renders into `.viewer`. */\n private get isLight(): boolean {\n return this.noShadowDom || this.hasAttribute('no-shadow-dom');\n }\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n if (!this.isLight) {\n const root = super.createRenderRoot();\n if (this.noStyle && root instanceof ShadowRoot) {\n const sheets = [accessible.styleSheet, shadowStructure.styleSheet].filter(\n (sheet): sheet is CSSStyleSheet => sheet != null,\n );\n root.adoptedStyleSheets = sheets;\n }\n return root;\n }\n const mount = this.ownerDocument.createElement('div');\n mount.className = 'viewer';\n this.mount = mount;\n this.append(mount);\n return mount;\n }\n\n override connectedCallback(): void {\n const light = this.isLight;\n super.connectedCallback();\n // A move in the DOM disconnects and reconnects. The disconnect guard must not stick,\n // or Escape would close the dialog and leave the viewer thinking it is still open.\n this.suppressClose = false;\n if (light) this.installLight(light);\n this.listen();\n this.slides = this.collect();\n this.watch();\n this.openFromUrl();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.unlisten();\n this.observer?.disconnect();\n this.dialogObserver?.disconnect();\n this.dialogObserver = undefined;\n this.observedDialog = undefined;\n window.clearTimeout(this.resizeTimer);\n this.cancelReveal();\n this.restoreDetails();\n this.pendingBack = false;\n this.queuedOpen = null;\n this.reopenGuard = false;\n // Closing the dialog here fires `close` synchronously. That is not the visitor dismissing\n // it: do not run history.back(), which could leave the page. `open` goes false so a later\n // connect can open again from the URL.\n this.suppressClose = true;\n this.open = false;\n const dialog = this.dialogEl;\n if (dialog?.open) dialog.close();\n this.suppressClose = false;\n this.ignoreClose = false;\n }\n\n protected override willUpdate(): void {\n if (!this.open) {\n this.lastSrc = '';\n return;\n }\n const src = this.displaySrc;\n if (src !== this.lastSrc) {\n this.lastSrc = src;\n this.status = src ? 'loading' : 'error';\n } else if (!src && this.status !== 'error') {\n // A refused URL (javascript:) has an empty src. On the first open `lastSrc` is already\n // empty, so the change above does not run, and the status would stay \"loading\".\n this.status = 'error';\n }\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (changed.has('selector')) this.watch();\n if (!this.open) {\n if (changed.has('open')) this.restoreDetails();\n return;\n }\n if (changed.has('open') || changed.has('index') || changed.has('slides')) this.placeDetails();\n this.bindDialogObserver();\n if (changed.has('open')) this.reveal();\n // Reading the image and writing `status` from inside `updated` makes Lit warn and schedule\n // a nested update. A microtask is still before the next paint.\n queueMicrotask(() => {\n if (this.isConnected) this.settleImage();\n });\n }\n\n private installLight(light: boolean): void {\n if (!light) return;\n const node = this.getRootNode();\n const root = node instanceof Document || node instanceof ShadowRoot ? node : undefined;\n if (this.noStyle) {\n installLightDomStyles(\n `${this.localName}::structure`,\n unsafeCSS(structuralRules(this.localName)),\n { root, scope: false },\n );\n installLightDomStyles(`${this.localName}::a11y`, accessible, { root });\n return;\n }\n installLightDomStyles(\n this.localName,\n (this.constructor as typeof UvalibElement).elementStyles,\n {\n root,\n },\n );\n }\n\n private get scope(): Document | ShadowRoot {\n const root = this.getRootNode();\n return root instanceof Document || root instanceof ShadowRoot ? root : this.ownerDocument;\n }\n\n private get base(): string {\n return this.ownerDocument.baseURI || location.href;\n }\n\n private loc(): PageLocation {\n return { pathname: location.pathname, search: location.search, hash: location.hash };\n }\n\n private listen(): void {\n if (this.listened) return;\n this.listened = true;\n this.listenRoot = this.scope;\n this.listenRoot.addEventListener('click', this.onClick, true);\n window.addEventListener('popstate', this.onPop);\n window.addEventListener('resize', this.onResize);\n }\n\n private unlisten(): void {\n if (!this.listened) return;\n this.listened = false;\n this.listenRoot?.removeEventListener('click', this.onClick, true);\n this.listenRoot = undefined;\n window.removeEventListener('popstate', this.onPop);\n window.removeEventListener('resize', this.onResize);\n }\n\n private watch(): void {\n this.observer?.disconnect();\n this.observer = new MutationObserver(() => this.scheduleSync());\n this.observer.observe(this, {\n attributes: true,\n attributeFilter: [\n 'href',\n 'id',\n 'alt',\n 'title',\n 'data-caption',\n 'data-id',\n 'data-details-id',\n 'slot',\n ],\n childList: true,\n subtree: true,\n });\n if (this.selector) this.observer.observe(this.scope, { childList: true, subtree: true });\n }\n\n /** Ignore mutations inside the viewer (the dialog, parked details) so a render cannot loop. */\n private scheduleSync(): void {\n if (this.syncQueued) return;\n this.syncQueued = true;\n queueMicrotask(() => {\n this.syncQueued = false;\n if (!this.isConnected) return;\n const next = this.collect();\n const same =\n next.length === this.slides.length &&\n next.every(\n (s, i) =>\n s.el === this.slides[i]?.el &&\n s.href === this.slides[i]?.href &&\n s.id === this.slides[i]?.id &&\n s.caption === this.slides[i]?.caption &&\n s.detailsId === this.slides[i]?.detailsId,\n );\n if (!same) {\n const current = this.current?.el;\n this.slides = next;\n if (this.open) {\n const at = current ? next.findIndex((s) => s.el === current) : -1;\n if (at >= 0) this.index = at;\n else if (!next.length) this.dismiss('empty');\n else this.index = Math.min(this.index, next.length - 1);\n }\n }\n if (!this.open) this.openFromUrl();\n });\n }\n\n private collect(): Slide[] {\n const found: HTMLAnchorElement[] = [];\n const detailRoots = new Set<Element>();\n const noteDetails = (a: Element) => {\n if (!(a instanceof HTMLAnchorElement)) return;\n const id = a.getAttribute('data-details-id');\n if (!id) return;\n const el = this.scope.getElementById(id);\n if (el) detailRoots.add(el);\n };\n const candidates: Element[] = [...this.querySelectorAll('a[href]')];\n if (this.selector) {\n try {\n candidates.push(...this.scope.querySelectorAll(this.selector));\n } catch {\n if (!this.warnedSelector) {\n this.warnedSelector = true;\n console.warn(\n `${this.localName}: selector ${JSON.stringify(this.selector)} is not a valid CSS selector.`,\n );\n }\n }\n }\n for (const a of candidates) noteDetails(a);\n const push = (a: Element) => {\n if (!(a instanceof HTMLAnchorElement) || !a.hasAttribute('href')) return;\n if (a.closest('[hidden]')) return;\n if (this.mount?.contains(a) || a.closest('dialog')) return;\n if (a.closest('[slot=\"details\"]')) return;\n for (const root of detailRoots) {\n if (root.contains(a)) return;\n }\n const owner = a.closest('uvalib-lightbox');\n if (owner && owner !== this) return;\n found.push(a);\n };\n for (const a of candidates) push(a);\n const unique = [...new Set(found)];\n unique.sort((a, b) => {\n if (a === b) return 0;\n const pos = a.compareDocumentPosition(b);\n if (pos & Node.DOCUMENT_POSITION_FOLLOWING) return -1;\n if (pos & Node.DOCUMENT_POSITION_PRECEDING) return 1;\n return 0;\n });\n return unique.map((el, i) => this.slide(el, i));\n }\n\n private slide(el: HTMLAnchorElement, index: number): Slide {\n const href = el.getAttribute('href') ?? '';\n const img = el.querySelector('img');\n const alt = normalize(img?.getAttribute('data-uvalib-alt') || img?.getAttribute('alt'));\n const text = this.linkText(el);\n const caption =\n normalize(el.dataset.caption) ||\n alt ||\n text ||\n normalize(el.getAttribute('title')) ||\n 'Image';\n const id =\n normalize(el.dataset.id) || el.id || iiifIdentifier(href, this.base) || String(index + 1);\n return {\n el,\n id,\n href,\n caption,\n alt: alt || caption,\n detailsId: normalize(el.dataset.detailsId) || null,\n };\n }\n\n /** The link's own text, not the alt of its image and not a details subtree. */\n private linkText(el: HTMLAnchorElement): string {\n const parts: string[] = [];\n const walk = (n: Node) => {\n if (n instanceof HTMLImageElement) return;\n if (n instanceof HTMLElement && (n.hidden || n.getAttribute('slot') === 'details')) return;\n if (n.nodeType === Node.TEXT_NODE) {\n parts.push(n.textContent ?? '');\n return;\n }\n n.childNodes.forEach(walk);\n };\n el.childNodes.forEach(walk);\n return normalize(parts.join(' '));\n }\n\n private get current(): Slide | undefined {\n return this.slides[this.index];\n }\n\n private get multiple(): boolean {\n return this.slides.length > 1;\n }\n\n /** The URL the `<img>` should load: a viewport-sized IIIF request, or the href itself. */\n private get displaySrc(): string {\n const href = this.current?.href ?? '';\n if (!usableImageUrl(href, this.base)) return '';\n const w = this.fitW || viewportIiifSize(window).w;\n const h = this.fitH || viewportIiifSize(window).h;\n return sizedIiifUrl(href, this.base, w, h) ?? href;\n }\n\n private measure(): void {\n const { w, h } = viewportIiifSize(window);\n if (w !== this.fitW) this.fitW = w;\n if (h !== this.fitH) this.fitH = h;\n }\n\n private readonly onResize = (): void => {\n if (!this.open) return;\n window.clearTimeout(this.resizeTimer);\n this.resizeTimer = window.setTimeout(() => {\n if (this.isConnected && this.open) this.measure();\n }, 150);\n };\n\n private readonly onClick = (e: Event): void => {\n if (\n !(e instanceof MouseEvent) ||\n e.button !== 0 ||\n e.metaKey ||\n e.ctrlKey ||\n e.shiftKey ||\n e.altKey\n )\n return;\n const link = this.linkFrom(e);\n if (!link) return;\n const slides = this.collect();\n const i = slides.findIndex((s) => s.el === link);\n if (i < 0) return;\n e.preventDefault();\n this.activate(i, slides);\n };\n\n private linkFrom(e: Event): HTMLAnchorElement | null {\n for (const n of e.composedPath()) {\n if (n instanceof HTMLAnchorElement) return n;\n }\n const t = e.target;\n return t instanceof Element ? t.closest('a[href]') : null;\n }\n\n /** A visitor chose `slides[i]`. The first open pushes a history entry; a later choice replaces it. */\n private activate(i: number, slides: Slide[]): void {\n const already = this.open;\n if (already && this.index === i) return;\n this.slides = slides;\n this.index = i;\n this.trigger = slides[i]?.el ?? null;\n this.userClosed = false;\n this.measure();\n this.open = true;\n if (this.pendingBack) {\n // Close already asked for history.back(). Writing now would push on the entry that\n // popstate is about to remove, and that pop would shut the viewer again.\n this.queuedOpen = { i, slides };\n } else if (this.urlParam) {\n const id = slides[i]?.id ?? null;\n const hashMode = usesHashParam(location.hash);\n if (already) this.writeParam(id, 'replace', hashMode);\n else {\n // The address can already carry this param (a leftover entry). Replace it away\n // on the current entry, then push, so Back still closes onto this page. Both\n // writes share hashMode: stripping `?photo` from `#chapter?photo=1` leaves\n // `#chapter`, which would otherwise fall out of the hash.\n if (paramFromLocation(this.loc(), this.urlParam))\n this.writeParam(null, 'replace', hashMode);\n this.historyPushed = this.writeParam(id, 'push', hashMode);\n }\n }\n trackEvent(this, ['uvalib-lightbox', 'open', `image ${i + 1}`, i + 1]);\n }\n\n /** Restore a viewer the URL already points at. No analytics: it is not a new action. */\n private openFromUrl(): void {\n if (this.open || this.userClosed || !this.urlParam) return;\n const id = paramFromLocation(this.loc(), this.urlParam);\n if (!id) return;\n const slides = this.slides.length ? this.slides : this.collect();\n const i = slides.findIndex((s) => s.id === id);\n if (i < 0) return;\n this.slides = slides;\n this.index = i;\n this.trigger = slides[i]?.el ?? null;\n this.measure();\n // Make Back close the viewer onto this page instead of leaving it. Remember the hash\n // route before the first write removes the `?` that marked it.\n const hashMode = usesHashParam(location.hash);\n this.writeParam(null, 'replace', hashMode);\n this.historyPushed = this.writeParam(id, 'push', hashMode);\n this.open = true;\n }\n\n private step(delta: number): void {\n const n = this.slides.length;\n if (n < 2) return;\n const i = (this.index + delta + n) % n;\n this.index = i;\n this.trigger = this.slides[i]?.el ?? this.trigger;\n if (this.urlParam) this.writeParam(this.slides[i]?.id ?? null, 'replace');\n const action = delta < 0 ? 'previous' : 'next';\n trackEvent(this, ['uvalib-lightbox', action, `image ${i + 1}`, i + 1]);\n }\n\n /**\n * Close. `ui` is Close, Escape or the backdrop (Back when this viewer pushed, else drop the\n * param). `pop` is the browser already moving: the URL is already right. `empty` is the\n * last image leaving the page: drop the param and do not reopen from it.\n */\n private dismiss(source: 'ui' | 'pop' | 'empty'): void {\n if (this.dismissing) return;\n const dialog = this.dialogEl;\n if (!this.open && !dialog?.open) return;\n this.dismissing = true;\n try {\n const pushed = this.historyPushed;\n this.historyPushed = false;\n this.ignoreClose = true;\n this.cancelReveal();\n this.open = false;\n if (source === 'ui' || source === 'empty') this.userClosed = true;\n this.restoreDetails();\n if (dialog?.open) dialog.close();\n this.focusTrigger();\n if (source === 'ui' && this.urlParam) {\n if (pushed) {\n this.backInHash = usesHashParam(location.hash);\n this.pendingBack = true;\n history.back();\n } else this.writeParam(null, 'replace', usesHashParam(location.hash));\n } else if (source === 'empty' && this.urlParam) {\n this.pendingBack = false;\n this.queuedOpen = null;\n this.writeParam(null, 'replace', usesHashParam(location.hash));\n }\n } finally {\n // Leave `ignoreClose` set. `dialog.close()` can queue a second close event for the\n // next task; clearing the guard here lets that event dismiss a viewer that has\n // already been opened again. `reveal` clears it once `showModal` has succeeded, which\n // is still before a later Escape. A throw while restoring details must not leave the\n // viewer stuck dismissing.\n this.dismissing = false;\n }\n }\n\n /** Returns false when this document cannot change the address (for example an iframe srcdoc). */\n private writeParam(id: string | null, mode: 'push' | 'replace', hashMode?: boolean): boolean {\n if (!this.urlParam) return false;\n const next = hrefWithParam(this.loc(), this.urlParam, id, hashMode);\n const now = location.pathname + location.search + location.hash;\n if (next === now) return false;\n const prev = history.state && typeof history.state === 'object' ? history.state : {};\n try {\n history[mode === 'push' ? 'pushState' : 'replaceState'](\n { ...prev, uvalibLightbox: this.urlParam },\n '',\n next,\n );\n return true;\n } catch {\n // A sandboxed document (an iframe srcdoc) cannot take a history entry. The viewer\n // still opens; the address is left as it is.\n return false;\n }\n }\n\n private readonly onPop = (): void => {\n if (!this.urlParam) return;\n if (this.pendingBack) {\n this.pendingBack = false;\n const queued = this.queuedOpen;\n this.queuedOpen = null;\n if (!this.isConnected || !queued) return;\n this.slides = queued.slides;\n this.index = queued.i;\n this.trigger = queued.slides[queued.i]?.el ?? null;\n this.userClosed = false;\n this.measure();\n const id = queued.slides[queued.i]?.id ?? null;\n this.historyPushed = this.writeParam(id, 'push', this.backInHash);\n if (!this.open) this.open = true;\n return;\n }\n const id = paramFromLocation(this.loc(), this.urlParam);\n if (!id) {\n this.historyPushed = false;\n if (this.open) this.dismiss('pop');\n return;\n }\n this.userClosed = false;\n const slides = this.collect();\n const i = slides.findIndex((s) => s.id === id);\n if (i < 0) {\n if (this.open) this.dismiss('pop');\n return;\n }\n this.slides = slides;\n this.index = i;\n this.trigger = slides[i]?.el ?? null;\n this.historyPushed = true;\n this.measure();\n this.armReopenGuard();\n if (!this.open) this.open = true;\n };\n\n /** Ignore the close event a history traversal fires on the dialog it just opened. */\n private armReopenGuard(): void {\n this.reopenGuard = true;\n const view = this.ownerDocument.defaultView;\n if (!view) return;\n view.requestAnimationFrame(() => {\n this.reopenGuard = false;\n });\n }\n\n private readonly onKey = (e: KeyboardEvent): void => {\n if (!this.multiple || this.typing(e)) return;\n // Left is previous in LTR and next in RTL, so the key matches the direction of the set.\n const rtl = getComputedStyle(this).direction === 'rtl';\n const back = rtl ? 'ArrowRight' : 'ArrowLeft';\n const forward = rtl ? 'ArrowLeft' : 'ArrowRight';\n if (e.key !== back && e.key !== forward) return;\n if (e.altKey || e.metaKey || e.ctrlKey) return;\n e.preventDefault();\n this.step(e.key === forward ? 1 : -1);\n };\n\n private typing(e: KeyboardEvent): boolean {\n const t = e.target;\n if (!(t instanceof HTMLElement)) return false;\n return t.isContentEditable || !!t.closest('input, textarea, select');\n }\n\n private readonly onDialogClick = (e: MouseEvent): void => {\n if (e.target === this.dialogEl) this.dismiss('ui');\n };\n\n /** The dialog element is stable across renders. Watch `open` on whichever node is current. */\n private bindDialogObserver(): void {\n const dialog = this.dialogEl;\n if (!dialog || dialog === this.observedDialog) return;\n this.dialogObserver?.disconnect();\n this.observedDialog = dialog;\n const observer = new MutationObserver(() => this.onNativeClose());\n observer.observe(dialog, { attributes: true, attributeFilter: ['open'] });\n this.dialogObserver = observer;\n }\n\n private readonly onDialogClose = (): void => {\n this.onNativeClose();\n };\n\n /**\n * Escape, the backdrop's close, and a direct `dialog.close()` all clear `open`. The\n * event itself is a later task; the attribute change is observable on the microtask\n * that `await updateComplete` flushes. A close that leaves the dialog open (a queued\n * event after `showModal`, or a history traversal) is not the visitor dismissing it.\n */\n private onNativeClose(): void {\n if (this.ignoreClose || this.suppressClose || !this.open) return;\n if (this.dialogEl?.open) return;\n if (this.reopenGuard) {\n const view = this.ownerDocument.defaultView;\n view?.queueMicrotask(() => {\n if (this.open && this.isConnected && !this.dialogEl?.open) this.reveal();\n });\n return;\n }\n this.dismiss('ui');\n }\n\n private readonly onFullSize = (): void => {\n const i = this.index;\n trackEvent(this, ['uvalib-lightbox', 'full-size', `image ${i + 1}`, i + 1]);\n };\n\n private get dialogEl(): HTMLDialogElement | null {\n return this.renderRoot.querySelector('dialog');\n }\n\n private get closeBtn(): HTMLButtonElement | null {\n return this.renderRoot.querySelector('button.close');\n }\n\n private get detailsBox(): HTMLElement | null {\n return this.renderRoot.querySelector('.details');\n }\n\n private focusTrigger(): void {\n const trigger = this.trigger;\n if (trigger?.isConnected) trigger.focus();\n }\n\n /**\n * Open the dialog and focus Close. `showModal` can throw while a dialog is still leaving\n * the top layer (a reopen from Back/Forward, or the first paint), so try again on the next\n * frames. Those frames are queued before a test's own `nextFrame`.\n */\n /** History restore can drop the light-DOM mount or orphan a shadow root. Put it back. */\n private ensureRoot(): void {\n const root = this.renderRoot;\n if (!this.isConnected) return;\n if (root instanceof HTMLElement && !root.isConnected) this.append(root);\n if (root instanceof ShadowRoot && this.shadowRoot && root !== this.shadowRoot) {\n (this as unknown as { renderRoot: ShadowRoot }).renderRoot = this.shadowRoot;\n this.requestUpdate();\n }\n }\n\n private cancelReveal(): void {\n const view = this.ownerDocument.defaultView;\n if (this.revealFrame && view) view.cancelAnimationFrame(this.revealFrame);\n this.revealFrame = 0;\n }\n\n private reveal(): void {\n this.ensureRoot();\n const dialog = this.dialogEl;\n if (!this.open || !dialog) return;\n const again = () => {\n if (this.revealTries++ > 8) {\n this.ignoreClose = false;\n return;\n }\n const view = this.ownerDocument.defaultView;\n if (!view) return;\n this.revealFrame = view.requestAnimationFrame(() => {\n this.revealFrame = 0;\n if (this.open) this.reveal();\n });\n };\n if (!dialog.isConnected) {\n again();\n return;\n }\n if (!dialog.open) {\n try {\n dialog.showModal();\n } catch {\n again();\n return;\n }\n }\n this.revealTries = 0;\n this.cancelReveal();\n // A close event already queued by the dialog we shut must not dismiss this open.\n // Clearing the guard here is synchronous, so Escape after this update still closes.\n this.ignoreClose = false;\n // A later reveal (a retry, or the history traversal showing the dialog again) must\n // not pull focus back to Close after the visitor has moved it inside the dialog.\n const active = this.shadowRoot?.activeElement ?? this.ownerDocument.activeElement;\n if (!active || !dialog.contains(active)) this.closeBtn?.focus();\n }\n\n /** A cached image may already be complete before the load listener runs. */\n private settleImage(): void {\n const img = this.renderRoot.querySelector('img');\n if (!img || this.status !== 'loading') return;\n if (img.complete && img.naturalWidth > 0) this.status = 'ready';\n else if (img.complete && img.getAttribute('src') && img.naturalWidth === 0)\n this.status = 'error';\n }\n\n private readonly onLoad = (): void => {\n if (this.status === 'loading') this.status = 'ready';\n };\n\n private readonly onError = (): void => {\n this.status = 'error';\n };\n\n /** Stable identity for a details element, so parking it does not look like a new one. */\n private detailTokens = new WeakMap<HTMLElement, number>();\n private detailTokenSeq = 0;\n private detailToken(el: HTMLElement): string {\n let n = this.detailTokens.get(el);\n if (n === undefined) this.detailTokens.set(el, (n = ++this.detailTokenSeq));\n return String(n);\n }\n\n /**\n * Details for the open image: `slot=\"details\"` children (honouring `data-for`) and the\n * element named by `data-details-id`. Elements already parked in the dialog stay in the\n * set, so this does not move them again.\n */\n private matchingDetails(): HTMLElement[] {\n const slide = this.current;\n const id = slide?.id ?? '';\n const position = String(this.index + 1);\n const pool: HTMLElement[] = [];\n const add = (el: HTMLElement | null) => {\n if (el && el !== this && !pool.includes(el)) pool.push(el);\n };\n for (const el of this.querySelectorAll(':scope > [slot=\"details\"]')) {\n if (el instanceof HTMLElement) add(el);\n }\n for (const item of this.parked) add(item.el);\n if (slide?.detailsId) add(this.scope.getElementById(slide.detailsId));\n return pool.filter((el) => {\n if (el.getAttribute('slot') === 'details') {\n const f = el.getAttribute('data-for');\n return !f || f === id || f === position;\n }\n return !!slide?.detailsId && el.id === slide.detailsId;\n });\n }\n\n private placeDetails(): void {\n const want = this.matchingDetails();\n const key = `${want.map((el) => this.detailToken(el)).join('|')}@${this.index}`;\n if (key === this.parkedKey) return;\n const keep = new Set(want);\n const still: typeof this.parked = [];\n for (const item of this.parked) {\n if (keep.has(item.el) && this.detailsBox?.contains(item.el)) still.push(item);\n else this.putBack(item);\n }\n this.parked = still;\n const box = this.detailsBox;\n if (box) {\n for (const el of want) {\n if (box.contains(el)) continue;\n const parent = el.parentNode;\n if (!parent) continue;\n this.parked.push({ el, parent, next: el.nextSibling, hidden: el.hidden });\n el.hidden = false;\n box.append(el);\n }\n }\n this.parkedKey = key;\n }\n\n /**\n * Put a parked element back. Restoring later siblings first keeps `next` inside `parent`;\n * if it is not (it was parked too), insert at the end instead of throwing NotFoundError.\n */\n private putBack(item: (typeof this.parked)[number]): void {\n item.el.hidden = item.hidden;\n const next = item.next?.parentNode === item.parent ? item.next : null;\n item.parent.insertBefore(item.el, next);\n }\n\n private restoreDetails(): void {\n for (let i = this.parked.length - 1; i >= 0; i--) this.putBack(this.parked[i]!);\n this.parked = [];\n this.parkedKey = '';\n }\n\n private get statusText(): string {\n if (!this.open) return '';\n if (this.status === 'loading') return 'Loading image.';\n if (this.status === 'error') return 'This image could not be loaded.';\n return '';\n }\n\n protected override render() {\n const slide = this.open ? this.current : undefined;\n const src = slide ? this.displaySrc : '';\n const full = slide && usableImageUrl(slide.href, this.base) ? slide.href : '';\n const shown = this.statusText;\n const counter = this.multiple\n ? html`<p class=\"count\" aria-live=\"polite\">${this.index + 1} of ${this.slides.length}</p>`\n : nothing;\n // Shadow mode needs a slot or the author's links are not rendered and cannot take focus.\n // Light mode renders into `.viewer`; a `<slot>` there would not show the siblings.\n return html`\n ${this.isLight ? nothing : html`<slot></slot><slot name=\"details\" hidden></slot>`}\n <dialog\n part=\"dialog\"\n aria-labelledby=${this.captionId}\n @click=${this.onDialogClick}\n @close=${this.onDialogClose}\n @keydown=${this.onKey}\n >\n <div class=\"panel\" part=\"panel\">\n <div class=\"head\">\n <p class=\"caption\" part=\"caption\" id=${this.captionId}>${slide?.caption ?? 'Image'}</p>\n <button type=\"button\" class=\"close\" autofocus @click=${() => this.dismiss('ui')}>\n Close\n </button>\n </div>\n <figure class=\"figure\">\n ${\n src\n ? html`<img\n part=\"image\"\n alt=${slide?.alt ?? ''}\n src=${src}\n aria-busy=${this.status === 'loading' ? 'true' : 'false'}\n @load=${this.onLoad}\n @error=${this.onError}\n />`\n : nothing\n }\n </figure>\n <p class=\"status ${shown ? '' : 'visually-hidden'}\" role=\"status\">${shown}</p>\n <div class=\"toolbar\" part=\"controls\">\n ${\n this.multiple\n ? html`<button type=\"button\" class=\"prev\" @click=${() => this.step(-1)}>\n Previous\n </button>\n <button type=\"button\" class=\"next\" @click=${() => this.step(1)}>Next</button>\n ${counter}`\n : nothing\n }\n ${\n full\n ? html`<a\n class=\"full\"\n href=${full}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n @click=${this.onFullSize}\n >Full size<span class=\"visually-hidden\"> (opens in a new tab)</span></a\n >`\n : nothing\n }\n </div>\n <div class=\"details\" part=\"details\"></div>\n </div>\n </dialog>\n `;\n }\n}\n","import { define } from '../../base/define.js';\nimport { UvalibLightbox } from './UvalibLightbox.js';\n\ndefine('uvalib-lightbox', UvalibLightbox);\n"],"mappings":";;;;AAOA,IAAMgB,IAAS,kDACTC,IAAW,mBACXC,IAAU,+EAEVC,IAAgB,4BAEhBC,IAAa;AAgBnB,SAAgBC,EAAU,GAAc,GAAkC;CACxE,IAAIC;CACJ,IAAI;EACF,IAAM,IAAI,IAAIC,GAAMC,CAAI;CAC1B,QAAQ;EACN,OAAO;CACT;CACA,IAAIF,EAAI,aAAa,WAAWA,EAAI,aAAa,UAAU,OAAO;CAClE,IAAMG,IAAQH,EAAI,SAAS,MAAM,GAAG;CACpC,IAAIG,EAAM,SAAS,GAAG,OAAO;CAC7B,IAAMC,IAAOD,EAAMA,EAAM,SAAS,MAAM,IAClCE,IAAWF,EAAMA,EAAM,SAAS,MAAM,IACtCG,IAASH,EAAMA,EAAM,SAAS,MAAM;CAE1C,OADI,CAACP,EAAQ,KAAKQ,CAAI,KAAK,CA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A,KAAA,CAAA,GAOzBxD,EAAA,CAAAC,EAAS,EAAE,WAAW,YAAY,CAAC,CAAA,GAAAuD,EAAA,WAAA,YAAA,KAAA,CAAA,GAEnCxD,EAAA,CAAAE,EAAM,CAAA,GAAAsD,EAAA,WAAA,UAAA,KAAA,CAAA,GACNxD,EAAA,CAAAE,EAAM,CAAA,GAAAsD,EAAA,WAAA,SAAA,KAAA,CAAA,GACNxD,EAAA,CAAAE,EAAM,CAAA,GAAAsD,EAAA,WAAA,QAAA,KAAA,CAAA,GACNxD,EAAA,CAAAE,EAAM,CAAA,GAAAsD,EAAA,WAAA,UAAA,KAAA,CAAA,GACNxD,EAAA,CAAAE,EAAM,CAAA,GAAAsD,EAAA,WAAA,QAAA,KAAA,CAAA,GACNxD,EAAA,CAAAE,EAAM,CAAA,GAAAsD,EAAA,WAAA,QAAA,KAAA,CAAA,GCpOTjD,EAAO,mBAAmBiD,CAAc"}
1
+ {"version":3,"file":"uvalib-lightbox.js","names":["unsafeCSS","nothing","_decorate","property","state","n","i","r$1","b","define","__decorate","r","installLightDomStyles","UvalibElement","trackEvent","accessible","paramFromLocation","usesHashParam","hrefWithParam","REGION","ROTATION","QUALITY","BROWSER_IMAGE","DATA_IMAGE","parseIiif","url","href","base","parts","file","rotation","region","sizedIiifUrl","parsed","width","w","height","h","iiifIdentifier","viewportIiifSize","dpr","view","usableImageUrl","normalize","s","structuralRules","host","shadowStructure","nextCaption","UvalibLightbox","_args","link","slides","queued","id","rtl","back","forward","root","sheet","mount","light","dialog","src","changed","node","next","current","at","found","detailRoots","noteDetails","a","el","candidates","push","owner","unique","pos","img","alt","text","caption","index","walk","already","hashMode","delta","action","pushed","source","prev","mode","observer","trigger","again","active","slide","position","pool","add","item","f","want","key","keep","still","box","parent","full","shown","counter","A"],"sources":["../src/components/uvalib-lightbox/media.ts","../src/components/uvalib-lightbox/UvalibLightbox.ts","../src/components/uvalib-lightbox/uvalib-lightbox.ts"],"sourcesContent":["export {\n hrefWithParam,\n paramFromLocation,\n usesHashParam,\n type PageLocation,\n} from '../../base/url-param.js';\n\nconst REGION = /^(full|square|max|pct:[^/]+|\\d+,\\d+,\\d+,\\d+)$/i;\nconst ROTATION = /^!?\\d+(\\.\\d+)?$/;\nconst QUALITY = /^(default|color|gray|grey|bitonal|native)\\.(jpe?g|png|gif|webp|tiff?|jp2)$/i;\n/** Formats a browser can paint. TIFF and JPEG2000 are left unchanged. */\nconst BROWSER_IMAGE = /\\.(jpe?g|png|gif|webp)$/i;\n/** Full size may offer these `data:` images. SVG is never one: it can carry a script. */\nconst DATA_IMAGE = /^image\\/(png|jpeg|gif|webp)($|[;,])/i;\n\nexport interface IiifRequest {\n url: URL;\n /** Path segments, with a leading `''` for an absolute path. */\n parts: string[];\n regionIndex: number;\n sizeIndex: number;\n}\n\n/**\n * A IIIF Image API request, recognised from the end of the path:\n * `/{region}/{size}/{rotation}/{quality}.{format}`. The identifier may contain slashes\n * and colons (`uva-lib:286686`). Anything else, including an image that merely lives\n * under a `/full/` folder, is not one.\n */\nexport function parseIiif(href: string, base: string): IiifRequest | null {\n let url: URL;\n try {\n url = new URL(href, base);\n } catch {\n return null;\n }\n if (url.protocol !== 'http:' && url.protocol !== 'https:') return null;\n const parts = url.pathname.split('/');\n if (parts.length < 5) return null;\n const file = parts[parts.length - 1] ?? '';\n const rotation = parts[parts.length - 2] ?? '';\n const region = parts[parts.length - 4] ?? '';\n if (!QUALITY.test(file) || !ROTATION.test(rotation) || !REGION.test(region)) return null;\n return { url, parts, regionIndex: parts.length - 4, sizeIndex: parts.length - 3 };\n}\n\n/**\n * The same image with only the size segment rewritten to `!w,h`, so the server sends a size\n * that fits `w` by `h` device pixels and does not scale the original up. The region stays\n * (a crop or `square` is kept). Returns null when `href` is not IIIF, and for a TIFF or\n * JPEG2000 request, which is left exactly as written.\n */\nexport function sizedIiifUrl(href: string, base: string, w: number, h: number): string | null {\n const parsed = parseIiif(href, base);\n if (!parsed) return null;\n const file = parsed.parts[parsed.parts.length - 1] ?? '';\n if (!BROWSER_IMAGE.test(file)) return null;\n const width = Math.max(1, Math.round(w));\n const height = Math.max(1, Math.round(h));\n parsed.parts[parsed.sizeIndex] = `!${width},${height}`;\n parsed.url.pathname = parsed.parts.join('/');\n return parsed.url.toString();\n}\n\n/** The IIIF identifier (the segment before the region), for a stable deep-link id. */\nexport function iiifIdentifier(href: string, base: string): string | null {\n const parsed = parseIiif(href, base);\n if (!parsed) return null;\n const id = parsed.parts[parsed.regionIndex - 1];\n return id || null;\n}\n\n/** CSS pixels of the viewport, in device pixels, capped so a request stays reasonable. */\nexport function viewportIiifSize(\n view: Pick<Window, 'innerWidth' | 'innerHeight' | 'devicePixelRatio'>,\n): {\n w: number;\n h: number;\n} {\n const dpr = Math.min(view.devicePixelRatio || 1, 2);\n const w = Math.max(1, Math.min(2000, Math.round((view.innerWidth || 800) * dpr)));\n const h = Math.max(1, Math.min(2000, Math.round((view.innerHeight || 600) * dpr)));\n return { w, h };\n}\n\n/**\n * Whether `href` may be offered as Full size: an http(s) URL (including a relative one), or\n * a `data:` image of type PNG, JPEG, GIF or WebP. SVG and every other scheme are refused.\n */\nexport function usableImageUrl(href: string, base: string): boolean {\n try {\n const url = new URL(href, base);\n if (url.protocol === 'http:' || url.protocol === 'https:') return true;\n if (url.protocol === 'data:') return DATA_IMAGE.test(url.pathname);\n return false;\n } catch {\n return false;\n }\n}\n","import { css, html, nothing, unsafeCSS, type PropertyValues } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { trackEvent } from '../../base/analytics.js';\nimport { UvalibElement } from '../../base/UvalibElement.js';\nimport { installLightDomStyles } from '../../base/light-dom-styles.js';\nimport { accessible } from '../../styles/accessible.js';\nimport {\n hrefWithParam,\n iiifIdentifier,\n paramFromLocation,\n sizedIiifUrl,\n usableImageUrl,\n usesHashParam,\n viewportIiifSize,\n type PageLocation,\n} from './media.js';\n\n/** One image in the set, in document order. */\ninterface Slide {\n el: HTMLAnchorElement;\n /** Deep-link id: `data-id`, else the element's id, else the IIIF identifier, else the position. */\n id: string;\n /** The href as written. */\n href: string;\n caption: string;\n alt: string;\n /** `data-details-id`, when the slide has its own details element. */\n detailsId: string | null;\n}\n\nconst normalize = (s: unknown) =>\n String(s ?? '')\n .replace(/\\s+/g, ' ')\n .trim();\n\n/**\n * Kept with `no-style`: the triggers stay put, `[hidden]` hides, the dialog hugs its panel\n * (so a click outside it is the backdrop), controls are at least 44px, and the image stays\n * within the viewport. `host` is `:host` (shadow) or the tag (light DOM).\n */\nconst structuralRules = (host: string) => `\n ${host} { display: block; }\n ${host} .viewer { display: contents; }\n ${host} dialog {\n margin: auto;\n padding: 0;\n border: none;\n background: transparent;\n width: min(72rem, calc(100% - 2rem));\n max-height: calc(100% - 2rem);\n }\n ${host} .panel {\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n gap: 0.75rem;\n max-height: calc(100dvh - 2rem);\n overflow: auto;\n overscroll-behavior: contain;\n padding: 0.75rem;\n }\n ${host} .head, ${host} .toolbar {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: 0.5rem;\n }\n ${host} .head { justify-content: space-between; }\n ${host} .caption { margin: 0; min-width: 0; overflow-wrap: anywhere; }\n ${host} .figure { margin: 0; }\n ${host} dialog img { display: block; max-width: 100%; max-height: 70dvh; width: auto; height: auto; margin: auto; }\n ${host} .count, ${host} .status { margin: 0; }\n ${host} dialog button, ${host} dialog .full {\n box-sizing: border-box;\n min-width: 44px;\n min-height: 44px;\n padding: 0.5rem 0.75rem;\n font: inherit;\n }\n ${host} .details:empty { display: none; }\n ${host} > [slot=\"details\"] { display: none; }\n ${host}[hidden], ${host} [hidden] { display: none !important; }\n`;\nconst shadowStructure = unsafeCSS(structuralRules(':host'));\n\nlet nextCaption = 0;\n\n/**\n * An accessible image viewer over a set of plain links. With JavaScript a primary click opens\n * a modal dialog; without it (or with a modified click) the link opens the image as before.\n * Wrap the links, or point at them with `selector` (for example `a.pb-image` on a reading\n * page). There is no autoplay and no carousel.\n *\n * The dialog is labelled by the caption (`data-caption`, else the image alt, else the link\n * text). Focus moves to Close on open and back to the trigger on close. Escape and a click on\n * the backdrop close it. With more than one image, Previous and Next and the arrow keys move\n * through the set (wrapping), and a polite “3 of 13” counter is shown. Full size opens the\n * original image in a new tab. A IIIF Image API URL keeps its region; only the size becomes\n * `!W,H` for the viewport. TIFF and JPEG2000 URLs are left as written. `url-param` (for\n * example `photo`) keeps `?photo=<id>` in sync, including on a hash route\n * (`#/text?photo=<id>`): opening pushes a history entry, stepping replaces it, and\n * Back closes.\n *\n * Optional details: children with `slot=\"details\"` (and `data-for` equal to the item's id or\n * its position from 1; without `data-for` they show for every image), or `data-details-id` on\n * a link pointing at an element elsewhere on the page. Either is shown inside the dialog and\n * put back when the viewer moves on or closes.\n *\n * @tagname uvalib-lightbox\n * @slot - The image links. A plain click opens the viewer; without JavaScript they open the image.\n * @slot details - Details for the open image. `data-for` selects one item by its id or position (from 1); without it the details show for every image.\n * @csspart dialog - The modal dialog.\n * @csspart panel - The surface inside the dialog.\n * @csspart caption - The caption that names the dialog.\n * @csspart image - The image.\n * @csspart controls - Previous, Next, the counter and Full size.\n * @csspart details - The details panel.\n * @fires 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). Never the URL or the caption. Not fired for a viewer restored from the URL or from Back and Forward. Bubbles and is composed.\n * @cssprop --uva-color-surface-raised - Dark-mode role token: dialog surface (else `--uva-color-surface`, else #fff).\n * @cssprop --uva-color-surface - Dark-mode role token: the figure behind the image (else #fff).\n * @cssprop --uva-color-text - Dark-mode role token: text (else `--uva-grey-darkest`).\n * @cssprop --uva-color-shadow - Dark-mode role token: the backdrop scrim (else rgba(16, 23, 43, 0.72)).\n * @cssprop --uva-color-border - Dark-mode role token: dialog border (else `--uva-grey-100`).\n * @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).\n * @cssprop --uva-color-link - Dark-mode role token: Full size text when it is not the filled control (else `--uva-brand-blue`).\n * @cssprop --uva-color-accent-bg - Dark-mode role token: Close and Full size background (else `--uva-brand-blue`).\n * @cssprop --uva-color-on-accent - Text on those controls (else #fff).\n * @cssprop [--uva-brand-orange=#e57200] - Focus ring when `--uva-color-focus` is unset.\n * @cssprop [--uva-brand-blue=#232d4b] - Control background when `--uva-color-accent-bg` is unset.\n * @cssprop [--uva-grey-darkest=#2b2b2b] - Text when `--uva-color-text` is unset.\n * @cssprop [--uva-grey-100=#dadada] - Border when `--uva-color-border` is unset.\n */\nexport class UvalibLightbox extends UvalibElement {\n static styles = [\n accessible,\n shadowStructure,\n css`\n .panel {\n background: var(--uva-color-surface-raised, var(--uva-color-surface, #fff));\n color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));\n border: 1px solid var(--uva-color-border, var(--uva-grey-100, #dadada));\n }\n dialog::backdrop {\n background: var(--uva-color-shadow, rgba(16, 23, 43, 0.72));\n }\n .details a {\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n }\n .figure {\n background: var(--uva-color-surface, #fff);\n }\n .caption {\n font-size: 1.125rem;\n line-height: 1.4;\n font-weight: 600;\n }\n .count {\n font-variant-numeric: tabular-nums;\n }\n dialog button,\n dialog .full {\n padding: 0.5rem 0.75rem;\n border: 2px solid transparent;\n text-decoration: none;\n cursor: pointer;\n color: var(--uva-color-on-accent, #fff);\n background: var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b));\n }\n dialog button:focus-visible,\n dialog .full:focus-visible {\n outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));\n outline-offset: 2px;\n }\n dialog button.prev,\n dialog button.next {\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n background: var(--uva-color-surface, #fff);\n border-color: var(--uva-color-border, var(--uva-grey-100, #dadada));\n }\n .status {\n font-size: 1rem;\n }\n @media (prefers-reduced-motion: no-preference) {\n .panel {\n animation: uvalib-lightbox-in 0.15s ease;\n }\n }\n @media (prefers-reduced-motion: reduce) {\n dialog,\n dialog * {\n animation: none !important;\n transition: none !important;\n scroll-behavior: auto !important;\n }\n }\n @media (forced-colors: active) {\n .panel,\n dialog button,\n dialog .full {\n border: 1px solid CanvasText;\n }\n }\n @keyframes uvalib-lightbox-in {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n }\n `,\n ];\n\n /**\n * CSS selector for image links elsewhere in this root (the page, or the shadow root the\n * component sits in). Combined with any links inside the component. Example: `a.pb-image`.\n */\n @property({ type: String }) selector = '';\n\n /**\n * Query parameter kept in sync with the open image, for example `photo` → `?photo=<id>`.\n * The id is the link's `data-id`, else its `id`, else the IIIF identifier, else its position\n * from 1. On a hash route the parameter is written inside the hash. Empty: no deep link.\n */\n @property({ attribute: 'url-param' }) urlParam = '';\n\n @state() private slides: Slide[] = [];\n @state() private index = 0;\n @state() private open = false;\n @state() private status: 'loading' | 'ready' | 'error' = 'loading';\n @state() private fitW = 0;\n @state() private fitH = 0;\n\n private readonly captionId = `uvalib-lightbox-caption-${++nextCaption}`;\n /** Where the dialog is rendered. Light DOM renders here so the author's links stay put. */\n private mount?: HTMLElement;\n private trigger: HTMLAnchorElement | null = null;\n /** The open image pushed a history entry, so Back (and Close) returns to the page. */\n private historyPushed = false;\n /** The visitor closed the viewer; a later mutation must not reopen it from the URL. */\n private userClosed = false;\n /** Disconnect (and the dialog it closes) is not a visitor action, so it must not touch history. */\n private suppressClose = false;\n private warnedSelector = false;\n private lastSrc = '';\n private observer?: MutationObserver;\n private syncQueued = false;\n private resizeTimer = 0;\n /** A close event from the dialog we just shut must not dismiss the next open. */\n private ignoreClose = false;\n private dismissing = false;\n private revealTries = 0;\n private revealFrame = 0;\n private listened = false;\n /** The root `listen` bound, so disconnect can remove the listener after leaving a shadow root. */\n private listenRoot?: Document | ShadowRoot;\n /**\n * `dialog.close()` removes `open` now and fires `close` on a later task. The attribute\n * observer runs as a microtask, which is what a caller sees after `await updateComplete`.\n */\n private dialogObserver?: MutationObserver;\n private observedDialog?: HTMLDialogElement;\n /** `history.back()` from Close has not fired `popstate` yet. */\n private pendingBack = false;\n /** Whether that entry kept the parameter in the hash. The pop leaves a hash that may not say so. */\n private backInHash = false;\n /** An image chosen while that Back is still in flight, opened once the popstate arrives. */\n private queuedOpen: { i: number; slides: Slide[] } | null = null;\n /**\n * Set while a history traversal is opening the dialog. The traversal can close the\n * dialog it just showed; that close is not the visitor, so show it again.\n */\n private reopenGuard = false;\n /** Details elements moved into the dialog, and where they go back to. */\n private parked: { el: HTMLElement; parent: Node; next: ChildNode | null; hidden: boolean }[] = [];\n private parkedKey = '';\n\n /** Shadow mode follows the base class. Light mode renders into `.viewer`. */\n private get isLight(): boolean {\n return this.noShadowDom || this.hasAttribute('no-shadow-dom');\n }\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n if (!this.isLight) {\n const root = super.createRenderRoot();\n if (this.noStyle && root instanceof ShadowRoot) {\n const sheets = [accessible.styleSheet, shadowStructure.styleSheet].filter(\n (sheet): sheet is CSSStyleSheet => sheet != null,\n );\n root.adoptedStyleSheets = sheets;\n }\n return root;\n }\n const mount = this.ownerDocument.createElement('div');\n mount.className = 'viewer';\n this.mount = mount;\n this.append(mount);\n return mount;\n }\n\n override connectedCallback(): void {\n const light = this.isLight;\n super.connectedCallback();\n // A move in the DOM disconnects and reconnects. The disconnect guard must not stick,\n // or Escape would close the dialog and leave the viewer thinking it is still open.\n this.suppressClose = false;\n if (light) this.installLight(light);\n this.listen();\n this.slides = this.collect();\n this.watch();\n this.openFromUrl();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.unlisten();\n this.observer?.disconnect();\n this.dialogObserver?.disconnect();\n this.dialogObserver = undefined;\n this.observedDialog = undefined;\n window.clearTimeout(this.resizeTimer);\n this.cancelReveal();\n this.restoreDetails();\n this.pendingBack = false;\n this.queuedOpen = null;\n this.reopenGuard = false;\n // Closing the dialog here fires `close` synchronously. That is not the visitor dismissing\n // it: do not run history.back(), which could leave the page. `open` goes false so a later\n // connect can open again from the URL.\n this.suppressClose = true;\n this.open = false;\n const dialog = this.dialogEl;\n if (dialog?.open) dialog.close();\n this.suppressClose = false;\n this.ignoreClose = false;\n }\n\n protected override willUpdate(): void {\n if (!this.open) {\n this.lastSrc = '';\n return;\n }\n const src = this.displaySrc;\n if (src !== this.lastSrc) {\n this.lastSrc = src;\n this.status = src ? 'loading' : 'error';\n } else if (!src && this.status !== 'error') {\n // A refused URL (javascript:) has an empty src. On the first open `lastSrc` is already\n // empty, so the change above does not run, and the status would stay \"loading\".\n this.status = 'error';\n }\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (changed.has('selector')) this.watch();\n if (!this.open) {\n if (changed.has('open')) this.restoreDetails();\n return;\n }\n if (changed.has('open') || changed.has('index') || changed.has('slides')) this.placeDetails();\n this.bindDialogObserver();\n if (changed.has('open')) this.reveal();\n // Reading the image and writing `status` from inside `updated` makes Lit warn and schedule\n // a nested update. A microtask is still before the next paint.\n queueMicrotask(() => {\n if (this.isConnected) this.settleImage();\n });\n }\n\n private installLight(light: boolean): void {\n if (!light) return;\n const node = this.getRootNode();\n const root = node instanceof Document || node instanceof ShadowRoot ? node : undefined;\n if (this.noStyle) {\n installLightDomStyles(\n `${this.localName}::structure`,\n unsafeCSS(structuralRules(this.localName)),\n { root, scope: false },\n );\n installLightDomStyles(`${this.localName}::a11y`, accessible, { root });\n return;\n }\n installLightDomStyles(\n this.localName,\n (this.constructor as typeof UvalibElement).elementStyles,\n {\n root,\n },\n );\n }\n\n private get scope(): Document | ShadowRoot {\n const root = this.getRootNode();\n return root instanceof Document || root instanceof ShadowRoot ? root : this.ownerDocument;\n }\n\n private get base(): string {\n return this.ownerDocument.baseURI || location.href;\n }\n\n private loc(): PageLocation {\n return { pathname: location.pathname, search: location.search, hash: location.hash };\n }\n\n private listen(): void {\n if (this.listened) return;\n this.listened = true;\n this.listenRoot = this.scope;\n this.listenRoot.addEventListener('click', this.onClick, true);\n window.addEventListener('popstate', this.onPop);\n window.addEventListener('resize', this.onResize);\n }\n\n private unlisten(): void {\n if (!this.listened) return;\n this.listened = false;\n this.listenRoot?.removeEventListener('click', this.onClick, true);\n this.listenRoot = undefined;\n window.removeEventListener('popstate', this.onPop);\n window.removeEventListener('resize', this.onResize);\n }\n\n private watch(): void {\n this.observer?.disconnect();\n this.observer = new MutationObserver(() => this.scheduleSync());\n this.observer.observe(this, {\n attributes: true,\n attributeFilter: [\n 'href',\n 'id',\n 'alt',\n 'title',\n 'data-caption',\n 'data-id',\n 'data-details-id',\n 'slot',\n ],\n childList: true,\n subtree: true,\n });\n if (this.selector) this.observer.observe(this.scope, { childList: true, subtree: true });\n }\n\n /** Ignore mutations inside the viewer (the dialog, parked details) so a render cannot loop. */\n private scheduleSync(): void {\n if (this.syncQueued) return;\n this.syncQueued = true;\n queueMicrotask(() => {\n this.syncQueued = false;\n if (!this.isConnected) return;\n const next = this.collect();\n const same =\n next.length === this.slides.length &&\n next.every(\n (s, i) =>\n s.el === this.slides[i]?.el &&\n s.href === this.slides[i]?.href &&\n s.id === this.slides[i]?.id &&\n s.caption === this.slides[i]?.caption &&\n s.detailsId === this.slides[i]?.detailsId,\n );\n if (!same) {\n const current = this.current?.el;\n this.slides = next;\n if (this.open) {\n const at = current ? next.findIndex((s) => s.el === current) : -1;\n if (at >= 0) this.index = at;\n else if (!next.length) this.dismiss('empty');\n else this.index = Math.min(this.index, next.length - 1);\n }\n }\n if (!this.open) this.openFromUrl();\n });\n }\n\n private collect(): Slide[] {\n const found: HTMLAnchorElement[] = [];\n const detailRoots = new Set<Element>();\n const noteDetails = (a: Element) => {\n if (!(a instanceof HTMLAnchorElement)) return;\n const id = a.getAttribute('data-details-id');\n if (!id) return;\n const el = this.scope.getElementById(id);\n if (el) detailRoots.add(el);\n };\n const candidates: Element[] = [...this.querySelectorAll('a[href]')];\n if (this.selector) {\n try {\n candidates.push(...this.scope.querySelectorAll(this.selector));\n } catch {\n if (!this.warnedSelector) {\n this.warnedSelector = true;\n console.warn(\n `${this.localName}: selector ${JSON.stringify(this.selector)} is not a valid CSS selector.`,\n );\n }\n }\n }\n for (const a of candidates) noteDetails(a);\n const push = (a: Element) => {\n if (!(a instanceof HTMLAnchorElement) || !a.hasAttribute('href')) return;\n if (a.closest('[hidden]')) return;\n if (this.mount?.contains(a) || a.closest('dialog')) return;\n if (a.closest('[slot=\"details\"]')) return;\n for (const root of detailRoots) {\n if (root.contains(a)) return;\n }\n const owner = a.closest('uvalib-lightbox');\n if (owner && owner !== this) return;\n found.push(a);\n };\n for (const a of candidates) push(a);\n const unique = [...new Set(found)];\n unique.sort((a, b) => {\n if (a === b) return 0;\n const pos = a.compareDocumentPosition(b);\n if (pos & Node.DOCUMENT_POSITION_FOLLOWING) return -1;\n if (pos & Node.DOCUMENT_POSITION_PRECEDING) return 1;\n return 0;\n });\n return unique.map((el, i) => this.slide(el, i));\n }\n\n private slide(el: HTMLAnchorElement, index: number): Slide {\n const href = el.getAttribute('href') ?? '';\n const img = el.querySelector('img');\n const alt = normalize(img?.getAttribute('data-uvalib-alt') || img?.getAttribute('alt'));\n const text = this.linkText(el);\n const caption =\n normalize(el.dataset.caption) ||\n alt ||\n text ||\n normalize(el.getAttribute('title')) ||\n 'Image';\n const id =\n normalize(el.dataset.id) || el.id || iiifIdentifier(href, this.base) || String(index + 1);\n return {\n el,\n id,\n href,\n caption,\n alt: alt || caption,\n detailsId: normalize(el.dataset.detailsId) || null,\n };\n }\n\n /** The link's own text, not the alt of its image and not a details subtree. */\n private linkText(el: HTMLAnchorElement): string {\n const parts: string[] = [];\n const walk = (n: Node) => {\n if (n instanceof HTMLImageElement) return;\n if (\n n instanceof HTMLElement &&\n (n.hidden ||\n n.getAttribute('slot') === 'details' ||\n n.getAttribute('slot') === 'badge' ||\n n.classList.contains('badge') ||\n n.classList.contains('visually-hidden') ||\n n.hasAttribute('data-uvalib-generated-badge') ||\n n.hasAttribute('data-uvalib-badge-sep'))\n )\n return;\n if (n.nodeType === Node.TEXT_NODE) {\n parts.push(n.textContent ?? '');\n return;\n }\n n.childNodes.forEach(walk);\n };\n el.childNodes.forEach(walk);\n return normalize(parts.join(' '));\n }\n\n private get current(): Slide | undefined {\n return this.slides[this.index];\n }\n\n private get multiple(): boolean {\n return this.slides.length > 1;\n }\n\n /** The URL the `<img>` should load: a viewport-sized IIIF request, or the href itself. */\n private get displaySrc(): string {\n const href = this.current?.href ?? '';\n if (!usableImageUrl(href, this.base)) return '';\n const w = this.fitW || viewportIiifSize(window).w;\n const h = this.fitH || viewportIiifSize(window).h;\n return sizedIiifUrl(href, this.base, w, h) ?? href;\n }\n\n private measure(): void {\n const { w, h } = viewportIiifSize(window);\n if (w !== this.fitW) this.fitW = w;\n if (h !== this.fitH) this.fitH = h;\n }\n\n private readonly onResize = (): void => {\n if (!this.open) return;\n window.clearTimeout(this.resizeTimer);\n this.resizeTimer = window.setTimeout(() => {\n if (this.isConnected && this.open) this.measure();\n }, 150);\n };\n\n private readonly onClick = (e: Event): void => {\n if (\n !(e instanceof MouseEvent) ||\n e.button !== 0 ||\n e.metaKey ||\n e.ctrlKey ||\n e.shiftKey ||\n e.altKey\n )\n return;\n const link = this.linkFrom(e);\n if (!link) return;\n const slides = this.collect();\n const i = slides.findIndex((s) => s.el === link);\n if (i < 0) return;\n e.preventDefault();\n this.activate(i, slides);\n };\n\n private linkFrom(e: Event): HTMLAnchorElement | null {\n for (const n of e.composedPath()) {\n if (n instanceof HTMLAnchorElement) return n;\n }\n const t = e.target;\n return t instanceof Element ? t.closest('a[href]') : null;\n }\n\n /** A visitor chose `slides[i]`. The first open pushes a history entry; a later choice replaces it. */\n private activate(i: number, slides: Slide[]): void {\n const already = this.open;\n if (already && this.index === i) return;\n this.slides = slides;\n this.index = i;\n this.trigger = slides[i]?.el ?? null;\n this.userClosed = false;\n this.measure();\n this.open = true;\n if (this.pendingBack) {\n // Close already asked for history.back(). Writing now would push on the entry that\n // popstate is about to remove, and that pop would shut the viewer again.\n this.queuedOpen = { i, slides };\n } else if (this.urlParam) {\n const id = slides[i]?.id ?? null;\n const hashMode = usesHashParam(location.hash);\n if (already) this.writeParam(id, 'replace', hashMode);\n else {\n // The address can already carry this param (a leftover entry). Replace it away\n // on the current entry, then push, so Back still closes onto this page. Both\n // writes share hashMode: stripping `?photo` from `#chapter?photo=1` leaves\n // `#chapter`, which would otherwise fall out of the hash.\n if (paramFromLocation(this.loc(), this.urlParam))\n this.writeParam(null, 'replace', hashMode);\n this.historyPushed = this.writeParam(id, 'push', hashMode);\n }\n }\n trackEvent(this, ['uvalib-lightbox', 'open', `image ${i + 1}`, i + 1]);\n }\n\n /** Restore a viewer the URL already points at. No analytics: it is not a new action. */\n private openFromUrl(): void {\n if (this.open || this.userClosed || !this.urlParam) return;\n const id = paramFromLocation(this.loc(), this.urlParam);\n if (!id) return;\n const slides = this.slides.length ? this.slides : this.collect();\n const i = slides.findIndex((s) => s.id === id);\n if (i < 0) return;\n this.slides = slides;\n this.index = i;\n this.trigger = slides[i]?.el ?? null;\n this.measure();\n // Make Back close the viewer onto this page instead of leaving it. Remember the hash\n // route before the first write removes the `?` that marked it.\n const hashMode = usesHashParam(location.hash);\n this.writeParam(null, 'replace', hashMode);\n this.historyPushed = this.writeParam(id, 'push', hashMode);\n this.open = true;\n }\n\n private step(delta: number): void {\n const n = this.slides.length;\n if (n < 2) return;\n const i = (this.index + delta + n) % n;\n this.index = i;\n this.trigger = this.slides[i]?.el ?? this.trigger;\n if (this.urlParam) this.writeParam(this.slides[i]?.id ?? null, 'replace');\n const action = delta < 0 ? 'previous' : 'next';\n trackEvent(this, ['uvalib-lightbox', action, `image ${i + 1}`, i + 1]);\n }\n\n /**\n * Close. `ui` is Close, Escape or the backdrop (Back when this viewer pushed, else drop the\n * param). `pop` is the browser already moving: the URL is already right. `empty` is the\n * last image leaving the page: drop the param and do not reopen from it.\n */\n private dismiss(source: 'ui' | 'pop' | 'empty'): void {\n if (this.dismissing) return;\n const dialog = this.dialogEl;\n if (!this.open && !dialog?.open) return;\n this.dismissing = true;\n try {\n const pushed = this.historyPushed;\n this.historyPushed = false;\n this.ignoreClose = true;\n this.cancelReveal();\n this.open = false;\n if (source === 'ui' || source === 'empty') this.userClosed = true;\n this.restoreDetails();\n if (dialog?.open) dialog.close();\n this.focusTrigger();\n if (source === 'ui' && this.urlParam) {\n if (pushed) {\n this.backInHash = usesHashParam(location.hash);\n this.pendingBack = true;\n history.back();\n } else this.writeParam(null, 'replace', usesHashParam(location.hash));\n } else if (source === 'empty' && this.urlParam) {\n this.pendingBack = false;\n this.queuedOpen = null;\n this.writeParam(null, 'replace', usesHashParam(location.hash));\n }\n } finally {\n // Leave `ignoreClose` set. `dialog.close()` can queue a second close event for the\n // next task; clearing the guard here lets that event dismiss a viewer that has\n // already been opened again. `reveal` clears it once `showModal` has succeeded, which\n // is still before a later Escape. A throw while restoring details must not leave the\n // viewer stuck dismissing.\n this.dismissing = false;\n }\n }\n\n /** Returns false when this document cannot change the address (for example an iframe srcdoc). */\n private writeParam(id: string | null, mode: 'push' | 'replace', hashMode?: boolean): boolean {\n if (!this.urlParam) return false;\n const next = hrefWithParam(this.loc(), this.urlParam, id, hashMode);\n const now = location.pathname + location.search + location.hash;\n if (next === now) return false;\n const prev = history.state && typeof history.state === 'object' ? history.state : {};\n try {\n history[mode === 'push' ? 'pushState' : 'replaceState'](\n { ...prev, uvalibLightbox: this.urlParam },\n '',\n next,\n );\n return true;\n } catch {\n // A sandboxed document (an iframe srcdoc) cannot take a history entry. The viewer\n // still opens; the address is left as it is.\n return false;\n }\n }\n\n private readonly onPop = (): void => {\n if (!this.urlParam) return;\n if (this.pendingBack) {\n this.pendingBack = false;\n const queued = this.queuedOpen;\n this.queuedOpen = null;\n if (!this.isConnected || !queued) return;\n this.slides = queued.slides;\n this.index = queued.i;\n this.trigger = queued.slides[queued.i]?.el ?? null;\n this.userClosed = false;\n this.measure();\n const id = queued.slides[queued.i]?.id ?? null;\n this.historyPushed = this.writeParam(id, 'push', this.backInHash);\n if (!this.open) this.open = true;\n return;\n }\n const id = paramFromLocation(this.loc(), this.urlParam);\n if (!id) {\n this.historyPushed = false;\n if (this.open) this.dismiss('pop');\n return;\n }\n this.userClosed = false;\n const slides = this.collect();\n const i = slides.findIndex((s) => s.id === id);\n if (i < 0) {\n if (this.open) this.dismiss('pop');\n return;\n }\n this.slides = slides;\n this.index = i;\n this.trigger = slides[i]?.el ?? null;\n this.historyPushed = true;\n this.measure();\n this.armReopenGuard();\n if (!this.open) this.open = true;\n };\n\n /** Ignore the close event a history traversal fires on the dialog it just opened. */\n private armReopenGuard(): void {\n this.reopenGuard = true;\n const view = this.ownerDocument.defaultView;\n if (!view) return;\n view.requestAnimationFrame(() => {\n this.reopenGuard = false;\n });\n }\n\n private readonly onKey = (e: KeyboardEvent): void => {\n if (!this.multiple || this.typing(e)) return;\n // Left is previous in LTR and next in RTL, so the key matches the direction of the set.\n const rtl = getComputedStyle(this).direction === 'rtl';\n const back = rtl ? 'ArrowRight' : 'ArrowLeft';\n const forward = rtl ? 'ArrowLeft' : 'ArrowRight';\n if (e.key !== back && e.key !== forward) return;\n if (e.altKey || e.metaKey || e.ctrlKey) return;\n e.preventDefault();\n this.step(e.key === forward ? 1 : -1);\n };\n\n private typing(e: KeyboardEvent): boolean {\n const t = e.target;\n if (!(t instanceof HTMLElement)) return false;\n return t.isContentEditable || !!t.closest('input, textarea, select');\n }\n\n private readonly onDialogClick = (e: MouseEvent): void => {\n if (e.target === this.dialogEl) this.dismiss('ui');\n };\n\n /** The dialog element is stable across renders. Watch `open` on whichever node is current. */\n private bindDialogObserver(): void {\n const dialog = this.dialogEl;\n if (!dialog || dialog === this.observedDialog) return;\n this.dialogObserver?.disconnect();\n this.observedDialog = dialog;\n const observer = new MutationObserver(() => this.onNativeClose());\n observer.observe(dialog, { attributes: true, attributeFilter: ['open'] });\n this.dialogObserver = observer;\n }\n\n private readonly onDialogClose = (): void => {\n this.onNativeClose();\n };\n\n /**\n * Escape, the backdrop's close, and a direct `dialog.close()` all clear `open`. The\n * event itself is a later task; the attribute change is observable on the microtask\n * that `await updateComplete` flushes. A close that leaves the dialog open (a queued\n * event after `showModal`, or a history traversal) is not the visitor dismissing it.\n */\n private onNativeClose(): void {\n if (this.ignoreClose || this.suppressClose || !this.open) return;\n if (this.dialogEl?.open) return;\n if (this.reopenGuard) {\n const view = this.ownerDocument.defaultView;\n view?.queueMicrotask(() => {\n if (this.open && this.isConnected && !this.dialogEl?.open) this.reveal();\n });\n return;\n }\n this.dismiss('ui');\n }\n\n private readonly onFullSize = (): void => {\n const i = this.index;\n trackEvent(this, ['uvalib-lightbox', 'full-size', `image ${i + 1}`, i + 1]);\n };\n\n private get dialogEl(): HTMLDialogElement | null {\n return this.renderRoot.querySelector('dialog');\n }\n\n private get closeBtn(): HTMLButtonElement | null {\n return this.renderRoot.querySelector('button.close');\n }\n\n private get detailsBox(): HTMLElement | null {\n return this.renderRoot.querySelector('.details');\n }\n\n private focusTrigger(): void {\n const trigger = this.trigger;\n if (trigger?.isConnected) trigger.focus();\n }\n\n /**\n * Open the dialog and focus Close. `showModal` can throw while a dialog is still leaving\n * the top layer (a reopen from Back/Forward, or the first paint), so try again on the next\n * frames. Those frames are queued before a test's own `nextFrame`.\n */\n /** History restore can drop the light-DOM mount or orphan a shadow root. Put it back. */\n private ensureRoot(): void {\n const root = this.renderRoot;\n if (!this.isConnected) return;\n if (root instanceof HTMLElement && !root.isConnected) this.append(root);\n if (root instanceof ShadowRoot && this.shadowRoot && root !== this.shadowRoot) {\n (this as unknown as { renderRoot: ShadowRoot }).renderRoot = this.shadowRoot;\n this.requestUpdate();\n }\n }\n\n private cancelReveal(): void {\n const view = this.ownerDocument.defaultView;\n if (this.revealFrame && view) view.cancelAnimationFrame(this.revealFrame);\n this.revealFrame = 0;\n }\n\n private reveal(): void {\n this.ensureRoot();\n const dialog = this.dialogEl;\n if (!this.open || !dialog) return;\n const again = () => {\n if (this.revealTries++ > 8) {\n this.ignoreClose = false;\n return;\n }\n const view = this.ownerDocument.defaultView;\n if (!view) return;\n this.revealFrame = view.requestAnimationFrame(() => {\n this.revealFrame = 0;\n if (this.open) this.reveal();\n });\n };\n if (!dialog.isConnected) {\n again();\n return;\n }\n if (!dialog.open) {\n try {\n dialog.showModal();\n } catch {\n again();\n return;\n }\n }\n this.revealTries = 0;\n this.cancelReveal();\n // A close event already queued by the dialog we shut must not dismiss this open.\n // Clearing the guard here is synchronous, so Escape after this update still closes.\n this.ignoreClose = false;\n // A later reveal (a retry, or the history traversal showing the dialog again) must\n // not pull focus back to Close after the visitor has moved it inside the dialog.\n const active = this.shadowRoot?.activeElement ?? this.ownerDocument.activeElement;\n if (!active || !dialog.contains(active)) this.closeBtn?.focus();\n }\n\n /** A cached image may already be complete before the load listener runs. */\n private settleImage(): void {\n const img = this.renderRoot.querySelector('img');\n if (!img || this.status !== 'loading') return;\n if (img.complete && img.naturalWidth > 0) this.status = 'ready';\n else if (img.complete && img.getAttribute('src') && img.naturalWidth === 0)\n this.status = 'error';\n }\n\n private readonly onLoad = (): void => {\n if (this.status === 'loading') this.status = 'ready';\n };\n\n private readonly onError = (): void => {\n this.status = 'error';\n };\n\n /** Stable identity for a details element, so parking it does not look like a new one. */\n private detailTokens = new WeakMap<HTMLElement, number>();\n private detailTokenSeq = 0;\n private detailToken(el: HTMLElement): string {\n let n = this.detailTokens.get(el);\n if (n === undefined) this.detailTokens.set(el, (n = ++this.detailTokenSeq));\n return String(n);\n }\n\n /**\n * Details for the open image: `slot=\"details\"` children (honouring `data-for`) and the\n * element named by `data-details-id`. Elements already parked in the dialog stay in the\n * set, so this does not move them again.\n */\n private matchingDetails(): HTMLElement[] {\n const slide = this.current;\n const id = slide?.id ?? '';\n const position = String(this.index + 1);\n const pool: HTMLElement[] = [];\n const add = (el: HTMLElement | null) => {\n if (el && el !== this && !pool.includes(el)) pool.push(el);\n };\n for (const el of this.querySelectorAll(':scope > [slot=\"details\"]')) {\n if (el instanceof HTMLElement) add(el);\n }\n for (const item of this.parked) add(item.el);\n if (slide?.detailsId) add(this.scope.getElementById(slide.detailsId));\n return pool.filter((el) => {\n if (el.getAttribute('slot') === 'details') {\n const f = el.getAttribute('data-for');\n return !f || f === id || f === position;\n }\n return !!slide?.detailsId && el.id === slide.detailsId;\n });\n }\n\n private placeDetails(): void {\n const want = this.matchingDetails();\n const key = `${want.map((el) => this.detailToken(el)).join('|')}@${this.index}`;\n if (key === this.parkedKey) return;\n const keep = new Set(want);\n const still: typeof this.parked = [];\n for (const item of this.parked) {\n if (keep.has(item.el) && this.detailsBox?.contains(item.el)) still.push(item);\n else this.putBack(item);\n }\n this.parked = still;\n const box = this.detailsBox;\n if (box) {\n for (const el of want) {\n if (box.contains(el)) continue;\n const parent = el.parentNode;\n if (!parent) continue;\n this.parked.push({ el, parent, next: el.nextSibling, hidden: el.hidden });\n el.hidden = false;\n box.append(el);\n }\n }\n this.parkedKey = key;\n }\n\n /**\n * Put a parked element back. Restoring later siblings first keeps `next` inside `parent`;\n * if it is not (it was parked too), insert at the end instead of throwing NotFoundError.\n */\n private putBack(item: (typeof this.parked)[number]): void {\n item.el.hidden = item.hidden;\n const next = item.next?.parentNode === item.parent ? item.next : null;\n item.parent.insertBefore(item.el, next);\n }\n\n private restoreDetails(): void {\n for (let i = this.parked.length - 1; i >= 0; i--) this.putBack(this.parked[i]!);\n this.parked = [];\n this.parkedKey = '';\n }\n\n private get statusText(): string {\n if (!this.open) return '';\n if (this.status === 'loading') return 'Loading image.';\n if (this.status === 'error') return 'This image could not be loaded.';\n return '';\n }\n\n protected override render() {\n const slide = this.open ? this.current : undefined;\n const src = slide ? this.displaySrc : '';\n const full = slide && usableImageUrl(slide.href, this.base) ? slide.href : '';\n const shown = this.statusText;\n const counter = this.multiple\n ? html`<p class=\"count\" aria-live=\"polite\">${this.index + 1} of ${this.slides.length}</p>`\n : nothing;\n // Shadow mode needs a slot or the author's links are not rendered and cannot take focus.\n // Light mode renders into `.viewer`; a `<slot>` there would not show the siblings.\n return html`\n ${this.isLight ? nothing : html`<slot></slot><slot name=\"details\" hidden></slot>`}\n <dialog\n part=\"dialog\"\n aria-labelledby=${this.captionId}\n @click=${this.onDialogClick}\n @close=${this.onDialogClose}\n @keydown=${this.onKey}\n >\n <div class=\"panel\" part=\"panel\">\n <div class=\"head\">\n <p class=\"caption\" part=\"caption\" id=${this.captionId}>${slide?.caption ?? 'Image'}</p>\n <button type=\"button\" class=\"close\" autofocus @click=${() => this.dismiss('ui')}>\n Close\n </button>\n </div>\n <figure class=\"figure\">\n ${\n src\n ? html`<img\n part=\"image\"\n alt=${slide?.alt ?? ''}\n src=${src}\n aria-busy=${this.status === 'loading' ? 'true' : 'false'}\n @load=${this.onLoad}\n @error=${this.onError}\n />`\n : nothing\n }\n </figure>\n <p class=\"status ${shown ? '' : 'visually-hidden'}\" role=\"status\">${shown}</p>\n <div class=\"toolbar\" part=\"controls\">\n ${\n this.multiple\n ? html`<button type=\"button\" class=\"prev\" @click=${() => this.step(-1)}>\n Previous\n </button>\n <button type=\"button\" class=\"next\" @click=${() => this.step(1)}>Next</button>\n ${counter}`\n : nothing\n }\n ${\n full\n ? html`<a\n class=\"full\"\n href=${full}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n @click=${this.onFullSize}\n >Full size<span class=\"visually-hidden\"> (opens in a new tab)</span></a\n >`\n : nothing\n }\n </div>\n <div class=\"details\" part=\"details\"></div>\n </div>\n </dialog>\n `;\n }\n}\n","import { define } from '../../base/define.js';\nimport { UvalibLightbox } from './UvalibLightbox.js';\n\ndefine('uvalib-lightbox', UvalibLightbox);\n"],"mappings":";;;;;AAOA,IAAMmB,IAAS,kDACTC,IAAW,mBACXC,IAAU,+EAEVC,IAAgB,4BAEhBC,IAAa;AAgBnB,SAAgBC,EAAU,GAAc,GAAkC;CACxE,IAAIC;CACJ,IAAI;EACF,IAAM,IAAI,IAAIC,GAAMC,CAAI;CAC1B,QAAQ;EACN,OAAO;CACT;CACA,IAAIF,EAAI,aAAa,WAAWA,EAAI,aAAa,UAAU,OAAO;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ytics-DTTihuBD.js";
3
- import { a as d, n as f, r as p, t as m } from "./chunks/source-children-RuAec527.js";
3
+ import { n as d } from "./chunks/inline-copy-BANQSMIR.js";
4
+ import { n as f, r as p, t as m } from "./chunks/source-children-BHsDwCvL.js";
4
5
  import { t as h } from "./chunks/accessible-GqhVn5_H.js";
5
6
  // src/components/uvalib-metadata/rights.ts
6
7
  var g = {
@@ -1 +1 @@
1
- {"version":3,"file":"uvalib-metadata.js","names":["unsafeCSS","nothing","_decorate","property","state","n","i","r$1","b","define","__decorate","r","installLightDomStyles","UvalibElement","trackEvent","langDir","normalize","safeHref","SourceChildren","accessible","STATEMENTS","rightsName","u","href","host","path","m","licence","tool","specialCollectionsCitation","title","RIGHTS_INFO_TEXT","STATUS_MS","structuralRules","shadowStructure","UvalibMetadata","nodes","root","sheet","node","kind","message","dl","key","cells","c","rows","row","label","clone","base","unsafe","el","size","a","span","doc","frag","dot","comma","v","download","A","items","value","own","rights","statement","info","more","text","p","source","changed","shownFrom"],"sources":["../src/components/uvalib-metadata/rights.ts","../src/components/uvalib-metadata/UvalibMetadata.ts","../src/components/uvalib-metadata/uvalib-metadata.ts"],"sourcesContent":["/** rightsstatements.org's statements, by their id in the URL, with their short names. */\nconst STATEMENTS: Record<string, string> = {\n INC: 'In Copyright',\n 'INC-OW-EU': 'In Copyright – EU Orphan Work',\n 'INC-EDU': 'In Copyright – Educational Use Permitted',\n 'INC-NC': 'In Copyright – Non-Commercial Use Permitted',\n 'INC-RUU': 'In Copyright – Rights-holder(s) Unlocatable or Unidentifiable',\n 'NOC-CR': 'No Copyright – Contractual Restrictions',\n 'NOC-NC': 'No Copyright – Non-Commercial Use Only',\n 'NOC-OKLR': 'No Copyright – Other Known Legal Restrictions',\n 'NOC-US': 'No Copyright – United States',\n CNE: 'Copyright Not Evaluated',\n UND: 'Copyright Undetermined',\n NKC: 'No Known Copyright',\n};\n\n/**\n * The short name of a rightsstatements.org statement or Creative Commons licence or tool from\n * its URL (\"In Copyright\", \"CC BY-NC 4.0\", \"CC0 1.0\", \"Public Domain Mark 1.0\"), or\n * `undefined` for any other URL.\n */\nexport function rightsName(href: string): string | undefined {\n let u: URL;\n try {\n u = new URL(href);\n } catch {\n return undefined;\n }\n const host = u.hostname.toLowerCase().replace(/^www\\./, '');\n const path = u.pathname;\n if (host === 'rightsstatements.org') {\n const m = /^\\/(?:vocab|page|data)\\/([a-z-]+)\\/\\d/i.exec(path);\n return m ? STATEMENTS[m[1]!.toUpperCase()] : undefined;\n }\n if (host === 'creativecommons.org') {\n const licence = /^\\/licenses\\/((?:by|nc|nd|sa)(?:-(?:by|nc|nd|sa))*)\\/(\\d+(?:\\.\\d+)*)/i.exec(\n path,\n );\n if (licence) return `CC ${licence[1]!.toUpperCase()} ${licence[2]}`;\n const tool = /^\\/publicdomain\\/(zero|mark)\\/(\\d+(?:\\.\\d+)*)/i.exec(path);\n if (tool)\n return tool[1]!.toLowerCase() === 'zero' ? `CC0 ${tool[2]}` : `Public Domain Mark ${tool[2]}`;\n }\n return undefined;\n}\n\n/** The Albert and Shirley Small Special Collections Library's citation for a title or collection. */\nexport const specialCollectionsCitation = (title: string): string =>\n `${title}, Albert and Shirley Small Special Collections Library, University of Virginia`;\n","import { css, html, nothing, unsafeCSS, type PropertyValues, type TemplateResult } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { trackEvent } from '../../base/analytics.js';\nimport { UvalibElement } from '../../base/UvalibElement.js';\nimport { installLightDomStyles } from '../../base/light-dom-styles.js';\nimport { langDir } from '../../base/inline-copy.js';\nimport { normalize, safeHref, SourceChildren } from '../../base/source-children.js';\nimport { accessible } from '../../styles/accessible.js';\nimport { rightsName, specialCollectionsCitation } from './rights.js';\n\n/** A link value: a download when it has `download` or a `size` (\"EPUB · 184 KB\"). */\nexport interface MetadataLink {\n label: string;\n href: string;\n /** The file's size as shown, such as `184 KB`. */\n size?: string;\n /** The `download` attribute: `true` for an empty one, a string for a file name. */\n download?: boolean | string;\n}\n\n/** One value: text, or a link. */\nexport type MetadataValue = string | number | MetadataLink;\n\n/** A row: its label and one value, or several (shown as a list). */\nexport interface MetadataItem {\n label: string;\n value: MetadataValue | MetadataValue[];\n}\n\n/**\n * A value as drawn: a template or text (from `items`), or `source`, prepared copies of an\n * author's `<dd>` content that are never inserted themselves (each render set clones them).\n * `lang`/`dir` come from the source `<dd>`.\n */\ninterface Value {\n content?: TemplateResult | string;\n source?: Node[];\n lang?: string;\n dir?: string;\n}\n\n/** A row as drawn; `lang`/`dir` come from the source `<dt>`. */\ninterface Row {\n label: string;\n lang?: string;\n dir?: string;\n values: Value[];\n}\n\nconst RIGHTS_INFO_TEXT = 'More about rights and permissions';\nconst STATUS_MS = 5000;\n\n/**\n * The rules kept with `no-style`: unmarked value lists, the terms and values stacked, the\n * visually hidden text hidden, and `[hidden]` hides.\n */\nconst structuralRules = (host: string) => `\n ${host} { display: block; }\n ${host} dl, ${host} dd { margin: 0; }\n ${host} dd :is(ul, ol) { list-style: none; margin: 0; padding: 0; }\n ${host}[hidden], ${host} [hidden] { display: none !important; }\n`;\nconst shadowStructure = unsafeCSS(structuralRules(':host'));\n\n/**\n * A record's details as a description list, as on the library's digital collections: label\n * and value side by side on wide screens (the element's own width, 36rem and up), stacked on\n * narrow ones. Values may be text, links or lists (subjects).\n *\n * Give the rows as a `<dl>` child (so the page reads the same before the script loads):\n * `<dt>` labels and `<dd>` values, optionally wrapped in a `<div>` per row; several `<dd>`\n * after one `<dt>` are several values. The values are copied as written (links, lists,\n * `download` attributes kept); a link with `data-size=\"184 KB\"` is shown as a download,\n * \"EPUB · 184 KB\". The list follows changes to the children. Apps set the `items`\n * property instead (`{ label, value }`, winning over the children while set).\n *\n * Built-in rows for credit and rights (as Special Collections asks): `creator` and\n * `organization` come first; `rights` (a rightsstatements.org or Creative Commons URL, shown\n * as its short name linked to it, or plain text) and `citation` (\"How to cite\", with a Copy\n * citation button that announces \"Copied\" politely) come last. `citation-title` builds the\n * Special Collections citation, \"<title>, Albert and Shirley Small Special Collections\n * Library, University of Virginia\".\n *\n * @tagname uvalib-metadata\n * @fires uvalib-analytics-event - For `<site-analytics>`: the Copy citation button, `['uvalib-metadata', 'copy-citation']`. Downloads are left to Matomo's own download tracking. Bubbles and is composed.\n * @cssprop [--uva-blue-alt-dark=#005679] - Link colour.\n * @cssprop [--uva-grey-darkest=#2b2b2b] - Value colour.\n * @cssprop --uva-color-utility-link - Dark-mode role token: link colour (else `--uva-blue-alt-dark`).\n * @cssprop --uva-color-text - Dark-mode role token: value colour (else `--uva-grey-darkest`).\n * @cssprop --uva-color-text-muted - Dark-mode role token: label and status colour (else #4b5563).\n * @cssprop --uva-color-border - Dark-mode role token: row dividers (else #dadada).\n * @cssprop --uva-color-link - Dark-mode role token: the button's text and border (else `--uva-brand-blue`).\n * @cssprop --uva-color-surface-raised - Dark-mode role token: the button's background (else #fff).\n * @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).\n */\nexport class UvalibMetadata extends UvalibElement {\n static styles = [\n accessible,\n shadowStructure,\n css`\n :host {\n container-type: inline-size;\n font-size: 1rem;\n line-height: 1.5;\n color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));\n overflow-wrap: anywhere;\n }\n .row {\n display: grid;\n grid-template-columns: minmax(7rem, 12rem) minmax(0, 1fr);\n column-gap: 1.5rem;\n padding-block: 0.5rem;\n border-top: 1px solid var(--uva-color-border, var(--uva-grey-100, #dadada));\n }\n .row:first-child {\n border-top: 0;\n }\n dt {\n grid-column: 1;\n color: var(--uva-color-text-muted, #4b5563);\n font-weight: 700;\n }\n dd {\n grid-column: 2;\n }\n @container (width < 36rem) {\n .row {\n grid-template-columns: minmax(0, 1fr);\n }\n dt,\n dd {\n grid-column: 1;\n }\n }\n dd li + li {\n margin-top: 0.25rem;\n }\n a {\n color: var(--uva-color-utility-link, var(--uva-blue-alt-dark, #005679));\n text-decoration: underline;\n }\n .citation {\n margin: 0 0 0.5rem;\n }\n .copy {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: 0.5rem 0.75rem;\n }\n .uvalib-button {\n min-height: 44px;\n padding: 0.25rem 0.75rem;\n border: 1px solid var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n border-radius: 0.3rem;\n background: var(--uva-color-surface-raised, #fff);\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n font: inherit;\n cursor: pointer;\n }\n .status {\n color: var(--uva-color-text-muted, #4b5563);\n }\n `,\n ];\n\n /** The creator (author, photographer…), shown first. */\n @property({ type: String }) creator?: string;\n\n /** The organization holding or crediting the item, shown after the creator. */\n @property({ type: String }) organization?: string;\n\n /**\n * The rights statement: a rightsstatements.org or Creative Commons URL (shown as its short\n * name, linked), another http(s) URL (shown as `rights-label`, or \"Rights statement\"), or\n * plain text.\n */\n @property({ type: String }) rights?: string;\n\n /** The link text for a `rights` URL, instead of its short name. */\n @property({ type: String, attribute: 'rights-label' }) rightsLabel?: string;\n\n /**\n * A \"More about rights and permissions\" link under the statement, such as\n * `https://www.library.virginia.edu/policies/use-of-materials`.\n */\n @property({ type: String, attribute: 'rights-info' }) rightsInfo?: string;\n\n /** \"How to cite\": the citation, as written. Wins over `citation-title`. */\n @property({ type: String }) citation?: string;\n\n /**\n * A title or collection name for the Special Collections citation: \"<title>, Albert and\n * Shirley Small Special Collections Library, University of Virginia\".\n */\n @property({ type: String, attribute: 'citation-title' }) citationTitle?: string;\n\n /**\n * The rows as data, for apps that build them in JavaScript: `{ label, value }`, a value\n * being text, a link `{ label, href, size?, download? }` or an array of them (a list).\n * Wins over the children while set; `undefined` goes back to them.\n */\n @property({ attribute: false }) items?: MetadataItem[];\n\n @state() private childRows: Row[] = [];\n /** The Copy citation button's result, announced politely. */\n @state() private status = '';\n\n private sourceKey = '';\n private warned = new Set<string>();\n private timer?: ReturnType<typeof setTimeout>;\n\n constructor() {\n super();\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 override disconnectedCallback(): void {\n super.disconnectedCallback();\n clearTimeout(this.timer);\n this.status = '';\n }\n\n private warnOnce(kind: string, message: string): void {\n if (this.warned.has(kind)) return;\n this.warned.add(kind);\n console.warn(`${this.localName}: ${message}`);\n }\n\n /** Read the rows from the first `<dl>` among the children. */\n private read(nodes: Node[]): void {\n let dl: Element | null = null;\n for (const n of nodes) {\n if (!(n instanceof Element)) continue;\n dl = n.localName === 'dl' ? n : n.querySelector('dl');\n if (dl) break;\n }\n const key = dl?.outerHTML ?? '';\n // Only a real change re-renders.\n if (key === this.sourceKey) return;\n this.sourceKey = key;\n this.childRows = dl ? this.parse(dl) : [];\n }\n\n private parse(dl: Element): Row[] {\n const cells = [...dl.children].flatMap((c) => (c.localName === 'div' ? [...c.children] : [c]));\n const rows: Row[] = [];\n let row: Row | undefined;\n for (const c of cells) {\n if (c.localName === 'dt') {\n const label = normalize(c.textContent);\n if (!label) continue;\n // Several <dt> before their values name one row.\n if (row && !row.values.length) row.label += ` / ${label}`;\n else rows.push((row = { label, values: [], ...langDir(c) }));\n } else if (c.localName === 'dd') {\n if (!row) {\n this.warnOnce('dd', 'ignoring a <dd> with no <dt> before it.');\n continue;\n }\n row.values.push({ source: [...c.childNodes].map((n) => this.copy(n)), ...langDir(c) });\n }\n }\n return rows.filter((r) => r.values.length);\n }\n\n /**\n * A copy of an author's node: links with an unsafe href (javascript:, data:, …) replaced\n * by their content, with one warning; sizes added to downloads once (not when the link's\n * text already ends with it), `data-size` dropped; ids dropped in light DOM.\n */\n private copy(n: Node): Node {\n const clone = n.cloneNode(true);\n if (!(clone instanceof Element)) return clone;\n const base = this.ownerDocument.baseURI;\n const unsafe: Element[] = [];\n for (const el of [clone, ...clone.querySelectorAll('*')]) {\n if (this.lightDom) el.removeAttribute('id');\n if (el.localName !== 'a') continue;\n const href = el.getAttribute('href');\n if (href !== null && !safeHref(href, base)) {\n this.warnOnce(\n 'href',\n 'showing a link as text: its href is not http(s), mailto, tel or relative.',\n );\n unsafe.push(el);\n }\n const size = normalize(el.getAttribute('data-size'));\n el.removeAttribute('data-size');\n if (size && !normalize(el.textContent).endsWith(size)) el.append(this.sizeNodes(size));\n }\n // An unsafe link keeps only its content (in a <span> when it is the copied node itself).\n for (const a of unsafe.reverse()) {\n if (a !== clone) {\n a.replaceWith(...a.childNodes);\n continue;\n }\n const span = this.ownerDocument.createElement('span');\n span.append(...a.childNodes);\n return span;\n }\n return clone;\n }\n\n /** \" · 184 KB\", read as \", 184 KB\". */\n private sizeNodes(size: string): DocumentFragment {\n const doc = this.ownerDocument;\n const frag = doc.createDocumentFragment();\n const dot = doc.createElement('span');\n dot.setAttribute('aria-hidden', 'true');\n dot.textContent = ' · ';\n const comma = doc.createElement('span');\n comma.className = 'visually-hidden';\n comma.textContent = ', ';\n frag.append(dot, comma, size);\n return frag;\n }\n\n private renderValue(v: MetadataValue): TemplateResult | string {\n if (v === null || v === undefined) return '';\n if (typeof v !== 'object') return String(v);\n const label = normalize(v.label);\n const href = v.href == null ? '' : String(v.href);\n if (!href || !safeHref(href, this.ownerDocument.baseURI)) {\n if (href)\n this.warnOnce(\n 'href',\n 'showing a link as text: its href is not http(s), mailto, tel or relative.',\n );\n return label;\n }\n const size = normalize(v.size);\n const download = v.download === true ? '' : v.download || undefined;\n return html`<a href=${href} download=${download ?? nothing}\n >${label}${\n size\n ? html`<span aria-hidden=\"true\"> · </span><span class=\"visually-hidden\">, </span>${size}`\n : nothing\n }</a\n >`;\n }\n\n private fromItems(items: readonly MetadataItem[]): Row[] {\n const rows: Row[] = [];\n for (const i of items) {\n const label = normalize(i?.label);\n if (!label) {\n this.warnOnce('label', 'ignoring rows with no label.');\n continue;\n }\n const value = Array.isArray(i.value)\n ? html`<ul role=\"list\">\n ${i.value.map((v) => html`<li>${this.renderValue(v)}</li>`)}\n </ul>`\n : this.renderValue(i.value);\n rows.push({ label, values: [{ content: value }] });\n }\n return rows;\n }\n\n /** The citation text: `citation`, else the Special Collections one for `citation-title`. */\n private get citationText(): string {\n const own = normalize(this.citation);\n if (own) return own;\n const title = normalize(this.citationTitle);\n return title ? specialCollectionsCitation(title) : '';\n }\n\n private renderRights(): TemplateResult | typeof nothing {\n const rights = normalize(this.rights);\n if (!rights) return nothing;\n const base = this.ownerDocument.baseURI;\n const isUrl = /^https?:\\/\\//i.test(rights);\n const statement = isUrl\n ? html`<a href=${rights} rel=\"license\"\n >${normalize(this.rightsLabel) || rightsName(rights) || 'Rights statement'}</a\n >`\n : rights;\n const info = normalize(this.rightsInfo);\n const more =\n info && safeHref(info, base)\n ? html`<div><a href=${info}>${RIGHTS_INFO_TEXT}</a></div>`\n : nothing;\n return html`<div class=\"row\">\n <dt>Rights</dt>\n <dd>\n <div>${statement}</div>\n ${more}\n </dd>\n </div>`;\n }\n\n private renderCitation(): TemplateResult | typeof nothing {\n const text = this.citationText;\n if (!text) return nothing;\n return html`<div class=\"row\">\n <dt>How to cite</dt>\n <dd>\n <p class=\"citation\">${text}</p>\n <div class=\"copy\">\n <button type=\"button\" class=\"uvalib-button\" @click=${this.copyCitation}>\n Copy citation\n </button>\n <span class=\"status\" role=\"status\">${this.status}</span>\n </div>\n </dd>\n </div>`;\n }\n\n /** Copy the citation; on failure select it, so the keyboard can copy it. */\n private async copyCitation(): Promise<void> {\n trackEvent(this, ['uvalib-metadata', 'copy-citation']);\n clearTimeout(this.timer);\n // Cleared first, so a second copy is announced again.\n this.status = '';\n await this.updateComplete;\n let message = 'Copied';\n try {\n await navigator.clipboard.writeText(this.citationText);\n } catch {\n const p = this.renderRoot.querySelector('.citation');\n if (p) this.ownerDocument.getSelection()?.selectAllChildren(p);\n message = 'Could not copy: the citation is selected, copy it with your keyboard';\n }\n this.status = message;\n this.timer = setTimeout(() => (this.status = ''), STATUS_MS);\n }\n\n private get rows(): Row[] {\n return this.items ? this.fromItems(this.items) : this.childRows;\n }\n\n /** The rows' source the clones below were made for. */\n private clonedFor?: unknown;\n private clones = new WeakMap<Node[], Node[]>();\n\n /**\n * A value's nodes: fresh clones of its prepared source whenever the rows shown change\n * (new markup, or back from `items`), reused by unrelated updates (the citation status) so\n * that focus in a value is not lost.\n */\n private nodesOf(source: Node[]): Node[] {\n let c = this.clones.get(source);\n if (!c) this.clones.set(source, (c = source.map((n) => n.cloneNode(true))));\n return c;\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n this.toggleAttribute('data-empty', !this.renderRoot.querySelector('.row'));\n }\n\n protected override render() {\n const text = (label: string, value?: string) => {\n const v = normalize(value);\n return v\n ? html`<div class=\"row\">\n <dt>${label}</dt>\n <dd>${v}</dd>\n </div>`\n : nothing;\n };\n const shownFrom = this.items ?? this.childRows;\n if (shownFrom !== this.clonedFor) {\n this.clonedFor = shownFrom;\n this.clones = new WeakMap();\n }\n return html`<dl>\n ${text('Creator', this.creator)}${text('Organization', this.organization)}\n ${this.rows.map(\n (r) =>\n html`<div class=\"row\">\n <dt lang=${r.lang ?? nothing} dir=${r.dir ?? nothing}>${r.label}</dt>\n ${r.values.map(\n (v) =>\n html`<dd lang=${v.lang ?? nothing} dir=${v.dir ?? nothing}>\n ${v.source ? this.nodesOf(v.source) : v.content}\n </dd>`,\n )}\n </div>`,\n )}\n ${this.renderRights()}${this.renderCitation()}\n </dl>`;\n }\n}\n","import { define } from '../../base/define.js';\nimport { UvalibMetadata } from './UvalibMetadata.js';\n\ndefine('uvalib-metadata', UvalibMetadata);\n"],"mappings":";;;;;AACA,IAAMoB,IAAqC;CACzC,KAAK;CACL,aAAa;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alib-metadata.js","names":["unsafeCSS","nothing","_decorate","property","state","n","i","r$1","b","define","__decorate","r","installLightDomStyles","UvalibElement","trackEvent","langDir","normalize","safeHref","SourceChildren","accessible","STATEMENTS","rightsName","u","href","host","path","m","licence","tool","specialCollectionsCitation","title","RIGHTS_INFO_TEXT","STATUS_MS","structuralRules","shadowStructure","UvalibMetadata","nodes","root","sheet","node","kind","message","dl","key","cells","c","rows","row","label","clone","base","unsafe","el","size","a","span","doc","frag","dot","comma","v","download","A","items","value","own","rights","statement","info","more","text","p","source","changed","shownFrom"],"sources":["../src/components/uvalib-metadata/rights.ts","../src/components/uvalib-metadata/UvalibMetadata.ts","../src/components/uvalib-metadata/uvalib-metadata.ts"],"sourcesContent":["/** rightsstatements.org's statements, by their id in the URL, with their short names. */\nconst STATEMENTS: Record<string, string> = {\n INC: 'In Copyright',\n 'INC-OW-EU': 'In Copyright – EU Orphan Work',\n 'INC-EDU': 'In Copyright – Educational Use Permitted',\n 'INC-NC': 'In Copyright – Non-Commercial Use Permitted',\n 'INC-RUU': 'In Copyright – Rights-holder(s) Unlocatable or Unidentifiable',\n 'NOC-CR': 'No Copyright – Contractual Restrictions',\n 'NOC-NC': 'No Copyright – Non-Commercial Use Only',\n 'NOC-OKLR': 'No Copyright – Other Known Legal Restrictions',\n 'NOC-US': 'No Copyright – United States',\n CNE: 'Copyright Not Evaluated',\n UND: 'Copyright Undetermined',\n NKC: 'No Known Copyright',\n};\n\n/**\n * The short name of a rightsstatements.org statement or Creative Commons licence or tool from\n * its URL (\"In Copyright\", \"CC BY-NC 4.0\", \"CC0 1.0\", \"Public Domain Mark 1.0\"), or\n * `undefined` for any other URL.\n */\nexport function rightsName(href: string): string | undefined {\n let u: URL;\n try {\n u = new URL(href);\n } catch {\n return undefined;\n }\n const host = u.hostname.toLowerCase().replace(/^www\\./, '');\n const path = u.pathname;\n if (host === 'rightsstatements.org') {\n const m = /^\\/(?:vocab|page|data)\\/([a-z-]+)\\/\\d/i.exec(path);\n return m ? STATEMENTS[m[1]!.toUpperCase()] : undefined;\n }\n if (host === 'creativecommons.org') {\n const licence = /^\\/licenses\\/((?:by|nc|nd|sa)(?:-(?:by|nc|nd|sa))*)\\/(\\d+(?:\\.\\d+)*)/i.exec(\n path,\n );\n if (licence) return `CC ${licence[1]!.toUpperCase()} ${licence[2]}`;\n const tool = /^\\/publicdomain\\/(zero|mark)\\/(\\d+(?:\\.\\d+)*)/i.exec(path);\n if (tool)\n return tool[1]!.toLowerCase() === 'zero' ? `CC0 ${tool[2]}` : `Public Domain Mark ${tool[2]}`;\n }\n return undefined;\n}\n\n/** The Albert and Shirley Small Special Collections Library's citation for a title or collection. */\nexport const specialCollectionsCitation = (title: string): string =>\n `${title}, Albert and Shirley Small Special Collections Library, University of Virginia`;\n","import { css, html, nothing, unsafeCSS, type PropertyValues, type TemplateResult } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { trackEvent } from '../../base/analytics.js';\nimport { UvalibElement } from '../../base/UvalibElement.js';\nimport { installLightDomStyles } from '../../base/light-dom-styles.js';\nimport { langDir } from '../../base/inline-copy.js';\nimport { normalize, safeHref, SourceChildren } from '../../base/source-children.js';\nimport { accessible } from '../../styles/accessible.js';\nimport { rightsName, specialCollectionsCitation } from './rights.js';\n\n/** A link value: a download when it has `download` or a `size` (\"EPUB · 184 KB\"). */\nexport interface MetadataLink {\n label: string;\n href: string;\n /** The file's size as shown, such as `184 KB`. */\n size?: string;\n /** The `download` attribute: `true` for an empty one, a string for a file name. */\n download?: boolean | string;\n}\n\n/** One value: text, or a link. */\nexport type MetadataValue = string | number | MetadataLink;\n\n/** A row: its label and one value, or several (shown as a list). */\nexport interface MetadataItem {\n label: string;\n value: MetadataValue | MetadataValue[];\n}\n\n/**\n * A value as drawn: a template or text (from `items`), or `source`, prepared copies of an\n * author's `<dd>` content that are never inserted themselves (each render set clones them).\n * `lang`/`dir` come from the source `<dd>`.\n */\ninterface Value {\n content?: TemplateResult | string;\n source?: Node[];\n lang?: string;\n dir?: string;\n}\n\n/** A row as drawn; `lang`/`dir` come from the source `<dt>`. */\ninterface Row {\n label: string;\n lang?: string;\n dir?: string;\n values: Value[];\n}\n\nconst RIGHTS_INFO_TEXT = 'More about rights and permissions';\nconst STATUS_MS = 5000;\n\n/**\n * The rules kept with `no-style`: unmarked value lists, the terms and values stacked, the\n * visually hidden text hidden, and `[hidden]` hides.\n */\nconst structuralRules = (host: string) => `\n ${host} { display: block; }\n ${host} dl, ${host} dd { margin: 0; }\n ${host} dd :is(ul, ol) { list-style: none; margin: 0; padding: 0; }\n ${host}[hidden], ${host} [hidden] { display: none !important; }\n`;\nconst shadowStructure = unsafeCSS(structuralRules(':host'));\n\n/**\n * A record's details as a description list, as on the library's digital collections: label\n * and value side by side on wide screens (the element's own width, 36rem and up), stacked on\n * narrow ones. Values may be text, links or lists (subjects).\n *\n * Give the rows as a `<dl>` child (so the page reads the same before the script loads):\n * `<dt>` labels and `<dd>` values, optionally wrapped in a `<div>` per row; several `<dd>`\n * after one `<dt>` are several values. The values are copied as written (links, lists,\n * `download` attributes kept); a link with `data-size=\"184 KB\"` is shown as a download,\n * \"EPUB · 184 KB\". The list follows changes to the children. Apps set the `items`\n * property instead (`{ label, value }`, winning over the children while set).\n *\n * Built-in rows for credit and rights (as Special Collections asks): `creator` and\n * `organization` come first; `rights` (a rightsstatements.org or Creative Commons URL, shown\n * as its short name linked to it, or plain text) and `citation` (\"How to cite\", with a Copy\n * citation button that announces \"Copied\" politely) come last. `citation-title` builds the\n * Special Collections citation, \"<title>, Albert and Shirley Small Special Collections\n * Library, University of Virginia\".\n *\n * @tagname uvalib-metadata\n * @fires uvalib-analytics-event - For `<site-analytics>`: the Copy citation button, `['uvalib-metadata', 'copy-citation']`. Downloads are left to Matomo's own download tracking. Bubbles and is composed.\n * @cssprop [--uva-blue-alt-dark=#005679] - Link colour.\n * @cssprop [--uva-grey-darkest=#2b2b2b] - Value colour.\n * @cssprop --uva-color-utility-link - Dark-mode role token: link colour (else `--uva-blue-alt-dark`).\n * @cssprop --uva-color-text - Dark-mode role token: value colour (else `--uva-grey-darkest`).\n * @cssprop --uva-color-text-muted - Dark-mode role token: label and status colour (else #4b5563).\n * @cssprop --uva-color-border - Dark-mode role token: row dividers (else #dadada).\n * @cssprop --uva-color-link - Dark-mode role token: the button's text and border (else `--uva-brand-blue`).\n * @cssprop --uva-color-surface-raised - Dark-mode role token: the button's background (else #fff).\n * @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).\n */\nexport class UvalibMetadata extends UvalibElement {\n static styles = [\n accessible,\n shadowStructure,\n css`\n :host {\n container-type: inline-size;\n font-size: 1rem;\n line-height: 1.5;\n color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));\n overflow-wrap: anywhere;\n }\n .row {\n display: grid;\n grid-template-columns: minmax(7rem, 12rem) minmax(0, 1fr);\n column-gap: 1.5rem;\n padding-block: 0.5rem;\n border-top: 1px solid var(--uva-color-border, var(--uva-grey-100, #dadada));\n }\n .row:first-child {\n border-top: 0;\n }\n dt {\n grid-column: 1;\n color: var(--uva-color-text-muted, #4b5563);\n font-weight: 700;\n }\n dd {\n grid-column: 2;\n }\n @container (width < 36rem) {\n .row {\n grid-template-columns: minmax(0, 1fr);\n }\n dt,\n dd {\n grid-column: 1;\n }\n }\n dd li + li {\n margin-top: 0.25rem;\n }\n a {\n color: var(--uva-color-utility-link, var(--uva-blue-alt-dark, #005679));\n text-decoration: underline;\n }\n .citation {\n margin: 0 0 0.5rem;\n }\n .copy {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: 0.5rem 0.75rem;\n }\n .uvalib-button {\n min-height: 44px;\n padding: 0.25rem 0.75rem;\n border: 1px solid var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n border-radius: 0.3rem;\n background: var(--uva-color-surface-raised, #fff);\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n font: inherit;\n cursor: pointer;\n }\n .status {\n color: var(--uva-color-text-muted, #4b5563);\n }\n `,\n ];\n\n /** The creator (author, photographer…), shown first. */\n @property({ type: String }) creator?: string;\n\n /** The organization holding or crediting the item, shown after the creator. */\n @property({ type: String }) organization?: string;\n\n /**\n * The rights statement: a rightsstatements.org or Creative Commons URL (shown as its short\n * name, linked), another http(s) URL (shown as `rights-label`, or \"Rights statement\"), or\n * plain text.\n */\n @property({ type: String }) rights?: string;\n\n /** The link text for a `rights` URL, instead of its short name. */\n @property({ type: String, attribute: 'rights-label' }) rightsLabel?: string;\n\n /**\n * A \"More about rights and permissions\" link under the statement, such as\n * `https://www.library.virginia.edu/policies/use-of-materials`.\n */\n @property({ type: String, attribute: 'rights-info' }) rightsInfo?: string;\n\n /** \"How to cite\": the citation, as written. Wins over `citation-title`. */\n @property({ type: String }) citation?: string;\n\n /**\n * A title or collection name for the Special Collections citation: \"<title>, Albert and\n * Shirley Small Special Collections Library, University of Virginia\".\n */\n @property({ type: String, attribute: 'citation-title' }) citationTitle?: string;\n\n /**\n * The rows as data, for apps that build them in JavaScript: `{ label, value }`, a value\n * being text, a link `{ label, href, size?, download? }` or an array of them (a list).\n * Wins over the children while set; `undefined` goes back to them.\n */\n @property({ attribute: false }) items?: MetadataItem[];\n\n @state() private childRows: Row[] = [];\n /** The Copy citation button's result, announced politely. */\n @state() private status = '';\n\n private sourceKey = '';\n private warned = new Set<string>();\n private timer?: ReturnType<typeof setTimeout>;\n\n constructor() {\n super();\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 override disconnectedCallback(): void {\n super.disconnectedCallback();\n clearTimeout(this.timer);\n this.status = '';\n }\n\n private warnOnce(kind: string, message: string): void {\n if (this.warned.has(kind)) return;\n this.warned.add(kind);\n console.warn(`${this.localName}: ${message}`);\n }\n\n /** Read the rows from the first `<dl>` among the children. */\n private read(nodes: Node[]): void {\n let dl: Element | null = null;\n for (const n of nodes) {\n if (!(n instanceof Element)) continue;\n dl = n.localName === 'dl' ? n : n.querySelector('dl');\n if (dl) break;\n }\n const key = dl?.outerHTML ?? '';\n // Only a real change re-renders.\n if (key === this.sourceKey) return;\n this.sourceKey = key;\n this.childRows = dl ? this.parse(dl) : [];\n }\n\n private parse(dl: Element): Row[] {\n const cells = [...dl.children].flatMap((c) => (c.localName === 'div' ? [...c.children] : [c]));\n const rows: Row[] = [];\n let row: Row | undefined;\n for (const c of cells) {\n if (c.localName === 'dt') {\n const label = normalize(c.textContent);\n if (!label) continue;\n // Several <dt> before their values name one row.\n if (row && !row.values.length) row.label += ` / ${label}`;\n else rows.push((row = { label, values: [], ...langDir(c) }));\n } else if (c.localName === 'dd') {\n if (!row) {\n this.warnOnce('dd', 'ignoring a <dd> with no <dt> before it.');\n continue;\n }\n row.values.push({ source: [...c.childNodes].map((n) => this.copy(n)), ...langDir(c) });\n }\n }\n return rows.filter((r) => r.values.length);\n }\n\n /**\n * A copy of an author's node: links with an unsafe href (javascript:, data:, …) replaced\n * by their content, with one warning; sizes added to downloads once (not when the link's\n * text already ends with it), `data-size` dropped; ids dropped in light DOM.\n */\n private copy(n: Node): Node {\n const clone = n.cloneNode(true);\n if (!(clone instanceof Element)) return clone;\n const base = this.ownerDocument.baseURI;\n const unsafe: Element[] = [];\n for (const el of [clone, ...clone.querySelectorAll('*')]) {\n if (this.lightDom) el.removeAttribute('id');\n if (el.localName !== 'a') continue;\n const href = el.getAttribute('href');\n if (href !== null && !safeHref(href, base)) {\n this.warnOnce(\n 'href',\n 'showing a link as text: its href is not http(s), mailto, tel or relative.',\n );\n unsafe.push(el);\n }\n const size = normalize(el.getAttribute('data-size'));\n el.removeAttribute('data-size');\n if (size && !normalize(el.textContent).endsWith(size)) el.append(this.sizeNodes(size));\n }\n // An unsafe link keeps only its content (in a <span> when it is the copied node itself).\n for (const a of unsafe.reverse()) {\n if (a !== clone) {\n a.replaceWith(...a.childNodes);\n continue;\n }\n const span = this.ownerDocument.createElement('span');\n span.append(...a.childNodes);\n return span;\n }\n return clone;\n }\n\n /** \" · 184 KB\", read as \", 184 KB\". */\n private sizeNodes(size: string): DocumentFragment {\n const doc = this.ownerDocument;\n const frag = doc.createDocumentFragment();\n const dot = doc.createElement('span');\n dot.setAttribute('aria-hidden', 'true');\n dot.textContent = ' · ';\n const comma = doc.createElement('span');\n comma.className = 'visually-hidden';\n comma.textContent = ', ';\n frag.append(dot, comma, size);\n return frag;\n }\n\n private renderValue(v: MetadataValue): TemplateResult | string {\n if (v === null || v === undefined) return '';\n if (typeof v !== 'object') return String(v);\n const label = normalize(v.label);\n const href = v.href == null ? '' : String(v.href);\n if (!href || !safeHref(href, this.ownerDocument.baseURI)) {\n if (href)\n this.warnOnce(\n 'href',\n 'showing a link as text: its href is not http(s), mailto, tel or relative.',\n );\n return label;\n }\n const size = normalize(v.size);\n const download = v.download === true ? '' : v.download || undefined;\n return html`<a href=${href} download=${download ?? nothing}\n >${label}${\n size\n ? html`<span aria-hidden=\"true\"> · </span><span class=\"visually-hidden\">, </span>${size}`\n : nothing\n }</a\n >`;\n }\n\n private fromItems(items: readonly MetadataItem[]): Row[] {\n const rows: Row[] = [];\n for (const i of items) {\n const label = normalize(i?.label);\n if (!label) {\n this.warnOnce('label', 'ignoring rows with no label.');\n continue;\n }\n const value = Array.isArray(i.value)\n ? html`<ul role=\"list\">\n ${i.value.map((v) => html`<li>${this.renderValue(v)}</li>`)}\n </ul>`\n : this.renderValue(i.value);\n rows.push({ label, values: [{ content: value }] });\n }\n return rows;\n }\n\n /** The citation text: `citation`, else the Special Collections one for `citation-title`. */\n private get citationText(): string {\n const own = normalize(this.citation);\n if (own) return own;\n const title = normalize(this.citationTitle);\n return title ? specialCollectionsCitation(title) : '';\n }\n\n private renderRights(): TemplateResult | typeof nothing {\n const rights = normalize(this.rights);\n if (!rights) return nothing;\n const base = this.ownerDocument.baseURI;\n const isUrl = /^https?:\\/\\//i.test(rights);\n const statement = isUrl\n ? html`<a href=${rights} rel=\"license\"\n >${normalize(this.rightsLabel) || rightsName(rights) || 'Rights statement'}</a\n >`\n : rights;\n const info = normalize(this.rightsInfo);\n const more =\n info && safeHref(info, base)\n ? html`<div><a href=${info}>${RIGHTS_INFO_TEXT}</a></div>`\n : nothing;\n return html`<div class=\"row\">\n <dt>Rights</dt>\n <dd>\n <div>${statement}</div>\n ${more}\n </dd>\n </div>`;\n }\n\n private renderCitation(): TemplateResult | typeof nothing {\n const text = this.citationText;\n if (!text) return nothing;\n return html`<div class=\"row\">\n <dt>How to cite</dt>\n <dd>\n <p class=\"citation\">${text}</p>\n <div class=\"copy\">\n <button type=\"button\" class=\"uvalib-button\" @click=${this.copyCitation}>\n Copy citation\n </button>\n <span class=\"status\" role=\"status\">${this.status}</span>\n </div>\n </dd>\n </div>`;\n }\n\n /** Copy the citation; on failure select it, so the keyboard can copy it. */\n private async copyCitation(): Promise<void> {\n trackEvent(this, ['uvalib-metadata', 'copy-citation']);\n clearTimeout(this.timer);\n // Cleared first, so a second copy is announced again.\n this.status = '';\n await this.updateComplete;\n let message = 'Copied';\n try {\n await navigator.clipboard.writeText(this.citationText);\n } catch {\n const p = this.renderRoot.querySelector('.citation');\n if (p) this.ownerDocument.getSelection()?.selectAllChildren(p);\n message = 'Could not copy: the citation is selected, copy it with your keyboard';\n }\n this.status = message;\n this.timer = setTimeout(() => (this.status = ''), STATUS_MS);\n }\n\n private get rows(): Row[] {\n return this.items ? this.fromItems(this.items) : this.childRows;\n }\n\n /** The rows' source the clones below were made for. */\n private clonedFor?: unknown;\n private clones = new WeakMap<Node[], Node[]>();\n\n /**\n * A value's nodes: fresh clones of its prepared source whenever the rows shown change\n * (new markup, or back from `items`), reused by unrelated updates (the citation status) so\n * that focus in a value is not lost.\n */\n private nodesOf(source: Node[]): Node[] {\n let c = this.clones.get(source);\n if (!c) this.clones.set(source, (c = source.map((n) => n.cloneNode(true))));\n return c;\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n this.toggleAttribute('data-empty', !this.renderRoot.querySelector('.row'));\n }\n\n protected override render() {\n const text = (label: string, value?: string) => {\n const v = normalize(value);\n return v\n ? html`<div class=\"row\">\n <dt>${label}</dt>\n <dd>${v}</dd>\n </div>`\n : nothing;\n };\n const shownFrom = this.items ?? this.childRows;\n if (shownFrom !== this.clonedFor) {\n this.clonedFor = shownFrom;\n this.clones = new WeakMap();\n }\n return html`<dl>\n ${text('Creator', this.creator)}${text('Organization', this.organization)}\n ${this.rows.map(\n (r) =>\n html`<div class=\"row\">\n <dt lang=${r.lang ?? nothing} dir=${r.dir ?? nothing}>${r.label}</dt>\n ${r.values.map(\n (v) =>\n html`<dd lang=${v.lang ?? nothing} dir=${v.dir ?? nothing}>\n ${v.source ? this.nodesOf(v.source) : v.content}\n </dd>`,\n )}\n </div>`,\n )}\n ${this.renderRights()}${this.renderCitation()}\n </dl>`;\n }\n}\n","import { define } from '../../base/define.js';\nimport { UvalibMetadata } from './UvalibMetadata.js';\n\ndefine('uvalib-metadata', UvalibMetadata);\n"],"mappings":";;;;;;AACA,IAAMoB,IAAqC;CACzC,KAAK;CACL,aAAa;CACb,WAAW;CACX,UAAU;CACV,WAAW;CACX,UAAU;CACV,UAAU;CACV,YAAY;CACZ,UAAU;CACV,KAAK;CACL,KAAK;CACL,KAAK;AACP;AAOA,SAAgBC,EAAW,GAAkC;CAC3D,IAAIC;CACJ,IAAI;EACF,IAAI,IAAI,IAAIC,CAAI;CAClB,QAAQ;EACN;CACF;CACA,IAAMC,IAAOF,EAAE,SAAS,YAAY,CAAC,CAAC,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