@adia-ai/web-components 0.7.11 → 0.7.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/README.md +2 -2
  3. package/USAGE.md +2 -2
  4. package/components/theme-provider/theme-provider.a2ui.json +88 -0
  5. package/components/theme-provider/theme-provider.class.js +134 -0
  6. package/components/theme-provider/theme-provider.css +18 -0
  7. package/components/theme-provider/theme-provider.d.ts +45 -0
  8. package/components/theme-provider/theme-provider.js +22 -0
  9. package/components/theme-provider/theme-provider.test.js +94 -0
  10. package/components/theme-provider/theme-provider.yaml +96 -0
  11. package/dist/host.min.css +1 -1
  12. package/dist/host.sheet.js +11 -0
  13. package/dist/prose.min.css +1 -0
  14. package/dist/prose.sheet.js +11 -0
  15. package/dist/themes.min.css +1 -0
  16. package/dist/themes.sheet.js +11 -0
  17. package/dist/verse.min.css +1 -0
  18. package/dist/verse.sheet.js +11 -0
  19. package/dist/web-components.min.css +1 -1
  20. package/dist/web-components.sheet.js +11 -0
  21. package/package.json +5 -1
  22. package/styles/README.md +1 -1
  23. package/styles/colors/parameters.css +1 -1
  24. package/styles/colors/primitives-accent.css +1 -1
  25. package/styles/colors/primitives-brand.css +1 -1
  26. package/styles/colors/primitives-danger.css +1 -1
  27. package/styles/colors/primitives-info.css +1 -1
  28. package/styles/colors/primitives-neutral.css +1 -1
  29. package/styles/colors/primitives-success.css +1 -1
  30. package/styles/colors/primitives-warning.css +1 -1
  31. package/styles/colors/scrims.css +1 -1
  32. package/styles/colors/semantics/aliases.css +1 -1
  33. package/styles/colors/semantics/buckets.css +1 -1
  34. package/styles/colors/semantics/core.css +1 -1
  35. package/styles/colors/semantics/data-viz.css +1 -1
  36. package/styles/colors/semantics/features.css +1 -1
  37. package/styles/colors/surfaces.css +1 -1
  38. package/styles/components.css +1 -0
  39. package/styles/design-tokens-export.js +1 -1
  40. package/styles/host.css +1 -1
  41. package/styles/prose.css +1 -1
  42. package/styles/themes.css +12 -12
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog — @adia-ai/web-components
2
2
 
3
+ ## [0.7.12] — 2026-06-04
4
+
5
+ ### Added
6
+
7
+ - **New `<theme-provider>` element — adopt the AdiaUI foundation from anywhere, no `<head>` link.** A Light-DOM, `display: contents` infra wrapper (the 122nd primitive) that adopts the foundation — design tokens + resets + page-frame + every primitive's CSS, the constructable-stylesheet twin of `web-components.min.css` (byte-identical to the CDN bundle) — into `document.adoptedStyleSheets` once, deduped, at module-eval. So SPA roots / embedded apps / dynamic mounts render fully-styled **without** a hand-wired `<link rel="stylesheet">` in `<head>`. Opt-in `theme="ocean|forest|…"` (named preset) + `scale="verse|prose"` (typographic register) adopt their layer twin **on demand** (`theme=` matches the `[theme]` hook directly; `scale=` maps onto the existing `[verse]`/`[prose]` attribute). Coexists with the render-blocking `<link>` path (same bytes) — link for multi-page / top-level surfaces (cacheable, no flash), provider for no-`<head>` contexts. Deliberately **not** in the all-primitives barrel (it carries the whole foundation) — import `@adia-ai/web-components/components/theme-provider` explicitly. Files: `components/theme-provider/{theme-provider.js,.class.js,.css,.yaml,.html,.test.js}`.
8
+ - **CDN `.sheet.js` twins.** `bundle-css.mjs` co-emits a constructable-`CSSStyleSheet` twin beside each foundation `.min.css` — `web-components.sheet.js`, `host.sheet.js`, and the `themes` / `verse` / `prose` register twins — from the **same minified buffer** (byte-identical to the `.min.css`, verified by `check:css-bundles-fresh`, exposed as the `./css/sheet` export). A page that links `web-components.min.css` and one that adopts `web-components.sheet.js` render identically. Powers `<theme-provider>` and any runtime style injector that can't add a `<head>` link.
9
+
10
+ ### Changed
11
+
12
+ - **BREAKING (pre-1.0 PATCH cadence) — the token-theme attribute `data-theme` is renamed `theme`.** `<html data-theme="ocean">` → `<html theme="ocean">`; `[data-theme="…"]` selectors → `[theme="…"]`; the token-root selector `:root, theme-ui, [data-theme]` → `:root, theme-ui, [theme], theme-provider` across the 14 foundation files (so `<theme-provider>` is itself a token-root). Cleaner, and it converges with `<canvas-ui theme="…">`, which already scoped AdiaUI themes the same way. Done as a repo-wide word-boundary sweep — compound attributes (`data-theme-slug`, `data-themes-grid`, `data-themed`, …) are preserved (the sweep also touched the styles/, traits/, and patterns/ trees). **Consumers using `data-theme="…"` must switch to `theme="…"`** — see `docs/MIGRATION GUIDE.md`.
13
+ - **CDN bundles rebuilt** — `dist/web-components.min.{css,js}` + `dist/host.min.css` regenerated so the `[theme]` rename, `<theme-provider>` registration, and the new register twins reach `@adia-ai/web-components@0.7` CDN consumers.
14
+
15
+ ### Fixed
16
+
17
+ - **`dts-codegen` reads the authoritative tag.** It reconstructed each demo's tag as `${name}-ui`, which mangles a no-`-ui` infra tag (`<theme-provider>` is the first) — it now reads `x-adiaui.tag` from the sidecar. Behavior-neutral for all 121 `-ui` components (their `name-ui` === `tag`); correct for infra tags. File: `scripts/build/dts-codegen.mjs`.
18
+
3
19
  ## [0.7.11] — 2026-06-04
