UNPKG

svelte-preprocess

Version:

A Svelte preprocessor wrapper with baked in support for common used preprocessors

34 lines (33 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.globalifySelector = void 0; /* * Split a selector string (ex: div > foo ~ .potato) by * separators: space, >, +, ~ and comma (maybe not needed) * We use a negative lookbehind assertion to prevent matching * escaped combinators like `\~`. */ const combinatorPattern = /(?<!\\)(?:\\\\)*([ >+~,]\s*)(?![^[]+\])/g; function globalifySelector(selector) { const parts = selector.trim().split(combinatorPattern); const modifiedSelector = parts .map((selectorPart, index) => { // if this is the separator if (index % 2 !== 0) { return selectorPart; } if (selectorPart === '') { return selectorPart; } if (selectorPart.startsWith(':local')) { return selectorPart.replace(/:local\((.+?)\)/g, '$1'); } if (selectorPart.startsWith(':global')) { return selectorPart; } return `:global(${selectorPart})`; }) .join(''); return modifiedSelector; } exports.globalifySelector = globalifySelector;