// fixtures/font-status.mjs — what the page says about its fonts, in one // place: a status strip laid over the formatting bar (views/show.html's // [docs-fonts-status]). // // Over the bar, never over the document (branch review 7: floating notes // covered text, and the substitutes note never went away). The strip is // in the page from the start and takes no space of its own, so saying // something moves nothing. While a font loads the bar is inert anyway; // the other notes go away on their own, or when dismissed. // // Its text is in a polite live region that is always in the page, empty // when there is nothing to say, so a screen reader hears each change. // The copy is the catalog's, on the element's data-* attributes. // // The fonts gate (fonts-gate.mjs) and the editor (editor-entry.js) each // make one of these over the same element, so what is being said is read // from the element, not kept here. export function fontStatus(el, { setTimer = setTimeout, clearTimer = clearTimeout } = {}) { if (!el) return { say() {}, tell() {}, clear() {}, state: '' } const text = el.querySelector('[docs-fonts-status-text]') const dismiss = el.querySelector('[docs-fonts-status-dismiss]') let timer = null const state = () => el.getAttribute('data-state') || '' // clear(kind) clears only if kind is still what is said. function clear(kind) { if (kind && state() !== kind) return clearTimer(timer) el.removeAttribute('data-state') if (text) text.textContent = '' } if (dismiss) dismiss.addEventListener('click', () => clear()) return { // say shows one of the element's messages: loading, refused, // unavailable or substitute. ms, when given, takes it down after. say(kind, ms = 0) { clearTimer(timer) el.setAttribute('data-state', kind) if (text) text.textContent = el.getAttribute('data-' + kind) || '' if (ms) timer = setTimer(() => clear(kind), ms) }, // tell says a sentence of the page's own (an image notice, Docs // images spec §2), as a 'notice' the strip can dismiss. tell(sentence, ms = 0) { clearTimer(timer) el.setAttribute('data-state', 'notice') if (text) text.textContent = sentence if (ms) timer = setTimer(() => clear('notice'), ms) }, clear, get state() { return state() }, } }