import { CanonicalValidate, ParseCheckReport } from './validate.js'; /** * A translation `@lokascript/semantic` refused because it would lose part of * the script (`LossyTranslationError`). A build that keeps the source text for * such an attribute (`lenient`) says so, with what the translation would drop; * it used to keep the source silently. */ interface RefusalReport { /** The hyperscript whose translation was refused. */ code: string; from: string; to: string; /** What the translation would drop. */ lost: string[]; /** What it would have produced: NOT the whole script. */ partial: string; } /** What to do with a refused translation. Default 'warn' (deduped console.warn). */ type OnRefused = 'warn' | 'error' | ((report: RefusalReport) => void); declare function formatRefusalReport(r: RefusalReport): string; /** * HTML attribute scanner + translator. * * Walks an HTML string, finds `_="..."` (and single-quoted / backtick variants) * attributes, translates each from a source locale to a target locale, and * returns the rewritten HTML. The grammar transformer doesn't know about HTML; * this module is the glue. * * Optionally parse-checks the ENGLISH side against the real `hyperscript.org` * engine (see ./validate): the input when `from === 'en'` and the output when * `to === 'en'`. The check only runs when a `validate` function is supplied, so * existing callers see no behaviour change. */ type LangCode = string; /** What to do with an invalid-English report. */ type OnInvalid = 'warn' | 'error' | ((report: ParseCheckReport) => void); interface TranslateHtmlOptions { /** Source locale of the input HTML's `_=` attributes. Defaults to 'en'. */ from?: LangCode; /** * If true, swallow per-attribute translation errors and leave the original * text in place. Defaults to true so a single bad sample doesn't fail the * whole page build. */ lenient?: boolean; /** * Canonical validator (from `loadValidator()`). When absent, no parse-check * runs and behaviour is unchanged. */ validate?: CanonicalValidate; /** What to do with an invalid-English report. Default 'warn' (deduped console.warn). */ onInvalid?: OnInvalid; /** * Set false when the caller already validated the English input (as * `translateHtmlToManyLangs` and the CLI do). Default true. */ checkInput?: boolean; /** * What to do when a translation is refused because it would lose part of the * script: 'warn' (default, deduped), 'error' (throw), or a callback. With * `lenient`, the attribute keeps its source text either way. */ onRefused?: OnRefused; } /** * Every `_=` attribute body in `html` (double/single/backtick quoted), deduped, * in document order. */ declare function extractHyperscriptAttributes(html: string): string[]; /** * Validate every English `_=` attribute body of `html`; returns a report for * each invalid one (stage 'input'). */ declare function checkHtmlInput(html: string, validate: CanonicalValidate, to?: LangCode): ParseCheckReport[]; declare function translateHtml(html: string, to: LangCode, options?: TranslateHtmlOptions): string; declare function translateHtmlToManyLangs(html: string, langs: ReadonlyArray, options?: TranslateHtmlOptions): Map; export { translateHtmlToManyLangs as a, checkHtmlInput as c, extractHyperscriptAttributes as e, formatRefusalReport as f, translateHtml as t }; export type { LangCode as L, OnInvalid as O, RefusalReport as R, TranslateHtmlOptions as T, OnRefused as b };