tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cab1fce

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 (148) hide show
  1. package/CHANGELOG.md +380 -1
  2. package/LICENSE +1 -2
  3. package/README.md +8 -4
  4. package/colors.d.ts +3 -0
  5. package/colors.js +2 -1
  6. package/defaultConfig.d.ts +3 -0
  7. package/defaultConfig.js +2 -1
  8. package/defaultTheme.d.ts +3 -0
  9. package/defaultTheme.js +2 -1
  10. package/lib/cli-peer-dependencies.js +10 -5
  11. package/lib/cli.js +311 -213
  12. package/lib/constants.js +9 -9
  13. package/lib/corePluginList.js +11 -1
  14. package/lib/corePlugins.js +1895 -1773
  15. package/lib/css/preflight.css +19 -13
  16. package/lib/featureFlags.js +22 -16
  17. package/lib/index.js +17 -8
  18. package/lib/lib/cacheInvalidation.js +69 -0
  19. package/lib/lib/collapseAdjacentRules.js +30 -14
  20. package/lib/lib/collapseDuplicateDeclarations.js +80 -0
  21. package/lib/lib/defaultExtractor.js +187 -0
  22. package/lib/lib/detectNesting.js +17 -2
  23. package/lib/lib/evaluateTailwindFunctions.js +40 -24
  24. package/lib/lib/expandApplyAtRules.js +414 -157
  25. package/lib/lib/expandTailwindAtRules.js +156 -151
  26. package/lib/lib/generateRules.js +402 -68
  27. package/lib/lib/getModuleDependencies.js +14 -14
  28. package/lib/lib/normalizeTailwindDirectives.js +45 -36
  29. package/lib/lib/partitionApplyAtRules.js +53 -0
  30. package/lib/lib/regex.js +53 -0
  31. package/lib/lib/resolveDefaultsAtRules.js +105 -90
  32. package/lib/lib/setupContextUtils.js +416 -291
  33. package/lib/lib/setupTrackingContext.js +60 -56
  34. package/lib/lib/sharedState.js +38 -15
  35. package/lib/lib/substituteScreenAtRules.js +9 -6
  36. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  37. package/lib/postcss-plugins/nesting/index.js +17 -0
  38. package/lib/postcss-plugins/nesting/plugin.js +85 -0
  39. package/lib/processTailwindFeatures.js +21 -9
  40. package/lib/public/colors.js +244 -248
  41. package/lib/public/resolve-config.js +5 -5
  42. package/lib/util/buildMediaQuery.js +13 -24
  43. package/lib/util/cloneDeep.js +1 -1
  44. package/lib/util/cloneNodes.js +12 -1
  45. package/lib/util/color.js +43 -32
  46. package/lib/util/createPlugin.js +1 -2
  47. package/lib/util/createUtilityPlugin.js +13 -17
  48. package/lib/util/dataTypes.js +114 -74
  49. package/lib/util/defaults.js +6 -0
  50. package/lib/util/escapeClassName.js +5 -5
  51. package/lib/util/escapeCommas.js +1 -1
  52. package/lib/util/flattenColorPalette.js +2 -4
  53. package/lib/util/formatVariantSelector.js +194 -0
  54. package/lib/util/getAllConfigs.js +13 -5
  55. package/lib/util/hashConfig.js +5 -5
  56. package/lib/util/isKeyframeRule.js +1 -1
  57. package/lib/util/isPlainObject.js +1 -1
  58. package/lib/util/isValidArbitraryValue.js +64 -0
  59. package/lib/util/log.js +35 -19
  60. package/lib/util/nameClass.js +7 -6
  61. package/lib/util/negateValue.js +5 -3
  62. package/lib/util/normalizeConfig.js +233 -0
  63. package/lib/util/normalizeScreens.js +59 -0
  64. package/lib/util/parseAnimationValue.js +56 -56
  65. package/lib/util/parseBoxShadowValue.js +76 -0
  66. package/lib/util/parseDependency.js +32 -32
  67. package/lib/util/parseObjectStyles.js +6 -6
  68. package/lib/util/pluginUtils.js +67 -170
  69. package/lib/util/prefixSelector.js +4 -7
  70. package/lib/util/resolveConfig.js +123 -133
  71. package/lib/util/resolveConfigPath.js +17 -18
  72. package/lib/util/responsive.js +6 -6
  73. package/lib/util/splitAtTopLevelOnly.js +72 -0
  74. package/lib/util/toColorValue.js +1 -2
  75. package/lib/util/toPath.js +6 -1
  76. package/lib/util/transformThemeValue.js +42 -34
  77. package/lib/util/validateConfig.js +21 -0
  78. package/lib/util/withAlphaVariable.js +19 -19
  79. package/nesting/index.js +2 -12
  80. package/package.json +41 -42
  81. package/peers/index.js +11539 -10859
  82. package/plugin.d.ts +11 -0
  83. package/plugin.js +2 -1
  84. package/resolveConfig.js +2 -1
  85. package/scripts/create-plugin-list.js +2 -2
  86. package/scripts/generate-types.js +52 -0
  87. package/src/cli-peer-dependencies.js +7 -1
  88. package/src/cli.js +174 -41
  89. package/src/corePluginList.js +1 -1
  90. package/src/corePlugins.js +641 -596
  91. package/src/css/preflight.css +19 -13
  92. package/src/featureFlags.js +16 -10
  93. package/src/index.js +14 -6
  94. package/src/lib/cacheInvalidation.js +52 -0
  95. package/src/lib/collapseAdjacentRules.js +21 -2
  96. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  97. package/src/lib/defaultExtractor.js +192 -0
  98. package/src/lib/detectNesting.js +22 -3
  99. package/src/lib/evaluateTailwindFunctions.js +24 -7
  100. package/src/lib/expandApplyAtRules.js +442 -154
  101. package/src/lib/expandTailwindAtRules.js +91 -65
  102. package/src/lib/generateRules.js +409 -43
  103. package/src/lib/normalizeTailwindDirectives.js +10 -3
  104. package/src/lib/partitionApplyAtRules.js +52 -0
  105. package/src/lib/regex.js +74 -0
  106. package/src/lib/resolveDefaultsAtRules.js +74 -53
  107. package/src/lib/setupContextUtils.js +388 -208
  108. package/src/lib/setupTrackingContext.js +15 -12
  109. package/src/lib/sharedState.js +42 -7
  110. package/src/lib/substituteScreenAtRules.js +6 -3
  111. package/src/postcss-plugins/nesting/README.md +42 -0
  112. package/src/postcss-plugins/nesting/index.js +13 -0
  113. package/src/postcss-plugins/nesting/plugin.js +80 -0
  114. package/src/processTailwindFeatures.js +17 -2
  115. package/src/public/colors.js +4 -9
  116. package/src/util/buildMediaQuery.js +14 -18
  117. package/src/util/cloneNodes.js +14 -1
  118. package/src/util/color.js +31 -14
  119. package/src/util/createUtilityPlugin.js +2 -2
  120. package/src/util/dataTypes.js +56 -16
  121. package/src/util/defaults.js +6 -0
  122. package/src/util/formatVariantSelector.js +213 -0
  123. package/src/util/getAllConfigs.js +7 -0
  124. package/src/util/isValidArbitraryValue.js +61 -0
  125. package/src/util/log.js +23 -22
  126. package/src/util/nameClass.js +2 -2
  127. package/src/util/negateValue.js +4 -2
  128. package/src/util/normalizeConfig.js +262 -0
  129. package/src/util/normalizeScreens.js +45 -0
  130. package/src/util/parseBoxShadowValue.js +72 -0
  131. package/src/util/pluginUtils.js +51 -147
  132. package/src/util/prefixSelector.js +7 -8
  133. package/src/util/resolveConfig.js +108 -79
  134. package/src/util/splitAtTopLevelOnly.js +71 -0
  135. package/src/util/toPath.js +23 -1
  136. package/src/util/transformThemeValue.js +24 -7
  137. package/src/util/validateConfig.js +13 -0
  138. package/stubs/defaultConfig.stub.js +157 -94
  139. package/stubs/simpleConfig.stub.js +0 -1
  140. package/types/config.d.ts +325 -0
  141. package/types/generated/.gitkeep +0 -0
  142. package/types/generated/colors.d.ts +276 -0
  143. package/types/generated/corePluginList.d.ts +1 -0
  144. package/types/index.d.ts +1 -0
  145. package/types.d.ts +1 -0
  146. package/lib/lib/setupWatchingContext.js +0 -284
  147. package/nesting/plugin.js +0 -41
  148. package/src/lib/setupWatchingContext.js +0 -306
