tailwind-to-style 2.7.0 → 2.7.1

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 CHANGED
@@ -79,8 +79,8 @@ This will apply the Tailwind classes directly as inline styles in the React comp
79
79
 
80
80
  #### Features of `twsx`:
81
81
  - Allows **nested styles** similar to SCSS, enabling more complex CSS structures.
82
- - **Grouping**: Supports grouping utilities inside parentheses, making the code more readable and modular.
83
- - Fully supports **responsive variants** (`sm`, `md`, `lg`, etc.).
82
+ - **Grouping**: Supports grouping utilities inside parentheses, including responsive variants.
83
+ - Supports **responsive variants** (`sm`, `md`, `lg`, etc.) when used within Tailwind utility classes or in grouping syntax.
84
84
  - Handles **state variants** like `hover`, `focus`, and more.
85
85
  - Supports **dynamic utilities** such as `w-[300px]`, `bg-[rgba(0,0,0,0.5)]`.
86
86
  - **@css directive**: Apply custom CSS properties directly for more complex styles like transitions and animations.
@@ -232,6 +232,62 @@ console.log(styles);
232
232
  }
233
233
  ```
234
234
 
235
+ #### Responsive Variants:
236
+
237
+ Responsive variants work within Tailwind utility classes and in grouping syntax:
238
+
239
+ ```javascript
240
+ const styles = twsx({
241
+ ".responsive-card": [
242
+ "w-full md:w-1/2 lg:w-1/3 p-4 bg-white",
243
+ {
244
+ "&:hover": "shadow-lg transform:scale-105"
245
+ }
246
+ ],
247
+ ".grouped-responsive": "text-sm md:(text-lg px-6) lg:(text-xl px-8)"
248
+ });
249
+ ```
250
+
251
+ **Output**:
252
+ ```css
253
+ .responsive-card {
254
+ width: 100%;
255
+ padding: 1rem;
256
+ background-color: white;
257
+ }
258
+ @media (min-width: 768px) {
259
+ .responsive-card {
260
+ width: 50%;
261
+ }
262
+ }
263
+ @media (min-width: 1024px) {
264
+ .responsive-card {
265
+ width: 33.333333%;
266
+ }
267
+ }
268
+ .responsive-card:hover {
269
+ box-shadow: 0 10px 15px rgba(0,0,0,0.1);
270
+ transform: scale(1.05);
271
+ }
272
+ .grouped-responsive {
273
+ font-size: 0.875rem;
274
+ }
275
+ @media (min-width: 768px) {
276
+ .grouped-responsive {
277
+ font-size: 1.125rem;
278
+ padding-left: 1.5rem;
279
+ padding-right: 1.5rem;
280
+ }
281
+ }
282
+ @media (min-width: 1024px) {
283
+ .grouped-responsive {
284
+ font-size: 1.25rem;
285
+ padding-left: 2rem;
286
+ padding-right: 2rem;
287
+ }
288
+ }
289
+ ```
290
+
235
291
  #### `@css` Direct CSS Properties:
236
292
 
237
293
  With the `@css` feature, you can directly add CSS properties that aren't available as Tailwind utilities or when you need more complex CSS values like transitions, animations, or custom properties.
@@ -285,7 +341,7 @@ The `@css` feature is particularly helpful for properties that require complex v
285
341
 
286
342
  #### Advanced `@css` Examples:
287
343
 
288
- You can combine `@css` with responsive and state variants:
344
+ You can combine `@css` with state variants:
289
345
 
290
346
  ```javascript
291
347
  const styles = twsx({
@@ -293,20 +349,18 @@ const styles = twsx({
293
349
  "bg-white rounded-lg shadow-xl",
294
350
  {
295
351
  "@css": {
296
- transform: "translateY(0)",
297
- transition: "transform 0.3s ease-out, opacity 0.2s ease-in-out",
352
+ transform: "translateX(0px)",
353
+ transition: "all 0.3s ease-out",
298
354
  "will-change": "transform, opacity"
299
355
  },
300
356
  "&.hidden": [
301
357
  "opacity-0",
302
358
  {
303
359
  "@css": {
304
- transform: "translateY(-20px)"
360
+ transform: "translateX(-100px)"
305
361
  }
306
362
  }
307
- ],
308
- "md:@css width": "500px",
309
- "lg:@css width": "700px"
363
+ ]
310
364
  }
311
365
  ]
312
366
  });
