- my $data = $row->{stats} or next; # skip metadata [summary]
- printf '<tr id="%s">', $id;
- printf '<th title="%s">%s', $row->{description}, $row->{title};
- printf '<td title="%s" class="%s">%s', $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $_ for $row->{status};
- for my $browser (@browsers) {
- my ($prev, @span);
- for my $ver (@{ $versions{$browser} }, undef) {
- unless (!defined $prev
- or $data->{$browser}->{$prev} ~~ $data->{$browser}->{$ver}) {
- printf '<td class="%s" colspan="%d">%s',
- $CSTATS{ $data->{$browser}->{$prev} },
- scalar @span,
- join('‒', $span[0], @span > 1 ? $span[-1] : ());
- undef $prev;
- @span = ();
- }
- push @span, $ver;
- $prev = $ver;
+
+ 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>';
+ print "<p>$_</p>"
+ for formatnotes($row->{description}, $row->{notes} || ());
+ if (my %notes = %{ $row->{notes_by_num} }) {
+ say '<p>Browser-specific notes:';
+ say "<br>#$_: ", formatnotes($notes{$_}) for sort keys %notes;
+ say '</p>';
+ }
+ printf 'Resources: %s.', join(', ', map {
+ showlink($_->{title}, $_->{url})
+ } @$_) for grep { @$_ } $row->{links} // ();
+ printf '<br>Parent feature: %s.', join(', ', map {
+ showlink($caniuse->{data}->{$_}->{title}, "#$_")
+ } $_) for $row->{parent} || ();
+ print '</div>';
+}
+
+sub saystatuscol {
+ my ($id) = @_;
+ my $row = $caniuse->{data}->{$id};
+
+ for ($row->{status}) {
+ my $cell = $_ // '-';
+ $cell = showlink($cell, $_) for $row->{spec} // ();
+ printf '<td title="%s" class="l %s">%s',
+ $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $cell;
+ }
+}
+
+sub saybrowsercols {
+ my ($id, $browser) = @_;
+ my $feature = $caniuse->{data}->{$id};
+ my $data = $feature->{stats}->{$browser};
+ if (ref $data eq 'ARRAY') {
+ # special case for unsupported
+ my $release = $caniuse->{agents}->{$browser}->{verrelease};
+ $data = {
+ map { $_ => defined $release->{$_} ? 'u' : 'n' } keys %$release
+ };
+ }
+
+ my ($prev, @span);
+ for my $ver (@{ $versions{$browser} }, undef) {
+ my $compare = (
+ !defined $ver ? undef : # last column if nameless
+ ref $data ne 'HASH' ? '' : # unclassified if no support hash
+ $data->{ $ver->[-1] } // $prev # known or inherit from predecessor
+ // (grep { defined } @{$data}{ map { $_->[0] } @{ $versions{$browser} } })[0]
+ ~~ 'n' && 'n' # first known version is unsupported
+ || 'u' # unsure
+ );
+ unless (!defined $prev or $prev ~~ $compare) {
+ my $usage = sum(@{ $canihas->{$browser} }{ map { @{$_} } @span });
+
+ # strip #\d note references from support class
+ my @notes;
+ push @notes, $feature->{notes_by_num}->{$1}
+ while $prev =~ s/\h \# (\d+) \b//x;
+
+ # prepare version hover details
+ my $title = sprintf('%.1f%% %s', $usage * $usagepct, join(', ',
+ map { ref $_ eq 'CODE' ? $_->($browser, $span[0]->[0]) : $_ }
+ map { $DSTATS{$_} // () }
+ map { split / /, $_ }
+ $prev
+ ));
+ $title .= "\n$_" for notestotitle(@notes);
+
+ printf('<td class="%s" colspan="%d" title="%s">%s',
+ join(' ',
+ X => $CSTATS{$prev},
+ !$usage ? ('p0') : ('p',
+ sprintf('p%01d', $usage * ($usagepct - .0001) / 10),
+ sprintf('p%02d', $usage * ($usagepct - .0001)),
+ ),
+ ),
+ scalar @span,
+ $title,
+ showversions($span[0]->[0], @span > 1 ? $span[-1]->[-1] : ()),
+ );
+ undef $prev;
+ @span = ();