Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed May 8, 2022
1 parent 623718e commit 42296f2
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/lib/setupContextUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,30 @@ function withIdentifiers(styles) {
})
}

export function parseVariant(variant) {
variant = variant
.replace(/\n+/g, '')
.replace(/\s{1,}/g, ' ')
.trim()

let fns = parseVariantFormatString(variant)
.map((str) => {
if (!str.startsWith('@')) {
return ({ format }) => format(str)
}

let [, name, params] = /@(.*?) (.*)/g.exec(str)
return ({ wrap }) => wrap(postcss.atRule({ name, params }))
})
.reverse()

return (api) => {
for (let fn of fns) {
fn(api)
}
}
}

function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offsets, classList }) {
function getConfigValue(path, defaultValue) {
return path ? dlv(tailwindConfig, path, defaultValue) : tailwindConfig
Expand Down Expand Up @@ -201,27 +225,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
}
}

variantFunction = variantFunction
.replace(/\n+/g, '')
.replace(/\s{1,}/g, ' ')
.trim()

let fns = parseVariantFormatString(variantFunction)
.map((str) => {
if (!str.startsWith('@')) {
return ({ format }) => format(str)
}

let [, name, params] = /@(.*?) (.*)/g.exec(str)
return ({ wrap }) => wrap(postcss.atRule({ name, params }))
})
.reverse()

return (api) => {
for (let fn of fns) {
fn(api)
}
}
return parseVariant(variantFunction)
})

insertInto(variantList, variantName, options)
Expand Down

0 comments on commit 42296f2

Please sign in to comment.