package tw
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=c6f2f55bdbafd557e7716e4ab2daa012beb2ab2548090fae4a6e53c8016a3b10
sha512=13c066b3b233227d620a28abb724c8aea13c08f8f4b4657f7462d5806aa227568b921523e2675f3cd8ec8597fbe23a0f512e98f143adcf49b64a80ac95e6b740
doc/tw/Tw/Scheme/index.html
Module Tw.SchemeSource
Theme scheme configuration for customizing CSS output.
A scheme defines theme overrides that affect how utilities generate CSS. This allows matching Tailwind's test expectations which use custom @theme definitions with hex colors and explicit spacing variables.
Color value - either hex string or oklch components
A \@custom-variant registered with a value map (the DEFAULT value under key "") and a selector template with {} where the value is substituted. & in the template denotes the element's own class.
One rule of a variant's block body: the element's selector, where & (Css.Selector.t.Nesting) stands for the element, inside \@media media when media is Some. The branch { media = Some m; selector = s } is the body \@media m { s { \@slot; } } of a Tailwind \@custom-variant.
type t = {colors : (string * color_value) list;(*Color overrides. Key is color name like "red-500". When a color is Hex, opacity modifiers use hex+alpha fallback. When Oklch, opacity modifiers use color-mix fallback.
*)spacing : (int * Cascade.Css.length) list;(*Explicit spacing variables. Key is the multiplier (e.g., 4 for --spacing-4). When defined, utilities use var(--spacing-N) instead of calc(var(--spacing) * N).
*)radius : (string * Cascade.Css.length) list;(*Explicit radius variables. Key is the radius name (e.g., "none", "full", "sm"). When defined, utilities use var(--radius-NAME) instead of raw values.
*)default_ring_width : int;(*Default ring width in pixels for bare
*)ringutility. Corresponds to Tailwind's@theme \{ --default-ring-width: Npx \}. Default: 1.default_border_width : int;(*Default border width in pixels for bare
*)borderutility. Corresponds to Tailwind's@theme \{ --default-border-width: Npx \}. Default: 1.default_outline_width : int;(*Default outline width in pixels for bare
*)outlineutility. Corresponds to Tailwind's@theme \{ --default-outline-width: Npx \}. Default: 1.breakpoints : (string * float) list;(*Explicit breakpoint values in px. Key is breakpoint name (e.g., "sm"). When defined, responsive media queries use
*)@media (min-width: Xpx)instead of rem-based values.token_overrides : (string * string) list;(*Per-render theme token overrides (from a
*)@themeblock). Key is the variable name without the leading--; value is the CSS string. Threaded replacement for the globalVar.theme_value_overrides.inline_tokens : string list;(*Names of the tokens a project declared in an
*)\@theme inlineblock. Such a token has no declaration of its own: a utility reading it inlines the value instead of referencingvar(--name).reference_tokens : string list;(*Names of the tokens a project declared in an
*)\@theme referenceblock. The block declares the token elsewhere, so the theme layer emits no declaration for it and a reader spells the value as the fallback of its own reference.reference_theme : bool;(*Whether the stylesheet only references the package, with
*)\@reference "tailwindcss", rather than importing it. Every token but the ones the stylesheet's own\@themedeclares is then a reference token.static_tokens : string list;(*Names of the tokens a project declared in an
*)\@theme staticblock. The theme layer declares each of them whether or not a utility reads it, with the value the block gave it.static_theme : bool;(*Whether the package was imported with
*)theme(static), which emits every theme variable rather than only the ones a utility used.important : bool;(*Whether the package was imported with
*)important, which marks every declaration a utility emits!important, dressed in variants or not. The author's own CSS, and what an\@applypulls into it, are not utilities and keep their declarations as written.prefix : string option;(*The prefix
*)prefix(tw)on the import asks for. Every candidate is then spelledtw:p-4, and every theme token is declared and read as--tw-spacing. The--tw-*variables a utility sets for itself are not theme tokens and keep their names, whatever the prefix is.custom_variants : (string * custom_variant) list;(*The
*)\@custom-variants this\@themedeclared, each a value map and a selector template. A variant belongs to the theme that declared it, so two stylesheets built in one process cannot see each other's.container_variants : (string * Cascade.Css.Container.t) list;(*The
*)\@custom-variants this\@themedeclared with a container-query body (e.g.has-a->\@container style(--a)). Kept apart fromcustom_variantsbecause the condition is structural, so thenot-prefix negates it soundly.dark : variant_branch list option;(*The body of the
darkvariant when the project redeclares it, as Tailwind's\@custom-variant dark { ... }does:Tw.darkand thedark:prefix then write one rule per branch, in order, each under the classdark:names.None, the default, is the built-in\@media (prefers-color-scheme: dark).A dark theme that follows the reader's choice as well as the system one is two branches: the media query with a selector that a
*)data-theme=lightroot turns off, and a selector fordata-theme=dark.
}Theme scheme configuration
default is the default scheme using oklch colors and calc-based spacing (matches Tailwind v4 default).
or_default theme is the scheme an optionally-threaded theme names: itself, or default when none was threaded.
register_default_token name css registers the v4.3.1 baseline default CSS for theme token name (without --). It updates a lock-free immutable snapshot and is called once at module initialisation by the utility that owns the token.
all_default_tokens () is every token a family has published through register_default_token. theme(static) emits them all.
token_default name returns the registered baseline default for name.
is_removed t name is whether the \@theme block removed name. Tailwind reads --name: initial as "remove this token", --namespace-*: initial as "remove the whole namespace" and the bare --*: initial as "remove every token", and a candidate that needed the token stops resolving. A token the block declares in its own right survives a reset, and so does a nested scale that merely shares the prefix: --font-*: initial leaves --font-weight-* alone.
token_override t name returns the per-render override for name, if any. A removed token has none.
theme_value theme name looks up a per-render token override from the optionally-threaded theme (None when no theme is threaded). Threaded replacement for the global Var.theme_value.
token t name resolves a theme token: override (if any) else default, or nothing at all when the \@theme block removed it.
removes_tokens t is whether the \@theme block took any token away, so a candidate has to be held against is_removed_token at all.
is_removed_token t name is is_removed narrowed to a name that was a theme token to begin with: a registered default or one the block declared. A --tw-* channel is neither, so the bare --*: initial leaves it be.
val with_overrides :
?inline:string list ->
?reference:string list ->
?static:string list ->
t ->
(string * string) list ->
twith_overrides ?inline ?reference ?static t overrides applies overrides on top of t's existing token overrides (new entries win). inline names the tokens that came from an \@theme inline block, reference those from an \@theme reference one, and static those from an \@theme static one.
is_inline_token t name is whether name was declared in an \@theme inline block, so a utility reading it inlines the value rather than referencing var(--name).
is_reference_token t name is whether name was declared in an \@theme reference block, so nothing declares it in the generated sheet and a reader carries the value as its own var() fallback.
is_static_token t name is whether name was declared in an \@theme static block, so the theme layer declares it whether or not a utility reads it.
color t name looks up a color in the scheme.
declares_color theme name is whether theme binds --color-<name>, through color or a token override.
spacing t n looks up a spacing value in the scheme.
is_hex_color t name checks if a color is defined as hex in the scheme.
hex_color t name returns the hex value for a color if defined as hex.
has_explicit_spacing t n checks if spacing has an explicit variable.
radius t name looks up a radius value in the scheme.
has_explicit_radius t name checks if radius has an explicit variable.
breakpoint t name looks up a breakpoint px value in the scheme.
breakpoint_length t name looks up a breakpoint as its exact CSS length. A breakpoint-NAME token override takes precedence over the legacy px-only breakpoint field.
all_breakpoints t is every breakpoint t defines, keyed by name and sorted by name: the registered defaults, the --breakpoint-* tokens a \@theme block set, and the legacy px-only breakpoints field. A breakpoint the block removed is left out.
has_breakpoint t name is whether t still defines the breakpoint name, reading the same set as all_breakpoints. A breakpoint the \@theme block removed is gone for the variants that name it.