/** * Auto-Init for Browser Bundle * Reads script tag attributes and auto-configures LionRapid * * Usage: * */ import { AutoTranslator } from './auto-translator.js'; import { LanguageSwitcher } from './language-switcher.js'; export interface AutoInitConfig { apiKey: string; baseUrl: string; defaultLocale: string; namespace: string; languages: string[]; excludeSelectors: string[]; autoDetect: boolean; mode: 'full' | 'dynamic-only'; switcherStyle?: string; switcherPosition?: string; switcherShowFlags?: boolean; switcherShowNames?: boolean; switcherCustomCss?: string; /** Override for the visual editor bundle URL. Defaults to the public CDN. * Self-hosted hosts (e.g. the WordPress plugin) point this at their own * vendored copy so the editor is version-locked to the host, not the CDN. */ editorCdnUrl?: string; /** Offline resilience: add a never-expiring "last known good" cache layer that * is hydrated by successful fetches, so the site keeps translating with the * server down even after the normal caches expire. Default on; disable with * `data-offline="false"`. */ offline?: boolean; } declare global { interface Window { LionRapid: LionRapidInstance | undefined; __lionrapidConfig?: AutoInitConfig; } } /** * Write policy for a browser-embedded key. * * A publishable `pk_` key gets the DISCOVERY path only: page views sync * missing source strings so rows appear in the dashboard (the server's * `_SYNC_KEYS` explicitly allows publishable keys on /sync). It can never * write translations — the server restricts those to master/editor-session * keys (`_WRITE_KEYS`), which is what actually blocks the stored-XSS loop. * * Anything that isn't a pk_ key is a secret shipped to the page (Phase 18): * the network layer refuses to boot at all — the key never goes on the * wire — and the refusal is flagged loudly so the integrator notices. */ export declare function resolveWritePolicy(apiKey: string): { /** Phase 18: pk_ is the ONLY key that boots the network layer — a non-pk_ * value is a secret (or garbage) pasted into public HTML and must never * go on the wire. Cached/offline translations still apply. */ bootNetwork: boolean; syncMissing: { enabled: boolean; }; warnRefused: boolean; }; /** * The config copy mirrored to `window.__lionrapidConfig` for the editor * bundle — with the API key stripped. The key must never sit on `window` * where any third-party script on the page could read it; the editor only * needs languages/namespace/locale from here. */ export declare function configForWindow(config: AutoInitConfig): AutoInitConfig; /** * Switcher change-handling that survives the boot window. `build()` can take * seconds under a failing network (retry backoff); a click in that window * must not be silently dropped. The cookie is written and dynamic-only * navigation happens immediately (neither needs core); in full mode a click * before `attach` is remembered (last one wins) and replayed the moment the * core-bound apply function is attached. */ export declare function createDeferredLocaleHandler(effects: { setCookie: (locale: string) => void; /** non-null in dynamic-only mode — navigation replaces in-place apply */ navigate: ((locale: string) => void) | null; }): { onChange: (locale: string) => Promise; attach: (apply: (locale: string) => Promise) => void; }; /** * Run `fn` once the DOM is parsed — immediately if it already is. Guards the * DOM-writing steps (switcher render, translatePage/observe) so a snippet * booted from `` doesn't run them against a null `document.body`. * Network preload and `build()` are NOT gated — only DOM writes wait. */ export declare function onDomReady(fn: () => void): void; export interface LionRapidInstance { t: (key: string, params?: Record, defaultValue?: string) => string; tHtml: (key: string, params?: Record, defaultValue?: string) => string; changeLanguage: (locale: string) => Promise; getCurrentLocale: () => string; on: (event: string, callback: (payload: unknown) => void) => void; retranslate: () => void; reloadTranslations: () => Promise; autoTranslator: AutoTranslator; languageSwitcher: LanguageSwitcher; } /** * Parse script tag attributes */ declare function parseConfig(script: HTMLScriptElement): AutoInitConfig; /** * Build a locale-prefixed URL (pure — no navigation). Strips an existing * locale prefix only when it's a known language, so a path like `/about-us/` * is never mistaken for a locale; full BCP-47 prefixes (`/pt-BR/…`) are handled. * The default locale is served un-prefixed. */ export declare function buildLocaleUrl(pathname: string, search: string, locale: string, defaultLocale: string, availableLanguages: string[]): string; /** * Resolve the initial locale from the environment, preserving full BCP-47 * tags. Dynamic-only trusts the server-set ``; full mode uses * cookie → browser negotiation → default. Extracted so the precedence matrix * is testable without booting `autoInit`. */ export declare function resolveInitialLocale(config: AutoInitConfig): string; /** Reflect the locale's text direction on `` (RTL languages). */ export declare function applyLocaleDir(locale: string): void; /** * The `