// fixtures/step-marks.mjs — the order of a slide's presses, drawn // (steps and presenter spec §4): a small muted number in each box's // margin, the press it arrives on, counted 1, 2, 3 in press order // whatever its step value; an item-by-item list has one beside each // item. Drawn only while a box on a slide with presses is selected, so a // slide without steps, or a slide nobody is working on, shows nothing. // // The numbers are an overlay laid over the stage, outside the slide's // own DOM (ProseMirror owns the boxes' insides) and hidden from readers // (aria-hidden): the card's Appears row says the same in words. Placed // from the boxes' rectangles as presence-view.mjs places its marks, and // empty (so not drawn: editor.css) when there is nothing to show. // // A scene block's states are presses too (scenes the deck's, presses.mjs): // it has one mark, its first press to its last ("1–2"). // // mountStepMarks({stageEl, getSlide, getSelected, getScenes}) → // {place(), destroy()}: place() after anything that moves a box or // changes the document. import { presses } from './presses.mjs' /** The numbers a slide shows: each box (item -1), or list item, with its press, 1-based; a scene's last press too. */ export function marksFor (slide, scenes) { const out = [] const seen = new Map() const blocks = Array.isArray(slide && slide.blocks) ? slide.blocks : [] const scene = new Set(blocks.filter(b => b.type === 'scene').map(b => b.id)) presses(slide, scenes).forEach((press, i) => { for (const m of press) { const item = scene.has(m.block) ? -1 : m.item const key = `${m.block}:${item}` if (seen.has(key)) { if (item === -1 && scene.has(m.block)) seen.get(key).last = i + 1 continue } const mark = { block: m.block, item, n: i + 1 } seen.set(key, mark) out.push(mark) } }) return out } export function mountStepMarks ({ stageEl, getSlide, getSelected, getScenes = () => null }) { const marks = document.createElement('div') marks.setAttribute('slides-step-marks', '') marks.setAttribute('aria-hidden', 'true') stageEl.append(marks) const boxEl = id => stageEl.querySelector(`[slides-slide] [slides-block][data-id="${CSS.escape(id)}"]`) function place () { if (!marks.isConnected) stageEl.append(marks) marks.replaceChildren() const id = getSelected() const slide = id ? getSlide() : null if (!slide || !Array.isArray(slide.blocks) || !slide.blocks.some(b => b.id === id) || !boxEl(id)) return const frame = stageEl.getBoundingClientRect() for (const m of marksFor(slide, getScenes())) { const el = boxEl(m.block) if (!el) continue const items = m.item >= 0 ? el.querySelectorAll('li') : null const at = items && items[m.item] ? items[m.item] : el const box = el.getBoundingClientRect() const r = at.getBoundingClientRect() if (!box.width && !box.height) continue const mark = document.createElement('span') mark.setAttribute('slides-step-mark', '') mark.textContent = m.last ? `${m.n}–${m.last}` : String(m.n) // Its end edge against the box's start edge, level with the // box's top, or the item's. const rtl = getComputedStyle(stageEl).direction === 'rtl' const x = (rtl ? box.right : box.left) - frame.left + stageEl.scrollLeft mark.style.left = x + 'px' if (rtl) mark.setAttribute('data-rtl', '') mark.style.top = (r.top - frame.top + stageEl.scrollTop) + 'px' marks.append(mark) } } const ro = typeof ResizeObserver === 'function' ? new ResizeObserver(() => place()) : null if (ro) ro.observe(stageEl) return { place, destroy () { if (ro) ro.disconnect() marks.remove() } } }