Blocks

Use case wheel

The site's use cases wheel: the headline inside an ellipse of creatives over a drum of audiences. The pill holds the current audience beside a White arrow link; every 2.4s on screen it turns, a new pair of creatives scaling up at the foot while the others climb the ring (50ms apart, turning away as they rise) and the top pair leaves into the distance.

Install

React apps get the React files; every other stack gets the web component.

npx spyglass-ds add use-case-wheel
<script type="module" src="/spyglass-ds/elements/use-case-wheel.js"></script>
Use case wheel

Built for every marketing team

  • The ads that are winning in any category, and why.
  • Which hooks, angles and formats are winning.
  • The posts that move an audience, across every platform.
  • Everything a brand does, in one place.
  • The creators a brand works with, and the ones it should.
  • Every client's ads, posts and creators, one API.

Usage

Showing who a product is for, one audience at a time, linking each to its use case page. items takes { key, label, line, href, linkLabel, pairs } with three pairs of creatives each (Acme placeholders by default, or src images); light puts a light layer behind it and can take the ring's ripple.

Never

  • Another brand's ads shipped in the library: placeholders, or the user's own creatives through src
  • Turning by itself with reduced motion (it crossfades and stays put)
  • Turning while the pointer or keyboard focus is in the drum
  • More than one White button in the section

With autoplay it turns on its own once half the window has reached it, and stops when the tab is hidden. A pointer resting on another label turns to it; a click queues a turn behind one in progress. The heading is the site's .t-h1 (32, 44 at 768, 56 only from 1280: type-section held at 44 until then), centered on the ring's middle and at most 480px wide. Each picture is an image slot (src, alt, fit, position); without src it keeps its placeholder, which carries data-ds-placeholder.

Adds with it: creative-card

Props

The web component takes the same as attributes or properties (<spyglass-use-case-wheel>); title is heading there.

<UseCaseWheel>

PropTypeDefault
idstring

The section's id (its heading is `<id>-heading`).

'use-cases'
headlinestringuseCaseWheelContent.headline
itemsWheelItem[]

The audiences: { key, label, line, href, linkLabel, pairs: three pairs of creatives }.

useCaseWheelContent.items
as'h1' | 'h2'

h2 in a page, h1 when the wheel opens one.

lightReactNode | ((ripple: WheelRipple) => ReactNode)

A light layer behind the ring, or a function that receives the ring's ripple and returns it.

autoplayboolean

Turn by itself while on screen.

true
onChange(index: number) => void

Called with the audience's index after each turn.

classNamestring

Examples

The same example in React and as web components; both render identically.

react/examples/use-case-wheel/Wheel.tsx
import { UseCaseWheel } from '@/react/components/blocks/UseCaseWheel'
// The wheel with its six audiences and Acme placeholder creatives, held still so it reads at rest (it turns every 2.4s
// with autoplay on).

export default function Wheel() {
  return <UseCaseWheel id="wheel" autoplay={false} />
}
elements/examples/use-case-wheel/Wheel.html
<!-- The wheel with its six audiences and Acme placeholder creatives, held still so it reads at rest (it turns every 2.4s with autoplay on). -->
<spyglass-use-case-wheel section-id="wheel" autoplay="false"></spyglass-use-case-wheel>

Source

react/components/blocks/UseCaseWheel.tsx
'use client'
import { useEffect, useRef, useState, type FocusEvent, type PointerEvent, type ReactNode } from 'react'
import { CreativeCard } from '@/react/components/site/CreativeCard'
import { createWheel, createWheelRipple, useCaseWheelContent, useCaseWheelCss, wheelFit, wheelLongest, wheelRest, type WheelEngine, type WheelItem, type WheelPicture, type WheelRipple } from '@/lib/use-case-wheel'
import { cn } from '@/react/lib/cn'

// The site's use cases wheel (v2/V2UseCases, UseCaseWheel): the headline in the middle of an ellipse of creatives, two
// arcs opening from a pill at its foot. The pill holds the current audience beside a White arrow link, the next below
// and the one before above at half strength, all turning like a drum. Every 2.4s while it is on screen it turns: a new
// pair of creatives scales up at the bottom, the others climb one slot (each 50ms after the last, turning away and
// sinking back as they rise) and the top pair leaves into the distance. The pointer or keyboard focus in the drum holds
// it; a click, or the pointer resting on another label, turns to that audience. With reduced motion the creatives stand
// at their slots and crossfade, and it never turns by itself. Under 768 only the headline and the drum show.
// Creatives are Acme placeholders unless `items` passes images; `light` puts a light layer behind it (the dispersion
// field in its ring composition: pass a function to receive the ripple that bends the light with each turn).
export interface UseCaseWheelProps {
  /** The section's id (its heading is `<id>-heading`). */
  id?: string
  headline?: string
  /** The audiences: { key, label, line, href, linkLabel, pairs: three pairs of creatives }. */
  items?: WheelItem[]
  /** h2 in a page, h1 when the wheel opens one. */
  as?: 'h1' | 'h2'
  /** A light layer behind the ring, or a function that receives the ring's ripple and returns it. */
  light?: ReactNode | ((ripple: WheelRipple) => ReactNode)
  /** Turn by itself while on screen. */
  autoplay?: boolean
  /** Called with the audience's index after each turn. */
  onChange?: (index: number) => void
  className?: string
}

function Picture({ picture }: { picture: WheelPicture }) {
  const fit = wheelFit(picture)
  return (
    <span className="ds-wheel-frame" data-fit={fit === 'fill' ? undefined : fit} style={picture.ratio ? { aspectRatio: String(picture.ratio) } : undefined}>
      <CreativeCard src={picture.src} alt={picture.alt} fit={picture.fit} position={picture.position} brand={picture.brand} caption={picture.caption} tone={picture.tone} ratio="fill" />
    </span>
  )
}

