tailwind-styled-v4 1.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animate.cjs +252 -0
- package/dist/animate.cjs.map +1 -0
- package/dist/animate.d.cts +117 -0
- package/dist/animate.d.ts +117 -0
- package/dist/animate.js +245 -0
- package/dist/animate.js.map +1 -0
- package/dist/astTransform-ua-eapqs.d.cts +41 -0
- package/dist/astTransform-ua-eapqs.d.ts +41 -0
- package/dist/compiler.cjs +3594 -0
- package/dist/compiler.cjs.map +1 -0
- package/dist/compiler.d.cts +716 -0
- package/dist/compiler.d.ts +716 -0
- package/dist/compiler.js +3535 -0
- package/dist/compiler.js.map +1 -0
- package/dist/css.cjs +71 -0
- package/dist/css.cjs.map +1 -0
- package/dist/css.d.cts +45 -0
- package/dist/css.d.ts +45 -0
- package/dist/css.js +62 -0
- package/dist/css.js.map +1 -0
- package/dist/devtools.cjs +959 -0
- package/dist/devtools.cjs.map +1 -0
- package/dist/devtools.d.cts +22 -0
- package/dist/devtools.d.ts +22 -0
- package/dist/devtools.js +952 -0
- package/dist/devtools.js.map +1 -0
- package/dist/index.cjs +1058 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +584 -0
- package/dist/index.d.ts +456 -958
- package/dist/index.js +1021 -8
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +268 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +45 -0
- package/dist/next.d.ts +45 -0
- package/dist/next.js +261 -0
- package/dist/next.js.map +1 -0
- package/dist/plugins.cjs +396 -0
- package/dist/plugins.cjs.map +1 -0
- package/dist/plugins.d.cts +231 -0
- package/dist/plugins.d.ts +231 -0
- package/dist/plugins.js +381 -0
- package/dist/plugins.js.map +1 -0
- package/dist/preset.cjs +129 -0
- package/dist/preset.cjs.map +1 -0
- package/dist/preset.d.cts +249 -0
- package/dist/preset.d.ts +249 -0
- package/dist/preset.js +124 -0
- package/dist/preset.js.map +1 -0
- package/dist/theme.cjs +154 -0
- package/dist/theme.cjs.map +1 -0
- package/dist/theme.d.cts +181 -0
- package/dist/theme.d.ts +181 -0
- package/dist/theme.js +148 -0
- package/dist/theme.js.map +1 -0
- package/dist/turbopackLoader.cjs +2689 -0
- package/dist/turbopackLoader.cjs.map +1 -0
- package/dist/turbopackLoader.d.cts +22 -0
- package/dist/turbopackLoader.d.ts +22 -0
- package/dist/turbopackLoader.js +2681 -0
- package/dist/turbopackLoader.js.map +1 -0
- package/dist/vite.cjs +105 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +22 -0
- package/dist/vite.d.ts +22 -0
- package/dist/vite.js +96 -0
- package/dist/vite.js.map +1 -0
- package/dist/webpackLoader.cjs +2670 -0
- package/dist/webpackLoader.cjs.map +1 -0
- package/dist/webpackLoader.d.cts +24 -0
- package/dist/webpackLoader.d.ts +24 -0
- package/dist/webpackLoader.js +2662 -0
- package/dist/webpackLoader.js.map +1 -0
- package/package.json +66 -90
- package/CHANGELOG.md +0 -75
- package/LICENSE +0 -21
- package/README.md +0 -330
- package/dist/compiler/index.d.mts +0 -214
- package/dist/compiler/index.d.ts +0 -214
- package/dist/compiler/index.js +0 -546
- package/dist/compiler/index.js.map +0 -1
- package/dist/compiler/index.mjs +0 -504
- package/dist/compiler/index.mjs.map +0 -1
- package/dist/index.d.mts +0 -1086
- package/dist/index.mjs +0 -9
- package/dist/index.mjs.map +0 -1
- package/dist/turbopack-loader.js +0 -232
- package/dist/webpack-loader.js +0 -213
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
import * as _tailwind_styled_animate from '@tailwind-styled/animate';
|
|
2
|
+
import React, { JSX } from 'react';
|
|
3
|
+
|
|
4
|
+
/** Reactive state config — generates data-attr CSS selectors */
|
|
5
|
+
interface StateConfig {
|
|
6
|
+
[stateName: string]: string;
|
|
7
|
+
}
|
|
8
|
+
/** Container query breakpoints */
|
|
9
|
+
interface ContainerConfig {
|
|
10
|
+
/** @container (min-width: Xpx) */
|
|
11
|
+
[breakpoint: string]: string | {
|
|
12
|
+
minWidth?: string;
|
|
13
|
+
maxWidth?: string;
|
|
14
|
+
classes: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
interface ComponentConfig {
|
|
18
|
+
base?: string;
|
|
19
|
+
variants?: Record<string, Record<string, string>>;
|
|
20
|
+
compoundVariants?: Array<{
|
|
21
|
+
class: string;
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}>;
|
|
24
|
+
defaultVariants?: Record<string, string>;
|
|
25
|
+
/** Reactive state: { active: "bg-blue-500", disabled: "opacity-50" } */
|
|
26
|
+
state?: StateConfig;
|
|
27
|
+
/** Container query: { sm: "flex-col", md: "flex-row" } */
|
|
28
|
+
container?: ContainerConfig;
|
|
29
|
+
/** Named container for @container queries */
|
|
30
|
+
containerName?: string;
|
|
31
|
+
}
|
|
32
|
+
type VariantLiterals<V extends Record<string, string>> = keyof V & string;
|
|
33
|
+
type InferVariantProps<C extends ComponentConfig> = C["variants"] extends Record<string, Record<string, string>> ? {
|
|
34
|
+
[K in keyof C["variants"]]?: VariantLiterals<C["variants"][K]>;
|
|
35
|
+
} : Record<never, never>;
|
|
36
|
+
type StyledComponentProps<P extends object, C extends ComponentConfig = ComponentConfig> = P & InferVariantProps<C> & {
|
|
37
|
+
className?: string;
|
|
38
|
+
};
|
|
39
|
+
interface TwStyledComponent<P extends object = Record<string, any>> extends React.ForwardRefExoticComponent<P & React.RefAttributes<any>> {
|
|
40
|
+
extend(strings: TemplateStringsArray, ...exprs: any[]): TwStyledComponent<P>;
|
|
41
|
+
withVariants(config: Partial<ComponentConfig>): TwStyledComponent<P>;
|
|
42
|
+
/** Attach a CSS animation. Requires @tailwind-styled/animate. */
|
|
43
|
+
animate(opts: _tailwind_styled_animate.AnimateOptions): TwStyledComponent<P>;
|
|
44
|
+
}
|
|
45
|
+
type CvFn<C extends ComponentConfig> = (props?: InferVariantProps<C> & {
|
|
46
|
+
className?: string;
|
|
47
|
+
} & Record<string, any>) => string;
|
|
48
|
+
type Interpolation<P extends object> = string | number | boolean | null | undefined | ((props: P) => string | number | boolean | null | undefined);
|
|
49
|
+
type TwTagFactory<E extends keyof JSX.IntrinsicElements = "div"> = {
|
|
50
|
+
(strings: TemplateStringsArray, ...exprs: Interpolation<JSX.IntrinsicElements[E]>[]): TwStyledComponent<JSX.IntrinsicElements[E]>;
|
|
51
|
+
<P extends object>(strings: TemplateStringsArray, ...exprs: Interpolation<JSX.IntrinsicElements[E] & P>[]): TwStyledComponent<JSX.IntrinsicElements[E] & P>;
|
|
52
|
+
<C extends ComponentConfig>(config: C): TwStyledComponent<JSX.IntrinsicElements[E] & InferVariantProps<C>>;
|
|
53
|
+
(config: ComponentConfig): TwStyledComponent<JSX.IntrinsicElements[E]>;
|
|
54
|
+
};
|
|
55
|
+
type TwComponentFactory<C extends React.ComponentType<any>> = {
|
|
56
|
+
(strings: TemplateStringsArray, ...exprs: Interpolation<React.ComponentPropsWithRef<C>>[]): TwStyledComponent<React.ComponentPropsWithRef<C>>;
|
|
57
|
+
<Config extends ComponentConfig>(config: Config): TwStyledComponent<React.ComponentPropsWithRef<C> & InferVariantProps<Config>>;
|
|
58
|
+
};
|
|
59
|
+
type HtmlTagName = "div" | "section" | "article" | "aside" | "header" | "footer" | "main" | "nav" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "span" | "strong" | "em" | "b" | "i" | "s" | "u" | "small" | "mark" | "sub" | "sup" | "blockquote" | "q" | "cite" | "abbr" | "address" | "time" | "code" | "pre" | "kbd" | "samp" | "var" | "ul" | "ol" | "li" | "dl" | "dt" | "dd" | "figure" | "figcaption" | "details" | "summary" | "table" | "thead" | "tbody" | "tfoot" | "tr" | "th" | "td" | "caption" | "colgroup" | "col" | "img" | "picture" | "video" | "audio" | "source" | "track" | "canvas" | "svg" | "path" | "circle" | "rect" | "line" | "polyline" | "polygon" | "ellipse" | "g" | "defs" | "use" | "symbol" | "text" | "tspan" | "form" | "input" | "textarea" | "select" | "option" | "optgroup" | "button" | "label" | "fieldset" | "legend" | "output" | "progress" | "meter" | "datalist" | "a" | "area" | "map" | "iframe" | "embed" | "object" | "hr" | "br" | "wbr" | "dialog" | "menu" | "template" | "slot";
|
|
60
|
+
type TwServerObject = {
|
|
61
|
+
[K in HtmlTagName]: K extends keyof JSX.IntrinsicElements ? TwTagFactory<K> : TwTagFactory<"div">;
|
|
62
|
+
};
|
|
63
|
+
type TwObject = {
|
|
64
|
+
[K in keyof JSX.IntrinsicElements]: TwTagFactory<K>;
|
|
65
|
+
} & {
|
|
66
|
+
<C extends React.ComponentType<any>>(component: C): TwComponentFactory<C>;
|
|
67
|
+
server: TwServerObject;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* tailwind-styled-v4 — Container Query Engine
|
|
72
|
+
*
|
|
73
|
+
* Generates @container rules from a simple breakpoint config.
|
|
74
|
+
*
|
|
75
|
+
* Usage:
|
|
76
|
+
* const Card = tw.div({
|
|
77
|
+
* base: "p-4",
|
|
78
|
+
* container: {
|
|
79
|
+
* sm: "flex-col", // @container (min-width: 320px)
|
|
80
|
+
* md: "flex-row", // @container (min-width: 640px)
|
|
81
|
+
* lg: "grid-cols-3", // @container (min-width: 1024px)
|
|
82
|
+
* },
|
|
83
|
+
* containerName: "card",
|
|
84
|
+
* })
|
|
85
|
+
*
|
|
86
|
+
* // Wrap with container context:
|
|
87
|
+
* const CardWrapper = tw.div`@container`
|
|
88
|
+
*
|
|
89
|
+
* Named containers:
|
|
90
|
+
* const SidebarCard = tw.div({
|
|
91
|
+
* base: "p-2",
|
|
92
|
+
* container: { lg: "text-sm" },
|
|
93
|
+
* containerName: "sidebar",
|
|
94
|
+
* })
|
|
95
|
+
* // Generates: @container sidebar (min-width: 1024px) { ... }
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
interface ContainerEntry {
|
|
99
|
+
id: string;
|
|
100
|
+
tag: string;
|
|
101
|
+
containerName?: string;
|
|
102
|
+
breakpoints: Array<{
|
|
103
|
+
minWidth: string;
|
|
104
|
+
classes: string;
|
|
105
|
+
}>;
|
|
106
|
+
cssInjected: boolean;
|
|
107
|
+
}
|
|
108
|
+
interface ContainerQueryResult {
|
|
109
|
+
containerClass: string;
|
|
110
|
+
hasContainer: true;
|
|
111
|
+
}
|
|
112
|
+
declare function processContainer(tag: string, container: ContainerConfig, containerName?: string): ContainerQueryResult;
|
|
113
|
+
declare function generateContainerCss(tag: string, container: ContainerConfig, containerName?: string): string;
|
|
114
|
+
declare function getContainerRegistry(): Map<string, ContainerEntry>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* tailwind-styled-v4 v3 — createComponent
|
|
118
|
+
*
|
|
119
|
+
* v3 additions:
|
|
120
|
+
* - StateEngine integration: state key → data-attr CSS
|
|
121
|
+
* - ContainerQuery integration: container key → @container CSS
|
|
122
|
+
*
|
|
123
|
+
* Fixes from v2:
|
|
124
|
+
* #03 — filterProps: dynamic based on actual variant keys
|
|
125
|
+
* #07 — extend(): always use originalTag, not previous forwardRef wrapper
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
declare function createComponent<P extends object = Record<string, any>>(tag: any, config: string | ComponentConfig): TwStyledComponent<P>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* tailwind-styled-v4 v2 — cv()
|
|
132
|
+
*
|
|
133
|
+
* UPGRADE #3: cv() now infers exact variant values from config.
|
|
134
|
+
*
|
|
135
|
+
* Standalone class variant function — no React needed.
|
|
136
|
+
* Compatible with shadcn/ui, Radix, Headless UI.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* const button = cv({
|
|
140
|
+
* base: "px-4 py-2 rounded-lg",
|
|
141
|
+
* variants: { size: { sm: "text-sm", lg: "text-lg" } },
|
|
142
|
+
* defaultVariants: { size: "sm" }
|
|
143
|
+
* })
|
|
144
|
+
*
|
|
145
|
+
* // BEFORE: button({ size: "xl" }) — no error (size was string)
|
|
146
|
+
* // AFTER: button({ size: "xl" }) — TypeScript ERROR: "xl" not in "sm" | "lg" ✓
|
|
147
|
+
*
|
|
148
|
+
* button({ size: "lg" }) → "px-4 py-2 rounded-lg text-lg"
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
declare function cv<C extends ComponentConfig>(config: C): CvFn<C>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* tailwind-styled-v4 v2 — cx / cn
|
|
155
|
+
*
|
|
156
|
+
* FIX #09: Rename for clarity — behavior was confusing with two near-identical utils.
|
|
157
|
+
*
|
|
158
|
+
* BEFORE:
|
|
159
|
+
* cx() → simple join, no conflict resolution → cx("p-4", "p-8") = "p-4 p-8" (WRONG)
|
|
160
|
+
* cxm() → twMerge, correct — but obscure name
|
|
161
|
+
*
|
|
162
|
+
* AFTER:
|
|
163
|
+
* cn() → simple join (for cases where you know there's no conflict)
|
|
164
|
+
* cx() → twMerge-powered, conflict-aware (recommended for most use cases)
|
|
165
|
+
* cxm() → kept as alias for cx() for backward compat
|
|
166
|
+
*/
|
|
167
|
+
type ClassValue = string | undefined | null | false | 0;
|
|
168
|
+
/**
|
|
169
|
+
* cn — simple class name joiner (no conflict resolution).
|
|
170
|
+
* Use when you know classes don't conflict.
|
|
171
|
+
*
|
|
172
|
+
* FIX #09: Previously named `cx`. Renamed to `cn` for clarity.
|
|
173
|
+
*
|
|
174
|
+
* @example cn("p-4", isActive && "opacity-100") → "p-4 opacity-100"
|
|
175
|
+
*/
|
|
176
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
177
|
+
/**
|
|
178
|
+
* cx — conflict-aware class merger using tailwind-merge.
|
|
179
|
+
* Recommended for combining Tailwind classes where conflicts are possible.
|
|
180
|
+
*
|
|
181
|
+
* FIX #09: Previously named `cxm`. Renamed to `cx` as the primary utility.
|
|
182
|
+
*
|
|
183
|
+
* @example cx("p-4 p-8") → "p-8" (conflict resolved, last wins)
|
|
184
|
+
* @example cx("bg-red-500", "bg-blue-500") → "bg-blue-500"
|
|
185
|
+
*/
|
|
186
|
+
declare function cx(...inputs: ClassValue[]): string;
|
|
187
|
+
/**
|
|
188
|
+
* cxm — alias for cx(), kept for backward compatibility.
|
|
189
|
+
* @deprecated Use cx() instead.
|
|
190
|
+
*/
|
|
191
|
+
declare const cxm: typeof cx;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* tailwind-styled-v4 — Live Token Engine
|
|
195
|
+
*
|
|
196
|
+
* Runtime design token management via CSS custom properties.
|
|
197
|
+
* Theme changes propagate instantly — no rebuild, no re-render.
|
|
198
|
+
*
|
|
199
|
+
* Usage:
|
|
200
|
+
* import { liveToken, setToken, setTokens, subscribeTokens } from "tailwind-styled-v4"
|
|
201
|
+
*
|
|
202
|
+
* // Define tokens (injected as CSS vars on first call)
|
|
203
|
+
* const theme = liveToken({
|
|
204
|
+
* primary: "#3b82f6",
|
|
205
|
+
* secondary: "#6366f1",
|
|
206
|
+
* accent: "#f59e0b",
|
|
207
|
+
* surface: "#18181b",
|
|
208
|
+
* "text-base": "#e4e4e7",
|
|
209
|
+
* })
|
|
210
|
+
*
|
|
211
|
+
* // Use in components
|
|
212
|
+
* const Button = tw.button`
|
|
213
|
+
* bg-[var(--tw-token-primary)]
|
|
214
|
+
* text-[var(--tw-token-text-base)]
|
|
215
|
+
* `
|
|
216
|
+
*
|
|
217
|
+
* // Update at runtime (instant, no rebuild)
|
|
218
|
+
* setToken("primary", "#ef4444") // single token
|
|
219
|
+
* setTokens({ primary: "#ef4444", secondary: "#ec4899" }) // batch
|
|
220
|
+
*
|
|
221
|
+
* // Switch themes
|
|
222
|
+
* applyTokenSet(darkTheme)
|
|
223
|
+
*
|
|
224
|
+
* // Subscribe to changes
|
|
225
|
+
* const unsub = subscribeTokens((tokens) => {
|
|
226
|
+
* console.log("theme changed", tokens)
|
|
227
|
+
* })
|
|
228
|
+
*
|
|
229
|
+
* Token CSS variable naming:
|
|
230
|
+
* token("primary") → var(--tw-token-primary)
|
|
231
|
+
* token("text-base") → var(--tw-token-text-base)
|
|
232
|
+
*/
|
|
233
|
+
type TokenMap = Record<string, string>;
|
|
234
|
+
interface LiveTokenSet {
|
|
235
|
+
/** Token name → CSS variable name mapping */
|
|
236
|
+
vars: Record<string, string>;
|
|
237
|
+
/** Get current value of a token */
|
|
238
|
+
get(name: string): string | undefined;
|
|
239
|
+
/** Update a single token */
|
|
240
|
+
set(name: string, value: string): void;
|
|
241
|
+
/** Update multiple tokens at once */
|
|
242
|
+
setAll(tokens: TokenMap): void;
|
|
243
|
+
/** Snapshot of current values */
|
|
244
|
+
snapshot(): TokenMap;
|
|
245
|
+
}
|
|
246
|
+
type TokenSubscriber = (tokens: TokenMap) => void;
|
|
247
|
+
declare function tokenVar(name: string): string;
|
|
248
|
+
declare function tokenRef(name: string): string;
|
|
249
|
+
/**
|
|
250
|
+
* Define a set of live tokens and inject them as CSS variables.
|
|
251
|
+
* Returns a LiveTokenSet for programmatic control.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* const theme = liveToken({ primary: "#3b82f6" })
|
|
255
|
+
* theme.set("primary", "#ef4444") // instant update
|
|
256
|
+
*/
|
|
257
|
+
declare function liveToken(tokens: TokenMap): LiveTokenSet;
|
|
258
|
+
/**
|
|
259
|
+
* Update a single design token at runtime.
|
|
260
|
+
* CSS variable is updated immediately — no rebuild needed.
|
|
261
|
+
*/
|
|
262
|
+
declare function setToken(name: string, value: string): void;
|
|
263
|
+
/**
|
|
264
|
+
* Update multiple tokens in one batch (single DOM update).
|
|
265
|
+
*/
|
|
266
|
+
declare function setTokens(tokens: TokenMap): void;
|
|
267
|
+
/**
|
|
268
|
+
* Replace all tokens with a new token set (theme switch).
|
|
269
|
+
*/
|
|
270
|
+
declare function applyTokenSet(tokens: TokenMap): void;
|
|
271
|
+
/**
|
|
272
|
+
* Get current value of a token.
|
|
273
|
+
*/
|
|
274
|
+
declare function getToken(name: string): string | undefined;
|
|
275
|
+
/**
|
|
276
|
+
* Get snapshot of all current tokens.
|
|
277
|
+
*/
|
|
278
|
+
declare function getTokens(): TokenMap;
|
|
279
|
+
/**
|
|
280
|
+
* Subscribe to token changes.
|
|
281
|
+
* Returns unsubscribe function.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* const unsub = subscribeTokens((tokens) => {
|
|
285
|
+
* document.documentElement.classList.toggle("dark", tokens.surface === "#000")
|
|
286
|
+
* })
|
|
287
|
+
* // Later:
|
|
288
|
+
* unsub()
|
|
289
|
+
*/
|
|
290
|
+
declare function subscribeTokens(fn: TokenSubscriber): () => void;
|
|
291
|
+
/**
|
|
292
|
+
* Generate SSR-safe CSS string for current tokens.
|
|
293
|
+
*/
|
|
294
|
+
declare function generateTokenCssString(): string;
|
|
295
|
+
/**
|
|
296
|
+
* React hook for reading live tokens (re-renders on change).
|
|
297
|
+
* Import from tailwind-styled-v4/react.
|
|
298
|
+
*/
|
|
299
|
+
declare function createUseTokens(): (() => TokenMap) | null;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* tailwind-styled-v4 — Reactive State Engine
|
|
303
|
+
*
|
|
304
|
+
* Zero-JS CSS state management via data attributes.
|
|
305
|
+
* No React re-render needed for style changes.
|
|
306
|
+
*
|
|
307
|
+
* How it works:
|
|
308
|
+
* 1. tw.button({ state: { active: "bg-blue-500", loading: "opacity-70" } })
|
|
309
|
+
* 2. State engine generates a unique class + injects CSS:
|
|
310
|
+
* .tw-s-abc123[data-active="true"] { @apply bg-blue-500; }
|
|
311
|
+
* .tw-s-abc123[data-loading="true"] { @apply opacity-70; }
|
|
312
|
+
* 3. Component renders with the state class
|
|
313
|
+
* 4. User sets data-active="true" directly — no state needed
|
|
314
|
+
*
|
|
315
|
+
* Devtools integration:
|
|
316
|
+
* All components register to __TW_STATE_REGISTRY__ for devtools inspection.
|
|
317
|
+
*/
|
|
318
|
+
|
|
319
|
+
interface StateComponentEntry {
|
|
320
|
+
id: string;
|
|
321
|
+
tag: string;
|
|
322
|
+
states: string[];
|
|
323
|
+
cssInjected: boolean;
|
|
324
|
+
}
|
|
325
|
+
interface StateEngineResult {
|
|
326
|
+
/** CSS class to add to the component */
|
|
327
|
+
stateClass: string;
|
|
328
|
+
/** Whether this component uses state (for SSR data attributes) */
|
|
329
|
+
hasState: true;
|
|
330
|
+
/** List of state names (for devtools) */
|
|
331
|
+
stateNames: string[];
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Process a StateConfig for a component.
|
|
335
|
+
* Returns the state class and injects CSS (client-side only).
|
|
336
|
+
*/
|
|
337
|
+
declare function processState(tag: string, state: StateConfig): StateEngineResult;
|
|
338
|
+
/**
|
|
339
|
+
* Generate SSR-safe CSS string for a state config.
|
|
340
|
+
* Used by SSR to inject styles into <head>.
|
|
341
|
+
*/
|
|
342
|
+
declare function generateStateCss(tag: string, state: StateConfig): string;
|
|
343
|
+
/**
|
|
344
|
+
* Get the state registry (for devtools).
|
|
345
|
+
*/
|
|
346
|
+
declare function getStateRegistry(): Map<string, StateComponentEntry>;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* tailwind-styled-v4 — createStyledSystem()
|
|
350
|
+
*
|
|
351
|
+
* Design System Factory — Mode 3 API.
|
|
352
|
+
*
|
|
353
|
+
* Level 1 — utility: tw.div`p-4`
|
|
354
|
+
* Level 2 — styled: tw(Button)`px-4`
|
|
355
|
+
* Level 3 — design system: ui.button({ variant: "primary" })
|
|
356
|
+
*
|
|
357
|
+
* Usage:
|
|
358
|
+
* const ui = createStyledSystem({
|
|
359
|
+
* tokens: {
|
|
360
|
+
* colors: { primary: "#6366f1", muted: "#71717a" },
|
|
361
|
+
* radius: { base: "0.5rem", full: "9999px" },
|
|
362
|
+
* },
|
|
363
|
+
* components: {
|
|
364
|
+
* button: {
|
|
365
|
+
* base: "inline-flex items-center font-medium transition-colors",
|
|
366
|
+
* variants: {
|
|
367
|
+
* variant: {
|
|
368
|
+
* primary: "bg-[var(--sys-color-primary)] text-white",
|
|
369
|
+
* ghost: "bg-transparent border border-current",
|
|
370
|
+
* danger: "bg-red-500 text-white",
|
|
371
|
+
* },
|
|
372
|
+
* size: {
|
|
373
|
+
* sm: "h-8 px-3 text-sm",
|
|
374
|
+
* md: "h-10 px-4 text-base",
|
|
375
|
+
* lg: "h-12 px-6 text-lg",
|
|
376
|
+
* },
|
|
377
|
+
* },
|
|
378
|
+
* defaultVariants: { variant: "primary", size: "md" },
|
|
379
|
+
* },
|
|
380
|
+
* },
|
|
381
|
+
* })
|
|
382
|
+
*
|
|
383
|
+
* const Button = ui.button()
|
|
384
|
+
* // → <Button variant="primary" size="lg" />
|
|
385
|
+
*
|
|
386
|
+
* // Token access
|
|
387
|
+
* ui.token("colors.primary") // → "var(--sys-color-primary)"
|
|
388
|
+
* ui.cssVar("colors.primary") // → "#6366f1"
|
|
389
|
+
*/
|
|
390
|
+
|
|
391
|
+
type SystemTokenMap = Record<string, Record<string, string>>;
|
|
392
|
+
interface SystemComponentConfig extends ComponentConfig {
|
|
393
|
+
/** Extra class applied only when used from the system (e.g. system-level resets) */
|
|
394
|
+
systemBase?: string;
|
|
395
|
+
}
|
|
396
|
+
interface StyledSystemConfig<T extends SystemTokenMap = SystemTokenMap, C extends Record<string, SystemComponentConfig> = Record<string, SystemComponentConfig>> {
|
|
397
|
+
/** Design tokens — injected as CSS custom properties under --sys-{group}-{name} */
|
|
398
|
+
tokens?: T;
|
|
399
|
+
/** Component presets */
|
|
400
|
+
components?: C;
|
|
401
|
+
/** CSS variable prefix. Default: "sys" → --sys-color-primary */
|
|
402
|
+
prefix?: string;
|
|
403
|
+
/** If true, auto-inject token CSS vars into :root on init. Default: true */
|
|
404
|
+
injectTokens?: boolean;
|
|
405
|
+
}
|
|
406
|
+
type SystemComponentFactory<C extends SystemComponentConfig> = (overrides?: Partial<C>) => TwStyledComponent<any>;
|
|
407
|
+
type StyledSystemInstance<T extends SystemTokenMap, C extends Record<string, SystemComponentConfig>> = {
|
|
408
|
+
[K in keyof C]: SystemComponentFactory<C[K]>;
|
|
409
|
+
} & {
|
|
410
|
+
/**
|
|
411
|
+
* Get the CSS variable reference for a token.
|
|
412
|
+
* @example ui.token("colors.primary") → "var(--sys-colors-primary)"
|
|
413
|
+
*/
|
|
414
|
+
token(path: string): string;
|
|
415
|
+
/**
|
|
416
|
+
* Get the raw value of a token.
|
|
417
|
+
* @example ui.rawToken("colors.primary") → "#6366f1"
|
|
418
|
+
*/
|
|
419
|
+
rawToken(path: string): string | undefined;
|
|
420
|
+
/**
|
|
421
|
+
* Update token values at runtime (re-injects into :root).
|
|
422
|
+
*/
|
|
423
|
+
setTokens(updates: Partial<{
|
|
424
|
+
[G in keyof T]: Partial<T[G]>;
|
|
425
|
+
}>): void;
|
|
426
|
+
/**
|
|
427
|
+
* Access the resolved component config for a registered component.
|
|
428
|
+
*/
|
|
429
|
+
getConfig(name: keyof C): ComponentConfig | undefined;
|
|
430
|
+
/**
|
|
431
|
+
* The tokens object (for reference).
|
|
432
|
+
*/
|
|
433
|
+
tokens: T;
|
|
434
|
+
};
|
|
435
|
+
declare function createStyledSystem<T extends SystemTokenMap = SystemTokenMap, C extends Record<string, SystemComponentConfig> = Record<string, SystemComponentConfig>>(config: StyledSystemConfig<T, C>): StyledSystemInstance<T, C>;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* tailwind-styled-v4 v2 — tw
|
|
439
|
+
*
|
|
440
|
+
* API:
|
|
441
|
+
* tw.div`p-4 bg-zinc-900`
|
|
442
|
+
* tw.button({ base: "px-4", variants: { size: { sm: "text-sm" } } })
|
|
443
|
+
* tw(Link)`underline text-blue-400`
|
|
444
|
+
* tw.server.div`p-4` ← server-only, compiler enforced + runtime dev warning
|
|
445
|
+
*/
|
|
446
|
+
|
|
447
|
+
declare const server: TwServerObject;
|
|
448
|
+
declare const tw: TwObject;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* tailwind-styled-v4 v2 — twTheme
|
|
452
|
+
*
|
|
453
|
+
* UPGRADE #1: Tailwind v4 CSS Variables integration.
|
|
454
|
+
*
|
|
455
|
+
* Tailwind v4 uses @theme inline to expose design tokens as CSS custom properties:
|
|
456
|
+
* @theme inline {
|
|
457
|
+
* --color-background: var(--background);
|
|
458
|
+
* --color-foreground: var(--foreground);
|
|
459
|
+
* --font-sans: var(--font-geist-sans);
|
|
460
|
+
* }
|
|
461
|
+
*
|
|
462
|
+
* This module bridges tw() syntax with those CSS variables — zero config,
|
|
463
|
+
* full IDE support, type-safe design tokens.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* // Without twTheme (verbose, error-prone)
|
|
467
|
+
* const Box = tw.div`bg-[var(--color-background)] text-[var(--color-foreground)]`
|
|
468
|
+
*
|
|
469
|
+
* // With twTheme (clean, type-safe)
|
|
470
|
+
* const Box = tw.div`${t.bg("color-background")} ${t.text("color-foreground")}`
|
|
471
|
+
*
|
|
472
|
+
* // Or with createTheme for full project-level token map
|
|
473
|
+
* const theme = createTheme({
|
|
474
|
+
* colors: { bg: "color-background", fg: "color-foreground", primary: "color-primary" },
|
|
475
|
+
* fonts: { sans: "font-sans", mono: "font-mono" },
|
|
476
|
+
* })
|
|
477
|
+
* const Box = tw.div`bg-${theme.colors.bg} text-${theme.colors.fg}`
|
|
478
|
+
*/
|
|
479
|
+
/**
|
|
480
|
+
* Reference a CSS custom property in Tailwind v4 arbitrary value syntax.
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* cssVar("color-background") → "var(--color-background)"
|
|
484
|
+
* cssVar("color-primary", "#3b82f6") → "var(--color-primary, #3b82f6)"
|
|
485
|
+
*/
|
|
486
|
+
declare function cssVar(varName: string, fallback?: string): string;
|
|
487
|
+
/**
|
|
488
|
+
* Generate a Tailwind v4 arbitrary value that references a CSS variable.
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* twVar("bg", "color-background") → "bg-[var(--color-background)]"
|
|
492
|
+
* twVar("text", "color-foreground") → "text-[var(--color-foreground)]"
|
|
493
|
+
* twVar("border", "color-border", "#e5e7eb") → "border-[var(--color-border,#e5e7eb)]"
|
|
494
|
+
*/
|
|
495
|
+
declare function twVar(property: string, varName: string, fallback?: string): string;
|
|
496
|
+
declare const t: {
|
|
497
|
+
/** Background color from CSS variable: t.bg("color-primary") → "bg-[var(--color-primary)]" */
|
|
498
|
+
bg: (v: string, fb?: string) => string;
|
|
499
|
+
/** Text color from CSS variable */
|
|
500
|
+
text: (v: string, fb?: string) => string;
|
|
501
|
+
/** Border color from CSS variable */
|
|
502
|
+
border: (v: string, fb?: string) => string;
|
|
503
|
+
/** Ring color from CSS variable */
|
|
504
|
+
ring: (v: string, fb?: string) => string;
|
|
505
|
+
/** Outline color from CSS variable */
|
|
506
|
+
outline: (v: string, fb?: string) => string;
|
|
507
|
+
/** Fill color from CSS variable (SVG) */
|
|
508
|
+
fill: (v: string, fb?: string) => string;
|
|
509
|
+
/** Stroke color from CSS variable (SVG) */
|
|
510
|
+
stroke: (v: string, fb?: string) => string;
|
|
511
|
+
/** Font family from CSS variable */
|
|
512
|
+
font: (v: string, fb?: string) => string;
|
|
513
|
+
/** Shadow from CSS variable */
|
|
514
|
+
shadow: (v: string, fb?: string) => string;
|
|
515
|
+
/** Any arbitrary property from CSS variable */
|
|
516
|
+
var: (property: string, v: string, fb?: string) => string;
|
|
517
|
+
};
|
|
518
|
+
interface ThemeTokenMap {
|
|
519
|
+
colors?: Record<string, string>;
|
|
520
|
+
fonts?: Record<string, string>;
|
|
521
|
+
spacing?: Record<string, string>;
|
|
522
|
+
[key: string]: Record<string, string> | undefined;
|
|
523
|
+
}
|
|
524
|
+
type ResolvedThemeTokens<T extends ThemeTokenMap> = {
|
|
525
|
+
[Group in keyof T]: T[Group] extends Record<string, string> ? {
|
|
526
|
+
[Token in keyof T[Group]]: string;
|
|
527
|
+
} : never;
|
|
528
|
+
};
|
|
529
|
+
/**
|
|
530
|
+
* Create a typed theme token map from your CSS variable names.
|
|
531
|
+
* Returns helper functions that generate Tailwind v4 arbitrary values.
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* // Define your tokens (match your globals.css @theme block)
|
|
535
|
+
* const theme = createTheme({
|
|
536
|
+
* colors: {
|
|
537
|
+
* bg: "color-background",
|
|
538
|
+
* fg: "color-foreground",
|
|
539
|
+
* primary: "color-primary",
|
|
540
|
+
* muted: "color-muted",
|
|
541
|
+
* },
|
|
542
|
+
* fonts: {
|
|
543
|
+
* sans: "font-sans",
|
|
544
|
+
* mono: "font-mono",
|
|
545
|
+
* },
|
|
546
|
+
* })
|
|
547
|
+
*
|
|
548
|
+
* // Use in tw components
|
|
549
|
+
* const Card = tw.div`
|
|
550
|
+
* bg-${theme.colors.bg}
|
|
551
|
+
* text-${theme.colors.fg}
|
|
552
|
+
* font-${theme.fonts.sans}
|
|
553
|
+
* `
|
|
554
|
+
* // → tw.div`bg-[var(--color-background)] text-[var(--color-foreground)] font-[var(--font-sans)]`
|
|
555
|
+
*
|
|
556
|
+
* // Use in cv()
|
|
557
|
+
* const button = cv({
|
|
558
|
+
* base: `px-4 py-2 ${theme.colors.bg} ${theme.colors.fg}`,
|
|
559
|
+
* variants: { ... }
|
|
560
|
+
* })
|
|
561
|
+
*/
|
|
562
|
+
declare function createTheme<T extends ThemeTokenMap>(tokenMap: T): ResolvedThemeTokens<T>;
|
|
563
|
+
/**
|
|
564
|
+
* Pre-built references for standard Tailwind v4 CSS variable tokens.
|
|
565
|
+
* Works out of the box with next-app-standar-config globals.css.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* import { v4Tokens } from "tailwind-styled-v4"
|
|
569
|
+
*
|
|
570
|
+
* const Page = tw.div`${v4Tokens.bg} ${v4Tokens.text}`
|
|
571
|
+
* // → tw.div`bg-[var(--color-background)] text-[var(--color-foreground)]`
|
|
572
|
+
*/
|
|
573
|
+
declare const v4Tokens: {
|
|
574
|
+
/** bg-[var(--color-background)] */
|
|
575
|
+
readonly bg: string;
|
|
576
|
+
/** text-[var(--color-foreground)] */
|
|
577
|
+
readonly text: string;
|
|
578
|
+
/** font-[var(--font-sans)] */
|
|
579
|
+
readonly fontSans: string;
|
|
580
|
+
/** font-[var(--font-mono)] */
|
|
581
|
+
readonly fontMono: string;
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
export { type ComponentConfig, type ContainerConfig, type ContainerEntry, type CvFn, type HtmlTagName, type InferVariantProps, type LiveTokenSet, type ResolvedThemeTokens, type StateComponentEntry, type StateConfig, type StyledComponentProps, type StyledSystemConfig, type StyledSystemInstance, type SystemComponentConfig, type SystemComponentFactory, type SystemTokenMap, type ThemeTokenMap, type TokenMap, type TokenSubscriber, type TwComponentFactory, type TwObject, type TwStyledComponent, type TwTagFactory, type VariantLiterals, applyTokenSet, cn, tokenRef as containerRef, createComponent, createStyledSystem, createTheme, createUseTokens, cssVar, cv, cx, cxm, generateContainerCss, generateStateCss, generateTokenCssString, getContainerRegistry, getStateRegistry, getToken, getTokens, liveToken, processContainer, processState, server, setToken, setTokens, subscribeTokens, t, tokenRef, tokenVar, tw, twVar, v4Tokens };
|