UNPKG

unocss-preset-weapp

Version:

the unocss preset for wechat miniprogram (uniapp, taro)

52 lines (49 loc) 1.58 kB
import { escapeRegExp, toArray } from '@unocss/core'; import { defaultRules, cacheRestoreSelector } from 'unplugin-transform-class/utils'; function variantMatcher(name, handler, transformRules = defaultRules) { let re; return { name, match(input, ctx) { if (!re) re = new RegExp(`^${escapeRegExp(name)}(?:${ctx.generator.config.separators.join("|")})`); input = cacheRestoreSelector(input, transformRules); const match = input.match(re); if (match) { const matcher = input.slice(match[0].length); const handlers = 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 = defaultRules) { let re; return { name, match(input, ctx) { if (!re) re = new RegExp(`^${escapeRegExp(name)}(?:${ctx.generator.config.separators.join("|")})`); input = 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}:` }; } export { variantParentMatcher as a, variantMatcher as v };