4
20
 
5
21
  ### Added
@@ -3042,7 +3058,7 @@ that don't surface in the export). Pure-JS OKLCH → OKLab → linear-sRGB
3042
3058
 
3043
3059
  - **`styles/design-tokens-export.js`** (new ~430 lines) — extraction module:
3044
3060
  CSSOM scanner with authoritative-selector filter (`:root, theme-ui,
3045
- [data-theme]` only — skipping attribute-scoped overrides that would
3061
+ [theme]` only — skipping attribute-scoped overrides that would
3046
3062
  pollute the cssVar map under last-wins semantics), symbolic
3047
3063
  `var()` / `light-dark()` chain walker, OKLCH color-math pipeline, four
3048
3064
  output formatters (DTCG / hex / float-RGB / HSL-decimal). Public API:
package/README.md CHANGED
@@ -336,12 +336,12 @@ generation engine consume.
336
336
  ## Themes, density, scale
337
337
 
338
338
  ```html
339
- <div data-theme="ocean" density="compact" size="sm">
339
+ <div theme="ocean" density="compact" size="sm">
340
340
  …all descendants re-theme / re-densify / re-scale automatically…
341
341
  </div>
342
342
  ```
343
343
 
344
- - `[data-theme]` — 8 themes: `default`, `ocean`, `forest`, `sunset`,
344
+ - `[theme]` — 8 themes: `default`, `ocean`, `forest`, `sunset`,
345
345
  `lavender`, `rose`, `slate`, `midnight`
346
346
  - `[density]` — `compact` (0.85×) · `spacious` (1.15×)
347
347
  - `[size]` — `sm`|`md`|`lg` shifts the entire typescale + component
package/USAGE.md CHANGED
@@ -673,14 +673,14 @@ The same applies to `bind()` — call it once in the constructor or use a field,
673
673
  AdiaUI is parametric. Three attributes drive global appearance:
674
674
 
675
675
  ```html
676
- <div data-theme="ocean" density="compact" size="sm">
676
+ <div theme="ocean" density="compact" size="sm">
677
677
  <!-- all descendants re-theme / re-densify / re-scale -->
678
678
  </div>
679
679
  ```
680
680
 
681
681
  | Attribute | Values | Effect |
682
682
  |---|---|---|
683
- | `[data-theme]` | `default`, `ocean`, `forest`, `sunset`, `lavender`, `rose`, `slate`, `midnight` | Swaps the OKLCH color ramp |
683
+ | `[theme]` | `default`, `ocean`, `forest`, `sunset`, `lavender`, `rose`, `slate`, `midnight` | Swaps the OKLCH color ramp |
684
684
  | `[density]` | `compact` (0.85×), `spacious` (1.15×) | Multiplies `--a-density` token |
685
685
  | `[size]` | `sm`, `md`, `lg` | Shifts typescale + component dimensions |
686
686
  | `[radius]` | `sharp` (0), `rounded` (1), `round` (2) | Multiplies `--a-radius-k` token |
@@ -0,0 +1,88 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://adiaui.dev/a2ui/v0_9/components/ThemeProvider.json",
4
+ "title": "ThemeProvider",
5
+ "description": "Foundation-providing wrapper — adopts the AdiaUI foundation (design tokens +\nresets + page-frame + every primitive's CSS) into the document from anywhere\nin the DOM, so a surface renders fully-styled WITHOUT a hand-wired\n<link rel=\"stylesheet\"> in <head>. Layout-transparent (display: contents): the\nelement owns no box; children lay out as if it weren't there.\n\nMechanism: it imports the constructable-stylesheet twin of web-components.min.css\n(byte-identical to the CDN bundle, emitted from the same build buffer) and\nadopts it once into document.adoptedStyleSheets, deduped — adoption fires at\nmodule load, before paint. Coexists with the render-blocking <link> path; both\ndeliver the same bytes. Use a <link> (-> the CDN web-components.min.css) for\nmulti-page / top-level surfaces (cacheable across navigations, zero flash); use\n<theme-provider> for SPA roots, embedded apps, and dynamic mounts where you do\nnot control <head> (e.g. <embed-shell>, an A2UI surface, a micro-frontend).\n\nTheming: the base foundation is OS light/dark via light-dark() tokens. Two opt-in\nattributes adopt their layer on demand — theme=\"ocean|forest|slate|…\" applies a\nnamed preset (adopts the themes layer; matches the [theme] hook) and\nscale=\"verse|prose\" sets the compact / long-form typographic register (adopts the\nmatching register layer; maps onto the [verse]/[prose] attribute). Each layer is\nfetched only when its attribute is set, so a bare provider stays lean.\nOpt-in infra: NOT in the all-in-one @adia-ai/web-components barrel (it carries\nthe whole foundation); import @adia-ai/web-components/components/theme-provider\nexplicitly. Distinct from <frame-ui> (a layout skeleton, owns no CSS delivery)\nand the page shells (chrome over the same foundation).\n",
6
+ "type": "object",
7
+ "allOf": [
8
+ {
9
+ "$ref": "common_types.json#/$defs/ComponentCommon"
10
+ },
11
+ {
12
+ "$ref": "common_types.json#/$defs/CatalogComponentCommon"
13
+ }
14
+ ],
15
+ "properties": {
16
+ "theme": {
17
+ "description": "Named theme preset for the wrapped subtree (default, ocean, forest, sunset, lavender, rose, slate, midnight). Adopts the themes layer on demand + matches the [theme=\"…\"] hook.",
18
+ "type": "string",
19
+ "default": ""
20
+ },
21
+ "component": {
22
+ "const": "ThemeProvider"
23
+ },
24
+ "scale": {
25
+ "description": "Typographic / density register for the subtree — \"verse\" (compact) or \"prose\" (long-form). Adopts the matching register layer on demand; maps onto the [verse]/[prose] attribute (additive).",
26
+ "type": "string",
27
+ "default": ""
28
+ }
29
+ },
30
+ "required": [
31
+ "component"
32
+ ],
33
+ "unevaluatedProperties": false,
34
+ "x-adiaui": {
35
+ "anti_patterns": [],
36
+ "category": "layout",
37
+ "composes": [],
38
+ "events": {},
39
+ "examples": [
40
+ {
41
+ "description": "A client-mounted app root that self-provides the foundation (no head link).",
42
+ "a2ui": "[\n { \"id\": \"root\", \"component\": \"ThemeProvider\", \"children\": [\"panel\"] },\n { \"id\": \"panel\", \"component\": \"Frame\", \"children\": [\"body\", \"actions\"] },\n { \"id\": \"body\", \"component\": \"Section\", \"children\": [\"copy\"] },\n { \"id\": \"copy\", \"component\": \"Text\", \"variant\": \"body\", \"textContent\": \"Fully styled — no <head> stylesheet link.\" },\n { \"id\": \"actions\", \"component\": \"Footer\", \"children\": [\"go\"] },\n { \"id\": \"go\", \"component\": \"Button\", \"text\": \"Continue\", \"variant\": \"primary\" }\n]",
43
+ "name": "spa-root"
44
+ }
45
+ ],
46
+ "keywords": [
47
+ "style",
48
+ "provider",
49
+ "foundation",
50
+ "tokens",
51
+ "reset",
52
+ "adopt",
53
+ "stylesheet",
54
+ "shell",
55
+ "embed",
56
+ "spa"
57
+ ],
58
+ "name": "UIThemeProvider",
59
+ "related": [
60
+ "Frame",
61
+ "Card"
62
+ ],
63
+ "slots": {},
64
+ "states": [
65
+ {
66
+ "description": "Default — foundation adopted into the document; children rendered.",
67
+ "name": "idle"
68
+ }
69
+ ],
70
+ "status": "experimental",
71
+ "synonyms": {
72
+ "foundation": [
73
+ "foundation",
74
+ "tokens",
75
+ "styles"
76
+ ],
77
+ "provider": [
78
+ "provider",
79
+ "root",
80
+ "host"
81
+ ]
82
+ },
83
+ "tag": "theme-provider",
84
+ "tokens": {},
85
+ "traits": [],
86
+ "version": 1
87
+ }
88
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Non-side-effect class export for `<theme-provider>`.
3
+ *
4
+ * Importing this file gives you the class (and adopts the foundation as a
5
+ * module-eval side effect) without auto-registering the tag. The auto-register
6
+ * path is `@adia-ai/web-components/components/theme-provider` (which imports this
7
+ * file + calls `defineIfFree()`).
8
+ *
9
+ * `<theme-provider>` — the foundation-providing wrapper. Adopt the AdiaUI
10
+ * foundation (design tokens + resets + page-frame + every primitive's CSS) into
11
+ * the document from anywhere in the DOM, so a surface renders fully-styled
12
+ * WITHOUT a hand-wired `<link rel="stylesheet">` in `<head>`. Layout-transparent
13
+ * (`display: contents`): the element owns no box; children lay out as if it
14
+ * weren't there.
15
+ *
16
+ * Mechanism: imports the constructable-stylesheet twin of `web-components.min.css`
17
+ * — byte-identical to the CDN bundle (emitted from the same buffer by
18
+ * `scripts/build/bundle-css.mjs`) — and adopts it once into
19
+ * `document.adoptedStyleSheets`, deduped by sheet identity. Adoption fires at
20
+ * module evaluation (the earliest point), so importing the element provides the
21
+ * foundation before the body paints in the common case.
22
+ *
23
+ * Coexists with the render-blocking `<link>` path — both deliver the same bytes.
24
+ * Use a `<link>` (→ the CDN `web-components.min.css`) for multi-page / top-level
25
+ * surfaces (cacheable across navigations, zero flash); use `<theme-provider>`
26
+ * for SPA roots, embedded apps, and dynamic mounts where you don't control
27
+ * `<head>` (e.g. `<embed-shell>`, an A2UI surface, a micro-frontend).
28
+ *
29
+ * Scope (v1): the provider supplies the FOUNDATION only — design tokens, resets,
30
+ * page-frame, and every primitive's CSS. OS light/dark resolves automatically
31
+ * (the tokens are `light-dark()`-based). Named themes (`[theme]`) and the
32
+ * `verse` / `prose` context registers live in OPT-IN layers (themes.css /
33
+ * verse.css / prose.css) that are NOT in the foundation bundle, so setting
34
+ * `theme` / `verse` on the wrapper does nothing until those layers are also
35
+ * adopted — a planned `theme=` / `verse` provider option (the token-root selector
36
+ * is pre-wired for it; see .brain/notes/theme-provider-design-2026-06-04.md).
37
+ *
38
+ * Deliberately NOT in the all-in-one `@adia-ai/web-components` barrel — it's
39
+ * opt-in infra (it carries the whole foundation). Import it explicitly:
40
+ * `import '@adia-ai/web-components/components/theme-provider';`
41
+ *
42
+ * @see ../../USAGE.md · .brain/notes/theme-provider-design-2026-06-04.md
43
+ */
44
+
45
+ import { UIElement } from '../../core/element.js';
46
+ import constructFoundationSheet from '../../dist/web-components.sheet.js';
47
+
48
+ /**
49
+ * Adopt the foundation sheet into the document exactly once. Idempotent across
50
+ * any number of `<theme-provider>` instances (dedup by sheet identity). No-ops in
51
+ * a non-DOM context — `constructFoundationSheet()` returns `null` on SSR/Node.
52
+ */
53
+ function provideFoundation() {
54
+ const sheet = constructFoundationSheet();
55
+ if (!sheet) return;
56
+ if (!document.adoptedStyleSheets.includes(sheet)) {
57
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
58
+ }
59
+ }
60
+
61
+ // Opt-in context registers — themes (named `[theme]` presets), and the `verse` /
62
+ // `prose` `scale` registers. Each is its own constructable-sheet twin (built by
63
+ // scripts/build/bundle-css.mjs, byte-identical to its .min.css). Adopted on demand
64
+ // the first time a provider needs one, deduped by sheet identity. Dynamic-imported
65
+ // (static paths, so bundlers can code-split) so the element stays lean — a provider
66
+ // that does no theming never pulls these in.
67
+ const TWIN_LOADED = { themes: false, verse: false, prose: false };
68
+ function loadTwin(name) {
69
+ switch (name) {
70
+ case 'themes': return import('../../dist/themes.sheet.js');
71
+ case 'verse': return import('../../dist/verse.sheet.js');
72
+ case 'prose': return import('../../dist/prose.sheet.js');
73
+ default: return null;
74
+ }
75
+ }
76
+ function ensureTwin(name) {
77
+ if (TWIN_LOADED[name]) return;
78
+ const p = loadTwin(name);
79
+ if (!p) return;
80
+ TWIN_LOADED[name] = true;
81
+ p.then((mod) => {
82
+ const sheet = mod?.default?.();
83
+ if (sheet && !document.adoptedStyleSheets.includes(sheet)) {
84
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
85
+ }
86
+ }).catch(() => { TWIN_LOADED[name] = false; }); // allow a later retry on failure
87
+ }
88
+
89
+ // Adopt the base foundation as early as this module evaluates — before any element
90
+ // connects, before the body paints when imported from <head>. Importing the
91
+ // provider IS the act of providing the foundation, wherever the element lands.
92
+ provideFoundation();
93
+
94
+ export class UIThemeProvider extends UIElement {
95
+ static properties = {
96
+ // Named theme preset (ocean / forest / slate / …). Reflected, so the attribute
97
+ // — which IS the `[theme="…"]` CSS hook in themes.css — tracks the property.
98
+ theme: { type: String, reflect: true },
99
+ // Typographic/density register: "verse" (compact) | "prose" (long-form).
100
+ // Mapped onto the existing `[verse]` / `[prose]` attribute below (additive —
101
+ // the register CSS is untouched), so every register rule incl. `[size]`
102
+ // sub-tiers applies for free.
103
+ scale: { type: String, reflect: true },
104
+ };
105
+ static template = () => null;
106
+
107
+ connected() {
108
+ // Layout-transparent + invisible to the a11y tree (the template-engine /
109
+ // traits-host convention). Set imperatively so it holds even in the frame
110
+ // before the adopted foundation's own `display: contents` rule applies.
111
+ this.style.display = 'contents';
112
+ if (!this.hasAttribute('role')) this.setAttribute('role', 'presentation');
113
+ provideFoundation(); // belt-and-suspenders for late registration
114
+ this.#applyContext();
115
+ }
116
+
117
+ updated() {
118
+ this.#applyContext();
119
+ }
120
+
121
+ // Adopt the opt-in twins for the current theme/scale, and map `scale` onto the
122
+ // existing register attribute. Idempotent (safe to call on every update).
123
+ #applyContext() {
124
+ // `theme="ocean"` already matches `[theme="ocean"]` (the attr is on the host);
125
+ // adopt themes.sheet.js so those preset rules exist in the document.
126
+ if (this.theme) ensureTwin('themes');
127
+
128
+ const scale = this.scale;
129
+ this.toggleAttribute('verse', scale === 'verse');
130
+ this.toggleAttribute('prose', scale === 'prose');
131
+ if (scale === 'verse') ensureTwin('verse');
132
+ else if (scale === 'prose') ensureTwin('prose');
133
+ }
134
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `<theme-provider>` — layout-transparent foundation host.
3
+ *
4
+ * The element exists to adopt the AdiaUI foundation into the document (see
5
+ * theme-provider.class.js); it owns no layout. `display: contents` removes its
6
+ * box so children lay out as if the wrapper weren't there. The class also sets
7
+ * this imperatively on connect — belt-and-suspenders for the frame before this
8
+ * adopted rule applies.
9
+ *
10
+ * NOTE: a `>` child combinator from an ancestor does NOT pierce a
11
+ * `display: contents` wrapper (FB-53) — keep `<theme-provider>` at/near the
12
+ * mount root, not spliced mid-layout-chain.
13
+ */
14
+ @scope (theme-provider) {
15
+ :where(:scope) {
16
+ display: contents;
17
+ }
18
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * `<theme-provider>` — Foundation-providing wrapper — adopts the AdiaUI foundation (design tokens +
3
+ resets + page-frame + every primitive's CSS) into the document from anywhere
4
+ in the DOM, so a surface renders fully-styled WITHOUT a hand-wired
5
+ <link rel="stylesheet"> in <head>. Layout-transparent (display: contents): the
6
+ element owns no box; children lay out as if it weren't there.
7
+
8
+ Mechanism: it imports the constructable-stylesheet twin of web-components.min.css
9
+ (byte-identical to the CDN bundle, emitted from the same build buffer) and
10
+ adopts it once into document.adoptedStyleSheets, deduped — adoption fires at
11
+ module load, before paint. Coexists with the render-blocking <link> path; both
12
+ deliver the same bytes. Use a <link> (-> the CDN web-components.min.css) for
13
+ multi-page / top-level surfaces (cacheable across navigations, zero flash); use
14
+ <theme-provider> for SPA roots, embedded apps, and dynamic mounts where you do
15
+ not control <head> (e.g. <embed-shell>, an A2UI surface, a micro-frontend).
16
+
17
+ Theming: the base foundation is OS light/dark via light-dark() tokens. Two opt-in
18
+ attributes adopt their layer on demand — theme="ocean|forest|slate|…" applies a
19
+ named preset (adopts the themes layer; matches the [theme] hook) and
20
+ scale="verse|prose" sets the compact / long-form typographic register (adopts the
21
+ matching register layer; maps onto the [verse]/[prose] attribute). Each layer is
22
+ fetched only when its attribute is set, so a bare provider stays lean.
23
+ Opt-in infra: NOT in the all-in-one @adia-ai/web-components barrel (it carries
24
+ the whole foundation); import @adia-ai/web-components/components/theme-provider
25
+ explicitly. Distinct from <frame-ui> (a layout skeleton, owns no CSS delivery)
26
+ and the page shells (chrome over the same foundation).
27
+
28
+ *
29
+ * @see https://ui-kit.exe.xyz/site/components/theme-provider
30
+ *
31
+ * Type declarations generated by scripts/build/dts-codegen.mjs from
32
+ * the component's `.a2ui.json` sidecar(s). Edit the source `.yaml`,
33
+ * run `npm run build:components`, then `npm run codegen:dts` to
34
+ * regenerate; or hand-author this file fully if rich event types are
35
+ * needed beyond what the yaml `events:` block can express.
36
+ */
37
+
38
+ import { UIElement } from '../../core/element.js';
39
+
40
+ export class UIThemeProvider extends UIElement {
41
+ /** Named theme preset for the wrapped subtree (default, ocean, forest, sunset, lavender, rose, slate, midnight). Adopts the themes layer on demand + matches the [theme="…"] hook. */
42
+ theme: string;
43
+ /** Typographic / density register for the subtree — "verse" (compact) or "prose" (long-form). Adopts the matching register layer on demand; maps onto the [verse]/[prose] attribute (additive). */
44
+ scale: string;
45
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * `<theme-provider>` — auto-registers the tag on import, and adopts the AdiaUI
3
+ * foundation into the document (the side effect lives in the class module).
4
+ *
5
+ * import '@adia-ai/web-components/components/theme-provider';
6
+ * <theme-provider> … your app … </theme-provider>
7
+ *
8
+ * Opt-in infra: NOT pulled by the `@adia-ai/web-components` barrel (it carries
9
+ * the full foundation CSS as a constructable sheet). For the class without
10
+ * auto-registering the tag, import the `class` subpath:
11
+ *
12
+ * import { UIThemeProvider } from '@adia-ai/web-components/components/theme-provider/class';
13
+ *
14
+ * @see ../../USAGE.md#registration--auto-vs-explicit
15
+ */
16
+
17
+ import { defineIfFree } from '../../core/register.js';
18
+ import { UIThemeProvider } from './theme-provider.class.js';
19
+
20
+ defineIfFree('theme-provider', UIThemeProvider);
21
+
22
+ export { UIThemeProvider };
@@ -0,0 +1,94 @@
1
+ /**
2
+ * <theme-provider> tests
3
+ *
4
+ * The provider adopts the AdiaUI foundation (a constructable stylesheet) into
5
+ * `document.adoptedStyleSheets` — once, deduped — and renders `display: contents`
6
+ * + `role=presentation`. The real foundation sheet (`web-components.sheet.js`,
7
+ * ~512 KB of LightningCSS output) is mocked here with a 1-rule stub so the test
8
+ * exercises the ELEMENT's contract (adopt-once, dedup, transparency), not the
9
+ * bundle's CSS. Byte-parity of the real sheet is covered by `check:css-bundles-fresh`.
10
+ */
11
+
12
+ import { describe, it, expect, beforeEach, vi } from 'vitest';
13
+
14
+ // Stub the heavy foundation sheet — same default-export shape as the generated
15
+ // module: a constructSheet() returning a memoized CSSStyleSheet singleton.
16
+ vi.mock('../../dist/web-components.sheet.js', () => {
17
+ let sheet = null;
18
+ return {
19
+ default: () => {
20
+ if (typeof CSSStyleSheet === 'undefined') return null;
21
+ if (!sheet) { sheet = new CSSStyleSheet(); sheet.replaceSync('theme-provider{display:contents}'); }
22
+ return sheet;
23
+ },
24
+ };
25
+ });
26
+
27
+ // Stub the opt-in twins — the element dynamic-imports these when theme=/scale= is
28
+ // set. We test the attribute contract (sync), not the adopted CSS. (Factories are
29
+ // inlined because vi.mock hoists above any shared `const`.)
30
+ vi.mock('../../dist/themes.sheet.js', () => ({ default: () => { const s = new CSSStyleSheet(); s.replaceSync(':root{}'); return s; } }));
31
+ vi.mock('../../dist/verse.sheet.js', () => ({ default: () => { const s = new CSSStyleSheet(); s.replaceSync(':root{}'); return s; } }));
32
+ vi.mock('../../dist/prose.sheet.js', () => ({ default: () => { const s = new CSSStyleSheet(); s.replaceSync(':root{}'); return s; } }));
33
+
34
+ import '../../core/element.js';
35
+ import './theme-provider.js'; // registers the tag + adopts the (mocked) foundation at module-eval
36
+
37
+ const tick = () => new Promise((r) => queueMicrotask(r));
38
+
39
+ function mount(html) {
40
+ const wrap = document.createElement('div');
41
+ wrap.innerHTML = html;
42
+ document.body.appendChild(wrap);
43
+ return wrap.firstElementChild;
44
+ }
45
+
46
+ describe('<theme-provider>', () => {
47
+ beforeEach(() => { document.body.innerHTML = ''; });
48
+
49
+ it('adopts the foundation sheet at import (module-eval side effect)', () => {
50
+ expect(document.adoptedStyleSheets.length).toBeGreaterThanOrEqual(1);
51
+ });
52
+
53
+ it('is display:contents + role=presentation on connect', async () => {
54
+ const el = mount('<theme-provider><span>hi</span></theme-provider>');
55
+ await tick();
56
+ expect(el.style.display).toBe('contents');
57
+ expect(el.getAttribute('role')).toBe('presentation');
58
+ });
59
+
60
+ it('does not clobber an author-set role', async () => {
61
+ const el = mount('<theme-provider role="group"><span>hi</span></theme-provider>');
62
+ await tick();
63
+ expect(el.getAttribute('role')).toBe('group');
64
+ });
65
+
66
+ it('dedupes — N instances adopt the foundation exactly once', async () => {
67
+ const before = document.adoptedStyleSheets.length; // singleton already adopted at import
68
+ mount('<theme-provider></theme-provider>');
69
+ mount('<theme-provider></theme-provider>');
70
+ mount('<theme-provider></theme-provider>');
71
+ await tick();
72
+ expect(document.adoptedStyleSheets.length).toBe(before);
73
+ });
74
+
75
+ it('reflects theme= to the [theme] attribute hook', async () => {
76
+ const el = mount('<theme-provider theme="ocean"><span>x</span></theme-provider>');
77
+ await tick();
78
+ expect(el.getAttribute('theme')).toBe('ocean');
79
+ });
80
+
81
+ it('scale="verse" maps to the [verse] register attribute', async () => {
82
+ const el = mount('<theme-provider scale="verse"><span>x</span></theme-provider>');
83
+ await tick();
84
+ expect(el.hasAttribute('verse')).toBe(true);
85
+ expect(el.hasAttribute('prose')).toBe(false);
86
+ });
87
+
88
+ it('scale="prose" maps to the [prose] register attribute', async () => {
89
+ const el = mount('<theme-provider scale="prose"><span>x</span></theme-provider>');
90
+ await tick();
91
+ expect(el.hasAttribute('prose')).toBe(true);
92
+ expect(el.hasAttribute('verse')).toBe(false);
93
+ });
94
+ });
@@ -0,0 +1,96 @@
1
+ # Edit this file; run `npm run build:components` to regenerate a2ui.json.
2
+ $schema: ../../../../scripts/schemas/component.yaml.schema.json
3
+ name: UIThemeProvider
4
+ tag: theme-provider
5
+ status: experimental
6
+ component: ThemeProvider
7
+ category: layout
8
+ version: 1
9
+ description: |
10
+ Foundation-providing wrapper — adopts the AdiaUI foundation (design tokens +
11
+ resets + page-frame + every primitive's CSS) into the document from anywhere
12
+ in the DOM, so a surface renders fully-styled WITHOUT a hand-wired
13
+ <link rel="stylesheet"> in <head>. Layout-transparent (display: contents): the
14
+ element owns no box; children lay out as if it weren't there.
15
+
16
+ Mechanism: it imports the constructable-stylesheet twin of web-components.min.css
17
+ (byte-identical to the CDN bundle, emitted from the same build buffer) and
18
+ adopts it once into document.adoptedStyleSheets, deduped — adoption fires at
19
+ module load, before paint. Coexists with the render-blocking <link> path; both
20
+ deliver the same bytes. Use a <link> (-> the CDN web-components.min.css) for
21
+ multi-page / top-level surfaces (cacheable across navigations, zero flash); use
22
+ <theme-provider> for SPA roots, embedded apps, and dynamic mounts where you do
23
+ not control <head> (e.g. <embed-shell>, an A2UI surface, a micro-frontend).
24
+
25
+ Theming: the base foundation is OS light/dark via light-dark() tokens. Two opt-in
26
+ attributes adopt their layer on demand — theme="ocean|forest|slate|…" applies a
27
+ named preset (adopts the themes layer; matches the [theme] hook) and
28
+ scale="verse|prose" sets the compact / long-form typographic register (adopts the
29
+ matching register layer; maps onto the [verse]/[prose] attribute). Each layer is
30
+ fetched only when its attribute is set, so a bare provider stays lean.
31
+ Opt-in infra: NOT in the all-in-one @adia-ai/web-components barrel (it carries
32
+ the whole foundation); import @adia-ai/web-components/components/theme-provider
33
+ explicitly. Distinct from <frame-ui> (a layout skeleton, owns no CSS delivery)
34
+ and the page shells (chrome over the same foundation).
35
+ props:
36
+ theme:
37
+ description: 'Named theme preset for the wrapped subtree (default, ocean, forest, sunset, lavender, rose, slate, midnight). Adopts the themes layer on demand + matches the [theme="…"] hook.'
38
+ type: string
39
+ default: ""
40
+ reflect: true
41
+ scale:
42
+ description: 'Typographic / density register for the subtree — "verse" (compact) or "prose" (long-form). Adopts the matching register layer on demand; maps onto the [verse]/[prose] attribute (additive).'
43
+ type: string
44
+ default: ""
45
+ reflect: true
46
+ events: {}
47
+ slots: {}
48
+ states:
49
+ - name: idle
50
+ description: Default — foundation adopted into the document; children rendered.
51
+ traits: []
52
+ tokens: {}
53
+ a2ui:
54
+ rules:
55
+ - rule: 'Wrap a client-mounted surface root (SPA shell, embedded app, dynamic mount) in <theme-provider> so it self-provides the AdiaUI foundation — no <head> stylesheet link required.'
56
+ reason: 'Adopts the foundation bundle into the document from anywhere in the tree (document.adoptedStyleSheets).'
57
+ - rule: 'For multi-page / top-level pages, prefer a render-blocking <link rel="stylesheet" href=".../web-components.min.css"> in <head> instead — cacheable across navigations, styled on the first frame. <theme-provider> and the link deliver byte-identical CSS, so they coexist.'
58
+ reason: 'Link for multi-page (no flash); provider for SPA/embedded (no head access).'
59
+ - rule: 'Theme the wrapped subtree with theme="ocean" (a named preset) and/or scale="verse|prose" (compact / long-form register) — the provider adopts the matching opt-in layer on demand. The base foundation is OS light/dark automatically. Keep <theme-provider> at/near the mount root — display:contents means an ancestor "> " child selector will not reach its children.'
60
+ reason: 'theme/scale each fetch + adopt their layer (themes.css / verse.css / prose.css) on demand; display:contents preserves custom-property inheritance but not child-combinator reach (Light DOM, ADR-0033).'
61
+ anti_patterns: []
62
+ examples:
63
+ - name: spa-root
64
+ description: A client-mounted app root that self-provides the foundation (no head link).
65
+ a2ui: >-
66
+ [
67
+ { "id": "root", "component": "ThemeProvider", "children": ["panel"] },
68
+ { "id": "panel", "component": "Frame", "children": ["body", "actions"] },
69
+ { "id": "body", "component": "Section", "children": ["copy"] },
70
+ { "id": "copy", "component": "Text", "variant": "body", "textContent": "Fully styled — no <head> stylesheet link." },
71
+ { "id": "actions", "component": "Footer", "children": ["go"] },
72
+ { "id": "go", "component": "Button", "text": "Continue", "variant": "primary" }
73
+ ]
74
+ keywords:
75
+ - style
76
+ - provider
77
+ - foundation
78
+ - tokens
79
+ - reset
80
+ - adopt
81
+ - stylesheet
82
+ - shell
83
+ - embed
84
+ - spa
85
+ synonyms:
86
+ provider:
87
+ - provider
88
+ - root
89
+ - host
90
+ foundation:
91
+ - foundation
92
+ - tokens
93
+ - styles
94
+ related:
95
+ - Frame
96
+ - Card