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 while (my ($version, $_) = each %$versions) {
113 $rank += $canihas->{$browser}->{$version} * $statspts->{$_};
119 while (my ($browser, $vercols) = each %versions) {
120 my $div = 0; # multiplier exponent (decreased to lower value)
121 my @vers = map { $row->{$browser}->{$_} } @$vercols;
122 if (my $current = $caniuse->{agents}->{$browser}->{versions}->[-3]) {
123 my @future; # find upcoming releases (after current)
124 for (reverse @$vercols) {
125 last if $_ eq $current;
126 push @future, pop @vers;
127 $_ eq 'u' and $_ = $vers[-1] for $future[-1]; # inherit latest value if unknown
129 splice @vers, -1, 0, @future; # move ahead to decrease precedence
131 $rank += $statspts->{$_} * 2**($div--) for reverse @vers;
138 featurescore($caniuse->{data}->{$b}->{stats})
139 <=> featurescore($caniuse->{data}->{$a}->{stats})
140 } keys %{ $caniuse->{data} }) {
141 my $row = $caniuse->{data}->{$id};
142 my $data = $row->{stats} or next; # skip metadata [summary]
143 printf '<tr id="%s">', $id;
144 for ($row->{categories}) {
145 my $cell = $_ ? lc $_->[0] : '-';
148 print '<td>', $row->{title};
149 print '<div class=aside>';
150 s/\.?$/./, print "<p>$_</p>" for map { ref $_ ? @$_ : $_ || () }
151 $row->{description}, $row->{notes};
152 printf 'Resources: %s.', join(', ',
153 map { qq(<a href="$_->{url}">$_->{title}</a>) } @$_
154 ) for $row->{links} // ();
156 for ($row->{status}) {
157 my $cell = $_ // '-';
158 $cell = sprintf '<a href="%s">%s</a>', $_, $cell for $row->{spec} // ();
159 printf '<td title="%s" class="%s">%s',
160 $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $cell;
162 for my $browser (@browsers) {
164 for my $ver (@{ $versions{$browser} }, undef) {
165 unless (!defined $prev
166 or $data->{$browser}->{$prev} ~~ $data->{$browser}->{$ver}) {
167 my $usage = sum(map { $canihas->{$browser}->{$_} } @span);
168 printf '<td class="%s" colspan="%d" title="%.1f%%">%s',
170 X => $CSTATS{ $data->{$browser}->{$prev} },
171 !$usage ? ('p0') : ('p',
172 sprintf('p%01d', $usage / 10),
173 sprintf('p%02d', $usage),
175 sprintf('pp%02d', $usage / $scorediv),
187 state $maxscore = featurescore({ # yes for every possible version
188 map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions
190 print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100;
192 print '<tfoot>', $header;
196 # normalised version number comparable as string (cmp)
197 shift =~ /^(\d*)(.*)/;
198 return sprintf('%02d', $1 || 0) . $2;
202 my @span = ($_[0], @_>1 ? $_[-1] : ());
207 return join('‒', @span);
215 <table class="glyphs"><tr>
216 <td class="X l6">supported
217 <td class="X l5">prefixed
218 <td class="X l4">partial
219 <td class="X l2">external (js/plugin)
220 <td class="X l0">missing
225 <span class=" p0">0</span> -
226 <span class="p p0 p00">.01</span> -
227 <span class="p p0 p05">1-9</span> -
228 <span class="p p1">10</span> -
229 <span class="p p2">20</span> -
230 <span class="p p5">majority</span>
234 <ul class="legend legend-set">
235 <li>default <strong>style</strong> is
236 <:= defined $get{style} && 'set to ' :><em><:= $style :></em>