Skip to content

Commit 36a93fa

Browse files
committed
Add v-deep support
1 parent ca62b3a commit 36a93fa

7 files changed

+88
-5
lines changed

src/Utils/StyleBuilder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ public function compile(?DOMElement $styleElement, ?string $path = null): ?strin
7878
return null;
7979
}
8080

81-
$style = $styleElement->textContent;
81+
$style = preg_replace('/ *(?:\/deep\/|>>>)/', '::v-deep', $styleElement->textContent);
8282

8383
if ($styleElement->hasAttribute('lang') && $styleElement->getAttribute('lang') === 'scss') {
8484
if ($this->scssCompiler === null) {
8585
$this->scssCompiler = new ScssCompiler();
8686
}
8787
try {
88-
$style = str_replace('/deep/', '__vue_to_twig_deep_placeholder__', $style);
88+
$style = str_replace('::v-deep', '__vue_to_twig_deep_placeholder__', $style);
8989
$style = $this->scssCompiler->compile($this->scssData . ' ' . $style, $path);
90-
$style = str_replace('__vue_to_twig_deep_placeholder__', '/deep/', $style);
90+
$style = str_replace('__vue_to_twig_deep_placeholder__', '::v-deep', $style);
9191
} catch (SassException $e) {
9292
$style = "\n/* Warning: " . $e->getMessage() . " */\n";
9393
}
@@ -109,8 +109,8 @@ public function compile(?DOMElement $styleElement, ?string $path = null): ?strin
109109
if (++$count < $selectorsCount) {
110110
$selector .= ',';
111111
}
112-
$regex = strpos($selector, '/deep/') !== false
113-
? '/((?:^|\s)\s*[^@\s][a-z0-9-_]+?)((?::{1,2}[a-z-]+)?\s*)(?:\/deep\/)/i'
112+
$regex = strpos($selector, '::v-deep') !== false
113+
? '/((?:^|\s)\s*[^@\s][a-z0-9-_]+?)((?::{1,2}[a-z-]+)?\s*)(?:::v-deep)/i'
114114
: '/((?:^|\s)\s*[^@\s][a-z0-9-_]+?)((?::{1,2}[a-z-]+)?\s*(?:[,{]|$))/i';
115115
$style = str_replace(
116116
$selector,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<style>
2+
.foo[data-v-a7086bdfdd04b85fedbd31210be0ce0d] li { color: purple; }
3+
</style>
4+
<div data-v-a7086bdfdd04b85fedbd31210be0ce0d {{ dataScopedStyleAttribute|default('') }} class="{{ class|default('') }}" style="{{ style|default('') }}">
5+
<ul class="foo" data-v-a7086bdfdd04b85fedbd31210be0ce0d>
6+
<li data-v-a7086bdfdd04b85fedbd31210be0ce0d>foo</li>
7+
</ul>
8+
</div>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<div>
3+
<ul class="foo">
4+
<li>foo</li>
5+
</ul>
6+
</div>
7+
</template>
8+
9+
<style scoped>
10+
.foo >>> li {
11+
color: purple;
12+
}
13+
</style>
14+
15+
<script>
16+
export default {
17+
}
18+
</script>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<style>.foo[data-v-380077bd8cc6cda5c4990f3e4ac075fd] { color: red;}.foo[data-v-380077bd8cc6cda5c4990f3e4ac075fd] .bar { color: blue;}</style>
2+
<div data-v-380077bd8cc6cda5c4990f3e4ac075fd {{ dataScopedStyleAttribute|default('') }} class="{{ class|default('') }}" style="{{ style|default('') }}">
3+
<div class="foo" data-v-380077bd8cc6cda5c4990f3e4ac075fd>
4+
foo
5+
</div>
6+
</div>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div>
3+
<div class="foo">
4+
foo
5+
</div>
6+
</div>
7+
</template>
8+
9+
<style lang="scss" scoped>
10+
.foo {
11+
color: red;
12+
&::v-deep .bar {
13+
color: blue;
14+
}
15+
}
16+
</style>
17+
18+
<script>
19+
export default {
20+
}
21+
</script>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<style>
2+
.foo[data-v-edb841210d6b44de44e970ef62228269] { color: red; }
3+
.foo[data-v-edb841210d6b44de44e970ef62228269] .bar { color: blue; }
4+
</style>
5+
<div data-v-edb841210d6b44de44e970ef62228269 {{ dataScopedStyleAttribute|default('') }} class="{{ class|default('') }}" style="{{ style|default('') }}">
6+
<div class="foo" data-v-edb841210d6b44de44e970ef62228269>
7+
foo
8+
</div>
9+
</div>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div>
3+
<div class="foo">
4+
foo
5+
</div>
6+
</div>
7+
</template>
8+
9+
<style scoped>
10+
.foo {
11+
color: red;
12+
}
13+
.foo::v-deep .bar {
14+
color: blue;
15+
}
16+
</style>
17+
18+
<script>
19+
export default {
20+
}
21+
</script>

0 commit comments

Comments
 (0)