tailwindcss 0.0.0-insiders.bbafc8e → 0.0.0-insiders.bbc2f3f

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 (198) hide show
  1. package/README.md +16 -13
  2. package/dist/chunk-5C7JPVMO.mjs +10 -0
  3. package/dist/chunk-AZANAYY2.mjs +1 -0
  4. package/dist/chunk-V2K3XTS4.mjs +1 -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 +1 -0
  17. package/dist/flatten-color-palette.mjs +1 -0
  18. package/dist/lib.d.mts +260 -0
  19. package/dist/lib.d.ts +3 -0
  20. package/dist/lib.js +33 -0
  21. package/dist/lib.mjs +24 -0
  22. package/dist/plugin.d.mts +11 -0
  23. package/dist/plugin.d.ts +104 -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-B254mqw1.d.mts +98 -0
  29. package/index.css +865 -0
  30. package/package.json +73 -95
  31. package/preflight.css +383 -0
  32. package/theme.css +453 -0
  33. package/CHANGELOG.md +0 -2084
  34. package/base.css +0 -1
  35. package/colors.js +0 -2
  36. package/components.css +0 -1
  37. package/defaultConfig.js +0 -2
  38. package/defaultTheme.js +0 -2
  39. package/lib/cli-peer-dependencies.js +0 -15
  40. package/lib/cli.js +0 -741
  41. package/lib/constants.js +0 -37
  42. package/lib/corePluginList.js +0 -178
  43. package/lib/corePlugins.js +0 -3587
  44. package/lib/css/LICENSE +0 -25
  45. package/lib/css/preflight.css +0 -367
  46. package/lib/featureFlags.js +0 -59
  47. package/lib/index.js +0 -41
  48. package/lib/lib/cacheInvalidation.js +0 -69
  49. package/lib/lib/collapseAdjacentRules.js +0 -54
  50. package/lib/lib/collapseDuplicateDeclarations.js +0 -80
  51. package/lib/lib/defaultExtractor.js +0 -44
  52. package/lib/lib/detectNesting.js +0 -34
  53. package/lib/lib/evaluateTailwindFunctions.js +0 -171
  54. package/lib/lib/expandApplyAtRules.js +0 -433
  55. package/lib/lib/expandTailwindAtRules.js +0 -262
  56. package/lib/lib/generateRules.js +0 -631
  57. package/lib/lib/getModuleDependencies.js +0 -48
  58. package/lib/lib/normalizeTailwindDirectives.js +0 -84
  59. package/lib/lib/partitionApplyAtRules.js +0 -53
  60. package/lib/lib/resolveDefaultsAtRules.js +0 -143
  61. package/lib/lib/setupContextUtils.js +0 -859
  62. package/lib/lib/setupTrackingContext.js +0 -171
  63. package/lib/lib/sharedState.js +0 -52
  64. package/lib/lib/substituteScreenAtRules.js +0 -27
  65. package/lib/postcss-plugins/nesting/README.md +0 -42
  66. package/lib/postcss-plugins/nesting/index.js +0 -17
  67. package/lib/postcss-plugins/nesting/plugin.js +0 -85
  68. package/lib/processTailwindFeatures.js +0 -59
  69. package/lib/public/colors.js +0 -329
  70. package/lib/public/create-plugin.js +0 -13
  71. package/lib/public/default-config.js +0 -14
  72. package/lib/public/default-theme.js +0 -14
  73. package/lib/public/resolve-config.js +0 -19
  74. package/lib/util/bigSign.js +0 -8
  75. package/lib/util/buildMediaQuery.js +0 -20
  76. package/lib/util/cloneDeep.js +0 -19
  77. package/lib/util/cloneNodes.js +0 -25
  78. package/lib/util/color.js +0 -99
  79. package/lib/util/configurePlugins.js +0 -18
  80. package/lib/util/createPlugin.js +0 -29
  81. package/lib/util/createUtilityPlugin.js +0 -49
  82. package/lib/util/dataTypes.js +0 -233
  83. package/lib/util/defaults.js +0 -22
  84. package/lib/util/escapeClassName.js +0 -19
  85. package/lib/util/escapeCommas.js +0 -8
  86. package/lib/util/flattenColorPalette.js +0 -17
  87. package/lib/util/formatVariantSelector.js +0 -186
  88. package/lib/util/getAllConfigs.js +0 -29
  89. package/lib/util/hashConfig.js +0 -16
  90. package/lib/util/isKeyframeRule.js +0 -8
  91. package/lib/util/isPlainObject.js +0 -12
  92. package/lib/util/isValidArbitraryValue.js +0 -64
  93. package/lib/util/log.js +0 -51
  94. package/lib/util/nameClass.js +0 -32
  95. package/lib/util/negateValue.js +0 -19
  96. package/lib/util/normalizeConfig.js +0 -240
  97. package/lib/util/normalizeScreens.js +0 -59
  98. package/lib/util/parseAnimationValue.js +0 -89
  99. package/lib/util/parseBoxShadowValue.js +0 -117
  100. package/lib/util/parseDependency.js +0 -63
  101. package/lib/util/parseObjectStyles.js +0 -31
  102. package/lib/util/pluginUtils.js +0 -179
  103. package/lib/util/prefixSelector.js +0 -20
  104. package/lib/util/resolveConfig.js +0 -255
  105. package/lib/util/resolveConfigPath.js +0 -51
  106. package/lib/util/responsive.js +0 -19
  107. package/lib/util/tap.js +0 -9
  108. package/lib/util/toColorValue.js +0 -8
  109. package/lib/util/toPath.js +0 -14
  110. package/lib/util/transformThemeValue.js +0 -59
  111. package/lib/util/withAlphaVariable.js +0 -67
  112. package/nesting/index.js +0 -2
  113. package/peers/index.js +0 -75077
  114. package/plugin.js +0 -2
  115. package/prettier.config.js +0 -19
  116. package/resolveConfig.js +0 -2
  117. package/screens.css +0 -1
  118. package/scripts/create-plugin-list.js +0 -10
  119. package/scripts/install-integrations.js +0 -27
  120. package/scripts/rebuildFixtures.js +0 -68
  121. package/src/cli-peer-dependencies.js +0 -9
  122. package/src/cli.js +0 -815
  123. package/src/constants.js +0 -17
  124. package/src/corePluginList.js +0 -1
  125. package/src/corePlugins.js +0 -2365
  126. package/src/css/LICENSE +0 -25
  127. package/src/css/preflight.css +0 -367
  128. package/src/featureFlags.js +0 -54
  129. package/src/index.js +0 -42
  130. package/src/lib/cacheInvalidation.js +0 -52
  131. package/src/lib/collapseAdjacentRules.js +0 -54
  132. package/src/lib/collapseDuplicateDeclarations.js +0 -93
  133. package/src/lib/defaultExtractor.js +0 -50
  134. package/src/lib/detectNesting.js +0 -39
  135. package/src/lib/evaluateTailwindFunctions.js +0 -198
  136. package/src/lib/expandApplyAtRules.js +0 -480
  137. package/src/lib/expandTailwindAtRules.js +0 -292
  138. package/src/lib/generateRules.js +0 -623
  139. package/src/lib/getModuleDependencies.js +0 -39
  140. package/src/lib/normalizeTailwindDirectives.js +0 -84
  141. package/src/lib/partitionApplyAtRules.js +0 -52
  142. package/src/lib/resolveDefaultsAtRules.js +0 -146
  143. package/src/lib/setupContextUtils.js +0 -883
  144. package/src/lib/setupTrackingContext.js +0 -183
  145. package/src/lib/sharedState.js +0 -48
  146. package/src/lib/substituteScreenAtRules.js +0 -19
  147. package/src/postcss-plugins/nesting/README.md +0 -42
  148. package/src/postcss-plugins/nesting/index.js +0 -13
  149. package/src/postcss-plugins/nesting/plugin.js +0 -80
  150. package/src/processTailwindFeatures.js +0 -58
  151. package/src/public/colors.js +0 -300
  152. package/src/public/create-plugin.js +0 -2
  153. package/src/public/default-config.js +0 -4
  154. package/src/public/default-theme.js +0 -4
  155. package/src/public/resolve-config.js +0 -7
  156. package/src/util/bigSign.js +0 -3
  157. package/src/util/buildMediaQuery.js +0 -20
  158. package/src/util/cloneDeep.js +0 -11
  159. package/src/util/cloneNodes.js +0 -24
  160. package/src/util/color.js +0 -69
  161. package/src/util/configurePlugins.js +0 -23
  162. package/src/util/createPlugin.js +0 -27
  163. package/src/util/createUtilityPlugin.js +0 -37
  164. package/src/util/dataTypes.js +0 -248
  165. package/src/util/defaults.js +0 -17
  166. package/src/util/escapeClassName.js +0 -8
  167. package/src/util/escapeCommas.js +0 -3
  168. package/src/util/flattenColorPalette.js +0 -13
  169. package/src/util/formatVariantSelector.js +0 -196
  170. package/src/util/getAllConfigs.js +0 -19
  171. package/src/util/hashConfig.js +0 -5
  172. package/src/util/isKeyframeRule.js +0 -3
  173. package/src/util/isPlainObject.js +0 -8
  174. package/src/util/isValidArbitraryValue.js +0 -61
  175. package/src/util/log.js +0 -29
  176. package/src/util/nameClass.js +0 -26
  177. package/src/util/negateValue.js +0 -16
  178. package/src/util/normalizeConfig.js +0 -270
  179. package/src/util/normalizeScreens.js +0 -45
  180. package/src/util/parseAnimationValue.js +0 -68
  181. package/src/util/parseBoxShadowValue.js +0 -119
  182. package/src/util/parseDependency.js +0 -49
  183. package/src/util/parseObjectStyles.js +0 -19
  184. package/src/util/pluginUtils.js +0 -192
  185. package/src/util/prefixSelector.js +0 -14
  186. package/src/util/resolveConfig.js +0 -269
  187. package/src/util/resolveConfigPath.js +0 -55
  188. package/src/util/responsive.js +0 -10
  189. package/src/util/tap.js +0 -4
  190. package/src/util/toColorValue.js +0 -3
  191. package/src/util/toPath.js +0 -26
  192. package/src/util/transformThemeValue.js +0 -52
  193. package/src/util/withAlphaVariable.js +0 -49
  194. package/stubs/defaultConfig.stub.js +0 -950
  195. package/stubs/defaultPostCssConfig.stub.js +0 -6
  196. package/stubs/simpleConfig.stub.js +0 -7
  197. package/tailwind.css +0 -5
  198. package/variants.css +0 -1
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- exports.defaultExtractor = defaultExtractor;
6
- const PATTERNS = [
7
- /(?:\['([^'\s]+[^<>"'`\s:\\])')/.source,
8
- /(?:\["([^"\s]+[^<>"'`\s:\\])")/.source,
9
- /(?:\[`([^`\s]+[^<>"'`\s:\\])`)/.source,
10
- /([^<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source,
11
- /([^<>"'`\s]*\[\w*"[^'`\s]*"?\])/.source,
12
- /([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source,
13
- /([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source,
14
- /([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source,
15
- /([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source,
16
- /([^<>"'`\s]*\[[^<>"'`\s]*\('[^"`\s]*'\)+\])/.source,
17
- /([^<>"'`\s]*\[[^<>"'`\s]*\("[^'`\s]*"\)+\])/.source,
18
- /([^<>"'`\s]*\['[^"'`\s]*'\])/.source,
19
- /([^<>"'`\s]*\["[^"'`\s]*"\])/.source,
20
- /([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source,
21
- /([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source,
22
- /([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source,
23
- /([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
24
- /([^"'`\s]*[^<>"'`\s:\\])/.source,
25
- /([^<>"'`\s]*[^"'`\s:\\])/.source,
26
- ].join('|');
27
- const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
28
- const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
29
- function defaultExtractor(content) {
30
- let broadMatches = content.matchAll(BROAD_MATCH_GLOBAL_REGEXP);
31
- let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || [];
32
- let results = [
33
- ...broadMatches,
34
- ...innerMatches
35
- ].flat().filter((v)=>v !== undefined
36
- );
37
- return results;
38
- } // Regular utilities
39
- // {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
40
- // Arbitrary values
41
- // {{modifier}:}*{namespace}-[{arbitraryValue}]{/{opacityModifier}}?
42
- // arbitraryValue: no whitespace, balanced quotes unless within quotes, balanced brackets unless within quotes
43
- // Arbitrary properties
44
- // {{modifier}:}*[{validCssPropertyName}:{arbitraryValue}]
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- exports.default = _default;
6
- function _default(_context) {
7
- return (root, result)=>{
8
- let found = false;
9
- root.walkAtRules('tailwind', (node)=>{
10
- if (found) return false;
11
- if (node.parent && node.parent.type !== 'root') {
12
- found = true;
13
- node.warn(result, [
14
- 'Nested @tailwind rules were detected, but are not supported.',
15
- "Consider using a prefix to scope Tailwind's classes: https://tailwindcss.com/docs/configuration#prefix",
16
- 'Alternatively, use the important selector strategy: https://tailwindcss.com/docs/configuration#selector-strategy',
17
- ].join('\n'));
18
- return false;
19
- }
20
- });
21
- root.walkRules((rule)=>{
22
- if (found) return false;
23
- rule.walkRules((nestedRule)=>{
24
- found = true;
25
- nestedRule.warn(result, [
26
- 'Nested CSS was detected, but CSS nesting has not been configured correctly.',
27
- 'Please enable a CSS nesting plugin *before* Tailwind in your configuration.',
28
- 'See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting',
29
- ].join('\n'));
30
- return false;
31
- });
32
- });
33
- };
34
- }
@@ -1,171 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- exports.default = _default;
6
- var _dlv = _interopRequireDefault(require("dlv"));
7
- var _didyoumean = _interopRequireDefault(require("didyoumean"));
8
- var _transformThemeValue = _interopRequireDefault(require("../util/transformThemeValue"));
9
- var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
10
- var _normalizeScreens = require("../util/normalizeScreens");
11
- var _buildMediaQuery = _interopRequireDefault(require("../util/buildMediaQuery"));
12
- var _toPath = require("../util/toPath");
13
- function _interopRequireDefault(obj) {
14
- return obj && obj.__esModule ? obj : {
15
- default: obj
16
- };
17
- }
18
- function isObject(input) {
19
- return typeof input === 'object' && input !== null;
20
- }
21
- function findClosestExistingPath(theme, path) {
22
- let parts = (0, _toPath).toPath(path);
23
- do {
24
- parts.pop();
25
- if ((0, _dlv).default(theme, parts) !== undefined) break;
26
- }while (parts.length)
27
- return parts.length ? parts : undefined;
28
- }
29
- function pathToString(path) {
30
- if (typeof path === 'string') return path;
31
- return path.reduce((acc, cur, i)=>{
32
- if (cur.includes('.')) return `${acc}[${cur}]`;
33
- return i === 0 ? cur : `${acc}.${cur}`;
34
- }, '');
35
- }
36
- function list(items) {
37
- return items.map((key)=>`'${key}'`
38
- ).join(', ');
39
- }
40
- function listKeys(obj) {
41
- return list(Object.keys(obj));
42
- }
43
- function validatePath(config, path, defaultValue) {
44
- const pathString = Array.isArray(path) ? pathToString(path) : path.replace(/^['"]+/g, '').replace(/['"]+$/g, '');
45
- const pathSegments = Array.isArray(path) ? path : (0, _toPath).toPath(pathString);
46
- const value = (0, _dlv).default(config.theme, pathSegments, defaultValue);
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 = (0, _dlv).default(config.theme, parentSegments);
51
- if (isObject(parentValue)) {
52
- const validKeys = Object.keys(parentValue).filter((key)=>validatePath(config, [
53
- ...parentSegments,
54
- key
55
- ]).isValid
56
- );
57
- const suggestion = (0, _didyoumean).default(pathSegments[pathSegments.length - 1], validKeys);
58
- if (suggestion) {
59
- error += ` Did you mean '${pathToString([
60
- ...parentSegments,
61
- suggestion
62
- ])}'?`;
63
- } else if (validKeys.length > 0) {
64
- error += ` '${pathToString(parentSegments)}' has the following valid keys: ${list(validKeys)}`;
65
- }
66
- } else {
67
- const closestPath = findClosestExistingPath(config.theme, pathString);
68
- if (closestPath) {
69
- const closestValue = (0, _dlv).default(config.theme, closestPath);
70
- if (isObject(closestValue)) {
71
- error += ` '${pathToString(closestPath)}' has the following keys: ${listKeys(closestValue)}`;
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
- return {
80
- isValid: false,
81
- error
82
- };
83
- }
84
- if (!(typeof value === 'string' || typeof value === 'number' || typeof value === 'function' || value instanceof String || value instanceof Number || Array.isArray(value))) {
85
- let error = `'${pathString}' was found but does not resolve to a string.`;
86
- if (isObject(value)) {
87
- let validKeys = Object.keys(value).filter((key)=>validatePath(config, [
88
- ...pathSegments,
89
- key
90
- ]).isValid
91
- );
92
- if (validKeys.length) {
93
- error += ` Did you mean something like '${pathToString([
94
- ...pathSegments,
95
- validKeys[0]
96
- ])}'?`;
97
- }
98
- }
99
- return {
100
- isValid: false,
101
- error
102
- };
103
- }
104
- const [themeSection] = pathSegments;
105
- return {
106
- isValid: true,
107
- value: (0, _transformThemeValue).default(themeSection)(value)
108
- };
109
- }
110
- function extractArgs(node, vNodes, functions) {
111
- vNodes = vNodes.map((vNode)=>resolveVNode(node, vNode, functions)
112
- );
113
- let args = [
114
- ''
115
- ];
116
- for (let vNode1 of vNodes){
117
- if (vNode1.type === 'div' && vNode1.value === ',') {
118
- args.push('');
119
- } else {
120
- args[args.length - 1] += _postcssValueParser.default.stringify(vNode1);
121
- }
122
- }
123
- return args;
124
- }
125
- function resolveVNode(node, vNode, functions) {
126
- if (vNode.type === 'function' && functions[vNode.value] !== undefined) {
127
- let args = extractArgs(node, vNode.nodes, functions);
128
- vNode.type = 'word';
129
- vNode.value = functions[vNode.value](node, ...args);
130
- }
131
- return vNode;
132
- }
133
- function resolveFunctions(node, input, functions) {
134
- return (0, _postcssValueParser).default(input).walk((vNode)=>{
135
- resolveVNode(node, vNode, functions);
136
- }).toString();
137
- }
138
- let nodeTypePropertyMap = {
139
- atrule: 'params',
140
- decl: 'value'
141
- };
142
- function _default({ tailwindConfig: config }) {
143
- let functions = {
144
- theme: (node, path, ...defaultValue)=>{
145
- const { isValid , value , error } = validatePath(config, path, defaultValue.length ? defaultValue : undefined);
146
- if (!isValid) {
147
- throw node.error(error);
148
- }
149
- return value;
150
- },
151
- screen: (node, screen)=>{
152
- screen = screen.replace(/^['"]+/g, '').replace(/['"]+$/g, '');
153
- let screens = (0, _normalizeScreens).normalizeScreens(config.theme.screens);
154
- let screenDefinition = screens.find(({ name })=>name === screen
155
- );
156
- if (!screenDefinition) {
157
- throw node.error(`The '${screen}' screen does not exist in your theme.`);
158
- }
159
- return (0, _buildMediaQuery).default(screenDefinition);
160
- }
161
- };
162
- return (root)=>{
163
- root.walk((node)=>{
164
- let property = nodeTypePropertyMap[node.type];
165
- if (property === undefined) {
166
- return;
167
- }
168
- node[property] = resolveFunctions(node, node[property], functions);
169
- });
170
- };
171
- }
@@ -1,433 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- exports.default = expandApplyAtRules;
6
- var _postcss = _interopRequireDefault(require("postcss"));
7
- var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
8
- var _generateRules = require("./generateRules");
9
- var _bigSign = _interopRequireDefault(require("../util/bigSign"));
10
- var _escapeClassName = _interopRequireDefault(require("../util/escapeClassName"));
11
- function _interopRequireDefault(obj) {
12
- return obj && obj.__esModule ? obj : {
13
- default: obj
14
- };
15
- }
16
- /** @typedef {Map<string, [any, import('postcss').Rule[]]>} ApplyCache */ function extractClasses(node) {
17
- let classes = new Set();
18
- let container = _postcss.default.root({
19
- nodes: [
20
- node.clone()
21
- ]
22
- });
23
- container.walkRules((rule)=>{
24
- (0, _postcssSelectorParser).default((selectors)=>{
25
- selectors.walkClasses((classSelector)=>{
26
- classes.add(classSelector.value);
27
- });
28
- }).processSync(rule.selector);
29
- });
30
- return Array.from(classes);
31
- }
32
- function extractBaseCandidates(candidates, separator) {
33
- let baseClasses = new Set();
34
- for (let candidate of candidates){
35
- baseClasses.add(candidate.split(separator).pop());
36
- }
37
- return Array.from(baseClasses);
38
- }
39
- function prefix(context, selector) {
40
- let prefix1 = context.tailwindConfig.prefix;
41
- return typeof prefix1 === 'function' ? prefix1(selector) : prefix1 + selector;
42
- }
43
- function* pathToRoot(node) {
44
- yield node;
45
- while(node.parent){
46
- yield node.parent;
47
- node = node.parent;
48
- }
49
- }
50
- /**
51
- * Only clone the node itself and not its children
52
- *
53
- * @param {*} node
54
- * @param {*} overrides
55
- * @returns
56
- */ function shallowClone(node, overrides = {}) {
57
- let children = node.nodes;
58
- node.nodes = [];
59
- let tmp = node.clone(overrides);
60
- node.nodes = children;
61
- return tmp;
62
- }
63
- /**
64
- * Clone just the nodes all the way to the top that are required to represent
65
- * this singular rule in the tree.
66
- *
67
- * For example, if we have CSS like this:
68
- * ```css
69
- * @media (min-width: 768px) {
70
- * @supports (display: grid) {
71
- * .foo {
72
- * display: grid;
73
- * grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
74
- * }
75
- * }
76
- *
77
- * @supports (backdrop-filter: blur(1px)) {
78
- * .bar {
79
- * backdrop-filter: blur(1px);
80
- * }
81
- * }
82
- *
83
- * .baz {
84
- * color: orange;
85
- * }
86
- * }
87
- * ```
88
- *
89
- * And we're cloning `.bar` it'll return a cloned version of what's required for just that single node:
90
- *
91
- * ```css
92
- * @media (min-width: 768px) {
93
- * @supports (backdrop-filter: blur(1px)) {
94
- * .bar {
95
- * backdrop-filter: blur(1px);
96
- * }
97
- * }
98
- * }
99
- * ```
100
- *
101
- * @param {import('postcss').Node} node
102
- */ function nestedClone(node) {
103
- for (let parent of pathToRoot(node)){
104
- if (node === parent) {
105
- continue;
106
- }
107
- if (parent.type === 'root') {
108
- break;
109
- }
110
- node = shallowClone(parent, {
111
- nodes: [
112
- node
113
- ]
114
- });
115
- }
116
- return node;
117
- }
118
- /**
119
- * @param {import('postcss').Root} root
120
- */ function buildLocalApplyCache(root, context) {
121
- /** @type {ApplyCache} */ let cache = new Map();
122
- let highestOffset = context.layerOrder.user >> 4n;
123
- root.walkRules((rule, idx)=>{
124
- // Ignore rules generated by Tailwind
125
- for (let node of pathToRoot(rule)){
126
- var ref;
127
- if (((ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.layer) !== undefined) {
128
- return;
129
- }
130
- }
131
- // Clone what's required to represent this singular rule in the tree
132
- let container = nestedClone(rule);
133
- for (let className of extractClasses(rule)){
134
- let list = cache.get(className) || [];
135
- cache.set(className, list);
136
- list.push([
137
- {
138
- layer: 'user',
139
- sort: BigInt(idx) + highestOffset,
140
- important: false
141
- },
142
- container,
143
- ]);
144
- }
145
- });
146
- return cache;
147
- }
148
- /**
149
- * @returns {ApplyCache}
150
- */ function buildApplyCache(applyCandidates, context) {
151
- for (let candidate of applyCandidates){
152
- if (context.notClassCache.has(candidate) || context.applyClassCache.has(candidate)) {
153
- continue;
154
- }
155
- if (context.classCache.has(candidate)) {
156
- context.applyClassCache.set(candidate, context.classCache.get(candidate).map(([meta, rule])=>[
157
- meta,
158
- rule.clone()
159
- ]
160
- ));
161
- continue;
162
- }
163
- let matches = Array.from((0, _generateRules).resolveMatches(candidate, context));
164
- if (matches.length === 0) {
165
- context.notClassCache.add(candidate);
166
- continue;
167
- }
168
- context.applyClassCache.set(candidate, matches);
169
- }
170
- return context.applyClassCache;
171
- }
172
- /**
173
- * Build a cache only when it's first used
174
- *
175
- * @param {() => ApplyCache} buildCacheFn
176
- * @returns {ApplyCache}
177
- */ function lazyCache(buildCacheFn) {
178
- let cache = null;
179
- return {
180
- get: (name)=>{
181
- cache = cache || buildCacheFn();
182
- return cache.get(name);
183
- },
184
- has: (name)=>{
185
- cache = cache || buildCacheFn();
186
- return cache.has(name);
187
- }
188
- };
189
- }
190
- /**
191
- * Take a series of multiple caches and merge
192
- * them so they act like one large cache
193
- *
194
- * @param {ApplyCache[]} caches
195
- * @returns {ApplyCache}
196
- */ function combineCaches(caches) {
197
- return {
198
- get: (name)=>caches.flatMap((cache)=>cache.get(name) || []
199
- )
200
- ,
201
- has: (name)=>caches.some((cache)=>cache.has(name)
202
- )
203
- };
204
- }
205
- function extractApplyCandidates(params) {
206
- let candidates = params.split(/[\s\t\n]+/g);
207
- if (candidates[candidates.length - 1] === '!important') {
208
- return [
209
- candidates.slice(0, -1),
210
- true
211
- ];
212
- }
213
- return [
214
- candidates,
215
- false
216
- ];
217
- }
218
- function processApply(root, context, localCache) {
219
- let applyCandidates = new Set();
220
- // Collect all @apply rules and candidates
221
- let applies = [];
222
- root.walkAtRules('apply', (rule)=>{
223
- let [candidates] = extractApplyCandidates(rule.params);
224
- for (let util of candidates){
225
- applyCandidates.add(util);
226
- }
227
- applies.push(rule);
228
- });
229
- // Start the @apply process if we have rules with @apply in them
230
- if (applies.length > 0) {
231
- // Fill up some caches!
232
- let applyClassCache = combineCaches([
233
- localCache,
234
- buildApplyCache(applyCandidates, context)
235
- ]);
236
- /**
237
- * When we have an apply like this:
238
- *
239
- * .abc {
240
- * @apply hover:font-bold;
241
- * }
242
- *
243
- * What we essentially will do is resolve to this:
244
- *
245
- * .abc {
246
- * @apply .hover\:font-bold:hover {
247
- * font-weight: 500;
248
- * }
249
- * }
250
- *
251
- * Notice that the to-be-applied class is `.hover\:font-bold:hover` and that the utility candidate was `hover:font-bold`.
252
- * What happens in this function is that we prepend a `.` and escape the candidate.
253
- * This will result in `.hover\:font-bold`
254
- * Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
255
- */ // TODO: Should we use postcss-selector-parser for this instead?
256
- function replaceSelector(selector, utilitySelectors, candidate) {
257
- let needle = `.${(0, _escapeClassName).default(candidate)}`;
258
- let utilitySelectorsList = utilitySelectors.split(/\s*\,(?![^(]*\))\s*/g);
259
- return selector.split(/\s*\,(?![^(]*\))\s*/g).map((s)=>{
260
- let replaced = [];
261
- for (let utilitySelector of utilitySelectorsList){
262
- let replacedSelector = utilitySelector.replace(needle, s);
263
- if (replacedSelector === utilitySelector) {
264
- continue;
265
- }
266
- replaced.push(replacedSelector);
267
- }
268
- return replaced.join(', ');
269
- }).join(', ');
270
- }
271
- let perParentApplies = new Map();
272
- // Collect all apply candidates and their rules
273
- for (let apply of applies){
274
- let candidates = perParentApplies.get(apply.parent) || [];
275
- perParentApplies.set(apply.parent, [
276
- candidates,
277
- apply.source
278
- ]);
279
- let [applyCandidates, important] = extractApplyCandidates(apply.params);
280
- if (apply.parent.type === 'atrule') {
281
- if (apply.parent.name === 'screen') {
282
- const screenType = apply.parent.params;
283
- throw apply.error(`@apply is not supported within nested at-rules like @screen. We suggest you write this as @apply ${applyCandidates.map((c)=>`${screenType}:${c}`
284
- ).join(' ')} instead.`);
285
- }
286
- throw apply.error(`@apply is not supported within nested at-rules like @${apply.parent.name}. You can fix this by un-nesting @${apply.parent.name}.`);
287
- }
288
- for (let applyCandidate of applyCandidates){
289
- if ([
290
- prefix(context, 'group'),
291
- prefix(context, 'peer')
292
- ].includes(applyCandidate)) {
293
- // TODO: Link to specific documentation page with error code.
294
- throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`);
295
- }
296
- if (!applyClassCache.has(applyCandidate)) {
297
- throw apply.error(`The \`${applyCandidate}\` class does not exist. If \`${applyCandidate}\` is a custom class, make sure it is defined within a \`@layer\` directive.`);
298
- }
299
- let rules = applyClassCache.get(applyCandidate);
300
- candidates.push([
301
- applyCandidate,
302
- important,
303
- rules
304
- ]);
305
- }
306
- }
307
- for (const [parent, [candidates, atApplySource]] of perParentApplies){
308
- let siblings = [];
309
- for (let [applyCandidate, important, rules] of candidates){
310
- for (let [meta, node1] of rules){
311
- let parentClasses = extractClasses(parent);
312
- let nodeClasses = extractClasses(node1);
313
- // Add base utility classes from the @apply node to the list of
314
- // classes to check whether it intersects and therefore results in a
315
- // circular dependency or not.
316
- //
317
- // E.g.:
318
- // .foo {
319
- // @apply hover:a; // This applies "a" but with a modifier
320
- // }
321
- //
322
- // We only have to do that with base classes of the `node`, not of the `parent`
323
- // E.g.:
324
- // .hover\:foo {
325
- // @apply bar;
326
- // }
327
- // .bar {
328
- // @apply foo;
329
- // }
330
- //
331
- // This should not result in a circular dependency because we are
332
- // just applying `.foo` and the rule above is `.hover\:foo` which is
333
- // unrelated. However, if we were to apply `hover:foo` then we _did_
334
- // have to include this one.
335
- nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
336
- let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector)
337
- );
338
- if (intersects) {
339
- throw node1.error(`You cannot \`@apply\` the \`${applyCandidate}\` utility here because it creates a circular dependency.`);
340
- }
341
- let root = _postcss.default.root({
342
- nodes: [
343
- node1.clone()
344
- ]
345
- });
346
- // Make sure every node in the entire tree points back at the @apply rule that generated it
347
- root.walk((node)=>{
348
- node.source = atApplySource;
349
- });
350
- let canRewriteSelector = node1.type !== 'atrule' || node1.type === 'atrule' && node1.name !== 'keyframes';
351
- if (canRewriteSelector) {
352
- root.walkRules((rule)=>{
353
- // Let's imagine you have the following structure:
354
- //
355
- // .foo {
356
- // @apply bar;
357
- // }
358
- //
359
- // @supports (a: b) {
360
- // .bar {
361
- // color: blue
362
- // }
363
- //
364
- // .something-unrelated {}
365
- // }
366
- //
367
- // In this case we want to apply `.bar` but it happens to be in
368
- // an atrule node. We clone that node instead of the nested one
369
- // because we still want that @supports rule to be there once we
370
- // applied everything.
371
- //
372
- // However it happens to be that the `.something-unrelated` is
373
- // also in that same shared @supports atrule. This is not good,
374
- // and this should not be there. The good part is that this is
375
- // a clone already and it can be safely removed. The question is
376
- // how do we know we can remove it. Basically what we can do is
377
- // match it against the applyCandidate that you want to apply. If
378
- // it doesn't match the we can safely delete it.
379
- //
380
- // If we didn't do this, then the `replaceSelector` function
381
- // would have replaced this with something that didn't exist and
382
- // therefore it removed the selector altogether. In this specific
383
- // case it would result in `{}` instead of `.something-unrelated {}`
384
- if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate
385
- )) {
386
- rule.remove();
387
- return;
388
- }
389
- rule.selector = replaceSelector(parent.selector, rule.selector, applyCandidate);
390
- rule.walkDecls((d)=>{
391
- d.important = meta.important || important;
392
- });
393
- });
394
- }
395
- // Insert it
396
- siblings.push([
397
- // Ensure that when we are sorting, that we take the layer order into account
398
- {
399
- ...meta,
400
- sort: meta.sort | context.layerOrder[meta.layer]
401
- },
402
- root.nodes[0],
403
- ]);
404
- }
405
- }
406
- // Inject the rules, sorted, correctly
407
- let nodes = siblings.sort(([a], [z])=>(0, _bigSign).default(a.sort - z.sort)
408
- ).map((s)=>s[1]
409
- );
410
- // `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
411
- parent.after(nodes);
412
- }
413
- for (let apply1 of applies){
414
- // If there are left-over declarations, just remove the @apply
415
- if (apply1.parent.nodes.length > 1) {
416
- apply1.remove();
417
- } else {
418
- // The node is empty, drop the full node
419
- apply1.parent.remove();
420
- }
421
- }
422
- // Do it again, in case we have other `@apply` rules
423
- processApply(root, context, localCache);
424
- }
425
- }
426
- function expandApplyAtRules(context) {
427
- return (root)=>{
428
- // Build a cache of the user's CSS so we can use it to resolve classes used by @apply
429
- let localCache = lazyCache(()=>buildLocalApplyCache(root, context)
430
- );
431
- processApply(root, context, localCache);
432
- };
433
- }