export function UseCaseWheel({ id = 'use-cases', headline = useCaseWheelContent.headline, items = useCaseWheelContent.items, as: Heading = 'h2', light, autoplay = true, onChange, className }: UseCaseWheelProps) {
  const [active, setActive] = useState(0)
  const sectionRef = useRef<HTMLElement>(null)
  const stage = useRef<HTMLDivElement>(null)
  const head = useRef<HTMLHeadingElement>(null)
  const queue = useRef<HTMLDivElement>(null)
  const pill = useRef<HTMLDivElement>(null)
  const pillText = useRef<HTMLSpanElement>(null)
  const focusBox = useRef<HTMLSpanElement>(null)
  const parts = useRef({ labels: [] as HTMLElement[], twins: [] as HTMLElement[], pictures: items.map((item) => item.pairs.map(() => [] as HTMLElement[])) })
  const engine = useRef<WheelEngine | null>(null)
  const [ripple] = useState(() => createWheelRipple(engine, stage))
  const holds = useRef({ pointer: false, focus: false })
  const lastRow = useRef<number | null>(null)
  const changed = useRef(onChange)
  changed.current = onChange

  useEffect(() => {
    if (!sectionRef.current || !stage.current || !head.current || !queue.current || !pill.current || !pillText.current || !focusBox.current) return
    const e = createWheel(
      { section: sectionRef.current, stage: stage.current, head: head.current, queue: queue.current, pill: pill.current, pillText: pillText.current, focusBox: focusBox.current, ...parts.current },
      { autoplay, onChange: (i) => { setActive(i); changed.current?.(i) } },
    )
    engine.current = e
    return () => {
      e.destroy()
      engine.current = null
    }
  }, [items, autoplay])

  const hold = () => engine.current?.hold(holds.current.pointer || holds.current.focus)
  const onPointerMove = (event: PointerEvent<HTMLDivElement>) => {
    if (event.pointerType !== 'mouse') return
    const target = (event.target as Element).closest<HTMLElement>('[data-item]')
    const index = target ? Number(target.dataset.item) : null
    engine.current?.mark('hover', index)
    const row = index === null ? (pill.current?.contains(event.target as Node) ? 0 : null) : engine.current?.row(index)
    if (row === undefined || row === lastRow.current) return
    lastRow.current = row
    if (index !== null && row !== 0 && row !== null) engine.current?.hover(index)
  }
  const onPointerEnter = () => { holds.current.pointer = true; hold() }
  const onPointerLeave = () => { holds.current.pointer = false; lastRow.current = null; engine.current?.mark('hover', null); hold() }
  const onFocus = (event: FocusEvent<HTMLDivElement>) => {
    const target = event.target as HTMLElement
    const keyboard = target.matches(':focus-visible')
    engine.current?.mark('focus', keyboard && target.dataset.item ? Number(target.dataset.item) : null)
    if (!keyboard) return
    holds.current.focus = true
    hold()
  }
  const onBlur = (event: FocusEvent<HTMLDivElement>) => {
    if (event.currentTarget.contains(event.relatedTarget as Node | null)) return
    engine.current?.mark('focus', null)
    holds.current.focus = false
    hold()
  }

  const current = items[active] ?? items[0]
  const lightLayer = typeof light === 'function' ? light(ripple) : light

  return (
    <section ref={sectionRef} data-ds="use-case-wheel" id={id} aria-labelledby={`${id}-heading`} data-light={lightLayer ? '' : undefined} className={cn('ds-wheel-section text-fg', className)}>
      <style href="ds-use-case-wheel" precedence="ds">{useCaseWheelCss}</style>
      <div ref={stage} className="ds-wheel">
        {lightLayer ? <div className="ds-wheel-light">{lightLayer}</div> : null}
        <Heading ref={head} id={`${id}-heading`} className="ds-wheel-head type-section">{headline}</Heading>
        <div className="ds-wheel-ring" aria-hidden="true">
          {items.map((item, g) => item.pairs.map((pair, p) => pair.map((picture, side) => (
            <div key={`${item.key}-${p}-${side}`} ref={(el) => { if (el) parts.current.pictures[g][p][side] = el }} className="ds-wheel-picture">
              <Picture picture={picture} />
            </div>
          ))))}
        </div>
        <div className="ds-wheel-queue" onPointerEnter={onPointerEnter} onPointerLeave={onPointerLeave} onPointerMove={onPointerMove} onFocus={onFocus} onBlur={onBlur}>
          <div ref={queue} className="ds-wheel-mask">
            <ul className="m-0 list-none p-0" role="list">
              {items.map((item, i) => (
                <li key={item.key}>
                  <button type="button" ref={(el) => { if (el) parts.current.labels[i] = el }} className="ds-wheel-label" data-item={i} data-rest={wheelRest(i, active, items.length)} aria-pressed={i === active} aria-describedby={`${id}-line-${item.key}`} onClick={() => engine.current?.choose(i)}>
                    {item.label}
                  </button>
                  <span id={`${id}-line-${item.key}`} className="sr-only">{item.line}</span>
                </li>
              ))}
            </ul>
            {items.map((item, i) => (
              <span key={item.key} ref={(el) => { if (el) parts.current.twins[i] = el }} className="ds-wheel-label ds-wheel-twin" aria-hidden="true">{item.label}</span>
            ))}
          </div>
          <span ref={focusBox} className="ds-wheel-focus" aria-hidden="true" />
          <div ref={pill} className="ds-wheel-pill">
            <span ref={pillText} className="ds-wheel-pill-text" aria-hidden="true">{wheelLongest(items)}</span>
            <a className="ds-wheel-send" href={current.href} aria-label={current.linkLabel}>
              <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M3 8h10M8.5 3.5 13 8l-4.5 4.5" /></svg>
            </a>
          </div>
        </div>
      </div>
    </section>
  )
}

export default UseCaseWheel
lib/use-case-wheel.ts
// The use case wheel (site v2/V2UseCases: UseCaseWheel, skillsMotion.ts, ringLight.ts), framework-free so both flavors
// run the same motion. Two arcs of creatives open from the pill at the foot of an ellipse and climb around the headline;
// each change brings a new pair in at the bottom, scaled up from 0.4 and faded in, pushes the others one slot up the
// ring (each later by the stagger, turning away and sinking back as they rise) and sends the top pair off into the
// distance. The labels turn like a drum through the pill: the current one sits in the pill beside the arrow link,
// the next below and the one before above at half strength. It advances every 2.4s while it is on screen, pauses
// under the pointer or keyboard focus, and a click or a hover on another label turns to it. With reduced motion the
// pictures stand still at their slots and change by a crossfade, and nothing advances by itself.

import type { ImageSlot } from '@/lib/image'

/** A creative in the ring: the user's image, or an Acme placeholder (the creative card's brand, caption and tone). */
export interface WheelPicture extends ImageSlot {
  /** The image's width over its height: a narrower image fills the card's height, a wider one its width. */
  ratio?: number
  brand?: string
  caption?: string
  tone?: 1 | 2 | 3 | 4
}

/** One audience on the wheel: its label, a line for assistive tech, the link and three pairs of creatives. */
export interface WheelItem {
  key: string
  label: string
  line: string
  href: string
  linkLabel: string
  pairs: [WheelPicture, WheelPicture][]
}

const pic = (brand: string, tone: 1 | 2 | 3 | 4): WheelPicture => ({ brand, tone })
const pairs = (a: string, b: string, t: number): [WheelPicture, WheelPicture][] => [
  [pic(a, ((t % 4) + 1) as 1), pic(b, (((t + 2) % 4) + 1) as 1)],
  [pic(a, (((t + 1) % 4) + 1) as 1), pic(b, (((t + 3) % 4) + 1) as 1)],
  [pic(a, (((t + 3) % 4) + 1) as 1), pic(b, ((t % 4) + 1) as 1)],
]

export const useCaseWheelContent: { headline: string; items: WheelItem[] } = {
  headline: 'Built for every marketing team',
  items: [
    { key: 'performance', label: 'Performance marketers', line: 'The ads that are winning in any category, and why.', href: '/use-cases/paid-media', linkLabel: 'See Paid ads', pairs: pairs('Acme', 'Acme Air', 0) },
    { key: 'creative', label: 'Creative strategists', line: 'Which hooks, angles and formats are winning.', href: '/use-cases/creative-research', linkLabel: 'See Creative research', pairs: pairs('Acme Labs', 'Acme Goods', 1) },
    { key: 'social', label: 'Social teams', line: 'The posts that move an audience, across every platform.', href: '/use-cases/organic-social', linkLabel: 'See Organic media', pairs: pairs('Acme Studio', 'Acme & Co', 2) },
    { key: 'brand', label: 'Brand teams', line: 'Everything a brand does, in one place.', href: '/use-cases/360-degree-research', linkLabel: 'See 360-degree research', pairs: pairs('Acme', 'Acme Studio', 3) },
    { key: 'partnerships', label: 'Partnerships teams', line: 'The creators a brand works with, and the ones it should.', href: '/use-cases/creators', linkLabel: 'See Creator sourcing', pairs: pairs('Acme Goods', 'Acme Labs', 0) },
    { key: 'agencies', label: 'Agencies', line: "Every client's ads, posts and creators, one API.", href: '/use-cases', linkLabel: 'See all use cases', pairs: pairs('Acme & Co', 'Acme Air', 1) },
  ],
}

