selectors.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. 'use strict';
  2. const htmlTags = require('html-tags');
  3. const uniteSets = require('../utils/uniteSets.js');
  4. const deprecatedHtmlTypeSelectors = new Set([
  5. 'acronym',
  6. 'applet',
  7. 'basefont',
  8. 'big',
  9. 'blink',
  10. 'center',
  11. 'content',
  12. 'dir',
  13. 'font',
  14. 'frame',
  15. 'frameset',
  16. 'hgroup',
  17. 'isindex',
  18. 'keygen',
  19. 'listing',
  20. 'marquee',
  21. 'nobr',
  22. 'noembed',
  23. 'plaintext',
  24. 'spacer',
  25. 'strike',
  26. 'tt',
  27. 'xmp',
  28. ]);
  29. // typecasting htmlTags to be more generic; see https://github.com/stylelint/stylelint/pull/6013 for discussion
  30. /** @type {Set<string>} */
  31. const standardHtmlTypeSelectors = new Set(htmlTags);
  32. const htmlTypeSelectors = uniteSets(deprecatedHtmlTypeSelectors, standardHtmlTypeSelectors);
  33. const mixedCaseSvgTypeSelectors = new Set([
  34. 'altGlyph',
  35. 'altGlyphDef',
  36. 'altGlyphItem',
  37. 'animateColor',
  38. 'animateMotion',
  39. 'animateTransform',
  40. 'clipPath',
  41. 'feBlend',
  42. 'feColorMatrix',
  43. 'feComponentTransfer',
  44. 'feComposite',
  45. 'feConvolveMatrix',
  46. 'feDiffuseLighting',
  47. 'feDisplacementMap',
  48. 'feDistantLight',
  49. 'feDropShadow',
  50. 'feFlood',
  51. 'feFuncA',
  52. 'feFuncB',
  53. 'feFuncG',
  54. 'feFuncR',
  55. 'feGaussianBlur',
  56. 'feImage',
  57. 'feMerge',
  58. 'feMergeNode',
  59. 'feMorphology',
  60. 'feOffset',
  61. 'fePointLight',
  62. 'feSpecularLighting',
  63. 'feSpotLight',
  64. 'feTile',
  65. 'feTurbulence',
  66. 'foreignObject',
  67. 'glyphRef',
  68. 'linearGradient',
  69. 'radialGradient',
  70. 'textPath',
  71. ]);
  72. // These are the ones that can have single-colon notation
  73. const levelOneAndTwoPseudoElements = new Set(['before', 'after', 'first-line', 'first-letter']);
  74. const shadowTreePseudoElements = new Set(['part']);
  75. const webkitScrollbarPseudoElements = new Set([
  76. '-webkit-resizer',
  77. '-webkit-scrollbar',
  78. '-webkit-scrollbar-button',
  79. '-webkit-scrollbar-corner',
  80. '-webkit-scrollbar-thumb',
  81. '-webkit-scrollbar-track',
  82. '-webkit-scrollbar-track-piece',
  83. ]);
  84. const vendorSpecificPseudoElements = uniteSets(webkitScrollbarPseudoElements, [
  85. '-moz-focus-inner',
  86. '-moz-focus-outer',
  87. '-moz-list-bullet',
  88. '-moz-meter-bar',
  89. '-moz-placeholder',
  90. '-moz-progress-bar',
  91. '-moz-range-progress',
  92. '-moz-range-thumb',
  93. '-moz-range-track',
  94. '-ms-browse',
  95. '-ms-check',
  96. '-ms-clear',
  97. '-ms-expand',
  98. '-ms-fill',
  99. '-ms-fill-lower',
  100. '-ms-fill-upper',
  101. '-ms-reveal',
  102. '-ms-thumb',
  103. '-ms-ticks-after',
  104. '-ms-ticks-before',
  105. '-ms-tooltip',
  106. '-ms-track',
  107. '-ms-value',
  108. '-webkit-color-swatch',
  109. '-webkit-color-swatch-wrapper',
  110. '-webkit-calendar-picker-indicator',
  111. '-webkit-clear-button',
  112. '-webkit-date-and-time-value',
  113. '-webkit-datetime-edit',
  114. '-webkit-datetime-edit-ampm-field',
  115. '-webkit-datetime-edit-day-field',
  116. '-webkit-datetime-edit-fields-wrapper',
  117. '-webkit-datetime-edit-hour-field',
  118. '-webkit-datetime-edit-millisecond-field',
  119. '-webkit-datetime-edit-minute-field',
  120. '-webkit-datetime-edit-month-field',
  121. '-webkit-datetime-edit-second-field',
  122. '-webkit-datetime-edit-text',
  123. '-webkit-datetime-edit-week-field',
  124. '-webkit-datetime-edit-year-field',
  125. '-webkit-details-marker',
  126. '-webkit-distributed',
  127. '-webkit-file-upload-button',
  128. '-webkit-input-placeholder',
  129. '-webkit-keygen-select',
  130. '-webkit-meter-bar',
  131. '-webkit-meter-even-less-good-value',
  132. '-webkit-meter-inner-element',
  133. '-webkit-meter-optimum-value',
  134. '-webkit-meter-suboptimum-value',
  135. '-webkit-progress-bar',
  136. '-webkit-progress-inner-element',
  137. '-webkit-progress-value',
  138. '-webkit-search-cancel-button',
  139. '-webkit-search-decoration',
  140. '-webkit-search-results-button',
  141. '-webkit-search-results-decoration',
  142. '-webkit-slider-runnable-track',
  143. '-webkit-slider-thumb',
  144. '-webkit-textfield-decoration-container',
  145. '-webkit-validation-bubble',
  146. '-webkit-validation-bubble-arrow',
  147. '-webkit-validation-bubble-arrow-clipper',
  148. '-webkit-validation-bubble-heading',
  149. '-webkit-validation-bubble-message',
  150. '-webkit-validation-bubble-text-block',
  151. ]);
  152. const pseudoElements = uniteSets(
  153. levelOneAndTwoPseudoElements,
  154. vendorSpecificPseudoElements,
  155. shadowTreePseudoElements,
  156. [
  157. 'backdrop',
  158. 'content',
  159. 'cue',
  160. 'file-selector-button',
  161. 'grammar-error',
  162. 'highlight',
  163. 'marker',
  164. 'placeholder',
  165. 'selection',
  166. 'shadow',
  167. 'slotted',
  168. 'spelling-error',
  169. 'target-text',
  170. ],
  171. );
  172. const aNPlusBNotationPseudoClasses = new Set([
  173. 'nth-column',
  174. 'nth-last-column',
  175. 'nth-last-of-type',
  176. 'nth-of-type',
  177. ]);
  178. const aNPlusBOfSNotationPseudoClasses = new Set(['nth-child', 'nth-last-child']);
  179. const atRulePagePseudoClasses = new Set(['first', 'right', 'left', 'blank']);
  180. const linguisticPseudoClasses = new Set(['dir', 'lang']);
  181. const logicalCombinationsPseudoClasses = new Set(['has', 'is', 'matches', 'not', 'where']);
  182. const vendorSpecificPseudoClasses = new Set([
  183. '-khtml-drag',
  184. '-moz-any',
  185. '-moz-any-link',
  186. '-moz-broken',
  187. '-moz-drag-over',
  188. '-moz-first-node',
  189. '-moz-focusring',
  190. '-moz-full-screen',
  191. '-moz-full-screen-ancestor',
  192. '-moz-last-node',
  193. '-moz-loading',
  194. '-moz-meter-optimum',
  195. '-moz-meter-sub-optimum',
  196. '-moz-meter-sub-sub-optimum',
  197. '-moz-placeholder',
  198. '-moz-submit-invalid',
  199. '-moz-suppressed',
  200. '-moz-ui-invalid',
  201. '-moz-ui-valid',
  202. '-moz-user-disabled',
  203. '-moz-window-inactive',
  204. '-ms-fullscreen',
  205. '-ms-input-placeholder',
  206. '-webkit-drag',
  207. '-webkit-any',
  208. '-webkit-any-link',
  209. '-webkit-autofill',
  210. '-webkit-full-screen',
  211. '-webkit-full-screen-ancestor',
  212. ]);
  213. // https://webkit.org/blog/363/styling-scrollbars/
  214. const webkitScrollbarPseudoClasses = new Set([
  215. 'horizontal',
  216. 'vertical',
  217. 'decrement',
  218. 'increment',
  219. 'start',
  220. 'end',
  221. 'double-button',
  222. 'single-button',
  223. 'no-button',
  224. 'corner-present',
  225. 'window-inactive',
  226. ]);
  227. const pseudoClasses = uniteSets(
  228. aNPlusBNotationPseudoClasses,
  229. linguisticPseudoClasses,
  230. logicalCombinationsPseudoClasses,
  231. aNPlusBOfSNotationPseudoClasses,
  232. vendorSpecificPseudoClasses,
  233. [
  234. 'active',
  235. 'any-link',
  236. 'autofill',
  237. 'blank',
  238. 'checked',
  239. 'current',
  240. 'default',
  241. 'defined',
  242. 'disabled',
  243. 'empty',
  244. 'enabled',
  245. 'first-child',
  246. 'first-of-type',
  247. 'focus',
  248. 'focus-within',
  249. 'focus-visible',
  250. 'fullscreen',
  251. 'fullscreen-ancestor',
  252. 'future',
  253. 'host',
  254. 'host-context',
  255. 'hover',
  256. 'indeterminate',
  257. 'in-range',
  258. 'invalid',
  259. 'last-child',
  260. 'last-of-type',
  261. 'link',
  262. 'only-child',
  263. 'only-of-type',
  264. 'optional',
  265. 'out-of-range',
  266. 'past',
  267. 'placeholder-shown',
  268. 'playing',
  269. 'picture-in-picture',
  270. 'paused',
  271. 'read-only',
  272. 'read-write',
  273. 'required',
  274. 'root',
  275. 'scope',
  276. 'state',
  277. 'target',
  278. 'unresolved',
  279. 'user-invalid',
  280. 'user-valid',
  281. 'valid',
  282. 'visited',
  283. 'window-inactive', // for ::selection (chrome)
  284. ],
  285. );
  286. module.exports = {
  287. aNPlusBNotationPseudoClasses,
  288. aNPlusBOfSNotationPseudoClasses,
  289. atRulePagePseudoClasses,
  290. levelOneAndTwoPseudoElements,
  291. linguisticPseudoClasses,
  292. logicalCombinationsPseudoClasses,
  293. mixedCaseSvgTypeSelectors,
  294. pseudoClasses,
  295. pseudoElements,
  296. shadowTreePseudoElements,
  297. htmlTypeSelectors,
  298. webkitScrollbarPseudoClasses,
  299. webkitScrollbarPseudoElements,
  300. };