// PhotoSwipe instantiation, data-source construction, history / hash // navigation. Individual UI elements (caption, download, fullscreen, // sidebar) live in lightbox-ui.ts and sidebar.ts. // Runtime URL resolved by Express static, not a TS-resolvable module path. // @ts-expect-error - browser-only ESM URL import PhotoSwipeLightbox from '/share/static/photoswipe/photoswipe-lightbox.esm.js' // eslint-disable-line import/no-absolute-path import { state, SIDEBAR_WIDTH, MOBILE_BREAKPOINT } from './state.js' import type { GalleryItem } from '../shared/types.js' import { registerBackButton, registerCaption, registerDownloadButton, registerFullscreenButton } from './lightbox-ui.js' import { registerSidebar } from './sidebar.js' /** * Replace the current history entry with the same URL minus any hash. * No-op when there is no hash. Used by the lightbox-close paths so the * browser bar shows a clean gallery URL after the lightbox dismisses, * even when the entry we land on came from a `#assetId` deep link. */ function clearHashIfPresent () { if (window.location.hash) { history.replaceState(null, '', window.location.pathname + window.location.search) } } function parseVideoData (item: GalleryItem): { src: string, type: string } { try { const data = JSON.parse(item.videoData || '{}') const source = (data.source && data.source[0]) || {} return { src: source.src || '', type: source.type || 'video/mp4' } } catch (e) { return { src: '', type: 'video/mp4' } } } function escapeAttr (s: string): string { return String(s).replace(/&/g, '&').replace(/"/g, '"').replace(//g, '>') } /** * Translate `state.items` into PhotoSwipe's dataSource array. Images use * `src`/`width`/`height`; videos use the `html` slide with a `