| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sabberworm\CSS\Value; |
| 5 |
|
| 6 |
use WCPOS\Vendor\Sabberworm\CSS\OutputFormat; |
| 7 |
use WCPOS\Vendor\Sabberworm\CSS\Parsing\ParserState; |
| 8 |
use WCPOS\Vendor\Sabberworm\CSS\Parsing\UnexpectedEOFException; |
| 9 |
use WCPOS\Vendor\Sabberworm\CSS\Parsing\UnexpectedTokenException; |
| 10 |
/** |
| 11 |
* A name for a named CSS grid line. |
| 12 |
* |
| 13 |
* @see https://www.w3.org/TR/css-grid-1/#line-name |
| 14 |
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Grid_layout/Named_grid_lines |
| 15 |
*/ |
| 16 |
class LineName extends ValueList |
| 17 |
{ |
| 18 |
/** |
| 19 |
* @param array<string> $components |
| 20 |
* @param int<1, max>|null $lineNumber |
| 21 |
*/ |
| 22 |
public function __construct(array $components = [], ?int $lineNumber = null) |
| 23 |
{ |
| 24 |
parent::__construct($components, ' ', $lineNumber); |
| 25 |
} |
| 26 |
/** |
| 27 |
* @throws UnexpectedTokenException |
| 28 |
* @throws UnexpectedEOFException |
| 29 |
* |
| 30 |
* @internal since V8.8.0 |
| 31 |
*/ |
| 32 |
public static function parse(ParserState $parserState) : LineName |
| 33 |
{ |
| 34 |
$parserState->consume('['); |
| 35 |
$parserState->consumeWhiteSpace(); |
| 36 |
$names = []; |
| 37 |
do { |
| 38 |
if ($parserState->getSettings()->usesLenientParsing()) { |
| 39 |
try { |
| 40 |
$names[] = $parserState->parseIdentifier(); |
| 41 |
} catch (UnexpectedTokenException $e) { |
| 42 |
if (!$parserState->comes(']')) { |
| 43 |
throw $e; |
| 44 |
} |
| 45 |
} |
| 46 |
} else { |
| 47 |
$names[] = $parserState->parseIdentifier(); |
| 48 |
} |
| 49 |
$parserState->consumeWhiteSpace(); |
| 50 |
} while (!$parserState->comes(']')); |
| 51 |
$parserState->consume(']'); |
| 52 |
return new LineName($names, $parserState->currentLine()); |
| 53 |
} |
| 54 |
/** |
| 55 |
* @return non-empty-string |
| 56 |
*/ |
| 57 |
public function render(OutputFormat $outputFormat) : string |
| 58 |
{ |
| 59 |
return '[' . parent::render(OutputFormat::createCompact()) . ']'; |
| 60 |
} |
| 61 |
} |
| 62 |
|