@nextgensoftwares/folio-a11y
Framework-free accessibility helpers every Folio UI shares (folio-react re-exports them; the reader and the slides viewer use them directly, with no editor code). Guide: Accessibility.
Tooltips
| Export | Signature | Description |
|---|---|---|
tooltipProps | (text?: string, shortcut?: string) => props | handlers for any element (React-style names): the tooltip on hover and keyboard focus (not on click or touch), after a short delay (none while moving along a toolbar), Esc dismisses, hoverable; aria-describedby points at it while shown; aria-keyshortcuts from shortcut. One shared role="tooltip" per document, in the top layer (popover: above dialogs, fullscreen shows and transformed stages), placed next to the trigger and kept on screen (flips above near the bottom, shifts at the sides), in the direction of the trigger, mouse and pen hover only. Its colours always reach 4.5:1: --folio-tooltip-bg / --folio-tooltip-fg when the host sets both with enough contrast, else a dark tip on light surfaces and a light tip on dark ones. Its styles stay in unstyled mode |
scheduleTooltip, dismissTooltip | (el, text, shortcut?), (el, now?) | the same, imperatively |
preloadTooltips | () => Promise<void> | the tooltip's DOM, styles and placement are a small lazy chunk: the first hover loads it inside the show delay, and tooltipProps prefetches it when the browser is idle. Await it to show tooltips synchronously (tests with fake timers) |
placeTooltip | (trigger rect, { w, h }, viewport { w, h }) => { left, top, below } | the placement rule (below, else above; shifted 8px inside the viewport) |
tooltipColors | (trigger: Element) => { bg, fg } | the colours a tooltip for that trigger uses |
contrast, parseColor | (a, b) => ratio, (css) => [r, g, b, a] | null | WCAG contrast ratio; parses rgb() / rgba() / #rgb / #rrggbb |
Dialogs
Folio's own small dialogs, used by the plugins' defaults instead of the browser's prompt, confirm and alert (Embed, Alt text…, player URLs, version names):
| Function | Answers |
|---|---|
askText({ label, value?, placeholder?, hint?, validate?, inputMode?, title?, okLabel?, cancelLabel?, from?, t? }) | the text, or null (Cancel, Escape, no DOM) |
askConfirm({ message, danger?, okLabel?, ... }) | true / false |
tell({ message, ... }) | once dismissed |
promptText(label, value?, more?) | askText in window.prompt's shape, for prompt options |
They are modal (role="dialog" / alertdialog, aria-modal), keep Tab inside, answer Enter and Escape, keep the page's shortcuts from seeing their keys, and give focus back to where it was. validate returns the message shown under the field (role="alert"); the dialog stays open until it returns nothing. They take the direction, lang (built-in or registerMessages strings) and data-folio-theme of the element they open from (from, default the focused one), and Folio's tokens when @nextgensoftwares/folio-react's stylesheet is on the page (class folio-ask-*). The DOM is its own chunk, loaded on first use.
Shortcuts
| Export | Signature | Description |
|---|---|---|
formatShortcut | (binding?: string, mac?: boolean) => string | undefined | Mod-Shift-z → ⇧⌘Z on Apple platforms, Ctrl+Shift+Z elsewhere; ProseMirror (Mod-b), Ctrl+= style and already formatted text |
ariaShortcut | (binding?, mac?) => string | undefined | the aria-keyshortcuts value (Control+B, Meta+B) |
isMac | () => boolean | Apple platform |
Announcements
| Export | Signature | Description |
|---|---|---|
announce | (message, { politeness?: 'polite' | 'assertive', doc? }) => void | one shared visually hidden live region per document (role="status", or role="alert" when assertive); repeated messages are spoken again |
visuallyHidden | string | inline style hiding an element visually, keeping it for assistive technology |
Roving focus
| Export | Signature | Description |
|---|---|---|
syncRoving | (group, selector?) => void | one tab stop per group (the focused, selected or current item, else the first) |
rovingKeyDown | (event, group, { selector?, orientation?, wrap? }) => boolean | arrows (mirrored right to left), Home and End move focus; text fields keep their arrows |
rovingRef | (options?) => (el) => void | a stable callback ref making an element a roving group (arrows, one tab stop, re-synced as items change): ref={rovingRef({ orientation: 'both' })} |
focusNeighbour | (from, dir: 1 | -1) => boolean | moves focus to the next / previous tab stop, as Tab would: for widgets that use Tab themselves (the slide editor stepping through shapes) and hand it back at their end |
rovingItems, ROVING_ITEMS, RovingOptions | the group's items (shown, not in a nested group); the default selector |
UI strings and language
Folio's built-in strings are English and are their own keys. A catalog maps the English text to another language, {name} placeholders are filled in, and anything the catalog lacks stays English. Arabic is built in; hosts add or override strings. folio-react (FolioApp, <FolioLocale>), the slides viewer and SlidesApp (locale, messages) and the reader shell use these.
| Export | Signature | Description |
|---|---|---|
translator | (locale = 'en', messages?) => Translator | { locale, dir, t(text, vars?) }: messages first, then the locale's built-in catalog once loaded, then English |
EN | Translator | English (the strings as written) |
Messages, Translator | types | Record<english, translated>; the translator object |
isRtlLocale | (locale?) => boolean | Arabic, Persian, Hebrew, Urdu and the other right-to-left languages |
loadMessages | (locale) => Promise<Messages | null> | loads a built-in catalog (its own small chunk; Arabic today); translators made afterwards use it, and Folio's UI re-renders when it lands |
messagesReady | (locale?) => boolean | true when nothing needs loading (English, a locale without a catalog, or one already loaded) |
registerMessages | (locale, messages) => void | registers or extends a locale's built-in catalog (another language, or your own Arabic wording) |
@nextgensoftwares/folio-a11y/ar → AR | Messages | the Arabic catalog itself, to pass as messages (or to registerMessages) up front instead of loading it |
Credit
The "Made with Folio" credit that FolioApp, SlidesApp, SlideDeck and FolioReaderShell show (each takes credit?: boolean | { href?, label? }; credit is requested, not required).
| Export | Description |
|---|---|
resolveCredit(prop, t?) → { href, label } | what a credit prop shows (always something): the default, or an object's own href (http(s) only) / label (non-empty); false gives the default |
CREDIT_HREF, CREDIT_LABEL | https://folio.nextgen-softwares.com, "Made with Folio" (Arabic: "صُنع باستخدام Folio") |
CREDIT_CSS | .folio-credit styles: small text in its bar's colour, a focus ring, the mark alone under 640px (the link keeps its name), hidden under [data-focus] and in print; --folio-credit-fg recolours it |
FOLIO_MARK | the mark's SVG paths (page, fold, lines, 24 × 24) |
CreditOptions, CreditProp | the prop's types |
Selection actions
SelectionAction<C, I>: { id, label, icon?, when?(ctx), onSelect(ctx), keepOpen? }, the shape of a host's action offered for a selection (reader shell, slides). SelectionActionsProp<C, I>: a list of them or a (ctx) => ReactNode-style render function. visibleSelectionActions(actions, ctx) keeps the ones whose when passes (a throwing when hides its action); runSelectionAction(action, ctx) runs one and logs a failing onSelect instead of throwing.
@nextgensoftwares/folio-a11y/export-credit
The credit's DOM-free helpers (mark geometry, direction, contrast), shared by the canvas and DOM surfaces. Exported files carry no credit since 0.57; resolveExportCredit and the labels stay for hosts that use them.
| Export | Description |
|---|---|
resolveExportCredit(prop, { lang?, rtl? }) → { href, label } | an exporter's credit option: "Made with Folio" by default, in Arabic for an Arabic lang or (without one) a right-to-left document; an object its own href / label; false gives the default |
EXPORT_CREDIT_LABEL, EXPORT_CREDIT_LABEL_AR | "Made with Folio", "صُنع باستخدام Folio" |
CREDIT_PRODUCER | Folio (https://folio.nextgen-softwares.com): the PDF Producer |