@cscfi/csc-ui 4.0.0-alpha.18 → 4.0.0-alpha.19

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.
@@ -134,6 +134,12 @@
134
134
  * Semantic tokens. Role-named properties that resolve to a
135
135
  * different palette step per theme mode; components author against the
136
136
  * per-role color utilities the @theme inline map in tailwind.css exposes.
137
+ *
138
+ * The mode selectors are not anchored to :root — any element carrying
139
+ * data-theme="light" or "dark" opens a mode scope for its subtree, and the
140
+ * nearest enclosing scope wins (ADR-0053). Block order is load-bearing:
141
+ * :root and [data-theme='dark'] have equal specificity, so dark must stay
142
+ * last. See utils/createSemanticTheme.cjs for the full cascade rationale.
137
143
  */
138
144
 
139
145
  /* Mode-invariant roles (identical in light and dark). */
@@ -145,8 +151,10 @@
145
151
  --c-scrim: var(--c-black);
146
152
  }
147
153
 
154
+ /* Light is the default; any element may open a light mode scope. */
148
155
  :root,
149
- :root[data-theme='light'] {
156
+ [data-theme='light'] {
157
+ color-scheme: light;
150
158
  --c-surface: var(--c-white);
151
159
  --c-surface-raised: var(--c-white);
152
160
  --c-surface-overlay: var(--c-white);
@@ -241,8 +249,9 @@
241
249
  --c-logo-magenta: oklch(0.4006 0.1660 351.9773);
242
250
  }
243
251
 
244
- /* Explicit dark mode (wins over the OS preference). */
245
- :root[data-theme='dark'] {
252
+ /* Explicit dark, at the root or in any mode scope (wins over the OS preference). */
253
+ [data-theme='dark'] {
254
+ color-scheme: dark;
246
255
  --c-surface: var(--c-slate-800);
247
256
  --c-surface-raised: var(--c-slate-800);
248
257
  --c-surface-overlay: var(--c-slate-700);
@@ -337,9 +346,10 @@
337
346
  --c-logo-magenta: var(--c-white);
338
347
  }
339
348
 
340
- /* OS dark preference, only when no explicit data-theme is set. */
349
+ /* OS dark preference, only when the root pins no mode. */
341
350
  @media (prefers-color-scheme: dark) {
342
- :root:not([data-theme]) {
351
+ :root:not([data-theme='light']):not([data-theme='dark']) {
352
+ color-scheme: dark;
343
353
  --c-surface: var(--c-slate-800);
344
354
  --c-surface-raised: var(--c-slate-800);
345
355
  --c-surface-overlay: var(--c-slate-700);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
3
3
  "name": "@cscfi/csc-ui",
4
- "version": "4.0.0-alpha.18",
4
+ "version": "4.0.0-alpha.19",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -29,7 +29,7 @@ export type { AppDefaults, DefaultableTag } from './shared/appDefaults';
29
29
  export { chartAnatomy, chartAnatomyHex, chartSlots, chartSlotsHex, } from './theme/chart-data';
30
30
  export type { ChartAnatomy, ChartSlots } from './theme/chart-data';
31
31
  export { DEFAULT_SEEDS, FAMILIES } from './theme/ramp.js';
32
- export { themeMode } from './theme/themeMode';
32
+ export { observeThemeMode, themeMode } from './theme/themeMode';
33
33
  export type { ThemeMode } from './theme/themeMode';
34
34
  export type { CFieldSize, CPlacement, CSelectItem, CToastMessage, CToastType, } from './types';
35
35
  export { h } from 'vue';
@@ -7,7 +7,8 @@
7
7
  * The chart tokens (ADR-0030) as importable data (ADR-0040): the twelve
8
8
  * series slots and the chart anatomy roles per theme mode. Values are the
9
9
  * frozen, validated set — they never follow a consumer's `--c-chart-*`
10
- * overrides. Pair with `themeMode()` to pick the mode on screen.
10
+ * overrides. Pair with `themeMode(el)` to pick the mode in effect where the
11
+ * chart sits, or `observeThemeMode()` to follow it.
11
12
  */
12
13
  import type { ThemeMode } from './themeMode';
13
14
  /** The twelve series slots in slot order (`chart-1` … `chart-12`). */
@@ -1,13 +1,36 @@
1
1
  /** The light-or-dark state that selects which palette the semantic tokens resolve to. */
2
2
  export type ThemeMode = 'dark' | 'light';
3
3
  /**
4
- * Resolve the theme mode currently in effect, mirroring the cascade in
5
- * `tokens.css`: an explicit `data-theme` on the root wins (any value other
6
- * than `dark` is light — `:root:not([data-theme])` is what enables the OS
7
- * fallback); otherwise the OS preference; light where neither is available
8
- * (server rendering, no `matchMedia`). Re-run on a `data-theme` mutation and
9
- * on the `(prefers-color-scheme: dark)` media query's `change` event.
10
- *
11
- * @param root the element carrying `data-theme` — defaults to `<html>`
4
+ * Resolve the theme mode in effect for an element, mirroring the cascade in
5
+ * `tokens.css`: the nearest enclosing **mode scope** wins (an ancestor-or-self
6
+ * carrying `data-theme="light"` or `"dark"`, ADR-0053); otherwise the OS
7
+ * preference; light where neither is available (server rendering, no
8
+ * `matchMedia`). Any other `data-theme` value is inert, exactly as it is in CSS.
9
+ *
10
+ * Pass the element whose mode you need — a chart inside a dark panel on an
11
+ * otherwise light page resolves `dark` only if you ask about the chart.
12
+ * `observeThemeMode()` keeps that answer current.
13
+ *
14
+ * @param root the element to resolve for — defaults to `<html>`
12
15
  */
13
16
  export declare function themeMode(root?: Element | null): ThemeMode;
17
+ /**
18
+ * Watch the theme mode in effect for an element and report every change.
19
+ *
20
+ * Calls `onChange` once synchronously with the current mode, then again
21
+ * whenever it actually changes — so wiring a chart up is the one call, with no
22
+ * separate initial render. Covers both paths that can change the answer: a
23
+ * `data-theme` attribute mutating anywhere in the document (the element's own
24
+ * **mode scope** or any ancestor's, which is why a `documentElement`-only
25
+ * observer is not enough), and the OS preference flipping while no scope pins
26
+ * a mode. Re-parenting `target` is not observed; re-subscribe if you move it.
27
+ *
28
+ * ```ts
29
+ * const stop = observeThemeMode(chartEl, (mode) => {
30
+ * chart.setOption({ color: chartSlotsHex[mode] });
31
+ * });
32
+ * ```
33
+ *
34
+ * @returns a disposer that detaches both listeners
35
+ */
36
+ export declare function observeThemeMode(target: Element, onChange: (mode: ThemeMode) => void): () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cscfi/csc-ui",
3
- "version": "4.0.0-alpha.18",
3
+ "version": "4.0.0-alpha.19",
4
4
  "description": "Vue 3-based replacement for @cscfi/csc-ui — same custom element tag names, Vue v-model contract.",
5
5
  "type": "module",
6
6
  "main": "./dist/csc-ui.js",