@uvalib/web-components 1.10.0 → 1.11.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.
- package/CHANGELOG.md +13 -0
- package/README.md +43 -5
- package/dist/base.css +7 -1
- package/dist/components/uvalib-contents/UvalibContents.d.ts +66 -2
- package/dist/components/uvalib-contents/UvalibContents.js +277 -29
- package/dist/components/uvalib-contents/UvalibContents.js.map +1 -1
- package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.d.ts +27 -1
- package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js +92 -1
- package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js.map +1 -1
- package/dist/custom-elements.json +400 -6
- package/dist/pagefind.css +144 -0
- package/dist/styles/base.js +7 -1
- package/dist/styles/base.js.map +1 -1
- package/dist/styles/pagefind.js +150 -0
- package/dist/styles/pagefind.js.map +1 -1
- package/dist-cdn/base.css +7 -1
- package/dist-cdn/chunks/{base-DXkGlSgH.js → base-DmImIMld.js} +8 -2
- package/dist-cdn/chunks/{base-DXkGlSgH.js.map → base-DmImIMld.js.map} +1 -1
- package/dist-cdn/custom-elements.json +400 -6
- package/dist-cdn/manifest.json +1 -1
- package/dist-cdn/pagefind.css +144 -0
- package/dist-cdn/site-page.js +1 -1
- package/dist-cdn/site-style.js +1 -1
- package/dist-cdn/skills/uvalib-web-components/SKILL.md +2 -2
- package/dist-cdn/skills/uvalib-web-components/reference/components.md +13 -4
- package/dist-cdn/uvalib-contents.js +185 -47
- package/dist-cdn/uvalib-contents.js.map +1 -1
- package/dist-cdn/uvalib-pagefind-search.js +64 -34
- package/dist-cdn/uvalib-pagefind-search.js.map +1 -1
- package/package.json +1 -1
- package/skills/uvalib-web-components/SKILL.md +2 -2
- package/skills/uvalib-web-components/reference/components.md +13 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uvalib-contents.js","names":["unsafeCSS","nothing","unsafeStatic","_decorate","property","state","n","i","r$1","define","__decorate","A","r","installLightDomStyles","UvalibElement","u","s","trackEvent","langDir","inlineCopy","normalize","safeHref","SourceChildren","accessible","markOf","v","entriesKey","items","k","DEFAULT_LABEL","DEFAULT_COLLAPSE","DEFAULT_LEVEL","DEFAULT_LEVELS","DEFAULT_MIN","uid","HEADINGS","slugify","text","headingText","walk","h","structuralRules","host","shadowStructure","pageKey","queryKey","q","UvalibContents","nodes","root","sheet","node","win","on","nav","targets","type","below","kind","message","sel","scope","finder","m","a","b","lo","hi","selector","top","open","added","label","base","id","level","entry","min","hash","list","ordered","out","li","sub","c","x","children","mark","own","item","copy","clean","e","rest","flat","l","entries","found","marked","here","target","resolve","key","query","same","page","section","go","changed","panel","links","p","current","collapsed","headline"],"sources":["../src/components/uvalib-contents/UvalibContents.ts","../src/components/uvalib-contents/uvalib-contents.ts"],"sourcesContent":["import { css, nothing, unsafeCSS, type PropertyValues, type TemplateResult } from 'lit';\nimport { html, unsafeStatic } from 'lit/static-html.js';\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 { inlineCopy, langDir } from '../../base/inline-copy.js';\nimport { normalize, safeHref, SourceChildren } from '../../base/source-children.js';\nimport { accessible } from '../../styles/accessible.js';\n\n/** One entry of the contents: its text, a link (optional for a group label) and sub-entries. */\nexport interface ContentsItem {\n label: string;\n href?: string;\n children?: ContentsItem[];\n}\n\n/**\n * An entry as drawn: `mark` is a valid `aria-current` the author gave its source link;\n * `lang`/`dir` come from the link and `itemLang`/`itemDir` from the `<li>`. `nodes` is a safe inline copy of the label (`em`, `cite`, `code`, `abbr`…),\n * cloned for each render; `rich` describes it, so two reads can be compared.\n */\ninterface Entry {\n label: string;\n href?: string;\n children: Entry[];\n mark?: Current;\n lang?: string;\n dir?: string;\n itemLang?: string;\n itemDir?: string;\n rich?: string;\n nodes?: Node[];\n}\n\n/** An `aria-current` value an author may give: `page`, `location`, or `true` (a page). */\nconst markOf = (v: string | null | undefined): Current | undefined => {\n const t = v?.trim().toLowerCase();\n return t === 'page' || t === 'true' ? 'page' : t === 'location' ? 'location' : undefined;\n};\n\n/** Compare two reads, leaving out the copied nodes (their `rich` key stands for them). */\nconst entriesKey = (items: Entry[]) =>\n JSON.stringify(items, (k, v: unknown) => (k === 'nodes' ? undefined : v));\n\ntype Current = 'page' | 'location';\n\nconst DEFAULT_LABEL = 'Contents';\nconst DEFAULT_COLLAPSE = '64rem';\nconst DEFAULT_LEVEL = 2;\nconst DEFAULT_LEVELS = '2-3';\nconst DEFAULT_MIN = 2;\nlet uid = 0;\n\n/** What is watched in the `headings-from` element: headings added, removed or retitled. */\nconst HEADINGS: MutationObserverInit = { childList: true, characterData: true, subtree: true };\n\n/**\n * An id from a heading's text: lowercase ASCII (accents dropped), runs of anything else as\n * one `-`, none at either end; `section` when nothing is left.\n */\nconst slugify = (text: string): string =>\n text\n .normalize('NFKD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '') || 'section';\n\n/** A heading's text, leaving out what is hidden from assistive technology (a `#` permalink). */\nconst headingText = (h: Element): string => {\n let text = '';\n const walk = (n: Node) => {\n if (n instanceof Element && n.getAttribute('aria-hidden') === 'true') return;\n if (n.nodeType === Node.TEXT_NODE) text += n.textContent;\n else n.childNodes.forEach(walk);\n };\n walk(h);\n return normalize(text);\n};\n\n/**\n * The rules kept with `no-style`: unmarked lists, the disclosure's closed panel hidden, and\n * `[hidden]` hides. `host` is `:host` (shadow) or the tag name (light DOM, so they stay scoped).\n */\nconst structuralRules = (host: string) => `\n ${host} { display: block; }\n ${host} :is(ol, ul) { list-style: none; margin: 0; padding: 0; }\n ${host} li :is(ol, ul) { padding-inline-start: 1rem; }\n ${host}[hidden], ${host} [hidden] { display: none !important; }\n`;\nconst shadowStructure = unsafeCSS(structuralRules(':host'));\n\n/** A comparable form of a URL: origin and path, without a trailing slash or index.html. */\nconst pageKey = (u: URL) =>\n u.origin + (u.pathname.replace(/\\/index\\.html?$/i, '/').replace(/(.)\\/$/, '$1') || '/');\n\n/** The query string as a sorted, comparable form (`?b=2&a=1` is `?a=1&b=2`). */\nconst queryKey = (u: URL) => {\n const q = new URLSearchParams(u.search);\n q.sort();\n return q.toString();\n};\n\n/**\n * Sub-navigation or a table of contents, as library.virginia.edu's sub-navigation: a\n * `<nav>` landmark (named by `label`, \"Contents\" by default) with the label as a visible\n * headline, and a nested list of links with dividers between the top-level entries and a bar\n * beside each nested level.\n *\n * Give the list as a child: an `<ol>` or `<ul>` of `<li>` elements, each with an `<a href>`\n * (or plain text for a group label) and, for sub-entries, a nested `<ol>`/`<ul>`, to any\n * depth. Other children (a heading) are ignored. The list follows changes to the children.\n * Apps set the `items` property instead (`{ label, href?, children? }`, winning over the\n * children while set).\n *\n * The current entry gets `aria-current`: `page` for the link to this page, `location` for the\n * link to the section of it in the URL's hash. It is found from the page URL (path, and hash\n * for in-page sections), followed through same-document navigations (`hashchange`,\n * `popstate` and the Navigation API), or from the `current` attribute (a URL, resolved like\n * the links). An entry whose href has a query string matches only that query (`?part=2`); one\n * without matches the page whatever its query. Hash-only hrefs are places on that page. With\n * `current` unset, a valid `aria-current` on a source link (`page`, `location` or `true`) is\n * used instead, the first of each kind. `lang` and `dir` on the source links and items, and\n * inline markup in their text (`em`, `cite`, `code`, `abbr`…, copied element by element,\n * never as HTML), are kept.\n *\n * On narrow screens the list collapses into a disclosure: the headline becomes a button with\n * `aria-expanded`, and the list starts closed (as the Electronic Text Collections' Contents\n * does on phones, so the text comes first) until the reader opens it, or while the `open`\n * attribute is set; opening it shows the current entry. Narrow means the viewport\n * (`collapse-below`, 64rem by default), not the element's own width: a contents sidebar is\n * always far narrower than 64rem, so a container query could not tell a phone from a\n * desktop. `sticky` keeps it in view in a sidebar on wide\n * screens; a list longer than the window then scrolls, and the current entry is scrolled\n * into view inside it (never the page).\n *\n * A table of contents for a long document: `headings-from=\"#article\"` builds the list from the\n * headings in that element (`levels`, `2-3` by default; nothing shown below `min` top-level\n * entries, 2 by default). Headings without text or hidden with `aria-hidden` are skipped;\n * one without an id gets one from its text (`budget-report`, then `budget-report-2`), and\n * existing ids are kept, so links to sections keep working. It follows headings added,\n * removed or retitled; `refresh()` reads them again after other changes. The children and\n * `items` win while they give a list. Without JavaScript there is no list: a list rendered\n * at build time, as children, works everywhere.\n *\n * Single-page apps: the list is drawn from copies of the children, so a router's own click\n * handlers on them do not run. Listen for `uvalib-contents-navigate` and cancel it to route in\n * place; hash links need nothing.\n *\n * @tagname uvalib-contents\n * @fires uvalib-analytics-event - For `<site-analytics>`: a click on an entry, `['uvalib-contents', 'link-click', 'level <N>', <N>]` (N from 1, the top level), and opening or closing the disclosure, `['uvalib-contents', 'toggle', 'open' | 'close']`; never the label or URL. Bubbles and is composed.\n * @fires uvalib-contents-navigate - A plain click on an entry: `detail` is `{ href, level }` (href as written). Cancel it (`preventDefault()`) to navigate in the app; the click's default is then prevented. Bubbles and is composed.\n * @cssprop [--uvalib-contents-sticky-top=1rem] - With `sticky`: the gap kept above it.\n * @cssprop [--uvalib-contents-max-height=none] - The list's maximum height on wide screens (it scrolls beyond it); with `sticky`, the window's height less twice the sticky gap.\n * @cssprop [--uva-blue-alt-dark=#005679] - Link colour.\n * @cssprop [--uva-brand-blue=#232d4b] - The current entry's bar.\n * @cssprop [--uva-brand-orange=#e57200] - The nested levels' bar.\n * @cssprop [--uva-grey-darkest=#2b2b2b] - Text and current entry 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: text and current entry (else `--uva-grey-darkest`).\n * @cssprop --uva-color-link - Dark-mode role token: the current entry's bar and the button's text (else `--uva-brand-blue`).\n * @cssprop --uva-color-current - Dark-mode role token: the nested levels' bar (else `--uva-brand-orange`).\n * @cssprop --uva-color-border - Dark-mode role token: dividers (else #dadada).\n * @cssprop --uva-color-control-border - Dark-mode role token: the button's border (else #808080).\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 UvalibContents extends UvalibElement {\n static styles = [\n accessible,\n shadowStructure,\n css`\n :host {\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 :host([sticky]:not([data-narrow])) {\n position: sticky;\n top: var(--uvalib-contents-sticky-top, 1rem);\n align-self: start;\n }\n .headline {\n margin: 0 0 0.5rem;\n font-size: 1.125rem;\n font-weight: 700;\n line-height: 1.3;\n }\n /* Balanced, but not when narrow: the headline is then a bordered button, and balanced\n lines would leave empty space inside its box. */\n :host(:not([data-narrow])) .headline {\n text-wrap: balance;\n }\n .panel {\n max-height: var(--uvalib-contents-max-height, none);\n overflow-y: auto;\n overscroll-behavior: contain;\n }\n :host([sticky]:not([data-narrow])) .panel {\n max-height: var(\n --uvalib-contents-max-height,\n calc(100dvh - 2 * var(--uvalib-contents-sticky-top, 1rem) - 3rem)\n );\n }\n :host([data-narrow]) .panel {\n max-height: none;\n overflow: visible;\n }\n .panel > :is(ol, ul) {\n border-block: 1px solid var(--uva-color-border, var(--uva-grey-100, #dadada));\n }\n .panel > :is(ol, ul) > li + li {\n border-top: 1px solid var(--uva-color-border, var(--uva-grey-100, #dadada));\n }\n li :is(ol, ul) {\n margin: 0 0 0.5rem 0.75rem;\n padding: 0;\n border-inline-start: 2px solid var(--uva-color-current, var(--uva-brand-orange, #e57200));\n }\n a,\n .group {\n display: block;\n padding: 0.5rem 0.75rem 0.5rem calc(0.75rem + 4px);\n }\n li li > :is(a, .group) {\n padding-block: 0.25rem;\n }\n .group {\n font-weight: 700;\n }\n a {\n color: var(--uva-color-utility-link, var(--uva-blue-alt-dark, #005679));\n text-decoration: none;\n }\n a:hover {\n text-decoration: underline;\n }\n a[aria-current] {\n padding-inline-start: 0.75rem;\n border-inline-start: 4px solid var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n color: inherit;\n font-weight: 700;\n }\n .panel a:focus-visible {\n outline-offset: -3px;\n }\n .toggle {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 0.75rem;\n box-sizing: border-box;\n width: 100%;\n min-height: 44px;\n margin: 0;\n padding: 0.5rem 0.75rem;\n border: 1px solid var(--uva-color-control-border, var(--uva-grey, #808080));\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 font-weight: 700;\n text-align: start;\n cursor: pointer;\n }\n .toggle::after {\n content: '';\n flex: none;\n width: 0.5em;\n height: 0.5em;\n margin-block-end: 0.25em;\n border-inline-end: 2px solid currentColor;\n border-block-end: 2px solid currentColor;\n transform: rotate(45deg);\n }\n .toggle[aria-expanded='true']::after {\n margin-block: 0.25em 0;\n transform: rotate(225deg);\n }\n :host([data-narrow]) .headline {\n margin-bottom: 0;\n }\n :host([data-narrow]) .panel {\n margin-top: 0.5rem;\n }\n `,\n ];\n\n /** Accessible name of the navigation landmark, and its visible headline. */\n @property({ type: String }) label = DEFAULT_LABEL;\n\n /** The headline's level (2 to 6), for the page's outline. */\n @property({ type: Number, attribute: 'heading-level' }) headingLevel = DEFAULT_LEVEL;\n\n /**\n * The URL of the current entry (resolved like the links), for apps whose route is not the\n * page URL. Unset: the page URL, followed through same-document navigations.\n */\n @property({ type: String }) current?: string;\n\n /**\n * The viewport width at and below which the list collapses into a disclosure: a CSS length\n * (`64rem`, `800px`). `0` or `none` never collapses.\n */\n @property({ type: String, attribute: 'collapse-below' }) collapseBelow = DEFAULT_COLLAPSE;\n\n /** Whether the collapsed disclosure is open (no effect on wide screens). Toggled by its button. */\n @property({ type: Boolean, reflect: true }) open = false;\n\n /** Keep it in view while the page scrolls (a sidebar), on wide screens. */\n @property({ type: Boolean, reflect: true }) sticky = false;\n\n /**\n * The entries as data, for apps that build them in JavaScript: `{ label, href?, children? }`.\n * Wins over the children while set; `undefined` goes back to them. Entries without a label\n * are skipped (with their children) with one console warning.\n */\n @property({ attribute: false }) items?: ContentsItem[];\n\n /**\n * Build the list from the headings in the element this selector names (`#article`): each\n * heading at `levels` gets an entry linking to it (an id is added when it has none), the\n * lower levels nested under the heading before them. The children and `items` win while\n * they give a list.\n */\n @property({ type: String, attribute: 'headings-from' }) headingsFrom?: string;\n\n /** With `headings-from`: the heading levels to list, `2-3` (the default) or one level, `2`. */\n @property({ type: String }) levels = DEFAULT_LEVELS;\n\n /**\n * With `headings-from`: the fewest top-level entries worth a list (default 2). With fewer,\n * nothing is shown.\n */\n @property({ type: Number }) min = DEFAULT_MIN;\n\n /** The entries built from the headings (`headings-from`). */\n @state() private headingItems: Entry[] = [];\n private headingsObserver?: MutationObserver;\n private headingsScope?: Element | null;\n private headingsQueued = false;\n private scrolledToHash = false;\n\n /** The entries read from the children. */\n @state() private childItems: Entry[] = [];\n /** The root list's element in the source (`ol` or `ul`). */\n @state() private ordered = false;\n @state() private narrow = false;\n /** The page URL, updated on same-document navigations. */\n @state() private here = '';\n\n private warned = new Set<string>();\n private readonly panelId = `uvalib-contents-${++uid}`;\n private mql?: MediaQueryList;\n /** What was last scrolled into view, so the list is not scrolled again on every update. */\n private scrolledTo?: string;\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 this.here = this.ownerDocument.defaultView?.location.href ?? '';\n this.listenLocation(true);\n this.watchWidth();\n // Reconnected: the headings may have changed meanwhile (the first time, willUpdate reads).\n if (this.hasUpdated) this.refresh();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.headingsObserver?.disconnect();\n this.headingsScope = undefined;\n this.listenLocation(false);\n this.mql?.removeEventListener('change', this.onWidth);\n this.mql = undefined;\n }\n\n private onLocation = (): void => {\n this.here = this.ownerDocument.defaultView?.location.href ?? '';\n };\n\n private listening = false;\n private listenLocation(on: boolean): void {\n const win = this.ownerDocument.defaultView;\n if (!win || on === this.listening) return;\n this.listening = on;\n const nav = (win as Window & { navigation?: EventTarget }).navigation;\n const targets: [EventTarget, string][] = [\n [win, 'popstate'],\n [win, 'hashchange'],\n ...(nav ? [[nav, 'currententrychange'] as [EventTarget, string]] : []),\n ];\n for (const [t, type] of targets) {\n if (on) t.addEventListener(type, this.onLocation);\n else t.removeEventListener(type, this.onLocation);\n }\n }\n\n private onWidth = (): void => {\n this.narrow = !!this.mql?.matches;\n };\n\n /** Follow the viewport against `collapse-below`. */\n private watchWidth(): void {\n this.mql?.removeEventListener('change', this.onWidth);\n const win = this.ownerDocument.defaultView;\n const below = normalize(this.collapseBelow) || DEFAULT_COLLAPSE;\n this.mql =\n win && !/^(none|0+(\\.0*)?[a-z%]*)$/i.test(below)\n ? win.matchMedia(`(max-width: ${below})`)\n : undefined;\n if (this.mql?.media === 'not all') {\n this.warnOnce('collapse', `ignoring collapse-below=\"${below}\" (not a CSS length).`);\n this.mql = win?.matchMedia(`(max-width: ${DEFAULT_COLLAPSE})`);\n }\n this.mql?.addEventListener('change', this.onWidth);\n this.onWidth();\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 /**\n * With `headings-from`: read the headings again, adding ids to new ones. Headings added,\n * removed or retitled are followed by themselves; call this after other changes (an\n * `aria-hidden` set or a heading's level changed).\n */\n refresh(): void {\n const sel = normalize(this.headingsFrom);\n let scope: Element | null = null;\n if (sel) {\n const root = this.getRootNode();\n const finder =\n root instanceof Document || root instanceof ShadowRoot ? root : this.ownerDocument;\n try {\n scope = finder.querySelector(sel);\n } catch {\n scope = null;\n }\n if (!scope && this.ownerDocument.readyState === 'loading') {\n // Still parsing: try again once the document is read.\n this.ownerDocument.addEventListener('DOMContentLoaded', () => this.refresh(), {\n once: true,\n });\n } else if (!scope) {\n this.warnOnce('headings-from', `no element matches headings-from=\"${sel}\".`);\n }\n }\n if (scope !== this.headingsScope) {\n this.headingsScope = scope;\n this.headingsObserver?.disconnect();\n if (scope) {\n this.headingsObserver ??= new MutationObserver(() => this.queueHeadings());\n this.headingsObserver.observe(scope, HEADINGS);\n }\n }\n const items = scope ? this.fromHeadings(scope) : [];\n if (entriesKey(items) !== entriesKey(this.headingItems)) this.headingItems = items;\n }\n\n /** Several changes at once read the headings once. */\n private queueHeadings(): void {\n if (this.headingsQueued) return;\n this.headingsQueued = true;\n queueMicrotask(() => {\n this.headingsQueued = false;\n if (this.isConnected) this.refresh();\n });\n }\n\n /** The heading levels to list, from `levels`. */\n private get headingRange(): [number, number] {\n const m = /^\\s*([1-6])\\s*(?:-\\s*([1-6]))?\\s*$/.exec(String(this.levels ?? ''));\n if (!m) {\n this.warnOnce(\n 'levels',\n `ignoring levels=\"${this.levels}\" (use a level, 2, or a range, 2-3).`,\n );\n return [2, 3];\n }\n const a = Number(m[1]);\n const b = m[2] ? Number(m[2]) : a;\n return [Math.min(a, b), Math.max(a, b)];\n }\n\n /**\n * The entries for the headings in `scope`, in document order: empty and `aria-hidden` ones\n * and those inside this element skipped; an id added to each without one (a slug of its\n * text, unique with `-2`, `-3`…); each nested under the previous higher-level heading.\n * Fewer than `min` top-level entries: none.\n */\n private fromHeadings(scope: Element): Entry[] {\n const [lo, hi] = this.headingRange;\n const selector = Array.from({ length: hi - lo + 1 }, (_, i) => `h${lo + i}`).join(', ');\n const root = scope.getRootNode() as Document | ShadowRoot;\n const top: Entry[] = [];\n const open: { level: number; entry: Entry }[] = [];\n const added: Element[] = [];\n for (const h of scope.querySelectorAll(selector)) {\n if (this.contains(h) || h.closest('[aria-hidden=\"true\"]')) continue;\n const label = headingText(h);\n if (!label) continue;\n if (!h.id) {\n const base = slugify(label);\n let id = base;\n for (let n = 2; root.getElementById(id); n++) id = `${base}-${n}`;\n h.id = id;\n added.push(h);\n }\n const level = Number(h.localName.slice(1));\n const entry: Entry = { label, href: `#${h.id}`, children: [] };\n while (open.length && open[open.length - 1]!.level >= level) open.pop();\n (open.length ? open[open.length - 1]!.entry.children : top).push(entry);\n open.push({ level, entry });\n }\n this.scrollToAdded(added);\n const min = Number.isFinite(Number(this.min)) ? Math.trunc(Number(this.min)) : DEFAULT_MIN;\n return top.length >= min ? top : [];\n }\n\n /**\n * The page was opened at a section whose heading had no id until now: go there, as the\n * browser would have (once).\n */\n private scrollToAdded(added: Element[]): void {\n if (this.scrolledToHash || !added.length) return;\n const hash = this.ownerDocument.defaultView?.location.hash.slice(1);\n if (!hash) return;\n let id = hash;\n try {\n id = decodeURIComponent(hash);\n } catch {\n /* keep it as written */\n }\n const h = added.find((a) => a.id === id);\n if (!h) return;\n this.scrolledToHash = true;\n requestAnimationFrame(() => h.scrollIntoView());\n }\n\n /** Read the entries from the first list among the children. */\n private read(nodes: Node[]): void {\n let list: Element | null = null;\n for (const n of nodes) {\n if (!(n instanceof Element)) continue;\n list = n.matches('ol, ul') ? n : n.querySelector('ol, ul');\n if (list) break;\n }\n const items = list ? this.parse(list) : [];\n const ordered = list?.localName === 'ol';\n if (ordered !== this.ordered) this.ordered = ordered;\n // Only a real change re-renders.\n if (entriesKey(items) !== entriesKey(this.childItems)) this.childItems = items;\n }\n\n private parse(list: Element): Entry[] {\n const out: Entry[] = [];\n for (const li of list.children) {\n if (li.localName !== 'li') continue;\n const sub = [...li.children].find((c) => c.matches('ol, ul'));\n const a = [...li.querySelectorAll('a[href]')].find((x) => x.closest('li') === li);\n // The entry's own text: the link's, or the item's without its sub-list.\n const label = normalize(\n a\n ? a.textContent\n : [...li.childNodes]\n .filter((c) => c !== sub)\n .map((c) => c.textContent)\n .join(' '),\n );\n const children = sub ? this.parse(sub) : [];\n if (!label) {\n this.warnOnce('label', 'ignoring entries with no text (each needs a label).');\n continue;\n }\n const entry: Entry = { label, children };\n if (a) entry.href = a.getAttribute('href')!;\n const mark = markOf(a?.getAttribute('aria-current'));\n if (mark) entry.mark = mark;\n const own = langDir(a);\n if (own.lang !== undefined) entry.lang = own.lang;\n if (own.dir) entry.dir = own.dir;\n const item = langDir(li);\n if (item.lang !== undefined) entry.itemLang = item.lang;\n if (item.dir) entry.itemDir = item.dir;\n const copy = inlineCopy(\n a ? a.childNodes : [...li.childNodes].filter((c) => c !== sub),\n this.ownerDocument,\n );\n if (copy.rich) {\n entry.rich = copy.key;\n entry.nodes = copy.nodes;\n }\n out.push(entry);\n }\n return out;\n }\n\n private fromItems(items: readonly ContentsItem[]): Entry[] {\n const out: Entry[] = [];\n for (const i of items) {\n const label = normalize(i?.label);\n if (!label) {\n this.warnOnce('label', 'ignoring entries with no text (each needs a label).');\n continue;\n }\n const entry: Entry = { label, children: this.fromItems(i.children ?? []) };\n if (i.href != null) entry.href = String(i.href);\n out.push(entry);\n }\n return out;\n }\n\n /** What is shown: `items` while set, else the children; unsafe hrefs made plain text. */\n private get entries(): Entry[] {\n const base = this.ownerDocument.baseURI;\n const clean = (list: Entry[]): Entry[] =>\n list.map((e) => {\n const children = clean(e.children);\n if (e.href === undefined || safeHref(e.href, base)) return { ...e, children };\n this.warnOnce(\n 'href',\n 'showing an entry as text: its href is not http(s), mailto, tel or relative.',\n );\n const rest: Entry = { ...e, children };\n delete rest.href;\n delete rest.mark;\n return rest;\n });\n return clean(\n this.items\n ? this.fromItems(this.items)\n : this.fromHeadingsNow\n ? this.headingItems\n : this.childItems,\n );\n }\n\n /** Whether the list shown is the one built from the headings (no items, no child list). */\n private get fromHeadingsNow(): boolean {\n return !this.items && !this.childItems.length && !!this.headingItems.length;\n }\n\n /** The current entries: the page's and its section's. */\n private currentOf(entries: Entry[]): Map<Entry, Current> {\n const flat: Entry[] = [];\n const walk = (l: Entry[]) => l.forEach((e) => (flat.push(e), walk(e.children)));\n walk(entries);\n const found = new Map<Entry, Current>();\n // The author's marks, on links only (a group or an unsafe link has none): the first\n // `page` and the first `location`.\n const marked = flat.filter((e) => e.mark && e.href !== undefined);\n if (!this.current && marked.length) {\n for (const kind of ['page', 'location'] as const) {\n const e = marked.find((m) => m.mark === kind);\n if (e) found.set(e, kind);\n }\n return found;\n }\n const base = this.ownerDocument.baseURI;\n const here = this.here || base;\n let target: URL;\n try {\n // A hash-only href is a place on this page, whatever the base URL (about:srcdoc frames).\n const c = this.current || here;\n target = new URL(c, c.startsWith('#') ? here : base);\n } catch {\n return found;\n }\n // Entries' hash-only hrefs are places on the target page (the current URL, or `current`).\n const resolve = (h: string) => new URL(h, h.startsWith('#') ? target.href : base);\n const key = pageKey(target);\n const query = queryKey(target);\n const same = flat.flatMap((e) => {\n if (e.href === undefined) return [];\n try {\n const u = resolve(e.href);\n // An entry with a query names that query (?part=2); one without matches the page\n // whatever its query (tracking parameters).\n if (pageKey(u) !== key || (u.search && queryKey(u) !== query)) return [];\n return [{ e, hash: u.hash }];\n } catch {\n return [];\n }\n });\n const page = same.find((s) => !s.hash);\n if (page) found.set(page.e, 'page');\n const section = target.hash && same.find((s) => s.hash === target.hash);\n if (section) found.set(section.e, 'location');\n return found;\n }\n\n private get level(): number {\n const n = Math.trunc(Number(this.headingLevel));\n return n >= 2 && n <= 6 ? n : DEFAULT_LEVEL;\n }\n\n private toggle(): void {\n this.open = !this.open;\n trackEvent(this, ['uvalib-contents', 'toggle', this.open ? 'open' : 'close']);\n }\n\n /**\n * A plain click on an entry fires a cancelable `uvalib-contents-navigate`; a router that\n * cancels it navigates itself (the click's default is prevented too).\n */\n private onClick(e: MouseEvent): void {\n const a = (e.target as Element | null)?.closest?.('a[href]');\n if (!a || !this.renderRoot.contains(a)) return;\n // Analytics: the entry's level (1 is the top), never its label or URL.\n const level = Number(a.getAttribute('data-level'));\n trackEvent(this, ['uvalib-contents', 'link-click', `level ${level}`, level]);\n if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)\n return;\n const go = new CustomEvent('uvalib-contents-navigate', {\n detail: { href: a.getAttribute('href'), level },\n bubbles: true,\n composed: true,\n cancelable: true,\n });\n if (!this.dispatchEvent(go)) e.preventDefault();\n }\n\n protected override willUpdate(changed: PropertyValues): void {\n if (changed.has('collapseBelow') && this.isConnected) this.watchWidth();\n if (\n (changed.has('headingsFrom') || changed.has('levels') || changed.has('min')) &&\n this.isConnected\n )\n this.refresh();\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n this.toggleAttribute('data-narrow', this.narrow);\n this.toggleAttribute('data-empty', !this.entries.length);\n this.reveal();\n }\n\n /** Scroll the list (never the page) so the current entry shows, once per entry and opening. */\n private reveal(): void {\n const panel = this.renderRoot.querySelector<HTMLElement>(`#${this.panelId}`);\n const links = panel ? [...panel.querySelectorAll<HTMLElement>('a[aria-current]')] : [];\n const a = links.find((l) => l.getAttribute('aria-current') === 'location') ?? links[0];\n if (!panel || !a || panel.hidden) return;\n const key = `${a.getAttribute('href')}|${this.narrow}|${this.open}`;\n if (key === this.scrolledTo) return;\n this.scrolledTo = key;\n if (panel.scrollHeight <= panel.clientHeight) return;\n const p = panel.getBoundingClientRect();\n const r = a.getBoundingClientRect();\n if (r.top >= p.top && r.bottom <= p.bottom) return;\n panel.scrollTop += r.top - p.top - (p.height - r.height) / 2;\n }\n\n private renderList(\n entries: Entry[],\n current: Map<Entry, Current>,\n level: number,\n ): TemplateResult {\n const items = entries.map((e) => {\n const mark = current.get(e);\n // Fresh copies of the label's inline markup each render (a node can be in one place).\n const text = e.nodes ? e.nodes.map((n) => n.cloneNode(true)) : e.label;\n const own =\n e.href !== undefined\n ? html`<a\n href=${e.href}\n data-level=${level}\n aria-current=${mark ?? nothing}\n lang=${e.lang ?? nothing}\n dir=${e.dir ?? nothing}\n >${text}</a\n >`\n : html`<span class=\"group\" lang=${e.lang ?? nothing} dir=${e.dir ?? nothing}\n >${text}</span\n >`;\n return html`<li role=\"listitem\" lang=${e.itemLang ?? nothing} dir=${e.itemDir ?? nothing}>\n ${own}${e.children.length ? this.renderList(e.children, current, level + 1) : nothing}\n </li>`;\n });\n // role=\"list\": Safari drops the list semantics of a list styled without markers. A list\n // built from headings is an <ol>: the document's order.\n return this.ordered || this.fromHeadingsNow\n ? html`<ol role=\"list\">\n ${items}\n </ol>`\n : html`<ul role=\"list\">\n ${items}\n </ul>`;\n }\n\n protected override render() {\n const entries = this.entries;\n const label = normalize(this.label) || DEFAULT_LABEL;\n const h = unsafeStatic(`h${this.level}`);\n const collapsed = this.narrow && !this.open;\n const headline = this.narrow\n ? html`<button\n type=\"button\"\n class=\"toggle\"\n aria-expanded=${this.open ? 'true' : 'false'}\n aria-controls=${this.panelId}\n @click=${this.toggle}\n >\n ${label}\n </button>`\n : label;\n // The heading's tag changes the inner template only: the <nav> (in light DOM, a child\n // of the element) is never replaced.\n return html`<nav aria-label=${label} ?hidden=${!entries.length} @click=${this.onClick}>\n ${html`<${h} class=\"headline\">${headline}</${h}>`}\n <div class=\"panel\" id=${this.panelId} ?hidden=${collapsed}>\n ${this.renderList(entries, this.currentOf(entries), 1)}\n </div>\n </nav>`;\n }\n}\n","import { define } from '../../base/define.js';\nimport { UvalibContents } from './UvalibContents.js';\n\ndefine('uvalib-contents', UvalibContents);\n"],"mappings":";;;;;;;AAoCA,IAAMwB,KAAU,MAAsD;CACpE,IAAM,IAAIC,GAAG,KAAK,CAAC,CAAC,YAAY;CAChC,OAAO,MAAM,UAAU,MAAM,SAAS,SAAS,MAAM,aAAa,aAAa,KAAA;AACjF,GAGMC,KAAc,MAClB,KAAK,UAAUC,IAAQ,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,WAAA,cAAA,KAAA,CAAA,GAEN5C,EAAA,CAAAE,EAAM,CAAA,GAAA0C,EAAA,WAAA,WAAA,KAAA,CAAA,GACN5C,EAAA,CAAAE,EAAM,CAAA,GAAA0C,EAAA,WAAA,UAAA,KAAA,CAAA,GAEN5C,EAAA,CAAAE,EAAM,CAAA,GAAA0C,EAAA,WAAA,QAAA,KAAA,CAAA,GC5VTtC,EAAO,mBAAmBsC,CAAc"}
|
|
1
|
+
{"version":3,"file":"uvalib-contents.js","names":["unsafeCSS","nothing","unsafeStatic","_decorate","property","state","n","i","r$1","define","__decorate","A","r","installLightDomStyles","UvalibElement","u","s","trackEvent","langDir","inlineCopy","normalize","safeHref","SourceChildren","accessible","markOf","v","entriesKey","items","k","DEFAULT_LABEL","DEFAULT_COLLAPSE","DEFAULT_LEVEL","DEFAULT_LEVELS","DEFAULT_MIN","DEFAULT_FULL_LABEL","DEFAULT_NOUN","uid","count","whole","optionalNumber","HEADINGS","slugify","text","headingText","walk","h","structuralRules","host","shadowStructure","pageKey","queryKey","q","UvalibContents","nodes","root","sheet","node","win","on","nav","targets","type","below","kind","message","sel","scope","finder","m","a","b","lo","hi","selector","top","open","added","label","base","id","level","entry","min","hash","list","ordered","out","li","sub","c","x","children","mark","own","item","copy","clean","e","rest","flat","l","entries","found","marked","here","target","resolve","key","query","same","page","section","plural","href","parent","up","size","marks","current","at","start","shown","first","go","changed","panel","links","p","some","windowed","all","total","showing","note","action","collapsed","has","headline","more"],"sources":["../src/components/uvalib-contents/UvalibContents.ts","../src/components/uvalib-contents/uvalib-contents.ts"],"sourcesContent":["import { css, nothing, unsafeCSS, type PropertyValues, type TemplateResult } from 'lit';\nimport { html, unsafeStatic } from 'lit/static-html.js';\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 { inlineCopy, langDir } from '../../base/inline-copy.js';\nimport { normalize, safeHref, SourceChildren } from '../../base/source-children.js';\nimport { accessible } from '../../styles/accessible.js';\n\n/** One entry of the contents: its text, a link (optional for a group label) and sub-entries. */\nexport interface ContentsItem {\n label: string;\n href?: string;\n children?: ContentsItem[];\n}\n\n/**\n * An entry as drawn: `mark` is a valid `aria-current` the author gave its source link;\n * `lang`/`dir` come from the link and `itemLang`/`itemDir` from the `<li>`. `nodes` is a safe inline copy of the label (`em`, `cite`, `code`, `abbr`…),\n * cloned for each render; `rich` describes it, so two reads can be compared.\n */\ninterface Entry {\n label: string;\n href?: string;\n children: Entry[];\n mark?: Current;\n lang?: string;\n dir?: string;\n itemLang?: string;\n itemDir?: string;\n rich?: string;\n nodes?: Node[];\n}\n\n/** An `aria-current` value an author may give: `page`, `location`, or `true` (a page). */\nconst markOf = (v: string | null | undefined): Current | undefined => {\n const t = v?.trim().toLowerCase();\n return t === 'page' || t === 'true' ? 'page' : t === 'location' ? 'location' : undefined;\n};\n\n/** Compare two reads, leaving out the copied nodes (their `rich` key stands for them). */\nconst entriesKey = (items: Entry[]) =>\n JSON.stringify(items, (k, v: unknown) => (k === 'nodes' ? undefined : v));\n\ntype Current = 'page' | 'location';\n\nconst DEFAULT_LABEL = 'Contents';\nconst DEFAULT_COLLAPSE = '64rem';\nconst DEFAULT_LEVEL = 2;\nconst DEFAULT_LEVELS = '2-3';\nconst DEFAULT_MIN = 2;\nconst DEFAULT_FULL_LABEL = 'Full contents';\nconst DEFAULT_NOUN = 'sections';\nlet uid = 0;\n\n/** A count as written in English text (`1,234`), as `<uvalib-results-count>`. */\nconst count = (n: number) => n.toLocaleString('en-US');\n\n/** A whole number at least 0, or undefined. */\nconst whole = (n: unknown): number | undefined => {\n const v = typeof n === 'number' ? n : Number.NaN;\n return Number.isFinite(v) && v >= 0 ? Math.trunc(v) : undefined;\n};\n\n/** `total` and `window` from attributes: a missing or blank one is unset, not 0. */\nconst optionalNumber = {\n fromAttribute: (v: string | null) => (v === null || v.trim() === '' ? undefined : Number(v)),\n toAttribute: (v: number | undefined) => (v === undefined ? null : String(v)),\n};\n\n/** What is watched in the `headings-from` element: headings added, removed or retitled. */\nconst HEADINGS: MutationObserverInit = { childList: true, characterData: true, subtree: true };\n\n/**\n * An id from a heading's text: lowercase ASCII (accents dropped), runs of anything else as\n * one `-`, none at either end; `section` when nothing is left.\n */\nconst slugify = (text: string): string =>\n text\n .normalize('NFKD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '') || 'section';\n\n/** A heading's text, leaving out what is hidden from assistive technology (a `#` permalink). */\nconst headingText = (h: Element): string => {\n let text = '';\n const walk = (n: Node) => {\n if (n instanceof Element && n.getAttribute('aria-hidden') === 'true') return;\n if (n.nodeType === Node.TEXT_NODE) text += n.textContent;\n else n.childNodes.forEach(walk);\n };\n walk(h);\n return normalize(text);\n};\n\n/**\n * The rules kept with `no-style`: unmarked lists, the disclosure's closed panel hidden, the\n * screen-reader line about a partial list visually hidden, and `[hidden]` hides. `host` is\n * `:host` (shadow) or the tag name (light DOM, so they stay scoped).\n */\nconst structuralRules = (host: string) => `\n ${host} { display: block; }\n ${host} :is(ol, ul) { list-style: none; margin: 0; padding: 0; }\n ${host} li :is(ol, ul) { padding-inline-start: 1rem; }\n ${host} .visually-hidden {\n position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;\n overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;\n }\n ${host}[hidden], ${host} [hidden] { display: none !important; }\n`;\nconst shadowStructure = unsafeCSS(structuralRules(':host'));\n\n/** A comparable form of a URL: origin and path, without a trailing slash or index.html. */\nconst pageKey = (u: URL) =>\n u.origin + (u.pathname.replace(/\\/index\\.html?$/i, '/').replace(/(.)\\/$/, '$1') || '/');\n\n/** The query string as a sorted, comparable form (`?b=2&a=1` is `?a=1&b=2`). */\nconst queryKey = (u: URL) => {\n const q = new URLSearchParams(u.search);\n q.sort();\n return q.toString();\n};\n\n/**\n * Sub-navigation or a table of contents, as library.virginia.edu's sub-navigation: a\n * `<nav>` landmark (named by `label`, \"Contents\" by default) with the label as a visible\n * headline, and a nested list of links with dividers between the top-level entries and a bar\n * beside each nested level.\n *\n * Give the list as a child: an `<ol>` or `<ul>` of `<li>` elements, each with an `<a href>`\n * (or plain text for a group label) and, for sub-entries, a nested `<ol>`/`<ul>`, to any\n * depth. Other children (a heading) are ignored. The list follows changes to the children.\n * Apps set the `items` property instead (`{ label, href?, children? }`, winning over the\n * children while set).\n *\n * The current entry gets `aria-current`: `page` for the link to this page, `location` for the\n * link to the section of it in the URL's hash. It is found from the page URL (path, and hash\n * for in-page sections), followed through same-document navigations (`hashchange`,\n * `popstate` and the Navigation API), or from the `current` attribute (a URL, resolved like\n * the links). An entry whose href has a query string matches only that query (`?part=2`); one\n * without matches the page whatever its query. Hash-only hrefs are places on that page. With\n * `current` unset, a valid `aria-current` on a source link (`page`, `location` or `true`) is\n * used instead, the first of each kind. `lang` and `dir` on the source links and items, and\n * inline markup in their text (`em`, `cite`, `code`, `abbr`…, copied element by element,\n * never as HTML), are kept.\n *\n * On narrow screens the list collapses into a disclosure: the headline becomes a button with\n * `aria-expanded`, and the list starts closed (as the Electronic Text Collections' Contents\n * does on phones, so the text comes first) until the reader opens it, or while the `open`\n * attribute is set; opening it shows the current entry. Narrow means the viewport\n * (`collapse-below`, 64rem by default), not the element's own width: a contents sidebar is\n * always far narrower than 64rem, so a container query could not tell a phone from a\n * desktop. `sticky` keeps it in view in a sidebar on wide\n * screens; a list longer than the window then scrolls, and the current entry is scrolled\n * into view inside it (never the page).\n *\n * A table of contents for a long document: `headings-from=\"#article\"` builds the list from the\n * headings in that element (`levels`, `2-3` by default; nothing shown below `min` top-level\n * entries, 2 by default). Headings without text or hidden with `aria-hidden` are skipped;\n * one without an id gets one from its text (`budget-report`, then `budget-report-2`), and\n * existing ids are kept, so links to sections keep working. It follows headings added,\n * removed or retitled; `refresh()` reads them again after other changes. The children and\n * `items` win while they give a list. Without JavaScript there is no list: a list rendered\n * at build time, as children, works everywhere.\n *\n * A very long contents (a text with hundreds of sections, each its own page) can show only\n * part of the list, with a link to the whole. `full-href` adds that link after the list: not\n * an entry but a call to action (bold, underlined, with an arrow), its text `full-label`\n * (\"Full contents\") followed by the count when `total` (the entries in the full contents) is\n * set: \"Full contents (243 sections)\" (`noun`, \"sections\" by default; `singular` for one). A\n * static site writes only the entries near the current one (with their parents) and sets\n * these. `window=\"12\"` does it in the browser when the whole list is given: only the current\n * entry and the 12 before and after it in document order (25 entries, shifted at either end)\n * are shown, with their parents so the nesting still makes sense; the others are hidden, not\n * removed, and a gap between the entries shown is marked with an ellipsis (hidden from\n * assistive technology). It follows the current entry, and applies to `items` and\n * `headings-from` too. Without `full-href`, a \"Show all 243 sections\" button shows the rest in\n * place (\"Show fewer\" goes back). While part of the list is shown, a visually hidden line\n * before it says so (\"Showing 25 of 243 sections.\"); the headline and the landmark keep the\n * visible label as their name. On narrow screens the link and the button are inside the\n * disclosure.\n *\n * Single-page apps: the list is drawn from copies of the children, so a router's own click\n * handlers on them do not run. Listen for `uvalib-contents-navigate` and cancel it to route in\n * place; hash links need nothing.\n *\n * @tagname uvalib-contents\n * @fires uvalib-analytics-event - For `<site-analytics>`: a click on an entry, `['uvalib-contents', 'link-click', 'level <N>', <N>]` (N from 1, the top level), on the full-contents link, `['uvalib-contents', 'full-contents-click']`, opening or closing the disclosure, `['uvalib-contents', 'toggle', 'open' | 'close']`, and the window's button, `['uvalib-contents', 'show-all' | 'show-fewer']`; never the label or URL. Bubbles and is composed.\n * @fires uvalib-contents-navigate - A plain click on an entry or the full-contents link: `detail` is `{ href, level }` (href as written; level 0 for the full-contents link). Cancel it (`preventDefault()`) to navigate in the app; the click's default is then prevented. Bubbles and is composed.\n * @cssprop [--uvalib-contents-sticky-top=1rem] - With `sticky`: the gap kept above it.\n * @cssprop [--uvalib-contents-max-height=none] - The list's maximum height on wide screens (it scrolls beyond it); with `sticky`, the window's height less twice the sticky gap.\n * @cssprop [--uva-blue-alt-dark=#005679] - Link colour.\n * @cssprop [--uva-brand-blue=#232d4b] - The current entry's bar.\n * @cssprop [--uva-brand-orange=#e57200] - The nested levels' bar.\n * @cssprop [--uva-grey-darkest=#2b2b2b] - Text and current entry 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: text and current entry (else `--uva-grey-darkest`).\n * @cssprop --uva-color-link - Dark-mode role token: the current entry's bar and the button's text (else `--uva-brand-blue`).\n * @cssprop --uva-color-current - Dark-mode role token: the nested levels' bar (else `--uva-brand-orange`).\n * @cssprop --uva-color-text-muted - Dark-mode role token: the ellipsis between the entries a window shows (else #4f4f4f).\n * @cssprop --uva-color-border - Dark-mode role token: dividers (else #dadada).\n * @cssprop --uva-color-control-border - Dark-mode role token: the button's border (else #808080).\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 UvalibContents extends UvalibElement {\n static styles = [\n accessible,\n shadowStructure,\n css`\n :host {\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 :host([sticky]:not([data-narrow])) {\n position: sticky;\n top: var(--uvalib-contents-sticky-top, 1rem);\n align-self: start;\n }\n .headline {\n margin: 0 0 0.5rem;\n font-size: 1.125rem;\n font-weight: 700;\n line-height: 1.3;\n }\n /* Balanced, but not when narrow: the headline is then a bordered button, and balanced\n lines would leave empty space inside its box. */\n :host(:not([data-narrow])) .headline {\n text-wrap: balance;\n }\n .panel {\n max-height: var(--uvalib-contents-max-height, none);\n overflow-y: auto;\n overscroll-behavior: contain;\n }\n :host([sticky]:not([data-narrow])) .panel {\n max-height: var(\n --uvalib-contents-max-height,\n calc(100dvh - 2 * var(--uvalib-contents-sticky-top, 1rem) - 3rem)\n );\n }\n :host([data-narrow]) .panel {\n max-height: none;\n overflow: visible;\n }\n .panel > :is(ol, ul) {\n border-block: 1px solid var(--uva-color-border, var(--uva-grey-100, #dadada));\n }\n .panel > :is(ol, ul) > li + li {\n border-top: 1px solid var(--uva-color-border, var(--uva-grey-100, #dadada));\n }\n li :is(ol, ul) {\n margin: 0 0 0.5rem 0.75rem;\n padding: 0;\n border-inline-start: 2px solid var(--uva-color-current, var(--uva-brand-orange, #e57200));\n }\n a,\n .group {\n display: block;\n padding: 0.5rem 0.75rem 0.5rem calc(0.75rem + 4px);\n }\n li li > :is(a, .group) {\n padding-block: 0.25rem;\n }\n .group {\n font-weight: 700;\n }\n a {\n color: var(--uva-color-utility-link, var(--uva-blue-alt-dark, #005679));\n text-decoration: none;\n }\n a:hover {\n text-decoration: underline;\n }\n a[aria-current] {\n padding-inline-start: 0.75rem;\n border-inline-start: 4px solid var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n color: inherit;\n font-weight: 700;\n }\n .panel a:focus-visible {\n outline-offset: -3px;\n }\n .toggle {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 0.75rem;\n box-sizing: border-box;\n width: 100%;\n min-height: 44px;\n margin: 0;\n padding: 0.5rem 0.75rem;\n border: 1px solid var(--uva-color-control-border, var(--uva-grey, #808080));\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 font-weight: 700;\n text-align: start;\n cursor: pointer;\n }\n .toggle::after {\n content: '';\n flex: none;\n width: 0.5em;\n height: 0.5em;\n margin-block-end: 0.25em;\n border-inline-end: 2px solid currentColor;\n border-block-end: 2px solid currentColor;\n transform: rotate(45deg);\n }\n .toggle[aria-expanded='true']::after {\n margin-block: 0.25em 0;\n transform: rotate(225deg);\n }\n :host([data-narrow]) .headline {\n margin-bottom: 0;\n }\n :host([data-narrow]) .panel {\n margin-top: 0.5rem;\n }\n /* A gap between the entries a window shows (aria-hidden). */\n .gap {\n padding: 0 0.75rem 0.25rem calc(0.75rem + 4px);\n color: var(--uva-color-text-muted, var(--uva-grey-A, #4f4f4f));\n line-height: 1;\n letter-spacing: 0.1em;\n }\n /* The full-contents link and the window's button: a call to action after the list, as\n library.virginia.edu's \"See all\" links (bold, underlined, an arrow), its text lined up\n with the entries'. Outside the scrolling panel, so it shows however long the list. */\n .more {\n margin: 0.5rem 0 0;\n }\n .more > :is(a, button) {\n display: inline-flex;\n align-items: center;\n gap: 0.5rem;\n box-sizing: border-box;\n min-height: 44px;\n margin: 0;\n padding: 0.5rem 0.75rem 0.5rem calc(0.75rem + 4px);\n border: 0;\n background: none;\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n font: inherit;\n font-weight: 700;\n text-align: start;\n text-decoration: underline;\n text-decoration-thickness: 1px;\n text-underline-offset: 0.2em;\n cursor: pointer;\n }\n .more > :is(a, button):hover {\n text-decoration-thickness: 2px;\n }\n .more > a::after {\n content: '';\n flex: none;\n width: 0.45em;\n height: 0.45em;\n border-inline-end: 2px solid currentColor;\n border-block-start: 2px solid currentColor;\n transform: rotate(45deg);\n }\n .more > a:dir(rtl)::after {\n transform: rotate(-45deg);\n }\n :host([sticky][data-more]:not([data-narrow])) .panel {\n max-height: var(\n --uvalib-contents-max-height,\n calc(100dvh - 2 * var(--uvalib-contents-sticky-top, 1rem) - 6.5rem)\n );\n }\n `,\n ];\n\n /** Accessible name of the navigation landmark, and its visible headline. */\n @property({ type: String }) label = DEFAULT_LABEL;\n\n /** The headline's level (2 to 6), for the page's outline. */\n @property({ type: Number, attribute: 'heading-level' }) headingLevel = DEFAULT_LEVEL;\n\n /**\n * The URL of the current entry (resolved like the links), for apps whose route is not the\n * page URL. Unset: the page URL, followed through same-document navigations.\n */\n @property({ type: String }) current?: string;\n\n /**\n * The viewport width at and below which the list collapses into a disclosure: a CSS length\n * (`64rem`, `800px`). `0` or `none` never collapses.\n */\n @property({ type: String, attribute: 'collapse-below' }) collapseBelow = DEFAULT_COLLAPSE;\n\n /** Whether the collapsed disclosure is open (no effect on wide screens). Toggled by its button. */\n @property({ type: Boolean, reflect: true }) open = false;\n\n /** Keep it in view while the page scrolls (a sidebar), on wide screens. */\n @property({ type: Boolean, reflect: true }) sticky = false;\n\n /**\n * The entries as data, for apps that build them in JavaScript: `{ label, href?, children? }`.\n * Wins over the children while set; `undefined` goes back to them. Entries without a label\n * are skipped (with their children) with one console warning.\n */\n @property({ attribute: false }) items?: ContentsItem[];\n\n /**\n * Build the list from the headings in the element this selector names (`#article`): each\n * heading at `levels` gets an entry linking to it (an id is added when it has none), the\n * lower levels nested under the heading before them. The children and `items` win while\n * they give a list.\n */\n @property({ type: String, attribute: 'headings-from' }) headingsFrom?: string;\n\n /** With `headings-from`: the heading levels to list, `2-3` (the default) or one level, `2`. */\n @property({ type: String }) levels = DEFAULT_LEVELS;\n\n /**\n * With `headings-from`: the fewest top-level entries worth a list (default 2). With fewer,\n * nothing is shown.\n */\n @property({ type: Number }) min = DEFAULT_MIN;\n\n /**\n * The URL of the full contents, when the list is only part of it: a \"Full contents\" link\n * after the list (`full-label`, with the count from `total`).\n */\n @property({ type: String, attribute: 'full-href' }) fullHref?: string;\n\n /** The full-contents link's text, before the count: \"Full contents\" by default. */\n @property({ type: String, attribute: 'full-label' }) fullLabel = DEFAULT_FULL_LABEL;\n\n /**\n * How many entries the full contents has, for the link (\"Full contents (243 sections)\") and\n * the screen-reader line (\"Showing 25 of 243 sections.\"). With `window`, the whole list's\n * count when unset.\n */\n @property({ converter: optionalNumber }) total?: number;\n\n /** What the entries are, plural, in the counts: \"sections\" by default. */\n @property({ type: String }) noun = DEFAULT_NOUN;\n\n /** What an entry is, singular, for a count of one. Default: \"section\" for the default `noun`, else `noun`. */\n @property({ type: String }) singular = '';\n\n /**\n * Show only the current entry and this many before and after it in document order (and\n * their parents); the others are hidden. Unset or blank: every entry.\n */\n @property({ converter: optionalNumber, attribute: 'window' }) windowSize?: number;\n\n /** Whether \"Show all\" was pressed (a window without `full-href`). */\n @state() private expanded = false;\n\n /** The entries built from the headings (`headings-from`). */\n @state() private headingItems: Entry[] = [];\n private headingsObserver?: MutationObserver;\n private headingsScope?: Element | null;\n private headingsQueued = false;\n private scrolledToHash = false;\n\n /** The entries read from the children. */\n @state() private childItems: Entry[] = [];\n /** The root list's element in the source (`ol` or `ul`). */\n @state() private ordered = false;\n @state() private narrow = false;\n /** The page URL, updated on same-document navigations. */\n @state() private here = '';\n\n private warned = new Set<string>();\n private readonly panelId = `uvalib-contents-${++uid}`;\n private mql?: MediaQueryList;\n /** Whether the last render drew the full-contents link or the window's button. */\n private hasMore = false;\n /** What was last scrolled into view, so the list is not scrolled again on every update. */\n private scrolledTo?: string;\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 this.here = this.ownerDocument.defaultView?.location.href ?? '';\n this.listenLocation(true);\n this.watchWidth();\n // Reconnected: the headings may have changed meanwhile (the first time, willUpdate reads).\n if (this.hasUpdated) this.refresh();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.headingsObserver?.disconnect();\n this.headingsScope = undefined;\n this.listenLocation(false);\n this.mql?.removeEventListener('change', this.onWidth);\n this.mql = undefined;\n }\n\n private onLocation = (): void => {\n this.here = this.ownerDocument.defaultView?.location.href ?? '';\n };\n\n private listening = false;\n private listenLocation(on: boolean): void {\n const win = this.ownerDocument.defaultView;\n if (!win || on === this.listening) return;\n this.listening = on;\n const nav = (win as Window & { navigation?: EventTarget }).navigation;\n const targets: [EventTarget, string][] = [\n [win, 'popstate'],\n [win, 'hashchange'],\n ...(nav ? [[nav, 'currententrychange'] as [EventTarget, string]] : []),\n ];\n for (const [t, type] of targets) {\n if (on) t.addEventListener(type, this.onLocation);\n else t.removeEventListener(type, this.onLocation);\n }\n }\n\n private onWidth = (): void => {\n this.narrow = !!this.mql?.matches;\n };\n\n /** Follow the viewport against `collapse-below`. */\n private watchWidth(): void {\n this.mql?.removeEventListener('change', this.onWidth);\n const win = this.ownerDocument.defaultView;\n const below = normalize(this.collapseBelow) || DEFAULT_COLLAPSE;\n this.mql =\n win && !/^(none|0+(\\.0*)?[a-z%]*)$/i.test(below)\n ? win.matchMedia(`(max-width: ${below})`)\n : undefined;\n if (this.mql?.media === 'not all') {\n this.warnOnce('collapse', `ignoring collapse-below=\"${below}\" (not a CSS length).`);\n this.mql = win?.matchMedia(`(max-width: ${DEFAULT_COLLAPSE})`);\n }\n this.mql?.addEventListener('change', this.onWidth);\n this.onWidth();\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 /**\n * With `headings-from`: read the headings again, adding ids to new ones. Headings added,\n * removed or retitled are followed by themselves; call this after other changes (an\n * `aria-hidden` set or a heading's level changed).\n */\n refresh(): void {\n const sel = normalize(this.headingsFrom);\n let scope: Element | null = null;\n if (sel) {\n const root = this.getRootNode();\n const finder =\n root instanceof Document || root instanceof ShadowRoot ? root : this.ownerDocument;\n try {\n scope = finder.querySelector(sel);\n } catch {\n scope = null;\n }\n if (!scope && this.ownerDocument.readyState === 'loading') {\n // Still parsing: try again once the document is read.\n this.ownerDocument.addEventListener('DOMContentLoaded', () => this.refresh(), {\n once: true,\n });\n } else if (!scope) {\n this.warnOnce('headings-from', `no element matches headings-from=\"${sel}\".`);\n }\n }\n if (scope !== this.headingsScope) {\n this.headingsScope = scope;\n this.headingsObserver?.disconnect();\n if (scope) {\n this.headingsObserver ??= new MutationObserver(() => this.queueHeadings());\n this.headingsObserver.observe(scope, HEADINGS);\n }\n }\n const items = scope ? this.fromHeadings(scope) : [];\n if (entriesKey(items) !== entriesKey(this.headingItems)) this.headingItems = items;\n }\n\n /** Several changes at once read the headings once. */\n private queueHeadings(): void {\n if (this.headingsQueued) return;\n this.headingsQueued = true;\n queueMicrotask(() => {\n this.headingsQueued = false;\n if (this.isConnected) this.refresh();\n });\n }\n\n /** The heading levels to list, from `levels`. */\n private get headingRange(): [number, number] {\n const m = /^\\s*([1-6])\\s*(?:-\\s*([1-6]))?\\s*$/.exec(String(this.levels ?? ''));\n if (!m) {\n this.warnOnce(\n 'levels',\n `ignoring levels=\"${this.levels}\" (use a level, 2, or a range, 2-3).`,\n );\n return [2, 3];\n }\n const a = Number(m[1]);\n const b = m[2] ? Number(m[2]) : a;\n return [Math.min(a, b), Math.max(a, b)];\n }\n\n /**\n * The entries for the headings in `scope`, in document order: empty and `aria-hidden` ones\n * and those inside this element skipped; an id added to each without one (a slug of its\n * text, unique with `-2`, `-3`…); each nested under the previous higher-level heading.\n * Fewer than `min` top-level entries: none.\n */\n private fromHeadings(scope: Element): Entry[] {\n const [lo, hi] = this.headingRange;\n const selector = Array.from({ length: hi - lo + 1 }, (_, i) => `h${lo + i}`).join(', ');\n const root = scope.getRootNode() as Document | ShadowRoot;\n const top: Entry[] = [];\n const open: { level: number; entry: Entry }[] = [];\n const added: Element[] = [];\n for (const h of scope.querySelectorAll(selector)) {\n if (this.contains(h) || h.closest('[aria-hidden=\"true\"]')) continue;\n const label = headingText(h);\n if (!label) continue;\n if (!h.id) {\n const base = slugify(label);\n let id = base;\n for (let n = 2; root.getElementById(id); n++) id = `${base}-${n}`;\n h.id = id;\n added.push(h);\n }\n const level = Number(h.localName.slice(1));\n const entry: Entry = { label, href: `#${h.id}`, children: [] };\n while (open.length && open[open.length - 1]!.level >= level) open.pop();\n (open.length ? open[open.length - 1]!.entry.children : top).push(entry);\n open.push({ level, entry });\n }\n this.scrollToAdded(added);\n const min = Number.isFinite(Number(this.min)) ? Math.trunc(Number(this.min)) : DEFAULT_MIN;\n return top.length >= min ? top : [];\n }\n\n /**\n * The page was opened at a section whose heading had no id until now: go there, as the\n * browser would have (once).\n */\n private scrollToAdded(added: Element[]): void {\n if (this.scrolledToHash || !added.length) return;\n const hash = this.ownerDocument.defaultView?.location.hash.slice(1);\n if (!hash) return;\n let id = hash;\n try {\n id = decodeURIComponent(hash);\n } catch {\n /* keep it as written */\n }\n const h = added.find((a) => a.id === id);\n if (!h) return;\n this.scrolledToHash = true;\n requestAnimationFrame(() => h.scrollIntoView());\n }\n\n /** Read the entries from the first list among the children. */\n private read(nodes: Node[]): void {\n let list: Element | null = null;\n for (const n of nodes) {\n if (!(n instanceof Element)) continue;\n list = n.matches('ol, ul') ? n : n.querySelector('ol, ul');\n if (list) break;\n }\n const items = list ? this.parse(list) : [];\n const ordered = list?.localName === 'ol';\n if (ordered !== this.ordered) this.ordered = ordered;\n // Only a real change re-renders.\n if (entriesKey(items) !== entriesKey(this.childItems)) this.childItems = items;\n }\n\n private parse(list: Element): Entry[] {\n const out: Entry[] = [];\n for (const li of list.children) {\n if (li.localName !== 'li') continue;\n const sub = [...li.children].find((c) => c.matches('ol, ul'));\n const a = [...li.querySelectorAll('a[href]')].find((x) => x.closest('li') === li);\n // The entry's own text: the link's, or the item's without its sub-list.\n const label = normalize(\n a\n ? a.textContent\n : [...li.childNodes]\n .filter((c) => c !== sub)\n .map((c) => c.textContent)\n .join(' '),\n );\n const children = sub ? this.parse(sub) : [];\n if (!label) {\n this.warnOnce('label', 'ignoring entries with no text (each needs a label).');\n continue;\n }\n const entry: Entry = { label, children };\n if (a) entry.href = a.getAttribute('href')!;\n const mark = markOf(a?.getAttribute('aria-current'));\n if (mark) entry.mark = mark;\n const own = langDir(a);\n if (own.lang !== undefined) entry.lang = own.lang;\n if (own.dir) entry.dir = own.dir;\n const item = langDir(li);\n if (item.lang !== undefined) entry.itemLang = item.lang;\n if (item.dir) entry.itemDir = item.dir;\n const copy = inlineCopy(\n a ? a.childNodes : [...li.childNodes].filter((c) => c !== sub),\n this.ownerDocument,\n );\n if (copy.rich) {\n entry.rich = copy.key;\n entry.nodes = copy.nodes;\n }\n out.push(entry);\n }\n return out;\n }\n\n private fromItems(items: readonly ContentsItem[]): Entry[] {\n const out: Entry[] = [];\n for (const i of items) {\n const label = normalize(i?.label);\n if (!label) {\n this.warnOnce('label', 'ignoring entries with no text (each needs a label).');\n continue;\n }\n const entry: Entry = { label, children: this.fromItems(i.children ?? []) };\n if (i.href != null) entry.href = String(i.href);\n out.push(entry);\n }\n return out;\n }\n\n /** What is shown: `items` while set, else the children; unsafe hrefs made plain text. */\n private get entries(): Entry[] {\n const base = this.ownerDocument.baseURI;\n const clean = (list: Entry[]): Entry[] =>\n list.map((e) => {\n const children = clean(e.children);\n if (e.href === undefined || safeHref(e.href, base)) return { ...e, children };\n this.warnOnce(\n 'href',\n 'showing an entry as text: its href is not http(s), mailto, tel or relative.',\n );\n const rest: Entry = { ...e, children };\n delete rest.href;\n delete rest.mark;\n return rest;\n });\n return clean(\n this.items\n ? this.fromItems(this.items)\n : this.fromHeadingsNow\n ? this.headingItems\n : this.childItems,\n );\n }\n\n /** Whether the list shown is the one built from the headings (no items, no child list). */\n private get fromHeadingsNow(): boolean {\n return !this.items && !this.childItems.length && !!this.headingItems.length;\n }\n\n /** The current entries: the page's and its section's. */\n private currentOf(entries: Entry[]): Map<Entry, Current> {\n const flat: Entry[] = [];\n const walk = (l: Entry[]) => l.forEach((e) => (flat.push(e), walk(e.children)));\n walk(entries);\n const found = new Map<Entry, Current>();\n // The author's marks, on links only (a group or an unsafe link has none): the first\n // `page` and the first `location`.\n const marked = flat.filter((e) => e.mark && e.href !== undefined);\n if (!this.current && marked.length) {\n for (const kind of ['page', 'location'] as const) {\n const e = marked.find((m) => m.mark === kind);\n if (e) found.set(e, kind);\n }\n return found;\n }\n const base = this.ownerDocument.baseURI;\n const here = this.here || base;\n let target: URL;\n try {\n // A hash-only href is a place on this page, whatever the base URL (about:srcdoc frames).\n const c = this.current || here;\n target = new URL(c, c.startsWith('#') ? here : base);\n } catch {\n return found;\n }\n // Entries' hash-only hrefs are places on the target page (the current URL, or `current`).\n const resolve = (h: string) => new URL(h, h.startsWith('#') ? target.href : base);\n const key = pageKey(target);\n const query = queryKey(target);\n const same = flat.flatMap((e) => {\n if (e.href === undefined) return [];\n try {\n const u = resolve(e.href);\n // An entry with a query names that query (?part=2); one without matches the page\n // whatever its query (tracking parameters).\n if (pageKey(u) !== key || (u.search && queryKey(u) !== query)) return [];\n return [{ e, hash: u.hash }];\n } catch {\n return [];\n }\n });\n const page = same.find((s) => !s.hash);\n if (page) found.set(page.e, 'page');\n const section = target.hash && same.find((s) => s.hash === target.hash);\n if (section) found.set(section.e, 'location');\n return found;\n }\n\n private get level(): number {\n const n = Math.trunc(Number(this.headingLevel));\n return n >= 2 && n <= 6 ? n : DEFAULT_LEVEL;\n }\n\n /** The noun for `n` entries. */\n private word(n: number): string {\n const plural = normalize(this.noun) || DEFAULT_NOUN;\n if (n !== 1) return plural;\n return normalize(this.singular) || (plural === DEFAULT_NOUN ? 'section' : plural);\n }\n\n /** The safe `full-href`, or undefined (unset, blank, or not http(s), mailto, tel or relative). */\n private get fullLink(): string | undefined {\n const href = this.fullHref?.trim();\n if (!href) return undefined;\n if (safeHref(href, this.ownerDocument.baseURI)) return href;\n this.warnOnce('full-href', 'ignoring full-href: it is not http(s), mailto, tel or relative.');\n return undefined;\n }\n\n /**\n * With `window`: the entries shown (the current one, `window` before and after it in\n * document order, shifted at either end, and their parents), or undefined when every entry\n * shows. The current entry is the section's (`location`), else the page's; with none, the\n * window starts at the top.\n */\n private windowOf(entries: Entry[], current: Map<Entry, Current>): Set<Entry> | undefined {\n const n = whole(this.windowSize);\n if (n === undefined || this.expanded) return undefined;\n const flat: Entry[] = [];\n const parent = new Map<Entry, Entry>();\n const walk = (list: Entry[], up?: Entry) =>\n list.forEach((e) => {\n flat.push(e);\n if (up) parent.set(e, up);\n walk(e.children, e);\n });\n walk(entries);\n const size = 2 * n + 1;\n if (flat.length <= size) return undefined;\n const marks = [...current];\n const here = (marks.find(([, k]) => k === 'location') ??\n marks.find(([, k]) => k === 'page'))?.[0];\n const at = here ? flat.indexOf(here) : 0;\n const start = Math.min(Math.max(at - n, 0), flat.length - size);\n const shown = new Set<Entry>();\n for (const first of flat.slice(start, start + size))\n for (let e: Entry | undefined = first; e && !shown.has(e); e = parent.get(e)) shown.add(e);\n return shown;\n }\n\n private showAll(): void {\n this.expanded = !this.expanded;\n trackEvent(this, ['uvalib-contents', this.expanded ? 'show-all' : 'show-fewer']);\n }\n\n private toggle(): void {\n this.open = !this.open;\n trackEvent(this, ['uvalib-contents', 'toggle', this.open ? 'open' : 'close']);\n }\n\n /**\n * A plain click on an entry fires a cancelable `uvalib-contents-navigate`; a router that\n * cancels it navigates itself (the click's default is prevented too).\n */\n private onClick(e: MouseEvent): void {\n const a = (e.target as Element | null)?.closest?.('a[href]');\n if (!a || !this.renderRoot.contains(a)) return;\n // Analytics: the entry's level (1 is the top), never its label or URL.\n const level = Number(a.getAttribute('data-level'));\n if (level) trackEvent(this, ['uvalib-contents', 'link-click', `level ${level}`, level]);\n else trackEvent(this, ['uvalib-contents', 'full-contents-click']);\n if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)\n return;\n const go = new CustomEvent('uvalib-contents-navigate', {\n detail: { href: a.getAttribute('href'), level },\n bubbles: true,\n composed: true,\n cancelable: true,\n });\n if (!this.dispatchEvent(go)) e.preventDefault();\n }\n\n protected override willUpdate(changed: PropertyValues): void {\n if (changed.has('collapseBelow') && this.isConnected) this.watchWidth();\n if (\n (changed.has('headingsFrom') || changed.has('levels') || changed.has('min')) &&\n this.isConnected\n )\n this.refresh();\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n this.toggleAttribute('data-narrow', this.narrow);\n this.toggleAttribute('data-empty', !this.entries.length);\n this.toggleAttribute('data-more', this.hasMore);\n this.reveal();\n }\n\n /** Scroll the list (never the page) so the current entry shows, once per entry and opening. */\n private reveal(): void {\n const panel = this.renderRoot.querySelector<HTMLElement>(`#${this.panelId}`);\n const links = panel ? [...panel.querySelectorAll<HTMLElement>('a[aria-current]')] : [];\n const a = links.find((l) => l.getAttribute('aria-current') === 'location') ?? links[0];\n if (!panel || !a || panel.hidden) return;\n const key = `${a.getAttribute('href')}|${this.narrow}|${this.open}`;\n if (key === this.scrolledTo) return;\n this.scrolledTo = key;\n if (panel.scrollHeight <= panel.clientHeight) return;\n const p = panel.getBoundingClientRect();\n const r = a.getBoundingClientRect();\n if (r.top >= p.top && r.bottom <= p.bottom) return;\n panel.scrollTop += r.top - p.top - (p.height - r.height) / 2;\n }\n\n private renderList(\n entries: Entry[],\n current: Map<Entry, Current>,\n level: number,\n shown?: Set<Entry>,\n ): TemplateResult {\n // A window: the entries it leaves out stay, hidden; each run of them between or around\n // entries shown is one ellipsis (aria-hidden), and a list with none shown is hidden whole.\n const some = !shown || entries.some((e) => shown.has(e));\n const items: TemplateResult[] = [];\n entries.forEach((e, i) => {\n const out = !!shown && !shown.has(e);\n if (out && some && (i === 0 || shown.has(entries[i - 1]!)))\n items.push(html`<li class=\"gap\" aria-hidden=\"true\">…</li>`);\n items.push(this.renderEntry(e, current, level, out, shown));\n });\n // role=\"list\": Safari drops the list semantics of a list styled without markers. A list\n // built from headings is an <ol>: the document's order.\n return this.ordered || this.fromHeadingsNow\n ? html`<ol role=\"list\" ?hidden=${!some}>\n ${items}\n </ol>`\n : html`<ul role=\"list\" ?hidden=${!some}>\n ${items}\n </ul>`;\n }\n\n private renderEntry(\n e: Entry,\n current: Map<Entry, Current>,\n level: number,\n out: boolean,\n shown?: Set<Entry>,\n ): TemplateResult {\n const mark = current.get(e);\n // Fresh copies of the label's inline markup each render (a node can be in one place).\n const text = e.nodes ? e.nodes.map((n) => n.cloneNode(true)) : e.label;\n const own =\n e.href !== undefined\n ? html`<a\n href=${e.href}\n data-level=${level}\n aria-current=${mark ?? nothing}\n lang=${e.lang ?? nothing}\n dir=${e.dir ?? nothing}\n >${text}</a\n >`\n : html`<span class=\"group\" lang=${e.lang ?? nothing} dir=${e.dir ?? nothing}\n >${text}</span\n >`;\n return html`<li\n role=\"listitem\"\n lang=${e.itemLang ?? nothing}\n dir=${e.itemDir ?? nothing}\n ?hidden=${out}\n >\n ${own}${e.children.length ? this.renderList(e.children, current, level + 1, shown) : nothing}\n </li>`;\n }\n\n /** The count of entries shown (all, or the window's). */\n private static size(entries: Entry[], shown?: Set<Entry>): number {\n let n = 0;\n const walk = (l: Entry[]) =>\n l.forEach((e) => {\n if (!shown || shown.has(e)) n++;\n walk(e.children);\n });\n walk(entries);\n return n;\n }\n\n /**\n * After the list: the full-contents link, or a window's Show all / Show fewer button; and\n * the visually hidden line before the list that says it is partial.\n */\n private renderMore(entries: Entry[], shown: Set<Entry> | undefined, collapsed: boolean) {\n const href = this.fullLink;\n const windowed = !!shown || this.expanded;\n const all = UvalibContents.size(entries);\n const total = whole(this.total) ?? (windowed ? all : undefined);\n const showing = UvalibContents.size(entries, shown);\n let note = '';\n if (total !== undefined && showing < total)\n note = `Showing ${count(showing)} of ${count(total)} ${this.word(total)}.`;\n else if (href && total === undefined)\n note = `Showing ${count(showing)} ${this.word(showing)}, part of the contents.`;\n let action: TemplateResult | undefined;\n if (href) {\n const text = `${normalize(this.fullLabel) || DEFAULT_FULL_LABEL}${\n total !== undefined ? ` (${count(total)} ${this.word(total)})` : ''\n }`;\n action = html`<a class=\"full\" href=${href} data-level=\"0\">${text}</a>`;\n } else if (windowed) {\n action = html`<button\n type=\"button\"\n aria-expanded=${this.expanded ? 'true' : 'false'}\n aria-controls=${this.panelId}\n @click=${this.showAll}\n >\n ${this.expanded ? 'Show fewer' : `Show all ${count(all)} ${this.word(all)}`}\n </button>`;\n }\n return {\n note: note ? html`<p class=\"visually-hidden\">${note}</p>` : nothing,\n more: action\n ? html`<p class=\"more\" id=${`${this.panelId}-more`} ?hidden=${collapsed}>${action}</p>`\n : nothing,\n has: !!action,\n };\n }\n\n protected override render() {\n const entries = this.entries;\n const label = normalize(this.label) || DEFAULT_LABEL;\n const h = unsafeStatic(`h${this.level}`);\n const collapsed = this.narrow && !this.open;\n const current = this.currentOf(entries);\n const shown = this.windowOf(entries, current);\n const { note, more, has } = this.renderMore(entries, shown, collapsed);\n this.hasMore = has;\n const headline = this.narrow\n ? html`<button\n type=\"button\"\n class=\"toggle\"\n aria-expanded=${this.open ? 'true' : 'false'}\n aria-controls=${has ? `${this.panelId} ${this.panelId}-more` : this.panelId}\n @click=${this.toggle}\n >\n ${label}\n </button>`\n : label;\n // The heading's tag changes the inner template only: the <nav> (in light DOM, a child\n // of the element) is never replaced.\n return html`<nav aria-label=${label} ?hidden=${!entries.length} @click=${this.onClick}>\n ${html`<${h} class=\"headline\">${headline}</${h}>`}\n <div class=\"panel\" id=${this.panelId} ?hidden=${collapsed}>\n ${note}${this.renderList(entries, current, 1, shown)}\n </div>\n ${more}\n </nav>`;\n }\n}\n","import { define } from '../../base/define.js';\nimport { UvalibContents } from './UvalibContents.js';\n\ndefine('uvalib-contents', UvalibContents);\n"],"mappings":";;;;;;;AAoCA,IAAMwB,KAAU,MAAsD;CACpE,IAAM,IAAIC,GAAG,KAAK,CAAC,CAAC,YAAY;CAChC,OAAO,MAAM,UAAU,MAAM,SAAS,SAAS,MAAM,aAAa,aAAa,KAAA;AACjF,GAGMC,KAAc,MAClB,KAAK,UAAUC,IAAQ,GAAG,MAAgBC,MAAM,UAAU,KAAA,IAAYH,CAAE,GAIpEI,IAAgB,YAChBC,IAAmB,SACnBC,IAAgB,GAChBC,IAAiB,OACjBC,IAAc,GACdC,IAAqB,iBACrBC,IAAe,YACjBC,IAAM,GAGJC,KAAS,MAAc/B,EAAE,eAAe,OAAO,GAG/CgC,KAAS,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"./chunks/analytics-DTTihuBD.js";
|
|
2
2
|
// src/components/uvalib-pagefind-search/UvalibPagefindSearch.ts
|
|
3
|
-
var r = "uvalib-pagefind-search", i = 1e3, a = 1e4, o = /* @__PURE__ */ new Map();
|
|
4
|
-
function
|
|
3
|
+
var r = "uvalib-pagefind-search", i = 1e3, a = 1e4, o = 15e3, s = 25, c = /* @__PURE__ */ new Map();
|
|
4
|
+
function l(e) {
|
|
5
5
|
let t = window;
|
|
6
6
|
if (t.PagefindUI) return Promise.resolve(t.PagefindUI);
|
|
7
|
-
let n =
|
|
7
|
+
let n = c.get(e);
|
|
8
8
|
return n || (n = new Promise((n, r) => {
|
|
9
9
|
let i = document.createElement("script");
|
|
10
10
|
i.src = e, i.onload = () => t.PagefindUI ? n(t.PagefindUI) : r(/* @__PURE__ */ Error("no PagefindUI")), i.onerror = () => r(/* @__PURE__ */ Error(`could not load ${e}`)), document.head.append(i);
|
|
11
|
-
}), n.catch(() =>
|
|
11
|
+
}), n.catch(() => c.delete(e)), c.set(e, n)), n;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
function u(e, t) {
|
|
14
|
+
let n = (e) => `<span class="uvalib-skeleton-text ${r}__skeleton-${e}"></span>`, i = `<div class="${r}__skeleton-sub">${n("title")}${n("line")}${n("short")}</div>`, a = `<div class="${r}__skeleton-result">${n("title")}${n("line")}${n("line")}${n("short")}${t ? i + i : ""}</div>`, o = document.createElement("div");
|
|
15
|
+
return o.className = `${r}__skeleton`, o.setAttribute("aria-hidden", "true"), o.innerHTML = n("message") + a.repeat(e), o;
|
|
16
|
+
}
|
|
17
|
+
var d = {
|
|
14
18
|
position: "absolute",
|
|
15
19
|
width: "1px",
|
|
16
20
|
height: "1px",
|
|
@@ -20,18 +24,18 @@ var c = {
|
|
|
20
24
|
clipPath: "inset(50%)",
|
|
21
25
|
whiteSpace: "nowrap",
|
|
22
26
|
border: "0"
|
|
23
|
-
},
|
|
27
|
+
}, f = 0, p = (e) => typeof e == "object" && !!e && Object.getPrototypeOf(e) === Object.prototype, m = (e, t, n) => {
|
|
24
28
|
if (!e) return t;
|
|
25
29
|
try {
|
|
26
30
|
let t = JSON.parse(e);
|
|
27
31
|
if (n(t)) return t;
|
|
28
32
|
} catch {}
|
|
29
33
|
return console.warn(`${r}: ignoring an attribute that is not the expected JSON`, e), t;
|
|
30
|
-
},
|
|
31
|
-
function
|
|
34
|
+
}, h = (e) => e.endsWith("/") ? e : `${e}/`, g = "[COUNT] results for [SEARCH_TERM]", _ = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
35
|
+
function v(e, t, n) {
|
|
32
36
|
let r;
|
|
33
37
|
if (n?.includes("[COUNT]")) {
|
|
34
|
-
let i = RegExp(`^${
|
|
38
|
+
let i = RegExp(`^${_(n).replace(_("[COUNT]"), "(.+?)").replace(_("[SEARCH_TERM]"), _(t))}$`);
|
|
35
39
|
r = e.match(i)?.[1];
|
|
36
40
|
}
|
|
37
41
|
if (r === void 0) {
|
|
@@ -41,9 +45,9 @@ function h(e, t, n) {
|
|
|
41
45
|
let i = r.match(/\d[\d.,\s\u00a0\u202f]*/);
|
|
42
46
|
return i ? Number(i[0].replace(/\D/g, "")) : void 0;
|
|
43
47
|
}
|
|
44
|
-
var
|
|
48
|
+
var y = class extends HTMLElement {
|
|
45
49
|
constructor(...e) {
|
|
46
|
-
super(...e), this.generation = 0, this.started = !1, this._ready = this.newReady(), this.uid = `${r}-${++
|
|
50
|
+
super(...e), this.generation = 0, this.started = !1, this._ready = this.newReady(), this.uid = `${r}-${++f}`, this.container = document.createElement("div"), this.status = document.createElement("p"), this.lastAnnounced = "", this.lastTracked = "", this.onPopState = () => this.followUrl();
|
|
47
51
|
}
|
|
48
52
|
newReady() {
|
|
49
53
|
let { promise: e, resolve: t } = Promise.withResolvers();
|
|
@@ -84,67 +88,67 @@ var g = class extends HTMLElement {
|
|
|
84
88
|
});
|
|
85
89
|
}
|
|
86
90
|
teardown() {
|
|
87
|
-
this.generation++, this.started = !1, clearTimeout(this.settleTimer), this.observer?.disconnect(), this.observer = void 0, window.removeEventListener("popstate", this.onPopState);
|
|
91
|
+
this.generation++, this.started = !1, clearTimeout(this.settleTimer), this.release(), this.unkeep(), this.observer?.disconnect(), this.observer = void 0, window.removeEventListener("popstate", this.onPopState);
|
|
88
92
|
try {
|
|
89
93
|
this._ui?.destroy();
|
|
90
94
|
} catch {}
|
|
91
95
|
this._ui && (this._ready = this.newReady()), this._ui = void 0, this.container.remove(), this.container = document.createElement("div"), this.querySelector(`:scope > .${r}__label`)?.remove(), this.status.remove(), this.status.textContent = "", this.lastAnnounced = this.lastTracked = "", this.focusIndex = void 0;
|
|
92
96
|
}
|
|
93
97
|
async start(e) {
|
|
94
|
-
let n =
|
|
95
|
-
o.className = `${r}__label`, o.htmlFor = `${this.uid}-input`, o.textContent = this.getAttribute("label") || i, this.hasAttribute("label-hidden") && Object.assign(o.style,
|
|
96
|
-
let
|
|
98
|
+
let n = h(this.getAttribute("bundle-path") || "/pagefind/"), i = this.getAttribute("placeholder") || "Search", o = document.createElement("label");
|
|
99
|
+
o.className = `${r}__label`, o.htmlFor = `${this.uid}-input`, o.textContent = this.getAttribute("label") || i, this.hasAttribute("label-hidden") && Object.assign(o.style, d), this.container.className = `${r}__ui`, this.status.className = `${r}__status`, this.status.setAttribute("role", "status"), Object.assign(this.status.style, d), this.append(o, this.container, this.status), this.urlQuery() && this.hasAttribute("searching") ? this.hold() : this.removeAttribute("searching");
|
|
100
|
+
let s;
|
|
97
101
|
try {
|
|
98
|
-
|
|
102
|
+
s = await l(`${n}pagefind-ui.js`);
|
|
99
103
|
} catch {
|
|
100
104
|
if (e !== this.generation) return;
|
|
101
|
-
t(this, r, "load"), o.remove();
|
|
105
|
+
this.release(), t(this, r, "load"), o.remove();
|
|
102
106
|
let n = document.createElement("p");
|
|
103
107
|
n.className = `${r}__error`, n.textContent = "Search is not available right now. Please try again later.", this.container.append(n);
|
|
104
108
|
return;
|
|
105
109
|
}
|
|
106
110
|
if (e !== this.generation) return;
|
|
107
|
-
let
|
|
111
|
+
let c = this.urlFilters(), u = (e, t) => {
|
|
108
112
|
let n = Number.parseInt(this.getAttribute(e) ?? "", 10);
|
|
109
113
|
return Number.isFinite(n) && n > 0 ? n : t;
|
|
110
|
-
},
|
|
114
|
+
}, f = m(this.getAttribute("merge-index"), [], Array.isArray).filter((e) => p(e) && typeof e.bundlePath == "string").map((e) => ({
|
|
111
115
|
...e,
|
|
112
|
-
bundlePath:
|
|
116
|
+
bundlePath: h(e.bundlePath)
|
|
113
117
|
})), _ = {
|
|
114
118
|
placeholder: i,
|
|
115
|
-
...
|
|
116
|
-
}, v =
|
|
119
|
+
...m(this.getAttribute("translations"), {}, p)
|
|
120
|
+
}, v = m(this.getAttribute("options"), {}, p), y = {
|
|
117
121
|
bundlePath: n,
|
|
118
|
-
mergeIndex:
|
|
119
|
-
pageSize:
|
|
122
|
+
mergeIndex: f,
|
|
123
|
+
pageSize: u("page-size", 10),
|
|
120
124
|
showSubResults: this.hasAttribute("show-sub-results"),
|
|
121
125
|
showImages: this.hasAttribute("show-images"),
|
|
122
126
|
...v,
|
|
123
127
|
translations: _,
|
|
124
128
|
element: this.container
|
|
125
129
|
};
|
|
126
|
-
typeof y.bundlePath == "string" && (y.bundlePath =
|
|
127
|
-
let b = Object.keys(
|
|
130
|
+
typeof y.bundlePath == "string" && (y.bundlePath = h(y.bundlePath));
|
|
131
|
+
let b = Object.keys(c);
|
|
128
132
|
if (b.length) {
|
|
129
133
|
let e = Array.isArray(y.openFilters) ? y.openFilters : [];
|
|
130
134
|
y.openFilters = [.../* @__PURE__ */ new Set([...e, ...b])];
|
|
131
135
|
}
|
|
132
|
-
let x =
|
|
136
|
+
let x = u("excerpt-length");
|
|
133
137
|
x && (y.excerptLength ??= x);
|
|
134
138
|
let S = (document.documentElement.lang || "en").toLowerCase();
|
|
135
|
-
this.manyResults = typeof _.many_results == "string" ? _.many_results : S === "en" || S.startsWith("en-") ?
|
|
136
|
-
let C = new
|
|
139
|
+
this.manyResults = typeof _.many_results == "string" ? _.many_results : S === "en" || S.startsWith("en-") ? g : void 0;
|
|
140
|
+
let C = new s(y);
|
|
137
141
|
this._ui = C;
|
|
138
142
|
let w = this.input;
|
|
139
143
|
w && (w.id = `${this.uid}-input`), this.listen(), window.addEventListener("popstate", this.onPopState);
|
|
140
144
|
let T = this.urlQuery();
|
|
141
|
-
if (Object.keys(
|
|
145
|
+
if (Object.keys(c).length) {
|
|
142
146
|
this.resolveReady(C);
|
|
143
147
|
let t = new Promise((e) => this.filtersDrawn = e);
|
|
144
148
|
w?.dispatchEvent(new Event("focus")), this.onMutation();
|
|
145
149
|
let n;
|
|
146
150
|
if (await Promise.race([t, new Promise((e) => n = setTimeout(e, a))]), clearTimeout(n), this.filtersDrawn = void 0, e !== this.generation) return;
|
|
147
|
-
this.applyUrl(
|
|
151
|
+
this.applyUrl(c, T, !this.input?.value);
|
|
148
152
|
} else T && C.triggerSearch(T), this.resolveReady(C);
|
|
149
153
|
}
|
|
150
154
|
known(e) {
|
|
@@ -185,10 +189,32 @@ var g = class extends HTMLElement {
|
|
|
185
189
|
let e = this.urlQuery(), t = this.input;
|
|
186
190
|
if (!t) return;
|
|
187
191
|
let n = !!this.queryParam && t.value.trim() !== e;
|
|
188
|
-
this.filterParams.length ? this.applyUrl(this.urlFilters(), e, n) : n && (e ? this._ui.triggerSearch(e) : (t.value = "", t.dispatchEvent(new Event("input", { bubbles: !0 }))));
|
|
192
|
+
e && n && this.hold(), this.filterParams.length ? this.applyUrl(this.urlFilters(), e, n) : n && (e ? this._ui.triggerSearch(e) : (t.value = "", t.dispatchEvent(new Event("input", { bubbles: !0 }))));
|
|
193
|
+
}
|
|
194
|
+
hold() {
|
|
195
|
+
if (this.hasAttribute("no-skeleton")) {
|
|
196
|
+
this.removeAttribute("searching");
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
this.release(), this.unkeep();
|
|
200
|
+
let e = Number.parseInt(this.getAttribute("page-size") ?? "", 10), t = Math.min(Number.isFinite(e) && e > 0 ? e : 10, s);
|
|
201
|
+
this.skeleton = u(t, this.hasAttribute("show-sub-results")), this.heldList = this.container.querySelector(".pagefind-ui__results"), this.container.after(this.skeleton), this.setAttribute("searching", ""), this.holdTimer = setTimeout(() => this.release(), o);
|
|
202
|
+
}
|
|
203
|
+
release(e = !1) {
|
|
204
|
+
if (clearTimeout(this.holdTimer), e && this.skeleton) {
|
|
205
|
+
let e = Math.ceil(window.innerHeight - this.getBoundingClientRect().top);
|
|
206
|
+
e > 0 && (this.ownMinSize ??= this.style.minBlockSize, this.style.minBlockSize = `${e}px`);
|
|
207
|
+
}
|
|
208
|
+
this.skeleton?.remove(), this.skeleton = void 0, this.removeAttribute("searching");
|
|
209
|
+
}
|
|
210
|
+
unkeep() {
|
|
211
|
+
this.ownMinSize !== void 0 && (this.style.minBlockSize = this.ownMinSize, this.ownMinSize = void 0);
|
|
189
212
|
}
|
|
190
213
|
listen() {
|
|
191
214
|
let t = this.container;
|
|
215
|
+
for (let e of ["input", "click"]) t.addEventListener(e, () => {
|
|
216
|
+
this.release(), this.unkeep();
|
|
217
|
+
});
|
|
192
218
|
t.addEventListener("click", (e) => {
|
|
193
219
|
let n = e.target;
|
|
194
220
|
n.closest(".pagefind-ui__search-clear") && this.refocus(), n.closest(".pagefind-ui__button") && (this.focusIndex = t.querySelectorAll(".pagefind-ui__results > li").length);
|
|
@@ -214,6 +240,10 @@ var g = class extends HTMLElement {
|
|
|
214
240
|
}
|
|
215
241
|
onMutation() {
|
|
216
242
|
let e = this.container;
|
|
243
|
+
if (this.skeleton) {
|
|
244
|
+
let t = e.querySelector(".pagefind-ui__results");
|
|
245
|
+
t && t !== this.heldList && !t.querySelector(".pagefind-ui__loading") && this.release(!0);
|
|
246
|
+
}
|
|
217
247
|
this.filtersDrawn && e.querySelector(".pagefind-ui__filter-checkbox") && this.filtersDrawn();
|
|
218
248
|
for (let t of e.querySelectorAll(".pagefind-ui__loading:not([aria-hidden])")) t.setAttribute("aria-hidden", "true");
|
|
219
249
|
if (this.focusIndex !== void 0) {
|
|
@@ -225,7 +255,7 @@ var g = class extends HTMLElement {
|
|
|
225
255
|
settled() {
|
|
226
256
|
let e = this.container, t = (this.input?.value ?? "").trim(), n = e.querySelector(".pagefind-ui__results-area"), r = n?.querySelector(".pagefind-ui__results");
|
|
227
257
|
if (!t || !r || r.querySelector(".pagefind-ui__loading")) return;
|
|
228
|
-
let i = n.querySelector(".pagefind-ui__message")?.textContent?.trim() ?? "", a = r.children.length, o = n.querySelector(".pagefind-ui__button") ?
|
|
258
|
+
let i = n.querySelector(".pagefind-ui__message")?.textContent?.trim() ?? "", a = r.children.length, o = n.querySelector(".pagefind-ui__button") ? v(i, t, this.manyResults) ?? a : a, s = [...e.querySelectorAll(".pagefind-ui__filter-checkbox")].filter((e) => e.checked).map((e) => `${e.name}:${e.value}`).sort();
|
|
229
259
|
return {
|
|
230
260
|
query: t,
|
|
231
261
|
count: o,
|
|
@@ -273,6 +303,6 @@ var g = class extends HTMLElement {
|
|
|
273
303
|
}
|
|
274
304
|
};
|
|
275
305
|
// src/components/uvalib-pagefind-search/uvalib-pagefind-search.ts
|
|
276
|
-
customElements.get("uvalib-pagefind-search") || customElements.define("uvalib-pagefind-search",
|
|
306
|
+
customElements.get("uvalib-pagefind-search") || customElements.define("uvalib-pagefind-search", y);
|
|
277
307
|
|
|
278
308
|
//# sourceMappingURL=uvalib-pagefind-search.js.map
|