tailwind-to-style 3.3.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.
Files changed (51) hide show
  1. package/README.md +208 -1118
  2. package/dist/animations/index.cjs +9391 -0
  3. package/dist/animations/index.d.ts +58 -0
  4. package/dist/animations/index.esm.js +9385 -0
  5. package/dist/animations/index.esm.js.map +1 -0
  6. package/dist/className/index.cjs +2241 -4181
  7. package/dist/className/index.esm.js +2241 -4181
  8. package/dist/className/index.esm.js.map +1 -1
  9. package/dist/core/tws.cjs +136 -114
  10. package/dist/core/tws.cjs.map +1 -0
  11. package/dist/core/tws.esm.js +136 -114
  12. package/dist/core/tws.esm.js.map +1 -1
  13. package/dist/core/twsx.cjs +1971 -3970
  14. package/dist/core/twsx.esm.js +1971 -3970
  15. package/dist/core/twsx.esm.js.map +1 -1
  16. package/dist/core/twsxVariants.cjs +1997 -3986
  17. package/dist/core/twsxVariants.esm.js +1997 -3986
  18. package/dist/core/twsxVariants.esm.js.map +1 -1
  19. package/dist/cx.cjs +2 -2
  20. package/dist/cx.cjs.map +1 -0
  21. package/dist/cx.esm.js +2 -2
  22. package/dist/index.cjs +5253 -9252
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.ts +4 -1
  25. package/dist/index.esm.js +5251 -9201
  26. package/dist/index.esm.js.map +1 -1
  27. package/dist/index.min.js +1 -1
  28. package/dist/index.min.js.map +1 -1
  29. package/dist/react/index.cjs +10177 -0
  30. package/dist/react/index.cjs.map +1 -0
  31. package/dist/react/index.d.ts +69 -0
  32. package/dist/react/index.esm.js +10173 -0
  33. package/dist/react/index.esm.js.map +1 -0
  34. package/dist/styled/index.cjs +9094 -0
  35. package/dist/styled/index.cjs.map +1 -0
  36. package/dist/styled/index.d.ts +17 -0
  37. package/dist/styled/index.esm.js +9087 -0
  38. package/dist/styled/index.esm.js.map +1 -0
  39. package/dist/tokens/index.cjs +359 -0
  40. package/dist/tokens/index.d.ts +33 -0
  41. package/dist/tokens/index.esm.js +355 -0
  42. package/dist/tokens/index.esm.js.map +1 -0
  43. package/dist/utils/index.cjs +219 -270
  44. package/dist/utils/index.esm.js +219 -270
  45. package/dist/utils/index.esm.js.map +1 -1
  46. package/package.json +33 -24
  47. package/types/animations/index.d.ts +58 -0
  48. package/types/index.d.ts +4 -1
  49. package/types/react/index.d.ts +69 -0
  50. package/types/tokens/index.d.ts +33 -0
  51. package/types/v4.d.ts +191 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tailwind-to-style",
3
- "version": "3.3.0",
4
- "description": "Runtime Tailwind CSS to inline styles converter. Zero build step, SSR support, tree-shakeable. Works with React, Vue, Svelte, vanilla JS.",
3
+ "version": "4.0.0",
4
+ "description": "Zero-build runtime Tailwind CSS engine. Convert utility classes to real CSS with variants, slots, tokens, and React bindings. SSR-ready, tree-shakeable.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.esm.js",
@@ -15,26 +15,26 @@
15
15
  "import": "./dist/index.esm.js",
16
16
  "require": "./dist/index.cjs"
17
17
  },
18
+ "./react": {
19
+ "types": "./dist/react/index.d.ts",
20
+ "import": "./dist/react/index.esm.js",
21
+ "require": "./dist/react/index.cjs"
22
+ },
23
+ "./tokens": {
24
+ "types": "./dist/tokens/index.d.ts",
25
+ "import": "./dist/tokens/index.esm.js",
26
+ "require": "./dist/tokens/index.cjs"
27
+ },
28
+ "./animations": {
29
+ "types": "./dist/animations/index.d.ts",
30
+ "import": "./dist/animations/index.esm.js",
31
+ "require": "./dist/animations/index.cjs"
32
+ },
18
33
  "./tws": {
19
34
  "types": "./dist/core/tws.d.ts",
20
35
  "import": "./dist/core/tws.esm.js",
21
36
  "require": "./dist/core/tws.cjs"
22
37
  },
