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);
61 unshift @{ $caniuse->{agents}->{gecko}->{versions} }, 2;
63 print '<table class="glyphs dimap">';
65 printf '<colgroup span="%d">', scalar @{ $caniuse->{agents}->{$_}->{versions} } for @browsers;
69 print "<th>$_" for qw(feature status);
70 printf '<th colspan="%d">%s', scalar @{ $_->{versions} }, $_->{browser}
71 for map { $caniuse->{agents}->{$_} } @browsers;
74 for my $id (keys %{ $caniuse->{data} }) {
75 my $row = $caniuse->{data}->{$id};
76 my $data = $row->{stats} or next; # skip metadata [summary]
77 printf '<tr id="%s">', $id;
78 printf '<th title="%s">%s', $row->{description}, $row->{title};
79 printf '<td title="%s" class="%s">%s', $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $_ for $row->{status};
80 for my $browser (@browsers) {
81 printf '<td class="%s">%s', $CSTATS{ $data->{$browser}->{$_} }, $_
82 for @{ $caniuse->{agents}->{$browser}->{versions} };
91 <table class="glyphs"><tr>
92 <td class="X di-a">yes
93 <td class="X di-d">almost
94 <td class="X di-prop">plugin or js
99 <ul class="legend legend-set">
100 <li>default <strong>style</strong> is
101 <:= defined $get{style} && 'set to ' :><em><:= $style :></em>