Skip to content

Commit fcad976

Browse files
committed
Chore: Add ArbitraryLengthValidator to Config class and ArbitraryShadowValidatorTest
1 parent 02273f8 commit fcad976

File tree

8 files changed

+239
-160
lines changed

8 files changed

+239
-160
lines changed

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@
2828
"require": {
2929
"php": "^8.2.0",
3030
"psr/simple-cache": "^3.0",
31-
"illuminate/support": "^v11.5"
31+
"illuminate/support": "^v11.10"
3232
},
3333
"require-dev": {
34-
"laravel/pint": "^v1.15.2",
35-
"nunomaduro/collision": "^v8.1.1",
36-
"pestphp/pest": "^v2.34.7",
37-
"pestphp/pest-plugin-arch": "^v2.7.0",
34+
"laravel/pint": "^v1.16",
35+
"nunomaduro/collision": "^v8.1",
36+
"pestphp/pest": "^v2.34",
37+
"pestphp/pest-plugin-arch": "^v2.7",
3838
"pestphp/pest-plugin-mock": "^2.0",
39-
"pestphp/pest-plugin-type-coverage": "^v2.8.1",
40-
"phpstan/phpstan": "^1.10.67",
41-
"rector/rector": "^1.0.4",
42-
"symfony/var-dumper": "^v7.0.6"
39+
"pestphp/pest-plugin-type-coverage": "^v2.8",
40+
"phpstan/phpstan": "^1.11",
41+
"rector/rector": "^1.1",
42+
"symfony/var-dumper": "^v7.1"
4343
},
4444
"autoload": {
4545
"psr-4": {

composer.lock

Lines changed: 218 additions & 149 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Support/Config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,6 +2371,7 @@ private static function getLengthWithEmptyAndArbitrary(): array
23712371
return [
23722372
'',
23732373
LengthValidator::validate(...),
2374+
ArbitraryLengthValidator::validate(...),
23742375
];
23752376
}
23762377

src/Support/TailwindClassParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private function getClassGroupId(string $class): string
118118
private function getGroupIdForArbitraryProperty(string $className): string
119119
{
120120
if (Str::match(self::ARBITRARY_PROPERTY_REGEX, $className) !== '' && Str::match(self::ARBITRARY_PROPERTY_REGEX, $className) !== '0') {
121-
$arbitraryPropertyClassName = Str::match(self::ARBITRARY_PROPERTY_REGEX, $className)[1] ?? '';
121+
$arbitraryPropertyClassName = Str::match(self::ARBITRARY_PROPERTY_REGEX, $className);
122122
$property = Str::before($arbitraryPropertyClassName, ':');
123123

124124
if ($property !== '' && $property !== '0') {

src/Validators/ArbitraryShadowValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ArbitraryShadowValidator implements \TailwindClassMerge\Contracts\Validato
1212
{
1313
use ValidatesArbitraryValue;
1414

15-
final public const SHADOW_REGEX = '/^-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/';
15+
final public const SHADOW_REGEX = '/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/';
1616

1717
public static function validate(string $value): bool
1818
{

tests/Feature/ArbitraryPropertiesTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
})->with([
99
['[paint-order:markers] [paint-order:normal]', '[paint-order:normal]'],
1010
['[paint-order:markers] [--my-var:2rem] [paint-order:normal] [--my-var:4px]', '[paint-order:normal] [--my-var:4px]'],
11+
['[--first-var:1rem] [--second-var:2rem]', '[--first-var:1rem] [--second-var:2rem]'],
1112
]);
1213

1314
it('handles arbitrary property conflicts with modifiers correctly', function (string $input, string $output) {

tests/Feature/ArbitraryValuesTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,10 @@
5555
['bg-cover bg-[percentage:30%] bg-[length:200px_100px]', 'bg-[length:200px_100px]'],
5656
['bg-none bg-[url(.)] bg-[image:.] bg-[url:.] bg-[linear-gradient(.)] bg-gradient-to-r', 'bg-gradient-to-r'],
5757
]);
58+
59+
it('handles ambiguous non conflicting arbitrary values correctly', function (string $input, string $output) {
60+
expect(TailwindClassMerge::instance()->merge($input))
61+
->toBe($output);
62+
})->with([
63+
['border-[2px] border-[0.85px] border-[#ff0000] border-[#0000ff]', 'border-[0.85px] border-[#0000ff]'],
64+
]);

tests/Unit/Validators/ArbitraryShadowValidatorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
expect(ArbitraryShadowValidator::validate($input))->toBe($output);
77
})->with([
88
['[0_35px_60px_-15px_rgba(0,0,0,0.3)]', true],
9+
['[inset_0_1px_0,inset_0_-1px_0]', true],
910
['[0_0_#00f]', true],
1011
['[.5rem_0_rgba(5,5,5,5)]', true],
1112
['[-.5rem_0_#123456]', true],

0 commit comments

Comments
 (0)