sc: lotv patch v5.0.13 (2024-03-26)
[sheet.git] / codec.plp
1 <(common.inc.plp)><:
2
3 my ($page, @feat) = split m{/+}, $Request || 'image';
4 $page !~ /\W/ or Html(), Abort('Invalid codec type request', 400);
5 @feat or @feat = 'default';
6 my $title = "$page codecs";
7 my $info = eval { Data("codec-$page") };
8 if ($@) {
9         $info = {};
10 }
11
12 Html({
13         title => "$title cheat sheet",
14         version => '1.1',
15         description => $info->{intro},
16         keywords => [@{ $info->{keywords} // [] }, qw' feature comparison support benchmark '],
17         data => ["codec-$page.inc.pl"],
18         raw => '<style>td,th {width:8%} tbody th {white-space:nowrap}</style>',
19 });
20
21 %{$info}
22         or Abort("Requested codec type <q>$page</q> not available", '404 request not found');
23
24 say "<h1>\u$title</h1>";
25 say "<p>$_</p>" for $info->{intro} // ();
26
27 my %BOOLSCORE = (y => [5, '✔'], n => [1, '✘'], 0 => [0, 'n/a']);
28 :>
29
30 <div class="section">
31 <table class="mapped">
32 <:
33 my @codecs = sort {
34         $info->{codec}->{$a}->{available} <=> $info->{codec}->{$b}->{available}
35 } keys $info->{codec}->%*;
36 my @codeccols = @{$info->{codec}}{@codecs};
37
38 {
39         print '<col>';
40         my @spans;
41         $spans[ $_->{generation} ]++ for @codeccols;
42         print "<colgroup span=$_>" for @spans;
43 }
44 say '<thead><tr><th rowspan=2>';
45 say "\t", '<th>', $_->{name} for @codeccols;
46 print '<tr>';
47 print '<td>', $_->{available} for @codeccols;
48 say '</thead>';
49
50 while (defined (my $feat = shift @feat)) {
51         my $featinfo = $info->{feature}->{$feat} or next;
52         unshift @feat, @{$_} for $featinfo->{children} // ();
53         $featinfo->{score} or next;
54         print '<tbody>' if $featinfo->{children};
55         printf '<tr><th>%s', $featinfo->{name} // $feat;
56         for (@codecs) {
57                 my ($score, $data, $title) = map { ref ? @$_ : $_ } $featinfo->{score}->{$_};
58                 if (not defined $data) {
59                         if (my $override = $BOOLSCORE{$score}) {
60                                 ($score, $data) = @{$override};
61                         }
62                         else {
63                                 $data = '•' x ($score - 1);
64                         }
65                 }
66                 printf '<td class="l%d"', $score;
67                 printf ' title="%s"', EscapeHTML($_) for $title // ();
68                 print '>', $data;
69         }
70         say '</td>';
71 }
72
73 :></table>
74 </div>
75