/** * Browser helpers for referencing CSS files from shadow roots via Vite's * `?url` imports. * * A `?url` import yields a real stylesheet URL — the dev server serves the * file as CSS, and `vite build` emits it as a hashed `.css` asset. That * makes it the right base for `` hrefs and `@import url()`s inside * shadow roots. The one gap is dev HMR: the imported URL string is identical * across module re-executions, so the browser would keep the stale * stylesheet. These helpers close that gap. * * This module imports nothing outside the package's runtime and must stay * safe to load in any environment, a server render included (see * `new-sheet.ts`). * * @module */ /** * Appends a cache-busting query to a `?url`-imported CSS file URL in dev. * * Call this at *module scope* (not in `render()`, where every render would * refetch): each HMR re-execution then yields a fresh href and the browser * refetches the changed stylesheet. * * In production builds the URL is a content-hashed asset, so the input is * returned unchanged. * * @example * ```ts * import cssUrl from './my-element.css?url'; * import {devCacheBust} from '@oddsquad/vite-plugin-lit/css.js'; * * const href = devCacheBust(cssUrl); // module scope * html``; * ``` */ export declare const devCacheBust: (url: string) => string; /** * A shared `CSSStyleSheet` built from CSS text, plus the callback to hot-swap * it in place. What a `?css-sheet` import compiles to in dev and in an * inlined build, over Vite's `?inline` (or `?raw`) text. * * Any `@property` rules in the text are also registered on the document, * where shadow roots can see them. */ export declare const inlineSheet: (css: string) => UrlSheet; /** * A shared `CSSStyleSheet` backed by a `?url` CSS asset, plus the callback to * hot-swap it in place. Returned by {@link urlSheet}. */ export interface UrlSheet { /** * The constructed stylesheet. Adopt it from any number of components * (`static styles = [sheet]`); an edit to the source CSS re-fetches and * `replaceSync()`s it, updating every shadow root that adopted it without * re-rendering a component or reloading the page. * * It is empty until the first fetch resolves, so expect a brief flash of * unstyled content on initial load — the cost of keeping the CSS as a real * asset rather than inlining it into the JS bundle. */ sheet: CSSStyleSheet; /** * Vite HMR accept callback for the `?url` dependency. Wire it up with the * *same literal specifier* you imported — Vite resolves accepted deps by * static analysis, so the string has to appear in your module: * * ```ts * import.meta.hot?.accept('./utils.css?url', onHotUpdate); * ``` * * Typed to match Vite's accept callback (`ModuleNamespace | undefined`) so * it drops straight in; the new module's `default` export is the updated * `?url` string. */ onHotUpdate: (mod: Record | undefined) => void; } /** * Builds a {@link UrlSheet} from a `?url`-imported CSS asset: a single * constructed `CSSStyleSheet`, shareable across shadow roots via * `adoptedStyleSheets`, that hot-swaps in place on edits — no component * re-render, no full-page reload. * * `?url` keeps the stylesheet as a standalone, pipeline-processed `.css` file * in the build output (unlike `?inline`/`?raw`, which inline it into the JS * chunk). The file is read into the sheet at runtime via `fetch()`, with the * dev/build path difference handled internally. * * @example * ```ts * import {urlSheet} from '@oddsquad/vite-plugin-lit/css.js'; * import sheetUrl from './utils.css?url'; * * const {sheet, onHotUpdate} = urlSheet(sheetUrl); * export default sheet; // `static styles = [sheet]` in components * * import.meta.hot?.accept('./utils.css?url', onHotUpdate); * ``` */ export declare const urlSheet: (url: string) => UrlSheet; //# sourceMappingURL=css.d.ts.map