/* ═══════════════════════════════════════════════════════════════ EVENT PRESENTATION: /events/:id/present An event page's content blocks as an endless slideshow for a screen (digital signage), opened from the page's Present button. Outside the site's Layout: no header, footer or backdrop. The page is cut into sections at its Heading blocks (the blocks before the first are a section under the event's title). Each section, in order, gives: section its text blocks (everything but the kinds below) on one slide under its heading, scrolling if long schedule each schedule block's slides (below) venue each map block (088): the map with its locations place then the map once per marked location, it lit up cards each events block (088): its events on one slide event then each event alone: picture, title, its person host and its own page's blocks (else its card text) list a list block picked for an Overview slide: its items' text, centered item then, picked for A slide per item, each item: its text the heading, its detail under it, centered A list picked for neither is part of its section's text. The setup picks them per list (`lists`, o
. and i
.) and ticks its items on and off (`hide`, l
..). A schedule's slides, for each day picked, in order: overview the day's picked entries on one slide spotlight one entry: its person beside title, time and place block a block entry (086) and its sub-items on one slide, in place of its spotlight; then each sub-item gets the spotlight, graphic and map slides an entry does graphic an entry's graphic, full screen map an entry's own map image (069), full screen tag after the days: each of the schedule's tags (087) and everything it's on, under each day's name A heading (086) is only a line on the overview; a break gets no spotlight. "Only entries tagged" (`only=`) cuts every schedule slide to what one tag is on, eg. for a screen outside the youth room. First a setup screen: which sections, days and entries, and how many seconds each kind of slide stays up (0 leaves that kind out). Play writes the choices into the address, so a signage device can bookmark it and start the same way every time (`play=1` skips the setup): `skip` the sections left out, by number; `hide` the days (schedule.day), entries (schedule.day.entry) and sub-items (schedule.day.entry.item) left out, a schedule numbered among the page's schedules. A slide with more than the screen holds waits half its seconds, scrolls to the end at "Scroll" seconds a screenful (`screen=`), then waits the other half. A section with only a heading (and subheadings or dividers) before its map, schedule or events gets no text slide: its heading titles the slides that follow. The setup's Order list moves any slide (`order`, slide ids, see buildSlides); a slide it doesn't name stays after the one it follows by default. The event's Presentation settings (095) give the slides their background, frame, colors and logo (lookTokens, Player); a block's give its Presentation text, leave it out, and say how a map is shown. The blocks themselves are drawn for a screen (Presenting): links as their text, people as round photos and names, their logos. In the dark theme the event's dark settings (096) take the place of any they set (lookFor); the setup's Theme (`theme=light|dark`) holds a screen in one theme while it plays. Keys while playing: arrows step, Space pauses, Escape leaves full screen (the browser's), S goes back to the setup. ═══════════════════════════════════════════════════════════════ */ import { ArrowDown, ArrowUp, ArrowsOut, CaretLeft, CaretRight, DotsSixVertical, Gear, Pause, Play } from '@phosphor-icons/react' import { createContext, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from 'react' import { useParams, useSearchParams } from 'react-router-dom' import PageState from '../components/PageState.tsx' import { Avatar, FeaturedStar, ScheduleTags, TagChips, daysWithTag, featuredStyle, groupByDay, mapAlt, withTag, type Day, } from '../components/ScheduleBlock.tsx' import ContentBlocks, { eventLine } from '../components/ContentBlocks.tsx' import { LocationNumber, MapPicture, isMarked, locationNumber } from '../components/MapBlock.tsx' import { Inline, Paragraphs } from '../components/InlineText.tsx' import { Presenting } from '../lib/presenting.ts' import { useEvent, type ContentBlock, type ContentBlockItem, type EventPresentLook, type ScheduleTag, type Venue, type VenueLocation, } from '../lib/useContent.ts' import { mediaUrl } from '../lib/media.ts' import { BRAND, accentText, readableOn, withAlpha } from '../lib/color.ts' import { documentTitle } from '../lib/site.ts' import { preview } from '../lib/text.ts' import { useDarkTheme } from '../lib/darkTheme.ts' import './EventPresent.css' /* Each kind of slide, its address key and seconds when unset. */ const KINDS = [ { key: 'section', label: 'Sections', help: "A section's text under its heading", seconds: 20 }, { key: 'overview', label: 'Day overview', help: 'A schedule day on one slide', seconds: 20 }, { key: 'spotlight', label: 'Entry spotlight', help: 'One schedule entry at a time, with its person', seconds: 12 }, { key: 'block', label: 'Blocks', help: 'A schedule block and the things in it, before each gets a spotlight', seconds: 15 }, { key: 'graphic', label: 'Graphics', help: "A schedule entry's graphic, full screen", seconds: 10 }, { key: 'map', label: 'Map images', help: "A schedule entry's own map, full screen", seconds: 10 }, { key: 'tag', label: 'Tag slides', help: "Each schedule tag and everything it's on, after the days", seconds: 15 }, { key: 'venue', label: 'Maps', help: "A map block: the venue's map with its locations", seconds: 15 }, { key: 'place', label: 'Map locations', help: 'The map again for each location, it lit up', seconds: 8 }, { key: 'cards', label: 'Event lists', help: "An events block's events on one slide", seconds: 15 }, { key: 'event', label: 'Event spotlight', help: 'Each event of an events block alone', seconds: 12 }, { key: 'list', label: 'List overview', help: "A list block's items on one slide, without their detail", seconds: 12 }, { key: 'item', label: 'List items', help: 'Each list item alone, its detail under it', seconds: 10 }, ] as const type Kind = (typeof KINDS)[number]['key'] /* Blocks with slides of their own, not a section's text, as the setup screen names them. */ const OWN_SLIDES = new Map([ ['schedule', 'Schedule'], ['map', 'Map'], ['events', 'Events'], ]) /* A list's picks in `lists`: its Overview slide, A slide per item. */ const overviewKey = (s: number, b: number) => `o${s}.${b}` const itemsKey = (s: number, b: number) => `i${s}.${b}` /* A list item's key in `hide`. */ const listKey = (s: number, b: number, i: number) => `l${s}.${b}.${i}` /* What the setup calls a block with slides of its own (a list picked for an Overview slide or A slide per item), else null. */ const ownSlides = (block: ContentBlock, lists: Set, s: number, b: number): string | null => OWN_SLIDES.get(block.type) ?? (block.type === 'list' && (lists.has(overviewKey(s, b)) || lists.has(itemsKey(s, b))) ? 'List' : null) /* Blocks that start a section. */ const STARTS_SECTION = new Set(['heading', 'tab']) /* Text that alone makes no section slide: the heading titles what follows instead. */ const FILLER = new Set(['subheading', 'divider']) /* Percent of the background color over the background image, unset. */ const DIM = 60 /* The themes a screen can be held in (`theme`). */ const THEMES = ['light', 'dark'] as const /* The event's look in the theme shown: in the dark one, its dark settings (096) over the light ones. */ function lookFor(look: EventPresentLook | undefined, dark: boolean): EventPresentLook | undefined { if (!look || !dark || !look.dark) return look const picked = Object.entries(look.dark).filter(([, value]) => value != null && value !== '') return { ...look, ...Object.fromEntries(picked) } } /* Seconds a long slide takes to scroll one screenful, when unset. */ const PER_SCREEN = 8 /* An overview with more entries than this goes to two columns. */ const ONE_COLUMN = 8 /* How long the controls stay up after the pointer last moved (ms). */ const CONTROLS_FOR = 2500 /* A section's text is drawn at the page's size, zoomed to a screen this many pixels wide or more. */ const TEXT_WIDTH = 1000 /* `label` is the top bar's right side: the day, else the section. The rest is what each kind draws. */ type Slide = { /* Where it comes from, for the Order list (buildSlides). */ id: string kind: Kind /* A map's or event list's title, when not the label. */ title?: string seconds: number label: string day?: Day entry?: ContentBlockItem parent?: ContentBlockItem tag?: ScheduleTag days?: Day[] tags?: ScheduleTag[] blocks?: ContentBlock[] venue?: Venue location?: VenueLocation items?: ContentBlockItem[] /* A map: the locations shown, by key (all when unset), and its block's Map only and No location details (095). */ only?: string[] noList?: boolean noDetails?: boolean } /* A part of the page: a heading (`headed`, else the event's title) and the blocks under it. */ type Section = { title: string; headed: boolean; blocks: ContentBlock[] } /* A schedule block, numbered among the page's, with its days. */ type Schedule = { n: number; days: Day[]; tags: ScheduleTag[] } /* Blocks left out of the presentation (095) are dropped; a left out heading still starts its section, under the event's title. */ function sectionsOf(blocks: ContentBlock[], title: string): Section[] { const sections: Section[] = [{ title, headed: false, blocks: [] }] for (const block of blocks) { if (STARTS_SECTION.has(block.type)) { const heading = block.present?.hide ? '' : block.present?.text || block.text sections.push({ title: heading || title, headed: Boolean(heading), blocks: [] }) } else if (!block.present?.hide) sections[sections.length - 1].blocks.push(block) } return sections.filter((section) => section.blocks.length) } /* A day's, entry's or sub-item's key in the address: the schedule's number, the day's, then the entry's and sub-item's, dotted. */ const key = (...at: number[]) => at.join('.') /* Lines on an overview: entries and sub-items. */ const lineCount = (entries: ContentBlockItem[]) => entries.reduce((n, entry) => n + 1 + (entry.kind === 'block' ? (entry.items?.length ?? 0) : 0), 0) const list = (value: string | null) => (value ? value.split(',').filter(Boolean) : null) function readSettings(params: URLSearchParams) { const seconds = Object.fromEntries( KINDS.map((kind) => { const value = Number(params.get(kind.key) ?? kind.seconds) return [kind.key, Number.isFinite(value) && value > 0 ? value : 0] }), ) as Record const screen = Number(params.get('screen') ?? PER_SCREEN) return { skipped: new Set((list(params.get('skip')) ?? []).map(Number)), hidden: new Set(list(params.get('hide')) ?? []), seconds, screen: Number.isFinite(screen) && screen > 0 ? screen : PER_SCREEN, only: params.get('only') || null, order: list(params.get('order')), lists: new Set(list(params.get('lists')) ?? []), theme: THEMES.find((theme) => theme === params.get('theme')) ?? null, } } type Settings = ReturnType type Picks = Pick /* An entry or sub-item with its key (key()), carried through the picks and the tag filter, which copy blocks. */ type Keyed = ContentBlockItem & { slideKey: string } const keyOf = (entry: ContentBlockItem) => (entry as Keyed).slideKey function scheduleSlides(slides: Slide[], { n, days, tags }: Schedule, { hidden, seconds, only }: Picks) { const kept: Day[] = [] days.forEach((all, d) => { if (hidden.has(key(n, d))) return let entries: ContentBlockItem[] = all.entries.flatMap((entry, e) => { if (hidden.has(key(n, d, e))) return [] const slideKey = key(n, d, e) if (entry.kind !== 'block') return [{ ...entry, slideKey }] const items = (entry.items ?? []).flatMap((item, i) => hidden.has(key(n, d, e, i)) ? [] : [{ ...item, slideKey: key(n, d, e, i) }], ) return [{ ...entry, slideKey, items }] }) if (only) entries = withTag(entries, only) if (entries.length === 0) return kept.push({ name: all.name, entries }) const day = { ...all, entries } const at = { day, label: day.name, tags } if (seconds.overview) slides.push({ id: `o${key(n, d)}`, kind: 'overview', seconds: seconds.overview, ...at }) const media = (entry: ContentBlockItem, parent?: ContentBlockItem) => { const k = keyOf(entry) if (seconds.graphic && entry.media) slides.push({ id: `g${k}`, kind: 'graphic', seconds: seconds.graphic, ...at, entry, parent }) if (seconds.map && entry.map_image) slides.push({ id: `m${k}`, kind: 'map', seconds: seconds.map, ...at, entry, parent }) } for (const entry of entries) { if (entry.kind === 'heading') continue if (entry.kind === 'block') { if (seconds.block) slides.push({ id: `k${keyOf(entry)}`, kind: 'block', seconds: seconds.block, ...at, entry }) media(entry) for (const item of entry.items ?? []) { if (seconds.spotlight) { slides.push({ id: `s${keyOf(item)}`, kind: 'spotlight', seconds: seconds.spotlight, ...at, entry: item, parent: entry }) } media(item, entry) } continue } if (seconds.spotlight && entry.kind !== 'break') { slides.push({ id: `s${keyOf(entry)}`, kind: 'spotlight', seconds: seconds.spotlight, ...at, entry }) } media(entry) } }) if (seconds.tag) { for (const tag of tags) { if (only && tag.key !== only) continue const tagDays = daysWithTag(kept, tag.key) if (tagDays.length) slides.push({ id: `x${n}.${tag.key}`, kind: 'tag', seconds: seconds.tag, label: tag.name, tag, days: tagDays, tags }) } } } /* A map block's slides: the map (once per section with A slide per section), then each location picked for a slide of its own (095). `title` is the heading folded in, if any. */ function mapSlides(slides: Slide[], block: ContentBlock, at: string, label: string, title: string | null, seconds: Picks['seconds']) { const venue = block.venue! const present = block.present const shown = { noList: present?.map_no_list, noDetails: present?.map_no_details } if (seconds.venue) { const parts = present?.map_split ? (block.map_sections ?? []) : [] if (parts.length) { parts.forEach((part, i) => { slides.push({ id: `v${at}.${i}`, kind: 'venue', seconds: seconds.venue, label, venue, title: part.name, only: part.keys, ...shown }) }) } else { slides.push({ id: `v${at}`, kind: 'venue', seconds: seconds.venue, label, venue, title: title ?? venue.name, ...shown }) } } if (!seconds.place || !venue.map_image || present?.places === 'none') return const picked = present?.places === 'picked' ? new Set(present.place_keys) : null for (const location of venue.locations.filter(isMarked)) { if (picked && !picked.has(location.key)) continue slides.push({ id: `p${at}.${location.key}`, kind: 'place', seconds: seconds.place, label, venue, location, ...shown }) } } /* Each slide's id says where it comes from, so a saved order still finds it: t
a section's text; v and p a map and its locations, c and e an events list and its events, by
.; l and i a list's overview and items (listKey); o, k, s, g and m a schedule's overview, block, spotlight, graphic and map image, and x its tag slides, by key(). */ function buildSlides(sections: Section[], schedules: Map, picks: Picks): Slide[] { const { skipped, seconds, hidden, lists } = picks const slides: Slide[] = [] sections.forEach((section, s) => { if (skipped.has(s)) return const label = section.title const text = section.blocks.filter((block, b) => !ownSlides(block, lists, s, b)) // Nothing but a heading: it titles the slides that follow. const own = text.some((block) => !FILLER.has(block.type)) if (seconds.section && own) slides.push({ id: `t${s}`, kind: 'section', seconds: seconds.section, label, blocks: text }) const title = section.headed && !own ? label : null section.blocks.forEach((block, b) => { const at = `${s}.${b}` const schedule = schedules.get(block) if (schedule) scheduleSlides(slides, schedule, picks) if (block.type === 'map' && block.venue) mapSlides(slides, block, at, label, title, seconds) if (block.type === 'list' && ownSlides(block, lists, s, b)) { const items = (block.items ?? []).flatMap((item, i) => (hidden.has(listKey(s, b, i)) ? [] : [{ item, i }])) if (seconds.list && lists.has(overviewKey(s, b)) && items.length) { slides.push({ id: `l${at}`, kind: 'list', seconds: seconds.list, label, title: title ?? undefined, items: items.map(({ item }) => item) }) } if (seconds.item && lists.has(itemsKey(s, b))) { for (const { item, i } of items) slides.push({ id: `i${at}.${i}`, kind: 'item', seconds: seconds.item, label, entry: item }) } } if (block.type === 'events') { const items = (block.items ?? []).filter((item) => item.event) if (seconds.cards && items.length) slides.push({ id: `c${at}`, kind: 'cards', seconds: seconds.cards, label, items }) if (seconds.event) { items.forEach((entry, i) => slides.push({ id: `e${at}.${i}`, kind: 'event', seconds: seconds.event, label, entry })) } } }) }) return slides } /* The slides in the Order list's order: one it doesn't name stays right after the slide it follows by default. */ function ordered(slides: Slide[], order: string[] | null): Slide[] { if (!order?.length) return slides const rank = new Map(order.map((id, i) => [id, i])) let last = -1 return slides .map((slide, i) => { const at = rank.get(slide.id) if (at != null) last = at return { slide, i, at: at ?? last + 0.5 } }) .sort((a, b) => a.at - b.at || a.i - b.i) .map(({ slide }) => slide) } /* A slide's line in the Order list. */ function slideName(slide: Slide): string { const entry = slide.entry switch (slide.kind) { case 'section': case 'cards': return slide.label case 'overview': return slide.day?.name || 'Schedule' case 'tag': return slide.tag!.name case 'venue': return slide.title ?? slide.venue!.name case 'place': return slide.location!.name case 'event': return entry!.text || entry!.event!.title case 'list': return slide.title ?? (slide.items ?? []).map((item) => item.text).join(', ') case 'item': return entry!.text default: return [slide.day?.name, entry!.time, entry!.text].filter(Boolean).join(' · ') } } const KIND_LABEL = new Map(KINDS.map((kind) => [kind.key, kind.label])) export default function EventPresent() { const { id } = useParams() const [params, setParams] = useSearchParams() const { data: event, loading, error, notFound, reload } = useEvent(id) const sections = useMemo(() => (event ? sectionsOf(event.blocks ?? [], event.title) : []), [event]) const schedules = useMemo(() => { const out = new Map() for (const block of event?.blocks ?? []) { if (block.type !== 'schedule') continue const days = groupByDay(block.items ?? []) if (days.length) out.set(block, { n: out.size, days, tags: block.tags ?? [] }) } return out }, [event]) useEffect(() => { if (event) document.title = documentTitle(`${event.title}: present`) }, [event]) // The setup's Theme, while playing; the device's again after. const held = params.get('play') === '1' ? params.get('theme') : null useEffect(() => { if (held !== 'light' && held !== 'dark') return const root = document.documentElement const was = root.dataset.theme root.dataset.theme = held return () => { if (was) root.dataset.theme = was } }, [held]) const dark = useDarkTheme() if (!event) { return ( ) } const look = lookFor(event.present, dark) const accent = look?.accent || event.color || BRAND const back = `/events/${encodeURIComponent(event.id)}` if (sections.length === 0) { return (

This event has nothing on its page to present.

Back to {event.title}
) } const settings = readSettings(params) if (params.get('play') === '1') { return ( { const next = new URLSearchParams(params) next.delete('play') setParams(next) }} /> ) } return ( { // Full screen needs the click itself, so it's asked for here. document.documentElement.requestFullscreen?.().catch(() => {}) const out = new URLSearchParams() if (next.skipped.size) out.set('skip', [...next.skipped].sort((a, b) => a - b).join(',')) if (next.hidden.size) out.set('hide', [...next.hidden].join(',')) for (const kind of KINDS) out.set(kind.key, String(next.seconds[kind.key])) out.set('screen', String(next.screen)) // Not 'tag': that's the tag slides' seconds. if (next.only) out.set('only', next.only) if (next.order?.length) out.set('order', next.order.join(',')) if (next.theme) out.set('theme', next.theme) if (next.lists.size) out.set('lists', [...next.lists].join(',')) out.set('play', '1') setParams(out) }} /> ) } /* ── Setup ──────────────────────────────────────────────────── */ function Setup({ title, back, accent, sections, schedules, settings, onPlay, }: { title: string back: string accent: string sections: Section[] schedules: Map settings: Settings onPlay: (settings: Settings) => void }) { const [skipped, setSkipped] = useState(settings.skipped) const [hidden, setHidden] = useState(settings.hidden) const [seconds, setSeconds] = useState(settings.seconds) const [only, setOnly] = useState(settings.only) const [screen, setScreen] = useState(settings.screen) const [order, setOrder] = useState(settings.order) const [theme, setTheme] = useState(settings.theme) const [lists, setLists] = useState(settings.lists) const [dragging, setDragging] = useState(null) const slides = ordered(buildSlides(sections, schedules, { skipped, hidden, seconds, only, lists }), order) const count = slides.length // Moves a slide in the list, which then names every slide shown. const move = (from: number, to: number) => { if (to < 0 || to >= slides.length || from === to) return const ids = slides.map((slide) => slide.id) const [id] = ids.splice(from, 1) ids.splice(to, 0, id) setOrder(ids) } const tags = [...schedules.values()].flatMap((schedule) => schedule.tags) const toggle = (set: Set, value: T) => { const next = new Set(set) if (next.has(value)) next.delete(value) else next.add(value) return next } return (

Present the page

{title}

Pick what to show and for how long, then Play. It loops until you stop it. Bookmark the address after pressing Play to start a screen the same way next time.

Slides

{KINDS.map((kind) => ( ))}

0 leaves that kind of slide out.

Theme

{tags.length > 0 && (

Tags

)}

Sections

The page's parts, each starting at a Heading block.

{sections.map((section, s) => { const on = !skipped.has(s) const kinds = [...new Set(section.blocks.map((block, b) => ownSlides(block, lists, s, b) ?? 'Text'))] return (
{section.title} {section.blocks.map((block, b) => { // A list: its own slides if picked, then its items. if (block.type === 'list' && block.items?.length) { const own = ownSlides(block, lists, s, b) const first = preview(block.items.map((item) => item.text).join(', '), 60) return (

List: {first}

setLists(toggle(lists, overviewKey(s, b)))} /> setLists(toggle(lists, itemsKey(s, b)))} /> {own && (
    {block.items.map((item, i) => (
  • setHidden(toggle(hidden, listKey(s, b, i)))} />
  • ))}
)}
) } const schedule = schedules.get(block) if (!schedule) return null const { n, days } = schedule return (
{days.map((day, d) => (
setHidden(toggle(hidden, key(n, d)))} />
    {day.entries.map((entry, e) => (
  • setHidden(toggle(hidden, key(n, d, e)))} /> {entry.kind === 'block' && entry.items?.length ? (
      {entry.items.map((item, i) => (
    • setHidden(toggle(hidden, key(n, d, e, i)))} />
    • ))}
    ) : null}
  • ))}
))}
) })}
) })}
{slides.length > 1 && (

Order

{order && ( )}

Drag a slide, or move it with its arrows. A slide picked again later goes back after the one it follows on the page.

    {slides.map((slide, i) => (
  1. setDragging(i)} onDragOver={(e) => e.preventDefault()} onDrop={() => { if (dragging != null) move(dragging, i) setDragging(null) }} onDragEnd={() => setDragging(null)} className={`flex cursor-grab items-center gap-3 bg-raised px-3 py-2 shadow-sm ${dragging === i ? 'opacity-50' : ''}`} >
  2. ))}
)}
{count === 0 ? 'Nothing picked to show.' : `${count} slide${count === 1 ? '' : 's'} in the loop`} Back to the event
) } /* One checkbox on the setup screen: a schedule entry (its time and kind beside it) or a day (`label`, `strong`). */ const KIND_NOTE = { block: 'Block', break: 'Break', heading: 'Heading' } as const function PickEntry({ entry, label, strong = false, enabled, checked, onToggle, }: { entry?: ContentBlockItem label?: string strong?: boolean enabled: boolean checked: boolean onToggle: () => void }) { const note = entry?.kind && entry.kind !== 'entry' ? KIND_NOTE[entry.kind] : null return ( ) } /* ── Player ─────────────────────────────────────────────────── */ /* The event's Presentation colors (095) as the site's color tokens, so every slide's text-ink, bg-raised and so on take them. */ function lookTokens(look?: EventPresentLook): CSSProperties | undefined { const bg = look?.background_color const ink = look?.text_color || (bg ? readableOn(bg) : null) if (!bg && !ink) return undefined const ground = bg ?? 'var(--color-surface)' return { ...(bg ? { '--color-surface': bg } : {}), ...(ink ? { '--color-ink': ink, '--color-body': ink, '--color-muted': `color-mix(in srgb, ${ink} 75%, ${ground})`, '--color-raised': `color-mix(in srgb, ${ink} 8%, ${ground})`, '--color-tint': `color-mix(in srgb, ${ink} 14%, ${ground})`, '--color-tint-soft': `color-mix(in srgb, ${ink} 6%, ${ground})`, } : {}), } as CSSProperties } function Player({ title, accent, look, slides, screen, onSetup, }: { title: string accent: string look?: EventPresentLook slides: Slide[] screen: number onSetup: () => void }) { const [index, setIndex] = useState(0) // Seconds this slide's scroll adds to it (Scroll), for its index. const [scroll, setScroll] = useState({ index: -1, seconds: 0 }) const [paused, setPaused] = useState(false) const [controls, setControls] = useState(true) const hideTimer = useRef(0) const slide = slides[index % Math.max(slides.length, 1)] const step = (by: number) => setIndex((i) => (i + by + slides.length) % slides.length) const seconds = (slide?.seconds ?? 0) + (scroll.index === index ? scroll.seconds : 0) // The next slide when this one's time is up. useEffect(() => { if (paused || !slide) return const timer = window.setTimeout(() => step(1), seconds * 1000) return () => window.clearTimeout(timer) }, [index, paused, seconds, slides.length]) useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === 'ArrowRight') step(1) else if (e.key === 'ArrowLeft') step(-1) else if (e.key === ' ') setPaused((p) => !p) else if (e.key === 's' || e.key === 'S') onSetup() else return e.preventDefault() } window.addEventListener('keydown', onKey) return () => window.removeEventListener('keydown', onKey) }) // Keeps a signage screen from going to sleep, where the browser can. useEffect(() => { let lock: { release: () => Promise } | null = null const ask = () => { if (document.visibilityState !== 'visible') return ;(navigator as any).wakeLock ?.request('screen') .then((l: typeof lock) => (lock = l)) .catch(() => {}) } ask() document.addEventListener('visibilitychange', ask) return () => { document.removeEventListener('visibilitychange', ask) lock?.release().catch(() => {}) } }, []) // The controls show while the pointer moves, then get out of the way. const wake = () => { setControls(true) window.clearTimeout(hideTimer.current) hideTimer.current = window.setTimeout(() => setControls(false), CONTROLS_FOR) } useEffect(() => { wake() return () => window.clearTimeout(hideTimer.current) }, []) if (!slide) { return (

Nothing picked to show.

) } const control = 'btn flex h-12 w-12 items-center justify-center bg-raised text-ink shadow-md' const frame = look?.frame ?? null const background = mediaUrl(look?.background) const label = slide.label === title || slide.label === slide.title ? '' : slide.label // Room clear at each edge, eg. inside a frame picture (097). const inset = look?.inset return (
{/* The background image, the background color over it at Dim. */} {background && (
) } /* ── Slides ─────────────────────────────────────────────────── */ /* Fades and rises in after `order` steps, so a slide's parts arrive one after another. */ function Rise({ order = 0, from = 'below', className = '', children }: { order?: number from?: 'below' | 'left' | 'right' className?: string children: ReactNode }) { return (
{children}
) } /* What a slide's Scroll needs from the Player: the wait at each end (half the slide's seconds), seconds a screenful, whether it's paused, and where to say how many seconds its scroll adds. */ const SlideTime = createContext({ wait: 0, screen: PER_SCREEN, paused: false, scrolls: (_seconds: number) => {} }) /* A slide's part that may not fit: when its content is taller than the room it has, it waits, scrolls to the end at the Player's seconds a screenful (making the slide that much longer), then waits again. `center` puts short content in the middle (and still starts long content at the top). */ function Scroll({ center = false, className = '', children }: { center?: boolean className?: string children: ReactNode }) { const { wait, screen, paused, scrolls } = useContext(SlideTime) const box = useRef(null) const [scrollFor, setScrollFor] = useState({ by: 0, seconds: 0 }) useLayoutEffect(() => { const outer = box.current const inner = outer?.firstElementChild as HTMLElement | null if (!outer || !inner) return const by = Math.max(0, inner.offsetHeight - outer.clientHeight) if (!by) return const seconds = (by / (outer.clientHeight || 1)) * screen setScrollFor({ by, seconds }) scrolls(seconds) }, []) const { by, seconds } = scrollFor const style = { '--present-scroll': `-${by}px`, animationDuration: `${seconds}s`, animationDelay: `${wait}s`, animationPlayState: paused ? 'paused' : 'running', } as CSSProperties return (
{children}
) } /* A slide's big title. */ function SlideTitle({ children, color }: { children: ReactNode; color: string }) { return (

{children}

) } /* A picture's width over its height, once it has loaded (0 before). */ function useRatio(src: string | null) { const [ratio, setRatio] = useState(0) useEffect(() => { if (!src) return const img = new Image() img.onload = () => setRatio(img.naturalWidth / (img.naturalHeight || 1)) img.src = src }, [src]) return ratio } /* A venue's map at the most the slide holds: as wide as it can be without being taller than `vh` of the screen. */ function SlideMap({ venue, accent, active, vh, only }: { venue: Venue accent: string active: string | null vh: number /** Marks only these locations' keys; all when unset. */ only?: string[] }) { const ratio = useRatio(mediaUrl(venue.map_image)) return (
) } /* An overview's rows: each entry, a block's sub-items under it. `start` is the first row's place in the slide's entrance. */ function OverviewEntries({ entries, accent, start = 1 }: { entries: ContentBlockItem[]; accent: string; start?: number }) { return ( <> {entries.map((entry, i) => (
  • {entry.kind === 'block' && entry.items?.length ? (
      {entry.items.map((item, j) => (
    • ))}
    ) : null}
  • ))} ) } /* One line of the day overview: an entry, or (`sub`) one of a block's sub-items under it. A heading is a label; a break is quieter. */ function OverviewLine({ entry, accent, sub = false }: { entry: ContentBlockItem; accent: string; sub?: boolean }) { const tags = useContext(ScheduleTags) const color = accentText(accent) if (entry.kind === 'heading') { return (

    {entry.text}

    ) } const quiet = entry.kind === 'break' return (
    {entry.time} {entry.featured && ( )} {entry.text} {(entry.location || entry.person || entry.tags?.length) && ( {entry.location && {entry.location}} {entry.person && {entry.person.name}} )}
    ) } function SlideView({ slide, accent }: { slide: Slide; accent: string }) { const tags = useContext(ScheduleTags) const color = accentText(accent) if (slide.kind === 'section') { // The page's own blocks, zoomed up from the page's size. The // zoom is inside Scroll, so it measures what the screen shows. const zoom = Math.max(1, window.innerWidth / TEXT_WIDTH) return (
    {slide.label}
    ) } if (slide.kind === 'venue') { const venue = slide.venue! const only = slide.only const locations = only ? venue.locations.filter((location) => only.includes(location.key)) : venue.locations const heading = slide.title ?? venue.name // Map only: the map under its title, as big as the slide holds. if (slide.noList && venue.map_image) { return (
    {heading}
    ) } return (
    {venue.map_image && ( )}
    {heading}
      {locations.map((location, i) => (
    1. {location.name} {location.detail && !slide.noDetails && ( {location.detail} )}
    2. ))}
    ) } if (slide.kind === 'place') { const venue = slide.venue! const location = slide.location! return (

    {location.name}

    {location.detail && !slide.noDetails && (

    {location.detail}

    )}

    {venue.name}

    ) } if (slide.kind === 'cards') { const items = slide.items ?? [] return (
    {slide.title ?? slide.label}
      4 ? 'grid-cols-3' : 'grid-cols-2'}`}> {items.map((item, i) => { const image = mediaUrl(item.event!.image) return (
    • {image && }
      {eventLine(item.event!) && (

      {eventLine(item.event!)}

      )}

      {item.text || item.event!.title}

      {item.person && (

      {item.person.name}

      )}
    • ) })}
    ) } if (slide.kind === 'list') { const items = slide.items ?? [] return (
    {slide.title && {slide.title}}
      {items.map((item, i) => (
    • ))}
    ) } const entry = slide.entry! if (slide.kind === 'item') { return (

    {entry.detail && (

    {entry.detail}

    )}
    ) } if (slide.kind === 'event') { const event = entry.event! const image = mediaUrl(event.image) const blurb = entry.detail || event.blurb // Its own page's blocks, when it has some, in place of its card // text, zoomed for the column they're in. const blocks = event.blocks?.length ? event.blocks : null const zoom = Math.max(1, (window.innerWidth * 0.75) / TEXT_WIDTH) return (
    {image && ( )} {eventLine(event) && (

    {eventLine(event)}

    )}

    {entry.text || event.title}

    {entry.person && ( {entry.person.name} {entry.person.tagline && ( {entry.person.tagline} )} )} {blocks ? (
    ) : ( blurb && (
    ) )}
    ) } if (slide.kind === 'overview') { const entries = slide.day!.entries const two = lineCount(entries) > ONE_COLUMN return (
    {slide.day!.name || 'Schedule'}
    ) } if (slide.kind === 'tag') { const tag = slide.tag! const tagDays = slide.days ?? [] const tagColor = tag.color || accent const two = tagDays.reduce((n, day) => n + 1 + lineCount(day.entries), 0) > ONE_COLUMN let order = 1 return (
    {tag.name}
      {tagDays.map((day, d) => { const start = order order += day.entries.length + 1 return (
    • {day.name && (

      {day.name}

      )}
    • ) })}
    ) } if (slide.kind === 'block') { const items = entry.items ?? [] return (

    {[slide.day!.name, entry.time].filter(Boolean).join(' · ')}

    {entry.featured && ( )} {entry.text}

    {(entry.location || entry.person || entry.detail) && (

    {[entry.location, entry.person?.name, entry.detail].filter(Boolean).map((part, i) => ( {part} ))}

    )}
      {items.map((item, i) => (
    • {item.time} {item.featured && ( )} {item.text} {(item.location || item.detail) && ( {[item.location, item.detail].filter(Boolean).join(' · ')} )} {item.person && ( {item.person.name} )}
    • ))}
    ) } if (slide.kind === 'graphic' || slide.kind === 'map') { const src = mediaUrl(slide.kind === 'map' ? entry.map_image : entry.media) const alt = slide.kind === 'map' ? mapAlt(entry) : (entry.media_alt ?? '') return (
    {alt} {entry.time} {entry.text} {slide.kind === 'map' && (entry.map || entry.location) && ( {entry.map || entry.location} )}
    ) } // Spotlight: the person on the left, when there is one. return (
    {entry.person && (

    {entry.person.name}

    {entry.person.tagline && (

    {entry.person.tagline}

    )}
    )}

    {[slide.day!.name, slide.parent?.text, entry.time].filter(Boolean).join(' · ')}

    {entry.featured && ( )} {entry.text}

    {entry.tags?.length ? (

    ) : null} {entry.location && (

    {entry.location}

    )} {entry.detail && (

    {entry.detail}

    )} {entry.description && (
    )}
    ) }