CSS-Prepare

 view release on metacpan or  search on metacpan

lib/CSS/Prepare/Property/Values.pm  view on Meta::CPAN

package CSS::Prepare::Property::Values;

use Modern::Perl;
use Exporter;

our @ISA    = qw( Exporter );
our @EXPORT = qw(
        is_length_value
        is_percentage_value
        is_string_value
        is_url_value
        
        is_background_attachment_value
        is_background_colour_value
        is_background_image_value
        is_background_position_value
        is_background_repeat_value
        is_border_collapse_value
        is_border_colour_value

lib/CSS/Prepare/Property/Values.pm  view on Meta::CPAN

        $list_style_type_value
        $list_style_image_value
        $list_style_position_value
        $margin_width_value
        $media_types_value
        $outline_colour_value
        $outline_style_value
        $outline_width_value
        $padding_width_value
        $positive_length_value
        $positive_percentage_value
        $string_value
        $url_value
        
        $concise_format
        $pretty_format
        $concise_separator
        $pretty_separator
    );


lib/CSS/Prepare/Property/Values.pm  view on Meta::CPAN

        )
    }x;
our $positive_length_value = qr{
        (?:
            $positive_number_value
            (?: px | em | ex | in | cm | mm | pt | pc )
            |
            0
        )
    }x;
my $percentage_value = qr{ $number_value % }x;
our $positive_percentage_value = qr{ $positive_number_value % }x;
our $colour_value = qr{
        (?:
              aqua | black  | blue | fuchsia | gray   | green
            | lime | maroon | navy | olive   | orange | purple
            | red  | silver | teal | white   | yellow
            |
            \# [0-9a-fA-F]{6}
            |
            \# [0-9a-fA-F]{3}
            |
            rgb\(
                (?:
                    (?: (?: $number_value | $percentage_value ) , \s* ){2}
                    (?: $number_value | $percentage_value )
                )
            \)
        )
    }x;
our $string_value = qr{
        (?:
            \' (?: \\ \' | [^'] )* \'   # single-quoted
            |                           # or
            \" (?: \\ \" | [^"] )* \"   # double-quoted
        )

lib/CSS/Prepare/Property/Values.pm  view on Meta::CPAN

our $background_repeat_value
    = qr{ (?: repeat | repeat-x | repeat-y | no-repeat | inherit ) }x;
my $background_positions_horizontal
    = qr{ (?: left | center | centre | right ) }x;
my $background_positions_vertical
    = qr{ (?: top | center | centre | bottom ) }x;
our $background_position_value = qr{
        (?:
                (?:
                    (?:
                        $percentage_value
                        | $length_value
                        | $background_positions_horizontal
                    )
                    (?:
                        \s+
                        (?:
                              $percentage_value
                            | $length_value
                            | $background_positions_vertical
                        )
                    )?
                )
            |
                (?:
                    $background_positions_horizontal \s+
                    $background_positions_vertical
                )

lib/CSS/Prepare/Property/Values.pm  view on Meta::CPAN

            |
                (?: $background_positions_vertical )
            |
                inherit
        )
    }x;

my $border_collapse_value = qr{ (?: collapse | separate | inherit ) }x;
our $border_colour_value = qr{ (?: transparent | inherit | $colour_value ) }x;
our $individual_border_radius_value
    = qr{ (?: $positive_length_value | $positive_percentage_value ) }x;
our $border_radius_corner_value = qr{
        $individual_border_radius_value
        (?: \s+ $individual_border_radius_value )?
    }x;
