tailwindcss 0.0.0-insiders.f4635e0 → 0.0.0-insiders.f4a2ccd

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 (238) 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 -304
  5. package/defaultConfig.d.ts +3 -0
  6. package/defaultConfig.js +2 -4
  7. package/defaultTheme.d.ts +4 -0
  8. package/defaultTheme.js +2 -4
  9. package/lib/cli/build/deps.js +54 -0
  10. package/lib/cli/build/index.js +52 -0
  11. package/lib/cli/build/plugin.js +376 -0
  12. package/lib/cli/build/utils.js +78 -0
  13. package/lib/cli/build/watching.js +180 -0
  14. package/lib/cli/help/index.js +71 -0
  15. package/lib/cli/index.js +230 -0
  16. package/lib/cli/init/index.js +61 -0
  17. package/lib/cli-peer-dependencies.js +22 -14
  18. package/lib/cli.js +4 -762
  19. package/lib/corePluginList.js +182 -5
  20. package/lib/corePlugins.js +4109 -2952
  21. package/lib/css/preflight.css +24 -9
  22. package/lib/featureFlags.js +68 -50
  23. package/lib/index.js +5 -30
  24. package/lib/lib/cacheInvalidation.js +90 -0
  25. package/lib/lib/collapseAdjacentRules.js +52 -36
  26. package/lib/lib/collapseDuplicateDeclarations.js +83 -0
  27. package/lib/lib/content.js +177 -0
  28. package/lib/lib/defaultExtractor.js +241 -0
  29. package/lib/lib/detectNesting.js +39 -17
  30. package/lib/lib/evaluateTailwindFunctions.js +203 -161
  31. package/lib/lib/expandApplyAtRules.js +503 -221
  32. package/lib/lib/expandTailwindAtRules.js +255 -243
  33. package/lib/lib/findAtConfigPath.js +44 -0
  34. package/lib/lib/generateRules.js +831 -317
  35. package/lib/lib/getModuleDependencies.js +93 -49
  36. package/lib/lib/load-config.js +36 -0
  37. package/lib/lib/normalizeTailwindDirectives.js +79 -60
  38. package/lib/lib/offsets.js +304 -0
  39. package/lib/lib/partitionApplyAtRules.js +56 -0
  40. package/lib/lib/regex.js +60 -0
  41. package/lib/lib/remap-bitfield.js +87 -0
  42. package/lib/lib/resolveDefaultsAtRules.js +150 -94
  43. package/lib/lib/setupContextUtils.js +1197 -685
  44. package/lib/lib/setupTrackingContext.js +150 -177
  45. package/lib/lib/sharedState.js +70 -21
  46. package/lib/lib/substituteScreenAtRules.js +26 -28
  47. package/lib/oxide/cli/build/deps.js +81 -0
  48. package/lib/oxide/cli/build/index.js +51 -0
  49. package/lib/oxide/cli/build/plugin.js +373 -0
  50. package/lib/oxide/cli/build/utils.js +77 -0
  51. package/lib/oxide/cli/build/watching.js +177 -0
  52. package/lib/oxide/cli/help/index.js +70 -0
  53. package/lib/oxide/cli/index.js +214 -0
  54. package/lib/oxide/cli/init/index.js +50 -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 +19 -0
  60. package/lib/postcss-plugins/nesting/plugin.js +87 -0
  61. package/lib/processTailwindFeatures.js +58 -56
  62. package/lib/public/colors.js +353 -0
  63. package/lib/public/create-plugin.js +15 -0
  64. package/lib/public/default-config.js +16 -0
  65. package/lib/public/default-theme.js +16 -0
  66. package/lib/public/load-config.js +10 -0
  67. package/lib/public/resolve-config.js +22 -0
  68. package/lib/util/applyImportantSelector.js +22 -0
  69. package/lib/util/bigSign.js +7 -6
  70. package/lib/util/buildMediaQuery.js +21 -32
  71. package/lib/util/cloneDeep.js +16 -14
  72. package/lib/util/cloneNodes.js +29 -15
  73. package/lib/util/color.js +104 -66
  74. package/lib/util/configurePlugins.js +17 -15
  75. package/lib/util/createPlugin.js +23 -26
  76. package/lib/util/createUtilityPlugin.js +46 -46
  77. package/lib/util/dataTypes.js +266 -0
  78. package/lib/util/defaults.js +20 -15
  79. package/lib/util/escapeClassName.js +18 -17
  80. package/lib/util/escapeCommas.js +7 -6
  81. package/lib/util/flattenColorPalette.js +13 -12
  82. package/lib/util/formatVariantSelector.js +341 -0
  83. package/lib/util/getAllConfigs.js +44 -18
  84. package/lib/util/hashConfig.js +15 -12
  85. package/lib/util/isKeyframeRule.js +7 -6
  86. package/lib/util/isPlainObject.js +11 -11
  87. package/lib/util/isSyntacticallyValidPropertyValue.js +72 -0
  88. package/lib/util/log.js +52 -33
  89. package/lib/util/nameClass.js +35 -29
  90. package/lib/util/negateValue.js +31 -17
  91. package/lib/util/normalizeConfig.js +294 -0
  92. package/lib/util/normalizeScreens.js +170 -0
  93. package/lib/util/parseAnimationValue.js +85 -54
  94. package/lib/util/parseBoxShadowValue.js +84 -0
  95. package/lib/util/parseDependency.js +41 -70
  96. package/lib/util/parseGlob.js +34 -0
  97. package/lib/util/parseObjectStyles.js +30 -24
  98. package/lib/util/pluginUtils.js +234 -288
  99. package/lib/util/prefixSelector.js +33 -19
  100. package/lib/util/removeAlphaVariables.js +29 -0
  101. package/lib/util/resolveConfig.js +221 -256
  102. package/lib/util/resolveConfigPath.js +55 -48
  103. package/lib/util/responsive.js +18 -14
  104. package/lib/util/splitAtTopLevelOnly.js +49 -0
  105. package/lib/util/tap.js +8 -7
  106. package/lib/util/toColorValue.js +7 -6
  107. package/lib/util/toPath.js +27 -8
  108. package/lib/util/transformThemeValue.js +67 -28
  109. package/lib/util/validateConfig.js +24 -0
  110. package/lib/util/validateFormalSyntax.js +24 -0
  111. package/lib/util/withAlphaVariable.js +67 -57
  112. package/loadConfig.d.ts +4 -0
  113. package/loadConfig.js +2 -0
  114. package/nesting/index.js +2 -12
  115. package/package.json +69 -66
  116. package/peers/index.js +76328 -84169
  117. package/plugin.d.ts +11 -0
  118. package/plugin.js +1 -2
  119. package/resolveConfig.d.ts +12 -0
  120. package/resolveConfig.js +2 -7
  121. package/scripts/create-plugin-list.js +2 -2
  122. package/scripts/generate-types.js +105 -0
  123. package/scripts/release-channel.js +18 -0
  124. package/scripts/release-notes.js +21 -0
  125. package/scripts/swap-engines.js +40 -0
  126. package/scripts/type-utils.js +27 -0
  127. package/src/cli/build/deps.js +56 -0
  128. package/src/cli/build/index.js +49 -0
  129. package/src/cli/build/plugin.js +444 -0
  130. package/src/cli/build/utils.js +76 -0
  131. package/src/cli/build/watching.js +229 -0
  132. package/src/cli/help/index.js +70 -0
  133. package/src/cli/index.js +216 -0
  134. package/src/cli/init/index.js +79 -0
  135. package/src/cli-peer-dependencies.js +7 -1
  136. package/src/cli.js +4 -756
  137. package/src/corePluginList.js +1 -1
  138. package/src/corePlugins.js +2526 -1956
  139. package/src/css/preflight.css +24 -9
  140. package/src/featureFlags.js +33 -10
  141. package/src/index.js +4 -33
  142. package/src/lib/cacheInvalidation.js +52 -0
  143. package/src/lib/collapseAdjacentRules.js +21 -2
  144. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  145. package/src/lib/content.js +208 -0
  146. package/src/lib/defaultExtractor.js +217 -0
  147. package/src/lib/detectNesting.js +30 -3
  148. package/src/lib/evaluateTailwindFunctions.js +84 -10
  149. package/src/lib/expandApplyAtRules.js +509 -153
  150. package/src/lib/expandTailwindAtRules.js +125 -104
  151. package/src/lib/findAtConfigPath.js +48 -0
  152. package/src/lib/generateRules.js +678 -70
  153. package/src/lib/getModuleDependencies.js +70 -30
  154. package/src/lib/load-config.ts +27 -0
  155. package/src/lib/normalizeTailwindDirectives.js +10 -3
  156. package/src/lib/offsets.js +373 -0
  157. package/src/lib/partitionApplyAtRules.js +52 -0
  158. package/src/lib/regex.js +74 -0
  159. package/src/lib/remap-bitfield.js +82 -0
  160. package/src/lib/resolveDefaultsAtRules.js +105 -47
  161. package/src/lib/setupContextUtils.js +848 -247
  162. package/src/lib/setupTrackingContext.js +53 -64
  163. package/src/lib/sharedState.js +60 -6
  164. package/src/lib/substituteScreenAtRules.js +6 -3
  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 +18 -3
  180. package/src/public/colors.js +322 -0
  181. package/src/public/create-plugin.js +2 -0
  182. package/src/public/default-config.js +4 -0
  183. package/src/public/default-theme.js +4 -0
  184. package/src/public/load-config.js +2 -0
  185. package/src/public/resolve-config.js +7 -0
  186. package/src/util/applyImportantSelector.js +19 -0
  187. package/src/util/buildMediaQuery.js +14 -16
  188. package/src/util/cloneNodes.js +19 -2
  189. package/src/util/color.js +43 -11
  190. package/src/util/createUtilityPlugin.js +2 -11
  191. package/src/util/dataTypes.js +281 -0
  192. package/src/util/defaults.js +6 -0
  193. package/src/util/formatVariantSelector.js +412 -0
  194. package/src/util/getAllConfigs.js +21 -2
  195. package/src/util/isSyntacticallyValidPropertyValue.js +61 -0
  196. package/src/util/log.js +23 -22
  197. package/src/util/nameClass.js +6 -2
  198. package/src/util/negateValue.js +15 -5
  199. package/src/util/normalizeConfig.js +318 -0
  200. package/src/util/normalizeScreens.js +140 -0
  201. package/src/util/parseAnimationValue.js +7 -1
  202. package/src/util/parseBoxShadowValue.js +72 -0
  203. package/src/util/parseDependency.js +37 -38
  204. package/src/util/parseGlob.js +24 -0
  205. package/src/util/pluginUtils.js +219 -219
  206. package/src/util/prefixSelector.js +30 -13
  207. package/src/util/removeAlphaVariables.js +24 -0
  208. package/src/util/resolveConfig.js +86 -91
  209. package/src/util/resolveConfigPath.js +12 -1
  210. package/src/util/splitAtTopLevelOnly.js +52 -0
  211. package/src/util/toPath.js +23 -1
  212. package/src/util/transformThemeValue.js +33 -8
  213. package/src/util/validateConfig.js +13 -0
  214. package/src/util/validateFormalSyntax.js +34 -0
  215. package/src/util/withAlphaVariable.js +14 -9
  216. package/stubs/.gitignore +1 -0
  217. package/stubs/.prettierrc.json +6 -0
  218. package/stubs/{defaultConfig.stub.js → config.full.js} +332 -249
  219. package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -1
  220. package/stubs/postcss.config.js +6 -0
  221. package/stubs/tailwind.config.cjs +2 -0
  222. package/stubs/tailwind.config.js +2 -0
  223. package/stubs/tailwind.config.ts +3 -0
  224. package/types/config.d.ts +373 -0
  225. package/types/generated/.gitkeep +0 -0
  226. package/types/generated/colors.d.ts +298 -0
  227. package/types/generated/corePluginList.d.ts +1 -0
  228. package/types/generated/default-theme.d.ts +347 -0
  229. package/types/index.d.ts +7 -0
  230. package/CHANGELOG.md +0 -1742
  231. package/lib/constants.js +0 -37
  232. package/lib/lib/setupWatchingContext.js +0 -331
  233. package/nesting/plugin.js +0 -41
  234. package/scripts/install-integrations.js +0 -27
  235. package/scripts/rebuildFixtures.js +0 -68
  236. package/src/constants.js +0 -17
  237. package/src/lib/setupWatchingContext.js +0 -307
  238. /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
