Skip to content

[3.0] Theme split (wave 5, part 2) — give the default theme a dark mode - #9497

Open
albertlast wants to merge 2 commits into
SimpleMachines:release-3.0from
albertlast:3.0/theme-dark-mode
Open

[3.0] Theme split (wave 5, part 2) — give the default theme a dark mode#9497
albertlast wants to merge 2 commits into
SimpleMachines:release-3.0from
albertlast:3.0/theme-dark-mode

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

The colour mode plumbing has been in 3.0 since Alpha. Theme.php resolves the mode, Themes.template.php and ThemeOptions.php offer it to the admin and the member, index.template.php writes it into data-mode, and dark.css has sat in the theme as a placeholder waiting to be filled.

None of it has ever run. Turning the flag on is not enough, because the feature is broken in four places rather than one. Each of these was found by trying to use it, not by reading it.

Theme::loadMode() had no callers It is the method that resolves the mode and loads dark.css. Nothing anywhere invoked it, so data-mode was never emitted and the stylesheet never requested. Now called beside loadVariant(), its sibling, which the same line of the template reads.
system lost the thing that makes it system That mode works by loading dark.css with a (prefers-color-scheme: dark) media attribute. But attributes are only printed for files served on their own, loadCSSFile() defaults to minimizing, and a file folded into the bundle loses them — so the browser was never asked and system would have meant always dark. That mode now opts out of the bundle. light and dark carry no attribute and still share one cached file.
Saving the mode to a profile was fatal Db::insert() wants a list of rows and was handed a single flat one. Outside backward-compatibility mode that is a critical error, so the first time a logged-in member picked a mode the page died with Invalid data structure sent to the database.
dark.css was empty Filled in — see below.
The stylesheet

Written against release-3.0's own tokens rather than ported. The snapshot on #7933 could not be used: of its 197 overrides only 84 name a token that exists here, while 213 colour-bearing tokens here have no value in it. Taken as-is it would have produced a dark mode with most of the forum still showing its light values.

It overrides 243 tokens and restates no rules. Everything is written against twelve values declared at the top of the file — five surfaces, two hairline weights, three text weights and two link colours — so the way to review this is to agree those twelve and then check that each component reached for the right one.

The primary and secondary ramps are deliberately left untouched. They carry the theme's identity and a variant re-tints the forum by moving --primary-color-hue; leaving them alone means dark mode moves with it. Where a token pointed at the dark end of a ramp because it was drawn on a light surface, the override points it at the light end instead, rather than redefining what the ramp means.

Verification

Run against a real forum, not read.

  • Light mode is unchanged. Computed color, background-color, background-image, all four border colours, box-shadow, outline-color and text-shadow for every element on twelve pages, with the file present and absent: 4254 elements, 0 differences.
  • All three modes emit correctly, including the media attribute on system and on system alone.
  • Eighteen pages swept in both modes for text landing on a background too close to it — board index, topic, posting form, profile, profile theme options, stats, help, search, calendar, memberlist, personal messages, moderation centre, admin centre, its permission grid and a group's permission form, the theme list, maintenance and the error log. Dark mode has 19 elements below the AA ratio against light mode's 136.
  • No errors logged during the sweep.
Known gaps, both outside the theme

The 19 are two causes, neither of them a token:

  • The bundled coloris colour picker (coloris.min.css) is third-party and carries no tokens at all, so its Hex/RGB/HSL labels stay light-on-light. Same class of thing as .sceditor-container — not ours to name.
  • The Administrator group's online_color is #FF0000, set by the installer. That is data, not styling, and it is marginal in light mode too.

Depends on #9496 (wave 5, part 1), which gives the last hard-coded colours in index.css a token. Without it #wrapper keeps a white background, the .titlebg headings stay #555 on a dark bar and the three sheen gradients stay pale. This branch is stacked on it, so the diff here is dark.css, Theme.php and one flag.

