+sub coltable {
+ my ($term) = @_;
+ my $info = $palettes->{$term};
+
+ if (ref $info eq 'ARRAY') {
+ coltable($_) for @{$info};
+ return;
+ }
+
+ if (ref $info eq 'CODE') {
+ coltable($_) for $info->($palettes);
+ return;
+ }
+
+ ref $info eq 'HASH' or return;
+ my $order = $get{order} && $get{order}.'order';
+ my $reorder = $info->{$order} // $palettes->{ $info->{parent} }->{$order};
+
+ my $caption = $info->{name} // $term;
+ $caption = sprintf('<%s %s>%s</%1$s>',
+ $info->{href} ? 'a' : 'span',
+ join(' ',
+ map { sprintf '%s="%s"', $_, $info->{$_} }
+ grep { defined $info->{$_} }
+ qw( href title )
+ ),
+ $caption,
+ ) if $info->{href} or $info->{title};
+
+ if ($info->{table} or $info->{rgbmap}) {
+ say '<table class="color mapped">';
+ say sprintf '<caption>%s</caption>', $caption;
+
+ print coltable_hsv(@{$_}) for $info->{rgbmap} || ();
+
+ if (my $table = $info->{table}) {
+ $table = [ @{$table}[@{$reorder}] ] if $reorder;
+
+ for my $row (@$table) {
+ if (!$row) {
+ say '<tbody>';
+ next;
+ }
+ print '<tr>';
+ print colcell(ref $_ ? @$_ : $_ ? reverse split /:/ : undef) for @$row;
+ }
+
+ if (@draw) {
+ my $width = scalar @{ $table->[0] };
+ my @imgpal = map {
+ [ ref $_ ? @{$_}[1 .. 3] : map {hex} /(..)(..)(..)/ ]
+ } map { @{$_} } @{$table};
+ for (@draw) {
+ print "<tr><td colspan=$width>", img_egapal(\@imgpal, @{$_});
+ }
+ }
+ }
+
+ say "</table>\n";
+ }
+
+ if (my $palette = $info->{list}) {
+ my $colours = colorder($palette, $reorder);
+
+ my $rows = 8;
+ my $columns = ceil(@{$palette} / $rows);
+
+ say '<table class=color>';
+ say sprintf '<caption>%s</caption>', $caption;
+ for my $row (0 .. $rows - 1) {
+ print '<tr>';
+ for my $col (0 .. $columns - 1) {
+ my $num = $row + $col * $rows;
+ my ($rgb, $name) = split /:/, $colours->[$num], 3;
+ $name //= $rgb && $num;
+ $name = [ $name, [] ] if $term =~ /^msx/ and !$name; # no bg for transparency
+ $name = [ $name, ['#333'] ] if $term eq 'xkcd';
+ print colcell($name, $rgb);
+ }