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' or do {
54 printf "<p>Browser usage data not found: <em>%s</em>.</p>\n", $_
57 my $scorediv = (max(map { sum(values %$_) } values %$canihas) // 1) / 100;
59 print '<table class="mapped">';
61 printf '<colgroup span="%d">', scalar @{ $versions{$_} } for @browsers;
66 '<th colspan="3">feature',
68 sprintf('<th colspan="%d" title="%.1f%%">%s',
69 scalar @{ $versions{$_} },
70 sum(values %{ $canihas->{$_} }),
72 my $name = $caniuse->{agents}->{$_}->{browser};
73 length $name < 16 ? $name : $caniuse->{agents}->{$_}->{abbr};
79 print '<thead>', $header;
80 # preceding row without any colspan to work around gecko bug
83 for my $browser (@browsers) {
84 printf('<td title="%.1f%%">%s',
85 $canihas->{$browser}->{$_}, showversions($_),
86 ) for @{ $versions{$browser} };
92 # relative amount of support for given feature
93 state $statspts = { y=>10, 'y x'=>9, a=>5, 'a x'=>5, j=>2, 'p j'=>2, p=>1 };
95 if (my $row = shift) {
97 while (my ($browser, $versions) = each %$row) {
98 while (my ($version, $_) = each %$versions) {
99 $rank += $canihas->{$browser}->{$version} * $statspts->{$_};
105 while (my ($browser, $vercols) = each %versions) {
106 my $div = 0; # multiplier exponent (decreased to lower value)
107 my @vers = map { $row->{$browser}->{$_} } @$vercols;
108 if (my $current = $caniuse->{agents}->{$browser}->{versions}->[-3]) {
109 my @future; # find upcoming releases (after current)
110 for (reverse @$vercols) {
111 last if $_ eq $current;
112 push @future, pop @vers;
113 $_ eq 'u' and $_ = $vers[-1] for $future[-1]; # inherit latest value if unknown
115 splice @vers, -1, 0, @future; # move ahead to decrease precedence
117 $rank += $statspts->{$_} * 2**($div--) for reverse @vers;
124 featurescore($caniuse->{data}->{$b}->{stats})
125 <=> featurescore($caniuse->{data}->{$a}->{stats})
126 } keys %{ $caniuse->{data} }) {
127 my $row = $caniuse->{data}->{$id};
128 my $data = $row->{stats} or next; # skip metadata [summary]
129 printf '<tr id="%s">', $id;
130 for ($row->{categories}) {
131 my $cell = $_ ? lc $_->[0] : '-';
134 printf '<td title="%s">%s', $row->{description}, $row->{title};
135 for ($row->{status}) {
136 my $cell = $_ // '-';
137 $cell = sprintf '<a href="%s">%s</a>', $_, $cell for $row->{spec} // ();
138 printf '<td title="%s" class="%s">%s',
139 $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $cell;
141 for my $browser (@browsers) {
143 for my $ver (@{ $versions{$browser} }, undef) {
144 unless (!defined $prev
145 or $data->{$browser}->{$prev} ~~ $data->{$browser}->{$ver}) {
146 my $usage = sum(map { $canihas->{$browser}->{$_} } @span);
147 printf '<td class="%s" colspan="%d" title="%.1f%%">%s',
149 X => $CSTATS{ $data->{$browser}->{$prev} },
150 !$usage ? ('p0') : ('p',
151 sprintf('p%01d', $usage / 10),
152 sprintf('p%02d', $usage),
154 sprintf('pp%02d', $usage / $scorediv),
166 state $maxscore = featurescore({ # yes for every possible version
167 map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions
169 print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100;
171 print '<tfoot>', $header;
175 # normalised version number comparable as string (cmp)
176 shift =~ /^(\d*)(.*)/;
177 return sprintf('%02d', $1) . $2;
181 my @span = ($_[0], @_>1 ? $_[-1] : ());
186 return join('‒', @span);
193 <table class="glyphs"><tr>
194 <td class="X l6">supported
195 <td class="X l5">prefixed
196 <td class="X l4">partial
197 <td class="X l2">external (js/plugin)
198 <td class="X l0">missing
203 <span class=" p0">0</span> -
204 <span class="p p0 p00">.01</span> -
205 <span class="p p0 p05">1-9</span> -
206 <span class="p p1">10</span> -
207 <span class="p p2">20</span> -
208 <span class="p p5">majority</span>
212 <ul class="legend legend-set">
213 <li>default <strong>style</strong> is
214 <:= defined $get{style} && 'set to ' :><em><:= $style :></em>