/** Where a label rests before the engine places it: in the pill, below it or above it. */
export function wheelRest(index: number, active: number, count: number) {
  const c = (index - active + count) % count
  return c === 0 ? 'pill' : c === 1 ? 'below' : 'above'
}

/** The longest label (it sizes the pill's hidden text, so every label fits). */
export const wheelLongest = (items: WheelItem[]) => items.reduce((a, b) => (b.label.length > a.length ? b.label : a), '')

/** A narrower picture fills the card's height, a wider one its width (the card is 3:4). */
export const wheelFit = (p: WheelPicture) => (p.ratio === undefined ? 'fill' : p.ratio < 3 / 4 ? 'tall' : 'wide')

// ----- Motion -----

export interface WheelElements {
  section: HTMLElement
  stage: HTMLElement
  head: HTMLElement
  queue: HTMLElement
  pill: HTMLElement
  pillText: HTMLElement
  focusBox: HTMLElement
  labels: HTMLElement[]
  twins: HTMLElement[]
  pictures: HTMLElement[][][]
}

type Bezier = (x: number) => number

export function bezier(x1: number, y1: number, x2: number, y2: number): Bezier {
  const at = (t: number, a: number, b: number) => 3 * a * (1 - t) * (1 - t) * t + 3 * b * (1 - t) * t * t + t * t * t
  return (x) => {
    if (x <= 0) return 0
    if (x >= 1) return 1
    let lo = 0
    let hi = 1
    for (let i = 0; i < 24; i++) {
      const mid = (lo + hi) / 2
      if (at(mid, x1, x2) < x) lo = mid
      else hi = mid
    }
    return at((lo + hi) / 2, y1, y2)
  }
}

const toMs = (raw: string, fallback: number) => {
  const n = parseFloat(raw)
  if (!Number.isFinite(n)) return fallback
  return raw.endsWith('ms') ? n : raw.endsWith('s') ? n * 1000 : n
}
const curveOf = (raw: string) => raw.match(/-?\d*\.?\d+/g)?.map(Number) ?? [0.85, 0, 0.15, 1]

function readTokens(el: HTMLElement) {
  const css = getComputedStyle(el)
  const v = (name: string) => css.getPropertyValue(name).trim()
  const num = (name: string) => parseFloat(v(name)) || 0
  const c = curveOf(v('--ds-wheel-ease'))
  return {
    ease: bezier(c[0], c[1], c[2], c[3]),
    step: toMs(v('--ds-wheel-every'), 2400),
    move: toMs(v('--ds-wheel-move'), 600),
    fade: toMs(v('--ds-wheel-fade'), 500),
    stagger: toMs(v('--ds-wheel-stagger'), 50),
    fadeLead: toMs(v('--ds-wheel-fade-lead'), 100),
    crossfade: toMs(v('--ds-wheel-crossfade'), 360),
    row: num('--ds-wheel-step'),
    rx: num('--rx'),
    ry: num('--ry'),
    cardW: num('--card-w'),
    cardH: num('--card-h'),
    slots: Math.max(2, Math.round(num('--slots'))),
    clear: num('--ds-wheel-clear'),
    perspective: num('--ds-wheel-perspective') || 1600,
    turn: num('--ds-wheel-turn'),
    depth: num('--ds-wheel-depth'),
    popScale: num('--ds-wheel-pop-scale'),
    exitZ: num('--ds-wheel-exit-z'),
    exitTurn: num('--ds-wheel-exit-turn'),
  }
}

type Box = { left: number; top: number; right: number; bottom: number }
type Gen = { c: number; pair: number; born: number }

const clamp = (min: number, max: number, n: number) => Math.min(max, Math.max(min, n))
const lerp = (a: number, b: number, t: number) => a + (b - a) * t
const mod = (n: number, m: number) => ((n % m) + m) % m
const PAIRS = 3
const hits = (a: Box, b: Box) => a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top

export interface WheelOptions {
  onChange: (index: number) => void
  /** Advance by itself while on screen (default true). */
  autoplay?: boolean
}

export type WheelEngine = ReturnType<typeof createWheel>

