tailwindcss 0.0.0-insiders.8259dfd → 0.0.0-insiders.825cd83

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 (235) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +17 -10
  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 +373 -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 +1 -700
  19. package/lib/corePluginList.js +25 -5
  20. package/lib/corePlugins.js +2643 -1894
  21. package/lib/css/preflight.css +50 -18
  22. package/lib/featureFlags.js +45 -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 +85 -0
  27. package/lib/lib/content.js +247 -0
  28. package/lib/lib/defaultExtractor.js +273 -0
  29. package/lib/lib/evaluateTailwindFunctions.js +117 -46
  30. package/lib/lib/expandApplyAtRules.js +484 -159
  31. package/lib/lib/expandTailwindAtRules.js +165 -129
  32. package/lib/lib/findAtConfigPath.js +46 -0
  33. package/lib/lib/generateRules.js +643 -139
  34. package/lib/lib/getModuleDependencies.js +88 -37
  35. package/lib/lib/load-config.js +61 -0
  36. package/lib/lib/normalizeTailwindDirectives.js +46 -33
  37. package/lib/lib/offsets.js +355 -0
  38. package/lib/lib/partitionApplyAtRules.js +58 -0
  39. package/lib/lib/regex.js +74 -0
  40. package/lib/lib/remap-bitfield.js +89 -0
  41. package/lib/lib/resolveDefaultsAtRules.js +96 -56
  42. package/lib/lib/setupContextUtils.js +815 -326
  43. package/lib/lib/setupTrackingContext.js +71 -75
  44. package/lib/lib/sharedState.js +70 -10
  45. package/lib/lib/substituteScreenAtRules.js +16 -9
  46. package/lib/plugin.js +48 -0
  47. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  48. package/lib/postcss-plugins/nesting/index.js +21 -0
  49. package/lib/postcss-plugins/nesting/plugin.js +89 -0
  50. package/lib/processTailwindFeatures.js +38 -25
  51. package/lib/public/colors.js +272 -246
  52. package/lib/public/create-plugin.js +9 -5
  53. package/lib/public/default-config.js +10 -6
  54. package/lib/public/default-theme.js +10 -6
  55. package/lib/public/load-config.js +12 -0
  56. package/lib/public/resolve-config.js +11 -6
  57. package/lib/util/applyImportantSelector.js +38 -0
  58. package/lib/util/bigSign.js +6 -1
  59. package/lib/util/buildMediaQuery.js +20 -24
  60. package/lib/util/cloneDeep.js +9 -6
  61. package/lib/util/cloneNodes.js +44 -4
  62. package/lib/util/color.js +70 -38
  63. package/lib/util/colorNames.js +752 -0
  64. package/lib/util/configurePlugins.js +7 -2
  65. package/lib/util/createPlugin.js +8 -6
  66. package/lib/util/createUtilityPlugin.js +14 -14
  67. package/lib/util/dataTypes.js +343 -101
  68. package/lib/util/defaults.js +14 -3
  69. package/lib/util/escapeClassName.js +13 -8
  70. package/lib/util/escapeCommas.js +7 -2
  71. package/lib/util/flattenColorPalette.js +11 -12
  72. package/lib/util/formatVariantSelector.js +270 -0
  73. package/lib/util/getAllConfigs.js +33 -12
  74. package/lib/util/hashConfig.js +9 -4
  75. package/lib/util/isKeyframeRule.js +7 -2
  76. package/lib/util/isPlainObject.js +8 -3
  77. package/lib/util/isSyntacticallyValidPropertyValue.js +74 -0
  78. package/lib/util/log.js +27 -13
  79. package/lib/util/nameClass.js +27 -9
  80. package/lib/util/negateValue.js +25 -8
  81. package/lib/util/normalizeConfig.js +147 -60
  82. package/lib/util/normalizeScreens.js +178 -0
  83. package/lib/util/parseAnimationValue.js +45 -41
  84. package/lib/util/parseBoxShadowValue.js +88 -0
  85. package/lib/util/parseDependency.js +39 -55
  86. package/lib/util/parseGlob.js +35 -0
  87. package/lib/util/parseObjectStyles.js +15 -10
  88. package/lib/util/pluginUtils.js +178 -199
  89. package/lib/util/prefixSelector.js +30 -14
  90. package/lib/util/pseudoElements.js +212 -0
  91. package/lib/util/removeAlphaVariables.js +31 -0
  92. package/lib/util/resolveConfig.js +96 -74
  93. package/lib/util/resolveConfigPath.js +32 -12
  94. package/lib/util/responsive.js +11 -6
  95. package/lib/util/splitAtTopLevelOnly.js +47 -0
  96. package/lib/util/tap.js +6 -1
  97. package/lib/util/toColorValue.js +7 -3
  98. package/lib/util/toPath.js +26 -3
  99. package/lib/util/transformThemeValue.js +52 -32
  100. package/lib/util/validateConfig.js +37 -0
  101. package/lib/util/validateFormalSyntax.js +26 -0
  102. package/lib/util/withAlphaVariable.js +27 -15
  103. package/lib/value-parser/LICENSE +22 -0
  104. package/lib/value-parser/README.md +3 -0
  105. package/lib/value-parser/index.d.js +2 -0
  106. package/lib/value-parser/index.js +22 -0
  107. package/lib/value-parser/parse.js +259 -0
  108. package/lib/value-parser/stringify.js +38 -0
  109. package/lib/value-parser/unit.js +86 -0
  110. package/lib/value-parser/walk.js +16 -0
  111. package/loadConfig.d.ts +4 -0
  112. package/loadConfig.js +2 -0
  113. package/nesting/index.d.ts +4 -0
  114. package/nesting/index.js +2 -12
  115. package/package.json +62 -57
  116. package/peers/index.js +80090 -59322
  117. package/plugin.d.ts +11 -0
  118. package/plugin.js +2 -1
  119. package/resolveConfig.d.ts +31 -0
  120. package/resolveConfig.js +2 -1
  121. package/scripts/generate-types.js +104 -0
  122. package/scripts/release-channel.js +18 -0
  123. package/scripts/release-notes.js +21 -0
  124. package/scripts/type-utils.js +27 -0
  125. package/src/cli/build/deps.js +56 -0
  126. package/src/cli/build/index.js +49 -0
  127. package/src/cli/build/plugin.js +441 -0
  128. package/src/cli/build/utils.js +76 -0
  129. package/src/cli/build/watching.js +229 -0
  130. package/src/cli/help/index.js +70 -0
  131. package/src/cli/index.js +216 -0
  132. package/src/cli/init/index.js +79 -0
  133. package/src/cli-peer-dependencies.js +7 -1
  134. package/src/cli.js +1 -759
  135. package/src/corePluginList.js +1 -1
  136. package/src/corePlugins.js +1133 -563
  137. package/src/css/preflight.css +50 -18
  138. package/src/featureFlags.js +13 -5
  139. package/src/index.js +1 -34
  140. package/src/lib/cacheInvalidation.js +52 -0
  141. package/src/lib/collapseAdjacentRules.js +21 -2
  142. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  143. package/src/lib/content.js +295 -0
  144. package/src/lib/defaultExtractor.js +255 -0
  145. package/src/lib/evaluateTailwindFunctions.js +88 -11
  146. package/src/lib/expandApplyAtRules.js +538 -152
  147. package/src/lib/expandTailwindAtRules.js +115 -83
  148. package/src/lib/findAtConfigPath.js +48 -0
  149. package/src/lib/generateRules.js +672 -110
  150. package/src/lib/getModuleDependencies.js +70 -30
  151. package/src/lib/load-config.ts +55 -0
  152. package/src/lib/normalizeTailwindDirectives.js +7 -1
  153. package/src/lib/offsets.js +432 -0
  154. package/src/lib/partitionApplyAtRules.js +52 -0
  155. package/src/lib/regex.js +74 -0
  156. package/src/lib/remap-bitfield.js +82 -0
  157. package/src/lib/resolveDefaultsAtRules.js +61 -17
  158. package/src/lib/setupContextUtils.js +756 -183
  159. package/src/lib/setupTrackingContext.js +52 -65
  160. package/src/lib/sharedState.js +54 -7
  161. package/src/lib/substituteScreenAtRules.js +6 -3
  162. package/src/plugin.js +47 -0
  163. package/src/postcss-plugins/nesting/README.md +42 -0
  164. package/src/postcss-plugins/nesting/index.js +13 -0
  165. package/src/postcss-plugins/nesting/plugin.js +80 -0
  166. package/src/processTailwindFeatures.js +15 -5
  167. package/src/public/colors.js +22 -0
  168. package/src/public/default-config.js +1 -1
  169. package/src/public/default-theme.js +2 -2
  170. package/src/public/load-config.js +2 -0
  171. package/src/util/applyImportantSelector.js +26 -0
  172. package/src/util/buildMediaQuery.js +14 -16
  173. package/src/util/cloneNodes.js +40 -2
  174. package/src/util/color.js +44 -12
  175. package/src/util/colorNames.js +150 -0
  176. package/src/util/dataTypes.js +249 -23
  177. package/src/util/defaults.js +6 -0
  178. package/src/util/formatVariantSelector.js +324 -0
  179. package/src/util/getAllConfigs.js +21 -2
  180. package/src/util/isPlainObject.js +1 -1
  181. package/src/util/isSyntacticallyValidPropertyValue.js +61 -0
  182. package/src/util/log.js +11 -7
  183. package/src/util/nameClass.js +5 -1
  184. package/src/util/negateValue.js +11 -3
  185. package/src/util/normalizeConfig.js +74 -8
  186. package/src/util/normalizeScreens.js +140 -0
  187. package/src/util/parseAnimationValue.js +1 -1
  188. package/src/util/parseBoxShadowValue.js +72 -0
  189. package/src/util/parseDependency.js +37 -42
  190. package/src/util/parseGlob.js +23 -0
  191. package/src/util/pluginUtils.js +151 -159
  192. package/src/util/prefixSelector.js +31 -13
  193. package/src/util/pseudoElements.js +171 -0
  194. package/src/util/removeAlphaVariables.js +24 -0
  195. package/src/util/resolveConfig.js +74 -26
  196. package/src/util/resolveConfigPath.js +14 -1
  197. package/src/util/splitAtTopLevelOnly.js +48 -0
  198. package/src/util/toPath.js +23 -1
  199. package/src/util/transformThemeValue.js +33 -8
  200. package/src/util/validateConfig.js +26 -0
  201. package/src/util/validateFormalSyntax.js +34 -0
  202. package/src/util/withAlphaVariable.js +1 -1
  203. package/src/value-parser/LICENSE +22 -0
  204. package/src/value-parser/README.md +3 -0
  205. package/src/value-parser/index.d.ts +177 -0
  206. package/src/value-parser/index.js +28 -0
  207. package/src/value-parser/parse.js +303 -0
  208. package/src/value-parser/stringify.js +41 -0
  209. package/src/value-parser/unit.js +118 -0
  210. package/src/value-parser/walk.js +18 -0
  211. package/stubs/.gitignore +1 -0
  212. package/stubs/.prettierrc.json +6 -0
  213. package/stubs/{defaultConfig.stub.js → config.full.js} +322 -184
  214. package/stubs/postcss.config.js +6 -0
  215. package/stubs/tailwind.config.cjs +2 -0
  216. package/stubs/tailwind.config.js +2 -0
  217. package/stubs/tailwind.config.ts +3 -0
  218. package/types/config.d.ts +376 -0
  219. package/types/generated/.gitkeep +0 -0
  220. package/types/generated/colors.d.ts +298 -0
  221. package/types/generated/corePluginList.d.ts +1 -0
  222. package/types/generated/default-theme.d.ts +397 -0
  223. package/types/index.d.ts +11 -0
  224. package/CHANGELOG.md +0 -1777
  225. package/lib/constants.js +0 -37
  226. package/lib/lib/detectNesting.js +0 -19
  227. package/lib/lib/setupWatchingContext.js +0 -284
  228. package/nesting/plugin.js +0 -41
  229. package/scripts/install-integrations.js +0 -27
  230. package/scripts/rebuildFixtures.js +0 -68
  231. package/src/constants.js +0 -17
  232. package/src/lib/detectNesting.js +0 -20
  233. package/src/lib/setupWatchingContext.js +0 -304
  234. /package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -0
  235. /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
