tailwindcss 3.0.0-alpha.2 → 3.0.0

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 (42) hide show
  1. package/lib/cli.js +58 -58
  2. package/lib/corePluginList.js +3 -0
  3. package/lib/corePlugins.js +138 -65
  4. package/lib/css/preflight.css +2 -1
  5. package/lib/lib/detectNesting.js +17 -2
  6. package/lib/lib/evaluateTailwindFunctions.js +6 -2
  7. package/lib/lib/expandApplyAtRules.js +4 -4
  8. package/lib/lib/expandTailwindAtRules.js +2 -0
  9. package/lib/lib/generateRules.js +36 -0
  10. package/lib/lib/setupContextUtils.js +8 -65
  11. package/lib/lib/substituteScreenAtRules.js +7 -4
  12. package/lib/util/buildMediaQuery.js +13 -24
  13. package/lib/util/dataTypes.js +14 -3
  14. package/lib/util/formatVariantSelector.js +88 -4
  15. package/lib/util/isValidArbitraryValue.js +64 -0
  16. package/lib/util/nameClass.js +1 -0
  17. package/lib/util/normalizeScreens.js +61 -0
  18. package/lib/util/resolveConfig.js +8 -8
  19. package/package.json +10 -10
  20. package/peers/.svgo.yml +75 -0
  21. package/peers/index.js +3784 -3146
  22. package/peers/orders/concentric-css.json +299 -0
  23. package/peers/orders/smacss.json +299 -0
  24. package/peers/orders/source.json +295 -0
  25. package/src/.DS_Store +0 -0
  26. package/src/corePluginList.js +1 -1
  27. package/src/corePlugins.js +114 -60
  28. package/src/css/preflight.css +2 -1
  29. package/src/lib/detectNesting.js +22 -3
  30. package/src/lib/evaluateTailwindFunctions.js +5 -2
  31. package/src/lib/expandTailwindAtRules.js +2 -0
  32. package/src/lib/generateRules.js +34 -0
  33. package/src/lib/setupContextUtils.js +6 -58
  34. package/src/lib/substituteScreenAtRules.js +6 -3
  35. package/src/util/buildMediaQuery.js +14 -18
  36. package/src/util/dataTypes.js +11 -6
  37. package/src/util/formatVariantSelector.js +92 -1
  38. package/src/util/isValidArbitraryValue.js +61 -0
  39. package/src/util/nameClass.js +1 -1
  40. package/src/util/normalizeScreens.js +45 -0
  41. package/stubs/defaultConfig.stub.js +17 -0
  42. package/CHANGELOG.md +0 -1825
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  exports.default = _default;
6
+ var _normalizeScreens = require("../util/normalizeScreens");
6
7
  var _buildMediaQuery = _interopRequireDefault(require("../util/buildMediaQuery"));
