'use strict';
const LayerCache = require('./lib/layerCache');
function pluginCreator(opts = {}) {
return {
postcssPlugin: 'postcss-zindex',
prepare() {
const cache = new LayerCache();
return {
OnceExit(css) {
const nodes = [];
let abort = false;
css.walkDecls(/z-index/i, (decl) => {
if (decl.value[0] === '-') {
abort = true;
return false;
}
nodes.push(decl);
cache.addValue(decl.value);
});
if (abort || !nodes.length) {
return;
}
cache.optimizeValues(opts.startIndex || 1);
nodes.forEach((decl) => {
decl.value = cache.getValue(decl.value).toString();
});
},
};
},
};
}
pluginCreator.postcss = true;
module.exports = pluginCreator;