Theme Scope
A provider that derives an invocation and themes everything inside it.
Live demo
Theme Scope materializes an invocation — a named algorithm plus its knobs and token constraints — and applies the derived register to a target, so everything beneath it renders on that theme. It draws nothing of its own: the children you write are the content, untouched.
target decides what the tokens land on, and it defaults to self, scoping the theme to this element's subtree — that is what makes a themed card, a mockup frame, or two algorithms side by side possible without either one leaking onto the page. target="root" drives :root instead, for the single scope that themes a whole document. The scope also owns the scheme: it derives the algorithm natively, and when the requested scheme is not the one that derivation produced, it re-derives with invert, so one set of inputs yields both modes through the engine rather than a hand-mirrored guess. An <xtyle-scheme-toggle> nested anywhere inside drives the scope rather than the document. Each settled derivation fires xtyle:theme-scope carrying the scheme and the applied register, and a bad invocation reports the error on that same event instead of applying a half-derived theme.
When to use
How this component composes with the rest of the set.
Props
5 props, straight from the manifest.
| Prop | Type | Default | Bindings | Description |
|---|---|---|---|---|
Appearance
States
effective scheme
The scheme the last derivation actually produced, published for anything that must reflect what is on screen rather than what was asked for.
Anatomy
The named parts that make up the component, with their selectors.
scope
The element itself. Under the default target="self" the derived custom properties are set on it, so the cascade carries the theme to its children.
Tokens & coverage
What the component consumes, checked live against what the algorithm produces.
Live coverage check against the xtyle-default register
(derive(xtyleDefault, { anchors }) →
coverComponent(manifest, register)). Every token this component
consumes must be a key the algorithm produces.
Slots
Everything the scope themes. Rendered exactly as authored; the scope adds no markup of its own.
Accessibility
Code
Scoped subtrees, pinned schemes, and the page-level scope
A scope theming just its own subtree, two invocations side by side owning their own schemes, and the root-targeting scope a toggle drives.
<!-- Scoped to its own subtree: everything inside renders on the derived theme -->
<xtyle-theme-scope algorithm="xtyle-quiet" constraints='{"--accent":"#7c5cff"}'>
<xtyle-card>
<xtyle-heading level="3">Quiet</xtyle-heading>
<xtyle-text>Only this card is themed.</xtyle-text>
</xtyle-card>
</xtyle-theme-scope>
<!-- Two invocations side by side, each owning its own scheme -->
<xtyle-theme-scope algorithm="xtyle-default" scheme="light">
<xtyle-card>Light</xtyle-card>
</xtyle-theme-scope>
<!-- The page-level scope: drives :root, with a toggle that re-derives through it -->
<xtyle-theme-scope target="root" algorithm="xtyle-default">
<xtyle-scheme-toggle></xtyle-scheme-toggle>
</xtyle-theme-scope>
<script lang="ts">
import { ThemeScope, SchemeToggle, Card } from "@xtyle/svelte";
</script>
<ThemeScope algorithm="xtyle-quiet" constraints={{ "--accent": "#7c5cff" }}>
<Card>Only this subtree is themed.</Card>
</ThemeScope>
<!-- the page-level scope, with a toggle that drives it -->
<ThemeScope target="root" scheme="light">
<SchemeToggle />
</ThemeScope>
---
import ThemeScope from "@xtyle/astro/ThemeScope.astro";
import SchemeToggle from "@xtyle/astro/SchemeToggle.astro";
import Card from "@xtyle/astro/Card.astro";
---
<ThemeScope algorithm="xtyle-quiet" constraints={{ "--accent": "#7c5cff" }}>
<Card>Only this subtree is themed.</Card>
</ThemeScope>
<!-- the page-level scope, with a toggle that drives it -->
<ThemeScope target="root" scheme="light">
<SchemeToggle />
</ThemeScope>