CSS-Orientation
view release on metacpan or search on metacpan
lib/CSS/Orientation.pm view on Meta::CPAN
# These two lookaheads are to test whether or not we are within a
# background: url(HERE) situation.
# Ref: http://www.w3.org/TR/CSS21/syndata.html#uri
our $VALID_AFTER_URI_CHARS = sprintf( q'[\'\"]?%s', $WHITESPACE );
our $LOOKAHEAD_NOT_CLOSING_PAREN = sprintf( q'(?!%s?%s\))', $URL_CHARS,
$VALID_AFTER_URI_CHARS );
our $LOOKAHEAD_FOR_CLOSING_PAREN = sprintf( q'(?=%s?%s\))', $URL_CHARS,
$VALID_AFTER_URI_CHARS );
# Compile a regex to swap left and right values in 4 part notations.
# We need to match negatives and decimal numeric values.
# The case of border-radius is extra complex, so we handle it separately below.
# ex. 'margin: .25em -2px 3px 0' becomes 'margin: .25em 0 3px -2px'.
our $POSSIBLY_NEGATIVE_QUANTITY = sprintf( q'((?:-?%s)|(?:inherit|auto))', $QUANTITY );
our $POSSIBLY_NEGATIVE_QUANTITY_SPACE = sprintf( q'%s%s%s', $POSSIBLY_NEGATIVE_QUANTITY,
$SPACE,
$WHITESPACE );
our $FOUR_NOTATION_QUANTITY_RE = risprintf( q'%s%s%s%s',
$POSSIBLY_NEGATIVE_QUANTITY_SPACE,
$POSSIBLY_NEGATIVE_QUANTITY_SPACE,
$POSSIBLY_NEGATIVE_QUANTITY_SPACE,
$POSSIBLY_NEGATIVE_QUANTITY );
our $COLOR = sprintf( q'(%s|%s)', $NAME, $HASH );
our $COLOR_SPACE = sprintf( q'%s%s', $COLOR, $SPACE );
our $FOUR_NOTATION_COLOR_RE = risprintf( q'(-color%s:%s)%s%s%s(%s)',
$WHITESPACE,
$WHITESPACE,
$COLOR_SPACE,
$COLOR_SPACE,
$COLOR_SPACE,
$COLOR );
# border-radius is very different from usual 4 part notation: ABCD should
# change to BADC (while it would be ADCB in normal 4 part notation), ABC
# should change to BABC, and AB should change to BA
our $BORDER_RADIUS_RE = risprintf( q'((?:%s)?)border-radius(%s:%s)' .
'(?:%s)?(?:%s)?(?:%s)?(?:%s)' .
'(?:%s/%s(?:%s)?(?:%s)?(?:%s)?(?:%s))?', $IDENT,
$WHITESPACE,
$WHITESPACE,
$POSSIBLY_NEGATIVE_QUANTITY_SPACE,
$POSSIBLY_NEGATIVE_QUANTITY_SPACE,
$POSSIBLY_NEGATIVE_QUANTITY_SPACE,
$POSSIBLY_NEGATIVE_QUANTITY,
$WHITESPACE,
$WHITESPACE,
$POSSIBLY_NEGATIVE_QUANTITY_SPACE,
$POSSIBLY_NEGATIVE_QUANTITY_SPACE,
$POSSIBLY_NEGATIVE_QUANTITY_SPACE,
$POSSIBLY_NEGATIVE_QUANTITY );
# Compile the cursor resize regexes
our $CURSOR_EAST_RE = resprintf( $LOOKBEHIND_NOT_LETTER . '([ns]?)e-resize' );
our $CURSOR_WEST_RE = resprintf( $LOOKBEHIND_NOT_LETTER . '([ns]?)w-resize' );
# Matches the condition where we need to replace the horizontal component
# of a background-position value when expressed in horizontal percentage.
# Had to make two regexes because in the case of position-x there is only
# one quantity, and otherwise we don't want to match and change cases with only
# one quantity.
our $BG_HORIZONTAL_PERCENTAGE_RE = resprintf( q'background(-position)?(%s:%s)' .
q'([^%%]*?)(%s)%%' .
q'(%s(?:%s|top|center|bottom))', $WHITESPACE,
$WHITESPACE,
$NUM,
$WHITESPACE,
$POSSIBLY_NEGATIVE_QUANTITY );
our $BG_HORIZONTAL_PERCENTAGE_X_RE = resprintf( q'background-position-x(%s:%s)' .
q'(%s)%%', $WHITESPACE,
$WHITESPACE,
$NUM );
# Non-percentage units used for CSS lengths
our $LENGTH_UNIT = q'(?:em|ex|px|cm|mm|in|pt|pc)';
# To make sure the lone 0 is not just starting a number (like "02") or a percentage like ("0 %")
our $LOOKAHEAD_END_OF_ZERO = sprintf( '(?![0-9]|%s%%)', $WHITESPACE );
# A length with a unit specified. Matches "0" too, as it's a length, not a percentage.
our $LENGTH = sprintf( '(?:-?%s(?:%s%s)|0+%s)', $NUM,
$WHITESPACE,
$LENGTH_UNIT,
$LOOKAHEAD_END_OF_ZERO );
# Zero length. Used in the replacement functions.
our $ZERO_LENGTH = resprintf( q'(?:-?0+(?:%s%s)|0+%s)$', $WHITESPACE,
$LENGTH_UNIT,
$LOOKAHEAD_END_OF_ZERO );
# Matches background, background-position, and background-position-x
# properties when using a CSS length for its horizontal positioning.
our $BG_HORIZONTAL_LENGTH_RE = resprintf( q'background(-position)?(%s:%s)' .
q'((?:.+?%s+)??)(%s)' .
q'((?:%s+)(?:%s|top|center|bottom))', $WHITESPACE,
$WHITESPACE,
$SPACE,
$LENGTH,
$SPACE,
$POSSIBLY_NEGATIVE_QUANTITY );
our $BG_HORIZONTAL_LENGTH_X_RE = resprintf( q'background-position-x(%s:%s)' .
q'(%s)', $WHITESPACE,
$WHITESPACE,
$LENGTH );
# Matches the opening of a body selector.
our $BODY_SELECTOR = sprintf( q'body%s{%s', $WHITESPACE, $WHITESPACE );
# Matches anything up until the closing of a selector.
our $CHARS_WITHIN_SELECTOR = q'[^\}]*?';
# Matches the direction property in a selector.
our $DIRECTION_RE = sprintf( q'direction%s:%s', $WHITESPACE, $WHITESPACE );
sub resprintf {
my $fmt = shift;
my $ret = sprintf( $fmt, @_ );
return qr/$ret/;
}
sub risprintf {
my $fmt = shift;
my $ret = sprintf( $fmt, @_ );
return qr/$ret/i;
}
# These allow us to swap "ltr" with "rtl" and vice versa ONLY within the
# body selector and on the same line.
our $BODY_DIRECTION_LTR_RE = risprintf( q'(%s)(%s)(%s)(ltr)',
$BODY_SELECTOR, $CHARS_WITHIN_SELECTOR,
$DIRECTION_RE );
our $BODY_DIRECTION_RTL_RE = risprintf( q'(%s)(%s)(%s)(rtl)',
$BODY_SELECTOR, $CHARS_WITHIN_SELECTOR,
$DIRECTION_RE );
( run in 2.776 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )