Skip to content

Commit 639f93e

Browse files
committed
Change style builder
1 parent 37f170c commit 639f93e

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

src/Utils/StyleBuilder.php

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ class StyleBuilder
1717
public const STYLE_ALL = 3;
1818

1919
/**
20-
* @var ScssCompiler|null
20+
* @var int
2121
*/
22-
private $scssCompiler;
22+
private $outputType;
2323

2424
/**
25-
* @var string|null
25+
* @var ScssCompiler|null
2626
*/
27-
private $lang;
27+
private $scssCompiler;
2828

2929
/**
3030
* @var bool
@@ -36,11 +36,6 @@ class StyleBuilder
3636
*/
3737
private $scopedAttribute;
3838

39-
/**
40-
* @var int
41-
*/
42-
private $outputType;
43-
4439
/**
4540
* StyleBuilder constructor.
4641
*
@@ -49,8 +44,9 @@ class StyleBuilder
4944
public function __construct()
5045
{
5146
$this->outputType = self::STYLE_ALL;
52-
$this->scopedAttribute = 'data-v-' . substr(md5(Uuid::uuid4()->toString()), 0, 8);
47+
$this->scssCompiler = null;
5348
$this->hasScoped = false;
49+
$this->scopedAttribute = 'data-v-' . substr(md5(Uuid::uuid4()->toString()), 0, 8);
5450
}
5551

5652
public function setOutputType(int $outputType): void
@@ -63,28 +59,21 @@ public function setOutputType(int $outputType): void
6359
*/
6460
public function compile($styleElement): ?string
6561
{
66-
if (!$styleElement instanceof DOMElement) {
67-
return null;
68-
}
69-
70-
if (($styleElement->hasAttribute('scoped') && !($this->outputType & self::STYLE_SCOPED))
62+
if (!$styleElement instanceof DOMElement
63+
|| ($styleElement->hasAttribute('scoped') && !($this->outputType & self::STYLE_SCOPED))
7164
|| (!$styleElement->hasAttribute('scoped') && !($this->outputType & self::STYLE))) {
7265
return null;
7366
}
7467

75-
if (
76-
!$this->scssCompiler instanceof ScssCompiler
77-
&& $styleElement->hasAttribute('lang')
78-
&& $styleElement->getAttribute('lang') === 'scss'
79-
) {
80-
$this->lang = 'scss';
81-
$this->scssCompiler = new ScssCompiler();
82-
}
83-
8468
$style = $styleElement->textContent;
85-
if ($this->lang === 'scss') {
69+
70+
if ($styleElement->hasAttribute('lang') && $styleElement->getAttribute('lang') === 'scss') {
71+
if ($this->scssCompiler === null) {
72+
$this->scssCompiler = new ScssCompiler();
73+
}
8674
$style = $this->scssCompiler->compile($style);
8775
}
76+
8877
if ($styleElement->hasAttribute('scoped')) {
8978
$this->hasScoped = true;
9079
$style = preg_replace('/((?:^|[^},]*?)\S+)(\s*[{,])/i', '$1[' . $this->scopedAttribute . ']$2', $style);

0 commit comments

Comments
 (0)