export function createWheel(els: WheelElements, opts: WheelOptions) {
  const count = els.labels.length
  const reduced = window.matchMedia('(prefers-reduced-motion: reduce)')
  const autoplay = opts.autoplay !== false
  let t = readTokens(els.stage)

  let active = 0
  let progress = 0
  let geo = { centre: 0, boxTop: 0, textTop: 0, textLeft: 0, widths: [] as number[], line: 0, boxH: 0 }
  const marks = { hover: null as number | null, focus: null as number | null }
  const rowsFromPill = (i: number) => {
    const c = i - active - progress
    return ((((c + count / 2) % count) + count) % count) - count / 2
  }
  const put = (el: HTMLElement, width: number, c: number, lit = false) => {
    const d = Math.abs(c)
    const p = clamp(0, 1, 1 - d / 0.6)
    const above = geo.boxTop - t.row
    const below = geo.boxTop + 1.5 * t.row
    const y = c < -1 ? above + (c + 1) * t.row : c < 0 ? lerp(above, geo.boxTop, c + 1) : c <= 1 ? lerp(geo.boxTop, below, c) : below + (c - 1) * t.row
    const x = (geo.centre - width / 2) * (1 - p) + geo.textLeft * p
    const top = y * (1 - p) + geo.textTop * p
    el.style.transform = `translate3d(${x}px, ${top}px, 0)`
    el.style.opacity = String(d > 4 ? 0 : lit ? 1 : 0.3 + 0.7 * p)
    return top
  }
  const mark = (box: HTMLElement, index: number | null, tops: number[]) => {
    if (index === null) return box.removeAttribute('data-on')
    box.style.transform = `translate3d(0, ${tops[index] + geo.line / 2 - geo.boxH / 2}px, 0)`
    box.setAttribute('data-on', '')
  }
  const place = () => {
    const tops: number[] = []
    for (let i = 0; i < count; i++) {
      const c = rowsFromPill(i)
      tops[i] = put(els.labels[i], geo.widths[i], c, marks.hover === i)
      put(els.twins[i], geo.widths[i], c < 0 ? c + count : c - count)
    }
    mark(els.focusBox, marks.focus, tops)
  }

  const LUT = 256
  let ring = { cx: 0, cy: 0, start: 0, gap: 0, theta: new Float64Array(LUT + 1), head: { left: 0, top: 0, right: 0, bottom: 0 } as Box, wheel: { left: 0, top: 0, right: 0, bottom: 0 } as Box }
  const point = (s: number, side: number) => {
    const f = clamp(0, 1, s) * LUT
    const i = Math.min(LUT - 1, Math.floor(f))
    const a = lerp(ring.theta[i], ring.theta[i + 1], f - i)
    return { x: ring.cx + side * t.rx * Math.sin(a), y: ring.cy + t.ry * Math.cos(a) }
  }
  const cardBox = (x: number, y: number, grow: number): Box => ({ left: x - t.cardW / 2 - grow, right: x + t.cardW / 2 + grow, top: y - t.cardH / 2 - grow, bottom: y + t.cardH / 2 + grow })
  const measureRing = () => {
    const stage = els.stage.getBoundingClientRect()
    const range = document.createRange()
    range.selectNodeContents(els.head)
    const text = range.getBoundingClientRect()
    const pill = els.pill.getBoundingClientRect()
    const rel = (r: Box): Box => ({ left: r.left - stage.left, right: r.right - stage.left, top: r.top - stage.top, bottom: r.bottom - stage.top })
    const head = rel(text)
    const wheel = rel({ left: pill.left, right: pill.right, top: pill.top - t.row, bottom: pill.bottom + t.row })
    const N = 1024
    const len = new Float64Array(N + 1)
    for (let i = 1; i <= N; i++) {
      const a0 = (Math.PI * (i - 1)) / N
      const a1 = (Math.PI * i) / N
      len[i] = len[i - 1] + Math.hypot(t.rx * (Math.sin(a1) - Math.sin(a0)), t.ry * (Math.cos(a1) - Math.cos(a0)))
    }
    const theta = new Float64Array(LUT + 1)
    for (let k = 0, i = 0; k <= LUT; k++) {
      const target = (len[N] * k) / LUT
      while (i < N && len[i + 1] < target) i++
      const seg = len[i + 1] - len[i] || 1
      theta[k] = (Math.PI * (i + clamp(0, 1, (target - len[i]) / seg))) / N
    }
    // Whole pixels, so the creatives land on the same rows whichever way the page rounds the stage.
    ring = { ...ring, cx: Math.round(stage.width / 2), cy: Math.round((head.top + head.bottom) / 2), theta, head, wheel }
    let start = 0
    while (start < 0.5) {
      const p = point(start, -1)
      if (!hits(cardBox(p.x, p.y, t.clear), wheel)) break
      start += 0.002
    }
    ring.start = start
    ring.gap = (1 - start) / t.slots
  }

  const setPicture = (el: HTMLElement, x: number, y: number, z: number, turn: number, scale: number, opacity: number) => {
    const k = (t.perspective - z) / t.perspective
    const px = ring.cx + (x - ring.cx) * k - t.cardW / 2
    const py = ring.cy + (y - ring.cy) * k - t.cardH / 2
    el.style.transform = `translate3d(${px.toFixed(2)}px, ${py.toFixed(2)}px, ${z.toFixed(1)}px) rotateY(${turn.toFixed(2)}deg) scale(${scale.toFixed(4)})`
    el.style.opacity = String(Math.round(opacity * 1000) / 1000)
    el.style.visibility = opacity > 0.001 ? 'visible' : 'hidden'
  }
  const rise = (y: number) => clamp(0, 1, (ring.cy - y) / t.ry)
  const pose = (el: HTMLElement, u: number, side: number, fade: number) => {
    const S = t.slots
    if (u <= 1) {
      const p = point(u * ring.start, side)
      return setPicture(el, p.x, p.y, 0, 0, lerp(t.popScale, 1, u), fade)
    }
    if (u <= S) {
      const p = point(ring.start + (u - 1) * ring.gap, side)
      const h = rise(p.y)
      return setPicture(el, p.x, p.y, -t.depth * h, -side * t.turn * h, 1, 1)
    }
    const e = clamp(0, 1, u - S)
    const last = point(ring.start + (S - 1) * ring.gap, side)
    const hLast = rise(last.y)
    const p = point(ring.start + (u - 1) * ring.gap, side)
    const z = lerp(-t.depth * hLast, t.exitZ, 1 - (1 - e) * (1 - e))
    const turn = -side * lerp(t.turn * hLast, t.exitTurn, e * e)
    setPicture(el, p.x, p.y, z, turn, 1, 1 - e * e)
  }
  const hide = (el: HTMLElement) => {
    el.style.opacity = '0'
    el.style.visibility = 'hidden'
  }

  let gens: Gen[] = []
  let switches = 0
  let nextPair: number[] = []
  const refill = () => {
    gens = []
    nextPair = Array.from({ length: count }, () => 0)
    for (let j = t.slots - 1; j >= 0; j--) {
      const c = mod(active - j, count)
      const pair = mod(Math.floor(-j / count), PAIRS)
      gens.push({ c, pair, born: switches - j })
      nextPair[c] = mod(pair + 1, PAIRS)
    }
  }

  type Change = { from: number; to: number; dir: number; start: number; wheel: number; total: number }
  let change: Change | null = null
  let clock = 0
  let lastStart = Number.NEGATIVE_INFINITY
  let landedClock = 0
  let landedWall = 0
  let pinned = Number.POSITIVE_INFINITY

  const render = () => {
    const shown = new Set<HTMLElement>()
    const at = change ? clock - change.start : Infinity
    if (reduced.matches) {
      const draw = (c: number, opacity: number) =>
        els.pictures[c].forEach((pair, i) => {
          const u = 1 + (i * (t.slots - 1)) / (PAIRS - 1)
          const s = ring.start + (u - 1) * ring.gap
          pair.forEach((el, side) => {
            const p = point(s, side ? 1 : -1)
            setPicture(el, p.x, p.y, 0, 0, 1, opacity)
            shown.add(el)
          })
        })
      if (change) {
        const e = clamp(0, 1, at / t.crossfade)
        draw(change.from, 1 - e)
        draw(change.to, e)
      } else draw(active, 1)
    } else {
      for (const g of gens) {
        const rest = switches - g.born + 1
        let u = rest
        let fade = 1
        if (change) {
          const k = rest - 1
          const local = at - (t.slots - k) * t.stagger
          u = k + t.ease(clamp(0, 1, local / t.move))
          if (k === 0) fade = t.ease(clamp(0, 1, (local - t.fadeLead) / t.fade))
        }
        els.pictures[g.c][g.pair].forEach((el, side) => {
          pose(el, u, side ? 1 : -1, fade)
          shown.add(el)
        })
      }
    }
    for (const group of els.pictures) for (const pair of group) for (const el of pair) if (!shown.has(el)) hide(el)
    if (change && !reduced.matches) {
      progress = change.dir * t.ease(clamp(0, 1, at / change.wheel))
      place()
    }
  }

  let frame = 0
  let last = 0
  let frozen = false
  let busy = false
  let queued: number | null = null
  const land = () => {
    if (!change) return
    landedClock = clock
    landedWall = performance.now()
    active = change.to
    progress = 0
    gens = gens.filter((g) => switches - g.born + 1 <= t.slots)
    change = null
    busy = false
    place()
    render()
    if (queued !== null && !frozen) {
      const next = queued
      queued = null
      go(next)
    }
  }
  const tick = (now: number) => {
    frame = 0
    const dt = now - last
    last = now
    clock += dt > 500 ? 33 : dt
    if (change && clock - change.start >= change.total) land()
    else render()
    if (change && !frozen) frame = requestAnimationFrame(tick)
  }
  const run = () => {
    if (frame || frozen) return
    last = performance.now()
    frame = requestAnimationFrame(tick)
  }

  const begin = (to: number) => {
    const forward = (to - active + count) % count
    const backward = (active - to + count) % count
    const dir = forward <= backward ? forward : -backward
    switches++
    gens.push({ c: to, pair: nextPair[to], born: switches })
    nextPair[to] = mod(nextPair[to] + 1, PAIRS)
    const wheel = Math.min(1.5 * t.move, t.move + 0.2 * t.move * Math.max(0, Math.abs(dir) - 1))
    const total = reduced.matches ? t.crossfade : Math.max(wheel, t.slots * t.stagger + t.move)
    change = { from: active, to, dir, start: clock, wheel, total }
    lastStart = clock
    if (reduced.matches) {
      active = to
      progress = 0
      place()
    }
    opts.onChange(to)
  }
  const go = (to: number) => {
    if (busy || frozen || to === active) return false
    busy = true
    begin(to)
    render()
    run()
    return true
  }

  let inView = false
  let held = false
  let started = false
  let timer = 0
  let due = 0
  let remaining = 0
  const canRun = () => autoplay && inView && !held && !document.hidden && !reduced.matches && !frozen
  const stopTimer = () => {
    if (timer) {
      window.clearTimeout(timer)
      timer = 0
      remaining = Math.max(0, due - performance.now())
    }
  }
  const startTimer = (wait: number) => {
    stopTimer()
    if (!canRun()) {
      remaining = wait
      return
    }
    due = performance.now() + wait
    timer = window.setTimeout(() => {
      timer = 0
      go((active + 1) % count)
      startTimer(t.step)
    }, wait)
  }
  const update = () => {
    if (!canRun()) return stopTimer()
    if (!started) {
      started = true
      go((active + 1) % count)
      startTimer(t.step)
    } else if (!timer) startTimer(remaining || t.step)
  }

  const measureWheel = () => {
    const q = els.queue.getBoundingClientRect()
    const box = els.pill.getBoundingClientRect()
    const text = els.pillText.getBoundingClientRect()
    geo = { centre: q.width / 2, boxTop: box.top - q.top, textTop: text.top - q.top, textLeft: text.left - q.left, widths: els.labels.map((l) => l.offsetWidth), line: text.height, boxH: box.height }
  }
  const layout = () => {
    const slots = t.slots
    t = readTokens(els.stage)
    measureWheel()
    measureRing()
    if (t.slots !== slots) {
      land()
      refill()
    }
    place()
    render()
  }

  const playing = new IntersectionObserver(
    ([entry]) => {
      inView = Boolean(entry?.isIntersecting)
      update()
    },
    { rootMargin: '0px 0px -50% 0px', threshold: 0.05 },
  )
  const onVisibility = () => update()
  const resized = new ResizeObserver(() => layout())
  const onReduced = () => {
    if (change) land()
    stopTimer()
    update()
    render()
  }

  measureWheel()
  measureRing()
  refill()
  place()
  render()
  playing.observe(els.section)
  resized.observe(els.stage)
  resized.observe(els.head)
  document.addEventListener('visibilitychange', onVisibility)
  reduced.addEventListener('change', onReduced)
  document.fonts?.ready.then(layout).catch(() => undefined)

  return {
    /** Turn to a label the pointer rests on (rows other than the pill's). */
    hover: (index: number) => go(index),
    /** Turn to a label that was pressed (queued behind a turn in progress). */
    choose: (index: number) => {
      if (busy) queued = index
      else go(index)
    },
    /** Light a label under the pointer, or draw the focus box around a focused one. */
    mark: (kind: 'hover' | 'focus', index: number | null) => {
      if (marks[kind] === index) return
      marks[kind] = index
      place()
    },
    /** How many rows a label is from the pill. */
    row: (index: number) => Math.round(rowsFromPill(index)),
    /** Pause while the pointer or keyboard focus is in the wheel. */
    hold: (on: boolean) => {
      if (on === held) return
      held = on
      if (on) stopTimer()
      else if (started) startTimer(t.step)
      else update()
    },
    /** Stop the clock at `ms` after the first turn (screenshots, tests). */
    seek: (ms: number) => {
      frozen = true
      stopTimer()
      if (frame) cancelAnimationFrame(frame)
      frame = 0
      queued = null
      change = null
      busy = false
      active = 0
      progress = 0
      switches = 0
      clock = 0
      lastStart = Number.NEGATIVE_INFINITY
      refill()
      const n = Math.max(0, Math.floor(ms / t.step))
      pinned = n > 0 ? ms - n * t.step : Number.POSITIVE_INFINITY
      for (let i = 1; i < n; i++) {
        begin((active + 1) % count)
        land()
      }
      if (n > 0) {
        begin((active + 1) % count)
        busy = true
        const current = change as Change | null
        clock = current ? current.start + (ms - n * t.step) : 0
        if (current && clock - current.start >= current.total) land()
      }
      place()
      render()
    },
    play: () => {
      frozen = false
      if (change) run()
      update()
    },
    geometry: () => ({ cx: ring.cx, cy: ring.cy, start: ring.start, gap: ring.gap, slots: t.slots, rx: t.rx, ry: t.ry, cardW: t.cardW, cardH: t.cardH, head: ring.head, wheel: ring.wheel }),
    /** Milliseconds since the last turn began (the ring light's ripple follows it). */
    since: () => {
      if (frozen) return pinned
      if (change) return clock - change.start
      if (lastStart === Number.NEGATIVE_INFINITY) return Number.POSITIVE_INFINITY
      return landedClock - lastStart + (performance.now() - landedWall)
    },
    frozen: () => frozen,
    destroy: () => {
      if (frame) cancelAnimationFrame(frame)
      window.clearTimeout(timer)
      playing.disconnect()
      resized.disconnect()
      document.removeEventListener('visibilitychange', onVisibility)
      reduced.removeEventListener('change', onReduced)
    },
  }
}

