UNPKG

caniemail

Version:

HTML and CSS Feature Support for Email Clients from caniemail.com

101 lines 3.58 kB
import * as CSSWhat from 'css-what'; import { SelectorType } from 'css-what'; import { getFeatures } from './features.js'; import { fromTitleEntries, getTitleMatches } from './helpers.js'; const features = getFeatures().css; const keys = [...features.keys()]; export const selectorDetectorsMap = { 'Adjacent sibling combinator': (selectors) => { for (const selector of selectors) { if (selector.some((s) => s.type === SelectorType.Adjacent)) return true; } return false; }, 'Attribute selector': (selectors) => { for (const selector of selectors) { if (selector.some((s) => s.type === SelectorType.Attribute && s.name !== 'id' && s.name !== 'class')) { return true; } } return false; }, 'Chaining selectors': (selectors) => { for (const selector of selectors) { if (selector.filter((s) => s.type === SelectorType.Attribute && s.name === 'class').length >= 2) { return true; } } return false; }, 'Child combinator': (selectors) => { for (const selector of selectors) { if (selector.some((s) => s.type === SelectorType.Child)) return true; } return false; }, 'Class selector': (selectors) => { for (const selector of selectors) { if (selector.some((s) => s.type === SelectorType.Attribute && s.name === 'class')) { return true; } } return false; }, 'Descendant combinator': (selectors) => { for (const selector of selectors) { if (selector.some((s) => s.type === SelectorType.Descendant)) return true; } return false; }, 'General sibling combinator': (selectors) => { for (const selector of selectors) { if (selector.some((s) => s.type === SelectorType.Sibling)) { return true; } } return false; }, 'Grouping selectors': (selectors) => selectors.length >= 2, 'ID selector': (selectors) => { for (const selector of selectors) { if (selector.some((s) => s.type === SelectorType.Attribute && s.name === 'id')) { return true; } } return false; }, 'Type selector': (selectors) => { for (const selector of selectors) { if (selector.some((s) => s.type === SelectorType.Tag)) return true; } return false; }, 'Universal selector *': (selectors) => { for (const selector of selectors) { if (selector.some((s) => s.type === SelectorType.Universal)) { return true; } } return false; } }; export const psuedoSelectorTitles = fromTitleEntries(keys.map((title) => { if (!title.startsWith(':')) return void 0; return { title, value: title }; })); export const selectorTitles = fromTitleEntries(keys.map((title) => { if (selectorDetectorsMap[title] === void 0) return void 0; return { title, value: selectorDetectorsMap[title] }; })); export const getMatchingSelectorTitles = ({ selector }) => { const parsedSelectors = CSSWhat.parse(selector); return getTitleMatches(selectorTitles, selector, (tester) => tester(parsedSelectors)); }; export const getMatchingPseudoSelectorTitles = ({ selector }) => getTitleMatches(psuedoSelectorTitles, selector); //# sourceMappingURL=selectors.js.map