;
} & SubComponentKeys;
interface TwSubComponent {
(props: P): React.ReactElement | null;
displayName?: string;
}
interface TwTemplateFactory {
(config: C & {
defaultVariants?: InferDefaultVariantsType;
}): TwStyledComponent, InferSubTagsFromConfig extends Record ? InferSubTagsFromConfig : Record, Tag, InferSubVariantsFromConfig extends Record> ? InferSubVariantsFromConfig : Record>;
(strings: readonly [T], ...exprs: []): TwStyledComponent, Record, Tag>;
(strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent, Tag>;
}
type TwTagFactory = {
[K in HtmlTagName]: TwTemplateFactory;
};
type TwTagFactoryAny = {
[key: string]: TwTemplateFactory;
};
type TwComponentFactory = (tag: T) => TwTemplateFactory;
type TwServerObject = TwTagFactory & {
[K in HtmlTagName as `${K}`]: TwTemplateFactory;
};
type TwObject = TwComponentFactory & TwTagFactory & {
server: TwServerObject;
};
/**
* tailwind-styled-v4 v2 — tw
*
* API:
* tw.div`p-4 bg-zinc-900`
* tw.button`px-4 [icon] { h-4 w-4 }` ← sub-components inline
* tw.button({ base: "px-4", variants: { size: { sm: "text-sm" } } })
* tw(Link)`underline text-blue-400`
* tw.server.div`p-4` ← server-only, compiler enforced + runtime dev warning
*/
declare const server: TwServerObject;
declare const tw: TwObject;
/**
* tailwind-styled-v4 — cv()
*
* Runtime: native-first with fallback to generated variant tables.
*
* Dua mode:
* 1. GENERATED (optimal) — import dari variants.generated.ts hasil `npx tw compile-variants`
* → O(1) lookup, static, zero runtime computation
* 2. RUNTIME (fallback) — compute on-the-fly via native binding
* → Requires native Rust binding for variant resolution
*/
/**
* Register pre-computed variant table dari generated file.
* Dipanggil otomatis saat import variants.generated.ts
*/
declare function registerVariantTable(componentId: string, table: Record): void;
declare function cv(config: C, componentId?: string): CvFn;
/**
* tailwind-styled-v4 v2 — cx / cn
*
* Native Rust binding dipakai di Node.js/SSR untuk performa maksimal.
*
* Browser fallback (Bug 2 — "Native binding 'resolveClassNames' is required
* but not available." crash di browser):
*
* getNativeBinding() return `null` di browser (bukan throw). Ketika itu terjadi
* kita gunakan pure-TS fallback yang semantiknya identik dengan implementasi Rust:
* - cn(): filter falsy + join spasi (identik dengan resolve_class_names di Rust)
* - cx(): conflict-aware merge via twMergeRawJs (port dari tw_merge.rs)
* - cxn(): flatten nested array + filter falsy + join spasi
*
* Server path TIDAK DIUBAH: throw Error tetap dijalankan jika native null di
* Node.js (menandakan miskonfigurasi). Fallback hanya aktif saat isBrowser=true.
*/
type ClassValue = string | undefined | null | false | 0;
/**
* cn — simple class name joiner (no conflict resolution).
* Node.js: delegates ke Rust `resolve_class_names`.
* Browser: pure-TS fallback — filter falsy + join spasi.
*
* @example cn("p-4", isActive && "opacity-100") → "p-4 opacity-100"
*/
declare function cn(...inputs: (ClassValue | ClassValue[])[]): string;
/**
* cx — conflict-aware class merger.
* Node.js: delegates ke Rust `tw_merge_many`.
* Browser: pure-TS fallback via twMergeRawJs (port algoritma Rust).
*
* @example cx("p-4 p-8") → "p-8"
* @example cx("bg-red-500", "bg-blue-500") → "bg-blue-500"
* @example cx(["flex", "items-center"], "px-4") → "flex items-center px-4"
*/
declare function cx(...inputs: (ClassValue | ClassValue[])[]): string;
/** @deprecated Use cx() instead. */
declare const cxm: typeof cx;
declare function createComponent(tag: React.ElementType, config: TConfig | string): TwStyledComponent>;
interface ThemeConfig$1 {
colors: Record;
spacing: Record;
fonts: Record;
breakpoints: Record;
animations: Record;
raw: Record;
}
/**
* tailwind-styled-v4 — createTwMerge()
*
* Native Rust binding (twMergeRaw) is used when available (Node.js, build
* time, SSR) for maximum performance/parity with the rest of the pipeline.
*
* Browser fallback (Bug C — "Uncaught Error: Native binding 'twMergeRaw' is
* required but not available." crashing in the browser):
*
* createComponent.ts calls twMerge() unconditionally inside the React render
* function for EVERY tw.* component, on EVERY render — including the very
* first client-side render of any component that runs/re-renders in the
* browser. A `.node` native addon can never load inside a browser JS engine,
* so this isn't a rare edge case, it's unconditional: any tw.* component
* rendering client-side needs a working fallback path.
*
* getNativeBinding() returns `null` (not a throw) when running in the
* browser — see native.ts. When that happens we use mergeFallback.ts, a
* hand-written pure-TS port of the SAME algorithm as `tw_merge_raw` in
* tw_merge.rs (conflict_group / split_variants / merge_class_string),
* instead of the third-party `tailwind-merge` package. This keeps merge
* behavior defined by one algorithm — ours — rather than risking the
* browser and the server silently disagreeing on merged className output
* because two different implementations drifted apart. The cost: when
* tw_merge.rs's conflict_group() changes, mergeFallback.ts must be updated
* by hand to match (see comments there).
*/
interface MergeOptions {
/**
* NOTE: not currently applied — matches the native path, which calls
* `native.twMergeRaw(inputs)` without ever forwarding a prefix either.
* Kept on the type for API stability; wire it through conflictGroup()
* in mergeFallback.ts (and tw_merge_raw on the Rust side) together if a
* custom Tailwind prefix needs to be supported correctly end-to-end.
*/
prefix?: string;
separator?: string;
theme?: ThemeConfig$1;
}
declare function createTwMerge(options?: MergeOptions): (...classLists: Array) => string;
declare const twMerge: (...classLists: Array) => string;
declare function mergeWithRules(rules: Record string>, ...classLists: string[]): string;
/**
* tailwind-styled-v4 — Reactive State Engine
*
* Zero-JS CSS state management via data attributes.
* No React re-render needed for style changes.
*
* How it works:
* 1. tw.button({ state: { active: "bg-blue-500", loading: "opacity-70" } })
* 2. State engine generates a unique class + injects CSS:
* .tw-s-abc123[data-active="true"] { @apply bg-blue-500; }
* .tw-s-abc123[data-loading="true"] { @apply opacity-70; }
* 3. Component renders with the state class
* 4. User sets data-active="true" directly — no state needed
*
* Devtools integration:
* All components register to __TW_STATE_REGISTRY__ for devtools inspection.
*/
interface StateComponentEntry {
id: string;
tag: string;
states: string[];
cssInjected: boolean;
}
declare const stateRegistry: Map;
declare global {
interface Window {
__TW_STATE_REGISTRY__?: typeof stateRegistry;
}
}
interface StateEngineResult {
/** CSS class to add to the component */
stateClass: string;
/** Whether this component uses state (for SSR data attributes) */
hasState: true;
/** List of state names (for devtools) */
stateNames: string[];
}
/**
* Process a StateConfig for a component.
* Returns the state class and injects CSS (client-side only).
*
* @param tag HTML tag name
* @param state State config object
* @param precomputedHash Optional pre-computed hash dari `inject_state_hash()` Rust transform.
* Kalau ada, skip runtime `hashState()` sepenuhnya → zero hashing overhead.
*/
declare function processState(tag: string, state: StateConfig, precomputedHash?: string): StateEngineResult;
/**
* Generate SSR-safe CSS string for a state config.
* Used by SSR to inject styles into .
*/
declare function generateStateCss(tag: string, state: StateConfig): string;
/**
* Get the state registry (for devtools).
*/
declare function getStateRegistry(): Map;
/**
* tailwind-styled-v4 — Container Query Engine
*
* Generates @container rules from a simple breakpoint config.
*
* Usage:
* const Card = tw.div({
* base: "p-4",
* container: {
* sm: "flex-col", // @container (min-width: 320px)
* md: "flex-row", // @container (min-width: 640px)
* lg: "grid-cols-3", // @container (min-width: 1024px)
* },
* containerName: "card",
* })
*
* // Wrap with container context:
* const CardWrapper = tw.div`@container`
*
* Named containers:
* const SidebarCard = tw.div({
* base: "p-2",
* container: { lg: "text-sm" },
* containerName: "sidebar",
* })
* // Generates: @container sidebar (min-width: 1024px) { ... }
*/
interface ContainerEntry {
id: string;
tag: string;
containerName?: string;
breakpoints: Array<{
minWidth: string;
classes: string;
}>;
cssInjected: boolean;
}
declare const containerRegistry: Map;
declare global {
interface Window {
__TW_CONTAINER_REGISTRY__?: typeof containerRegistry;
}
}
interface ContainerQueryResult {
containerClass: string;
hasContainer: true;
}
declare function processContainer(tag: string, container: ContainerConfig, containerName?: string): ContainerQueryResult;
/**
* Generate @container CSS rules dari breakpoint config.
*
* Native-only: Rust string building tanpa intermediate allocations.
*/
declare function generateContainerCss(tag: string, container: ContainerConfig, containerName?: string): string;
declare function getContainerRegistry(): Map;
/**
* tailwind-styled-v4 — createStyledSystem()
*
* Design System Factory — Mode 3 API.
*
* Level 1 — utility: tw.div`p-4`
* Level 2 — styled: tw(Button)`px-4`
* Level 3 — design system: ui.button({ variant: "primary" })
*
* Usage:
* const ui = createStyledSystem({
* tokens: {
* colors: { primary: "#6366f1", muted: "#71717a" },
* radius: { base: "0.5rem", full: "9999px" },
* },
* components: {
* button: {
* base: "inline-flex items-center font-medium transition-colors",
* variants: {
* variant: {
* primary: "bg-[var(--sys-color-primary)] text-white",
* ghost: "bg-transparent border border-current",
* danger: "bg-red-500 text-white",
* },
* size: {
* sm: "h-8 px-3 text-sm",
* md: "h-10 px-4 text-base",
* lg: "h-12 px-6 text-lg",
* },
* },
* defaultVariants: { variant: "primary", size: "md" },
* },
* },
* })
*
* const Button = ui.button()
* // →
*
* // Token access
* ui.token("colors.primary") // → "var(--sys-color-primary)"
* ui.cssVar("colors.primary") // → "#6366f1"
*/
type SystemTokenMap = Record>;
interface SystemComponentConfig extends ComponentConfig {
/** Extra class applied only when used from the system (e.g. system-level resets) */
systemBase?: string;
/** HTML tag for the component */
tag?: string;
}
interface StyledSystemConfig = Record> {
/** Design tokens — injected as CSS custom properties under --sys-{group}-{name} */
tokens?: T;
/** Component presets */
components?: C;
/** CSS variable prefix. Default: "sys" → --sys-color-primary */
prefix?: string;
/** If true, auto-inject token CSS vars into :root on init. Default: true */
injectTokens?: boolean;
}
type SystemComponentFactory = (overrides?: Partial) => TwStyledComponent;
type StyledSystemInstance> = {
[K in keyof C]: SystemComponentFactory;
} & {
/**
* Get the CSS variable reference for a token.
* @example ui.token("colors.primary") → "var(--sys-colors-primary)"
*/
token(path: string): string;
/**
* Get the raw value of a token.
* @example ui.rawToken("colors.primary") → "#6366f1"
*/
rawToken(path: string): string | undefined;
/**
* Update token values at runtime (re-injects into :root).
*/
setTokens(updates: Partial<{
[G in keyof T]: Partial;
}>): void;
/**
* Access the resolved component config for a registered component.
*/
getConfig(name: keyof C): ComponentConfig | undefined;
/**
* The tokens object (for reference).
*/
tokens: T;
};
declare function createStyledSystem = Record>(config: StyledSystemConfig): StyledSystemInstance;
interface StyledOptions {
base?: string;
variants?: Record>;
defaultVariants?: Record;
compoundVariants?: Array<{
variants: Record;
className: string;
}>;
}
type StyledProps = {
className?: string;
} & Record;
declare function resolveStyledClassName(options: StyledOptions, props?: StyledProps): string;
declare function styled(options: StyledOptions): (props?: StyledProps) => string;
/**
* tailwind-styled-v4 v2 — twTheme
*
* UPGRADE #1: Tailwind v4 CSS Variables integration.
*
* Tailwind v4 uses @theme inline to expose design tokens as CSS custom properties:
* @theme inline {
* --color-background: var(--background);
* --color-foreground: var(--foreground);
* --font-sans: var(--font-geist-sans);
* }
*
* This module bridges tw() syntax with those CSS variables — zero config,
* full IDE support, type-safe design tokens.
*
* @example
* // Without twTheme (verbose, error-prone)
* const Box = tw.div`bg-[var(--color-background)] text-[var(--color-foreground)]`
*
* // With twTheme (clean, type-safe)
* const Box = tw.div`${t.bg("color-background")} ${t.text("color-foreground")}`
*
* // Or with createTheme for full project-level token map
* const theme = createTheme({
* colors: { bg: "color-background", fg: "color-foreground", primary: "color-primary" },
* fonts: { sans: "font-sans", mono: "font-mono" },
* })
* const Box = tw.div`bg-${theme.colors.bg} text-${theme.colors.fg}`
*/
/**
* Reference a CSS custom property in Tailwind v4 arbitrary value syntax.
*
* @example
* cssVar("color-background") → "var(--color-background)"
* cssVar("color-primary", "#3b82f6") → "var(--color-primary, #3b82f6)"
*/
declare function cssVar(varName: string, fallback?: string): string;
/**
* Generate a Tailwind v4 arbitrary value that references a CSS variable.
*
* @example
* twVar("bg", "color-background") → "bg-[var(--color-background)]"
* twVar("text", "color-foreground") → "text-[var(--color-foreground)]"
* twVar("border", "color-border", "#e5e7eb") → "border-[var(--color-border,#e5e7eb)]"
*/
declare function twVar(property: string, varName: string, fallback?: string): string;
declare const t: {
/** Background color from CSS variable: t.bg("color-primary") → "bg-[var(--color-primary)]" */
bg: (v: string, fb?: string) => string;
/** Text color from CSS variable */
text: (v: string, fb?: string) => string;
/** Border color from CSS variable */
border: (v: string, fb?: string) => string;
/** Ring color from CSS variable */
ring: (v: string, fb?: string) => string;
/** Outline color from CSS variable */
outline: (v: string, fb?: string) => string;
/** Fill color from CSS variable (SVG) */
fill: (v: string, fb?: string) => string;
/** Stroke color from CSS variable (SVG) */
stroke: (v: string, fb?: string) => string;
/** Font family from CSS variable */
font: (v: string, fb?: string) => string;
/** Shadow from CSS variable */
shadow: (v: string, fb?: string) => string;
/** Any arbitrary property from CSS variable */
var: (property: string, v: string, fb?: string) => string;
};
interface ThemeTokenMap {
colors?: Record;
fonts?: Record;
spacing?: Record;
[key: string]: Record | undefined;
}
type ResolvedThemeTokens = {
[Group in keyof T]: T[Group] extends Record ? {
[Token in keyof T[Group]]: string;
} : never;
};
/**
* Create a typed theme token map from your CSS variable names.
* Returns helper functions that generate Tailwind v4 arbitrary values.
*
* @example
* // Define your tokens (match your globals.css @theme block)
* const theme = createTheme({
* colors: {
* bg: "color-background",
* fg: "color-foreground",
* primary: "color-primary",
* muted: "color-muted",
* },
* fonts: {
* sans: "font-sans",
* mono: "font-mono",
* },
* })
*
* // Use in tw components
* const Card = tw.div`
* bg-${theme.colors.bg}
* text-${theme.colors.fg}
* font-${theme.fonts.sans}
* `
* // → tw.div`bg-[var(--color-background)] text-[var(--color-foreground)] font-[var(--font-sans)]`
*
* // Use in cv()
* const button = cv({
* base: `px-4 py-2 ${theme.colors.bg} ${theme.colors.fg}`,
* variants: { ... }
* })
*/
declare function createTheme(tokenMap: T): ResolvedThemeTokens;
/**
* Pre-built references for standard Tailwind v4 CSS variable tokens.
* Works out of the box with next-app-standar-config globals.css.
*
* @example
* import { v4Tokens } from "tailwind-styled-v4"
*
* const Page = tw.div`${v4Tokens.bg} ${v4Tokens.text}`
* // → tw.div`bg-[var(--color-background)] text-[var(--color-foreground)]`
*/
declare const v4Tokens: {
/** bg-[var(--color-background)] */
readonly bg: string;
/** text-[var(--color-foreground)] */
readonly text: string;
/** font-[var(--font-sans)] */
readonly fontSans: string;
/** font-[var(--font-mono)] */
readonly fontMono: string;
};
interface SubComponentProps {
children?: React.ReactNode;
className?: string;
}
interface SubComponentEntry {
name: string;
component: React.FC;
defaultClasses?: string;
}
declare function registerSubComponent(entry: SubComponentEntry): void;
declare function getSubComponent(name: string): SubComponentEntry | undefined;
declare function getAllSubComponents(): SubComponentEntry[];
declare function withSubComponents(Component: T, subComponentNames: string[]): T & Record>;
/**
* tailwind-styled-v5 — Native Rust Bindings
*
* All functions require native Rust bindings.
* Uses @tailwind-styled/shared for native resolution.
*/
interface ParsedClassModifier {
type: "opacity" | "arbitrary";
value: string;
}
interface ParsedClass {
raw: string;
base: string;
variants: string[];
modifier?: ParsedClassModifier;
}
interface ThemeConfig {
colors: Record;
spacing: Record;
fonts: Record;
breakpoints: Record;
animations: Record;
raw: Record;
}
export { type ComponentConfig, type ContainerConfig, type ContainerEntry, type CvFn, type HtmlTagName, type InferVariantProps, type MergeOptions, type ParsedClass, type ParsedClassModifier, type ResolvedThemeTokens, type StateComponentEntry, type StateConfig, type StyledComponentProps, type StyledOptions, type StyledProps, type StyledSystemConfig, type StyledSystemInstance, type SubComponentEntry, type SubComponentMap, type SubComponentProps, type SystemComponentConfig, type SystemComponentFactory, type SystemTokenMap, type ThemeConfig, type ThemeTokenMap, type TwComponentFactory, type TwObject, type TwStyledComponent, type TwSubComponent, type TwTagFactory, type TwTagFactoryAny, type VariantLiterals, cn, createComponent, createStyledSystem, createTheme, createTwMerge, cssVar, cv, cx, cxm, generateContainerCss, generateStateCss, getAllSubComponents, getContainerRegistry, getStateRegistry, getSubComponent, mergeWithRules, processContainer, processState, registerSubComponent, registerVariantTable, resolveStyledClassName, server, styled, t, tw, twMerge, twVar, v4Tokens, withSubComponents };