23
- "./twsx": {
24
- "types": "./dist/core/twsx.d.ts",
25
- "import": "./dist/core/twsx.esm.js",
26
- "require": "./dist/core/twsx.cjs"
27
- },
28
- "./twsx-variants": {
29
- "types": "./dist/core/twsxVariants.d.ts",
30
- "import": "./dist/core/twsxVariants.esm.js",
31
- "require": "./dist/core/twsxVariants.cjs"
32
- },
33
- "./utils": {
34
- "types": "./dist/utils/index.d.ts",
35
- "import": "./dist/utils/index.esm.js",
36
- "require": "./dist/utils/index.cjs"
37
- },
38
38
  "./cx": {
39
39
  "types": "./dist/cx.d.ts",
40
40
  "import": "./dist/cx.esm.js",
@@ -48,7 +48,7 @@
48
48
  "./preflight.css": "./preflight.css",
49
49
  "./package.json": "./package.json"
50
50
  },
51
- "sideEffects": false,
51
+ "sideEffects": ["*.css", "dist/*.js", "dist/**/*.js"],
52
52
  "files": [
53
53
  "dist",
54
54
  "types",
@@ -82,19 +82,20 @@
82
82
  "tailwind",
83
83
  "tailwindcss",
84
84
  "css",
85
- "stylesheet",
86
- "inline-styles",
87
- "runtime-css",
88
85
  "css-in-js",
86
+ "runtime-css",
89
87
  "zero-build",
88
+ "variants",
89
+ "slots",
90
+ "design-tokens",
91
+ "styled-components",
90
92
  "ssr",
91
93
  "server-side-rendering",
92
94
  "tree-shakeable",
93
- "variants",
94
- "style-converter",
95
95
  "react",
96
96
  "vue",
97
- "svelte"
97
+ "svelte",
98
+ "vanilla-js"
98
99
  ],
99
100
  "author": "Bigetion",
100
101
  "license": "MIT",
@@ -106,6 +107,14 @@
106
107
  "url": "https://github.com/Bigetion/tailwind-to-style/issues"
107
108
  },
108
109
  "homepage": "https://github.com/Bigetion/tailwind-to-style#readme",
