tailwindcss 0.0.0-insiders.ea139f2 → 0.0.0-insiders.ea4e1cd

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 (236) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +15 -7
  3. package/colors.d.ts +3 -0
  4. package/colors.js +2 -1
  5. package/defaultConfig.d.ts +3 -0
  6. package/defaultConfig.js +2 -1
  7. package/defaultTheme.d.ts +4 -0
  8. package/defaultTheme.js +2 -1
  9. package/lib/cli/build/deps.js +62 -0
  10. package/lib/cli/build/index.js +54 -0
  11. package/lib/cli/build/plugin.js +378 -0
  12. package/lib/cli/build/utils.js +88 -0
  13. package/lib/cli/build/watching.js +182 -0
  14. package/lib/cli/help/index.js +73 -0
  15. package/lib/cli/index.js +230 -0
  16. package/lib/cli/init/index.js +63 -0
  17. package/lib/cli-peer-dependencies.js +28 -7
  18. package/lib/cli.js +4 -703
  19. package/lib/corePluginList.js +12 -3
  20. package/lib/corePlugins.js +2373 -1863
  21. package/lib/css/preflight.css +10 -8
  22. package/lib/featureFlags.js +49 -26
  23. package/lib/index.js +1 -31
  24. package/lib/lib/cacheInvalidation.js +92 -0
  25. package/lib/lib/collapseAdjacentRules.js +30 -10
  26. package/lib/lib/collapseDuplicateDeclarations.js +60 -4
  27. package/lib/lib/content.js +181 -0
  28. package/lib/lib/defaultExtractor.js +243 -0
  29. package/lib/lib/detectNesting.js +21 -10
  30. package/lib/lib/evaluateTailwindFunctions.js +115 -50
  31. package/lib/lib/expandApplyAtRules.js +467 -161
  32. package/lib/lib/expandTailwindAtRules.js +160 -133
  33. package/lib/lib/findAtConfigPath.js +46 -0
  34. package/lib/lib/generateRules.js +553 -200
  35. package/lib/lib/getModuleDependencies.js +88 -37
  36. package/lib/lib/load-config.js +42 -0
  37. package/lib/lib/normalizeTailwindDirectives.js +46 -33
  38. package/lib/lib/offsets.js +306 -0
  39. package/lib/lib/partitionApplyAtRules.js +58 -0
  40. package/lib/lib/regex.js +74 -0
  41. package/lib/lib/remap-bitfield.js +89 -0
  42. package/lib/lib/resolveDefaultsAtRules.js +98 -58
  43. package/lib/lib/setupContextUtils.js +773 -321
  44. package/lib/lib/setupTrackingContext.js +70 -75
  45. package/lib/lib/sharedState.js +78 -10
  46. package/lib/lib/substituteScreenAtRules.js +14 -10
  47. package/lib/oxide/cli/build/deps.js +89 -0
  48. package/lib/oxide/cli/build/index.js +53 -0
  49. package/lib/oxide/cli/build/plugin.js +375 -0
  50. package/lib/oxide/cli/build/utils.js +87 -0
  51. package/lib/oxide/cli/build/watching.js +179 -0
  52. package/lib/oxide/cli/help/index.js +72 -0
  53. package/lib/oxide/cli/index.js +214 -0
  54. package/lib/oxide/cli/init/index.js +52 -0
  55. package/lib/oxide/cli.js +5 -0
  56. package/lib/oxide/postcss-plugin.js +2 -0
  57. package/lib/plugin.js +98 -0
  58. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  59. package/lib/postcss-plugins/nesting/index.js +21 -0
  60. package/lib/postcss-plugins/nesting/plugin.js +89 -0
  61. package/lib/processTailwindFeatures.js +39 -26
  62. package/lib/public/colors.js +272 -246
  63. package/lib/public/create-plugin.js +9 -5
  64. package/lib/public/default-config.js +10 -6
  65. package/lib/public/default-theme.js +10 -6
  66. package/lib/public/load-config.js +12 -0
  67. package/lib/public/resolve-config.js +11 -6
  68. package/lib/util/applyImportantSelector.js +36 -0
  69. package/lib/util/bigSign.js +6 -1
  70. package/lib/util/buildMediaQuery.js +13 -6
  71. package/lib/util/cloneDeep.js +9 -6
  72. package/lib/util/cloneNodes.js +23 -3
  73. package/lib/util/color.js +70 -38
  74. package/lib/util/colorNames.js +752 -0
  75. package/lib/util/configurePlugins.js +7 -2
  76. package/lib/util/createPlugin.js +8 -6
  77. package/lib/util/createUtilityPlugin.js +16 -16
  78. package/lib/util/dataTypes.js +173 -108
  79. package/lib/util/defaults.js +14 -3
  80. package/lib/util/escapeClassName.js +13 -8
  81. package/lib/util/escapeCommas.js +7 -2
  82. package/lib/util/flattenColorPalette.js +11 -12
  83. package/lib/util/formatVariantSelector.js +228 -151
  84. package/lib/util/getAllConfigs.js +33 -12
  85. package/lib/util/hashConfig.js +9 -4
  86. package/lib/util/isKeyframeRule.js +7 -2
  87. package/lib/util/isPlainObject.js +7 -2
  88. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
  89. package/lib/util/log.js +27 -13
  90. package/lib/util/nameClass.js +27 -10
  91. package/lib/util/negateValue.js +25 -8
  92. package/lib/util/normalizeConfig.js +139 -65
  93. package/lib/util/normalizeScreens.js +131 -11
  94. package/lib/util/parseAnimationValue.js +44 -40
  95. package/lib/util/parseBoxShadowValue.js +34 -23
  96. package/lib/util/parseDependency.js +39 -55
  97. package/lib/util/parseGlob.js +36 -0
  98. package/lib/util/parseObjectStyles.js +15 -10
  99. package/lib/util/pluginUtils.js +159 -69
  100. package/lib/util/prefixSelector.js +30 -12
  101. package/lib/util/pseudoElements.js +229 -0
  102. package/lib/util/removeAlphaVariables.js +31 -0
  103. package/lib/util/resolveConfig.js +97 -75
  104. package/lib/util/resolveConfigPath.js +30 -12
  105. package/lib/util/responsive.js +11 -6
  106. package/lib/util/splitAtTopLevelOnly.js +51 -0
  107. package/lib/util/tap.js +6 -1
  108. package/lib/util/toColorValue.js +7 -3
  109. package/lib/util/toPath.js +26 -3
  110. package/lib/util/transformThemeValue.js +40 -30
  111. package/lib/util/validateConfig.js +37 -0
  112. package/lib/util/validateFormalSyntax.js +26 -0
  113. package/lib/util/withAlphaVariable.js +27 -15
  114. package/loadConfig.d.ts +4 -0
  115. package/loadConfig.js +2 -0
  116. package/nesting/index.js +2 -12
  117. package/package.json +66 -57
  118. package/peers/index.js +75964 -55560
  119. package/plugin.d.ts +11 -0
  120. package/plugin.js +2 -1
  121. package/resolveConfig.d.ts +12 -0
  122. package/resolveConfig.js +2 -1
  123. package/scripts/generate-types.js +105 -0
  124. package/scripts/release-channel.js +18 -0
  125. package/scripts/release-notes.js +21 -0
  126. package/scripts/swap-engines.js +40 -0
  127. package/scripts/type-utils.js +27 -0
  128. package/src/cli/build/deps.js +56 -0
  129. package/src/cli/build/index.js +49 -0
  130. package/src/cli/build/plugin.js +444 -0
  131. package/src/cli/build/utils.js +76 -0
  132. package/src/cli/build/watching.js +229 -0
  133. package/src/cli/help/index.js +70 -0
  134. package/src/cli/index.js +216 -0
  135. package/src/cli/init/index.js +79 -0
  136. package/src/cli-peer-dependencies.js +7 -1
  137. package/src/cli.js +4 -765
  138. package/src/corePluginList.js +1 -1
  139. package/src/corePlugins.js +786 -306
  140. package/src/css/preflight.css +10 -8
  141. package/src/featureFlags.js +21 -5
  142. package/src/index.js +1 -34
  143. package/src/lib/cacheInvalidation.js +52 -0
  144. package/src/lib/collapseAdjacentRules.js +21 -2
  145. package/src/lib/collapseDuplicateDeclarations.js +66 -1
  146. package/src/lib/content.js +208 -0
  147. package/src/lib/defaultExtractor.js +217 -0
  148. package/src/lib/detectNesting.js +9 -1
  149. package/src/lib/evaluateTailwindFunctions.js +79 -8
  150. package/src/lib/expandApplyAtRules.js +515 -153
  151. package/src/lib/expandTailwindAtRules.js +115 -86
  152. package/src/lib/findAtConfigPath.js +48 -0
  153. package/src/lib/generateRules.js +545 -147
  154. package/src/lib/getModuleDependencies.js +70 -30
  155. package/src/lib/load-config.ts +31 -0
  156. package/src/lib/normalizeTailwindDirectives.js +7 -1
  157. package/src/lib/offsets.js +373 -0
  158. package/src/lib/partitionApplyAtRules.js +52 -0
  159. package/src/lib/regex.js +74 -0
  160. package/src/lib/remap-bitfield.js +82 -0
  161. package/src/lib/resolveDefaultsAtRules.js +59 -17
  162. package/src/lib/setupContextUtils.js +701 -175
  163. package/src/lib/setupTrackingContext.js +51 -62
  164. package/src/lib/sharedState.js +58 -7
  165. package/src/oxide/cli/build/deps.ts +91 -0
  166. package/src/oxide/cli/build/index.ts +47 -0
  167. package/src/oxide/cli/build/plugin.ts +442 -0
  168. package/src/oxide/cli/build/utils.ts +74 -0
  169. package/src/oxide/cli/build/watching.ts +225 -0
  170. package/src/oxide/cli/help/index.ts +69 -0
  171. package/src/oxide/cli/index.ts +204 -0
  172. package/src/oxide/cli/init/index.ts +59 -0
  173. package/src/oxide/cli.ts +1 -0
  174. package/src/oxide/postcss-plugin.ts +1 -0
  175. package/src/plugin.js +107 -0
  176. package/src/postcss-plugins/nesting/README.md +42 -0
  177. package/src/postcss-plugins/nesting/index.js +13 -0
  178. package/src/postcss-plugins/nesting/plugin.js +80 -0
  179. package/src/processTailwindFeatures.js +12 -2
  180. package/src/public/colors.js +22 -0
  181. package/src/public/default-config.js +1 -1
  182. package/src/public/default-theme.js +2 -2
  183. package/src/public/load-config.js +2 -0
  184. package/src/util/applyImportantSelector.js +27 -0
  185. package/src/util/buildMediaQuery.js +5 -3
  186. package/src/util/cloneNodes.js +19 -2
  187. package/src/util/color.js +44 -12
  188. package/src/util/colorNames.js +150 -0
  189. package/src/util/dataTypes.js +51 -16
  190. package/src/util/defaults.js +6 -0
  191. package/src/util/formatVariantSelector.js +264 -144
  192. package/src/util/getAllConfigs.js +21 -2
  193. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  194. package/src/util/log.js +11 -7
  195. package/src/util/nameClass.js +4 -0
  196. package/src/util/negateValue.js +11 -3
  197. package/src/util/normalizeConfig.js +57 -5
  198. package/src/util/normalizeScreens.js +105 -7
  199. package/src/util/parseBoxShadowValue.js +4 -3
  200. package/src/util/parseDependency.js +37 -42
  201. package/src/util/parseGlob.js +24 -0
  202. package/src/util/pluginUtils.js +123 -24
  203. package/src/util/prefixSelector.js +30 -10
  204. package/src/util/pseudoElements.js +170 -0
  205. package/src/util/removeAlphaVariables.js +24 -0
  206. package/src/util/resolveConfig.js +74 -26
  207. package/src/util/resolveConfigPath.js +12 -1
  208. package/src/util/splitAtTopLevelOnly.js +52 -0
  209. package/src/util/toPath.js +23 -1
  210. package/src/util/transformThemeValue.js +13 -3
  211. package/src/util/validateConfig.js +26 -0
  212. package/src/util/validateFormalSyntax.js +34 -0
  213. package/src/util/withAlphaVariable.js +1 -1
  214. package/stubs/.gitignore +1 -0
  215. package/stubs/.prettierrc.json +6 -0
  216. package/stubs/{defaultConfig.stub.js → config.full.js} +206 -166
  217. package/stubs/postcss.config.js +6 -0
  218. package/stubs/tailwind.config.cjs +2 -0
  219. package/stubs/tailwind.config.js +2 -0
  220. package/stubs/tailwind.config.ts +3 -0
  221. package/types/config.d.ts +368 -0
  222. package/types/generated/.gitkeep +0 -0
  223. package/types/generated/colors.d.ts +298 -0
  224. package/types/generated/corePluginList.d.ts +1 -0
  225. package/types/generated/default-theme.d.ts +371 -0
  226. package/types/index.d.ts +7 -0
  227. package/CHANGELOG.md +0 -1843
  228. package/lib/constants.js +0 -37
  229. package/lib/lib/setupWatchingContext.js +0 -288
  230. package/nesting/plugin.js +0 -41
  231. package/scripts/install-integrations.js +0 -27
  232. package/scripts/rebuildFixtures.js +0 -68
  233. package/src/constants.js +0 -17
  234. package/src/lib/setupWatchingContext.js +0 -311
  235. /package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -0
  236. /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
