数通智联化工云平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
746 B

2 years ago
'use strict';
const styleSearch = require('style-search');
const rangeOperators = ['>=', '<=', '>', '<', '='];
/** @typedef {import('style-search').StyleSearchMatch} StyleSearchMatch */
/**
* @template {import('postcss').AtRule} T
* @param {T} atRule
* @param {(match: StyleSearchMatch, params: string, atRule: T) => void} cb
*/
module.exports = function findMediaOperator(atRule, cb) {
if (atRule.name.toLowerCase() !== 'media') {
return;
}
const params = atRule.raws.params ? atRule.raws.params.raw : atRule.params;
styleSearch({ source: params, target: rangeOperators }, (match) => {
const before = params[match.startIndex - 1];
if (before === '>' || before === '<') {
return;
}
cb(match, params, atRule);
});
};