loadVariant() carries the identical Db::insert() defect three lines below the one fixed here. It is left alone deliberately: this branch neither enables nor exercises variants, and shipping a fix I cannot verify is worse than recording a known one.

Part 2 of wave 5 of the #7933 split.

Issues References (Fixes|Related|Closes)

Related #7933

Wave 4 tokenised index.css area by area and left a remainder: 55 declarations
that no area owned, scattered across the file. This takes those, so that every
colour the default theme draws now resolves through variables.css.

Most are one-offs - the forum title link, the current page number, the status
words, the COPPA contact block, the error file viewer, the warning level bars.
Three are not: the sheen gradients on raised controls, on their hover state and
on the overlay surfaces are each shared by a long selector list spanning menus,
quick buttons, popups and post options, so they are named for what they are
rather than for any one component that uses them.

Every token is seeded with the literal it takes over from, so this is not meant
to change what the forum looks like, and does not. Verified by recording the
computed color, background, background-image, border colours, box-shadow,
outline and text-shadow of every element on twelve pages - the board index, a
topic, the poster, the profile, the stats, help, search, the calendar, personal
messages, the admin centre, its permission grid and its theme list - before and
after: 4254 elements, zero differences.

The one literal left is the diagonal stripe the progress bar draws over its
fill, which is a translucent white texture rather than a colour.

Signed-off-by: Mathias Alberts <mathiaspapealbert@hotmail.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
The colour mode plumbing has been in 3.0 since Alpha: Theme.php resolves the
mode, Themes.template.php and ThemeOptions.php offer it to the admin and the
member, index.template.php writes it into data-mode, and dark.css has sat in the
theme as a placeholder. None of it has ever run. Turning the flag on was not
enough, because the feature is broken in four places rather than one.

loadMode() had no callers. It is the method that resolves the mode and loads
dark.css, and nothing anywhere invoked it, so data-mode was never emitted and
the stylesheet was never asked for. It is now called beside loadVariant(), which
is its sibling and is read by the same line of the template.

The 'system' mode lost the very thing that makes it 'system'. That mode works by
loading dark.css with a (prefers-color-scheme: dark) media attribute, but
attributes are only printed for files served on their own - loadCSSFile()
defaults to minimizing, and a file folded into the bundle loses them. The
browser was never asked, so 'system' would have meant 'always dark'. That mode
now opts out of the bundle; 'light' and 'dark' carry no attribute and still
share one cached file.

Saving the chosen mode to a member's profile was fatal. Db::insert() wants a
list of rows and was handed a single flat one, which is a critical error rather
than a warning outside backward compatibility mode, so the first time a logged
in member chose a mode the page died. loadVariant() has the identical defect
three lines further down; it is left alone here because this branch neither
enables nor exercises variants, and shipping an unverified fix is worse than
recording a known one.

dark.css itself is written against release-3.0's own tokens rather than ported.
The snapshot on SimpleMachines#7933 could not be used: of its 197 overrides only 84 name a
token that exists here, while 213 colour-bearing tokens here have no value in
it. It overrides 243 tokens and restates no rules, all written against twelve
values declared at the top of the file, so the way to review it is to agree
those and then check each component reached for the right one.

The ramps are deliberately untouched, so a variant still re-tints the forum by
moving --primary-color-hue and dark mode moves with it.

Verified on a running forum. Light mode is unchanged: the computed colours of
4254 elements over twelve pages are identical with the file present and absent.
All three modes emit the right markup and the right stylesheets, including the
media attribute on 'system' alone. Eighteen pages were swept in both modes for
text that lands on a background too close to it; dark mode has nineteen elements
below the AA ratio against light mode's hundred and thirty-six, and both dark
causes sit outside the theme - the bundled coloris colour picker, which carries
no tokens at all, and the Administrator group's online_color, which is data. No
errors were logged.

Signed-off-by: Mathias Alberts <mathiaspapealbert@hotmail.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants