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,preset-wind): add @supports variant unocss/unocss#1686
- Loading branch information
Showing
8 changed files
with
51 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { VariantContext, VariantObject } from '@unocss/core' | ||
import type { Theme } from '../theme' | ||
import { getComponent, handler as h } from '../utils' | ||
|
||
export const variantSupports: VariantObject = { | ||
name: 'supports', | ||
match(matcher, { theme }: VariantContext<Theme>) { | ||
if (matcher.startsWith('supports-')) { | ||
const matcherValue = matcher.substring(9) | ||
|
||
const [match, rest] = getComponent(matcherValue, '[', ']', ':') ?? [] | ||
if (!(match && rest && rest !== '')) | ||
return | ||
|
||
let supports = h.bracket(match) ?? '' | ||
if (supports === '') { | ||
const themeValue = theme.supports?.[match] | ||
if (themeValue) | ||
supports = themeValue | ||
} | ||
|
||
if (supports) { | ||
return { | ||
matcher: rest, | ||
handle: (input, next) => next({ | ||
...input, | ||
parent: `${input.parent ? `${input.parent} $$ ` : ''}@supports ${supports}`, | ||
}), | ||
} | ||
} | ||
} | ||
}, | ||
multiPass: true, | ||
} |
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
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