tailwindcss 0.0.0-insiders.fe08e91 → 0.0.0-oxide.dd87d75

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 (178) hide show
  1. package/CHANGELOG.md +379 -3
  2. package/LICENSE +1 -2
  3. package/README.md +12 -8
  4. package/colors.d.ts +3 -0
  5. package/defaultConfig.d.ts +3 -0
  6. package/defaultTheme.d.ts +4 -0
  7. package/lib/cli/build/deps.js +54 -0
  8. package/lib/cli/build/index.js +48 -0
  9. package/lib/cli/build/plugin.js +367 -0
  10. package/lib/cli/build/utils.js +78 -0
  11. package/lib/cli/build/watching.js +178 -0
  12. package/lib/cli/help/index.js +71 -0
  13. package/lib/cli/index.js +239 -0
  14. package/lib/cli/init/index.js +46 -0
  15. package/lib/cli/shared.js +13 -0
  16. package/lib/cli-peer-dependencies.js +20 -7
  17. package/lib/cli.js +4 -740
  18. package/lib/constants.js +27 -20
  19. package/lib/corePluginList.js +6 -3
  20. package/lib/corePlugins.js +2064 -1811
  21. package/lib/css/preflight.css +5 -5
  22. package/lib/featureFlags.js +31 -22
  23. package/lib/index.js +4 -28
  24. package/lib/lib/cacheInvalidation.js +90 -0
  25. package/lib/lib/collapseAdjacentRules.js +27 -9
  26. package/lib/lib/collapseDuplicateDeclarations.js +12 -9
  27. package/lib/lib/content.js +176 -0
  28. package/lib/lib/defaultExtractor.js +225 -31
  29. package/lib/lib/detectNesting.js +13 -10
  30. package/lib/lib/evaluateTailwindFunctions.js +118 -55
  31. package/lib/lib/expandApplyAtRules.js +439 -190
  32. package/lib/lib/expandTailwindAtRules.js +151 -134
  33. package/lib/lib/findAtConfigPath.js +44 -0
  34. package/lib/lib/generateRules.js +454 -187
  35. package/lib/lib/getModuleDependencies.js +11 -8
  36. package/lib/lib/normalizeTailwindDirectives.js +36 -32
  37. package/lib/lib/offsets.js +217 -0
  38. package/lib/lib/partitionApplyAtRules.js +56 -0
  39. package/lib/lib/regex.js +60 -0
  40. package/lib/lib/resolveDefaultsAtRules.js +89 -67
  41. package/lib/lib/setupContextUtils.js +667 -376
  42. package/lib/lib/setupTrackingContext.js +38 -67
  43. package/lib/lib/sharedState.js +27 -14
  44. package/lib/lib/substituteScreenAtRules.js +11 -9
  45. package/lib/plugin.js +48 -0
  46. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  47. package/lib/postcss-plugins/nesting/index.js +19 -0
  48. package/lib/postcss-plugins/nesting/plugin.js +87 -0
  49. package/lib/processTailwindFeatures.js +35 -25
  50. package/lib/public/colors.js +247 -245
  51. package/lib/public/create-plugin.js +6 -4
  52. package/lib/public/default-config.js +7 -5
  53. package/lib/public/default-theme.js +7 -5
  54. package/lib/public/resolve-config.js +8 -5
  55. package/lib/util/bigSign.js +4 -1
  56. package/lib/util/buildMediaQuery.js +11 -6
  57. package/lib/util/cloneDeep.js +7 -6
  58. package/lib/util/cloneNodes.js +21 -3
  59. package/lib/util/color.js +53 -54
  60. package/lib/util/configurePlugins.js +5 -2
  61. package/lib/util/createPlugin.js +6 -6
  62. package/lib/util/createUtilityPlugin.js +12 -14
  63. package/lib/util/dataTypes.js +119 -110
  64. package/lib/util/defaults.js +4 -1
  65. package/lib/util/escapeClassName.js +7 -4
  66. package/lib/util/escapeCommas.js +5 -2
  67. package/lib/util/flattenColorPalette.js +9 -12
  68. package/lib/util/formatVariantSelector.js +184 -85
  69. package/lib/util/getAllConfigs.js +27 -8
  70. package/lib/util/hashConfig.js +6 -3
  71. package/lib/util/isKeyframeRule.js +5 -2
  72. package/lib/util/isPlainObject.js +5 -2
  73. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +23 -15
  74. package/lib/util/log.js +20 -14
  75. package/lib/util/nameClass.js +20 -9
  76. package/lib/util/negateValue.js +23 -8
  77. package/lib/util/normalizeConfig.js +116 -72
  78. package/lib/util/normalizeScreens.js +120 -11
  79. package/lib/util/parseAnimationValue.js +42 -40
  80. package/lib/util/parseBoxShadowValue.js +30 -23
  81. package/lib/util/parseDependency.js +38 -56
  82. package/lib/util/parseGlob.js +34 -0
  83. package/lib/util/parseObjectStyles.js +11 -8
  84. package/lib/util/pluginUtils.js +147 -50
  85. package/lib/util/prefixSelector.js +10 -8
  86. package/lib/util/removeAlphaVariables.js +29 -0
  87. package/lib/util/resolveConfig.js +97 -85
  88. package/lib/util/resolveConfigPath.js +11 -9
  89. package/lib/util/responsive.js +8 -5
  90. package/lib/util/splitAtTopLevelOnly.js +43 -0
  91. package/lib/util/tap.js +4 -1
  92. package/lib/util/toColorValue.js +5 -3
  93. package/lib/util/toPath.js +20 -4
  94. package/lib/util/transformThemeValue.js +37 -29
  95. package/lib/util/validateConfig.js +24 -0
  96. package/lib/util/validateFormalSyntax.js +24 -0
  97. package/lib/util/withAlphaVariable.js +23 -15
  98. package/nesting/index.js +2 -12
  99. package/package.json +47 -42
  100. package/peers/index.js +11381 -7950
  101. package/plugin.d.ts +11 -0
  102. package/resolveConfig.d.ts +12 -0
  103. package/scripts/generate-types.js +105 -0
  104. package/scripts/release-channel.js +18 -0
  105. package/scripts/release-notes.js +21 -0
  106. package/scripts/type-utils.js +27 -0
  107. package/src/cli/build/deps.js +56 -0
  108. package/src/cli/build/index.js +49 -0
  109. package/src/cli/build/plugin.js +439 -0
  110. package/src/cli/build/utils.js +76 -0
  111. package/src/cli/build/watching.js +227 -0
  112. package/src/cli/help/index.js +70 -0
  113. package/src/cli/index.js +234 -0
  114. package/src/cli/init/index.js +50 -0
  115. package/src/cli/shared.js +6 -0
  116. package/src/cli-peer-dependencies.js +7 -1
  117. package/src/cli.js +4 -810
  118. package/src/corePluginList.js +1 -1
  119. package/src/corePlugins.js +532 -217
  120. package/src/css/preflight.css +5 -5
  121. package/src/featureFlags.js +15 -9
  122. package/src/index.js +4 -27
  123. package/src/lib/cacheInvalidation.js +52 -0
  124. package/src/lib/collapseAdjacentRules.js +21 -2
  125. package/src/lib/content.js +212 -0
  126. package/src/lib/defaultExtractor.js +196 -33
  127. package/src/lib/evaluateTailwindFunctions.js +78 -7
  128. package/src/lib/expandApplyAtRules.js +482 -183
  129. package/src/lib/expandTailwindAtRules.js +106 -85
  130. package/src/lib/findAtConfigPath.js +48 -0
  131. package/src/lib/generateRules.js +418 -129
  132. package/src/lib/normalizeTailwindDirectives.js +1 -0
  133. package/src/lib/offsets.js +270 -0
  134. package/src/lib/partitionApplyAtRules.js +52 -0
  135. package/src/lib/regex.js +74 -0
  136. package/src/lib/resolveDefaultsAtRules.js +51 -30
  137. package/src/lib/setupContextUtils.js +556 -208
  138. package/src/lib/setupTrackingContext.js +11 -48
  139. package/src/lib/sharedState.js +5 -0
  140. package/src/plugin.js +47 -0
  141. package/src/postcss-plugins/nesting/README.md +42 -0
  142. package/src/postcss-plugins/nesting/index.js +13 -0
  143. package/src/postcss-plugins/nesting/plugin.js +80 -0
  144. package/src/processTailwindFeatures.js +8 -0
  145. package/src/util/buildMediaQuery.js +5 -3
  146. package/src/util/cloneNodes.js +19 -2
  147. package/src/util/color.js +25 -21
  148. package/src/util/dataTypes.js +29 -21
  149. package/src/util/formatVariantSelector.js +184 -61
  150. package/src/util/getAllConfigs.js +19 -0
  151. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  152. package/src/util/log.js +8 -8
  153. package/src/util/nameClass.js +4 -0
  154. package/src/util/negateValue.js +11 -3
  155. package/src/util/normalizeConfig.js +44 -6
  156. package/src/util/normalizeScreens.js +99 -4
  157. package/src/util/parseBoxShadowValue.js +4 -3
  158. package/src/util/parseDependency.js +37 -42
  159. package/src/util/parseGlob.js +24 -0
  160. package/src/util/pluginUtils.js +132 -10
  161. package/src/util/prefixSelector.js +7 -5
  162. package/src/util/removeAlphaVariables.js +24 -0
  163. package/src/util/resolveConfig.js +70 -32
  164. package/src/util/splitAtTopLevelOnly.js +45 -0
  165. package/src/util/toPath.js +1 -1
  166. package/src/util/transformThemeValue.js +13 -3
  167. package/src/util/validateConfig.js +13 -0
  168. package/src/util/validateFormalSyntax.js +34 -0
  169. package/src/util/withAlphaVariable.js +1 -1
  170. package/stubs/defaultConfig.stub.js +23 -20
  171. package/stubs/simpleConfig.stub.js +1 -0
  172. package/types/config.d.ts +362 -0
  173. package/types/generated/.gitkeep +0 -0
  174. package/types/generated/colors.d.ts +276 -0
  175. package/types/generated/corePluginList.d.ts +1 -0
  176. package/types/generated/default-theme.d.ts +342 -0
  177. package/types/index.d.ts +7 -0
  178. package/nesting/plugin.js +0 -41
