Site
Row fan
Big names, each a link, whose pictures fan out in perspective beside the name (from 1024) or below it when it is pointed at, focused, tapped or scrolled to the middle, travelling from row to row on a soft spring; a card opens with its title and meta.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add row-fan<script type="module" src="/spyglass-ds/elements/row-fan.js"></script>Usage
A list of a few templates, products or use cases, each with a handful of example pictures, as the templates page sets its rows.
Never
- More than a few rows, or long names that wrap
- Pictures of real people or other brands' ads in examples: pass your own
- Travel and scaling with reduced motion: it fades
Each card is an image slot (src, alt, fit, position); a card without src, or with a generated blank, carries data-ds-placeholder.
Adds with it: creative-card
Props
The web component takes the same as attributes or properties (<spyglass-row-fan>); title is heading there.
<RowFan>
| Prop | Type | Default |
|---|---|---|
rows | FanRow[] | |
sizes | string The img sizes attribute for the cards. | '(min-width: 1024px) 128px, (min-width: 768px) 96px, 72px' |
newTab | boolean Open the rows' links in a new tab. | false |
className | string |
Examples
The same example in React and as web components; both render identically.
import { RowFan, type FanRow } from '@/react/components/site/RowFan'
// The templates page's rows: each template's name with what it brings back (Acme placeholder pictures; pass your own).
const SHADES = ['#262626', '#1A1A1A', '#363636', '#4D4D4D']
const picture = (n: number) => `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="128" height="128" fill="${SHADES[n % 4]}"/><text x="64" y="70" fill="#A3A3A3" font-family="sans-serif" font-size="14" text-anchor="middle">Acme ${n + 1}</text></svg>`)}`
const items = (row: number, what: string) => Array.from({ length: 6 }, (_, i) => ({ key: `${row}-${i}`, src: picture(row * 6 + i), title: `Acme ${['Skin', 'Drinks', 'Fit', 'Studio', 'Motors', 'Home'][i]}`, meta: what }))
const rows: FanRow[] = [
{ key: 'ads', name: 'Ad library', href: '#ads', cta: 'Every ad a brand is running, and how long it ran.', items: items(0, 'Meta ad') },
{ key: 'creators', name: 'Creators', href: '#creators', cta: 'The creators a brand works with, and their posts.', items: items(1, 'Instagram') },
{ key: 'pages', name: 'Landing pages', href: '#pages', cta: 'Where the ads send people.', items: items(2, 'Landing page') },
]
export default function Templates() {
return <RowFan rows={rows} />
}<!-- The templates page's rows: each template's name with what it brings back (Acme placeholder pictures; pass your own). -->
<spyglass-row-fan rows='[{"key":"ads","name":"Ad library","href":"#ads","cta":"Every ad a brand is running, and how long it ran.","items":[{"key":"0-0","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%23262626%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%201%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Skin","meta":"Meta ad"},{"key":"0-1","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%231A1A1A%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%202%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Drinks","meta":"Meta ad"},{"key":"0-2","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%23363636%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%203%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Fit","meta":"Meta ad"},{"key":"0-3","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%234D4D4D%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%204%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Studio","meta":"Meta ad"},{"key":"0-4","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%23262626%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%205%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Motors","meta":"Meta ad"},{"key":"0-5","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%231A1A1A%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%206%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Home","meta":"Meta ad"}]},{"key":"creators","name":"Creators","href":"#creators","cta":"The creators a brand works with, and their posts.","items":[{"key":"1-0","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%23363636%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%207%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Skin","meta":"Instagram"},{"key":"1-1","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%234D4D4D%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%208%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Drinks","meta":"Instagram"},{"key":"1-2","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%23262626%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%209%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Fit","meta":"Instagram"},{"key":"1-3","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%231A1A1A%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%2010%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Studio","meta":"Instagram"},{"key":"1-4","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%23363636%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%2011%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Motors","meta":"Instagram"},{"key":"1-5","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%234D4D4D%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%2012%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Home","meta":"Instagram"}]},{"key":"pages","name":"Landing pages","href":"#pages","cta":"Where the ads send people.","items":[{"key":"2-0","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%23262626%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%2013%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Skin","meta":"Landing page"},{"key":"2-1","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%231A1A1A%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%2014%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Drinks","meta":"Landing page"},{"key":"2-2","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%23363636%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%2015%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Fit","meta":"Landing page"},{"key":"2-3","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%234D4D4D%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%2016%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Studio","meta":"Landing page"},{"key":"2-4","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%23262626%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%2017%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Motors","meta":"Landing page"},{"key":"2-5","src":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22128%22%20height%3D%22128%22%20fill%3D%22%231A1A1A%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2270%22%20fill%3D%22%23A3A3A3%22%20font-family%3D%22sans-serif%22%20font-size%3D%2214%22%20text-anchor%3D%22middle%22%3EAcme%2018%3C%2Ftext%3E%3C%2Fsvg%3E","title":"Acme Home","meta":"Landing page"}]}]'></spyglass-row-fan>Source
'use client'
import { useEffect, useRef } from 'react'
import { mountRowFan } from '@/lib/effects/row-fan'
import { ROW_FAN_CSS } from '@/lib/effects/row-fan-css'
import { cn } from '@/react/lib/cn'
import { imageFit, isPlaceholderSrc, type ImageSlot } from '@/lib/image'
// The site's row fan (ui/RowFan, as the templates page sets it): a list of big names, each a link, with a set of
// pictures. Point at, focus or tap a name (on touch and below 1024, scroll it to the middle) and it lifts 16px while
// its pictures fan out, turned in perspective, beside it from 1024 or below it on smaller screens, travelling from row
// to row on a soft spring; its line appears under the name. Point at a card and it opens with the picture's title and
// meta. Pictures come through `rows` (your own images); the layer is hidden from assistive tech and each row's link
// carries `srLabel`. Reduced motion: no travel or scaling, short fades.
/** A card in the fan: its picture ({ src, alt, fit, position }; none, or a generated blank, is a placeholder), title and meta. */
export interface FanItem extends ImageSlot { key: string, title: string, meta?: string }
export interface FanRow { key: string, name: string, href: string, cta: string, srLabel?: string, items: FanItem[] }
export interface RowFanProps {
rows: FanRow[]
/** The img sizes attribute for the cards. */
sizes?: string
/** Open the rows' links in a new tab. */
newTab?: boolean
className?: string
}
const sideOf = (k: number) => (k % 2 === 0 ? 'l' : 'r')
export function RowFan({ rows, sizes = '(min-width: 1024px) 128px, (min-width: 768px) 96px, 72px', newTab = false, className }: RowFanProps) {
const ref = useRef<HTMLDivElement>(null)
useEffect(() => {
const root = ref.current
return root ? mountRowFan(root) : undefined
}, [rows])
const most = Math.max(0, ...rows.map((r) => r.items.length))
const places = Array.from({ length: most }, (_, k) => ({ side: sideOf(k), step: Math.floor(k / 2), k }))
return (
<div ref={ref} data-ds="row-fan" data-fan-root="" className={cn('ds-fan', className)}>
<style href="ds-row-fan" precedence="ds">{ROW_FAN_CSS}</style>
<ul className="ds-fan-list" role="list">
{rows.map((row) => (
<li key={row.key}>
<a className="ds-fan-row" href={row.href} data-fan-row="" data-fan-cta={row.cta} {...(newTab ? { target: '_blank', rel: 'noreferrer' } : null)}>
<span className="ds-fan-anchor" data-fan-anchor=""><span className="ds-fan-name" data-fan-name="">{row.name}</span></span>
{row.srLabel ? <span className="sr-only">{row.srLabel}</span> : null}
</a>
</li>
))}
</ul>
<div className="ds-fan-layer" data-fan-layer="" aria-hidden="true">
{places.map((p) => (
<div key={p.k} className="ds-fan-slot" data-fan-slot="" data-side={p.side} data-step={p.step}>
<div className="ds-fan-turn">
<div className="ds-fan-chrome" />
<div className="ds-fan-pic">
{rows.map((row, i) => {
const item = row.items[p.k]
if (!item) return null
return (
<div key={row.key} className="ds-fan-img" data-fan-img="" data-ds-placeholder={isPlaceholderSrc(item.src) ? '' : undefined} data-row={i} data-title={item.title} data-meta={item.meta}>
{item.src ? <img src={item.src} alt="" sizes={sizes} decoding="async" draggable={false} style={imageFit(item)} /> : null}
</div>
)
})}
</div>
<div className="ds-fan-details" data-fan-details="">
<span className="ds-fan-title" data-fan-title="" />
<span className="ds-fan-meta" data-fan-meta="" />
</div>
</div>
</div>
))}
{[0, 1].map((k) => <span key={k} className="ds-fan-cta" data-fan-cta=""><span data-fan-cta-label="" /></span>)}
</div>
</div>
)
}
export default RowFan// The site's row fan motion (ui/rowFanMotion): a list of names, each with a set of pictures. Hovering, focusing or
// tapping a row (or, on touch and below 960, scrolling it to the middle) lifts its name and fans its pictures out
// beside it (or below it), the cards travelling between rows on a springy curve; hovering a card opens it with its
// title and meta. Reads its sizes and timings from --fan-* on the root (row-fan.ts sets them from the tokens).
// Reduced motion: no travel or scale, short fades.
type Mode = "first" | "switch" | "place";
type SlotState = {
el: HTMLElement;
side: "l" | "r";
step: number;
imgs: Map<number, HTMLElement>;
shown: boolean;
on: number;
token: number;
};
type Place = { x: number; y: number; z: number; show: boolean };
const ms = (v: string) => {
const s = v.trim();
if (!s) return 0;
return s.endsWith("ms") ? parseFloat(s) : s.endsWith("s") ? parseFloat(s) * 1000 : parseFloat(s);
};
const reflow = (el: HTMLElement) => void el.offsetWidth;
export function mountRowFan(root: HTMLElement): () => void {
const rows = Array.from(root.querySelectorAll<HTMLElement>("[data-fan-row]"));
const anchors = rows.map((r) => r.querySelector<HTMLElement>("[data-fan-anchor]") ?? r);
const names = rows.map((r) => r.querySelector<HTMLElement>("[data-fan-name]") ?? r);
const layer = root.querySelector<HTMLElement>("[data-fan-layer]");
if (!layer || rows.length === 0) return () => {};
const slots: SlotState[] = Array.from(layer.querySelectorAll<HTMLElement>("[data-fan-slot]")).map((el) => ({
el,
side: el.dataset.side === "l" ? "l" : "r",
step: Number(el.dataset.step) || 0,
imgs: new Map(
Array.from(el.querySelectorAll<HTMLElement>("[data-fan-img]")).map((img) => [
Number(img.dataset.row),
img,
]),
),
shown: false,
on: -1,
token: 0,
}));
const ctas = Array.from(layer.querySelectorAll<HTMLElement>("[data-fan-cta]"));
const ctaRow = ctas.map(() => -1);
const mqTouch = window.matchMedia("(hover: none), (pointer: coarse)");
const mqNarrow = window.matchMedia("(max-width: 959.98px)");
const mqReduce = window.matchMedia("(prefers-reduced-motion: reduce)");
let scrollMode = mqTouch.matches || mqNarrow.matches;
let reduce = mqReduce.matches;
let active = -1;
let cta = -1;
let openSlot: SlotState | null = null;
let touchOff: (() => void) | null = null;
let v = read();
function read() {
const cs = getComputedStyle(root);
const px = (n: string) => parseFloat(cs.getPropertyValue(n)) || 0;
const t = (n: string) => ms(cs.getPropertyValue(n));
const e = (n: string) => cs.getPropertyValue(n).trim() || "ease";
return {
below: cs.getPropertyValue("--fan-layout").trim() === "below",
card: px("--fan-card"),
gap: px("--fan-gap"),
nameGap: px("--fan-name-gap"),
belowGap: px("--fan-below-gap"),
lift: px("--fan-lift"),
ctaTop: px("--fan-cta-top"),
ctaRise: px("--fan-cta-rise"),
ctaSink: px("--fan-cta-sink"),
enterScale: parseFloat(cs.getPropertyValue("--fan-enter-scale")) || 0,
exitScale: parseFloat(cs.getPropertyValue("--fan-exit-scale")) || 0,
pop: t("--fan-dur-pop"),
exit: t("--fan-dur-exit"),
travelMin: t("--fan-dur-travel-min"),
travelMax: t("--fan-dur-travel-max"),
lift_in: t("--fan-dur-lift"),
settle: t("--fan-dur-settle"),
ctaDelay: t("--fan-dur-cta-delay"),
ctaOut: t("--fan-dur-cta-out"),
fade: t("--fan-dur-fade"),
fadeOut: t("--fan-dur-fade-out"),
easePop: e("--fan-ease-pop"),
easeTravel: e("--fan-ease-travel"),
easeLift: e("--fan-ease-lift"),
easeCtaOut: e("--fan-ease-cta-out"),
card_on: cs.getPropertyValue("--fan-card-hover").trim() !== "off",
scrollAlways: cs.getPropertyValue("--fan-scroll").trim() === "always",
pickNearest: cs.getPropertyValue("--fan-scroll-pick").trim() === "nearest",
};
}
function layout(row: number): Place[] {
const r = root.getBoundingClientRect();
const box = (el: HTMLElement) => {
const b = el.getBoundingClientRect();
return { l: b.left - r.left, r: b.right - r.left, t: b.top - r.top, b: b.bottom - r.top };
};
const own = box(anchors[row]);
let left = own.l;
let right = own.r;
if (!v.below && !scrollMode) {
const all = anchors.map(box);
const centre = all.reduce((s, b) => s + (b.l + b.r) / 2, 0) / all.length;
const half = Math.max(...all.map((b) => b.r - b.l)) / 2;
left = centre - half;
right = centre + half;
}
const step = v.card + v.gap;
const vpLeft = -r.left;
const vpRight = vpLeft + document.documentElement.clientWidth;
const centreX = (own.l + own.r) / 2;
const y = v.below ? own.b + v.belowGap : (own.t + own.b) / 2 - v.card / 2;
return slots.map((s) => {
const x = v.below
? s.side === "l"
? centreX - v.gap / 2 - v.card - s.step * step
: centreX + v.gap / 2 + s.step * step
: s.side === "l"
? left - v.nameGap - v.card - s.step * step
: right + v.nameGap + s.step * step;
const inView = x + v.card > vpLeft && x < vpRight;
return { x: Math.round(x), y: Math.round(y), z: 1000 - s.step, show: inView && s.imgs.has(row) };
});
}
const tf = (p: { x: number; y: number }, scale: number) =>
`translate3d(${p.x}px, ${p.y}px, 0) scale(${scale})`;
function setImage(s: SlotState, row: number, animate: boolean) {
if (s.on === row) return;
const next = s.imgs.get(row);
s.token += 1;
const token = s.token;
if (!animate || !next) {
s.el.setAttribute("data-instant", "");
for (const [r, el] of s.imgs) if (r !== row) el.removeAttribute("data-on");
next?.setAttribute("data-on", "");
reflow(s.el);
s.el.removeAttribute("data-instant");
s.on = row;
return;
}
s.on = row;
const img = next.querySelector("img") ?? (next as HTMLImageElement);
const go = () => {
if (s.token !== token) return;
for (const [r, el] of s.imgs) if (r !== row) el.removeAttribute("data-on");
next.setAttribute("data-on", "");
};
const decode = img instanceof HTMLImageElement && img.decode ? img.decode() : Promise.resolve();
decode.then(go, go);
}
function placeSlots(mode: Mode) {
const places = layout(active);
const entering = new Set<SlotState>();
slots.forEach((s, i) => {
const p = places[i];
if (p.show && (!s.shown || mode === "first")) {
s.el.style.transition = "none";
s.el.style.transform = tf(p, reduce ? 1 : v.enterScale);
s.el.style.opacity = "0";
s.el.style.zIndex = String(p.z);
setImage(s, active, false);
entering.add(s);
}
});
if (entering.size) reflow(layer!);
slots.forEach((s, i) => {
const p = places[i];
const st = s.el.style;
if (!p.show) {
if (s.shown) {
st.transition = reduce
? `opacity ${v.fade}ms ${v.easePop}`
: `transform ${v.pop}ms ${v.easePop}, opacity ${v.pop}ms ${v.easePop}`;
if (!reduce) st.transform = tf(currentPlace(s), v.enterScale);
st.opacity = "0";
}
s.shown = false;
st.pointerEvents = "none";
return;
}
st.zIndex = String(p.z);
st.pointerEvents = v.card_on && !scrollMode ? "auto" : "none";
if (entering.has(s)) {
st.transition = reduce
? `opacity ${v.fade}ms ${v.easePop}`
: `transform ${v.pop}ms ${v.easePop}, opacity ${v.pop}ms ${v.easePop}`;
st.transform = tf(p, 1);
st.opacity = "1";
} else if (mode === "place" || reduce) {
st.transition = "none";
st.transform = tf(p, 1);
st.opacity = "1";
setImage(s, active, mode !== "place");
} else {
const d = Math.round(v.travelMin + Math.random() * (v.travelMax - v.travelMin));
st.transition = `transform ${d}ms ${v.easeTravel}, opacity ${d}ms ${v.easeTravel}`;
st.transform = tf(p, 1);
st.opacity = "1";
setImage(s, active, true);
}
s.el.dataset.x = String(p.x);
s.el.dataset.y = String(p.y);
s.shown = true;
});
}
function currentPlace(s: SlotState) {
return { x: Number(s.el.dataset.x) || 0, y: Number(s.el.dataset.y) || 0 };
}
function moveName(i: number, up: boolean) {
const st = names[i].style;
st.transition = reduce ? "none" : `transform ${up ? v.lift_in : v.settle}ms ${v.easeLift}`;
st.transform = up ? `translate3d(0, ${-v.lift}px, 0)` : "translate3d(0, 0, 0)";
}
function ctaPlace(i: number, el: HTMLElement) {
const r = root.getBoundingClientRect();
const b = anchors[i].getBoundingClientRect();
return {
x: Math.round((b.left + b.right) / 2 - r.left - el.offsetWidth / 2),
y: Math.round(b.bottom - r.top + v.ctaTop),
};
}
function showCta(i: number) {
if (!ctas.length) return;
const text = rows[i].dataset.fanCta ?? "";
let k = cta >= 0 && ctaRow[cta] === i ? cta : cta === 0 ? 1 % ctas.length : 0;
if (ctaRow[k] === i && k === cta) return;
const el = ctas[k];
const label = el.querySelector<HTMLElement>("[data-fan-cta-label]") ?? el;
label.textContent = text;
const p = ctaPlace(i, el);
el.style.transition = "none";
el.style.transform = `translate3d(${p.x}px, ${p.y + (reduce ? 0 : v.ctaRise)}px, 0)`;
el.style.opacity = "0";
reflow(el);
el.style.transition = reduce
? `opacity ${v.fadeOut}ms ${v.easeLift}`
: `transform ${v.lift_in}ms ${v.easeLift} ${v.ctaDelay}ms, opacity ${v.lift_in}ms ${v.easeLift} ${v.ctaDelay}ms`;
el.style.transform = `translate3d(${p.x}px, ${p.y}px, 0)`;
el.style.opacity = "1";
if (cta >= 0 && cta !== k) hideCta(cta);
ctaRow[k] = i;
cta = k;
}
function hideCta(k: number) {
const el = ctas[k];
const m = /translate3d\(([-\d.]+)px, ([-\d.]+)px/.exec(el.style.transform);
const x = m ? Number(m[1]) : 0;
const y = m ? Number(m[2]) : 0;
el.style.transition = reduce
? `opacity ${v.fade}ms ${v.easeCtaOut}`
: `transform ${v.ctaOut}ms ${v.easeCtaOut}, opacity ${v.ctaOut}ms ${v.easeCtaOut}`;
if (!reduce) el.style.transform = `translate3d(${x}px, ${y + v.ctaSink}px, 0)`;
el.style.opacity = "0";
ctaRow[k] = -1;
}
function openCard(s: SlotState) {
if (!v.card_on || scrollMode || !s.shown || openSlot === s) return;
if (openSlot) closeCard(openSlot, true);
const img = s.imgs.get(s.on);
const details = s.el.querySelector<HTMLElement>("[data-fan-details]");
if (!img || !details) return;
const title = details.querySelector<HTMLElement>("[data-fan-title]");
const meta = details.querySelector<HTMLElement>("[data-fan-meta]");
if (title) title.textContent = img.dataset.title ?? "";
if (meta) {
meta.textContent = img.dataset.meta ?? "";
meta.hidden = !img.dataset.meta;
}
const pad = parseFloat(getComputedStyle(root).getPropertyValue("--fan-card-pad")) || 0;
s.el.style.setProperty("--fan-open-h", `${details.offsetTop + details.offsetHeight + pad}px`);
s.el.removeAttribute("data-fast");
s.el.setAttribute("data-open", "");
openSlot = s;
}
function closeCard(s: SlotState, fast: boolean) {
if (fast) s.el.setAttribute("data-fast", "");
else s.el.removeAttribute("data-fast");
s.el.removeAttribute("data-open");
if (openSlot === s) openSlot = null;
}
function activate(i: number) {
if (i === active || i < 0) return;
if (openSlot) closeCard(openSlot, true);
const prev = active;
active = i;
placeSlots(prev < 0 ? "first" : "switch");
if (prev >= 0) moveName(prev, false);
moveName(i, true);
showCta(i);
root.dataset.fanActive = String(i);
rows.forEach((r, k) => (k === i ? r.setAttribute("data-active", "") : r.removeAttribute("data-active")));
}
function deactivate() {
if (active < 0) return;
if (openSlot) closeCard(openSlot, true);
moveName(active, false);
if (cta >= 0) hideCta(cta);
cta = -1;
for (const s of slots) {
if (!s.shown) continue;
const st = s.el.style;
st.transition = reduce
? `opacity ${v.fadeOut}ms ${v.easePop}`
: `transform ${v.exit}ms ${v.easePop}, opacity ${v.exit}ms ${v.easePop}`;
if (!reduce) st.transform = tf(currentPlace(s), v.exitScale);
st.opacity = "0";
st.pointerEvents = "none";
s.shown = false;
}
rows[active].removeAttribute("data-active");
active = -1;
delete root.dataset.fanActive;
touchOff?.();
touchOff = null;
}
const rowOf = (t: EventTarget | null) => {
if (!(t instanceof Element) || layer!.contains(t)) return -1;
const row = t.closest<HTMLElement>("[data-fan-row]");
return row ? rows.indexOf(row) : -1;
};
let hoverRow = -1;
let focusRow = -1;
let tapRow = -1;
let scrollRow = -1;
const resolve = () => {
const i = focusRow >= 0 ? focusRow : hoverRow >= 0 ? hoverRow : tapRow >= 0 ? tapRow : scrollRow;
if (i >= 0) activate(i);
else deactivate();
};
const scrollDrives = () => scrollMode || v.scrollAlways;
const onOver = (e: PointerEvent) => {
if (scrollMode || (e.pointerType !== "mouse" && e.pointerType !== "pen")) return;
const i = rowOf(e.target);
if (i >= 0 && i !== hoverRow) {
hoverRow = i;
resolve();
}
};
const onLeave = (e: PointerEvent) => {
if (scrollMode || (e.pointerType !== "mouse" && e.pointerType !== "pen")) return;
const to = e.relatedTarget;
if (to instanceof Node && root.contains(to)) return;
hoverRow = -1;
resolve();
};
const onDown = (e: PointerEvent) => {
if (scrollMode || e.pointerType !== "touch") return;
const i = rowOf(e.target);
if (i < 0) return;
tapRow = i === active ? -1 : i;
if (tapRow < 0 && scrollRow === i) scrollRow = -1;
resolve();
if (!touchOff && tapRow >= 0) {
const outside = (ev: PointerEvent) => {
if (ev.target instanceof Node && root.contains(ev.target)) return;
tapRow = -1;
touchOff?.();
touchOff = null;
resolve();
};
document.addEventListener("pointerdown", outside, { passive: true });
touchOff = () => document.removeEventListener("pointerdown", outside);
}
};
const onFocusIn = (e: FocusEvent) => {
const i = rowOf(e.target);
if (i >= 0) {
focusRow = i;
resolve();
}
};
const onFocusOut = (e: FocusEvent) => {
const to = e.relatedTarget;
if (to instanceof Node && root.contains(to)) return;
focusRow = -1;
if (!scrollMode || v.scrollAlways) resolve();
};
const onSlotOver = (e: PointerEvent) => {
if (e.pointerType !== "mouse" && e.pointerType !== "pen") return;
const el = (e.target as Element | null)?.closest<HTMLElement>("[data-fan-slot]");
const s = el ? slots.find((x) => x.el === el) : undefined;
if (s) openCard(s);
};
const onSlotOut = (e: PointerEvent) => {
if (!openSlot) return;
const to = e.relatedTarget;
if (to instanceof Node && openSlot.el.contains(to)) return;
const from = (e.target as Element | null)?.closest<HTMLElement>("[data-fan-slot]");
if (from === openSlot.el) closeCard(openSlot, false);
};
root.addEventListener("pointerover", onOver);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("pointerdown", onDown, { passive: true });
root.addEventListener("focusin", onFocusIn);
root.addEventListener("focusout", onFocusOut);
layer.addEventListener("pointerover", onSlotOver);
layer.addEventListener("pointerout", onSlotOut);
let frame = 0;
let listening = false;
// The scroll pick waits until the fonts have loaded and a frame has laid the rows out, so which row it picks depends
// only on the rows and the viewport, never on how fast the page loaded.
let settled = false;
const pick = () => {
frame = 0;
if (!settled || !scrollDrives()) return;
const mid = window.innerHeight * 0.5;
let row = 0;
if (v.pickNearest) {
const r = root.getBoundingClientRect();
if (r.bottom <= 0 || r.top >= window.innerHeight) row = -1;
else {
let best = Infinity;
anchors.forEach((a, i) => {
const b = a.getBoundingClientRect();
const d = Math.abs((b.top + b.bottom) / 2 - mid);
if (d < best) {
best = d;
row = i;
}
});
}
} else {
anchors.forEach((a, i) => {
if (a.getBoundingClientRect().top <= mid) row = i;
});
}
if (row === scrollRow && row === active) return;
// Leaving the screen is confirmed a frame later: a moment's resize (a screenshot, a toolbar) must not drop the row.
if (row < 0 && scrollRow >= 0) {
if (!dropping) dropping = requestAnimationFrame(confirmDrop);
return;
}
scrollRow = row;
resolve();
};
let dropping = 0;
const offscreen = () => {
const r = root.getBoundingClientRect();
const m = window.innerHeight * 0.2;
return r.bottom <= -m || r.top >= window.innerHeight + m;
};
function confirmDrop() {
dropping = 0;
const r = root.getBoundingClientRect();
if (r.bottom > 0 && r.top < window.innerHeight) return;
scrollRow = -1;
resolve();
}
const onScroll = () => {
if (!frame) frame = requestAnimationFrame(pick);
};
const listen = (on: boolean) => {
if (on === listening) return;
listening = on;
if (on) {
window.addEventListener("scroll", onScroll, { passive: true });
window.addEventListener("resize", onScroll);
} else {
window.removeEventListener("scroll", onScroll);
window.removeEventListener("resize", onScroll);
if (frame) cancelAnimationFrame(frame);
frame = 0;
}
};
let near = false;
const io = new IntersectionObserver(
([entry]) => {
near = Boolean(entry?.isIntersecting);
v = read();
listen(near && scrollDrives());
if (near && scrollDrives()) pick();
else if (!near && v.pickNearest && scrollRow >= 0) {
requestAnimationFrame(() => {
if (!offscreen()) {
near = true;
listen(scrollDrives());
pick();
return;
}
if (near || scrollRow < 0) return;
scrollRow = -1;
resolve();
});
}
},
{ rootMargin: "20% 0px 20% 0px" },
);
io.observe(root);
const onMode = () => {
const next = mqTouch.matches || mqNarrow.matches;
reduce = mqReduce.matches;
if (next !== scrollMode) {
scrollMode = next;
hoverRow = -1;
tapRow = -1;
deactivate();
listen(near && scrollDrives());
if (near && scrollDrives()) pick();
}
};
mqTouch.addEventListener("change", onMode);
mqNarrow.addEventListener("change", onMode);
mqReduce.addEventListener("change", onMode);
const relayout = () => {
v = read();
listen(near && scrollDrives());
if (active < 0) return;
placeSlots("place");
const k = cta;
if (k >= 0) {
const p = ctaPlace(active, ctas[k]);
ctas[k].style.transition = "none";
ctas[k].style.transform = `translate3d(${p.x}px, ${p.y}px, 0)`;
}
};
let ro: ResizeObserver | null = null;
let roFirst = true;
if (typeof ResizeObserver !== "undefined") {
ro = new ResizeObserver(() => {
if (roFirst) {
roFirst = false;
return;
}
relayout();
});
ro.observe(root);
}
let alive = true;
let settle = 0;
const ready = document.fonts?.ready ?? Promise.resolve();
ready.then(() => {
if (!alive) return;
settle = requestAnimationFrame(() => {
settle = requestAnimationFrame(() => {
if (!alive) return;
settled = true;
relayout();
if (near && scrollDrives()) pick();
});
});
});
return () => {
alive = false;
cancelAnimationFrame(settle);
cancelAnimationFrame(dropping);
root.removeEventListener("pointerover", onOver);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("pointerdown", onDown);
root.removeEventListener("focusin", onFocusIn);
root.removeEventListener("focusout", onFocusOut);
layer.removeEventListener("pointerover", onSlotOver);
layer.removeEventListener("pointerout", onSlotOut);
mqTouch.removeEventListener("change", onMode);
mqNarrow.removeEventListener("change", onMode);
mqReduce.removeEventListener("change", onMode);
listen(false);
io.disconnect();
ro?.disconnect();
touchOff?.();
};
}// The row fan's look (pages/TemplatesPage/TemplateCities.module.css), shared by both flavors: names in Funnel Display
// (32, 44 from 768, 64 from 1024), cards 72, 96 and 128 turned in perspective, the open card's chrome, the CTA under the
// name. Below 1024 the cards fan below the name; from 1024 beside it. Timings are the brand's steps.
export const ROW_FAN_CSS = `
.ds-fan {
position: relative;
/* The site's section clips the fan sideways (TemplateCities .section overflow-x: clip): the outer cards run past a
phone's edge under the name, and past 1024's beside a long one. Set the fan full-bleed so they reach the screen's. */
overflow-x: clip;
--fan-layout: below; --fan-scroll: always; --fan-scroll-pick: nearest;
--fan-card: var(--ds-fan-card); --fan-gap: var(--ds-space-sm); --fan-name-gap: var(--ds-space-2xl); --fan-below-gap: var(--ds-fan-below-gap);
--fan-lift: var(--ds-space-lg); --fan-cta-top: var(--ds-fan-cta-top); --fan-cta-rise: var(--ds-space-sm); --fan-cta-sink: var(--ds-space-sm);
--fan-card-pad: var(--ds-space-sm); --fan-enter-scale: var(--ds-fan-enter-scale); --fan-exit-scale: var(--ds-fan-enter-scale);
--fan-dur-pop: var(--ds-duration-enter); --fan-dur-exit: var(--ds-duration-exit);
--fan-dur-travel-min: var(--ds-duration-micro); --fan-dur-travel-max: var(--ds-duration-slow);
--fan-dur-lift: var(--ds-duration-enter); --fan-dur-settle: var(--ds-duration-micro);
--fan-dur-cta-delay: var(--ds-duration-stagger); --fan-dur-cta-out: var(--ds-duration-exit);
--fan-dur-fade: var(--ds-duration-press); --fan-dur-fade-out: var(--ds-duration-exit);
--fan-ease-pop: var(--ds-easing-fan-pop); --fan-ease-travel: var(--ds-easing-fan-travel);
--fan-ease-lift: var(--ds-easing-fan-lift); --fan-ease-cta-out: var(--ds-easing-fan-cta-out);
--fan-name-size: var(--ds-text-heading-2); --fan-name-line: var(--ds-text-heading-2-leading); --fan-row-gap: 0px; --fan-row-pad: var(--ds-space-lg);
}
.ds-fan-list { display: flex; flex-direction: column; gap: var(--fan-row-gap); margin: 0; padding: 0; list-style: none; }
.ds-fan-row { display: flex; justify-content: center; padding-top: var(--fan-row-pad); padding-bottom: calc(var(--fan-row-pad) + var(--fan-below-gap) + var(--fan-card)); color: var(--ds-color-fg); text-decoration: none; outline: none; -webkit-tap-highlight-color: transparent; }
.ds-fan-anchor { display: inline-block; }
.ds-fan-name { display: inline-block; font-family: var(--ds-font-heading); font-weight: var(--ds-font-weight-regular); font-size: var(--fan-name-size); line-height: var(--fan-name-line); white-space: nowrap; will-change: transform; }
.ds-fan-row:focus-visible .ds-fan-name { outline: var(--ds-border-focus) solid var(--ds-color-edge-focus); outline-offset: var(--ds-space-sm); }
.ds-fan-layer { position: absolute; inset: 0; z-index: 1; pointer-events: none; overflow: visible; }
.ds-fan-slot { position: absolute; top: 0; left: 0; width: var(--fan-card); height: var(--fan-card); opacity: 0; pointer-events: none; will-change: transform, opacity; }
.ds-fan-slot[data-open] { z-index: 2000 !important; }
.ds-fan-turn { position: absolute; inset: 0; --turn: var(--ds-fan-turn); transform: perspective(var(--ds-fan-perspective)) rotateY(var(--turn)); }
.ds-fan-slot[data-side="r"] .ds-fan-turn { --turn: calc(var(--ds-fan-turn) * -1); }
.ds-fan-slot[data-step="0"][data-side="l"] .ds-fan-turn { --turn: var(--ds-fan-turn-0); }
.ds-fan-slot[data-step="0"][data-side="r"] .ds-fan-turn { --turn: calc(var(--ds-fan-turn-0) * -1); }
.ds-fan-slot[data-step="1"][data-side="l"] .ds-fan-turn { --turn: var(--ds-fan-turn-1); }
.ds-fan-slot[data-step="1"][data-side="r"] .ds-fan-turn { --turn: calc(var(--ds-fan-turn-1) * -1); }
.ds-fan-chrome { position: absolute; top: 0; left: 0; right: 0; height: var(--fan-open-h, var(--fan-card)); border-radius: var(--ds-radius-panel); background: var(--ds-color-surface-subtle); opacity: 0; clip-path: inset(0 0 calc(100% - var(--fan-card)) 0 round var(--ds-radius-panel)); transition: opacity var(--ds-duration-enter) var(--ds-easing-in-out), clip-path var(--ds-duration-enter) var(--ds-easing-in-out); }
.ds-fan-pic { position: absolute; inset: 0; overflow: hidden; border-radius: var(--ds-radius-sm); background: var(--ds-color-surface-subtle); transform-origin: top center; transition: transform var(--ds-duration-enter) var(--ds-easing-in-out); }
.ds-fan-img { position: absolute; inset: 0; opacity: 0; transition: opacity var(--ds-duration-enter) var(--ds-easing-fan-pop) var(--ds-duration-stagger); }
.ds-fan-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; user-select: none; }
.ds-fan-img[data-on] { opacity: 1; }
[data-instant] .ds-fan-img { transition: none; }
.ds-fan-details { position: absolute; top: calc(var(--fan-card-pad) + var(--fan-card) * var(--ds-fan-card-scale) + var(--ds-space-sm)); left: var(--fan-card-pad); right: var(--fan-card-pad); display: grid; opacity: 0; transform: translateY(var(--ds-space-sm)); text-align: left; transition: opacity var(--ds-duration-enter) var(--ds-easing-in-out), transform var(--ds-duration-enter) var(--ds-easing-in-out); }
.ds-fan-title { overflow: hidden; font-size: var(--ds-text-ui); line-height: var(--ds-text-ui-leading); color: var(--ds-color-fg); white-space: nowrap; text-overflow: ellipsis; }
.ds-fan-meta { font-size: var(--ds-text-caption); line-height: var(--ds-text-caption-leading); color: var(--ds-color-fg-muted); opacity: 0; transform: translateY(var(--ds-space-sm)); transition: opacity var(--ds-duration-enter) var(--ds-easing-in-out), transform var(--ds-duration-enter) var(--ds-easing-in-out); }
.ds-fan-slot[data-open] .ds-fan-chrome { opacity: 1; clip-path: inset(0 0 0 0 round var(--ds-radius-panel)); transition: opacity var(--ds-duration-glide) var(--ds-easing-fan-lift), clip-path var(--ds-duration-glide) var(--ds-easing-fan-lift); }
.ds-fan-slot[data-open] .ds-fan-pic { transform: translateY(var(--fan-card-pad)) scale(var(--ds-fan-card-scale)); transition: transform var(--ds-duration-glide) var(--ds-easing-fan-lift); }
.ds-fan-slot[data-open] .ds-fan-details, .ds-fan-slot[data-open] .ds-fan-meta { opacity: 1; transform: none; transition: opacity var(--ds-duration-glide) var(--ds-easing-fan-lift), transform var(--ds-duration-glide) var(--ds-easing-fan-lift); }
.ds-fan-slot[data-open] .ds-fan-meta { transition-delay: var(--ds-duration-stagger); }
.ds-fan-slot[data-fast] .ds-fan-chrome, .ds-fan-slot[data-fast] .ds-fan-pic, .ds-fan-slot[data-fast] .ds-fan-details, .ds-fan-slot[data-fast] .ds-fan-meta { transition-duration: var(--ds-duration-press); }
.ds-fan-cta { position: absolute; top: 0; left: 0; display: inline-flex; align-items: center; gap: var(--ds-space-sm); max-width: calc(100% - 2 * var(--ds-layout-gutter)); padding: var(--ds-space-xs) var(--ds-space-md); font-size: var(--ds-text-ui); line-height: var(--ds-text-ui-leading); color: var(--ds-color-fg-muted); text-align: center; text-wrap: balance; opacity: 0; will-change: transform, opacity; }
@media (min-width: 768px) {
.ds-fan { --fan-card: var(--ds-fan-card-md); --fan-gap: var(--ds-space-md); --fan-name-size: var(--ds-text-heading-1); --fan-name-line: var(--ds-text-heading-1-leading); --fan-below-gap: var(--ds-space-xl); }
.ds-fan-cta { max-width: none; font-size: var(--ds-text-body-lg); line-height: var(--ds-text-body-lg-leading); white-space: nowrap; }
}
@media (min-width: 1024px) {
.ds-fan { --fan-layout: side; --fan-card: var(--ds-fan-card-lg); --fan-gap: var(--ds-space-lg); --fan-name-size: var(--ds-text-display-s); --fan-name-line: var(--ds-text-display-s-leading); --fan-row-gap: calc(var(--ds-space-lg) + var(--ds-space-xl)); }
.ds-fan-row { padding-bottom: var(--fan-row-pad); }
}
@media (prefers-reduced-motion: reduce) {
.ds-fan-chrome, .ds-fan-pic, .ds-fan-details, .ds-fan-meta,
.ds-fan-slot[data-open] .ds-fan-chrome, .ds-fan-slot[data-open] .ds-fan-pic, .ds-fan-slot[data-open] .ds-fan-details, .ds-fan-slot[data-open] .ds-fan-meta { transition-duration: var(--ds-duration-press); }
}
`// Joins class names, skipping falsy ones: cn('a', on && 'b', ['c', undefined]). It does not merge conflicting
// utilities (no tailwind-merge), as Vue's class binding does not: the library's classes are written not to compete,
// and a className from the caller is appended after them, as Vue appends a fallthrough class.
export type ClassValue = string | false | null | undefined | 0 | ClassValue[]
export function cn(...values: ClassValue[]): string {
const out: string[] = []
for (const v of values) {
if (!v) continue
if (Array.isArray(v)) {
const s = cn(...v)
if (s) out.push(s)
}
else out.push(v)
}
return out.join(' ')
}import { html, nothing, unsafeCSS, type PropertyValues } from 'lit'
import { DsElement, define } from '@/elements/lib/element'
import { mountRowFan } from '@/lib/effects/row-fan'
import { ROW_FAN_CSS } from '@/lib/effects/row-fan-css'
import styles from 'virtual:tw'
import { imageFit, isPlaceholderSrc, type ImageSlot } from '@/lib/image'
import { styleMap } from 'lit/directives/style-map.js'
// RowFan.tsx as <spyglass-row-fan>: big names, each a link, whose pictures fan out beside (from 1024) or below the name
// when it is pointed at, focused, tapped or scrolled to the middle; a card opens with its title and meta. `rows` (JSON:
// { key, name, href, cta, srLabel?, items: [{ key, src, alt?, title, meta? }] }), `sizes`, `new-tab`.
export interface FanItem extends ImageSlot { key: string, title: string, meta?: string }
export interface FanRow { key: string, name: string, href: string, cta: string, srLabel?: string, items: FanItem[] }
/**
* @summary Names whose pictures fan out beside them.
*/
export class RowFan extends DsElement {
static styles = [DsElement.styles, styles, unsafeCSS(ROW_FAN_CSS)]
static properties = { rows: { type: Array }, sizes: {}, newTab: { type: Boolean, attribute: 'new-tab' } }
rows: FanRow[] = []
/** The img sizes attribute for the cards. */
sizes = '(min-width: 1024px) 128px, (min-width: 768px) 96px, 72px'
/** Open the rows' links in a new tab. */
newTab = false
private stop: (() => void) | null = null
protected updated(changed: PropertyValues) {
super.updated(changed)
if (!changed.has('rows') && this.stop) return
this.stop?.()
const root = this.renderRoot.querySelector<HTMLElement>('[data-fan-root]')
this.stop = root ? mountRowFan(root) : null
}
connectedCallback() {
super.connectedCallback()
if (this.hasUpdated && !this.stop) this.requestUpdate('rows')
}
disconnectedCallback() {
super.disconnectedCallback()
this.stop?.()
this.stop = null
}
render() {
const rows = Array.isArray(this.rows) ? this.rows : []
const most = Math.max(0, ...rows.map((r) => r.items.length))
const places = Array.from({ length: most }, (_, k) => ({ side: k % 2 === 0 ? 'l' : 'r', step: Math.floor(k / 2), k }))
return html`<div data-ds="row-fan" data-fan-root="" class="ds-fan"><ul class="ds-fan-list" role="list">${rows.map((row) => html`<li><a class="ds-fan-row" href=${row.href} data-fan-row="" data-fan-cta=${row.cta} target=${this.newTab ? '_blank' : nothing} rel=${this.newTab ? 'noreferrer' : nothing}><span class="ds-fan-anchor" data-fan-anchor=""><span class="ds-fan-name" data-fan-name="">${row.name}</span></span>${row.srLabel ? html`<span class="sr-only">${row.srLabel}</span>` : nothing}</a></li>`)}</ul><div class="ds-fan-layer" data-fan-layer="" aria-hidden="true">${places.map((p) => html`<div class="ds-fan-slot" data-fan-slot="" data-side=${p.side} data-step=${p.step}><div class="ds-fan-turn"><div class="ds-fan-chrome"></div><div class="ds-fan-pic">${rows.map((row, i) => {
const item = row.items[p.k]
return item ? html`<div class="ds-fan-img" data-fan-img="" data-ds-placeholder=${isPlaceholderSrc(item.src) ? '' : nothing} data-row=${i} data-title=${item.title} data-meta=${item.meta ?? nothing}>${item.src ? html`<img src=${item.src} alt="" sizes=${this.sizes} decoding="async" draggable="false" style=${styleMap(imageFit(item) ?? {})} />` : nothing}</div>` : nothing
})}</div><div class="ds-fan-details" data-fan-details=""><span class="ds-fan-title" data-fan-title=""></span><span class="ds-fan-meta" data-fan-meta=""></span></div></div></div>`)}${[0, 1].map(() => html`<span class="ds-fan-cta" data-fan-cta=""><span data-fan-cta-label=""></span></span>`)}</div></div>`
}
}
define('row-fan', RowFan)Reference: Site ui/RowFan and rowFanMotion, set as pages/TemplatesPage/TemplateCities (TemplateCities.module.css, --cities-* tokens): cards 72, 96, 128; names h4, h2, display-s; turns 18, 15, 12 degrees at 640px perspective; the travel curve --ease-cities-travel.