// PhotoSwipe instantiation, data-source construction, history / hash // navigation. Individual UI elements (caption, download, fullscreen, motion // photo, 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 type { PhotoSwipeOptions } from 'photoswipe' import { state, SIDEBAR_WIDTH, SIDEBAR_SHEET_FRACTION, MOBILE_BREAKPOINT } from './state.js' import type { GalleryItem } from '../shared/types.js' import { registerBackButton, registerCaption, registerDownloadButton, registerFullscreenButton, registerMotionButton } from './lightbox-ui.js' import { registerSidebar } from './sidebar.js' import { registerLazyDetail } from './metadata.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]) || {} // type may be empty for lazy album videos (the content-type probe is // deferred); an empty type attribute is omitted below so the browser // falls back to the proxy's response Content-Type. return { src: source.src || '', type: source.type || '' } } catch (e) { return { src: '', type: '' } } } function escapeAttr (s: string): string { return String(s).replace(/&/g, '&').replace(/"/g, '"').replace(//g, '>') } // Per-slide bookkeeping for the zoom-to-upgrade + native-resolution cap, keyed // by the gallery item index (stamped on each dataSource entry as `_ippIndex`). // Reset on every lightbox open. const loadedBitmapWidth = new Map() // index -> naturalWidth of the bitmap now in the const upgradedSlides = new Set() // indices already swapped to fullUrl /** * Translate `state.items` into PhotoSwipe's dataSource array. Images use * `src`/`width`/`height`; videos use the `html` slide with a `