5 title => 'browser compatibility cheat sheet',
9 keywords => [qw'html css browser feature'],
10 stylesheet => [qw'light dark circus mono red'],
11 data => ['caniuse.js'],
15 <h1>Browser compatibility</h1>
17 <p>Alternate view of Fyrd's <a href="http://caniuse.com/">when can I use...</a> site.</p>
21 use File::Slurp 'read_file';
22 my $source = read_file('caniuse.js');
23 for ($source) { # cleanup
24 # convert seperate variables to hash keys
26 s/^caniuse\.(\w+) = /"$1":/gm;
29 # fractions not supported by barekey
30 s/(?<=[,{]) (\d*\.\d) (?=:')/"$1"/gx;
31 # escapes not supported in singlequote
32 s{'((?:[^\\']+|\\.)*)'}{
39 my $caniuse = from_json($source, {
40 # allow_singlequote => 1,
53 unoff => 'di-rare', # unofficial
55 pr => 'di-prop', # proposed
56 cr => 'di-d', # candidate
57 rec => 'di-a', # recommendation
58 ietf => 'di-a', # standard
60 my @browsers = qw(trident gecko webkit_saf presto);
62 if (my ($somerow) = values %{ $caniuse->{data} }) {
63 while (my ($browser, $row) = each %{ $somerow->{stats} }) {
64 $versions{$browser} = [ sort { paddedver($a) cmp paddedver($b) } keys %$row ];
68 print '<table class="glyphs dimap">';
70 printf '<colgroup span="%d">', scalar @{ $versions{$_} } for @browsers;
74 print "<th>$_" for qw(feature status);
75 printf '<th colspan="%d">%s',
76 scalar @{ $versions{$_} }, $caniuse->{agents}->{$_}->{browser}
78 # preceding row without any colspan to work around gecko bug
80 print '<td>' x $_ for 2, map { scalar @{ $versions{$_} } } @browsers;
83 for my $id (keys %{ $caniuse->{data} }) {
84 my $row = $caniuse->{data}->{$id};
85 my $data = $row->{stats} or next; # skip metadata [summary]
86 printf '<tr id="%s">', $id;
87 printf '<th title="%s">%s', $row->{description}, $row->{title};
88 printf '<td title="%s" class="%s">%s', $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $_ for $row->{status};
89 for my $browser (@browsers) {
91 for my $ver (@{ $versions{$browser} }, undef) {
92 unless (!defined $prev
93 or $data->{$browser}->{$prev} ~~ $data->{$browser}->{$ver}) {
94 printf '<td class="%s" colspan="%d">%s',
95 $CSTATS{ $data->{$browser}->{$prev} },
97 join('‒', $span[0], @span > 1 ? $span[-1] : ());
109 # normalised version number comparable as string (cmp)
110 shift =~ /^(\d*)(.*)/;
111 return sprintf('%02d', $1) . $2;
118 <table class="glyphs"><tr>
119 <td class="X di-a">yes
120 <td class="X di-d">almost
121 <td class="X di-prop">plugin or js
122 <td class="X di-b">no
126 <ul class="legend legend-set">
127 <li>default <strong>style</strong> is
128 <:= defined $get{style} && 'set to ' :><em><:= $style :></em>