+my $header = join('',
+ '<tr>',
+ '<th colspan="3">feature',
+ (map {
+ my $name = $caniuse->{agents}->{$_}->{browser};
+ sprintf('<th colspan="%d" class="%s" title="%s">%s',
+ scalar @{ $versions{$_} },
+ join(' ', map {"b-a-$_"} grep {$_}
+ $_, @{ $caniuse->{agents}->{$_} }{'prefix', 'type'},
+ ),
+ join(' ',
+ sprintf('%.1f%%', sum(values %{ $canihas->{$_} })),
+ $name,
+ ),
+ do {
+ length $name < 3 + @{ $versions{$_} }*2 ? $name
+ : $caniuse->{agents}->{$_}->{abbr};
+ },
+ )
+ } @browsers),
+ '<th>%',
+);
+print '<thead>', $header;
+# preceding row without any colspan to work around gecko bug
+print "\n<tr>";
+print '<td>' x 3;
+for my $browser (@browsers) {
+ printf('<td title="%s"%s>%s',
+ join(' ',
+ sprintf('%.1f%%', $canihas->{$browser}->{$_}),
+ "version $_",
+ ),
+ (map {
+ defined $_ && !$_ && ' class="ex"'
+ } $caniuse->{agents}->{$browser}->{verrelease}->{$_}),
+ showversions($_),
+ ) for @{ $versions{$browser} };
+}
+print '<td>' x 1;
+say '</thead>';
+say '<tfoot>', $header, '</tfoot>';
+
+sub featurescore {
+ # relative amount of support for given feature
+ state $statspts = { y=>10, 'y x'=>10, a=>5, 'a x'=>5, j=>2, 'p j'=>2, 'p p'=>2, p=>1 };
+ my $rank = 0;
+ if (my $row = shift) {
+ if ($canihas) {
+ while (my ($browser, $versions) = each %$row) {
+ ref $versions eq 'HASH' or next;
+ while (my ($version, $_) = each %$versions) {
+ $rank += ($canihas->{$browser}->{$version} || .001) * $statspts->{$_};
+ }
+ }
+ return $rank;
+ }
+
+ while (my ($browser, $vercols) = each %versions) {
+ my $div = 0; # multiplier exponent (decreased to lower value)
+ my @vers = map { $row->{$browser}->{$_} } @$vercols;
+ if (my $current = $caniuse->{agents}->{$browser}->{versions}->[-3]) {
+ my @future; # find upcoming releases (after current)
+ for (reverse @$vercols) {
+ last if $_ eq $current;
+ push @future, pop @vers;
+ $_ eq 'u' and $_ = $vers[-1] for $future[-1]; # inherit latest value if unknown
+ }
+ splice @vers, -1, 0, @future; # move ahead to decrease precedence
+ }
+ $rank += $statspts->{$_} * 2**($div--) for reverse @vers;
+ }
+ }
+ return $rank;
+}
+
+sub saytitlecol {
+ my ($id) = @_;
+ my $row = $caniuse->{data}->{$id};
+
+ for ($row->{categories}) {
+ my $cell = $_ ? lc $_->[0] : '-';
+ $cell =~ s/ api$//; # trim unessential fluff in 'js api'
+ printf '<th title="%s">%s', join(' + ', @$_), $cell;
+ }
+
+ print '<td>', map {
+ sprintf('<a href="%s" onclick="%s">%s</a>',
+ "#$id",
+ sprintf("try { %s; return false } catch(err) { return true }",
+ "document.getElementById('$id').classList.toggle('target')",
+ ),
+ Entity($_),
+ );
+ } $row->{title};
+ print '<div class=aside>';
+ s/\.?$/./, print "<p>$_</p>" for map { ref $_ ? @$_ : $_ || () }
+ Entity($row->{description}), formathtml($row->{notes}); # sic
+ printf 'Resources: %s.', join(', ', map {
+ sprintf '<a href="%s">%s</a>', EscapeHTML($_->{url}), $_->{title}
+ } @$_) for grep { @$_ } $row->{links} // ();
+ print '</div>';
+}