@@ -2,37 +2,231 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.defaultExtractor = defaultExtractor;
6
- const PATTERNS = [
7
- /(?:\['([^'\s]+[^<>"'`\s:\\])')/.source,
8
- /(?:\["([^"\s]+[^<>"'`\s:\\])")/.source,
9
- /(?:\[`([^`\s]+[^<>"'`\s:\\])`)/.source,
10
- /([^<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source,
11
- /([^<>"'`\s]*\[\w*"[^'`\s]*"?\])/.source,
12
- /([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source,
13
- /([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source,
14
- /([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source,
15
- /([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source,
16
- /([^<>"'`\s]*\['[^"'`\s]*'\])/.source,
17
- /([^<>"'`\s]*\["[^"'`\s]*"\])/.source,
18
- /([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source,
19
- /([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source,
20
- /([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source,
21
- /([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
22
- /([^"'`\s]*[^<>"'`\s:\\])/.source,
23
- /([^<>"'`\s]*[^"'`\s:\\])/.source,
24
- ].join('|');
25
- const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
26
- const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
27
- function defaultExtractor(content) {
28
- let broadMatches = content.matchAll(BROAD_MATCH_GLOBAL_REGEXP);
29
- let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || [];
30
- let results = [
31
- ...broadMatches,
32
- ...innerMatches
33
- ].flat().filter((v)=>v !== undefined
34
- );
35
- return results;
5
+ Object.defineProperty(exports, "defaultExtractor", {
6
+ enumerable: true,
7
+ get: ()=>defaultExtractor
8
+ });
9
+ const _featureFlags = require("../featureFlags");
10
+ const _regex = /*#__PURE__*/ _interopRequireWildcard(require("./regex"));
11
+ function _getRequireWildcardCache(nodeInterop) {
12
+ if (typeof WeakMap !== "function") return null;
13
+ var cacheBabelInterop = new WeakMap();
14
+ var cacheNodeInterop = new WeakMap();
15
+ return (_getRequireWildcardCache = function(nodeInterop) {
16
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
17
+ })(nodeInterop);
18
+ }
19
+ function _interopRequireWildcard(obj, nodeInterop) {
20
+ if (!nodeInterop && obj && obj.__esModule) {
21
+ return obj;
22
+ }
23
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
24
+ return {
25
+ default: obj
26
+ };
27
+ }
28
+ var cache = _getRequireWildcardCache(nodeInterop);
29
+ if (cache && cache.has(obj)) {
30
+ return cache.get(obj);
31
+ }
32
+ var newObj = {};
33
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
34
+ for(var key in obj){
35
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
36
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
37
+ if (desc && (desc.get || desc.set)) {
38
+ Object.defineProperty(newObj, key, desc);
39
+ } else {
40
+ newObj[key] = obj[key];
41
+ }
42
+ }
43
+ }
44
+ newObj.default = obj;
45
+ if (cache) {
46
+ cache.set(obj, newObj);
47
+ }
48
+ return newObj;
49
+ }
50
+ function defaultExtractor(context) {
51
+ let patterns = Array.from(buildRegExps(context));
52
+ /**
53
+ * @param {string} content
54
+ */ return (content)=>{
55
+ /** @type {(string|string)[]} */ let results = [];
56
+ for (let pattern of patterns){
57
+ var ref;
58
+ results = [
59
+ ...results,
60
+ ...(ref = content.match(pattern)) !== null && ref !== void 0 ? ref : []
61
+ ];
62
+ }
63
+ return results.filter((v)=>v !== undefined).map(clipAtBalancedParens);
64
+ };
65
+ }
66
+ function* buildRegExps(context) {
67
+ let separator = context.tailwindConfig.separator;
68
+ let variantGroupingEnabled = (0, _featureFlags.flagEnabled)(context.tailwindConfig, "variantGrouping");
69
+ let prefix = context.tailwindConfig.prefix !== "" ? _regex.optional(_regex.pattern([
70
+ /-?/,
71
+ _regex.escape(context.tailwindConfig.prefix)
72
+ ])) : "";
73
+ let utility = _regex.any([
74
+ // Arbitrary properties
75
+ /\[[^\s:'"`]+:[^\s]+\]/,
76
+ // Utilities
77
+ _regex.pattern([
78
+ // Utility Name / Group Name
79
+ /-?(?:\w+)/,
80
+ // Normal/Arbitrary values
81
+ _regex.optional(_regex.any([
82
+ _regex.pattern([
83
+ // Arbitrary values
84
+ /-(?:\w+-)*\[[^\s:]+\]/,
85
+ // Not immediately followed by an `{[(`
86
+ /(?![{([]])/,
87
+ // optionally followed by an opacity modifier
88
+ /(?:\/[^\s'"`\\><$]*)?/
89
+ ]),
90
+ _regex.pattern([
91
+ // Arbitrary values
92
+ /-(?:\w+-)*\[[^\s]+\]/,
93
+ // Not immediately followed by an `{[(`
94
+ /(?![{([]])/,
95
+ // optionally followed by an opacity modifier
96
+ /(?:\/[^\s'"`\\$]*)?/
97
+ ]),
98
+ // Normal values w/o quotes — may include an opacity modifier
99
+ /[-\/][^\s'"`\\$={><]*/
100
+ ]))
101
+ ])
102
+ ]);
103
+ let variantPatterns = [
104
+ // Without quotes
105
+ _regex.any([
106
+ // This is here to provide special support for the `@` variant
107
+ _regex.pattern([
108
+ /@\[[^\s"'`]+\](\/[^\s"'`]+)?/,
109
+ separator
110
+ ]),
111
+ _regex.pattern([
112
+ /([^\s"'`\[\\]+-)?\[[^\s"'`]+\]/,
113
+ separator
114
+ ]),
115
+ _regex.pattern([
116
+ /[^\s"'`\[\\]+/,
117
+ separator
118
+ ])
119
+ ]),
120
+ // With quotes allowed
121
+ _regex.any([
122
+ _regex.pattern([
123
+ /([^\s"'`\[\\]+-)?\[[^\s`]+\]/,
124
+ separator
125
+ ]),
126
+ _regex.pattern([
127
+ /[^\s`\[\\]+/,
128
+ separator
129
+ ])
130
+ ])
131
+ ];
132
+ for (const variantPattern of variantPatterns){
133
+ yield _regex.pattern([
134
+ // Variants
135
+ "((?=((",
136
+ variantPattern,
137
+ ")+))\\2)?",
138
+ // Important (optional)
139
+ /!?/,
140
+ prefix,
141
+ variantGroupingEnabled ? _regex.any([
142
+ // Or any of those things but grouped separated by commas
143
+ _regex.pattern([
144
+ /\(/,
145
+ utility,
146
+ _regex.zeroOrMore([
147
+ /,/,
148
+ utility
149
+ ]),
150
+ /\)/
151
+ ]),
152
+ // Arbitrary properties, constrained utilities, arbitrary values, etc…
153
+ utility
154
+ ]) : utility
155
+ ]);
156
+ }
157
+ // 5. Inner matches
158
+ yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
159
+ }
160
+ // We want to capture any "special" characters
161
+ // AND the characters immediately following them (if there is one)
162
+ let SPECIALS = /([\[\]'"`])([^\[\]'"`])?/g;
163
+ let ALLOWED_CLASS_CHARACTERS = /[^"'`\s<>\]]+/;
164
+ /**
165
+ * Clips a string ensuring that parentheses, quotes, etc… are balanced
166
+ * Used for arbitrary values only
167
+ *
168
+ * We will go past the end of the balanced parens until we find a non-class character
169
+ *
170
+ * Depth matching behavior:
171
+ * w-[calc(100%-theme('spacing[some_key][1.5]'))]']
172
+ * ┬ ┬ ┬┬ ┬ ┬┬ ┬┬┬┬┬┬┬
173
+ * 1 2 3 4 34 3 210 END
174
+ * ╰────┴──────────┴────────┴────────┴┴───┴─┴┴┴
175
+ *
176
+ * @param {string} input
177
+ */ function clipAtBalancedParens(input) {
178
+ // We are care about this for arbitrary values
179
+ if (!input.includes("-[")) {
180
+ return input;
181
+ }
182
+ let depth = 0;
183
+ let openStringTypes = [];
184
+ // Find all parens, brackets, quotes, etc
185
+ // Stop when we end at a balanced pair
186
+ // This is naive and will treat mismatched parens as balanced
187
+ // This shouldn't be a problem in practice though
188
+ let matches = input.matchAll(SPECIALS);
189
+ // We can't use lookbehind assertions because we have to support Safari
190
+ // So, instead, we've emulated it using capture groups and we'll re-work the matches to accommodate
191
+ matches = Array.from(matches).flatMap((match)=>{
192
+ const [, ...groups] = match;
193
+ return groups.map((group, idx)=>Object.assign([], match, {
194
+ index: match.index + idx,
195
+ 0: group
196
+ }));
197
+ });
198
+ for (let match of matches){
199
+ let char = match[0];
200
+ let inStringType = openStringTypes[openStringTypes.length - 1];
201
+ if (char === inStringType) {
202
+ openStringTypes.pop();
203
+ } else if (char === "'" || char === '"' || char === "`") {
204
+ openStringTypes.push(char);
205
+ }
206
+ if (inStringType) {
207
+ continue;
208
+ } else if (char === "[") {
209
+ depth++;
210
+ continue;
211
+ } else if (char === "]") {
212
+ depth--;
213
+ continue;
214
+ }
215
+ // We've gone one character past the point where we should stop
216
+ // This means that there was an extra closing `]`
217
+ // We'll clip to just before it
218
+ if (depth < 0) {
219
+ return input.substring(0, match.index);
220
+ }
221
+ // We've finished balancing the brackets but there still may be characters that can be included
222
+ // For example in the class `text-[#336699]/[.35]`
223
+ // The depth goes to `0` at the closing `]` but goes up again at the `[`
224
+ // If we're at zero and encounter a non-class character then we clip the class there
225
+ if (depth === 0 && !ALLOWED_CLASS_CHARACTERS.test(char)) {
226
+ return input.substring(0, match.index);
227
+ }
228
+ }
229
+ return input;
36
230
  } // Regular utilities
37
231
  // {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
38
232
  // Arbitrary values
@@ -2,19 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.default = _default;
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>_default
8
+ });
6
9
  function _default(_context) {
7
10
  return (root, result)=>{
8
11
  let found = false;
9
- root.walkAtRules('tailwind', (node)=>{
12
+ root.walkAtRules("tailwind", (node)=>{
10
13
  if (found) return false;
11
- if (node.parent && node.parent.type !== 'root') {
14
+ if (node.parent && node.parent.type !== "root") {
12
15
  found = true;
13
16
  node.warn(result, [
14
- 'Nested @tailwind rules were detected, but are not supported.',
17
+ "Nested @tailwind rules were detected, but are not supported.",
15
18
  "Consider using a prefix to scope Tailwind's classes: https://tailwindcss.com/docs/configuration#prefix",
16
- 'Alternatively, use the important selector strategy: https://tailwindcss.com/docs/configuration#selector-strategy',
17
- ].join('\n'));
19
+ "Alternatively, use the important selector strategy: https://tailwindcss.com/docs/configuration#selector-strategy"
20
+ ].join("\n"));
18
21
  return false;
19
22
  }
20
23
  });
@@ -23,10 +26,10 @@ function _default(_context) {
23
26
  rule.walkRules((nestedRule)=>{
24
27
  found = true;
25
28
  nestedRule.warn(result, [
26
- 'Nested CSS was detected, but CSS nesting has not been configured correctly.',
27
- 'Please enable a CSS nesting plugin *before* Tailwind in your configuration.',
28
- 'See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting',
29
- ].join('\n'));
29
+ "Nested CSS was detected, but CSS nesting has not been configured correctly.",
30
+ "Please enable a CSS nesting plugin *before* Tailwind in your configuration.",
31
+ "See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting"
32
+ ].join("\n"));
30
33
  return false;
31
34
  });
32
35
  });
@@ -2,59 +2,63 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.default = _default;
6
- var _dlv = _interopRequireDefault(require("dlv"));
7
- var _didyoumean = _interopRequireDefault(require("didyoumean"));
8
- var _transformThemeValue = _interopRequireDefault(require("../util/transformThemeValue"));
9
- var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
10
- var _normalizeScreens = require("../util/normalizeScreens");
11
- var _buildMediaQuery = _interopRequireDefault(require("../util/buildMediaQuery"));
12
- var _toPath = require("../util/toPath");
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>_default
8
+ });
9
+ const _dlv = /*#__PURE__*/ _interopRequireDefault(require("dlv"));
10
+ const _didyoumean = /*#__PURE__*/ _interopRequireDefault(require("didyoumean"));
11
+ const _transformThemeValue = /*#__PURE__*/ _interopRequireDefault(require("../util/transformThemeValue"));
12
+ const _postcssValueParser = /*#__PURE__*/ _interopRequireDefault(require("postcss-value-parser"));
13
+ const _normalizeScreens = require("../util/normalizeScreens");
14
+ const _buildMediaQuery = /*#__PURE__*/ _interopRequireDefault(require("../util/buildMediaQuery"));
15
+ const _toPath = require("../util/toPath");
16
+ const _withAlphaVariable = require("../util/withAlphaVariable");
17
+ const _pluginUtils = require("../util/pluginUtils");
18
+ const _log = /*#__PURE__*/ _interopRequireDefault(require("../util/log"));
13
19
  function _interopRequireDefault(obj) {
14
20
  return obj && obj.__esModule ? obj : {
15
21
  default: obj
16
22
  };
17
23
  }
18
24
  function isObject(input) {
19
- return typeof input === 'object' && input !== null;
25
+ return typeof input === "object" && input !== null;
20
26
  }
21
27
  function findClosestExistingPath(theme, path) {
22
- let parts = (0, _toPath).toPath(path);
28
+ let parts = (0, _toPath.toPath)(path);
23
29
  do {
24
30
  parts.pop();
25
- if ((0, _dlv).default(theme, parts) !== undefined) break;
26
- }while (parts.length)
31
+ if ((0, _dlv.default)(theme, parts) !== undefined) break;
32
+ }while (parts.length);
27
33
  return parts.length ? parts : undefined;
28
34
  }
29
35
  function pathToString(path) {
30
- if (typeof path === 'string') return path;
36
+ if (typeof path === "string") return path;
31
37
  return path.reduce((acc, cur, i)=>{
32
- if (cur.includes('.')) return `${acc}[${cur}]`;
38
+ if (cur.includes(".")) return `${acc}[${cur}]`;
33
39
  return i === 0 ? cur : `${acc}.${cur}`;
34
- }, '');
40
+ }, "");
35
41
  }
36
42
  function list(items) {
37
- return items.map((key)=>`'${key}'`
38
- ).join(', ');
43
+ return items.map((key)=>`'${key}'`).join(", ");
39
44
  }
40
45
  function listKeys(obj) {
41
46
  return list(Object.keys(obj));
42
47
  }
43
- function validatePath(config, path, defaultValue) {
44
- const pathString = Array.isArray(path) ? pathToString(path) : path.replace(/^['"]+/g, '').replace(/['"]+$/g, '');
45
- const pathSegments = Array.isArray(path) ? path : (0, _toPath).toPath(pathString);
46
- const value = (0, _dlv).default(config.theme, pathSegments, defaultValue);
48
+ function validatePath(config, path, defaultValue, themeOpts = {}) {
49
+ const pathString = Array.isArray(path) ? pathToString(path) : path.replace(/^['"]+|['"]+$/g, "");
50
+ const pathSegments = Array.isArray(path) ? path : (0, _toPath.toPath)(pathString);
51
+ const value = (0, _dlv.default)(config.theme, pathSegments, defaultValue);
47
52
  if (value === undefined) {
48
53
  let error = `'${pathString}' does not exist in your theme config.`;
49
54
  const parentSegments = pathSegments.slice(0, -1);
50
- const parentValue = (0, _dlv).default(config.theme, parentSegments);
55
+ const parentValue = (0, _dlv.default)(config.theme, parentSegments);
51
56
  if (isObject(parentValue)) {
52
57
  const validKeys = Object.keys(parentValue).filter((key)=>validatePath(config, [
53
58
  ...parentSegments,
54
59
  key
55
- ]).isValid
56
- );
57
- const suggestion = (0, _didyoumean).default(pathSegments[pathSegments.length - 1], validKeys);
60
+ ]).isValid);
61
+ const suggestion = (0, _didyoumean.default)(pathSegments[pathSegments.length - 1], validKeys);
58
62
  if (suggestion) {
59
63
  error += ` Did you mean '${pathToString([
60
64
  ...parentSegments,
@@ -66,7 +70,7 @@ function validatePath(config, path, defaultValue) {
66
70
  } else {
67
71
  const closestPath = findClosestExistingPath(config.theme, pathString);
68
72
  if (closestPath) {
69
- const closestValue = (0, _dlv).default(config.theme, closestPath);
73
+ const closestValue = (0, _dlv.default)(config.theme, closestPath);
70
74
  if (isObject(closestValue)) {
71
75
  error += ` '${pathToString(closestPath)}' has the following keys: ${listKeys(closestValue)}`;
72
76
  } else {
@@ -81,82 +85,141 @@ function validatePath(config, path, defaultValue) {
81
85
  error
82
86
  };
83
87
  }
84
- if (!(typeof value === 'string' || typeof value === 'number' || typeof value === 'function' || value instanceof String || value instanceof Number || Array.isArray(value))) {
85
- let error = `'${pathString}' was found but does not resolve to a string.`;
88
+ if (!(typeof value === "string" || typeof value === "number" || typeof value === "function" || value instanceof String || value instanceof Number || Array.isArray(value))) {
89
+ let error1 = `'${pathString}' was found but does not resolve to a string.`;
86
90
  if (isObject(value)) {
87
- let validKeys = Object.keys(value).filter((key)=>validatePath(config, [
91
+ let validKeys1 = Object.keys(value).filter((key)=>validatePath(config, [
88
92
  ...pathSegments,
89
93
  key
90
- ]).isValid
91
- );
92
- if (validKeys.length) {
93
- error += ` Did you mean something like '${pathToString([
94
+ ]).isValid);
95
+ if (validKeys1.length) {
96
+ error1 += ` Did you mean something like '${pathToString([
94
97
  ...pathSegments,
95
- validKeys[0]
98
+ validKeys1[0]
96
99
  ])}'?`;
97
100
  }
98
101
  }
99
102
  return {
100
103
  isValid: false,
101
- error
104
+ error: error1
102
105
  };
103
106
  }
104
107
  const [themeSection] = pathSegments;
105
108
  return {
106
109
  isValid: true,
107
- value: (0, _transformThemeValue).default(themeSection)(value)
110
+ value: (0, _transformThemeValue.default)(themeSection)(value, themeOpts)
108
111
  };
109
112
  }
110
113
  function extractArgs(node, vNodes, functions) {
111
- vNodes = vNodes.map((vNode)=>resolveVNode(node, vNode, functions)
112
- );
114
+ vNodes = vNodes.map((vNode)=>resolveVNode(node, vNode, functions));
113
115
  let args = [
114
- ''
116
+ ""
115
117
  ];
116
- for (let vNode1 of vNodes){
117
- if (vNode1.type === 'div' && vNode1.value === ',') {
118
- args.push('');
118
+ for (let vNode of vNodes){
119
+ if (vNode.type === "div" && vNode.value === ",") {
120
+ args.push("");
119
121
  } else {
120
- args[args.length - 1] += _postcssValueParser.default.stringify(vNode1);
122
+ args[args.length - 1] += _postcssValueParser.default.stringify(vNode);
121
123
  }
122
124
  }
123
125
  return args;
124
126
  }
125
127
  function resolveVNode(node, vNode, functions) {
126
- if (vNode.type === 'function' && functions[vNode.value] !== undefined) {
128
+ if (vNode.type === "function" && functions[vNode.value] !== undefined) {
127
129
  let args = extractArgs(node, vNode.nodes, functions);
128
- vNode.type = 'word';
130
+ vNode.type = "word";
129
131
  vNode.value = functions[vNode.value](node, ...args);
130
132
  }
131
133
  return vNode;
132
134
  }
133
135
  function resolveFunctions(node, input, functions) {
134
- return (0, _postcssValueParser).default(input).walk((vNode)=>{
136
+ return (0, _postcssValueParser.default)(input).walk((vNode)=>{
135
137
  resolveVNode(node, vNode, functions);
136
138
  }).toString();
137
139
  }
138
140
  let nodeTypePropertyMap = {
139
- atrule: 'params',
140
- decl: 'value'
141
+ atrule: "params",
142
+ decl: "value"
141
143
  };
142
- function _default({ tailwindConfig: config }) {
144
+ /**
145
+ * @param {string} path
146
+ * @returns {Iterable<[path: string, alpha: string|undefined]>}
147
+ */ function* toPaths(path) {
148
+ // Strip quotes from beginning and end of string
149
+ // This allows the alpha value to be present inside of quotes
150
+ path = path.replace(/^['"]+|['"]+$/g, "");
151
+ let matches = path.match(/^([^\s]+)(?![^\[]*\])(?:\s*\/\s*([^\/\s]+))$/);
152
+ let alpha = undefined;
153
+ yield [
154
+ path,
155
+ undefined
156
+ ];
157
+ if (matches) {
158
+ path = matches[1];
159
+ alpha = matches[2];
160
+ yield [
161
+ path,
162
+ alpha
163
+ ];
164
+ }
165
+ }
166
+ /**
167
+ *
168
+ * @param {any} config
169
+ * @param {string} path
170
+ * @param {any} defaultValue
171
+ */ function resolvePath(config, path, defaultValue) {
172
+ const results = Array.from(toPaths(path)).map(([path, alpha])=>{
173
+ return Object.assign(validatePath(config, path, defaultValue, {
174
+ opacityValue: alpha
175
+ }), {
176
+ resolvedPath: path,
177
+ alpha
178
+ });
179
+ });
180
+ var ref;
181
+ return (ref = results.find((result)=>result.isValid)) !== null && ref !== void 0 ? ref : results[0];
182
+ }
183
+ function _default(context) {
184
+ let config = context.tailwindConfig;
143
185
  let functions = {
144
186
  theme: (node, path, ...defaultValue)=>{
145
- const { isValid , value , error } = validatePath(config, path, defaultValue.length ? defaultValue : undefined);
187
+ let { isValid , value , error , alpha } = resolvePath(config, path, defaultValue.length ? defaultValue : undefined);
146
188
  if (!isValid) {
189
+ var ref;
190
+ let parentNode = node.parent;
191
+ let candidate = (ref = parentNode === null || parentNode === void 0 ? void 0 : parentNode.raws.tailwind) === null || ref === void 0 ? void 0 : ref.candidate;
192
+ if (parentNode && candidate !== undefined) {
193
+ // Remove this utility from any caches
194
+ context.markInvalidUtilityNode(parentNode);
195
+ // Remove the CSS node from the markup
196
+ parentNode.remove();
197
+ // Show a warning
198
+ _log.default.warn("invalid-theme-key-in-class", [
199
+ `The utility \`${candidate}\` contains an invalid theme value and was not generated.`
200
+ ]);
201
+ return;
202
+ }
147
203
  throw node.error(error);
148
204
  }
205
+ let maybeColor = (0, _pluginUtils.parseColorFormat)(value);
206
+ let isColorFunction = maybeColor !== undefined && typeof maybeColor === "function";
207
+ if (alpha !== undefined || isColorFunction) {
208
+ if (alpha === undefined) {
209
+ alpha = 1.0;
210
+ }
211
+ value = (0, _withAlphaVariable.withAlphaValue)(maybeColor, alpha, maybeColor);
212
+ }
149
213
  return value;
150
214
  },
151
215
  screen: (node, screen)=>{
152
- screen = screen.replace(/^['"]+/g, '').replace(/['"]+$/g, '');
153
- let screens = (0, _normalizeScreens).normalizeScreens(config.theme.screens);
154
- let screenDefinition = screens.find(({ name })=>name === screen
155
- );
216
+ screen = screen.replace(/^['"]+/g, "").replace(/['"]+$/g, "");
217
+ let screens = (0, _normalizeScreens.normalizeScreens)(config.theme.screens);
218
+ let screenDefinition = screens.find(({ name })=>name === screen);
156
219
  if (!screenDefinition) {
157
220
  throw node.error(`The '${screen}' screen does not exist in your theme.`);
158
221
  }
159
- return (0, _buildMediaQuery).default(screenDefinition);
222
+ return (0, _buildMediaQuery.default)(screenDefinition);
160
223
  }
161
224
  };
162
225
  return (root)=>{