110
+ "peerDependencies": {
111
+ "react": ">=17.0.0"
112
+ },
113
+ "peerDependenciesMeta": {
114
+ "react": {
115
+ "optional": true
116
+ }
117
+ },
109
118
  "devDependencies": {
110
119
  "@babel/core": "^7.27.4",
111
120
  "@babel/plugin-proposal-optional-chaining": "^7.21.0",
@@ -0,0 +1,58 @@
1
+ // Type definitions for tailwind-to-style/animations
2
+
3
+ export type AnimationPresetName =
4
+ | 'fadeIn' | 'fadeOut'
5
+ | 'slideInUp' | 'slideInDown' | 'slideInLeft' | 'slideInRight'
6
+ | 'scaleIn' | 'scaleOut'
7
+ | 'bounce' | 'shake' | 'pulse' | 'spin' | 'ping';
8
+
9
+ export interface AnimationKeyframe {
10
+ [property: string]: string;
11
+ }
12
+
13
+ export interface AnimationConfig {
14
+ keyframes: AnimationKeyframe[];
15
+ duration?: string;
16
+ easing?: string;
17
+ delay?: string;
18
+ iterations?: string | number;
19
+ fillMode?: string;
20
+ }
21
+
22
+ export interface AnimateOptions {
23
+ duration?: string;
24
+ easing?: string;
25
+ delay?: string;
26
+ iterations?: string | number;
27
+ fillMode?: string;
28
+ }
29
+
30
+ /**
31
+ * Apply a named animation, returning a className with the animation injected.
32
+ */
33
+ export declare function animate(name: AnimationPresetName | string, options?: AnimateOptions): string;
34
+
35
+ /**
36
+ * Define a custom animation preset.
37
+ */
38
+ export declare function defineAnimation(name: string, config: AnimationConfig): void;
39
+
40
+ /**
41
+ * Get all available animation names (built-in + custom).
42
+ */
43
+ export declare function getAnimationNames(): string[];
44
+
45
+ /**
46
+ * Get an animation preset config by name.
47
+ */
48
+ export declare function getPreset(name: string): AnimationConfig | undefined;
49
+
50
+ /**
51
+ * Clear all injected keyframes and custom animations.
52
+ */
53
+ export declare function clearAnimations(): void;
54
+
55
+ /**
56
+ * Built-in animation presets.
57
+ */
58
+ export declare const ANIMATION_PRESETS: Record<AnimationPresetName, AnimationConfig>;
package/types/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- // Type definitions for tailwind-to-style
1
+ // Type definitions for tailwind-to-style v4
2
2
  // Project: https://github.com/Bigetion/tailwind-to-style
3
3
  // Definitions by: Bigetion
4
4
 
5
+ // v4 unified API re-exports
6
+ export { tw, tws, cx, createSSRCollector } from './v4';
7
+
5
8
  // ============================================================================
6
9
  // Environment Detection
7
10
  // ============================================================================
@@ -0,0 +1,69 @@
1
+ // Type definitions for tailwind-to-style/react
2
+
3
+ import { ComponentType, ForwardRefExoticComponent, PropsWithoutRef, RefAttributes } from 'react';
4
+
5
+ // ============================================================================
6
+ // styled()
7
+ // ============================================================================
8
+
9
+ type IntrinsicElement = keyof JSX.IntrinsicElements;
10
+
11
+ interface StyledConfig<V extends Record<string, Record<string, string>> = {}> {
12
+ name?: string;
13
+ base?: string;
14
+ variants?: V;
15
+ defaultVariants?: { [K in keyof V]?: keyof V[K] };
16
+ compoundVariants?: Array<{ class?: string; className?: string; [key: string]: any }>;
17
+ slots?: Record<string, string>;
18
+ }
19
+
20
+ type VariantProps<V extends Record<string, Record<string, string>>> = {
21
+ [K in keyof V]?: keyof V[K];
22
+ };
23
+
24
+ type StyledComponent<
25
+ T extends IntrinsicElement | ComponentType<any>,
26
+ V extends Record<string, Record<string, string>>
27
+ > = ForwardRefExoticComponent<
28
+ PropsWithoutRef<
29
+ (T extends IntrinsicElement ? JSX.IntrinsicElements[T] : T extends ComponentType<infer P> ? P : never) &
30
+ VariantProps<V> & { className?: string }
31
+ > &
32
+ RefAttributes<T extends IntrinsicElement ? HTMLElement : any>
33
+ > & {
34
+ variants: any;
35
+ raw: StyledConfig<V>;
36
+ };
37
+
38
+ export declare function styled<
39
+ T extends IntrinsicElement | ComponentType<any>,
40
+ V extends Record<string, Record<string, string>> = {}
41
+ >(
42
+ element: T,
43
+ config?: StyledConfig<V>
44
+ ): StyledComponent<T, V>;
45
+
46
+ // ============================================================================
47
+ // ThemeProvider & useTheme
48
+ // ============================================================================
49
+
50
+ interface ThemeProviderProps {
51
+ theme: Record<string, any>;
52
+ name?: string;
53
+ children: React.ReactNode;
54
+ }
55
+
56
+ interface ThemeContextValue {
57
+ theme: Record<string, any>;
58
+ setTheme: (newTheme: Record<string, any>) => void;
59
+ tokens: Record<string, any>;
60
+ }
61
+
62
+ export declare function ThemeProvider(props: ThemeProviderProps): JSX.Element;
63
+ export declare function useTheme(): ThemeContextValue;
64
+
65
+ // ============================================================================
66
+ // useTws
67
+ // ============================================================================
68
+
69
+ export declare function useTws(classes: string): Record<string, string>;
@@ -0,0 +1,33 @@
1
+ // Type definitions for tailwind-to-style/tokens
2
+
3
+ export interface TokenRegistry {
4
+ get(path: string): string | undefined;
5
+ set(path: string, value: string): void;
6
+ subscribe(callback: (tokens: Record<string, any>) => void): () => void;
7
+ toCSS(): string;
8
+ getAll(): Record<string, any>;
9
+ clear(): void;
10
+ }
11
+
12
+ export interface ThemeResult {
13
+ name: string;
14
+ tokens: Record<string, any>;
15
+ selector: string;
16
+ var(path: string): string;
17
+ }
18
+
19
+ export interface CreateThemeOptions {
20
+ name?: string;
21
+ selector?: string;
22
+ }
23
+
24
+ export declare const tokenRegistry: TokenRegistry;
25
+
26
+ export declare function createTheme(
27
+ tokens: Record<string, any>,
28
+ options?: CreateThemeOptions
29
+ ): ThemeResult;
30
+
31
+ export declare function activateTheme(name: string): void;
32
+
33
+ export declare function token(path: string, fallback?: string): string;
package/types/v4.d.ts ADDED
@@ -0,0 +1,191 @@
1
+ // Type definitions for tailwind-to-style v4
2
+ // Unified API type declarations
3
+
4
+ // ============================================================================
5
+ // Core Types
6
+ // ============================================================================
7
+
8
+ type ClassValue = string | number | boolean | null | undefined | ClassObject | ClassArray;
9
+ type ClassObject = Record<string, any>;
10
+ type ClassArray = ClassValue[];
11
+
12
+ // ============================================================================
13
+ // tw() — The Main Function
14
+ // ============================================================================
15
+
16
+ /**
17
+ * Variants definition for tw()
18
+ */
19
+ interface TwVariantsDefinition {
20
+ [variantName: string]: {
21
+ [optionKey: string]: string | { _?: string; [key: string]: string | undefined };
22
+ };
23
+ }
24
+
25
+ /**
26
+ * Variant props inferred from definition
27
+ */
28
+ type TwVariantProps<V extends TwVariantsDefinition> = {
29
+ [K in keyof V]?: keyof V[K] | boolean;
30
+ };
31
+
32
+ /**
33
+ * Variant selector function returned by tw() in Mode 3
34
+ */
35
+ interface TwVariantFunction<V extends TwVariantsDefinition> {
36
+ (props?: TwVariantProps<V>): string;
37
+ merge(props?: TwVariantProps<V>, ...additionalClasses: ClassValue[]): string;
38
+ merge(...additionalClasses: ClassValue[]): string;
39
+ raw(): TwVariantsConfig<V>;
40
+ }
41
+
42
+ /**
43
+ * Slots definition for tw()
44
+ */
45
+ interface TwSlotsDefinition {
46
+ [slotName: string]: string | { _?: string; [key: string]: string | undefined };
47
+ }
48
+
49
+ /**
50
+ * Slots function returned by tw() in Mode 4
51
+ */
52
+ interface TwSlotsFunction<S extends TwSlotsDefinition, V extends TwVariantsDefinition> {
53
+ (props?: TwVariantProps<V>): { [K in keyof S]: string };
54
+ merge(props?: TwVariantProps<V>, slotOverrides?: Partial<{ [K in keyof S]: string }>): { [K in keyof S]: string };
55
+ raw(): TwSlotsConfig<S, V>;
56
+ }
57
+
58
+ /**
59
+ * Config for tw() Mode 3 (variants)
60
+ */
61
+ interface TwVariantsConfig<V extends TwVariantsDefinition = TwVariantsDefinition> {
62
+ name?: string;
63
+ base?: string | { _?: string; [key: string]: string | undefined };
64
+ variants: V;
65
+ compoundVariants?: Array<{ class?: string; className?: string; [key: string]: any }>;
66
+ defaultVariants?: { [K in keyof V]?: keyof V[K] | boolean };
67
+ responsiveVariants?: (keyof V)[];
68
+ prefix?: string;
69
+ hash?: boolean;
70
+ hashLength?: number;
71
+ inject?: boolean;
72
+ }
73
+
74
+ /**
75
+ * Config for tw() Mode 4 (slots)
76
+ */
77
+ interface TwSlotsConfig<
78
+ S extends TwSlotsDefinition = TwSlotsDefinition,
79
+ V extends TwVariantsDefinition = TwVariantsDefinition
80
+ > {
81
+ name?: string;
82
+ slots: S;
83
+ variants?: V;
84
+ compoundVariants?: Array<{ class?: string; className?: string; [key: string]: any }>;
85
+ defaultVariants?: { [K in keyof V]?: keyof V[K] | boolean };
86
+ prefix?: string;
87
+ hash?: boolean;
88
+ hashLength?: number;
89
+ inject?: boolean;
90
+ }
91
+
92
+ /**
93
+ * Config for tw() Mode 2 (named class — object form)
94
+ */
95
+ interface TwBasicConfig {
96
+ name?: string;
97
+ _?: string;
98
+ prefix?: string;
99
+ hash?: boolean;
100
+ hashLength?: number;
101
+ inject?: boolean;
102
+ [key: string]: any;
103
+ }
104
+
105
+ /**
106
+ * The unified tw() function.
107
+ */
108
+ interface TwFunction {
109
+ /** Mode 1: String → atomic CSS classes */
110
+ (classes: string): string;
111
+
112
+ /** Mode 2: Named class → scoped className */
113
+ (name: string, classes: string): string;
114
+
115
+ /** Mode 3: Variants config → variant selector function */
116
+ <V extends TwVariantsDefinition>(config: TwVariantsConfig<V>): TwVariantFunction<V>;
117
+
118
+ /** Mode 4: Slots config → slots generator function */
119
+ <S extends TwSlotsDefinition, V extends TwVariantsDefinition>(config: TwSlotsConfig<S, V>): TwSlotsFunction<S, V>;
120
+
121
+ /** Mode 2/3/4: Generic object config */
122
+ (config: TwBasicConfig): string;
123
+
124
+ /** Extract all generated CSS (for SSR) */
125
+ extractCSS(): string;
126
+
127
+ /** Clear internal caches */
128
+ clearCache(): void;
129
+
130
+ /** Configure global settings */
131
+ config(options: {
132
+ prefix?: string;
133
+ hash?: boolean;
134
+ hashLength?: number;
135
+ inject?: boolean;
136
+ deduplicate?: boolean;
137
+ }): void;
138
+ }
139
+
140
+ export declare const tw: TwFunction;
141
+
142
+ // ============================================================================
143
+ // tws() — Inline Style Converter
144
+ // ============================================================================
145
+
146
+ /**
147
+ * Convert Tailwind classes to inline CSS string or JSON object.
148
+ */
149
+ export declare function tws(classNames: string, convertToJson?: false): string;
150
+ export declare function tws(classNames: string, convertToJson: true): Record<string, string>;
151
+ export declare function tws(classNames: string, convertToJson?: boolean): string | Record<string, string>;
152
+
153
+ // ============================================================================
154
+ // cx() — Conditional Class Names
155
+ // ============================================================================
156
+
157
+ /**
158
+ * Conditionally join class names.
159
+ */
160
+ export declare function cx(...args: ClassValue[]): string;
161
+
162
+ export declare namespace cx {
163
+ function with_(...baseArgs: ClassValue[]): (...args: ClassValue[]) => string;
164
+ export { with_ as with };
165
+ }
166
+
167
+ // ============================================================================
168
+ // SSR
169
+ // ============================================================================
170
+
171
+ export interface SSRCollectorOptions {
172
+ dedupe?: boolean;
173
+ minify?: boolean;
174
+ sort?: boolean;
175
+ }
176
+
177
+ export interface SSRCollector {
178
+ extract(options?: { id?: string; nonce?: string; minify?: boolean }): string;
179
+ getCSS(): string;
180
+ getStyleTag(options?: { id?: string; nonce?: string }): string;
181
+ reset(): void;
182
+ stats(): { ruleCount: number; uniqueCount: number; totalSize: number };
183
+ }
184
+
185
+ export declare function createSSRCollector(options?: SSRCollectorOptions): SSRCollector;
186
+
187
+ // ============================================================================
188
+ // Default Export
189
+ // ============================================================================
190
+
191
+ export default tw;