@@ -0,0 +1,247 @@
1
+ // @ts-check
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ function _export(target, all) {
7
+ for(var name in all)Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ parseCandidateFiles: function() {
14
+ return parseCandidateFiles;
15
+ },
16
+ resolvedChangedContent: function() {
17
+ return resolvedChangedContent;
18
+ },
19
+ createBroadPatternCheck: function() {
20
+ return createBroadPatternCheck;
21
+ }
22
+ });
23
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
24
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
25
+ const _isglob = /*#__PURE__*/ _interop_require_default(require("is-glob"));
26
+ const _fastglob = /*#__PURE__*/ _interop_require_default(require("fast-glob"));
27
+ const _normalizepath = /*#__PURE__*/ _interop_require_default(require("normalize-path"));
28
+ const _parseGlob = require("../util/parseGlob");
29
+ const _sharedState = require("./sharedState");
30
+ const _log = /*#__PURE__*/ _interop_require_default(require("../util/log"));
31
+ const _micromatch = /*#__PURE__*/ _interop_require_default(require("micromatch"));
32
+ function _interop_require_default(obj) {
33
+ return obj && obj.__esModule ? obj : {
34
+ default: obj
35
+ };
36
+ }
37
+ function parseCandidateFiles(context, tailwindConfig) {
38
+ let files = tailwindConfig.content.files;
39
+ // Normalize the file globs
40
+ files = files.filter((filePath)=>typeof filePath === "string");
41
+ files = files.map(_normalizepath.default);
42
+ // Split into included and excluded globs
43
+ let tasks = _fastglob.default.generateTasks(files);
44
+ /** @type {ContentPath[]} */ let included = [];
45
+ /** @type {ContentPath[]} */ let excluded = [];
46
+ for (const task of tasks){
47
+ included.push(...task.positive.map((filePath)=>parseFilePath(filePath, false)));
48
+ excluded.push(...task.negative.map((filePath)=>parseFilePath(filePath, true)));
49
+ }
50
+ let paths = [
51
+ ...included,
52
+ ...excluded
53
+ ];
54
+ // Resolve paths relative to the config file or cwd
55
+ paths = resolveRelativePaths(context, paths);
56
+ // Resolve symlinks if possible
57
+ paths = paths.flatMap(resolvePathSymlinks);
58
+ // Update cached patterns
59
+ paths = paths.map(resolveGlobPattern);
60
+ return paths;
61
+ }
62
+ /**
63
+ *
64
+ * @param {string} filePath
65
+ * @param {boolean} ignore
66
+ * @returns {ContentPath}
67
+ */ function parseFilePath(filePath, ignore) {
68
+ let contentPath = {
69
+ original: filePath,
70
+ base: filePath,
71
+ ignore,
72
+ pattern: filePath,
73
+ glob: null
74
+ };
75
+ if ((0, _isglob.default)(filePath)) {
76
+ Object.assign(contentPath, (0, _parseGlob.parseGlob)(filePath));
77
+ }
78
+ return contentPath;
79
+ }
80
+ /**
81
+ *
82
+ * @param {ContentPath} contentPath
83
+ * @returns {ContentPath}
84
+ */ function resolveGlobPattern(contentPath) {
85
+ // This is required for Windows support to properly pick up Glob paths.
86
+ // Afaik, this technically shouldn't be needed but there's probably
87
+ // some internal, direct path matching with a normalized path in
88
+ // a package which can't handle mixed directory separators
89
+ let base = (0, _normalizepath.default)(contentPath.base);
90
+ // If the user's file path contains any special characters (like parens) for instance fast-glob
91
+ // is like "OOOH SHINY" and treats them as such. So we have to escape the base path to fix this
92
+ base = _fastglob.default.escapePath(base);
93
+ contentPath.pattern = contentPath.glob ? `${base}/${contentPath.glob}` : base;
94
+ contentPath.pattern = contentPath.ignore ? `!${contentPath.pattern}` : contentPath.pattern;
95
+ return contentPath;
96
+ }
97
+ /**
98
+ * Resolve each path relative to the config file (when possible) if the experimental flag is enabled
99
+ * Otherwise, resolve relative to the current working directory
100
+ *
101
+ * @param {any} context
102
+ * @param {ContentPath[]} contentPaths
103
+ * @returns {ContentPath[]}
104
+ */ function resolveRelativePaths(context, contentPaths) {
105
+ let resolveFrom = [];
106
+ // Resolve base paths relative to the config file (when possible) if the experimental flag is enabled
107
+ if (context.userConfigPath && context.tailwindConfig.content.relative) {
108
+ resolveFrom = [
109
+ _path.default.dirname(context.userConfigPath)
110
+ ];
111
+ }
112
+ return contentPaths.map((contentPath)=>{
113
+ contentPath.base = _path.default.resolve(...resolveFrom, contentPath.base);
114
+ return contentPath;
115
+ });
116
+ }
117
+ /**
118
+ * Resolve the symlink for the base directory / file in each path
119
+ * These are added as additional dependencies to watch for changes because
120
+ * some tools (like webpack) will only watch the actual file or directory
121
+ * but not the symlink itself even in projects that use monorepos.
122
+ *
123
+ * @param {ContentPath} contentPath
124
+ * @returns {ContentPath[]}
125
+ */ function resolvePathSymlinks(contentPath) {
126
+ let paths = [
127
+ contentPath
128
+ ];
129
+ try {
130
+ let resolvedPath = _fs.default.realpathSync(contentPath.base);
131
+ if (resolvedPath !== contentPath.base) {
132
+ paths.push({
133
+ ...contentPath,
134
+ base: resolvedPath
135
+ });
136
+ }
137
+ } catch {
138
+ // TODO: log this?
139
+ }
140
+ return paths;
141
+ }
142
+ function resolvedChangedContent(context, candidateFiles, fileModifiedMap) {
143
+ let changedContent = context.tailwindConfig.content.files.filter((item)=>typeof item.raw === "string").map(({ raw , extension ="html" })=>({
144
+ content: raw,
145
+ extension
146
+ }));
147
+ let [changedFiles, mTimesToCommit] = resolveChangedFiles(candidateFiles, fileModifiedMap);
148
+ for (let changedFile of changedFiles){
149
+ let extension = _path.default.extname(changedFile).slice(1);
150
+ changedContent.push({
151
+ file: changedFile,
152
+ extension
153
+ });
154
+ }
155
+ return [
156
+ changedContent,
157
+ mTimesToCommit
158
+ ];
159
+ }
160
+ const LARGE_DIRECTORIES = [
161
+ "node_modules"
162
+ ];
163
+ // Ensures that `node_modules` has to match as-is, otherwise `mynode_modules`
164
+ // would match as well, but that is not a known large directory.
165
+ const LARGE_DIRECTORIES_REGEX = new RegExp(`(${LARGE_DIRECTORIES.map((dir)=>String.raw`\b${dir}\b`).join("|")})`);
166
+ function createBroadPatternCheck(paths) {
167
+ // Detect whether a glob pattern might be too broad. This means that it:
168
+ // - Includes `**`
169
+ // - Does not include any of the known large directories (e.g.: node_modules)
170
+ let maybeBroadPattern = paths.some((path)=>path.includes("**") && !LARGE_DIRECTORIES_REGEX.test(path));
171
+ // Didn't detect any potentially broad patterns, so we can skip further
172
+ // checks.
173
+ if (!maybeBroadPattern) {
174
+ return ()=>{};
175
+ }
176
+ // All glob matchers
177
+ let matchers = [];
178
+ // All glob matchers that explicitly contain any of the known large
179
+ // directories (e.g.: node_modules).
180
+ let explicitMatchers = [];
181
+ // Create matchers for all paths
182
+ for (let path of paths){
183
+ let matcher = _micromatch.default.matcher(path);
184
+ if (LARGE_DIRECTORIES_REGEX.test(path)) {
185
+ explicitMatchers.push(matcher);
186
+ }
187
+ matchers.push(matcher);
188
+ }
189
+ // Keep track of whether we already warned about the broad pattern issue or
190
+ // not. The `log.warn` function already does something similar where we only
191
+ // output the log once. However, with this we can also skip the other checks
192
+ // when we already warned about the broad pattern.
193
+ let warned = false;
194
+ /**
195
+ * @param {string} file
196
+ */ return (file)=>{
197
+ if (warned) return; // Already warned about the broad pattern
198
+ if (explicitMatchers.some((matcher)=>matcher(file))) return; // Explicitly included, so we can skip further checks
199
+ // When a broad pattern is used, we have to double check that the file was
200
+ // not explicitly included in the globs.
201
+ let matchingGlobIndex = matchers.findIndex((matcher)=>matcher(file));
202
+ if (matchingGlobIndex === -1) return; // This should never happen
203
+ let matchingGlob = paths[matchingGlobIndex];
204
+ // Create relative paths to make the output a bit more readable.
205
+ let relativeMatchingGlob = _path.default.relative(process.cwd(), matchingGlob);
206
+ if (relativeMatchingGlob[0] !== ".") relativeMatchingGlob = `./${relativeMatchingGlob}`;
207
+ let largeDirectory = LARGE_DIRECTORIES.find((directory)=>file.includes(directory));
208
+ if (largeDirectory) {
209
+ warned = true;
210
+ _log.default.warn("broad-content-glob-pattern", [
211
+ `Your \`content\` configuration includes a pattern which looks like it's accidentally matching all of \`${largeDirectory}\` and can cause serious performance issues.`,
212
+ `Pattern: \`${relativeMatchingGlob}\``,
213
+ `See our documentation for recommendations:`,
214
+ "https://tailwindcss.com/docs/content-configuration#pattern-recommendations"
215
+ ]);
216
+ }
217
+ };
218
+ }
219
+ /**
220
+ *
221
+ * @param {ContentPath[]} candidateFiles
222
+ * @param {Map<string, number>} fileModifiedMap
223
+ * @returns {[Set<string>, Map<string, number>]}
224
+ */ function resolveChangedFiles(candidateFiles, fileModifiedMap) {
225
+ let paths = candidateFiles.map((contentPath)=>contentPath.pattern);
226
+ let mTimesToCommit = new Map();
227
+ let checkBroadPattern = createBroadPatternCheck(paths);
228
+ let changedFiles = new Set();
229
+ _sharedState.env.DEBUG && console.time("Finding changed files");
230
+ let files = _fastglob.default.sync(paths, {
231
+ absolute: true
232
+ });
233
+ for (let file of files){
234
+ checkBroadPattern(file);
235
+ let prevModified = fileModifiedMap.get(file) || -Infinity;
236
+ let modified = _fs.default.statSync(file).mtimeMs;
237
+ if (modified > prevModified) {
238
+ changedFiles.add(file);
239
+ mTimesToCommit.set(file, modified);
240
+ }
241
+ }
242
+ _sharedState.env.DEBUG && console.timeEnd("Finding changed files");
243
+ return [
244
+ changedFiles,
245
+ mTimesToCommit
246
+ ];
247
+ }
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "defaultExtractor", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return defaultExtractor;
9
+ }
10
+ });
11
+ const _regex = /*#__PURE__*/ _interop_require_wildcard(require("./regex"));
12
+ const _splitAtTopLevelOnly = require("../util/splitAtTopLevelOnly");
13
+ function _getRequireWildcardCache(nodeInterop) {
14
+ if (typeof WeakMap !== "function") return null;
15
+ var cacheBabelInterop = new WeakMap();
16
+ var cacheNodeInterop = new WeakMap();
17
+ return (_getRequireWildcardCache = function(nodeInterop) {
18
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
19
+ })(nodeInterop);
20
+ }
21
+ function _interop_require_wildcard(obj, nodeInterop) {
22
+ if (!nodeInterop && obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache(nodeInterop);
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {};
35
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
36
+ for(var key in obj){
37
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
38
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
39
+ if (desc && (desc.get || desc.set)) {
40
+ Object.defineProperty(newObj, key, desc);
41
+ } else {
42
+ newObj[key] = obj[key];
43
+ }
44
+ }
45
+ }
46
+ newObj.default = obj;
47
+ if (cache) {
48
+ cache.set(obj, newObj);
49
+ }
50
+ return newObj;
51
+ }
52
+ function defaultExtractor(context) {
53
+ let patterns = Array.from(buildRegExps(context));
54
+ /**
55
+ * @param {string} content
56
+ */ return (content)=>{
57
+ /** @type {(string|string)[]} */ let results = [];
58
+ for (let pattern of patterns){
59
+ var _content_match;
60
+ for (let result of (_content_match = content.match(pattern)) !== null && _content_match !== void 0 ? _content_match : []){
61
+ results.push(clipAtBalancedParens(result));
62
+ }
63
+ }
64
+ // Extract any subclasses from languages like Slim and Pug, eg:
65
+ // div.flex.px-5.underline
66
+ for (let result of results.slice()){
67
+ let segments = (0, _splitAtTopLevelOnly.splitAtTopLevelOnly)(result, ".");
68
+ for(let idx = 0; idx < segments.length; idx++){
69
+ let segment = segments[idx];
70
+ if (idx >= segments.length - 1) {
71
+ results.push(segment);
72
+ continue;
73
+ }
74
+ // If the next segment is a number, discard both, for example seeing
75
+ // `px-1` and `5` means the real candidate was `px-1.5` which is already
76
+ // captured.
77
+ let next = Number(segments[idx + 1]);
78
+ if (isNaN(next)) {
79
+ results.push(segment);
80
+ } else {
81
+ idx++;
82
+ }
83
+ }
84
+ }
85
+ return results;
86
+ };
87
+ }
88
+ function* buildRegExps(context) {
89
+ let separator = context.tailwindConfig.separator;
90
+ let prefix = context.tailwindConfig.prefix !== "" ? _regex.optional(_regex.pattern([
91
+ /-?/,
92
+ _regex.escape(context.tailwindConfig.prefix)
93
+ ])) : "";
94
+ let utility = _regex.any([
95
+ // Arbitrary properties (without square brackets)
96
+ /\[[^\s:'"`]+:[^\s\[\]]+\]/,
97
+ // Arbitrary properties with balanced square brackets
98
+ // This is a targeted fix to continue to allow theme()
99
+ // with square brackets to work in arbitrary properties
100
+ // while fixing a problem with the regex matching too much
101
+ /\[[^\s:'"`\]]+:[^\s]+?\[[^\s]+\][^\s]+?\]/,
102
+ // Utilities
103
+ _regex.pattern([
104
+ // Utility Name / Group Name
105
+ _regex.any([
106
+ /-?(?:\w+)/,
107
+ // This is here to make sure @container supports everything that other utilities do
108
+ /@(?:\w+)/
109
+ ]),
110
+ // Normal/Arbitrary values
111
+ _regex.optional(_regex.any([
112
+ _regex.pattern([
113
+ // Arbitrary values
114
+ _regex.any([
115
+ /-(?:\w+-)*\['[^\s]+'\]/,
116
+ /-(?:\w+-)*\["[^\s]+"\]/,
117
+ /-(?:\w+-)*\[`[^\s]+`\]/,
118
+ /-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s:\[\]]+\]/
119
+ ]),
120
+ // Not immediately followed by an `{[(`
121
+ /(?![{([]])/,
122
+ // optionally followed by an opacity modifier
123
+ /(?:\/[^\s'"`\\><$]*)?/
124
+ ]),
125
+ _regex.pattern([
126
+ // Arbitrary values
127
+ _regex.any([
128
+ /-(?:\w+-)*\['[^\s]+'\]/,
129
+ /-(?:\w+-)*\["[^\s]+"\]/,
130
+ /-(?:\w+-)*\[`[^\s]+`\]/,
131
+ /-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s\[\]]+\]/
132
+ ]),
133
+ // Not immediately followed by an `{[(`
134
+ /(?![{([]])/,
135
+ // optionally followed by an opacity modifier
136
+ /(?:\/[^\s'"`\\$]*)?/
137
+ ]),
138
+ // Normal values w/o quotes — may include an opacity modifier
139
+ /[-\/][^\s'"`\\$={><]*/
140
+ ]))
141
+ ])
142
+ ]);
143
+ let variantPatterns = [
144
+ // Without quotes
145
+ _regex.any([
146
+ // This is here to provide special support for the `@` variant
147
+ _regex.pattern([
148
+ /@\[[^\s"'`]+\](\/[^\s"'`]+)?/,
149
+ separator
150
+ ]),
151
+ // With variant modifier (e.g.: group-[..]/modifier)
152
+ _regex.pattern([
153
+ /([^\s"'`\[\\]+-)?\[[^\s"'`]+\]\/[\w_-]+/,
154
+ separator
155
+ ]),
156
+ _regex.pattern([
157
+ /([^\s"'`\[\\]+-)?\[[^\s"'`]+\]/,
158
+ separator
159
+ ]),
160
+ _regex.pattern([
161
+ /[^\s"'`\[\\]+/,
162
+ separator
163
+ ])
164
+ ]),
165
+ // With quotes allowed
166
+ _regex.any([
167
+ // With variant modifier (e.g.: group-[..]/modifier)
168
+ _regex.pattern([
169
+ /([^\s"'`\[\\]+-)?\[[^\s`]+\]\/[\w_-]+/,
170
+ separator
171
+ ]),
172
+ _regex.pattern([
173
+ /([^\s"'`\[\\]+-)?\[[^\s`]+\]/,
174
+ separator
175
+ ]),
176
+ _regex.pattern([
177
+ /[^\s`\[\\]+/,
178
+ separator
179
+ ])
180
+ ])
181
+ ];
182
+ for (const variantPattern of variantPatterns){
183
+ yield _regex.pattern([
184
+ // Variants
185
+ "((?=((",
186
+ variantPattern,
187
+ ")+))\\2)?",
188
+ // Important (optional)
189
+ /!?/,
190
+ prefix,
191
+ utility
192
+ ]);
193
+ }
194
+ // 5. Inner matches
195
+ yield /[^<>"'`\s.(){}[\]#=%$][^<>"'`\s(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
196
+ }
197
+ // We want to capture any "special" characters
198
+ // AND the characters immediately following them (if there is one)
199
+ let SPECIALS = /([\[\]'"`])([^\[\]'"`])?/g;
200
+ let ALLOWED_CLASS_CHARACTERS = /[^"'`\s<>\]]+/;
201
+ /**
202
+ * Clips a string ensuring that parentheses, quotes, etc… are balanced
203
+ * Used for arbitrary values only
204
+ *
205
+ * We will go past the end of the balanced parens until we find a non-class character
206
+ *
207
+ * Depth matching behavior:
208
+ * w-[calc(100%-theme('spacing[some_key][1.5]'))]']
209
+ * ┬ ┬ ┬┬ ┬ ┬┬ ┬┬┬┬┬┬┬
210
+ * 1 2 3 4 34 3 210 END
211
+ * ╰────┴──────────┴────────┴────────┴┴───┴─┴┴┴
212
+ *
213
+ * @param {string} input
214
+ */ function clipAtBalancedParens(input) {
215
+ // We are care about this for arbitrary values
216
+ if (!input.includes("-[")) {
217
+ return input;
218
+ }
219
+ let depth = 0;
220
+ let openStringTypes = [];
221
+ // Find all parens, brackets, quotes, etc
222
+ // Stop when we end at a balanced pair
223
+ // This is naive and will treat mismatched parens as balanced
224
+ // This shouldn't be a problem in practice though
225
+ let matches = input.matchAll(SPECIALS);
226
+ // We can't use lookbehind assertions because we have to support Safari
227
+ // So, instead, we've emulated it using capture groups and we'll re-work the matches to accommodate
228
+ matches = Array.from(matches).flatMap((match)=>{
229
+ const [, ...groups] = match;
230
+ return groups.map((group, idx)=>Object.assign([], match, {
231
+ index: match.index + idx,
232
+ 0: group
233
+ }));
234
+ });
235
+ for (let match of matches){
236
+ let char = match[0];
237
+ let inStringType = openStringTypes[openStringTypes.length - 1];
238
+ if (char === inStringType) {
239
+ openStringTypes.pop();
240
+ } else if (char === "'" || char === '"' || char === "`") {
241
+ openStringTypes.push(char);
242
+ }
243
+ if (inStringType) {
244
+ continue;
245
+ } else if (char === "[") {
246
+ depth++;
247
+ continue;
248
+ } else if (char === "]") {
249
+ depth--;
250
+ continue;
251
+ }
252
+ // We've gone one character past the point where we should stop
253
+ // This means that there was an extra closing `]`
254
+ // We'll clip to just before it
255
+ if (depth < 0) {
256
+ return input.substring(0, match.index - 1);
257
+ }
258
+ // We've finished balancing the brackets but there still may be characters that can be included
259
+ // For example in the class `text-[#336699]/[.35]`
260
+ // The depth goes to `0` at the closing `]` but goes up again at the `[`
261
+ // If we're at zero and encounter a non-class character then we clip the class there
262
+ if (depth === 0 && !ALLOWED_CLASS_CHARACTERS.test(char)) {
263
+ return input.substring(0, match.index);
264
+ }
265
+ }
266
+ return input;
267
+ } // Regular utilities
268
+ // {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
269
+ // Arbitrary values
270
+ // {{modifier}:}*{namespace}-[{arbitraryValue}]{/{opacityModifier}}?
271
+ // arbitraryValue: no whitespace, balanced quotes unless within quotes, balanced brackets unless within quotes
272
+ // Arbitrary properties
273
+ // {{modifier}:}*[{validCssPropertyName}:{arbitraryValue}]