Site
Enterprise hero
The site's enterprise hero: the headline, lead and two buttons centered in a hero at least the window's height, inside a ring of twelve creatives that rise in, bob while seen, come forward with a tag naming the hook, and step through their set on a press.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add enterprise-hero<script type="module" src="/spyglass-ds/elements/enterprise-hero.js"></script>Building creative engines for the world’s most ambitious brands
Powered by the first agent-native creative search engine.
Usage
The head of an enterprise or sales page whose proof is the creatives themselves. One per page.
Never
- Third-party creatives you may not show: pass your own through
cards(placeholders are neutral gradients) - More than one White button
- Cards that keep moving with reduced motion
- A ring around a long headline: the words keep a 216px room in the middle
cards takes up to twelve sets, clockwise from the top left (the two side places show from 1280, the six corner and middle places on phones). Each card: brand, title, ratio (3:4, 4:5 or 1:1), hook, meta (the tag's lines) and src; without src it is a neutral gradient with the brand. The tag finds room below, above or inside its card, off the headline and inside the hero. Each ring card takes src, fit and position; one without src carries data-ds-placeholder.
Adds with it: ascii-drift, button, creative-card, enterprise-page
Props
The web component takes the same as attributes or properties (<spyglass-enterprise-hero>); title is heading there.
<EnterpriseHero>
| Prop | Type | Default |
|---|---|---|
content | EnterpriseHeroContent | |
cards | RingCard[][] Twelve sets of creatives, clockwise from the top left. | ringPlaceholders |
id | string The section's id (the heading is `<id>-heading`). | 'enterprise' |
className | string |
Examples
The same example in React and as web components; both render identically.
import { EnterpriseHero } from '@/react/components/site/EnterpriseHero'
// The headline inside the ring; point at a card for its tag, press it for the next creative (Acme placeholders: pass your creatives through `cards`).
export default function Hero() {
return <EnterpriseHero />
}<!-- The headline inside the ring; point at a card for its tag, press it for the next creative (Acme placeholders: pass your creatives through `cards`). -->
<spyglass-enterprise-hero></spyglass-enterprise-hero>Source
'use client'
import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties } from 'react'
import { Button } from '@/react/components/ui/Button'
import { ASCII_TEXTURE } from '@/lib/textures'
import { placeRingTag, preloadNextRingCard, ringAspect, ringCardLabel, ringCss, ringIntent, ringPlaceStyle, ringPlaceholders, watchRing, RING_PLACES, type RingCard } from '@/lib/enterprise-ring'
import { enterpriseHeroContent, type EnterpriseHeroContent } from '@/lib/pages/enterprise'
import { cn } from '@/react/lib/cn'
import { imageFit } from '@/lib/image'
// The site's enterprise hero (pages/Enterprise EnterprisePage .hero and HeroRing): at least the window's height less the
// header (640px at the least), the headline in the section head (its first line kept whole from 768), the lead and two
// buttons centered, and twelve creatives around them (ten from 768, six on phones, sized to the room). Each card rises
// in (40ms apart), then bobs 8px on a 6s loop while the hero is on screen; under a mouse (after 80ms), on focus or a tap it
// comes forward to 1.1 with a tag (its hook and how long it ran) placed below, above or inside where it fits; a press
// shows the next creative in its set, announced politely. Every 6s, while nobody touches it, one card comes forward
// for 2s. From 1024 two tiles of the ASCII texture sit at the sides, cleared around the words. Reduced motion keeps the
// cards still. `cards` takes your creatives (sets of RingCard, clockwise from the top left); without `src` a card is a
// neutral gradient.
export interface EnterpriseHeroProps {
content?: EnterpriseHeroContent
/** Twelve sets of creatives, clockwise from the top left. */
cards?: RingCard[][]
/** The section's id (the heading is `<id>-heading`). */
id?: string
className?: string
}
export function EnterpriseHero({ content: c = enterpriseHeroContent, cards = ringPlaceholders, id = 'enterprise', className }: EnterpriseHeroProps) {
const sets = cards.slice(0, RING_PLACES.length)
const [at, setAt] = useState<number[]>(() => sets.map(() => 0))
const [stepped, setStepped] = useState<boolean[]>(() => sets.map(() => false))
const [shown, setShown] = useState<number | null>(null)
const [hint, setHint] = useState<number | null>(null)
const [said, setSaid] = useState('')
const [held, setHeld] = useState<number | null>(null)
const sectionRef = useRef<HTMLElement>(null)
const ringRef = useRef<HTMLUListElement>(null)
const places = useRef(new Map<number, HTMLLIElement>())
const pointer = useRef('mouse')
const intent = useRef(0)
const busy = useRef(false)
const forward = shown ?? hint
if (forward !== null && forward !== held) setHeld(forward)
const next = (i: number) => {
const n = sets[i].length
const to = ((at[i] ?? 0) + 1) % n
setAt((prev) => sets.map((_, j) => (j === i ? to : prev[j] ?? 0)))
setStepped((prev) => sets.map((_, j) => (j === i ? true : prev[j] ?? false)))
const card = sets[i][to]
setSaid(`${to + 1} of ${n} with this hook: ${card.brand}, ${card.title}.`)
}
useLayoutEffect(() => {
const el = held === null ? null : places.current.get(held)
if (el && sectionRef.current) placeRingTag(el, sectionRef.current)
}, [held, at, stepped])
useEffect(() => {
busy.current = shown !== null
}, [shown])
useEffect(() => preloadNextRingCard(sets, shown, at), [shown, at, sets])
useEffect(() => {
const ring = ringRef.current
const section = sectionRef.current
if (!ring || !section) return
const watch = watchRing(ring, section, () => busy.current, setHint)
const onDown = (e: PointerEvent) => {
if (e.pointerType !== 'mouse' && !(e.target as HTMLElement).closest('[data-ring-card]')) setShown(null)
}
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') setShown(null)
}
section.addEventListener('pointerdown', onDown)
section.addEventListener('keydown', onKey)
return () => {
watch.stop()
section.removeEventListener('pointerdown', onDown)
section.removeEventListener('keydown', onKey)
window.clearTimeout(intent.current)
}
}, [])
return (
<section ref={sectionRef} id={id} aria-labelledby={`${id}-heading`} data-ds="enterprise-hero" className={cn('ds-ent-hero relative grid items-center overflow-x-clip bg-surface text-fg', className)}>
<style href="ds-enterprise-hero" precedence="ds">{ringCss}</style>
<div className="mx-auto w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] px-(--ds-layout-gutter)">
<div data-ring-words="" className="relative z-2 mx-auto flex max-w-(--ds-ent-hero-head-w) flex-col items-center gap-6 text-center">
<h1 id={`${id}-heading`} className="max-w-(--ds-ent-hero-title-w) type-section"><span className="ds-ent-hero-keep">{c.title[0]}</span> {c.title[1]}</h1>
<p className="type-body-lg text-fg-soft">{c.lead}</p>
<div className="flex flex-col flex-wrap justify-center gap-3 self-stretch md:flex-row md:self-auto">
<Button href={c.primary.href}>{c.primary.label}</Button>
<Button href={c.secondary.href} variant="secondary">{c.secondary.label}</Button>
</div>
</div>
</div>
<span aria-hidden="true" className="ds-ent-hero-ascii" style={{ backgroundImage: `url("${ASCII_TEXTURE}"), url("${ASCII_TEXTURE}")` }} />
<ul ref={ringRef} className="ds-ring" aria-label={c.label} data-run="false">
{sets.map((set, i) => {
const card = set[at[i] ?? 0]
if (!card) return null
const slot = RING_PLACES[i]
return (
<li
key={i}
ref={(el) => { if (el) places.current.set(i, el); else places.current.delete(i) }}
data-ring-place=""
className="ds-ring-place"
data-wide={slot.wide ? '' : undefined}
data-phone={slot.phone ? '' : undefined}
data-forward={forward === i ? '' : undefined}
style={ringPlaceStyle(i) as CSSProperties}
>
<button
type="button"
className="ds-ring-card"
data-ring-card=""
aria-label={ringCardLabel(card, at[i] ?? 0, set.length)}
onPointerDown={(e) => { pointer.current = e.pointerType }}
onKeyDown={() => { pointer.current = 'keyboard' }}
onPointerEnter={(e) => {
if (e.pointerType !== 'mouse') return
window.clearTimeout(intent.current)
intent.current = window.setTimeout(() => setShown(i), ringRef.current ? ringIntent(ringRef.current) : 0)
}}
onPointerLeave={(e) => {
if (e.pointerType !== 'mouse') return
window.clearTimeout(intent.current)
setShown((s) => (s === i ? null : s))
}}
onFocus={(e) => { if (e.currentTarget.matches(':focus-visible')) setShown(i) }}
onBlur={() => setShown((s) => (s === i ? null : s))}
onClick={() => {
const touch = pointer.current === 'touch' || pointer.current === 'pen'
pointer.current = 'mouse'
setShown(i)
if (touch && shown !== i) return
next(i)
}}
>
<span className="ds-ring-frame" style={{ aspectRatio: ringAspect(card.ratio) }} data-tone={card.src ? undefined : card.tone ?? (i % 4) + 1} data-ds-placeholder={card.src ? undefined : ''} data-stepped={stepped[i] ? '' : undefined}>
{card.src ? <img key={card.src} src={card.src} alt="" draggable={false} style={imageFit(card)} /> : <span key={`${card.brand}-${card.title}`} className="absolute inset-0 flex items-end p-2"><span className="hidden type-label text-fg md:block">{card.brand}</span></span>}
</span>
</button>
{held === i ? (
<div className="ds-ring-tag" data-ring-tag="" data-shown={forward === i ? '' : undefined} aria-hidden="true">
<span>{`Hook: ${card.hook.toLowerCase()}`}</span>
{card.meta.map((line) => <span key={line} className="text-fg-muted">{line}</span>)}
{stepped[i] ? <span className="text-fg-muted">{`${(at[i] ?? 0) + 1} of ${set.length} with this hook`}</span> : null}
</div>
) : null}
</li>
)
})}
</ul>
<p className="sr-only" aria-live="polite">{said}</p>
</section>
)
}
export default EnterpriseHero// The enterprise hero's ring, shared by EnterpriseHero.tsx and <spyglass-enterprise-hero> (site pages/Enterprise
// HeroRing.tsx and HeroRing.module.css): twelve places around the headline (ten from 768, six on phones), each holding a
// set of creatives. A card rises in (a 40ms stagger), then bobs 8px on a 6s loop while the hero is on screen; under a
// mouse (after 80ms), on focus or a tap it comes forward (1.1) with a tag naming its hook and how long it ran; a press
// steps to the next creative in its set. Every 6s, while nobody is touching it, one card comes forward on its own for 2s.
import type { ImageSlot } from '@/lib/image'
export type RingRatio = '3:4' | '4:5' | '1:1'
export interface RingCard extends ImageSlot {
/** The advertiser (the placeholder's label and the button's name). */
brand: string
/** The ad's headline. */
title: string
/** The creative's shape. */
ratio: RingRatio
/** The hook it uses, in the tag ("Hook: product showcase"). */
hook: string
/** The tag's lines under the hook: "Ran 7 days", "Posted 9 days ago". */
meta: string[]
/** The creative (fit and position place it; the button is named by the brand and title). Without one the card
* draws a neutral placeholder. */
src?: string
/** The placeholder's neutral gradient, 1 (darkest) to 4. */
tone?: 1 | 2 | 3 | 4
}
type Slot = { u: number; v: number; s: number; wide?: true; mid?: [number, number]; phone?: [number, number] }
/** The places, clockwise from the top left, as fractions of the ring's half width and height. */
export const RING_PLACES: Slot[] = [
{ u: -0.86, v: -0.84, s: 1, mid: [-0.92, -1], phone: [-1, -1] },
{ u: -0.46, v: -1, s: 0.84 },
{ u: -0.04, v: -1, s: 0.92, phone: [0, -0.92] },
{ u: 0.4, v: -1, s: 0.84 },
{ u: 0.84, v: -0.86, s: 1, mid: [0.92, -1], phone: [1, -1] },
{ u: 1, v: 0.04, s: 0.84, wide: true },
{ u: 0.82, v: 0.86, s: 1, mid: [0.92, 1], phone: [1, 1] },
{ u: 0.38, v: 1, s: 0.84 },
{ u: -0.06, v: 1, s: 0.92, phone: [0, 0.92] },
{ u: -0.48, v: 1, s: 0.84 },
{ u: -0.88, v: 0.84, s: 1, mid: [-0.92, 1], phone: [-1, 1] },
{ u: -1, v: -0.06, s: 0.84, wide: true },
]
/** A place's custom properties (the CSS does the rest). */
export function ringPlaceStyle(i: number): Record<string, string> {
const s = RING_PLACES[i]
return { '--u': String(s.u), '--v': String(s.v), '--s': String(s.s), '--mu': String(s.mid?.[0] ?? s.u), '--mv': String(s.mid?.[1] ?? s.v), '--pu': String(s.phone?.[0] ?? 0), '--pv': String(s.phone?.[1] ?? 0), '--i': String(i), '--float-at': String((i * 1.27) % 6) }
}
export const ringAspect = (r: RingRatio) => r.replace(':', ' / ')
const card = (brand: string, title: string, ratio: RingRatio, hook: string, meta: string, tone: 1 | 2 | 3 | 4): RingCard => ({ brand, title, ratio, hook, meta: [meta], tone })
/** Acme placeholders: twelve sets of three or four, as the site's ring. */
export const ringPlaceholders: RingCard[][] = [
[card('Acme Shoes', 'Everyday sneaker', '3:4', 'Product showcase', 'Ran 190 days', 3), card('Acme Shoes', 'Better than leather', '3:4', 'Product showcase', 'Ran 7 days', 2), card('Acme Wear', 'The grid', '4:5', 'Product showcase', 'Ran 9 days', 4)],
[card('Acme Skin', 'Body cleanser', '3:4', 'New launch reveal', 'Ran 12 days', 4), card('Acme Skin', 'The fragrance', '1:1', 'New launch reveal', 'Ran 55 days', 2), card('Acme Beauty', 'Eau de parfum', '3:4', 'New launch reveal', 'Ran 11 days', 3)],
[{ ...card('Acme Shoes', 'New colorway', '4:5', 'New launch reveal', 'Posted 21 days ago', 4), meta: ['Posted 21 days ago', '486K views'] }, card('Acme Drinks', 'The drop of the summer', '3:4', 'New launch reveal', 'Ran 59 days', 3), card('Acme Skin', 'Blue glass', '4:5', 'New launch reveal', 'Ran 9 days', 2), card('Acme Beauty', 'Lip liner', '3:4', 'New launch reveal', 'Ran 34 days', 4)],
[card('Acme Audio', 'Headphone (a)', '3:4', 'New launch reveal', 'Ran 17 days', 2), card('Acme Audio', 'Headphone (1)', '1:1', 'New launch reveal', 'Ran 13 days', 3), card('Acme Beauty', 'The kit', '4:5', 'New launch reveal', 'Ran 105 days', 4)],
[{ ...card('Acme Pantry', 'Blossom honey', '4:5', 'Product showcase', 'Posted 5 days ago', 3), meta: ['Posted 5 days ago', '64K views'] }, card('Acme Goods', 'Sorted and stunning', '4:5', 'Product showcase', 'Ran 21 days', 2), card('Acme Skin', 'The dewy cream', '4:5', 'Product showcase', 'Ran 18 days', 4), card('Acme Beauty', 'Essentials', '3:4', 'Product showcase', 'Running 7 days', 3)],
[card('Acme Fit', 'Made by the sea', '1:1', 'New launch reveal', 'Ran 30 days', 2), card('Acme Fit', 'The powders', '1:1', 'New launch reveal', 'Ran 4 days', 3), card('Acme Skin', 'Bottles', '4:5', 'New launch reveal', 'Ran 3 days', 4)],
[{ ...card('Acme Drinks', 'Poured', '4:5', 'Product showcase', 'Posted 9 days ago', 4), meta: ['Posted 9 days ago', '128K views'] }, card('Acme Shoes', 'Color edit', '3:4', 'Product showcase', 'Ran 47 days', 3), card('Acme Skin', 'Gingerbread', '4:5', 'Product showcase', 'Ran 6 days', 2), card('Acme Beauty', 'Velvet', '4:5', 'Product showcase', 'Ran 6 days', 4)],
[card('Acme Fit', 'The meal', '4:5', 'New launch reveal', 'Ran 16 days', 3), card('Acme Beauty', 'The collection', '3:4', 'New launch reveal', 'Ran 19 days', 4), card('Acme Beauty', 'Blush', '4:5', 'New launch reveal', 'Ran 5 days', 2)],
[card('Acme Drinks', 'Lemon lovers', '4:5', 'New launch reveal', 'Ran 10 days', 4), card('Acme Beauty', 'Pear', '3:4', 'New launch reveal', 'Ran 19 days', 3), card('Acme Skin', 'The travel duo', '1:1', 'New launch reveal', 'Ran 10 days', 2)],
[card('Acme Home', 'The pot', '1:1', 'New launch reveal', 'Ran 18 days', 3), card('Acme Home', 'The candle', '3:4', 'New launch reveal', 'Ran 129 days', 2), card('Acme Skin', 'Violet jar', '3:4', 'New launch reveal', 'Ran 5 days', 4)],
[card('Acme Beauty', 'The pink edit', '4:5', 'New launch reveal', 'Ran 121 days', 4), card('Acme Beauty', 'Meet the tube', '3:4', 'New launch reveal', 'Ran 38 days', 2), card('Acme Beauty', 'Cloud set', '1:1', 'New launch reveal', 'Ran 39 days', 3)],
[card('Acme Beauty', 'Warm bronzer', '4:5', 'New launch reveal', 'Ran 49 days', 2), card('Acme Skin', 'Peach stack', '4:5', 'New launch reveal', 'Ran 5 days', 4), card('Acme Beauty', 'The fragrance', '1:1', 'New launch reveal', 'Ran 138 days', 3)],
]
/** Starts loading the creative a press on card `i` would show next, so a real picture never flashes blank (the site's HeroRing does the same when a card comes forward). */
export function preloadNextRingCard(sets: RingCard[][], i: number | null, at: number[]) {
if (i === null || typeof Image === 'undefined') return
const set = sets[i]
const src = set?.[((at[i] ?? 0) + 1) % set.length]?.src
if (!src) return
const img = new Image()
img.src = src
img.decode().catch(() => undefined)
}
export const ringCardLabel = (c: RingCard, at: number, of: number) => `${c.brand}: ${c.title}. Hook: ${c.hook.toLowerCase()}. ${c.meta.join(', ')}. ${at + 1} of ${of} with this hook. Show the next one.`
// The ring's CSS, the same for both flavors. The place's size follows the room the hero has (container units); from
// 768 the two side places go, below 768 only the six phone places stay.
export const ringCss = `
.ds-ring { position: absolute; z-index: 1; inset: 0; margin: 0; padding: 0; list-style: none; container-type: size; }
.ds-ring-place {
--L: round(down, clamp(var(--ds-ent-ring-card-min), min((50cqh - var(--ds-ent-ring-words)) / 0.96, 16cqw), var(--ds-ent-ring-card)), 4px);
--rx: calc(50cqw - var(--L) * 0.42 - var(--ds-ent-ring-edge));
--ry: calc(50cqh - var(--L) / 2 - var(--ds-ent-ring-edge));
position: absolute; left: calc(50% + var(--u) * var(--rx)); top: calc(50% + var(--v) * var(--ry)); z-index: 1;
width: round(var(--L) * var(--s) * 0.75, 4px); translate: -50% -50%;
animation: ds-ring-enter var(--ds-duration-slow) var(--ds-ent-ring-ease-enter) calc(var(--i) * var(--ds-duration-stagger)) both;
}
.ds-ring-place[data-forward] { z-index: 3; }
@keyframes ds-ring-enter { from { opacity: 0; transform: translateY(var(--ds-ent-ring-enter-y)) scale(var(--ds-ent-ring-enter-scale)) rotate(var(--ds-ent-ring-enter-turn)); } to { opacity: 1; transform: none; } }
.ds-ring-card {
display: block; width: 100%; padding: 0; border: 0; border-radius: var(--ds-radius-sm); background: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
animation: ds-ring-float 6s ease-in-out calc(var(--float-at) * -1s) infinite; animation-play-state: paused;
transition: scale var(--ds-duration-glide) var(--ds-ent-ring-ease-hover);
}
.ds-ring-card:focus-visible { outline: 2px solid var(--ds-color-edge-focus); outline-offset: 2px; }
.ds-ring[data-run="true"] .ds-ring-card { animation-play-state: running; }
@keyframes ds-ring-float { 0%, 100% { translate: 0; } 50% { translate: 0 calc(var(--ds-ent-ring-float) * -1); } }
.ds-ring-place[data-forward] .ds-ring-card { scale: var(--ds-ent-ring-forward); }
@media (hover: hover) and (pointer: fine) { .ds-ring-card:hover { scale: var(--ds-ent-ring-forward); } }
.ds-ring-card:active, .ds-ring-place[data-forward] .ds-ring-card:active { scale: var(--ds-ent-ring-press); transition-duration: var(--ds-duration-press); }
.ds-ring-frame { position: relative; display: block; width: 100%; border-radius: inherit; overflow: hidden; background: var(--ds-color-surface-raised); transition: aspect-ratio var(--ds-duration-glide) var(--ds-ent-ring-ease-hover); }
.ds-ring-frame img { display: block; width: 100%; height: 100%; object-fit: cover; user-select: none; }
.ds-ring-frame[data-tone="1"] { background: linear-gradient(to bottom, var(--ds-color-neutral-4), var(--ds-color-neutral-2)); }
.ds-ring-frame[data-tone="2"] { background: linear-gradient(to bottom, var(--ds-color-neutral-5), var(--ds-color-neutral-3)); }
.ds-ring-frame[data-tone="3"] { background: linear-gradient(to bottom, var(--ds-color-neutral-6), var(--ds-color-neutral-4)); }
.ds-ring-frame[data-tone="4"] { background: linear-gradient(to bottom, var(--ds-color-neutral-7), var(--ds-color-neutral-5)); }
.ds-ring-frame[data-stepped] > * { animation: ds-ring-swap var(--ds-duration-glide) var(--ds-ent-ring-ease-enter) both; }
@keyframes ds-ring-swap { from { opacity: 0; transform: scale(var(--ds-ent-ring-swap-from)); } }
.ds-ring-tag {
--grown: calc((var(--ds-ent-ring-forward) - 1) / 2 * 100%);
position: absolute; z-index: 1; top: calc(100% + var(--grown) + var(--ds-ent-ring-tag-gap)); left: calc(var(--grown) * -1);
display: flex; flex-direction: column; align-items: flex-start; padding: 8px 12px;
border: 1px solid var(--ds-color-edge); border-radius: var(--ds-radius-panel); background: var(--ds-color-surface-subtle); color: var(--ds-color-fg);
font-size: var(--ds-text-ui); line-height: var(--ds-text-ui-leading); white-space: nowrap; pointer-events: none;
opacity: 0; transition: opacity var(--ds-duration-micro) var(--ds-easing-loop);
}
.ds-ring-tag[data-side="above"] { top: auto; bottom: calc(100% + var(--grown) + var(--ds-ent-ring-tag-gap)); }
.ds-ring-tag[data-side="inside"] { top: auto; bottom: var(--ds-ent-ring-tag-gap); left: var(--ds-ent-ring-tag-gap); }
.ds-ring-tag[data-align="end"] { right: calc(var(--grown) * -1); left: auto; }
.ds-ring-tag[data-side="inside"][data-align="end"] { right: var(--ds-ent-ring-tag-gap); }
.ds-ring-tag[data-shown] { opacity: 1; animation: ds-ring-tag-in var(--ds-duration-micro) var(--ds-easing-loop); }
@keyframes ds-ring-tag-in { from { opacity: 0; translate: 0 4px; } }
@media (width < 1280px) { .ds-ring-place { left: calc(50% + var(--mu) * var(--rx)); top: calc(50% + var(--mv) * var(--ry)); } .ds-ring-place[data-wide] { display: none; } }
@media (width < 768px) {
.ds-ring-place { --L: var(--ds-ent-ring-card-phone); --rx: calc(50cqw - var(--L) * 0.42 - var(--ds-layout-gutter)); left: calc(50% + var(--pu) * var(--rx)); top: calc(50% + var(--pv) * var(--ry)); width: round(var(--L) * 0.75, 4px); }
.ds-ring-place:not([data-phone]) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
.ds-ring-place, .ds-ring-card, .ds-ring-frame[data-stepped] > *, .ds-ring-tag[data-shown] { animation: none; }
.ds-ring-card, .ds-ring-frame { transition: none; }
.ds-ring-place[data-forward] .ds-ring-card, .ds-ring-card:hover, .ds-ring-card:active { scale: none; }
}
.ds-ent-hero-ascii { display: none; }
@media (min-width: 1024px) {
.ds-ent-hero-ascii {
position: absolute; z-index: 0; inset: 0; display: block; pointer-events: none; opacity: var(--ds-ent-hero-ascii-opacity);
background-position: left center, right center; background-size: var(--ds-ent-hero-ascii-tile), var(--ds-ent-hero-ascii-tile); background-repeat: no-repeat;
mask-image: linear-gradient(to right, var(--ds-color-black) calc(50% - var(--ds-ent-hero-ascii-clear) - var(--ds-ent-hero-ascii-feather)), transparent calc(50% - var(--ds-ent-hero-ascii-clear)), transparent calc(50% + var(--ds-ent-hero-ascii-clear)), var(--ds-color-black) calc(50% + var(--ds-ent-hero-ascii-clear) + var(--ds-ent-hero-ascii-feather))), linear-gradient(to bottom, transparent, var(--ds-color-black) 160px, var(--ds-color-black) calc(100% - 160px), transparent);
mask-composite: intersect;
}
}
.ds-ent-hero { min-height: max(var(--ds-ent-hero-min-h), calc(100svh - var(--ds-size-header))); }
@media (width < 768px) { .ds-ent-hero { padding-block: calc(var(--ds-ent-ring-card-phone) + var(--ds-ent-ring-edge) + var(--ds-space-3xl)); } }
@media (min-width: 768px) { .ds-ent-hero-keep { white-space: nowrap; } }
`
const ms = (el: Element, name: string, fallback: number) => {
const v = getComputedStyle(el).getPropertyValue(name).trim()
const n = parseFloat(v)
return Number.isFinite(n) ? (v.endsWith('ms') ? n : v.endsWith('s') ? n * 1000 : n) : fallback
}
export const ringIntent = (el: Element) => ms(el, '--ds-ent-ring-intent', 80)
/**
* Places a card's tag below it, else above, else inside, keeping it inside the hero, off the headline's words and in the
* window; it aligns to the card's end when it would run past the hero's right edge.
*/
export function placeRingTag(place: HTMLElement, section: HTMLElement) {
const tag = place.querySelector<HTMLElement>('[data-ring-tag]')
if (!tag) return
const clear = parseFloat(getComputedStyle(section).getPropertyValue('--ds-ent-ring-tag-clear')) || 16
const s = section.getBoundingClientRect()
const words = [...section.querySelectorAll<HTMLElement>('[data-ring-words] > *')].map((n) => n.getBoundingClientRect())
const next = section.nextElementSibling ?? (section.getRootNode() instanceof ShadowRoot ? (section.getRootNode() as ShadowRoot).host.nextElementSibling : null)
const below = next ? Math.max(0, parseFloat(getComputedStyle(next).paddingTop) - clear) : 0
const fits = () => {
const r = tag.getBoundingClientRect()
return r.top >= s.top + clear && r.bottom <= s.bottom + (tag.dataset.side === 'below' ? below : -clear) && r.bottom <= window.innerHeight - clear && !words.some((b) => r.left < b.right + clear && b.left < r.right + clear && r.top < b.bottom + clear && b.top < r.bottom + clear)
}
tag.dataset.align = 'start'
for (const side of ['below', 'above', 'inside']) {
tag.dataset.side = side
if (side === 'inside' || fits()) break
}
if (tag.getBoundingClientRect().right > s.right - clear) tag.dataset.align = 'end'
}
export interface RingWatch {
/** Whether the ring is on screen and the tab visible. */
running: () => boolean
stop: () => void
}
/**
* Runs the ring while it is seen (writes data-run on it) and, unless motion is reduced, brings one card forward on its
* own every 6s for 2s while nobody is touching the hero. `busy` says a card is already forward.
*/
export function watchRing(ring: HTMLElement, section: HTMLElement, busy: () => boolean, setHint: (i: number | null) => void): RingWatch {
let running = false
let onScreen = false
const sync = () => {
running = onScreen && document.visibilityState === 'visible'
ring.dataset.run = String(running)
}
const io = new IntersectionObserver(([entry]) => {
onScreen = entry.isIntersecting
sync()
})
io.observe(ring)
document.addEventListener('visibilitychange', sync)
let timer = 0
const cleanups: (() => void)[] = []
if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches && navigator.webdriver !== true) {
const intent = ringIntent(ring)
const every = ms(ring, '--ds-ent-ring-hint-every', 6000)
const hold = ms(ring, '--ds-ent-ring-hint-hold', 2000)
let last: number | null = null
let seenSince = 0
let touched = 0
const touch = () => {
touched = performance.now()
setHint(null)
}
const step = () => {
const now = performance.now()
if (!running) seenSince = 0
else if (!seenSince) seenSince = now
const ready = running && !busy() && now - seenSince >= every - intent && now - touched >= every - intent
const places = [...ring.querySelectorAll<HTMLElement>('[data-ring-place]')]
const pool = ready ? places.map((el, i) => [i, el] as const).filter(([i, el]) => i !== last && el.offsetWidth > 0).map(([i]) => i) : []
if (!pool.length) {
timer = window.setTimeout(step, hold)
return
}
last = pool[Math.floor(Math.random() * pool.length)]
setHint(last)
timer = window.setTimeout(() => {
setHint(null)
timer = window.setTimeout(step, every - hold)
}, hold)
}
timer = window.setTimeout(step, hold)
const onOver = (e: PointerEvent) => {
if (e.composedPath().some((n) => n instanceof HTMLElement && n.hasAttribute('data-ring-card'))) touch()
}
section.addEventListener('pointerover', onOver)
for (const t of ['pointerdown', 'keydown', 'focusin'] as const) section.addEventListener(t, touch)
cleanups.push(() => {
section.removeEventListener('pointerover', onOver)
for (const t of ['pointerdown', 'keydown', 'focusin'] as const) section.removeEventListener(t, touch)
})
}
return {
running: () => running,
stop: () => {
window.clearTimeout(timer)
io.disconnect()
document.removeEventListener('visibilitychange', sync)
cleanups.forEach((f) => f())
},
}
}// 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 { ifDefined } from 'lit/directives/if-defined.js'
import { styleMap } from 'lit/directives/style-map.js'
import { keyed } from 'lit/directives/keyed.js'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import { ASCII_TEXTURE } from '@/lib/textures'
import { placeRingTag, preloadNextRingCard, ringAspect, ringCardLabel, ringCss, ringIntent, ringPlaceStyle, ringPlaceholders, watchRing, RING_PLACES, type RingCard, type RingWatch } from '@/lib/enterprise-ring'
import { enterpriseHeroContent, type EnterpriseHeroContent } from '@/lib/pages/enterprise'
import '@/elements/components/ui/button'
import styles from 'virtual:tw'
import { imageFit } from '@/lib/image'
// EnterpriseHero.tsx as <spyglass-enterprise-hero>: the headline, lead and two buttons centered in a hero at least the
// window's height, with twelve creatives around them that rise in, bob while seen, come forward with a tag under the
// pointer, on focus or a tap (and one on its own every 6s), and step through their set on a press. `content`, `cards`
// (JSON: sets of { brand, title, ratio, hook, meta, src, tone }) and `section-id`.
/**
* @summary The enterprise hero: the headline inside a ring of creatives that step on a press.
*/
export class EnterpriseHero extends DsElement {
static styles = [DsElement.styles, styles, unsafeCSS(ringCss)]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="enterprise-hero"]'))
static properties = { content: { type: Object }, cards: { type: Array }, sectionId: { attribute: 'section-id' }, at: { state: true }, stepped: { state: true }, shown: { state: true }, hint: { state: true }, said: { state: true }, held: { state: true } }
/** The headline's two lines, the lead, the buttons and the ring's name. */
content: EnterpriseHeroContent = enterpriseHeroContent
/** Twelve sets of creatives, clockwise from the top left. */
cards: RingCard[][] = ringPlaceholders
/** The section's id (the heading is `<id>-heading`). */
sectionId = 'enterprise'
at: number[] = []
stepped: boolean[] = []
shown: number | null = null
hint: number | null = null
said = ''
held: number | null = null
#watch: RingWatch | null = null
#pointer = 'mouse'
#intent = 0
get #section() { return this.renderRoot.querySelector<HTMLElement>('[data-ds="enterprise-hero"]') }
#onDown = (e: PointerEvent) => {
if (e.pointerType !== 'mouse' && !e.composedPath().some((n) => n instanceof HTMLElement && n.hasAttribute('data-ring-card'))) this.shown = null
}
#onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') this.shown = null }
#start() {
const section = this.#section
const ring = this.renderRoot.querySelector<HTMLElement>('.ds-ring')
if (!section || !ring) return
this.#watch = watchRing(ring, section, () => this.shown !== null, (i) => (this.hint = i))
section.addEventListener('pointerdown', this.#onDown)
section.addEventListener('keydown', this.#onKey)
}
#stop() {
this.#watch?.stop()
this.#watch = null
const section = this.#section
section?.removeEventListener('pointerdown', this.#onDown)
section?.removeEventListener('keydown', this.#onKey)
window.clearTimeout(this.#intent)
}
connectedCallback() {
super.connectedCallback()
if (this.hasUpdated) this.updateComplete.then(() => this.#start())
}
disconnectedCallback() {
super.disconnectedCallback()
this.#stop()
}
protected firstUpdated(changed: PropertyValues) {
super.firstUpdated(changed)
this.#start()
}
protected willUpdate(changed: PropertyValues) {
if (changed.has('cards')) {
this.at = (this.cards ?? []).map(() => 0)
this.stepped = (this.cards ?? []).map(() => false)
}
const forward = this.shown ?? this.hint
if (forward !== null && forward !== this.held) this.held = forward
}
protected updated(changed: PropertyValues) {
super.updated(changed)
if (changed.has('shown') || changed.has('at')) preloadNextRingCard((this.cards ?? ringPlaceholders).slice(0, RING_PLACES.length), this.shown, this.at)
if (changed.has('held') || changed.has('at') || changed.has('stepped')) {
const el = this.held === null ? null : this.renderRoot.querySelectorAll<HTMLElement>('[data-ring-place]')[this.held]
const section = this.#section
if (el && section) placeRingTag(el, section)
}
}
#next(i: number, sets: RingCard[][]) {
const n = sets[i].length
const to = ((this.at[i] ?? 0) + 1) % n
this.at = sets.map((_, j) => (j === i ? to : this.at[j] ?? 0))
this.stepped = sets.map((_, j) => (j === i ? true : this.stepped[j] ?? false))
const card = sets[i][to]
this.said = `${to + 1} of ${n} with this hook: ${card.brand}, ${card.title}.`
}
render() {
const c = this.content ?? enterpriseHeroContent
const sets = (this.cards ?? ringPlaceholders).slice(0, RING_PLACES.length)
const id = this.sectionId
const forward = this.shown ?? this.hint
return html`<section id=${id} aria-labelledby=${`${id}-heading`} data-ds="enterprise-hero" class="ds-ent-hero relative grid items-center overflow-x-clip bg-surface text-fg"><div class="mx-auto w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] px-(--ds-layout-gutter)"><div data-ring-words="" class="relative z-2 mx-auto flex max-w-(--ds-ent-hero-head-w) flex-col items-center gap-6 text-center"><h1 id=${`${id}-heading`} class="max-w-(--ds-ent-hero-title-w) type-section"><span class="ds-ent-hero-keep">${c.title[0]}</span> ${c.title[1]}</h1><p class="type-body-lg text-fg-soft">${c.lead}</p><div class="flex flex-col flex-wrap justify-center gap-3 self-stretch md:flex-row md:self-auto"><spyglass-button href=${c.primary.href}>${c.primary.label}</spyglass-button><spyglass-button href=${c.secondary.href} variant="secondary">${c.secondary.label}</spyglass-button></div></div></div><span aria-hidden="true" class="ds-ent-hero-ascii" style=${`background-image: url("${ASCII_TEXTURE}"), url("${ASCII_TEXTURE}")`}></span><ul class="ds-ring" aria-label=${c.label} data-run="false">${sets.map((set, i) => {
const at = this.at[i] ?? 0
const card = set[at]
if (!card) return nothing
const slot = RING_PLACES[i]
return html`<li data-ring-place="" class="ds-ring-place" data-wide=${ifDefined(slot.wide ? '' : undefined)} data-phone=${ifDefined(slot.phone ? '' : undefined)} data-forward=${ifDefined(forward === i ? '' : undefined)} style=${styleMap(ringPlaceStyle(i))}><button type="button" class="ds-ring-card" data-ring-card="" aria-label=${ringCardLabel(card, at, set.length)}
@pointerdown=${(e: PointerEvent) => { this.#pointer = e.pointerType }}
@keydown=${() => { this.#pointer = 'keyboard' }}
@pointerenter=${(e: PointerEvent) => { if (e.pointerType !== 'mouse') return; window.clearTimeout(this.#intent); const ring = this.renderRoot.querySelector('.ds-ring'); this.#intent = window.setTimeout(() => (this.shown = i), ring ? ringIntent(ring) : 0) }}
@pointerleave=${(e: PointerEvent) => { if (e.pointerType !== 'mouse') return; window.clearTimeout(this.#intent); if (this.shown === i) this.shown = null }}
@focus=${(e: FocusEvent) => { if ((e.currentTarget as HTMLElement).matches(':focus-visible')) this.shown = i }}
@blur=${() => { if (this.shown === i) this.shown = null }}
@click=${() => { const touch = this.#pointer === 'touch' || this.#pointer === 'pen'; this.#pointer = 'mouse'; const was = this.shown; this.shown = i; if (touch && was !== i) return; this.#next(i, sets) }}
><span class="ds-ring-frame" style=${`aspect-ratio: ${ringAspect(card.ratio)}`} data-tone=${ifDefined(card.src ? undefined : card.tone ?? (i % 4) + 1)} data-ds-placeholder=${ifDefined(card.src ? undefined : '')} data-stepped=${ifDefined(this.stepped[i] ? '' : undefined)}>${keyed(card.src ?? `${card.brand}-${card.title}`, card.src ? html`<img src=${card.src} alt="" draggable="false" style=${styleMap(imageFit(card) ?? {})}>` : html`<span class="absolute inset-0 flex items-end p-2"><span class="hidden type-label text-fg md:block">${card.brand}</span></span>`)}</span></button>${this.held === i ? html`<div class="ds-ring-tag" data-ring-tag="" data-shown=${ifDefined(forward === i ? '' : undefined)} aria-hidden="true"><span>${`Hook: ${card.hook.toLowerCase()}`}</span>${card.meta.map((line) => html`<span class="text-fg-muted">${line}</span>`)}${this.stepped[i] ? html`<span class="text-fg-muted">${`${at + 1} of ${set.length} with this hook`}</span>` : nothing}</div>` : nothing}</li>`
})}</ul><p class="sr-only" aria-live="polite">${this.said}</p></section>`
}
}
define('enterprise-hero', EnterpriseHero)Reference: Site pages/Enterprise (EnterprisePage .hero, Enterprise.module.css, HeroRing.tsx, HeroRing.module.css) and content/pages/enterprise.ts: min height max(640px, 100svh less the header); --ent-ring-* (cards 136 to 240px from the room, 128 on phones, 24px edge; forward 1.1 after 80ms; float 8px over 6s; a hint every 6s held 2s); the ASCII tiles from 1024 cleared 464px around the words; the entrance 480ms with a 40ms stagger and no blur (site 1500ms, 24ms, a 16px blur), the hover 320ms (site 300ms), the tag 160ms (site 150ms) and no shadow under a forward card.