@@ -318,26 +372,24 @@ const styles = twsx({
318
372
  background-color: white;
319
373
  border-radius: 0.5rem;
320
374
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
321
- transform: translateY(0);
322
- transition: transform 0.3s ease-out, opacity 0.2s ease-in-out;
375
+ transform: translateX(0px);
376
+ transition: all 0.3s ease-out;
323
377
  will-change: transform, opacity;
324
378
  }
325
379
  .modal.hidden {
326
380
  opacity: 0;
327
- transform: translateY(-20px);
328
- }
329
- @media (min-width: 768px) {
330
- .modal {
331
- width: 500px;
332
- }
333
- }
334
- @media (min-width: 1024px) {
335
- .modal {
336
- width: 700px;
337
- }
381
+ transform: translateX(-100px);
338
382
  }
339
383
  ```
340
384
 
385
+ For responsive styles, you can use standard Tailwind responsive utilities within your classes:
386
+
387
+ ```javascript
388
+ const styles = twsx({
389
+ ".responsive-box": "w-full md:w-1/2 lg:w-1/3 p-4 bg-blue-500"
390
+ });
391
+ ```
392
+
341
393
  The `@css` feature provides a powerful way to bridge the gap between Tailwind's utility classes and custom CSS when needed, without leaving the `twsx` syntax.
342
394
 
343
395
  ### Inject Option (Browser Only)
@@ -430,9 +482,9 @@ const complexStyles = twsx({
430
482
  ".hero": [
431
483
  "bg-gradient-to-br from-indigo-900 to-purple-900 min-h-screen",
432
484
  {
433
- "h1": "text-6xl font-bold text-white",
434
- "@media (max-width: 768px)": {
435
- "h1": "text-4xl"
485
+ "h1": "text-6xl font-bold text-white md:text-4xl",
486
+ "@css": {
487
+ transition: "font-size 0.3s ease-in-out"
436
488
  }
437
489
  }
438
490
  ]
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v2.7.0
2
+ * tailwind-to-style v2.7.1
3
3
  * Convert tailwind classes to inline style
4
4
  *
5
5
  * @author Bigetion
package/dist/index.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v2.7.0
2
+ * tailwind-to-style v2.7.1
3
3
  * Convert tailwind classes to inline style
4
4
  *
5
5
  * @author Bigetion
@@ -0,0 +1,82 @@
1
+ // Type definitions for tailwind-to-style
2
+ // Project: https://github.com/your-username/tailwind-to-style
3
+ // Definitions by: Your Name <https://github.com/your-username>
4
+
5
+ export interface TwsxOptions {
6
+ inject?: boolean;
7
+ [key: string]: any;
8
+ }
9
+
10
+ export interface PerformanceStats {
11
+ cacheStats: {
12
+ cssResolution: number;
13
+ configOptions: number;
14
+ parseSelector: number;
15
+ encodeBracket: number;
16
+ decodeBracket: number;
17
+ };
18
+ injectionStats: {
19
+ uniqueStylesheets: number;
20
+ };
21
+ }
22
+
23
+ export interface PerformanceUtils {
24
+ getStats(): PerformanceStats;
25
+ clearCaches(): void;
26
+ enablePerformanceLogging(enabled?: boolean): void;
27
+ }
28
+
29
+ export interface StyleObject {
30
+ [selector: string]: string | StyleObject | Array<string | StyleObject>;
31
+ }
32
+
33
+ /**
34
+ * Converts Tailwind CSS classes to inline styles or JSON object
35
+ * @param classNames - String containing Tailwind classes to convert
36
+ * @param convertToJson - If true, returns JSON object, if false returns CSS string
37
+ * @returns CSS inline string or style JSON object
38
+ */
39
+ export function tws(classNames: string, convertToJson?: false): string;
40
+ export function tws(classNames: string, convertToJson: true): Record<string, string>;
41
+ export function tws(classNames: string, convertToJson?: boolean): string | Record<string, string>;
42
+
43
+ /**
44
+ * Generates CSS string from style object with SCSS-like syntax
45
+ * Supports nested selectors, state variants, responsive variants, and @css directives
46
+ * @param obj - Object with SCSS-like style format
47
+ * @param options - Additional options
48
+ * @returns Generated CSS string
49
+ */
50
+ export function twsx(obj: StyleObject, options?: TwsxOptions): string;
51
+
52
+ /**
53
+ * Debounced version of tws function with performance monitoring
54
+ * @param classNames - String containing Tailwind classes to convert
55
+ * @param convertToJson - If true, returns JSON object, if false returns CSS string
56
+ * @returns CSS inline string or style JSON object
57
+ */
58
+ export const debouncedTws: typeof tws;
59
+
60
+ /**
61
+ * Debounced version of twsx function with performance monitoring
62
+ * @param obj - Object with SCSS-like style format
63
+ * @param options - Additional options
64
+ * @returns Generated CSS string
65
+ */
66
+ export const debouncedTwsx: typeof twsx;
67
+
68
+ /**
69
+ * Performance utilities for debugging and monitoring
70
+ */
71
+ export const performanceUtils: PerformanceUtils;
72
+
73
+ // Default export (if needed)
74
+ declare const tailwindToStyle: {
75
+ tws: typeof tws;
76
+ twsx: typeof twsx;
77
+ debouncedTws: typeof debouncedTws;
78
+ debouncedTwsx: typeof debouncedTwsx;
79
+ performanceUtils: typeof performanceUtils;
80
+ };
81
+
82
+ export default tailwindToStyle;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v2.7.0
2
+ * tailwind-to-style v2.7.1
3
3
  * Convert tailwind classes to inline style
4
4
  *
5
5
  * @author Bigetion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-to-style",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "Convert tailwind classes to inline style",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
@@ -55,6 +55,7 @@
55
55
  "jest": "^28.1.0",
56
56
  "prettier": "^3.5.3",
57
57
  "rollup": "^2.75.0",
58
+ "rollup-plugin-copy": "^3.5.0",
58
59
  "rollup-plugin-terser": "^7.0.2",
59
60
  "terser": "^5.43.1",
60
61
  "webpack": "^5.99.9",