+<:
+$canihas ||= {
+ map {
+ $_ => +{
+ map {
+ my $zero = $#$_ - 2; # baseline index
+ ($_->[$zero - 2] => .5), # past
+ ($_->[$zero - 1] => 10 ), # previous
+ ($_->[$zero + 2] => 0 ), # future
+ ($_->[$zero + 1] => .5), # next
+ ($_->[$zero ] => 30 ), # current
+ } $caniuse->{agents}->{$_}->{versions}
+ }
+ } @browsers
+}; # fallback hash based on release semantics
+my $usagemax = (max(map { ref $_ eq 'HASH' && sum(values %$_) } values %$canihas) // 1) / 100;
+
+my $usagepct = 1; # score multiplier for 0..100 result
+# normalise usage percentage to only include shown browsers
+$usagepct = 100 / featurescore({ # yes for every possible version
+ map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions
+});
+
+print '<table class="mapped">';
+print '<col span="3">'; # should match first thead row
+printf '<colgroup span="%d">', scalar @{ $versions{$_} } for @browsers;
+say '</colgroup><col>';
+
+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->{$_} }) * $usagepct),
+ $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) {
+ for my $_ (@{ $versions{$browser} }) {
+ my $release = $caniuse->{agents}->{$browser}->{verrelease}->{$_};
+ my $future = defined $release;
+ printf('<td title="%s"%s>%s',
+ join(' ',
+ sprintf('%.1f%%', $canihas->{$browser}->{$_} * $usagepct),
+ $future ? 'development' : (),
+ "version $_",
+ ),
+ $future && ' class="ex"',
+ showversions($_),
+ );
+ }
+}
+print '<td>' x 1;
+say '</thead>';
+say '<tfoot>', $header, '</tfoot>';
+
+sub featurescore {
+ # relative amount of support for given feature
+ state $statspts = { y=>1, 'y x'=>1, 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}),
+ map { s/\s*\n/\n<br>/g; $_ } $row->{notes};
+ printf 'Resources: %s.', join(', ', map {
+ sprintf '<a href="%s">%s</a>', EscapeHTML($_->{url}), $_->{title}
+ } @$_) for grep { @$_ } $row->{links} // ();
+ printf '<br>Parent feature: %s.', join(', ', map {
+ sprintf '<a href="%s">%s</a>', EscapeHTML("#$_"), $caniuse->{data}->{$_}->{title}
+ } $_) for $row->{parent} || ();
+ print '</div>';
+}
+
+sub saystatuscol {
+ my ($id) = @_;