tailwind-to-style 1.0.3 → 1.0.4
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 +2 -2
- package/index.js +13 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ yarn add tailwind-to-style
|
|
|
24
24
|
## Usage
|
|
25
25
|
|
|
26
26
|
```javascript
|
|
27
|
-
import tws from "tailwind-to-style";
|
|
27
|
+
import { tws } from "tailwind-to-style";
|
|
28
28
|
|
|
29
29
|
// Convert classes to inline CSS
|
|
30
30
|
const styleInline = tws(`bg-white mx-auto`);
|
|
@@ -41,7 +41,7 @@ Here is an example of how to use `tailwind-to-style` in a React application:
|
|
|
41
41
|
|
|
42
42
|
```javascript
|
|
43
43
|
import React from 'react';
|
|
44
|
-
import tws from 'tailwind-to-style';
|
|
44
|
+
import { tws } from 'tailwind-to-style';
|
|
45
45
|
|
|
46
46
|
const App = () => {
|
|
47
47
|
return (
|
package/index.js
CHANGED
|
@@ -5615,18 +5615,18 @@ function generateTailwindCssString(options = {}) {
|
|
|
5615
5615
|
return cssString;
|
|
5616
5616
|
}
|
|
5617
5617
|
|
|
5618
|
-
function
|
|
5619
|
-
const
|
|
5620
|
-
|
|
5621
|
-
const regex = /([a-zA-Z0-9\-]+)\s*{\s*([^}]+)\s*}/g;
|
|
5618
|
+
function convertCssToObject(cssString) {
|
|
5619
|
+
const cssObject = {};
|
|
5620
|
+
const regex = /([a-zA-Z0-9\-\\.]+)\s*{\s*([^}]+)\s*}/g;
|
|
5622
5621
|
let match;
|
|
5623
|
-
while ((match = regex.exec(cssString)) !== null) {
|
|
5624
|
-
const className = match[1].trim();
|
|
5625
|
-
const cssRules = match[2].trim();
|
|
5626
5622
|
|
|
5627
|
-
|
|
5623
|
+
while ((match = regex.exec(cssString)) !== null) {
|
|
5624
|
+
const className = match[1].replace(/\\/g, "");
|
|
5625
|
+
const cssRules = match[2].trim().replace(/\s+/g, " ");
|
|
5626
|
+
cssObject[className] = cssRules;
|
|
5628
5627
|
}
|
|
5629
|
-
|
|
5628
|
+
|
|
5629
|
+
return cssObject;
|
|
5630
5630
|
}
|
|
5631
5631
|
|
|
5632
5632
|
function inlineStyleToJson(styleString) {
|
|
@@ -5649,7 +5649,6 @@ function inlineStyleToJson(styleString) {
|
|
|
5649
5649
|
function jsonToStyle(json) {
|
|
5650
5650
|
return Object.entries(json)
|
|
5651
5651
|
.map(([key, value]) => {
|
|
5652
|
-
// Convert camelCase to kebab-case for CSS properties
|
|
5653
5652
|
const kebabCaseKey = key.replace(
|
|
5654
5653
|
/[A-Z]/g,
|
|
5655
5654
|
(letter) => `-${letter.toLowerCase()}`
|
|
@@ -5665,7 +5664,7 @@ function replaceAndRemoveCSSVariables(styleString) {
|
|
|
5665
5664
|
let match;
|
|
5666
5665
|
|
|
5667
5666
|
while ((match = variableRegex.exec(styleString)) !== null) {
|
|
5668
|
-
const [
|
|
5667
|
+
const [, variableName, value] = match;
|
|
5669
5668
|
customProperties[variableName] = value.trim();
|
|
5670
5669
|
}
|
|
5671
5670
|
|
|
@@ -5694,12 +5693,12 @@ const breakpoints = {
|
|
|
5694
5693
|
function tws(classNames, convertToJson) {
|
|
5695
5694
|
const cssString = generateTailwindCssString().replace(/\s\s+/g, " ");
|
|
5696
5695
|
|
|
5697
|
-
const
|
|
5696
|
+
const cssObject = convertCssToObject(cssString);
|
|
5698
5697
|
|
|
5699
5698
|
const classes = classNames.split(" ");
|
|
5700
5699
|
let cssResult = classes.map((className) => {
|
|
5701
|
-
if (
|
|
5702
|
-
return
|
|
5700
|
+
if (cssObject[className]) {
|
|
5701
|
+
return cssObject[className];
|
|
5703
5702
|
}
|
|
5704
5703
|
return "";
|
|
5705
5704
|
});
|