7
8
  function _interopRequireDefault(obj) {
8
9
  return obj && obj.__esModule ? obj : {
@@ -12,13 +13,15 @@ function _interopRequireDefault(obj) {
12
13
  function _default({ tailwindConfig: { theme } }) {
13
14
  return function(css) {
14
15
  css.walkAtRules('screen', (atRule)=>{
15
- var ref, ref1;
16
- const screen = atRule.params;
17
- if (!((ref = theme.screens) === null || ref === void 0 ? void 0 : (ref1 = ref.hasOwnProperty) === null || ref1 === void 0 ? void 0 : ref1.call(ref, screen))) {
16
+ let screen = atRule.params;
17
+ let screens = (0, _normalizeScreens).normalizeScreens(theme.screens);
18
+ let screenDefinition = screens.find(({ name })=>name === screen
19
+ );
20
+ if (!screenDefinition) {
18
21
  throw atRule.error(`No \`${screen}\` screen found.`);
19
22
  }
20
23
  atRule.name = 'media';
21
- atRule.params = (0, _buildMediaQuery).default(theme.screens[screen]);
24
+ atRule.params = (0, _buildMediaQuery).default(screenDefinition);
22
25
  });
23
26
  };
24
27
  }
@@ -4,28 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  exports.default = buildMediaQuery;
6
6
  function buildMediaQuery(screens) {
7
- if (typeof screens === 'string') {
8
- screens = {
9
- min: screens
10
- };
11
- }
12
- if (!Array.isArray(screens)) {
13
- screens = [
14
- screens
15
- ];
16
- }
17
- return screens.map((screen)=>{
18
- var ref;
19
- if (screen === null || screen === void 0 ? void 0 : (ref = screen.hasOwnProperty) === null || ref === void 0 ? void 0 : ref.call(screen, 'raw')) {
20
- return screen.raw;
21
- }
22
- return Object.entries(screen).map(([feature, value])=>{
23
- var _feature;
24
- feature = (_feature = ({
25
- min: 'min-width',
26
- max: 'max-width'
27
- })[feature]) !== null && _feature !== void 0 ? _feature : feature;
28
- return `(${feature}: ${value})`;
29
- }).join(' and ');
30
- }).join(', ');
7
+ screens = Array.isArray(screens) ? screens : [
8
+ screens
9
+ ];
10
+ return screens.map((screen1)=>screen1.values.map((screen)=>{
11
+ if (screen.raw !== undefined) {
12
+ return screen.raw;
13
+ }
14
+ return [
15
+ screen.min && `(min-width: ${screen.min})`,
16
+ screen.max && `(max-width: ${screen.max})`,
17
+ ].filter(Boolean).join(' and ');
18
+ })
19
+ ).join(', ');
31
20
  }
@@ -19,6 +19,12 @@ exports.absoluteSize = absoluteSize;
19
19
  exports.relativeSize = relativeSize;
20
20
  var _color = require("./color");
21
21
  var _parseBoxShadowValue = require("./parseBoxShadowValue");
22
+ let cssFunctions = [
23
+ 'min',
24
+ 'max',
25
+ 'clamp',
26
+ 'calc'
27
+ ];
22
28
  // Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types
23
29
  let COMMA = /,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
24
30
  ;
@@ -49,10 +55,12 @@ function url(value) {
49
55
  return value.startsWith('url(');
50
56
  }
51
57
  function number(value) {
52
- return !isNaN(Number(value));
58
+ return !isNaN(Number(value)) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?`).test(value)
59
+ );
53
60
  }
54
61
  function percentage(value) {
55
- return /%$/g.test(value) || /^calc\(.+?%\)/g.test(value);
62
+ return /%$/g.test(value) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?%`).test(value)
63
+ );
56
64
  }
57
65
  let lengthUnits = [
58
66
  'cm',
@@ -74,7 +82,10 @@ let lengthUnits = [
74
82
  ];
75
83
  let lengthUnitsPattern = `(?:${lengthUnits.join('|')})`;
76
84
  function length(value) {
77
- return new RegExp(`${lengthUnitsPattern}$`).test(value) || new RegExp(`^calc\\(.+?${lengthUnitsPattern}`).test(value);
85
+ return value.split(UNDERSCORE).every((part)=>{
86
+ return part === '0' || new RegExp(`${lengthUnitsPattern}$`).test(part) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?${lengthUnitsPattern}`).test(part)
87
+ );
88
+ });
78
89
  }
79
90
  let lineWidths = new Set([
80
91
  'thin',
@@ -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
+ }
@@ -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"));
@@ -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.0",
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",
46
+ "@swc/cli": "^0.1.52",
47
+ "@swc/core": "^1.2.118",
48
48
  "@swc/jest": "^0.1.5",
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",
52
+ "cssnano": "^5.0.12",
53
53
  "esbuild": "^0.13.12",
54
- "eslint": "^8.0.1",
54
+ "eslint": "^8.2.0",
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"
@@ -0,0 +1,75 @@
1
+ # replace default config
2
+
3
+ # multipass: true
4
+ # full: true
5
+
6
+ plugins:
7
+
8
+ # - name
9
+ #
10
+ # or:
11
+ # - name: false
12
+ # - name: true
13
+ #
14
+ # or:
15
+ # - name:
16
+ # param1: 1
17
+ # param2: 2
18
+
19
+ - removeDoctype
20
+ - removeXMLProcInst
21
+ - removeComments
22
+ - removeMetadata
23
+ - removeXMLNS
24
+ - removeEditorsNSData
25
+ - cleanupAttrs
26
+ - inlineStyles
27
+ - minifyStyles
28
+ - convertStyleToAttrs
29
+ - cleanupIDs
30
+ - prefixIds
31
+ - removeRasterImages
32
+ - removeUselessDefs
33
+ - cleanupNumericValues
34
+ - cleanupListOfValues
35
+ - convertColors
36
+ - removeUnknownsAndDefaults
37
+ - removeNonInheritableGroupAttrs
38
+ - removeUselessStrokeAndFill
39
+ - removeViewBox
40
+ - cleanupEnableBackground
41
+ - removeHiddenElems
42
+ - removeEmptyText
43
+ - convertShapeToPath
44
+ - convertEllipseToCircle
45
+ - moveElemsAttrsToGroup
46
+ - moveGroupAttrsToElems
47
+ - collapseGroups
48
+ - convertPathData
49
+ - convertTransform
50
+ - removeEmptyAttrs
51
+ - removeEmptyContainers
52
+ - mergePaths
53
+ - removeUnusedNS
54
+ - sortAttrs
55
+ - sortDefsChildren
56
+ - removeTitle
57
+ - removeDesc
58
+ - removeDimensions
59
+ - removeAttrs
60
+ - removeAttributesBySelector
61
+ - removeElementsByAttr
62
+ - addClassesToSVGElement
63
+ - removeStyleElement
64
+ - removeScriptElement
65
+ - addAttributesToSVGElement
66
+ - removeOffCanvasPaths
67
+ - reusePaths
68
+
69
+ # configure the indent (default 4 spaces) used by `--pretty` here:
70
+ #
71
+ # @see https://github.com/svg/svgo/blob/master/lib/svgo/js2svg.js#L6 for more config options
72
+ #
73
+ # js2svg:
74
+ # pretty: true
75
+ # indent: ' '