our $border_radius_value = qr{
        $individual_border_radius_value
        (?: \s+ $individual_border_radius_value ){0,3}
        (?:
            \s* / \s*
            $individual_border_radius_value

lib/CSS/Prepare/Property/Values.pm  view on Meta::CPAN

    }x;
our $font_family_value = qr{
        (?:
            $font_family
            |
            (?: $font_family (?: \s* \, \s* $font_family )+ )
        )
    }x;
our $line_height_value = qr{
        (?:   normal
            | $number_value | $length_value | $percentage_value
            | inherit
        )
    }x;
our $font_size_value = qr{
        (?:
              xx-small | x-small | small  | medium | large | x-large
            | xx-large | smaller | larger | inherit
            | $length_value | $percentage_value
        )
    }x;
my $font_size_line_height_value
    = qr{ $font_size_value / $line_height_value }x;
our $font_style_value = qr{ (?: italic | oblique | normal | inherit ) }x;
our $font_variant_value = qr{ (?: normal | small-caps | inherit ) }x;
our $font_weight_value = qr{
        (?:
              normal | bold | bolder | lighter
            | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
            | inherit
        )
    }x;

my $height_value
    = qr{ (?: $length_value | $percentage_value | auto | inherit ) }x;
my $letter_spacing_value = qr{ (?: normal | $length_value | inherit ) }x;
our $list_style_image_value = qr{ (?: $url_value | none | inherit ) }x;
our $list_style_position_value = qr{ (?: inside | outside | inherit ) }x;
our $list_style_type_value = qr{
        (?:
              armenian    | circle      | decimal     | decimal-leading-zero
            | disc        | georgian    | lower-alpha | lower-greek
            | lower-latin | lower-roman | upper-alpha | upper-latin
            | upper-roman
            
            | none | inherit
        )
    }x;

our $margin_width_value
    = qr{ (?: $length_value | $percentage_value | auto | inherit ) }x;
my $max_height_value
    = qr{ (?: $length_value | $percentage_value | none | inherit ) }x;
my $max_width_value
    = qr{ (?: $length_value | $percentage_value | none | inherit ) }x;
my $min_height_value
    = qr{ (?: $length_value | $percentage_value | inherit ) }x;
my $min_width_value
    = qr{ (?: $length_value | $percentage_value | inherit ) }x;

my $offset_value
    = qr{ (?: $length_value | $percentage_value | auto | inherit ) }x;
my $opacity_value = qr{ (?: $number_value | inherit ) }x;
our $outline_colour_value = qr{ (?: invert | inherit | $colour_value ) }x;
our $outline_style_value = qr{ (?: $border_style_value ) }x;
our $outline_width_value = qr{ (?: $border_width_value ) }x;
my $overflow_value = qr{ (?: visible | hidden | scroll | auto | inherit ) }x;
our $padding_width_value = qr{
        (?: $positive_length_value | $positive_percentage_value | inherit )
    }x;
my $position_value
    = qr{ (?: absolute | fixed | relative | static | inherit ) }x;
my $quotes_value = qr{
        (?:
              (?:
                  (?: $string_value \s+ $string_value )
                  (?: \s+ $string_value \s+ $string_value )*
              )
            | none | inherit
        )
    }x;

my $table_layout_value = qr{ (?: auto | fixed | inherit ) }x;
my $text_align_value
    = qr{ (?: left | right | center | justify | inherit ) }x;
my $text_decoration_value = qr{
       (?: none | underline | overline | line-through | blink | inherit )
   }x;
my $text_indent_value
    = qr{ (?: $length_value | $percentage_value | inherit ) }x;
my $text_transform_value
    = qr{ (?: capitalize | uppercase | lowercase | none | inherit ) }x;

my $unicode_bidi_value
    = qr{ (?: normal | embed | bidi-override | inherit ) }x;
my $vertical_align_value = qr{
        (?:
              baseline | sub    | super  | top
            | text-top | middle | bottom | text-bottom
            | $length_value | $percentage_value
            | inherit
        )
    }x;
my $visibility_value = qr{ (?: visible | hidden | collapse | inherit ) }x;
my $white_space_value
    = qr{ (?: normal | pre | nowrap | pre-wrap | pre-line | inherit ) }x;
my $width_value
    = qr{ (?: $length_value | $percentage_value | auto | inherit ) }x;
my $word_spacing_value = qr{ (?: normal | $length_value | inherit ) }x;
my $z_index_value = qr{ (?: $integer_value | auto | inherit ) }x;



our $concise_format    = "%s%s;";
our $pretty_format     = "    %-23s %s;\n";
our $concise_separator = ' ';
our $pretty_separator  = "\n" . ( ' ' x 28 );


sub is_length_value {
    my $value = shift;
    return $value =~ m{^ $length_value $}x;
}
sub is_percentage_value {
    my $value = shift;
    return $value =~ m{^ $percentage_value $}x;
}
sub is_string_value {
    my $value = shift;
    return $value =~ m{^ $string_value $}x;
}
sub is_url_value {
    my $value = shift;
    return $value =~ m{^ $url_value $}x;
}

t/01.values.t  view on Meta::CPAN

    foreach my $value ( @invalid_zero_values ) {
        ok( ! is_length_value( $value ),
            "invalid zero: '$value'" );
    }

    my @valid_length_values
        = qw( 0 +0px 5px .5em 10.0001em 15ex 20in 25cm 30mm 35pt 40pc );
    foreach my $value ( @valid_length_values ) {
        ok( is_length_value( $value ),
            "length: '$value'" );
        ok( ! is_percentage_value( $value ),
            "not percentage: '$value'" );
    }

    my @valid_percentage_values = qw( 0.254338% +150% -5% );
    foreach my $value ( @valid_percentage_values ) {
        ok( is_percentage_value( $value ),
            "percentage: '$value'" );
        ok( ! is_length_value( $value ),
            "not length: '$value'" );
    }
}

