<(common.inc.plp)><:
use 5.010;
+use utf8;
use List::Util qw(sum max);
Html({
description =>
"caniuse.",
keywords => [qw'html css browser feature'],
- stylesheet => [qw'light dark circus mono red'],
- data => ['caniuse.js'],
+ stylesheet => [qw'circus dark mono red'],
+ data => ['browser-support.inc.pl'],
});
:>
browser usage statistics.</p>
<:
-use JSON;
-use File::Slurp 'read_file';
-my $source = read_file('caniuse.js');
-for ($source) { # cleanup
- # convert seperate variables to hash keys
- s/\A/{/;
- s/^caniuse\.(\w+) = /"$1":/gm;
- s/;$/,/gm;
- s/,\s*\Z/\n}/;
- # fractions not supported by barekey
- s/(?<=[,{]) (\d*\.\d) (?=:')/"$1"/gx;
- # escapes not supported in singlequote
- s{'((?:[^\\']+|\\.)*)'}{
- my $_ = $1;
- s/"/\\"/g;
- s/\\'/'/g;
- qq("$_");
- }ge;
-}
-my $caniuse = from_json($source, {
-# allow_singlequote => 1,
- allow_barekey => 1,
-});
+my $caniuse = do 'browser-support.inc.pl' or die $! || $@;
my %CSTATS = (
- n => 'di-b',
- y => 'di-aa',
- a => 'di-d',
- 'a x' => 'di-d',
- j => 'di-prop',
- p => 'di-prop',
- 'p j' => 'di-prop',
- 'y x' => 'di-a',
+ 'n' => 'l0',
+ 'y' => 'l6',
+ 'y x' => 'l5',
+ 'a' => 'l4',
+ 'a x' => 'l4',
+ 'p j' => 'l2',
+ 'j' => 'l2',
+ 'p' => 'l2',
);
my %CSTATUS = (
- unoff => 'di-rare', # unofficial
- wd => 'di-b', # draft
- pr => 'di-prop', # proposed
- cr => 'di-d', # candidate
- rec => 'di-a', # recommendation
- ietf => 'di-aa', # standard
+ unoff => 'ex', # unofficial
+ wd => 'l0', # draft
+ pr => 'l2', # proposed
+ cr => 'l4', # candidate
+ rec => 'l5', # recommendation
+ ietf => 'l6', # standard
);
my @browsers = qw(trident gecko webkit_saf webkit_chr presto);
my %versions;
printf '<colgroup span="%d">', scalar @{ $versions{$_} } for @browsers;
print "\n";
-print '<thead><tr>';
-print '<th colspan="3">feature';
-printf '<th colspan="%d">%s',
- scalar @{ $versions{$_} }, $caniuse->{agents}->{$_}->{browser}
- for @browsers;
-print '<th>%';
+my $header = join('',
+ '<tr>',
+ '<th colspan="3">feature',
+ (map {
+ sprintf('<th colspan="%d" title="%.1f%%">%s',
+ scalar @{ $versions{$_} },
+ sum(values %{ $canihas->{$_} }),
+ do {
+ my $name = $caniuse->{agents}->{$_}->{browser};
+ length $name < 16 ? $name : $caniuse->{agents}->{$_}->{abbr};
+ },
+ )
+ } @browsers),
+ '<th>%',
+);
+print '<thead>', $header;
# preceding row without any colspan to work around gecko bug
-print '<tr>';
-print '<td>' x $_ for 3, (map { scalar @{ $versions{$_} } } @browsers), 1;
+print "\n<tr>";
+print '<td>' x 3;
+for my $browser (@browsers) {
+ printf('<td title="%.1f%%">%s',
+ $canihas->{$browser}->{$_}, showversions($_),
+ ) for @{ $versions{$browser} };
+}
+print '<td>' x 1;
print "</thead>\n";
sub featurescore {
),
scalar @span,
$usage,
- showversions(\@span),
+ showversions(@span),
undef $prev;
@span = ();
}
});
print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100;
}
+print '<tfoot>', $header;
print '</table>';
sub paddedver {
}
sub showversions {
- my ($span) = @_;
- splice @$span, 1, -1;
- for (@$span) {
+ my @span = ($_[0], @_>1 ? $_[-1] : ());
+ for (@span) {
s/^\./0./;
s/x$/.*/;
}
- return join('‒', @$span);
+ return join('‒', @span);
}
:>
+<script>
+var classmatch = /\bopacity(\d+)/;
+Array.forEach(document.getElementsByTagName('TD'), function(val) {
+ var opacity;
+ if (opacity = classmatch.exec(val.className)) {
+ var c = document.defaultView.getComputedStyle(val, null).getPropertyValue('background-color');
+ var o = opacity[1] / 100;
+ val.style.backgroundColor = c.replace(/rgb\((.*)\)/, 'rgba($1, '+o+')');
+ val.style.textShadow = c+' 1px 1px 2px, ' + c+' -1px -1px 2px';
+ }
+});
+alert(t);
+</script>
<hr>
<div class="legend">
<table class="glyphs"><tr>
- <td class="X di-aa">supported
- <td class="X di-a">prefixed
- <td class="X di-d">partial
- <td class="X di-prop">external (js/plugin)
- <td class="X di-b">missing
+ <td class="X l6">supported
+ <td class="X l5">prefixed
+ <td class="X l4">partial
+ <td class="X l2">external (js/plugin)
+ <td class="X l0">missing
</table>
<div class="right">