tailwind-to-style 1.1.5 → 1.1.7
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/index.js +53 -19
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -5678,28 +5678,62 @@ function jsonToStyle(json) {
|
|
|
5678
5678
|
.join(" ");
|
|
5679
5679
|
}
|
|
5680
5680
|
|
|
5681
|
-
function
|
|
5682
|
-
const
|
|
5683
|
-
const
|
|
5684
|
-
|
|
5681
|
+
function separateAndResolveCSS(arr) {
|
|
5682
|
+
const cssProperties = [];
|
|
5683
|
+
const cssVariables = [];
|
|
5684
|
+
const variableMap = {};
|
|
5685
|
+
|
|
5686
|
+
arr.forEach((item) => {
|
|
5687
|
+
const declarations = item
|
|
5688
|
+
.split(";")
|
|
5689
|
+
.map((decl) => decl.trim())
|
|
5690
|
+
.filter((decl) => decl);
|
|
5691
|
+
|
|
5692
|
+
declarations.forEach((declaration) => {
|
|
5693
|
+
if (declaration.startsWith("--")) {
|
|
5694
|
+
const [key, value] = declaration.split(":").map((part) => part.trim());
|
|
5695
|
+
variableMap[key] = value;
|
|
5696
|
+
cssVariables.push(declaration + ";");
|
|
5697
|
+
} else {
|
|
5698
|
+
cssProperties.push(declaration + ";");
|
|
5699
|
+
}
|
|
5700
|
+
});
|
|
5701
|
+
});
|
|
5685
5702
|
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5703
|
+
function resolveVariable(value) {
|
|
5704
|
+
return value.replace(/var\((--[\w-]+)\)/g, (_, varName) => {
|
|
5705
|
+
if (variableMap[varName]) {
|
|
5706
|
+
return resolveVariable(variableMap[varName]);
|
|
5707
|
+
}
|
|
5708
|
+
return `var(${varName})`;
|
|
5709
|
+
});
|
|
5689
5710
|
}
|
|
5690
5711
|
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
(
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5712
|
+
const resolvedVariables = cssVariables.map((variable) => {
|
|
5713
|
+
const [key, value] = variable.split(":").map((part) => part.trim());
|
|
5714
|
+
const resolvedValue = resolveVariable(value.slice(0, -1));
|
|
5715
|
+
return `${key}: ${resolvedValue};`;
|
|
5716
|
+
});
|
|
5717
|
+
|
|
5718
|
+
const uniqueVariables = [
|
|
5719
|
+
...new Map(
|
|
5720
|
+
resolvedVariables.reverse().map((variable) => {
|
|
5721
|
+
const key = variable.split(":")[0].trim();
|
|
5722
|
+
return [key, variable];
|
|
5723
|
+
})
|
|
5724
|
+
).values(),
|
|
5725
|
+
].reverse();
|
|
5697
5726
|
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
.
|
|
5727
|
+
uniqueVariables.forEach((variable) => {
|
|
5728
|
+
const [key, value] = variable.split(":").map((part) => part.trim());
|
|
5729
|
+
variableMap[key] = value.slice(0, -1);
|
|
5730
|
+
});
|
|
5731
|
+
|
|
5732
|
+
const resolvedCSSProperties = cssProperties.map((property) =>
|
|
5733
|
+
resolveVariable(property)
|
|
5734
|
+
);
|
|
5701
5735
|
|
|
5702
|
-
return
|
|
5736
|
+
return resolvedCSSProperties;
|
|
5703
5737
|
}
|
|
5704
5738
|
|
|
5705
5739
|
const breakpoints = {
|
|
@@ -5745,8 +5779,8 @@ function tws(classNames, convertToJson) {
|
|
|
5745
5779
|
return "";
|
|
5746
5780
|
});
|
|
5747
5781
|
|
|
5748
|
-
cssResult =
|
|
5749
|
-
cssResult = inlineStyleToJson(cssResult);
|
|
5782
|
+
cssResult = separateAndResolveCSS(cssResult);
|
|
5783
|
+
cssResult = inlineStyleToJson(cssResult.join(""));
|
|
5750
5784
|
|
|
5751
5785
|
if (!convertToJson) {
|
|
5752
5786
|
cssResult = jsonToStyle(cssResult);
|