@uvalib/web-components 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +133 -12
  3. package/dist/base/states.d.ts +12 -0
  4. package/dist/base/states.js +33 -0
  5. package/dist/base/states.js.map +1 -0
  6. package/dist/base.css +15 -5
  7. package/dist/components/bento-box/BentoBox.js +1 -0
  8. package/dist/components/bento-box/BentoBox.js.map +1 -1
  9. package/dist/components/events-section/EventsSection.js +1 -0
  10. package/dist/components/events-section/EventsSection.js.map +1 -1
  11. package/dist/components/library-hours/hours-data.js +1 -1
  12. package/dist/components/library-hours/hours-data.js.map +1 -1
  13. package/dist/components/library-weekly-hours/LibraryWeeklyHours.js +1 -0
  14. package/dist/components/library-weekly-hours/LibraryWeeklyHours.js.map +1 -1
  15. package/dist/components/uvalib-card/UvalibCard.js +6 -0
  16. package/dist/components/uvalib-card/UvalibCard.js.map +1 -1
  17. package/dist/components/uvalib-combobox/UvalibCombobox.d.ts +27 -0
  18. package/dist/components/uvalib-combobox/UvalibCombobox.js +85 -1
  19. package/dist/components/uvalib-combobox/UvalibCombobox.js.map +1 -1
  20. package/dist/components/uvalib-contents/UvalibContents.js +5 -0
  21. package/dist/components/uvalib-contents/UvalibContents.js.map +1 -1
  22. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.d.ts +6 -0
  23. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js +10 -0
  24. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js.map +1 -1
  25. package/dist/components/uvalib-image-regions/UvalibImageRegions.d.ts +1 -0
  26. package/dist/components/uvalib-image-regions/UvalibImageRegions.js +4 -1
  27. package/dist/components/uvalib-image-regions/UvalibImageRegions.js.map +1 -1
  28. package/dist/components/uvalib-image-regions/regions.d.ts +6 -2
  29. package/dist/components/uvalib-image-regions/regions.js +6 -3
  30. package/dist/components/uvalib-image-regions/regions.js.map +1 -1
  31. package/dist/components/uvalib-lightbox/UvalibLightbox.d.ts +100 -7
  32. package/dist/components/uvalib-lightbox/UvalibLightbox.js +310 -83
  33. package/dist/components/uvalib-lightbox/UvalibLightbox.js.map +1 -1
  34. package/dist/components/uvalib-lightbox/compare.d.ts +48 -8
  35. package/dist/components/uvalib-lightbox/compare.js +226 -22
  36. package/dist/components/uvalib-lightbox/compare.js.map +1 -1
  37. package/dist/components/uvalib-map/UvalibMap.js +2 -2
  38. package/dist/components/uvalib-map/UvalibMap.js.map +1 -1
  39. package/dist/components/uvalib-metadata/UvalibMetadata.js +3 -0
  40. package/dist/components/uvalib-metadata/UvalibMetadata.js.map +1 -1
  41. package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js +3 -1
  42. package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js.map +1 -1
  43. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.d.ts +3 -3
  44. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js +16 -8
  45. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js.map +1 -1
  46. package/dist/components/uvalib-tag-list/UvalibTagList.d.ts +4 -1
  47. package/dist/components/uvalib-tag-list/UvalibTagList.js +9 -2
  48. package/dist/components/uvalib-tag-list/UvalibTagList.js.map +1 -1
  49. package/dist/custom-elements.json +596 -19
  50. package/dist/styles/message.js +4 -0
  51. package/dist/styles/message.js.map +1 -1
  52. package/dist/styles/result-list.js +25 -4
  53. package/dist/styles/result-list.js.map +1 -1
  54. package/dist/styles/results.js +17 -2
  55. package/dist/styles/results.js.map +1 -1
  56. package/dist-cdn/base.css +15 -5
  57. package/dist-cdn/bento-box.js +1 -0
  58. package/dist-cdn/bento-box.js.map +1 -1
  59. package/dist-cdn/chunks/{compare-D4VdaIJN.js → compare-C0nhByn7.js} +185 -56
  60. package/dist-cdn/chunks/compare-C0nhByn7.js.map +1 -0
  61. package/dist-cdn/chunks/{hours-data-Bw6vkIw7.js → hours-data-gMu5uT7H.js} +2 -2
  62. package/dist-cdn/chunks/hours-data-gMu5uT7H.js.map +1 -0
  63. package/dist-cdn/chunks/{library-weekly-hours-CrV3TlP5.js → library-weekly-hours-BJgxAyah.js} +3 -2
  64. package/dist-cdn/chunks/library-weekly-hours-BJgxAyah.js.map +1 -0
  65. package/dist-cdn/chunks/{regions-B8ExwUGP.js → regions-B-rOwa-v.js} +15 -15
  66. package/dist-cdn/chunks/regions-B-rOwa-v.js.map +1 -0
  67. package/dist-cdn/chunks/states-DGXGzcte.js +17 -0
  68. package/dist-cdn/chunks/states-DGXGzcte.js.map +1 -0
  69. package/dist-cdn/custom-elements.json +596 -19
  70. package/dist-cdn/events-section.js +1 -0
  71. package/dist-cdn/events-section.js.map +1 -1
  72. package/dist-cdn/library-hours-setup.js +1 -1
  73. package/dist-cdn/library-weekly-hours.js +1 -1
  74. package/dist-cdn/manifest.json +1 -1
  75. package/dist-cdn/site-hours-section.js +1 -1
  76. package/dist-cdn/skills/uvalib-web-components/SKILL.md +8 -6
  77. package/dist-cdn/skills/uvalib-web-components/reference/components.md +37 -6
  78. package/dist-cdn/uvalib-card.js +6 -0
  79. package/dist-cdn/uvalib-card.js.map +1 -1
  80. package/dist-cdn/uvalib-combobox.js +107 -68
  81. package/dist-cdn/uvalib-combobox.js.map +1 -1
  82. package/dist-cdn/uvalib-contents.js +5 -0
  83. package/dist-cdn/uvalib-contents.js.map +1 -1
  84. package/dist-cdn/uvalib-filter-drawer.js +27 -25
  85. package/dist-cdn/uvalib-filter-drawer.js.map +1 -1
  86. package/dist-cdn/uvalib-image-regions.js +4 -2
  87. package/dist-cdn/uvalib-image-regions.js.map +1 -1
  88. package/dist-cdn/uvalib-lightbox.js +230 -129
  89. package/dist-cdn/uvalib-lightbox.js.map +1 -1
  90. package/dist-cdn/uvalib-map.js +2 -2
  91. package/dist-cdn/uvalib-map.js.map +1 -1
  92. package/dist-cdn/uvalib-metadata.js +3 -0
  93. package/dist-cdn/uvalib-metadata.js.map +1 -1
  94. package/dist-cdn/uvalib-pagefind-search.js +2 -1
  95. package/dist-cdn/uvalib-pagefind-search.js.map +1 -1
  96. package/dist-cdn/uvalib-photo-grid.js +4 -5
  97. package/dist-cdn/uvalib-photo-grid.js.map +1 -1
  98. package/dist-cdn/uvalib-tag-list.js +21 -16
  99. package/dist-cdn/uvalib-tag-list.js.map +1 -1
  100. package/package.json +1 -1
  101. package/skills/uvalib-web-components/SKILL.md +8 -6
  102. package/skills/uvalib-web-components/reference/components.md +37 -6
  103. package/dist-cdn/chunks/compare-D4VdaIJN.js.map +0 -1
  104. package/dist-cdn/chunks/hours-data-Bw6vkIw7.js.map +0 -1
  105. package/dist-cdn/chunks/library-weekly-hours-CrV3TlP5.js.map +0 -1
  106. package/dist-cdn/chunks/regions-B8ExwUGP.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"library-weekly-hours-CrV3TlP5.js","names":["unsafeCSS","nothing","_decorate","property","state","n","i","r$1","b","define","__decorate","r","installLightDomStyles","UvalibElement","trackEvent","trackError","precedingHeadingLevel","accessible","todayInNewYork","hoursTiming","longDate","shortDate","shortWeekday","weekStart","hoursEndpoints","weekHeadingDate","formatDay","loadHours","fullDate","loadLibraries","addDays","setHoursEndpoints","instanceCounter","structuralRules","host","shadowStructure","LibraryWeeklyHours","_args","value","root","sheet","above","node","today","every","start","changed","id","announce","slug","days","background","libraries","library","l","spaces","ids","hours","maxAge","sameWeek","hadFocus","active","day","dates","calId","text","A","lib","cells","building","space","view","level","headingId","tableDays"],"sources":["../../src/components/library-weekly-hours/LibraryWeeklyHours.ts","../../src/components/library-weekly-hours/library-weekly-hours.ts"],"sourcesContent":["import { html, css, nothing, unsafeCSS, type PropertyValues } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { trackError, trackEvent } from '../../base/analytics.js';\nimport { UvalibElement } from '../../base/UvalibElement.js';\nimport { precedingHeadingLevel } from '../../base/heading-level.js';\nimport { installLightDomStyles } from '../../base/light-dom-styles.js';\nimport { accessible } from '../../styles/accessible.js';\nimport {\n addDays,\n formatDay,\n fullDate,\n hoursEndpoints,\n hoursTiming,\n setHoursEndpoints,\n loadHours,\n loadLibraries,\n longDate,\n shortDate,\n shortWeekday,\n todayInNewYork,\n weekHeadingDate,\n weekStart,\n type HoursByCalendar,\n type HoursEndpoints,\n type LibraryInfo,\n} from '../library-hours/hours-data.js';\n\n/** Element ids share the document id space in light DOM, so each instance gets its own prefix. */\nlet instanceCounter = 0;\n\n/** What the table shows: one week's data, kept on screen while the next week loads. */\ninterface WeekView {\n days: string[];\n library: LibraryInfo;\n spaces: LibraryInfo[];\n hours: HoursByCalendar;\n}\n\n/** `loading` until the first data arrives, then `ready`, or `error` when it cannot be loaded. */\nexport type HoursState = 'loading' | 'ready' | 'error';\n\n/**\n * The layout rules the week header and table need even with `no-style`: Drupal's /hours CSS\n * relies on them. `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}[loading] { min-height: var(--library-weekly-hours-min-height, 0); }\n ${host} .hours-placeholder { visibility: hidden; }\n /* One line even when empty, so \"Loading hours…\" giving way to nothing moves nothing below. */\n ${host} .weekly-hours-status { min-height: 1.5em; min-height: 1lh; }\n ${host}[hidden], ${host} [hidden] { display: none !important; }\n ${host} .weekly-hours-header-section {\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n align-items: center;\n text-align: center;\n }\n ${host} .weekly-hours-header-section div[role='heading'] { flex: 1; }\n ${host} .visually-hidden {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border: 0;\n }\n`;\nconst shadowStructure = unsafeCSS(structuralRules(':host'));\n\n/**\n * One library's opening hours for a week (Sunday to Saturday, in America/New_York): a\n * header with \"Previous week\" / \"Next week\" buttons and the date range, then a table with a\n * \"Building hours\" row and a row per space in the library. Data comes from the library\n * website's JSON:API (same origin) and LibCal, shared between all hours elements on a page.\n * Used on library.virginia.edu/hours through `<library-hours-setup>`.\n *\n * @tagname library-weekly-hours\n * @fires uvalib-analytics-event - For `<site-analytics>`: `['library-weekly-hours', 'week-change', 'next' | 'previous']` for the week buttons, and `['library-weekly-hours', 'error', 'hours-load']` once when the hours cannot be loaded. Bubbles and is composed.\n * @csspart building-hours - The \"Building hours\" table row (shadow mode).\n * @cssprop [--library-weekly-hours-min-height=0] - Height the element keeps during its first load (while it has the `loading` attribute, before any rows show), so content below does not jump when the hours arrive. Applies with `no-style` too. Pages can reserve the same height before the element upgrades with `library-weekly-hours:not(:defined) { display: block; min-height: … }`.\n * @cssprop [--uva-brand-orange=#e57200] - Border of today's column; focus ring colour.\n * @cssprop [--uva-brand-blue=#232d4b] - Header and button colour.\n * @cssprop --uva-color-border - Dark-mode role token: table cell borders (else #dadada).\n * @cssprop --uva-color-current - Dark-mode role token: today's column border (else `--uva-brand-orange`).\n * @cssprop --uva-color-link - Dark-mode role token: heading, button text and border (else `--uva-brand-blue`).\n * @cssprop --uva-color-surface-raised - Dark-mode role token: button background (else #fff).\n * @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).\n */\nexport class LibraryWeeklyHours extends UvalibElement {\n static styles = [\n accessible,\n shadowStructure,\n css`\n table {\n width: 100%;\n border-collapse: collapse;\n margin-block: 1rem;\n }\n th,\n td {\n padding: 0.5rem;\n border: 1px solid var(--uva-color-border, #dadada);\n text-align: center;\n vertical-align: middle;\n }\n tbody th {\n text-align: start;\n }\n th.today,\n td.today {\n border-inline: 2px solid var(--uva-color-current, var(--uva-brand-orange, #e57200));\n }\n th.today {\n border-block-start: 2px solid var(--uva-color-current, var(--uva-brand-orange, #e57200));\n }\n .date-header-day {\n font-weight: bold;\n }\n tbody .date--mobile {\n display: none;\n }\n .uvalib-button {\n font: inherit;\n padding: 0.4rem 0.9rem;\n border: 1px solid var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n border-radius: 0.3rem;\n background: var(--uva-color-surface-raised, #fff);\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n cursor: pointer;\n }\n .heading-h1,\n .heading-h2,\n .heading-h3,\n .heading-h4,\n .heading-h5,\n .heading-h6 {\n font-size: 1.25rem;\n font-weight: bold;\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n }\n `,\n ];\n\n /**\n * The data endpoints shared by all hours elements: `libraries` (the Drupal JSON:API URL,\n * relative by default) and `hours` (LibCal, with `{ids}`). Assigning an object (or setting\n * a key) changes them for every hours element from the next load on. To repoint before\n * elements already in the HTML start fetching, set `window.uvalibHoursEndpoints` before\n * the define script runs.\n */\n static get endpoints(): HoursEndpoints {\n return hoursEndpoints;\n }\n static set endpoints(value: Partial<HoursEndpoints>) {\n setHoursEndpoints(value);\n }\n\n /** The library's `field_slug` in Drupal (for example `clemons`). */\n @property({ type: String, attribute: 'library-slug' })\n librarySlug?: string;\n\n /** Which week to show: 0 is this week, 1 next week, -1 last week. Changed by the buttons. */\n @property({ type: Number, attribute: 'week-count', reflect: true })\n weekCount = 0;\n\n /** How often (ms) the current week's hours are fetched again. 0 turns it off. */\n @property({ type: Number, attribute: 'refresh-every' })\n refreshEvery = 600000;\n\n /** Hide the \"Building hours\" row (for a library whose building calendar is one of its spaces). */\n @property({ type: Boolean, attribute: 'hide-building-hours', reflect: true })\n hideBuildingHours = false;\n\n /**\n * `aria-level` (1–6) of the week heading, also its `heading-h<n>` class. Unset (the\n * default), the level is one below the nearest heading before the element in the page\n * (`aria-level` 3 under a library's `<h2>` on /hours), or 2 when there is none, and the\n * class stays `heading-h2`, the one the library website's CSS styles.\n */\n @property({ type: Number, attribute: 'heading-level' })\n headingLevel?: number;\n\n /** Old name of `heading-level`, still accepted; `heading-level` wins. */\n @property({ type: Number, attribute: 'headinglevelstart' })\n headingLevelStart?: number;\n\n /** One below the nearest preceding heading, worked out on connect (see `level`). */\n @state() private inferredLevel = 2;\n\n /** `loading` (the default, until data arrives), `ready` or `error`. Read-only. */\n get state(): HoursState {\n return this._state;\n }\n\n @state() private _state: HoursState = 'loading';\n @state() private today = '';\n @state() private view?: WeekView;\n /**\n * During the first load, once the library list is in: the rows the table will have, so\n * placeholder rows can hold their height until the hours arrive.\n */\n @state() private pending?: Omit<WeekView, 'hours'>;\n @state() private announcement = '';\n\n private readonly uid = `library-weekly-hours-${++instanceCounter}`;\n private loadId = 0;\n /** Set by the week buttons and Retry: announce the result of the next load. */\n private userInitiated = false;\n private tickTimer?: ReturnType<typeof setInterval>;\n private refreshTimer?: ReturnType<typeof setInterval>;\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 const above = precedingHeadingLevel(this);\n this.inferredLevel = above === null ? 2 : Math.min(above + 1, 6);\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.today = todayInNewYork();\n clearInterval(this.tickTimer);\n this.tickTimer = setInterval(() => {\n const today = todayInNewYork();\n if (today !== this.today) this.today = today;\n else if (this._state === 'error') void this.load({ background: true });\n }, hoursTiming.tick);\n this.restartRefresh();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n clearInterval(this.tickTimer);\n clearInterval(this.refreshTimer);\n this.tickTimer = this.refreshTimer = undefined;\n }\n\n private restartRefresh() {\n clearInterval(this.refreshTimer);\n this.refreshTimer = undefined;\n const every = this.refreshEvery;\n if (!this.isConnected || !(every > 0)) return;\n this.refreshTimer = setInterval(() => {\n if (this.weekCount === 0 && this._state !== 'loading')\n void this.load({ background: true, maxAge: every / 2 });\n }, every);\n }\n\n /** The seven `YYYY-MM-DD` dates of the week shown. */\n private get days(): string[] {\n const start = addDays(weekStart(this.today), (Math.trunc(this.weekCount) || 0) * 7);\n return Array.from({ length: 7 }, (_, i) => addDays(start, i));\n }\n\n /** The level set by `heading-level` (or the old `headinglevelstart`), or null. */\n private get explicitLevel(): number | null {\n const n = Math.trunc(this.headingLevel ?? this.headingLevelStart ?? Number.NaN);\n return n >= 1 && n <= 6 ? n : null;\n }\n\n /** The week heading's `aria-level`: as set, else inferred from the page on connect. */\n private get level(): number {\n return this.explicitLevel ?? this.inferredLevel;\n }\n\n /** The `heading-h<n>` class: as set, else `heading-h2` (what the library's CSS styles). */\n private get headingClass(): number {\n return this.explicitLevel ?? 2;\n }\n\n // A plain map: `today` is private, which PropertyValues<this> does not cover.\n protected override willUpdate(changed: Map<PropertyKey, unknown>) {\n if (!this.isConnected || !this.today) return;\n if (!this.hasUpdated || changed.has('librarySlug') || changed.has('weekCount')) {\n void this.load();\n } else if (changed.has('today')) {\n // The date rolled over: reload quietly. The same week keeps its rows on a failure.\n void this.load({ background: this.view?.days[0] === this.days[0] });\n }\n }\n\n protected override updated(changed: PropertyValues<this>) {\n // Only the first load, before any rows show, reserves --library-weekly-hours-min-height.\n this.toggleAttribute('loading', this._state === 'loading' && !this.view);\n // The first value is picked up by connectedCallback.\n if (changed.has('refreshEvery') && changed.get('refreshEvery') !== undefined)\n this.restartRefresh();\n }\n\n /**\n * Load the week shown. The previous rows stay on screen (the table is `aria-busy`) until\n * the new data lands. A `background` load (refresh, retry from the interval or a rollover\n * within the week) does not change the state to loading and, if it fails while rows for\n * the same week are shown, keeps them. Only user-initiated loads announce their result.\n */\n private async load({\n background = false,\n maxAge = Infinity,\n }: { background?: boolean; maxAge?: number } = {}) {\n const id = ++this.loadId;\n const announce = this.userInitiated;\n this.userInitiated = false;\n const slug = this.librarySlug;\n if (!slug) {\n this._state = 'ready';\n this.view = undefined;\n return;\n }\n const days = this.days;\n if (!background) {\n this._state = 'loading';\n this.announcement = '';\n }\n try {\n const libraries = await loadLibraries();\n const library = libraries.find((l) => l.slug === slug);\n if (!library) throw new Error(`no library with slug \"${slug}\"`);\n const spaces = libraries.filter((l) => l.parent === library.id);\n if (id === this.loadId && !this.view) this.pending = { days, library, spaces };\n const ids = [library, ...spaces]\n .map((l) => l.calId)\n .filter((n): n is number => n !== undefined);\n const hours = await loadHours(ids, days[0]!, days[6]!, maxAge);\n if (id !== this.loadId) return; // a newer load owns the element\n this.view = { days, library, spaces, hours };\n this.pending = undefined;\n this._state = 'ready';\n if (announce)\n this.announcement = `Showing hours for ${fullDate(days[0]!)} to ${fullDate(days[6]!)}`;\n } catch {\n if (id !== this.loadId) return;\n const sameWeek = this.view?.days[0] === days[0];\n if (background && sameWeek && this._state !== 'error') return;\n if (!sameWeek) this.view = undefined;\n this.pending = undefined;\n this._state = 'error';\n trackError(this, 'library-weekly-hours', 'hours-load');\n }\n }\n\n private retry() {\n this.userInitiated = true;\n const hadFocus = this.focusedInside();\n void this.load().then(() => {\n // The Retry button is gone once the hours load; keep keyboard focus in the element.\n if (hadFocus && this._state === 'ready' && !this.focusedInside())\n this.renderRoot\n .querySelector<HTMLButtonElement>('.weekly-hours-header-section button')\n ?.focus();\n });\n }\n\n private focusedInside(): boolean {\n const active =\n this.renderRoot instanceof ShadowRoot\n ? this.renderRoot.activeElement\n : document.activeElement;\n return !!active && (this.renderRoot as Node).contains(active) && active !== this;\n }\n\n private previousWeek() {\n this.userInitiated = true;\n this.weekCount = (Math.trunc(this.weekCount) || 0) - 1;\n trackEvent(this, ['library-weekly-hours', 'week-change', 'previous']);\n }\n\n private nextWeek() {\n this.userInitiated = true;\n this.weekCount = (Math.trunc(this.weekCount) || 0) + 1;\n trackEvent(this, ['library-weekly-hours', 'week-change', 'next']);\n }\n\n private renderMobileDate(day: string) {\n return html`<div class=\"date--mobile\">\n <div class=\"date-header-day\">${shortWeekday(day)}</div>\n <div class=\"date-header-month\">${shortDate(day)}</div>\n </div>`;\n }\n\n private renderCells(days: string[], hours: HoursByCalendar, calId: number | undefined) {\n const dates = calId === undefined ? undefined : hours.get(calId);\n return days.map((day) => {\n const text = formatDay(dates?.[day]);\n return html`<td\n aria-label=${text ? `${longDate(day)}: ${text}` : longDate(day)}\n class=${day === this.today ? 'today' : nothing}\n >\n ${this.renderMobileDate(day)}${text}\n </td>`;\n });\n }\n\n /**\n * The first load's rows before the hours arrive: the real row headers with invisible,\n * typical hours text in each cell, so the table already has its final height in whatever\n * font the page uses and nothing below it moves when the hours replace the placeholders.\n */\n private renderPlaceholderRows({ days, library: lib, spaces }: Omit<WeekView, 'hours'>) {\n const cells = () =>\n days.map(\n (day) =>\n html`<td class=${day === this.today ? 'today' : nothing}>\n ${this.renderMobileDate(day)}<span class=\"hours-placeholder\" aria-hidden=\"true\"\n >10am - 10pm</span\n >\n </td>`,\n );\n const building =\n !this.hideBuildingHours && lib.calId !== undefined\n ? html`<tr part=\"building-hours\">\n <th scope=\"row\" colspan=\"2\">Building hours</th>\n ${cells()}\n </tr>`\n : nothing;\n return html`${building}${spaces.map(\n (space) =>\n html`<tr>\n <th scope=\"row\" colspan=\"2\">\n <span class=${space.siteLink ? 'lib-space-link' : 'lib-space'}>${space.title}</span>\n </th>\n ${cells()}\n </tr>`,\n )}`;\n }\n\n private renderRows(view: WeekView | undefined) {\n if (!view) {\n if (this.pending) return this.renderPlaceholderRows(this.pending);\n // Before the library list is in: the Building hours row nearly every library has, so\n // only a library's extra spaces can still move what follows the table.\n if (this._state === 'loading' && !this.hideBuildingHours)\n return this.renderPlaceholderRows({\n days: this.days,\n library: { calId: 0 } as LibraryInfo,\n spaces: [],\n });\n return nothing;\n }\n const { days, library: lib, spaces, hours } = view;\n const building =\n !this.hideBuildingHours && lib.calId !== undefined && hours.has(lib.calId)\n ? html`<tr part=\"building-hours\">\n <th scope=\"row\" colspan=\"2\" aria-label=\"Building hours\">Building hours</th>\n ${this.renderCells(days, hours, lib.calId)}\n </tr>`\n : nothing;\n return html`${building}${spaces.map(\n (space) =>\n html`<tr>\n <th scope=\"row\" colspan=\"2\" aria-label=${space.title}>\n ${\n space.siteLink\n ? html`<a class=\"lib-space-link\" href=${space.siteLink}>${space.title}</a>`\n : html`<span class=\"lib-space\">${space.title}</span>`\n }\n </th>\n ${this.renderCells(days, hours, space.calId)}\n </tr>`,\n )}`;\n }\n\n private renderStatus() {\n // Only the first load says so; later loads keep the previous rows (aria-busy) quietly.\n if (this._state === 'loading') return this.view ? nothing : 'Loading hours…';\n if (this._state === 'error')\n return html`Hours are unavailable right now.\n <button type=\"button\" class=\"uvalib-button uvalib-button--basic\" @click=${this.retry}>\n Retry\n </button>`;\n return this.announcement\n ? html`<span class=\"visually-hidden\">${this.announcement}</span>`\n : nothing;\n }\n\n render() {\n if (!this.librarySlug || !this.today) return nothing;\n const days = this.days;\n const level = this.level;\n const headingId = `${this.uid}-heading`;\n // The table shows the data it has (the previous week while the next one loads).\n const tableDays = this.view?.days ?? days;\n return html`<div class=\"weekly-hours-header-section\">\n <button\n type=\"button\"\n class=\"uvalib-button uvalib-button--basic\"\n aria-describedby=${headingId}\n @click=${this.previousWeek}\n >\n Previous week\n </button>\n <div\n class=\"heading-h${this.headingClass}\"\n role=\"heading\"\n aria-level=${level}\n id=${headingId}\n >\n ${weekHeadingDate(days[0]!)} - ${weekHeadingDate(days[6]!)}\n </div>\n <button\n type=\"button\"\n class=\"uvalib-button uvalib-button--basic\"\n aria-describedby=${headingId}\n @click=${this.nextWeek}\n >\n Next week\n </button>\n </div>\n <table\n class=\"weekly-hours-body-section\"\n aria-busy=${this._state === 'loading' ? 'true' : nothing}\n >\n <colgroup>\n <col class=\"location-column\" />\n ${tableDays.map(() => html`<col />`)}\n <col />\n </colgroup>\n <thead>\n <tr>\n <th colspan=\"2\" scope=\"col\"><span class=\"visually-hidden\">Day</span></th>\n ${tableDays.map(\n (day) =>\n html`<th\n scope=\"col\"\n aria-label=${longDate(day)}\n aria-current=${day === this.today ? 'date' : nothing}\n class=${day === this.today ? 'today' : nothing}\n >\n <div class=\"date-header\">${this.renderMobileDate(day)}</div>\n </th>`,\n )}\n </tr>\n </thead>\n <tbody>\n ${this.renderRows(this.view)}\n </tbody>\n </table>\n <div class=\"weekly-hours-status\" role=\"status\">${this.renderStatus()}</div>`;\n }\n}\n","import { define } from '../../base/define.js';\nimport { LibraryWeeklyHours } from './LibraryWeeklyHours.js';\n\ndefine('library-weekly-hours', LibraryWeeklyHours);\n"],"mappings":";;;;;;;AA4BA,IAAIgC,IAAkB,GAiBhBC,KAAmB,MAAiB;IACtCC,EAAK;IACLA,EAAK;IACLA,EAAK;;IAELA,EAAK;IACLA,EAAK,YAAYA,EAAK;IACtBA,EAAK;;;;;;;IAOLA,EAAK;IACLA,EAAK;;;;;;;;;;;GAYHC,IAAkBnC,EAAUiC,EAAgB,OAAO,CAAC,GAqB7CG,IAAb,cAAwCvB,EAAc;;EAuH5B,A,aA5CZ,KAAA,YAAA,GAIG,KAAA,eAAA,KAIK,KAAA,oBAAA,IAgBa,KAAA,gBAAA,GAOK,KAAA,SAAA,WACb,KAAA,QAAA,IAOO,KAAA,eAAA,IAET,KAAA,MAAA,wBAAwB,EAAEmB,KAChC,KAAA,SAAA,GAEO,KAAA,gBAAA;;;EAtHR,KAAA,SAAA;GACdf;GACAkB;GACA,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiDL;;CASA,WAAW,YAA4B;EACrC,OAAOX;CACT;CACA,WAAW,UAAU,GAAgC;EACnD,EAAkBc,CAAK;CACzB;CAmCA,IAAI,QAAoB;EACtB,OAAO,KAAK;CACd;CAmBA,mBAAsE;EACpE,IAAMC,IAAO,MAAM,iBAAiB;EACpC,IAAIA,aAAgB,cAAc,KAAK,SAAS;GAC9C,IAAMC,IAAQL,EAAgB;GAC9B,AAAIK,MAAO,EAAK,qBAAqB,CAACA,CAAK;EAC7C;EACA,OAAOD;CACT;CAEA,oBAAmC;EACjC,MAAM,kBAAkB;EACxB,IAAME,IAAQzB,EAAs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GAAAgC,EAAA,WAAA,QAAA,KAAA,CAAA,GAKNlC,EAAA,CAAAE,EAAM,CAAA,GAAAgC,EAAA,WAAA,WAAA,KAAA,CAAA,GACNlC,EAAA,CAAAE,EAAM,CAAA,GAAAgC,EAAA,WAAA,gBAAA,KAAA,CAAA,GC5MT3B,EAAO,wBAAwB2B,CAAkB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"regions-B8ExwUGP.js","names":["parseXywh","s","value","at","unit","prefix","parts","p","x","y","w","h","text","v","toRegion","o","label","box","n","out","parseRegions","list","r","entry","m","toPercent","width","height","clamp","left","top","right","bottom"],"sources":["../../src/components/uvalib-image-regions/regions.ts"],"sourcesContent":["/**\n * Region parsing shared by `<uvalib-image-regions>` and `<uvalib-lightbox>` (its\n * `data-regions`). No Lit, no DOM rendering: small enough for the lightbox to import\n * statically.\n */\n\n/** One region on an image. */\nexport interface ImageRegion {\n /** A stable id, sent back in events. */\n id?: string;\n /** The region's name, shown in the list and on the highlighted outline. */\n label: string;\n /** Left edge, in `unit`s from the image's left. */\n x: number;\n /** Top edge, in `unit`s from the image's top. */\n y: number;\n /** Width, in `unit`s. */\n w: number;\n /** Height, in `unit`s. */\n h: number;\n /**\n * `percent` (of the image's width and height) or `px` (pixels of the image's natural size,\n * or of `image-width` × `image-height` when set). Default `px`, as in IIIF.\n */\n unit?: 'px' | 'percent';\n /** Where the region's list entry links. */\n href?: string;\n /** A short description after the label in the list. */\n description?: string;\n}\n\n/** A region box: its unit and four numbers. */\nexport interface RegionBox {\n x: number;\n y: number;\n w: number;\n h: number;\n unit: 'px' | 'percent';\n}\n\n/**\n * A IIIF / Media Fragments `xywh` value: `percent:10,20,30,40`, `pixel:160,120,320,240`\n * or `160,120,320,240` (pixels), optionally as `xywh=…` or a URL ending `#xywh=…`.\n * Returns null for anything else, and for a zero width or height.\n */\nexport function parseXywh(value: string | null | undefined): RegionBox | null {\n let s = String(value ?? '').trim();\n const at = s.lastIndexOf('xywh=');\n if (at >= 0) s = s.slice(at + 5);\n s = s.split('&')[0]!.trim();\n let unit: RegionBox['unit'] = 'px';\n const prefix = /^(pixel|percent):/i.exec(s);\n if (prefix) {\n unit = prefix[1]!.toLowerCase() === 'percent' ? 'percent' : 'px';\n s = s.slice(prefix[0].length);\n }\n const parts = s.split(',');\n if (parts.length !== 4 || parts.some((p) => !/^\\s*\\d+(\\.\\d+)?\\s*$/.test(p))) return null;\n const [x, y, w, h] = parts.map(Number) as [number, number, number, number];\n if (w <= 0 || h <= 0) return null;\n return { x, y, w, h, unit };\n}\n\nconst text = (v: unknown): string =>\n String(v ?? '')\n .replace(/\\s+/g, ' ')\n .trim();\n\n/** A usable region from an unknown value (an `items` entry or JSON), or null. */\nexport function toRegion(v: unknown): ImageRegion | null {\n if (!v || typeof v !== 'object') return null;\n const o = v as Record<string, unknown>;\n const label = text(o.label);\n let box: RegionBox | null = null;\n if (typeof o.xywh === 'string') box = parseXywh(o.xywh);\n else {\n const n = [o.x, o.y, o.w, o.h].map((x) => (typeof x === 'string' ? Number(x) : x));\n if (n.every((x) => typeof x === 'number' && Number.isFinite(x) && x >= 0)) {\n const [x, y, w, h] = n as number[];\n if (w! > 0 && h! > 0)\n box = { x: x!, y: y!, w: w!, h: h!, unit: o.unit === 'percent' ? 'percent' : 'px' };\n }\n }\n if (!box) return null;\n const out: ImageRegion = { label, ...box };\n if (o.id != null && text(o.id)) out.id = text(o.id);\n if (typeof o.href === 'string' && o.href.trim()) out.href = o.href.trim();\n if (o.description != null && text(o.description)) out.description = text(o.description);\n return out;\n}\n\n/**\n * Regions written in an attribute (the lightbox's `data-regions`): a JSON array of region\n * objects, or entries separated by `;`, each an `xywh` value then its label, e.g.\n * `percent:10,20,30,40 Person 1; percent:55,15,20,30 Sign`. Entries that do not parse are\n * dropped.\n */\nexport function parseRegions(value: string | null | undefined): ImageRegion[] {\n const s = String(value ?? '').trim();\n if (!s) return [];\n if (s.startsWith('[')) {\n try {\n const list: unknown = JSON.parse(s);\n return Array.isArray(list)\n ? list.map(toRegion).filter((r): r is ImageRegion => r !== null)\n : [];\n } catch {\n return [];\n }\n }\n const out: ImageRegion[] = [];\n for (const entry of s.split(';')) {\n const m = /^\\s*(\\S+)\\s*(.*)$/.exec(entry);\n if (!m) continue;\n const box = parseXywh(m[1]);\n if (box) out.push({ label: text(m[2]), ...box });\n }\n return out;\n}\n\n/**\n * The box in percent of the image, clamped to it. Pixel boxes need the coordinate space\n * (`width` × `height`); without it they return null (not drawn yet).\n */\nexport function toPercent(box: RegionBox, width: number, height: number): RegionBox | null {\n let { x, y, w, h } = box;\n if (box.unit === 'px') {\n if (!(width > 0) || !(height > 0)) return null;\n x = (x / width) * 100;\n w = (w / width) * 100;\n y = (y / height) * 100;\n h = (h / height) * 100;\n }\n const clamp = (v: number) => Math.min(100, Math.max(0, v));\n const left = clamp(x);\n const top = clamp(y);\n const right = clamp(x + w);\n const bottom = clamp(y + h);\n if (right <= left || bottom <= top) return null;\n return { x: left, y: top, w: right - left, h: bottom - top, unit: 'percent' };\n}\n"],"mappings":";AA6CA,SAAgBA,EAAU,GAAoD;CAC5E,IAAIC,IAAI,OAAOC,KAAS,EAAE,CAAC,CAAC,KAAK,GAC3BC,IAAKF,EAAE,YAAY,OAAO;CAEhC,AADIE,KAAM,MAAG,IAAIF,EAAE,MAAME,IAAK,CAAC,IAC/B,IAAIF,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,CAAE,KAAK;CAC1B,IAAIG,IAA0B,MACxBC,IAAS,qBAAqB,KAAKJ,CAAC;CAC1C,AAAII,MACF,IAAOA,EAAO,EAAE,CAAE,YAAY,MAAM,YAAY,YAAY,MAC5D,IAAIJ,EAAE,MAAMI,EAAO,EAAE,CAAC,MAAM;CAE9B,IAAMC,IAAQL,EAAE,MAAM,GAAG;CACzB,IAAIK,EAAM,WAAW,KAAKA,EAAM,MAAM,MAAM,CAAC,sBAAsB,KAAKC,CAAC,CAAC,GAAG,OAAO;CACpF,IAAM,CAACC,GAAGC,GAAGC,GAAGC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