X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/20883523f524360de2c7758b02d15be980ed08c3..b85146b7eafcb24fa8b79b37ed465a628df1d63d:/common.inc.plp
diff --git a/common.inc.plp b/common.inc.plp
index 6d6a532..ff84a9a 100644
--- a/common.inc.plp
+++ b/common.inc.plp
@@ -54,8 +54,7 @@ our $style;
$header{content_type} = 'text/html; charset=utf-8';
sub stylesheet {
- my ($avail) = @_;
- my @avail = ref $avail eq 'ARRAY' ? @{$avail} : $avail or return;
+ my @avail = qw( light dark circus mono red );
my %styles = map {$_ => $_} @avail;
if (defined( my $setstyle = $get{style} )) {
@@ -127,7 +126,6 @@ sub Html {
}
# default fallbacks
- $meta->{stylesheet} ||= [qw( light dark circus mono red )];
$meta->{charset} ||= 'utf-8';
$meta->{lang} ||= 'en';
@@ -143,7 +141,7 @@ sub Html {
unshift @{ $meta->{raw} }, (
'',
);
- $meta->{stylesheet} = stylesheet($meta->{stylesheet});
+ $meta->{stylesheet} = stylesheet();
if (my $img = $meta->{image}) {
my $proto = sprintf('http%s://', !!$ENV{HTTPS} && 's');
@@ -181,8 +179,17 @@ sub Html {
say for map { @{$_} } $meta->{raw} || ();
say '' if $Dev;
say "" for join($/,
- "if (m = window.matchMedia('(monochrome)'))",
- "(m.onchange = e => document.documentElement.classList.toggle('s-mono', e.matches))(m);",
+ "docroot = document.documentElement;",
+ "if (docroot.className == '') {",
+ "new Map([",
+ "['s-mono','(monochrome)'],",
+ "['s-dark','(prefers-color-scheme: dark)'],",
+ "['s-circus','(prefers-contrast: more)'],",
+ "]).forEach((q,c) => {",
+ "if (m = window.matchMedia(q))",
+ "(m.onchange = e => docroot.classList.toggle(c, e.matches))(m)",
+ "})",
+ "}",
);
say '';
say '';