CSS-Minifier-XS

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - Simplified whitespace compaction

0.12      2021-01-30 21:46:07-08:00 America/Vancouver
    - rewrote test suite into a single ".t" test
    - GH #1 / RT #97574; whitespace before a ":" in a pseudo-selector is
      meaningful and needs to be preserved (e.g. "#link :visited")
    - Further reductions of "zero values", when possible
      - "00000px" and "0.0px" become "0px"
      - "000%" and "0.0%" become "0%"
      - units are preserved inside of functions, but eliminated otherwise, and
        percentages are always left as a percentages
    - Optimized whitespace collapsing
    - Optimized memory usage and string copying

0.11      2020-12-30 21:27:39-08:00 America/Vancouver
    - POD spelling fixes
    - Switch to DZil Author Bundle

0.10      2020-12-28 11:00:17-08:00 America/Vancouver
    - RT #90879; correct minification of %s in "hsl()" and "hsla()" functions
      Thanks to Philipp Soehnlein
    - RT #103231; don't remove units on zero values inside of functions.
      Thanks to Isaac Montoya, for an additional test case.
    - No long drop units on zero percentages, as those may be required for CSS
      animations.  Thanks to Isaac Montoya for continuing to poke me on this.
    - Now prunes leading whitespace before "!important"
        e.g. "color: red !important" becomes "color:red!important"
    - Switch to Dist::Zilla

0.09        Wed Oct 31 13:00 PDT 2013
    - RT #85350; retain WS around "+" and "-" operators, so that we don't break
      the "calc()" function by accident.
      Thanks to Philipp Soehnlein
    - RT #60239; remove WS around ">" and "~" selector combinators

