import type React from 'react'; export interface ColletConfig { /** Color mode: 'light', 'dark', or 'auto' (follows prefers-color-scheme). */ mode?: 'light' | 'dark' | 'auto'; /** Brand name for theming. Loads and applies a complete visual identity. */ brand?: string; /** Locale string (e.g. 'en', 'sv'). Sets lang attribute on the theme wrapper. */ locale?: string; /** Enable lazy WASM loading (default: true). */ lazy?: boolean; /** * Where the runtime assets live — `{baseUrl}/tokens.css`, * `{baseUrl}/cx-utilities.css`, `{baseUrl}/wasm_api_bg.wasm`. Omit it and * core inlines the CSS and resolves the WASM relative to its own module, * which is what most bundlers want. * * Forwarded verbatim to `init()`. Without it here, any app that copies the * assets somewhere explicit — a CDN prefix, a hashed `/static/` path — could * not use this provider at all and had to call `init()` itself, which is the * one setup path the documentation does not describe. * * `''` is meaningful and different from omitted: it resolves against the site * root (`/tokens.css`). */ baseUrl?: string; /** * Components to register, as kebab-case names without the `cx-` prefix * (e.g. `['button', 'text-input']`). * * Strongly recommended for any app that does not render its full component * set on first paint. Without it, `init()` falls back to scanning the DOM * and then watching for additions — which works, but registers on demand * rather than up front. An explicit list makes registration deterministic * and lets bundlers drop the element modules you never use. * * `cx-theme` is always registered regardless of this list. */ components?: string[]; /** * Localized strings, as a partial map of dotted key → text * (`{ 'dialog.close': 'Stäng' }`). Unlisted keys keep their English default. * * Passed here rather than through `setStrings()` because the provider hands * them to `init()` BEFORE the WASM binary resolves, and core replays them the * moment it does — strictly before any component's first render. Calling * `setStrings()` from your own effect instead is a race you usually lose: the * app paints English, then repaints translated. * * Read the valid keys with `stringKeys()` from `@colletdev/core`; unknown keys * are returned by `setStrings()` and warned about in dev mode. */ strings?: Record; } /** * What `useCollet()` returns: the configuration you passed, plus the outcome of * the `init()` the provider ran. */ export interface ColletState extends ColletConfig { /** * True once `init()` has SETTLED — successfully or not. * * Settled means the promise `init()` returned has resolved: stylesheets * adopted, and every element in `components` (plus `cx-theme`) passed through * `customElements.define`. When this is true, `customElements.get('cx-button')` * is defined. * * It used to mean only that `import('@colletdev/core')` had resolved — the * provider called `init()` and dropped the promise on the floor — so `ready` * flipped true one microtask into a multi-step async registration, and * anything gated on it ran against un-upgraded elements. */ ready: boolean; /** * The failure `init()` reported, or `null`. * * Populated from BOTH channels, because which one fires depends on `lazy`: * * - `lazy: false` — a failed WASM fetch rejects the `init()` promise. * - `lazy: true` (the default) — `init()` resolves as soon as the stylesheets * are in and WASM continues in the background. A failure there cannot * reject an already-resolved promise, so core dispatches `cx-load-error` on * `document` instead. The provider listens for it. * * Watching only the promise is therefore watching the channel the default * configuration never uses: a consumer whose WASM 404'd behind a CDN rule got * `ready: true`, `error: null`, and an app of empty custom elements — every * `` renders as an inert unknown element until it is upgraded. */ error: Error | null; } /** Access Collet configuration and init state from any child component. */ export declare function useCollet(): ColletState; export interface ColletProviderProps extends ColletConfig { /** * Called if initialization fails, from either channel described on * {@link ColletState.error}. Without it the provider logs the failure and * renders children anyway — it must not blank the app, but it must not stay * quiet either. * * Called at most once per provider: the first failure wins, so a background * WASM error arriving after a rejected `init()` does not report twice. */ onError?: (error: Error) => void; children: React.ReactNode; } /** * Wraps your app with Collet initialization and theme configuration. * * Handles `init()`, theme propagation via ``, and locale. * Place at the root of your app — replaces manual init() calls. * * @example * ```tsx * * * * ``` */ export declare const ColletProvider: React.FC;