tailwindcss 0.0.0-insiders.deefbf5 → 0.0.0-insiders.df96ea5

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