@@ -1,53 +1,97 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.default = getModuleDependencies;
7
-
8
- var _fs = _interopRequireDefault(require("fs"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _resolve = _interopRequireDefault(require("resolve"));
13
-
14
- var _detective = _interopRequireDefault(require("detective"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function createModule(file) {
19
- const source = _fs.default.readFileSync(file, 'utf-8');
20
-
21
- const requires = (0, _detective.default)(source);
22
- return {
23
- file,
24
- requires
25
- };
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>getModuleDependencies
8
+ });
9
+ const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
10
+ const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
11
+ function _interopRequireDefault(obj) {
12
+ return obj && obj.__esModule ? obj : {
13
+ default: obj
14
+ };
15
+ }
16
+ let jsExtensions = [
17
+ ".js",
18
+ ".cjs",
19
+ ".mjs"
20
+ ];
21
+ // Given the current file `a.ts`, we want to make sure that when importing `b` that we resolve
22
+ // `b.ts` before `b.js`
23
+ //
24
+ // E.g.:
25
+ //
26
+ // a.ts
27
+ // b // .ts
28
+ // c // .ts
29
+ // a.js
30
+ // b // .js or .ts
31
+ let jsResolutionOrder = [
32
+ "",
33
+ ".js",
34
+ ".cjs",
35
+ ".mjs",
36
+ ".ts",
37
+ ".cts",
38
+ ".mts",
39
+ ".jsx",
40
+ ".tsx"
41
+ ];
42
+ let tsResolutionOrder = [
43
+ "",
44
+ ".ts",
45
+ ".cts",
46
+ ".mts",
47
+ ".tsx",
48
+ ".js",
49
+ ".cjs",
50
+ ".mjs",
51
+ ".jsx"
52
+ ];
53
+ function resolveWithExtension(file, extensions) {
54
+ // Try to find `./a.ts`, `./a.ts`, ... from `./a`
55
+ for (let ext of extensions){
56
+ let full = `${file}${ext}`;
57
+ if (_fs.default.existsSync(full) && _fs.default.statSync(full).isFile()) {
58
+ return full;
59
+ }
60
+ }
61
+ // Try to find `./a/index.js` from `./a`
62
+ for (let ext1 of extensions){
63
+ let full1 = `${file}/index${ext1}`;
64
+ if (_fs.default.existsSync(full1)) {
65
+ return full1;
66
+ }
67
+ }
68
+ return null;
69
+ }
70
+ function* _getModuleDependencies(filename, base, seen, ext = _path.default.extname(filename)) {
71
+ // Try to find the file
72
+ let absoluteFile = resolveWithExtension(_path.default.resolve(base, filename), jsExtensions.includes(ext) ? jsResolutionOrder : tsResolutionOrder);
73
+ if (absoluteFile === null) return; // File doesn't exist
74
+ // Prevent infinite loops when there are circular dependencies
75
+ if (seen.has(absoluteFile)) return; // Already seen
76
+ seen.add(absoluteFile);
77
+ // Mark the file as a dependency
78
+ yield absoluteFile;
79
+ // Resolve new base for new imports/requires
80
+ base = _path.default.dirname(absoluteFile);
81
+ ext = _path.default.extname(absoluteFile);
82
+ let contents = _fs.default.readFileSync(absoluteFile, "utf-8");
83
+ // Find imports/requires
84
+ for (let match of [
85
+ ...contents.matchAll(/import[\s\S]*?['"](.{3,}?)['"]/gi),
86
+ ...contents.matchAll(/import[\s\S]*from[\s\S]*?['"](.{3,}?)['"]/gi),
87
+ ...contents.matchAll(/require\(['"`](.+)['"`]\)/gi)
88
+ ]){
89
+ // Bail out if it's not a relative file
90
+ if (!match[1].startsWith(".")) continue;
91
+ yield* _getModuleDependencies(match[1], base, seen, ext);
92
+ }
93
+ }
94
+ function getModuleDependencies(absoluteFilePath) {
95
+ if (absoluteFilePath === null) return new Set();
96
+ return new Set(_getModuleDependencies(absoluteFilePath, _path.default.dirname(absoluteFilePath), new Set()));
26
97
  }
27
-
28
- function getModuleDependencies(entryFile) {
29
- const rootModule = createModule(entryFile);
30
- const modules = [rootModule]; // Iterate over the modules, even when new
31
- // ones are being added
32
-
33
- for (const mdl of modules) {
34
- mdl.requires.filter(dep => {
35
- // Only track local modules, not node_modules
36
- return dep.startsWith('./') || dep.startsWith('../');
37
- }).forEach(dep => {
38
- try {
39
- const basedir = _path.default.dirname(mdl.file);
40
-
41
- const depPath = _resolve.default.sync(dep, {
42
- basedir
43
- });
44
-
45
- const depModule = createModule(depPath);
46
- modules.push(depModule);
47
- } catch (_err) {// eslint-disable-next-line no-empty
48
- }
49
- });
50
- }
51
-
52
- return modules;
53
- }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "loadConfig", {
6
+ enumerable: true,
7
+ get: ()=>loadConfig
8
+ });
9
+ const _jiti = /*#__PURE__*/ _interopRequireDefault(require("jiti"));
10
+ const _sucrase = require("sucrase");
11
+ function _interopRequireDefault(obj) {
12
+ return obj && obj.__esModule ? obj : {
13
+ default: obj
14
+ };
15
+ }
16
+ let jiti = null;
17
+ function lazyJiti() {
18
+ return jiti !== null && jiti !== void 0 ? jiti : jiti = (0, _jiti.default)(__filename, {
19
+ interopDefault: true,
20
+ transform: (opts)=>{
21
+ return (0, _sucrase.transform)(opts.source, {
22
+ transforms: [
23
+ "typescript",
24
+ "imports"
25
+ ]
26
+ });
27
+ }
28
+ });
29
+ }
30
+ function loadConfig(path) {
31
+ try {
32
+ return path ? require(path) : {};
33
+ } catch {
34
+ return lazyJiti()(path);
35
+ }
36
+ }
@@ -1,68 +1,87 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.default = normalizeTailwindDirectives;
7
-
8
- var _log = _interopRequireDefault(require("../util/log"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>normalizeTailwindDirectives
8
+ });
9
+ const _log = /*#__PURE__*/ _interopRequireDefault(require("../util/log"));
10
+ function _interopRequireDefault(obj) {
11
+ return obj && obj.__esModule ? obj : {
12
+ default: obj
13
+ };
14
+ }
12
15
  function normalizeTailwindDirectives(root) {
13
- let tailwindDirectives = new Set();
14
- let layerDirectives = new Set();
15
- root.walkAtRules(atRule => {
16
- if (atRule.name === 'import') {
17
- if (atRule.params === '"tailwindcss/base"' || atRule.params === "'tailwindcss/base'") {
18
- atRule.name = 'tailwind';
19
- atRule.params = 'base';
20
- } else if (atRule.params === '"tailwindcss/components"' || atRule.params === "'tailwindcss/components'") {
21
- atRule.name = 'tailwind';
22
- atRule.params = 'components';
23
- } else if (atRule.params === '"tailwindcss/utilities"' || atRule.params === "'tailwindcss/utilities'") {
24
- atRule.name = 'tailwind';
25
- atRule.params = 'utilities';
26
- } else if (atRule.params === '"tailwindcss/screens"' || atRule.params === "'tailwindcss/screens'" || atRule.params === '"tailwindcss/variants"' || atRule.params === "'tailwindcss/variants'") {
27
- atRule.name = 'tailwind';
28
- atRule.params = 'variants';
29
- }
30
- }
31
-
32
- if (atRule.name === 'tailwind') {
33
- if (atRule.params === 'screens') {
34
- atRule.params = 'variants';
35
- }
36
-
37
- tailwindDirectives.add(atRule.params);
38
- }
39
-
40
- if (['layer', 'responsive', 'variants'].includes(atRule.name)) {
41
- if (['responsive', 'variants'].includes(atRule.name)) {
42
- _log.default.warn([`'@${atRule.name}' is deprecated, use '@layer utilities' or '@layer components' instead.`]);
43
- }
44
-
45
- layerDirectives.add(atRule);
46
- }
47
- });
48
-
49
- if (!tailwindDirectives.has('base') || !tailwindDirectives.has('components') || !tailwindDirectives.has('utilities')) {
50
- for (let rule of layerDirectives) {
51
- if (rule.name === 'layer' && ['base', 'components', 'utilities'].includes(rule.params)) {
52
- if (!tailwindDirectives.has(rule.params)) {
53
- throw rule.error(`\`@layer ${rule.params}\` is used but no matching \`@tailwind ${rule.params}\` directive is present.`);
16
+ let tailwindDirectives = new Set();
17
+ let layerDirectives = new Set();
18
+ let applyDirectives = new Set();
19
+ root.walkAtRules((atRule)=>{
20
+ if (atRule.name === "apply") {
21
+ applyDirectives.add(atRule);
22
+ }
23
+ if (atRule.name === "import") {
24
+ if (atRule.params === '"tailwindcss/base"' || atRule.params === "'tailwindcss/base'") {
25
+ atRule.name = "tailwind";
26
+ atRule.params = "base";
27
+ } else if (atRule.params === '"tailwindcss/components"' || atRule.params === "'tailwindcss/components'") {
28
+ atRule.name = "tailwind";
29
+ atRule.params = "components";
30
+ } else if (atRule.params === '"tailwindcss/utilities"' || atRule.params === "'tailwindcss/utilities'") {
31
+ atRule.name = "tailwind";
32
+ atRule.params = "utilities";
33
+ } else if (atRule.params === '"tailwindcss/screens"' || atRule.params === "'tailwindcss/screens'" || atRule.params === '"tailwindcss/variants"' || atRule.params === "'tailwindcss/variants'") {
34
+ atRule.name = "tailwind";
35
+ atRule.params = "variants";
36
+ }
37
+ }
38
+ if (atRule.name === "tailwind") {
39
+ if (atRule.params === "screens") {
40
+ atRule.params = "variants";
41
+ }
42
+ tailwindDirectives.add(atRule.params);
54
43
  }
55
- } else if (rule.name === 'responsive') {
56
- if (!tailwindDirectives.has('utilities')) {
57
- throw rule.error('`@responsive` is used but `@tailwind utilities` is missing.');
44
+ if ([
45
+ "layer",
46
+ "responsive",
47
+ "variants"
48
+ ].includes(atRule.name)) {
49
+ if ([
50
+ "responsive",
51
+ "variants"
52
+ ].includes(atRule.name)) {
53
+ _log.default.warn(`${atRule.name}-at-rule-deprecated`, [
54
+ `The \`@${atRule.name}\` directive has been deprecated in Tailwind CSS v3.0.`,
55
+ `Use \`@layer utilities\` or \`@layer components\` instead.`,
56
+ "https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer"
57
+ ]);
58
+ }
59
+ layerDirectives.add(atRule);
58
60
  }
59
- } else if (rule.name === 'variants') {
60
- if (!tailwindDirectives.has('utilities')) {
61
- throw rule.error('`@variants` is used but `@tailwind utilities` is missing.');
61
+ });
62
+ if (!tailwindDirectives.has("base") || !tailwindDirectives.has("components") || !tailwindDirectives.has("utilities")) {
63
+ for (let rule of layerDirectives){
64
+ if (rule.name === "layer" && [
65
+ "base",
66
+ "components",
67
+ "utilities"
68
+ ].includes(rule.params)) {
69
+ if (!tailwindDirectives.has(rule.params)) {
70
+ throw rule.error(`\`@layer ${rule.params}\` is used but no matching \`@tailwind ${rule.params}\` directive is present.`);
71
+ }
72
+ } else if (rule.name === "responsive") {
73
+ if (!tailwindDirectives.has("utilities")) {
74
+ throw rule.error("`@responsive` is used but `@tailwind utilities` is missing.");
75
+ }
76
+ } else if (rule.name === "variants") {
77
+ if (!tailwindDirectives.has("utilities")) {
78
+ throw rule.error("`@variants` is used but `@tailwind utilities` is missing.");
79
+ }
80
+ }
62
81
  }
63
- }
64
82
  }
65
- }
66
-
67
- return tailwindDirectives;
68
- }
83
+ return {
84
+ tailwindDirectives,
85
+ applyDirectives
86
+ };
87
+ }
@@ -0,0 +1,304 @@
1
+ // @ts-check
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Offsets", {
7
+ enumerable: true,
8
+ get: ()=>Offsets
9
+ });
10
+ const _bigSign = /*#__PURE__*/ _interopRequireDefault(require("../util/bigSign"));
11
+ const _remapBitfieldJs = require("./remap-bitfield.js");
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ class Offsets {
18
+ constructor(){
19
+ /**
20
+ * Offsets for the next rule in a given layer
21
+ *
22
+ * @type {Record<Layer, bigint>}
23
+ */ this.offsets = {
24
+ defaults: 0n,
25
+ base: 0n,
26
+ components: 0n,
27
+ utilities: 0n,
28
+ variants: 0n,
29
+ user: 0n
30
+ };
31
+ /**
32
+ * Positions for a given layer
33
+ *
34
+ * @type {Record<Layer, bigint>}
35
+ */ this.layerPositions = {
36
+ defaults: 0n,
37
+ base: 1n,
38
+ components: 2n,
39
+ utilities: 3n,
40
+ // There isn't technically a "user" layer, but we need to give it a position
41
+ // Because it's used for ordering user-css from @apply
42
+ user: 4n,
43
+ variants: 5n
44
+ };
45
+ /**
46
+ * The total number of functions currently registered across all variants (including arbitrary variants)
47
+ *
48
+ * @type {bigint}
49
+ */ this.reservedVariantBits = 0n;
50
+ /**
51
+ * Positions for a given variant
52
+ *
53
+ * @type {Map<string, bigint>}
54
+ */ this.variantOffsets = new Map();
55
+ }
56
+ /**
57
+ * @param {Layer} layer
58
+ * @returns {RuleOffset}
59
+ */ create(layer) {
60
+ return {
61
+ layer,
62
+ parentLayer: layer,
63
+ arbitrary: 0n,
64
+ variants: 0n,
65
+ parallelIndex: 0n,
66
+ index: this.offsets[layer]++,
67
+ options: []
68
+ };
69
+ }
70
+ /**
71
+ * @returns {RuleOffset}
72
+ */ arbitraryProperty() {
73
+ return {
74
+ ...this.create("utilities"),
75
+ arbitrary: 1n
76
+ };
77
+ }
78
+ /**
79
+ * Get the offset for a variant
80
+ *
81
+ * @param {string} variant
82
+ * @param {number} index
83
+ * @returns {RuleOffset}
84
+ */ forVariant(variant, index = 0) {
85
+ let offset = this.variantOffsets.get(variant);
86
+ if (offset === undefined) {
87
+ throw new Error(`Cannot find offset for unknown variant ${variant}`);
88
+ }
89
+ return {
90
+ ...this.create("variants"),
91
+ variants: offset << BigInt(index)
92
+ };
93
+ }
94
+ /**
95
+ * @param {RuleOffset} rule
96
+ * @param {RuleOffset} variant
97
+ * @param {VariantOption} options
98
+ * @returns {RuleOffset}
99
+ */ applyVariantOffset(rule, variant, options) {
100
+ options.variant = variant.variants;
101
+ return {
102
+ ...rule,
103
+ layer: "variants",
104
+ parentLayer: rule.layer === "variants" ? rule.parentLayer : rule.layer,
105
+ variants: rule.variants | variant.variants,
106
+ options: options.sort ? [].concat(options, rule.options) : rule.options,
107
+ // TODO: Technically this is wrong. We should be handling parallel index on a per variant basis.
108
+ // We'll take the max of all the parallel indexes for now.
109
+ // @ts-ignore
110
+ parallelIndex: max([
111
+ rule.parallelIndex,
112
+ variant.parallelIndex
113
+ ])
114
+ };
115
+ }
116
+ /**
117
+ * @param {RuleOffset} offset
118
+ * @param {number} parallelIndex
119
+ * @returns {RuleOffset}
120
+ */ applyParallelOffset(offset, parallelIndex) {
121
+ return {
122
+ ...offset,
123
+ parallelIndex: BigInt(parallelIndex)
124
+ };
125
+ }
126
+ /**
127
+ * Each variant gets 1 bit per function / rule registered.
128
+ * This is because multiple variants can be applied to a single rule and we need to know which ones are present and which ones are not.
129
+ * Additionally, every unique group of variants is grouped together in the stylesheet.
130
+ *
131
+ * This grouping is order-independent. For instance, we do not differentiate between `hover:focus` and `focus:hover`.
132
+ *
133
+ * @param {string[]} variants
134
+ * @param {(name: string) => number} getLength
135
+ */ recordVariants(variants, getLength) {
136
+ for (let variant of variants){
137
+ this.recordVariant(variant, getLength(variant));
138
+ }
139
+ }
140
+ /**
141
+ * The same as `recordVariants` but for a single arbitrary variant at runtime.
142
+ * @param {string} variant
143
+ * @param {number} fnCount
144
+ *
145
+ * @returns {RuleOffset} The highest offset for this variant
146
+ */ recordVariant(variant, fnCount = 1) {
147
+ this.variantOffsets.set(variant, 1n << this.reservedVariantBits);
148
+ // Ensure space is reserved for each "function" in the parallel variant
149
+ // by offsetting the next variant by the number of parallel variants
150
+ // in the one we just added.
151
+ // Single functions that return parallel variants are NOT handled separately here
152
+ // They're offset by 1 (or the number of functions) as usual
153
+ // And each rule returned is tracked separately since the functions are evaluated lazily.
154
+ // @see `RuleOffset.parallelIndex`
155
+ this.reservedVariantBits += BigInt(fnCount);
156
+ return {
157
+ ...this.create("variants"),
158
+ variants: this.variantOffsets.get(variant)
159
+ };
160
+ }
161
+ /**
162
+ * @param {RuleOffset} a
163
+ * @param {RuleOffset} b
164
+ * @returns {bigint}
165
+ */ compare(a, b) {
166
+ // Sort layers together
167
+ if (a.layer !== b.layer) {
168
+ return this.layerPositions[a.layer] - this.layerPositions[b.layer];
169
+ }
170
+ // When sorting the `variants` layer, we need to sort based on the parent layer as well within
171
+ // this variants layer.
172
+ if (a.parentLayer !== b.parentLayer) {
173
+ return this.layerPositions[a.parentLayer] - this.layerPositions[b.parentLayer];
174
+ }
175
+ // Sort based on the sorting function
176
+ for (let aOptions of a.options){
177
+ for (let bOptions of b.options){
178
+ if (aOptions.id !== bOptions.id) continue;
179
+ if (!aOptions.sort || !bOptions.sort) continue;
180
+ var _max;
181
+ let maxFnVariant = (_max = max([
182
+ aOptions.variant,
183
+ bOptions.variant
184
+ ])) !== null && _max !== void 0 ? _max : 0n;
185
+ // Create a mask of 0s from bits 1..N where N represents the mask of the Nth bit
186
+ let mask = ~(maxFnVariant | maxFnVariant - 1n);
187
+ let aVariantsAfterFn = a.variants & mask;
188
+ let bVariantsAfterFn = b.variants & mask;
189
+ // If the variants the same, we _can_ sort them
190
+ if (aVariantsAfterFn !== bVariantsAfterFn) {
191
+ continue;
192
+ }
193
+ let result = aOptions.sort({
194
+ value: aOptions.value,
195
+ modifier: aOptions.modifier
196
+ }, {
197
+ value: bOptions.value,
198
+ modifier: bOptions.modifier
199
+ });
200
+ if (result !== 0) return result;
201
+ }
202
+ }
203
+ // Sort variants in the order they were registered
204
+ if (a.variants !== b.variants) {
205
+ return a.variants - b.variants;
206
+ }
207
+ // Make sure each rule returned by a parallel variant is sorted in ascending order
208
+ if (a.parallelIndex !== b.parallelIndex) {
209
+ return a.parallelIndex - b.parallelIndex;
210
+ }
211
+ // Always sort arbitrary properties after other utilities
212
+ if (a.arbitrary !== b.arbitrary) {
213
+ return a.arbitrary - b.arbitrary;
214
+ }
215
+ // Sort utilities, components, etc… in the order they were registered
216
+ return a.index - b.index;
217
+ }
218
+ /**
219
+ * Arbitrary variants are recorded in the order they're encountered.
220
+ * This means that the order is not stable between environments and sets of content files.
221
+ *
222
+ * In order to make the order stable, we need to remap the arbitrary variant offsets to
223
+ * be in alphabetical order starting from the offset of the first arbitrary variant.
224
+ */ recalculateVariantOffsets() {
225
+ // Sort the variants by their name
226
+ let variants = Array.from(this.variantOffsets.entries()).filter(([v])=>v.startsWith("[")).sort(([a], [z])=>fastCompare(a, z));
227
+ // Sort the list of offsets
228
+ // This is not necessarily a discrete range of numbers which is why
229
+ // we're using sort instead of creating a range from min/max
230
+ let newOffsets = variants.map(([, offset])=>offset).sort((a, z)=>(0, _bigSign.default)(a - z));
231
+ // Create a map from the old offsets to the new offsets in the new sort order
232
+ /** @type {[bigint, bigint][]} */ let mapping = variants.map(([, oldOffset], i)=>[
233
+ oldOffset,
234
+ newOffsets[i]
235
+ ]);
236
+ // Remove any variants that will not move letting us skip
237
+ // remapping if everything happens to be in order
238
+ return mapping.filter(([a, z])=>a !== z);
239
+ }
240
+ /**
241
+ * @template T
242
+ * @param {[RuleOffset, T][]} list
243
+ * @returns {[RuleOffset, T][]}
244
+ */ remapArbitraryVariantOffsets(list) {
245
+ let mapping = this.recalculateVariantOffsets();
246
+ // No arbitrary variants? Nothing to do.
247
+ // Everyhing already in order? Nothing to do.
248
+ if (mapping.length === 0) {
249
+ return list;
250
+ }
251
+ // Remap every variant offset in the list
252
+ return list.map((item)=>{
253
+ let [offset, rule] = item;
254
+ offset = {
255
+ ...offset,
256
+ variants: (0, _remapBitfieldJs.remapBitfield)(offset.variants, mapping)
257
+ };
258
+ return [
259
+ offset,
260
+ rule
261
+ ];
262
+ });
263
+ }
264
+ /**
265
+ * @template T
266
+ * @param {[RuleOffset, T][]} list
267
+ * @returns {[RuleOffset, T][]}
268
+ */ sort(list) {
269
+ list = this.remapArbitraryVariantOffsets(list);
270
+ return list.sort(([a], [b])=>(0, _bigSign.default)(this.compare(a, b)));
271
+ }
272
+ }
273
+ /**
274
+ *
275
+ * @param {bigint[]} nums
276
+ * @returns {bigint|null}
277
+ */ function max(nums) {
278
+ let max = null;
279
+ for (const num of nums){
280
+ max = max !== null && max !== void 0 ? max : num;
281
+ max = max > num ? max : num;
282
+ }
283
+ return max;
284
+ }
285
+ /**
286
+ * A fast ASCII order string comparison function.
287
+ *
288
+ * Using `.sort()` without a custom compare function is faster
289
+ * But you can only use that if you're sorting an array of
290
+ * only strings. If you're sorting strings inside objects
291
+ * or arrays, you need must use a custom compare function.
292
+ *
293
+ * @param {string} a
294
+ * @param {string} b
295
+ */ function fastCompare(a, b) {
296
+ let aLen = a.length;
297
+ let bLen = b.length;
298
+ let minLen = aLen < bLen ? aLen : bLen;
299
+ for(let i = 0; i < minLen; i++){
300
+ let cmp = a.charCodeAt(i) - b.charCodeAt(i);
301
+ if (cmp !== 0) return cmp;
302
+ }
303
+ return aLen - bLen;
304
+ }