@michaelyagi/shoji 0.1.0-beta.13 → 0.1.0-beta.14
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/dist/core/shoji-core.css +43 -0
- package/dist/core/shoji-core.min.css +1 -1
- package/dist/esm/core/iconSwap.d.ts +21 -0
- package/dist/esm/iconSwap-BAXTLihx.js +21 -0
- package/dist/esm/iconSwap-BAXTLihx.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index2.css +43 -0
- package/dist/esm/plugins/autoplay/index.js +4 -2
- package/dist/esm/plugins/autoplay/index.js.map +1 -1
- package/dist/esm/plugins/fullscreen/index.js +4 -2
- package/dist/esm/plugins/fullscreen/index.js.map +1 -1
- package/dist/esm/plugins/zoom/icons.d.ts +14 -1
- package/dist/esm/plugins/zoom/index.js +18 -2
- package/dist/esm/plugins/zoom/index.js.map +1 -1
- package/dist/plugins/autoplay.js +20 -2
- package/dist/plugins/autoplay.js.map +1 -1
- package/dist/plugins/autoplay.min.js +1 -1
- package/dist/plugins/autoplay.min.js.map +1 -1
- package/dist/plugins/fullscreen.js +20 -2
- package/dist/plugins/fullscreen.js.map +1 -1
- package/dist/plugins/fullscreen.min.js +1 -1
- package/dist/plugins/fullscreen.min.js.map +1 -1
- package/dist/plugins/zoom.js +34 -2
- package/dist/plugins/zoom.js.map +1 -1
- package/dist/plugins/zoom.min.js +1 -1
- package/dist/plugins/zoom.min.js.map +1 -1
- package/dist/shoji.css +43 -0
- package/dist/shoji.js +41 -7
- package/dist/shoji.js.map +1 -1
- package/dist/shoji.min.css +1 -1
- package/dist/shoji.min.js +1 -1
- package/dist/shoji.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zoom.min.js","sources":["../../src/core/zoomTransition.ts","../../src/plugins/zoom/icons.ts","../../src/plugins/zoom/zoomMath.ts","../../src/plugins/zoom/index.ts"],"sourcesContent":["/** The drag's exact on-screen appearance at the moment it completed a close — `translateY(px)`/`scale`/`opacity`, all as last shown live (translateY clamped, see `GestureController.takeFrozenDragTransform`). `zoomOut()` jumps `target` here instantly (after measuring its natural box — see `ZoomTransitionTarget.dragStart`) before transitioning away from it, so the close continues in one motion from exactly where the drag left off. */\nexport interface FrozenDragTransform {\n translateY: number;\n scale: number;\n opacity: number;\n}\n\nexport interface ZoomTransitionTarget {\n /** The thumbnail element to animate to/from. */\n origin: HTMLElement;\n /** The `.shoji-slide-media` element being animated — not `.shoji-slide` itself, whose transform is already owned by pool-offset positioning. */\n target: HTMLElement;\n /** `item.width / item.height`, when known, else the origin thumbnail's own `naturalWidth`/`naturalHeight` ratio — just a *shape* guess; see `effectiveTargetBox`. */\n aspectRatio?: number;\n /** The real photo's true pixel size — `item.width`/`item.height` only, never the thumbnail's own natural size (would under-cap a large photo). Caps `containedBox` below at native resolution, mirroring `.shoji-slide-img`'s own `max-width/max-height: 100%`, instead of always growing toward filling the dialog. */\n naturalSize?: { width: number; height: number };\n /**\n * A completed drag-close's own last appearance (`GestureController.\n * takeFrozenDragTransform`) — `zoomOut()` (the only consumer) jumps\n * `target` here instantly, *after* measuring its natural box for the\n * landing math, then transitions away from it. Order matters: applying\n * this before measuring would make `effectiveTargetBox()` read the\n * child `<img>`'s rect *already* shrunk by this scale, double-counting\n * it once `zoomOut()`'s own transform (computed from that shrunk\n * measurement) then wholesale replaces — not composes with — it.\n */\n dragStart?: FrozenDragTransform;\n /**\n * The zoomed `<img>`'s own real on-screen rect (`getBoundingClientRect()`)\n * at the moment a button-close (or any non-drag close) starts, if it's\n * currently zoomed in — captured by `Gallery.beginClose()` from\n * `registerZoomStartProvider()` *before* the Zoom plugin's own\n * `beforeClose` handler resets it back to neutral (so `zoomOut()`'s own\n * measurement below stays correct — same ordering requirement `dragStart`\n * has, and the same reason).\n *\n * A rect, not the Zoom plugin's raw scale/pan numbers — an earlier version\n * passed those through directly and re-applied them to `target`\n * (`.shoji-slide-media`) the same way `dragStart` reapplies its own\n * translateY/scale. That doesn't work here: Zoom's own pan math is\n * relative to the `<img>` itself with `transform-origin: 0 0`\n * (`zoom/index.ts`), a *different* element with a *different* origin than\n * `target`'s `transform-origin: center` below — reapplying the same\n * numbers onto the wrong element/origin pair visibly shifted the image\n * toward its top-left corner the instant close started, worse the more\n * zoomed in it was. A rect sidesteps this entirely: `zoomOut()` computes\n * the jump the same center-to-center way it computes everything else\n * (`transformBetween`), from `target`'s own freshly-measured natural box\n * to this rect — origin-and-coordinate-system-agnostic, so it doesn't\n * matter what internal convention produced the rect.\n *\n * `zoomOut()` jumps `target` here instantly, then transitions away from\n * it, so closing while zoomed continues in one motion from the zoomed-in\n * view instead of snapping back to neutral first and only then shrinking\n * to the thumbnail. Mutually exclusive with `dragStart` in practice — you\n * can't complete a vertical drag-close while the zoom plugin is also\n * mid-pan, since `GestureController` suspends its own drag handling\n * entirely while zoomed (`isZoomed()`, DESIGN.md §4.6).\n */\n zoomStart?: Box;\n}\n\nfunction prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === 'function' &&\n window.matchMedia('(prefers-reduced-motion: reduce)').matches\n );\n}\n\n/** `\"300ms\"` / `\"0.3s\"` → milliseconds. Reads the *actual* computed value, not an assumed default, so a host overriding `--shoji-duration` still gets a correct fallback timeout below. */\nfunction parseCssTime(value: string): number {\n const first = value.split(',')[0]?.trim() ?? '';\n if (first.endsWith('ms')) return parseFloat(first);\n if (first.endsWith('s')) return parseFloat(first) * 1000;\n return 0;\n}\n\nexport interface Box {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\n/** The `object-fit: contain` box for `aspectRatio` within `container`, computed analytically since the real image may not be loaded yet. `naturalSize` caps the result at the photo's own true pixel size, never stretching past native resolution. Exported — `SlideManager.ts`'s open-transition placeholder (§2.3) reuses this same math. */\nexport function containedBox(\n container: Box,\n aspectRatio: number,\n naturalSize?: { width: number; height: number },\n): Box {\n const containerRatio = container.width / container.height;\n let width = aspectRatio > containerRatio ? container.width : container.height * aspectRatio;\n let height = aspectRatio > containerRatio ? container.width / aspectRatio : container.height;\n if (naturalSize && naturalSize.width > 0 && naturalSize.height > 0) {\n const cap = Math.min(1, naturalSize.width / width, naturalSize.height / height);\n width *= cap;\n height *= cap;\n }\n return {\n left: container.left + (container.width - width) / 2,\n top: container.top + (container.height - height) / 2,\n width,\n height,\n };\n}\n\n/**\n * `target`'s effective visual box, not necessarily its own\n * `getBoundingClientRect()`. `target` is always its full flex-box size; the\n * photo inside is usually *smaller*, letterboxed to its own aspect ratio —\n * a real bug used the container's full rect, making the animation scale\n * from/to a box far bigger than the photo ever renders at, visibly\n * shrinking it to something much smaller than the thumbnail whenever the\n * aspect ratios didn't match (the common case). Preferred sources: the real\n * rendered media child, if attached; else an analytical contain-box from\n * `aspectRatio`; else the container's own rect as a last resort.\n *\n * A real bug this guards against: on a fresh open with nothing decoded yet,\n * `target`'s only child at this point is the loading spinner (§2.3) — a\n * fixed ~40px circle, not the photo. Trusting its rect as \"the real\n * rendered media child\" made the FLIP transition scale toward/from a box\n * far smaller than the actual photo, so the scale factor came out inverted\n * (>1 instead of <1) and the spinner rendered wildly oversized for the\n * transition's first frames before shrinking back down — never the actual\n * photo, which hadn't swapped in yet either way.\n *\n * Same reasoning excludes `.shoji-slide-open-placeholder` (§2.3's low-res\n * open() stand-in): it's a real, non-spinner `<img>`, but its own rendered\n * rect reflects *its* crop/aspect ratio, not the real photo's — trusting it\n * would scale toward the placeholder's shape instead of the real photo's,\n * only to visibly jump again once the real photo swaps in and this\n * transition (already run) no longer applies. Excluding it falls through to\n * the analytical `aspectRatio`-based box below, sized for the real photo\n * regardless of what shape the placeholder happens to be.\n */\nfunction effectiveTargetBox(\n target: HTMLElement,\n aspectRatio?: number,\n naturalSize?: { width: number; height: number },\n): Box {\n const child = target.firstElementChild;\n const isPlaceholder =\n child instanceof HTMLElement &&\n (child.classList.contains('shoji-slide-spinner') ||\n child.classList.contains('shoji-slide-open-placeholder'));\n if (child instanceof HTMLElement && !isPlaceholder) {\n const rect = child.getBoundingClientRect();\n if (rect.width > 0 && rect.height > 0) return rect;\n }\n const containerRect = target.getBoundingClientRect();\n if (aspectRatio && containerRect.width > 0 && containerRect.height > 0) {\n return containedBox(containerRect, aspectRatio, naturalSize);\n }\n return containerRect;\n}\n\n/**\n * Center-to-center translate + a single uniform scale that lands `target`'s\n * effective box (`effectiveTargetBox` above) *within* `origin`'s box,\n * without distorting it. `null` if either has no real size — nothing sane\n * to animate. One scale factor, not independent scaleX/scaleY: origin and\n * the photo essentially never share an exact aspect ratio, and scaling each\n * axis independently to force a rect match visibly squeezes/stretches the\n * image. `Math.min` keeps the box fully contained within origin's rect\n * (same tradeoff `object-fit: contain` makes); center always lands exactly\n * on origin's center, only the unconstrained axis's edges fall short.\n */\n/**\n * The actual translate3d/scale3d math `computeTransform` below needs —\n * pulled out on its own so `zoomOut`'s `zoomStart` jump (a *second* use of\n * the exact same center-to-center box-fitting math, landing on a captured\n * live rect instead of `origin`'s) can reuse it directly, rather than\n * re-deriving Zoom's own transform-origin/coordinate conventions on a\n * different element — see `ZoomTransitionTarget.zoomStart`'s own doc\n * comment for why that direct-replication approach doesn't work.\n */\nfunction transformBetween(from: Box, to: Box): string {\n const scale = Math.min(to.width / from.width, to.height / from.height);\n const translateX = to.left + to.width / 2 - (from.left + from.width / 2);\n const translateY = to.top + to.height / 2 - (from.top + from.height / 2);\n // translate3d/scale3d, not translate()/scale() — forces the GPU\n // compositing path instead of a main-thread-painted 2D transform, the\n // same fix already validated for the Zoom plugin's own scale animation\n // (DESIGN.md §4.6): this is the identical technique (a large photo\n // scaled via `transform`) on the same element, just driven by open/close\n // instead of pinch/toolbar zoom.\n return `translate3d(${translateX}px, ${translateY}px, 0) scale3d(${scale}, ${scale}, 1)`;\n}\n\n/**\n * `origin`'s effective visual box, not necessarily its own\n * `getBoundingClientRect()`. In selector/DOM-markup mode without Layout,\n * `origin` is typically a plain `<a>` wrapping a `<img>` — an inline element\n * by default, whose own box is sized to a text-line-height sliver (its\n * `font-size`/`line-height`), not the image it visually contains, even\n * though the image itself paints at full size. A real bug: the zoom\n * open/close transform used that sliver directly as the FLIP target,\n * landing the animation at a tiny, essentially-random offset instead of the\n * real thumbnail's visible position and size. Layout tiles aren't affected\n * (`display: block`, sized to match their child image exactly) — preferring\n * the child's rect there returns the same box either way.\n *\n * `querySelector('img')`, not `firstElementChild` — matches `scan.ts`'s own\n * `scanImage()` convention for locating a thumbnail inside arbitrary host\n * markup, where the `<img>` isn't necessarily the first child (a badge or\n * caption element placed before it in the DOM would otherwise get measured\n * instead, no more correct than the wrapper's own sliver).\n */\nfunction effectiveOriginBox(origin: HTMLElement): Box {\n const img = origin.querySelector('img');\n if (img) {\n const rect = img.getBoundingClientRect();\n if (rect.width > 0 && rect.height > 0) return rect;\n }\n return origin.getBoundingClientRect();\n}\n\nfunction computeTransform(\n origin: HTMLElement,\n target: HTMLElement,\n aspectRatio?: number,\n naturalSize?: { width: number; height: number },\n): string | null {\n const originRect = effectiveOriginBox(origin);\n const targetRect = effectiveTargetBox(target, aspectRatio, naturalSize);\n if (\n targetRect.width === 0 ||\n targetRect.height === 0 ||\n originRect.width === 0 ||\n originRect.height === 0\n ) {\n return null;\n }\n return transformBetween(targetRect, originRect);\n}\n\n/**\n * Waits for `target`'s own transition (on `property`, default `'transform'`)\n * to end (with a safety-net timeout in case transitionend never fires — an\n * interrupted/removed element, a browser quirk, or `--shoji-duration: 0ms`\n * under `prefers-reduced-motion`, which some browsers never fire a real\n * transitionend for at all) then calls `cb` exactly once. Exported: the\n * gesture-driven drag-to-navigate/drag-to-close settle animations (§2.4,\n * `Gallery.ts`) reuse this same wait-with-fallback logic rather than\n * duplicating it — same instant-jump-then-transition FLIP family of moves\n * as the zoom transition, just on a different element/property pairing.\n * `close()`'s own controls-fade-before-zoom-out sequencing (§2.6a) reuses it\n * a second way, waiting on `opacity` instead.\n */\nexport function waitForTransitionEnd(\n target: HTMLElement,\n cb: () => void,\n property = 'transform',\n): void {\n const durationMs = parseCssTime(getComputedStyle(target).transitionDuration);\n let done = false;\n const finish = (): void => {\n if (done) return;\n done = true;\n target.removeEventListener('transitionend', onEnd);\n cb();\n };\n const onEnd = (event: Event): void => {\n if (event.target === target && (event as TransitionEvent).propertyName === property) finish();\n };\n target.addEventListener('transitionend', onEnd);\n setTimeout(finish, durationMs + 100);\n}\n\n/**\n * A real bug: unconditionally clearing `transform` here could wipe out a\n * value another plugin (rotateFlip) legitimately set on the *same* element\n * in the time between this animation starting and its cleanup callback\n * firing (transitionend, or the fallback timeout — either can land well\n * after a quick click elsewhere). Only clears `transform` if it still\n * matches what this animation itself last wrote — nothing else has touched\n * it since — otherwise leaves it alone. `transition`/`transformOrigin`\n * are always safe to clear; nothing else in this codebase sets them.\n *\n * A second real bug, found via reopening the lightbox: `expectedTransform`\n * must be the value *read back* from `target.style.transform` right after\n * assigning it, not the raw string `computeTransform()` produced. Setting\n * `element.style.transform` to a string containing an arbitrary JS float\n * (e.g. `scale(0.10416666666666667)`, `computeTransform`'s un-rounded\n * `Math.min(...)` result) and reading it back gives a *differently\n * formatted* string — the browser's CSSOM serializer rounds/reformats\n * numeric values on its own (observed in Chromium: `scale(0.104167)`).\n * Comparing the raw JS string against that reformatted one here always\n * failed for any scale factor without a short, clean decimal, silently\n * skipping the clear — permanently leaving `zoomOut`'s shrink transform\n * applied to `.shoji-slide-media` after the lightbox closed. The next\n * `open()`'s `computeTransform` then measured that *already-shrunk*\n * element's `getBoundingClientRect()` as if it were the natural size,\n * computing a near-1 (barely visible) scale instead of a real zoom-in —\n * reads as \"doesn't zoom, just appears,\" and compounds on every further\n * open/close cycle since the stuck transform is never cleared either way.\n * `zoomIn`'s own `'none'` literal never hit this — a fixed string round-trips\n * through the CSSOM unchanged, unlike an arbitrary computed float.\n *\n * `opacity` is cleared unconditionally, same as `transition`/\n * `transformOrigin` — a completed drag-close (`Gallery.beginClose`) bakes\n * the drag's own dim onto `target` before this animation starts; nothing\n * else in this codebase sets `.shoji-slide-media`'s opacity, so there's\n * nothing else's value this could ever clobber.\n */\nfunction clearInlineTransform(target: HTMLElement, expectedTransform: string): void {\n target.style.transition = '';\n target.style.transformOrigin = '';\n target.style.willChange = '';\n target.style.opacity = '';\n if (target.style.transform === expectedTransform) target.style.transform = '';\n}\n\n/**\n * FLIP-style open: `target` starts visually at `origin`'s position/size (an\n * instant, untransitioned jump), then transitions to its natural layout —\n * reads as \"growing out of the thumbnail.\" Fire-and-forget: cleans up its\n * own inline styles once the transition ends, nothing to await.\n */\nexport function zoomIn({ origin, target, aspectRatio, naturalSize }: ZoomTransitionTarget): void {\n if (prefersReducedMotion()) return;\n const transform = computeTransform(origin, target, aspectRatio, naturalSize);\n if (!transform) return;\n\n target.style.transition = 'none';\n // computeTransform's translateX/Y is center-to-center math — must pair with\n // a center transform-origin (the CSS default), not 'top left', or the\n // scaled box ends up offset from origin by however far origin's center\n // sits from its own top-left corner.\n target.style.transformOrigin = 'center';\n // Promotes target onto its own compositing layer before the animated\n // transform starts, not mid-animation — same GPU-seam mitigation as the\n // Zoom plugin (DESIGN.md §4.6). Cleared in clearInlineTransform once the\n // transition ends, not left on permanently: this is the offset-0 pool\n // slot, alive for the gallery's whole lifetime, not a class scoped to\n // only-while-zoomed.\n target.style.willChange = 'transform';\n target.style.transform = transform;\n void target.offsetHeight; // force the instant jump to commit before transitioning away from it\n target.style.transition = 'transform var(--shoji-duration) var(--shoji-easing)';\n target.style.transform = 'none';\n\n waitForTransitionEnd(target, () => clearInlineTransform(target, 'none'));\n}\n\n/**\n * Reverse of `zoomIn`: `target` transitions from its natural position down\n * to `origin`'s rect — \"shrinking back into the thumbnail.\" `onComplete`\n * always fires exactly once, synchronously if there's nothing to animate\n * (reduced motion, or no valid rect), otherwise once the transition ends —\n * callers use this to know when it's safe to actually hide/finalize.\n */\nexport function zoomOut(\n { origin, target, aspectRatio, naturalSize, dragStart, zoomStart }: ZoomTransitionTarget,\n onComplete: () => void,\n): void {\n if (prefersReducedMotion()) {\n onComplete();\n return;\n }\n // Measured before dragStart/zoomStart is ever applied to `target` — see\n // ZoomTransitionTarget.dragStart's doc comment for why the order matters.\n const transform = computeTransform(origin, target, aspectRatio, naturalSize);\n if (!transform) {\n onComplete();\n return;\n }\n\n // computeTransform's translateX/Y is center-to-center math — must pair with\n // a center transform-origin (the CSS default), not 'top left', or the\n // scaled box ends up offset from origin by however far origin's center\n // sits from its own top-left corner.\n target.style.transformOrigin = 'center';\n target.style.willChange = 'transform'; // see zoomIn's doc comment on this line\n if (dragStart) {\n // Instant jump to exactly where the drag left off — same FLIP\n // technique `zoomIn()` uses to jump onto origin's box before\n // transitioning away from it, just jumping to wherever the drag left\n // off instead of a fixed point. translate3d/scale3d (not the 2D forms),\n // matching the landing transform's own function list below — mismatched\n // function types between the transition's start/end values force the\n // browser into matrix-decomposition interpolation instead of simple\n // per-parameter interpolation, and lose the GPU-compositing path this\n // codebase otherwise always uses for this element (DESIGN.md §2.3b).\n target.style.transition = 'none';\n target.style.transform = `translate3d(0px, ${dragStart.translateY}px, 0px) scale3d(${dragStart.scale}, ${dragStart.scale}, 1)`;\n target.style.opacity = String(dragStart.opacity);\n void target.offsetHeight; // commit the jump before transitioning away from it\n } else if (zoomStart) {\n // Same FLIP jump as dragStart above, computed the same center-to-center\n // way as `transform` above (not dragStart's raw translate/scale reuse\n // — see ZoomTransitionTarget.zoomStart's doc comment for why that\n // doesn't work here). `target`'s own effective box, re-measured fresh:\n // cheap, and guaranteed unchanged since the read inside\n // computeTransform() above — nothing's touched `target` in between.\n // Still correct even if `target` is currently rotated/flipped (the\n // RotateFlip plugin, applied directly to this same element, unlike\n // Zoom's own scale/pan — see below): both this measurement and\n // `zoomStart` itself were captured at the same rotation, so the\n // scale/translate between their two (equally rotated) bounding boxes\n // still isolates the zoom-only delta correctly.\n const targetRect = effectiveTargetBox(target, aspectRatio, naturalSize);\n if (targetRect.width > 0 && targetRect.height > 0) {\n // Composed onto whatever's already there, never replacing it outright\n // — a real bug, reported from real usage: closing while both rotated/\n // flipped *and* zoomed wholesale-overwrote RotateFlip's own\n // scaleX/scaleY/rotate() with this jump's plain translate/scale,\n // un-rotating *instantly* right here, before the real transition\n // below even starts — a snap to neutral rotation, then a separate\n // zoom-out, instead of the smooth combined un-rotate-while-shrinking\n // motion closing while rotated (without zoomStart at all) already\n // gets for free: transitioning target's transform from *whatever it\n // currently is* to the final plain shrink value is what makes that\n // work, and it needs target's rotation to still be sitting there\n // when the transition starts, not already erased by this jump.\n const existing = target.style.transform;\n const jump = transformBetween(targetRect, zoomStart);\n target.style.transition = 'none';\n target.style.transform = existing && existing !== 'none' ? `${existing} ${jump}` : jump;\n void target.offsetHeight;\n }\n }\n target.style.transition = 'transform var(--shoji-duration) var(--shoji-easing)';\n void target.offsetHeight;\n target.style.transform = transform;\n // Read back what the browser actually stored, not the raw string just\n // assigned — see clearInlineTransform's own doc comment for why the two\n // can differ (CSSOM float reformatting) and why that difference matters.\n const appliedTransform = target.style.transform;\n\n waitForTransitionEnd(target, () => {\n clearInlineTransform(target, appliedTransform);\n onComplete();\n });\n}\n","/** DESIGN.md §9 — inline SVG, stroke = currentColor, matches src/core/icons.ts's convention. A magnifying glass with a +/− in the lens, and a plain expand-corners glyph for \"actual size\" (distinct from fullscreen's EXPAND_ICON — no diagonal corner arrows, just a frame, so the two aren't visually confusable when both plugins are enabled). */\nexport const ZOOM_IN_ICON =\n '<svg viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"10\" cy=\"10\" r=\"7\"/><path d=\"M21 21l-5.5-5.5M10 7v6M7 10h6\"/></svg>';\n\nexport const ZOOM_OUT_ICON =\n '<svg viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"10\" cy=\"10\" r=\"7\"/><path d=\"M21 21l-5.5-5.5M7 10h6\"/></svg>';\n\nexport const ZOOM_ACTUAL_SIZE_ICON =\n '<svg viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"1\"/><path d=\"M9 15l6-6M9 9h0M15 15h0\"/></svg>';\n","/** A viewport-relative rect: `{left, top, width, height}`, same shape as `DOMRect` but plain-object so it's trivial to mock in tests. */\nexport interface ZoomBox {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nexport interface PanOffset {\n tx: number;\n ty: number;\n}\n\nexport function clampScale(scale: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, scale));\n}\n\n/** The 2x2 linear part of a CSS transform matrix — `{a, b, c, d}` from `matrix(a, b, c, d, e, f)`, translation (`e`/`f`) deliberately excluded, since everything below only ever uses this to remap a *delta* or a *local offset*, never an absolute position. */\nexport interface LinearTransform {\n a: number;\n b: number;\n c: number;\n d: number;\n}\n\n/** No parent transform — used as the default wherever a caller doesn't have (or need) one, so every function below stays backward-compatible with a pre-RotateFlip-aware caller. */\nexport const IDENTITY_TRANSFORM: LinearTransform = { a: 1, b: 0, c: 0, d: 1 };\n\n/**\n * `getComputedStyle().transform`'s own `matrix(a, b, c, d, e, f)` (or\n * `none`) string, parsed by hand rather than via the `DOMMatrix`\n * constructor — jsdom (`tests/unit/`) doesn't implement it, so relying on\n * it broke every unit test that exercises a pan drag; a plain regex needs\n * nothing environment-specific and works identically in a real browser.\n * RotateFlip only ever emits a 2D `matrix(...)` (never `matrix3d(...)`),\n * so that's the only form handled — `none` and anything unparseable both\n * fall back to the identity matrix.\n */\nexport function parseLinearTransform(transform: string): LinearTransform {\n const match = /^matrix\\(\\s*([^,]+),\\s*([^,]+),\\s*([^,]+),\\s*([^,]+),/.exec(transform);\n if (!match) return { ...IDENTITY_TRANSFORM };\n return { a: Number(match[1]), b: Number(match[2]), c: Number(match[3]), d: Number(match[4]) };\n}\n\n/**\n * DESIGN.md §4.6 — a real bug, reported from real usage: dragging to pan a\n * zoomed photo that RotateFlip (§4.5) had also rotated moved it in the\n * *wrong* direction (e.g. dragging down moved the image sideways instead)\n * — `onPointerMove`'s raw `event.clientX/Y` delta (screen space) was being\n * applied directly as `pan.tx`/`ty` (the `<img>`'s own *local* space,\n * nested inside `.shoji-slide-media`), with nothing correcting for\n * whatever transform that parent has — RotateFlip's rotation, in this\n * case, but this doesn't need to know that specifically: it corrects for\n * *any* linear transform on the parent, read live off its own computed\n * style, not by reaching into RotateFlip.\n *\n * Standard 2x2 matrix inversion: for `M = [[a, c], [b, d]]`, `M⁻¹ =\n * 1/det * [[d, -c], [-b, a]]` — applying `M⁻¹` to a screen-space delta\n * converts it into the local space `M` itself maps *from*, which is\n * exactly what a child nested inside that transformed parent needs to\n * move by to track the pointer 1:1 on screen regardless of the parent's\n * own rotation/scale/flip. `det === 0` is a degenerate parent transform\n * (zero scale on some axis) that can't be un-done at all — returns the\n * raw delta unchanged rather than dividing by zero into `NaN`.\n */\nexport function screenDeltaToLocal(dx: number, dy: number, m: LinearTransform): PanOffset {\n const det = m.a * m.d - m.b * m.c;\n if (det === 0) return { tx: dx, ty: dy };\n return {\n tx: (m.d * dx - m.c * dy) / det,\n ty: (m.a * dy - m.b * dx) / det,\n };\n}\n\n/** The forward companion to `screenDeltaToLocal` above: `M * [dx; dy]`, converting a *local* delta into the screen-space delta it produces once composed through the parent's current transform `m`. */\nexport function localDeltaToScreen(dx: number, dy: number, m: LinearTransform): PanOffset {\n return { tx: m.a * dx + m.c * dy, ty: m.b * dx + m.d * dy };\n}\n\n/**\n * DESIGN.md §4.6 — the img's own true, *unrotated* layout size (its\n * `offsetWidth`/`offsetHeight` — CSS `transform` is paint-only and never\n * affects these, unlike `natural`'s own `getBoundingClientRect()`, which\n * *does* reflect the parent's current rotation) as an offset from the\n * img's own local origin `(0, 0)` to its own layout center, negated:\n * `{tx: -width/2, ty: -height/2}`. See `localOriginScreen`'s own doc\n * comment for why this specific offset is what a rotated parent needs.\n * Defaults to deriving it from `natural` itself (assuming `natural` *is*\n * already the true, unrotated size) — correct whenever the parent has no\n * rotation, wrong whenever it does; real callers with a possibly-rotated\n * parent should always pass the img's real `offsetWidth`/`offsetHeight`\n * explicitly instead of relying on this default.\n */\nexport function trueOriginOffset(natural: ZoomBox): PanOffset {\n return { tx: -natural.width / 2, ty: -natural.height / 2 };\n}\n\n/**\n * DESIGN.md §4.6 — a real bug, found immediately after the pan-drag fix\n * above while testing the analogous double-click-to-zoom case: `natural`'s\n * own `left`/`top` (from `getBoundingClientRect()` on the *rotated* img)\n * is **not** the screen position of the img's local origin `(0, 0)` —\n * rotating a rectangle moves *which of its own corners* ends up at the\n * bounding box's own top-left. For a 90°-rotated landscape photo, the\n * corner that lands at `natural`'s own top-left is the photo's original\n * *bottom*-left, not its top-left — confirmed directly, by hand, against\n * real `getBoundingClientRect()` numbers: treating `natural.left + pan.tx`\n * as \"the origin's screen position\" (what `zoomTowardPoint`/`clampPan`\n * both did) was off by the img's own full width on one axis, which is\n * exactly why double-clicking to zoom toward the pointer, after a\n * rotation, zoomed toward the wrong point instead — sometimes a\n * plausible-looking wrong point, sometimes (as reported) toward an edge\n * of the image instead of the actual click.\n *\n * The one point immune to this ambiguity is the bounding box's own\n * *center* — rotating a rectangle around its own center (the default\n * `transform-origin`, and where `.shoji-slide-media`'s flex-centering\n * already puts the img) never moves that center, on screen or off. Used\n * as a pivot: the img's local origin, relative to its own *true* (layout,\n * pre-rotation) center, is a fixed offset (`originOffset`, `-width/2,\n * -height/2` in the img's own local space) — that offset plus the current\n * `pan`, mapped through the parent's rotation matrix `m` and added back to\n * the pivot's own (rotation-invariant) screen position, gives the origin's\n * *real* current screen position, correct for any axis-aligned rotation\n * RotateFlip can produce. At the default identity `m` and the default\n * `originOffset` (derived from `natural` itself, correct exactly when\n * there's no rotation to begin with), this reduces to plain\n * `natural.left + pan.tx` — the original, pre-fix formula.\n */\nexport function localOriginScreen(\n natural: ZoomBox,\n pan: PanOffset,\n m: LinearTransform = IDENTITY_TRANSFORM,\n originOffset: PanOffset = trueOriginOffset(natural),\n): { x: number; y: number } {\n const pivotX = natural.left + natural.width / 2;\n const pivotY = natural.top + natural.height / 2;\n const fromPivot = localDeltaToScreen(originOffset.tx + pan.tx, originOffset.ty + pan.ty, m);\n return { x: pivotX + fromPivot.tx, y: pivotY + fromPivot.ty };\n}\n\n/** One axis of `clampEdgeToContainer` below — see `clampPan`'s own doc comment for the geometry. Keeps the scaled content's edge from retreating inside the container's edge (no empty gap beyond the image); when the content is already smaller than the container on this axis, no position can avoid a gap on *both* sides at once, so centered is the only sensible answer. */\nfunction clampEdge(\n contentPos: number,\n contentSize: number,\n containerPos: number,\n containerSize: number,\n): number {\n if (contentSize <= containerSize) {\n return containerPos + (containerSize - contentSize) / 2;\n }\n const minPos = containerPos + containerSize - contentSize;\n const maxPos = containerPos;\n return Math.min(maxPos, Math.max(minPos, contentPos));\n}\n\n/**\n * The content's own current screen-space bounding box, for `clampPan`\n * below — the four corners of the img's true (unrotated) `width x height`\n * rect (from `originOffset`, negated), scaled and panned in the wrapper's\n * own unrotated frame, then each mapped to screen space individually via\n * `m` before taking the min/max. Four corners, not one edge scaled\n * directly, because `m` can swap which axis grows with which — RotateFlip\n * only ever produces axis-aligned (90°-multiple) rotations, so the result\n * is still a plain axis-aligned box, just not derivable from a single\n * corner the way an unrotated one is.\n */\nfunction contentScreenBounds(\n natural: ZoomBox,\n pan: PanOffset,\n scale: number,\n m: LinearTransform,\n originOffset: PanOffset,\n): { left: number; top: number; right: number; bottom: number } {\n const trueWidth = -originOffset.tx * 2;\n const trueHeight = -originOffset.ty * 2;\n const pivotX = natural.left + natural.width / 2;\n const pivotY = natural.top + natural.height / 2;\n const localCorners = [\n { x: 0, y: 0 },\n { x: trueWidth, y: 0 },\n { x: 0, y: trueHeight },\n { x: trueWidth, y: trueHeight },\n ];\n const screenCorners = localCorners.map(({ x, y }) => {\n const wrapperFrame = {\n x: originOffset.tx + pan.tx + x * scale,\n y: originOffset.ty + pan.ty + y * scale,\n };\n const screen = localDeltaToScreen(wrapperFrame.x, wrapperFrame.y, m);\n return { x: pivotX + screen.tx, y: pivotY + screen.ty };\n });\n const xs = screenCorners.map((p) => p.x);\n const ys = screenCorners.map((p) => p.y);\n return {\n left: Math.min(...xs),\n top: Math.min(...ys),\n right: Math.max(...xs),\n bottom: Math.max(...ys),\n };\n}\n\n/**\n * Keeps the scaled+panned content's edges from retreating inside\n * `container`'s edges (no empty gap beyond the image), on both screen axes\n * independently.\n *\n * `m`/`originOffset` (default identity / derived from `natural`, DESIGN.md\n * §4.6) — same real bug and same root cause as `localOriginScreen`'s own\n * doc comment: the old per-axis formula compared `natural.left + pan.tx`\n * (mixing screen-space and, once rotated, the wrong corner entirely)\n * against the container's screen bounds. The content's actual screen\n * bounding box is computed properly via `contentScreenBounds` (which\n * itself only ever needs `m`/`originOffset` to do that correctly), each\n * edge is clamped against the container the same way as before, and the\n * *difference* — a screen-space delta — is mapped back to local space and\n * folded into `pan`. At the defaults, every step is a no-op and this\n * reduces to exactly the original per-axis formula.\n */\nexport function clampPan(\n natural: ZoomBox,\n container: ZoomBox,\n scale: number,\n pan: PanOffset,\n m: LinearTransform = IDENTITY_TRANSFORM,\n originOffset: PanOffset = trueOriginOffset(natural),\n): PanOffset {\n const bounds = contentScreenBounds(natural, pan, scale, m, originOffset);\n const clampedLeft = clampEdge(\n bounds.left,\n bounds.right - bounds.left,\n container.left,\n container.width,\n );\n const clampedTop = clampEdge(\n bounds.top,\n bounds.bottom - bounds.top,\n container.top,\n container.height,\n );\n const screenDelta = { tx: clampedLeft - bounds.left, ty: clampedTop - bounds.top };\n const localDelta = screenDeltaToLocal(screenDelta.tx, screenDelta.ty, m);\n return { tx: pan.tx + localDelta.tx, ty: pan.ty + localDelta.ty };\n}\n\n/**\n * The standard \"zoom toward a point\" formula: adjusts pan so the viewport\n * point `(anchorX, anchorY)` stays visually fixed as scale changes from\n * `oldScale` to `newScale`, given `transform-origin: 0 0` (scaling never\n * moves the img's own local origin on screen, only `pan` does). Callers\n * still need to clamp the result with `clampPan` afterward; this only\n * solves the anchor-fixed part, not boundary containment.\n *\n * `m`/`originOffset` (default identity / derived from `natural`, DESIGN.md\n * §4.6) — a real bug, reported from real usage: double-clicking to zoom\n * toward the pointer, after RotateFlip had rotated the slide, zoomed\n * toward the wrong point — sometimes badly (see `localOriginScreen`'s own\n * doc comment for the root cause and how these two parameters fix it,\n * shared with `clampPan` above). At the defaults, every step is a no-op\n * and this reduces to exactly the original formula.\n */\nexport function zoomTowardPoint(\n natural: ZoomBox,\n pan: PanOffset,\n oldScale: number,\n newScale: number,\n anchorX: number,\n anchorY: number,\n m: LinearTransform = IDENTITY_TRANSFORM,\n originOffset: PanOffset = trueOriginOffset(natural),\n): PanOffset {\n const origin = localOriginScreen(natural, pan, m, originOffset);\n const screenDx = anchorX - origin.x;\n const screenDy = anchorY - origin.y;\n const local = screenDeltaToLocal(screenDx, screenDy, m);\n const factor = 1 - newScale / oldScale;\n return {\n tx: pan.tx + local.tx * factor,\n ty: pan.ty + local.ty * factor,\n };\n}\n","import type { PluginContext, ShojiPlugin } from '../../core/plugin';\nimport { waitForTransitionEnd } from '../../core/zoomTransition';\nimport { ZOOM_ACTUAL_SIZE_ICON, ZOOM_IN_ICON, ZOOM_OUT_ICON } from './icons';\nimport {\n clampPan,\n clampScale,\n parseLinearTransform,\n screenDeltaToLocal,\n zoomTowardPoint,\n type PanOffset,\n type ZoomBox,\n} from './zoomMath';\nimport './zoom.css';\n\nexport interface ZoomOptions {\n /** Multiplier cap for pinch/wheel/button zoom. \"Actual size\" can exceed this deliberately — it's an explicit action, not continuous gesture zoom. Default 4. */\n maxScale?: number;\n /** Scale a double-tap/double-click jumps to; a second one while already zoomed resets to 1 instead. Default 2. */\n doubleTapScale?: number;\n /** Multiplier applied per zoom-in/zoom-out toolbar button click. Default 1.5. */\n buttonStep?: number;\n}\n\nconst ZOOM_EPSILON = 1.001; // treat \"just barely above 1\" as unzoomed — avoids float residue pinning isZoomed() true forever\n\n/** A click/drag starting on a real control shouldn't engage pan — same exclusion list GestureController's shouldIgnoreGesture uses, duplicated rather than imported since that function isn't part of core's exported surface. */\nfunction isRealControl(event: PointerEvent): boolean {\n return event\n .composedPath()\n .some(\n (node) =>\n node instanceof Element &&\n node.matches(\n 'button, video, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption',\n ),\n );\n}\n\n/**\n * DESIGN.md §4-zoom — pinch, double-tap/click, wheel+ctrl, and three toolbar\n * buttons (zoom in/out/actual-size) all drive a single `scale`/pan state on\n * the active slide's `<img>` — never `.shoji-slide-media` itself, which the\n * rotateFlip plugin (§4) already transforms; nesting on the inner element\n * instead of fighting over the same transform string means a rotated *and*\n * zoomed photo behaves correctly for free (the outer rotate carries the\n * inner pan/scale along with it as a rigid unit, which is also the visually\n * expected result — see DESIGN.md's note on this plugin for the full\n * reasoning). Pinch/double-tap/wheel are core's own gesture relay (§2.4) —\n * scaffolding that existed specifically for this plugin to consume, not\n * reimplemented here. Pan (single-pointer drag while zoomed) is the one\n * piece core's relay doesn't cover — core's own drag-to-navigate/\n * drag-to-close would otherwise fight over the same drag — so this plugin\n * registers a zoom gate (`Gallery.registerZoomGate`, §4-zoom) that suspends\n * core's drag handling entirely while zoomed, and tracks pan with its own\n * minimal raw pointer listeners instead of reusing `GestureEngine` (whose\n * axis-locked model — pick horizontal *or* vertical per gesture — is the\n * wrong shape for a 2D pan that needs both at once).\n */\nexport const Zoom: ShojiPlugin = {\n name: 'zoom',\n defaults: {\n maxScale: 4,\n doubleTapScale: 2,\n buttonStep: 1.5,\n } satisfies ZoomOptions,\n\n init(ctx: PluginContext): () => void {\n const { gallery } = ctx;\n const maxScale = Number(ctx.options.maxScale ?? 4);\n const doubleTapScale = Number(ctx.options.doubleTapScale ?? 2);\n const buttonStep = Number(ctx.options.buttonStep ?? 1.5);\n const locale = (gallery.options.locale ?? {}) as Record<string, string>;\n const zoomInLabel = locale.zoomIn ?? 'Zoom in';\n const zoomOutLabel = locale.zoomOut ?? 'Zoom out';\n const actualSizeLabel = locale.zoomActualSize ?? 'Actual size';\n\n let scale = 1;\n let pan: PanOffset = { tx: 0, ty: 0 };\n let natural: ZoomBox | null = null;\n let container: ZoomBox | null = null;\n // The img's own true, unrotated local origin, as an offset from its\n // (rotation-invariant) layout center — see zoomTowardPoint/clampPan's\n // own doc comments (DESIGN.md §4.6) for why natural's left/top/width/\n // height alone aren't a safe stand-in for this once RotateFlip has\n // rotated the parent.\n let originOffset: PanOffset | null = null;\n let pinchStartScale = 1;\n\n function getImg(): HTMLImageElement | null {\n const media = gallery.getActiveMedia();\n const child = media?.firstElementChild;\n return child instanceof HTMLImageElement ? child : null;\n }\n\n function boxOf(el: Element): ZoomBox {\n const rect = el.getBoundingClientRect();\n return { left: rect.left, top: rect.top, width: rect.width, height: rect.height };\n }\n\n /** Only valid to measure while scale===1 (untransformed) — the very first zoom action on a slide; every subsequent action within the same slide reuses the cached box, since measuring an already-scaled element would capture the scaled size, not the natural one. */\n function ensureNatural(img: HTMLImageElement): boolean {\n if (natural && container && originOffset) return true;\n if (scale !== 1) return false; // shouldn't happen — defensive\n natural = boxOf(img);\n container = boxOf(img.parentElement ?? img);\n // offsetWidth/Height, not natural's own width/height above — CSS\n // transform (RotateFlip's rotation on the parent) is paint-only and\n // never affects layout size, unlike getBoundingClientRect(), which\n // reports the *rotated* bounding box (DESIGN.md §4.6). Falls back to\n // natural's own (unrotated-assuming) size when offsetWidth/Height\n // read 0 — real layout engines only report 0 for a genuinely\n // unrendered element, but jsdom (tests/unit/) never computes layout\n // at all and always reports 0, so this also keeps every rotation-\n // unaware unit test's mocked getBoundingClientRect() meaningful.\n originOffset = {\n tx: -(img.offsetWidth || natural.width) / 2,\n ty: -(img.offsetHeight || natural.height) / 2,\n };\n return true;\n }\n\n /**\n * A real bug: `ensureNatural`'s first measurement of a slide is only\n * trustworthy once the lightbox's own open FLIP transition (`zoomIn`,\n * `core/zoomTransition.ts`) has actually settled — that transition\n * applies its own transform directly to `.shoji-slide-media`, the exact\n * element `ensureNatural` measures as `container`. A zoom action firing\n * before it settles (any interaction within `--shoji-duration` of\n * opening — a fast click, or a test that only waits for the dialog to\n * become visible) captured a wildly wrong, mid-animation rect,\n * permanently poisoning that slide's zoom math (every later action\n * reuses the same cached, wrong box). `zoomIn` is fire-and-forget by\n * design (nothing to await when opening) and clears this exact inline\n * style once its own transition ends — the one signal available for\n * \"is it still running.\" Runs `action` immediately once settled, which\n * is right away in the overwhelming common case (any real interaction\n * more than ~300ms after open).\n */\n function whenSettled(action: () => void): void {\n const media = gallery.getActiveMedia();\n if (!media || media.style.transition === '') {\n action();\n return;\n }\n waitForTransitionEnd(media, action);\n }\n\n /**\n * `translate3d`/`scale3d`, not the 2D `translate`/`scale` this used to\n * use — a real bug, reported from real usage: evenly-spaced horizontal\n * lines visible across a zoomed photo, at certain zoom levels, on real\n * GPU hardware (not reproducible in headless/software rendering, so\n * this can't be verified here). The regular spacing matches Chromium's\n * own raster-tile boundaries — a known quirk where scaling large\n * content via a 2D `scale()` transform can show seams between GPU\n * tiles. Forcing the fully 3D compositing path instead (functionally\n * identical — `scale3d(s, s, 1)` and `scale(s)` produce the same\n * on-screen result) is the commonly effective fix, since it takes a\n * different rasterization path than the 2D one.\n */\n function apply(): void {\n const img = getImg();\n if (!img) return;\n img.style.transformOrigin = '0 0';\n img.style.transform =\n scale === 1 && pan.tx === 0 && pan.ty === 0\n ? 'none'\n : `translate3d(${pan.tx}px, ${pan.ty}px, 0) scale3d(${scale}, ${scale}, 1)`;\n img.classList.toggle('shoji-zoomed', scale > 1);\n }\n\n function emitChange(): void {\n ctx.emit('zoomChange', { index: gallery.currentIndex, scale });\n }\n\n /** Wraps a transform-setting `run` in a transition, for discrete jumps (buttons, double-tap, actual-size) — never for pinch/pan/wheel, which already track the input 1:1 and would visibly lag behind it under a transition. `afterEnd`, if given, runs once the transition actually completes, not before — `reset()` uses it to clear `transformOrigin` only once it's safe to (see its own comment for why clearing it any earlier is a real bug). The transition itself is always cleared afterward, so it doesn't linger onto the next, possibly-continuous, zoom action. */\n function withTransition(img: HTMLImageElement, run: () => void, afterEnd?: () => void): void {\n img.style.transition = 'transform var(--shoji-duration) var(--shoji-easing)';\n run();\n waitForTransitionEnd(img, () => {\n img.style.transition = '';\n afterEnd?.();\n });\n }\n\n /** Shared by every zoom-in/out entry point (pinch, wheel, buttons, double-tap, actual-size) — anchors on (anchorX, anchorY), clamps scale to [1, ceiling] and pan to the container bounds. `ceiling` defaults to maxScale; actual-size passes its own (possibly larger) target so it isn't capped by the gesture-zoom limit. Deferred via `whenSettled` — see its doc comment — so a zoom action landing right as the lightbox opens doesn't measure mid-animation. `animate` — see `withTransition`. */\n function zoomTo(\n targetScale: number,\n anchorX: number,\n anchorY: number,\n ceiling = maxScale,\n animate = false,\n ): void {\n whenSettled(() => {\n const img = getImg();\n if (!img || !ensureNatural(img)) return;\n const clampedScale = clampScale(targetScale, 1, Math.max(ceiling, 1));\n // DESIGN.md §4.6 — zoomTowardPoint's own doc comment has the full\n // reasoning: the anchor point needs the same screen-vs-local\n // correction as onPointerMove's own pan drag, since RotateFlip may\n // have rotated/flipped `.shoji-slide-media` in the meantime.\n const media = gallery.getActiveMedia();\n const parentTransform = parseLinearTransform(\n media ? getComputedStyle(media).transform : 'none',\n );\n pan = zoomTowardPoint(\n natural!,\n pan,\n scale,\n clampedScale,\n anchorX,\n anchorY,\n parentTransform,\n originOffset!,\n );\n scale = clampedScale;\n // Same correction, same reason — clampAxis compares against the\n // container's screen bounds, so the candidate pan needs to be in\n // screen space too, or a 90/270deg rotation clamps the wrong edge\n // and can undo the anchor-preserving pan just computed above.\n pan = clampPan(natural!, container!, scale, pan, parentTransform, originOffset!);\n if (animate) withTransition(img, apply);\n else apply();\n emitChange();\n });\n }\n\n function reset(animate = false): void {\n // A real gap, found auditing this against its own documented contract\n // (\"emits zoomChange on every scale change, gesture or button-driven\",\n // DESIGN.md §4.6): resetting from an engaged scale back to 1 is a\n // scale change like any other, but every call site here (beforeSlide,\n // afterSlide, beforeClose, afterOpen, and zoomOutStep/toggleZoom\n // reaching neutral) silently skipped emitting it — a host listening\n // for zoomChange to reflect \"is this slide currently zoomed\" would\n // never learn it stopped being true unless something else zoomed in\n // again first. Only when there's an actual change: the overwhelming\n // majority of these calls fire while already at scale 1 (nothing\n // engaged to begin with), and emitting on every no-op reset would be\n // noisy against the \"on every *change*\" contract, not a fix for it.\n const wasEngaged = scale !== 1;\n scale = 1;\n pan = { tx: 0, ty: 0 };\n natural = null;\n container = null;\n originOffset = null;\n if (wasEngaged) emitChange(); // after scale is already 1, so listeners see the real new value\n const img = getImg();\n if (!img) return;\n const clearTransform = (): void => {\n img.style.transform = '';\n img.classList.remove('shoji-zoomed');\n };\n if (animate) {\n // transform-origin has to stay put (0 0) for the duration of the\n // transition — clearing it to the browser default (center) in the\n // same tick as starting the transition snaps the scale anchor\n // instantly, which visibly jumped the image before it eased down\n // to neutral. Deferred to `afterEnd`, once the transition is done\n // and transform-origin no longer affects anything visible.\n withTransition(img, clearTransform, () => {\n img.style.transformOrigin = '';\n });\n } else {\n clearTransform();\n img.style.transformOrigin = '';\n }\n }\n\n /** DESIGN.md §2.5/§4.6 — same fix, same reasoning, as RotateFlip's own equivalent (`rotateFlip/index.ts`): `beforeSlide`'s unanimated `reset()` above can't itself animate (it has to finish before `SlideManager.render()` reparents the outgoing image), so the live `transform`/`transformOrigin` about to be wiped are captured here first and handed to `SlideTransition` via `registerSlideLeaveDecorator()` below, to animate away on the leave-ghost's own clone instead of just vanishing. */\n let pendingLeaveTransform: string | null = null;\n let pendingLeaveOrigin = '';\n function captureLeaveTransform(): void {\n const img = getImg();\n const transform = img?.style.transform;\n pendingLeaveTransform = transform && transform !== 'none' ? transform : null;\n pendingLeaveOrigin = img?.style.transformOrigin || '0 0';\n }\n\n /** Each slide gets a freshly-created `<img>` (SlideManager never reuses elements across renders), so the cursor-affordance marker (`zoom.css`) needs reapplying every time the active media changes, not just once. */\n function markEnabled(): void {\n getImg()?.classList.add('shoji-zoom-enabled');\n }\n\n function toggleZoom(x: number, y: number): void {\n if (scale > ZOOM_EPSILON) reset(true);\n else zoomTo(doubleTapScale, x, y, maxScale, true);\n }\n\n // --- pinch (relayed by core, §2.4 — no built-in effect until this plugin exists) ---\n const offPinchStart = ctx.on('pinchStart', () => {\n pinchStartScale = scale;\n });\n const offPinchMove = ctx.on('pinchMove', ({ scale: relative, centerX, centerY }) => {\n zoomTo(pinchStartScale * relative, centerX, centerY);\n });\n const offPinchEnd = ctx.on('pinchEnd', () => {\n if (scale <= ZOOM_EPSILON) reset(); // snap fully back to neutral rather than leaving float residue\n });\n\n // --- double-tap / double-click (relayed by core; Pointer Events unify the two, see GestureEngine) ---\n const offDoubleTap = ctx.on('doubleTap', ({ x, y }) => toggleZoom(x, y));\n\n // --- ctrl+wheel / trackpad pinch (relayed by core) ---\n const offWheelZoom = ctx.on('wheelZoom', ({ deltaScale, x, y }) => {\n zoomTo(scale + deltaScale, x, y);\n });\n\n /**\n * A generic command surface, requested directly (DESIGN.md §4.6), so a\n * *custom* (host-authored) plugin's own button can drive zoom without\n * importing this plugin at all — same \"events over inheritance\"\n * decoupling `pinchStart`/`doubleTap`/`wheelZoom` above already use,\n * just in the opposite direction (a command in, not a gesture relay).\n * `GalleryEvents` (`core/types.ts`) already extends `Record<string,\n * unknown>`, so `ctx.emit('requestZoomIn', {})` from any plugin —\n * official or custom — type-checks with zero core changes; this is\n * just the listening half. Each mirrors its real toolbar button\n * exactly — same functions, same behavior on a video slide (a no-op,\n * `zoomInStep`/`zoomOutStep`/`actualSizeToggle` all bail via `getImg()`\n * returning null there).\n */\n const offRequestZoomIn = ctx.on('requestZoomIn', zoomInStep);\n const offRequestZoomOut = ctx.on('requestZoomOut', zoomOutStep);\n const offRequestZoomActualSize = ctx.on('requestZoomActualSize', actualSizeToggle);\n const offRequestZoomReset = ctx.on('requestZoomReset', () => reset(true));\n\n // --- pan while zoomed — the one gesture core's relay doesn't cover; see the plugin doc comment for why this can't reuse GestureEngine. ---\n let panPointerId: number | null = null;\n let lastX = 0;\n let lastY = 0;\n const outer = ctx.ui.outer();\n\n function onPointerDown(event: PointerEvent): void {\n if (scale <= ZOOM_EPSILON || isRealControl(event)) return;\n const img = getImg();\n // A real bug, reported from real usage: this listens on `outer` (the\n // whole lightbox, not just the image) so a fast pan can be tracked\n // even once the pointer leaves the image's own bounds — but with no\n // check on where the pointerdown itself landed, a click on the plain\n // backdrop (between the image and a nav arrow, say) engaged pan and\n // captured the pointer onto `img` regardless, which — see below —\n // retargets the click and makes it misread as \"on the image,\" not\n // backdrop, silently defeating click-to-close while zoomed.\n if (!img || !event.composedPath().includes(img)) return;\n panPointerId = event.pointerId;\n lastX = event.clientX;\n lastY = event.clientY;\n // Without this, a fast pan whose pointer exits `outer`'s bounds\n // stops receiving pointermove/pointerup entirely (no capture = only\n // elements actually under the cursor get events), leaving\n // panPointerId stuck non-null until the next pointerdown — the\n // gesture just goes dead mid-drag. Captured on the `<img>` itself,\n // not `outer`: capturing retargets the subsequent synthetic `click`\n // to whatever captured it, and `img` — unlike `outer` — already\n // matches isBackdropClick's own exclusion selector (Gallery.ts), so\n // a captured pan's release still can't misread as a backdrop click.\n // GestureEngine's own capture needs a separate suppressRetargetedClick\n // step for exactly this reason; this doesn't, since the retarget\n // lands somewhere already excluded.\n img.setPointerCapture(event.pointerId);\n }\n function onPointerMove(event: PointerEvent): void {\n if (panPointerId !== event.pointerId || !natural || !container || !originOffset) return;\n event.preventDefault();\n const rawDx = event.clientX - lastX;\n const rawDy = event.clientY - lastY;\n lastX = event.clientX;\n lastY = event.clientY;\n // DESIGN.md §4.6 — screenDeltaToLocal's own doc comment has the full\n // reasoning: the raw pointer delta is screen space, but pan.tx/ty are\n // local to the <img>, nested inside whatever transform (e.g.\n // RotateFlip's rotation) `.shoji-slide-media` currently has.\n const media = gallery.getActiveMedia();\n const m = parseLinearTransform(media ? getComputedStyle(media).transform : 'none');\n const { tx: dx, ty: dy } = screenDeltaToLocal(rawDx, rawDy, m);\n pan = clampPan(\n natural,\n container,\n scale,\n { tx: pan.tx + dx, ty: pan.ty + dy },\n m,\n originOffset,\n );\n apply();\n }\n function onPointerUp(event: PointerEvent): void {\n if (panPointerId === event.pointerId) panPointerId = null;\n }\n\n outer.addEventListener('pointerdown', onPointerDown);\n outer.addEventListener('pointermove', onPointerMove, { passive: false });\n outer.addEventListener('pointerup', onPointerUp);\n outer.addEventListener('pointercancel', onPointerUp);\n\n // --- toolbar buttons ---\n function buildButton(icon: string, label: string): HTMLButtonElement {\n const button = document.createElement('button');\n button.type = 'button';\n button.className = 'shoji-toolbar-button';\n button.innerHTML = icon;\n button.setAttribute('aria-label', label);\n button.title = label;\n return button;\n }\n\n function centerAnchor(): { x: number; y: number } {\n const media = gallery.getActiveMedia();\n const rect = media?.getBoundingClientRect();\n return rect\n ? { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }\n : { x: 0, y: 0 };\n }\n\n /** Shared by the zoom-in toolbar button and the `w` keyboard shortcut — same fixed `buttonStep` multiplier either way. */\n function zoomInStep(): void {\n const { x, y } = centerAnchor();\n zoomTo(scale * buttonStep, x, y, maxScale, true);\n }\n\n /** Shared by the zoom-out toolbar button and the `s` keyboard shortcut. */\n function zoomOutStep(): void {\n const { x, y } = centerAnchor();\n if (scale / buttonStep <= ZOOM_EPSILON) reset(true);\n else zoomTo(scale / buttonStep, x, y, maxScale, true);\n }\n\n /** Shared by the actual-size toolbar button and `requestZoomActualSize` below. Reads natural.width directly (unlike every other entry point, which just hands zoomTo a target and lets it call ensureNatural itself) — needs its own whenSettled wrap for that reason, not just zoomTo's. */\n function actualSizeToggle(): void {\n whenSettled(() => {\n const img = getImg();\n if (!img || !img.naturalWidth) return;\n if (!ensureNatural(img)) return;\n if (scale > ZOOM_EPSILON) {\n reset(true);\n return;\n }\n const targetScale = img.naturalWidth / natural!.width;\n const { x, y } = centerAnchor();\n zoomTo(targetScale, x, y, targetScale, true); // ceiling = targetScale — bypasses maxScale deliberately\n });\n }\n\n const zoomInBtn = buildButton(ZOOM_IN_ICON, zoomInLabel);\n const zoomOutBtn = buildButton(ZOOM_OUT_ICON, zoomOutLabel);\n const actualSizeBtn = buildButton(ZOOM_ACTUAL_SIZE_ICON, actualSizeLabel);\n\n zoomInBtn.addEventListener('click', zoomInStep);\n zoomOutBtn.addEventListener('click', zoomOutStep);\n actualSizeBtn.addEventListener('click', actualSizeToggle);\n\n // 'right' — registered in this order, so they cluster left-to-right as\n // zoomIn, zoomOut, actualSize, then whatever later plugin (or the close\n // button) follows (DESIGN.md §3.1).\n const removeButtons = [zoomInBtn, zoomOutBtn, actualSizeBtn].map((button) =>\n ctx.ui.toolbar('right', button),\n );\n\n /** All three zoom buttons are no-ops on a video slide — `getImg()` returns null, so `apply()`/`ensureNatural()` bail out immediately. Hidden rather than left clickable-but-dead. */\n function updateButtonVisibility(): void {\n const isVideo = !!gallery.items[gallery.currentIndex]?.video;\n zoomInBtn.hidden = isVideo;\n zoomOutBtn.hidden = isVideo;\n actualSizeBtn.hidden = isVideo;\n }\n\n // w/s zoom in/out, same step as the toolbar buttons — both cases\n // registered explicitly (registerShortcut matches event.key verbatim,\n // no case-insensitive matching of its own) so Shift/CapsLock still work.\n const removeShortcuts = [\n ctx.ui.registerShortcut('w', zoomInStep),\n ctx.ui.registerShortcut('W', zoomInStep),\n ctx.ui.registerShortcut('s', zoomOutStep),\n ctx.ui.registerShortcut('S', zoomOutStep),\n ];\n\n const offOpen = ctx.on('afterOpen', () => {\n reset();\n markEnabled();\n updateButtonVisibility();\n });\n // Un-animated, and on beforeSlide rather than only afterSlide below:\n // SlideManager.render() (called synchronously between the two) reuses a\n // still-cached slide's node via a plain reparent (moveIn(), no state\n // clearing of its own) into whichever pool slot its new offset needs —\n // there is no code path afterward that can still find *this* image to\n // reset it. A real bug, reported from real usage: zoom in via \"Actual\n // size\", click next — the old, still-scaled image, now reparented into\n // the (unclipped, per shoji.css) neighboring slot, visibly bled into the\n // new slide instead of being invisible off-screen like an unzoomed one\n // always is. Resetting here, while getActiveMedia() still resolves to\n // the about-to-move image, clears it before that reparent ever happens.\n // captureLeaveTransform() (see registerSlideLeaveDecorator below) reads\n // the live transform first, while it's still there to read.\n const offBeforeSlide = ctx.on('beforeSlide', () => {\n captureLeaveTransform();\n reset();\n });\n const offSlide = ctx.on('afterSlide', () => {\n reset();\n markEnabled();\n updateButtonVisibility();\n });\n // Fires synchronously, before Gallery.close() measures the active\n // media's rect to compute the zoom-out-to-thumbnail animation — reset\n // here (not just afterOpen/afterSlide) so that measurement sees the\n // image at its natural position/scale, not wherever it was left\n // zoomed/panned to. Skipping this made closing while zoomed animate\n // from the image's current (zoomed, often partly off-screen) rect\n // instead of its real thumbnail-relative size, landing \"closed\" at a\n // seemingly random spot instead of visibly shrinking into the thumbnail.\n const offBeforeClose = ctx.on('beforeClose', () => reset());\n const unregisterGate = gallery.registerZoomGate(() => scale > ZOOM_EPSILON);\n // Read by Gallery.beginClose() *before* the beforeClose reset above\n // runs, so a button-close continues the zoom-out from wherever the\n // viewer was actually zoomed/panned to, instead of the reset above\n // making it (correctly, for the measurement) but also making the\n // close itself snap back to neutral first. The image's own real\n // rendered rect, not this plugin's raw scale/pan numbers — see\n // zoomTransition.ts's ZoomTransitionTarget.zoomStart for why a direct\n // scale/pan replay doesn't work once it lands on a different element.\n const unregisterZoomStart = gallery.registerZoomStartProvider(() =>\n scale > ZOOM_EPSILON ? (getImg()?.getBoundingClientRect() ?? null) : null,\n );\n const unregisterLeaveDecorator = gallery.registerSlideLeaveDecorator((clonedMedia) => {\n if (!pendingLeaveTransform) return;\n const transform = pendingLeaveTransform;\n const origin = pendingLeaveOrigin;\n pendingLeaveTransform = null;\n const clonedImg = clonedMedia.querySelector<HTMLImageElement>('img');\n if (!clonedImg) return;\n clonedImg.style.transformOrigin = origin;\n clonedImg.style.transform = transform;\n return () => {\n clonedImg.style.transition = 'transform var(--shoji-duration) var(--shoji-easing)';\n clonedImg.style.transform = 'none';\n };\n });\n markEnabled(); // covers the (unusual but possible) case of the gallery already being open when this plugin initializes\n updateButtonVisibility();\n\n return () => {\n for (const remove of removeButtons) remove();\n for (const remove of removeShortcuts) remove();\n offOpen();\n offBeforeSlide();\n offSlide();\n offBeforeClose();\n offPinchStart();\n offPinchMove();\n offPinchEnd();\n offDoubleTap();\n offWheelZoom();\n offRequestZoomIn();\n offRequestZoomOut();\n offRequestZoomActualSize();\n offRequestZoomReset();\n outer.removeEventListener('pointerdown', onPointerDown);\n outer.removeEventListener('pointermove', onPointerMove);\n outer.removeEventListener('pointerup', onPointerUp);\n outer.removeEventListener('pointercancel', onPointerUp);\n unregisterGate();\n unregisterZoomStart();\n unregisterLeaveDecorator();\n reset();\n getImg()?.classList.remove('shoji-zoom-enabled');\n };\n },\n};\n"],"names":["parseCssTime","value","first","_a","waitForTransitionEnd","target","cb","property","durationMs","done","finish","onEnd","event","ZOOM_IN_ICON","ZOOM_OUT_ICON","ZOOM_ACTUAL_SIZE_ICON","clampScale","scale","min","max","IDENTITY_TRANSFORM","parseLinearTransform","transform","match","screenDeltaToLocal","dx","dy","m","det","localDeltaToScreen","trueOriginOffset","natural","localOriginScreen","pan","originOffset","pivotX","pivotY","fromPivot","clampEdge","contentPos","contentSize","containerPos","containerSize","minPos","contentScreenBounds","trueWidth","trueHeight","screenCorners","x","y","wrapperFrame","screen","xs","p","ys","clampPan","container","bounds","clampedLeft","clampedTop","screenDelta","localDelta","zoomTowardPoint","oldScale","newScale","anchorX","anchorY","origin","screenDx","screenDy","local","factor","ZOOM_EPSILON","isRealControl","node","ctx","gallery","maxScale","doubleTapScale","buttonStep","locale","zoomInLabel","zoomOutLabel","actualSizeLabel","pinchStartScale","getImg","media","child","boxOf","el","rect","ensureNatural","img","whenSettled","action","apply","emitChange","withTransition","run","afterEnd","zoomTo","targetScale","ceiling","animate","clampedScale","parentTransform","reset","wasEngaged","clearTransform","pendingLeaveTransform","pendingLeaveOrigin","captureLeaveTransform","markEnabled","toggleZoom","offPinchStart","offPinchMove","relative","centerX","centerY","offPinchEnd","offDoubleTap","offWheelZoom","deltaScale","offRequestZoomIn","zoomInStep","offRequestZoomOut","zoomOutStep","offRequestZoomActualSize","actualSizeToggle","offRequestZoomReset","panPointerId","lastX","lastY","outer","onPointerDown","onPointerMove","rawDx","rawDy","onPointerUp","buildButton","icon","label","button","centerAnchor","zoomInBtn","zoomOutBtn","actualSizeBtn","removeButtons","updateButtonVisibility","isVideo","removeShortcuts","offOpen","offBeforeSlide","offSlide","offBeforeClose","unregisterGate","unregisterZoomStart","unregisterLeaveDecorator","clonedMedia","clonedImg","remove"],"mappings":"gPAsEA,SAASA,EAAaC,EAAuB,OAC3C,MAAMC,IAAQC,EAAAF,EAAM,MAAM,GAAG,EAAE,CAAC,IAAlB,YAAAE,EAAqB,SAAU,GAC7C,OAAID,EAAM,SAAS,IAAI,EAAU,WAAWA,CAAK,EAC7CA,EAAM,SAAS,GAAG,EAAU,WAAWA,CAAK,EAAI,IAC7C,CACT,CA8KO,SAASE,EACdC,EACAC,EACAC,EAAW,YACL,CACN,MAAMC,EAAaR,EAAa,iBAAiBK,CAAM,EAAE,kBAAkB,EAC3E,IAAII,EAAO,GACX,MAAMC,EAAS,IAAY,CACrBD,IACJA,EAAO,GACPJ,EAAO,oBAAoB,gBAAiBM,CAAK,EACjDL,EAAA,EACF,EACMK,EAASC,GAAuB,CAChCA,EAAM,SAAWP,GAAWO,EAA0B,eAAiBL,GAAUG,EAAA,CACvF,EACAL,EAAO,iBAAiB,gBAAiBM,CAAK,EAC9C,WAAWD,EAAQF,EAAa,GAAG,CACrC,CC1QO,MAAMK,GACX,mOAEWC,GACX,4NAEWC,GACX,+OCKK,SAASC,GAAWC,EAAeC,EAAaC,EAAqB,CAC1E,OAAO,KAAK,IAAIA,EAAK,KAAK,IAAID,EAAKD,CAAK,CAAC,CAC3C,CAWO,MAAMG,EAAsC,CAAE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ACpF,GAAI,CAACjD,EAAuB,OAC5B,MAAMvF,EAAYuF,EACZ1C,EAAS2C,GACfD,EAAwB,KACxB,MAAMkD,EAAYD,EAAY,cAAgC,KAAK,EACnE,GAAKC,EACL,OAAAA,EAAU,MAAM,gBAAkB5F,EAClC4F,EAAU,MAAM,UAAYzI,EACrB,IAAM,CACXyI,EAAU,MAAM,WAAa,sDAC7BA,EAAU,MAAM,UAAY,MAC9B,CACF,CAAC,EACD,OAAA/C,EAAA,EACAoC,EAAA,EAEO,IAAM,OACX,UAAWY,KAAUb,GAAea,EAAA,EACpC,UAAWA,KAAUV,GAAiBU,EAAA,EACtCT,GAAA,EACAC,GAAA,EACAC,GAAA,EACAC,GAAA,EACAxC,GAAA,EACAC,GAAA,EACAI,GAAA,EACAC,GAAA,EACAC,GAAA,EACAE,GAAA,EACAE,GAAA,EACAE,GAAA,EACAE,GAAA,EACAI,EAAM,oBAAoB,cAAeC,EAAa,EACtDD,EAAM,oBAAoB,cAAeE,EAAa,EACtDF,EAAM,oBAAoB,YAAaK,CAAW,EAClDL,EAAM,oBAAoB,gBAAiBK,CAAW,EACtDiB,GAAA,EACAC,GAAA,EACAC,GAAA,EACAnD,EAAA,GACAvG,EAAAkF,MAAA,MAAAlF,EAAU,UAAU,OAAO,qBAC7B,CACF,CACF"}
|
|
1
|
+
{"version":3,"file":"zoom.min.js","sources":["../../src/core/iconSwap.ts","../../src/core/zoomTransition.ts","../../src/plugins/zoom/icons.ts","../../src/plugins/zoom/zoomMath.ts","../../src/plugins/zoom/index.ts"],"sourcesContent":["/**\n * DESIGN.md §9 — a toolbar button whose icon reflects live state (Fullscreen's\n * enter/exit, Autoplay's play/pause, Zoom's actual-size expand/contract) used\n * to just replace `button.innerHTML` outright — an instant cut, no\n * transition, and each plugin reimplementing the same two-icon swap\n * independently. Requested directly: make every one of these a smooth\n * cross-fade, and make them all go through one shared mechanism rather than\n * three slightly different ones. Both icons are always in the DOM at once,\n * stacked via `position: absolute` inside a fixed-size wrapper\n * (`.shoji-icon-swap`, `shoji.css`) — swapping is just toggling which one is\n * `opacity: 1` via a single modifier class, so there's nothing to actually\n * replace, no risk of a flash-of-no-icon between the old node being removed\n * and the new one's fill/stroke painting in.\n */\nexport interface IconSwap {\n /** Append this into the button — it *is* the button's visible icon content. */\n el: HTMLSpanElement;\n /** `false` shows `iconOff`, `true` shows `iconOn` — cross-fades between them via CSS, respecting `prefers-reduced-motion` the same way every other transition in this codebase does (shoji.css zeroes `--shoji-icon-swap-duration` there). */\n setState(on: boolean): void;\n}\n\nexport function createIconSwap(iconOff: string, iconOn: string): IconSwap {\n const el = document.createElement('span');\n el.className = 'shoji-icon-swap';\n\n const off = document.createElement('span');\n off.className = 'shoji-icon-swap-icon shoji-icon-swap-icon--off';\n off.innerHTML = iconOff;\n\n const on = document.createElement('span');\n on.className = 'shoji-icon-swap-icon shoji-icon-swap-icon--on';\n on.innerHTML = iconOn;\n\n el.append(off, on);\n\n return {\n el,\n setState(state: boolean): void {\n el.classList.toggle('shoji-icon-swap--on', state);\n },\n };\n}\n","/** The drag's exact on-screen appearance at the moment it completed a close — `translateY(px)`/`scale`/`opacity`, all as last shown live (translateY clamped, see `GestureController.takeFrozenDragTransform`). `zoomOut()` jumps `target` here instantly (after measuring its natural box — see `ZoomTransitionTarget.dragStart`) before transitioning away from it, so the close continues in one motion from exactly where the drag left off. */\nexport interface FrozenDragTransform {\n translateY: number;\n scale: number;\n opacity: number;\n}\n\nexport interface ZoomTransitionTarget {\n /** The thumbnail element to animate to/from. */\n origin: HTMLElement;\n /** The `.shoji-slide-media` element being animated — not `.shoji-slide` itself, whose transform is already owned by pool-offset positioning. */\n target: HTMLElement;\n /** `item.width / item.height`, when known, else the origin thumbnail's own `naturalWidth`/`naturalHeight` ratio — just a *shape* guess; see `effectiveTargetBox`. */\n aspectRatio?: number;\n /** The real photo's true pixel size — `item.width`/`item.height` only, never the thumbnail's own natural size (would under-cap a large photo). Caps `containedBox` below at native resolution, mirroring `.shoji-slide-img`'s own `max-width/max-height: 100%`, instead of always growing toward filling the dialog. */\n naturalSize?: { width: number; height: number };\n /**\n * A completed drag-close's own last appearance (`GestureController.\n * takeFrozenDragTransform`) — `zoomOut()` (the only consumer) jumps\n * `target` here instantly, *after* measuring its natural box for the\n * landing math, then transitions away from it. Order matters: applying\n * this before measuring would make `effectiveTargetBox()` read the\n * child `<img>`'s rect *already* shrunk by this scale, double-counting\n * it once `zoomOut()`'s own transform (computed from that shrunk\n * measurement) then wholesale replaces — not composes with — it.\n */\n dragStart?: FrozenDragTransform;\n /**\n * The zoomed `<img>`'s own real on-screen rect (`getBoundingClientRect()`)\n * at the moment a button-close (or any non-drag close) starts, if it's\n * currently zoomed in — captured by `Gallery.beginClose()` from\n * `registerZoomStartProvider()` *before* the Zoom plugin's own\n * `beforeClose` handler resets it back to neutral (so `zoomOut()`'s own\n * measurement below stays correct — same ordering requirement `dragStart`\n * has, and the same reason).\n *\n * A rect, not the Zoom plugin's raw scale/pan numbers — an earlier version\n * passed those through directly and re-applied them to `target`\n * (`.shoji-slide-media`) the same way `dragStart` reapplies its own\n * translateY/scale. That doesn't work here: Zoom's own pan math is\n * relative to the `<img>` itself with `transform-origin: 0 0`\n * (`zoom/index.ts`), a *different* element with a *different* origin than\n * `target`'s `transform-origin: center` below — reapplying the same\n * numbers onto the wrong element/origin pair visibly shifted the image\n * toward its top-left corner the instant close started, worse the more\n * zoomed in it was. A rect sidesteps this entirely: `zoomOut()` computes\n * the jump the same center-to-center way it computes everything else\n * (`transformBetween`), from `target`'s own freshly-measured natural box\n * to this rect — origin-and-coordinate-system-agnostic, so it doesn't\n * matter what internal convention produced the rect.\n *\n * `zoomOut()` jumps `target` here instantly, then transitions away from\n * it, so closing while zoomed continues in one motion from the zoomed-in\n * view instead of snapping back to neutral first and only then shrinking\n * to the thumbnail. Mutually exclusive with `dragStart` in practice — you\n * can't complete a vertical drag-close while the zoom plugin is also\n * mid-pan, since `GestureController` suspends its own drag handling\n * entirely while zoomed (`isZoomed()`, DESIGN.md §4.6).\n */\n zoomStart?: Box;\n}\n\nfunction prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === 'function' &&\n window.matchMedia('(prefers-reduced-motion: reduce)').matches\n );\n}\n\n/** `\"300ms\"` / `\"0.3s\"` → milliseconds. Reads the *actual* computed value, not an assumed default, so a host overriding `--shoji-duration` still gets a correct fallback timeout below. */\nfunction parseCssTime(value: string): number {\n const first = value.split(',')[0]?.trim() ?? '';\n if (first.endsWith('ms')) return parseFloat(first);\n if (first.endsWith('s')) return parseFloat(first) * 1000;\n return 0;\n}\n\nexport interface Box {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\n/** The `object-fit: contain` box for `aspectRatio` within `container`, computed analytically since the real image may not be loaded yet. `naturalSize` caps the result at the photo's own true pixel size, never stretching past native resolution. Exported — `SlideManager.ts`'s open-transition placeholder (§2.3) reuses this same math. */\nexport function containedBox(\n container: Box,\n aspectRatio: number,\n naturalSize?: { width: number; height: number },\n): Box {\n const containerRatio = container.width / container.height;\n let width = aspectRatio > containerRatio ? container.width : container.height * aspectRatio;\n let height = aspectRatio > containerRatio ? container.width / aspectRatio : container.height;\n if (naturalSize && naturalSize.width > 0 && naturalSize.height > 0) {\n const cap = Math.min(1, naturalSize.width / width, naturalSize.height / height);\n width *= cap;\n height *= cap;\n }\n return {\n left: container.left + (container.width - width) / 2,\n top: container.top + (container.height - height) / 2,\n width,\n height,\n };\n}\n\n/**\n * `target`'s effective visual box, not necessarily its own\n * `getBoundingClientRect()`. `target` is always its full flex-box size; the\n * photo inside is usually *smaller*, letterboxed to its own aspect ratio —\n * a real bug used the container's full rect, making the animation scale\n * from/to a box far bigger than the photo ever renders at, visibly\n * shrinking it to something much smaller than the thumbnail whenever the\n * aspect ratios didn't match (the common case). Preferred sources: the real\n * rendered media child, if attached; else an analytical contain-box from\n * `aspectRatio`; else the container's own rect as a last resort.\n *\n * A real bug this guards against: on a fresh open with nothing decoded yet,\n * `target`'s only child at this point is the loading spinner (§2.3) — a\n * fixed ~40px circle, not the photo. Trusting its rect as \"the real\n * rendered media child\" made the FLIP transition scale toward/from a box\n * far smaller than the actual photo, so the scale factor came out inverted\n * (>1 instead of <1) and the spinner rendered wildly oversized for the\n * transition's first frames before shrinking back down — never the actual\n * photo, which hadn't swapped in yet either way.\n *\n * Same reasoning excludes `.shoji-slide-open-placeholder` (§2.3's low-res\n * open() stand-in): it's a real, non-spinner `<img>`, but its own rendered\n * rect reflects *its* crop/aspect ratio, not the real photo's — trusting it\n * would scale toward the placeholder's shape instead of the real photo's,\n * only to visibly jump again once the real photo swaps in and this\n * transition (already run) no longer applies. Excluding it falls through to\n * the analytical `aspectRatio`-based box below, sized for the real photo\n * regardless of what shape the placeholder happens to be.\n */\nfunction effectiveTargetBox(\n target: HTMLElement,\n aspectRatio?: number,\n naturalSize?: { width: number; height: number },\n): Box {\n const child = target.firstElementChild;\n const isPlaceholder =\n child instanceof HTMLElement &&\n (child.classList.contains('shoji-slide-spinner') ||\n child.classList.contains('shoji-slide-open-placeholder'));\n if (child instanceof HTMLElement && !isPlaceholder) {\n const rect = child.getBoundingClientRect();\n if (rect.width > 0 && rect.height > 0) return rect;\n }\n const containerRect = target.getBoundingClientRect();\n if (aspectRatio && containerRect.width > 0 && containerRect.height > 0) {\n return containedBox(containerRect, aspectRatio, naturalSize);\n }\n return containerRect;\n}\n\n/**\n * Center-to-center translate + a single uniform scale that lands `target`'s\n * effective box (`effectiveTargetBox` above) *within* `origin`'s box,\n * without distorting it. `null` if either has no real size — nothing sane\n * to animate. One scale factor, not independent scaleX/scaleY: origin and\n * the photo essentially never share an exact aspect ratio, and scaling each\n * axis independently to force a rect match visibly squeezes/stretches the\n * image. `Math.min` keeps the box fully contained within origin's rect\n * (same tradeoff `object-fit: contain` makes); center always lands exactly\n * on origin's center, only the unconstrained axis's edges fall short.\n */\n/**\n * The actual translate3d/scale3d math `computeTransform` below needs —\n * pulled out on its own so `zoomOut`'s `zoomStart` jump (a *second* use of\n * the exact same center-to-center box-fitting math, landing on a captured\n * live rect instead of `origin`'s) can reuse it directly, rather than\n * re-deriving Zoom's own transform-origin/coordinate conventions on a\n * different element — see `ZoomTransitionTarget.zoomStart`'s own doc\n * comment for why that direct-replication approach doesn't work.\n */\nfunction transformBetween(from: Box, to: Box): string {\n const scale = Math.min(to.width / from.width, to.height / from.height);\n const translateX = to.left + to.width / 2 - (from.left + from.width / 2);\n const translateY = to.top + to.height / 2 - (from.top + from.height / 2);\n // translate3d/scale3d, not translate()/scale() — forces the GPU\n // compositing path instead of a main-thread-painted 2D transform, the\n // same fix already validated for the Zoom plugin's own scale animation\n // (DESIGN.md §4.6): this is the identical technique (a large photo\n // scaled via `transform`) on the same element, just driven by open/close\n // instead of pinch/toolbar zoom.\n return `translate3d(${translateX}px, ${translateY}px, 0) scale3d(${scale}, ${scale}, 1)`;\n}\n\n/**\n * `origin`'s effective visual box, not necessarily its own\n * `getBoundingClientRect()`. In selector/DOM-markup mode without Layout,\n * `origin` is typically a plain `<a>` wrapping a `<img>` — an inline element\n * by default, whose own box is sized to a text-line-height sliver (its\n * `font-size`/`line-height`), not the image it visually contains, even\n * though the image itself paints at full size. A real bug: the zoom\n * open/close transform used that sliver directly as the FLIP target,\n * landing the animation at a tiny, essentially-random offset instead of the\n * real thumbnail's visible position and size. Layout tiles aren't affected\n * (`display: block`, sized to match their child image exactly) — preferring\n * the child's rect there returns the same box either way.\n *\n * `querySelector('img')`, not `firstElementChild` — matches `scan.ts`'s own\n * `scanImage()` convention for locating a thumbnail inside arbitrary host\n * markup, where the `<img>` isn't necessarily the first child (a badge or\n * caption element placed before it in the DOM would otherwise get measured\n * instead, no more correct than the wrapper's own sliver).\n */\nfunction effectiveOriginBox(origin: HTMLElement): Box {\n const img = origin.querySelector('img');\n if (img) {\n const rect = img.getBoundingClientRect();\n if (rect.width > 0 && rect.height > 0) return rect;\n }\n return origin.getBoundingClientRect();\n}\n\nfunction computeTransform(\n origin: HTMLElement,\n target: HTMLElement,\n aspectRatio?: number,\n naturalSize?: { width: number; height: number },\n): string | null {\n const originRect = effectiveOriginBox(origin);\n const targetRect = effectiveTargetBox(target, aspectRatio, naturalSize);\n if (\n targetRect.width === 0 ||\n targetRect.height === 0 ||\n originRect.width === 0 ||\n originRect.height === 0\n ) {\n return null;\n }\n return transformBetween(targetRect, originRect);\n}\n\n/**\n * Waits for `target`'s own transition (on `property`, default `'transform'`)\n * to end (with a safety-net timeout in case transitionend never fires — an\n * interrupted/removed element, a browser quirk, or `--shoji-duration: 0ms`\n * under `prefers-reduced-motion`, which some browsers never fire a real\n * transitionend for at all) then calls `cb` exactly once. Exported: the\n * gesture-driven drag-to-navigate/drag-to-close settle animations (§2.4,\n * `Gallery.ts`) reuse this same wait-with-fallback logic rather than\n * duplicating it — same instant-jump-then-transition FLIP family of moves\n * as the zoom transition, just on a different element/property pairing.\n * `close()`'s own controls-fade-before-zoom-out sequencing (§2.6a) reuses it\n * a second way, waiting on `opacity` instead.\n */\nexport function waitForTransitionEnd(\n target: HTMLElement,\n cb: () => void,\n property = 'transform',\n): void {\n const durationMs = parseCssTime(getComputedStyle(target).transitionDuration);\n let done = false;\n const finish = (): void => {\n if (done) return;\n done = true;\n target.removeEventListener('transitionend', onEnd);\n cb();\n };\n const onEnd = (event: Event): void => {\n if (event.target === target && (event as TransitionEvent).propertyName === property) finish();\n };\n target.addEventListener('transitionend', onEnd);\n setTimeout(finish, durationMs + 100);\n}\n\n/**\n * A real bug: unconditionally clearing `transform` here could wipe out a\n * value another plugin (rotateFlip) legitimately set on the *same* element\n * in the time between this animation starting and its cleanup callback\n * firing (transitionend, or the fallback timeout — either can land well\n * after a quick click elsewhere). Only clears `transform` if it still\n * matches what this animation itself last wrote — nothing else has touched\n * it since — otherwise leaves it alone. `transition`/`transformOrigin`\n * are always safe to clear; nothing else in this codebase sets them.\n *\n * A second real bug, found via reopening the lightbox: `expectedTransform`\n * must be the value *read back* from `target.style.transform` right after\n * assigning it, not the raw string `computeTransform()` produced. Setting\n * `element.style.transform` to a string containing an arbitrary JS float\n * (e.g. `scale(0.10416666666666667)`, `computeTransform`'s un-rounded\n * `Math.min(...)` result) and reading it back gives a *differently\n * formatted* string — the browser's CSSOM serializer rounds/reformats\n * numeric values on its own (observed in Chromium: `scale(0.104167)`).\n * Comparing the raw JS string against that reformatted one here always\n * failed for any scale factor without a short, clean decimal, silently\n * skipping the clear — permanently leaving `zoomOut`'s shrink transform\n * applied to `.shoji-slide-media` after the lightbox closed. The next\n * `open()`'s `computeTransform` then measured that *already-shrunk*\n * element's `getBoundingClientRect()` as if it were the natural size,\n * computing a near-1 (barely visible) scale instead of a real zoom-in —\n * reads as \"doesn't zoom, just appears,\" and compounds on every further\n * open/close cycle since the stuck transform is never cleared either way.\n * `zoomIn`'s own `'none'` literal never hit this — a fixed string round-trips\n * through the CSSOM unchanged, unlike an arbitrary computed float.\n *\n * `opacity` is cleared unconditionally, same as `transition`/\n * `transformOrigin` — a completed drag-close (`Gallery.beginClose`) bakes\n * the drag's own dim onto `target` before this animation starts; nothing\n * else in this codebase sets `.shoji-slide-media`'s opacity, so there's\n * nothing else's value this could ever clobber.\n */\nfunction clearInlineTransform(target: HTMLElement, expectedTransform: string): void {\n target.style.transition = '';\n target.style.transformOrigin = '';\n target.style.willChange = '';\n target.style.opacity = '';\n if (target.style.transform === expectedTransform) target.style.transform = '';\n}\n\n/**\n * FLIP-style open: `target` starts visually at `origin`'s position/size (an\n * instant, untransitioned jump), then transitions to its natural layout —\n * reads as \"growing out of the thumbnail.\" Fire-and-forget: cleans up its\n * own inline styles once the transition ends, nothing to await.\n */\nexport function zoomIn({ origin, target, aspectRatio, naturalSize }: ZoomTransitionTarget): void {\n if (prefersReducedMotion()) return;\n const transform = computeTransform(origin, target, aspectRatio, naturalSize);\n if (!transform) return;\n\n target.style.transition = 'none';\n // computeTransform's translateX/Y is center-to-center math — must pair with\n // a center transform-origin (the CSS default), not 'top left', or the\n // scaled box ends up offset from origin by however far origin's center\n // sits from its own top-left corner.\n target.style.transformOrigin = 'center';\n // Promotes target onto its own compositing layer before the animated\n // transform starts, not mid-animation — same GPU-seam mitigation as the\n // Zoom plugin (DESIGN.md §4.6). Cleared in clearInlineTransform once the\n // transition ends, not left on permanently: this is the offset-0 pool\n // slot, alive for the gallery's whole lifetime, not a class scoped to\n // only-while-zoomed.\n target.style.willChange = 'transform';\n target.style.transform = transform;\n void target.offsetHeight; // force the instant jump to commit before transitioning away from it\n target.style.transition = 'transform var(--shoji-duration) var(--shoji-easing)';\n target.style.transform = 'none';\n\n waitForTransitionEnd(target, () => clearInlineTransform(target, 'none'));\n}\n\n/**\n * Reverse of `zoomIn`: `target` transitions from its natural position down\n * to `origin`'s rect — \"shrinking back into the thumbnail.\" `onComplete`\n * always fires exactly once, synchronously if there's nothing to animate\n * (reduced motion, or no valid rect), otherwise once the transition ends —\n * callers use this to know when it's safe to actually hide/finalize.\n */\nexport function zoomOut(\n { origin, target, aspectRatio, naturalSize, dragStart, zoomStart }: ZoomTransitionTarget,\n onComplete: () => void,\n): void {\n if (prefersReducedMotion()) {\n onComplete();\n return;\n }\n // Measured before dragStart/zoomStart is ever applied to `target` — see\n // ZoomTransitionTarget.dragStart's doc comment for why the order matters.\n const transform = computeTransform(origin, target, aspectRatio, naturalSize);\n if (!transform) {\n onComplete();\n return;\n }\n\n // computeTransform's translateX/Y is center-to-center math — must pair with\n // a center transform-origin (the CSS default), not 'top left', or the\n // scaled box ends up offset from origin by however far origin's center\n // sits from its own top-left corner.\n target.style.transformOrigin = 'center';\n target.style.willChange = 'transform'; // see zoomIn's doc comment on this line\n if (dragStart) {\n // Instant jump to exactly where the drag left off — same FLIP\n // technique `zoomIn()` uses to jump onto origin's box before\n // transitioning away from it, just jumping to wherever the drag left\n // off instead of a fixed point. translate3d/scale3d (not the 2D forms),\n // matching the landing transform's own function list below — mismatched\n // function types between the transition's start/end values force the\n // browser into matrix-decomposition interpolation instead of simple\n // per-parameter interpolation, and lose the GPU-compositing path this\n // codebase otherwise always uses for this element (DESIGN.md §2.3b).\n target.style.transition = 'none';\n target.style.transform = `translate3d(0px, ${dragStart.translateY}px, 0px) scale3d(${dragStart.scale}, ${dragStart.scale}, 1)`;\n target.style.opacity = String(dragStart.opacity);\n void target.offsetHeight; // commit the jump before transitioning away from it\n } else if (zoomStart) {\n // Same FLIP jump as dragStart above, computed the same center-to-center\n // way as `transform` above (not dragStart's raw translate/scale reuse\n // — see ZoomTransitionTarget.zoomStart's doc comment for why that\n // doesn't work here). `target`'s own effective box, re-measured fresh:\n // cheap, and guaranteed unchanged since the read inside\n // computeTransform() above — nothing's touched `target` in between.\n // Still correct even if `target` is currently rotated/flipped (the\n // RotateFlip plugin, applied directly to this same element, unlike\n // Zoom's own scale/pan — see below): both this measurement and\n // `zoomStart` itself were captured at the same rotation, so the\n // scale/translate between their two (equally rotated) bounding boxes\n // still isolates the zoom-only delta correctly.\n const targetRect = effectiveTargetBox(target, aspectRatio, naturalSize);\n if (targetRect.width > 0 && targetRect.height > 0) {\n // Composed onto whatever's already there, never replacing it outright\n // — a real bug, reported from real usage: closing while both rotated/\n // flipped *and* zoomed wholesale-overwrote RotateFlip's own\n // scaleX/scaleY/rotate() with this jump's plain translate/scale,\n // un-rotating *instantly* right here, before the real transition\n // below even starts — a snap to neutral rotation, then a separate\n // zoom-out, instead of the smooth combined un-rotate-while-shrinking\n // motion closing while rotated (without zoomStart at all) already\n // gets for free: transitioning target's transform from *whatever it\n // currently is* to the final plain shrink value is what makes that\n // work, and it needs target's rotation to still be sitting there\n // when the transition starts, not already erased by this jump.\n const existing = target.style.transform;\n const jump = transformBetween(targetRect, zoomStart);\n target.style.transition = 'none';\n target.style.transform = existing && existing !== 'none' ? `${existing} ${jump}` : jump;\n void target.offsetHeight;\n }\n }\n target.style.transition = 'transform var(--shoji-duration) var(--shoji-easing)';\n void target.offsetHeight;\n target.style.transform = transform;\n // Read back what the browser actually stored, not the raw string just\n // assigned — see clearInlineTransform's own doc comment for why the two\n // can differ (CSSOM float reformatting) and why that difference matters.\n const appliedTransform = target.style.transform;\n\n waitForTransitionEnd(target, () => {\n clearInlineTransform(target, appliedTransform);\n onComplete();\n });\n}\n","/** DESIGN.md §9 — inline SVG, stroke = currentColor, matches src/core/icons.ts's convention. A magnifying glass with a +/− in the lens, and a plain expand-corners glyph for \"actual size\" (distinct from fullscreen's EXPAND_ICON — no diagonal corner arrows, just a frame, so the two aren't visually confusable when both plugins are enabled). */\nexport const ZOOM_IN_ICON =\n '<svg viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"10\" cy=\"10\" r=\"7\"/><path d=\"M21 21l-5.5-5.5M10 7v6M7 10h6\"/></svg>';\n\nexport const ZOOM_OUT_ICON =\n '<svg viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"10\" cy=\"10\" r=\"7\"/><path d=\"M21 21l-5.5-5.5M7 10h6\"/></svg>';\n\n/**\n * Live state icons for the actual-size button (index.ts's icon-swap wiring)\n * — a diagonal double-arrow pair, matching the shape of Bootstrap Icons'\n * `arrows-angle-expand`/`arrows-angle-contract` (requested directly), not\n * literally that icon set's own path data. Still distinct from Fullscreen's\n * own EXPAND_ICON/COMPRESS_ICON (fullscreen/icons.ts) despite both being\n * diagonal-corner glyphs: Fullscreen draws four independent corner brackets\n * with no connecting line between them; these draw one continuous diagonal\n * shaft with an arrowhead-style bracket at each end, a different enough\n * shape that the two read as separate icons at a glance, not near-copies of\n * each other.\n */\nexport const ZOOM_ACTUAL_SIZE_EXPAND_ICON =\n '<svg viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M9 9L3 3M3 8V3h5M15 15l6 6M21 16v5h-5\"/></svg>';\n\nexport const ZOOM_ACTUAL_SIZE_CONTRACT_ICON =\n '<svg viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M3 3l6 6M9 3v6H3M21 21l-6-6M15 21v-6h6\"/></svg>';\n","/** A viewport-relative rect: `{left, top, width, height}`, same shape as `DOMRect` but plain-object so it's trivial to mock in tests. */\nexport interface ZoomBox {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nexport interface PanOffset {\n tx: number;\n ty: number;\n}\n\nexport function clampScale(scale: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, scale));\n}\n\n/** The 2x2 linear part of a CSS transform matrix — `{a, b, c, d}` from `matrix(a, b, c, d, e, f)`, translation (`e`/`f`) deliberately excluded, since everything below only ever uses this to remap a *delta* or a *local offset*, never an absolute position. */\nexport interface LinearTransform {\n a: number;\n b: number;\n c: number;\n d: number;\n}\n\n/** No parent transform — used as the default wherever a caller doesn't have (or need) one, so every function below stays backward-compatible with a pre-RotateFlip-aware caller. */\nexport const IDENTITY_TRANSFORM: LinearTransform = { a: 1, b: 0, c: 0, d: 1 };\n\n/**\n * `getComputedStyle().transform`'s own `matrix(a, b, c, d, e, f)` (or\n * `none`) string, parsed by hand rather than via the `DOMMatrix`\n * constructor — jsdom (`tests/unit/`) doesn't implement it, so relying on\n * it broke every unit test that exercises a pan drag; a plain regex needs\n * nothing environment-specific and works identically in a real browser.\n * RotateFlip only ever emits a 2D `matrix(...)` (never `matrix3d(...)`),\n * so that's the only form handled — `none` and anything unparseable both\n * fall back to the identity matrix.\n */\nexport function parseLinearTransform(transform: string): LinearTransform {\n const match = /^matrix\\(\\s*([^,]+),\\s*([^,]+),\\s*([^,]+),\\s*([^,]+),/.exec(transform);\n if (!match) return { ...IDENTITY_TRANSFORM };\n return { a: Number(match[1]), b: Number(match[2]), c: Number(match[3]), d: Number(match[4]) };\n}\n\n/**\n * DESIGN.md §4.6 — a real bug, reported from real usage: dragging to pan a\n * zoomed photo that RotateFlip (§4.5) had also rotated moved it in the\n * *wrong* direction (e.g. dragging down moved the image sideways instead)\n * — `onPointerMove`'s raw `event.clientX/Y` delta (screen space) was being\n * applied directly as `pan.tx`/`ty` (the `<img>`'s own *local* space,\n * nested inside `.shoji-slide-media`), with nothing correcting for\n * whatever transform that parent has — RotateFlip's rotation, in this\n * case, but this doesn't need to know that specifically: it corrects for\n * *any* linear transform on the parent, read live off its own computed\n * style, not by reaching into RotateFlip.\n *\n * Standard 2x2 matrix inversion: for `M = [[a, c], [b, d]]`, `M⁻¹ =\n * 1/det * [[d, -c], [-b, a]]` — applying `M⁻¹` to a screen-space delta\n * converts it into the local space `M` itself maps *from*, which is\n * exactly what a child nested inside that transformed parent needs to\n * move by to track the pointer 1:1 on screen regardless of the parent's\n * own rotation/scale/flip. `det === 0` is a degenerate parent transform\n * (zero scale on some axis) that can't be un-done at all — returns the\n * raw delta unchanged rather than dividing by zero into `NaN`.\n */\nexport function screenDeltaToLocal(dx: number, dy: number, m: LinearTransform): PanOffset {\n const det = m.a * m.d - m.b * m.c;\n if (det === 0) return { tx: dx, ty: dy };\n return {\n tx: (m.d * dx - m.c * dy) / det,\n ty: (m.a * dy - m.b * dx) / det,\n };\n}\n\n/** The forward companion to `screenDeltaToLocal` above: `M * [dx; dy]`, converting a *local* delta into the screen-space delta it produces once composed through the parent's current transform `m`. */\nexport function localDeltaToScreen(dx: number, dy: number, m: LinearTransform): PanOffset {\n return { tx: m.a * dx + m.c * dy, ty: m.b * dx + m.d * dy };\n}\n\n/**\n * DESIGN.md §4.6 — the img's own true, *unrotated* layout size (its\n * `offsetWidth`/`offsetHeight` — CSS `transform` is paint-only and never\n * affects these, unlike `natural`'s own `getBoundingClientRect()`, which\n * *does* reflect the parent's current rotation) as an offset from the\n * img's own local origin `(0, 0)` to its own layout center, negated:\n * `{tx: -width/2, ty: -height/2}`. See `localOriginScreen`'s own doc\n * comment for why this specific offset is what a rotated parent needs.\n * Defaults to deriving it from `natural` itself (assuming `natural` *is*\n * already the true, unrotated size) — correct whenever the parent has no\n * rotation, wrong whenever it does; real callers with a possibly-rotated\n * parent should always pass the img's real `offsetWidth`/`offsetHeight`\n * explicitly instead of relying on this default.\n */\nexport function trueOriginOffset(natural: ZoomBox): PanOffset {\n return { tx: -natural.width / 2, ty: -natural.height / 2 };\n}\n\n/**\n * DESIGN.md §4.6 — a real bug, found immediately after the pan-drag fix\n * above while testing the analogous double-click-to-zoom case: `natural`'s\n * own `left`/`top` (from `getBoundingClientRect()` on the *rotated* img)\n * is **not** the screen position of the img's local origin `(0, 0)` —\n * rotating a rectangle moves *which of its own corners* ends up at the\n * bounding box's own top-left. For a 90°-rotated landscape photo, the\n * corner that lands at `natural`'s own top-left is the photo's original\n * *bottom*-left, not its top-left — confirmed directly, by hand, against\n * real `getBoundingClientRect()` numbers: treating `natural.left + pan.tx`\n * as \"the origin's screen position\" (what `zoomTowardPoint`/`clampPan`\n * both did) was off by the img's own full width on one axis, which is\n * exactly why double-clicking to zoom toward the pointer, after a\n * rotation, zoomed toward the wrong point instead — sometimes a\n * plausible-looking wrong point, sometimes (as reported) toward an edge\n * of the image instead of the actual click.\n *\n * The one point immune to this ambiguity is the bounding box's own\n * *center* — rotating a rectangle around its own center (the default\n * `transform-origin`, and where `.shoji-slide-media`'s flex-centering\n * already puts the img) never moves that center, on screen or off. Used\n * as a pivot: the img's local origin, relative to its own *true* (layout,\n * pre-rotation) center, is a fixed offset (`originOffset`, `-width/2,\n * -height/2` in the img's own local space) — that offset plus the current\n * `pan`, mapped through the parent's rotation matrix `m` and added back to\n * the pivot's own (rotation-invariant) screen position, gives the origin's\n * *real* current screen position, correct for any axis-aligned rotation\n * RotateFlip can produce. At the default identity `m` and the default\n * `originOffset` (derived from `natural` itself, correct exactly when\n * there's no rotation to begin with), this reduces to plain\n * `natural.left + pan.tx` — the original, pre-fix formula.\n */\nexport function localOriginScreen(\n natural: ZoomBox,\n pan: PanOffset,\n m: LinearTransform = IDENTITY_TRANSFORM,\n originOffset: PanOffset = trueOriginOffset(natural),\n): { x: number; y: number } {\n const pivotX = natural.left + natural.width / 2;\n const pivotY = natural.top + natural.height / 2;\n const fromPivot = localDeltaToScreen(originOffset.tx + pan.tx, originOffset.ty + pan.ty, m);\n return { x: pivotX + fromPivot.tx, y: pivotY + fromPivot.ty };\n}\n\n/** One axis of `clampEdgeToContainer` below — see `clampPan`'s own doc comment for the geometry. Keeps the scaled content's edge from retreating inside the container's edge (no empty gap beyond the image); when the content is already smaller than the container on this axis, no position can avoid a gap on *both* sides at once, so centered is the only sensible answer. */\nfunction clampEdge(\n contentPos: number,\n contentSize: number,\n containerPos: number,\n containerSize: number,\n): number {\n if (contentSize <= containerSize) {\n return containerPos + (containerSize - contentSize) / 2;\n }\n const minPos = containerPos + containerSize - contentSize;\n const maxPos = containerPos;\n return Math.min(maxPos, Math.max(minPos, contentPos));\n}\n\n/**\n * The content's own current screen-space bounding box, for `clampPan`\n * below — the four corners of the img's true (unrotated) `width x height`\n * rect (from `originOffset`, negated), scaled and panned in the wrapper's\n * own unrotated frame, then each mapped to screen space individually via\n * `m` before taking the min/max. Four corners, not one edge scaled\n * directly, because `m` can swap which axis grows with which — RotateFlip\n * only ever produces axis-aligned (90°-multiple) rotations, so the result\n * is still a plain axis-aligned box, just not derivable from a single\n * corner the way an unrotated one is.\n */\nfunction contentScreenBounds(\n natural: ZoomBox,\n pan: PanOffset,\n scale: number,\n m: LinearTransform,\n originOffset: PanOffset,\n): { left: number; top: number; right: number; bottom: number } {\n const trueWidth = -originOffset.tx * 2;\n const trueHeight = -originOffset.ty * 2;\n const pivotX = natural.left + natural.width / 2;\n const pivotY = natural.top + natural.height / 2;\n const localCorners = [\n { x: 0, y: 0 },\n { x: trueWidth, y: 0 },\n { x: 0, y: trueHeight },\n { x: trueWidth, y: trueHeight },\n ];\n const screenCorners = localCorners.map(({ x, y }) => {\n const wrapperFrame = {\n x: originOffset.tx + pan.tx + x * scale,\n y: originOffset.ty + pan.ty + y * scale,\n };\n const screen = localDeltaToScreen(wrapperFrame.x, wrapperFrame.y, m);\n return { x: pivotX + screen.tx, y: pivotY + screen.ty };\n });\n const xs = screenCorners.map((p) => p.x);\n const ys = screenCorners.map((p) => p.y);\n return {\n left: Math.min(...xs),\n top: Math.min(...ys),\n right: Math.max(...xs),\n bottom: Math.max(...ys),\n };\n}\n\n/**\n * Keeps the scaled+panned content's edges from retreating inside\n * `container`'s edges (no empty gap beyond the image), on both screen axes\n * independently.\n *\n * `m`/`originOffset` (default identity / derived from `natural`, DESIGN.md\n * §4.6) — same real bug and same root cause as `localOriginScreen`'s own\n * doc comment: the old per-axis formula compared `natural.left + pan.tx`\n * (mixing screen-space and, once rotated, the wrong corner entirely)\n * against the container's screen bounds. The content's actual screen\n * bounding box is computed properly via `contentScreenBounds` (which\n * itself only ever needs `m`/`originOffset` to do that correctly), each\n * edge is clamped against the container the same way as before, and the\n * *difference* — a screen-space delta — is mapped back to local space and\n * folded into `pan`. At the defaults, every step is a no-op and this\n * reduces to exactly the original per-axis formula.\n */\nexport function clampPan(\n natural: ZoomBox,\n container: ZoomBox,\n scale: number,\n pan: PanOffset,\n m: LinearTransform = IDENTITY_TRANSFORM,\n originOffset: PanOffset = trueOriginOffset(natural),\n): PanOffset {\n const bounds = contentScreenBounds(natural, pan, scale, m, originOffset);\n const clampedLeft = clampEdge(\n bounds.left,\n bounds.right - bounds.left,\n container.left,\n container.width,\n );\n const clampedTop = clampEdge(\n bounds.top,\n bounds.bottom - bounds.top,\n container.top,\n container.height,\n );\n const screenDelta = { tx: clampedLeft - bounds.left, ty: clampedTop - bounds.top };\n const localDelta = screenDeltaToLocal(screenDelta.tx, screenDelta.ty, m);\n return { tx: pan.tx + localDelta.tx, ty: pan.ty + localDelta.ty };\n}\n\n/**\n * The standard \"zoom toward a point\" formula: adjusts pan so the viewport\n * point `(anchorX, anchorY)` stays visually fixed as scale changes from\n * `oldScale` to `newScale`, given `transform-origin: 0 0` (scaling never\n * moves the img's own local origin on screen, only `pan` does). Callers\n * still need to clamp the result with `clampPan` afterward; this only\n * solves the anchor-fixed part, not boundary containment.\n *\n * `m`/`originOffset` (default identity / derived from `natural`, DESIGN.md\n * §4.6) — a real bug, reported from real usage: double-clicking to zoom\n * toward the pointer, after RotateFlip had rotated the slide, zoomed\n * toward the wrong point — sometimes badly (see `localOriginScreen`'s own\n * doc comment for the root cause and how these two parameters fix it,\n * shared with `clampPan` above). At the defaults, every step is a no-op\n * and this reduces to exactly the original formula.\n */\nexport function zoomTowardPoint(\n natural: ZoomBox,\n pan: PanOffset,\n oldScale: number,\n newScale: number,\n anchorX: number,\n anchorY: number,\n m: LinearTransform = IDENTITY_TRANSFORM,\n originOffset: PanOffset = trueOriginOffset(natural),\n): PanOffset {\n const origin = localOriginScreen(natural, pan, m, originOffset);\n const screenDx = anchorX - origin.x;\n const screenDy = anchorY - origin.y;\n const local = screenDeltaToLocal(screenDx, screenDy, m);\n const factor = 1 - newScale / oldScale;\n return {\n tx: pan.tx + local.tx * factor,\n ty: pan.ty + local.ty * factor,\n };\n}\n","import type { PluginContext, ShojiPlugin } from '../../core/plugin';\nimport { createIconSwap } from '../../core/iconSwap';\nimport { waitForTransitionEnd } from '../../core/zoomTransition';\nimport {\n ZOOM_ACTUAL_SIZE_CONTRACT_ICON,\n ZOOM_ACTUAL_SIZE_EXPAND_ICON,\n ZOOM_IN_ICON,\n ZOOM_OUT_ICON,\n} from './icons';\nimport {\n clampPan,\n clampScale,\n parseLinearTransform,\n screenDeltaToLocal,\n zoomTowardPoint,\n type PanOffset,\n type ZoomBox,\n} from './zoomMath';\nimport './zoom.css';\n\nexport interface ZoomOptions {\n /** Multiplier cap for pinch/wheel/button zoom. \"Actual size\" can exceed this deliberately — it's an explicit action, not continuous gesture zoom. Default 4. */\n maxScale?: number;\n /** Scale a double-tap/double-click jumps to; a second one while already zoomed resets to 1 instead. Default 2. */\n doubleTapScale?: number;\n /** Multiplier applied per zoom-in/zoom-out toolbar button click. Default 1.5. */\n buttonStep?: number;\n}\n\nconst ZOOM_EPSILON = 1.001; // treat \"just barely above 1\" as unzoomed — avoids float residue pinning isZoomed() true forever\n\n/** A click/drag starting on a real control shouldn't engage pan — same exclusion list GestureController's shouldIgnoreGesture uses, duplicated rather than imported since that function isn't part of core's exported surface. */\nfunction isRealControl(event: PointerEvent): boolean {\n return event\n .composedPath()\n .some(\n (node) =>\n node instanceof Element &&\n node.matches(\n 'button, video, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption',\n ),\n );\n}\n\n/**\n * DESIGN.md §4-zoom — pinch, double-tap/click, wheel+ctrl, and three toolbar\n * buttons (zoom in/out/actual-size) all drive a single `scale`/pan state on\n * the active slide's `<img>` — never `.shoji-slide-media` itself, which the\n * rotateFlip plugin (§4) already transforms; nesting on the inner element\n * instead of fighting over the same transform string means a rotated *and*\n * zoomed photo behaves correctly for free (the outer rotate carries the\n * inner pan/scale along with it as a rigid unit, which is also the visually\n * expected result — see DESIGN.md's note on this plugin for the full\n * reasoning). Pinch/double-tap/wheel are core's own gesture relay (§2.4) —\n * scaffolding that existed specifically for this plugin to consume, not\n * reimplemented here. Pan (single-pointer drag while zoomed) is the one\n * piece core's relay doesn't cover — core's own drag-to-navigate/\n * drag-to-close would otherwise fight over the same drag — so this plugin\n * registers a zoom gate (`Gallery.registerZoomGate`, §4-zoom) that suspends\n * core's drag handling entirely while zoomed, and tracks pan with its own\n * minimal raw pointer listeners instead of reusing `GestureEngine` (whose\n * axis-locked model — pick horizontal *or* vertical per gesture — is the\n * wrong shape for a 2D pan that needs both at once).\n */\nexport const Zoom: ShojiPlugin = {\n name: 'zoom',\n defaults: {\n maxScale: 4,\n doubleTapScale: 2,\n buttonStep: 1.5,\n } satisfies ZoomOptions,\n\n init(ctx: PluginContext): () => void {\n const { gallery } = ctx;\n const maxScale = Number(ctx.options.maxScale ?? 4);\n const doubleTapScale = Number(ctx.options.doubleTapScale ?? 2);\n const buttonStep = Number(ctx.options.buttonStep ?? 1.5);\n const locale = (gallery.options.locale ?? {}) as Record<string, string>;\n const zoomInLabel = locale.zoomIn ?? 'Zoom in';\n const zoomOutLabel = locale.zoomOut ?? 'Zoom out';\n const actualSizeLabel = locale.zoomActualSize ?? 'Actual size';\n\n let scale = 1;\n let pan: PanOffset = { tx: 0, ty: 0 };\n let natural: ZoomBox | null = null;\n let container: ZoomBox | null = null;\n // The img's own true, unrotated local origin, as an offset from its\n // (rotation-invariant) layout center — see zoomTowardPoint/clampPan's\n // own doc comments (DESIGN.md §4.6) for why natural's left/top/width/\n // height alone aren't a safe stand-in for this once RotateFlip has\n // rotated the parent.\n let originOffset: PanOffset | null = null;\n let pinchStartScale = 1;\n\n function getImg(): HTMLImageElement | null {\n const media = gallery.getActiveMedia();\n const child = media?.firstElementChild;\n return child instanceof HTMLImageElement ? child : null;\n }\n\n function boxOf(el: Element): ZoomBox {\n const rect = el.getBoundingClientRect();\n return { left: rect.left, top: rect.top, width: rect.width, height: rect.height };\n }\n\n /** Only valid to measure while scale===1 (untransformed) — the very first zoom action on a slide; every subsequent action within the same slide reuses the cached box, since measuring an already-scaled element would capture the scaled size, not the natural one. */\n function ensureNatural(img: HTMLImageElement): boolean {\n if (natural && container && originOffset) return true;\n if (scale !== 1) return false; // shouldn't happen — defensive\n natural = boxOf(img);\n container = boxOf(img.parentElement ?? img);\n // offsetWidth/Height, not natural's own width/height above — CSS\n // transform (RotateFlip's rotation on the parent) is paint-only and\n // never affects layout size, unlike getBoundingClientRect(), which\n // reports the *rotated* bounding box (DESIGN.md §4.6). Falls back to\n // natural's own (unrotated-assuming) size when offsetWidth/Height\n // read 0 — real layout engines only report 0 for a genuinely\n // unrendered element, but jsdom (tests/unit/) never computes layout\n // at all and always reports 0, so this also keeps every rotation-\n // unaware unit test's mocked getBoundingClientRect() meaningful.\n originOffset = {\n tx: -(img.offsetWidth || natural.width) / 2,\n ty: -(img.offsetHeight || natural.height) / 2,\n };\n return true;\n }\n\n /**\n * A real bug: `ensureNatural`'s first measurement of a slide is only\n * trustworthy once the lightbox's own open FLIP transition (`zoomIn`,\n * `core/zoomTransition.ts`) has actually settled — that transition\n * applies its own transform directly to `.shoji-slide-media`, the exact\n * element `ensureNatural` measures as `container`. A zoom action firing\n * before it settles (any interaction within `--shoji-duration` of\n * opening — a fast click, or a test that only waits for the dialog to\n * become visible) captured a wildly wrong, mid-animation rect,\n * permanently poisoning that slide's zoom math (every later action\n * reuses the same cached, wrong box). `zoomIn` is fire-and-forget by\n * design (nothing to await when opening) and clears this exact inline\n * style once its own transition ends — the one signal available for\n * \"is it still running.\" Runs `action` immediately once settled, which\n * is right away in the overwhelming common case (any real interaction\n * more than ~300ms after open).\n */\n function whenSettled(action: () => void): void {\n const media = gallery.getActiveMedia();\n if (!media || media.style.transition === '') {\n action();\n return;\n }\n waitForTransitionEnd(media, action);\n }\n\n /**\n * `translate3d`/`scale3d`, not the 2D `translate`/`scale` this used to\n * use — a real bug, reported from real usage: evenly-spaced horizontal\n * lines visible across a zoomed photo, at certain zoom levels, on real\n * GPU hardware (not reproducible in headless/software rendering, so\n * this can't be verified here). The regular spacing matches Chromium's\n * own raster-tile boundaries — a known quirk where scaling large\n * content via a 2D `scale()` transform can show seams between GPU\n * tiles. Forcing the fully 3D compositing path instead (functionally\n * identical — `scale3d(s, s, 1)` and `scale(s)` produce the same\n * on-screen result) is the commonly effective fix, since it takes a\n * different rasterization path than the 2D one.\n */\n function apply(): void {\n const img = getImg();\n if (!img) return;\n img.style.transformOrigin = '0 0';\n img.style.transform =\n scale === 1 && pan.tx === 0 && pan.ty === 0\n ? 'none'\n : `translate3d(${pan.tx}px, ${pan.ty}px, 0) scale3d(${scale}, ${scale}, 1)`;\n img.classList.toggle('shoji-zoomed', scale > 1);\n }\n\n function emitChange(): void {\n ctx.emit('zoomChange', { index: gallery.currentIndex, scale });\n updateActualSizeIcon();\n }\n\n /**\n * The actual-size button's icon reflects live state, requested directly:\n * `arrows-angle-expand` at fit, `arrows-angle-contract` while zoomed in\n * at all — by pinch, wheel, the zoom-in/out buttons, or this button\n * itself, not just specifically at native pixel size. Matches\n * `actualSizeToggle()`'s own real click behavior exactly: it resets to\n * fit for *any* `scale > 1`, regardless of how that zoom was reached,\n * and only attempts to zoom to native size from exactly `scale === 1`\n * (a no-op there for a photo whose native resolution is at or below its\n * fitted size — `clampScale(targetScale, 1, ...)`'s own floor — which\n * this correctly still shows as expand, since scale is still 1 in that\n * case). A real bug in an earlier version of this: tracking a separate\n * \"are we exactly at native size\" cache (naturalWidth / natural.width,\n * refreshed on slideItemLoad) went stale the moment `reset()` cleared\n * it without every call site re-populating it, so only the *first*\n * actual-size press of a session ever updated the icon at all — using\n * `scale` directly instead, already the single live source of truth\n * `zoomChange` itself is built on, has no cache to go stale in the\n * first place.\n */\n function updateActualSizeIcon(): void {\n actualSizeIconSwap.setState(scale > ZOOM_EPSILON);\n }\n\n /** Wraps a transform-setting `run` in a transition, for discrete jumps (buttons, double-tap, actual-size) — never for pinch/pan/wheel, which already track the input 1:1 and would visibly lag behind it under a transition. `afterEnd`, if given, runs once the transition actually completes, not before — `reset()` uses it to clear `transformOrigin` only once it's safe to (see its own comment for why clearing it any earlier is a real bug). The transition itself is always cleared afterward, so it doesn't linger onto the next, possibly-continuous, zoom action. */\n function withTransition(img: HTMLImageElement, run: () => void, afterEnd?: () => void): void {\n img.style.transition = 'transform var(--shoji-duration) var(--shoji-easing)';\n run();\n waitForTransitionEnd(img, () => {\n img.style.transition = '';\n afterEnd?.();\n });\n }\n\n /** Shared by every zoom-in/out entry point (pinch, wheel, buttons, double-tap, actual-size) — anchors on (anchorX, anchorY), clamps scale to [1, ceiling] and pan to the container bounds. `ceiling` defaults to maxScale; actual-size passes its own (possibly larger) target so it isn't capped by the gesture-zoom limit. Deferred via `whenSettled` — see its doc comment — so a zoom action landing right as the lightbox opens doesn't measure mid-animation. `animate` — see `withTransition`. */\n function zoomTo(\n targetScale: number,\n anchorX: number,\n anchorY: number,\n ceiling = maxScale,\n animate = false,\n ): void {\n whenSettled(() => {\n const img = getImg();\n if (!img || !ensureNatural(img)) return;\n const clampedScale = clampScale(targetScale, 1, Math.max(ceiling, 1));\n // DESIGN.md §4.6 — zoomTowardPoint's own doc comment has the full\n // reasoning: the anchor point needs the same screen-vs-local\n // correction as onPointerMove's own pan drag, since RotateFlip may\n // have rotated/flipped `.shoji-slide-media` in the meantime.\n const media = gallery.getActiveMedia();\n const parentTransform = parseLinearTransform(\n media ? getComputedStyle(media).transform : 'none',\n );\n pan = zoomTowardPoint(\n natural!,\n pan,\n scale,\n clampedScale,\n anchorX,\n anchorY,\n parentTransform,\n originOffset!,\n );\n scale = clampedScale;\n // Same correction, same reason — clampAxis compares against the\n // container's screen bounds, so the candidate pan needs to be in\n // screen space too, or a 90/270deg rotation clamps the wrong edge\n // and can undo the anchor-preserving pan just computed above.\n pan = clampPan(natural!, container!, scale, pan, parentTransform, originOffset!);\n if (animate) withTransition(img, apply);\n else apply();\n emitChange();\n });\n }\n\n function reset(animate = false): void {\n // A real gap, found auditing this against its own documented contract\n // (\"emits zoomChange on every scale change, gesture or button-driven\",\n // DESIGN.md §4.6): resetting from an engaged scale back to 1 is a\n // scale change like any other, but every call site here (beforeSlide,\n // afterSlide, beforeClose, afterOpen, and zoomOutStep/toggleZoom\n // reaching neutral) silently skipped emitting it — a host listening\n // for zoomChange to reflect \"is this slide currently zoomed\" would\n // never learn it stopped being true unless something else zoomed in\n // again first. Only when there's an actual change: the overwhelming\n // majority of these calls fire while already at scale 1 (nothing\n // engaged to begin with), and emitting on every no-op reset would be\n // noisy against the \"on every *change*\" contract, not a fix for it.\n const wasEngaged = scale !== 1;\n scale = 1;\n pan = { tx: 0, ty: 0 };\n natural = null;\n container = null;\n originOffset = null;\n updateActualSizeIcon(); // scale is already 1 here, so this is always the expand state\n if (wasEngaged) emitChange(); // after scale is already 1, so listeners see the real new value\n const img = getImg();\n if (!img) return;\n const clearTransform = (): void => {\n img.style.transform = '';\n img.classList.remove('shoji-zoomed');\n };\n if (animate) {\n // transform-origin has to stay put (0 0) for the duration of the\n // transition — clearing it to the browser default (center) in the\n // same tick as starting the transition snaps the scale anchor\n // instantly, which visibly jumped the image before it eased down\n // to neutral. Deferred to `afterEnd`, once the transition is done\n // and transform-origin no longer affects anything visible.\n withTransition(img, clearTransform, () => {\n img.style.transformOrigin = '';\n });\n } else {\n clearTransform();\n img.style.transformOrigin = '';\n }\n }\n\n /** DESIGN.md §2.5/§4.6 — same fix, same reasoning, as RotateFlip's own equivalent (`rotateFlip/index.ts`): `beforeSlide`'s unanimated `reset()` above can't itself animate (it has to finish before `SlideManager.render()` reparents the outgoing image), so the live `transform`/`transformOrigin` about to be wiped are captured here first and handed to `SlideTransition` via `registerSlideLeaveDecorator()` below, to animate away on the leave-ghost's own clone instead of just vanishing. */\n let pendingLeaveTransform: string | null = null;\n let pendingLeaveOrigin = '';\n function captureLeaveTransform(): void {\n const img = getImg();\n const transform = img?.style.transform;\n pendingLeaveTransform = transform && transform !== 'none' ? transform : null;\n pendingLeaveOrigin = img?.style.transformOrigin || '0 0';\n }\n\n /** Each slide gets a freshly-created `<img>` (SlideManager never reuses elements across renders), so the cursor-affordance marker (`zoom.css`) needs reapplying every time the active media changes, not just once. */\n function markEnabled(): void {\n getImg()?.classList.add('shoji-zoom-enabled');\n }\n\n function toggleZoom(x: number, y: number): void {\n if (scale > ZOOM_EPSILON) reset(true);\n else zoomTo(doubleTapScale, x, y, maxScale, true);\n }\n\n // --- pinch (relayed by core, §2.4 — no built-in effect until this plugin exists) ---\n const offPinchStart = ctx.on('pinchStart', () => {\n pinchStartScale = scale;\n });\n const offPinchMove = ctx.on('pinchMove', ({ scale: relative, centerX, centerY }) => {\n zoomTo(pinchStartScale * relative, centerX, centerY);\n });\n const offPinchEnd = ctx.on('pinchEnd', () => {\n if (scale <= ZOOM_EPSILON) reset(); // snap fully back to neutral rather than leaving float residue\n });\n\n // --- double-tap / double-click (relayed by core; Pointer Events unify the two, see GestureEngine) ---\n const offDoubleTap = ctx.on('doubleTap', ({ x, y }) => toggleZoom(x, y));\n\n // --- ctrl+wheel / trackpad pinch (relayed by core) ---\n const offWheelZoom = ctx.on('wheelZoom', ({ deltaScale, x, y }) => {\n zoomTo(scale + deltaScale, x, y);\n });\n\n /**\n * A generic command surface, requested directly (DESIGN.md §4.6), so a\n * *custom* (host-authored) plugin's own button can drive zoom without\n * importing this plugin at all — same \"events over inheritance\"\n * decoupling `pinchStart`/`doubleTap`/`wheelZoom` above already use,\n * just in the opposite direction (a command in, not a gesture relay).\n * `GalleryEvents` (`core/types.ts`) already extends `Record<string,\n * unknown>`, so `ctx.emit('requestZoomIn', {})` from any plugin —\n * official or custom — type-checks with zero core changes; this is\n * just the listening half. Each mirrors its real toolbar button\n * exactly — same functions, same behavior on a video slide (a no-op,\n * `zoomInStep`/`zoomOutStep`/`actualSizeToggle` all bail via `getImg()`\n * returning null there).\n */\n const offRequestZoomIn = ctx.on('requestZoomIn', zoomInStep);\n const offRequestZoomOut = ctx.on('requestZoomOut', zoomOutStep);\n const offRequestZoomActualSize = ctx.on('requestZoomActualSize', actualSizeToggle);\n const offRequestZoomReset = ctx.on('requestZoomReset', () => reset(true));\n\n // --- pan while zoomed — the one gesture core's relay doesn't cover; see the plugin doc comment for why this can't reuse GestureEngine. ---\n let panPointerId: number | null = null;\n let lastX = 0;\n let lastY = 0;\n const outer = ctx.ui.outer();\n\n function onPointerDown(event: PointerEvent): void {\n if (scale <= ZOOM_EPSILON || isRealControl(event)) return;\n const img = getImg();\n // A real bug, reported from real usage: this listens on `outer` (the\n // whole lightbox, not just the image) so a fast pan can be tracked\n // even once the pointer leaves the image's own bounds — but with no\n // check on where the pointerdown itself landed, a click on the plain\n // backdrop (between the image and a nav arrow, say) engaged pan and\n // captured the pointer onto `img` regardless, which — see below —\n // retargets the click and makes it misread as \"on the image,\" not\n // backdrop, silently defeating click-to-close while zoomed.\n if (!img || !event.composedPath().includes(img)) return;\n panPointerId = event.pointerId;\n lastX = event.clientX;\n lastY = event.clientY;\n // Without this, a fast pan whose pointer exits `outer`'s bounds\n // stops receiving pointermove/pointerup entirely (no capture = only\n // elements actually under the cursor get events), leaving\n // panPointerId stuck non-null until the next pointerdown — the\n // gesture just goes dead mid-drag. Captured on the `<img>` itself,\n // not `outer`: capturing retargets the subsequent synthetic `click`\n // to whatever captured it, and `img` — unlike `outer` — already\n // matches isBackdropClick's own exclusion selector (Gallery.ts), so\n // a captured pan's release still can't misread as a backdrop click.\n // GestureEngine's own capture needs a separate suppressRetargetedClick\n // step for exactly this reason; this doesn't, since the retarget\n // lands somewhere already excluded.\n img.setPointerCapture(event.pointerId);\n }\n function onPointerMove(event: PointerEvent): void {\n if (panPointerId !== event.pointerId || !natural || !container || !originOffset) return;\n event.preventDefault();\n const rawDx = event.clientX - lastX;\n const rawDy = event.clientY - lastY;\n lastX = event.clientX;\n lastY = event.clientY;\n // DESIGN.md §4.6 — screenDeltaToLocal's own doc comment has the full\n // reasoning: the raw pointer delta is screen space, but pan.tx/ty are\n // local to the <img>, nested inside whatever transform (e.g.\n // RotateFlip's rotation) `.shoji-slide-media` currently has.\n const media = gallery.getActiveMedia();\n const m = parseLinearTransform(media ? getComputedStyle(media).transform : 'none');\n const { tx: dx, ty: dy } = screenDeltaToLocal(rawDx, rawDy, m);\n pan = clampPan(\n natural,\n container,\n scale,\n { tx: pan.tx + dx, ty: pan.ty + dy },\n m,\n originOffset,\n );\n apply();\n }\n function onPointerUp(event: PointerEvent): void {\n if (panPointerId === event.pointerId) panPointerId = null;\n }\n\n outer.addEventListener('pointerdown', onPointerDown);\n outer.addEventListener('pointermove', onPointerMove, { passive: false });\n outer.addEventListener('pointerup', onPointerUp);\n outer.addEventListener('pointercancel', onPointerUp);\n\n // --- toolbar buttons ---\n function buildButton(icon: string, label: string): HTMLButtonElement {\n const button = document.createElement('button');\n button.type = 'button';\n button.className = 'shoji-toolbar-button';\n button.innerHTML = icon;\n button.setAttribute('aria-label', label);\n button.title = label;\n return button;\n }\n\n function centerAnchor(): { x: number; y: number } {\n const media = gallery.getActiveMedia();\n const rect = media?.getBoundingClientRect();\n return rect\n ? { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }\n : { x: 0, y: 0 };\n }\n\n /** Shared by the zoom-in toolbar button and the `w` keyboard shortcut — same fixed `buttonStep` multiplier either way. */\n function zoomInStep(): void {\n const { x, y } = centerAnchor();\n zoomTo(scale * buttonStep, x, y, maxScale, true);\n }\n\n /** Shared by the zoom-out toolbar button and the `s` keyboard shortcut. */\n function zoomOutStep(): void {\n const { x, y } = centerAnchor();\n if (scale / buttonStep <= ZOOM_EPSILON) reset(true);\n else zoomTo(scale / buttonStep, x, y, maxScale, true);\n }\n\n /** Shared by the actual-size toolbar button and `requestZoomActualSize` below. Reads natural.width directly (unlike every other entry point, which just hands zoomTo a target and lets it call ensureNatural itself) — needs its own whenSettled wrap for that reason, not just zoomTo's. */\n function actualSizeToggle(): void {\n whenSettled(() => {\n const img = getImg();\n if (!img || !img.naturalWidth) return;\n if (!ensureNatural(img)) return;\n if (scale > ZOOM_EPSILON) {\n reset(true);\n return;\n }\n const targetScale = img.naturalWidth / natural!.width;\n const { x, y } = centerAnchor();\n zoomTo(targetScale, x, y, targetScale, true); // ceiling = targetScale — bypasses maxScale deliberately\n });\n }\n\n const zoomInBtn = buildButton(ZOOM_IN_ICON, zoomInLabel);\n const zoomOutBtn = buildButton(ZOOM_OUT_ICON, zoomOutLabel);\n\n const actualSizeBtn = document.createElement('button');\n actualSizeBtn.type = 'button';\n actualSizeBtn.className = 'shoji-toolbar-button';\n const actualSizeIconSwap = createIconSwap(\n ZOOM_ACTUAL_SIZE_EXPAND_ICON,\n ZOOM_ACTUAL_SIZE_CONTRACT_ICON,\n );\n actualSizeBtn.appendChild(actualSizeIconSwap.el);\n actualSizeBtn.setAttribute('aria-label', actualSizeLabel);\n actualSizeBtn.title = actualSizeLabel;\n\n zoomInBtn.addEventListener('click', zoomInStep);\n zoomOutBtn.addEventListener('click', zoomOutStep);\n actualSizeBtn.addEventListener('click', actualSizeToggle);\n\n // 'right' — registered in this order, so they cluster left-to-right as\n // zoomIn, zoomOut, actualSize, then whatever later plugin (or the close\n // button) follows (DESIGN.md §3.1).\n const removeButtons = [zoomInBtn, zoomOutBtn, actualSizeBtn].map((button) =>\n ctx.ui.toolbar('right', button),\n );\n\n /** All three zoom buttons are no-ops on a video slide — `getImg()` returns null, so `apply()`/`ensureNatural()` bail out immediately. Hidden rather than left clickable-but-dead. */\n function updateButtonVisibility(): void {\n const isVideo = !!gallery.items[gallery.currentIndex]?.video;\n zoomInBtn.hidden = isVideo;\n zoomOutBtn.hidden = isVideo;\n actualSizeBtn.hidden = isVideo;\n }\n\n // w/s zoom in/out, same step as the toolbar buttons — both cases\n // registered explicitly (registerShortcut matches event.key verbatim,\n // no case-insensitive matching of its own) so Shift/CapsLock still work.\n const removeShortcuts = [\n ctx.ui.registerShortcut('w', zoomInStep),\n ctx.ui.registerShortcut('W', zoomInStep),\n ctx.ui.registerShortcut('s', zoomOutStep),\n ctx.ui.registerShortcut('S', zoomOutStep),\n ];\n\n const offOpen = ctx.on('afterOpen', () => {\n reset();\n markEnabled();\n updateButtonVisibility();\n });\n // Un-animated, and on beforeSlide rather than only afterSlide below:\n // SlideManager.render() (called synchronously between the two) reuses a\n // still-cached slide's node via a plain reparent (moveIn(), no state\n // clearing of its own) into whichever pool slot its new offset needs —\n // there is no code path afterward that can still find *this* image to\n // reset it. A real bug, reported from real usage: zoom in via \"Actual\n // size\", click next — the old, still-scaled image, now reparented into\n // the (unclipped, per shoji.css) neighboring slot, visibly bled into the\n // new slide instead of being invisible off-screen like an unzoomed one\n // always is. Resetting here, while getActiveMedia() still resolves to\n // the about-to-move image, clears it before that reparent ever happens.\n // captureLeaveTransform() (see registerSlideLeaveDecorator below) reads\n // the live transform first, while it's still there to read.\n const offBeforeSlide = ctx.on('beforeSlide', () => {\n captureLeaveTransform();\n reset();\n });\n const offSlide = ctx.on('afterSlide', () => {\n reset();\n markEnabled();\n updateButtonVisibility();\n });\n // Fires synchronously, before Gallery.close() measures the active\n // media's rect to compute the zoom-out-to-thumbnail animation — reset\n // here (not just afterOpen/afterSlide) so that measurement sees the\n // image at its natural position/scale, not wherever it was left\n // zoomed/panned to. Skipping this made closing while zoomed animate\n // from the image's current (zoomed, often partly off-screen) rect\n // instead of its real thumbnail-relative size, landing \"closed\" at a\n // seemingly random spot instead of visibly shrinking into the thumbnail.\n const offBeforeClose = ctx.on('beforeClose', () => reset());\n const unregisterGate = gallery.registerZoomGate(() => scale > ZOOM_EPSILON);\n // Read by Gallery.beginClose() *before* the beforeClose reset above\n // runs, so a button-close continues the zoom-out from wherever the\n // viewer was actually zoomed/panned to, instead of the reset above\n // making it (correctly, for the measurement) but also making the\n // close itself snap back to neutral first. The image's own real\n // rendered rect, not this plugin's raw scale/pan numbers — see\n // zoomTransition.ts's ZoomTransitionTarget.zoomStart for why a direct\n // scale/pan replay doesn't work once it lands on a different element.\n const unregisterZoomStart = gallery.registerZoomStartProvider(() =>\n scale > ZOOM_EPSILON ? (getImg()?.getBoundingClientRect() ?? null) : null,\n );\n const unregisterLeaveDecorator = gallery.registerSlideLeaveDecorator((clonedMedia) => {\n if (!pendingLeaveTransform) return;\n const transform = pendingLeaveTransform;\n const origin = pendingLeaveOrigin;\n pendingLeaveTransform = null;\n const clonedImg = clonedMedia.querySelector<HTMLImageElement>('img');\n if (!clonedImg) return;\n clonedImg.style.transformOrigin = origin;\n clonedImg.style.transform = transform;\n return () => {\n clonedImg.style.transition = 'transform var(--shoji-duration) var(--shoji-easing)';\n clonedImg.style.transform = 'none';\n };\n });\n markEnabled(); // covers the (unusual but possible) case of the gallery already being open when this plugin initializes\n updateButtonVisibility();\n\n return () => {\n for (const remove of removeButtons) remove();\n for (const remove of removeShortcuts) remove();\n offOpen();\n offBeforeSlide();\n offSlide();\n offBeforeClose();\n offPinchStart();\n offPinchMove();\n offPinchEnd();\n offDoubleTap();\n offWheelZoom();\n offRequestZoomIn();\n offRequestZoomOut();\n offRequestZoomActualSize();\n offRequestZoomReset();\n outer.removeEventListener('pointerdown', onPointerDown);\n outer.removeEventListener('pointermove', onPointerMove);\n outer.removeEventListener('pointerup', onPointerUp);\n outer.removeEventListener('pointercancel', onPointerUp);\n unregisterGate();\n unregisterZoomStart();\n unregisterLeaveDecorator();\n reset();\n getImg()?.classList.remove('shoji-zoom-enabled');\n };\n },\n};\n"],"names":["createIconSwap","iconOff","iconOn","el","off","on","state","parseCssTime","value","first","_a","waitForTransitionEnd","target","cb","property","durationMs","done","finish","onEnd","event","ZOOM_IN_ICON","ZOOM_OUT_ICON","ZOOM_ACTUAL_SIZE_EXPAND_ICON","ZOOM_ACTUAL_SIZE_CONTRACT_ICON","clampScale","scale","min","max","IDENTITY_TRANSFORM","parseLinearTransform","transform","match","screenDeltaToLocal","dx","dy","m","det","localDeltaToScreen","trueOriginOffset","natural","localOriginScreen","pan","originOffset","pivotX","pivotY","fromPivot","clampEdge","contentPos","contentSize","containerPos","containerSize","minPos","contentScreenBounds","trueWidth","trueHeight","screenCorners","x","y","wrapperFrame","screen","xs","p","ys","clampPan","container","bounds","clampedLeft","clampedTop","screenDelta","localDelta","zoomTowardPoint","oldScale","newScale","anchorX","anchorY","origin","screenDx","screenDy","local","factor","ZOOM_EPSILON","isRealControl","node","ctx","gallery","maxScale","doubleTapScale","buttonStep","locale","zoomInLabel","zoomOutLabel","actualSizeLabel","pinchStartScale","getImg","media","child","boxOf","rect","ensureNatural","img","whenSettled","action","apply","emitChange","updateActualSizeIcon","actualSizeIconSwap","withTransition","run","afterEnd","zoomTo","targetScale","ceiling","animate","clampedScale","parentTransform","reset","wasEngaged","clearTransform","pendingLeaveTransform","pendingLeaveOrigin","captureLeaveTransform","markEnabled","toggleZoom","offPinchStart","offPinchMove","relative","centerX","centerY","offPinchEnd","offDoubleTap","offWheelZoom","deltaScale","offRequestZoomIn","zoomInStep","offRequestZoomOut","zoomOutStep","offRequestZoomActualSize","actualSizeToggle","offRequestZoomReset","panPointerId","lastX","lastY","outer","onPointerDown","onPointerMove","rawDx","rawDy","onPointerUp","buildButton","icon","label","button","centerAnchor","zoomInBtn","zoomOutBtn","actualSizeBtn","removeButtons","updateButtonVisibility","isVideo","removeShortcuts","offOpen","offBeforeSlide","offSlide","offBeforeClose","unregisterGate","unregisterZoomStart","unregisterLeaveDecorator","clonedMedia","clonedImg","remove"],"mappings":"gPAqBO,SAASA,EAAeC,EAAiBC,EAA0B,CACxE,MAAMC,EAAK,SAAS,cAAc,MAAM,EACxCA,EAAG,UAAY,kBAEf,MAAMC,EAAM,SAAS,cAAc,MAAM,EACzCA,EAAI,UAAY,iDAChBA,EAAI,UAAYH,EAEhB,MAAMI,EAAK,SAAS,cAAc,MAAM,EACxC,OAAAA,EAAG,UAAY,gDACfA,EAAG,UAAYH,EAEfC,EAAG,OAAOC,EAAKC,CAAE,EAEV,CACL,GAAAF,EACA,SAASG,EAAsB,CAC7BH,EAAG,UAAU,OAAO,sBAAuBG,CAAK,CAClD,CAAA,CAEJ,CC6BA,SAASC,EAAaC,EAAuB,OAC3C,MAAMC,IAAQC,EAAAF,EAAM,MAAM,GAAG,EAAE,CAAC,IAAlB,YAAAE,EAAqB,SAAU,GAC7C,OAAID,EAAM,SAAS,IAAI,EAAU,WAAWA,CAAK,EAC7CA,EAAM,SAAS,GAAG,EAAU,WAAWA,CAAK,EAAI,IAC7C,CACT,CA8KO,SAASE,EACdC,EACAC,EACAC,EAAW,YACL,CACN,MAAMC,EAAaR,EAAa,iBAAiBK,CAAM,EAAE,kBAAkB,EAC3E,IAAII,EAAO,GACX,MAAMC,EAAS,IAAY,CACrBD,IACJA,EAAO,GACPJ,EAAO,oBAAoB,gBAAiBM,CAAK,EACjDL,EAAA,EACF,EACMK,EAASC,GAAuB,CAChCA,EAAM,SAAWP,GAAWO,EAA0B,eAAiBL,GAAUG,EAAA,CACvF,EACAL,EAAO,iBAAiB,gBAAiBM,CAAK,EAC9C,WAAWD,EAAQF,EAAa,GAAG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,MAAA,MAAAnF,EAAU,UAAU,OAAO,qBAC7B,CACF,CACF"}
|
package/dist/shoji.css
CHANGED
|
@@ -449,6 +449,13 @@
|
|
|
449
449
|
|
|
450
450
|
--shoji-easing: cubic-bezier(0.4, 0, 0.2, 1);
|
|
451
451
|
--shoji-duration: 300ms;
|
|
452
|
+
/* A dedicated var, not a reuse of --shoji-duration: a toolbar icon
|
|
453
|
+
cross-fade (Fullscreen's enter/exit, Autoplay's play/pause, Zoom's
|
|
454
|
+
actual-size expand/contract, src/core/iconSwap.ts) reads as a snappy
|
|
455
|
+
state flip, not a UI transition on the same scale as opening/closing —
|
|
456
|
+
the same "reuse read as too slow/fast for a different purpose"
|
|
457
|
+
reasoning `--shoji-active-thumbnail-fade-duration` was split out for. */
|
|
458
|
+
--shoji-icon-swap-duration: 150ms;
|
|
452
459
|
/* The toolbar's own rendered height (44px button + top/bottom padding) —
|
|
453
460
|
defined before the caption sizing below since it now derives from
|
|
454
461
|
this. Also reserves space at the top of a provider embed (YouTube
|
|
@@ -523,6 +530,7 @@
|
|
|
523
530
|
@media (prefers-reduced-motion: reduce) {
|
|
524
531
|
:root {
|
|
525
532
|
--shoji-duration: 0ms;
|
|
533
|
+
--shoji-icon-swap-duration: 0ms;
|
|
526
534
|
}
|
|
527
535
|
}
|
|
528
536
|
|
|
@@ -756,6 +764,41 @@
|
|
|
756
764
|
pointer-events: none;
|
|
757
765
|
}
|
|
758
766
|
|
|
767
|
+
/* `src/core/iconSwap.ts` — a toolbar button whose icon reflects live state
|
|
768
|
+
(Fullscreen enter/exit, Autoplay play/pause, Zoom actual-size
|
|
769
|
+
expand/contract). Both icons stay in the DOM at once, exactly stacked;
|
|
770
|
+
the modifier class below only ever changes which one is opaque, so the
|
|
771
|
+
swap is a plain cross-fade with nothing being added/removed mid-transition
|
|
772
|
+
(no flash-of-no-icon between an old node's removal and a new one's
|
|
773
|
+
fill/stroke painting in). */
|
|
774
|
+
.shoji-icon-swap {
|
|
775
|
+
position: relative;
|
|
776
|
+
display: inline-flex;
|
|
777
|
+
width: 24px;
|
|
778
|
+
height: 24px;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
.shoji-icon-swap-icon {
|
|
782
|
+
position: absolute;
|
|
783
|
+
inset: 0;
|
|
784
|
+
display: flex;
|
|
785
|
+
align-items: center;
|
|
786
|
+
justify-content: center;
|
|
787
|
+
transition: opacity var(--shoji-icon-swap-duration, 150ms) var(--shoji-easing);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
.shoji-icon-swap-icon--on {
|
|
791
|
+
opacity: 0;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
.shoji-icon-swap--on .shoji-icon-swap-icon--off {
|
|
795
|
+
opacity: 0;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
.shoji-icon-swap--on .shoji-icon-swap-icon--on {
|
|
799
|
+
opacity: 1;
|
|
800
|
+
}
|
|
801
|
+
|
|
759
802
|
.shoji-slides {
|
|
760
803
|
position: relative;
|
|
761
804
|
flex: 1;
|
package/dist/shoji.js
CHANGED
|
@@ -3413,6 +3413,23 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3413
3413
|
};
|
|
3414
3414
|
}
|
|
3415
3415
|
};
|
|
3416
|
+
function createIconSwap(iconOff, iconOn) {
|
|
3417
|
+
const el = document.createElement("span");
|
|
3418
|
+
el.className = "shoji-icon-swap";
|
|
3419
|
+
const off = document.createElement("span");
|
|
3420
|
+
off.className = "shoji-icon-swap-icon shoji-icon-swap-icon--off";
|
|
3421
|
+
off.innerHTML = iconOff;
|
|
3422
|
+
const on = document.createElement("span");
|
|
3423
|
+
on.className = "shoji-icon-swap-icon shoji-icon-swap-icon--on";
|
|
3424
|
+
on.innerHTML = iconOn;
|
|
3425
|
+
el.append(off, on);
|
|
3426
|
+
return {
|
|
3427
|
+
el,
|
|
3428
|
+
setState(state) {
|
|
3429
|
+
el.classList.toggle("shoji-icon-swap--on", state);
|
|
3430
|
+
}
|
|
3431
|
+
};
|
|
3432
|
+
}
|
|
3416
3433
|
const PLAY_ICON = '<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>';
|
|
3417
3434
|
const PAUSE_ICON = '<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor"><path d="M7 5h4v14H7zM13 5h4v14h-4z"/></svg>';
|
|
3418
3435
|
function findPlayable(media) {
|
|
@@ -3507,7 +3524,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3507
3524
|
button.className = "shoji-toolbar-button shoji-autoplay-toggle";
|
|
3508
3525
|
button.setAttribute("aria-label", playLabel);
|
|
3509
3526
|
button.title = playLabel;
|
|
3510
|
-
|
|
3527
|
+
const iconSwap = createIconSwap(PLAY_ICON, PAUSE_ICON);
|
|
3528
|
+
button.appendChild(iconSwap.el);
|
|
3511
3529
|
const progress = document.createElement("div");
|
|
3512
3530
|
progress.className = "shoji-autoplay-progress";
|
|
3513
3531
|
progress.hidden = true;
|
|
@@ -3543,7 +3561,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3543
3561
|
}
|
|
3544
3562
|
function setButtonState(isPlaying) {
|
|
3545
3563
|
playing = isPlaying;
|
|
3546
|
-
|
|
3564
|
+
iconSwap.setState(isPlaying);
|
|
3547
3565
|
button.setAttribute("aria-label", isPlaying ? pauseLabel : playLabel);
|
|
3548
3566
|
button.title = isPlaying ? pauseLabel : playLabel;
|
|
3549
3567
|
updateToggleAvailability();
|
|
@@ -3799,7 +3817,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3799
3817
|
const button = document.createElement("button");
|
|
3800
3818
|
button.type = "button";
|
|
3801
3819
|
button.className = "shoji-toolbar-button";
|
|
3802
|
-
|
|
3820
|
+
const iconSwap = createIconSwap(EXPAND_ICON, COMPRESS_ICON);
|
|
3821
|
+
button.appendChild(iconSwap.el);
|
|
3803
3822
|
button.setAttribute("aria-label", enterLabel);
|
|
3804
3823
|
button.title = enterLabel;
|
|
3805
3824
|
button.setAttribute("aria-pressed", "false");
|
|
@@ -3807,7 +3826,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3807
3826
|
return currentFullscreenElement() === outer;
|
|
3808
3827
|
}
|
|
3809
3828
|
function setState(active) {
|
|
3810
|
-
|
|
3829
|
+
iconSwap.setState(active);
|
|
3811
3830
|
button.setAttribute("aria-label", active ? exitLabel : enterLabel);
|
|
3812
3831
|
button.title = active ? exitLabel : enterLabel;
|
|
3813
3832
|
button.setAttribute("aria-pressed", String(active));
|
|
@@ -4988,7 +5007,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4988
5007
|
};
|
|
4989
5008
|
const ZOOM_IN_ICON = '<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="10" cy="10" r="7"/><path d="M21 21l-5.5-5.5M10 7v6M7 10h6"/></svg>';
|
|
4990
5009
|
const ZOOM_OUT_ICON = '<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="10" cy="10" r="7"/><path d="M21 21l-5.5-5.5M7 10h6"/></svg>';
|
|
4991
|
-
const
|
|
5010
|
+
const ZOOM_ACTUAL_SIZE_EXPAND_ICON = '<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 9L3 3M3 8V3h5M15 15l6 6M21 16v5h-5"/></svg>';
|
|
5011
|
+
const ZOOM_ACTUAL_SIZE_CONTRACT_ICON = '<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3l6 6M9 3v6H3M21 21l-6-6M15 21v-6h6"/></svg>';
|
|
4992
5012
|
function clampScale(scale, min, max) {
|
|
4993
5013
|
return Math.min(max, Math.max(min, scale));
|
|
4994
5014
|
}
|
|
@@ -5150,6 +5170,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5150
5170
|
}
|
|
5151
5171
|
function emitChange() {
|
|
5152
5172
|
ctx.emit("zoomChange", { index: gallery.currentIndex, scale });
|
|
5173
|
+
updateActualSizeIcon();
|
|
5174
|
+
}
|
|
5175
|
+
function updateActualSizeIcon() {
|
|
5176
|
+
actualSizeIconSwap.setState(scale > ZOOM_EPSILON);
|
|
5153
5177
|
}
|
|
5154
5178
|
function withTransition(img, run, afterEnd) {
|
|
5155
5179
|
img.style.transition = "transform var(--shoji-duration) var(--shoji-easing)";
|
|
@@ -5192,6 +5216,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5192
5216
|
natural = null;
|
|
5193
5217
|
container = null;
|
|
5194
5218
|
originOffset = null;
|
|
5219
|
+
updateActualSizeIcon();
|
|
5195
5220
|
if (wasEngaged) emitChange();
|
|
5196
5221
|
const img = getImg();
|
|
5197
5222
|
if (!img) return;
|
|
@@ -5320,7 +5345,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5320
5345
|
}
|
|
5321
5346
|
const zoomInBtn = buildButton(ZOOM_IN_ICON, zoomInLabel);
|
|
5322
5347
|
const zoomOutBtn = buildButton(ZOOM_OUT_ICON, zoomOutLabel);
|
|
5323
|
-
const actualSizeBtn =
|
|
5348
|
+
const actualSizeBtn = document.createElement("button");
|
|
5349
|
+
actualSizeBtn.type = "button";
|
|
5350
|
+
actualSizeBtn.className = "shoji-toolbar-button";
|
|
5351
|
+
const actualSizeIconSwap = createIconSwap(
|
|
5352
|
+
ZOOM_ACTUAL_SIZE_EXPAND_ICON,
|
|
5353
|
+
ZOOM_ACTUAL_SIZE_CONTRACT_ICON
|
|
5354
|
+
);
|
|
5355
|
+
actualSizeBtn.appendChild(actualSizeIconSwap.el);
|
|
5356
|
+
actualSizeBtn.setAttribute("aria-label", actualSizeLabel);
|
|
5357
|
+
actualSizeBtn.title = actualSizeLabel;
|
|
5324
5358
|
zoomInBtn.addEventListener("click", zoomInStep);
|
|
5325
5359
|
zoomOutBtn.addEventListener("click", zoomOutStep);
|
|
5326
5360
|
actualSizeBtn.addEventListener("click", actualSizeToggle);
|
|
@@ -5407,7 +5441,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5407
5441
|
};
|
|
5408
5442
|
}
|
|
5409
5443
|
};
|
|
5410
|
-
const version = "0.1.0-beta.
|
|
5444
|
+
const version = "0.1.0-beta.14";
|
|
5411
5445
|
const Shoji = Object.assign(Gallery, {
|
|
5412
5446
|
Autoplay,
|
|
5413
5447
|
Layout,
|