tailwindcss 3.0.11 → 3.0.12

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.
@@ -75,45 +75,6 @@ function extractApplyCandidates(params) {
75
75
  false
76
76
  ];
77
77
  }
78
- function partitionApplyParents(root) {
79
- let applyParents = new Set();
80
- root.walkAtRules('apply', (rule)=>{
81
- applyParents.add(rule.parent);
82
- });
83
- for (let rule1 of applyParents){
84
- let nodeGroups = [];
85
- let lastGroup = [];
86
- for (let node of rule1.nodes){
87
- if (node.type === 'atrule' && node.name === 'apply') {
88
- if (lastGroup.length > 0) {
89
- nodeGroups.push(lastGroup);
90
- lastGroup = [];
91
- }
92
- nodeGroups.push([
93
- node
94
- ]);
95
- } else {
96
- lastGroup.push(node);
97
- }
98
- }
99
- if (lastGroup.length > 0) {
100
- nodeGroups.push(lastGroup);
101
- }
102
- if (nodeGroups.length === 1) {
103
- continue;
104
- }
105
- for (let group of [
106
- ...nodeGroups
107
- ].reverse()){
108
- let newParent = rule1.clone({
109
- nodes: []
110
- });
111
- newParent.append(group);
112
- rule1.after(newParent);
113
- }
114
- rule1.remove();
115
- }
116
- }
117
78
  function processApply(root, context) {
118
79
  let applyCandidates = new Set();
119
80
  // Collect all @apply rules and candidates
@@ -311,7 +272,6 @@ function processApply(root, context) {
311
272
  }
312
273
  function expandApplyAtRules(context) {
313
274
  return (root)=>{
314
- partitionApplyParents(root);
315
275
  processApply(root, context);
316
276
  };
317
277
  }
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  exports.default = expandTailwindAtRules;
6
- exports.DEFAULTS_LAYER = void 0;
7
6
  var _quickLru = _interopRequireDefault(require("quick-lru"));
8
7
  var sharedState = _interopRequireWildcard(require("./sharedState"));
9
8
  var _generateRules = require("./generateRules");
@@ -133,8 +132,6 @@ function buildStylesheet(rules, context) {
133
132
  }
134
133
  return returnValue;
135
134
  }
