tailwindcss 3.0.0-alpha.2 → 3.0.3

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 (53) hide show
  1. package/CHANGELOG.md +59 -2
  2. package/colors.js +2 -1
  3. package/defaultConfig.js +2 -1
  4. package/defaultTheme.js +2 -1
  5. package/lib/cli.js +58 -58
  6. package/lib/corePluginList.js +3 -0
  7. package/lib/corePlugins.js +227 -172
  8. package/lib/css/preflight.css +5 -3
  9. package/lib/featureFlags.js +3 -1
  10. package/lib/lib/detectNesting.js +17 -2
  11. package/lib/lib/evaluateTailwindFunctions.js +6 -2
  12. package/lib/lib/expandApplyAtRules.js +23 -6
  13. package/lib/lib/expandTailwindAtRules.js +19 -1
  14. package/lib/lib/generateRules.js +54 -0
  15. package/lib/lib/resolveDefaultsAtRules.js +23 -9
  16. package/lib/lib/setupContextUtils.js +48 -71
  17. package/lib/lib/substituteScreenAtRules.js +7 -4
  18. package/lib/util/buildMediaQuery.js +13 -24
  19. package/lib/util/dataTypes.js +14 -3
  20. package/lib/util/defaults.js +6 -0
  21. package/lib/util/formatVariantSelector.js +88 -4
  22. package/lib/util/isValidArbitraryValue.js +64 -0
  23. package/lib/util/log.js +4 -0
  24. package/lib/util/nameClass.js +1 -0
  25. package/lib/util/normalizeConfig.js +34 -5
  26. package/lib/util/normalizeScreens.js +61 -0
  27. package/lib/util/resolveConfig.js +8 -8
  28. package/package.json +14 -13
  29. package/peers/index.js +3739 -3027
  30. package/plugin.js +2 -1
  31. package/resolveConfig.js +2 -1
  32. package/src/corePluginList.js +1 -1
  33. package/src/corePlugins.js +205 -165
  34. package/src/css/preflight.css +5 -3
  35. package/src/featureFlags.js +5 -1
  36. package/src/lib/detectNesting.js +22 -3
  37. package/src/lib/evaluateTailwindFunctions.js +5 -2
  38. package/src/lib/expandApplyAtRules.js +29 -2
  39. package/src/lib/expandTailwindAtRules.js +18 -0
  40. package/src/lib/generateRules.js +57 -0
  41. package/src/lib/resolveDefaultsAtRules.js +28 -7
  42. package/src/lib/setupContextUtils.js +45 -64
  43. package/src/lib/substituteScreenAtRules.js +6 -3
  44. package/src/util/buildMediaQuery.js +14 -18
  45. package/src/util/dataTypes.js +11 -6
  46. package/src/util/defaults.js +6 -0
  47. package/src/util/formatVariantSelector.js +92 -1
  48. package/src/util/isValidArbitraryValue.js +61 -0
  49. package/src/util/log.js +4 -0
  50. package/src/util/nameClass.js +1 -1
  51. package/src/util/normalizeConfig.js +14 -1
  52. package/src/util/normalizeScreens.js +45 -0
  53. package/stubs/defaultConfig.stub.js +17 -0
@@ -11,6 +11,12 @@ function defaults(target, ...sources) {
11
11
  target[k] = source[k];
12
12
  }
13
13
  }
14
+ for (let k1 of Object.getOwnPropertySymbols(source)){
15
+ var ref1;
16
+ if (!(target === null || target === void 0 ? void 0 : (ref1 = target.hasOwnProperty) === null || ref1 === void 0 ? void 0 : ref1.call(target, k1))) {
17
+ target[k1] = source[k1];
18
+ }
19
+ }
14
20
  }
15
21
  return target;
16
22
  }
