4 use List::Util qw(sum max);
7 title => 'browser compatibility cheat sheet',
11 keywords => [qw'html css browser feature'],
12 stylesheet => [qw'circus dark mono red light'],
13 data => ['browser-support.inc.pl'],
17 <h1>Browser compatibility</h1>
19 <p>Alternate view of Fyrd's <a href="http://caniuse.com/">when can I use...</a> page
20 with <a href="http://stats.wikimedia.org/archive/squid_reports/">Wikimedia</a>
21 browser usage statistics.</p>
24 my $caniuse = do 'browser-support.inc.pl' or die $! || $@;
38 unoff => 'l0', # unofficial
40 cr => 'l5', # candidate
41 pr => 'l5', # proposed
42 rec => 'l6', # recommendation
43 ietf => 'l6', # standard
45 my @browsers = qw(trident gecko webkit_saf webkit_chr presto);
47 if (my ($somerow) = values %{ $caniuse->{data} }) {
48 while (my ($browser, $row) = each %{ $somerow->{stats} }) {
49 $versions{$browser} = [ sort { paddedver($a) cmp paddedver($b) } keys %$row ];
53 my $canihas = do 'browser-usage.inc.pl' || do {
54 printf "<p>Browser usage data not found: <em>%s</em>.</p>\n", $_
60 ($_->[4] => 0 ), # future
61 ($_->[3] => .5), # next
62 ($_->[0] => 5 ), # past
63 ($_->[1] => 10 ), # previous
64 ($_->[2] => 30 ), # current
65 } $caniuse->{agents}->{$_}->{versions}
68 }; # fallback hash based on release semantics
70 my $scorediv = (max(map { sum(values %$_) } values %$canihas) // 1) / 100;
72 print '<table class="mapped">';
74 printf '<colgroup span="%d">', scalar @{ $versions{$_} } for @browsers;
79 '<th colspan="3">feature',
81 sprintf('<th colspan="%d" title="%.1f%%">%s',
82 scalar @{ $versions{$_} },
83 sum(values %{ $canihas->{$_} }),
85 my $name = $caniuse->{agents}->{$_}->{browser};
86 length $name < 16 ? $name : $caniuse->{agents}->{$_}->{abbr};
92 print '<thead>', $header;
93 # preceding row without any colspan to work around gecko bug
96 for my $browser (@browsers) {
97 printf('<td title="%.1f%%">%s',
98 $canihas->{$browser}->{$_}, showversions($_),
99 ) for @{ $versions{$browser} };
105 # relative amount of support for given feature
106 state $statspts = { y=>10, 'y x'=>9, a=>5, 'a x'=>5, j=>2, 'p j'=>2, p=>1 };
108 if (my $row = shift) {
110 while (my ($browser, $versions) = each %$row) {
111 while (my ($version, $_) = each %$versions) {
112 $rank += $canihas->{$browser}->{$version} * $statspts->{$_};
118 while (my ($browser, $vercols) = each %versions) {
119 my $div = 0; # multiplier exponent (decreased to lower value)
120 my @vers = map { $row->{$browser}->{$_} } @$vercols;
121 if (my $current = $caniuse->{agents}->{$browser}->{versions}->[-3]) {
122 my @future; # find upcoming releases (after current)
123 for (reverse @$vercols) {
124 last if $_ eq $current;
125 push @future, pop @vers;
126 $_ eq 'u' and $_ = $vers[-1] for $future[-1]; # inherit latest value if unknown
128 splice @vers, -1, 0, @future; # move ahead to decrease precedence
130 $rank += $statspts->{$_} * 2**($div--) for reverse @vers;
137 featurescore($caniuse->{data}->{$b}->{stats})
138 <=> featurescore($caniuse->{data}->{$a}->{stats})
139 } keys %{ $caniuse->{data} }) {
140 my $row = $caniuse->{data}->{$id};
141 my $data = $row->{stats} or next; # skip metadata [summary]
142 printf '<tr id="%s">', $id;
143 for ($row->{categories}) {
144 my $cell = $_ ? lc $_->[0] : '-';
147 printf '<td title="%s">%s', $row->{description}, $row->{title};
148 for ($row->{status}) {
149 my $cell = $_ // '-';
150 $cell = sprintf '<a href="%s">%s</a>', $_, $cell for $row->{spec} // ();
151 printf '<td title="%s" class="%s">%s',
152 $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $cell;
154 for my $browser (@browsers) {
156 for my $ver (@{ $versions{$browser} }, undef) {
157 unless (!defined $prev
158 or $data->{$browser}->{$prev} ~~ $data->{$browser}->{$ver}) {
159 my $usage = sum(map { $canihas->{$browser}->{$_} } @span);
160 printf '<td class="%s" colspan="%d" title="%.1f%%">%s',
162 X => $CSTATS{ $data->{$browser}->{$prev} },
163 !$usage ? ('p0') : ('p',
164 sprintf('p%01d', $usage / 10),
165 sprintf('p%02d', $usage),
167 sprintf('pp%02d', $usage / $scorediv),
179 state $maxscore = featurescore({ # yes for every possible version
180 map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions
182 print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100;
184 print '<tfoot>', $header;
188 # normalised version number comparable as string (cmp)
189 shift =~ /^(\d*)(.*)/;
190 return sprintf('%02d', $1) . $2;
194 my @span = ($_[0], @_>1 ? $_[-1] : ());
199 return join('‒', @span);
206 <table class="glyphs"><tr>
207 <td class="X l6">supported
208 <td class="X l5">prefixed
209 <td class="X l4">partial
210 <td class="X l2">external (js/plugin)
211 <td class="X l0">missing
216 <span class=" p0">0</span> -
217 <span class="p p0 p00">.01</span> -
218 <span class="p p0 p05">1-9</span> -
219 <span class="p p1">10</span> -
220 <span class="p p2">20</span> -
221 <span class="p p5">majority</span>
225 <ul class="legend legend-set">
226 <li>default <strong>style</strong> is
227 <:= defined $get{style} && 'set to ' :><em><:= $style :></em>