tailwindcss 0.0.0-oxide-insiders.f49b054 → 0.0.0-oxide.1

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 (286) hide show
  1. package/dist/chunk-J6HTTNZH.mjs +5017 -0
  2. package/dist/cli.d.mts +2 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +5446 -0
  5. package/dist/cli.mjs +438 -0
  6. package/dist/lib.d.mts +244 -0
  7. package/dist/lib.d.ts +244 -0
  8. package/dist/lib.js +4947 -0
  9. package/dist/lib.mjs +1 -0
  10. package/index.css +4 -4
  11. package/package.json +36 -106
  12. package/preflight.css +404 -0
  13. package/theme.css +468 -0
  14. package/LICENSE +0 -21
  15. package/README.md +0 -41
  16. package/base.css +0 -1
  17. package/colors.d.ts +0 -3
  18. package/colors.js +0 -2
  19. package/components.css +0 -1
  20. package/defaultConfig.d.ts +0 -3
  21. package/defaultConfig.js +0 -2
  22. package/defaultTheme.d.ts +0 -4
  23. package/defaultTheme.js +0 -2
  24. package/lib/cli/build/deps.js +0 -62
  25. package/lib/cli/build/index.js +0 -54
  26. package/lib/cli/build/plugin.js +0 -383
  27. package/lib/cli/build/utils.js +0 -88
  28. package/lib/cli/build/watching.js +0 -182
  29. package/lib/cli/help/index.js +0 -73
  30. package/lib/cli/index.js +0 -230
  31. package/lib/cli/init/index.js +0 -67
  32. package/lib/cli-peer-dependencies.js +0 -36
  33. package/lib/cli.js +0 -7
  34. package/lib/corePluginList.js +0 -187
  35. package/lib/corePlugins.js +0 -4173
  36. package/lib/css/LICENSE +0 -25
  37. package/lib/css/preflight.css +0 -375
  38. package/lib/featureFlags.js +0 -83
  39. package/lib/index.js +0 -2
  40. package/lib/lib/cacheInvalidation.js +0 -92
  41. package/lib/lib/collapseAdjacentRules.js +0 -61
  42. package/lib/lib/collapseDuplicateDeclarations.js +0 -85
  43. package/lib/lib/content.js +0 -202
  44. package/lib/lib/defaultExtractor.js +0 -243
  45. package/lib/lib/detectNesting.js +0 -45
  46. package/lib/lib/evaluateTailwindFunctions.js +0 -238
  47. package/lib/lib/expandApplyAtRules.js +0 -534
  48. package/lib/lib/expandTailwindAtRules.js +0 -274
  49. package/lib/lib/findAtConfigPath.js +0 -46
  50. package/lib/lib/generateRules.js +0 -882
  51. package/lib/lib/getModuleDependencies.js +0 -99
  52. package/lib/lib/handleImportAtRules.js +0 -49
  53. package/lib/lib/load-config.js +0 -42
  54. package/lib/lib/normalizeTailwindDirectives.js +0 -91
  55. package/lib/lib/offsets.js +0 -306
  56. package/lib/lib/partitionApplyAtRules.js +0 -58
  57. package/lib/lib/regex.js +0 -74
  58. package/lib/lib/remap-bitfield.js +0 -89
  59. package/lib/lib/resolveDefaultsAtRules.js +0 -165
  60. package/lib/lib/setupContextUtils.js +0 -1255
  61. package/lib/lib/setupTrackingContext.js +0 -165
  62. package/lib/lib/sharedState.js +0 -87
  63. package/lib/lib/substituteScreenAtRules.js +0 -31
  64. package/lib/oxide/cli/build/deps.js +0 -89
  65. package/lib/oxide/cli/build/index.js +0 -53
  66. package/lib/oxide/cli/build/plugin.js +0 -354
  67. package/lib/oxide/cli/build/utils.js +0 -87
  68. package/lib/oxide/cli/build/watching.js +0 -179
  69. package/lib/oxide/cli/help/index.js +0 -72
  70. package/lib/oxide/cli/index.js +0 -214
  71. package/lib/oxide/cli/init/index.js +0 -56
  72. package/lib/oxide/cli.js +0 -5
  73. package/lib/oxide/postcss-plugin.js +0 -2
  74. package/lib/plugin.js +0 -100
  75. package/lib/postcss-plugins/nesting/README.md +0 -42
  76. package/lib/postcss-plugins/nesting/index.js +0 -21
  77. package/lib/postcss-plugins/nesting/plugin.js +0 -89
  78. package/lib/processTailwindFeatures.js +0 -64
  79. package/lib/public/colors.js +0 -355
  80. package/lib/public/create-plugin.js +0 -17
  81. package/lib/public/default-config.js +0 -18
  82. package/lib/public/default-theme.js +0 -18
  83. package/lib/public/load-config.js +0 -12
  84. package/lib/public/resolve-config.js +0 -24
  85. package/lib/util/applyImportantSelector.js +0 -36
  86. package/lib/util/bigSign.js +0 -13
  87. package/lib/util/buildMediaQuery.js +0 -27
  88. package/lib/util/cloneDeep.js +0 -22
  89. package/lib/util/cloneNodes.js +0 -34
  90. package/lib/util/color.js +0 -116
  91. package/lib/util/colorNames.js +0 -752
  92. package/lib/util/configurePlugins.js +0 -23
  93. package/lib/util/createPlugin.js +0 -32
  94. package/lib/util/createUtilityPlugin.js +0 -53
  95. package/lib/util/dataTypes.js +0 -304
  96. package/lib/util/defaults.js +0 -27
  97. package/lib/util/escapeClassName.js +0 -24
  98. package/lib/util/escapeCommas.js +0 -13
  99. package/lib/util/flattenColorPalette.js +0 -18
  100. package/lib/util/formatVariantSelector.js +0 -263
  101. package/lib/util/getAllConfigs.js +0 -52
  102. package/lib/util/hashConfig.js +0 -21
  103. package/lib/util/isKeyframeRule.js +0 -13
  104. package/lib/util/isPlainObject.js +0 -17
  105. package/lib/util/isSyntacticallyValidPropertyValue.js +0 -74
  106. package/lib/util/log.js +0 -61
  107. package/lib/util/nameClass.js +0 -49
  108. package/lib/util/negateValue.js +0 -36
  109. package/lib/util/normalizeConfig.js +0 -304
  110. package/lib/util/normalizeScreens.js +0 -178
  111. package/lib/util/parseAnimationValue.js +0 -93
  112. package/lib/util/parseBoxShadowValue.js +0 -88
  113. package/lib/util/parseDependency.js +0 -47
  114. package/lib/util/parseGlob.js +0 -36
  115. package/lib/util/parseObjectStyles.js +0 -36
  116. package/lib/util/pluginUtils.js +0 -276
  117. package/lib/util/prefixSelector.js +0 -39
  118. package/lib/util/pseudoElements.js +0 -229
  119. package/lib/util/removeAlphaVariables.js +0 -31
  120. package/lib/util/resolveConfig.js +0 -256
  121. package/lib/util/resolveConfigPath.js +0 -70
  122. package/lib/util/responsive.js +0 -24
  123. package/lib/util/splitAtTopLevelOnly.js +0 -51
  124. package/lib/util/tap.js +0 -14
  125. package/lib/util/toColorValue.js +0 -13
  126. package/lib/util/toPath.js +0 -32
  127. package/lib/util/transformThemeValue.js +0 -73
  128. package/lib/util/validateConfig.js +0 -43
  129. package/lib/util/validateFormalSyntax.js +0 -26
  130. package/lib/util/withAlphaVariable.js +0 -79
  131. package/lib/value-parser/LICENSE +0 -22
  132. package/lib/value-parser/README.md +0 -3
  133. package/lib/value-parser/index.d.js +0 -2
  134. package/lib/value-parser/index.js +0 -22
  135. package/lib/value-parser/parse.js +0 -259
  136. package/lib/value-parser/stringify.js +0 -38
  137. package/lib/value-parser/unit.js +0 -86
  138. package/lib/value-parser/walk.js +0 -16
  139. package/loadConfig.d.ts +0 -4
  140. package/loadConfig.js +0 -2
  141. package/nesting/index.js +0 -2
  142. package/peers/index.js +0 -96294
  143. package/plugin.d.ts +0 -11
  144. package/plugin.js +0 -2
  145. package/prettier.config.js +0 -19
  146. package/resolveConfig.d.ts +0 -12
  147. package/resolveConfig.js +0 -2
  148. package/screens.css +0 -1
  149. package/scripts/create-plugin-list.js +0 -10
  150. package/scripts/generate-types.js +0 -105
  151. package/scripts/release-channel.js +0 -18
  152. package/scripts/release-notes.js +0 -21
  153. package/scripts/swap-engines.js +0 -40
  154. package/scripts/type-utils.js +0 -27
  155. package/src/cli/build/deps.js +0 -56
  156. package/src/cli/build/index.js +0 -49
  157. package/src/cli/build/plugin.js +0 -451
  158. package/src/cli/build/utils.js +0 -76
  159. package/src/cli/build/watching.js +0 -229
  160. package/src/cli/help/index.js +0 -70
  161. package/src/cli/index.js +0 -216
  162. package/src/cli/init/index.js +0 -84
  163. package/src/cli-peer-dependencies.js +0 -15
  164. package/src/cli.js +0 -7
  165. package/src/corePluginList.js +0 -1
  166. package/src/corePlugins.js +0 -2849
  167. package/src/css/LICENSE +0 -25
  168. package/src/css/preflight.css +0 -375
  169. package/src/featureFlags.js +0 -70
  170. package/src/index.js +0 -1
  171. package/src/lib/cacheInvalidation.js +0 -52
  172. package/src/lib/collapseAdjacentRules.js +0 -58
  173. package/src/lib/collapseDuplicateDeclarations.js +0 -93
  174. package/src/lib/content.js +0 -235
  175. package/src/lib/defaultExtractor.js +0 -217
  176. package/src/lib/detectNesting.js +0 -47
  177. package/src/lib/evaluateTailwindFunctions.js +0 -272
  178. package/src/lib/expandApplyAtRules.js +0 -613
  179. package/src/lib/expandTailwindAtRules.js +0 -283
  180. package/src/lib/findAtConfigPath.js +0 -48
  181. package/src/lib/generateRules.js +0 -927
  182. package/src/lib/getModuleDependencies.js +0 -79
  183. package/src/lib/handleImportAtRules.js +0 -33
  184. package/src/lib/load-config.ts +0 -31
  185. package/src/lib/normalizeTailwindDirectives.js +0 -86
  186. package/src/lib/offsets.js +0 -373
  187. package/src/lib/partitionApplyAtRules.js +0 -52
  188. package/src/lib/regex.js +0 -74
  189. package/src/lib/remap-bitfield.js +0 -82
  190. package/src/lib/resolveDefaultsAtRules.js +0 -163
  191. package/src/lib/setupContextUtils.js +0 -1327
  192. package/src/lib/setupTrackingContext.js +0 -171
  193. package/src/lib/sharedState.js +0 -61
  194. package/src/lib/substituteScreenAtRules.js +0 -19
  195. package/src/oxide/cli/build/deps.ts +0 -91
  196. package/src/oxide/cli/build/index.ts +0 -47
  197. package/src/oxide/cli/build/plugin.ts +0 -419
  198. package/src/oxide/cli/build/utils.ts +0 -74
  199. package/src/oxide/cli/build/watching.ts +0 -225
  200. package/src/oxide/cli/help/index.ts +0 -69
  201. package/src/oxide/cli/index.ts +0 -204
  202. package/src/oxide/cli/init/index.ts +0 -64
  203. package/src/oxide/cli.ts +0 -1
  204. package/src/oxide/postcss-plugin.ts +0 -1
  205. package/src/plugin.js +0 -109
  206. package/src/postcss-plugins/nesting/README.md +0 -42
  207. package/src/postcss-plugins/nesting/index.js +0 -13
  208. package/src/postcss-plugins/nesting/plugin.js +0 -80
  209. package/src/processTailwindFeatures.js +0 -58
  210. package/src/public/colors.js +0 -322
  211. package/src/public/create-plugin.js +0 -2
  212. package/src/public/default-config.js +0 -4
  213. package/src/public/default-theme.js +0 -4
  214. package/src/public/load-config.js +0 -2
  215. package/src/public/resolve-config.js +0 -7
  216. package/src/util/applyImportantSelector.js +0 -27
  217. package/src/util/bigSign.js +0 -3
  218. package/src/util/buildMediaQuery.js +0 -22
  219. package/src/util/cloneDeep.js +0 -11
  220. package/src/util/cloneNodes.js +0 -28
  221. package/src/util/color.js +0 -88
  222. package/src/util/colorNames.js +0 -150
  223. package/src/util/configurePlugins.js +0 -23
  224. package/src/util/createPlugin.js +0 -27
  225. package/src/util/createUtilityPlugin.js +0 -37
  226. package/src/util/dataTypes.js +0 -292
  227. package/src/util/defaults.js +0 -17
  228. package/src/util/escapeClassName.js +0 -8
  229. package/src/util/escapeCommas.js +0 -3
  230. package/src/util/flattenColorPalette.js +0 -13
  231. package/src/util/formatVariantSelector.js +0 -316
  232. package/src/util/getAllConfigs.js +0 -45
  233. package/src/util/hashConfig.js +0 -5
  234. package/src/util/isKeyframeRule.js +0 -3
  235. package/src/util/isPlainObject.js +0 -8
  236. package/src/util/isSyntacticallyValidPropertyValue.js +0 -61
  237. package/src/util/log.js +0 -29
  238. package/src/util/nameClass.js +0 -30
  239. package/src/util/negateValue.js +0 -24
  240. package/src/util/normalizeConfig.js +0 -335
  241. package/src/util/normalizeScreens.js +0 -140
  242. package/src/util/parseAnimationValue.js +0 -68
  243. package/src/util/parseBoxShadowValue.js +0 -72
  244. package/src/util/parseDependency.js +0 -44
  245. package/src/util/parseGlob.js +0 -24
  246. package/src/util/parseObjectStyles.js +0 -19
  247. package/src/util/pluginUtils.js +0 -291
  248. package/src/util/prefixSelector.js +0 -32
  249. package/src/util/pseudoElements.js +0 -170
  250. package/src/util/removeAlphaVariables.js +0 -24
  251. package/src/util/resolveConfig.js +0 -277
  252. package/src/util/resolveConfigPath.js +0 -66
  253. package/src/util/responsive.js +0 -10
  254. package/src/util/splitAtTopLevelOnly.js +0 -52
  255. package/src/util/tap.js +0 -4
  256. package/src/util/toColorValue.js +0 -3
  257. package/src/util/toPath.js +0 -26
  258. package/src/util/transformThemeValue.js +0 -62
  259. package/src/util/validateConfig.js +0 -33
  260. package/src/util/validateFormalSyntax.js +0 -34
  261. package/src/util/withAlphaVariable.js +0 -49
  262. package/src/value-parser/LICENSE +0 -22
  263. package/src/value-parser/README.md +0 -3
  264. package/src/value-parser/index.d.ts +0 -177
  265. package/src/value-parser/index.js +0 -28
  266. package/src/value-parser/parse.js +0 -303
  267. package/src/value-parser/stringify.js +0 -41
  268. package/src/value-parser/unit.js +0 -118
  269. package/src/value-parser/walk.js +0 -18
  270. package/stubs/.gitignore +0 -1
  271. package/stubs/.prettierrc.json +0 -6
  272. package/stubs/config.full.js +0 -991
  273. package/stubs/config.simple.js +0 -7
  274. package/stubs/postcss.config.cjs +0 -6
  275. package/stubs/postcss.config.js +0 -6
  276. package/stubs/tailwind.config.cjs +0 -2
  277. package/stubs/tailwind.config.js +0 -2
  278. package/stubs/tailwind.config.ts +0 -3
  279. package/tailwind.css +0 -5
  280. package/types/config.d.ts +0 -368
  281. package/types/generated/.gitkeep +0 -0
  282. package/types/generated/colors.d.ts +0 -298
  283. package/types/generated/corePluginList.d.ts +0 -1
  284. package/types/generated/default-theme.d.ts +0 -372
  285. package/types/index.d.ts +0 -7
  286. package/variants.css +0 -1