XS.xs  view on Meta::CPAN

                }

                /* did we skip the entire thing, and thus the Node is "all zeros"? */
                size_t skipped = ptr - curr->contents;
                if (skipped == curr->length) {
                    /* nothing but zeros, so truncate to "0" */
                    CssSetNodeContents(curr, "0", 1);
                    break;
                }

                /* was it a zero percentage? */
                if (*ptr == '%') {
                    /* a zero percentage; truncate to "0%" */
                    CssSetNodeContents(curr, "0%", 2);
                    break;
                }

                /* if all we're left with is a known CSS unit, and we're NOT in
                 * a function (where we have to preserve units), just truncate
                 * to "0"
                 */
                if (!inFunction && CssIsKnownUnit(ptr)) {
                    /* not in a function, and is a zero unit; truncate to "0" */

t/minify.t  view on Meta::CPAN

  };

  subtest 'no units' => sub {
    my $given  = 'p { width: 0 }';
    my $expect = 'p{width:0}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Percent is special, and may need to be preserved for CSS animations
  subtest 'percent' => sub {
    my $given  = 'p { width: 0% }';
    my $expect = 'p{width:0%}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Inside of a function, units/zeros are preserved.
  subtest 'inside a function' => sub {
    my $given  = 'p { width: calc(300px - 0px) }';
    my $expect = 'p{width:calc(300px - 0px)}';

t/minify.t  view on Meta::CPAN


  subtest 'no units' => sub {
    my $given  = 'p { width: .0 }';
    my $expect = 'p{width:0}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Percent is special, and may need to be preserved for CSS animations,
  # but will be minified from "point-zero" to just "zero".
  subtest 'percent' => sub {
    my $given  = 'p { width: .0% }';
    my $expect = 'p{width:0%}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Inside of a function, units/zeros are preserved.
  subtest 'inside a function' => sub {
    my $given  = 'p { width: calc(300px - .0px) }';
    my $expect = 'p{width:calc(300px - 0px)}';

t/minify.t  view on Meta::CPAN

  };

  subtest 'no units' => sub {
    my $given  = 'p { width: .001 }';
    my $expect = 'p{width:.001}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Percent is special, and may need to be preserved for CSS animations
  subtest 'percent' => sub {
    my $given  = 'p { width: .001% }';
    my $expect = 'p{width:.001%}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Inside of a function, units/zeros are preserved.
  subtest 'inside a function' => sub {
    my $given  = 'p { width: calc(300px - .001px) }';
    my $expect = 'p{width:calc(300px - .001px)}';

t/minify.t  view on Meta::CPAN

# "something point zero" requires preservation of the unit
subtest 'something-point-zero preserves units' => sub {
  subtest 'px' => sub {
    my $given  = 'p { width: 1.0px }';
    my $expect = 'p{width:1.0px}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Percent is special, and may need to be preserved for CSS animations
  subtest 'percent' => sub {
    my $given  = 'p { width: 1.0% }';
    my $expect = 'p{width:1.0%}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Inside of a function, units/zeros are preserved.
  subtest 'inside a function' => sub {
    my $given  = 'p { width: calc(300px - 1.0px) }';
    my $expect = 'p{width:calc(300px - 1.0px)}';

t/minify.t  view on Meta::CPAN


  subtest 'no units' => sub {
    my $given  = 'p { width: 0.0 }';
    my $expect = 'p{width:0}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Percent is special, and may need to be preserved for CSS animations,
  # but will be minified from "zero-point-zero" to just "zero".
  subtest 'percent' => sub {
    my $given  = 'p { width: 0.0% }';
    my $expect = 'p{width:0%}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Inside of a function, units/zeros are preserved.
  subtest 'inside a function' => sub {
    my $given  = 'p { width: calc(300px - 0.0px) }';
    my $expect = 'p{width:calc(300px - 0px)}';

t/minify.t  view on Meta::CPAN

  subtest 'no units' => sub {
    my $given  = 'p { width: 0.001 }';
    my $expect = 'p{width:.001}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Percent is special, and may need to be preserved for CSS animations,
  # but will be minified from "zero-point-zero-something" to just
  # "point-zero-something"
  subtest 'percent' => sub {
    my $given  = 'p { width: 0.001% }';
    my $expect = 'p{width:.001%}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Inside of a function, units/zeros are preserved.
  subtest 'inside a function' => sub {
    my $given  = 'p { width: calc(300px - 0.001px) }';
    my $expect = 'p{width:calc(300px - .001px)}';

t/minify.t  view on Meta::CPAN


  subtest 'no units' => sub {
    my $given  = 'p { width: 0000 }';
    my $expect = 'p{width:0}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Percent is special, and may need to be preserved for CSS animations,
  # but will be minified from "zerooooo" to just "zero".
  subtest 'percent' => sub {
    my $given  = 'p { width: 000% }';
    my $expect = 'p{width:0%}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Inside of a function, units/zeros are preserved.
  subtest 'inside a function' => sub {
    my $given  = 'p { width: calc(300px - 0000px) }';
    my $expect = 'p{width:calc(300px - 0px)}';

t/minify.t  view on Meta::CPAN

subtest 'zerooooo-point-zeroooo without units' => sub {
  subtest 'px' => sub {
    my $given  = 'p { width: 000.0000px }';
    my $expect = 'p{width:0}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Percent is special, and may need to be preserved for CSS animations,
  # but will be minified from "zerooo-point-zerooo" to just "zero".
  subtest 'percent' => sub {
    my $given  = 'p { width: 000.000% }';
    my $expect = 'p{width:0%}';
    my $got    = minify($given);
    is $got, $expect;
  };

  # Inside of a function, units/zeros are preserved.
  subtest 'inside a function' => sub {
    my $given  = 'p { width: calc(300px - 000.0000px) }';
    my $expect = 'p{width:calc(300px - 0px)}';

xt/author/comparison.t  view on Meta::CPAN

    # Compress the CSS
    my $small;
    my $count = countit($time, sub { $small = $cb->($css) } );

    # Stuff the compressed CSS out to file for examination
    my $fname = lc($name);
    $fname =~ s{\W+}{-}g;
    my $fout  = IO::File->new(">$fname.out");
    $fout->print($small);

    # Calculate length, speed, and percent savings
    my $before   = length($css);
    my $after    = length($small);
    my $rate     = sprintf('%ld', ($count->iters / $time) * $before);
    my $savings  = sprintf('%0.2f%%', (($before - $after) / $before) * 100);

    my $results  = sprintf("%20s before[%7d] after[%7d] savings[%6s] rate[%8s/sec]",
      $name, $before, $after, $savings, format_bytes($rate, unit => 'K', precision => 0),
    );
    pass $results;
}



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