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>
25 my $caniuse = do 'browser-support.inc.pl' or die $! || $@;
39 unoff => 'l0', # unofficial
41 cr => 'l5', # candidate
42 pr => 'l5', # proposed
43 rec => 'l6', # recommendation
44 ietf => 'l6', # standard
46 my @browsers = qw(trident gecko webkit_saf webkit_chr presto);
48 if (my ($somerow) = values %{ $caniuse->{data} }) {
49 while (my ($browser, $row) = each %{ $somerow->{stats} }) {
50 $versions{$browser} = [ sort { paddedver($a) cmp paddedver($b) } keys %$row ];
54 my $canihas = do 'browser-usage.inc.pl' || do {
55 printf "<p>Browser usage data not found: <em>%s</em>.</p>\n", $_
61 ($_->[4] => 0 ), # future
62 ($_->[3] => .5), # next
63 ($_->[0] => 5 ), # past
64 ($_->[1] => 10 ), # previous
65 ($_->[2] => 30 ), # current
66 } $caniuse->{agents}->{$_}->{versions}
69 }; # fallback hash based on release semantics
71 my $scorediv = (max(map { sum(values %$_) } values %$canihas) // 1) / 100;
73 print '<table class="mapped">';
75 printf '<colgroup span="%d">', scalar @{ $versions{$_} } for @browsers;
80 '<th colspan="3">feature',
82 sprintf('<th colspan="%d" title="%.1f%%">%s',
83 scalar @{ $versions{$_} },
84 sum(values %{ $canihas->{$_} }),
86 my $name = $caniuse->{agents}->{$_}->{browser};
87 length $name < 16 ? $name : $caniuse->{agents}->{$_}->{abbr};
93 print '<thead>', $header;
94 # preceding row without any colspan to work around gecko bug
97 for my $browser (@browsers) {
98 printf('<td title="%.1f%%">%s',
99 $canihas->{$browser}->{$_}, showversions($_),
100 ) for @{ $versions{$browser} };
106 # relative amount of support for given feature
107 state $statspts = { y=>10, 'y x'=>9, a=>5, 'a x'=>5, j=>2, 'p j'=>2, p=>1 };
109 if (my $row = shift) {
111 while (my ($browser, $versions) = each %$row) {
112 ref $versions eq 'HASH' or next;
113 while (my ($version, $_) = each %$versions) {
114 $rank += $canihas->{$browser}->{$version} * $statspts->{$_};
120 while (my ($browser, $vercols) = each %versions) {
121 my $div = 0; # multiplier exponent (decreased to lower value)
122 my @vers = map { $row->{$browser}->{$_} } @$vercols;
123 if (my $current = $caniuse->{agents}->{$browser}->{versions}->[-3]) {
124 my @future; # find upcoming releases (after current)
125 for (reverse @$vercols) {
126 last if $_ eq $current;
127 push @future, pop @vers;
128 $_ eq 'u' and $_ = $vers[-1] for $future[-1]; # inherit latest value if unknown
130 splice @vers, -1, 0, @future; # move ahead to decrease precedence
132 $rank += $statspts->{$_} * 2**($div--) for reverse @vers;
139 featurescore($caniuse->{data}->{$b}->{stats})
140 <=> featurescore($caniuse->{data}->{$a}->{stats})
141 } keys %{ $caniuse->{data} }) {
142 my $row = $caniuse->{data}->{$id};
143 my $data = $row->{stats} or next; # skip metadata [summary]
144 printf '<tr id="%s">', $id;
145 for ($row->{categories}) {
146 my $cell = $_ ? lc $_->[0] : '-';
150 sprintf('<a href="%s" onclick="%s">%s</a>',
152 sprintf("try { %s; return false } catch(err) { return true }",
153 "document.getElementById('$id').classList.toggle('target')",
158 print '<div class=aside>';
159 s/\.?$/./, print "<p>$_</p>" for map { ref $_ ? @$_ : $_ || () }
160 $row->{description}, $row->{notes};
161 printf 'Resources: %s.', join(', ',
162 map { qq(<a href="$_->{url}">$_->{title}</a>) } @$_
163 ) for grep { @$_ } $row->{links} // ();
165 for ($row->{status}) {
166 my $cell = $_ // '-';
167 $cell = sprintf '<a href="%s">%s</a>', $_, $cell for $row->{spec} // ();
168 printf '<td title="%s" class="%s">%s',
169 $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $cell;
171 for my $browser (@browsers) {
173 for my $ver (@{ $versions{$browser} }, undef) {
174 unless (!defined $prev
175 or ref $data->{$browser} eq 'HASH'
176 && $data->{$browser}->{$prev} ~~ $data->{$browser}->{$ver}) {
177 my $usage = sum(map { $canihas->{$browser}->{$_} } @span);
178 printf '<td class="%s" colspan="%d" title="%.1f%%">%s',
181 ref $data->{$browser} ne 'HASH' ? 'u' :
182 $data->{$browser}->{$prev} // 'u'
184 !$usage ? ('p0') : ('p',
185 sprintf('p%01d', $usage / 10),
186 sprintf('p%02d', $usage),
188 sprintf('pp%02d', $usage / $scorediv),
200 state $maxscore = featurescore({ # yes for every possible version
201 map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions
203 print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100;
205 print '<tfoot>', $header;
209 # normalised version number comparable as string (cmp)
210 shift =~ /^(\d*)(.*)/;
211 return sprintf('%02d', $1 || 0) . $2;
215 my @span = ($_[0], @_>1 ? $_[-1] : ());
220 return join('‒', @span);
228 <table class="glyphs"><tr>
229 <td class="X l6">supported
230 <td class="X l5">prefixed
231 <td class="X l4">partial
232 <td class="X l2">external (js/plugin)
233 <td class="X l0">missing
234 <td class="X l9">unknown
239 <span class=" p0">0</span> -
240 <span class="p p0 p00">.01</span> -
241 <span class="p p0 p05">1-9</span> -
242 <span class="p p1">10</span> -
243 <span class="p p2">20</span> -
244 <span class="p p5">majority</span>
248 <ul class="legend legend-set">
249 <li>default <strong>style</strong> is
250 <:= defined $get{style} && 'set to ' :><em><:= $style :></em>