tailwindcss 0.0.0-insiders.7c337f2 → 0.0.0-insiders.7d8eb21

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 (161) hide show
  1. package/CHANGELOG.md +246 -6
  2. package/README.md +13 -9
  3. package/defaultTheme.d.ts +2 -1
  4. package/lib/cli/build/deps.js +54 -0
  5. package/lib/cli/build/index.js +48 -0
  6. package/lib/cli/build/plugin.js +362 -0
  7. package/lib/cli/build/utils.js +78 -0
  8. package/lib/cli/build/watching.js +178 -0
  9. package/lib/cli/help/index.js +71 -0
  10. package/lib/cli/index.js +18 -0
  11. package/lib/cli/init/index.js +46 -0
  12. package/lib/cli/shared.js +12 -0
  13. package/lib/cli-peer-dependencies.js +18 -5
  14. package/lib/cli.js +62 -592
  15. package/lib/constants.js +19 -12
  16. package/lib/corePluginList.js +5 -3
  17. package/lib/corePlugins.js +619 -347
  18. package/lib/css/preflight.css +7 -0
  19. package/lib/featureFlags.js +34 -22
  20. package/lib/index.js +16 -9
  21. package/lib/lib/cacheInvalidation.js +42 -21
  22. package/lib/lib/collapseAdjacentRules.js +16 -14
  23. package/lib/lib/collapseDuplicateDeclarations.js +13 -10
  24. package/lib/lib/content.js +177 -0
  25. package/lib/lib/defaultExtractor.js +230 -33
  26. package/lib/lib/detectNesting.js +13 -4
  27. package/lib/lib/evaluateTailwindFunctions.js +105 -42
  28. package/lib/lib/expandApplyAtRules.js +151 -92
  29. package/lib/lib/expandTailwindAtRules.js +134 -149
  30. package/lib/lib/findAtConfigPath.js +44 -0
  31. package/lib/lib/generateRules.js +404 -185
  32. package/lib/lib/getModuleDependencies.js +21 -18
  33. package/lib/lib/normalizeTailwindDirectives.js +11 -8
  34. package/lib/lib/offsets.js +285 -0
  35. package/lib/lib/partitionApplyAtRules.js +14 -11
  36. package/lib/lib/regex.js +60 -0
  37. package/lib/lib/remap-bitfield.js +87 -0
  38. package/lib/lib/resolveDefaultsAtRules.js +97 -79
  39. package/lib/lib/setupContextUtils.js +567 -242
  40. package/lib/lib/setupTrackingContext.js +77 -106
  41. package/lib/lib/sharedState.js +18 -10
  42. package/lib/lib/substituteScreenAtRules.js +9 -7
  43. package/lib/postcss-plugins/nesting/index.js +7 -5
  44. package/lib/postcss-plugins/nesting/plugin.js +10 -8
  45. package/lib/processTailwindFeatures.js +34 -31
  46. package/lib/public/colors.js +7 -5
  47. package/lib/public/create-plugin.js +6 -4
  48. package/lib/public/default-config.js +7 -5
  49. package/lib/public/default-theme.js +7 -5
  50. package/lib/public/resolve-config.js +13 -10
  51. package/lib/util/bigSign.js +4 -1
  52. package/lib/util/buildMediaQuery.js +10 -5
  53. package/lib/util/cloneDeep.js +6 -5
  54. package/lib/util/cloneNodes.js +9 -2
  55. package/lib/util/color.js +20 -17
  56. package/lib/util/configurePlugins.js +5 -2
  57. package/lib/util/createPlugin.js +6 -5
  58. package/lib/util/createUtilityPlugin.js +15 -13
  59. package/lib/util/dataTypes.js +75 -51
  60. package/lib/util/defaults.js +8 -5
  61. package/lib/util/escapeClassName.js +13 -10
  62. package/lib/util/escapeCommas.js +4 -1
  63. package/lib/util/flattenColorPalette.js +7 -8
  64. package/lib/util/formatVariantSelector.js +270 -103
  65. package/lib/util/getAllConfigs.js +34 -15
  66. package/lib/util/hashConfig.js +10 -7
  67. package/lib/util/isKeyframeRule.js +4 -1
  68. package/lib/util/isPlainObject.js +4 -1
  69. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +34 -26
  70. package/lib/util/log.js +14 -8
  71. package/lib/util/nameClass.js +19 -8
  72. package/lib/util/negateValue.js +20 -5
  73. package/lib/util/normalizeConfig.js +94 -53
  74. package/lib/util/normalizeScreens.js +115 -4
  75. package/lib/util/parseAnimationValue.js +43 -41
  76. package/lib/util/parseBoxShadowValue.js +12 -45
  77. package/lib/util/parseDependency.js +37 -55
  78. package/lib/util/parseGlob.js +34 -0
  79. package/lib/util/parseObjectStyles.js +15 -12
  80. package/lib/util/pluginUtils.js +146 -42
  81. package/lib/util/prefixSelector.js +26 -9
  82. package/lib/util/removeAlphaVariables.js +29 -0
  83. package/lib/util/resolveConfig.js +104 -105
  84. package/lib/util/resolveConfigPath.js +20 -17
  85. package/lib/util/responsive.js +12 -9
  86. package/lib/util/splitAtTopLevelOnly.js +43 -0
  87. package/lib/util/tap.js +4 -1
  88. package/lib/util/toColorValue.js +4 -1
  89. package/lib/util/toPath.js +18 -2
  90. package/lib/util/transformThemeValue.js +23 -11
  91. package/lib/util/validateConfig.js +24 -0
  92. package/lib/util/validateFormalSyntax.js +24 -0
  93. package/lib/util/withAlphaVariable.js +32 -24
  94. package/package.json +32 -29
  95. package/peers/index.js +6693 -3036
  96. package/plugin.d.ts +10 -5
  97. package/resolveConfig.d.ts +12 -0
  98. package/scripts/generate-types.js +53 -0
  99. package/scripts/release-channel.js +18 -0
  100. package/scripts/release-notes.js +21 -0
  101. package/scripts/type-utils.js +27 -0
  102. package/src/cli/build/deps.js +56 -0
  103. package/src/cli/build/index.js +49 -0
  104. package/src/cli/build/plugin.js +434 -0
  105. package/src/cli/build/utils.js +76 -0
  106. package/src/cli/build/watching.js +227 -0
  107. package/src/cli/help/index.js +70 -0
  108. package/src/cli/index.js +3 -0
  109. package/src/cli/init/index.js +50 -0
  110. package/src/cli/shared.js +5 -0
  111. package/src/cli-peer-dependencies.js +7 -1
  112. package/src/cli.js +46 -659
  113. package/src/corePlugins.js +346 -79
  114. package/src/css/preflight.css +7 -0
  115. package/src/featureFlags.js +12 -2
  116. package/src/index.js +5 -0
  117. package/src/lib/content.js +213 -0
  118. package/src/lib/defaultExtractor.js +202 -35
  119. package/src/lib/detectNesting.js +9 -1
  120. package/src/lib/evaluateTailwindFunctions.js +78 -7
  121. package/src/lib/expandApplyAtRules.js +129 -34
  122. package/src/lib/expandTailwindAtRules.js +12 -50
  123. package/src/lib/findAtConfigPath.js +48 -0
  124. package/src/lib/generateRules.js +379 -126
  125. package/src/lib/offsets.js +351 -0
  126. package/src/lib/regex.js +74 -0
  127. package/src/lib/remap-bitfield.js +82 -0
  128. package/src/lib/resolveDefaultsAtRules.js +53 -36
  129. package/src/lib/setupContextUtils.js +510 -120
  130. package/src/lib/setupTrackingContext.js +8 -45
  131. package/src/lib/sharedState.js +2 -0
  132. package/src/util/buildMediaQuery.js +5 -3
  133. package/src/util/cloneNodes.js +5 -1
  134. package/src/util/dataTypes.js +51 -26
  135. package/src/util/formatVariantSelector.js +317 -101
  136. package/src/util/getAllConfigs.js +19 -0
  137. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  138. package/src/util/log.js +1 -1
  139. package/src/util/nameClass.js +4 -0
  140. package/src/util/negateValue.js +10 -2
  141. package/src/util/normalizeConfig.js +40 -10
  142. package/src/util/normalizeScreens.js +99 -4
  143. package/src/util/parseBoxShadowValue.js +3 -50
  144. package/src/util/parseDependency.js +37 -42
  145. package/src/util/parseGlob.js +24 -0
  146. package/src/util/pluginUtils.js +132 -10
  147. package/src/util/prefixSelector.js +28 -10
  148. package/src/util/removeAlphaVariables.js +24 -0
  149. package/src/util/resolveConfig.js +70 -62
  150. package/src/util/splitAtTopLevelOnly.js +45 -0
  151. package/src/util/toPath.js +1 -1
  152. package/src/util/transformThemeValue.js +13 -3
  153. package/src/util/validateConfig.js +13 -0
  154. package/src/util/validateFormalSyntax.js +34 -0
  155. package/src/util/withAlphaVariable.js +1 -1
  156. package/stubs/defaultConfig.stub.js +165 -164
  157. package/stubs/simpleConfig.stub.js +1 -0
  158. package/types/config.d.ts +77 -37
  159. package/types/generated/default-theme.d.ts +342 -0
  160. package/types/index.d.ts +7 -1
  161. package/types.d.ts +0 -1
@@ -2,39 +2,236 @@
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]*\('[^"`\s]*'\)+\])/.source,
17
- /([^<>"'`\s]*\[[^<>"'`\s]*\("[^'`\s]*"\)+\])/.source,
18
- /([^${(<>"'`\s]*\['[^"'`\s]*'\])/.source,
19
- /([^${(<>"'`\s]*\["[^"'`\s]*"\])/.source,
20
- /([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source,
21
- /([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source,
22
- /([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source,
23
- /([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
24
- /([^"'`\s]*[^<>"'`\s:\\])/.source,
25
- /([^<>"'`\s]*[^"'`\s:\\])/.source,
26
- ].join("|");
27
- const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, "g");
28
- const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
29
- function defaultExtractor(content) {
30
- let broadMatches = content.matchAll(BROAD_MATCH_GLOBAL_REGEXP);
31
- let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || [];
32
- let results = [
33
- ...broadMatches,
34
- ...innerMatches
35
- ].flat().filter((v)=>v !== undefined
36
- );
37
- 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 _content_match;
58
+ results = [
59
+ ...results,
60
+ ...(_content_match = content.match(pattern)) !== null && _content_match !== void 0 ? _content_match : []
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 (without square brackets)
75
+ /\[[^\s:'"`]+:[^\s\[\]]+\]/,
76
+ // Arbitrary properties with balanced square brackets
77
+ // This is a targeted fix to continue to allow theme()
78
+ // with square brackets to work in arbitrary properties
79
+ // while fixing a problem with the regex matching too much
80
+ /\[[^\s:'"`]+:[^\s]+?\[[^\s]+?\][^\s]+?\]/,
81
+ // Utilities
82
+ _regex.pattern([
83
+ // Utility Name / Group Name
84
+ /-?(?:\w+)/,
85
+ // Normal/Arbitrary values
86
+ _regex.optional(_regex.any([
87
+ _regex.pattern([
88
+ // Arbitrary values
89
+ /-(?:\w+-)*\[[^\s:]+\]/,
90
+ // Not immediately followed by an `{[(`
91
+ /(?![{([]])/,
92
+ // optionally followed by an opacity modifier
93
+ /(?:\/[^\s'"`\\><$]*)?/
94
+ ]),
95
+ _regex.pattern([
96
+ // Arbitrary values
97
+ /-(?:\w+-)*\[[^\s]+\]/,
98
+ // Not immediately followed by an `{[(`
99
+ /(?![{([]])/,
100
+ // optionally followed by an opacity modifier
101
+ /(?:\/[^\s'"`\\$]*)?/
102
+ ]),
103
+ // Normal values w/o quotes — may include an opacity modifier
104
+ /[-\/][^\s'"`\\$={><]*/
105
+ ]))
106
+ ])
107
+ ]);
108
+ let variantPatterns = [
109
+ // Without quotes
110
+ _regex.any([
111
+ // This is here to provide special support for the `@` variant
112
+ _regex.pattern([
113
+ /@\[[^\s"'`]+\](\/[^\s"'`]+)?/,
114
+ separator
115
+ ]),
116
+ _regex.pattern([
117
+ /([^\s"'`\[\\]+-)?\[[^\s"'`]+\]/,
118
+ separator
119
+ ]),
120
+ _regex.pattern([
121
+ /[^\s"'`\[\\]+/,
122
+ separator
123
+ ])
124
+ ]),
125
+ // With quotes allowed
126
+ _regex.any([
127
+ _regex.pattern([
128
+ /([^\s"'`\[\\]+-)?\[[^\s`]+\]/,
129
+ separator
130
+ ]),
131
+ _regex.pattern([
132
+ /[^\s`\[\\]+/,
133
+ separator
134
+ ])
135
+ ])
136
+ ];
137
+ for (const variantPattern of variantPatterns){
138
+ yield _regex.pattern([
139
+ // Variants
140
+ "((?=((",
141
+ variantPattern,
142
+ ")+))\\2)?",
143
+ // Important (optional)
144
+ /!?/,
145
+ prefix,
146
+ variantGroupingEnabled ? _regex.any([
147
+ // Or any of those things but grouped separated by commas
148
+ _regex.pattern([
149
+ /\(/,
150
+ utility,
151
+ _regex.zeroOrMore([
152
+ /,/,
153
+ utility
154
+ ]),
155
+ /\)/
156
+ ]),
157
+ // Arbitrary properties, constrained utilities, arbitrary values, etc…
158
+ utility
159
+ ]) : utility
160
+ ]);
161
+ }
162
+ // 5. Inner matches
163
+ yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
164
+ }
165
+ // We want to capture any "special" characters
166
+ // AND the characters immediately following them (if there is one)
167
+ let SPECIALS = /([\[\]'"`])([^\[\]'"`])?/g;
168
+ let ALLOWED_CLASS_CHARACTERS = /[^"'`\s<>\]]+/;
169
+ /**
170
+ * Clips a string ensuring that parentheses, quotes, etc… are balanced
171
+ * Used for arbitrary values only
172
+ *
173
+ * We will go past the end of the balanced parens until we find a non-class character
174
+ *
175
+ * Depth matching behavior:
176
+ * w-[calc(100%-theme('spacing[some_key][1.5]'))]']
177
+ * ┬ ┬ ┬┬ ┬ ┬┬ ┬┬┬┬┬┬┬
178
+ * 1 2 3 4 34 3 210 END
179
+ * ╰────┴──────────┴────────┴────────┴┴───┴─┴┴┴
180
+ *
181
+ * @param {string} input
182
+ */ function clipAtBalancedParens(input) {
183
+ // We are care about this for arbitrary values
184
+ if (!input.includes("-[")) {
185
+ return input;
186
+ }
187
+ let depth = 0;
188
+ let openStringTypes = [];
189
+ // Find all parens, brackets, quotes, etc
190
+ // Stop when we end at a balanced pair
191
+ // This is naive and will treat mismatched parens as balanced
192
+ // This shouldn't be a problem in practice though
193
+ let matches = input.matchAll(SPECIALS);
194
+ // We can't use lookbehind assertions because we have to support Safari
195
+ // So, instead, we've emulated it using capture groups and we'll re-work the matches to accommodate
196
+ matches = Array.from(matches).flatMap((match)=>{
197
+ const [, ...groups] = match;
198
+ return groups.map((group, idx)=>Object.assign([], match, {
199
+ index: match.index + idx,
200
+ 0: group
201
+ }));
202
+ });
203
+ for (let match of matches){
204
+ let char = match[0];
205
+ let inStringType = openStringTypes[openStringTypes.length - 1];
206
+ if (char === inStringType) {
207
+ openStringTypes.pop();
208
+ } else if (char === "'" || char === '"' || char === "`") {
209
+ openStringTypes.push(char);
210
+ }
211
+ if (inStringType) {
212
+ continue;
213
+ } else if (char === "[") {
214
+ depth++;
215
+ continue;
216
+ } else if (char === "]") {
217
+ depth--;
218
+ continue;
219
+ }
220
+ // We've gone one character past the point where we should stop
221
+ // This means that there was an extra closing `]`
222
+ // We'll clip to just before it
223
+ if (depth < 0) {
224
+ return input.substring(0, match.index - 1);
225
+ }
226
+ // We've finished balancing the brackets but there still may be characters that can be included
227
+ // For example in the class `text-[#336699]/[.35]`
228
+ // The depth goes to `0` at the closing `]` but goes up again at the `[`
229
+ // If we're at zero and encounter a non-class character then we clip the class there
230
+ if (depth === 0 && !ALLOWED_CLASS_CHARACTERS.test(char)) {
231
+ return input.substring(0, match.index);
232
+ }
233
+ }
234
+ return input;
38
235
  } // Regular utilities
39
236
  // {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
40
237
  // Arbitrary values
@@ -2,18 +2,27 @@
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
+ });
9
+ function isRoot(node) {
10
+ return node.type === "root";
11
+ }
12
+ function isAtLayer(node) {
13
+ return node.type === "atrule" && node.name === "layer";
14
+ }
6
15
  function _default(_context) {
7
16
  return (root, result)=>{
8
17
  let found = false;
9
18
  root.walkAtRules("tailwind", (node)=>{
10
19
  if (found) return false;
11
- if (node.parent && node.parent.type !== "root") {
20
+ if (node.parent && !(isRoot(node.parent) || isAtLayer(node.parent))) {
12
21
  found = true;
13
22
  node.warn(result, [
14
23
  "Nested @tailwind rules were detected, but are not supported.",
15
24
  "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",
25
+ "Alternatively, use the important selector strategy: https://tailwindcss.com/docs/configuration#selector-strategy"
17
26
  ].join("\n"));
18
27
  return false;
19
28
  }
@@ -25,7 +34,7 @@ function _default(_context) {
25
34
  nestedRule.warn(result, [
26
35
  "Nested CSS was detected, but CSS nesting has not been configured correctly.",
27
36
  "Please enable a CSS nesting plugin *before* Tailwind in your configuration.",
28
- "See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting",
37
+ "See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting"
29
38
  ].join("\n"));
30
39
  return false;
31
40
  });
@@ -2,14 +2,20 @@
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
@@ -19,10 +25,10 @@ function isObject(input) {
19
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;
31
+ if ((0, _dlv.default)(theme, parts) !== undefined) break;
26
32
  }while (parts.length);
27
33
  return parts.length ? parts : undefined;
28
34
  }
@@ -34,27 +40,25 @@ function pathToString(path) {
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 {
@@ -82,42 +86,40 @@ function validatePath(config, path, defaultValue) {
82
86
  };
83
87
  }
84
88
  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.`;
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
+ for (let vNode of vNodes){
119
+ if (vNode.type === "div" && vNode.value === ",") {
118
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;
@@ -131,7 +133,7 @@ function resolveVNode(node, vNode, functions) {
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
  }
@@ -139,24 +141,85 @@ let nodeTypePropertyMap = {
139
141
  atrule: "params",
140
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 _results_find;
181
+ return (_results_find = results.find((result)=>result.isValid)) !== null && _results_find !== void 0 ? _results_find : 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 _parentNode_raws_tailwind;
190
+ let parentNode = node.parent;
191
+ let candidate = (_parentNode_raws_tailwind = parentNode === null || parentNode === void 0 ? void 0 : parentNode.raws.tailwind) === null || _parentNode_raws_tailwind === void 0 ? void 0 : _parentNode_raws_tailwind.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
216
  screen = screen.replace(/^['"]+/g, "").replace(/['"]+$/g, "");
153
- let screens = (0, _normalizeScreens).normalizeScreens(config.theme.screens);
154
- let screenDefinition = screens.find(({ name })=>name === screen
155
- );
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)=>{