// ----- The ring light's ripple -----
// A light layer behind the wheel (the site's dispersion field in its ring composition) can bend with each turn: this
// source simulates a damped spring along the ellipse, pushed by the creatives as they travel, and writes the
// displacement and stir per sample. It is structural: any light that asks for `ring`, `sample` and `frozen` can use it.

export interface WheelRingGeometry { cx: number; cy: number; rx: number; ry: number; cardW: number; cardH: number }

export interface WheelRipple {
  samples: number
  reach: number
  slope: number
  ring: (canvas: HTMLCanvasElement) => WheelRingGeometry | null
  sample: (out: Float32Array) => boolean
  frozen: () => boolean
}

const SAMPLES = 48
const REACH = 0.6
const GUST = 11
const SPREAD = 0.09
const ZETA = 0.55
const STEP = 1000 / 120
const STIR_SPEED = 4
const STIR = 0.35
const REST = 0.004

export function createWheelRipple(engine: { readonly current: WheelEngine | null }, stage: { readonly current: HTMLElement | null }): WheelRipple {
  let times = { move: 600, stagger: 50, spring: 720, ease: bezier(0.85, 0, 0.15, 1) }
  let geo = { start: 0.18, gap: 0.16, slots: 5 }
  const LUT = 128
  let angle = new Float32Array(LUT + 1)
  const uAt = (s: number) => {
    const f = Math.min(1, Math.max(0, s)) * LUT
    const i = Math.min(LUT - 1, Math.floor(f))
    return angle[i] + (angle[i + 1] - angle[i]) * (f - i)
  }
  const measure = (rx: number, ry: number) => {
    const N = 512
    const len = new Float64Array(N + 1)
    for (let i = 1; i <= N; i++) {
      const a0 = (Math.PI * (i - 1)) / N
      const a1 = (Math.PI * i) / N
      len[i] = len[i - 1] + Math.hypot(rx * (Math.sin(a1) - Math.sin(a0)), ry * (Math.cos(a1) - Math.cos(a0)))
    }
    angle = new Float32Array(LUT + 1)
    for (let k = 0, i = 0; k <= LUT; k++) {
      const target = (len[N] * k) / LUT
      while (i < N && len[i + 1] < target) i++
      const seg = len[i + 1] - len[i] || 1
      angle[k] = (i + Math.min(1, Math.max(0, (target - len[i]) / seg))) / N
    }
  }
  measure(1, 1)

  const D = new Float32Array(SAMPLES)
  const V = new Float32Array(SAMPLES)
  const F = new Float32Array(SAMPLES)
  const taper = new Float32Array(SAMPLES)
  for (let i = 0; i < SAMPLES; i++) taper[i] = Math.sin((Math.PI * (i + 0.5)) / SAMPLES) ** 0.5
  let simulated = Number.NaN
  let resting = true

  const gust = (at: number) => {
    F.fill(0)
    const S = geo.slots
    const avg = geo.gap / times.move
    const h = 4
    for (let k = 0; k <= S; k++) {
      const local = at - (S - k) * times.stagger
      if (local <= -h || local >= times.move + h) continue
      const e = times.ease(Math.min(1, Math.max(0, local / times.move)))
      const slope = (times.ease(Math.min(1, (local + h) / times.move)) - times.ease(Math.max(0, (local - h) / times.move))) / (2 * h)
      const span = k === 0 ? geo.start : geo.gap
      const arc = k === 0 ? e * geo.start : geo.start + (k - 1 + e) * geo.gap
      const speed = (span * slope) / avg
      if (speed <= 0) continue
      const u = uAt(arc)
      for (let i = 0; i < SAMPLES; i++) {
        const du = ((i + 0.5) / SAMPLES - u) / SPREAD
        if (du > -3 && du < 3) F[i] += speed * Math.exp(-du * du)
      }
    }
  }
  const step = (at: number) => {
    gust(at)
    const dt = STEP / 1000
    const omega = (2 * Math.PI * 1000) / times.spring
    let busy = false
    for (let i = 0; i < SAMPLES; i++) {
      let v = V[i] + (-GUST * F[i] * taper[i] - omega * omega * D[i] - 2 * ZETA * omega * V[i]) * dt
      const d = Math.max(-REACH, Math.min(REACH, D[i] + v * dt))
      if (Math.abs(d) >= REACH) v = 0
      D[i] = d
      V[i] = v
      if (!busy && (Math.abs(d) > REST || Math.abs(v) > REST * 10 || F[i] > 0)) busy = true
    }
    resting = !busy
  }
  const reset = () => {
    D.fill(0)
    V.fill(0)
    simulated = 0
    resting = false
  }

  return {
    samples: SAMPLES,
    reach: REACH,
    slope: 1 / SPREAD,
    ring: (canvas) => {
      const e = engine.current
      const el = stage.current
      if (!e || !el) return null
      const g = e.geometry()
      const css = getComputedStyle(el)
      const c = curveOf(css.getPropertyValue('--ds-wheel-ease'))
      times = { move: toMs(css.getPropertyValue('--ds-wheel-move').trim(), 600), stagger: toMs(css.getPropertyValue('--ds-wheel-stagger').trim(), 50), spring: toMs(css.getPropertyValue('--ds-wheel-light-spring').trim(), 720), ease: bezier(c[0], c[1], c[2], c[3]) }
      geo = { start: g.start, gap: g.gap, slots: g.slots }
      measure(g.rx, g.ry)
      simulated = Number.NaN
      const s = el.getBoundingClientRect()
      const r = canvas.getBoundingClientRect()
      return { cx: g.cx + s.left - r.left, cy: g.cy + s.top - r.top, rx: g.rx, ry: g.ry, cardW: g.cardW, cardH: g.cardH }
    },
    sample: (out) => {
      const since = engine.current?.since() ?? Number.POSITIVE_INFINITY
      if (!Number.isFinite(since) || since < 0) {
        out.fill(0)
        return false
      }
      if (Number.isNaN(simulated) || since < simulated - STEP) reset()
      if (!resting || since - simulated < times.move * 2) {
        while (simulated + STEP <= since) {
          step(simulated)
          simulated += STEP
          if (resting && simulated > (geo.slots + 1) * times.stagger + times.move) break
        }
      }
      if (resting) {
        out.fill(0)
        return false
      }
      for (let side = 0; side < 2; side++) {
        const gain = side ? 1 : 0.8
        for (let i = 0; i < SAMPLES; i++) {
          out[side * SAMPLES + i] = gain * D[i]
          out[2 * SAMPLES + side * SAMPLES + i] = STIR * Math.min(1, Math.abs(V[i]) / STIR_SPEED)
        }
      }
      return true
    },
    frozen: () => engine.current?.frozen() ?? false,
  }
}

