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/dist/index.d.ts CHANGED
@@ -2,7 +2,61 @@
2
2
  // Project: https://github.com/Bigetion/tailwind-to-style
3
3
  // Definitions by: Bigetion
4
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
+ // ============================================================================
5
58
  // Logger types
59
+ // ============================================================================
6
60
  export class Logger {
7
61
  constructor(level?: 'debug' | 'info' | 'warn' | 'error' | 'silent');
8
62
  setLevel(level: 'debug' | 'info' | 'warn' | 'error' | 'silent'): void;
@@ -202,34 +256,44 @@ export interface VariantsDefinition {
202
256
  [variantName: string]: VariantOptions;
203
257
  }
204
258
 
205
- /**
206
- * Compound variant definition
259
+ /** * Compound variant definition - strict typing for better autocomplete
207
260
  */
208
- export interface CompoundVariant {
209
- [variantName: string]: string | boolean | string[];
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> {
210
267
  class?: string;
211
268
  className?: string;
212
269
  }
213
270
 
214
271
  /**
215
- * Default variants definition
272
+ * Default variants definition - ensures only valid variant keys and values
216
273
  */
217
- export interface DefaultVariants {
218
- [variantName: string]: string | boolean;
219
- }
274
+ export type DefaultVariants<V extends VariantsDefinition> = {
275
+ [K in keyof V]?: keyof V[K];
276
+ };
220
277
 
221
278
  /**
222
- * Configuration for twsxVariants
279
+ * Variant props - infers types from variants definition
223
280
  */
224
- export interface TwsxVariantsConfig {
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> {
225
289
  /** Base Tailwind classes applied to all variants */
226
290
  base?: string;
227
291
  /** Variant definitions with their options */
228
- variants?: VariantsDefinition;
292
+ variants?: V;
229
293
  /** Compound variant rules for multi-variant combinations */
230
- compoundVariants?: CompoundVariant[];
294
+ compoundVariants?: CompoundVariantWithClass<V>[];
231
295
  /** Default variant values */
232
- defaultVariants?: DefaultVariants;
296
+ defaultVariants?: DefaultVariants<V>;
233
297
  /**
234
298
  * Nested selectors for child elements.
235
299
  * Keys are CSS selectors relative to the parent className.
@@ -246,26 +310,29 @@ export interface TwsxVariantsConfig {
246
310
  }
247
311
 
248
312
  /**
249
- * Props type for variant function
313
+ * Props type for variant function - DEPRECATED, use VariantProps<V> instead
250
314
  */
251
- export interface VariantProps {
315
+ export interface VariantPropsLegacy {
252
316
  [variantName: string]: string | boolean | undefined;
253
317
  }
254
318
 
255
319
  /**
256
320
  * Variant function returned by twsxVariants
321
+ * Generic type V allows for type-safe variant props
257
322
  */
258
- export type VariantFunction = (props?: VariantProps) => string;
323
+ export type VariantFunction<V extends VariantsDefinition = VariantsDefinition> =
324
+ (props?: Partial<VariantProps<V>>) => string;
259
325
 
260
326
  /**
261
- * Create a variant-based style generator (similar to tailwind-variants)
327
+ * Create a variant-based style generator with full type safety
262
328
  * Supports base styles, variants, compound variants, and default variants
263
329
  *
264
330
  * Auto-injects CSS for all variant combinations and returns a function to build class names
265
331
  *
332
+ * @template V - Variants definition type for type-safe props
266
333
  * @param className - CSS class name (e.g., '.btn' or 'btn')
267
334
  * @param config - Configuration object with base, variants, compoundVariants, defaultVariants
268
- * @returns A function that accepts variant props and returns the class name string
335
+ * @returns A type-safe function that accepts variant props and returns the class name string
269
336
  *
270
337
  * @example
271
338
  * const btn = twsxVariants('.btn', {
@@ -274,12 +341,28 @@ export type VariantFunction = (props?: VariantProps) => string;
274
341
  * variant: { solid: 'bg-blue-500', outline: 'bg-transparent border-2' },
275
342
  * size: { sm: 'text-sm', md: 'text-base', lg: 'text-lg' }
276
343
  * },
344
+ * compoundVariants: [
345
+ * { variant: 'outline', size: 'lg', class: 'border-4' }
346
+ * ],
277
347
  * defaultVariants: { variant: 'solid', size: 'md' }
278
348
  * });
279
- * // CSS generated: .btn, .btn-sm, .btn-lg, .btn-outline, .btn-outline-sm, etc.
349
+ *
350
+ * // CSS auto-generated for all combinations
351
+ * // Type-safe usage with autocomplete:
280
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)
281
355
  */
282
- export function twsxVariants(className: string, config?: TwsxVariantsConfig): VariantFunction;
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;
283
366
 
284
367
  /**
285
368
  * Performance utilities for debugging and monitoring