css_placeholder_splice.ts

The build-mode placeholder that vite_plugin_fuz_css emits for virtual:fuz.css, and the splice that replaces it with the generated CSS.

Normally the placeholder never reaches the output: once every module is transformed, the build restates the virtual module's text with the generated CSS through Vite's CSS pipeline (vite_plugin_fuz_css_build.ts). The splice is the fallback for when that restatement can't run, writing the CSS into the bundled stylesheet at the placeholder's position.

view source

Declarations
#

4 declarations

FUZ_CSS_PLACEHOLDER
#

css_placeholder_splice.ts view source

"--fuz-css-placeholder" import {FUZ_CSS_PLACEHOLDER} from '@fuzdev/fuz_css/css_placeholder_splice.js';

Marker custom property emitted by the build-mode virtual module. Unlike a CSS comment (stripped by minification) this survives into the output, so generateBundle can locate both the asset where Vite placed the virtual module's CSS - the importer's globally-loaded stylesheet, not an arbitrary code-split chunk - and the offset within it that import order put it at.

FUZ_CSS_PLACEHOLDER_RULE
#

css_placeholder_splice.ts view source

":root{--fuz-css-placeholder:1}" import {FUZ_CSS_PLACEHOLDER_RULE} from '@fuzdev/fuz_css/css_placeholder_splice.js';

The rule the build-mode virtual module loads as, before the generated CSS is known.

splice_css_at_placeholder
#

css_placeholder_splice.ts view source

(source: string, generated_css: string): string | null import {splice_css_at_placeholder} from '@fuzdev/fuz_css/css_placeholder_splice.js';

Replaces the first placeholder in a bundled stylesheet with the generated CSS, at the offset the marker occupies.

Position is the point: the marker sits where Vite placed virtual:fuz.css in the importer's stylesheet, so writing the generated CSS there reproduces the import order the source asked for. Appending to the end of the asset instead would silently move fuz_css's :root after every stylesheet bundled alongside it, so an app's own equal-specificity token override would win in dev (where the virtual module is served in place) and lose in the production bundle.

Usually the marker is its own rule, but a minifier that merges adjacent rules with identical selectors (lightningcss is one; esbuild, Vite's default, isn't) folds neighboring :root declarations into the marker's block - from either or both sides. Declaration order preserves the merged rules' order, so splitting the block at the marker keeps the cascade exact: declarations before it came from stylesheets bundled before virtual:fuz.css and stay before the generated CSS, declarations after it stay after. The solo-rule case is the same split with both sides empty.

The marker's rule starts after whatever ends the preceding construct: a rule's }, a statement at-rule's ; (@charset, @import, which a bundler hoists ahead of the first rule), or an enclosing block's {. Comments, strings, and unquoted url()s are read past, since one can hold any of those - an unminified build or a preserved /*! *\/ comment leaves them in, and a content string or a URL can hold a /* of its own.

source

the bundled stylesheet holding the marker

type string

generated_css

the CSS to write at the marker's position

type string

returns

string | null

source with the generated CSS spliced in and the marker stripped, or null if no marker sits inside a well-formed rule

splice_css_into_asset
#

css_placeholder_splice.ts view source

(source: string, generated_css: string): string | null import {splice_css_into_asset} from '@fuzdev/fuz_css/css_placeholder_splice.js';

Finishes one bundled stylesheet: writes the generated CSS at its first placeholder and strips any others. Two entries' CSS merged into one asset, or a pipeline that copied the placeholder rule, leave more than one; the generated CSS belongs at the first.

source

the bundled stylesheet

type string

generated_css

the CSS to write at the first placeholder

type string

returns

string | null

the finished stylesheet, or null when it holds no placeholder

Imported by
#