3 use List::Util qw(sum max);
6 title => 'browser compatibility cheat sheet',
10 keywords => [qw'html css browser feature'],
11 stylesheet => [qw'light dark circus mono red'],
12 data => ['browser-support.inc.pl'],
16 <h1>Browser compatibility</h1>
18 <p>Alternate view of Fyrd's <a href="http://caniuse.com/">when can I use...</a> page
19 with <a href="http://stats.wikimedia.org/archive/squid_reports/">Wikimedia</a>
20 browser usage statistics.</p>
23 my $caniuse = do 'browser-support.inc.pl' or die $! || $@;
36 unoff => 'di-rare', # unofficial
38 pr => 'di-prop', # proposed
39 cr => 'di-d', # candidate
40 rec => 'di-a', # recommendation
41 ietf => 'di-aa', # standard
43 my @browsers = qw(trident gecko webkit_saf webkit_chr presto);
45 if (my ($somerow) = values %{ $caniuse->{data} }) {
46 while (my ($browser, $row) = each %{ $somerow->{stats} }) {
47 $versions{$browser} = [ sort { paddedver($a) cmp paddedver($b) } keys %$row ];
51 my $canihas = do 'browser-usage.inc.pl' or do {
52 printf "<p>Browser usage data not found: <em>%s</em>.</p>\n", $_
55 my $scorediv = (max(map { sum(values %$_) } values %$canihas) // 1) / 100;
57 print '<table class="mapped">';
59 printf '<colgroup span="%d">', scalar @{ $versions{$_} } for @browsers;
63 print '<th colspan="3">feature';
64 printf('<th colspan="%d">%s',
65 scalar @{ $versions{$_} },
67 my $name = $caniuse->{agents}->{$_}->{browser};
68 length $name < 16 ? $name : $caniuse->{agents}->{$_}->{abbr};
72 # preceding row without any colspan to work around gecko bug
75 for my $browser (@browsers) {
76 printf('<td title="%.1f%%">%s',
77 $canihas->{$browser}->{$_}, showversions($_),
78 ) for @{ $versions{$browser} };
84 # relative amount of support for given feature
85 state $statspts = { y=>10, 'y x'=>9, a=>5, 'a x'=>5, j=>2, 'p j'=>2, p=>1 };
87 if (my $row = shift) {
89 while (my ($browser, $versions) = each %$row) {
90 while (my ($version, $_) = each %$versions) {
91 $rank += $canihas->{$browser}->{$version} * $statspts->{$_};
97 while (my ($browser, $vercols) = each %versions) {
98 my $div = 0; # multiplier exponent (decreased to lower value)
99 my @vers = map { $row->{$browser}->{$_} } @$vercols;
100 if (my $current = $caniuse->{agents}->{$browser}->{versions}->[-3]) {
101 my @future; # find upcoming releases (after current)
102 for (reverse @$vercols) {
103 last if $_ eq $current;
104 push @future, pop @vers;
105 $_ eq 'u' and $_ = $vers[-1] for $future[-1]; # inherit latest value if unknown
107 splice @vers, -1, 0, @future; # move ahead to decrease precedence
109 $rank += $statspts->{$_} * 2**($div--) for reverse @vers;
116 featurescore($caniuse->{data}->{$b}->{stats})
117 <=> featurescore($caniuse->{data}->{$a}->{stats})
118 } keys %{ $caniuse->{data} }) {
119 my $row = $caniuse->{data}->{$id};
120 my $data = $row->{stats} or next; # skip metadata [summary]
121 printf '<tr id="%s">', $id;
122 for ($row->{categories}) {
123 my $cell = $_ ? lc $_->[0] : '-';
126 printf '<td title="%s">%s', $row->{description}, $row->{title};
127 for ($row->{status}) {
128 my $cell = $_ // '-';
129 $cell = sprintf '<a href="%s">%s</a>', $_, $cell for $row->{spec} // ();
130 printf '<td title="%s" class="%s">%s',
131 $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $cell;
133 for my $browser (@browsers) {
135 for my $ver (@{ $versions{$browser} }, undef) {
136 unless (!defined $prev
137 or $data->{$browser}->{$prev} ~~ $data->{$browser}->{$ver}) {
138 my $usage = sum(map { $canihas->{$browser}->{$_} } @span);
139 printf '<td class="%s" colspan="%d" title="%.1f%%">%s',
141 $CSTATS{ $data->{$browser}->{$prev} },
142 sprintf('opacity%.0f', $usage / $scorediv),
154 state $maxscore = featurescore({ # yes for every possible version
155 map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions
157 print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100;
162 # normalised version number comparable as string (cmp)
163 shift =~ /^(\d*)(.*)/;
164 return sprintf('%02d', $1) . $2;
168 my @span = ($_[0], @_>1 ? $_[-1] : ());
173 return join('‒', @span);
180 <table class="glyphs"><tr>
181 <td class="X di-aa">supported
182 <td class="X di-a">prefixed
183 <td class="X di-d">partial
184 <td class="X di-prop">external (js/plugin)
185 <td class="X di-b">missing
189 <ul class="legend legend-set">
190 <li>default <strong>style</strong> is
191 <:= defined $get{style} && 'set to ' :><em><:= $style :></em>