@ttoss/fsl-theme 1.1.13 → 1.1.15
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.
- package/dist/Types-BiBa17RL.d.cts +1427 -0
- package/dist/Types-BiBa17RL.d.mts +1427 -0
- package/dist/baseBundle-DxvXyhGa.mjs +17 -0
- package/dist/baseBundle-iEFf5nqT.cjs +22 -0
- package/dist/{esm/chunk-SE5Z52RE.js → createTheme-BLNYztZU.mjs} +76 -172
- package/dist/createTheme-Cv6RP9D6.cjs +1825 -0
- package/dist/css.cjs +48 -0
- package/dist/{css.d.ts → css.d.cts} +67 -63
- package/dist/css.d.mts +168 -0
- package/dist/css.mjs +42 -0
- package/dist/dataviz/index.cjs +45 -0
- package/dist/dataviz/{index.d.ts → index.d.cts} +9 -5
- package/dist/dataviz/index.d.mts +66 -0
- package/dist/dataviz/index.mjs +39 -0
- package/dist/dtcg.cjs +115 -0
- package/dist/{dtcg.d.ts → dtcg.d.cts} +9 -7
- package/dist/dtcg.d.mts +51 -0
- package/dist/dtcg.mjs +112 -0
- package/dist/helpers-4p4-QVt_.cjs +258 -0
- package/dist/helpers-CaswNJMy.mjs +211 -0
- package/dist/{index.d.ts → index-CsIjfw86.d.cts} +42 -34
- package/dist/index-nJrjI0BA.d.mts +94 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +7 -0
- package/dist/{react.d.ts → react-CGa6FlNL.d.cts} +130 -106
- package/dist/react-DnKxR2gK.d.mts +370 -0
- package/dist/react-EUwpdvY7.cjs +481 -0
- package/dist/react.cjs +12 -0
- package/dist/react.d.cts +4 -0
- package/dist/react.d.mts +4 -0
- package/dist/react.mjs +412 -0
- package/dist/runtime-entry.cjs +9 -0
- package/dist/runtime-entry.d.cts +3 -0
- package/dist/runtime-entry.d.mts +3 -0
- package/dist/runtime-entry.mjs +3 -0
- package/dist/{runtime-entry.d.ts → ssrScript-BVysxDws.d.cts} +26 -23
- package/dist/ssrScript-BVysxDws.d.mts +98 -0
- package/dist/ssrScript-CRfrN8Pm.cjs +202 -0
- package/dist/ssrScript-D3kGPQpi.mjs +179 -0
- package/dist/themes/bruttal.cjs +75 -0
- package/dist/themes/bruttal.d.cts +3 -0
- package/dist/themes/bruttal.d.mts +3 -0
- package/dist/themes/bruttal.mjs +72 -0
- package/dist/themes/corporate.cjs +34 -0
- package/dist/themes/corporate.d.cts +3 -0
- package/dist/themes/corporate.d.mts +3 -0
- package/dist/{esm/chunk-TPMN75JM.js → themes/corporate.mjs} +7 -5
- package/dist/themes/oca.cjs +34 -0
- package/dist/themes/oca.d.cts +3 -0
- package/dist/themes/oca.d.mts +3 -0
- package/dist/{esm/chunk-DU4QDQUC.js → themes/oca.mjs} +7 -5
- package/dist/themes/ventures.cjs +34 -0
- package/dist/themes/ventures.d.cts +3 -0
- package/dist/themes/ventures.d.mts +3 -0
- package/dist/{esm/chunk-BXKVVQEP.js → themes/ventures.mjs} +7 -5
- package/dist/toCssVars-CYZCe-on.mjs +286 -0
- package/dist/toCssVars-DudHKvt2.cjs +297 -0
- package/dist/{esm/chunk-4Q4P3JBB.js → tokenRegistry-DjgSN3oU.mjs} +23 -20
- package/dist/tokenRegistry-OhaJ9sPJ.cjs +199 -0
- package/dist/vars.cjs +127 -0
- package/dist/{vars.d.ts → vars.d.cts} +8 -7
- package/dist/vars.d.mts +128 -0
- package/dist/vars.mjs +123 -0
- package/dist/withDataviz-B4pVsOwV.cjs +192 -0
- package/dist/{esm/chunk-FBVUI2PK.js → withDataviz-DY5s7R51.mjs} +40 -12
- package/package.json +20 -20
- package/dist/Types-6tR0_2Ss.d.ts +0 -1452
- package/dist/esm/chunk-5PWPAQMC.js +0 -9
- package/dist/esm/chunk-HRNXVRS3.js +0 -54
- package/dist/esm/chunk-IJGA42O6.js +0 -141
- package/dist/esm/chunk-PQPQNZ73.js +0 -262
- package/dist/esm/chunk-UMRQ4OTX.js +0 -11
- package/dist/esm/chunk-VL6EGE6Z.js +0 -222
- package/dist/esm/chunk-WVQSTQD5.js +0 -192
- package/dist/esm/css.js +0 -6
- package/dist/esm/dataviz/index.js +0 -19
- package/dist/esm/dtcg.js +0 -65
- package/dist/esm/index.js +0 -10
- package/dist/esm/react.js +0 -8
- package/dist/esm/runtime-entry.js +0 -4
- package/dist/esm/themes/bruttal.js +0 -6
- package/dist/esm/themes/corporate.js +0 -6
- package/dist/esm/themes/oca.js +0 -6
- package/dist/esm/themes/ventures.js +0 -6
- package/dist/esm/vars.js +0 -28
- package/dist/themes/bruttal.d.ts +0 -5
- package/dist/themes/corporate.d.ts +0 -5
- package/dist/themes/oca.d.ts +0 -5
- package/dist/themes/ventures.d.ts +0 -5
|
@@ -1,84 +1,85 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { ThemeMode, ResolvedMode, ThemeScriptConfig } from './runtime-entry.js';
|
|
4
|
-
import { a as ThemeBundle, S as SemanticTokens } from './Types-6tR0_2Ss.js';
|
|
5
1
|
|
|
2
|
+
import { n as SemanticTokens, r as ThemeBundle } from "./Types-BiBa17RL.cjs";
|
|
3
|
+
import { a as ResolvedMode, o as ThemeMode, t as ThemeScriptConfig } from "./ssrScript-BVysxDws.cjs";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/react.d.ts
|
|
6
7
|
/**
|
|
7
8
|
* Props for the `ThemeProvider` component.
|
|
8
9
|
*/
|
|
9
10
|
interface ThemeProviderProps {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
11
|
+
/** Mode to use when no persisted value is found. Only read on initial mount. @default 'system' */
|
|
12
|
+
defaultMode?: ThemeMode;
|
|
13
|
+
/** localStorage key for persistence. Only read on initial mount. @default 'tt-theme' */
|
|
14
|
+
storageKey?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Theme identifier written to `data-tt-theme`. Reactive — changing this
|
|
17
|
+
* prop recreates the runtime and rewrites the attribute so the browser
|
|
18
|
+
* matches the scoped CSS (e.g. `[data-tt-theme="<id>"]`). Provide only
|
|
19
|
+
* for MFE / multi-theme CSS scoping (Storybook toolbar, runtime theme swap).
|
|
20
|
+
*/
|
|
21
|
+
themeId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The theme bundle for the app — the canonical 1-theme / 2-mode model.
|
|
24
|
+
*
|
|
25
|
+
* Passing `theme` enables `useTokens()` and `useResolvedTokens()` for all
|
|
26
|
+
* descendants, and automatically injects the CSS Custom Properties `<style>`
|
|
27
|
+
* tag into the document head (React 19 hoisting).
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* import { createTheme } from '@ttoss/fsl-theme';
|
|
32
|
+
* import { ThemeProvider } from '@ttoss/fsl-theme/react';
|
|
33
|
+
*
|
|
34
|
+
* const myTheme = createTheme();
|
|
35
|
+
*
|
|
36
|
+
* <ThemeProvider theme={myTheme}>
|
|
37
|
+
* <App />
|
|
38
|
+
* </ThemeProvider>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
theme?: ThemeBundle;
|
|
42
|
+
/**
|
|
43
|
+
* Called after each mode transition. Does **not** fire on initial mount —
|
|
44
|
+
* only on subsequent user-triggered or system-triggered mode changes.
|
|
45
|
+
*
|
|
46
|
+
* Receives both `mode` (user intent: `'light' | 'dark' | 'system'`) and
|
|
47
|
+
* `resolvedMode` (actual: `'light' | 'dark'`), covering all integration
|
|
48
|
+
* needs in one callback.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```tsx
|
|
52
|
+
* <ThemeProvider
|
|
53
|
+
* theme={myTheme}
|
|
54
|
+
* onModeChange={(mode, resolvedMode) => {
|
|
55
|
+
* analytics.track('modeChanged', { mode, resolvedMode });
|
|
56
|
+
* }}
|
|
57
|
+
* >
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
onModeChange?: (mode: ThemeMode, resolvedMode: ResolvedMode) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Root element to anchor `data-tt-theme` / `data-tt-mode` attributes.
|
|
63
|
+
* Defaults to `document.documentElement`. Pass a container element for
|
|
64
|
+
* Storybook isolation or micro-frontend use cases.
|
|
65
|
+
*
|
|
66
|
+
* Because the element is often `null` on the first render when passed via
|
|
67
|
+
* `ref.current`, `root` is reactive: the runtime is recreated once when
|
|
68
|
+
* it transitions from `undefined` to the actual element.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```tsx
|
|
72
|
+
* // Storybook decorator — isolates each story from <html>
|
|
73
|
+
* const rootRef = React.useRef<HTMLDivElement>(null);
|
|
74
|
+
* <div ref={rootRef}>
|
|
75
|
+
* <ThemeProvider theme={myTheme} root={rootRef.current ?? undefined}>
|
|
76
|
+
* <Story />
|
|
77
|
+
* </ThemeProvider>
|
|
78
|
+
* </div>
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
root?: HTMLElement;
|
|
82
|
+
children: React.ReactNode;
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
84
85
|
* React provider that manages theme switching via `createThemeRuntime`.
|
|
@@ -102,7 +103,15 @@ interface ThemeProviderProps {
|
|
|
102
103
|
* );
|
|
103
104
|
* ```
|
|
104
105
|
*/
|
|
105
|
-
declare const ThemeProvider: ({
|
|
106
|
+
declare const ThemeProvider: ({
|
|
107
|
+
defaultMode,
|
|
108
|
+
storageKey,
|
|
109
|
+
theme,
|
|
110
|
+
themeId,
|
|
111
|
+
onModeChange,
|
|
112
|
+
root,
|
|
113
|
+
children
|
|
114
|
+
}: ThemeProviderProps) => any;
|
|
106
115
|
/**
|
|
107
116
|
* Access mode state and the mode setter — without subscribing to theme changes.
|
|
108
117
|
*
|
|
@@ -127,9 +136,9 @@ declare const ThemeProvider: ({ defaultMode, storageKey, theme, themeId, onModeC
|
|
|
127
136
|
* ```
|
|
128
137
|
*/
|
|
129
138
|
interface UseColorModeResult {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
139
|
+
mode: ThemeMode;
|
|
140
|
+
resolvedMode: ResolvedMode;
|
|
141
|
+
setMode: (mode: ThemeMode) => void;
|
|
133
142
|
}
|
|
134
143
|
declare const useColorMode: () => UseColorModeResult;
|
|
135
144
|
/**
|
|
@@ -214,8 +223,8 @@ declare const useResolvedTokens: () => Record<string, string | number>;
|
|
|
214
223
|
* Props for the `ThemeScript` component.
|
|
215
224
|
*/
|
|
216
225
|
interface ThemeScriptProps extends ThemeScriptConfig {
|
|
217
|
-
|
|
218
|
-
|
|
226
|
+
/** CSP nonce for the inline script. */
|
|
227
|
+
nonce?: string;
|
|
219
228
|
}
|
|
220
229
|
/**
|
|
221
230
|
* Renders an inline `<script>` that prevents theme flash on SSR/SSG.
|
|
@@ -239,26 +248,31 @@ interface ThemeScriptProps extends ThemeScriptConfig {
|
|
|
239
248
|
* }
|
|
240
249
|
* ```
|
|
241
250
|
*/
|
|
242
|
-
declare const ThemeScript: ({
|
|
251
|
+
declare const ThemeScript: ({
|
|
252
|
+
defaultTheme,
|
|
253
|
+
defaultMode,
|
|
254
|
+
storageKey,
|
|
255
|
+
nonce
|
|
256
|
+
}?: ThemeScriptProps) => any;
|
|
243
257
|
/**
|
|
244
258
|
* Props for the `ThemeStyles` component.
|
|
245
259
|
*/
|
|
246
260
|
interface ThemeStylesProps {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
261
|
+
/** The theme bundle to generate CSS for. */
|
|
262
|
+
theme: ThemeBundle;
|
|
263
|
+
/**
|
|
264
|
+
* Theme identifier for CSS scoping (`[data-tt-theme="<themeId>"]`).
|
|
265
|
+
*
|
|
266
|
+
* **Omit in the canonical 1-theme model** — CSS targets `:root` and the
|
|
267
|
+
* alternate mode selector becomes `:root[data-tt-mode="dark"]`. No theme
|
|
268
|
+
* name repetition required.
|
|
269
|
+
*
|
|
270
|
+
* Pass `themeId` only for multi-theme scenarios (Storybook, micro-frontends,
|
|
271
|
+
* apps with visual theme switching).
|
|
272
|
+
*/
|
|
273
|
+
themeId?: string;
|
|
274
|
+
/** CSP nonce for the inline style tag. */
|
|
275
|
+
nonce?: string;
|
|
262
276
|
}
|
|
263
277
|
/**
|
|
264
278
|
* Renders an inline `<style>` tag with all CSS Custom Properties for a theme
|
|
@@ -302,15 +316,19 @@ interface ThemeStylesProps {
|
|
|
302
316
|
* <ThemeStyles theme={brandB} themeId="brand-b" />
|
|
303
317
|
* ```
|
|
304
318
|
*/
|
|
305
|
-
declare const ThemeStyles: ({
|
|
319
|
+
declare const ThemeStyles: ({
|
|
320
|
+
theme,
|
|
321
|
+
themeId,
|
|
322
|
+
nonce
|
|
323
|
+
}: ThemeStylesProps) => any;
|
|
306
324
|
/**
|
|
307
325
|
* Props for the `ThemeHead` component.
|
|
308
326
|
*/
|
|
309
327
|
interface ThemeHeadProps extends ThemeStylesProps {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
328
|
+
/** Mode to use when no persisted value is found. @default 'system' */
|
|
329
|
+
defaultMode?: ThemeMode;
|
|
330
|
+
/** localStorage key for persistence. Must match `ThemeProvider`'s `storageKey`. @default 'tt-theme' */
|
|
331
|
+
storageKey?: string;
|
|
314
332
|
}
|
|
315
333
|
/**
|
|
316
334
|
* Convenience component that renders both `<ThemeScript>` and `<ThemeStyles>`
|
|
@@ -341,6 +359,12 @@ interface ThemeHeadProps extends ThemeStylesProps {
|
|
|
341
359
|
* }
|
|
342
360
|
* ```
|
|
343
361
|
*/
|
|
344
|
-
declare const ThemeHead: ({
|
|
345
|
-
|
|
346
|
-
|
|
362
|
+
declare const ThemeHead: ({
|
|
363
|
+
theme,
|
|
364
|
+
themeId,
|
|
365
|
+
nonce,
|
|
366
|
+
defaultMode,
|
|
367
|
+
storageKey
|
|
368
|
+
}: ThemeHeadProps) => any;
|
|
369
|
+
//#endregion
|
|
370
|
+
export { ThemeScript as a, ThemeStylesProps as c, useResolvedTokens as d, useTokens as f, ThemeProviderProps as i, UseColorModeResult as l, ThemeHeadProps as n, ThemeScriptProps as o, ThemeProvider as r, ThemeStyles as s, ThemeHead as t, useColorMode as u };
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
|
|
2
|
+
import { n as SemanticTokens, r as ThemeBundle } from "./Types-BiBa17RL.mjs";
|
|
3
|
+
import { a as ResolvedMode, o as ThemeMode, t as ThemeScriptConfig } from "./ssrScript-BVysxDws.mjs";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/react.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Props for the `ThemeProvider` component.
|
|
9
|
+
*/
|
|
10
|
+
interface ThemeProviderProps {
|
|
11
|
+
/** Mode to use when no persisted value is found. Only read on initial mount. @default 'system' */
|
|
12
|
+
defaultMode?: ThemeMode;
|
|
13
|
+
/** localStorage key for persistence. Only read on initial mount. @default 'tt-theme' */
|
|
14
|
+
storageKey?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Theme identifier written to `data-tt-theme`. Reactive — changing this
|
|
17
|
+
* prop recreates the runtime and rewrites the attribute so the browser
|
|
18
|
+
* matches the scoped CSS (e.g. `[data-tt-theme="<id>"]`). Provide only
|
|
19
|
+
* for MFE / multi-theme CSS scoping (Storybook toolbar, runtime theme swap).
|
|
20
|
+
*/
|
|
21
|
+
themeId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The theme bundle for the app — the canonical 1-theme / 2-mode model.
|
|
24
|
+
*
|
|
25
|
+
* Passing `theme` enables `useTokens()` and `useResolvedTokens()` for all
|
|
26
|
+
* descendants, and automatically injects the CSS Custom Properties `<style>`
|
|
27
|
+
* tag into the document head (React 19 hoisting).
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* import { createTheme } from '@ttoss/fsl-theme';
|
|
32
|
+
* import { ThemeProvider } from '@ttoss/fsl-theme/react';
|
|
33
|
+
*
|
|
34
|
+
* const myTheme = createTheme();
|
|
35
|
+
*
|
|
36
|
+
* <ThemeProvider theme={myTheme}>
|
|
37
|
+
* <App />
|
|
38
|
+
* </ThemeProvider>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
theme?: ThemeBundle;
|
|
42
|
+
/**
|
|
43
|
+
* Called after each mode transition. Does **not** fire on initial mount —
|
|
44
|
+
* only on subsequent user-triggered or system-triggered mode changes.
|
|
45
|
+
*
|
|
46
|
+
* Receives both `mode` (user intent: `'light' | 'dark' | 'system'`) and
|
|
47
|
+
* `resolvedMode` (actual: `'light' | 'dark'`), covering all integration
|
|
48
|
+
* needs in one callback.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```tsx
|
|
52
|
+
* <ThemeProvider
|
|
53
|
+
* theme={myTheme}
|
|
54
|
+
* onModeChange={(mode, resolvedMode) => {
|
|
55
|
+
* analytics.track('modeChanged', { mode, resolvedMode });
|
|
56
|
+
* }}
|
|
57
|
+
* >
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
onModeChange?: (mode: ThemeMode, resolvedMode: ResolvedMode) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Root element to anchor `data-tt-theme` / `data-tt-mode` attributes.
|
|
63
|
+
* Defaults to `document.documentElement`. Pass a container element for
|
|
64
|
+
* Storybook isolation or micro-frontend use cases.
|
|
65
|
+
*
|
|
66
|
+
* Because the element is often `null` on the first render when passed via
|
|
67
|
+
* `ref.current`, `root` is reactive: the runtime is recreated once when
|
|
68
|
+
* it transitions from `undefined` to the actual element.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```tsx
|
|
72
|
+
* // Storybook decorator — isolates each story from <html>
|
|
73
|
+
* const rootRef = React.useRef<HTMLDivElement>(null);
|
|
74
|
+
* <div ref={rootRef}>
|
|
75
|
+
* <ThemeProvider theme={myTheme} root={rootRef.current ?? undefined}>
|
|
76
|
+
* <Story />
|
|
77
|
+
* </ThemeProvider>
|
|
78
|
+
* </div>
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
root?: HTMLElement;
|
|
82
|
+
children: React.ReactNode;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* React provider that manages theme switching via `createThemeRuntime`.
|
|
86
|
+
*
|
|
87
|
+
* Applies `data-tt-theme` and `data-tt-mode` on `<html>` (or `root`),
|
|
88
|
+
* persists to localStorage, and listens to system color scheme changes.
|
|
89
|
+
* When `theme` is provided, automatically injects CSS Custom Properties into
|
|
90
|
+
* the document `<head>` via React 19 style hoisting.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```tsx
|
|
94
|
+
* import { ThemeProvider } from '@ttoss/fsl-theme/react';
|
|
95
|
+
* import { createTheme } from '@ttoss/fsl-theme';
|
|
96
|
+
*
|
|
97
|
+
* const myTheme = createTheme();
|
|
98
|
+
*
|
|
99
|
+
* export const App = () => (
|
|
100
|
+
* <ThemeProvider theme={myTheme}>
|
|
101
|
+
* <YourApp />
|
|
102
|
+
* </ThemeProvider>
|
|
103
|
+
* );
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare const ThemeProvider: ({
|
|
107
|
+
defaultMode,
|
|
108
|
+
storageKey,
|
|
109
|
+
theme,
|
|
110
|
+
themeId,
|
|
111
|
+
onModeChange,
|
|
112
|
+
root,
|
|
113
|
+
children
|
|
114
|
+
}: ThemeProviderProps) => any;
|
|
115
|
+
/**
|
|
116
|
+
* Access mode state and the mode setter — without subscribing to theme changes.
|
|
117
|
+
*
|
|
118
|
+
* Consumers of `useColorMode()` only re-render on mode transitions, never on
|
|
119
|
+
* `themeId` changes. Use this for components that only need dark/light toggling
|
|
120
|
+
* (e.g. a sun/moon icon button) to avoid unnecessary re-renders.
|
|
121
|
+
*
|
|
122
|
+
* Must be used within a `<ThemeProvider>`.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```tsx
|
|
126
|
+
* import { useColorMode } from '@ttoss/fsl-theme/react';
|
|
127
|
+
*
|
|
128
|
+
* const DarkModeToggle = () => {
|
|
129
|
+
* const { resolvedMode, setMode } = useColorMode();
|
|
130
|
+
* return (
|
|
131
|
+
* <button onClick={() => setMode(resolvedMode === 'dark' ? 'light' : 'dark')}>
|
|
132
|
+
* {resolvedMode === 'dark' ? '☀️' : '🌙'}
|
|
133
|
+
* </button>
|
|
134
|
+
* );
|
|
135
|
+
* };
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
interface UseColorModeResult {
|
|
139
|
+
mode: ThemeMode;
|
|
140
|
+
resolvedMode: ResolvedMode;
|
|
141
|
+
setMode: (mode: ThemeMode) => void;
|
|
142
|
+
}
|
|
143
|
+
declare const useColorMode: () => UseColorModeResult;
|
|
144
|
+
/**
|
|
145
|
+
* Access the current theme's **semantic tokens only** — the structural tree
|
|
146
|
+
* with **unresolved** `TokenRef` values (e.g. `'{core.colors.brand.500}'`).
|
|
147
|
+
*
|
|
148
|
+
* ### Primary use cases
|
|
149
|
+
* - Introspection and devtools
|
|
150
|
+
* - Token path comparison (e.g. checking which tokens differ between themes)
|
|
151
|
+
* - Passing to `createTheme` calls
|
|
152
|
+
*
|
|
153
|
+
* ### ✗ Do not use for styling
|
|
154
|
+
* `TokenRef` values are reference strings, not CSS values. Using them in
|
|
155
|
+
* inline styles produces silently broken rendering:
|
|
156
|
+
*
|
|
157
|
+
* ```tsx
|
|
158
|
+
* // ✗ WRONG — tokens.colors.brand.main is '{core.colors.brand.main}', not '#FF0000'
|
|
159
|
+
* <div style={{ color: tokens.colors.brand.main }} />
|
|
160
|
+
*
|
|
161
|
+
* // ✓ CSS consumers — use vars:
|
|
162
|
+
* <div style={{ color: 'var(--tt-color-brand-main)' }} />
|
|
163
|
+
*
|
|
164
|
+
* // ✓ Non-CSS consumers (React Native, canvas) — use useResolvedTokens():
|
|
165
|
+
* const resolved = useResolvedTokens();
|
|
166
|
+
* <View style={{ backgroundColor: resolved['semantic.colors.action.primary.background.default'] }} />
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* Requires `<ThemeProvider theme={...}>`.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```tsx
|
|
173
|
+
* import { useTokens } from '@ttoss/fsl-theme/react';
|
|
174
|
+
*
|
|
175
|
+
* const Button = () => {
|
|
176
|
+
* const tokens = useTokens(); // introspection only
|
|
177
|
+
* // tokens.colors.action.primary.background.default → '{core.colors.brand.500}'
|
|
178
|
+
* return <button style={{ background: 'var(--tt-action-primary-background-default)' }} />;
|
|
179
|
+
* };
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
declare const useTokens: () => SemanticTokens;
|
|
183
|
+
/**
|
|
184
|
+
* Access fully resolved token values as a flat `Record<string, string | number>`.
|
|
185
|
+
*
|
|
186
|
+
* All `{ref}` indirections are resolved to their final raw values — hex colors,
|
|
187
|
+
* px sizes, unitless numbers, etc. Keys use `semantic.*` dot-path notation.
|
|
188
|
+
*
|
|
189
|
+
* ### When to use
|
|
190
|
+
* Use in non-CSS environments where CSS custom properties (`var()`) are not
|
|
191
|
+
* available: React Native, canvas renderers, PDF generation, test assertions.
|
|
192
|
+
*
|
|
193
|
+
* ### ✗ Do not use for CSS rendering
|
|
194
|
+
* CSS consumers should use `vars.*` instead for zero-JS rendering:
|
|
195
|
+
*
|
|
196
|
+
* ```tsx
|
|
197
|
+
* // ✓ CSS (browser)
|
|
198
|
+
* <div style={{ color: 'var(--tt-color-informational-primary-default)' }} />
|
|
199
|
+
*
|
|
200
|
+
* // ✓ Non-CSS (React Native, canvas)
|
|
201
|
+
* const resolved = useResolvedTokens();
|
|
202
|
+
* <View style={{ backgroundColor: resolved['semantic.colors.action.primary.background.default'] }} />
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* Requires `<ThemeProvider theme={...}>`.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```tsx
|
|
209
|
+
* import { useResolvedTokens } from '@ttoss/fsl-theme/react';
|
|
210
|
+
*
|
|
211
|
+
* const ReactNativeButton = () => {
|
|
212
|
+
* const resolved = useResolvedTokens();
|
|
213
|
+
* return (
|
|
214
|
+
* <View style={{ backgroundColor: resolved['semantic.colors.action.primary.background.default'] }}>
|
|
215
|
+
* <Text>Click</Text>
|
|
216
|
+
* </View>
|
|
217
|
+
* );
|
|
218
|
+
* };
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
declare const useResolvedTokens: () => Record<string, string | number>;
|
|
222
|
+
/**
|
|
223
|
+
* Props for the `ThemeScript` component.
|
|
224
|
+
*/
|
|
225
|
+
interface ThemeScriptProps extends ThemeScriptConfig {
|
|
226
|
+
/** CSP nonce for the inline script. */
|
|
227
|
+
nonce?: string;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Renders an inline `<script>` that prevents theme flash on SSR/SSG.
|
|
231
|
+
*
|
|
232
|
+
* Place in the `<head>` before stylesheets.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```tsx
|
|
236
|
+
* // Next.js app/layout.tsx
|
|
237
|
+
* import { ThemeScript } from '@ttoss/fsl-theme/react';
|
|
238
|
+
*
|
|
239
|
+
* export default function RootLayout({ children }) {
|
|
240
|
+
* return (
|
|
241
|
+
* <html lang="en">
|
|
242
|
+
* <head>
|
|
243
|
+
* <ThemeScript defaultTheme="bruttal" />
|
|
244
|
+
* </head>
|
|
245
|
+
* <body>{children}</body>
|
|
246
|
+
* </html>
|
|
247
|
+
* );
|
|
248
|
+
* }
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
declare const ThemeScript: ({
|
|
252
|
+
defaultTheme,
|
|
253
|
+
defaultMode,
|
|
254
|
+
storageKey,
|
|
255
|
+
nonce
|
|
256
|
+
}?: ThemeScriptProps) => any;
|
|
257
|
+
/**
|
|
258
|
+
* Props for the `ThemeStyles` component.
|
|
259
|
+
*/
|
|
260
|
+
interface ThemeStylesProps {
|
|
261
|
+
/** The theme bundle to generate CSS for. */
|
|
262
|
+
theme: ThemeBundle;
|
|
263
|
+
/**
|
|
264
|
+
* Theme identifier for CSS scoping (`[data-tt-theme="<themeId>"]`).
|
|
265
|
+
*
|
|
266
|
+
* **Omit in the canonical 1-theme model** — CSS targets `:root` and the
|
|
267
|
+
* alternate mode selector becomes `:root[data-tt-mode="dark"]`. No theme
|
|
268
|
+
* name repetition required.
|
|
269
|
+
*
|
|
270
|
+
* Pass `themeId` only for multi-theme scenarios (Storybook, micro-frontends,
|
|
271
|
+
* apps with visual theme switching).
|
|
272
|
+
*/
|
|
273
|
+
themeId?: string;
|
|
274
|
+
/** CSP nonce for the inline style tag. */
|
|
275
|
+
nonce?: string;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Renders an inline `<style>` tag with all CSS Custom Properties for a theme
|
|
279
|
+
* bundle — including coarse-pointer, reduced-motion, and container query
|
|
280
|
+
* progressive enhancement blocks.
|
|
281
|
+
*
|
|
282
|
+
* Use as an escape hatch for SSR frameworks that need explicit `<head>` style
|
|
283
|
+
* injection. In most React apps, `<ThemeProvider theme={...}>` already injects
|
|
284
|
+
* styles automatically via React 19 style hoisting — no `<ThemeStyles>` needed.
|
|
285
|
+
*
|
|
286
|
+
* `dangerouslySetInnerHTML` is safe: content comes exclusively from
|
|
287
|
+
* `toCssVars()` (a pure internal function) — no user input is interpolated.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```tsx
|
|
291
|
+
* // SSR escape hatch — no themeId needed for canonical 1-theme model
|
|
292
|
+
* import { ThemeScript, ThemeStyles } from '@ttoss/fsl-theme/react';
|
|
293
|
+
* import { createTheme } from '@ttoss/fsl-theme';
|
|
294
|
+
*
|
|
295
|
+
* const myTheme = createTheme();
|
|
296
|
+
*
|
|
297
|
+
* export default function RootLayout({ children }) {
|
|
298
|
+
* return (
|
|
299
|
+
* <html lang="en">
|
|
300
|
+
* <head>
|
|
301
|
+
* <ThemeScript />
|
|
302
|
+
* <ThemeStyles theme={myTheme} />
|
|
303
|
+
* </head>
|
|
304
|
+
* <body>
|
|
305
|
+
* <ThemeProvider theme={myTheme}>{children}</ThemeProvider>
|
|
306
|
+
* </body>
|
|
307
|
+
* </html>
|
|
308
|
+
* );
|
|
309
|
+
* }
|
|
310
|
+
* ```
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```tsx
|
|
314
|
+
* // Multi-theme: explicit themeId for CSS scoping
|
|
315
|
+
* <ThemeStyles theme={brandA} themeId="brand-a" />
|
|
316
|
+
* <ThemeStyles theme={brandB} themeId="brand-b" />
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
declare const ThemeStyles: ({
|
|
320
|
+
theme,
|
|
321
|
+
themeId,
|
|
322
|
+
nonce
|
|
323
|
+
}: ThemeStylesProps) => any;
|
|
324
|
+
/**
|
|
325
|
+
* Props for the `ThemeHead` component.
|
|
326
|
+
*/
|
|
327
|
+
interface ThemeHeadProps extends ThemeStylesProps {
|
|
328
|
+
/** Mode to use when no persisted value is found. @default 'system' */
|
|
329
|
+
defaultMode?: ThemeMode;
|
|
330
|
+
/** localStorage key for persistence. Must match `ThemeProvider`'s `storageKey`. @default 'tt-theme' */
|
|
331
|
+
storageKey?: string;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Convenience component that renders both `<ThemeScript>` and `<ThemeStyles>`
|
|
335
|
+
* in a single line — the complete SSR `<head>` setup for flash-free theming.
|
|
336
|
+
*
|
|
337
|
+
* Use in SSR frameworks (Next.js, Remix) where you need explicit `<head>`
|
|
338
|
+
* injection. In CSR apps, `<ThemeProvider theme={...}>` handles everything.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```tsx
|
|
342
|
+
* // Next.js app/layout.tsx
|
|
343
|
+
* import { ThemeHead, ThemeProvider } from '@ttoss/fsl-theme/react';
|
|
344
|
+
* import { createTheme } from '@ttoss/fsl-theme';
|
|
345
|
+
*
|
|
346
|
+
* const myTheme = createTheme();
|
|
347
|
+
*
|
|
348
|
+
* export default function RootLayout({ children }) {
|
|
349
|
+
* return (
|
|
350
|
+
* <html lang="en">
|
|
351
|
+
* <head>
|
|
352
|
+
* <ThemeHead theme={myTheme} />
|
|
353
|
+
* </head>
|
|
354
|
+
* <body>
|
|
355
|
+
* <ThemeProvider theme={myTheme}>{children}</ThemeProvider>
|
|
356
|
+
* </body>
|
|
357
|
+
* </html>
|
|
358
|
+
* );
|
|
359
|
+
* }
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
declare const ThemeHead: ({
|
|
363
|
+
theme,
|
|
364
|
+
themeId,
|
|
365
|
+
nonce,
|
|
366
|
+
defaultMode,
|
|
367
|
+
storageKey
|
|
368
|
+
}: ThemeHeadProps) => any;
|
|
369
|
+
//#endregion
|
|
370
|
+
export { ThemeScript as a, ThemeStylesProps as c, useResolvedTokens as d, useTokens as f, ThemeProviderProps as i, UseColorModeResult as l, ThemeHeadProps as n, ThemeScriptProps as o, ThemeProvider as r, ThemeStyles as s, ThemeHead as t, useColorMode as u };
|