modifiers.ts

Declarative modifier definitions for CSS-literal syntax.

Modifiers enable responsive, state-based, and contextual styling: - Media modifiers: md:, print:, motion-safe: - Ancestor modifiers: dark:, light: - State modifiers: hover:, focus:, disabled: - Pseudo-element modifiers: before:, after:

@see {@link https://github.com/fuzdev/fuz_css} for documentation

Declarations
#

17 declarations

view source

ALL_MODIFIER_NAMES
#

ANCESTOR_MODIFIERS
#

extract_balanced_parens
#

modifiers.ts view source

(segment: string, prefix: string): string | null

Extracts content from balanced parentheses after a prefix. Supports nested parens for calc(), clamp(), min(), max(), etc.

segment

the full segment to parse (e.g., "min-width(calc(100vw - 200px))")

type string

prefix

the prefix before the opening paren (e.g., "min-width")

type string

returns

string | null

the content inside the balanced parens, or null if no match/unbalanced

examples

extract_balanced_parens("min-width(800px)", "min-width") // "800px" extract_balanced_parens("min-width(calc(100vw - 20px))", "min-width") // "calc(100vw - 20px)" extract_balanced_parens("min-width(calc(100vw)", "min-width") // null (unbalanced)

get_all_modifier_names
#

get_modifier
#

modifiers.ts view source

(segment: string): (ModifierDefinition & { is_arbitrary?: boolean | undefined; }) | null

Gets the modifier definition for a segment. Handles both static modifiers and dynamic patterns (arbitrary breakpoints, parameterized states).

segment

type string

returns

(ModifierDefinition & { is_arbitrary?: boolean | undefined; }) | null

the modifier definition or null if not a known modifier

MEDIA_MODIFIERS
#

ModifierDefinition
#

modifiers.ts view source

ModifierDefinition

Definition for a single modifier.

name

The prefix used in class names (e.g., 'hover', 'md', 'dark')

type string

type

Type determines position in modifier order and CSS output behavior

css

The CSS output - wrapper for media/ancestor, suffix for state/pseudo-element

type string

order

Optional ordering within type (for breakpoints, sorted by this value)

type number

MODIFIERS
#

modifiers.ts view source

ModifierDefinition[]

All modifier definitions in a single declarative structure. Adding a new modifier requires only adding to this array.

ModifierType
#

modifiers.ts view source

ModifierType

Type of modifier determining its position in the class name and CSS output.

Order in class names: [media:][ancestor:][state...:][pseudo-element:]property:value

NTH_CHILD_PATTERN
#

NTH_LAST_CHILD_PATTERN
#

NTH_LAST_OF_TYPE_PATTERN
#

NTH_OF_TYPE_PATTERN
#

parse_arbitrary_breakpoint
#

modifiers.ts view source

(segment: string): string | null

Parses an arbitrary breakpoint modifier. Supports nested parentheses for calc(), clamp(), min(), max(), var(). Requires value to start with a digit or known CSS function to catch obvious mistakes.

segment

type string

returns

string | null

the CSS media query or null if not an arbitrary breakpoint

examples

parse_arbitrary_breakpoint("min-width(800px)") // "@media (width >= 800px)" parse_arbitrary_breakpoint("min-width(calc(100vw - 200px))") // "@media (width >= calc(100vw - 200px))" parse_arbitrary_breakpoint("min-width(px)") // null (invalid - no digit or function)

parse_parameterized_state
#

modifiers.ts view source

(segment: string): { name: string; css: string; type: "state"; } | null

Parses a parameterized state modifier (nth-child, nth-last-child, nth-of-type, nth-last-of-type).

segment

type string

returns

{ name: string; css: string; type: "state"; } | null

object with name (including parameter) and CSS, or null if not parameterized

PSEUDO_ELEMENT_MODIFIERS
#

STATE_MODIFIERS
#

Imported by
#