Table of contents
Namespace: Com\Tecnick\Pdf\CSS
class Specificity
Source: src/CSS/Specificity.php:37
CSS 2.1 specificity (a,b,c) tuple calculator and comparator:
- a = number of ID selectors
- b = number of class selectors, attribute selectors, and pseudo-classes
- c = number of type selectors and pseudo-elements
Properties
$classCount
Number of class selectors, attribute selectors, and pseudo-classes
public int $classCount = 0
Source: src/CSS/Specificity.php:47
$idCount
Number of ID selectors
public int $idCount = 0
Source: src/CSS/Specificity.php:42
$typeCount
Number of type selectors and pseudo-elements
public int $typeCount = 0
Source: src/CSS/Specificity.php:52
Methods
__construct()
Initialize specificity tuple
public __construct(int $idCount = 0, int $classCount = 0, int $typeCount = 0)
Parameters:
$idCount(int): Number of ID selectors$classCount(int): Number of class/attribute/pseudo-class selectors$typeCount(int): Number of type selectors and pseudo-elements
Source: src/CSS/Specificity.php:61
compareTo()
Compare two specificity tuples
public compareTo(self $other): int
Parameters:
$other(self): The specificity to compare against
Returns: int: -1 if this < other, 0 if equal, 1 if this > other
Source: src/CSS/Specificity.php:111
equals()
Check if this specificity equals another
public equals(self $other): bool
Parameters:
$other(self)
Returns: bool
Source: src/CSS/Specificity.php:153
fromLegacyString()
Parse specificity from legacy string format
public static fromLegacyString(string $legacyStr): self
Parameters:
$legacyStr(string): Legacy format string (e.g., “0123”)
Returns: self
Source: src/CSS/Specificity.php:203
fromSelector()
Parse specificity tuple from a selector string
public static fromSelector(string $selector): self
Parameters:
$selector(string): CSS selector string
Returns: self
Source: src/CSS/Specificity.php:74
isGreaterThan()
Check if this specificity is greater than another
public isGreaterThan(self $other): bool
Parameters:
$other(self)
Returns: bool
Source: src/CSS/Specificity.php:142
isLessThan()
Check if this specificity is less than another
public isLessThan(self $other): bool
Parameters:
$other(self)
Returns: bool
Source: src/CSS/Specificity.php:131
toLegacyString()
String representation of the specificity.
Format: inline-style flag followed by the id, class and type counts (e.g. “0123” = inline-style 0, 1 id, 2 classes, 3 types). Internal comparisons use the numeric tuple instead.
public toLegacyString(int $inlineStyle = 0): string
Parameters:
$inlineStyle(int): 0 for rule, 1 for inline
Returns: string
Source: src/CSS/Specificity.php:192
toSortKey()
Convert specificity to a sortable string key with source order index
Format: “{a:04d}{b:04d}{c:04d}_{index:06d}” This allows string-based sorting to maintain specificity precedence
public toSortKey(int $sourceOrder = 0): string
Parameters:
$sourceOrder(int): Source order index for tie-breaking
Returns: string: Sortable key
Source: src/CSS/Specificity.php:167
toString()
Convert specificity to display string (a,b,c format)
public toString(): string
Returns: string
Source: src/CSS/Specificity.php:177