diff --git a/components/CssCompiler.php b/components/CssCompiler.php index 658a60c4e..a61639144 100644 --- a/components/CssCompiler.php +++ b/components/CssCompiler.php @@ -1,8 +1,11 @@ getTmpDir(); - if ($path !== null && substr($path, -4) === '.css') { - $cssOnly = true; - } + $this->copyAndFixScss($tmpDir); - $parser = new class($path, \count($this->sourceNames), $this->encoding, $this->cache, $cssOnly) extends Parser { - public function __construct($sourceName, $sourceIndex = 0, $encoding = 'utf-8', \ScssPhp\ScssPhp\Cache $cache = null, $cssOnly = false, \ScssPhp\ScssPhp\Logger\LoggerInterface $logger = null) - { - parent::__construct($sourceName, $sourceIndex, $encoding, $cache, $cssOnly, $logger); - } + $scss = new Compiler(); + $scss->addImportPath($tmpDir . 'css-compile'); + $scss->setOutputStyle(OutputStyle::COMPRESSED); - public function parse($buffer) - { - $buffer = str_replace('@use "sass:math";', '', $buffer); - $buffer = preg_replace_callback('/math\.div\((?[^,]*), (?[^)]+)\)/siu', function ($matches): string { - return $matches['first'] . ' / ' . $matches['second']; - }, $buffer); + return $scss->compileString($css)->getCss(); + } - return parent::parse($buffer); + private function copyAndFixScss(string $tmpDir): void + { + $filesystem = new \Symfony\Component\Filesystem\Filesystem(); + $filesystem->mirror(\Yii::$app->basePath . '/web/css', $tmpDir . 'css-compile'); + $filesystem->mirror(\Yii::$app->basePath . '/web/fonts', $tmpDir . 'fonts'); + + $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tmpDir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST); + foreach ($iterator as $file) { + if (!str_ends_with($file->getPathname(), 'scss')) { + continue; } - }; - $this->sourceNames[] = $path; - $this->addParsedFile($path); + $content = file_get_contents($file->getPathname()); + file_put_contents($file->getPathname(), $this->fixCss($content)); + } + } + + private function fixCss(String $css): string + { + $css = str_replace('@use "sass:math";', '', $css); + $css = preg_replace_callback('/math\.div\((?[^,]*), (?[^)]+)\)/siu', function ($matches): string { + return $matches['first'] . ' / ' . $matches['second']; + }, $css); - return $parser; + return $css; } } diff --git a/composer.json b/composer.json index 1ffafff7a..dbf19443e 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "phpoffice/phpspreadsheet": "^3.3", "predis/predis": "^2.2", "s1syphos/php-simple-captcha": "^2.3", - "scssphp/scssphp": "^1.13.0", + "scssphp/scssphp": "dev-main#12d3cdf0fc2a73e9438ded5a5a82fb353b68d718 as 1.13.0", "setasign/fpdi": "^2.3.7", "spomky-labs/otphp": "^11.3", "symfony/amazon-mailer": "^5.4.23", diff --git a/composer.lock b/composer.lock index 457547f00..d64478902 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "412e28ab5b578a3962d8d9f0f8e19ede", + "content-hash": "4766a046699135157aeeaf06f9e42ebf", "packages": [ { "name": "async-aws/core", @@ -1301,6 +1301,180 @@ ], "time": "2024-07-18T11:15:46+00:00" }, + { + "name": "league/uri", + "version": "7.4.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/uri.git", + "reference": "bedb6e55eff0c933668addaa7efa1e1f2c417cc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/uri/zipball/bedb6e55eff0c933668addaa7efa1e1f2c417cc4", + "reference": "bedb6e55eff0c933668addaa7efa1e1f2c417cc4", + "shasum": "" + }, + "require": { + "league/uri-interfaces": "^7.3", + "php": "^8.1" + }, + "conflict": { + "league/uri-schemes": "^1.0" + }, + "suggest": { + "ext-bcmath": "to improve IPV4 host parsing", + "ext-fileinfo": "to create Data URI from file contennts", + "ext-gmp": "to improve IPV4 host parsing", + "ext-intl": "to handle IDN host with the best performance", + "jeremykendall/php-domain-parser": "to resolve Public Suffix and Top Level Domain", + "league/uri-components": "Needed to easily manipulate URI objects components", + "php-64bit": "to improve IPV4 host parsing", + "symfony/polyfill-intl-idn": "to handle IDN host via the Symfony polyfill if ext-intl is not present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Uri\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://nyamsprod.com" + } + ], + "description": "URI manipulation library", + "homepage": "https://uri.thephpleague.com", + "keywords": [ + "data-uri", + "file-uri", + "ftp", + "hostname", + "http", + "https", + "middleware", + "parse_str", + "parse_url", + "psr-7", + "query-string", + "querystring", + "rfc3986", + "rfc3987", + "rfc6570", + "uri", + "uri-template", + "url", + "ws" + ], + "support": { + "docs": "https://uri.thephpleague.com", + "forum": "https://thephpleague.slack.com", + "issues": "https://github.com/thephpleague/uri-src/issues", + "source": "https://github.com/thephpleague/uri/tree/7.4.1" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2024-03-23T07:42:40+00:00" + }, + { + "name": "league/uri-interfaces", + "version": "7.4.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/uri-interfaces.git", + "reference": "8d43ef5c841032c87e2de015972c06f3865ef718" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/uri-interfaces/zipball/8d43ef5c841032c87e2de015972c06f3865ef718", + "reference": "8d43ef5c841032c87e2de015972c06f3865ef718", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "php": "^8.1", + "psr/http-factory": "^1", + "psr/http-message": "^1.1 || ^2.0" + }, + "suggest": { + "ext-bcmath": "to improve IPV4 host parsing", + "ext-gmp": "to improve IPV4 host parsing", + "ext-intl": "to handle IDN host with the best performance", + "php-64bit": "to improve IPV4 host parsing", + "symfony/polyfill-intl-idn": "to handle IDN host via the Symfony polyfill if ext-intl is not present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Uri\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://nyamsprod.com" + } + ], + "description": "Common interfaces and classes for URI representation and interaction", + "homepage": "https://uri.thephpleague.com", + "keywords": [ + "data-uri", + "file-uri", + "ftp", + "hostname", + "http", + "https", + "parse_str", + "parse_url", + "psr-7", + "query-string", + "querystring", + "rfc3986", + "rfc3987", + "rfc6570", + "uri", + "url", + "ws" + ], + "support": { + "docs": "https://uri.thephpleague.com", + "forum": "https://thephpleague.slack.com", + "issues": "https://github.com/thephpleague/uri-src/issues", + "source": "https://github.com/thephpleague/uri-interfaces/tree/7.4.1" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2024-03-23T07:42:40+00:00" + }, { "name": "maennchen/zipstream-php", "version": "3.1.1", @@ -2436,41 +2610,43 @@ }, { "name": "scssphp/scssphp", - "version": "v1.13.0", + "version": "dev-main", "source": { "type": "git", "url": "https://github.com/scssphp/scssphp.git", - "reference": "63d1157457e5554edf00b0c1fabab4c1511d2520" + "reference": "12d3cdf0fc2a73e9438ded5a5a82fb353b68d718" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/scssphp/scssphp/zipball/63d1157457e5554edf00b0c1fabab4c1511d2520", - "reference": "63d1157457e5554edf00b0c1fabab4c1511d2520", + "url": "https://api.github.com/repos/scssphp/scssphp/zipball/12d3cdf0fc2a73e9438ded5a5a82fb353b68d718", + "reference": "12d3cdf0fc2a73e9438ded5a5a82fb353b68d718", "shasum": "" }, "require": { "ext-ctype": "*", "ext-json": "*", - "php": ">=5.6.0" + "league/uri": "^7.4", + "league/uri-interfaces": "^7.4", + "php": ">=8.1", + "symfony/filesystem": "^5.4 || ^6.0 || ^7.0", + "symfony/polyfill-mbstring": "^1.30" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.4", - "phpunit/phpunit": "^5.7 || ^6.5 || ^7.5 || ^8.3 || ^9.4", + "phpunit/phpunit": "^9.5.6", "sass/sass-spec": "*", "squizlabs/php_codesniffer": "~3.5", "symfony/phpunit-bridge": "^5.1", + "symfony/var-dumper": "^6.3", "thoughtbot/bourbon": "^7.0", "twbs/bootstrap": "~5.0", "twbs/bootstrap4": "4.6.1", "zurb/foundation": "~6.7.0" }, "suggest": { - "ext-iconv": "Can be used as fallback when ext-mbstring is not available", - "ext-mbstring": "For best performance, mbstring should be installed as it is faster than ext-iconv" + "ext-mbstring": "For best performance, mbstring should be installed as it is faster than the polyfill" }, - "bin": [ - "bin/pscss" - ], + "default-branch": true, "type": "library", "extra": { "bamarni-bin": { @@ -2510,9 +2686,9 @@ ], "support": { "issues": "https://github.com/scssphp/scssphp/issues", - "source": "https://github.com/scssphp/scssphp/tree/v1.13.0" + "source": "https://github.com/scssphp/scssphp/tree/main" }, - "time": "2024-08-17T21:02:11+00:00" + "time": "2024-10-24T15:03:30+00:00" }, { "name": "setasign/fpdi", @@ -3030,6 +3206,73 @@ ], "time": "2024-04-18T09:32:20+00:00" }, + { + "name": "symfony/filesystem", + "version": "v5.4.45", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "57c8294ed37d4a055b77057827c67f9558c95c54" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/57c8294ed37d4a055b77057827c67f9558c95c54", + "reference": "57c8294ed37d4a055b77057827c67f9558c95c54", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8", + "symfony/polyfill-php80": "^1.16" + }, + "require-dev": { + "symfony/process": "^5.4|^6.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides basic utilities for the filesystem", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/filesystem/tree/v5.4.45" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-10-22T13:05:35+00:00" + }, { "name": "symfony/http-client", "version": "v5.4.45", @@ -8437,73 +8680,6 @@ ], "time": "2024-10-22T13:05:35+00:00" }, - { - "name": "symfony/filesystem", - "version": "v5.4.45", - "source": { - "type": "git", - "url": "https://github.com/symfony/filesystem.git", - "reference": "57c8294ed37d4a055b77057827c67f9558c95c54" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/57c8294ed37d4a055b77057827c67f9558c95c54", - "reference": "57c8294ed37d4a055b77057827c67f9558c95c54", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.8", - "symfony/polyfill-php80": "^1.16" - }, - "require-dev": { - "symfony/process": "^5.4|^6.4" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Filesystem\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides basic utilities for the filesystem", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/filesystem/tree/v5.4.45" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-10-22T13:05:35+00:00" - }, { "name": "symfony/finder", "version": "v5.4.45", @@ -9018,12 +9194,19 @@ "version": "dev-main", "alias": "1.0.6", "alias_normalized": "1.0.6.0" + }, + { + "package": "scssphp/scssphp", + "version": "dev-main", + "alias": "1.13.0", + "alias_normalized": "1.13.0.0" } ], "minimum-stability": "stable", "stability-flags": { "codeception/codeception": 20, - "codeception/lib-web": 20 + "codeception/lib-web": 20, + "scssphp/scssphp": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/views/pages/css.php b/views/pages/css.php index 4c9393f04..cc6b95e0a 100644 --- a/views/pages/css.php +++ b/views/pages/css.php @@ -4,6 +4,7 @@ * @var \app\models\settings\Stylesheet $stylesheetSettings */ +use app\components\CssCompiler; use ScssPhp\ScssPhp\OutputStyle; $css = ' @@ -92,8 +93,5 @@ } '; - -$scss = new \app\components\CssCompiler(); -$scss->addImportPath(Yii::$app->basePath . '/web/css/'); -$scss->setOutputStyle(OutputStyle::COMPRESSED); -echo $scss->compileString($css)->getCss(); +$compiler = new CssCompiler(); +echo $compiler->compileCss($css);