tailwind-to-style 3.1.2 → 3.2.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/README.md +535 -282
- package/dist/core/tws.cjs +984 -0
- package/dist/core/tws.d.ts +14 -0
- package/dist/core/tws.esm.js +981 -0
- package/dist/core/tws.esm.js.map +1 -0
- package/dist/core/twsx.cjs +9068 -0
- package/dist/core/twsx.d.ts +26 -0
- package/dist/core/twsx.esm.js +9066 -0
- package/dist/core/twsx.esm.js.map +1 -0
- package/dist/core/twsxVariants.cjs +9542 -0
- package/dist/core/twsxVariants.d.ts +85 -0
- package/dist/core/twsxVariants.esm.js +9541 -0
- package/dist/core/twsxVariants.esm.js.map +1 -0
- package/dist/cx.cjs +115 -0
- package/dist/cx.d.ts +41 -0
- package/dist/cx.esm.js +111 -0
- package/dist/cx.esm.js.map +1 -0
- package/dist/index.cjs +623 -242
- package/dist/index.d.ts +103 -20
- package/dist/index.esm.js +619 -243
- package/dist/index.esm.js.map +1 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/utils/index.cjs +1797 -0
- package/dist/utils/index.d.ts +44 -0
- package/dist/utils/index.esm.js +1795 -0
- package/dist/utils/index.esm.js.map +1 -0
- package/package.json +51 -7
- package/types/core/tws.d.ts +14 -0
- package/types/core/twsx.d.ts +26 -0
- package/types/core/twsxVariants.d.ts +85 -0
- package/types/cx.d.ts +41 -0
- package/types/index.d.ts +382 -0
- package/types/utils/index.d.ts +44 -0
- package/README.v2-backup.md +0 -2456
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
// Type definitions for tailwind-to-style
|
|
2
|
+
// Project: https://github.com/Bigetion/tailwind-to-style
|
|
3
|
+
// Definitions by: Bigetion
|
|
4
|
+
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// Environment Detection
|
|
7
|
+
// ============================================================================
|
|
8
|
+
|
|
9
|
+
/** True when running in a browser environment (window & document available) */
|
|
10
|
+
export const IS_BROWSER: boolean;
|
|
11
|
+
/** True when running in a server/Node.js environment */
|
|
12
|
+
export const IS_SERVER: boolean;
|
|
13
|
+
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// SSR (Server-Side Rendering) Support
|
|
16
|
+
// ============================================================================
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Start collecting CSS for server-side rendering.
|
|
20
|
+
* Call before rendering your application.
|
|
21
|
+
*/
|
|
22
|
+
export function startSSR(): void;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Stop collecting CSS and return all collected CSS as a single string.
|
|
26
|
+
* Call after rendering your application.
|
|
27
|
+
*/
|
|
28
|
+
export function stopSSR(): string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get currently collected CSS without stopping collection.
|
|
32
|
+
*/
|
|
33
|
+
export function getSSRStyles(): string;
|
|
34
|
+
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// Conditional Class Name Builder
|
|
37
|
+
// ============================================================================
|
|
38
|
+
|
|
39
|
+
type ClassValue = string | number | boolean | null | undefined | ClassObject | ClassArray;
|
|
40
|
+
type ClassObject = Record<string, any>;
|
|
41
|
+
type ClassArray = ClassValue[];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Conditionally join class names into a single string.
|
|
45
|
+
* Similar to clsx/classnames but built-in.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* cx('bg-blue-500', isActive && 'ring-2', { 'opacity-50': isDisabled })
|
|
49
|
+
*/
|
|
50
|
+
export function cx(...args: ClassValue[]): string;
|
|
51
|
+
|
|
52
|
+
export namespace cx {
|
|
53
|
+
function with_(...baseArgs: ClassValue[]): (...args: ClassValue[]) => string;
|
|
54
|
+
export { with_ as with };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Logger types
|
|
59
|
+
// ============================================================================
|
|
60
|
+
export class Logger {
|
|
61
|
+
constructor(level?: 'debug' | 'info' | 'warn' | 'error' | 'silent');
|
|
62
|
+
setLevel(level: 'debug' | 'info' | 'warn' | 'error' | 'silent'): void;
|
|
63
|
+
getLevel(): string;
|
|
64
|
+
debug(message: string, ...args: any[]): void;
|
|
65
|
+
info(message: string, ...args: any[]): void;
|
|
66
|
+
warn(message: string, ...args: any[]): void;
|
|
67
|
+
error(message: string, ...args: any[]): void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const logger: Logger;
|
|
71
|
+
|
|
72
|
+
// LRU Cache types
|
|
73
|
+
export class LRUCache<K = any, V = any> {
|
|
74
|
+
constructor(maxSize?: number);
|
|
75
|
+
get(key: K): V | undefined;
|
|
76
|
+
set(key: K, value: V): void;
|
|
77
|
+
has(key: K): boolean;
|
|
78
|
+
clear(): void;
|
|
79
|
+
delete(key: K): boolean;
|
|
80
|
+
readonly size: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Error handling types
|
|
84
|
+
export class TwsError extends Error {
|
|
85
|
+
constructor(message: string, context?: Record<string, any>);
|
|
86
|
+
context: Record<string, any>;
|
|
87
|
+
timestamp: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function onError(handler: (error: TwsError) => void): () => void;
|
|
91
|
+
export function handleError(error: Error, context?: Record<string, any>): TwsError;
|
|
92
|
+
|
|
93
|
+
// Tailwind cache types
|
|
94
|
+
export class TailwindCache {
|
|
95
|
+
getOrGenerate(generateFn: Function, convertFn: Function): any;
|
|
96
|
+
getCssString(): string | null;
|
|
97
|
+
getCssObject(): Record<string, string> | null;
|
|
98
|
+
isInitialized(): boolean;
|
|
99
|
+
reset(): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function getTailwindCache(): TailwindCache;
|
|
103
|
+
export function resetTailwindCache(): void;
|
|
104
|
+
|
|
105
|
+
// Configuration and Plugin System
|
|
106
|
+
export interface ThemeExtension {
|
|
107
|
+
colors?: Record<string, string | Record<string, string>>;
|
|
108
|
+
spacing?: Record<string, string>;
|
|
109
|
+
borderRadius?: Record<string, string>;
|
|
110
|
+
fontSize?: Record<string, string>;
|
|
111
|
+
[key: string]: any;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface TailwindConfig {
|
|
115
|
+
theme?: {
|
|
116
|
+
extend?: ThemeExtension;
|
|
117
|
+
colors?: Record<string, string | Record<string, string>>;
|
|
118
|
+
spacing?: Record<string, string>;
|
|
119
|
+
[key: string]: any;
|
|
120
|
+
};
|
|
121
|
+
plugins?: Plugin[];
|
|
122
|
+
corePlugins?: Record<string, boolean>;
|
|
123
|
+
prefix?: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface Plugin {
|
|
127
|
+
name: string;
|
|
128
|
+
type: string;
|
|
129
|
+
utilities?: Record<string, string | Record<string, string>>;
|
|
130
|
+
components?: Record<string, string | Record<string, string>>;
|
|
131
|
+
handler?: any;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface UtilityPluginConfig {
|
|
135
|
+
prefix: string;
|
|
136
|
+
values: Record<string, string>;
|
|
137
|
+
formatter: (value: string, key: string) => Record<string, string>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Configure tailwind-to-style with custom theme and plugins
|
|
142
|
+
*/
|
|
143
|
+
export function configure(config: TailwindConfig): void;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get current configuration
|
|
147
|
+
*/
|
|
148
|
+
export function getConfig(): TailwindConfig;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Reset configuration to defaults
|
|
152
|
+
*/
|
|
153
|
+
export function resetConfig(): void;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Create a custom plugin
|
|
157
|
+
*/
|
|
158
|
+
export function createPlugin(name: string, definition: {
|
|
159
|
+
utilities?: Record<string, string | Record<string, string>>;
|
|
160
|
+
components?: Record<string, string | Record<string, string>>;
|
|
161
|
+
handler?: Function;
|
|
162
|
+
}): Plugin;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Create a utility plugin with dynamic values
|
|
166
|
+
*/
|
|
167
|
+
export function createUtilityPlugin(name: string, config: UtilityPluginConfig): Plugin;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Create a variant plugin
|
|
171
|
+
*/
|
|
172
|
+
export function createVariantPlugin(name: string, handler: (selector: string) => string): Plugin;
|
|
173
|
+
|
|
174
|
+
// Main function types
|
|
175
|
+
export interface TwsxOptions {
|
|
176
|
+
inject?: boolean;
|
|
177
|
+
[key: string]: any;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface PerformanceStats {
|
|
181
|
+
cacheStats: {
|
|
182
|
+
cssResolution: number;
|
|
183
|
+
configOptions: number;
|
|
184
|
+
parseSelector: number;
|
|
185
|
+
encodeBracket: number;
|
|
186
|
+
decodeBracket: number;
|
|
187
|
+
};
|
|
188
|
+
injectionStats: {
|
|
189
|
+
uniqueStylesheets: number;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface PerformanceUtils {
|
|
194
|
+
getStats(): PerformanceStats;
|
|
195
|
+
clearCaches(): void;
|
|
196
|
+
enablePerformanceLogging(enabled?: boolean): void;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface StyleObject {
|
|
200
|
+
[selector: string]: string | StyleObject | Array<string | StyleObject>;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Converts Tailwind CSS classes to inline styles or JSON object
|
|
205
|
+
* @param classNames - String containing Tailwind classes to convert
|
|
206
|
+
* @param convertToJson - If true, returns JSON object, if false returns CSS string
|
|
207
|
+
* @returns CSS inline string or style JSON object
|
|
208
|
+
*/
|
|
209
|
+
export function tws(classNames: string, convertToJson?: false): string;
|
|
210
|
+
export function tws(classNames: string, convertToJson: true): Record<string, string>;
|
|
211
|
+
export function tws(classNames: string, convertToJson?: boolean): string | Record<string, string>;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Generates CSS string from style object with SCSS-like syntax
|
|
215
|
+
* Supports nested selectors, state variants, responsive variants, and @css directives
|
|
216
|
+
* @param obj - Object with SCSS-like style format
|
|
217
|
+
* @param options - Additional options
|
|
218
|
+
* @returns Generated CSS string
|
|
219
|
+
*/
|
|
220
|
+
export function twsx(obj: StyleObject, options?: TwsxOptions): string;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Debounced version of tws function with performance monitoring
|
|
224
|
+
* @param classNames - String containing Tailwind classes to convert
|
|
225
|
+
* @param convertToJson - If true, returns JSON object, if false returns CSS string
|
|
226
|
+
* @returns CSS inline string or style JSON object
|
|
227
|
+
*/
|
|
228
|
+
export const debouncedTws: typeof tws;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Debounced version of twsx function with performance monitoring
|
|
232
|
+
* @param obj - Object with SCSS-like style format
|
|
233
|
+
* @param options - Additional options
|
|
234
|
+
* @returns Generated CSS string
|
|
235
|
+
*/
|
|
236
|
+
export const debouncedTwsx: typeof twsx;
|
|
237
|
+
|
|
238
|
+
// Variant System Types (similar to tailwind-variants)
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Variant option values - can be string classes or nested object
|
|
242
|
+
*/
|
|
243
|
+
export type VariantValue = string;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Variant options definition
|
|
247
|
+
*/
|
|
248
|
+
export interface VariantOptions {
|
|
249
|
+
[optionKey: string]: VariantValue;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Variants definition object
|
|
254
|
+
*/
|
|
255
|
+
export interface VariantsDefinition {
|
|
256
|
+
[variantName: string]: VariantOptions;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** * Compound variant definition - strict typing for better autocomplete
|
|
260
|
+
*/
|
|
261
|
+
export interface CompoundVariant<V extends VariantsDefinition = VariantsDefinition> {
|
|
262
|
+
[K in keyof V]?: keyof V[K] | (keyof V[K])[];
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface CompoundVariantWithClass<V extends VariantsDefinition = VariantsDefinition>
|
|
266
|
+
extends CompoundVariant<V> {
|
|
267
|
+
class?: string;
|
|
268
|
+
className?: string;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Default variants definition - ensures only valid variant keys and values
|
|
273
|
+
*/
|
|
274
|
+
export type DefaultVariants<V extends VariantsDefinition> = {
|
|
275
|
+
[K in keyof V]?: keyof V[K];
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Variant props - infers types from variants definition
|
|
280
|
+
*/
|
|
281
|
+
export type VariantProps<V extends VariantsDefinition> = {
|
|
282
|
+
[K in keyof V]?: keyof V[K] | (keyof V[K])[];
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Configuration for twsxVariants with strict typing
|
|
287
|
+
*/
|
|
288
|
+
export interface TwsxVariantsConfig<V extends VariantsDefinition = VariantsDefinition> {
|
|
289
|
+
/** Base Tailwind classes applied to all variants */
|
|
290
|
+
base?: string;
|
|
291
|
+
/** Variant definitions with their options */
|
|
292
|
+
variants?: V;
|
|
293
|
+
/** Compound variant rules for multi-variant combinations */
|
|
294
|
+
compoundVariants?: CompoundVariantWithClass<V>[];
|
|
295
|
+
/** Default variant values */
|
|
296
|
+
defaultVariants?: DefaultVariants<V>;
|
|
297
|
+
/**
|
|
298
|
+
* Nested selectors for child elements.
|
|
299
|
+
* Keys are CSS selectors relative to the parent className.
|
|
300
|
+
* Use '&' prefix for attached selectors (e.g., '&.active' -> '.alert.active')
|
|
301
|
+
* Without '&', creates descendant selector (e.g., '.icon' -> '.alert .icon')
|
|
302
|
+
* @example
|
|
303
|
+
* nested: {
|
|
304
|
+
* '.icon': 'flex-shrink-0 mt-0.5',
|
|
305
|
+
* '.content': 'flex-1',
|
|
306
|
+
* '&.dismissable': 'pr-10'
|
|
307
|
+
* }
|
|
308
|
+
*/
|
|
309
|
+
nested?: Record<string, string>;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Props type for variant function - DEPRECATED, use VariantProps<V> instead
|
|
314
|
+
*/
|
|
315
|
+
export interface VariantPropsLegacy {
|
|
316
|
+
[variantName: string]: string | boolean | undefined;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Variant function returned by twsxVariants
|
|
321
|
+
* Generic type V allows for type-safe variant props
|
|
322
|
+
*/
|
|
323
|
+
export type VariantFunction<V extends VariantsDefinition = VariantsDefinition> =
|
|
324
|
+
(props?: Partial<VariantProps<V>>) => string;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Create a variant-based style generator with full type safety
|
|
328
|
+
* Supports base styles, variants, compound variants, and default variants
|
|
329
|
+
*
|
|
330
|
+
* Auto-injects CSS for all variant combinations and returns a function to build class names
|
|
331
|
+
*
|
|
332
|
+
* @template V - Variants definition type for type-safe props
|
|
333
|
+
* @param className - CSS class name (e.g., '.btn' or 'btn')
|
|
334
|
+
* @param config - Configuration object with base, variants, compoundVariants, defaultVariants
|
|
335
|
+
* @returns A type-safe function that accepts variant props and returns the class name string
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* const btn = twsxVariants('.btn', {
|
|
339
|
+
* base: 'px-4 py-2 rounded font-medium',
|
|
340
|
+
* variants: {
|
|
341
|
+
* variant: { solid: 'bg-blue-500', outline: 'bg-transparent border-2' },
|
|
342
|
+
* size: { sm: 'text-sm', md: 'text-base', lg: 'text-lg' }
|
|
343
|
+
* },
|
|
344
|
+
* compoundVariants: [
|
|
345
|
+
* { variant: 'outline', size: 'lg', class: 'border-4' }
|
|
346
|
+
* ],
|
|
347
|
+
* defaultVariants: { variant: 'solid', size: 'md' }
|
|
348
|
+
* });
|
|
349
|
+
*
|
|
350
|
+
* // CSS auto-generated for all combinations
|
|
351
|
+
* // Type-safe usage with autocomplete:
|
|
352
|
+
* btn({ variant: 'outline', size: 'lg' }) // Returns: "btn btn-outline-lg"
|
|
353
|
+
* btn({ variant: 'solid' }) // Returns: "btn btn-solid"
|
|
354
|
+
* btn() // Returns: "btn" (uses defaults)
|
|
355
|
+
*/
|
|
356
|
+
export function twsxVariants<V extends VariantsDefinition>(
|
|
357
|
+
className: string,
|
|
358
|
+
config?: TwsxVariantsConfig<V>
|
|
359
|
+
): VariantFunction<V>;
|
|
360
|
+
|
|
361
|
+
// Overload for legacy support without generics
|
|
362
|
+
export function twsxVariants(
|
|
363
|
+
className: string,
|
|
364
|
+
config?: TwsxVariantsConfig
|
|
365
|
+
): VariantFunction;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Performance utilities for debugging and monitoring
|
|
369
|
+
*/
|
|
370
|
+
export const performanceUtils: PerformanceUtils;
|
|
371
|
+
|
|
372
|
+
// Default export (if needed)
|
|
373
|
+
declare const tailwindToStyle: {
|
|
374
|
+
tws: typeof tws;
|
|
375
|
+
twsx: typeof twsx;
|
|
376
|
+
twsxVariants: typeof twsxVariants;
|
|
377
|
+
debouncedTws: typeof debouncedTws;
|
|
378
|
+
debouncedTwsx: typeof debouncedTwsx;
|
|
379
|
+
performanceUtils: typeof performanceUtils;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export default tailwindToStyle;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Type definitions for tailwind-to-style/utils
|
|
2
|
+
// Tree-shakeable import: import { logger, LRUCache } from 'tailwind-to-style/utils'
|
|
3
|
+
|
|
4
|
+
export class Logger {
|
|
5
|
+
constructor(level?: 'debug' | 'info' | 'warn' | 'error' | 'silent');
|
|
6
|
+
setLevel(level: 'debug' | 'info' | 'warn' | 'error' | 'silent'): void;
|
|
7
|
+
getLevel(): string;
|
|
8
|
+
debug(message: string, ...args: any[]): void;
|
|
9
|
+
info(message: string, ...args: any[]): void;
|
|
10
|
+
warn(message: string, ...args: any[]): void;
|
|
11
|
+
error(message: string, ...args: any[]): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const logger: Logger;
|
|
15
|
+
|
|
16
|
+
export class LRUCache<K = any, V = any> {
|
|
17
|
+
constructor(maxSize?: number);
|
|
18
|
+
get(key: K): V | undefined;
|
|
19
|
+
set(key: K, value: V): void;
|
|
20
|
+
has(key: K): boolean;
|
|
21
|
+
clear(): void;
|
|
22
|
+
delete(key: K): boolean;
|
|
23
|
+
readonly size: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class TwsError extends Error {
|
|
27
|
+
constructor(message: string, context?: Record<string, any>);
|
|
28
|
+
context: Record<string, any>;
|
|
29
|
+
timestamp: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function onError(handler: (error: TwsError) => void): () => void;
|
|
33
|
+
export function handleError(error: Error, context?: Record<string, any>): TwsError;
|
|
34
|
+
|
|
35
|
+
export class TailwindCache {
|
|
36
|
+
getOrGenerate(generateFn: Function, convertFn: Function): any;
|
|
37
|
+
getCssString(): string | null;
|
|
38
|
+
getCssObject(): Record<string, string> | null;
|
|
39
|
+
isInitialized(): boolean;
|
|
40
|
+
reset(): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getTailwindCache(): TailwindCache;
|
|
44
|
+
export function resetTailwindCache(): void;
|