Skip to content

[FEATURE] Add support for the dvh, lvh and svh length units (#415) #627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).

### Added

- Add support for the `dvh`, `lvh` and `svh` length units (#415)

### Changed

### Deprecated
Expand Down
7 changes: 6 additions & 1 deletion src/Value/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ class Size extends PrimitiveValue
*
* @internal
*/
const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem'];
const ABSOLUTE_SIZE_UNITS = [
'px', 'pt', 'pc',
'cm', 'mm', 'mozmm', 'in',
'vh', 'dvh', 'svh', 'lvh',
'vw', 'vmin', 'vmax', 'rem',
];

/**
* @var array<int, string>
Expand Down
51 changes: 51 additions & 0 deletions tests/Value/SizeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Sabberworm\CSS\Tests\Value;

use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Settings;
use Sabberworm\CSS\Value\Size;

/**
* @covers \Sabberworm\CSS\Value\Size
*/
final class SizeTest extends TestCase
{
/**
* @return array<string, array{0: string}>
*/
public static function provideUnit()
{
$units = [
'px', 'pt', 'pc',
'cm', 'mm', 'mozmm', 'in',
'vh', 'dvh', 'svh', 'lvh',
'vw', 'vmin', 'vmax', 'rem',
'%', 'em', 'ex', 'ch', 'fr',
'deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz',
];

return \array_combine(
$units,
\array_map(
function ($unit) {
return [$unit];
},
$units
)
);
}

/**
* @test
*
* @dataProvider provideUnit
*/
public function parsesUnit($unit)
{
$subject = Size::parse(new ParserState('1' . $unit, Settings::create()));

self::assertSame($unit, $subject->getUnit());
}
}