Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(core): support passing array of tokens to generate()
  • Loading branch information
antfu committed Jul 2, 2022
1 parent 2d8f438 commit 0b2f3a8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/core/src/generator/index.ts
Expand Up @@ -123,7 +123,7 @@ export class UnoGenerator {
}

async generate(
input: string | Set<string> = '',
input: string | Set<string> | string[],
{
id,
scope,
Expand All @@ -132,9 +132,11 @@ export class UnoGenerator {
minify = false,
}: GenerateOptions = {},
): Promise<GenerateResult> {
const tokens = typeof input === 'string'
const tokens: Readonly<Set<string>> = typeof input === 'string'
? await this.applyExtractors(input, id)
: input
: Array.isArray(input)
? new Set(input)
: input

if (safelist)
this.config.safelist.forEach(s => tokens.add(s))
Expand Down Expand Up @@ -247,11 +249,11 @@ export class UnoGenerator {
}

const selectors = selectorSortPair
? [...new Set(selectorSortPair
.sort((a, b) => a[1] - b[1] || a[0]?.localeCompare(b[0] || '') || 0)
.map(pair => pair[0])
.filter(Boolean),
)]
? uniq(selectorSortPair
.sort((a, b) => a[1] - b[1] || a[0]?.localeCompare(b[0] || '') || 0)
.map(pair => pair[0])
.filter(Boolean),
)
: []

return selectors.length
Expand Down Expand Up @@ -338,7 +340,7 @@ export class UnoGenerator {
return [raw, processed, handlers, variants]
}

applyVariants(parsed: ParsedUtil, variantHandlers = parsed[4], raw = parsed[1]): UtilObject {
private applyVariants(parsed: ParsedUtil, variantHandlers = parsed[4], raw = parsed[1]): UtilObject {
const handler = [...variantHandlers]
.sort((a, b) => (a.order || 0) - (b.order || 0))
.reverse()
Expand Down

0 comments on commit 0b2f3a8

Please sign in to comment.