Skip to main content

Module theme

Module theme 

Source
Expand description

The custom theme, which is custom CSS. Itโ€™s applied after the theme tokens in src/theme.css, so a theme changes colors and radii by setting those tokens.

The saved theme.css and exported theme files are the same plain CSS. Nothing in a theme may load from outside this device: it can reference only embedded data URLs, so a shared theme canโ€™t reveal anything to a remote server. The CSS editor can name local files, which are embedded before the theme is saved.

Constantsยง

MAX_CSS_BYTES ๐Ÿ”’
Room for images and fonts embedded as data URLs.
MAX_IMPORT_DEPTH ๐Ÿ”’
How deeply local CSS files can import each other.

Functionsยง

check_size ๐Ÿ”’
css_is_local
True when the CSS canโ€™t load anything except embedded data URLs. url(#id) refers to an element in the same document.
data_url ๐Ÿ”’
Reads an image or font file as a data URL, typed by its extension. The file name is kept as a form-encoded name parameter, which browsers ignore, so the CSS editor can show it.
embed ๐Ÿ”’
embed_files
Embeds the local files that theme CSS names. Each @import of a local CSS file is replaced with that fileโ€™s contents, and each url() naming a local file becomes a data URL. Absolute paths and file: URLs are local, and inside an imported file, relative paths resolve against its folder. Other URLs are left for validate to reject.
embed_urls ๐Ÿ”’
Replaces each url() that names a local file with the file as a data URL.
import_target ๐Ÿ”’
The path an @import names as a string or url(), when only ; follows it, and the length of the rule after @import.
inline_imports ๐Ÿ”’
Replaces each unconditional @import of a local CSS file with the fileโ€™s embedded contents.
local_path ๐Ÿ”’
The local file a value names: an absolute path, a file: URL, or a path relative to folder. Network paths and other URLs arenโ€™t local.
normalize_css ๐Ÿ”’
Lowercases CSS, decodes escapes, and drops comments outside strings.
read_file ๐Ÿ”’
split_url ๐Ÿ”’
Splits the text after url( into the whitespace and opening quote, the value, and the rest, which starts at the closing quote or parenthesis.
validate
Checks that theme CSS is within the size limit and loads nothing from outside this device.