# test strings
{
    my @strings = ( '"hello"', q('hello'), qq('that\\'s mine'), qq("\\"") );
    foreach my $value ( @strings ) {
        ok( is_string_value( $value ),

t/01.values.t  view on Meta::CPAN

    }
    
    foreach my $value ( @radii ) {
        ok( ! is_border_radius_corner_value( $value ),
            "not border-radius corner: '$value'" );
    }
}

# test margins and padding
{
    # other lengths and percentages are tested above
    ok( is_margin_width_value( '5px' ),
        "margin-width: '5px'" );
    ok( is_margin_width_value( '-2em' ),
        "margin-width: '-2em'" );
    ok( is_margin_width_value( '10%' ),
        "margin-width: '10%'" );
    ok( is_margin_width_value( 'auto' ),
        "margin-width: 'auto'" );
    ok( is_margin_width_value( 'inherit' ),
        "margin-width: 'inherit'" );

t/01.values.t  view on Meta::CPAN

    
    foreach my $value qw( static  relative  absolute  fixed  inherit ) {
        ok( is_position_value( $value ),
            "position: '$value'" );
    }
    ok( ! is_position_value( 'float' ),
        "not position: 'float'" );
    
    
    # top, right, bottom, left properties
    # other lengths and percentages are tested above
    foreach my $value qw( 5px  20%  auto  inherit ) {
        ok( is_offset_value( $value ),
            "offset: '$value'" );
    }
    ok( ! is_offset_value( 'bottom' ),
        "not offset: 'bottom'" );
    
    
    foreach my $value qw( left  right  none  inherit ) {
        ok( is_float_value( $value ),

t/01.values.t  view on Meta::CPAN

    
    
    foreach my $value qw( embed  bidi-override  inherit  normal ) {
        ok( is_unicode_bidi_value( $value ),
            "unicode-bidi: '$value'" );
    }
    ok( ! is_unicode_bidi_value( 'bidi-curious' ),
        "not unicode-bidi: 'bidi-curious'" );
    
    
    # other lengths and percentages are tested above
    my @vertical_align_values = qw(
          baseline  sub     super   top
          text-top  middle  bottom  text-bottom
          5px       20%     inherit
        );
    foreach my $value ( @vertical_align_values ) {
        ok( is_vertical_align_value( $value ),
            "vertical-align: '$value'" );
    }
    ok( ! is_vertical_align_value( 'up' ),
        "not vertical-align: 'up'" );
    ok( ! is_vertical_align_value( '5' ),
        "not vertical-align: '5'" );
    
    
    # other lengths and percentages are tested above
    foreach my $value qw( 5px 20% inherit ) {
        ok( is_height_value( $value ),
            "height: '$value'" );
        ok( is_max_height_value( $value ),
            "max-height: '$value'" );
        ok( is_min_height_value( $value ),
            "min-height: '$value'" );
        ok( is_width_value( $value ),
            "width: '$value'" );
        ok( is_max_width_value( $value ),

t/01.values.t  view on Meta::CPAN

    ok( ! is_min_height_value( 'none' ),
        "not min-height: 'none'" );
    ok( ! is_width_value( 'none' ),
        "not width: 'none'" );
    ok( is_max_width_value( 'none' ),
        "max-width: 'none'" );
    ok( ! is_min_width_value( 'none' ),
        "not min-width: 'none'" );
    
    
    # other lengths and percentages are tested above
    ok( is_line_height_value( 'normal' ),
        "line-height: 'normal'" );
    ok( is_line_height_value( '1.2' ),
        "line-height: '1.2'" );
    ok( is_line_height_value( '5px' ),
        "line-height: '5px'" );
    ok( is_line_height_value( '20%' ),
        "line-height: '20%'" );
    ok( is_line_height_value( 'inherit' ),
        "line-height: 'inherit'" );



( run in 0.329 second using v1.01-cache-2.11-cpan-624ce96ca49 )