// ----- Styles -----
// The site's V2UseCases.module.css on the brand's tokens, shared by both flavors (the React file renders it in a style
// tag, the element adopts it). The ring's measures step up at 768, 1024 and 1280; under 768 the ring is hidden and the
// heading sits over the drum alone.
export const useCaseWheelCss = `
.ds-wheel-section { position: relative; isolation: isolate; overflow-x: clip; padding-block: var(--ds-layout-section); }
.ds-wheel {
  --rx: var(--ds-wheel-rx); --ry: var(--ds-wheel-ry); --card-w: var(--ds-wheel-card-w); --card-h: var(--ds-wheel-card-h);
  --slots: var(--ds-wheel-slots); --head-w: var(--ds-wheel-head-w);
  --q-line: calc(var(--ds-text-body-lg) * var(--ds-text-body-lg-leading));
  --q-travel: var(--ds-wheel-step);
  --q-pad: var(--ds-space-md);
  --q-height: calc(var(--ds-wheel-step) * 2.5 + var(--q-line));
  --q-box: calc(var(--q-height) + var(--q-travel) * 2);
  --q-fade: calc(var(--q-travel) - var(--q-line));
  --q-pill-h: calc(var(--ds-wheel-send) + var(--q-pad) * 2);
  --cy: calc(var(--card-h) / 2 + var(--ry));
  position: relative;
  height: calc(var(--cy) + var(--ry) + var(--ds-wheel-below));
}
.ds-wheel-light { position: absolute; top: calc(var(--ds-layout-section) * -1); left: 0; z-index: -1; display: block; width: 100%; height: calc(100% + var(--ds-layout-section) * 2); pointer-events: none; }
.ds-wheel-head { position: absolute; top: var(--cy); left: 50%; z-index: 1; width: min(var(--head-w), 100% - var(--ds-layout-gutter) * 2); margin: 0; text-align: center; transform: translate(-50%, -50%); }
.ds-wheel-ring { position: absolute; inset: 0; perspective: var(--ds-wheel-perspective); perspective-origin: 50% var(--cy); pointer-events: none; }
.ds-wheel-picture { position: absolute; top: 0; left: 0; display: grid; place-items: center; width: var(--card-w); height: var(--card-h); opacity: 0; visibility: hidden; backface-visibility: hidden; will-change: transform, opacity; }
.ds-wheel-frame { display: block; overflow: hidden; width: 100%; height: 100%; border-radius: var(--ds-radius-sm); background: var(--ds-color-surface-raised); }
.ds-wheel-frame[data-fit="tall"] { width: auto; }
.ds-wheel-frame[data-fit="wide"] { height: auto; }
.ds-wheel-frame > img { display: block; width: 100%; height: 100%; object-fit: cover; }
.ds-wheel-queue { position: absolute; top: calc(var(--cy) + var(--ry) - var(--q-travel) - var(--ds-wheel-step) - var(--q-pill-h) / 2); left: 50%; z-index: 2; width: var(--ds-wheel-pill-w); height: var(--q-box); transform: translateX(-50%); }
.ds-wheel-mask { position: absolute; inset: 0; z-index: 2; pointer-events: none; mask-image: linear-gradient(to bottom, transparent 0, transparent var(--q-line), var(--ds-color-black) var(--q-travel), var(--ds-color-black) calc(var(--q-travel) + var(--q-height)), transparent calc(var(--q-travel) + var(--q-height) + var(--q-fade)), transparent var(--q-box)); }
.ds-wheel-label { position: absolute; top: 0; left: 0; margin: 0; padding: 0; border: 0; background: none; color: var(--ds-color-fg); font-family: var(--ds-font-text); font-size: var(--ds-text-body-lg); font-weight: var(--ds-font-weight-regular); line-height: var(--q-line); white-space: nowrap; cursor: pointer; pointer-events: auto; will-change: transform, opacity; transition: opacity var(--ds-duration-micro) var(--ds-easing-out); }
.ds-wheel-label[aria-pressed="true"] { cursor: default; }
.ds-wheel-label:focus-visible { outline: none; }
.ds-wheel-label::before { position: absolute; inset: calc((var(--ds-space-3xl) - 100%) / -2) 0; content: ""; }
.ds-wheel-label[data-rest="above"] { opacity: 0.5; transform: translate(calc(var(--ds-wheel-pill-w) / 2 - 50%), var(--q-travel)); }
.ds-wheel-label[data-rest="pill"] { transform: translate(calc(var(--q-pad) + var(--ds-space-sm)), calc(var(--q-travel) + var(--ds-wheel-step) + var(--q-pad) + (var(--ds-wheel-send) - var(--q-line)) / 2)); }
.ds-wheel-label[data-rest="below"] { opacity: 0.5; transform: translate(calc(var(--ds-wheel-pill-w) / 2 - 50%), calc(var(--q-travel) + var(--ds-wheel-step) * 2.5)); }
.ds-wheel-twin { opacity: 0; pointer-events: none; }
.ds-wheel-focus { position: absolute; top: 0; left: 0; z-index: 3; width: 100%; height: var(--q-pill-h); border-radius: var(--ds-radius-panel); opacity: 0; pointer-events: none; outline: 2px solid var(--ds-color-white); outline-offset: 2px; }
.ds-wheel-focus[data-on] { opacity: 1; }
.ds-wheel-pill { position: absolute; top: calc(var(--q-travel) + var(--ds-wheel-step)); left: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; width: 100%; height: var(--q-pill-h); padding: var(--q-pad); border-radius: var(--ds-radius-panel); background: var(--ds-color-surface-raised); }
.ds-wheel-pill-text { margin-inline: var(--ds-space-sm); font-family: var(--ds-font-text); font-size: var(--ds-text-body-lg); line-height: var(--q-line); white-space: nowrap; visibility: hidden; }
.ds-wheel-send { position: relative; display: grid; flex: none; place-items: center; width: var(--ds-wheel-send); height: var(--ds-wheel-send); border-radius: var(--ds-radius-control); background: var(--ds-color-action-primary); color: var(--ds-color-action-primary-fg); transition: background-color var(--ds-duration-micro) var(--ds-easing-out); }
.ds-wheel-send::before { position: absolute; inset: calc((var(--ds-space-3xl) - var(--ds-wheel-send)) / -2); content: ""; }
.ds-wheel-send svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.ds-wheel-send:focus-visible { outline: 2px solid var(--ds-color-white); outline-offset: 2px; }
@media (hover: hover) and (pointer: fine) { .ds-wheel-send:hover { background: var(--ds-color-action-primary-hover); } }
@media (width < 768px) {
  .ds-wheel-section { --ds-wheel-ry: var(--ds-wheel-ry-phone); padding-bottom: calc(var(--ds-layout-section) - var(--ds-space-xl)); }
  .ds-wheel { --cy: calc(var(--ds-text-heading-2) * var(--ds-text-heading-2-leading)); }
  .ds-wheel-head { width: calc(100% - var(--ds-layout-gutter) * 2); }
  .ds-wheel-ring, .ds-wheel-light { display: none; }
}
@media (min-width: 768px) { .ds-wheel { --rx: var(--ds-wheel-rx-md); --ry: var(--ds-wheel-ry-md); --card-w: var(--ds-wheel-card-w-md); --card-h: var(--ds-wheel-card-h-md); --slots: var(--ds-wheel-slots-md); --head-w: var(--ds-wheel-head-w-md); } }
@media (min-width: 1024px) {
  .ds-wheel { --rx: var(--ds-wheel-rx-lg); --ry: var(--ds-wheel-ry-lg); --card-w: var(--ds-wheel-card-w-lg); --card-h: var(--ds-wheel-card-h-lg); --slots: var(--ds-wheel-slots-lg); --head-w: var(--ds-wheel-head-w-lg); }
  .ds-wheel-section[data-light] { padding-top: calc(var(--ds-layout-section) - var(--ds-space-sm)); padding-bottom: calc(var(--ds-layout-section) + var(--ds-space-3xl) - var(--ds-space-xs)); }
}
/* The site's .t-h1: the section head's 44/48 holds until 1280 here (type-section steps to 56 at 1024). */
@media (min-width: 1024px) and (max-width: 1279.98px) { .ds-wheel-head { font-size: var(--ds-text-heading-1); line-height: var(--ds-text-heading-1-leading); } }
@media (min-width: 1280px) { .ds-wheel { --rx: var(--ds-wheel-rx-xl); --ry: var(--ds-wheel-ry-xl); --card-w: var(--ds-wheel-card-w-xl); --card-h: var(--ds-wheel-card-h-xl); --head-w: var(--ds-wheel-head-w-xl); } }
@media (min-width: 1600px) { .ds-wheel-section[data-light] { padding-top: calc(var(--ds-layout-section) + var(--ds-space-xs)); padding-bottom: calc(var(--ds-layout-section) + var(--ds-space-4xl) + var(--ds-space-md)); } }
@media (prefers-reduced-motion: reduce) { .ds-wheel-label { transition: none; } }
`
react/lib/cn.ts
// 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(' ')
}
elements/components/blocks/use-case-wheel.ts
import { html, unsafeCSS, type PropertyValues } from 'lit'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import { createWheel, createWheelRipple, useCaseWheelContent, useCaseWheelCss, wheelFit, wheelLongest, wheelRest, type WheelEngine, type WheelItem, type WheelPicture, type WheelRipple } from '@/lib/use-case-wheel'
import '@/elements/components/site/creative-card'
import styles from 'virtual:tw'

// UseCaseWheel.tsx as <spyglass-use-case-wheel>: the headline inside an ellipse of creatives over a drum of audiences
// that turns every 2.4s on screen, holds under the pointer or keyboard focus, and turns to a label that is clicked or
// rested on; still with reduced motion (the creatives crossfade). `items` as JSON; `section-id` names the section;
// `as="h1"` when it opens a page; `autoplay="false"` keeps it still. A light layer goes in the `light` slot, and the
// element's `ripple` property hands it the ring's ripple. Fires `change` (detail.index) after each turn.

const picture = (p: WheelPicture) => {
	const fit = wheelFit(p)
	return html`<span class="ds-wheel-frame" data-fit=${fit === 'fill' ? '' : fit} style=${p.ratio ? `aspect-ratio: ${p.ratio}` : ''}><spyglass-creative-card .src=${p.src} .alt=${p.alt ?? ''} .fit=${p.fit} .position=${p.position} .brand=${p.brand} .caption=${p.caption} .tone=${p.tone ?? 2} ratio="fill"></spyglass-creative-card></span>`
}

/**
 * @summary The use cases wheel: a ring of creatives around the headline and a drum of audiences.
 * @slot light - A light layer behind the ring.
 * @fires change - detail.index is the audience turned to.
 */
export class UseCaseWheel extends DsElement {
	static styles = [DsElement.styles, styles, unsafeCSS(useCaseWheelCss)]
	protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="use-case-wheel"]'))
	static properties = { sectionId: { attribute: 'section-id' }, headline: {}, items: { type: Array }, as: {}, autoplay: { type: Boolean, converter: { fromAttribute: (v: string | null) => v !== 'false' } }, active: { state: true } }
	/** The section's id (React's `id`); its heading is `<id>-heading`. */
	sectionId = 'use-cases'
	headline = useCaseWheelContent.headline
	/** The audiences: { key, label, line, href, linkLabel, pairs }. */
	items: WheelItem[] = useCaseWheelContent.items
	/** h2 in a page, h1 when the wheel opens one. */
	as: 'h1' | 'h2' = 'h2'
	/** Turn by itself while on screen ("false" keeps it still). */
	autoplay = true
	declare active: number
	#engine: { current: WheelEngine | null } = { current: null }
	#stage: { current: HTMLElement | null } = { current: null }
	/** The ring's ripple, for a light layer that bends with each turn. */
	readonly ripple: WheelRipple = createWheelRipple(this.#engine, this.#stage)
	#holds = { pointer: false, focus: false }
	#lastRow: number | null = null

	constructor() {
		super()
		this.active = 0
	}

	protected updated(changed: PropertyValues) {
		if (changed.has('items') || changed.has('autoplay') || !this.#engine.current) this.#start()
	}

	disconnectedCallback() {
		super.disconnectedCallback()
		this.#engine.current?.destroy()
		this.#engine.current = null
	}

	#start() {
		const root = this.renderRoot
		const q = <T extends HTMLElement>(s: string) => root.querySelector<T>(s)
		const section = q('[data-ds="use-case-wheel"]')
		const stage = q('.ds-wheel')
		const head = q('.ds-wheel-head')
		const queue = q('.ds-wheel-mask')
		const pill = q('.ds-wheel-pill')
		const pillText = q('.ds-wheel-pill-text')
		const focusBox = q('.ds-wheel-focus')
		if (!section || !stage || !head || !queue || !pill || !pillText || !focusBox) return
		this.#engine.current?.destroy()
		const items = this.items ?? useCaseWheelContent.items
		const pictures = items.map((item, g) => item.pairs.map((_, p) => [0, 1].map((side) => q(`[data-picture="${g}-${p}-${side}"]`) as HTMLElement)))
		this.#stage.current = stage
		this.#engine.current = createWheel(
			{ section, stage, head, queue, pill, pillText, focusBox, labels: [...root.querySelectorAll<HTMLElement>('button.ds-wheel-label')], twins: [...root.querySelectorAll<HTMLElement>('.ds-wheel-twin')], pictures },
			{ autoplay: this.autoplay, onChange: (index) => { this.active = index; this.emit('change', { index }) } },
		)
	}

	#hold() { this.#engine.current?.hold(this.#holds.pointer || this.#holds.focus) }
	#onPointerMove = (event: PointerEvent) => {
		if (event.pointerType !== 'mouse') return
		const target = (event.composedPath()[0] as Element).closest?.<HTMLElement>('[data-item]') ?? null
		const index = target ? Number(target.dataset.item) : null
		const e = this.#engine.current
		e?.mark('hover', index)
		const pill = this.renderRoot.querySelector('.ds-wheel-pill')
		const row = index === null ? (pill?.contains(event.composedPath()[0] as Node) ? 0 : null) : e?.row(index)
		if (row === undefined || row === this.#lastRow) return
		this.#lastRow = row
		if (index !== null && row !== 0 && row !== null) e?.hover(index)
	}
	#onPointerEnter = () => { this.#holds.pointer = true; this.#hold() }
	#onPointerLeave = () => { this.#holds.pointer = false; this.#lastRow = null; this.#engine.current?.mark('hover', null); this.#hold() }
	#onFocus = (event: FocusEvent) => {
		const target = event.composedPath()[0] as HTMLElement
		const keyboard = target.matches(':focus-visible')
		this.#engine.current?.mark('focus', keyboard && target.dataset.item ? Number(target.dataset.item) : null)
		if (!keyboard) return
		this.#holds.focus = true
		this.#hold()
	}
	#onBlur = (event: FocusEvent) => {
		if ((event.currentTarget as HTMLElement).contains(event.relatedTarget as Node | null)) return
		this.#engine.current?.mark('focus', null)
		this.#holds.focus = false
		this.#hold()
	}

	render() {
		const id = this.sectionId
		const items = this.items ?? useCaseWheelContent.items
		const active = this.active ?? 0
		const current = items[active] ?? items[0]
		const lit = Boolean(this.querySelector('[slot="light"]'))
		const heading = this.as === 'h1'
			? html`<h1 id=${`${id}-heading`} class="ds-wheel-head type-section">${this.headline}</h1>`
			: html`<h2 id=${`${id}-heading`} class="ds-wheel-head type-section">${this.headline}</h2>`
		return html`<section data-ds="use-case-wheel" id=${id} aria-labelledby=${`${id}-heading`} ?data-light=${lit} class="ds-wheel-section text-fg"><div class="ds-wheel">${lit ? html`<div class="ds-wheel-light"><slot name="light"></slot></div>` : ''}${heading}<div class="ds-wheel-ring" aria-hidden="true">${items.map((item, g) => item.pairs.map((pair, p) => pair.map((pic, side) => html`<div data-picture=${`${g}-${p}-${side}`} class="ds-wheel-picture">${picture(pic)}</div>`)))}</div><div class="ds-wheel-queue" @pointerenter=${this.#onPointerEnter} @pointerleave=${this.#onPointerLeave} @pointermove=${this.#onPointerMove} @focusin=${this.#onFocus} @focusout=${this.#onBlur}><div class="ds-wheel-mask"><ul class="m-0 list-none p-0" role="list">${items.map((item, i) => html`<li><button type="button" class="ds-wheel-label" data-item=${i} data-rest=${wheelRest(i, active, items.length)} aria-pressed=${i === active ? 'true' : 'false'} aria-describedby=${`${id}-line-${item.key}`} @click=${() => this.#engine.current?.choose(i)}>${item.label}</button><span id=${`${id}-line-${item.key}`} class="sr-only">${item.line}</span></li>`)}</ul>${items.map((item) => html`<span class="ds-wheel-label ds-wheel-twin" aria-hidden="true">${item.label}</span>`)}</div><span class="ds-wheel-focus" aria-hidden="true"></span><div class="ds-wheel-pill"><span class="ds-wheel-pill-text" aria-hidden="true">${wheelLongest(items)}</span><a class="ds-wheel-send" href=${current.href} aria-label=${current.linkLabel}><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M3 8h10M8.5 3.5 13 8l-4.5 4.5"></path></svg></a></div></div></div></section>`
	}
}

define('use-case-wheel', UseCaseWheel)

Reference: Site v2/V2UseCases (UseCaseWheel.tsx, skillsMotion.ts, ringLight.ts, V2UseCases.module.css) and tokens.css 355-393 and 659-700: ring 152x216 (300x240 at 768, 384x292 at 1024, 440x332 at 1280; 140 tall under 768), cards 48x64 to 108x144, 3 to 5 slots, 96px below; the drum's 52px rows, a 312px pill 12px in with the 36px arrow; turns every 2400ms over 600ms on cubic-bezier(0.85, 0, 0.15, 1), 50ms stagger, new pair from 0.4 fading in over 500ms after 100ms, crossfade 360ms with reduced motion; the ring hidden under 768.