@@ -40,7 +40,16 @@ function formatVariantSelector(current, ...others) {
40
40
  function finalizeSelector(format, { selector: selector1 , candidate , context }) {
41
41
  var ref, ref1;
42
42
  var ref2;
43
- let base = candidate.split((ref2 = context === null || context === void 0 ? void 0 : (ref = context.tailwindConfig) === null || ref === void 0 ? void 0 : ref.separator) !== null && ref2 !== void 0 ? ref2 : ':').pop();
43
+ let separator = (ref2 = context === null || context === void 0 ? void 0 : (ref = context.tailwindConfig) === null || ref === void 0 ? void 0 : ref.separator) !== null && ref2 !== void 0 ? ref2 : ':';
44
+ // Split by the separator, but ignore the separator inside square brackets:
45
+ //
46
+ // E.g.: dark:lg:hover:[paint-order:markers]
47
+ // ┬ ┬ ┬ ┬
48
+ // │ │ │ ╰── We will not split here
49
+ // ╰──┴─────┴─────────────── We will split here
50
+ //
51
+ let splitter = new RegExp(`\\${separator}(?![^[]*\\])`);
52
+ let base = candidate.split(splitter).pop();
44
53
  if (context === null || context === void 0 ? void 0 : (ref1 = context.tailwindConfig) === null || ref1 === void 0 ? void 0 : ref1.prefix) {
45
54
  format = (0, _prefixSelector).default(context.tailwindConfig.prefix, format);
46
55
  }
@@ -69,17 +78,92 @@ function finalizeSelector(format, { selector: selector1 , candidate , context }
69
78
  selector1 = selector1.replace(`.${(0, _escapeClassName).default(base)}`, format);
70
79
  // Remove unnecessary pseudo selectors that we used as placeholders
71
80
  return (0, _postcssSelectorParser).default((selectors)=>{
72
- return selectors.map((selector)=>{
73
- selector.walkPseudos((p)=>{
81
+ return selectors.map((selector2)=>{
82
+ selector2.walkPseudos((p)=>{
74
83
  if (selectorFunctions.has(p.value)) {
75
84
  p.replaceWith(p.nodes);
76
85
  }
77
86
  return p;
78
87
  });
79
- return selector;
88
+ // This will make sure to move pseudo's to the correct spot (the end for
89
+ // pseudo elements) because otherwise the selector will never work
90
+ // anyway.
91
+ //
92
+ // E.g.:
93
+ // - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
94
+ // - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
95
+ //
96
+ // `::before:hover` doesn't work, which means that we can make it work for you by flipping the order.
97
+ function collectPseudoElements(selector) {
98
+ let nodes = [];
99
+ for (let node of selector.nodes){
100
+ if (isPseudoElement(node)) {
101
+ nodes.push(node);
102
+ selector.removeChild(node);
103
+ }
104
+ if (node === null || node === void 0 ? void 0 : node.nodes) {
105
+ nodes.push(...collectPseudoElements(node));
106
+ }
107
+ }
108
+ return nodes;
109
+ }
110
+ let pseudoElements = collectPseudoElements(selector2);
111
+ if (pseudoElements.length > 0) {
112
+ selector2.nodes.push(pseudoElements.sort(sortSelector));
113
+ }
114
+ return selector2;
80
115
  });
81
116
  }).processSync(selector1);
82
117
  }
118
+ // Note: As a rule, double colons (::) should be used instead of a single colon
119
+ // (:). This distinguishes pseudo-classes from pseudo-elements. However, since
120
+ // this distinction was not present in older versions of the W3C spec, most
121
+ // browsers support both syntaxes for the original pseudo-elements.
122
+ let pseudoElementsBC = [
123
+ ':before',
124
+ ':after',
125
+ ':first-line',
126
+ ':first-letter'
127
+ ];
128
+ // These pseudo-elements _can_ be combined with other pseudo selectors AND the order does matter.
129
+ let pseudoElementExceptions = [
130
+ '::file-selector-button'
131
+ ];
132
+ // This will make sure to move pseudo's to the correct spot (the end for
133
+ // pseudo elements) because otherwise the selector will never work
134
+ // anyway.
135
+ //
136
+ // E.g.:
137
+ // - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
138
+ // - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
139
+ //
140
+ // `::before:hover` doesn't work, which means that we can make it work
141
+ // for you by flipping the order.
142
+ function sortSelector(a, z) {
143
+ // Both nodes are non-pseudo's so we can safely ignore them and keep
144
+ // them in the same order.
145
+ if (a.type !== 'pseudo' && z.type !== 'pseudo') {
146
+ return 0;
147
+ }
148
+ // If one of them is a combinator, we need to keep it in the same order
149
+ // because that means it will start a new "section" in the selector.
150
+ if (a.type === 'combinator' ^ z.type === 'combinator') {
151
+ return 0;
152
+ }
153
+ // One of the items is a pseudo and the other one isn't. Let's move
154
+ // the pseudo to the right.
155
+ if (a.type === 'pseudo' ^ z.type === 'pseudo') {
156
+ return (a.type === 'pseudo') - (z.type === 'pseudo');
157
+ }
158
+ // Both are pseudo's, move the pseudo elements (except for
159
+ // ::file-selector-button) to the right.
160
+ return isPseudoElement(a) - isPseudoElement(z);
161
+ }
162
+ function isPseudoElement(node) {
163
+ if (node.type !== 'pseudo') return false;
164
+ if (pseudoElementExceptions.includes(node.value)) return false;
165
+ return node.value.startsWith('::') || pseudoElementsBC.includes(node.value);
166
+ }
83
167
  function resolveFunctionArgument(haystack, needle, arg) {
84
168
  let startIdx = haystack.indexOf(arg ? `${needle}(${arg})` : needle);
85
169
  if (startIdx === -1) return null;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.default = isValidArbitraryValue;
6
+ let matchingBrackets = new Map([
7
+ [
8
+ '{',
9
+ '}'
10
+ ],
11
+ [
12
+ '[',
13
+ ']'
14
+ ],
15
+ [
16
+ '(',
17
+ ')'
18
+ ],
19
+ ]);
20
+ let inverseMatchingBrackets = new Map(Array.from(matchingBrackets.entries()).map(([k, v])=>[
21
+ v,
22
+ k
23
+ ]
24
+ ));
25
+ let quotes = new Set([
26
+ '"',
27
+ "'",
28
+ '`'
29
+ ]);
30
+ function isValidArbitraryValue(value) {
31
+ let stack = [];
32
+ let inQuotes = false;
33
+ for(let i = 0; i < value.length; i++){
34
+ let char = value[i];
35
+ if (char === ':' && !inQuotes && stack.length === 0) {
36
+ return false;
37
+ }
38
+ // Non-escaped quotes allow us to "allow" anything in between
39
+ if (quotes.has(char) && value[i - 1] !== '\\') {
40
+ inQuotes = !inQuotes;
41
+ }
42
+ if (inQuotes) continue;
43
+ if (value[i - 1] === '\\') continue; // Escaped
44
+ if (matchingBrackets.has(char)) {
45
+ stack.push(char);
46
+ } else if (inverseMatchingBrackets.has(char)) {
47
+ let inverse = inverseMatchingBrackets.get(char);
48
+ // Nothing to pop from, therefore it is unbalanced
49
+ if (stack.length <= 0) {
50
+ return false;
51
+ }
52
+ // Popped value must match the inverse value, otherwise it is unbalanced
53
+ if (stack.pop() !== inverse) {
54
+ return false;
55
+ }
56
+ }
57
+ }
58
+ // If there is still something on the stack, it is also unbalanced
59
+ if (stack.length > 0) {
60
+ return false;
61
+ }
62
+ // All good, totally balanced!
63
+ return true;
64
+ }
package/lib/util/log.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ exports.dim = dim;
5
6
  exports.default = void 0;
6
7
  var _chalk = _interopRequireDefault(require("chalk"));
7
8
  function _interopRequireDefault(obj) {
@@ -18,6 +19,9 @@ function log(chalk, messages, key) {
18
19
  messages.forEach((message)=>console.warn(chalk, '-', message)
19
20
  );
20
21
  }
22
+ function dim(input) {
23
+ return _chalk.default.dim(input);
24
+ }
21
25
  var _default = {
22
26
  info (key, messages) {
23
27
  log(_chalk.default.bold.cyan('info'), ...Array.isArray(key) ? [
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ exports.asClass = asClass;
5
6
  exports.default = nameClass;
6
7
  exports.formatClass = formatClass;
7
8
  var _escapeClassName = _interopRequireDefault(require("./escapeClassName"));
@@ -3,11 +3,29 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  exports.normalizeConfig = normalizeConfig;
6
- var _log = _interopRequireDefault(require("./log"));
7
- function _interopRequireDefault(obj) {
8
- return obj && obj.__esModule ? obj : {
9
- default: obj
10
- };
6
+ var _log = _interopRequireWildcard(require("./log"));
7
+ function _interopRequireWildcard(obj) {
8
+ if (obj && obj.__esModule) {
9
+ return obj;
10
+ } else {
11
+ var newObj = {
12
+ };
13
+ if (obj != null) {
14
+ for(var key in obj){
15
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
16
+ var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {
17
+ };
18
+ if (desc.get || desc.set) {
19
+ Object.defineProperty(newObj, key, desc);
20
+ } else {
21
+ newObj[key] = obj[key];
22
+ }
23
+ }
24
+ }
25
+ }
26
+ newObj.default = obj;
27
+ return newObj;
28
+ }
11
29
  }
12
30
  function normalizeConfig(config) {
13
31
  // Quick structure validation
@@ -204,5 +222,16 @@ function normalizeConfig(config) {
204
222
  return transformers;
205
223
  })()
206
224
  };
225
+ // Validate globs to prevent bogus globs.
226
+ // E.g.: `./src/*.{html}` is invalid, the `{html}` should just be `html`
227
+ for (let file of config.content.files){
228
+ if (typeof file === 'string' && /{([^,]*?)}/g.test(file)) {
229
+ _log.default.warn('invalid-glob-braces', [
230
+ `The glob pattern ${(0, _log).dim(file)} in your config is invalid.`,
231
+ ` Update it to ${(0, _log).dim(file.replace(/{([^,]*?)}/g, '$1'))} to silence this warning.`
232
+ ]);
233
+ break;
234
+ }
235
+ }
207
236
  return config;
208
237
  }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.normalizeScreens = normalizeScreens;
6
+ function normalizeScreens(screens, root = true) {
7
+ if (Array.isArray(screens)) {
8
+ return screens.map((screen)=>{
9
+ if (root && Array.isArray(screen)) {
10
+ throw new Error('The tuple syntax is not supported for `screens`.');
11
+ }
12
+ if (typeof screen === 'string') {
13
+ return {
14
+ name: screen.toString(),
15
+ values: [
16
+ {
17
+ min: screen,
18
+ max: undefined
19
+ }
20
+ ]
21
+ };
22
+ }
23
+ let [name, options] = screen;
24
+ name = name.toString();
25
+ if (typeof options === 'string') {
26
+ return {
27
+ name,
28
+ values: [
29
+ {
30
+ min: options,
31
+ max: undefined
32
+ }
33
+ ]
34
+ };
35
+ }
36
+ if (Array.isArray(options)) {
37
+ return {
38
+ name,
39
+ values: options.map((option)=>resolveValue(option)
40
+ )
41
+ };
42
+ }
43
+ return {
44
+ name,
45
+ values: [
46
+ resolveValue(options)
47
+ ]
48
+ };
49
+ });
50
+ }
51
+ return normalizeScreens(Object.entries(screens !== null && screens !== void 0 ? screens : {
52
+ }), false);
53
+ }
54
+ function resolveValue({ 'min-width': _minWidth , min =_minWidth , max , raw } = {
55
+ }) {
56
+ return {
57
+ min,
58
+ max,
59
+ raw
60
+ };
61
+ }
@@ -64,7 +64,7 @@ const configUtils = {
64
64
  });
65
65
  }
66
66
  };
67
- function value1(valueToResolve, ...args) {
67
+ function value(valueToResolve, ...args) {
68
68
  return isFunction(valueToResolve) ? valueToResolve(...args) : valueToResolve;
69
69
  }
70
70
  function collectExtends(items) {
@@ -99,21 +99,21 @@ function mergeThemes(themes) {
99
99
  extend: collectExtends(themes)
100
100
  };
101
101
  }
102
- function mergeExtensionCustomizer(merged, value) {
102
+ function mergeExtensionCustomizer(merged, value1) {
103
103
  // When we have an array of objects, we do want to merge it
104
104
  if (Array.isArray(merged) && isObject(merged[0])) {
105
- return merged.concat(value);
105
+ return merged.concat(value1);
106
106
  }
107
107
  // When the incoming value is an array, and the existing config is an object, prepend the existing object
108
- if (Array.isArray(value) && isObject(value[0]) && isObject(merged)) {
108
+ if (Array.isArray(value1) && isObject(value1[0]) && isObject(merged)) {
109
109
  return [
110
110
  merged,
111
- ...value
111
+ ...value1
112
112
  ];
113
113
  }
114
114
  // Override arrays (for example for font-families, box-shadows, ...)
115
- if (Array.isArray(value)) {
116
- return value;
115
+ if (Array.isArray(value1)) {
116
+ return value1;
117
117
  }
118
118
  // Execute default behaviour
119
119
  return undefined;
@@ -129,7 +129,7 @@ function mergeExtensions({ extend , ...theme }) {
129
129
  }, ...[
130
130
  themeValue,
131
131
  ...extensions
132
- ].map((e)=>value1(e, resolveThemePath, utils)
132
+ ].map((e)=>value(e, resolveThemePath, utils)
133
133
  ), mergeExtensionCustomizer)
134
134
  ;
135
135
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwindcss",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.3",
4
4
  "description": "A utility-first CSS framework for rapidly building custom user interfaces.",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -43,22 +43,22 @@
43
43
  "*.js"
44
44
  ],
45
45
  "devDependencies": {
46
- "@swc/cli": "^0.1.51",
47
- "@swc/core": "^1.2.106",
48
- "@swc/jest": "^0.1.5",
46
+ "@swc/cli": "^0.1.52",
47
+ "@swc/core": "^1.2.118",
48
+ "@swc/jest": "^0.2.11",
49
49
  "@swc/register": "^0.1.7",
50
50
  "autoprefixer": "^10.4.0",
51
51
  "cross-env": "^7.0.3",
52
- "cssnano": "^5.0.8",
53
- "esbuild": "^0.13.12",
54
- "eslint": "^8.0.1",
52
+ "cssnano": "^5.0.12",
53
+ "esbuild": "^0.14.2",
54
+ "eslint": "^8.4.1",
55
55
  "eslint-config-prettier": "^8.3.0",
56
56
  "eslint-plugin-prettier": "^4.0.0",
57
- "jest": "^27.3.1",
58
- "jest-diff": "^27.2.5",
59
- "postcss": "^8.3.11",
57
+ "jest": "^27.4.3",
58
+ "jest-diff": "^27.4.2",
59
+ "postcss": "^8.4.4",
60
60
  "postcss-cli": "^8.3.1",
61
- "prettier": "^2.4.1",
61
+ "prettier": "^2.5.0",
62
62
  "rimraf": "^3.0.0"
63
63
  },
64
64
  "peerDependencies": {
@@ -83,7 +83,7 @@
83
83
  "postcss-load-config": "^3.1.0",
84
84
  "postcss-nested": "5.0.6",
85
85
  "postcss-selector-parser": "^6.0.6",
86
- "postcss-value-parser": "^4.1.0",
86
+ "postcss-value-parser": "^4.2.0",
87
87
  "quick-lru": "^5.1.1",
88
88
  "resolve": "^1.20.0",
89
89
  "tmp": "^0.2.1"
@@ -101,7 +101,8 @@
101
101
  ],
102
102
  "testPathIgnorePatterns": [
103
103
  "/node_modules/",
104
- "/integrations/"
104
+ "/integrations/",
105
+ "/standalone-cli/"
105
106
  ],
106
107
  "transform": {
107
108
  "\\.js$": "@swc/jest"