tailwind-to-style 2.6.3 → 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 +159 -22
- package/dist/index.browser.js +2172 -1491
- package/dist/index.cjs.js +2172 -1491
- package/dist/index.d.ts +82 -0
- package/dist/index.esm.js +2172 -1492
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +2 -1
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,
|
|
83
|
-
-
|
|
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
|
|
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: "
|
|
297
|
-
transition: "
|
|
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: "
|
|
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:
|
|
322
|
-
transition:
|
|
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:
|
|
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)
|
|
@@ -359,6 +411,91 @@ twsx({ ... }, { inject: false }) // CSS is NOT injected, just returned as string
|
|
|
359
411
|
|
|
360
412
|
> Note: This option only affects browser usage. In Node.js or SSR, no injection occurs.
|
|
361
413
|
|
|
414
|
+
## Performance Monitoring & Debugging (v2.7.0+)
|
|
415
|
+
|
|
416
|
+
Starting from version 2.7.0, `tailwind-to-style` includes built-in performance monitoring and debugging utilities to help you optimize your application and troubleshoot issues.
|
|
417
|
+
|
|
418
|
+
### Performance Utils
|
|
419
|
+
|
|
420
|
+
```javascript
|
|
421
|
+
import { performanceUtils } from "tailwind-to-style";
|
|
422
|
+
|
|
423
|
+
// Enable performance logging (logs operations > 5ms as warnings)
|
|
424
|
+
performanceUtils.enablePerformanceLogging(true);
|
|
425
|
+
|
|
426
|
+
// Get cache and injection statistics
|
|
427
|
+
const stats = performanceUtils.getStats();
|
|
428
|
+
console.log(stats);
|
|
429
|
+
// Output:
|
|
430
|
+
// {
|
|
431
|
+
// cacheStats: {
|
|
432
|
+
// cssResolution: 45,
|
|
433
|
+
// configOptions: 2,
|
|
434
|
+
// parseSelector: 23,
|
|
435
|
+
// encodeBracket: 12,
|
|
436
|
+
// decodeBracket: 8
|
|
437
|
+
// },
|
|
438
|
+
// injectionStats: {
|
|
439
|
+
// uniqueStylesheets: 15
|
|
440
|
+
// }
|
|
441
|
+
// }
|
|
442
|
+
|
|
443
|
+
// Clear all caches (useful for memory management)
|
|
444
|
+
performanceUtils.clearCaches();
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Performance Metrics
|
|
448
|
+
|
|
449
|
+
The library automatically tracks performance for key operations:
|
|
450
|
+
|
|
451
|
+
- **tws:total** - Total execution time for `tws()`
|
|
452
|
+
- **tws:parse** - Time spent parsing classes
|
|
453
|
+
- **tws:process** - Time spent processing classes
|
|
454
|
+
- **twsx:total** - Total execution time for `twsx()`
|
|
455
|
+
- **twsx:flatten** - Time spent flattening objects
|
|
456
|
+
- **twsx:generate** - Time spent generating CSS
|
|
457
|
+
- **css:inject** - Time spent injecting CSS to DOM
|
|
458
|
+
|
|
459
|
+
### Debounced Functions
|
|
460
|
+
|
|
461
|
+
For high-frequency usage, use the debounced versions:
|
|
462
|
+
|
|
463
|
+
```javascript
|
|
464
|
+
import { debouncedTws, debouncedTwsx } from "tailwind-to-style";
|
|
465
|
+
|
|
466
|
+
// Debounced versions (50ms for tws, 100ms for twsx)
|
|
467
|
+
const styles = debouncedTws("bg-red-500 p-4");
|
|
468
|
+
const complexStyles = debouncedTwsx({ ".card": "bg-white p-6" });
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### Example: Performance Monitoring
|
|
472
|
+
|
|
473
|
+
```javascript
|
|
474
|
+
import { tws, twsx, performanceUtils } from "tailwind-to-style";
|
|
475
|
+
|
|
476
|
+
// Enable monitoring
|
|
477
|
+
performanceUtils.enablePerformanceLogging(true);
|
|
478
|
+
|
|
479
|
+
// Your code that uses tws/twsx
|
|
480
|
+
const styles = tws("bg-gradient-to-r from-purple-400 to-pink-500 p-8");
|
|
481
|
+
const complexStyles = twsx({
|
|
482
|
+
".hero": [
|
|
483
|
+
"bg-gradient-to-br from-indigo-900 to-purple-900 min-h-screen",
|
|
484
|
+
{
|
|
485
|
+
"h1": "text-6xl font-bold text-white md:text-4xl",
|
|
486
|
+
"@css": {
|
|
487
|
+
transition: "font-size 0.3s ease-in-out"
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
]
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
// Check performance stats
|
|
494
|
+
console.log(performanceUtils.getStats());
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
This will automatically log warnings for operations taking longer than 5ms and provide insights into cache usage and performance bottlenecks.
|
|
498
|
+
|
|
362
499
|
## License
|
|
363
500
|
|
|
364
501
|
## Contributing
|