unicode: silence perl warning about empty query range offsets
[sheet.git] / keyboard / altgr / index.inc.plp
1 <: # included from keyboard.plp
2 use 5.014;
3 use warnings;
4 use utf8;
5
6 my $dirbase = 'keyboard/altgr';
7 my $indexfile = "$dirbase/index";
8
9 Html({
10         title => "altgr keyboard cheat sheets",
11         version => '1.3',
12         description => [
13                 "Overview of alternate keyboard modes,",
14                 "offering extended Unicode characters if a modifier key",
15                 "(such as AltGr or option) is pressed.",
16         ],
17         keywords => [qw'
18                 sheet cheat reference overview keyboard altgr option
19         '],
20         image => "$dirbase/thumb/ibm-m.jpg",
21         data => ["$dirbase/index.inc.plp", "$indexfile.inc.pl"],
22         raw => <<'.',
23 <style>
24 .keys.cmp {
25         display: inline-table; /* centered */
26         float: none;
27         margin: 0;
28         border-collapse: separate;
29         border-spacing: 2px;
30         border-spacing: .4vw; /* inline td margin equivalent */
31 }
32 .keys.big.cmp tbody {
33         font-size: 150%;
34 }
35 @media (max-width: 48em) {
36         .keys.big.cmp tbody {
37                 font-size: 100%;
38         }
39         .keys.big.cmp tbody a {
40                 white-space: normal;
41         }
42 }
43 .keys.cmp tbody {
44         display: table-row-group;
45 }
46 .keys.cmp tr {
47         display: table-row;
48 }
49 .keys.cmp tr > * {
50         display: table-cell;
51         position: static; /* under sticky thead */
52 }
53 .keys.cmp tbody th {
54         padding-right: 1ex;
55         text-align: right;
56 }
57
58 @font-face {
59         font-family: osicons;
60         src: url(/osicon.ttf);
61 }
62 .icon {
63         font-family: osicons;
64 }
65 .keys.cmp tbody .ni {
66         font-size: 80%;
67         padding: 0 .2em;
68 }
69
70 .graph {
71         display: block;
72         line-height: 1ex;
73         height: 1.2ex;
74         margin-top: .4ex;
75 }
76 .graph ~ .graph {
77         /* subsequent graphs */
78         height: .7ex;
79 }
80 .graph > * {
81         display: inline-block;
82         height: 100%;
83         vertical-align: top;
84 }
85 .graph > label {
86         font-size: 75%;
87         margin-right: .2em;
88 }
89 .graph > span {
90         border: 1px solid #000;
91         border-right-width: 0;
92         font-size: 0;
93 }
94 .graph > :last-of-type {
95         border-right-width: 1px;
96 }
97 .graph > .ext {
98         border-left: 0; /* assume following unext */
99 }
100
101 img {
102         object-fit: cover;
103         height: 100%;
104         vertical-align: middle;
105 }
106 </style>
107 .
108 });
109
110 :>
111 <h1>Extended keyboards</h1>
112
113 <p>Overview of available key layouts with AltGr or similar modifier keys.
114 Also see <a href="/digraphs">digraphs</a> for compose key combinations.
115 </p>
116
117 <:
118 my $idx = Data($indexfile);
119 my @incs;
120 push @incs, @{ $idx->{$_} } for @{ $idx->{default} };
121
122 my @sample = split /(?<!\+)/, $get{sample} // 'asSci1!+1';
123 require Shiar_Sheet::Keyboard;
124 Shiar_Sheet::Keyboard->VERSION(3.00);
125 use List::Util qw( uniq max sum );
126
127 my %caticon = (
128         legacy  => qq{<span class=icon title="deprecated">\N{TOP HAT}</span>},
129         windows => qq{<span class=icon title="Windows">\x{1FA9F}</span>}, # \N{WINDOW}
130         macos   => qq{<span class=icon title="MacOS">\N{RED APPLE}</span>},
131         xorg    => qq{<span class=icon title="Xorg">\N{PENGUIN}</span>},
132 );
133
134 printf '<section class="%s">', @sample ? 'section' : 'gallery';
135 if (@sample) {
136         print '<table class="big keys cmp">';
137         print '<thead><tr><th colspan=2>';
138         print "<th>$_" for @sample;
139         say '</tr></thead>';
140 }
141 my $most = max(
142         map { sum values %{$_} } map { $_->{inventory}{''} } @{$idx}{@incs}
143 );
144 for my $inc (@incs) {
145         my $table = $idx->{$inc};
146         print @sample ? '<tr><th>' : '<figure>';
147         printf '<a href="/%s">', "$dirbase/$inc";
148         my $title = $table->{title} || $inc;
149
150         unless (@sample) {
151                 if (my $img = $table->{image}) {
152                         EscapeHTML $name = $table->{imagealt} // $img =~ m{.*/([^/.]*)};
153                         print qq{<img src="/$img" alt="$name" />};
154                 }
155                 printf '<figcaption>%s</figcaption>', $title;
156                 say '</a></figure>';
157         }
158         else {
159                 print $title;
160                 print '</a>', "\n\t";
161                 for my $mode ($table->{mode} ? sort keys %{ $table->{mode} } : '') {
162                         print '<span class=graph>';
163                         printf "<label>%s</label>", m/^(\S*)/
164                                 for $mode && $table->{mode}{$mode} || ();
165                         for my $g (sort keys %{ $table->{inventory}{$mode} }) {
166                                 printf '<span class="%s" style="width:%.0f%%" title="%3$d %4$s"> %s</span>',
167                                         $g, $_/$most*100, $_,
168                                         join(' ', map {
169                                                 $table->{flag}{$_}[0] || 'extra'  # legend label of each class
170                                         } reverse split / /, $g)
171                                         for $table->{inventory}{$mode}{$g};
172                         }
173                         say '</span>';
174                 }
175                 print "\t<td class=ni>";
176                 print join ' ', map { $caticon{$_} // () }
177                         split m{/}, $table->{category} // '';
178                 say '';
179                 if (my $keys = eval {
180                         my $keydata = Data("$dirbase/$inc.eng");
181                         Shiar_Sheet::Keyboard->new($keydata)
182                 }) {
183                         for my $c (@sample) {
184                                 my $def = $keys->{def}{''}{$c} // [];
185                                 $def->[0] //= 'ni';
186                                 $def->[0] =~ s/ mode\S*//;
187                                 $keys->print_key('', $c, $def);
188                         }
189                 }
190                 say '</tr>';
191         }
192 }
193 print '</table>' if @sample;
194 :></section>
195