@@ -7,19 +7,6 @@ var _fs = _interopRequireDefault(require("fs"));
7
7
  var _path = _interopRequireDefault(require("path"));
8
8
  var _resolve = _interopRequireDefault(require("resolve"));
9
9
  var _detective = _interopRequireDefault(require("detective"));
10
- function _interopRequireDefault(obj) {
11
- return obj && obj.__esModule ? obj : {
12
- default: obj
13
- };
14
- }
15
- function createModule(file) {
16
- const source = _fs.default.readFileSync(file, 'utf-8');
17
- const requires = (0, _detective).default(source);
18
- return {
19
- file,
20
- requires
21
- };
22
- }
23
10
  function getModuleDependencies(entryFile) {
24
11
  const rootModule = createModule(entryFile);
25
12
  const modules = [
@@ -30,7 +17,7 @@ function getModuleDependencies(entryFile) {
30
17
  for (const mdl of modules){
31
18
  mdl.requires.filter((dep)=>{
32
19
  // Only track local modules, not node_modules
33
- return dep.startsWith('./') || dep.startsWith('../');
20
+ return dep.startsWith("./") || dep.startsWith("../");
34
21
  }).forEach((dep)=>{
35
22
  try {
36
23
  const basedir = _path.default.dirname(mdl.file);
@@ -46,3 +33,16 @@ function getModuleDependencies(entryFile) {
46
33
  }
47
34
  return modules;
48
35
  }
36
+ function _interopRequireDefault(obj) {
37
+ return obj && obj.__esModule ? obj : {
38
+ default: obj
39
+ };
40
+ }
41
+ function createModule(file) {
42
+ const source = _fs.default.readFileSync(file, "utf-8");
43
+ const requires = (0, _detective).default(source);
44
+ return {
45
+ file,
46
+ requires
47
+ };
48
+ }
@@ -4,72 +4,81 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  exports.default = normalizeTailwindDirectives;
6
6
  var _log = _interopRequireDefault(require("../util/log"));
7
- function _interopRequireDefault(obj) {
8
- return obj && obj.__esModule ? obj : {
9
- default: obj
10
- };
11
- }
12
7
  function normalizeTailwindDirectives(root) {
13
8
  let tailwindDirectives = new Set();
14
9
  let layerDirectives = new Set();
10
+ let applyDirectives = new Set();
15
11
  root.walkAtRules((atRule)=>{
16
- if (atRule.name === 'import') {
12
+ if (atRule.name === "apply") {
13
+ applyDirectives.add(atRule);
14
+ }
15
+ if (atRule.name === "import") {
17
16
  if (atRule.params === '"tailwindcss/base"' || atRule.params === "'tailwindcss/base'") {
18
- atRule.name = 'tailwind';
19
- atRule.params = 'base';
17
+ atRule.name = "tailwind";
18
+ atRule.params = "base";
20
19
  } else if (atRule.params === '"tailwindcss/components"' || atRule.params === "'tailwindcss/components'") {
21
- atRule.name = 'tailwind';
22
- atRule.params = 'components';
20
+ atRule.name = "tailwind";
21
+ atRule.params = "components";
23
22
  } else if (atRule.params === '"tailwindcss/utilities"' || atRule.params === "'tailwindcss/utilities'") {
24
- atRule.name = 'tailwind';
25
- atRule.params = 'utilities';
23
+ atRule.name = "tailwind";
24
+ atRule.params = "utilities";
26
25
  } 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';
26
+ atRule.name = "tailwind";
27
+ atRule.params = "variants";
29
28
  }
30
29
  }
31
- if (atRule.name === 'tailwind') {
32
- if (atRule.params === 'screens') {
33
- atRule.params = 'variants';
30
+ if (atRule.name === "tailwind") {
31
+ if (atRule.params === "screens") {
32
+ atRule.params = "variants";
34
33
  }
35
34
  tailwindDirectives.add(atRule.params);
36
35
  }
37
36
  if ([
38
- 'layer',
39
- 'responsive',
40
- 'variants'
37
+ "layer",
38
+ "responsive",
39
+ "variants"
41
40
  ].includes(atRule.name)) {
42
41
  if ([
43
- 'responsive',
44
- 'variants'
42
+ "responsive",
43
+ "variants"
45
44
  ].includes(atRule.name)) {
46
- _log.default.warn([
47
- `'@${atRule.name}' is deprecated, use '@layer utilities' or '@layer components' instead.`,
45
+ _log.default.warn(`${atRule.name}-at-rule-deprecated`, [
46
+ `The \`@${atRule.name}\` directive has been deprecated in Tailwind CSS v3.0.`,
47
+ `Use \`@layer utilities\` or \`@layer components\` instead.`,
48
+ "https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer",
48
49
  ]);
49
50
  }
50
51
  layerDirectives.add(atRule);
51
52
  }
52
53
  });
53
- if (!tailwindDirectives.has('base') || !tailwindDirectives.has('components') || !tailwindDirectives.has('utilities')) {
54
+ if (!tailwindDirectives.has("base") || !tailwindDirectives.has("components") || !tailwindDirectives.has("utilities")) {
54
55
  for (let rule of layerDirectives){
55
- if (rule.name === 'layer' && [
56
- 'base',
57
- 'components',
58
- 'utilities'
56
+ if (rule.name === "layer" && [
57
+ "base",
58
+ "components",
59
+ "utilities"
59
60
  ].includes(rule.params)) {
60
61
  if (!tailwindDirectives.has(rule.params)) {
61
62
  throw rule.error(`\`@layer ${rule.params}\` is used but no matching \`@tailwind ${rule.params}\` directive is present.`);
62
63
  }
63
- } else if (rule.name === 'responsive') {
64
- if (!tailwindDirectives.has('utilities')) {
65
- throw rule.error('`@responsive` is used but `@tailwind utilities` is missing.');
64
+ } else if (rule.name === "responsive") {
65
+ if (!tailwindDirectives.has("utilities")) {
66
+ throw rule.error("`@responsive` is used but `@tailwind utilities` is missing.");
66
67
  }
67
- } else if (rule.name === 'variants') {
68
- if (!tailwindDirectives.has('utilities')) {
69
- throw rule.error('`@variants` is used but `@tailwind utilities` is missing.');
68
+ } else if (rule.name === "variants") {
69
+ if (!tailwindDirectives.has("utilities")) {
70
+ throw rule.error("`@variants` is used but `@tailwind utilities` is missing.");
70
71
  }
71
72
  }
72
73
  }
73
74
  }
74
- return tailwindDirectives;
75
+ return {
76
+ tailwindDirectives,
77
+ applyDirectives
78
+ };
79
+ }
80
+ function _interopRequireDefault(obj) {
81
+ return obj && obj.__esModule ? obj : {
82
+ default: obj
83
+ };
75
84
  }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.default = expandApplyAtRules;
6
+ function expandApplyAtRules() {
7
+ return (root)=>{
8
+ partitionRules(root);
9
+ };
10
+ }
11
+ function partitionRules(root) {
12
+ if (!root.walkAtRules) return;
13
+ let applyParents = new Set();
14
+ root.walkAtRules("apply", (rule)=>{
15
+ applyParents.add(rule.parent);
16
+ });
17
+ if (applyParents.size === 0) {
18
+ return;
19
+ }
20
+ for (let rule1 of applyParents){
21
+ let nodeGroups = [];
22
+ let lastGroup = [];
23
+ for (let node of rule1.nodes){
24
+ if (node.type === "atrule" && node.name === "apply") {
25
+ if (lastGroup.length > 0) {
26
+ nodeGroups.push(lastGroup);
27
+ lastGroup = [];
28
+ }
29
+ nodeGroups.push([
30
+ node
31
+ ]);
32
+ } else {
33
+ lastGroup.push(node);
34
+ }
35
+ }
36
+ if (lastGroup.length > 0) {
37
+ nodeGroups.push(lastGroup);
38
+ }
39
+ if (nodeGroups.length === 1) {
40
+ continue;
41
+ }
42
+ for (let group of [
43
+ ...nodeGroups
44
+ ].reverse()){
45
+ let clone = rule1.clone({
46
+ nodes: []
47
+ });
48
+ clone.append(group);
49
+ rule1.after(clone);
50
+ }
51
+ rule1.remove();
52
+ }
53
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.pattern = pattern;
6
+ exports.withoutCapturing = withoutCapturing;
7
+ exports.any = any;
8
+ exports.optional = optional;
9
+ exports.zeroOrMore = zeroOrMore;
10
+ exports.nestedBrackets = nestedBrackets;
11
+ exports.escape = escape;
12
+ const REGEX_SPECIAL = /[\\^$.*+?()[\]{}|]/g;
13
+ const REGEX_HAS_SPECIAL = RegExp(REGEX_SPECIAL.source);
14
+ /**
15
+ * @param {string|RegExp|Array<string|RegExp>} source
16
+ */ function toSource(source) {
17
+ source = Array.isArray(source) ? source : [
18
+ source
19
+ ];
20
+ source = source.map((item)=>item instanceof RegExp ? item.source : item
21
+ );
22
+ return source.join("");
23
+ }
24
+ function pattern(source) {
25
+ return new RegExp(toSource(source), "g");
26
+ }
27
+ function withoutCapturing(source) {
28
+ return new RegExp(`(?:${toSource(source)})`, "g");
29
+ }
30
+ function any(sources) {
31
+ return `(?:${sources.map(toSource).join("|")})`;
32
+ }
33
+ function optional(source) {
34
+ return `(?:${toSource(source)})?`;
35
+ }
36
+ function zeroOrMore(source) {
37
+ return `(?:${toSource(source)})*`;
38
+ }
39
+ function nestedBrackets(open, close, depth = 1) {
40
+ return withoutCapturing([
41
+ escape(open),
42
+ /[^\s]*/,
43
+ depth === 1 ? `[^${escape(open)}${escape(close)}\s]*` : any([
44
+ `[^${escape(open)}${escape(close)}\s]*`,
45
+ nestedBrackets(open, close, depth - 1)
46
+ ]),
47
+ /[^\s]*/,
48
+ escape(close),
49
+ ]);
50
+ }
51
+ function escape(string) {
52
+ return string && REGEX_HAS_SPECIAL.test(string) ? string.replace(REGEX_SPECIAL, "\\$&") : string || "";
53
+ }
@@ -3,87 +3,15 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  exports.default = resolveDefaultsAtRules;
6
+ exports.elementSelectorParser = void 0;
6
7
  var _postcss = _interopRequireDefault(require("postcss"));
7
8
  var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
8
9
  var _featureFlags = require("../featureFlags");
9
- function _interopRequireDefault(obj) {
10
- return obj && obj.__esModule ? obj : {
11
- default: obj
12
- };
13
- }
14
- function isPseudoElement(n) {
15
- if (n.type !== 'pseudo') {
16
- return false;
17
- }
18
- return n.value.startsWith('::') || [
19
- ':before',
20
- ':after',
21
- ':first-line',
22
- ':first-letter'
23
- ].includes(n.value);
24
- }
25
- function minimumImpactSelector(nodes) {
26
- let rest = nodes// Keep all pseudo & combinator types (:not([hidden]) ~ :not([hidden]))
27
- .filter((n)=>n.type === 'pseudo' || n.type === 'combinator'
28
- )// Remove leading pseudo's (:hover, :focus, ...)
29
- .filter((n, idx, all)=>{
30
- // Keep pseudo elements
31
- if (isPseudoElement(n)) return true;
32
- if (idx === 0 && n.type === 'pseudo') return false;
33
- if (idx > 0 && n.type === 'pseudo' && all[idx - 1].type === 'pseudo') return false;
34
- return true;
35
- });
36
- let [bestNode] = nodes;
37
- for (let [type, getNode = (n)=>n
38
- ] of [
39
- [
40
- 'class'
41
- ],
42
- [
43
- 'id',
44
- (n)=>_postcssSelectorParser.default.attribute({
45
- attribute: 'id',
46
- operator: '=',
47
- value: n.value,
48
- quoteMark: '"'
49
- })
50
- ,
51
- ],
52
- [
53
- 'attribute'
54
- ],
55
- ]){
56
- let match = nodes.find((n)=>n.type === type
57
- );
58
- if (match) {
59
- bestNode = getNode(match);
60
- break;
61
- }
62
- }
63
- return [
64
- bestNode,
65
- ...rest
66
- ].join('').trim();
67
- }
68
- let elementSelectorParser = (0, _postcssSelectorParser).default((selectors)=>{
69
- return selectors.map((s)=>{
70
- let nodes = s.split((n)=>n.type === 'combinator' && n.value === ' '
71
- ).pop();
72
- return minimumImpactSelector(nodes);
73
- });
74
- });
75
- let cache = new Map();
76
- function extractElementSelector(selector) {
77
- if (!cache.has(selector)) {
78
- cache.set(selector, elementSelectorParser.transformSync(selector));
79
- }
80
- return cache.get(selector);
81
- }
82
10
  function resolveDefaultsAtRules({ tailwindConfig }) {
83
11
  return (root)=>{
84
12
  let variableNodeMap = new Map();
85
- let universals = new Set();
86
- root.walkAtRules('defaults', (rule)=>{
13
+ /** @type {Set<import('postcss').AtRule>} */ let universals = new Set();
14
+ root.walkAtRules("defaults", (rule)=>{
87
15
  if (rule.nodes && rule.nodes.length > 0) {
88
16
  universals.add(rule);
89
17
  return;
@@ -96,33 +24,120 @@ function resolveDefaultsAtRules({ tailwindConfig }) {
96
24
  rule.remove();
97
25
  });
98
26
  for (let universal of universals){
99
- let selectors = new Set();
27
+ /** @type {Map<string, Set<string>>} */ let selectorGroups = new Map();
100
28
  var ref;
101
29
  let rules = (ref = variableNodeMap.get(universal.params)) !== null && ref !== void 0 ? ref : [];
102
30
  for (let rule of rules){
103
31
  for (let selector of extractElementSelector(rule.selector)){
32
+ // If selector contains a vendor prefix after a pseudo element or class,
33
+ // we consider them separately because merging the declarations into
34
+ // a single rule will cause browsers that do not understand the
35
+ // vendor prefix to throw out the whole rule
36
+ let selectorGroupName = selector.includes(":-") || selector.includes("::-") ? selector : "__DEFAULT__";
37
+ var ref1;
38
+ let selectors = (ref1 = selectorGroups.get(selectorGroupName)) !== null && ref1 !== void 0 ? ref1 : new Set();
39
+ selectorGroups.set(selectorGroupName, selectors);
104
40
  selectors.add(selector);
105
41
  }
106
42
  }
107
- if (selectors.size === 0) {
108
- universal.remove();
109
- continue;
110
- }
111
- let universalRule = _postcss.default.rule();
112
- if ((0, _featureFlags).flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
113
- universalRule.selectors = [
114
- ...selectors
115
- ];
43
+ if ((0, _featureFlags).flagEnabled(tailwindConfig, "optimizeUniversalDefaults")) {
44
+ if (selectorGroups.size === 0) {
45
+ universal.remove();
46
+ continue;
47
+ }
48
+ for (let [, selectors] of selectorGroups){
49
+ let universalRule = _postcss.default.rule({
50
+ source: universal.source
51
+ });
52
+ universalRule.selectors = [
53
+ ...selectors
54
+ ];
55
+ universalRule.append(universal.nodes.map((node)=>node.clone()
56
+ ));
57
+ universal.before(universalRule);
58
+ }
116
59
  } else {
60
+ let universalRule = _postcss.default.rule({
61
+ source: universal.source
62
+ });
117
63
  universalRule.selectors = [
118
- '*',
119
- '::before',
120
- '::after'
64
+ "*",
65
+ "::before",
66
+ "::after"
121
67
  ];
68
+ universalRule.append(universal.nodes);
69
+ universal.before(universalRule);
122
70
  }
123
- universalRule.append(universal.nodes);
124
- universal.before(universalRule);
125
71
  universal.remove();
126
72
  }
127
73
  };
128
74
  }
75
+ function _interopRequireDefault(obj) {
76
+ return obj && obj.__esModule ? obj : {
77
+ default: obj
78
+ };
79
+ }
80
+ let getNode = {
81
+ id (node) {
82
+ return _postcssSelectorParser.default.attribute({
83
+ attribute: "id",
84
+ operator: "=",
85
+ value: node.value,
86
+ quoteMark: '"'
87
+ });
88
+ }
89
+ };
90
+ function minimumImpactSelector(nodes) {
91
+ let rest = nodes.filter((node)=>{
92
+ // Keep non-pseudo nodes
93
+ if (node.type !== "pseudo") return true;
94
+ // Keep pseudo nodes that have subnodes
95
+ // E.g.: `:not()` contains subnodes inside the parentheses
96
+ if (node.nodes.length > 0) return true;
97
+ // Keep pseudo `elements`
98
+ // This implicitly means that we ignore pseudo `classes`
99
+ return node.value.startsWith("::") || [
100
+ ":before",
101
+ ":after",
102
+ ":first-line",
103
+ ":first-letter"
104
+ ].includes(node.value);
105
+ }).reverse();
106
+ let searchFor = new Set([
107
+ "tag",
108
+ "class",
109
+ "id",
110
+ "attribute"
111
+ ]);
112
+ let splitPointIdx = rest.findIndex((n)=>searchFor.has(n.type)
113
+ );
114
+ if (splitPointIdx === -1) return rest.reverse().join("").trim();
115
+ let node1 = rest[splitPointIdx];
116
+ let bestNode = getNode[node1.type] ? getNode[node1.type](node1) : node1;
117
+ rest = rest.slice(0, splitPointIdx);
118
+ let combinatorIdx = rest.findIndex((n)=>n.type === "combinator" && n.value === ">"
119
+ );
120
+ if (combinatorIdx !== -1) {
121
+ rest.splice(0, combinatorIdx);
122
+ rest.unshift(_postcssSelectorParser.default.universal());
123
+ }
124
+ return [
125
+ bestNode,
126
+ ...rest.reverse()
127
+ ].join("").trim();
128
+ }
129
+ let elementSelectorParser = (0, _postcssSelectorParser).default((selectors)=>{
130
+ return selectors.map((s)=>{
131
+ let nodes = s.split((n)=>n.type === "combinator" && n.value === " "
132
+ ).pop();
133
+ return minimumImpactSelector(nodes);
134
+ });
135
+ });
136
+ exports.elementSelectorParser = elementSelectorParser;
137
+ let cache = new Map();
138
+ function extractElementSelector(selector) {
139
+ if (!cache.has(selector)) {
140
+ cache.set(selector, elementSelectorParser.transformSync(selector));
141
+ }
142
+ return cache.get(selector);
143
+ }