Blocks
Templates wall
The site's templates wall: a helix of tiles drifting toward the viewer and turning slowly around the words, the headline over a chip that rolls through the template names on a raised surface stretching to each name, the lead and a quiet status line.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add templates-wall<script type="module" src="/spyglass-ds/elements/templates-wall.js"></script>Build your own
- Brand monitor
- Hook finder
- Creator shortlist
Acme playbooks that run inside your agent, every morning.
Coming soon
Build your own
- Ad library
- Creator sourcing tool
- Competitor monitor
- Trend tracker
Ready-made playbooks that run inside your agent on Spyglass data.
Coming soon
Usage
Introducing a set of templates or playbooks: the templates page's first section (hero) or a section on the home page. pictures fills the tiles with your own creatives; without them the tiles take four neutral tones.
Never
- Another brand's ads or photos in the tiles: pass your own creatives or keep the neutral tones
- A filter, a tint or a glow over the pictures: color as posted
- More than one rolling chip in a view
- Tiles that keep moving with reduced motion: it holds one still frame
The tiles keep clear of the words: the engine measures the headline, the chip, the lead and the status and fades any tile whose edge comes within 32px of them, and lets none reach the section's top or bottom edge. It runs only while the wall is on screen and the tab is visible. at draws the frame at a given time and holds it, for a still. pictures takes srcs or image slots (fit becomes the tile's background size, position its background position). Without pictures each tile carries data-ds-placeholder.
Adds with it: automation-run, creative-card, resources-page
Props
The web component takes the same as attributes or properties (<spyglass-templates-wall>); title is heading there.
<TemplatesWall>
| Prop | Type | Default |
|---|---|---|
content | TemplatesWallContent | |
pictures | (string | ImageSlot)[] Pictures for the tiles, used in turn (a src or { src, alt, fit, position }); none draws neutral tones. | |
hero | boolean The page's first section: an h1 and the window's height less the header. | false |
at | number Draw the frame at this time (ms) and hold it. | |
id | string The section's id (its heading is `<id>-heading`). | 'templates' |
className | string |
Examples
The same example in React and as web components; both render identically.
import { TemplatesWall } from '@/react/components/blocks/TemplatesWall'
// The wall as a home page section, with Acme's copy.
export default function Section() {
return <TemplatesWall id="home-templates" content={{ headline: 'Build your own', names: ['Brand monitor', 'Hook finder', 'Creator shortlist'], lead: 'Acme playbooks that run inside your agent, every morning.', status: 'Coming soon' }} />
}<!-- The wall as a home page section, with Acme's copy. -->
<spyglass-templates-wall section-id="home-templates" content='{"headline":"Build your own","names":["Brand monitor","Hook finder","Creator shortlist"],"lead":"Acme playbooks that run inside your agent, every morning.","status":"Coming soon"}'></spyglass-templates-wall>import { TemplatesWall } from '@/react/components/blocks/TemplatesWall'
// The templates page's first section with the neutral tiles, held on its first frame (`at`), as a still for a print or a
// screenshot; the Section example runs.
export default function Hero() {
return <TemplatesWall hero at={0} />
}<!-- The templates page's first section with the neutral tiles, held on its first frame (`at`), as a still for a print or a screenshot; the Section example runs. -->
<spyglass-templates-wall hero at="0"></spyglass-templates-wall>Source
'use client'
import { useEffect, useRef } from 'react'
import { createTemplatesWall, TEMPLATES_WALL_TILES, templatesWallKey } from '@/lib/templates-wall'
import { templatesWallContent, type TemplatesWallContent } from '@/lib/pages/templates'
import { cn } from '@/react/lib/cn'
import type { ImageSlot } from '@/lib/image'
// The site's templates wall (v2/V2Templates): a helix of tiles drifting toward the viewer and turning slowly around
// the words (lib/templates-wall.ts), the headline over a chip that rolls through the template names on a raised
// surface stretching to each name, the lead and a quiet status line. The tiles keep clear of the words and fade before
// the edges. `pictures` fills the tiles in turn (the user's own creatives, color as posted); without them the tiles
// take four neutral tones. `hero` makes it the page's first section (an h1, the window's height under the header);
// otherwise an h2 section with the section padding. Reduced motion holds one still frame; `at` draws the frame at
// that time (ms) and holds it.
export interface TemplatesWallProps {
content?: TemplatesWallContent
/** Pictures for the tiles, used in turn (a src or { src, alt, fit, position }); none draws neutral tones. */
pictures?: (string | ImageSlot)[]
/** The page's first section: an h1 and the window's height less the header. */
hero?: boolean
/** Draw the frame at this time (ms) and hold it. */
at?: number
/** The section's id (its heading is `<id>-heading`). */
id?: string
className?: string
}
const TILES = Array.from({ length: TEMPLATES_WALL_TILES }, (_, j) => j)
export function TemplatesWall({ content: c = templatesWallContent, pictures, hero = false, at, id = 'templates', className }: TemplatesWallProps) {
const scene = useRef<HTMLDivElement>(null)
const key = `${templatesWallKey(pictures)}|${at ?? ''}|${c.names.join('|')}`
useEffect(() => {
const root = scene.current
if (!root) return
const one = (name: string) => root.querySelector<HTMLElement>(`[data-tpl="${name}"]`)!
const all = (name: string) => [...root.querySelectorAll<HTMLElement>(`[data-tpl="${name}"]`)]
const wall = createTemplatesWall({ root, tunnel: one('tunnel'), box: one('box'), tiles: all('tile'), rows: all('row'), names: all('name'), chip: one('chip'), capL: one('cap-l'), capR: one('cap-r'), bar: one('bar') }, { pictures, at })
return () => wall.destroy()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [key])
const Heading = hero ? 'h1' : 'h2'
const headingId = `${id}-heading`
return (
<section data-ds="templates-wall" id={id} aria-labelledby={headingId} data-hero={hero ? '' : undefined} className={cn('ds-tpl relative isolate z-1 overflow-hidden bg-surface text-fg', className)}>
<style href="ds-templates-wall" precedence="ds">{css}</style>
<div ref={scene} className="ds-tpl-scene relative grid place-items-center">
<div aria-hidden="true" data-tpl="tunnel" className="pointer-events-none absolute inset-0">
<div data-tpl="box" className="ds-tpl-box">
{TILES.map((j) => <span key={j} data-tpl="tile" data-ds-placeholder={pictures?.length ? undefined : ''} className="ds-tpl-tile" />)}
</div>
</div>
<div className="relative z-1 mx-auto flex w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] flex-col items-center px-(--ds-layout-gutter) text-center">
<div className="ds-tpl-line flex flex-col items-center gap-y-2 type-section text-fg">
<Heading id={headingId} data-tpl="row" className="ds-tpl-headline whitespace-nowrap">{c.headline}</Heading>
<span aria-hidden="true" data-tpl="chip" className="ds-tpl-chip relative inline-grid px-3 md:px-4">
<span className="ds-tpl-surface absolute inset-0">
<span data-tpl="cap-l" className="ds-tpl-cap" />
<span data-tpl="bar" className="ds-tpl-bar" />
<span data-tpl="cap-r" className="ds-tpl-cap" />
</span>
<span className="ds-tpl-window relative grid justify-items-center overflow-hidden py-2">
{c.names.map((name) => <span key={name} data-tpl="name" className="ds-tpl-name whitespace-nowrap">{name}</span>)}
</span>
</span>
</div>
<ul className="sr-only">
{c.names.map((name) => <li key={name}>{name}</li>)}
</ul>
<div className="mt-8 flex flex-col items-center gap-4">
<p data-tpl="row" className="ds-tpl-lead max-w-(--ds-layout-measure) type-body-xl text-fg-soft">{c.lead}</p>
<p data-tpl="row" className="type-ui text-fg-faint">{c.status}</p>
</div>
</div>
</div>
</section>
)
}
export default TemplatesWall
const css = `
.ds-tpl { padding-block: var(--ds-layout-section); }
.ds-tpl[data-hero] { padding-block: 0 calc(var(--ds-layout-section) - var(--ds-templates-edge)); }
.ds-tpl-scene { min-height: 100svh; }
.ds-tpl[data-hero] .ds-tpl-scene { min-height: calc(100svh - var(--ds-space-4xl)); }
.ds-tpl-box {
position: absolute; top: 50%; left: 50%;
width: calc(var(--ds-templates-design-w) * 1px); height: calc(var(--ds-templates-design-h) * 1px);
perspective: var(--ds-templates-perspective); transform: translate(-50%, -50%);
}
.ds-tpl-tile {
position: absolute; inset: 0; display: block; margin: auto;
width: var(--ds-templates-tile-w); height: var(--ds-templates-tile-h);
border-radius: var(--ds-radius-sm); background-color: var(--ds-color-surface-subtle);
background-position: center; background-size: cover; background-repeat: no-repeat;
visibility: hidden; opacity: 0; backface-visibility: hidden; user-select: none; will-change: transform, opacity;
}
.ds-tpl-tile[data-tone="1"] { background-image: linear-gradient(var(--ds-color-neutral-4), var(--ds-color-neutral-2)); }
.ds-tpl-tile[data-tone="2"] { background-image: linear-gradient(var(--ds-color-neutral-5), var(--ds-color-neutral-3)); }
.ds-tpl-tile[data-tone="3"] { background-image: linear-gradient(var(--ds-color-neutral-6), var(--ds-color-neutral-4)); }
.ds-tpl-tile[data-tone="4"] { background-image: linear-gradient(var(--ds-color-neutral-7), var(--ds-color-neutral-5)); }
.ds-tpl-headline { font: inherit; }
.ds-tpl-lead { font-weight: var(--ds-font-weight-medium); text-wrap: balance; }
.ds-tpl-surface { opacity: 0; }
.ds-tpl-scene[data-ready] .ds-tpl-surface { opacity: var(--ds-templates-chip-opacity); }
.ds-tpl-cap, .ds-tpl-bar { position: absolute; top: 0; left: 50%; height: 100%; background: var(--ds-color-surface-raised); translate: -50% 0; }
.ds-tpl-cap { aspect-ratio: 1; border-radius: var(--ds-radius-panel); }
.ds-tpl-bar { width: var(--ds-space-4xl); }
.ds-tpl-window { mask-image: linear-gradient(transparent, var(--ds-color-black) var(--ds-space-md), var(--ds-color-black) calc(100% - var(--ds-space-md)), transparent); }
.ds-tpl-name { grid-area: 1 / 1; }
.ds-tpl-name:not(:first-child) { opacity: 0; }
@media (min-width: 768px) {
.ds-tpl-scene {
--ds-templates-design-w: var(--ds-templates-design-w-md); --ds-templates-design-h: var(--ds-templates-design-h-md);
--ds-templates-count: var(--ds-templates-count-md); --ds-templates-near: var(--ds-templates-near-md);
}
}
@media (min-width: 1024px) { .ds-tpl[data-hero] .ds-tpl-scene { min-height: calc(100svh - var(--ds-size-header)); } }
@media (width < 372px) {
.ds-tpl-line { font-size: var(--ds-text-heading-3); line-height: var(--ds-text-heading-3-leading); }
.ds-tpl-lead { font-size: var(--ds-text-heading-4); line-height: var(--ds-text-heading-4-leading); }
}
`// The templates wall's motion (site v2/V2Templates/templatesMotion.ts), framework-free so the React component and the
// web component run the same code: a helix of tiles drifting toward the viewer and turning slowly around the words,
// each tile fading in where it clears the headline and out before it reaches the edge, while the chip under the
// headline rolls through the template names and its surface stretches to each name's width.
//
// Tiles are elements the wall styles itself: with `pictures` each shows one (a src or { src, fit, position }: background
// cover unless `fit` says otherwise, color as posted);
// without, each takes one of four neutral tones (data-tone 1 to 4), so the wall never needs a third-party picture.
// Every length, count and duration is a --ds-templates-* token read from the root, so the CSS decides the layout.
// Reduced motion draws one still frame (the first name, the tunnel at rest). `at` draws the frame at that time and
// holds it (a still for print and screenshots).
import { toSlot, type ImageFit, type ImageSlot } from '@/lib/image'
export interface TemplatesWallElements {
root: HTMLElement
tunnel: HTMLElement
box: HTMLElement
tiles: HTMLElement[]
/** The rows of words the tiles keep clear of (the headline, the chip, the lead, the status). */
rows: HTMLElement[]
names: HTMLElement[]
chip: HTMLElement
capL: HTMLElement
capR: HTMLElement
bar: HTMLElement
}
export interface TemplatesWallOptions {
/** Pictures for the tiles, used in turn (a src or { src, fit, position }); none draws the neutral tones. */
pictures?: (string | ImageSlot)[]
/** Draw the frame at this time (ms) and hold it. */
at?: number
}
export interface TemplatesWall {
destroy(): void
}
/** The number of tile elements the wall renders (the pool the tunnel draws from). */
export const TEMPLATES_WALL_TILES = 80
type Tier = 'near' | 'mid' | 'far'
interface Place { n: number; pick: number; flip: number; along: number; across: number; tile: number }
const TIER_SCALE: Record<Tier, number> = { near: 1.5, mid: 1, far: 0.5 }
const TIER_NEAR = 1.25
const TIER_FAR = 0.6
const CLEAR_BAND = 0.15
const TONES = 4
function bezier(x1: number, y1: number, x2: number, y2: number) {
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: number) => {
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)
}
}
function readTokens(el: HTMLElement) {
const css = getComputedStyle(el)
const v = (name: string) => css.getPropertyValue(name).trim()
const ms = (name: string) => {
const raw = v(name)
const n = parseFloat(raw) || 0
return raw.endsWith('ms') ? n : raw.endsWith('s') ? n * 1000 : n
}
const num = (name: string) => parseFloat(v(name)) || 0
const curve = v('--ds-easing-templates-name').match(/-?\d*\.?\d+/g)?.map(Number) ?? [0.85, 0, 0.15, 1]
return {
ease: bezier(curve[0] ?? 0.85, curve[1] ?? 0, curve[2] ?? 0.15, curve[3] ?? 1),
step: ms('--ds-templates-name-step') || 2400,
move: ms('--ds-templates-name-move') || 600,
appear: ms('--ds-templates-appear') || 600,
gather: ms('--ds-templates-gather'),
appearScale: num('--ds-templates-appear-scale'),
edge: num('--ds-templates-edge'),
designW: num('--ds-templates-design-w') || 500,
designH: num('--ds-templates-design-h') || 1084,
tileW: num('--ds-templates-tile-w') || 176,
tileH: num('--ds-templates-tile-h') || 220,
pitch: (num('--ds-templates-tile-h') || 220) + num('--ds-templates-tile-gap'),
perTurn: num('--ds-templates-per-turn') || 18.5,
perspective: num('--ds-templates-perspective') || 520,
count: num('--ds-templates-count') || 74,
near: num('--ds-templates-near'),
drift: num('--ds-templates-drift'),
turn: num('--ds-templates-turn'),
nearDim: num('--ds-templates-near-dim'),
brightFrom: num('--ds-templates-bright-from') || 560,
brightUntil: num('--ds-templates-bright-until') || 880,
clear: num('--ds-templates-clear'),
}
}
const clamp01 = (n: number) => Math.min(1, Math.max(0, n))
const smooth = (n: number) => {
const x = clamp01(n)
return x * x * (3 - 2 * x)
}
const mod = (n: number, m: number) => ((n % m) + m) % m
/** A picture's fit as the tile's background size (the tile is a background, not an img). */
const tileSize = (fit?: ImageFit) => (fit === 'contain' || fit === 'scale-down' ? 'contain' : fit === 'fill' ? '100% 100%' : fit === 'none' ? 'auto' : '')
/** The pictures' sources, for re-running the wall when they change. */
export const templatesWallKey = (pictures?: (string | ImageSlot)[]) => (pictures ?? []).map((p) => { const s = toSlot(p); return `${s.src ?? ''} ${s.fit ?? ''} ${s.position ?? ''}` }).join('|')
const squircle = (x: number, y: number) => (x ** 4 + y ** 4) ** 0.25
export function createTemplatesWall(els: TemplatesWallElements, options: TemplatesWallOptions = {}): TemplatesWall {
const slots = (options.pictures ?? []).map(toSlot).filter((p) => p.src)
const pictures = slots.map((p) => p.src!)
const picks = Math.max(1, pictures.length || TONES * 7)
const names = els.names.length
const reduced = window.matchMedia('(prefers-reduced-motion: reduce)')
const frozen = options.at !== undefined
let t = readTokens(els.root)
let S = 0
let radius = 0
let dz = 1
let stepDeg = 0
let scale = 1
let halfW = 0
let halfH = 0
let clearA = 1
let clearB = 1
let places: (Place | undefined)[] = []
let free: number[] = []
const present: number[] = []
const whole: boolean[] = []
const tiers: Tier[] = []
let chipH = 0
let barW = 1
let widths: number[] = []
const flowAt = (clock: number) => ((t.drift / dz) * clock) / 1000
const turnAt = (clock: number) => (-t.turn * clock) / 1000
const tierAt = (z: number): Tier => {
const drawn = (t.perspective / z) * scale
return drawn >= TIER_NEAR ? 'near' : drawn >= TIER_FAR ? 'mid' : 'far'
}
const measure = () => {
t = readTokens(els.root)
S = Math.round(t.count)
radius = (t.pitch * t.perTurn) / (2 * Math.PI)
dz = t.pitch / t.perTurn
stepDeg = 360 / t.perTurn
const W = els.tunnel.clientWidth
const H = els.tunnel.clientHeight
scale = Math.max(W / t.designW, H / t.designH) || 1
halfW = W / 2
halfH = H / 2
els.box.style.transform = `translate(-50%, -50%) scale(${scale})`
const frame = els.tunnel.getBoundingClientRect()
const cx = frame.left + frame.width / 2
const cy = frame.top + frame.height / 2
const corners: [number, number][] = []
let blockW = 1
let blockH = 1
for (const row of els.rows) {
const r = row.getBoundingClientRect()
const x = Math.max(Math.abs(r.left - cx), Math.abs(r.right - cx)) + t.clear
const y = Math.max(Math.abs(r.top - cy), Math.abs(r.bottom - cy)) + t.clear
corners.push([x, y])
blockW = Math.max(blockW, x)
blockH = Math.max(blockH, y)
}
const grow = Math.max(1, ...corners.map(([x, y]) => squircle(x / blockW, y / blockH)))
clearA = blockW * grow
clearB = blockH * grow
places = []
free = els.tiles.map((el, j) => {
el.style.visibility = ''
present[j] = 0
return j
})
chipH = els.chip.offsetHeight
barW = els.bar.offsetWidth || 1
const pad = parseFloat(getComputedStyle(els.chip).paddingInlineStart) || 0
widths = els.names.map((n) => Math.ceil((n.offsetWidth + 2 * pad) / 4) * 4)
}
const decoded = new Map<string, boolean>()
const keep: HTMLImageElement[] = []
const loaded = (url: string) => {
const state = decoded.get(url)
if (state !== undefined) return state
decoded.set(url, false)
const img = new Image()
img.src = url
keep.push(img)
const done = () => {
decoded.set(url, true)
if (!raf && !settle) settle = requestAnimationFrame(() => {
settle = 0
if (!raf) draw()
})
}
img.decode().then(done, done)
return false
}
const dress = (j: number, pick: number, tier: Tier) => {
const el = els.tiles[j]!
tiers[j] = tier
el.style.width = `${t.tileW * TIER_SCALE[tier]}px`
el.style.height = `${t.tileH * TIER_SCALE[tier]}px`
if (pictures.length) {
const url = pictures[pick % pictures.length]!
if (el.dataset.src !== url) {
el.dataset.src = url
el.style.backgroundImage = `url("${url}")`
const slot = slots[pick % slots.length]!
el.style.backgroundSize = tileSize(slot.fit)
el.style.backgroundPosition = slot.position ?? ''
}
whole[j] = loaded(url)
} else {
el.dataset.tone = String((pick % TONES) + 1)
whole[j] = true
}
}
const release = (place: Place) => {
els.tiles[place.tile]!.style.visibility = ''
free.push(place.tile)
place.tile = -1
}
const drawName = (clock: number) => {
const k = Math.max(0, Math.floor(clock / t.step))
const local = clock - k * t.step
const pos = k === 0 ? 0 : k - 1 + t.ease(clamp01(local / t.move))
els.names.forEach((el, i) => {
const d = mod(i - pos + names / 2, names) - names / 2
el.style.transform = `translate3d(0, ${d * chipH}px, 0)`
el.style.opacity = Math.abs(d) < 1 ? '1' : '0'
})
const i0 = Math.floor(pos)
const f = pos - i0
const w0 = widths[mod(i0, names)] ?? 0
const w1 = widths[mod(i0 + 1, names)] ?? 0
const reach = Math.max(0, (w0 + (w1 - w0) * f) / 2 - chipH / 2)
els.capL.style.transform = `translate3d(${-reach}px, 0, 0)`
els.capR.style.transform = `translate3d(${reach}px, 0, 0)`
els.bar.style.transform = `scaleX(${(2 * reach) / barW})`
}
const drawTunnel = (clock: number, dt: number) => {
const flow = flowAt(clock)
const turn = turnAt(clock)
const f = t.perspective
const perMs = t.drift / dz / 1000 || 1e-9
const far = t.near + S * dz
for (let i = 0; i < S; i++) {
const n = i + S * Math.floor((flow - i) / S)
let place = places[i]
if (!place || place.n !== n) {
if (place && place.tile >= 0) release(place)
const best = (n + ((t.brightFrom + t.brightUntil) / 2 - t.near) / dz) / perMs
const quarter = mod(-Math.round((n * stepDeg + turnAt(best)) / 90), 4)
const sideways = quarter % 2 === 1
place = places[i] = { n, pick: mod(n, picks), flip: quarter * 90, along: sideways ? t.tileW : t.tileH, across: sideways ? t.tileH : t.tileW, tile: -1 }
}
const z = t.near + (flow - n) * dz
const angle = mod(n * stepDeg + turn, 360)
const rad = (angle * Math.PI) / 180
const dx = -Math.sin(rad)
const dy = Math.cos(rad)
const zIn = z + place.along / 2
const zOut = z - place.along / 2
let clear = Infinity
let reach = Infinity
let offL = true
let offR = true
if (zOut > 1) {
reach = 0
for (let edge = 0; edge < 2; edge++) {
const zEdge = edge ? zOut : zIn
const r = (f * radius) / zEdge
const half = ((place.across / 2) * f) / zEdge
for (let side = -1; side <= 1; side++) {
const x = (r * dx + side * half * dy) * scale
const y = (r * dy - side * half * dx) * scale
if (!edge) clear = Math.min(clear, squircle(x / clearA, y / clearB))
reach = Math.max(reach, Math.abs(y))
offL &&= x < -halfW
offR &&= x > halfW
}
}
}
const bright = (t.nearDim + (1 - t.nearDim) * smooth((z - t.near) / (t.brightFrom - t.near))) * (1 - smooth((z - t.brightUntil) / (far - t.brightUntil))) * smooth((clear - 1) / CLEAR_BAND)
const room = halfH - t.edge - reach
const held = place.tile >= 0
const wanted = (held ? room > 0 : room > 8) && !offL && !offR && bright >= 0.004
if (!held) {
if (!wanted || !free.length) continue
place.tile = free.pop() as number
present[place.tile] = 0
dress(place.tile, place.pick, tierAt(z))
}
const j = place.tile
const el = els.tiles[j]!
if (wanted) {
if (!whole[j] && pictures.length) whole[j] = loaded(pictures[place.pick % pictures.length]!)
if (present[j]! > 0 || (whole[j] && !gathering) || dt === Infinity) present[j] = Math.min(1, present[j]! + dt / t.appear)
} else {
present[j] = Math.max(0, present[j]! - dt / t.appear)
if (present[j] === 0) {
release(place)
continue
}
}
const tier = tierAt(z)
if (tier !== tiers[j]) dress(j, place.pick, tier)
const here = 1 - (1 - present[j]!) ** 3
const size = (t.appearScale + (1 - t.appearScale) * here) / TIER_SCALE[tiers[j]!]
el.style.transform = `translateZ(${(f - z).toFixed(2)}px) rotateZ(${angle.toFixed(3)}deg) translateY(${radius.toFixed(1)}px) rotateX(90deg) rotateZ(${place.flip}deg) scale(${size.toFixed(4)})`
el.style.opacity = (bright * here).toFixed(3)
el.style.visibility = present[j]! > 0 ? 'visible' : ''
}
if (gathering && (performance.now() >= gatherUntil || places.every((p) => !p || p.tile < 0 || whole[p.tile]))) gathering = false
}
let clock = options.at ?? 0
let last = 0
let raf = 0
let settle = 0
let inView = false
let armed = false
let gathering = false
let gatherUntil = 0
let gatherTimer = 0
// A first frame (dt Infinity) shows every tile that is ready at once; the clock runs from there.
const draw = (dt = Infinity) => {
const at = reduced.matches && !frozen ? 0 : clock
drawName(at)
drawTunnel(at, dt)
}
const running = () => armed && inView && !document.hidden && !frozen && !reduced.matches
const tick = (now: number) => {
const dt = now - last > 500 ? 33 : now - last
last = now
clock += dt
draw(dt)
raf = requestAnimationFrame(tick)
}
const sync = () => {
if (running() && !raf) {
last = performance.now()
raf = requestAnimationFrame(tick)
} else if (!running() && raf) {
cancelAnimationFrame(raf)
raf = 0
}
}
const arm = () => {
if (armed) return
armed = true
gathering = !frozen && pictures.length > 0
gatherUntil = performance.now() + t.gather
gatherTimer = window.setTimeout(() => {
if (gathering && !raf) draw()
}, t.gather)
measure()
draw()
els.root.dataset.ready = ''
sync()
}
const near = new IntersectionObserver(([e]) => e?.isIntersecting && arm(), { rootMargin: '100% 0px' })
near.observe(els.tunnel)
const seen = new IntersectionObserver(([e]) => {
inView = !!e?.isIntersecting
sync()
})
seen.observe(els.tunnel)
const remeasure = () => {
if (!armed) return
measure()
draw()
}
let lastW = els.tunnel.clientWidth
const ro = new ResizeObserver(() => {
const w = els.tunnel.clientWidth
if (w === lastW) return
lastW = w
remeasure()
})
ro.observe(els.tunnel)
let alive = true
document.fonts?.ready.then(() => alive && remeasure())
const onReduced = () => {
if (armed) draw()
sync()
}
reduced.addEventListener('change', onReduced)
document.addEventListener('visibilitychange', sync)
arm()
return {
destroy() {
alive = false
cancelAnimationFrame(raf)
cancelAnimationFrame(settle)
clearTimeout(gatherTimer)
near.disconnect()
seen.disconnect()
ro.disconnect()
reduced.removeEventListener('change', onReduced)
document.removeEventListener('visibilitychange', sync)
},
}
}// The templates wall's copy and the templates page's copy (site content/v2/templates.ts, content/home.ts templates,
// content/pages/templates.ts and templatesCities.ts), with Acme's material: the names are the templates' own kinds,
// never a platform's product. Both flavors read this file; the page's header and footer come from site-chrome.ts.
import { siteChrome } from '@/lib/pages/site-chrome'
import type { ImageSlot } from '@/lib/image'
import type { RunItem } from '@/lib/automation-run'
export interface TemplatesWallContent {
/** The line over the rolling chip. */
headline: string
/** The names the chip rolls through, one per step. */
names: string[]
lead: string
/** The quiet line under the lead (the site's "Coming soon"). */
status: string
}
export const templatesWallContent: TemplatesWallContent = {
headline: 'Build your own',
names: ['Ad library', 'Creator sourcing tool', 'Competitor monitor', 'Trend tracker'],
lead: 'Ready-made playbooks that run inside your agent on Spyglass data.',
status: 'Coming soon',
}
// ----- The templates page (site app/templates/page.tsx): the wall as the hero, the automation run, what each template
// brings back (TemplateCities: a row per template fanning out its items), the questions and the close. -----
export interface TemplateCityItem extends ImageSlot {
key: string
alt: string
title: string
meta?: string
}
export interface TemplateCityRow {
key: string
name: string
href: string
/** The line under the row's name when it opens. */
line: string
items: TemplateCityItem[]
}
// Acme placeholder pictures for the rows: a square in one of four neutral steps, lighter at the top, with the
// advertiser at the foot, so the fan never needs a third-party picture (it carries data-ds-placeholder, so it counts
// as a placeholder). Pass your own `src` (with `fit` and `position`).
const STEPS = [['#262626', '#0F0F0F'], ['#363636', '#1A1A1A'], ['#4D4D4D', '#262626'], ['#666666', '#363636']] // the creative card's four tones (neutral 4 to 2 up to 7 to 5)
const placeholder = (n: number, label: string) => {
const [top, bottom] = STEPS[n % STEPS.length]!
return `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" data-ds-placeholder="" width="256" height="256"><defs><linearGradient id="g" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="${top}"/><stop offset="1" stop-color="${bottom}"/></linearGradient></defs><rect width="256" height="256" fill="url(#g)"/><text x="20" y="232" fill="#D4D4D4" font-family="sans-serif" font-size="22" letter-spacing="1">${label.toUpperCase()}</text></svg>`)}`
}
const ADVERTISERS = ['Acme Skin', 'Acme Drinks', 'Acme Fit', 'Acme Studio', 'Acme Home', 'Acme Motors', 'Acme Foods', 'Acme Travel', 'Acme Pets', 'Acme Wear']
const acme = (key: string, n: number, meta: (i: number) => string, shift = 0): TemplateCityItem[] =>
Array.from({ length: n }, (_, i) => {
const title = ADVERTISERS[(i + shift) % ADVERTISERS.length]!
return { key: `${key}-${i + 1}`, src: placeholder(i + shift, title), alt: `${title} creative`, title, meta: meta(i) }
})
export const templatesPageContent = {
chrome: siteChrome,
wall: templatesWallContent,
cities: {
id: 'templates-cities',
headline: 'What each template brings back',
lead: 'Coming soon. Real ads, creators and posts, the kind each one will send your agent.',
status: templatesWallContent.status,
rows: [
{ key: 'adLibrary', name: 'Ad library', href: '/use-cases/paid-ads', line: 'Every morning at 8:00, every ad from the brands you follow.', items: acme('ads', 10, (i) => `Ad, ${[74, 26, 48, 12, 9, 31, 5, 17, 40, 22][i]} days live`) },
{ key: 'creators', name: 'Creator sourcing tool', href: '/use-cases/creator-sourcing', line: 'Every Friday at 10:00, creators who fit your audience, place and size.', items: acme('creators', 10, () => 'Creator post', 1) },
{ key: 'monitor', name: 'Competitor monitor', href: '/use-cases/competitive-analysis', line: "Every Monday at 8:00, a competitor's new ads, pages and creators.", items: acme('monitor', 10, (i) => (i % 3 === 1 ? 'Landing page' : 'Ad'), 2) },
{ key: 'trends', name: 'Trend tracker', href: '/use-cases/organic-social', line: 'Every day at 7:00, the hooks gaining share in your category.', items: acme('trends', 10, (i) => `Post, ${['275.5K', '652.9K', '36.3K', '28.2K', '91K'][i % 5]} views`, 3) },
] satisfies TemplateCityRow[],
},
faq: {
id: 'templates-faq',
headline: 'Frequently asked questions',
lead: 'What a template is, where it runs and what it costs.',
docs: { label: 'Read the docs', href: '/docs' },
items: [
{ q: 'What is a template?', a: 'A ready-made playbook your agent runs on Spyglass data. It holds the question, the data it needs and what to send back. You start from something that already works.' },
{ q: 'Where does a template run?', a: 'Inside your agent, through the Spyglass MCP server. Each run reads Spyglass data and brings the answer back to the chat.' },
{ q: 'How do the schedule and test mode work?', a: 'Every template runs on a schedule by default, like every Monday at 8:00. Run it once in test mode first to see what comes back.' },
{ q: 'What does a template cost?', a: 'Each run uses credits from the same pool as the API and the MCP server. Every account gets 500 free credits a month.' },
],
},
close: {
lines: ['Templates run on the Spyglass API.', 'Start today'],
note: '500 free credits every month. No card required.',
primary: { label: 'Get a free API key', href: '/sign-up' },
secondary: { label: 'Read the docs', href: '/docs' },
},
}
export type TemplatesPageContent = typeof templatesPageContent
/** The templates page's sections in order; pass `sections` to reorder them or leave some out. */
export const templatesSections = ['wall', 'run', 'cities', 'faq', 'close'] as const
export type TemplatesSection = (typeof templatesSections)[number]
/** Each block's own data, pictures included (Acme placeholders where left out). */
export interface TemplatesBlocks {
/** The wall's pictures, used in turn (a src or { src, fit, position }). */
wall?: { pictures?: (string | ImageSlot)[] }
/** The automation run's creatives (each with `src`, `alt`, `fit`, `position`). */
run?: { items?: RunItem[] }
}// 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, type PropertyValues } from 'lit'
import { unsafeStatic, html as shtml } from 'lit/static-html.js'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import { createTemplatesWall, TEMPLATES_WALL_TILES, type TemplatesWall as Wall, templatesWallKey } from '@/lib/templates-wall'
import { templatesWallContent, type TemplatesWallContent } from '@/lib/pages/templates'
import styles from 'virtual:tw'
import type { ImageSlot } from '@/lib/image'
import { ifDefined } from 'lit/directives/if-defined.js'
// TemplatesWall.tsx as <spyglass-templates-wall>: the helix of tiles drifting and turning around the words
// (lib/templates-wall.ts), the headline over the chip rolling through the template names, the lead and the status.
// `content`, `pictures` (JSON list of image URLs or { src, fit, position }; none draws neutral tones), `hero` (h1, the window's height under
// the header), `at` (draw that moment and hold it) and `section-id`. Reduced motion holds one still frame.
const TILES = Array.from({ length: TEMPLATES_WALL_TILES }, (_, j) => j)
/**
* @summary The templates wall: a turning tunnel of tiles around the headline and the rolling names.
*/
export class TemplatesWall extends DsElement {
static styles = [DsElement.styles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="templates-wall"]'))
static properties = { content: { type: Object }, pictures: { type: Array }, hero: { type: Boolean }, at: { type: Number }, sectionId: { attribute: 'section-id' } }
/** The copy (lib/pages/templates.ts by default). */
content: TemplatesWallContent = templatesWallContent
/** Pictures for the tiles, used in turn. */
pictures?: (string | ImageSlot)[]
/** The page's first section: an h1 and the window's height less the header. */
hero = false
/** Draw the frame at this time (ms) and hold it. */
at?: number
/** The section's id (React's `id`); its heading is `<id>-heading`. */
sectionId = 'templates'
private wall?: Wall
private key = ''
protected updated(changed: PropertyValues) {
super.updated(changed)
const c = this.content ?? templatesWallContent
const key = `${templatesWallKey(this.pictures)}|${this.at ?? ''}|${c.names.join('|')}`
if (key === this.key && this.wall) return
this.key = key
this.wall?.destroy()
const root = this.renderRoot.querySelector<HTMLElement>('.ds-tpl-scene')
if (!root) return
const one = (name: string) => root.querySelector<HTMLElement>(`[data-tpl="${name}"]`)!
const all = (name: string) => [...root.querySelectorAll<HTMLElement>(`[data-tpl="${name}"]`)]
this.wall = createTemplatesWall({ root, tunnel: one('tunnel'), box: one('box'), tiles: all('tile'), rows: all('row'), names: all('name'), chip: one('chip'), capL: one('cap-l'), capR: one('cap-r'), bar: one('bar') }, { pictures: this.pictures, at: this.at })
}
connectedCallback() {
super.connectedCallback()
if (this.hasUpdated && !this.wall) this.requestUpdate()
}
disconnectedCallback() {
super.disconnectedCallback()
this.wall?.destroy()
this.wall = undefined
this.key = ''
}
render() {
const c = this.content ?? templatesWallContent
const heading = unsafeStatic(this.hero ? 'h1' : 'h2')
const headingId = `${this.sectionId}-heading`
return html`<section data-ds="templates-wall" id=${this.sectionId} aria-labelledby=${headingId} ?data-hero=${this.hero} class="ds-tpl relative isolate z-1 overflow-hidden bg-surface text-fg"><div class="ds-tpl-scene relative grid place-items-center"><div aria-hidden="true" data-tpl="tunnel" class="pointer-events-none absolute inset-0"><div data-tpl="box" class="ds-tpl-box">${TILES.map(() => html`<span data-tpl="tile" data-ds-placeholder=${ifDefined(this.pictures?.length ? undefined : '')} class="ds-tpl-tile"></span>`)}</div></div><div class="relative z-1 mx-auto flex w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] flex-col items-center px-(--ds-layout-gutter) text-center"><div class="ds-tpl-line flex flex-col items-center gap-y-2 type-section text-fg">${shtml`<${heading} id=${headingId} data-tpl="row" class="ds-tpl-headline whitespace-nowrap">${c.headline}</${heading}>`}<span aria-hidden="true" data-tpl="chip" class="ds-tpl-chip relative inline-grid px-3 md:px-4"><span class="ds-tpl-surface absolute inset-0"><span data-tpl="cap-l" class="ds-tpl-cap"></span><span data-tpl="bar" class="ds-tpl-bar"></span><span data-tpl="cap-r" class="ds-tpl-cap"></span></span><span class="ds-tpl-window relative grid justify-items-center overflow-hidden py-2">${c.names.map((name) => html`<span data-tpl="name" class="ds-tpl-name whitespace-nowrap">${name}</span>`)}</span></span></div><ul class="sr-only">${c.names.map((name) => html`<li>${name}</li>`)}</ul><div class="mt-8 flex flex-col items-center gap-4"><p data-tpl="row" class="ds-tpl-lead max-w-(--ds-layout-measure) type-body-xl text-fg-soft">${c.lead}</p><p data-tpl="row" class="type-ui text-fg-faint">${c.status}</p></div></div></div></section>`
}
}
define('templates-wall', TemplatesWall).ds-tpl { padding-block: var(--ds-layout-section); }
.ds-tpl[data-hero] { padding-block: 0 calc(var(--ds-layout-section) - var(--ds-templates-edge)); }
.ds-tpl-scene { min-height: 100svh; }
.ds-tpl[data-hero] .ds-tpl-scene { min-height: calc(100svh - var(--ds-space-4xl)); }
.ds-tpl-box {
position: absolute; top: 50%; left: 50%;
width: calc(var(--ds-templates-design-w) * 1px); height: calc(var(--ds-templates-design-h) * 1px);
perspective: var(--ds-templates-perspective); transform: translate(-50%, -50%);
}
.ds-tpl-tile {
position: absolute; inset: 0; display: block; margin: auto;
width: var(--ds-templates-tile-w); height: var(--ds-templates-tile-h);
border-radius: var(--ds-radius-sm); background-color: var(--ds-color-surface-subtle);
background-position: center; background-size: cover; background-repeat: no-repeat;
visibility: hidden; opacity: 0; backface-visibility: hidden; user-select: none; will-change: transform, opacity;
}
.ds-tpl-tile[data-tone="1"] { background-image: linear-gradient(var(--ds-color-neutral-4), var(--ds-color-neutral-2)); }
.ds-tpl-tile[data-tone="2"] { background-image: linear-gradient(var(--ds-color-neutral-5), var(--ds-color-neutral-3)); }
.ds-tpl-tile[data-tone="3"] { background-image: linear-gradient(var(--ds-color-neutral-6), var(--ds-color-neutral-4)); }
.ds-tpl-tile[data-tone="4"] { background-image: linear-gradient(var(--ds-color-neutral-7), var(--ds-color-neutral-5)); }
.ds-tpl-headline { font: inherit; }
.ds-tpl-lead { font-weight: var(--ds-font-weight-medium); text-wrap: balance; }
.ds-tpl-surface { opacity: 0; }
.ds-tpl-scene[data-ready] .ds-tpl-surface { opacity: var(--ds-templates-chip-opacity); }
.ds-tpl-cap, .ds-tpl-bar { position: absolute; top: 0; left: 50%; height: 100%; background: var(--ds-color-surface-raised); translate: -50% 0; }
.ds-tpl-cap { aspect-ratio: 1; border-radius: var(--ds-radius-panel); }
.ds-tpl-bar { width: var(--ds-space-4xl); }
.ds-tpl-window { mask-image: linear-gradient(transparent, var(--ds-color-black) var(--ds-space-md), var(--ds-color-black) calc(100% - var(--ds-space-md)), transparent); }
.ds-tpl-name { grid-area: 1 / 1; }
.ds-tpl-name:not(:first-child) { opacity: 0; }
@media (min-width: 768px) {
.ds-tpl-scene {
--ds-templates-design-w: var(--ds-templates-design-w-md); --ds-templates-design-h: var(--ds-templates-design-h-md);
--ds-templates-count: var(--ds-templates-count-md); --ds-templates-near: var(--ds-templates-near-md);
}
}
@media (min-width: 1024px) { .ds-tpl[data-hero] .ds-tpl-scene { min-height: calc(100svh - var(--ds-size-header)); } }
@media (width < 372px) {
.ds-tpl-line { font-size: var(--ds-text-heading-3); line-height: var(--ds-text-heading-3-leading); }
.ds-tpl-lead { font-size: var(--ds-text-heading-4); line-height: var(--ds-text-heading-4-leading); }
}Reference: Site v2/V2Templates (V2Templates, TemplatesWall, TemplatesBoot, templatesMotion.ts, field.ts, V2Templates.module.css) and tokens.css 355-357, 395-414, 605-608: 80 tiles, 74 in the tunnel on phones and 128 from 768, 176x220 at 4px radius, 18.5 a turn, drifting 24px and turning 1.5 degrees a second, fading in over 600ms from 0.92; the head at the section size, the chip padded 12px (16px from 768) on the 72% raised surface, a name every 2400ms rolling 600ms on cubic-bezier(0.85, 0, 0.15, 1); the lead 24/32 medium, the status 14/20; the hero fills the window under the header.