Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(preset-wind): support bg position #1001

Merged
merged 2 commits into from May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/preset-mini/src/utils/handlers/handlers.ts
Expand Up @@ -97,7 +97,7 @@ function bracketWithType(str: string, type?: string) {
if (str && str.startsWith('[') && str.endsWith(']')) {
let base: string | undefined

const match = str.match(/^\[(color|length):/i)
const match = str.match(new RegExp(`^\\[\(${type}\):`, 'i'))
zyyv marked this conversation as resolved.
Show resolved Hide resolved
if (!match)
base = str.slice(1, -1)
else if (type && match[1] === type)
Expand Down Expand Up @@ -126,6 +126,10 @@ export function bracketOfLength(str: string) {
return bracketWithType(str, 'length')
}

export function bracketOfPosition(str: string) {
return bracketWithType(str, 'position')
}

export function cssvar(str: string) {
if (str.match(/^\$\S/))
return `var(--${escapeSelector(str.slice(1))})`
Expand Down
2 changes: 2 additions & 0 deletions packages/preset-wind/src/rules/background.ts
Expand Up @@ -45,6 +45,8 @@ export const backgroundStyles: Rule[] = [
return { '--un-url': `${h.bracket(d)}`, 'background-image': 'var(--un-url)' }
else if (/^\[length:(.+)\]$/.test(d) && h.bracketOfLength(d) != null)
return { 'background-size': h.bracketOfLength(d)!.split(' ').map(e => h.fraction.auto.px.cssvar(e)).join(' ') }
else if (/^\[position:(.+)\]$/.test(d) && h.bracketOfPosition(d) != null)
return { 'background-position': h.bracketOfPosition(d)!.split(' ').map(e => h.fraction.auto.px.cssvar(e)).join(' ') }
}],

// gradients
Expand Down
3 changes: 3 additions & 0 deletions test/__snapshots__/preset-wind.test.ts.snap
Expand Up @@ -187,7 +187,10 @@ exports[`preset-wind > targets 1`] = `
.overscroll-none{overscroll-behavior:none;}
.overscroll-x-auto{overscroll-behavior-x:auto;}
.scroll-auto{scroll-behavior:auto;}
.bg-\\\\[length\\\\:1\\\\/2_20rem\\\\]{background-size:50% 20rem;}
.bg-\\\\[length\\\\:10_20rem\\\\]{background-size:10px 20rem;}
.bg-\\\\[position\\\\:1\\\\/2_20rem\\\\]{background-position:50% 20rem;}
.bg-\\\\[position\\\\:10_20rem\\\\]{background-position:10px 20rem;}
.bg-gradient-\\\\[70deg\\\\,blue\\\\,pink\\\\]{--un-gradient:70deg,blue,pink;}
.bg-gradient-stops-\\\\[blue\\\\,pink\\\\],
.stops-\\\\[blue\\\\,pink\\\\]{--un-gradient-stops:blue,pink;}
Expand Down
3 changes: 3 additions & 0 deletions test/assets/preset-wind-targets.ts
Expand Up @@ -61,6 +61,9 @@ export const presetWindTargets: string[] = [
'bg-right-bottom',
'bg-scroll',
'bg-[length:10_20rem]',
'bg-[length:1/2_20rem]',
'bg-[position:10_20rem]',
'bg-[position:1/2_20rem]',

// bg gradient
'from-current',
Expand Down