/* react-motion-lightbox * * Theme it with the variables on `.rml`. Everything else is layout the * component relies on: the track is sized from `.rml-view`'s box, and pictures * are centred with `translate` so `transform` stays free for Motion. */ .rml, .rml-gallery { --rml-backdrop: rgb(0 0 0 / 0.92); /* How much the page behind is blurred once the lightbox is open. */ --rml-blur: 0px; --rml-color: #f4f4f5; --rml-muted: #a1a1aa; --rml-border: rgb(255 255 255 / 0.2); --rml-accent: #e4c590; --rml-focus: #fde68a; --rml-padding: 1rem clamp(1rem, 4vw, 3rem); --rml-gap: 0.75rem; --rml-button-size: 2.75rem; --rml-caption-size: 0.75rem; --rml-thumb-size: 3.5rem; --rml-thumb-radius: 0.375rem; /* The frame around the current thumbnail. */ --rml-frame: #e0b04a; --rml-frame-width: 2px; --rml-ease: cubic-bezier(0.16, 1, 0.3, 1); } /* Pictures can't be selected or dragged out, in either. Safari reads the * -webkit- property; the others need the dragstart handlers in the components. */ .rml img, .rml video, .rml-gallery img, .rml-gallery video { user-select: none; -webkit-user-drag: none; } .rml-gallery-box, .rml-thumbs { user-select: none; } .rml[open] { /* `clip`, not `hidden`: a hidden box can still be scrolled by script, and a * picture parked off screen mid-slide gives it somewhere to scroll to. */ position: fixed; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: var(--rml-gap); width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: var(--rml-padding); border: 0; background: none; color: var(--rml-color); overflow: clip; /* `--rml-p` runs from 0 to 1 as the picture opens and back as it closes * (Lightbox.tsx), so the blur and the backdrop rise and settle with it. */ backdrop-filter: blur(calc(var(--rml-blur) * var(--rml-p, 1))); } .rml[open]::before { content: ''; position: fixed; inset: 0; z-index: -1; background: var(--rml-backdrop); opacity: var(--rml-p, 1); } /* While the picture moves in or out, nothing takes a pointer: no drag, zoom, * click or button (Lightbox.tsx keeps keys and the wheel out too). */ .rml[data-moving] > * { pointer-events: none; } .rml::backdrop { background: transparent; } /* The page stays put while a lightbox is open. The scrollbar's space is kept, * so nothing behind it shifts sideways. */ html:has(.rml[open]) { overflow: hidden; scrollbar-gutter: stable; } /* The chrome fades in with the dialog and out as it closes, so only the * picture travels back into the thumbnail. */ .rml-chrome { animation: rml-in 220ms var(--rml-ease); transition: opacity 220ms var(--rml-ease); } .rml[data-leaving] .rml-chrome, .rml[data-leaving] .rml-nav { opacity: 0; } @keyframes rml-in { from { opacity: 0; } } .rml-top { display: flex; align-items: center; justify-content: space-between; gap: var(--rml-gap); min-width: 0; } .rml-title { min-width: 0; } .rml-toolbar { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; } .rml-button { /* Above a zoomed picture. */ position: relative; z-index: 2; display: grid; place-items: center; width: var(--rml-button-size); height: var(--rml-button-size); padding: 0; border: 1px solid var(--rml-border); border-radius: 999px; background: transparent; color: var(--rml-muted); cursor: pointer; transition: color 120ms var(--rml-ease), border-color 120ms var(--rml-ease), opacity 220ms var(--rml-ease); } .rml-button:hover { color: var(--rml-color); border-color: var(--rml-accent); } .rml-button:focus-visible { outline: 2px solid var(--rml-focus); outline-offset: 2px; color: var(--rml-color); } .rml-button:active { translate: 0 1px; } /* Above the bars, so a picture on its way to or from the thumbnail passes * over the caption and the thumbnails, not under them. The buttons stay on top. */ .rml-stage { position: relative; z-index: 1; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--rml-gap); min-height: 0; } /* The track. Every touch is ours: one finger moves the track (or, zoomed in, * the picture), two pinch it. The browser's own pinch would zoom the page. A * zoomed picture stops at the stage's top and bottom; sideways it is left * open, so pictures slide in and out from the screen's edges. */ .rml-view { position: relative; display: grid; place-items: center; height: 100%; min-width: 0; touch-action: none; user-select: none; overflow: visible clip; /* Pinned to the middle column. With one item there are no arrows to fill * the side columns, and auto-placed it landed in the first one, 0px wide. */ grid-column: 2; } .rml-view[data-many] { cursor: pointer; } /* The current item's box: what opens out of the thumbnail and closes back * into it. Not clipped otherwise, so neighbours can sit beside it. */ .rml-frame { position: relative; } /* Each picture centred with `translate`, on a layer of its own: painted into * the page's layer, one sliding past left 1px stripes of itself behind. */ .rml-media { will-change: transform, opacity; position: absolute; top: 50%; left: 50%; translate: -50% -50%; display: block; max-width: none; object-fit: cover; -webkit-user-drag: none; } .rml-video { overflow: hidden; } .rml-video > * { width: 100%; height: 100%; } .rml-video > video { display: block; object-fit: cover; } .rml-foot { display: grid; justify-items: center; gap: var(--rml-gap); min-width: 0; } .rml-foot:empty { display: none; } /* One line, so the row under it never shifts as captions change length. A * thumbnail's caption shown as a preview is dimmed: "this one if you click". */ .rml-caption { display: flex; align-items: baseline; gap: 1rem; max-width: 100%; margin: 0; font-size: var(--rml-caption-size); line-height: 1.5; color: var(--rml-muted); text-align: center; transition: opacity 120ms var(--rml-ease); } .rml-caption[data-peek] { opacity: 0.6; } .rml-caption-main { display: grid; min-width: 0; } .rml-count { flex: none; font-variant-numeric: tabular-nums; } .rml-thumbs { --rml-row-pad: 8px; position: relative; display: flex; gap: 0.5rem; max-width: 100%; padding: var(--rml-row-pad); overflow-x: auto; scrollbar-width: none; } .rml-thumb { flex: none; width: var(--rml-thumb-size); height: var(--rml-thumb-size); padding: 0; border: 0; border-radius: var(--rml-thumb-radius); overflow: hidden; background: none; cursor: pointer; /* Lit by the square, live, so no transition: one would lag behind a drag. */ opacity: calc(0.45 + 0.55 * var(--rml-lit, 0)); scale: calc(1 + 0.1 * var(--rml-lit, 0)); } /* Hover lifts one in place, never pushing its neighbours: the square follows * the thumbnails' positions. */ .rml-thumb:hover, .rml-thumb:focus-visible { opacity: 1; scale: 1.1; transition: opacity 120ms var(--rml-ease), scale 220ms var(--rml-ease); } .rml-thumb:focus-visible { outline: 2px solid var(--rml-focus); outline-offset: 2px; } .rml-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; } /* The square marking the current item moves with the track. */ .rml-thumb-layer { position: absolute; top: 0; left: 0; height: 100%; overflow: clip; pointer-events: none; z-index: 1; } /* Outside the lit thumbnail, which is 10% bigger, with 2px of air between. */ .rml-thumb-frame { --grow: calc(var(--rml-thumb-size) * 0.05 + 2px + var(--rml-frame-width)); box-sizing: border-box; position: absolute; top: calc(var(--rml-row-pad) - var(--grow)); left: calc(-1 * var(--grow)); width: calc(var(--rml-thumb-size) + 2 * var(--grow)); height: calc(var(--rml-thumb-size) + 2 * var(--grow)); border: var(--rml-frame-width) solid var(--rml-frame); border-radius: calc(var(--rml-thumb-radius) + var(--grow)); } /* A touch screen swipes; the arrows only take room from the picture. */ @media (hover: none) { .rml-stage { grid-template-columns: minmax(0, 1fr); } .rml-view { grid-column: 1; } .rml-nav { display: none; } } /* The small lightbox on the page (Gallery.tsx). It sits on the page, so its * text and buttons take the page's colour. */ .rml-gallery { --rml-color: currentColor; --rml-muted: currentColor; --rml-border: color-mix(in srgb, currentColor 25%, transparent); --rml-caption-size: 0.875rem; display: grid; gap: var(--rml-gap); min-width: 0; } .rml-gallery-box { position: relative; max-width: 100%; touch-action: pan-y; cursor: grab; } .rml-gallery-box:active { cursor: grabbing; } /* A few pixels out, so the focus ring survives. */ .rml-gallery-box[data-clip] { clip-path: inset(-6px); } /* Its width is set inline: the box's, less any peek at the next picture. */ .rml-gallery-slide { will-change: transform, opacity; position: absolute; top: 0; bottom: 0; left: 0; padding: 0; border: 0; overflow: hidden; background: none; cursor: inherit; } .rml-gallery-slide:focus-visible { outline: 2px solid var(--rml-focus); outline-offset: 2px; } .rml-gallery-slide img { position: absolute; display: block; max-width: none; user-select: none; -webkit-user-drag: none; } .rml-gallery-video, .rml-gallery-video > * { position: absolute; inset: 0; width: 100%; height: 100%; } .rml-gallery-foot { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--rml-gap); font-size: var(--rml-caption-size); } .rml-gallery-caption { min-width: 0; margin: 0; color: var(--rml-muted); } .rml-gallery-nav { display: flex; flex: none; align-items: center; gap: 0.25rem; } .rml-gallery-nav .rml-count { min-width: 3.5em; text-align: center; } @media (prefers-reduced-motion: reduce) { .rml-chrome { animation: none; } }