tailwind-to-style 1.1.8 → 1.1.9

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.
Files changed (2) hide show
  1. package/index.js +35 -59
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  const theme = {
4
4
  accentColor: ({ theme }) => ({
@@ -1375,7 +1375,8 @@ function generator$2l(configOptions = {}) {
1375
1375
  `
1376
1376
  );
1377
1377
  return cssString;
1378
- });
1378
+ }
1379
+ );
1379
1380
 
1380
1381
  return responsiveCssString;
1381
1382
  }
@@ -2153,7 +2154,8 @@ function generator$1Y(configOptions = {}) {
2153
2154
  return str;
2154
2155
  });
2155
2156
  return cssString;
2156
- });
2157
+ }
2158
+ );
2157
2159
 
2158
2160
  return responsiveCssString;
2159
2161
  }
@@ -2262,7 +2264,8 @@ function generator$1U(configOptions = {}) {
2262
2264
  `
2263
2265
  );
2264
2266
  return cssString;
2265
- });
2267
+ }
2268
+ );
2266
2269
 
2267
2270
  return responsiveCssString;
2268
2271
  }
@@ -4829,7 +4832,8 @@ function generator$p(configOptions = {}) {
4829
4832
  `
4830
4833
  );
4831
4834
  return cssString;
4832
- });
4835
+ }
4836
+ );
4833
4837
 
4834
4838
  return responsiveCssString;
4835
4839
  }
@@ -5670,23 +5674,8 @@ function inlineStyleToJson(styleString) {
5670
5674
  return styleObject;
5671
5675
  }
5672
5676
 
5673
- function jsonToStyle(json) {
5674
- return Object.entries(json)
5675
- .map(([key, value]) => {
5676
- const kebabCaseKey = key.replace(
5677
- /[A-Z]/g,
5678
- (letter) => `-${letter.toLowerCase()}`
5679
- );
5680
- return `${kebabCaseKey}: ${value};`;
5681
- })
5682
- .join(" ");
5683
- }
5684
-
5685
5677
  function separateAndResolveCSS(arr) {
5686
- const cssProperties = [];
5687
- const cssVariables = [];
5688
- const variableMap = {};
5689
-
5678
+ const cssProperties = {};
5690
5679
  arr.forEach((item) => {
5691
5680
  const declarations = item
5692
5681
  .split(";")
@@ -5694,50 +5683,38 @@ function separateAndResolveCSS(arr) {
5694
5683
  .filter((decl) => decl);
5695
5684
 
5696
5685
  declarations.forEach((declaration) => {
5697
- if (declaration.startsWith("--")) {
5698
- const [key, value] = declaration.split(":").map((part) => part.trim());
5699
- variableMap[key] = value;
5700
- cssVariables.push(declaration + ";");
5701
- } else {
5702
- cssProperties.push(declaration + ";");
5703
- }
5686
+ const [key, value] = declaration.split(":").map((part) => part.trim());
5687
+ cssProperties[key] = value;
5704
5688
  });
5705
5689
  });
5706
5690
 
5707
- function resolveVariable(value) {
5708
- return value.replace(/var\((--[\w-]+)\)/g, (_, varName) => {
5709
- if (variableMap[varName]) {
5710
- return resolveVariable(variableMap[varName]);
5691
+ const resolvedProperties = { ...cssProperties };
5692
+
5693
+ const resolveValue = (value, variables) => {
5694
+ return value.replace(
5695
+ /var\((--[a-zA-Z0-9-]+)(?:,\s*([^\)]+))?\)/g,
5696
+ (match, variable, fallback) => {
5697
+ return variables[variable] || fallback || match;
5711
5698
  }
5712
- return `var(${varName})`;
5713
- });
5714
- }
5699
+ );
5700
+ };
5715
5701
 
5716
- const resolvedVariables = cssVariables.map((variable) => {
5717
- const [key, value] = variable.split(":").map((part) => part.trim());
5718
- const resolvedValue = resolveVariable(value.slice(0, -1));
5719
- return `${key}: ${resolvedValue};`;
5702
+ Object.keys(resolvedProperties).forEach((key) => {
5703
+ resolvedProperties[key] = resolveValue(
5704
+ resolvedProperties[key],
5705
+ resolvedProperties
5706
+ );
5720
5707
  });
5721
5708
 
5722
- const uniqueVariables = [
5723
- ...new Map(
5724
- resolvedVariables.reverse().map((variable) => {
5725
- const key = variable.split(":")[0].trim();
5726
- return [key, variable];
5727
- })
5728
- ).values(),
5729
- ].reverse();
5730
-
5731
- uniqueVariables.forEach((variable) => {
5732
- const [key, value] = variable.split(":").map((part) => part.trim());
5733
- variableMap[key] = value.slice(0, -1);
5709
+ Object.keys(resolvedProperties).forEach((key) => {
5710
+ if (key.startsWith("--")) {
5711
+ delete resolvedProperties[key];
5712
+ }
5734
5713
  });
5735
5714
 
5736
- const resolvedCSSProperties = cssProperties.map((property) =>
5737
- resolveVariable(property)
5738
- );
5739
-
5740
- return resolvedCSSProperties;
5715
+ return Object.entries(resolvedProperties)
5716
+ .map(([key, value]) => `${key}: ${value};`)
5717
+ .join(" ");
5741
5718
  }
5742
5719
 
5743
5720
  const breakpoints = {
@@ -5784,10 +5761,9 @@ function tws(classNames, convertToJson) {
5784
5761
  });
5785
5762
 
5786
5763
  cssResult = separateAndResolveCSS(cssResult);
5787
- cssResult = inlineStyleToJson(cssResult.join(""));
5788
5764
 
5789
- if (!convertToJson) {
5790
- cssResult = jsonToStyle(cssResult);
5765
+ if (convertToJson) {
5766
+ cssResult = inlineStyleToJson(cssResult);
5791
5767
  }
5792
5768
 
5793
5769
  return cssResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-to-style",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "Convert tailwind classes to inline style",
5
5
  "main": "index.js",
6
6
  "scripts": {