diff --git a/color-convert/composer.json b/color-convert/composer.json new file mode 100644 index 0000000..1015d08 --- /dev/null +++ b/color-convert/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "spatie/color": "^1.5" + } +} diff --git a/color-convert/composer.lock b/color-convert/composer.lock new file mode 100644 index 0000000..18a9588 --- /dev/null +++ b/color-convert/composer.lock @@ -0,0 +1,78 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "603b92d7e2cc25b708dbb66ae8ecabd8", + "packages": [ + { + "name": "spatie/color", + "version": "1.5.3", + "source": { + "type": "git", + "url": "https://github.com/spatie/color.git", + "reference": "49739265900cabce4640cd26c3266fd8d2cca390" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/color/zipball/49739265900cabce4640cd26c3266fd8d2cca390", + "reference": "49739265900cabce4640cd26c3266fd8d2cca390", + "shasum": "" + }, + "require": { + "php": "^7.3|^8.0" + }, + "require-dev": { + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^6.5||^9.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\Color\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Sebastian De Deyne", + "email": "sebastian@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "A little library to handle color conversions", + "homepage": "https://github.com/spatie/color", + "keywords": [ + "color", + "conversion", + "rgb", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/color/issues", + "source": "https://github.com/spatie/color/tree/1.5.3" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2022-12-18T12:58:32+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/color-convert/replacer b/color-convert/replacer new file mode 100755 index 0000000..0bd21e5 --- /dev/null +++ b/color-convert/replacer @@ -0,0 +1,79 @@ +#!/usr/bin/php8.2 +toHsl()); +$nextPrimaryColorH = (int) preg_replace('/hsl\(([0-9]+),.+$/', '$1', Hex::fromString($nextPrimaryColor)->toHsl()); + +$hDiff = $nextPrimaryColorH - $currentPrimaryColorH; + +foreach ($properties as $property) { + preg_match_all( + sprintf( + '/%s: *((?#[A-F0-9]{6})(?[A-F0-9]{2}){0,1});/is', + $property, + ), + $content, + $matches, + PREG_SET_ORDER + ); + + foreach ($matches as $match) { + $match['alpha'] ??= 'ff'; + + $color = Hex::fromString($match['color']); + $hsl = $color->toHsla(hexdec($match['alpha']) * 1 / 255); + + $hsl = preg_replace_callback('/\(([0-9]+),/', function ($m) use ($hDiff) { + return sprintf('(%d,', $m[1] + $hDiff); + }, $hsl); + + $content = str_replace( + $match[0], + sprintf('%s: %s;', $property, $hsl), + $content + ); + } +} + +file_put_contents(str_replace('.css', '-'.$name.'.css', $input), $content);