@@ -1,12 +1,32 @@
1
1
  import parser from 'postcss-selector-parser'
2
- import { tap } from './tap'
3
-
4
- export default function (prefix, selector) {
5
- return parser((selectors) => {
6
- selectors.walkClasses((classSelector) => {
7
- tap(classSelector.value, (baseClass) => {
8
- classSelector.value = `${prefix}${baseClass}`
9
- })
10
- })
11
- }).processSync(selector)
2
+
3
+ /**
4
+ * @template {string | import('postcss-selector-parser').Root} T
5
+ *
6
+ * Prefix all classes in the selector with the given prefix
7
+ *
8
+ * It can take either a string or a selector AST and will return the same type
9
+ *
10
+ * @param {string} prefix
11
+ * @param {T} selector
12
+ * @param {boolean} prependNegative
13
+ * @returns {T}
14
+ */
15
+ export default function (prefix, selector, prependNegative = false) {
16
+ if (prefix === '') {
17
+ return selector
18
+ }
19
+
20
+ let ast = typeof selector === 'string' ? parser().astSync(selector) : selector
21
+
22
+ ast.walkClasses((classSelector) => {
23
+ let baseClass = classSelector.value
24
+ let shouldPlaceNegativeBeforePrefix = prependNegative && baseClass.startsWith('-')
25
+
26
+ classSelector.value = shouldPlaceNegativeBeforePrefix
27
+ ? `-${prefix}${baseClass.slice(1)}`
28
+ : `${prefix}${baseClass}`
29
+ })
30
+
31
+ return typeof selector === 'string' ? ast.toString() : ast
12
32
  }
@@ -0,0 +1,170 @@
1
+ /** @typedef {import('postcss-selector-parser').Root} Root */
2
+ /** @typedef {import('postcss-selector-parser').Selector} Selector */
3
+ /** @typedef {import('postcss-selector-parser').Pseudo} Pseudo */
4
+ /** @typedef {import('postcss-selector-parser').Node} Node */
5
+
6
+ // There are some pseudo-elements that may or may not be:
7
+
8
+ // **Actionable**
9
+ // Zero or more user-action pseudo-classes may be attached to the pseudo-element itself
10
+ // structural-pseudo-classes are NOT allowed but we don't make
11
+ // The spec is not clear on whether this is allowed or not — but in practice it is.
12
+
13
+ // **Terminal**
14
+ // It MUST be placed at the end of a selector
15
+ //
16
+ // This is the required in the spec. However, some pseudo elements are not "terminal" because
17
+ // they represent a "boundary piercing" that is compiled out by a build step.
18
+
19
+ // **Jumpable**
20
+ // Any terminal element may "jump" over combinators when moving to the end of the selector
21
+ //
22
+ // This is a backwards-compat quirk of :before and :after variants.
23
+
24
+ /** @typedef {'terminal' | 'actionable' | 'jumpable'} PseudoProperty */
25
+
26
+ /** @type {Record<string, PseudoProperty[]>} */
27
+ let elementProperties = {
28
+ '::after': ['terminal', 'jumpable'],
29
+ '::backdrop': ['terminal', 'jumpable'],
30
+ '::before': ['terminal', 'jumpable'],
31
+ '::cue': ['terminal'],
32
+ '::cue-region': ['terminal'],
33
+ '::first-letter': ['terminal', 'jumpable'],
34
+ '::first-line': ['terminal', 'jumpable'],
35
+ '::grammar-error': ['terminal'],
36
+ '::marker': ['terminal', 'jumpable'],
37
+ '::part': ['terminal', 'actionable'],
38
+ '::placeholder': ['terminal', 'jumpable'],
39
+ '::selection': ['terminal', 'jumpable'],
40
+ '::slotted': ['terminal'],
41
+ '::spelling-error': ['terminal'],
42
+ '::target-text': ['terminal'],
43
+
44
+ // other
45
+ '::file-selector-button': ['terminal', 'actionable'],
46
+ '::-webkit-progress-bar': ['terminal', 'actionable'],
47
+
48
+ // Webkit scroll bar pseudo elements can be combined with user-action pseudo classes
49
+ '::-webkit-scrollbar': ['terminal', 'actionable'],
50
+ '::-webkit-scrollbar-button': ['terminal', 'actionable'],
51
+ '::-webkit-scrollbar-thumb': ['terminal', 'actionable'],
52
+ '::-webkit-scrollbar-track': ['terminal', 'actionable'],
53
+ '::-webkit-scrollbar-track-piece': ['terminal', 'actionable'],
54
+ '::-webkit-scrollbar-corner': ['terminal', 'actionable'],
55
+ '::-webkit-resizer': ['terminal', 'actionable'],
56
+
57
+ // Note: As a rule, double colons (::) should be used instead of a single colon
58
+ // (:). This distinguishes pseudo-classes from pseudo-elements. However, since
59
+ // this distinction was not present in older versions of the W3C spec, most
60
+ // browsers support both syntaxes for the original pseudo-elements.
61
+ ':after': ['terminal', 'jumpable'],
62
+ ':before': ['terminal', 'jumpable'],
63
+ ':first-letter': ['terminal', 'jumpable'],
64
+ ':first-line': ['terminal', 'jumpable'],
65
+
66
+ // The default value is used when the pseudo-element is not recognized
67
+ // Because it's not recognized, we don't know if it's terminal or not
68
+ // So we assume it can't be moved AND can have user-action pseudo classes attached to it
69
+ __default__: ['actionable'],
70
+ }
71
+
72
+ /**
73
+ * @param {Selector} sel
74
+ * @returns {Selector}
75
+ */
76
+ export function movePseudos(sel) {
77
+ let [pseudos] = movablePseudos(sel)
78
+
79
+ // Remove all pseudo elements from their respective selectors
80
+ pseudos.forEach(([sel, pseudo]) => sel.removeChild(pseudo))
81
+
82
+ // Re-add them to the end of the selector in the correct order.
83
+ // This moves terminal pseudo elements to the end of the
84
+ // selector otherwise the selector will not be valid.
85
+ //
86
+ // Examples:
87
+ // - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
88
+ // - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
89
+ //
90
+ // The selector `::before:hover` does not work but we
91
+ // can make it work for you by flipping the order.
92
+ sel.nodes.push(...pseudos.map(([, pseudo]) => pseudo))
93
+
94
+ return sel
95
+ }
96
+
97
+ /** @typedef {[sel: Selector, pseudo: Pseudo, attachedTo: Pseudo | null]} MovablePseudo */
98
+ /** @typedef {[pseudos: MovablePseudo[], lastSeenElement: Pseudo | null]} MovablePseudosResult */
99
+
100
+ /**
101
+ * @param {Selector} sel
102
+ * @returns {MovablePseudosResult}
103
+ */
104
+ function movablePseudos(sel) {
105
+ /** @type {MovablePseudo[]} */
106
+ let buffer = []
107
+
108
+ /** @type {Pseudo | null} */
109
+ let lastSeenElement = null
110
+
111
+ for (let node of sel.nodes) {
112
+ if (node.type === 'combinator') {
113
+ buffer = buffer.filter(([, node]) => propertiesForPseudo(node).includes('jumpable'))
114
+ lastSeenElement = null
115
+ } else if (node.type === 'pseudo') {
116
+ if (isMovablePseudoElement(node)) {
117
+ lastSeenElement = node
118
+ buffer.push([sel, node, null])
119
+ } else if (lastSeenElement && isAttachablePseudoClass(node, lastSeenElement)) {
120
+ buffer.push([sel, node, lastSeenElement])
121
+ } else {
122
+ lastSeenElement = null
123
+ }
124
+
125
+ for (let sub of node.nodes ?? []) {
126
+ let [movable, lastSeenElementInSub] = movablePseudos(sub)
127
+ lastSeenElement = lastSeenElementInSub || lastSeenElement
128
+ buffer.push(...movable)
129
+ }
130
+ }
131
+ }
132
+
133
+ return [buffer, lastSeenElement]
134
+ }
135
+
136
+ /**
137
+ * @param {Node} node
138
+ * @returns {boolean}
139
+ */
140
+ function isPseudoElement(node) {
141
+ return node.value.startsWith('::') || elementProperties[node.value] !== undefined
142
+ }
143
+
144
+ /**
145
+ * @param {Node} node
146
+ * @returns {boolean}
147
+ */
148
+ function isMovablePseudoElement(node) {
149
+ return isPseudoElement(node) && propertiesForPseudo(node).includes('terminal')
150
+ }
151
+
152
+ /**
153
+ * @param {Node} node
154
+ * @param {Pseudo} pseudo
155
+ * @returns {boolean}
156
+ */
157
+ function isAttachablePseudoClass(node, pseudo) {
158
+ if (node.type !== 'pseudo') return false
159
+ if (isPseudoElement(node)) return false
160
+
161
+ return propertiesForPseudo(pseudo).includes('actionable')
162
+ }
163
+
164
+ /**
165
+ * @param {Pseudo} pseudo
166
+ * @returns {PseudoProperty[]}
167
+ */
168
+ function propertiesForPseudo(pseudo) {
169
+ return elementProperties[pseudo.value] ?? elementProperties.__default__
170
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * This function removes any uses of CSS variables used as an alpha channel
3
+ *
4
+ * This is required for selectors like `:visited` which do not allow
5
+ * changes in opacity or external control using CSS variables.
6
+ *
7
+ * @param {import('postcss').Container} container
8
+ * @param {string[]} toRemove
9
+ */
10
+ export function removeAlphaVariables(container, toRemove) {
11
+ container.walkDecls((decl) => {
12
+ if (toRemove.includes(decl.prop)) {
13
+ decl.remove()
14
+
15
+ return
16
+ }
17
+
18
+ for (let varName of toRemove) {
19
+ if (decl.value.includes(`/ var(${varName})`)) {
20
+ decl.value = decl.value.replace(`/ var(${varName})`, '')
21
+ }
22
+ }
23
+ })
24
+ }
@@ -1,20 +1,20 @@
1
1
  import negateValue from './negateValue'
2
2
  import corePluginList from '../corePluginList'
3
3
  import configurePlugins from './configurePlugins'
4
- import defaultConfig from '../../stubs/defaultConfig.stub'
5
4
  import colors from '../public/colors'
6
5
  import { defaults } from './defaults'
7
6
  import { toPath } from './toPath'
8
7
  import { normalizeConfig } from './normalizeConfig'
8
+ import isPlainObject from './isPlainObject'
9
+ import { cloneDeep } from './cloneDeep'
10
+ import { parseColorFormat } from './pluginUtils'
11
+ import { withAlphaValue } from './withAlphaVariable'
12
+ import toColorValue from './toColorValue'
9
13
 
10
14
  function isFunction(input) {
11
15
  return typeof input === 'function'
12
16
  }
13
17
 
14
- function isObject(input) {
15
- return typeof input === 'object' && input !== null
16
- }
17
-
18
18
  function mergeWith(target, ...sources) {
19
19
  let customizer = sources.pop()
20
20
 
@@ -23,8 +23,8 @@ function mergeWith(target, ...sources) {
23
23
  let merged = customizer(target[k], source[k])
24
24
 
25
25
  if (merged === undefined) {
26
- if (isObject(target[k]) && isObject(source[k])) {
27
- target[k] = mergeWith(target[k], source[k], customizer)
26
+ if (isPlainObject(target[k]) && isPlainObject(source[k])) {
27
+ target[k] = mergeWith({}, target[k], source[k], customizer)
28
28
  } else {
29
29
  target[k] = source[k]
30
30
  }
@@ -98,12 +98,12 @@ function mergeThemes(themes) {
98
98
 
99
99
  function mergeExtensionCustomizer(merged, value) {
100
100
  // When we have an array of objects, we do want to merge it
101
- if (Array.isArray(merged) && isObject(merged[0])) {
101
+ if (Array.isArray(merged) && isPlainObject(merged[0])) {
102
102
  return merged.concat(value)
103
103
  }
104
104
 
105
105
  // When the incoming value is an array, and the existing config is an object, prepend the existing object
106
- if (Array.isArray(value) && isObject(value[0]) && isObject(merged)) {
106
+ if (Array.isArray(value) && isPlainObject(value[0]) && isPlainObject(merged)) {
107
107
  return [merged, ...value]
108
108
  }
109
109
 
@@ -132,32 +132,81 @@ function mergeExtensions({ extend, ...theme }) {
132
132
  })
133
133
  }
134
134
 
135
+ /**
136
+ *
137
+ * @param {string} key
138
+ * @return {Iterable<string[] & {alpha: string | undefined}>}
139
+ */
140
+ function* toPaths(key) {
141
+ let path = toPath(key)
142
+
143
+ if (path.length === 0) {
144
+ return
145
+ }
146
+
147
+ yield path
148
+
149
+ if (Array.isArray(key)) {
150
+ return
151
+ }
152
+
153
+ let pattern = /^(.*?)\s*\/\s*([^/]+)$/
154
+ let matches = key.match(pattern)
155
+
156
+ if (matches !== null) {
157
+ let [, prefix, alpha] = matches
158
+
159
+ let newPath = toPath(prefix)
160
+ newPath.alpha = alpha
161
+
162
+ yield newPath
163
+ }
164
+ }
165
+
135
166
  function resolveFunctionKeys(object) {
167
+ // theme('colors.red.500 / 0.5') -> ['colors', 'red', '500 / 0', '5]
168
+
136
169
  const resolvePath = (key, defaultValue) => {
137
- const path = toPath(key)
170
+ for (const path of toPaths(key)) {
171
+ let index = 0
172
+ let val = object
138
173
 
139
- let index = 0
140
- let val = object
174
+ while (val !== undefined && val !== null && index < path.length) {
175
+ val = val[path[index++]]
141
176
 
142
- while (val !== undefined && val !== null && index < path.length) {
143
- val = val[path[index++]]
144
- val = isFunction(val) ? val(resolvePath, configUtils) : val
145
- }
177
+ let shouldResolveAsFn =
178
+ isFunction(val) && (path.alpha === undefined || index <= path.length - 1)
146
179
 
147
- return val === undefined ? defaultValue : val
148
- }
180
+ val = shouldResolveAsFn ? val(resolvePath, configUtils) : val
181
+ }
182
+
183
+ if (val !== undefined) {
184
+ if (path.alpha !== undefined) {
185
+ let normalized = parseColorFormat(val)
186
+
187
+ return withAlphaValue(normalized, path.alpha, toColorValue(normalized))
188
+ }
189
+
190
+ if (isPlainObject(val)) {
191
+ return cloneDeep(val)
192
+ }
149
193
 
150
- resolvePath.theme = resolvePath
194
+ return val
195
+ }
196
+ }
151
197
 
152
- for (let key in configUtils) {
153
- resolvePath[key] = configUtils[key]
198
+ return defaultValue
154
199
  }
155
200
 
201
+ Object.assign(resolvePath, {
202
+ theme: resolvePath,
203
+ ...configUtils,
204
+ })
205
+
156
206
  return Object.keys(object).reduce((resolved, key) => {
157
- return {
158
- ...resolved,
159
- [key]: isFunction(object[key]) ? object[key](resolvePath, configUtils) : object[key],
160
- }
207
+ resolved[key] = isFunction(object[key]) ? object[key](resolvePath, configUtils) : object[key]
208
+
209
+ return resolved
161
210
  }, {})
162
211
  }
163
212
 
@@ -210,7 +259,6 @@ export default function resolveConfig(configs) {
210
259
  prefix: '',
211
260
  important: false,
212
261
  separator: ':',
213
- variantOrder: defaultConfig.variantOrder,
214
262
  },
215
263
  ]
216
264
 
@@ -1,6 +1,13 @@
1
1
  import fs from 'fs'
2
2
  import path from 'path'
3
3
 
4
+ const defaultConfigFiles = [
5
+ './tailwind.config.js',
6
+ './tailwind.config.cjs',
7
+ './tailwind.config.mjs',
8
+ './tailwind.config.ts',
9
+ ]
10
+
4
11
  function isObject(value) {
5
12
  return typeof value === 'object' && value !== null
6
13
  }
@@ -43,7 +50,11 @@ export default function resolveConfigPath(pathOrConfig) {
43
50
  }
44
51
 
45
52
  // require('tailwindcss')
46
- for (const configFile of ['./tailwind.config.js', './tailwind.config.cjs']) {
53
+ return resolveDefaultConfigPath()
54
+ }
55
+
56
+ export function resolveDefaultConfigPath() {
57
+ for (const configFile of defaultConfigFiles) {
47
58
  try {
48
59
  const configPath = path.resolve(configFile)
49
60
  fs.accessSync(configPath)
@@ -0,0 +1,52 @@
1
+ /**
2
+ * This splits a string on a top-level character.
3
+ *
4
+ * Regex doesn't support recursion (at least not the JS-flavored version).
5
+ * So we have to use a tiny state machine to keep track of paren placement.
6
+ *
7
+ * Expected behavior using commas:
8
+ * var(--a, 0 0 1px rgb(0, 0, 0)), 0 0 1px rgb(0, 0, 0)
9
+ * ─┬─ ┬ ┬ ┬
10
+ * x x x ╰──────── Split because top-level
11
+ * ╰──────────────┴──┴───────────── Ignored b/c inside >= 1 levels of parens
12
+ *
13
+ * @param {string} input
14
+ * @param {string} separator
15
+ */
16
+ export function splitAtTopLevelOnly(input, separator) {
17
+ let stack = []
18
+ let parts = []
19
+ let lastPos = 0
20
+ let isEscaped = false
21
+
22
+ for (let idx = 0; idx < input.length; idx++) {
23
+ let char = input[idx]
24
+
25
+ if (stack.length === 0 && char === separator[0] && !isEscaped) {
26
+ if (separator.length === 1 || input.slice(idx, idx + separator.length) === separator) {
27
+ parts.push(input.slice(lastPos, idx))
28
+ lastPos = idx + separator.length
29
+ }
30
+ }
31
+
32
+ if (isEscaped) {
33
+ isEscaped = false
34
+ } else if (char === '\\') {
35
+ isEscaped = true
36
+ }
37
+
38
+ if (char === '(' || char === '[' || char === '{') {
39
+ stack.push(char)
40
+ } else if (
41
+ (char === ')' && stack[stack.length - 1] === '(') ||
42
+ (char === ']' && stack[stack.length - 1] === '[') ||
43
+ (char === '}' && stack[stack.length - 1] === '{')
44
+ ) {
45
+ stack.pop()
46
+ }
47
+ }
48
+
49
+ parts.push(input.slice(lastPos))
50
+
51
+ return parts
52
+ }
@@ -1,4 +1,26 @@
1
+ /**
2
+ * Parse a path string into an array of path segments.
3
+ *
4
+ * Square bracket notation `a[b]` may be used to "escape" dots that would otherwise be interpreted as path separators.
5
+ *
6
+ * Example:
7
+ * a -> ['a']
8
+ * a.b.c -> ['a', 'b', 'c']
9
+ * a[b].c -> ['a', 'b', 'c']
10
+ * a[b.c].e.f -> ['a', 'b.c', 'e', 'f']
11
+ * a[b][c][d] -> ['a', 'b', 'c', 'd']
12
+ *
13
+ * @param {string|string[]} path
14
+ **/
1
15
  export function toPath(path) {
2
16
  if (Array.isArray(path)) return path
3
- return path.split(/[\.\]\[]+/g)
17
+
18
+ let openBrackets = path.split('[').length - 1
19
+ let closedBrackets = path.split(']').length - 1
20
+
21
+ if (openBrackets !== closedBrackets) {
22
+ throw new Error(`Path is invalid. Has unbalanced brackets: ${path}`)
23
+ }
24
+
25
+ return path.split(/\.(?![^\[]*\])|[\[\]]/g).filter(Boolean)
4
26
  }
@@ -1,4 +1,5 @@
1
1
  import postcss from 'postcss'
2
+ import isPlainObject from './isPlainObject'
2
3
 
3
4
  export default function transformThemeValue(themeSection) {
4
5
  if (['fontSize', 'outline'].includes(themeSection)) {
@@ -10,9 +11,16 @@ export default function transformThemeValue(themeSection) {
10
11
  }
11
12
  }
12
13
 
14
+ if (themeSection === 'fontFamily') {
15
+ return (value) => {
16
+ if (typeof value === 'function') value = value({})
17
+ let families = Array.isArray(value) && isPlainObject(value[1]) ? value[0] : value
18
+ return Array.isArray(families) ? families.join(', ') : families
19
+ }
20
+ }
21
+
13
22
  if (
14
23
  [
15
- 'fontFamily',
16
24
  'boxShadow',
17
25
  'transitionProperty',
18
26
  'transitionDuration',
@@ -44,8 +52,10 @@ export default function transformThemeValue(themeSection) {
44
52
  }
45
53
  }
46
54
 
47
- return (value) => {
48
- if (typeof value === 'function') value = value({})
55
+ return (value, opts = {}) => {
56
+ if (typeof value === 'function') {
57
+ value = value(opts)
58
+ }
49
59
 
50
60
  return value
51
61
  }
@@ -0,0 +1,26 @@
1
+ import log from './log'
2
+
3
+ export function validateConfig(config) {
4
+ if (config.content.files.length === 0) {
5
+ log.warn('content-problems', [
6
+ 'The `content` option in your Tailwind CSS configuration is missing or empty.',
7
+ 'Configure your content sources or your generated CSS will be missing styles.',
8
+ 'https://tailwindcss.com/docs/content-configuration',
9
+ ])
10
+ }
11
+
12
+ // Warn if the line-clamp plugin is installed
13
+ try {
14
+ let plugin = require('@tailwindcss/line-clamp')
15
+ if (config.plugins.includes(plugin)) {
16
+ log.warn('line-clamp-in-core', [
17
+ 'As of Tailwind CSS v3.3, the `@tailwindcss/line-clamp` plugin is now included by default.',
18
+ 'Remove it from the `plugins` array in your configuration to eliminate this warning.',
19
+ ])
20
+
21
+ config.plugins = config.plugins.filter((p) => p !== plugin)
22
+ }
23
+ } catch {}
24
+
25
+ return config
26
+ }
@@ -0,0 +1,34 @@
1
+ import { length, percentage } from './dataTypes'
2
+ import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
3
+
4
+ /**
5
+ *
6
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/background-size#formal_syntax
7
+ *
8
+ * background-size =
9
+ * <bg-size>#
10
+ *
11
+ * <bg-size> =
12
+ * [ <length-percentage [0,∞]> | auto ]{1,2} |
13
+ * cover |
14
+ * contain
15
+ *
16
+ * <length-percentage> =
17
+ * <length> |
18
+ * <percentage>
19
+ *
20
+ * @param {string} value
21
+ */
22
+ export function backgroundSize(value) {
23
+ let keywordValues = ['cover', 'contain']
24
+ // the <length-percentage> type will probably be a css function
25
+ // so we have to use `splitAtTopLevelOnly`
26
+ return splitAtTopLevelOnly(value, ',').every((part) => {
27
+ let sizes = splitAtTopLevelOnly(part, '_').filter(Boolean)
28
+ if (sizes.length === 1 && keywordValues.includes(sizes[0])) return true
29
+
30
+ if (sizes.length !== 1 && sizes.length !== 2) return false
31
+
32
+ return sizes.every((size) => length(size) || percentage(size) || size === 'auto')
33
+ })
34
+ }
@@ -5,7 +5,7 @@ export function withAlphaValue(color, alphaValue, defaultValue) {
5
5
  return color({ opacityValue: alphaValue })
6
6
  }
7
7
 
8
- let parsed = parseColor(color)
8
+ let parsed = parseColor(color, { loose: true })
9
9
 
10
10
  if (parsed === null) {
11
11
  return defaultValue
@@ -0,0 +1 @@
1
+ !*
@@ -0,0 +1,6 @@
1
+ {
2
+ "printWidth": 120,
3
+ "semi": false,
4
+ "singleQuote": true,
5
+ "trailingComma": "es5"
6
+ }