unocss-preset-weapp
Version:
the unocss preset for wechat miniprogram (uniapp, taro)
55 lines (51 loc) • 1.62 kB
JavaScript
;
const core = require('@unocss/core');
const utils = require('unplugin-transform-class/utils');
function variantMatcher(name, handler, transformRules = utils.defaultRules) {
let re;
return {
name,
match(input, ctx) {
if (!re)
re = new RegExp(`^${core.escapeRegExp(name)}(?:${ctx.generator.config.separators.join("|")})`);
input = utils.cacheRestoreSelector(input, transformRules);
const match = input.match(re);
if (match) {
const matcher = input.slice(match[0].length);
const handlers = core.toArray(handler).map((handler2) => ({
matcher,
handle: (input2, next) => next({
...input2,
...handler2(input2)
})
}));
return handlers.length === 1 ? handlers[0] : handlers;
}
},
autocomplete: `${name}:`
};
}
function variantParentMatcher(name, parent, transformRules = utils.defaultRules) {
let re;
return {
name,
match(input, ctx) {
if (!re)
re = new RegExp(`^${core.escapeRegExp(name)}(?:${ctx.generator.config.separators.join("|")})`);
input = utils.cacheRestoreSelector(input, transformRules);
const match = input.match(re);
if (match) {
return {
matcher: input.slice(match[0].length),
handle: (input2, next) => next({
...input2,
parent: `${input2.parent ? `${input2.parent} $$ ` : ""}${parent}`
})
};
}
},
autocomplete: `${name}:`
};
}
exports.variantMatcher = variantMatcher;
exports.variantParentMatcher = variantParentMatcher;