import { FontRegistry, FontFaceRequest, FontLoadSummary, FontResolutionRecord } from '../../../../../../../shared/font-system/src/index.js';
export type { FontLoadSummary } from '../../../../../../../shared/font-system/src/index.js';
/**
 * The font set the gate operates on plus the constructor for new managed faces.
 * Both come from the SAME window/document so the registry it derives and the set
 * it watches for load events are the same object - the iframe-safe pairing. The
 * ctor is the host window's `FontFace` (the structural cast to the registry's
 * face type is confined to {@link FontReadinessGate} so callers pass it directly).
 */
export interface FontEnvironment {
    fontSet: FontFaceSet;
    FontFaceCtor: typeof FontFace;
}
export interface FontReadinessGateOptions {
    /** Logical font families the current document DECLARES (fontTable). Used for diagnostics. */
    getDocumentFonts: () => string[];
    /**
     * The exact physical FACES (family + weight + style) the current document RENDERS, from
     * the planner walking layout input. When provided, the gate awaits these faces instead of
     * declared families - so bold/italic load before measure and declared-but-unused fonts are
     * not fetched. Falls back to the {@link getDocumentFonts} + {@link resolveFamilies} family
     * path when omitted (tests / non-layout callers).
     */
    getRequiredFaces?: () => FontFaceRequest[];
    /** Trigger a re-measure + re-layout + repaint (PresentationEditor's immediate render). */
    requestReflow: () => void;
    /**
     * The font set + face constructor for this editor's document. Resolved lazily (the host
     * document is not available at construction). The registry is derived from this same
     * `fontSet`, so awaits and load-event watching always target one set. Defaults to the
     * ambient `document.fonts`.
     */
    getFontEnvironment?: () => FontEnvironment | null;
    /**
     * Map logical families to the physical families that must actually load: the
     * logical->physical map so the gate waits on the real substitute (e.g. Calibri -> Carlito).
     * Defaults to identity when not provided; the editor wires `resolvePhysicalFamilies`.
     */
    resolveFamilies?: (families: string[]) => string[];
    /** Per-font load budget before a face is treated as timed out. */
    timeoutMs?: number;
    /** Explicit registry override (tests). Normally derived from the font environment. */
    registry?: FontRegistry;
    /**
     * Called once when the registry is first resolved (a real font set is available).
     * The editor uses this to install the bundled substitute pack into the registry, so
     * the gate stays pack-agnostic and never imports the font assets itself.
     */
    onRegistryResolved?: (registry: FontRegistry) => void;
    /**
     * Cache invalidation hook. Defaults to clearing every font-dependent measurement cache
     * (text/font-metric/table caches + the block-measure cache). Injectable for tests.
     */
    invalidateCaches?: () => void;
    /** Late-load reflow batching: quiet window before the leading flush. Defaults to the scheduler default. */
    reflowQuietMs?: number;
    /** Late-load reflow batching: cooldown (min interval between flushes). Defaults to the scheduler default. */
    reflowCooldownMs?: number;
    /** Timer hooks for the late-load scheduler (injectable for tests); default to the globals. */
    scheduleTimeout?: (cb: () => void, ms: number) => unknown;
    cancelTimeout?: (handle: unknown) => void;
}
/**
 * Load-before-measure gate.
 *
 * The layout pipeline measures text with the canvas `measureText` API, which silently
 * substitutes a fallback when the requested font has not loaded yet. That makes first
 * paint paginate against the wrong metrics and then reflow once the font arrives. This
 * gate closes that window: before each measurement pass it awaits the specific faces the
 * current document needs (not a global `document.fonts.ready`), and if a required face
 * finishes after a timed-out first paint it invalidates the measurement caches and
 * reflows exactly once.
 *
 * It owns no font loading itself - that is `@superdoc/font-system`. It owns the editor-side
 * lifecycle: when to wait, when to invalidate, when to reflow.
 */
export declare class FontReadinessGate {
    #private;
    constructor(options: FontReadinessGateOptions);
    /**
     * Font-config epoch. Increments whenever the available-font picture changes (a late
     * load, or a runtime add/map). The resolver (T1) will fold this into the per-fragment
     * paint signature so paint reuse busts on a font change, not just measurement.
     */
    get fontConfigVersion(): number;
    /** Most recent readiness summary, for diagnostics and the public DX surface (later). */
    getDiagnostics(): FontLoadSummary | null;
    /**
     * Per-font resolution report for the current document: requested -> rendered -> reason
     * -> load status -> export family. The observable answer to "what did SuperDoc render
     * and is it faithful". Built through the shared resolver + registry, so it reflects
     * exactly what was measured and painted - not an independent computation.
     */
    getReport(): FontResolutionRecord[];
    /**
     * Await the faces the current document needs, then return their outcomes. Safe and
     * cheap to call on every render: when the required set is unchanged and already fully
     * loaded it returns the cached summary without awaiting. Never rejects - font readiness
     * must not break layout.
     */
    ensureReadyForMeasure(): Promise<FontLoadSummary>;
    /**
     * Signal that the font configuration changed at runtime (customer add/map, T7). Bumps
     * the epoch, invalidates measurement caches, and reflows so the new mapping takes effect.
     */
    notifyFontConfigChanged(): void;
    /**
     * Reset late-load state for a document swap: cancel the pending batched reflow and drop the
     * prior document's required/seen sets, so a flush armed under the old document cannot fire a
     * spurious reflow against the new one. The new document's own render re-plans and invalidates.
     */
    resetForDocumentChange(): void;
    /** Remove the late-load listener and cancel any pending batched reflow. Call on teardown. */
    dispose(): void;
}
//# sourceMappingURL=FontReadinessGate.d.ts.map