-
-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(preset-mini): update/add variants-[x] that target x as raw selec…
…tor (#568)
- Loading branch information
1 parent
e634e9d
commit 7301214
Showing
4 changed files
with
59 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
import type { Variant } from '@unocss/core' | ||
import type { Variant, VariantHandler } from '@unocss/core' | ||
import { variantMatcher } from '../utils' | ||
|
||
const scopeMatcher = (strict: boolean, name: string, template: string) => { | ||
const re = strict | ||
? new RegExp(`^${name}(?:-\\[(.+?)\\])[:-]`) | ||
: new RegExp(`^${name}(?:-\\[(.+?)\\])?[:-]`) | ||
return (matcher: string): VariantHandler | undefined => { | ||
const match = matcher.match(re) | ||
if (match) { | ||
return { | ||
matcher: matcher.slice(match[0].length), | ||
selector: s => template.replace('&&-s', s).replace('&&-c', match[1] ?? '*'), | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const variantCombinators: Variant[] = [ | ||
variantMatcher('all', input => `${input} *`), | ||
variantMatcher('children', input => `${input}>*`), | ||
variantMatcher('next', input => `${input}+*`), | ||
variantMatcher('sibling', input => `${input}+*`), | ||
variantMatcher('siblings', input => `${input}~*`), | ||
scopeMatcher(false, 'all', '&&-s &&-c'), | ||
scopeMatcher(false, 'children', '&&-s>&&-c'), | ||
scopeMatcher(false, 'next', '&&-s+&&-c'), | ||
scopeMatcher(false, 'sibling', '&&-s+&&-c'), | ||
scopeMatcher(false, 'siblings', '&&-s~&&-c'), | ||
scopeMatcher(true, 'group', '&&-c &&-s'), | ||
scopeMatcher(true, 'parent', '&&-c>&&-s'), | ||
scopeMatcher(true, 'previous', '&&-c+&&-s'), | ||
scopeMatcher(true, 'peer', '&&-c~&&-s'), | ||
variantMatcher('svg', input => `${input} svg`), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters