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): add container query syntax (#1821)
- Loading branch information
1 parent
1388275
commit ce59126
Showing
20 changed files
with
130 additions
and
24 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Rule } from '@unocss/core' | ||
import { warnOnce } from '@unocss/core' | ||
|
||
export const containerParent: Rule[] = [ | ||
[/^@container(?:\/(\w+))?(?:-(normal))?$/, ([, l, v]) => { | ||
warnOnce('The container query rule is experimental and may not follow semver.') | ||
|
||
return { | ||
'container-type': v ?? 'inline-size', | ||
'container-name': l, | ||
} | ||
}], | ||
] |
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
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
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,39 @@ | ||
import type { VariantContext, VariantObject } from '@unocss/core' | ||
import { warnOnce } from '@unocss/core' | ||
import type { Theme } from '../theme' | ||
import { handler as h, variantGetParameter } from '../utils' | ||
|
||
export const variantContainerQuery: VariantObject = { | ||
name: '@', | ||
match(matcher, { theme }: VariantContext<Theme>) { | ||
if (matcher.startsWith('@container')) | ||
return | ||
|
||
const variant = variantGetParameter('@', matcher, [':', '-']) | ||
if (variant) { | ||
const [match, rest, label] = variant | ||
const unbracket = h.bracket(match) | ||
let container: string | undefined | ||
if (unbracket) { | ||
const minWidth = h.numberWithUnit(unbracket) | ||
if (minWidth) | ||
container = `(min-width: ${minWidth})` | ||
} | ||
else { | ||
container = theme.containers?.[match] ?? '' | ||
} | ||
|
||
if (container) { | ||
warnOnce('The container query variant is experimental and may not follow semver.') | ||
return { | ||
matcher: rest, | ||
handle: (input, next) => next({ | ||
...input, | ||
parent: `${input.parent ? `${input.parent} $$ ` : ''}@container${label ? ` ${label} ` : ' '}${container}`, | ||
}), | ||
} | ||
} | ||
} | ||
}, | ||
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
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
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