@@ -1,1327 +0,0 @@
1
- import fs from 'fs'
2
- import url from 'url'
3
- import postcss from 'postcss'
4
- import dlv from 'dlv'
5
- import selectorParser from 'postcss-selector-parser'
6
-
7
- import transformThemeValue from '../util/transformThemeValue'
8
- import parseObjectStyles from '../util/parseObjectStyles'
9
- import prefixSelector from '../util/prefixSelector'
10
- import isPlainObject from '../util/isPlainObject'
11
- import escapeClassName from '../util/escapeClassName'
12
- import nameClass, { formatClass } from '../util/nameClass'
13
- import { coerceValue } from '../util/pluginUtils'
14
- import { variantPlugins, corePlugins } from '../corePlugins'
15
- import * as sharedState from './sharedState'
16
- import { env } from './sharedState'
17
- import { toPath } from '../util/toPath'
18
- import log from '../util/log'
19
- import negateValue from '../util/negateValue'
20
- import isSyntacticallyValidPropertyValue from '../util/isSyntacticallyValidPropertyValue'
21
- import { generateRules, getClassNameFromSelector } from './generateRules'
22
- import { hasContentChanged } from './cacheInvalidation.js'
23
- import { Offsets } from './offsets.js'
24
- import { flagEnabled } from '../featureFlags.js'
25
- import { finalizeSelector, formatVariantSelector } from '../util/formatVariantSelector'
26
-
27
- const VARIANT_TYPES = {
28
- AddVariant: Symbol.for('ADD_VARIANT'),
29
- MatchVariant: Symbol.for('MATCH_VARIANT'),
30
- }
31
-
32
- const VARIANT_INFO = {
33
- Base: 1 << 0,
34
- Dynamic: 1 << 1,
35
- }
36
-
37
- function prefix(context, selector) {
38
- let prefix = context.tailwindConfig.prefix
39
- return typeof prefix === 'function' ? prefix(selector) : prefix + selector
40
- }
41
-
42
- function normalizeOptionTypes({ type = 'any', ...options }) {
43
- let types = [].concat(type)
44
-
45
- return {
46
- ...options,
47
- types: types.map((type) => {
48
- if (Array.isArray(type)) {
49
- return { type: type[0], ...type[1] }
50
- }
51
- return { type, preferOnConflict: false }
52
- }),
53
- }
54
- }
55
-
56
- function parseVariantFormatString(input) {
57
- /** @type {string[]} */
58
- let parts = []
59
-
60
- // When parsing whitespace around special characters are insignificant
61
- // However, _inside_ of a variant they could be
62
- // Because the selector could look like this
63
- // @media { &[data-name="foo bar"] }
64
- // This is why we do not skip whitespace
65
-
66
- let current = ''
67
- let depth = 0
68
-
69
- for (let idx = 0; idx < input.length; idx++) {
70
- let char = input[idx]
71
-
72
- if (char === '\\') {
73
- // Escaped characters are not special
74
- current += '\\' + input[++idx]
75
- } else if (char === '{') {
76
- // Nested rule: start
77
- ++depth
78
- parts.push(current.trim())
79
- current = ''
80
- } else if (char === '}') {
81
- // Nested rule: end
82
- if (--depth < 0) {
83
- throw new Error(`Your { and } are unbalanced.`)
84
- }
85
-
86
- parts.push(current.trim())
87
- current = ''
88
- } else {
89
- // Normal character
90
- current += char
91
- }
92
- }
93
-
94
- if (current.length > 0) {
95
- parts.push(current.trim())
96
- }
97
-
98
- parts = parts.filter((part) => part !== '')
99
-
100
- return parts
101
- }
102
-
103
- function insertInto(list, value, { before = [] } = {}) {
104
- before = [].concat(before)
105
-
106
- if (before.length <= 0) {
107
- list.push(value)
108
- return
109
- }
110
-
111
- let idx = list.length - 1
112
- for (let other of before) {
113
- let iidx = list.indexOf(other)
114
- if (iidx === -1) continue
115
- idx = Math.min(idx, iidx)
116
- }
117
-
118
- list.splice(idx, 0, value)
119
- }
120
-
121
- function parseStyles(styles) {
122
- if (!Array.isArray(styles)) {
123
- return parseStyles([styles])
124
- }
125
-
126
- return styles.flatMap((style) => {
127
- let isNode = !Array.isArray(style) && !isPlainObject(style)
128
- return isNode ? style : parseObjectStyles(style)
129
- })
130
- }
131
-
132
- function getClasses(selector, mutate) {
133
- let parser = selectorParser((selectors) => {
134
- let allClasses = []
135
-
136
- if (mutate) {
137
- mutate(selectors)
138
- }
139
-
140
- selectors.walkClasses((classNode) => {
141
- allClasses.push(classNode.value)
142
- })
143
-
144
- return allClasses
145
- })
146
- return parser.transformSync(selector)
147
- }
148
-
149
- function extractCandidates(node, state = { containsNonOnDemandable: false }, depth = 0) {
150
- let classes = []
151
-
152
- // Handle normal rules
153
- if (node.type === 'rule') {
154
- // Ignore everything inside a :not(...). This allows you to write code like
155
- // `div:not(.foo)`. If `.foo` is never found in your code, then we used to
156
- // not generated it. But now we will ignore everything inside a `:not`, so
157
- // that it still gets generated.
158
- function ignoreNot(selectors) {
159
- selectors.walkPseudos((pseudo) => {
160
- if (pseudo.value === ':not') {
161
- pseudo.remove()
162
- }
163
- })
164
- }
165
-
166
- for (let selector of node.selectors) {
167
- let classCandidates = getClasses(selector, ignoreNot)
168
- // At least one of the selectors contains non-"on-demandable" candidates.
169
- if (classCandidates.length === 0) {
170
- state.containsNonOnDemandable = true
171
- }
172
-
173
- for (let classCandidate of classCandidates) {
174
- classes.push(classCandidate)
175
- }
176
- }
177
- }
178
-
179
- // Handle at-rules (which contains nested rules)
180
- else if (node.type === 'atrule') {
181
- node.walkRules((rule) => {
182
- for (let classCandidate of rule.selectors.flatMap((selector) => getClasses(selector))) {
183
- classes.push(classCandidate)
184
- }
185
- })
186
- }
187
-
188
- if (depth === 0) {
189
- return [state.containsNonOnDemandable || classes.length === 0, classes]
190
- }
191
-
192
- return classes
193
- }
194
-
195
- function withIdentifiers(styles) {
196
- return parseStyles(styles).flatMap((node) => {
197
- let nodeMap = new Map()
198
- let [containsNonOnDemandableSelectors, candidates] = extractCandidates(node)
199
-
200
- // If this isn't "on-demandable", assign it a universal candidate to always include it.
201
- if (containsNonOnDemandableSelectors) {
202
- candidates.unshift(sharedState.NOT_ON_DEMAND)
203
- }
204
-
205
- // However, it could be that it also contains "on-demandable" candidates.
206
- // E.g.: `span, .foo {}`, in that case it should still be possible to use
207
- // `@apply foo` for example.
208
- return candidates.map((c) => {
209
- if (!nodeMap.has(node)) {
210
- nodeMap.set(node, node)
211
- }
212
- return [c, nodeMap.get(node)]
213
- })
214
- })
215
- }
216
-
217
- export function isValidVariantFormatString(format) {
218
- return format.startsWith('@') || format.includes('&')
219
- }
220
-
221
- export function parseVariant(variant) {
222
- variant = variant
223
- .replace(/\n+/g, '')
224
- .replace(/\s{1,}/g, ' ')
225
- .trim()
226
-
227
- let fns = parseVariantFormatString(variant)
228
- .map((str) => {
229
- if (!str.startsWith('@')) {
230
- return ({ format }) => format(str)
231
- }
232
-
233
- let [, name, params] = /@(.*?)( .+|[({].*)/g.exec(str)
234
- return ({ wrap }) => wrap(postcss.atRule({ name, params: params.trim() }))
235
- })
236
- .reverse()
237
-
238
- return (api) => {
239
- for (let fn of fns) {
240
- fn(api)
241
- }
242
- }
243
- }
244
-
245
- /**
246
- *
247
- * @param {any} tailwindConfig
248
- * @param {any} context
249
- * @param {object} param2
250
- * @param {Offsets} param2.offsets
251
- */
252
- function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offsets, classList }) {
253
- function getConfigValue(path, defaultValue) {
254
- return path ? dlv(tailwindConfig, path, defaultValue) : tailwindConfig
255
- }
256
-
257
- function applyConfiguredPrefix(selector) {
258
- return prefixSelector(tailwindConfig.prefix, selector)
259
- }
260
-
261
- function prefixIdentifier(identifier, options) {
262
- if (identifier === sharedState.NOT_ON_DEMAND) {
263
- return sharedState.NOT_ON_DEMAND
264
- }
265
-
266
- if (!options.respectPrefix) {
267
- return identifier
268
- }
269
-
270
- return context.tailwindConfig.prefix + identifier
271
- }
272
-
273
- function resolveThemeValue(path, defaultValue, opts = {}) {
274
- let parts = toPath(path)
275
- let value = getConfigValue(['theme', ...parts], defaultValue)
276
- return transformThemeValue(parts[0])(value, opts)
277
- }
278
-
279
- let variantIdentifier = 0
280
- let api = {
281
- postcss,
282
- prefix: applyConfiguredPrefix,
283
- e: escapeClassName,
284
- config: getConfigValue,
285
- theme: resolveThemeValue,
286
- corePlugins: (path) => {
287
- if (Array.isArray(tailwindConfig.corePlugins)) {
288
- return tailwindConfig.corePlugins.includes(path)
289
- }
290
-
291
- return getConfigValue(['corePlugins', path], true)
292
- },
293
- variants: () => {
294
- // Preserved for backwards compatibility but not used in v3.0+
295
- return []
296
- },
297
- addBase(base) {
298
- for (let [identifier, rule] of withIdentifiers(base)) {
299
- let prefixedIdentifier = prefixIdentifier(identifier, {})
300
- let offset = offsets.create('base')
301
-
302
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
303
- context.candidateRuleMap.set(prefixedIdentifier, [])
304
- }
305
-
306
- context.candidateRuleMap
307
- .get(prefixedIdentifier)
308
- .push([{ sort: offset, layer: 'base' }, rule])
309
- }
310
- },
311
- /**
312
- * @param {string} group
313
- * @param {Record<string, string | string[]>} declarations
314
- */
315
- addDefaults(group, declarations) {
316
- const groups = {
317
- [`@defaults ${group}`]: declarations,
318
- }
319
-
320
- for (let [identifier, rule] of withIdentifiers(groups)) {
321
- let prefixedIdentifier = prefixIdentifier(identifier, {})
322
-
323
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
324
- context.candidateRuleMap.set(prefixedIdentifier, [])
325
- }
326
-
327
- context.candidateRuleMap
328
- .get(prefixedIdentifier)
329
- .push([{ sort: offsets.create('defaults'), layer: 'defaults' }, rule])
330
- }
331
- },
332
- addComponents(components, options) {
333
- let defaultOptions = {
334
- preserveSource: false,
335
- respectPrefix: true,
336
- respectImportant: false,
337
- }
338
-
339
- options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options)
340
-
341
- for (let [identifier, rule] of withIdentifiers(components)) {
342
- let prefixedIdentifier = prefixIdentifier(identifier, options)
343
-
344
- classList.add(prefixedIdentifier)
345
-
346
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
347
- context.candidateRuleMap.set(prefixedIdentifier, [])
348
- }
349
-
350
- context.candidateRuleMap
351
- .get(prefixedIdentifier)
352
- .push([{ sort: offsets.create('components'), layer: 'components', options }, rule])
353
- }
354
- },
355
- addUtilities(utilities, options) {
356
- let defaultOptions = {
357
- preserveSource: false,
358
- respectPrefix: true,
359
- respectImportant: true,
360
- }
361
-
362
- options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options)
363
-
364
- for (let [identifier, rule] of withIdentifiers(utilities)) {
365
- let prefixedIdentifier = prefixIdentifier(identifier, options)
366
-
367
- classList.add(prefixedIdentifier)
368
-
369
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
370
- context.candidateRuleMap.set(prefixedIdentifier, [])
371
- }
372
-
373
- context.candidateRuleMap
374
- .get(prefixedIdentifier)
375
- .push([{ sort: offsets.create('utilities'), layer: 'utilities', options }, rule])
376
- }
377
- },
378
- matchUtilities: function (utilities, options) {
379
- let defaultOptions = {
380
- respectPrefix: true,
381
- respectImportant: true,
382
- modifiers: false,
383
- }
384
-
385
- options = normalizeOptionTypes({ ...defaultOptions, ...options })
386
-
387
- let offset = offsets.create('utilities')
388
-
389
- for (let identifier in utilities) {
390
- let prefixedIdentifier = prefixIdentifier(identifier, options)
391
- let rule = utilities[identifier]
392
-
393
- classList.add([prefixedIdentifier, options])
394
-
395
- function wrapped(modifier, { isOnlyPlugin }) {
396
- let [value, coercedType, utilityModifier] = coerceValue(
397
- options.types,
398
- modifier,
399
- options,
400
- tailwindConfig
401
- )
402
-
403
- if (value === undefined) {
404
- return []
405
- }
406
-
407
- if (!options.types.some(({ type }) => type === coercedType)) {
408
- if (isOnlyPlugin) {
409
- log.warn([
410
- `Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
411
- `You can safely update it to \`${identifier}-${modifier.replace(
412
- coercedType + ':',
413
- ''
414
- )}\`.`,
415
- ])
416
- } else {
417
- return []
418
- }
419
- }
420
-
421
- if (!isSyntacticallyValidPropertyValue(value)) {
422
- return []
423
- }
424
-
425
- let extras = {
426
- get modifier() {
427
- if (!options.modifiers) {
428
- log.warn(`modifier-used-without-options-for-${identifier}`, [
429
- 'Your plugin must set `modifiers: true` in its options to support modifiers.',
430
- ])
431
- }
432
-
433
- return utilityModifier
434
- },
435
- }
436
-
437
- let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
438
-
439
- let ruleSets = []
440
- .concat(modifiersEnabled ? rule(value, extras) : rule(value))
441
- .filter(Boolean)
442
- .map((declaration) => ({
443
- [nameClass(identifier, modifier)]: declaration,
444
- }))
445
-
446
- return ruleSets
447
- }
448
-
449
- let withOffsets = [{ sort: offset, layer: 'utilities', options }, wrapped]
450
-
451
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
452
- context.candidateRuleMap.set(prefixedIdentifier, [])
453
- }
454
-
455
- context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
456
- }
457
- },
458
- matchComponents: function (components, options) {
459
- let defaultOptions = {
460
- respectPrefix: true,
461
- respectImportant: false,
462
- modifiers: false,
463
- }
464
-
465
- options = normalizeOptionTypes({ ...defaultOptions, ...options })
466
-
467
- let offset = offsets.create('components')
468
-
469
- for (let identifier in components) {
470
- let prefixedIdentifier = prefixIdentifier(identifier, options)
471
- let rule = components[identifier]
472
-
473
- classList.add([prefixedIdentifier, options])
474
-
475
- function wrapped(modifier, { isOnlyPlugin }) {
476
- let [value, coercedType, utilityModifier] = coerceValue(
477
- options.types,
478
- modifier,
479
- options,
480
- tailwindConfig
481
- )
482
-
483
- if (value === undefined) {
484
- return []
485
- }
486
-
487
- if (!options.types.some(({ type }) => type === coercedType)) {
488
- if (isOnlyPlugin) {
489
- log.warn([
490
- `Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
491
- `You can safely update it to \`${identifier}-${modifier.replace(
492
- coercedType + ':',
493
- ''
494
- )}\`.`,
495
- ])
496
- } else {
497
- return []
498
- }
499
- }
500
-
501
- if (!isSyntacticallyValidPropertyValue(value)) {
502
- return []
503
- }
504
-
505
- let extras = {
506
- get modifier() {
507
- if (!options.modifiers) {
508
- log.warn(`modifier-used-without-options-for-${identifier}`, [
509
- 'Your plugin must set `modifiers: true` in its options to support modifiers.',
510
- ])
511
- }
512
-
513
- return utilityModifier
514
- },
515
- }
516
-
517
- let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
518
-
519
- let ruleSets = []
520
- .concat(modifiersEnabled ? rule(value, extras) : rule(value))
521
- .filter(Boolean)
522
- .map((declaration) => ({
523
- [nameClass(identifier, modifier)]: declaration,
524
- }))
525
-
526
- return ruleSets
527
- }
528
-
529
- let withOffsets = [{ sort: offset, layer: 'components', options }, wrapped]
530
-
531
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
532
- context.candidateRuleMap.set(prefixedIdentifier, [])
533
- }
534
-
535
- context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
536
- }
537
- },
538
- addVariant(variantName, variantFunctions, options = {}) {
539
- variantFunctions = [].concat(variantFunctions).map((variantFunction) => {
540
- if (typeof variantFunction !== 'string') {
541
- // Safelist public API functions
542
- return (api = {}) => {
543
- let { args, modifySelectors, container, separator, wrap, format } = api
544
- let result = variantFunction(
545
- Object.assign(
546
- { modifySelectors, container, separator },
547
- options.type === VARIANT_TYPES.MatchVariant && { args, wrap, format }
548
- )
549
- )
550
-
551
- if (typeof result === 'string' && !isValidVariantFormatString(result)) {
552
- throw new Error(
553
- `Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
554
- )
555
- }
556
-
557
- if (Array.isArray(result)) {
558
- return result
559
- .filter((variant) => typeof variant === 'string')
560
- .map((variant) => parseVariant(variant))
561
- }
562
-
563
- // result may be undefined with legacy variants that use APIs like `modifySelectors`
564
- // result may also be a postcss node if someone was returning the result from `modifySelectors`
565
- return result && typeof result === 'string' && parseVariant(result)(api)
566
- }
567
- }
568
-
569
- if (!isValidVariantFormatString(variantFunction)) {
570
- throw new Error(
571
- `Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
572
- )
573
- }
574
-
575
- return parseVariant(variantFunction)
576
- })
577
-
578
- insertInto(variantList, variantName, options)
579
- variantMap.set(variantName, variantFunctions)
580
- context.variantOptions.set(variantName, options)
581
- },
582
- matchVariant(variant, variantFn, options) {
583
- // A unique identifier that "groups" these variants together.
584
- // This is for internal use only which is why it is not present in the types
585
- let id = options?.id ?? ++variantIdentifier
586
- let isSpecial = variant === '@'
587
-
588
- let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
589
-
590
- for (let [key, value] of Object.entries(options?.values ?? {})) {
591
- if (key === 'DEFAULT') continue
592
-
593
- api.addVariant(
594
- isSpecial ? `${variant}${key}` : `${variant}-${key}`,
595
- ({ args, container }) => {
596
- return variantFn(
597
- value,
598
- modifiersEnabled ? { modifier: args?.modifier, container } : { container }
599
- )
600
- },
601
-
602
- {
603
- ...options,
604
- value,
605
- id,
606
- type: VARIANT_TYPES.MatchVariant,
607
- variantInfo: VARIANT_INFO.Base,
608
- }
609
- )
610
- }
611
-
612
- let hasDefault = 'DEFAULT' in (options?.values ?? {})
613
-
614
- api.addVariant(
615
- variant,
616
- ({ args, container }) => {
617
- if (args?.value === sharedState.NONE && !hasDefault) {
618
- return null
619
- }
620
-
621
- return variantFn(
622
- args?.value === sharedState.NONE
623
- ? options.values.DEFAULT
624
- : // Falling back to args if it is a string, otherwise '' for older intellisense
625
- // (JetBrains) plugins.
626
- args?.value ?? (typeof args === 'string' ? args : ''),
627
- modifiersEnabled ? { modifier: args?.modifier, container } : { container }
628
- )
629
- },
630
- {
631
- ...options,
632
- id,
633
- type: VARIANT_TYPES.MatchVariant,
634
- variantInfo: VARIANT_INFO.Dynamic,
635
- }
636
- )
637
- },
638
- }
639
-
640
- return api
641
- }
642
-
643
- let fileModifiedMapCache = new WeakMap()
644
- export function getFileModifiedMap(context) {
645
- if (!fileModifiedMapCache.has(context)) {
646
- fileModifiedMapCache.set(context, new Map())
647
- }
648
- return fileModifiedMapCache.get(context)
649
- }
650
-
651
- function trackModified(files, fileModifiedMap) {
652
- let changed = false
653
- let mtimesToCommit = new Map()
654
-
655
- for (let file of files) {
656
- if (!file) continue
657
-
658
- let parsed = url.parse(file)
659
- let pathname = parsed.hash ? parsed.href.replace(parsed.hash, '') : parsed.href
660
- pathname = parsed.search ? pathname.replace(parsed.search, '') : pathname
661
- let newModified = fs.statSync(decodeURIComponent(pathname), { throwIfNoEntry: false })?.mtimeMs
662
- if (!newModified) {
663
- // It could happen that a file is passed in that doesn't exist. E.g.:
664
- // postcss-cli will provide you a fake path when reading from stdin. This
665
- // path then looks like /path-to-your-project/stdin In that case we just
666
- // want to ignore it and don't track changes at all.
667
- continue
668
- }
669
-
670
- if (!fileModifiedMap.has(file) || newModified > fileModifiedMap.get(file)) {
671
- changed = true
672
- }
673
-
674
- mtimesToCommit.set(file, newModified)
675
- }
676
-
677
- return [changed, mtimesToCommit]
678
- }
679
-
680
- function extractVariantAtRules(node) {
681
- node.walkAtRules((atRule) => {
682
- if (['responsive', 'variants'].includes(atRule.name)) {
683
- extractVariantAtRules(atRule)
684
- atRule.before(atRule.nodes)
685
- atRule.remove()
686
- }
687
- })
688
- }
689
-
690
- function collectLayerPlugins(root) {
691
- let layerPlugins = []
692
-
693
- root.each((node) => {
694
- if (node.type === 'atrule' && ['responsive', 'variants'].includes(node.name)) {
695
- node.name = 'layer'
696
- node.params = 'utilities'
697
- }
698
- })
699
-
700
- // Walk @layer rules and treat them like plugins
701
- root.walkAtRules('layer', (layerRule) => {
702
- extractVariantAtRules(layerRule)
703
-
704
- if (layerRule.params === 'base') {
705
- for (let node of layerRule.nodes) {
706
- layerPlugins.push(function ({ addBase }) {
707
- addBase(node, { respectPrefix: false })
708
- })
709
- }
710
- layerRule.remove()
711
- } else if (layerRule.params === 'components') {
712
- for (let node of layerRule.nodes) {
713
- layerPlugins.push(function ({ addComponents }) {
714
- addComponents(node, { respectPrefix: false, preserveSource: true })
715
- })
716
- }
717
- layerRule.remove()
718
- } else if (layerRule.params === 'utilities') {
719
- for (let node of layerRule.nodes) {
720
- layerPlugins.push(function ({ addUtilities }) {
721
- addUtilities(node, { respectPrefix: false, preserveSource: true })
722
- })
723
- }
724
- layerRule.remove()
725
- }
726
- })
727
-
728
- return layerPlugins
729
- }
730
-
731
- function resolvePlugins(context, root) {
732
- let corePluginList = Object.entries({ ...variantPlugins, ...corePlugins })
733
- .map(([name, plugin]) => {
734
- if (!context.tailwindConfig.corePlugins.includes(name)) {
735
- return null
736
- }
737
-
738
- return plugin
739
- })
740
- .filter(Boolean)
741
-
742
- let userPlugins = context.tailwindConfig.plugins.map((plugin) => {
743
- if (plugin.__isOptionsFunction) {
744
- plugin = plugin()
745
- }
746
-
747
- return typeof plugin === 'function' ? plugin : plugin.handler
748
- })
749
-
750
- let layerPlugins = collectLayerPlugins(root)
751
-
752
- // TODO: This is a workaround for backwards compatibility, since custom variants
753
- // were historically sorted before screen/stackable variants.
754
- let beforeVariants = [
755
- variantPlugins['pseudoElementVariants'],
756
- variantPlugins['pseudoClassVariants'],
757
- variantPlugins['ariaVariants'],
758
- variantPlugins['dataVariants'],
759
- ]
760
- let afterVariants = [
761
- variantPlugins['supportsVariants'],
762
- variantPlugins['directionVariants'],
763
- variantPlugins['reducedMotionVariants'],
764
- variantPlugins['prefersContrastVariants'],
765
- variantPlugins['darkVariants'],
766
- variantPlugins['printVariant'],
767
- variantPlugins['screenVariants'],
768
- variantPlugins['orientationVariants'],
769
- ]
770
-
771
- return [...corePluginList, ...beforeVariants, ...userPlugins, ...afterVariants, ...layerPlugins]
772
- }
773
-
774
- function registerPlugins(plugins, context) {
775
- let variantList = []
776
- let variantMap = new Map()
777
- context.variantMap = variantMap
778
-
779
- let offsets = new Offsets()
780
- context.offsets = offsets
781
-
782
- let classList = new Set()
783
-
784
- let pluginApi = buildPluginApi(context.tailwindConfig, context, {
785
- variantList,
786
- variantMap,
787
- offsets,
788
- classList,
789
- })
790
-
791
- for (let plugin of plugins) {
792
- if (Array.isArray(plugin)) {
793
- for (let pluginItem of plugin) {
794
- pluginItem(pluginApi)
795
- }
796
- } else {
797
- plugin?.(pluginApi)
798
- }
799
- }
800
-
801
- // Make sure to record bit masks for every variant
802
- offsets.recordVariants(variantList, (variant) => variantMap.get(variant).length)
803
-
804
- // Build variantMap
805
- for (let [variantName, variantFunctions] of variantMap.entries()) {
806
- context.variantMap.set(
807
- variantName,
808
- variantFunctions.map((variantFunction, idx) => [
809
- offsets.forVariant(variantName, idx),
810
- variantFunction,
811
- ])
812
- )
813
- }
814
-
815
- let safelist = (context.tailwindConfig.safelist ?? []).filter(Boolean)
816
- if (safelist.length > 0) {
817
- let checks = []
818
-
819
- for (let value of safelist) {
820
- if (typeof value === 'string') {
821
- context.changedContent.push({ content: value, extension: 'html' })
822
- continue
823
- }
824
-
825
- if (value instanceof RegExp) {
826
- log.warn('root-regex', [
827
- 'Regular expressions in `safelist` work differently in Tailwind CSS v3.0.',
828
- 'Update your `safelist` configuration to eliminate this warning.',
829
- 'https://tailwindcss.com/docs/content-configuration#safelisting-classes',
830
- ])
831
- continue
832
- }
833
-
834
- checks.push(value)
835
- }
836
-
837
- if (checks.length > 0) {
838
- let patternMatchingCount = new Map()
839
- let prefixLength = context.tailwindConfig.prefix.length
840
- let checkImportantUtils = checks.some((check) => check.pattern.source.includes('!'))
841
-
842
- for (let util of classList) {
843
- let utils = Array.isArray(util)
844
- ? (() => {
845
- let [utilName, options] = util
846
- let values = Object.keys(options?.values ?? {})
847
- let classes = values.map((value) => formatClass(utilName, value))
848
-
849
- if (options?.supportsNegativeValues) {
850
- // This is the normal negated version
851
- // e.g. `-inset-1` or `-tw-inset-1`
852
- classes = [...classes, ...classes.map((cls) => '-' + cls)]
853
-
854
- // This is the negated version *after* the prefix
855
- // e.g. `tw--inset-1`
856
- // The prefix is already attached to util name
857
- // So we add the negative after the prefix
858
- classes = [
859
- ...classes,
860
- ...classes.map(
861
- (cls) => cls.slice(0, prefixLength) + '-' + cls.slice(prefixLength)
862
- ),
863
- ]
864
- }
865
-
866
- if (options.types.some(({ type }) => type === 'color')) {
867
- classes = [
868
- ...classes,
869
- ...classes.flatMap((cls) =>
870
- Object.keys(context.tailwindConfig.theme.opacity).map(
871
- (opacity) => `${cls}/${opacity}`
872
- )
873
- ),
874
- ]
875
- }
876
-
877
- if (checkImportantUtils && options?.respectImportant) {
878
- classes = [...classes, ...classes.map((cls) => '!' + cls)]
879
- }
880
-
881
- return classes
882
- })()
883
- : [util]
884
-
885
- for (let util of utils) {
886
- for (let { pattern, variants = [] } of checks) {
887
- // RegExp with the /g flag are stateful, so let's reset the last
888
- // index pointer to reset the state.
889
- pattern.lastIndex = 0
890
-
891
- if (!patternMatchingCount.has(pattern)) {
892
- patternMatchingCount.set(pattern, 0)
893
- }
894
-
895
- if (!pattern.test(util)) continue
896
-
897
- patternMatchingCount.set(pattern, patternMatchingCount.get(pattern) + 1)
898
-
899
- context.changedContent.push({ content: util, extension: 'html' })
900
- for (let variant of variants) {
901
- context.changedContent.push({
902
- content: variant + context.tailwindConfig.separator + util,
903
- extension: 'html',
904
- })
905
- }
906
- }
907
- }
908
- }
909
-
910
- for (let [regex, count] of patternMatchingCount.entries()) {
911
- if (count !== 0) continue
912
-
913
- log.warn([
914
- `The safelist pattern \`${regex}\` doesn't match any Tailwind CSS classes.`,
915
- 'Fix this pattern or remove it from your `safelist` configuration.',
916
- 'https://tailwindcss.com/docs/content-configuration#safelisting-classes',
917
- ])
918
- }
919
- }
920
- }
921
-
922
- let darkClassName = [].concat(context.tailwindConfig.darkMode ?? 'media')[1] ?? 'dark'
923
-
924
- // A list of utilities that are used by certain Tailwind CSS utilities but
925
- // that don't exist on their own. This will result in them "not existing" and
926
- // sorting could be weird since you still require them in order to make the
927
- // host utilities work properly. (Thanks Biology)
928
- let parasiteUtilities = [
929
- prefix(context, darkClassName),
930
- prefix(context, 'group'),
931
- prefix(context, 'peer'),
932
- ]
933
- context.getClassOrder = function getClassOrder(classes) {
934
- // Sort classes so they're ordered in a deterministic manner
935
- let sorted = [...classes].sort((a, z) => {
936
- if (a === z) return 0
937
- if (a < z) return -1
938
- return 1
939
- })
940
-
941
- // Non-util classes won't be generated, so we default them to null
942
- let sortedClassNames = new Map(sorted.map((className) => [className, null]))
943
-
944
- // Sort all classes in order
945
- // Non-tailwind classes won't be generated and will be left as `null`
946
- let rules = generateRules(new Set(sorted), context)
947
- rules = context.offsets.sort(rules)
948
-
949
- let idx = BigInt(parasiteUtilities.length)
950
-
951
- for (const [, rule] of rules) {
952
- sortedClassNames.set(rule.raws.tailwind.candidate, idx++)
953
- }
954
-
955
- return classes.map((className) => {
956
- let order = sortedClassNames.get(className) ?? null
957
- let parasiteIndex = parasiteUtilities.indexOf(className)
958
-
959
- if (order === null && parasiteIndex !== -1) {
960
- // This will make sure that it is at the very beginning of the
961
- // `components` layer which technically means 'before any
962
- // components'.
963
- order = BigInt(parasiteIndex)
964
- }
965
-
966
- return [className, order]
967
- })
968
- }
969
-
970
- // Generate a list of strings for autocompletion purposes, e.g.
971
- // ['uppercase', 'lowercase', ...]
972
- context.getClassList = function getClassList(options = {}) {
973
- let output = []
974
-
975
- for (let util of classList) {
976
- if (Array.isArray(util)) {
977
- let [utilName, utilOptions] = util
978
- let negativeClasses = []
979
-
980
- let modifiers = Object.keys(utilOptions?.modifiers ?? {})
981
-
982
- if (utilOptions?.types?.some(({ type }) => type === 'color')) {
983
- modifiers.push(...Object.keys(context.tailwindConfig.theme.opacity ?? {}))
984
- }
985
-
986
- let metadata = { modifiers }
987
- let includeMetadata = options.includeMetadata && modifiers.length > 0
988
-
989
- for (let [key, value] of Object.entries(utilOptions?.values ?? {})) {
990
- // Ignore undefined and null values
991
- if (value == null) {
992
- continue
993
- }
994
-
995
- let cls = formatClass(utilName, key)
996
- output.push(includeMetadata ? [cls, metadata] : cls)
997
-
998
- if (utilOptions?.supportsNegativeValues && negateValue(value)) {
999
- let cls = formatClass(utilName, `-${key}`)
1000
- negativeClasses.push(includeMetadata ? [cls, metadata] : cls)
1001
- }
1002
- }
1003
-
1004
- output.push(...negativeClasses)
1005
- } else {
1006
- output.push(util)
1007
- }
1008
- }
1009
-
1010
- return output
1011
- }
1012
-
1013
- // Generate a list of available variants with meta information of the type of variant.
1014
- context.getVariants = function getVariants() {
1015
- let result = []
1016
- for (let [name, options] of context.variantOptions.entries()) {
1017
- if (options.variantInfo === VARIANT_INFO.Base) continue
1018
-
1019
- result.push({
1020
- name,
1021
- isArbitrary: options.type === Symbol.for('MATCH_VARIANT'),
1022
- values: Object.keys(options.values ?? {}),
1023
- hasDash: name !== '@',
1024
- selectors({ modifier, value } = {}) {
1025
- let candidate = '__TAILWIND_PLACEHOLDER__'
1026
-
1027
- let rule = postcss.rule({ selector: `.${candidate}` })
1028
- let container = postcss.root({ nodes: [rule.clone()] })
1029
-
1030
- let before = container.toString()
1031
-
1032
- let fns = (context.variantMap.get(name) ?? []).flatMap(([_, fn]) => fn)
1033
- let formatStrings = []
1034
- for (let fn of fns) {
1035
- let localFormatStrings = []
1036
-
1037
- let api = {
1038
- args: { modifier, value: options.values?.[value] ?? value },
1039
- separator: context.tailwindConfig.separator,
1040
- modifySelectors(modifierFunction) {
1041
- // Run the modifierFunction over each rule
1042
- container.each((rule) => {
1043
- if (rule.type !== 'rule') {
1044
- return
1045
- }
1046
-
1047
- rule.selectors = rule.selectors.map((selector) => {
1048
- return modifierFunction({
1049
- get className() {
1050
- return getClassNameFromSelector(selector)
1051
- },
1052
- selector,
1053
- })
1054
- })
1055
- })
1056
-
1057
- return container
1058
- },
1059
- format(str) {
1060
- localFormatStrings.push(str)
1061
- },
1062
- wrap(wrapper) {
1063
- localFormatStrings.push(`@${wrapper.name} ${wrapper.params} { & }`)
1064
- },
1065
- container,
1066
- }
1067
-
1068
- let ruleWithVariant = fn(api)
1069
- if (localFormatStrings.length > 0) {
1070
- formatStrings.push(localFormatStrings)
1071
- }
1072
-
1073
- if (Array.isArray(ruleWithVariant)) {
1074
- for (let variantFunction of ruleWithVariant) {
1075
- localFormatStrings = []
1076
- variantFunction(api)
1077
- formatStrings.push(localFormatStrings)
1078
- }
1079
- }
1080
- }
1081
-
1082
- // Reverse engineer the result of the `container`
1083
- let manualFormatStrings = []
1084
- let after = container.toString()
1085
-
1086
- if (before !== after) {
1087
- // Figure out all selectors
1088
- container.walkRules((rule) => {
1089
- let modified = rule.selector
1090
-
1091
- // Rebuild the base selector, this is what plugin authors would do
1092
- // as well. E.g.: `${variant}${separator}${className}`.
1093
- // However, plugin authors probably also prepend or append certain
1094
- // classes, pseudos, ids, ...
1095
- let rebuiltBase = selectorParser((selectors) => {
1096
- selectors.walkClasses((classNode) => {
1097
- classNode.value = `${name}${context.tailwindConfig.separator}${classNode.value}`
1098
- })
1099
- }).processSync(modified)
1100
-
1101
- // Now that we know the original selector, the new selector, and
1102
- // the rebuild part in between, we can replace the part that plugin
1103
- // authors need to rebuild with `&`, and eventually store it in the
1104
- // collectedFormats. Similar to what `format('...')` would do.
1105
- //
1106
- // E.g.:
1107
- // variant: foo
1108
- // selector: .markdown > p
1109
- // modified (by plugin): .foo .foo\\:markdown > p
1110
- // rebuiltBase (internal): .foo\\:markdown > p
1111
- // format: .foo &
1112
- manualFormatStrings.push(modified.replace(rebuiltBase, '&').replace(candidate, '&'))
1113
- })
1114
-
1115
- // Figure out all atrules
1116
- container.walkAtRules((atrule) => {
1117
- manualFormatStrings.push(`@${atrule.name} (${atrule.params}) { & }`)
1118
- })
1119
- }
1120
-
1121
- let isArbitraryVariant = !(value in (options.values ?? {}))
1122
-
1123
- formatStrings = formatStrings.map((format) =>
1124
- format.map((str) => ({
1125
- format: str,
1126
- isArbitraryVariant,
1127
- }))
1128
- )
1129
-
1130
- manualFormatStrings = manualFormatStrings.map((format) => ({
1131
- format,
1132
- isArbitraryVariant,
1133
- }))
1134
-
1135
- let opts = {
1136
- candidate,
1137
- context,
1138
- }
1139
-
1140
- let result = formatStrings.map((formats) =>
1141
- finalizeSelector(`.${candidate}`, formatVariantSelector(formats, opts), opts)
1142
- .replace(`.${candidate}`, '&')
1143
- .replace('{ & }', '')
1144
- .trim()
1145
- )
1146
-
1147
- if (manualFormatStrings.length > 0) {
1148
- result.push(
1149
- formatVariantSelector(manualFormatStrings, opts)
1150
- .toString()
1151
- .replace(`.${candidate}`, '&')
1152
- )
1153
- }
1154
-
1155
- return result
1156
- },
1157
- })
1158
- }
1159
-
1160
- return result
1161
- }
1162
- }
1163
-
1164
- /**
1165
- * Mark as class as retroactively invalid
1166
- *
1167
- *
1168
- * @param {string} candidate
1169
- */
1170
- function markInvalidUtilityCandidate(context, candidate) {
1171
- if (!context.classCache.has(candidate)) {
1172
- return
1173
- }
1174
-
1175
- // Mark this as not being a real utility
1176
- context.notClassCache.add(candidate)
1177
-
1178
- // Remove it from any candidate-specific caches
1179
- context.classCache.delete(candidate)
1180
- context.applyClassCache.delete(candidate)
1181
- context.candidateRuleMap.delete(candidate)
1182
- context.candidateRuleCache.delete(candidate)
1183
-
1184
- // Ensure the stylesheet gets rebuilt
1185
- context.stylesheetCache = null
1186
- }
1187
-
1188
- /**
1189
- * Mark as class as retroactively invalid
1190
- *
1191
- * @param {import('postcss').Node} node
1192
- */
1193
- function markInvalidUtilityNode(context, node) {
1194
- let candidate = node.raws.tailwind.candidate
1195
-
1196
- if (!candidate) {
1197
- return
1198
- }
1199
-
1200
- for (const entry of context.ruleCache) {
1201
- if (entry[1].raws.tailwind.candidate === candidate) {
1202
- context.ruleCache.delete(entry)
1203
- // context.postCssNodeCache.delete(node)
1204
- }
1205
- }
1206
-
1207
- markInvalidUtilityCandidate(context, candidate)
1208
- }
1209
-
1210
- export function createContext(tailwindConfig, changedContent = [], root = postcss.root()) {
1211
- let context = {
1212
- disposables: [],
1213
- ruleCache: new Set(),
1214
- candidateRuleCache: new Map(),
1215
- classCache: new Map(),
1216
- applyClassCache: new Map(),
1217
- // Seed the not class cache with the blocklist (which is only strings)
1218
- notClassCache: new Set(tailwindConfig.blocklist ?? []),
1219
- postCssNodeCache: new Map(),
1220
- candidateRuleMap: new Map(),
1221
- tailwindConfig,
1222
- changedContent: changedContent,
1223
- variantMap: new Map(),
1224
- stylesheetCache: null,
1225
- variantOptions: new Map(),
1226
-
1227
- markInvalidUtilityCandidate: (candidate) => markInvalidUtilityCandidate(context, candidate),
1228
- markInvalidUtilityNode: (node) => markInvalidUtilityNode(context, node),
1229
- }
1230
-
1231
- let resolvedPlugins = resolvePlugins(context, root)
1232
- registerPlugins(resolvedPlugins, context)
1233
-
1234
- return context
1235
- }
1236
-
1237
- let contextMap = sharedState.contextMap
1238
- let configContextMap = sharedState.configContextMap
1239
- let contextSourcesMap = sharedState.contextSourcesMap
1240
-
1241
- export function getContext(
1242
- root,
1243
- result,
1244
- tailwindConfig,
1245
- userConfigPath,
1246
- tailwindConfigHash,
1247
- contextDependencies
1248
- ) {
1249
- let sourcePath = result.opts.from
1250
- let isConfigFile = userConfigPath !== null
1251
-
1252
- env.DEBUG && console.log('Source path:', sourcePath)
1253
-
1254
- let existingContext
1255
-
1256
- if (isConfigFile && contextMap.has(sourcePath)) {
1257
- existingContext = contextMap.get(sourcePath)
1258
- } else if (configContextMap.has(tailwindConfigHash)) {
1259
- let context = configContextMap.get(tailwindConfigHash)
1260
- contextSourcesMap.get(context).add(sourcePath)
1261
- contextMap.set(sourcePath, context)
1262
-
1263
- existingContext = context
1264
- }
1265
-
1266
- let cssDidChange = hasContentChanged(sourcePath, root)
1267
-
1268
- // If there's already a context in the cache and we don't need to
1269
- // reset the context, return the cached context.
1270
- if (existingContext) {
1271
- let [contextDependenciesChanged, mtimesToCommit] = trackModified(
1272
- [...contextDependencies],
1273
- getFileModifiedMap(existingContext)
1274
- )
1275
- if (!contextDependenciesChanged && !cssDidChange) {
1276
- return [existingContext, false, mtimesToCommit]
1277
- }
1278
- }
1279
-
1280
- // If this source is in the context map, get the old context.
1281
- // Remove this source from the context sources for the old context,
1282
- // and clean up that context if no one else is using it. This can be
1283
- // called by many processes in rapid succession, so we check for presence
1284
- // first because the first process to run this code will wipe it out first.
1285
- if (contextMap.has(sourcePath)) {
1286
- let oldContext = contextMap.get(sourcePath)
1287
- if (contextSourcesMap.has(oldContext)) {
1288
- contextSourcesMap.get(oldContext).delete(sourcePath)
1289
- if (contextSourcesMap.get(oldContext).size === 0) {
1290
- contextSourcesMap.delete(oldContext)
1291
- for (let [tailwindConfigHash, context] of configContextMap) {
1292
- if (context === oldContext) {
1293
- configContextMap.delete(tailwindConfigHash)
1294
- }
1295
- }
1296
- for (let disposable of oldContext.disposables.splice(0)) {
1297
- disposable(oldContext)
1298
- }
1299
- }
1300
- }
1301
- }
1302
-
1303
- env.DEBUG && console.log('Setting up new context...')
1304
-
1305
- let context = createContext(tailwindConfig, [], root)
1306
-
1307
- Object.assign(context, {
1308
- userConfigPath,
1309
- })
1310
-
1311
- let [, mtimesToCommit] = trackModified([...contextDependencies], getFileModifiedMap(context))
1312
-
1313
- // ---
1314
-
1315
- // Update all context tracking state
1316
-
1317
- configContextMap.set(tailwindConfigHash, context)
1318
- contextMap.set(sourcePath, context)
1319
-
1320
- if (!contextSourcesMap.has(context)) {
1321
- contextSourcesMap.set(context, new Set())
1322
- }
1323
-
1324
- contextSourcesMap.get(context).add(sourcePath)
1325
-
1326
- return [context, true, mtimesToCommit]
1327
- }