1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/postcss-prefix-selector/index.js

46 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
module.exports = function postcssPrefixSelector(options) {
const prefix = options.prefix;
const prefixWithSpace = /\s+$/.test(prefix) ? prefix : `${prefix} `;
return function(root) {
root.walkRules(rule => {
const keyframeRules = [
'keyframes',
'-webkit-keyframes',
'-moz-keyframes',
'-o-keyframes'
];
if (rule.parent && keyframeRules.includes(rule.parent.name)) {
return;
}
rule.selectors = rule.selectors.map(selector => {
if (options.exclude && excludeSelector(selector, options.exclude)) {
return selector;
}
if (options.transform) {
return options.transform(
prefix,
selector,
prefixWithSpace + selector
);
}
return prefixWithSpace + selector;
});
});
};
};
function excludeSelector(selector, excludeArr) {
return excludeArr.some(excludeRule => {
if (excludeRule instanceof RegExp) {
return excludeRule.test(selector);
}
return selector === excludeRule;
});
}