// fixtures/font-status.mjs — what the editor says about its fonts, in one // place: the status strip under the editor's bar // (templates/editor.html's [slides-fonts-status]). Docs' font-status.mjs, // adopted. // // The strip is always in the page and keeps its own row, so saying // something moves nothing (editor.css), and its text is a polite live // region that is there before the text changes, so a screen reader hears // each change. The copy is the catalog's, on the element's data-* // attributes (fontgate.go); this file holds none. // // 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 () {}, clear () {}, state: '' } const text = el.querySelector('[slides-fonts-status-text]') const dismiss = el.querySelector('[slides-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) }, clear, get state () { return state() } } }