136
- const DEFAULTS_LAYER = Symbol('defaults-layer');
137
- exports.DEFAULTS_LAYER = DEFAULTS_LAYER;
138
135
  function expandTailwindAtRules(context) {
139
136
  return (root)=>{
140
137
  let layerNodes = {
@@ -143,7 +140,6 @@ function expandTailwindAtRules(context) {
143
140
  utilities: null,
144
141
  variants: null
145
142
  };
146
- // let hasApply = false
147
143
  root.walkAtRules((rule)=>{
148
144
  // Make sure this file contains Tailwind directives. If not, we can save
149
145
  // a lot of work and bail early. Also we don't have to register our touch
@@ -154,12 +150,6 @@ function expandTailwindAtRules(context) {
154
150
  layerNodes[rule.params] = rule;
155
151
  }
156
152
  }
157
- // We also want to check for @apply because the user can
158
- // apply classes in an isolated environment like CSS
159
- // modules and we still need to inject defaults
160
- // if (rule.name === 'apply') {
161
- // hasApply = true
162
- // }
163
153
  });
164
154
  if (Object.values(layerNodes).every((n)=>n === null
165
155
  )) {
@@ -177,6 +167,7 @@ function expandTailwindAtRules(context) {
177
167
  let extractor = getExtractor(context.tailwindConfig, extension);
178
168
  getClassCandidates(transformer(content), extractor, candidates, seen);
179
169
  }
170
+ env.DEBUG && console.timeEnd('Reading changed files');
180
171
  // ---
181
172
  // Generate the actual CSS
182
173
  let classCacheCount = context.classCache.size;
@@ -199,23 +190,10 @@ function expandTailwindAtRules(context) {
199
190
  // Replace any Tailwind directives with generated CSS
200
191
  if (layerNodes.base) {
201
192
  layerNodes.base.before((0, _cloneNodes).default([
202
- ...baseNodes
193
+ ...baseNodes,
194
+ ...defaultNodes
203
195
  ], layerNodes.base.source));
204
196
  }
205
- // @defaults rules are unconditionally added first to ensure that
206
- // using any utility that relies on defaults will work even when
207
- // compiled in an isolated environment like CSS modules
208
- if (context.tailwindConfig[DEFAULTS_LAYER] !== false) {
209
- if (layerNodes.base) {
210
- layerNodes.base.after((0, _cloneNodes).default([
211
- ...defaultNodes
212
- ], root.source));
213
- } else {
214
- root.prepend((0, _cloneNodes).default([
215
- ...defaultNodes
216
- ], root.source));
217
- }
218
- }
219
197
  if (layerNodes.base) {
220
198
  layerNodes.base.remove();
221
199
  }
@@ -109,11 +109,11 @@ function resolveDefaultsAtRules({ tailwindConfig }) {
109
109
  selectors.add(selector);
110
110
  }
111
111
  }
112
- if (selectorGroups.size === 0) {
113
- universal.remove();
114
- continue;
115
- }
116
112
  if ((0, _featureFlags).flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
113
+ if (selectorGroups.size === 0) {
114
+ universal.remove();
115
+ continue;
116
+ }
117
117
  for (let [, selectors] of selectorGroups){
118
118
  let universalRule = _postcss.default.rule();
119
119
  universalRule.selectors = [
@@ -52,6 +52,55 @@ function _interopRequireWildcard(obj) {
52
52
  return newObj;
53
53
  }
54
54
  }
55
+ function partitionRules(root) {
56
+ if (!root.walkAtRules) return [
57
+ root
58
+ ];
59
+ let applyParents = new Set();
60
+ let rules = [];
61
+ root.walkAtRules('apply', (rule)=>{
62
+ applyParents.add(rule.parent);
63
+ });
64
+ if (applyParents.size === 0) {
65
+ rules.push(root);
66
+ }
67
+ for (let rule1 of applyParents){
68
+ let nodeGroups = [];
69
+ let lastGroup = [];
70
+ for (let node of rule1.nodes){
71
+ if (node.type === 'atrule' && node.name === 'apply') {
72
+ if (lastGroup.length > 0) {
73
+ nodeGroups.push(lastGroup);
74
+ lastGroup = [];
75
+ }
76
+ nodeGroups.push([
77
+ node
78
+ ]);
79
+ } else {
80
+ lastGroup.push(node);
81
+ }
82
+ }
83
+ if (lastGroup.length > 0) {
84
+ nodeGroups.push(lastGroup);
85
+ }
86
+ if (nodeGroups.length === 1) {
87
+ rules.push(rule1);
88
+ continue;
89
+ }
90
+ for (let group of [
91
+ ...nodeGroups
92
+ ].reverse()){
93
+ let clone = rule1.clone({
94
+ nodes: []
95
+ });
96
+ clone.append(group);
97
+ rules.unshift(clone);
98
+ rule1.after(clone);
99
+ }
100
+ rule1.remove();
101
+ }
102
+ return rules;
103
+ }
55
104
  function parseVariantFormatString(input) {
56
105
  if (input.includes('{')) {
57
106
  if (!isBalanced(input)) throw new Error(`Your { and } are unbalanced.`);
@@ -112,44 +161,49 @@ function getClasses(selector) {
112
161
  });
113
162
  return parser.transformSync(selector);
114
163
  }
115
- function extractCandidates(node) {
164
+ function extractCandidates(node, state = {
165
+ containsNonOnDemandable: false
166
+ }, depth = 0) {
116
167
  let classes = [];
168
+ // Handle normal rules
117
169
  if (node.type === 'rule') {
118
170
  for (let selector of node.selectors){
119
171
  let classCandidates = getClasses(selector);
120
172
  // At least one of the selectors contains non-"on-demandable" candidates.
121
- if (classCandidates.length === 0) return [];
122
- classes = [
123
- ...classes,
124
- ...classCandidates
125
- ];
173
+ if (classCandidates.length === 0) {
174
+ state.containsNonOnDemandable = true;
175
+ }
176
+ for (let classCandidate of classCandidates){
177
+ classes.push(classCandidate);
178
+ }
126
179
  }
127
- return classes;
128
- }
129
- if (node.type === 'atrule') {
180
+ } else if (node.type === 'atrule') {
130
181
  node.walkRules((rule)=>{
131
- classes = [
132
- ...classes,
133
- ...rule.selectors.flatMap((selector)=>getClasses(selector)
134
- )
135
- ];
182
+ for (let classCandidate of rule.selectors.flatMap((selector)=>getClasses(selector, state, depth + 1)
183
+ )){
184
+ classes.push(classCandidate);
185
+ }
136
186
  });
137
187
  }
188
+ if (depth === 0) {
189
+ return [
190
+ state.containsNonOnDemandable || classes.length === 0,
191
+ classes
192
+ ];
193
+ }
138
194
  return classes;
139
195
  }
140
196
  function withIdentifiers(styles) {
141
197
  return parseStyles(styles).flatMap((node)=>{
142
198
  let nodeMap = new Map();
143
- let candidates = extractCandidates(node);
144
- // If this isn't "on-demandable", assign it a universal candidate.
145
- if (candidates.length === 0) {
146
- return [
147
- [
148
- '*',
149
- node
150
- ]
151
- ];
199
+ let [containsNonOnDemandableSelectors, candidates] = extractCandidates(node);
200
+ // If this isn't "on-demandable", assign it a universal candidate to always include it.
201
+ if (containsNonOnDemandableSelectors) {
202
+ candidates.unshift('*');
152
203
  }
204
+ // However, it could be that it also contains "on-demandable" candidates.
205
+ // E.g.: `span, .foo {}`, in that case it should still be possible to use
206
+ // `@apply foo` for example.
153
207
  return candidates.map((c)=>{
154
208
  if (!nodeMap.has(node)) {
155
209
  nodeMap.set(node, node);
@@ -240,35 +294,37 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
240
294
  return [];
241
295
  },
242
296
  addUserCss (userCss) {
243
- for (let [identifier, rule] of withIdentifiers(userCss)){
297
+ for (let [identifier, rule2] of withIdentifiers(userCss)){
244
298
  let offset = offsets.user++;
245
299
  if (!context.candidateRuleMap.has(identifier)) {
246
300
  context.candidateRuleMap.set(identifier, []);
247
301
  }
248
- context.candidateRuleMap.get(identifier).push([
249
- {
250
- sort: offset,
251
- layer: 'user'
252
- },
253
- rule
254
- ]);
302
+ context.candidateRuleMap.get(identifier).push(...partitionRules(rule2).map((rule)=>[
303
+ {
304
+ sort: offset,
305
+ layer: 'user'
306
+ },
307
+ rule
308
+ ]
309
+ ));
255
310
  }
256
311
  },
257
312
  addBase (base) {
258
- for (let [identifier, rule] of withIdentifiers(base)){
313
+ for (let [identifier, rule3] of withIdentifiers(base)){
259
314
  let prefixedIdentifier = prefixIdentifier(identifier, {
260
315
  });
261
316
  let offset = offsets.base++;
262
317
  if (!context.candidateRuleMap.has(prefixedIdentifier)) {
263
318
  context.candidateRuleMap.set(prefixedIdentifier, []);
264
319
  }
265
- context.candidateRuleMap.get(prefixedIdentifier).push([
266
- {
267
- sort: offset,
268
- layer: 'base'
269
- },
270
- rule
271
- ]);
320
+ context.candidateRuleMap.get(prefixedIdentifier).push(...partitionRules(rule3).map((rule)=>[
321
+ {
322
+ sort: offset,
323
+ layer: 'base'
324
+ },
325
+ rule
326
+ ]
327
+ ));
272
328
  }
273
329
  },
274
330
  /**
@@ -278,20 +334,20 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
278
334
  const groups = {
279
335
  [`@defaults ${group}`]: declarations
280
336
  };
281
- for (let [identifier, rule] of withIdentifiers(groups)){
337
+ for (let [identifier, rule4] of withIdentifiers(groups)){
282
338
  let prefixedIdentifier = prefixIdentifier(identifier, {
283
339
  });
284
- let offset = offsets.base++;
285
340
  if (!context.candidateRuleMap.has(prefixedIdentifier)) {
286
341
  context.candidateRuleMap.set(prefixedIdentifier, []);
287
342
  }
288
- context.candidateRuleMap.get(prefixedIdentifier).push([
289
- {
290
- sort: offset,
291
- layer: 'defaults'
292
- },
293
- rule
294
- ]);
343
+ context.candidateRuleMap.get(prefixedIdentifier).push(...partitionRules(rule4).map((rule)=>[
344
+ {
345
+ sort: offsets.base++,
346
+ layer: 'defaults'
347
+ },
348
+ rule,
349
+ ]
350
+ ));
295
351
  }
296
352
  },
297
353
  addComponents (components, options) {
@@ -302,21 +358,21 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
302
358
  options = Object.assign({
303
359
  }, defaultOptions, Array.isArray(options) ? {
304
360
  } : options);
305
- for (let [identifier, rule] of withIdentifiers(components)){
361
+ for (let [identifier, rule5] of withIdentifiers(components)){
306
362
  let prefixedIdentifier = prefixIdentifier(identifier, options);
307
- let offset = offsets.components++;
308
363
  classList.add(prefixedIdentifier);
309
364
  if (!context.candidateRuleMap.has(prefixedIdentifier)) {
310
365
  context.candidateRuleMap.set(prefixedIdentifier, []);
311
366
  }
312
- context.candidateRuleMap.get(prefixedIdentifier).push([
313
- {
314
- sort: offset,
315
- layer: 'components',
316
- options
317
- },
318
- rule
319
- ]);
367
+ context.candidateRuleMap.get(prefixedIdentifier).push(...partitionRules(rule5).map((rule)=>[
368
+ {
369
+ sort: offsets.components++,
370
+ layer: 'components',
371
+ options
372
+ },
373
+ rule,
374
+ ]
375
+ ));
320
376
  }
321
377
  },
322
378
  addUtilities (utilities, options) {
@@ -327,21 +383,21 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
327
383
  options = Object.assign({
328
384
  }, defaultOptions, Array.isArray(options) ? {
329
385
  } : options);
330
- for (let [identifier, rule] of withIdentifiers(utilities)){
386
+ for (let [identifier, rule6] of withIdentifiers(utilities)){
331
387
  let prefixedIdentifier = prefixIdentifier(identifier, options);
332
- let offset = offsets.utilities++;
333
388
  classList.add(prefixedIdentifier);
334
389
  if (!context.candidateRuleMap.has(prefixedIdentifier)) {
335
390
  context.candidateRuleMap.set(prefixedIdentifier, []);
336
391
  }
337
- context.candidateRuleMap.get(prefixedIdentifier).push([
338
- {
339
- sort: offset,
340
- layer: 'utilities',
341
- options
342
- },
343
- rule
344
- ]);
392
+ context.candidateRuleMap.get(prefixedIdentifier).push(...partitionRules(rule6).map((rule)=>[
393
+ {
394
+ sort: offsets.utilities++,
395
+ layer: 'utilities',
396
+ options
397
+ },
398
+ rule,
399
+ ]
400
+ ));
345
401
  }
346
402
  },
347
403
  matchUtilities: function(utilities, options) {
@@ -22,6 +22,7 @@ function _interopRequireDefault(obj) {
22
22
  function processTailwindFeatures(setupContext) {
23
23
  return function(root, result) {
24
24
  let { tailwindDirectives , applyDirectives } = (0, _normalizeTailwindDirectives).default(root);
25
+ (0, _detectNesting).default()(root, result);
25
26
  let context = setupContext({
26
27
  tailwindDirectives,
27
28
  applyDirectives,
@@ -40,7 +41,6 @@ function processTailwindFeatures(setupContext) {
40
41
  throw new Error("The '-' character cannot be used as a custom separator in JIT mode due to parsing ambiguity. Please use another character like '_' instead.");
41
42
  }
42
43
  (0, _featureFlags).issueFlagNotices(context.tailwindConfig);
43
- (0, _detectNesting).default(context)(root, result);
44
44
  (0, _expandTailwindAtRules).default(context)(root, result);
45
45
  (0, _expandApplyAtRules).default(context)(root, result);
46
46
  (0, _evaluateTailwindFunctions).default(context)(root, result);
@@ -177,7 +177,7 @@ function coerceValue(types, modifier, options, tailwindConfig) {
177
177
  let result = typeMap[type](modifier, options, {
178
178
  tailwindConfig
179
179
  });
180
- if (result) return [
180
+ if (result !== undefined) return [
181
181
  result,
182
182
  type
183
183
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwindcss",
3
- "version": "3.0.11",
3
+ "version": "3.0.12",
4
4
  "description": "A utility-first CSS framework for rapidly building custom user interfaces.",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -47,7 +47,7 @@
47
47
  "@swc/core": "^1.2.118",
48
48
  "@swc/jest": "^0.2.15",
49
49
  "@swc/register": "^0.1.7",
50
- "autoprefixer": "^10.4.0",
50
+ "autoprefixer": "^10.4.1",
51
51
  "cross-env": "^7.0.3",
52
52
  "cssnano": "^5.0.14",
53
53
  "esbuild": "^0.14.2",
@@ -82,7 +82,7 @@
82
82
  "postcss-js": "^4.0.0",
83
83
  "postcss-load-config": "^3.1.0",
84
84
  "postcss-nested": "5.0.6",
85
- "postcss-selector-parser": "^6.0.7",
85
+ "postcss-selector-parser": "^6.0.8",
86
86
  "postcss-value-parser": "^4.2.0",
87
87
  "quick-lru": "^5.1.1",
88
88
  "resolve": "^1.20.0"