MiCyte

← The wiki

45 — The theme library

BuiltRendered from 45-theme-library.md in the public repository. Edits belong there.

A portal theme is a datum document whose rows are its colours. One sandbox, theme, holds every theme an instance's portal can offer, so a theme is added or changed by writing a document, not by shipping a stylesheet.

The codec is micyte/core/datum_ops/theme.py. The library (its anchor, the seeds, the writer and the reader) is micyte/ui/themes.py.

What a theme sets

Fourteen colours, each one a custom property of the shell's stylesheet:

paper paper2 ink ink2 coal coal2 line accent accent2 moss held notice danger accent-fg

Every renderer takes its palette from these. The network atlas and the planting grid derive their own variables from them with var() and color-mix(), so a theme that sets the fourteen recolours everything.

The list is THEME_TOKENS, and it only grows. A theme reads each colour by the token's name, so a token added later is one a theme may carry; a theme without it shows the stylesheet's own value for that token.

The colour

A colour is a point in a 256×256×256 cube: 24 bits, red in the high eight. Its chain runs off the photon rudi 0-0-10:

(((((ppu;256:);256:);256:);1:);0)

Read outside-in it says three extents, then a count, then the 0 that makes it referencable. The width is the sum of the extents' logs (8 + 8 + 8), as in the glyph library's grid chain, not their product. The chain is five deep, so its babelette is 5-1-1 and a colour row is layer 6.

The rows

AddressCellsWhat it is
6-1-N[colour, <24 bits>]One token's colour. The row's label is the token's name
7-0-1[~, 6-1-1, 6-1-2, ...]The palette
8-1-1[7-0-1, <count>]The theme

A theme's id is its document's name (midnight), and its title is that name made readable (Midnight). Nothing stores the title a second time.

The reader refuses a theme whose palette names a row that is not a colour, or whose count disagrees with its palette. The refusal names the theme, and the other themes are still offered.

The anchor

Authored, as the glyph library's is. Its fields are declared first as the THEME namespace in field_registry, so every reader resolves them by name:

FieldAddressChain
colour5-1-1the colour chain above
title3-1-364 characters, as in the glyph library
lcl_id3-1-13the local domain's node vocabulary

One library per store

The library is a shared sandbox: one instance keeps it and every portal in the store reads it. write_library writes the anchor, the local domain and every theme in one transaction. It refuses a store in which any instance already holds a theme sandbox; edit that library's themes instead of seeding another.

The five seeds (SEED_THEMES) are what a library is minted from: paper, ocean, forest, midnight and spore. Nothing else reads them. A store with no library offers no themes.

How a page draws a theme

The host reads the library (page_themes) and the page carries it as JSON in #v2-portal-themes. portal.js offers those themes in the theme select, ground first, then by title. Choosing one sets that theme's colours on body as custom properties, and every colour the stylesheet derives from them follows. Choosing another takes the last one's colours off first.

The stylesheet's :root is the ground (paper). A page draws it with no theme applied, so a store with no library shows paper and no select. A choice the store cannot draw (a theme since removed, a mistyped ?theme=) also lands on the ground.

The page checks every colour before applying it: a token name a stylesheet can take, a value written #rrggbb. A theme with anything else is not offered. Another script puts a theme on the page with window.MyCiteTheme.apply(id), which returns the id actually applied.

Whose choice it is

The library belongs to the store. The choice belongs to the person, so a host can keep it in their own instance and every browser they sign in from draws it. page_themes(engine, chosen=, door=) carries two more fields beside the themes:

FieldWhat it is
chosenThe theme the person's instance chose. Empty when nothing is chosen or the library no longer holds it
doorThe same-origin path a new choice is posted to, as {"theme": "<id>"}. Empty where the page cannot save a choice

The page draws the first of these that the library holds:

  1. ?theme= in the address;
  2. chosen;
  3. the browser's cached choice (localStorage, key mycite.theme.portal.default);
  4. the page's own default, then the ground.

Choosing a theme applies it at once, caches it in the browser, and posts it to door when there is one. A refused post leaves the page and the cache as chosen; the instance keeps its earlier choice, and the console says so.

FND's portal keeps the choice as a settings document in the person's own instance, one row per theme with the chosen one at 1. Its page offers a door only where a save can succeed. The local host (python -m micyte.ui) keeps no choice: it offers no door, and the browser's cache is all there is.

Seeding a store of your own

python -m micyte.ui themes --db path/to/store.sqlite3                      # list the library
python -m micyte.ui themes --db path/to/store.sqlite3 --seed --msn <msn>   # write the seeds

--msn names the instance in your store that keeps the library.