From 24a087d979cb762eb99de8daa1b0c0ebd33abb1b Mon Sep 17 00:00:00 2001 From: Thierry Bela Date: Sun, 22 Aug 2021 00:16:21 -0400 Subject: [PATCH] #142 insert font-display declaration before the font declaration --- helpers/CSS.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/helpers/CSS.php b/helpers/CSS.php index 097cd6e..cc974ac 100644 --- a/helpers/CSS.php +++ b/helpers/CSS.php @@ -14,7 +14,7 @@ namespace Gzip\Helpers; use Gzip\GZipHelper; -use TBela\CSS\Compiler; +//use TBela\CSS\Compiler; use TBela\CSS\Element; use TBela\CSS\Element\Stylesheet; use TBela\CSS\Interfaces\ElementInterface; @@ -112,7 +112,15 @@ public function processHTML($html, array $options = []) } $copy = $query->copy(); - $copy->getParent()->addDeclaration('font-display', $options['fontdisplay']); + + $declaration = new Element\Declaration(); + $declaration->setName('font-display'); + $declaration->setValue($options['fontdisplay']); + + /** + * @var RuleListInterface + */ + $copy->getParent()->insert($declaration, 0); $headStyle->append($copy->getRoot()); } @@ -385,7 +393,7 @@ public function processHTML($html, array $options = []) } $position = isset($attributes['data-position']) && $attributes['data-position'] == 'head' ? 'head' : 'body'; - $links[$position]['style'][] = !empty($css_options['compress']) ? (new Compiler($css_options))->setContent($matches[2])->compile() : $matches[2]; + $links[$position]['style'][] = !empty($css_options['compress']) ? (new Renderer($css_options))->renderAst(new Parser($matches[2])) : $matches[2]; return ''; }, $html);