Components Data display
Exhibit gallery
Walk along a wall of framed prints and open any work for a closer look.
Quiet Forms
06 worksSelect a work to view it. Use the left and right arrow keys to explore. Press Escape to return to the wall.
The ribs of a single leaf stretch across the wall. The small chips in the plaster interrupt the shadow at its edges.
The stair wraps around an opening just wide enough to hold the light. A pale handrail traces its way inward.
Light passes through the middle of the vessel and picks out the grit along its rim.
The water catches the pale sky in narrow strips. Each approaching wave briefly breaks one strip in two.
The gaps between columns almost vanish in the distance. Their shadows keep the spacing visible on the floor.
One crease turns a flat sheet into a landscape. The soft grain of the paper still shows in the deepest fold.
Usage
Set Title to the exhibition name. Each item in Items takes a Title, ImageURL, and descriptive Alt text. Add a Caption and Description for the wall label. LinkURL and LinkLabel can point to a work’s own page. Serve the images from URLs available to your application. Enable Pinned to travel along the wall as the page scrolls. Drag or use the arrows to browse, and select a frame to see it straight on. Use Left and Right in the viewer. Escape returns you to the wall. The works remain available in reading order when JavaScript is off.
Register exhibit-gallery with Head and pass its properties to Render. Go setup guide
Go usage
err := mono.UI.Render(w, "exhibit-gallery", mono.Props{
"Items": []any{
map[string]any{
"Alt": "A fan-shaped palm shadow radiates across a sunlit plaster wall.",
"Caption": "Study of light on plaster",
"Description": "The ribs of a single leaf stretch across the wall. The small chips in the plaster interrupt the shadow at its edges.",
"ImageURL": "../components/exhibitions/quiet-forms/fan-light.webp",
"Title": "Fan Light",
},
map[string]any{
"Alt": "Concrete steps spiral around a dark circular opening.",
"Caption": "Concrete stair study",
"Description": "The stair wraps around an opening just wide enough to hold the light. A pale handrail traces its way inward.",
"ImageURL": "../components/exhibitions/quiet-forms/inner-turn.webp",
"Title": "Inner Turn",
},
map[string]any{
"Alt": "A rough stoneware bottle with an open center rests on a pale stone slab.",
"Caption": "Stoneware still life",
"Description": "Light passes through the middle of the vessel and picks out the grit along its rim.",
"ImageURL": "../components/exhibitions/quiet-forms/hollow-body.webp",
"Title": "Hollow Body",
},
map[string]any{
"Alt": "Small waves cross a band of reflected sunlight beneath a misty horizon.",
"Caption": "Sea study at first light",
"Description": "The water catches the pale sky in narrow strips. Each approaching wave briefly breaks one strip in two.",
"ImageURL": "../components/exhibitions/quiet-forms/tideline.webp",
"Title": "Tideline",
},
map[string]any{
"Alt": "Stone columns recede along a walkway crossed by long diagonal shadows.",
"Caption": "Colonnade in afternoon light",
"Description": "The gaps between columns almost vanish in the distance. Their shadows keep the spacing visible on the floor.",
"ImageURL": "../components/exhibitions/quiet-forms/long-interval.webp",
"Title": "Long Interval",
},
map[string]any{
"Alt": "Light and dark triangular folds meet at a sharp crease in white paper.",
"Caption": "Folded paper under side light",
"Description": "One crease turns a flat sheet into a landscape. The soft grain of the paper still shows in the deepest fold.",
"ImageURL": "../components/exhibitions/quiet-forms/paper-ridge.webp",
"Title": "Paper Ridge",
},
},
"Pinned": true,
"Title": "Quiet Forms",
})Rendered HTML
<section id="demo-exhibit-gallery" data-mono="exhibit-gallery" data-exhibit-pinned aria-labelledby="demo-exhibit-gallery-name">
<div class="mu-exhibit-room" data-exhibit-room>
<header class="mu-exhibit-heading">
<h2 id="demo-exhibit-gallery-name">Quiet Forms</h2>
<span>06 works</span>
</header>
<div class="mu-exhibit-stage" data-exhibit-stage role="group" aria-label="Gallery wall" aria-describedby="demo-exhibit-gallery-instructions">
<p class="mu-sr-only" id="demo-exhibit-gallery-instructions">Select a work to view it. Use the left and right arrow keys to explore. Press Escape to return to the wall.</p>
<div class="mu-exhibit-architecture" aria-hidden="true"></div>
<figure class="mu-exhibit-frame" data-exhibit-frame>
<a class="mu-exhibit-print" data-exhibit-open href="../components/exhibitions/quiet-forms/fan-light.webp" aria-label="View Fan Light. A fan-shaped palm shadow radiates across a sunlit plaster wall.">
<img src="../components/exhibitions/quiet-forms/fan-light.webp" alt="A fan-shaped palm shadow radiates across a sunlit plaster wall." decoding="async" draggable="false">
</a>
<figcaption>
<strong data-exhibit-item-title>Fan Light</strong>
<span data-exhibit-item-caption>Study of light on plaster</span>
<p data-exhibit-item-description>The ribs of a single leaf stretch across the wall. The small chips in the plaster interrupt the shadow at its edges.</p>
</figcaption>
</figure>
<figure class="mu-exhibit-frame" data-exhibit-frame>
<a class="mu-exhibit-print" data-exhibit-open href="../components/exhibitions/quiet-forms/inner-turn.webp" aria-label="View Inner Turn. Concrete steps spiral around a dark circular opening.">
<img src="../components/exhibitions/quiet-forms/inner-turn.webp" alt="Concrete steps spiral around a dark circular opening." decoding="async" draggable="false">
</a>
<figcaption>
<strong data-exhibit-item-title>Inner Turn</strong>
<span data-exhibit-item-caption>Concrete stair study</span>
<p data-exhibit-item-description>The stair wraps around an opening just wide enough to hold the light. A pale handrail traces its way inward.</p>
</figcaption>
</figure>
<figure class="mu-exhibit-frame" data-exhibit-frame>
<a class="mu-exhibit-print" data-exhibit-open href="../components/exhibitions/quiet-forms/hollow-body.webp" aria-label="View Hollow Body. A rough stoneware bottle with an open center rests on a pale stone slab.">
<img src="../components/exhibitions/quiet-forms/hollow-body.webp" alt="A rough stoneware bottle with an open center rests on a pale stone slab." decoding="async" draggable="false">
</a>
<figcaption>
<strong data-exhibit-item-title>Hollow Body</strong>
<span data-exhibit-item-caption>Stoneware still life</span>
<p data-exhibit-item-description>Light passes through the middle of the vessel and picks out the grit along its rim.</p>
</figcaption>
</figure>
<figure class="mu-exhibit-frame" data-exhibit-frame>
<a class="mu-exhibit-print" data-exhibit-open href="../components/exhibitions/quiet-forms/tideline.webp" aria-label="View Tideline. Small waves cross a band of reflected sunlight beneath a misty horizon.">
<img src="../components/exhibitions/quiet-forms/tideline.webp" alt="Small waves cross a band of reflected sunlight beneath a misty horizon." loading="lazy" decoding="async" draggable="false">
</a>
<figcaption>
<strong data-exhibit-item-title>Tideline</strong>
<span data-exhibit-item-caption>Sea study at first light</span>
<p data-exhibit-item-description>The water catches the pale sky in narrow strips. Each approaching wave briefly breaks one strip in two.</p>
</figcaption>
</figure>
<figure class="mu-exhibit-frame" data-exhibit-frame>
<a class="mu-exhibit-print" data-exhibit-open href="../components/exhibitions/quiet-forms/long-interval.webp" aria-label="View Long Interval. Stone columns recede along a walkway crossed by long diagonal shadows.">
<img src="../components/exhibitions/quiet-forms/long-interval.webp" alt="Stone columns recede along a walkway crossed by long diagonal shadows." loading="lazy" decoding="async" draggable="false">
</a>
<figcaption>
<strong data-exhibit-item-title>Long Interval</strong>
<span data-exhibit-item-caption>Colonnade in afternoon light</span>
<p data-exhibit-item-description>The gaps between columns almost vanish in the distance. Their shadows keep the spacing visible on the floor.</p>
</figcaption>
</figure>
<figure class="mu-exhibit-frame" data-exhibit-frame>
<a class="mu-exhibit-print" data-exhibit-open href="../components/exhibitions/quiet-forms/paper-ridge.webp" aria-label="View Paper Ridge. Light and dark triangular folds meet at a sharp crease in white paper.">
<img src="../components/exhibitions/quiet-forms/paper-ridge.webp" alt="Light and dark triangular folds meet at a sharp crease in white paper." loading="lazy" decoding="async" draggable="false">
</a>
<figcaption>
<strong data-exhibit-item-title>Paper Ridge</strong>
<span data-exhibit-item-caption>Folded paper under side light</span>
<p data-exhibit-item-description>One crease turns a flat sheet into a landscape. The soft grain of the paper still shows in the deepest fold.</p>
</figcaption>
</figure>
<div class="mu-exhibit-controls" data-exhibit-controls hidden>
<div class="mu-exhibit-plaque">
<span class="mu-exhibit-count" data-exhibit-count></span>
<h3 data-exhibit-title></h3>
<p class="mu-exhibit-caption" data-exhibit-caption></p>
<p class="mu-exhibit-description" data-exhibit-description hidden></p>
<a class="mu-exhibit-link" data-exhibit-link hidden></a>
</div>
<div class="mu-exhibit-arrows" role="group" aria-label="Browse works">
<button type="button" data-exhibit-prev aria-label="Previous work" title="Previous work">
<svg viewBox="0 0 24 24" width="19" height="19" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5m6-6-6 6 6 6"/></svg>
</button>
<button type="button" data-exhibit-next aria-label="Next work" title="Next work">
<svg viewBox="0 0 24 24" width="19" height="19" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14m-6-6 6 6-6 6"/></svg>
</button>
</div>
<button class="mu-exhibit-close" type="button" data-exhibit-close aria-label="Close artwork" title="Close artwork" hidden>
<svg viewBox="0 0 24 24" width="19" height="19" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><path d="m6 6 12 12M18 6 6 18"/></svg>
</button>
</div>
<p class="mu-sr-only" data-exhibit-status role="status" aria-live="polite" aria-atomic="true"></p>
</div>
</div>
</section>Go template
<section id="{{.ID}}" data-mono="exhibit-gallery"{{if .Pinned}} data-exhibit-pinned{{end}} aria-labelledby="{{.ID}}-name">
<div class="mu-exhibit-room" data-exhibit-room>
<header class="mu-exhibit-heading">
<h2 id="{{.ID}}-name">{{or .Title "Exhibition"}}</h2>
{{with .Items}}<span>{{printf "%02d" (len .)}} {{if eq (len .) 1}}work{{else}}works{{end}}</span>{{end}}
</header>
{{if .Items}}
<div class="mu-exhibit-stage" data-exhibit-stage role="group" aria-label="Gallery wall" aria-describedby="{{.ID}}-instructions">
<p class="mu-sr-only" id="{{.ID}}-instructions">Select a work to view it. Use the left and right arrow keys to explore. Press Escape to return to the wall.</p>
<div class="mu-exhibit-architecture" aria-hidden="true"></div>
{{range $i, $work := .Items}}
<figure class="mu-exhibit-frame" data-exhibit-frame>
<a class="mu-exhibit-print" data-exhibit-open href="{{.ImageURL}}" aria-label="View {{.Title}}{{with .Alt}}. {{.}}{{end}}">
<img src="{{.ImageURL}}" alt="{{.Alt}}"{{if gt $i 2}} loading="lazy"{{end}} decoding="async" draggable="false"{{with .Width}} width="{{.}}"{{end}}{{with .Height}} height="{{.}}"{{end}}>
</a>
<figcaption>
<strong data-exhibit-item-title>{{.Title}}</strong>
{{with .Caption}}<span data-exhibit-item-caption>{{.}}</span>{{end}}
{{with .Description}}<p data-exhibit-item-description>{{.}}</p>{{end}}
{{with .LinkURL}}<a data-exhibit-item-link href="{{.}}">{{or $work.LinkLabel "View work"}}</a>{{end}}
</figcaption>
</figure>
{{end}}
<div class="mu-exhibit-controls" data-exhibit-controls hidden>
<div class="mu-exhibit-plaque">
<span class="mu-exhibit-count" data-exhibit-count></span>
<h3 data-exhibit-title></h3>
<p class="mu-exhibit-caption" data-exhibit-caption></p>
<p class="mu-exhibit-description" data-exhibit-description hidden></p>
<a class="mu-exhibit-link" data-exhibit-link hidden></a>
</div>
<div class="mu-exhibit-arrows" role="group" aria-label="Browse works">
<button type="button" data-exhibit-prev aria-label="Previous work" title="Previous work">
<svg viewBox="0 0 24 24" width="19" height="19" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5m6-6-6 6 6 6"/></svg>
</button>
<button type="button" data-exhibit-next aria-label="Next work" title="Next work">
<svg viewBox="0 0 24 24" width="19" height="19" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14m-6-6 6 6-6 6"/></svg>
</button>
</div>
<button class="mu-exhibit-close" type="button" data-exhibit-close aria-label="Close artwork" title="Close artwork" hidden>
<svg viewBox="0 0 24 24" width="19" height="19" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><path d="m6 6 12 12M18 6 6 18"/></svg>
</button>
</div>
<p class="mu-sr-only" data-exhibit-status role="status" aria-live="polite" aria-atomic="true"></p>
</div>
{{else}}<p class="mu-exhibit-empty">No works on display.</p>{{end}}
</div>
</section>Component CSS
[data-mono="exhibit-gallery"] {
--exhibit-paper: #f4f4f4;
--exhibit-mono: ui-monospace, SFMono-Regular, Consolas, monospace;
position: relative; width: 100%; container-type: inline-size; background: var(--exhibit-paper);
}
.mu-exhibit-room { position: relative; background: var(--exhibit-paper); }
.mu-exhibit-heading {
display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
padding: .85rem clamp(1.1rem, 3cqi, 2.6rem); border-bottom: 1px solid #c8c8c8;
}
.mu-exhibit-heading h2 { font: 500 clamp(1.35rem, 3cqi, 1.9rem)/1.1 Georgia, serif; letter-spacing: -.045em; }
.mu-exhibit-heading > span, .mu-exhibit-count { font: .66rem/1.2 var(--exhibit-mono); letter-spacing: .065em; text-transform: uppercase; }
.mu-exhibit-heading > span { color: #545454; white-space: nowrap; }
.mu-exhibit-stage { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,12rem),1fr)); gap: 1.4rem; padding: 1.2rem; }
.mu-exhibit-frame { margin: 0; min-width: 0; }
.mu-exhibit-print { position: relative; display: block; color: inherit; background: #eee; }
.mu-exhibit-print img { display: block; width: 100%; height: auto; filter: grayscale(1); }
.mu-exhibit-frame figcaption { display: grid; gap: .3rem; margin-top: .5rem; font-size: .85rem; }
.mu-exhibit-frame figcaption strong { font-family: Georgia, serif; font-size: 1.15rem; }
.mu-exhibit-frame figcaption a, .mu-exhibit-link { text-decoration: underline; text-underline-offset: .18em; }
.mu-exhibit-empty { padding: 2rem 1.2rem; }
.mu-exhibit-architecture { display: none; }
[data-exhibit-pinned][data-enhanced] > .mu-exhibit-room { position: sticky; top: var(--exhibit-sticky-top, 0px); }
[data-exhibit-pinned][data-enhanced]::after { content: ""; display: block; height: var(--exhibit-travel, 0px); }
[data-enhanced] .mu-exhibit-stage {
position: relative; isolation: isolate; display: block; padding: 0; overflow: hidden;
height: var(--exhibit-stage-height, clamp(23rem, 63cqi, 37rem)); touch-action: pan-y pinch-zoom;
background: #dedede; cursor: grab;
}
[data-enhanced][data-dragging] .mu-exhibit-stage, [data-dragging] .mu-exhibit-print { cursor: grabbing; }
[data-viewing] .mu-exhibit-stage { cursor: default; }
[data-enhanced] .mu-exhibit-architecture {
display: block; position: absolute; inset: 0; pointer-events: none;
background: radial-gradient(ellipse at 23% 32%, #f3f3f3, transparent 70%), linear-gradient(115deg,#cecece,#e5e5e5 65%,#cacaca);
}
.mu-exhibit-architecture::before, .mu-exhibit-architecture::after { content: ""; position: absolute; inset: 0; }
.mu-exhibit-architecture::before { background: #f5f5f5; clip-path: polygon(0 122%,100% 62%,100% 100%,0 100%); }
.mu-exhibit-architecture::after {
background: linear-gradient(12deg,#c0c0c0,#a5a5a5); clip-path: polygon(0 124%,100% 63%,100% 100%,0 100%);
}
[data-enhanced] .mu-exhibit-frame { position: absolute; margin: 0; transform-origin: center; opacity: var(--exhibit-opacity,1); }
[data-enhanced] .mu-exhibit-frame figcaption { display: none; }
[data-enhanced] .mu-exhibit-print {
width: 100%; height: 100%; border: clamp(2px, .48cqi, 6px) solid #242424; border-radius: 1px;
background: #e1e1e1; box-shadow: -2px 1px 0 #474747, 3px 4px 3px #0003, 7px 12px 11px #0003;
-webkit-user-drag: none; user-select: none; cursor: zoom-in;
}
[data-enhanced] .mu-exhibit-print img { height: 100%; object-fit: cover; }
[data-viewing] .mu-exhibit-frame[data-current] .mu-exhibit-print { cursor: zoom-out; box-shadow: 0 3px 8px #0002, 4px 15px 19px #0003; }
[data-viewing] .mu-exhibit-frame[data-current] img { object-fit: contain; }
.mu-exhibit-controls { position: absolute; inset: 0; z-index: 1000; pointer-events: none; }
.mu-exhibit-controls :is(a,button) { pointer-events: auto; }
.mu-exhibit-plaque {
position: absolute; isolation: isolate; left: clamp(1.1rem, 4cqi, 3.3rem);
bottom: clamp(1rem, 3.5cqi, 2.6rem); max-width: min(65%, 23rem); overflow-wrap: anywhere;
}
[data-enhanced]:not([data-viewing]) .mu-exhibit-plaque {
padding: .85rem 1.15rem 1rem; max-width: min(23rem, calc(100% - 8rem));
background: #f8f8f8; color: #181818; border: 1px solid #d6d6d6;
box-shadow: 1px 2px 4px #0002;
}
.mu-exhibit-count { color: #4b4b4b; }
.mu-exhibit-plaque h3 { margin: .35rem 0 0; font: 500 clamp(1.5rem, 3.8cqi, 2.65rem)/1.06 Georgia, serif; letter-spacing: -.045em; }
.mu-exhibit-caption { margin-top: .38rem; color: #373737; font-size: clamp(.75rem, 1.65cqi, .92rem); line-height: 1.35; }
.mu-exhibit-description { margin-top: .8rem; line-height: 1.5; font-size: clamp(.76rem, 1.55cqi, .94rem); }
.mu-exhibit-link { display: inline-block; margin-top: .6rem; color: inherit; font-size: .85rem; }
.mu-exhibit-arrows { position: absolute; right: clamp(1rem, 3.5cqi, 2.6rem); bottom: clamp(1rem, 3.5cqi, 2.6rem); display: flex; gap: .45rem; }
.mu-exhibit-controls button {
display: grid; place-items: center; width: 2.75rem; height: 2.75rem; padding: 0; border-radius: 50%;
border: 1px solid #a7a7a7; color: #121212; background: #f4f4f4e8;
}
.mu-exhibit-controls button:hover:where(:not(:disabled)) { background: #fff; border-color: #3c3c3c; }
.mu-exhibit-close { position: absolute; top: .8rem; right: .8rem; }
[data-viewing] .mu-exhibit-plaque { left: 5cqi; bottom: 15%; width: 28%; max-height: 70%; overflow-y: auto; pointer-events: auto; scrollbar-width: thin; }
[data-viewing] .mu-exhibit-arrows { left: 5cqi; right: auto; bottom: 4%; }
@media (prefers-reduced-motion: no-preference) {
[data-enhanced]:not([data-exhibit-moving]):not([data-dragging]) .mu-exhibit-frame {
transition: left 440ms ease, top 440ms ease, width 440ms ease, height 440ms ease, transform 440ms ease, opacity 320ms ease;
}
}
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
[data-enhanced]:not([data-viewing]):not([data-dragging]) .mu-exhibit-print { transition: transform 180ms ease, box-shadow 180ms ease; }
[data-enhanced]:not([data-viewing]):not([data-dragging]) .mu-exhibit-print:hover {
transform: translateY(-3px); box-shadow: -2px 1px 0 #474747, 3px 6px 6px #0003, 8px 16px 16px #0003;
}
}
@container (max-width: 33rem) {
[data-enhanced] .mu-exhibit-stage { height: var(--exhibit-stage-height, clamp(24rem, 108cqi, 31rem)); }
.mu-exhibit-heading { padding: .75rem 1rem; }
[data-viewing] .mu-exhibit-plaque { left: 1rem; bottom: 1rem; width: calc(100% - 7.7rem); max-width: none; max-height: 29%; }
[data-viewing] .mu-exhibit-arrows { left: auto; right: 1rem; bottom: 1rem; }
[data-viewing] .mu-exhibit-plaque h3 { margin-top: .15rem; font-size: 1.45rem; }
[data-viewing] .mu-exhibit-description { margin-top: .35rem; font-size: .75rem; }
}
@media (forced-colors: active) {
.mu-exhibit-controls button, [data-enhanced] .mu-exhibit-print { border: 2px solid ButtonText; }
.mu-exhibit-plaque { background: Canvas; color: CanvasText; }
}JavaScript module
const clamp = (value, low, high) => Math.max(low, Math.min(high, value));
const modulo = (value, size) => ((value % size) + size) % size;
export function mount(root) {
const find = name => root.querySelector('[data-exhibit-' + name + ']');
const stage = find('stage');
const room = find('room');
const frames = stage ? [...stage.querySelectorAll('[data-exhibit-frame]')] : [];
const items = frames.map(frame => ({
frame,
link: frame.querySelector('[data-exhibit-open]'),
img: frame.querySelector('img'),
title: frame.querySelector('[data-exhibit-item-title]')?.textContent.trim() || '',
caption: frame.querySelector('[data-exhibit-item-caption]')?.textContent.trim() || '',
description: frame.querySelector('[data-exhibit-item-description]')?.textContent.trim() || '',
destination: frame.querySelector('[data-exhibit-item-link]'),
}));
if (!items.length || items.some(item => !item.link || !item.img)) return;
const count = items.length;
const reduced = matchMedia('(prefers-reduced-motion: reduce)');
const prev = find('prev'), next = find('next'), close = find('close');
const title = find('title'), caption = find('caption'), description = find('description');
const destination = find('link'), counter = find('count'), status = find('status');
const pinned = root.hasAttribute('data-exhibit-pinned') && room && count > 1;
let position = 0, target = 0, selected = -1, viewing = false;
let width = 0, height = 0, travel = 0, cycle = 1;
let tween = 0, wheelTimer = 0, scrollFrame = 0, measureFrame = 0, drag = null, suppressClick = false;
let lastProgress = null, anchorProgress = 0, anchorWork = 0;
const slots = [], centers = [], ratios = [];
const numbered = value => String(value).padStart(2, '0');
function geometry() {
width = stage.clientWidth;
height = stage.clientHeight;
cycle = 0;
items.forEach(({img}, i) => {
const w = img.naturalWidth || Number(img.getAttribute('width'));
const h = img.naturalHeight || Number(img.getAttribute('height'));
ratios[i] = w > 0 && h > 0 ? w / h : .8;
slots[i] = clamp(ratios[i], .5, 1.8) / .9;
centers[i] = cycle + slots[i] / 2;
cycle += slots[i] + .1;
});
if (pinned) {
travel = Math.round(Math.min(count - 1, 8) * clamp(width * .29, 115, 250));
root.style.setProperty('--exhibit-travel', travel + 'px');
}
}
function worldPosition(value) {
const whole = Math.floor(value);
const index = modulo(whole, count);
const step = (slots[index] + slots[(index + 1) % count]) / 2 + .1;
return Math.floor(whole / count) * cycle + centers[index] + (value - whole) * step;
}
function select(force = false, value = position) {
const index = modulo(Math.round(value), count);
if (selected === index && !force) return;
const changed = selected < 0 || force ? items.keys() : [selected, index];
selected = index;
const item = items[index];
for (const i of changed) {
const work = items[i];
work.frame.toggleAttribute('data-current', i === index);
work.link.tabIndex = i === index ? 0 : -1;
work.link.setAttribute('aria-expanded', String(viewing && i === index));
}
if (title) title.textContent = item.title;
if (caption) { caption.textContent = item.caption; caption.hidden = !item.caption; }
if (counter) counter.textContent = numbered(index + 1) + ' / ' + numbered(count);
if (description) {
description.textContent = item.description;
description.hidden = !viewing || !item.description;
}
if (destination) {
const href = item.destination?.getAttribute('href');
destination.hidden = !viewing || !href;
destination.textContent = item.destination?.textContent.trim() || '';
if (href) destination.setAttribute('href', href);
else destination.removeAttribute('href');
}
if (close) close.hidden = !viewing;
if (status) status.textContent = (viewing ? 'Viewing ' : '') + item.title + ', ' + (index + 1) + ' of ' + count + '.';
}
function pose(frame, x, y, w, h, matrix, opacity, layer, visible) {
frame.style.width = w.toFixed(2) + 'px';
frame.style.height = h.toFixed(2) + 'px';
frame.style.left = (x - w / 2).toFixed(2) + 'px';
frame.style.top = (y - h / 2).toFixed(2) + 'px';
frame.style.transform = matrix;
frame.style.zIndex = layer;
frame.style.setProperty('--exhibit-opacity', opacity);
frame.style.visibility = visible ? '' : 'hidden';
}
function paint() {
if (!width || !height) return;
const narrow = width <= 528;
const center = worldPosition(position);
const focusX = width * (narrow ? .42 : .395);
const focusY = height * (narrow ? .42 : .445);
const horizonX = width * (narrow ? 1.44 : 1.18);
const horizonY = height * .48;
const baseHeight = Math.min(height * (narrow ? .59 : .72), width * 1.03);
const depth = .39;
items.forEach((item, i) => {
if ((viewing && i === selected) || count === 1) {
const availableWidth = width * (narrow ? .83 : .53);
const availableHeight = height * (narrow && viewing ? .57 : .77);
const h = Math.min(availableHeight, availableWidth / ratios[i]);
const x = width * (narrow || count === 1 && !viewing ? .5 : .66);
const y = height * (narrow && viewing ? .365 : .45);
pose(item.frame, x, y, h * ratios[i], h, 'none', 1, 100, true);
return;
}
// Keep the preceding print at the near edge. Two works share a finite wall.
const delta = count === 2 ? i - (1 - Math.abs(modulo(position, 2) - 1))
: modulo(i - position + 1.5, count) - 1.5;
if (delta > 7) {
if (item.frame.style.visibility !== 'hidden') item.frame.style.visibility = 'hidden';
return;
}
const away = count === 2 ? delta * ((slots[0] + slots[1]) / 2 + .1)
: worldPosition(position + delta) - center;
const denominator = 1 + depth * away;
if (denominator < .12) { item.frame.style.visibility = 'hidden'; return; }
const scale = 1 / denominator;
const x = horizonX + (focusX - horizonX) * scale;
const y = horizonY + (focusY - horizonY) * scale;
const w = slots[i] * .9 * baseHeight;
// Project a rectangular print onto one plane. Both horizontal edges and all
// neighbouring frames converge on the same point on the gallery horizon.
const perspective = depth * scale / (.9 * baseHeight);
const a = (horizonX - x) * perspective, b = (horizonY - y) * perspective;
const matrix = 'matrix3d(' + [a,b,0,perspective, 0,scale,0,0, 0,0,1,0, 0,0,0,1].join(',') + ')';
const opacity = viewing ? .12 : clamp(1 - Math.max(0, away - 1) * .09, .4, 1);
pose(item.frame, x, y, w, baseHeight, matrix, opacity, Math.round(60 - delta * 3),
!viewing || Math.abs(delta) < 4);
});
}
function stop() {
cancelAnimationFrame(tween);
clearTimeout(wheelTimer);
root.removeAttribute('data-exhibit-moving');
}
function focusArtwork() { items[selected].link.focus({preventScroll: true}); }
function snap(value, keepFocus = false) {
stop();
target = Math.round(value);
select(false, target);
if (keepFocus) focusArtwork();
if (viewing || reduced.matches || Math.abs(position - target) < .002) {
position = target;
paint();
return;
}
const start = position, started = performance.now();
root.setAttribute('data-exhibit-moving', '');
function tick(time) {
const t = clamp((time - started) / 360, 0, 1);
position = target + (start - target) * (1 - t) ** 3;
paint();
if (t < 1) tween = requestAnimationFrame(tick);
else root.removeAttribute('data-exhibit-moving');
}
tween = requestAnimationFrame(tick);
}
function pinProgress() {
const top = parseFloat(getComputedStyle(room).top) || 0;
return clamp((top - root.getBoundingClientRect().top) / travel, 0, 1);
}
function reanchor(value) {
if (!pinned || !travel) return;
anchorProgress = lastProgress = pinProgress();
anchorWork = modulo(value, count);
}
function followPage() {
if (!pinned || !travel || viewing || drag) return;
const progress = pinProgress();
if (progress === lastProgress) return;
lastProgress = progress;
const value = progress < anchorProgress
? anchorWork * progress / anchorProgress
: anchorWork + (count - 1 - anchorWork) * (progress - anchorProgress) / (1 - anchorProgress || 1);
stop();
root.setAttribute('data-exhibit-moving', '');
position = reduced.matches ? Math.round(value) : value;
target = Math.round(position);
select();
paint();
wheelTimer = setTimeout(() => root.removeAttribute('data-exhibit-moving'), 125);
}
function scrollUpdate() {
if (scrollFrame) return;
scrollFrame = requestAnimationFrame(() => { scrollFrame = 0; followPage(); });
}
function step(by, keepFocus = false) {
if (count < 2) return;
const value = Math.round(target) + by;
reanchor(value);
snap(value, keepFocus);
}
function detail(open, index) {
stop();
drag = null;
root.removeAttribute('data-dragging');
viewing = open;
position = target = index;
root.toggleAttribute('data-viewing', open);
select(true);
paint();
reanchor(index);
if (open && close) close.focus({preventScroll:true});
else focusArtwork();
}
root.setAttribute('data-enhanced', '');
for (const ctl of root.querySelectorAll('[data-exhibit-controls]')) ctl.hidden = false;
if (prev) prev.disabled = count === 1;
if (next) next.disabled = count === 1;
geometry();
select();
paint();
items.forEach(({link, img}, i) => {
link.setAttribute('role', 'button');
img.draggable = false;
link.draggable = false;
link.addEventListener('click', event => {
if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey || event.button > 0) return;
event.preventDefault();
if (suppressClick && event.detail) return;
detail(!(viewing && selected === i), i);
});
if (!img.complete) img.addEventListener('load', () => {
if (!measureFrame) measureFrame = requestAnimationFrame(() => { measureFrame = 0; geometry(); paint(); });
}, {once:true});
});
prev?.addEventListener('click', () => step(-1));
next?.addEventListener('click', () => step(1));
close?.addEventListener('click', () => detail(false, selected));
root.addEventListener('keydown', event => {
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
if (event.key === 'Escape' && viewing) {
event.preventDefault();
detail(false, selected);
return;
}
if (event.key === ' ' && event.target.closest('[data-exhibit-open]')) {
event.preventDefault();
event.target.closest('[data-exhibit-open]').click();
return;
}
const keepFocus = !!event.target.closest('[data-exhibit-open]');
switch (event.key) {
case 'ArrowLeft': event.preventDefault(); step(-1, keepFocus); break;
case 'ArrowRight': event.preventDefault(); step(1, keepFocus); break;
case 'Home': case 'End': {
event.preventDefault();
const index = event.key === 'Home' ? 0 : count - 1;
reanchor(index);
snap(index + Math.round((position - index) / count) * count, keepFocus);
break;
}
}
});
// Plain vertical scrolling belongs to the page, including the pinned section.
stage.addEventListener('wheel', event => {
if (count < 2 || event.ctrlKey || event.metaKey || viewing || drag) return;
const horizontal = Math.abs(event.deltaX) > Math.abs(event.deltaY);
if (!horizontal && !event.shiftKey) return;
const delta = horizontal ? event.deltaX : event.deltaY;
if (!delta) return;
event.preventDefault();
stop();
const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? width : 1;
target += clamp(delta * unit / Math.max(width * .24, 95), -2, 2);
position = reduced.matches ? Math.round(target) : target;
reanchor(Math.round(target));
root.setAttribute('data-exhibit-moving', '');
select();
paint();
wheelTimer = setTimeout(() => snap(Math.round(target)), 100);
}, {passive:false});
stage.addEventListener('pointerdown', event => {
if (!event.isPrimary || event.button !== 0) return;
suppressClick = false;
if (count < 2 || event.target.closest('button, input, [data-exhibit-link]')) return;
drag = {id:event.pointerId, x:event.clientX, y:event.clientY, start:position, moving:false};
});
stage.addEventListener('pointermove', event => {
if (drag?.id !== event.pointerId) return;
const dx = drag.x - event.clientX, dy = drag.y - event.clientY;
if (!drag.moving) {
if (Math.abs(dy) > 7 && Math.abs(dy) >= Math.abs(dx)) { drag = null; return; }
if (Math.abs(dx) < 7) return;
drag.moving = true;
suppressClick = true;
stop();
stage.setPointerCapture(event.pointerId);
root.setAttribute('data-dragging', '');
}
if (!viewing) {
const p = drag.start + dx / Math.max(width * .26, 100);
position = target = reduced.matches ? Math.round(p) : p;
select();
paint();
}
});
function finish(event) {
if (drag?.id !== event.pointerId) return;
const gesture = drag;
drag = null;
root.removeAttribute('data-dragging');
if (!gesture.moving) return;
if (viewing) {
const dx = gesture.x - event.clientX;
if (event.type === 'pointerup' && Math.abs(dx) > 28) step(dx > 0 ? 1 : -1);
} else {
const dx = gesture.x - event.clientX;
let end = Math.round(position);
if (event.type === 'pointerup' && end === Math.round(gesture.start) && Math.abs(dx) > 32) end += dx > 0 ? 1 : -1;
reanchor(end);
snap(end);
}
}
stage.addEventListener('pointerup', finish);
stage.addEventListener('pointercancel', finish);
stage.addEventListener('lostpointercapture', finish);
if (pinned) {
if ('IntersectionObserver' in window) {
new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
document.addEventListener('scroll', scrollUpdate, {capture:true, passive:true});
scrollUpdate();
} else document.removeEventListener('scroll', scrollUpdate, true);
}).observe(root);
} else document.addEventListener('scroll', scrollUpdate, {capture:true, passive:true});
followPage();
}
if ('ResizeObserver' in window) new ResizeObserver(() => { geometry(); paint(); followPage(); }).observe(stage);
}Use the HTML in a static site
Copy the rendered HTML above. Download these assets into the same folder as your page, then add the tags below to its head.
Shared CSS Component CSS Ready-to-use module
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./exhibit-gallery.css">
<script type="module" src="./exhibit-gallery.js"></script>Copy into your project
Run this command from the Mono checkout. Set -out to the component directory in your application.
go run ./cmd/mono-ui add -out ./components exhibit-galleryExample properties (JSON)
{
"Items": [
{
"Alt": "A fan-shaped palm shadow radiates across a sunlit plaster wall.",
"Caption": "Study of light on plaster",
"Description": "The ribs of a single leaf stretch across the wall. The small chips in the plaster interrupt the shadow at its edges.",
"ImageURL": "../components/exhibitions/quiet-forms/fan-light.webp",
"Title": "Fan Light"
},
{
"Alt": "Concrete steps spiral around a dark circular opening.",
"Caption": "Concrete stair study",
"Description": "The stair wraps around an opening just wide enough to hold the light. A pale handrail traces its way inward.",
"ImageURL": "../components/exhibitions/quiet-forms/inner-turn.webp",
"Title": "Inner Turn"
},
{
"Alt": "A rough stoneware bottle with an open center rests on a pale stone slab.",
"Caption": "Stoneware still life",
"Description": "Light passes through the middle of the vessel and picks out the grit along its rim.",
"ImageURL": "../components/exhibitions/quiet-forms/hollow-body.webp",
"Title": "Hollow Body"
},
{
"Alt": "Small waves cross a band of reflected sunlight beneath a misty horizon.",
"Caption": "Sea study at first light",
"Description": "The water catches the pale sky in narrow strips. Each approaching wave briefly breaks one strip in two.",
"ImageURL": "../components/exhibitions/quiet-forms/tideline.webp",
"Title": "Tideline"
},
{
"Alt": "Stone columns recede along a walkway crossed by long diagonal shadows.",
"Caption": "Colonnade in afternoon light",
"Description": "The gaps between columns almost vanish in the distance. Their shadows keep the spacing visible on the floor.",
"ImageURL": "../components/exhibitions/quiet-forms/long-interval.webp",
"Title": "Long Interval"
},
{
"Alt": "Light and dark triangular folds meet at a sharp crease in white paper.",
"Caption": "Folded paper under side light",
"Description": "One crease turns a flat sheet into a landscape. The soft grain of the paper still shows in the deepest fold.",
"ImageURL": "../components/exhibitions/quiet-forms/paper-ridge.webp",
"Title": "Paper Ridge"
}
],
"Pinned": true,
"Title": "Quiet Forms"
}