{"version":3,"sources":["../src/dark-mode.ts","../src/style-sink.ts","../src/runtime.ts","../src/config-source.ts","../src/index.ts"],"names":["createEngine","mergeConfig"],"mappings":";;;;;;;;;AAGO,IAAM,gBAAA,GAAmB;AAEhC,IAAM,WAAA,GAAc,gBAAA;AAeb,SAAS,kBAAA,GAA6B;AACzC,EAAA,OACI,CAAA,+BAAA,EAC8B,IAAA,CAAK,SAAA,CAAU,gBAAgB,CAAC,CAAA,qKAAA,CAAA;AAKtE;AAOO,IAAM,qBAAN,MAAyB;AAAA,EAO5B,YAAY,QAAA,EAA4B;AANxC,IAAA,aAAA,CAAA,IAAA,EAAQ,UAAA,CAAA;AACR,IAAA,aAAA,CAAA,IAAA,EAAQ,KAAA,EAA6B,IAAA,CAAA;AACrC,IAAA,aAAA,CAAA,IAAA,EAAQ,YAAW,MAAM;AACrB,MAAA,IAAI,IAAA,CAAK,YAAW,KAAM,IAAA,OAAW,KAAA,CAAM,IAAA,CAAK,mBAAmB,CAAA;AAAA,IACvE,CAAA,CAAA;AAGI,IAAA,IAAA,CAAK,QAAA,GAAW,QAAA;AAChB,IAAA,IAAI,IAAA,CAAK,QAAO,EAAG;AACf,MAAA,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,cAAA,EAAgB,CAAA;AAChC,MAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,MAAA,CAAO,eAAe,UAAA,EAAY;AAC1E,QAAA,IAAA,CAAK,GAAA,GAAM,MAAA,CAAO,UAAA,CAAW,8BAA8B,CAAA;AAC3D,QAAA,IAAA,CAAK,GAAA,CAAI,gBAAA,GAAmB,QAAA,EAAU,IAAA,CAAK,QAAQ,CAAA;AAAA,MACvD;AAAA,IACJ;AAAA,EACJ;AAAA,EAEQ,MAAA,GAAkB;AACtB,IAAA,OAAO,IAAA,CAAK,QAAA,KAAa,OAAA,IAAW,OAAO,QAAA,KAAa,WAAA;AAAA,EAC5D;AAAA,EAEQ,iBAAA,GAA6B;AACjC,IAAA,OA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B;AASO,SAAS,YAAA,GAAqB;AACjC,EAAA,KAAA,CAAM,oBAAoB,OAAA,EAAQ;AAClC,EAAA,KAAA,CAAM,kBAAA,GAAqB,IAAA;AAC/B;AAGO,SAAS,UAAA,GAAgC;AAC5C,EAAA,OAAO,MAAM,kBAAA,IAAsB,IAAA;AACvC","file":"index.cjs","sourcesContent":["import type { DarkModeStrategy } from \"@nibcss/core\";\n\n/** Where the manual light/dark choice is kept, for `darkMode: \"class\"`. */\nexport const DARK_STORAGE_KEY = \"nib-dark\";\n\nconst STORAGE_KEY = DARK_STORAGE_KEY;\n\n/**\n * The same decision as `resolveInitial()`, as a string to inline in `<head>`.\n *\n * `html.dark` is added by the runtime, which cannot run before the document\n * exists — so a server-rendered page in dark mode painted light first and\n * turned dark a moment later. On a reload that is a white flash in a dark app,\n * and the one thing a stylesheet cannot fix: the class has to be there before\n * the first paint.\n *\n * Kept tiny and `try`-wrapped, because it runs blocking, before anything else,\n * in whatever state the browser is in — private mode, storage blocked, no\n * `matchMedia`.\n */\nexport function darkModeBootScript(): string {\n    return (\n        \"try{\" +\n        `var k=localStorage.getItem(${JSON.stringify(DARK_STORAGE_KEY)});` +\n        'var d=k===null?!!(window.matchMedia&&matchMedia(\"(prefers-color-scheme: dark)\").matches):k===\"true\";' +\n        'if(d)document.documentElement.classList.add(\"dark\");' +\n        \"}catch(e){}\"\n    );\n}\n\n/**\n * Toggles the `.dark` class on `<html>` for the `\"class\"` strategy.\n * Persists the choice and falls back to the OS preference.\n * A no-op (but safe to call) for `\"media\"` / `false` / non-browser.\n */\nexport class DarkModeController {\n    private strategy: DarkModeStrategy;\n    private mql: MediaQueryList | null = null;\n    private onSystem = () => {\n        if (this.readStored() === null) this.apply(this.systemPrefersDark());\n    };\n\n    constructor(strategy: DarkModeStrategy) {\n        this.strategy = strategy;\n        if (this.active()) {\n            this.apply(this.resolveInitial());\n            if (typeof window !== \"undefined\" && typeof window.matchMedia === \"function\") {\n                this.mql = window.matchMedia(\"(prefers-color-scheme: dark)\");\n                this.mql.addEventListener?.(\"change\", this.onSystem);\n            }\n        }\n    }\n\n    private active(): boolean {\n        return this.strategy === \"class\" && typeof document !== \"undefined\";\n    }\n\n    private systemPrefersDark(): boolean {\n        return typeof window !== \"undefined\" && !!window.matchMedia?.(\"(prefers-color-scheme: dark)\").matches;\n    }\n\n    private readStored(): boolean | null {\n        try {\n            const v = localStorage.getItem(STORAGE_KEY);\n            return v === null ? null : v === \"true\";\n        } catch {\n            return null;\n        }\n    }\n\n    private resolveInitial(): boolean {\n        const stored = this.readStored();\n        return stored ?? this.systemPrefersDark();\n    }\n\n    private apply(dark: boolean): void {\n        if (typeof document === \"undefined\") return;\n        document.documentElement.classList.toggle(\"dark\", dark);\n    }\n\n    /**\n     * Whether dark rules are in effect right now.\n     *\n     * Under `\"media\"` that is the OS preference, not `html.dark`: the generated\n     * CSS is inside `@media (prefers-color-scheme: dark)`, so the page really is\n     * dark while the class is absent. Reading only the class made\n     * `NibService.isDark` always answer `false` under `\"media\"`, and a template\n     * showing a sun or a moon from it showed the wrong one.\n     */\n    isDark(): boolean {\n        if (this.strategy === \"media\") return this.systemPrefersDark();\n        if (!this.active()) return false;\n        return document.documentElement.classList.contains(\"dark\");\n    }\n\n    enable(): void {\n        if (!this.active()) return;\n        this.persist(true);\n        this.apply(true);\n    }\n\n    disable(): void {\n        if (!this.active()) return;\n        this.persist(false);\n        this.apply(false);\n    }\n\n    /**\n     * Flip the class, when there is a class to flip.\n     *\n     * A no-op under `\"media\"` and `false` — every one of these used to write\n     * `html.dark` whatever the strategy said. `darkMode: false` therefore looked\n     * like it did nothing at all: NibCSS dropped its own `dark:` rules, as asked,\n     * but a project's hand-written `html.dark body { … }` still fired on the\n     * class the toggle had just added, so the page still went dark.\n     */\n    toggle(): boolean {\n        if (!this.active()) return this.isDark();\n        const next = !this.isDark();\n        next ? this.enable() : this.disable();\n        return next;\n    }\n\n    /** Forget the manual choice and follow the OS again. */\n    useSystem(): void {\n        try {\n            localStorage.removeItem(STORAGE_KEY);\n        } catch {\n            /* ignore */\n        }\n        if (!this.active()) return;\n        this.apply(this.systemPrefersDark());\n    }\n\n    setStrategy(strategy: DarkModeStrategy): void {\n        this.strategy = strategy;\n        if (this.active()) this.apply(this.resolveInitial());\n        else this.apply(false);\n    }\n\n    private persist(v: boolean): void {\n        try {\n            localStorage.setItem(STORAGE_KEY, String(v));\n        } catch {\n            /* ignore */\n        }\n    }\n\n    destroy(): void {\n        this.mql?.removeEventListener?.(\"change\", this.onSystem);\n        this.mql = null;\n    }\n}\n","/**\n * Owns a single `<style>` element in `<head>` and pushes the engine's\n * accumulated stylesheet into it. Uses a constructable stylesheet when the\n * browser supports it, otherwise falls back to `textContent`.\n */\nexport class StyleSink {\n    private el: HTMLStyleElement | null = null;\n    private sheet: CSSStyleSheet | null = null;\n    private lastCss = \"\";\n    /** True until the first non-empty render — protects adopted SSR CSS. */\n    private guardEmpty = false;\n\n    constructor(private readonly id = \"nib\") {}\n\n    /**\n     * Create (or adopt) the `<style>` element. Public so the runtime can put it\n     * in place the moment it boots — including from a `<script>` in `<head>`,\n     * before `<body>` exists — so the first rules it generates apply to markup\n     * the parser has not reached yet.\n     */\n    ensure(): void {\n        if (this.el || typeof document === \"undefined\") return;\n\n        const existing = document.getElementById(this.id);\n        if (existing instanceof HTMLStyleElement) {\n            // Adopt an SSR-rendered <style>: keep managing this exact element so\n            // there's no flash and no duplicate. Seed lastCss so an identical\n            // first render is a no-op.\n            this.el = existing;\n            this.el.setAttribute(\"data-nib\", \"runtime\");\n            this.lastCss = existing.textContent ?? \"\";\n            this.guardEmpty = this.lastCss.length > 0;\n            return;\n        }\n\n        this.el = document.createElement(\"style\");\n        this.el.id = this.id;\n        this.el.setAttribute(\"data-nib\", \"runtime\");\n        // `document.head` can still be null very early (a script injected into\n        // documentElement before <head> is open); documentElement always exists.\n        (document.head ?? document.documentElement).appendChild(this.el);\n\n        try {\n            if (\"adoptedStyleSheets\" in document && typeof CSSStyleSheet === \"function\") {\n                this.sheet = new CSSStyleSheet();\n                (document as unknown as { adoptedStyleSheets: CSSStyleSheet[] }).adoptedStyleSheets = [\n                    ...(document as unknown as { adoptedStyleSheets: CSSStyleSheet[] }).adoptedStyleSheets,\n                    this.sheet,\n                ];\n            }\n        } catch {\n            this.sheet = null;\n        }\n    }\n\n    /**\n     * @param css       the stylesheet to render\n     * @param onlyReset true when the engine has not generated any utility rules\n     *                  yet, so `css` is nothing but the preflight reset\n     */\n    render(css: string, onlyReset = false): void {\n        this.ensure();\n        if (css === this.lastCss) return;\n        // Don't wipe adopted SSR CSS before the engine has rebuilt anything.\n        // Note this can't test `css.length === 0`: with preflight enabled the\n        // engine always returns *something*, even with zero rules.\n        if (this.guardEmpty && onlyReset) return;\n        this.guardEmpty = false;\n        this.lastCss = css;\n\n        if (this.sheet) {\n            try {\n                this.sheet.replaceSync(css);\n                return;\n            } catch {\n                this.sheet = null;\n            }\n        }\n        if (this.el) this.el.textContent = css;\n    }\n\n    destroy(): void {\n        if (this.sheet) {\n            const host = document as unknown as { adoptedStyleSheets: CSSStyleSheet[] };\n            host.adoptedStyleSheets = host.adoptedStyleSheets.filter((s) => s !== this.sheet);\n            this.sheet = null;\n        }\n        this.el?.remove();\n        this.el = null;\n        this.lastCss = \"\";\n    }\n}\n","import { createEngine, mergeConfig, type Engine, type NibConfig } from \"@nibcss/core\";\nimport { DarkModeController } from \"./dark-mode.js\";\nimport { StyleSink } from \"./style-sink.js\";\n\nconst ATTRS = [\"nib\", \"data-nib\"] as const;\n\nexport interface RuntimeOptions extends NibConfig {\n    /**\n     * Where to scan and observe. Default: `document.documentElement`, so the\n     * runtime can start from a `<script>` in `<head>` — before `<body>` exists\n     * — and still style body markup as the parser produces it.\n     */\n    root?: ParentNode;\n    /** Watch the DOM for added nodes / attribute changes. Default: `true`. */\n    watch?: boolean;\n    /** Inject `CSS.supports` as the value validator. Default: `true`. */\n    nativeValidation?: boolean;\n    /**\n     * Periodically drop CSS rules whose class is no longer on any element —\n     * keeps long-lived SPAs that generate many one-off dynamic utilities bounded.\n     * `true` (default) uses sensible thresholds; `false` disables; or tune with\n     * `{ everyFlushes, maxRules }`.\n     */\n    gc?: boolean | { everyFlushes?: number; maxRules?: number };\n}\n\n/**\n * Elements that can never be styled, and so are never worth processing.\n * `STYLE` matters in particular: the runtime marks its own sheet with\n * `data-nib=\"runtime\"` (and SSR sheets carry `data-nib=\"ssr\"`), which the\n * `[data-nib]` scan would otherwise pick up and try to parse as utilities.\n */\nconst SKIP_TAGS = new Set([\"STYLE\", \"SCRIPT\", \"LINK\", \"META\", \"TITLE\", \"HEAD\", \"BASE\"]);\n\nfunction readNibAttr(el: Element): string | null {\n    if (SKIP_TAGS.has(el.tagName)) return null;\n    for (const a of ATTRS) {\n        const v = el.getAttribute(a);\n        if (v != null) return v;\n    }\n    return null;\n}\n\nconst schedule: (cb: () => void) => void =\n    typeof requestAnimationFrame === \"function\"\n        ? (cb) => requestAnimationFrame(cb)\n        : (cb) => setTimeout(cb, 0);\n\n/**\n * The document element is the only root that exists while the parser is still\n * inside `<head>` — `document.body` is null then. Observing from here is what\n * lets a synchronous `<script>` in `<head>` style body elements as the parser\n * creates them, before the browser's first paint.\n */\nfunction defaultRoot(): ParentNode {\n    if (typeof document === \"undefined\") return null as never;\n    return document.documentElement ?? document;\n}\n\n/**\n * Every *started* runtime in this page, so a config change can reach all of them.\n *\n * Vite's dev server reloads the page when `nibcss.config.ts` changes; webpack\n * has no equivalent, so the generated config module carries a hot hook that\n * calls `configure()` instead. It needs a handle on the runtimes, and a\n * framework provider may have created one the module never sees — React's\n * `NibProvider` constructs its own. Registering here is the only place that\n * knows about all of them.\n *\n * Exposed on `globalThis` rather than exported, because the hook is generated\n * source that must not depend on this module's identity: with two copies of the\n * package in a tree, an import would reach the wrong set.\n */\nconst liveRuntimes: Set<NibRuntime> = ((globalThis as Record<string, unknown>).__nibRuntimes ??=\n    new Set()) as Set<NibRuntime>;\n\n/**\n * A comparable fingerprint of the styling-relevant config.\n *\n * `JSON.stringify` drops `onWarn` and `supports` for us, and the key order is\n * stable because the merge keeps the base object's order for keys it already\n * had — so two configs that say the same thing produce the same string.\n */\nfunction signature(config: NibConfig): string {\n    try {\n        return JSON.stringify(config);\n    } catch {\n        // A circular value in someone's config: treat it as always different.\n        return Math.random().toString(36);\n    }\n}\n\nexport class NibRuntime {\n    readonly engine: Engine;\n    readonly darkMode: DarkModeController;\n\n    private readonly sink = new StyleSink();\n    private readonly root: ParentNode;\n    private readonly watch: boolean;\n    private userConfig: NibConfig;\n\n    /** element -> what we last applied, so we can diff on re-process. */\n    private applied = new WeakMap<Element, { attr: string; classes: string[] }>();\n\n    private observer: MutationObserver | null = null;\n    private queue = new Set<Element>();\n    /** Guards against re-entering flushNow via the class mutations it causes. */\n    private flushing = false;\n    private started = false;\n\n    private readonly gcEvery: number;\n    private readonly gcMaxRules: number;\n    private flushCount = 0;\n    /** Classes handed out by `classesFor` since the last gc — never collected (may not be in the DOM yet). */\n    private recentlyIssued = new Set<string>();\n\n    constructor(options: RuntimeOptions = {}) {\n        const { root, watch = true, nativeValidation = true, gc = true, ...config } = options;\n        this.root = root ?? defaultRoot();\n        this.watch = watch;\n        this.userConfig = config;\n\n        const gcOpts = gc === true ? {} : gc === false ? null : gc;\n        this.gcEvery = gcOpts ? (gcOpts.everyFlushes ?? 60) : Infinity;\n        this.gcMaxRules = gcOpts ? (gcOpts.maxRules ?? 4000) : Infinity;\n\n        this.engine = createEngine(this.withDefaults(config, nativeValidation));\n        this.darkMode = new DarkModeController(this.engine.config.darkMode);\n    }\n\n    private withDefaults(config: NibConfig, nativeValidation = true): NibConfig {\n        const supports =\n            config.supports ??\n            (nativeValidation && typeof CSS !== \"undefined\" && typeof CSS.supports === \"function\"\n                ? (p: string, v: string) => CSS.supports(p, v)\n                : undefined);\n        return { ...config, supports };\n    }\n\n    /**\n     * Scan once, start observing, emit `nib:ready`. Safe to call twice.\n     *\n     * Designed to be called as early as possible — including from a\n     * synchronous `<script>` in `<head>`, while `<body>` is still being\n     * parsed. The observer is installed *first* so elements the parser is\n     * about to create are styled in the same microtask checkpoint they are\n     * inserted in, i.e. before the browser paints them.\n     */\n    start(): this {\n        if (this.started || typeof document === \"undefined\") return this;\n        this.started = true;\n        // Registered here rather than in the constructor: React's StrictMode\n        // builds a runtime it then throws away, and a config hot update should\n        // not be pushed into instances that never ran.\n        liveRuntimes.add(this);\n\n        // Observe before the first scan: anything the parser appends while we\n        // are scanning is then queued rather than missed.\n        if (this.watch) this.observe();\n\n        this.sink.ensure(); // put <style id=\"nib\"> in <head> up front\n        this.scanSync(this.root);\n        this.renderSheet(); // adopt any SSR <style id=\"nib\">\n\n        // Safety net: if we booted mid-parse, re-scan once the document is\n        // complete. processElement() is idempotent, so this is nearly free and\n        // covers any node the observer could not see (e.g. document.write).\n        if (this.watch && document.readyState === \"loading\") {\n            document.addEventListener(\n                \"DOMContentLoaded\",\n                () => {\n                    this.scan(defaultRoot());\n                },\n                { once: true },\n            );\n        }\n\n        document.dispatchEvent(new CustomEvent(\"nib:ready\", { detail: this }));\n        return this;\n    }\n\n    /** Re-process every styled element under `root` (synchronously). */\n    scan(root: ParentNode = this.root): void {\n        this.scanSync(root);\n    }\n\n    private scanSync(root: ParentNode): void {\n        if (root instanceof Element && readNibAttr(root) != null) this.queue.add(root);\n        root.querySelectorAll<Element>(\"[nib],[data-nib]\").forEach((el) => this.queue.add(el));\n        this.flushNow();\n    }\n\n    /** Swap config at runtime (e.g. on `nib.config.ts` HMR). */\n    /**\n     * Apply everything queued, now.\n     *\n     * The runtime batches: elements the observer reports are processed in a\n     * microtask, which is invisible in an app and awkward in a test. A second\n     * `render()` in the same file put its markup through the observer rather\n     * than through `start()`, so an assertion on the line after it saw no\n     * classes at all — the first render in the file passed and the second did\n     * not, which reads as a NibCSS bug rather than as a batch boundary.\n     *\n     * Also useful after inserting a lot of markup by hand, when the next line\n     * measures it.\n     */\n    flush(): void {\n        if (!this.root) return;\n        this.root.querySelectorAll<Element>(\"[nib],[data-nib]\").forEach((el) => {\n            if (!this.applied.has(el)) this.queue.add(el);\n        });\n        this.flushNow();\n    }\n\n    /**\n     * Take a config handed over after the runtime already exists.\n     *\n     * Framework providers reuse the page's runtime rather than starting a\n     * second one, and used to drop the config they were given on the floor.\n     * That is invisible while the two agree — the bundler starts the runtime\n     * from the same generated module the provider imports — and wrong the\n     * moment they do not. On a server the instance lives for the whole process,\n     * so after an edit to `nibcss.config.ts` the next render still resolved the\n     * previous tokens: the HTML came back with the old brand colour while the\n     * browser had the new one, and the framework reported a hydration mismatch\n     * on text the author had not touched.\n     *\n     * Applied only when it changes something, so the common case — provider\n     * and bundler in agreement — costs one comparison and never re-processes\n     * the document.\n     */\n    adopt(next: RuntimeOptions | undefined): void {\n        if (!next) return;\n        // `root`, `watch`, `nativeValidation` and `gc` are fixed when the\n        // instance is built, so a provider passing them must not look like a\n        // config change — and must not smuggle them into `userConfig`.\n        const { root, watch, nativeValidation, gc, ...config } = next;\n        void root, void watch, void nativeValidation, void gc;\n        const merged = mergeConfig(this.userConfig, config);\n        if (signature(merged) === signature(this.userConfig)) return;\n        this.configure(config);\n    }\n\n    configure(next: NibConfig): void {\n        const oldPrefix = this.engine.config.prefix;\n        // Merged a level deep: `configure({ tokens: { color: { brand } } })`\n        // is an edit to one token, not a new palette. A spread dropped every\n        // other group and the page lost $space, $radius and the recipes built\n        // on them.\n        this.userConfig = mergeConfig(this.userConfig, next);\n        this.engine.update(this.withDefaults(this.userConfig));\n        this.darkMode.setStrategy(this.engine.config.darkMode);\n\n        this.applied = new WeakMap();\n        /**\n         * Re-resolve the document, where there is one.\n         *\n         * On a server there is not: `root` is null, and this threw\n         * \"Cannot read properties of null (reading 'querySelectorAll')\" —\n         * which the framework turned into a 500 for the request that followed\n         * a config change, so an edit to `nibcss.config.ts` was answered with\n         * an error page. Nothing is lost by skipping it: the next render builds\n         * its markup from the config this call has already installed.\n         */\n        if (this.root) {\n            this.root.querySelectorAll<Element>(\"[nib],[data-nib]\").forEach((el) => {\n                for (const c of [...el.classList]) {\n                    if (c.startsWith(oldPrefix)) el.classList.remove(c);\n                }\n                this.queue.add(el);\n            });\n            this.flushNow();\n        }\n\n        if (typeof document !== \"undefined\") {\n            document.dispatchEvent(\n                new CustomEvent(\"nib:config\", { detail: this.engine.config }),\n            );\n        }\n    }\n\n    /**\n     * Tell the page about a problem, in the form the dev overlay renders.\n     *\n     * The structured diagnostics travel alongside the sentences, so a warning\n     * raised in the browser shows the same \"opc is short for opacity — accepts\n     * 0.7, 0, .5, …\" that the build shows. They were dropped before, leaving the\n     * overlay to re-derive what it could from one long string.\n     */\n    private announce(attr: string, warnings: string[], diagnostics: unknown[]): void {\n        if (!warnings.length) return;\n        if (!this.engine.config.debug || typeof document === \"undefined\") return;\n        document.dispatchEvent(\n            new CustomEvent(\"nib:warning\", {\n                detail: { attr, messages: warnings, diagnostics },\n            }),\n        );\n    }\n\n    toggleDarkMode(): boolean {\n        return this.darkMode.toggle();\n    }\n\n    /**\n     * Generate the class names for an attribute string and make sure their CSS\n     * is in the document. Synchronous — for framework adapters that bind the\n     * class themselves (React/Vue) instead of relying on the DOM scan.\n     */\n    classesFor(attr: string): string {\n        const { classNames, warnings, diagnostics } = this.engine.process(attr);\n        this.announce(attr, warnings, diagnostics);\n        for (const c of classNames) this.recentlyIssued.add(c);\n        this.renderSheet();\n        this.maybeGc();\n        return classNames.join(\" \");\n    }\n\n    /** The current accumulated stylesheet (for SSR extraction). */\n    css(): string {\n        return this.engine.css();\n    }\n\n    /**\n     * Drop CSS rules whose class is no longer attached to any element under the\n     * root. Runs automatically; call it directly after a big teardown if needed.\n     * Returns the number of rules removed.\n     */\n    gc(): number {\n        if (typeof document === \"undefined\") return 0;\n        const prefix = this.engine.config.prefix;\n        const active = new Set<string>(this.recentlyIssued);\n        this.root.querySelectorAll<Element>(`[class*=\"${prefix}\"]`).forEach((el) => {\n            el.classList.forEach((c) => {\n                if (c.startsWith(prefix)) active.add(c);\n            });\n        });\n        this.recentlyIssued = new Set();\n        const removed = this.engine.gc(active);\n        if (removed) this.renderSheet();\n        return removed;\n    }\n\n    private maybeGc(): void {\n        this.flushCount++;\n        const overBudget = this.engine.stats().rules > this.gcMaxRules;\n        if (overBudget || this.flushCount % this.gcEvery === 0) {\n            const run = () => this.gc();\n            if (typeof requestIdleCallback === \"function\") requestIdleCallback(run);\n            else schedule(run);\n        }\n    }\n\n    destroy(): void {\n        this.observer?.disconnect();\n        this.observer = null;\n        this.darkMode.destroy();\n        this.sink.destroy();\n        this.queue.clear();\n        this.started = false;\n        liveRuntimes.delete(this);\n    }\n\n    // -- internals ----------------------------------------------------------\n\n    private observe(): void {\n        const target = this.root instanceof Node ? this.root : defaultRoot();\n        if (!(target instanceof Node)) return;\n        this.observer = new MutationObserver((mutations) => this.onMutations(mutations));\n        this.observer.observe(target, {\n            subtree: true,\n            childList: true,\n            attributes: true,\n            attributeFilter: [...ATTRS, \"class\"],\n        });\n    }\n\n    private onMutations(mutations: MutationRecord[]): void {\n        for (const m of mutations) {\n            if (m.type === \"attributes\") {\n                const el = m.target as Element;\n                if (m.attributeName === \"class\") {\n                    const prev = this.applied.get(el);\n                    // Re-render stripped our classes: re-add. Our own re-add lands\n                    // here too, but then every class is present, so it's a no-op.\n                    if (prev && !prev.classes.every((c) => el.classList.contains(c))) {\n                        this.queue.add(el);\n                    }\n                } else {\n                    this.queue.add(el);\n                }\n            } else if (m.type === \"childList\") {\n                m.addedNodes.forEach((n) => {\n                    if (n.nodeType !== 1) return;\n                    const el = n as Element;\n                    if (readNibAttr(el) != null) this.queue.add(el);\n                    el.querySelectorAll<Element>(\"[nib],[data-nib]\").forEach((d) =>\n                        this.queue.add(d),\n                    );\n                });\n            }\n        }\n        // Flush *synchronously*, inside the observer callback.\n        //\n        // MutationObserver callbacks are delivered at the microtask checkpoint\n        // at the end of the current task, and the browser's \"update the\n        // rendering\" step (style/layout/paint) runs after that checkpoint — so\n        // styling here lands before the newly inserted elements are ever\n        // painted. Deferring to requestAnimationFrame (as this used to) is at\n        // best one frame late and at worst many, which is exactly what showed\n        // up as a flash of unstyled markup on navigation and on first load.\n        this.flushNow();\n    }\n\n    private flushNow(): void {\n        if (this.queue.size === 0 || this.flushing) return;\n        this.flushing = true;\n        try {\n            // Drain: processing an element can legitimately enqueue more work\n            // (a component recipe that adds nodes, a framework re-render).\n            while (this.queue.size > 0) {\n                const batch = [...this.queue];\n                this.queue.clear();\n                for (const el of batch) this.processElement(el);\n            }\n            this.renderSheet();\n        } finally {\n            this.flushing = false;\n        }\n        this.maybeGc();\n    }\n\n    /**\n     * Push the engine's stylesheet into the <style> element, telling the sink\n     * whether it is still nothing but the preflight reset — in which case an\n     * adopted SSR stylesheet must not be overwritten with it.\n     */\n    private renderSheet(): void {\n        this.sink.render(this.engine.css(), this.engine.stats().rules === 0);\n    }\n\n    private processElement(el: Element): void {\n        const attr = readNibAttr(el);\n        const prev = this.applied.get(el);\n\n        if (attr == null) {\n            if (prev) {\n                el.classList.remove(...prev.classes);\n                this.applied.delete(el);\n            }\n            return;\n        }\n\n        const unchanged =\n            prev != null &&\n            prev.attr === attr &&\n            prev.classes.every((c) => el.classList.contains(c));\n        if (unchanged) return;\n\n        const { classNames, warnings, diagnostics } = this.engine.process(attr);\n        this.announce(attr, warnings, diagnostics);\n\n        if (prev) {\n            for (const c of prev.classes) {\n                if (!classNames.includes(c)) el.classList.remove(c);\n            }\n        }\n        const toAdd = classNames.filter((c) => !el.classList.contains(c));\n        if (toAdd.length) el.classList.add(...toAdd);\n        this.applied.set(el, { attr, classes: classNames });\n    }\n}\n","import type { NibConfig } from \"@nibcss/core\";\n\n/**\n * Discover a config for CDN usage, in priority order:\n *   1. `window.__NIB__` / `window.nibConfig`\n *   2. `<script type=\"application/json\" data-nib-config>…</script>`\n *   3. `data-nib-*` attributes on the loading `<script>` tag\n */\nexport function readConfigFromDocument(): NibConfig {\n    if (typeof window === \"undefined\") return {};\n\n    const globalCfg =\n        (window as unknown as { __NIB__?: NibConfig; nibConfig?: NibConfig }).__NIB__ ??\n        (window as unknown as { nibConfig?: NibConfig }).nibConfig;\n    if (globalCfg) return globalCfg;\n\n    if (typeof document !== \"undefined\") {\n        const jsonTag = document.querySelector<HTMLScriptElement>(\n            'script[type=\"application/json\"][data-nib-config]',\n        );\n        if (jsonTag?.textContent) {\n            try {\n                return JSON.parse(jsonTag.textContent) as NibConfig;\n            } catch {\n                console.warn(\"[nib] could not parse inline config JSON\");\n            }\n        }\n\n        const self =\n            (document.currentScript as HTMLScriptElement | null) ??\n            document.querySelector<HTMLScriptElement>(\"script[data-nib-prefix],script[data-nib-dark]\");\n        if (self) {\n            const cfg: NibConfig = {};\n            const prefix = self.dataset.nibPrefix;\n            const dark = self.dataset.nibDark;\n            if (prefix) cfg.prefix = prefix;\n            if (dark === \"media\" || dark === \"class\") cfg.darkMode = dark;\n            else if (dark === \"false\") cfg.darkMode = false;\n            if (self.dataset.nibDebug === \"true\") cfg.debug = true;\n            return cfg;\n        }\n    }\n\n    return {};\n}\n","export { NibRuntime, type RuntimeOptions } from \"./runtime.js\";\nexport { DarkModeController, DARK_STORAGE_KEY, darkModeBootScript } from \"./dark-mode.js\";\nexport { StyleSink } from \"./style-sink.js\";\nexport { readConfigFromDocument } from \"./config-source.js\";\n\nimport { NibRuntime, type RuntimeOptions } from \"./runtime.js\";\n\n/**\n * The shared runtime, kept on `globalThis` rather than in this module.\n *\n * A bundle can end up with two copies of this package — the bundler's\n * auto-start module reaching it one way and a framework provider another, ESM\n * beside CJS — and a module-level variable then gives each copy its own\n * \"shared\" instance. That is how a page with one provider still ended up\n * running two runtimes, each observing the same DOM.\n */\nconst store = globalThis as { __nibSharedRuntime?: NibRuntime | null };\n\n/**\n * Create (once) and start the shared runtime. Subsequent calls return the same\n * instance; pass config only on the first call, or use `runtime.configure(...)`.\n */\nexport function init(options: RuntimeOptions = {}): NibRuntime {\n    if (!store.__nibSharedRuntime) {\n        const rt = new NibRuntime(options);\n        store.__nibSharedRuntime = rt;\n        rt.start();\n    }\n    return store.__nibSharedRuntime;\n}\n\n/**\n * Adopt `rt` as the shared runtime, if there is not one already.\n *\n * `init()` starts what it creates, which a framework provider cannot allow:\n * starting during render mutates the DOM React is about to hydrate against.\n * This registers without starting, so the provider can start it from an effect\n * and still be the one runtime everything else finds.\n */\nexport function shareRuntime(rt: NibRuntime): NibRuntime {\n    store.__nibSharedRuntime ??= rt;\n    return store.__nibSharedRuntime;\n}\n\n/**\n * Destroy the shared runtime and forget it.\n *\n * For tests and teardown: the instance lives on `globalThis`, so without this\n * one test's runtime — and its prefix, tokens and stylesheet — is still there\n * for the next.\n */\nexport function resetRuntime(): void {\n    store.__nibSharedRuntime?.destroy();\n    store.__nibSharedRuntime = null;\n}\n\n/** The shared runtime, if `init()` has run. */\nexport function getRuntime(): NibRuntime | null {\n    return store.__nibSharedRuntime ?? null;\n}\n"]}