UNPKG

aliascss

Version:

AliasCSS is a CSS post processor.

37 lines (36 loc) 1.6 kB
export default function extractMediaPrefix(className, prefix, match, bool = false) { var _a, _b, _c; const medias = []; let cls = className; const matchNestedMedia = /@\[(.*?)]/; // case 1. single media if (className.match(match)) { const prefixMedia = (_a = className.match(match)) === null || _a === void 0 ? void 0 : _a[0]; if (prefixMedia) { if (prefix.hasOwnProperty(prefixMedia)) { medias.push(prefix[prefixMedia]); cls = className.replace(prefixMedia, ''); // return [[], ] } } } else if (className.match(matchNestedMedia)) { // Nested Media Selector (_c = (_b = className.match(matchNestedMedia)) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c.split(',').map((e) => { var _a, _b; const suffixedMatch = e + "-"; if (suffixedMatch.match(match) || ("@" + suffixedMatch).match(match)) { const prefixMedia = ((_a = suffixedMatch.match(match)) === null || _a === void 0 ? void 0 : _a[0]) || ((_b = ('@' + suffixedMatch).match(match)) === null || _b === void 0 ? void 0 : _b[0]); if (prefixMedia) { if (prefix.hasOwnProperty(prefixMedia)) { medias.push(prefix[prefixMedia]); // return [[], ] } } } }); if (medias.length) { cls = className.replace(matchNestedMedia, ''); } } return [medias, cls]; }