Bridge Customizer

Site-wide appearance for the Bridge admin theme: colours for light and dark, logo, favicon, login screen, admin title, radius and density.

Site-wide appearance for Bridge, an admin theme based on ProcessWire: colours for the light and the dark scheme, logo, favicon, login screen, admin title, radius and density. Everything is set on one screen with a live preview; no stylesheet of your own is needed.

A Bridge extension (extension contract 0.2, docs/extensions.md in Bridge). It works through the theme's appearance seams (appearance(), tokenOverrides(), adminTitle(), faviconUrl()) and requires AdminThemeBridge 1.2.0 or later and InputfieldColorPickerPlus 1.0.0 or later (the colour fields). Version 0.4.0.

Install


  1. The theme: AdminThemeBridge 1.2.0 or later, from github.com/theoretic/AdminThemeBridge.
  2. The colour picker: InputfieldColorPickerPlus 1.0.0 or later ("ColorPickerPlus", MIT, a module of its own) from github.com/theoretic/ColorPickerPlus. Put it in site/modules/ColorPickerPlus/ (Modules > New > "Add module from URL" with the repository's zip, or a copy of it), Modules > Refresh, install InputfieldColorPickerPlus.
  3. This module, from github.com/theoretic/BridgeCustomizer, in site/modules/BridgeCustomizer/ (the same two ways; on a development machine that path may be a junction or symlink to a checkout).
  4. Modules > Refresh, then install Bridge Customizer. It requires AdminThemeBridge 1.2.0 or later and InputfieldColorPickerPlus 1.0.0 or later (installed in that order: ProcessWire refuses the Customizer while the picker is missing).
  5. Modules > Configure > BridgeCustomizer.

It runs on admin pages only (autoload on the admin template), the login screen included.

Settings


An empty field keeps the theme's own value (under Colours, the colour worked out from the key colours when that is on, see below).

  • Use the Customizer: off, the admin shows the Bridge theme's own Appearance settings; the Customizer's settings and files are kept for when it is switched on again.

  • Preview: a light and a dark sample of the admin (masthead with logo and title, a card with a label, an input and buttons, muted and error text, the login form's card on the login background: logo, heading, username and password, the Login button). Where no logo file is set it shows the theme's own mark. It follows the fields as you type or upload a file and posts nothing; Save applies the settings to the admin (after a save in place the screen reloads). On a screen 1200px wide or more it sits in a panel fixed beside the form: from the top of the first fieldset (Module Information) to the bottom of the window, filling the width right of the form's column with the theme's gutter on each side (scrolling on its own when it is taller than the window); narrower, and in a modal, it stays in the form.

  • Colours, top to bottom:

    • Contrast warnings, only when a saved colour fails a contrast pair (see "Contrast" below).
    • Presets: seven accent colours, Gold #ff8f00, Purple #8e00ff, Teal #00958e, Green #009100, Crimson #e70000, Azure #008fff and Indigo #0000ff, a button each. A click puts the colour into Accent and a light variation of it (the colour mixed with white, 92 % white: Gold #fff6eb, Indigo #ebebff) into Light background; the pickers and the preview follow. The dark background is left as it is. While Accent holds one of the presets, a Revert button (a cross) shows after them: it empties Accent and Light background, back to the theme's colours. Nothing is stored until Save.
    • Key colours: the accent, one colour for both schemes (buttons, links, the focus ring; hover, tints and shadows follow from it), and the light and the dark background.
    • Other colours: "Work out the other colours from the background" (see "Key colours and what is worked out from them" below).
    • Advanced, collapsed: the other nine colours for Light and nine for Dark: surface (cards, menus), text, muted surface, item background, muted text, border, danger, input background, login background. Its description says how many of the 18 have a value. A value here always wins over a worked-out one; the fields post whether Advanced is open or not.

    The item background (0.2.0, Bridge's --pw-item-bg) colours the list items: page reference rows, asmSelect items, tags and repeater item headers; left empty, it follows the background when that is set, else the theme's colour (the muted surface). Each colour is a colour picker (InputfieldColorPickerPlus, the Sketch picker): its swatch opens the picker, the text takes a typed colour (#RRGGBB, #RGB, rgb(), hsl()), and × ("Theme default") empties it. Stored as #rrggbb or empty. While a field is empty its swatch is struck through; for the accent it shows the theme's own colour when that is a custom one (the theme's preset colours and its palette colours live in its stylesheet, which the Customizer does not read). A value that is not a colour is refused with an error on its field and the saved one is kept.

  • Shape and density, in rem as the theme's sizes (1 rem is 16 px at 100 %, so the browser's text size scales them; steps of 0.0625 rem = 1 px): the corner radius (0 to 1.5; empty keeps the theme's), and the theme's field label size (0.75 to 1.25, default 0.875) and control height (1.75 to 3.5, default 2.25: inputs, selects and buttons). Those two are settings of the Bridge theme (Modules > Bridge > Appearance): this screen shows them and saves them there, so they stay when the Customizer is off or uninstalled. Also there (0.3.0): Untranslated language tabs, the look of a language tab whose value is empty: faded (the theme's default since Bridge 1.2.0), italic, italic and faded, or like the other tabs.

  • Logo and favicon: a logo (in place of the theme's mark, in the masthead and on the login card), a logo for the dark scheme (used together with the logo only), a favicon for the browser tab.

  • Login screen: a login logo (else the logo), a background image laid over the scheme's login background colour (centred, covering), a heading: a line of text under the logo.

  • Title: the admin's name, in the browser tab in place of "Bridge" (on by default) and, if chosen, beside the logo in the masthead (hidden below 768 px).

  • Export and import: see below.

Key colours and what is worked out from them

With the box "Work out the other colours from the background" ticked, a scheme whose background is set gets the colours below for every one of its Advanced fields that is empty. A scheme without a background gets nothing worked out. The colours are mixed in sRGB, as CSS color-mix(in srgb, …) does, from the background (B), the text (the scheme's text field, else the theme's: #0a0a0a light, #fafafa dark) and the surface; never from the accent. With the theme's own backgrounds they give the theme's own colours (the muted text and the light border within a shade).

  • Surface: white in light; in dark the background with 5.5 % of the text.
  • Muted surface: in light the surface with 4 % of the text; in dark the background with 11.5 % of the text.
  • Muted text: the text with 40 % of the surface, in both schemes.
  • Border: in light the background with 15 % of the text; in dark nothing (the theme's translucent border follows any background).
  • Item background: in light the background; in dark nothing (the theme's follows the muted surface).
  • Text, danger, input background, login background: never worked out; the theme's colours (the login background follows the muted surface on its own).

Nothing worked out is stored: the colours are computed when the page is printed, from the stored key colours, so the export holds only what was typed. The preview works them out as you type. Unticked, an empty field keeps the theme's colour as before.

The text on the accent (button text, checked controls, the selection) is white, unless the accent is very light (white under 2 to 1 on it, such as #ffd400): then near-black #0a0a0a. White stays on mid-tones even where near-black would measure higher. The preview shows it that way; in the admin it is the theme that chooses the text on a custom colour, so a version of the theme that does not choose it yet keeps white text there.

Contrast

The colours in effect (a field's value, else the worked-out one, else the theme's) are checked per scheme with the WCAG 2 contrast ratio:

PairLowest ratio
Text on background4.5
Text on surface4.5
Muted text on surface4.5
Danger on surface4.5
Button text on accent4.5
Accent on surface3
Links on surface (the theme's link colour: the accent with 35 % of the text in light, 20 % in dark)4.5

The three accent pairs are checked only when the accent is set; a user's own colour from the user menu is not checked. A pair under its ratio shows as a line ("Light: Text on background, 1.00 to 1 (at least 4.5)") in the live list under the preview while you type, with its fields marked, and after Save in Contrast warnings at the top of Colours. A warning never blocks a save: the colours are saved and used as they are.

The seven presets were measured with these pairs, each with its light background and the theme's other colours (BridgeCustomizer.check.php checks the figures on every run). Each gets warnings, like any colour. With a preset as the accent the text on the admin's buttons is white for all seven, as on the preset buttons, so the button text is warned about in both schemes for Gold (2.29 to 1), Azure (3.30), Teal (3.69) and Green (4.16) (at least 4.5). Also Gold on the light card 2.29 to 1 (accent, at least 3); Purple's links on the dark card 3.81, Crimson's 4.30 (at least 4.5); Indigo on the dark card 2.09 and its links 2.58.

After an upgrade

Settings saved by 0.3.0 or before keep their look: nothing is worked out until the form is saved with the box ticked, and every field keeps its name and value (the accent and the two backgrounds are the key colours, the other 18 are under Advanced). On the first visit the box is shown unticked when any colour of a scheme was saved, and ticked when none was (as on a fresh install). An export of 0.3.0 imports as it is and works out nothing.

What wins over what

  • A user's own colour (the theme's "Users choose their own colour", the picker in the user menu) stays above the accent; "Site default" in the picker shows the accent.
  • The Customizer's values stand above the theme's Appearance settings (colour variant, primary colour, logo, dark logo). The theme's config screen keeps the values saved there and notes, under each field the Customizer sets, the value in use. With the Customizer off, a field empty or the module uninstalled, the theme's own settings apply again.
  • The colours reach the whole admin page, the login screen and modal windows. Parts that set their own data-pw-scheme (such as the preview panes) keep the theme's base values.

When the admin cannot be read

Colours that make the admin unreadable can be switched off without reading it:

  • For one browser: open any admin URL with ?bridgeCustomizer=off, the login screen included (for example /processwire/?bridgeCustomizer=off, with your site's admin path). It sets a cookie (bridge_customizer_off, HttpOnly, until the browser is closed) and that browser shows the theme's own look; sign in, repair the colours, then open any admin URL with ?bridgeCustomizer=on. The config screen says so while the cookie is there. Nothing is written to the site, and other browsers and users keep the Customizer.
  • For every browser: add $config->bridgeCustomizerOff = true; to site/config.php and remove the line after the repair. The URL parameter cannot turn it back on.
  • Last resort: remove the folder site/modules/BridgeCustomizer (FTP or the host's file manager); put it back, then repair the colours.

The stored settings are kept and the config screen still saves them in each case. A known property: a link from elsewhere with ?bridgeCustomizer=off switches the Customizer's look off in the browser of whoever follows it; it changes nothing but that browser's view, and the notice on the config screen says how to undo it.

The module's files


  • BridgeCustomizer.module.php: the module (settings, the config screen, the seams' hooks, the colour arithmetic, export and import).
  • BridgeCustomizer.mjs: the client module, loaded by the theme on admin pages; on the config screen it runs the preview.
  • BridgeCustomizerColours.mjs: the colour arithmetic, the worked-out colours and the live contrast list of the preview; imported by BridgeCustomizer.mjs only where the preview is, so other admin pages do not load it.
  • BridgeCustomizer.css: the stylesheet the theme links after its own; it styles the config screen (the preview, the presets, the warnings).
  • BridgeCustomizer.check.php and tests/: the checks (see "Checks").

Files


Each file slot is an image field, shown on the screen by Bridge's own image field: drag a file onto it or choose one, see its thumbnail, replace it (a slot holds one file; the field asks before it replaces), delete it with the trash. Logos SVG, PNG, JPG, WebP or GIF; favicon ICO, PNG or SVG; login background JPG, PNG, WebP or SVG; 1 MB at most each. An upload goes to the server at once but is used only after Save (until then it is temporary, and a reload without Save drops it); a deleted file goes on Save.

Install makes the storage: a hidden system page bridge-customizer under the admin page, of its own template and fieldgroup bridge-customizer (no template file), with one image field per slot (bridge_customizer_logo, bridge_customizer_logo_dark, bridge_customizer_login_logo, bridge_customizer_favicon, bridge_customizer_login_bg). The files live in site/assets/files/<page id>/, so a module update leaves them alone; their URLs carry the file's time (?v=), which changes when a file is replaced. Uploads go to that page's editor: editing a system page takes a superuser, as the module's own screen does in practice. Uninstall removes the page with its files, the template, the fieldgroup and the fields (a field another template uses is left, with a warning).

SVG files go through the site's file validators when it has one (such as an SVG sanitizer module); otherwise they are stored as they are: the admin shows them through <img>, but opened directly by its URL a script inside an SVG would run. Upload SVG files you trust, or use PNG or WebP. The login screen shows the files to visitors who are not signed in: with $config->pagefileSecure on, ProcessWire serves a page's files only to those who may view the page, so check the login screen signed out.

Export and import


Under Export and import on the same screen. "Download settings (JSON)" gives bridge-customizer.json: every setting above, the theme's label size and control height, and the files embedded as data: URIs (so one file reproduces the look on another site; up to about 7 MB with every slot at 1 MB). It holds nothing else: no user data, no path, no host. The same settings give the same bytes. Sizes are rem numbers: settings.radius a string ("0.5", or "" for the theme's), theme.labelSize and theme.controlHeight numbers (0.875, 2.25).

To import, paste an export into Import (or pick its file there) and Save. Its settings and files take the place of the ones on the screen (the files written into the slot fields, under their names in the export, through the site's file validators): a file slot the export has no file for is emptied, and the theme's label size and control height are saved when the export has them. A value that is not valid takes its default and is named in a warning (a size in px, such as a radius of 8 or a label size of 14, is out of the rem ranges: the radius takes the theme's, the theme keeps its own size); a file that is not valid leaves its slot empty, with a warning. Text that is not an export (JSON with "format": "bridge-customizer" and "version": 1) shows an error, and that save stores nothing at all. A large export needs PHP's post_max_size above its size.

Content Security Policy


The Customizer prints no <script>, no <style> and no style attribute. Its client module comes through the theme (with the nonce) and imports BridgeCustomizerColours.mjs from its own folder on the config screen; the presets get their colours from the stylesheet; the preview changes through the CSSOM, and the colours reach the page in the theme's own token style, which carries the nonce. The colour picker (InputfieldColorPickerPlus) adds no style attribute either: its own styles are adopted stylesheets of its shadow root and CSSOM writes. It runs under Bridge CSP (BridgeCsp) in enforce mode.

Limits


  • One accent for both schemes (the theme's primary colour is one value, and a user's own colour must keep winning).
  • Working out the other colours never changes the text: a mid-tone background, or a light one in the dark scheme, is warned about, not compensated (set the text under Advanced).
  • The select chevron keeps the theme's colour (a fixed image).
  • The preview: an emptied corner radius, label size or control height previews the saved value until Save, as the samples take it from the page. Without a logo file of the Customizer it shows the theme's own mark, also where the theme's own Appearance settings name a logo URL.
  • The admin title and the login heading are one text each, not translated per language.
  • No font choice and no custom CSS in 0.1.

Checks


From a Bridge checkout, against a sandbox (tools/sandbox-site.sh) whose server runs. The extension is put into the sandbox only while its checks run and taken out after them, also after a failed run (an installed third-party extension changes counts that Bridge's own smoke test pins). <playwright-core> is the path of a playwright-core package.

The colour picker goes in first, as on a site: link <sandbox>/app/modules/ColorPickerPlus to a checkout of it (Windows: mklink /J), then php tools/sandbox-modules.php sandbox/<site> InputfieldColorPickerPlus. It may stay installed between runs; take it out after the Customizer (uninstall it, then remove the link only).

Git Bash (MSYS_NO_PATHCONV=1 keeps the paths as they are):

php tools/sandbox-extension.php sandbox/<site> <BridgeCustomizer dir>
php tools/extension-check.php sandbox/<site> BridgeCustomizer
MSYS_NO_PATHCONV=1 PHP=<php> SANDBOX=sandbox/<site> node tools/extension-check.js <playwright-core> chromium BridgeCustomizer
php tools/extension-compat.php <BridgeCustomizer dir>
MSYS_NO_PATHCONV=1 BRIDGE=<Bridge checkout> SANDBOX=<sandbox root> PHP=<php> node <BridgeCustomizer dir>/tests/customizer-check.js <playwright-core> chromium
php tools/sandbox-extension.php sandbox/<site> <BridgeCustomizer dir> --remove

PowerShell (the same, the variables set first):

php tools/sandbox-extension.php sandbox/<site> <BridgeCustomizer dir>
php tools/extension-check.php sandbox/<site> BridgeCustomizer
$env:PHP = '<php>'; $env:SANDBOX = 'sandbox/<site>'; node tools/extension-check.js <playwright-core> chromium BridgeCustomizer
php tools/extension-compat.php <BridgeCustomizer dir>
$env:BRIDGE = '<Bridge checkout>'; $env:SANDBOX = '<sandbox root>'; $env:PHP = '<php>'; node <BridgeCustomizer dir>/tests/customizer-check.js <playwright-core> chromium
php tools/sandbox-extension.php sandbox/<site> <BridgeCustomizer dir> --remove

Run the browser checks with firefox too, one at a time (they sign in as the same user).

  • BridgeCustomizer.check.php: the extension's own checks (settings, validation, the tokens, the storage page and its fields, export and import, the colour arithmetic, the worked-out colours, the contrast pairs and the presets, the way back), run by extension-check.php. It also holds the sizes: each of the two client modules and the stylesheet under 8 KiB (8192 bytes, raw).
  • tests/colour-vectors.mjs: the client's colour arithmetic (BridgeCustomizerColours.mjs) against tests/colour-vectors.json, the same vectors BridgeCustomizer.check.php runs through the PHP methods, so both give the same colours and ratios. It needs Node 18 or later and no sandbox: node <BridgeCustomizer dir>/tests/colour-vectors.mjs (the same in Git Bash and PowerShell); it prints ok/FAIL lines and exits 1 on a failure.
  • tests/customizer-check.js: the browser harness. Sections: A the config screen (presets, key colours, the derive box, Advanced); B the live preview with Bridge CSP enforcing, and inside it N the colours file, the presets and the text on the accent, V the Revert button (also after a save); C colours per scheme; W the contrast warnings after a save; O the worked-out colours and the live contrast list in the preview, and the same after a save; D the accent and a user's own colour; E the logo through the slot's image field (upload, refused files, replace, delete); F the favicon; G the admin title; H the login screen (logos, heading, background per scheme, signing in) and phone width; I label size and control height; P the preview's fixed panel on wide screens; J export and import; K every feature with Bridge CSP enforcing; L a modal window; R the way back (?bridgeCustomizer=off in a signed-out browser); M the Customizer off. It installs nothing; it puts back what it changed (the Customizer's settings and files, the theme's label size and control height, the user's own colour, Bridge CSP's mode) and ends by comparing the export with the one it started from. It prints ok/FAIL lines and exits 1 on a failure.

Licence


MIT, see LICENSE.

More modules by atis.pro

  • Bridge

    Native-component admin shell that still runs every existing Inputfield and Process module.
  • StaticPages

    Saves output to static html files. A page save deletes only the files whose render depended on the saved page; settings module config saves and tracked file changes delete them all.
  • Bridge Customizer

    Site-wide appearance for the Bridge admin theme: colours for light and dark, logo, favicon, login screen, admin title, radius and density.
  • ColorPickerPlus

    Colour input with the 13 pickers of react-color (Sketch, Chrome, Photoshop, Compact, Circle, Twitter and more), without React or jQuery.
  • OutputTransformer

    Strips extra symbols from output, performs typographics, replacements etc.

All modules by atis.pro

Install and use modules at your own risk. Always have a site and database backup before installing new modules.