Site themes
The public pages of a site — the frame of every page, the header and the footer, the typography, the look of the blocks and of the modules' pages — are drawn by a theme. This page is about the themes themselves: how a chain of them makes one look, the commands that show, check, make, extract and eject a theme, and the test every theme runs. Which file of the site holds what is in Where the styles live.
A chain of layers
A site stands on a chain, top first:
resources/views the site's own overrides — above every theme, for the developer
theme/ the site's local theme: only what makes this site different
acme/theme-clinic a packaged theme several sites share (optional)
webx-ui/theme-default the bottom: a value for every token, the shell, the seven blocks
the modules each module's own views and base lookA layer is a directory with the same parts, each optional — a part that is missing is inherited from below:
| Part | What it is |
|---|---|
theme.json / composer.json | the manifest: title, uses, requires, locales, fonts, preset, settings |
tokens.json | defaults, presets, schemes.dark and the layer's own vocabulary |
src/css, src/js | the stylesheet (and, rarely, a script) on var(--site-…) only |
views/ | Blade views: the header, the footer, an override of a module's view |
compositions/ | patches of the layout and the other compound views, by id (Compositions) |
blocks/ | block types by slug, in the format webx:blocks:export writes |
icons/, assets/ | the sprite's icons, pictures and fonts for theme_asset() |
lang/<locale>/theme.php | the words of the layout |
A local theme is theme/ inside the site; its manifest is theme/theme.json, and the site's Vite builds its src/. A packaged theme is a Composer package of "type": "webx-theme"; its manifest is extra.webx.theme of its composer.json, and its dist/ is built and committed, so a site installs it without Node.
WEBX_THEME in .env names the top of the chain — theme for a local theme, a Composer name for a packaged one; every layer below comes from the uses of the one above it.
What the theme prints from the settings
A theme that prints the site's contacts says so under settings of its manifest, and the panel offers the «Contacts» tab only then — with the sections the theme prints:
"settings": { "contacts": ["phones", "emails", "addresses", "hours", "socials"] }A tab is true (the whole tab) or the list of its sections — phones, emails, addresses, hours, messengers, socials. Down the chain the layer nearest to the site that names a tab decides it: a local theme over theme-default that lists its own sections replaces the default's list — a studio with no office and no opening hours declares "settings": {"contacts": ["emails", "messengers", "socials"]} and the editor is not asked about addresses, hours, special dates or the time zone; a local theme that says nothing keeps what the default prints. Packages and the project still add their sections on top. "settings": {} says the theme prints none of them. A manifest with no settings key at all keeps the tab while the transition of module-settings lasts (until the next minor) — declare it. webx:theme:eject carries the package's declaration into theme/theme.json. More in Settings.
The dark scheme
A theme may give the same tokens a second set of values, which the visitor sees when their system is dark or when the site set data-theme="dark" on <html>. It lives in tokens.json, beside defaults:
{
"defaults": { "color-bg": "#f7f7f4", "color-text": "#121413", "color-accent": "#2e49f5" },
"schemes": {
"dark": { "color-bg": "#0d0f0e", "color-text": "#ecede8", "color-accent": "#8394ff" }
}
}schemes has only dark — the light scheme is defaults. The names are those of the vocabulary, each value of its token's type. The set merges up the chain like defaults: a local theme retunes one dark token of the theme below without repeating the rest, and a token with no dark value keeps its light one in the dark. A preset recolours the light scheme only.
With a dark set, @webxTheme prints, after the light :root:
:root {
/* light values */
color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme='light']) {
/* dark values */
}
}
:root[data-theme='dark'] {
/* dark values */
color-scheme: dark;
}
:root[data-theme='light'] {
color-scheme: light;
}Without one it prints exactly what it always did. That @media is the only one by scheme on the page: the theme's CSS does not write prefers-color-scheme (webx:theme:check says so), and light-dark() in a token is a workaround, not the way — its contrast is not measured, and the engine sets neither color-scheme nor data-theme for it.
The contract is the attribute: data-theme="dark" or "light" on <html> overrides the system, no attribute follows it. The switch is the site's to draw — there is no widget for it. A button in the theme's header, and its script in theme/src/js/theme.js:
<button type="button" class="site-scheme" data-scheme-toggle aria-pressed="false">Dark mode</button>const root = document.documentElement
const isDark = () =>
root.dataset.theme
? root.dataset.theme === 'dark'
: matchMedia('(prefers-color-scheme: dark)').matches
for (const button of document.querySelectorAll('[data-scheme-toggle]')) {
button.setAttribute('aria-pressed', String(isDark()))
button.addEventListener('click', () => {
const scheme = isDark() ? 'light' : 'dark'
root.dataset.theme = scheme
button.setAttribute('aria-pressed', String(scheme === 'dark'))
try {
localStorage.setItem('site-scheme', scheme)
} catch {
// Private mode or blocked storage: the choice lasts until the page is left.
}
})
}The remembered choice has to be on <html> before the first paint, or a dark visitor sees the light page flash first: a module script runs too late. So a few lines go inline at the top of <head> of the layout, above @webxTheme — a patch of the compositionlayout, not a copy of the layout:
{
"add": [
{
"id": "scheme.early",
"to": "head",
"first": true,
"html": "<script>try{const s=localStorage.getItem('site-scheme');if(s==='dark'||s==='light')document.documentElement.dataset.theme=s}catch{}</script>"
}
]
}in theme/compositions/layout/default.json. The layout keeps @stack('head') as well, but it stands after the stylesheets; for this script the top of <head> is the place.
The theme's test measures the contrast of rule 29 in the dark scheme too (dark scheme, preset warm, dark scheme), a dark token left unset counting with its light value; webx:theme:check says the same as notes, and notes a layer that recoloured a token in its defaults while the dark value of it still comes from a layer below. webx:theme:show gives each token its dark value and the layer it comes from, or «as light». Letters stay light: theme_token() returns the light value.
Four doors, cheapest first
A change goes through the cheapest door that solves it:
- A token — a value in
theme/tokens.json. Every page, block and module page follows, in every preset. - CSS on the classes —
theme/src/css/theme.css, on the classes the shell (site-*) and the modules (webx-<module>-*, listed in each module'sAGENTS.md) print. - An extension point —
theme/views/parts/<point>.blade.phpfor a point a module's view offers with@webxPart(parts/blog/card.blade.php) — or a patch of a composition,theme/compositions/layout/default.json, for the layout —header/andfooter/for the header and the footer: an attribute, a piece gone, moved or added, by id (Compositions). - An override of a view — a copy of the current version in
theme/views/…, changed the least. The expensive door: the copy stops getting the module's fixes.
The header and the footer without a copy
The header and the footer of theme-default are the compositions header and footer, the fallbacks of their regions. A theme that wants the logo of its own, no phone in the bar, a search among the actions or the announcement bar inside the header patches them by id — the same JSON as the layout:
header header.topbar → header.contacts · header.brand → header.logo · header.nav ·
header.actions → header.phones, header.cta, header.languages
footer footer.inner → footer.contacts · footer.nav → footer.menu, footer.consent ·
footer.copy// theme/compositions/header/default.json
{
"replace": { "header.logo": { "view": "components.logo" } },
"add": [{ "id": "search", "to": "header.actions", "first": true, "view": "components.search" }],
"remove": ["header.phones"],
}A view of the theme in a node's place gets what the leaves get ($nav, $calls, $contacts, $hours, $email, $phones, $languages). Every id and the announcement bar's two files — Compositions. A theme with its own views/components/header.blade.php keeps working — the copy prints, the patches do not —, and webx:theme:check notes it; going over is webx:composition:show header --blade against the copy, the differences as a patch, the copy gone.
Another look of a block
A block the theme brings gets another look by the same slug in theme/blocks/<slug>.json — its template, styles and fields. The fields may only grow: a field of the type below keeps its type (title was wx-input — it stays wx-input), or webx:theme:check fails and webx:blocks:import --theme writes nothing for the type.
A field of the type below the file does not describe is inherited, not lost: it comes over whole — label, default, its sample value — after the field it follows below, or at the end. So when a package adds a field to its block in a minor release, a site whose theme overrides the block goes on working: the panel offers the field with its default, and the check says it in a note —
theme/blocks/contact.json note: contact inherits field "show_form_description" (wx-switch) from
webx-ui/theme-default with its default, and this template does not use it — print it in the
template if the block should show itA field the file describes is the file's: its label and default win over the package's.
The buttons of hero, cta, media-text and cards are wx-link fields — button_link, second_link, link in a card — with a page, an address, a new tab or a file of the library to download. The old button_url, second_url and link_url stay beside them with their type, read while the link is empty and shown in the panel only while they hold something: an override written for the old buttons stays compatible and prints what it printed. A site gets the new fields with webx:blocks:import --theme --replace=hero (and the other three), when it chooses to.
Blocks that come in as the page scrolls
The blocks of theme-default can come in as they scroll into view: their words rise and fade in, a grid of cards and the picture with its text come one after another. Off unless the theme says so — a site that never asked looks as it did. The theme says it in its manifest:
{ "theme": { "uses": ["webx-ui/theme-default"], "reveal": true } }true is up; "fade" and "scale" are the other two effects, false (or "off") switches off what a layer below turned on. The layer nearest to the site that names it decides, as with the preset, and webx:theme:show prints the answer. It is not a panel setting: the look of a site is the theme's (and in git).
What is on the screen when the page opens is never hidden — the script hides only what is below the fold, so the first screen does not blink and its picture is not held back. Without JavaScript, with prefers-reduced-motion and in print everything is simply there. A block that should stand still — a form, a price list — has the switch «Without animation».
A block of your own takes part with the same directive on the elements that come in — never on the <section> itself, or a list inside it fades twice:
<section class="b-offer" data-wx-block="offer">
<div class="b-offer__head" @webxReveal('', $no_reveal)>…</div>
<ul class="b-offer__list" role="list" @webxReveal('stagger', $no_reveal)>…</ul>
</section>@webxReveal prints data-webx-reveal="<effect>" (or, with stagger, the effect for the children) while the theme names one and nothing otherwise; the second argument is the block's own switch, a wx-switch field no_reveal. The motion is the widgets' data-webx-reveal (Widgets). The blocks print the directive from the version that brought it: a site takes it with webx:blocks:import --theme --replace=<slug>, until then the blocks stand still.
A picture that moves slower than the page
The hero and the cta of theme-default over a picture, and its text-tiles, have the switch «Parallax», off by default: on, the picture behind the words moves slower than the page while the words and the shade stay put. «Parallax strength» under it — soft, medium (the default) or strong — says how far behind it falls. The page's first hero, as tall as the screen, is its first screen: there the picture goes down with the scroll and grows a little until the screen is gone (the widgets' screen parallax; a theme sets k, the zoom and the room above with --webx-parallax-screen-*). It is the widgets' data-webx-parallax (Widgets), so a block of your own takes part by putting the attribute on a picture that fills its frame:
<section class="b-offer" data-wx-block="offer">
<img class="b-offer__picture"@if ($parallax) data-webx-parallax="{{ $strength }}" @endif src="…" alt="">
…
</section>A site takes the switch with webx:blocks:import --theme --replace=hero,cta, and text-tiles with a plain webx:blocks:import --theme --publish — a new slug is created, the others are left as they are.
A section that slides over the one above
Every block of theme-default has the switch «Slide over the section above», off by default, and under it «Edge picture» and «Edge picture on a phone». On, the section before the block — the hero banner of the page, or any block — stays in place while this one comes up over it, the words of the hero (and of the text with tiles, and a banner's words and layers) fade as they are covered, and the edge picture stands over this block's top across the whole page. Take a PNG or WebP with transparency whose bottom row is the colour of the block — one file serves both schemes, so a site with a dark scheme wants fog that fades out into transparency. It is the widgets' data-webx-overlap (Widgets); a block of your own takes part with two directives:
<section class="b-offer" data-wx-block="offer"@webxOverlap($overlap)>
@webxOverlapEdge($overlap, $overlap_edge, $overlap_edge_narrow)
…
</section>and data-webx-overlap-fade on its own words, for when something slides over it. Visitors who ask for less motion, and a page without JavaScript, see the sections one after another. A site takes the fields with webx:blocks:import --theme --replace=hero,text,media-text,cards,cta,contact,text-tiles.
Cards in a carousel, with labels and photos
The cards block of theme-default is a grid by default and a carousel on request («View»): the carousel shows as many cards across as the grid would in the same column, with arrows, dots, a loop and, if asked, turning on its own every few seconds. A card has labels — a few short words under its title («2 rooms», «54 m²») — and more photos beside its picture: with two or more a photo card turns them on its own (the photos of a card). A block saved before prints as it did; a site takes the fields with webx:blocks:import --theme --replace=cards.
A call to action on a picture
The cta of theme-default takes a fourth background, «Picture»: a photo or a sketch across the band under a shade that keeps the words readable — dark or light, turned round by a dark scheme — with the parallax of the hero. Its height is the words, the screen or a proportion (21:9, 16:9, 3:2, 4:3); words that need more make it taller. «Above the heading» puts a line over the heading on any background, and «Width» takes any of them edge to edge. Everything is optional: a picture with no words and no buttons is the picture alone, across the column or the page, with nothing around it.
A button opens a form of the Inbox in a dialog when its link is the address #webx-form-<slug> (or an empty address with the anchor webx-form-<slug>); a file of the library with «Download» is a brochure to save. A block saved before prints as it did; a site takes the fields with webx:blocks:import --theme --replace=cta.
An accent in a heading
Part of a heading in another colour — «Homes by the river» — is typed in the heading itself: two equals signs on each side of the words, Homes ==by the river==. The blocks of theme-default print it as <span class="site-accent">, in the theme's color-accent; on the accent and over a photo (hero, cta, text-tiles) the words keep the colour and lean instead. The heading stays one <h1>/<h2> with its words in reading order, and each language of the site puts the accent where its own word order wants it — one field, translated like any other. A heading without marks prints as before; a == b and an unclosed == are printed as typed.
A block of your own takes the same with the directive in place of the echo:
<h2 class="b-offer__heading">@webxAccent($heading)</h2>Another look for every accent of the site is one rule in the local theme on .site-accent (font-style: italic, background: var(--site-color-highlight) …). Where a span cannot go — an attribute, a title — \WebxUi\Themes\ThemeAccent::plain($heading) is the text without the marks.
media-text also has a logo — a small picture above the heading (a mark, a badge, a partner), at most 4rem high and 12rem wide, never stretched, its alt from the media library.
The 35 rules of a theme — where to work, tokens, where each style lives, blocks, views, languages and fonts, accessibility, what to check before saying it is done — are in the engine's RULES.md. The check and the test name a rule by its number.
The commands
| Command | What it does |
|---|---|
webx:theme:show [--json] | the layers, every token with the layer or preset that set it, every view with what it hides, blocks, icons, fonts |
webx:theme:check [path] | the rules a machine can hold; a line per finding (file:line, what, why), non-zero exit |
webx:composition:show [name] | the compositions, or the final tree of one with who added, moved, replaced or removed each node (--origin, --json, --blade) |
webx:theme:sync [--dry-run] | publishes dist/, assets/, the sprite and the modules' base look; never writes a block type |
webx:theme:critical [--check] | the critical CSS of the first screen of the pages critical names; --check compares it pixel by pixel with the full CSS |
webx:theme:make theme --local --uses=… | the local theme webx:setup gives every new site |
webx:theme:make vendor/name [--uses=…] | a packaged theme in packages/<name>, over webx-ui/theme-default unless told otherwise |
webx:theme:extract vendor/name | the site's local theme becomes a package the site then stands on |
webx:theme:eject [vendor/name] | a packaged theme becomes part of the site's local theme; its updates stop |
show is what to read before a change: it says which layer owns the value you are about to change. check is what to run before saying the change is done.
The first screen: critical CSS and fonts
Every stylesheet of the head holds the first paint until it arrives. A site that wants the first screen at once names a page of each template its visitors land on, in theme/theme.json:
{ "theme": { "uses": ["webx-ui/theme-default"], "critical": ["/", "/blog/first-article"] } }and, with playwright and lightningcss in its package.json (npx playwright install chromium), runs php artisan webx:theme:critical. It opens the pages at 1440×900 and 390×844, keeps the rules the first screen draws with and writes them, minified and prefixed, to theme/critical.css. @webxTheme then prints them inline, and every stylesheet of the head loads without blocking. php artisan webx:theme:critical --check draws each first screen with the critical CSS alone and with the full CSS and says where a pixel differs — run both after a change of the look, a sync or a build. Without the file the head is what it always was.
A face in fonts takes two options. "preload": true preloads its files of the page language's script — Latin on an English page, Cyrillic on a Ukrainian one, never both. "fallback" gives the local font the text is drawn in until the file arrives the font's metrics, so nothing moves on the swap:
{
"family": "Inter",
"weight": "100 900",
"preload": true,
"fallback": {
"local": ["Arial"],
"size-adjust": "107.4%",
"ascent-override": "90.2%",
"descent-override": "22.5%",
"line-gap-override": "0%"
},
"files": { "latin": "fonts/inter-latin.woff2", "cyrillic": "fonts/inter-cyrillic.woff2" }
}"Inter Fallback" then follows Inter in every font token of the site.
The test of a theme
Every theme has a PHPUnit test that runs the engine's contract:
use WebxUi\Themes\Testing\ThemeContract;
final class ThemeTest extends TestCase
{
use ThemeContract;
protected function themePath(): string
{
return dirname(__DIR__);
}
}make writes it for both kinds — the local theme's test runs with the site's (php artisan test), the package's on Testbench (vendor/bin/phpunit) — and it is green on the theme make just wrote. It holds the theme to:
- the manifest reads and the chain builds with this theme on top;
- every token of the vocabulary has a value somewhere in the chain;
webx:theme:checkfinds nothing: tokens, the preset, stylesheets, block types and their schemas, icons, assets, words in every declared language, fonts, letters;- text reads in every preset — WCAG AA, 4.5:1 for
textonbgandsurface,text-mutedon both,accent-contrastonaccent,accentonbg(hex colours; another notation is left to the eye); - the layout of the chain keeps
@webxTheme,@webxSeo,@webxBlocksand theheaderandfooterregions — in the final tree of the compositionlayout, whose patches of the theme apply with no finding; - the theme's views compile (a component of a module not installed where the test runs is not the theme's fault and is skipped);
- a packaged theme's committed
dist/is built from its currentsrc/.
The first red line is the first rule a change broke.
A packaged theme
php artisan webx:theme:make acme/theme-clinic writes packages/theme-clinic/:
composer.json "type": "webx-theme", the manifest under extra.webx.theme
tokens.json {"defaults": {}} — every value comes from below until you set one
src/css/theme.css empty, with the doors in a comment
dist/ theme.css and sources.json, already built — the test is green at once
package.json npm run build — Vite builds src/ into dist/ and writes sources.json
vite.config.js
tests/ThemeTest.php the contract, on Testbench
phpunit.xml.dist
.github/workflows/theme.yml dist/ is rebuilt and unchanged; the contract is greenAfter every change to src/: npm install && npm run build in the package, and commit dist/ — the test fails while src/ and dist/ disagree. A site stands on the theme with "uses": ["acme/theme-clinic"] in its theme/theme.json and the package required from Composer (a path repository while it lives beside the site, a VCS or Packagist one when it moves out).
Extract: a site's look becomes a theme
A design worked out on one site, and a second site wants the same. Copying theme/ would mean fixing every bug twice; instead the local theme becomes a package both sites stand on:
php artisan webx:theme:extract acme/theme-clinictheme/moves intopackages/theme-clinic/(--pathfor another place);theme.jsonbecomes the composer.json'sextra.webx.theme,usesand the rest kept.- The package gets what a packaged theme has: the build of
dist/, the test on the contract, the CI. The local theme's own test (a test of the site) is dropped, and the stubsrc/js/theme.jsthat says nothing too. - The site stands on the package: a path repository and
"acme/theme-clinic": "@dev"in its composer.json,WEBX_THEME=acme/theme-clinicin.env, the theme's suite gone fromphpunit.xml; the entries oftheme/invite.config.jsare named for you to remove. - The look of the chain is compared before and after — tokens, the winning file of every view, picture and icon, block types, font faces, words; any difference is listed.
Composer and npm are not run — the command ends with the steps:
composer update acme/theme-clinic
(cd packages/theme-clinic && npm install && npm run build)
php artisan webx:theme:syncUntil they run, the site has no theme stylesheet. The block types the theme brings stay on the site as they are: they are the site's now, and no sync touches them. A new theme/ for this site's own differences is php artisan webx:theme:make theme --local --uses=acme/theme-clinic.
Eject: a site leaves a theme
A site has come to differ from its packaged theme more than it shares with it, and every update of the theme breaks something the site overrode. It takes the theme in and stops following it:
php artisan webx:theme:eject acme/theme-clinic- On a site with a local theme over the package, the package folds into
theme/: a file the site already has wins, as it won in the chain;tokens.jsonmerges by token (presets by name, then by token), the words of the layout by key, the manifest key by key —usesbecomes what the package stood on. The package'ssrc/goes undertheme/src/css/theme-clinic/(andsrc/js/…), imported first intheme.css, where its stylesheet used to come. - On a site that stood on the package itself, the package becomes
theme/whole (--pathfor another directory) andWEBX_THEMEnames it. - The look is compared before and after, as for extract.
webx-ui/theme-defaultis never ejected: it is the value of every token and the shell every site stands on — override what you need of it intheme/, file by file.
Then composer remove acme/theme-clinic, npm run build, php artisan webx:theme:sync and php artisan webx:theme:check. After a fold the check may ask for words: a language the site declares in locales now needs every key of en, the package's included — before, they fell back to English as well.
For an agent
php artisan webx:theme:show— what the chain gives and which layer owns it.- The change, in
theme/, through the cheapest door; the rules inRULES.md. php artisan webx:theme:check— no findings; the theme's test — green. The pictures, fonts and scripts of the theme keep rules 36–41 (Speed).- Screenshots in a browser: the home page, an inner page, each module's page — on a desktop and at 375px, in every preset. jsdom does not check layout.
- The home page and the heaviest page measured at a phone's width — LCP, CLS, bytes.
- A report to the person: what changed, through which door, which views are overridden.