tailwind-to-style 1.0.3 → 1.0.5

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 (3) hide show
  1. package/README.md +2 -2
  2. package/index.js +55 -14
  3. 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
@@ -4,11 +4,13 @@ const theme = {
4
4
  accentColor: ({ theme }) => ({
5
5
  ...theme("colors"),
6
6
  auto: "auto",
7
+ custom: "custom_value",
7
8
  }),
8
9
  aspectRatio: {
9
10
  auto: "auto",
10
11
  square: "1 / 1",
11
12
  video: "16 / 9",
13
+ custom: "custom_value",
12
14
  },
13
15
  backdropBlur: ({ theme }) => theme("blur"),
14
16
  backdropBrightness: ({ theme }) => theme("brightness"),
@@ -34,6 +36,7 @@ const theme = {
34
36
  "gradient-to-l": "linear-gradient(to left, var(--gradient-color-stops))",
35
37
  "gradient-to-tl":
36
38
  "linear-gradient(to top left, var(--gradient-color-stops))",
39
+ custom: "custom_value",
37
40
  },
38
41
  backgroundOpacity: ({ theme }) => theme("opacity"),
39
42
  backgroundPosition: {
@@ -62,6 +65,7 @@ const theme = {
62
65
  xl: "24px",
63
66
  "2xl": "40px",
64
67
  "3xl": "64px",
68
+ custom: "custom_value",
65
69
  },
66
70
  borderColor: ({ theme }) => ({
67
71
  ...theme("colors"),
@@ -78,6 +82,7 @@ const theme = {
78
82
  "2xl": "1rem",
79
83
  "3xl": "1.5rem",
80
84
  full: "9999px",
85
+ custom: "custom_value",
81
86
  },
82
87
  borderSpacing: ({ theme }) => ({
83
88
  ...theme("spacing"),
@@ -88,6 +93,7 @@ const theme = {
88
93
  2: "2px",
89
94
  4: "4px",
90
95
  8: "8px",
96
+ custom: "custom_value",
91
97
  },
92
98
  boxShadow: {
93
99
  sm: "0 1px 2px 0 rgb(0 0 0 / 0.05)",
@@ -98,6 +104,7 @@ const theme = {
98
104
  "2xl": "0 25px 50px -12px rgb(0 0 0 / 0.25)",
99
105
  inner: "inset 0 2px 4px 0 rgb(0 0 0 / 0.05)",
100
106
  none: "none",
107
+ custom: "custom_value",
101
108
  },
102
109
  boxShadowColor: ({ theme }) => theme("colors"),
103
110
  brightness: {
@@ -112,6 +119,7 @@ const theme = {
112
119
  125: "1.25",
113
120
  150: "1.5",
114
121
  200: "2",
122
+ custom: "custom_value",
115
123
  },
116
124
  caretColor: ({ theme }) => theme("colors"),
117
125
  colors: {
@@ -383,6 +391,7 @@ const theme = {
383
391
  800: "#9f1239",
384
392
  900: "#881337",
385
393
  },
394
+ custom: "custom_value",
386
395
  },
387
396
  columns: {
388
397
  auto: "auto",
@@ -411,6 +420,7 @@ const theme = {
411
420
  "5xl": "64rem",
412
421
  "6xl": "72rem",
413
422
  "7xl": "80rem",
423
+ custom: "custom_value",
414
424
  },
415
425
  container: {},
416
426
  content: {
@@ -424,6 +434,7 @@ const theme = {
424
434
  125: "1.25",
425
435
  150: "1.5",
426
436
  200: "2",
437
+ custom: "custom_value",
427
438
  },
428
439
  cursor: {
429
440
  auto: "auto",
@@ -535,6 +546,7 @@ const theme = {
535
546
  "7xl": "4.5rem",
536
547
  "8xl": "6rem",
537
548
  "9xl": "8rem",
549
+ custom: "custom_value",
538
550
  },
539
551
  fontWeight: {
540
552
  thin: "100",
@@ -546,6 +558,7 @@ const theme = {
546
558
  bold: "700",
547
559
  extrabold: "800",
548
560
  black: "900",
561
+ custom: "custom_value",
549
562
  },
550
563
  gap: ({ theme }) => theme("spacing"),
551
564
  gradientColorStops: ({ theme }) => theme("colors"),
@@ -742,6 +755,7 @@ const theme = {
742
755
  min: "min-content",
743
756
  max: "max-content",
744
757
  fit: "fit-content",
758
+ custom: "custom_value",
745
759
  }),
746
760
  hueRotate: {
747
761
  0: "0deg",
@@ -773,6 +787,7 @@ const theme = {
773
787
  wide: "0.025em",
774
788
  wider: "0.05em",
775
789
  widest: "0.1em",
790
+ custom: "custom_value",
776
791
  },
777
792
  lineClamp: {
778
793
  1: "1",
@@ -781,6 +796,7 @@ const theme = {
781
796
  4: "4",
782
797
  5: "5",
783
798
  6: "6",
799
+ custom: "custom_value",
784
800
  },
785
801
  lineHeight: {
786
802
  none: "1",
@@ -797,6 +813,7 @@ const theme = {
797
813
  8: "2rem",
798
814
  9: "2.25rem",
799
815
  10: "2.5rem",
816
+ custom: "custom_value",
800
817
  },
801
818
  listStyleType: {
802
819
  none: "none",
@@ -890,6 +907,7 @@ const theme = {
890
907
  90: "0.9",
891
908
  95: "0.95",
892
909
  100: "1",
910
+ custom: "custom_value",
893
911
  },
894
912
  order: {
895
913
  first: "-9999",
@@ -907,6 +925,7 @@ const theme = {
907
925
  10: "10",
908
926
  11: "11",
909
927
  12: "12",
928
+ custom: "custom_value",
910
929
  },
911
930
  outlineColor: ({ theme }) => theme("colors"),
912
931
  outlineOffset: {
@@ -915,6 +934,7 @@ const theme = {
915
934
  2: "2px",
916
935
  4: "4px",
917
936
  8: "8px",
937
+ custom: "custom_value",
918
938
  },
919
939
  outlineOpacity: ({ theme }) => theme("opacity"),
920
940
  outlineWidth: {
@@ -923,6 +943,7 @@ const theme = {
923
943
  2: "2px",
924
944
  4: "4px",
925
945
  8: "8px",
946
+ custom: "custom_value",
926
947
  },
927
948
  padding: ({ theme }) => theme("spacing"),
928
949
  ringColor: ({ theme }) => ({
@@ -936,6 +957,7 @@ const theme = {
936
957
  2: "2px",
937
958
  4: "4px",
938
959
  8: "8px",
960
+ custom: "custom_value",
939
961
  },
940
962
  ringOpacity: ({ theme }) => ({
941
963
  DEFAULT: "0.5",
@@ -948,6 +970,7 @@ const theme = {
948
970
  2: "2px",
949
971
  4: "4px",
950
972
  8: "8px",
973
+ custom: "custom_value",
951
974
  },
952
975
  rotate: {
953
976
  0: "0deg",
@@ -959,6 +982,7 @@ const theme = {
959
982
  45: "45deg",
960
983
  90: "90deg",
961
984
  180: "180deg",
985
+ custom: "custom_value",
962
986
  },
963
987
  saturate: {
964
988
  0: "0",
@@ -966,6 +990,7 @@ const theme = {
966
990
  100: "1",
967
991
  150: "1.5",
968
992
  200: "2",
993
+ custom: "custom_value",
969
994
  },
970
995
  scale: {
971
996
  0: "0",
@@ -978,6 +1003,7 @@ const theme = {
978
1003
  110: "1.1",
979
1004
  125: "1.25",
980
1005
  150: "1.5",
1006
+ custom: "custom_value",
981
1007
  },
982
1008
  scrollMargin: ({ theme }) => ({
983
1009
  ...theme("spacing"),
@@ -994,6 +1020,7 @@ const theme = {
994
1020
  3: "3deg",
995
1021
  6: "6deg",
996
1022
  12: "12deg",
1023
+ custom: "custom_value",
997
1024
  },
998
1025
  space: ({ theme }) => ({
999
1026
  ...theme("spacing"),
@@ -1034,6 +1061,7 @@ const theme = {
1034
1061
  72: "18rem",
1035
1062
  80: "20rem",
1036
1063
  96: "24rem",
1064
+ custom: "custom_value",
1037
1065
  },
1038
1066
  stroke: ({ theme }) => ({
1039
1067
  none: "none",
@@ -1043,6 +1071,7 @@ const theme = {
1043
1071
  0: "0",
1044
1072
  1: "1",
1045
1073
  2: "2",
1074
+ custom: "custom_value",
1046
1075
  },
1047
1076
  textColor: ({ theme }) => theme("colors"),
1048
1077
  textDecorationColor: ({ theme }) => theme("colors"),
@@ -1054,6 +1083,7 @@ const theme = {
1054
1083
  2: "2px",
1055
1084
  4: "4px",
1056
1085
  8: "8px",
1086
+ custom: "custom_value",
1057
1087
  },
1058
1088
  textIndent: ({ theme }) => ({
1059
1089
  ...theme("spacing"),
@@ -1077,6 +1107,7 @@ const theme = {
1077
1107
  8: "8px",
1078
1108
  9: "9px",
1079
1109
  10: "10px",
1110
+ custom: "custom_value",
1080
1111
  },
1081
1112
  textShadowY: ({ theme }) => theme("textShadowX"),
1082
1113
  textUnderlineOffset: {
@@ -1086,6 +1117,7 @@ const theme = {
1086
1117
  2: "2px",
1087
1118
  4: "4px",
1088
1119
  8: "8px",
1120
+ custom: "custom_value",
1089
1121
  },
1090
1122
  transformOrigin: {
1091
1123
  center: "center",
@@ -1199,6 +1231,7 @@ const theme = {
1199
1231
  90: "90",
1200
1232
  100: "100",
1201
1233
  auto: "auto",
1234
+ custom: "custom_value",
1202
1235
  },
1203
1236
  };
1204
1237
 
@@ -5615,18 +5648,18 @@ function generateTailwindCssString(options = {}) {
5615
5648
  return cssString;
5616
5649
  }
5617
5650
 
5618
- function generateCssClasses(cssString) {
5619
- const cssClasses = {};
5620
- // eslint-disable-next-line
5621
- const regex = /([a-zA-Z0-9\-]+)\s*{\s*([^}]+)\s*}/g;
5651
+ function convertCssToObject(cssString) {
5652
+ const cssObject = {};
5653
+ const regex = /([a-zA-Z0-9\-\\.]+)\s*{\s*([^}]+)\s*}/g;
5622
5654
  let match;
5623
- while ((match = regex.exec(cssString)) !== null) {
5624
- const className = match[1].trim();
5625
- const cssRules = match[2].trim();
5626
5655
 
5627
- cssClasses[className] = cssRules;
5656
+ while ((match = regex.exec(cssString)) !== null) {
5657
+ const className = match[1].replace(/\\/g, "");
5658
+ const cssRules = match[2].trim().replace(/\s+/g, " ");
5659
+ cssObject[className] = cssRules;
5628
5660
  }
5629
- return cssClasses;
5661
+
5662
+ return cssObject;
5630
5663
  }
5631
5664
 
5632
5665
  function inlineStyleToJson(styleString) {
@@ -5649,7 +5682,6 @@ function inlineStyleToJson(styleString) {
5649
5682
  function jsonToStyle(json) {
5650
5683
  return Object.entries(json)
5651
5684
  .map(([key, value]) => {
5652
- // Convert camelCase to kebab-case for CSS properties
5653
5685
  const kebabCaseKey = key.replace(
5654
5686
  /[A-Z]/g,
5655
5687
  (letter) => `-${letter.toLowerCase()}`
@@ -5665,7 +5697,7 @@ function replaceAndRemoveCSSVariables(styleString) {
5665
5697
  let match;
5666
5698
 
5667
5699
  while ((match = variableRegex.exec(styleString)) !== null) {
5668
- const [_, variableName, value] = match;
5700
+ const [, variableName, value] = match;
5669
5701
  customProperties[variableName] = value.trim();
5670
5702
  }
5671
5703
 
@@ -5694,12 +5726,21 @@ const breakpoints = {
5694
5726
  function tws(classNames, convertToJson) {
5695
5727
  const cssString = generateTailwindCssString().replace(/\s\s+/g, " ");
5696
5728
 
5697
- const cssClasses = generateCssClasses(cssString);
5729
+ const cssObject = convertCssToObject(cssString);
5698
5730
 
5699
5731
  const classes = classNames.split(" ");
5700
5732
  let cssResult = classes.map((className) => {
5701
- if (cssClasses[className]) {
5702
- return cssClasses[className];
5733
+ if (cssObject[className]) {
5734
+ return cssObject[className];
5735
+ } else if (className.includes("[")) {
5736
+ const customValue = className.match(/\[([^\]]+)\]/)[1];
5737
+ const baseKey = className.split("[")[0];
5738
+ if (cssObject[`${baseKey}custom`]) {
5739
+ return cssObject[`${baseKey}custom`].replace(
5740
+ /custom_value/g,
5741
+ customValue
5742
+ );
5743
+ }
5703
5744
  }
5704
5745
  return "";
5705
5746
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-to-style",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Convert tailwind classes to inline style",
5
5
  "main": "index.js",
6
6
  "scripts": {