Skip to content

Commit

Permalink
fix: bg-[url(xxx)] value
Browse files Browse the repository at this point in the history
  • Loading branch information
zguolee committed Aug 17, 2022
1 parent 897a8f3 commit 8d84443
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 120 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -30,7 +30,7 @@
"rimraf": "^3.0.2",
"typescript": "^4.7.4",
"unbuild": "^0.8.8",
"unocss": "^0.45.6",
"unocss": "^0.45.7",
"unocss-applet": "workspace:*",
"vite": "^2.9.15",
"vitest": "^0.21.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/preset-applet/package.json
Expand Up @@ -54,8 +54,8 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "0.45.6",
"@unocss/preset-mini": "0.45.6",
"@unocss/preset-wind": "0.45.6"
"@unocss/core": "0.45.7",
"@unocss/preset-mini": "0.45.7",
"@unocss/preset-wind": "0.45.7"
}
}
2 changes: 1 addition & 1 deletion packages/preset-rem-to-rpx/package.json
Expand Up @@ -37,6 +37,6 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "^0.45.6"
"@unocss/core": "^0.45.7"
}
}
2 changes: 1 addition & 1 deletion packages/transformer-rename-class/package.json
Expand Up @@ -35,7 +35,7 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "^0.45.6"
"@unocss/core": "^0.45.7"
},
"devDependencies": {
"magic-string": "^0.26.2"
Expand Down
7 changes: 4 additions & 3 deletions packages/transformer-rename-class/src/index.ts
Expand Up @@ -78,13 +78,13 @@ export default function transformerRenameClass(options: RenameClassOptions = {})
continue

const start = match.index!
const matchSplit = match[0].split('=')
const matchSplit = match[0].split('class=')

const body = expandVariantGroup(matchSplit[1].slice(1, -1), options.separators)

if (charReg.test(body)) {
const replacements = await compileApplet(body, ctx)
s.overwrite(start, start + match[0].length, `${matchSplit[0]}="${replacements.join(' ')}"`)
s.overwrite(start, start + match[0].length, `${matchSplit[0]}class="${replacements.join(' ')}"`)
}
}

Expand All @@ -95,12 +95,13 @@ export default function transformerRenameClass(options: RenameClassOptions = {})
if (/\$\{.*\}/g.test(match[0]))
continue

// There may be no need
// https://tailwindcss.com/docs/background-image#arbitrary-values
// skip all the image formats in HTML for bg-[url('...')]
if (/\.(png|jpg|jpeg|gif|svg)/g.test(match[0]))
continue
// skip http(s)://
if (/^http(s)?:\/\//g.test(match[0]))
if (/http(s)?:\/\//g.test(match[0]))
continue

const start = match.index!
Expand Down
5 changes: 4 additions & 1 deletion playground/src/pages/index/index.vue
Expand Up @@ -21,7 +21,10 @@ const type = 'text'
<div :class="{ 'is-textarea-icon': type === 'textarea' }">
uniapp
</div>
<div class="bg-[url('https://raw.githubusercontent.com/unocss/unocss/main/playground/public/icon-gray.svg')]">
<div
class="bg-[url(https://avatars.githubusercontent.com/u/40738594?s=40&v=4)]"
:class="{ 'bg-[url(https://avatars.githubusercontent.com/u/40738594?s=40&v=4)]': type === 'textarea' }"
>
uniapp
</div>
<div class="m-0.5 p-1 text-2xl" :class="true ? '' : 'text-yellow-500 p-2.5'">
Expand Down
186 changes: 93 additions & 93 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion test/fixtures/rules.vue
Expand Up @@ -21,7 +21,10 @@ const type = 'text'
<div :class="{ 'is-textarea-icon': type === 'textarea' }">
uniapp
</div>
<div class="bg-[url('https://raw.githubusercontent.com/unocss/unocss/main/playground/public/icon-gray.svg')]">
<div
class="bg-[url(https://avatars.githubusercontent.com/u/40738594?s=40&v=4)]"
:class="{ 'bg-[url(https://avatars.githubusercontent.com/u/40738594?s=40&v=4)]': type === 'textarea' }"
>
uniapp
</div>
<div class="m-0.5 p-1 text-2xl" :class="true ? '' : 'text-yellow-500 p-2.5'">
Expand Down

0 comments on commit 8d84443

Please sign in to comment.