react-native-terra-ui 0.10.2 → 0.11.0
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/CHANGELOG.md +22 -0
- package/README.md +8 -4
- package/lib/module/context/ThemeProvider.js +5 -5
- package/lib/module/context/ThemeProvider.js.map +1 -1
- package/lib/module/theme/define-config.js +5 -5
- package/lib/module/theme/define-config.js.map +1 -1
- package/lib/module/theme/errors.js +1 -1
- package/lib/module/theme/index.js +2 -2
- package/lib/module/theme/index.js.map +1 -1
- package/lib/module/theme/registry.js +15 -21
- package/lib/module/theme/registry.js.map +1 -1
- package/lib/module/theme/resolve-config.js +68 -68
- package/lib/module/theme/resolve-config.js.map +1 -1
- package/lib/module/theme/runtime.js +11 -11
- package/lib/module/theme/runtime.js.map +1 -1
- package/lib/module/theme/selection-store.js +7 -7
- package/lib/module/theme/selection-store.js.map +1 -1
- package/lib/module/theme/unistyles-adapter.js +1 -1
- package/lib/module/utils/accent-utils.js +24 -24
- package/lib/module/utils/accent-utils.js.map +1 -1
- package/lib/typescript/src/context/ThemeProvider.d.ts +7 -7
- package/lib/typescript/src/context/ThemeProvider.d.ts.map +1 -1
- package/lib/typescript/src/theme/define-config.d.ts +11 -8
- package/lib/typescript/src/theme/define-config.d.ts.map +1 -1
- package/lib/typescript/src/theme/errors.d.ts +1 -1
- package/lib/typescript/src/theme/index.d.ts +3 -3
- package/lib/typescript/src/theme/index.d.ts.map +1 -1
- package/lib/typescript/src/theme/registry.d.ts +5 -5
- package/lib/typescript/src/theme/registry.d.ts.map +1 -1
- package/lib/typescript/src/theme/resolve-config.d.ts +25 -25
- package/lib/typescript/src/theme/resolve-config.d.ts.map +1 -1
- package/lib/typescript/src/theme/runtime.d.ts +5 -5
- package/lib/typescript/src/theme/runtime.d.ts.map +1 -1
- package/lib/typescript/src/theme/selection-store.d.ts +5 -5
- package/lib/typescript/src/theme/selection-store.d.ts.map +1 -1
- package/lib/typescript/src/theme/types.d.ts +20 -47
- package/lib/typescript/src/theme/types.d.ts.map +1 -1
- package/lib/typescript/src/theme/unistyles-adapter.d.ts +1 -1
- package/lib/typescript/src/utils/accent-utils.d.ts +6 -7
- package/lib/typescript/src/utils/accent-utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/context/ThemeProvider.tsx +10 -10
- package/src/theme/define-config.ts +12 -7
- package/src/theme/errors.ts +1 -1
- package/src/theme/index.ts +6 -8
- package/src/theme/registry.ts +15 -23
- package/src/theme/resolve-config.ts +88 -95
- package/src/theme/runtime.ts +11 -11
- package/src/theme/selection-store.ts +9 -9
- package/src/theme/types.ts +21 -47
- package/src/theme/unistyles-adapter.ts +1 -1
- package/src/utils/accent-utils.ts +25 -25
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Runtime selection commands —
|
|
4
|
+
* Runtime selection commands — theme and theme mode — plus the subscribed
|
|
5
5
|
* selection snapshot consumed by `useTheme()`.
|
|
6
6
|
*
|
|
7
|
-
* Every
|
|
8
|
-
* configuration (never from the previously resolved
|
|
7
|
+
* Every theme change re-resolves both schemes from the installed, immutable
|
|
8
|
+
* configuration (never from the previously resolved theme), hands them to
|
|
9
9
|
* Unistyles, and only then publishes the new selection. A rejected or failed
|
|
10
10
|
* change leaves both the native themes and the published selection untouched.
|
|
11
11
|
*/
|
|
@@ -16,18 +16,18 @@ import { applyMode, updateThemes } from "./unistyles-adapter.js";
|
|
|
16
16
|
export { getThemeSelection, subscribeThemeSelection } from "./selection-store.js";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Apply a registered
|
|
19
|
+
* Apply a registered theme (`null` restores the base themes) by updating both
|
|
20
20
|
* registered themes. An unknown name warns in development and changes nothing.
|
|
21
21
|
*
|
|
22
22
|
* If the native update fails part-way (see `updateThemes` in the adapter), the
|
|
23
23
|
* error propagates and the previous selection stays published; calling
|
|
24
|
-
* `
|
|
24
|
+
* `setTheme(getCurrentTheme() ?? null)` rewrites both themes.
|
|
25
25
|
*/
|
|
26
|
-
export function
|
|
26
|
+
export function setTheme(name) {
|
|
27
27
|
const config = getInstalledConfig();
|
|
28
|
-
if (name !== null && !config.
|
|
28
|
+
if (name !== null && !config.themeNames.includes(name)) {
|
|
29
29
|
if (__DEV__) {
|
|
30
|
-
console.warn(`[react-native-terra-ui] Unknown
|
|
30
|
+
console.warn(`[react-native-terra-ui] Unknown theme "${name}".`);
|
|
31
31
|
}
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
@@ -37,13 +37,13 @@ export function applyAccent(name) {
|
|
|
37
37
|
} = resolveThemes(config, name);
|
|
38
38
|
updateThemes(themes);
|
|
39
39
|
publishThemeSelection({
|
|
40
|
-
|
|
40
|
+
themeName: name ?? undefined
|
|
41
41
|
});
|
|
42
42
|
warnContrastDiagnostics(diagnostics);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/** The applied
|
|
46
|
-
export const
|
|
45
|
+
/** The applied theme name, or `undefined` for the base themes. */
|
|
46
|
+
export const getCurrentTheme = () => getThemeSelection().themeName;
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Choose how the active scheme is selected: `system` follows the OS appearance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["warnContrastDiagnostics","resolveThemes","getInstalledConfig","getThemeSelection","publishThemeSelection","applyMode","updateThemes","subscribeThemeSelection","
|
|
1
|
+
{"version":3,"names":["warnContrastDiagnostics","resolveThemes","getInstalledConfig","getThemeSelection","publishThemeSelection","applyMode","updateThemes","subscribeThemeSelection","setTheme","name","config","themeNames","includes","__DEV__","console","warn","themes","diagnostics","themeName","undefined","getCurrentTheme","setThemeMode","mode","getThemeMode","applyScheme","scheme"],"sourceRoot":"../../../src","sources":["theme/runtime.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,uBAAuB;AAChC,SAASC,aAAa;AACtB,SAASC,kBAAkB,EAAEC,iBAAiB,EAAEC,qBAAqB;AAErE,SAASC,SAAS,EAAEC,YAAY;AAGhC,SAASH,iBAAiB,EAAEI,uBAAuB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAACC,IAAmB,EAAQ;EAClD,MAAMC,MAAM,GAAGR,kBAAkB,CAAC,CAAC;EACnC,IAAIO,IAAI,KAAK,IAAI,IAAI,CAACC,MAAM,CAACC,UAAU,CAACC,QAAQ,CAACH,IAAI,CAAC,EAAE;IACtD,IAAII,OAAO,EAAE;MACXC,OAAO,CAACC,IAAI,CAAC,0CAA0CN,IAAI,IAAI,CAAC;IAClE;IACA;EACF;EAEA,MAAM;IAAEO,MAAM;IAAEC;EAAY,CAAC,GAAGhB,aAAa,CAACS,MAAM,EAAED,IAAI,CAAC;EAC3DH,YAAY,CAACU,MAAM,CAAC;EACpBZ,qBAAqB,CAAC;IAAEc,SAAS,EAAET,IAAI,IAAIU;EAAU,CAAC,CAAC;EACvDnB,uBAAuB,CAACiB,WAAW,CAAC;AACtC;;AAEA;AACA,OAAO,MAAMG,eAAe,GAAGA,CAAA,KAA0BjB,iBAAiB,CAAC,CAAC,CAACe,SAAS;;AAEtF;AACA;AACA;AACA;AACA,OAAO,SAASG,YAAYA,CAACC,IAAe,EAAQ;EAClDjB,SAAS,CAACiB,IAAI,CAAC;EACflB,qBAAqB,CAAC;IAAEkB;EAAK,CAAC,CAAC;AACjC;;AAEA;AACA,OAAO,MAAMC,YAAY,GAAGA,CAAA,KAAiBpB,iBAAiB,CAAC,CAAC,CAACmB,IAAI;;AAErE;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,WAAWA,CAACC,MAAc,EAAQ;EAChDJ,YAAY,CAACI,MAAM,CAAC;AACtB","ignoreList":[]}
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* those has to import the other.
|
|
7
7
|
*
|
|
8
8
|
* Holds two things, both private to `theme/`:
|
|
9
|
-
* - the installed {@link NormalizedThemeConfig} — immutable; every
|
|
9
|
+
* - the installed {@link NormalizedThemeConfig} — immutable; every theme
|
|
10
10
|
* selection is re-resolved from it, never layered on a previous result;
|
|
11
|
-
* - the selection snapshot (`
|
|
11
|
+
* - the selection snapshot (`themeName`, `mode`) behind a `useSyncExternalStore`
|
|
12
12
|
* compatible subscribe/get pair. The snapshot object keeps its identity until
|
|
13
13
|
* a value actually changes, so subscribers only re-render on real changes.
|
|
14
14
|
*
|
|
@@ -33,10 +33,10 @@ export function setInstalledConfig(config) {
|
|
|
33
33
|
|
|
34
34
|
// ─── Selection snapshot ──────────────────────────────────────────────────────
|
|
35
35
|
|
|
36
|
-
/** The current runtime selection: which
|
|
36
|
+
/** The current runtime selection: which theme is applied and how the scheme is chosen. */
|
|
37
37
|
|
|
38
38
|
let selection = Object.freeze({
|
|
39
|
-
|
|
39
|
+
themeName: undefined,
|
|
40
40
|
mode: "system"
|
|
41
41
|
});
|
|
42
42
|
const listeners = new Set();
|
|
@@ -61,11 +61,11 @@ export function subscribeThemeSelection(listener) {
|
|
|
61
61
|
* A no-op — same snapshot identity, no notification — when nothing changed.
|
|
62
62
|
*/
|
|
63
63
|
export function publishThemeSelection(next) {
|
|
64
|
-
const
|
|
64
|
+
const themeName = "themeName" in next ? next.themeName : selection.themeName;
|
|
65
65
|
const mode = next.mode ?? selection.mode;
|
|
66
|
-
if (
|
|
66
|
+
if (themeName === selection.themeName && mode === selection.mode) return;
|
|
67
67
|
selection = Object.freeze({
|
|
68
|
-
|
|
68
|
+
themeName,
|
|
69
69
|
mode
|
|
70
70
|
});
|
|
71
71
|
for (const listener of listeners) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["normalizeThemeInput","installedConfig","getInstalledConfig","setInstalledConfig","config","selection","Object","freeze","
|
|
1
|
+
{"version":3,"names":["normalizeThemeInput","installedConfig","getInstalledConfig","setInstalledConfig","config","selection","Object","freeze","themeName","undefined","mode","listeners","Set","getThemeSelection","subscribeThemeSelection","listener","add","delete","publishThemeSelection","next"],"sourceRoot":"../../../src","sources":["theme/selection-store.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAqCA,mBAAmB;AAGxD;;AAEA;AACA;AACA;AACA;AACA,IAAIC,eAAsC,GAAGD,mBAAmB,CAAC,CAAC,CAAC,CAAC;;AAEpE;AACA,OAAO,MAAME,kBAAkB,GAAGA,CAAA,KAA6BD,eAAe;;AAE9E;AACA,OAAO,SAASE,kBAAkBA,CAACC,MAA6B,EAAQ;EACtEH,eAAe,GAAGG,MAAM;AAC1B;;AAEA;;AAEA;;AAQA,IAAIC,SAAyB,GAAGC,MAAM,CAACC,MAAM,CAAC;EAAEC,SAAS,EAAEC,SAAS;EAAEC,IAAI,EAAE;AAAsB,CAAC,CAAC;AAEpG,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAa,CAAC;;AAEvC;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAGA,CAAA,KAAsBR,SAAS;;AAEhE;AACA,OAAO,SAASS,uBAAuBA,CAACC,QAAoB,EAAc;EACxEJ,SAAS,CAACK,GAAG,CAACD,QAAQ,CAAC;EACvB,OAAO,MAAM;IACXJ,SAAS,CAACM,MAAM,CAACF,QAAQ,CAAC;EAC5B,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,qBAAqBA,CAACC,IAA6B,EAAQ;EACzE,MAAMX,SAAS,GAAG,WAAW,IAAIW,IAAI,GAAGA,IAAI,CAACX,SAAS,GAAGH,SAAS,CAACG,SAAS;EAC5E,MAAME,IAAI,GAAGS,IAAI,CAACT,IAAI,IAAIL,SAAS,CAACK,IAAI;EACxC,IAAIF,SAAS,KAAKH,SAAS,CAACG,SAAS,IAAIE,IAAI,KAAKL,SAAS,CAACK,IAAI,EAAE;EAElEL,SAAS,GAAGC,MAAM,CAACC,MAAM,CAAC;IAAEC,SAAS;IAAEE;EAAK,CAAC,CAAC;EAC9C,KAAK,MAAMK,QAAQ,IAAIJ,SAAS,EAAE;IAChCI,QAAQ,CAAC,CAAC;EACZ;AACF","ignoreList":[]}
|
|
@@ -53,7 +53,7 @@ export function configureUnistyles({
|
|
|
53
53
|
* runtime holds the new `light` theme and the previous `dark` theme. Callers
|
|
54
54
|
* publish registry/selection state only after this returns, so on a throw Terra
|
|
55
55
|
* still reports the previous selection; calling the same command again with the
|
|
56
|
-
* previous selection (e.g. `
|
|
56
|
+
* previous selection (e.g. `setTheme(getCurrentTheme() ?? null)`) rewrites
|
|
57
57
|
* both themes and restores consistency. No automatic rollback is attempted.
|
|
58
58
|
*/
|
|
59
59
|
export function updateThemes(themes) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { normalizeTokenOverride } from "../theme/legacy-tokens.js";
|
|
4
|
-
import {
|
|
4
|
+
import { normalizeThemeScheme } from "../theme/resolve-config.js";
|
|
5
5
|
import { defaultDarkTheme, defaultLightTheme } from "../theme/theme.js";
|
|
6
6
|
import { ACCENT_SURFACE_ROLES, generateAccentColors } from "./accent-generator.js";
|
|
7
7
|
/**
|
|
@@ -21,32 +21,33 @@ export function defaultAccentContext(scheme) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
* the
|
|
26
|
-
*
|
|
24
|
+
* Generate a palette using the named theme's ordinary surface overrides. The
|
|
25
|
+
* rest of the patch passes through as authored, matching the unseeded branch —
|
|
26
|
+
* so `spacing.base` / `radius.base` stay pseudo-tokens here; only
|
|
27
|
+
* `applyThemeLayer` expands them into a scale.
|
|
27
28
|
*/
|
|
28
|
-
function seedToColorPatch(seed,
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
color: overrides
|
|
35
|
-
})?.color;
|
|
36
|
-
if (normalized) {
|
|
37
|
-
for (const [key, value] of Object.entries(normalized)) {
|
|
38
|
-
if (value !== undefined) color[key] = value;
|
|
39
|
-
}
|
|
29
|
+
function seedToColorPatch(seed, patch, scheme) {
|
|
30
|
+
const normalized = normalizeTokenOverride(patch);
|
|
31
|
+
const context = defaultAccentContext(scheme);
|
|
32
|
+
for (const role of ACCENT_SURFACE_ROLES) {
|
|
33
|
+
const value = normalized?.color?.[role];
|
|
34
|
+
if (value !== undefined) context.surfaces[role] = value;
|
|
40
35
|
}
|
|
36
|
+
context.pressedOpacity = normalized?.opacity?.pressed ?? context.pressedOpacity;
|
|
37
|
+
const generated = generateAccentColors(seed, context).colors;
|
|
41
38
|
return {
|
|
42
|
-
|
|
39
|
+
...normalized,
|
|
40
|
+
color: {
|
|
41
|
+
...generated,
|
|
42
|
+
...normalized?.color
|
|
43
|
+
}
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
function normalizeSchemeInput(input, scheme) {
|
|
46
|
-
const normalized =
|
|
47
|
+
const normalized = normalizeThemeScheme(input, `themes.<name>.${scheme}`);
|
|
47
48
|
if (normalized.kind === "none") return {};
|
|
48
49
|
if (normalized.kind === "seed") {
|
|
49
|
-
return seedToColorPatch(normalized.seed, normalized.
|
|
50
|
+
return seedToColorPatch(normalized.seed, normalized.patch, scheme);
|
|
50
51
|
}
|
|
51
52
|
// Preserve the compatibility helper's identity contract for full patches;
|
|
52
53
|
// the resolver itself uses the sanitized copy in `normalized.patch`.
|
|
@@ -54,11 +55,10 @@ function normalizeSchemeInput(input, scheme) {
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* pass through unchanged. Pure and independent of the registry.
|
|
58
|
+
* @deprecated Prefer createTerraThemes for complete theme resolution.
|
|
59
|
+
* Generates per-scheme patches without shared config. Explicit unseeded patches
|
|
60
|
+
* pass through unchanged; seeded entries generate against their own surface and
|
|
61
|
+
* color tokens and carry the remainder of the patch through unresolved.
|
|
62
62
|
*/
|
|
63
63
|
export function normalizeAccent(accent) {
|
|
64
64
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["normalizeTokenOverride","
|
|
1
|
+
{"version":3,"names":["normalizeTokenOverride","normalizeThemeScheme","defaultDarkTheme","defaultLightTheme","ACCENT_SURFACE_ROLES","generateAccentColors","defaultAccentContext","scheme","theme","surfaces","role","color","pressedOpacity","opacity","pressed","seedToColorPatch","seed","patch","normalized","context","value","undefined","generated","colors","normalizeSchemeInput","input","kind","normalizeAccent","accent","light","dark"],"sourceRoot":"../../../src","sources":["utils/accent-utils.ts"],"mappings":";;AAAA,SAASA,sBAAsB;AAC/B,SAASC,oBAAoB;AAC7B,SAASC,gBAAgB,EAAEC,iBAAiB;AAS5C,SACEC,oBAAoB,EAGpBC,oBAAoB;AAItB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAACC,MAAc,EAA2B;EAC5E,MAAMC,KAAK,GAAGD,MAAM,KAAK,OAAO,GAAGJ,iBAAiB,GAAGD,gBAAgB;EACvE,MAAMO,QAAQ,GAAG,CAAC,CAAsC;EACxD,KAAK,MAAMC,IAAI,IAAIN,oBAAoB,EAAEK,QAAQ,CAACC,IAAI,CAAC,GAAGF,KAAK,CAACG,KAAK,CAACD,IAAI,CAAC;EAC3E,OAAO;IAAEH,MAAM;IAAEE,QAAQ;IAAEG,cAAc,EAAEJ,KAAK,CAACK,OAAO,CAACC;EAAQ,CAAC;AACpE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,gBAAgBA,CACvBC,IAAY,EACZC,KAAqC,EACrCV,MAAc,EACW;EACzB,MAAMW,UAAU,GAAGlB,sBAAsB,CAACiB,KAAK,CAAC;EAChD,MAAME,OAAO,GAAGb,oBAAoB,CAACC,MAAM,CAAC;EAC5C,KAAK,MAAMG,IAAI,IAAIN,oBAAoB,EAAE;IACvC,MAAMgB,KAAK,GAAGF,UAAU,EAAEP,KAAK,GAAGD,IAAI,CAAC;IACvC,IAAIU,KAAK,KAAKC,SAAS,EAAEF,OAAO,CAACV,QAAQ,CAACC,IAAI,CAAC,GAAGU,KAAK;EACzD;EACAD,OAAO,CAACP,cAAc,GAAGM,UAAU,EAAEL,OAAO,EAAEC,OAAO,IAAIK,OAAO,CAACP,cAAc;EAC/E,MAAMU,SAAS,GAAGjB,oBAAoB,CAACW,IAAI,EAAEG,OAAO,CAAC,CAACI,MAAM;EAC5D,OAAO;IAAE,GAAGL,UAAU;IAAEP,KAAK,EAAE;MAAE,GAAGW,SAAS;MAAE,GAAGJ,UAAU,EAAEP;IAAM;EAAE,CAAC;AACzE;AAEA,SAASa,oBAAoBA,CAACC,KAAmC,EAAElB,MAAc,EAA2B;EAC1G,MAAMW,UAAU,GAAGjB,oBAAoB,CAACwB,KAAK,EAAE,iBAAiBlB,MAAM,EAAE,CAAC;EACzE,IAAIW,UAAU,CAACQ,IAAI,KAAK,MAAM,EAAE,OAAO,CAAC,CAAC;EACzC,IAAIR,UAAU,CAACQ,IAAI,KAAK,MAAM,EAAE;IAC9B,OAAOX,gBAAgB,CAACG,UAAU,CAACF,IAAI,EAAEE,UAAU,CAACD,KAAK,EAAEV,MAAM,CAAC;EACpE;EACA;EACA;EACA,OAAOkB,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,eAAeA,CAACC,MAAkB,EAAoB;EACpE,OAAO;IACLC,KAAK,EAAEL,oBAAoB,CAACI,MAAM,CAACC,KAAK,EAAE,OAAO,CAAC;IAClDC,IAAI,EAAEN,oBAAoB,CAACI,MAAM,CAACE,IAAI,EAAE,MAAM;EAChD,CAAC;AACH","ignoreList":[]}
|
|
@@ -20,13 +20,13 @@ export interface UseThemeResult {
|
|
|
20
20
|
scheme: Scheme;
|
|
21
21
|
/** Pin a scheme (stops following the system). Same as `setMode(scheme)`. */
|
|
22
22
|
setScheme: (scheme: Scheme) => void;
|
|
23
|
-
/** Applied
|
|
24
|
-
|
|
23
|
+
/** Applied theme name, or `undefined` for the base themes. */
|
|
24
|
+
themeName: string | undefined;
|
|
25
25
|
/**
|
|
26
|
-
* Apply a registered
|
|
27
|
-
* name warns in development and leaves the
|
|
26
|
+
* Apply a registered theme; `null` restores the base themes. An unknown
|
|
27
|
+
* name warns in development and leaves the theme unchanged.
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
setTheme: (name: string | null) => void;
|
|
30
30
|
/**
|
|
31
31
|
* How the active scheme is chosen: `system` follows the OS appearance,
|
|
32
32
|
* `light` / `dark` pin a scheme. A system appearance change updates
|
|
@@ -37,8 +37,8 @@ export interface UseThemeResult {
|
|
|
37
37
|
setMode: (mode: ThemeMode) => void;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* Access the active theme and switch scheme / mode /
|
|
41
|
-
* comes from the runtime store, so changes made imperatively (`
|
|
40
|
+
* Access the active theme and switch scheme / mode / theme. Selection state
|
|
41
|
+
* comes from the runtime store, so changes made imperatively (`setTheme`,
|
|
42
42
|
* `setThemeMode`) and through this hook are observed by every consumer.
|
|
43
43
|
*/
|
|
44
44
|
export declare function useTheme(): UseThemeResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../../../src/context/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAwB,MAAM,OAAO,CAAC;AAarE,OAAO,EAAE,KAAK,qBAAqB,EAAwB,MAAM,4BAAyB,CAAC;AAC3F,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAgB,CAAC;AAOpE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,cAAc,iBAAiB,gCAE9D,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,KAAK,EAAE,UAAU,CAAC;IAClB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../../../src/context/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAwB,MAAM,OAAO,CAAC;AAarE,OAAO,EAAE,KAAK,qBAAqB,EAAwB,MAAM,4BAAyB,CAAC;AAC3F,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAgB,CAAC;AAOpE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,cAAc,iBAAiB,gCAE9D,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,KAAK,EAAE,UAAU,CAAC;IAClB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,8DAA8D;IAC9D,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B;;;OAGG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACxC;;;;OAIG;IACH,IAAI,EAAE,SAAS,CAAC;IAChB,+EAA+E;IAC/E,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CACpC;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,IAAI,cAAc,CAazC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,qBAAqB,CAGxD;AAED,wCAAwC;AACxC,eAAO,MAAM,eAAe,yBAAmB,CAAC"}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import type { TerraConfig } from "./types.js";
|
|
2
|
-
/** The literal
|
|
3
|
-
type
|
|
4
|
-
|
|
2
|
+
/** The literal theme names declared in `T.themes`, or `never` when none are declared. */
|
|
3
|
+
type DeclaredThemeNames<T> = T extends {
|
|
4
|
+
themes: infer A;
|
|
5
5
|
} ? A extends Record<string, unknown> ? keyof A & string : never : never;
|
|
6
6
|
/**
|
|
7
7
|
* Identity helper for authoring a {@link TerraConfig} with contextual typing.
|
|
8
|
-
* Has no side effects. With literal `
|
|
9
|
-
* them; a dynamic `Record<string,
|
|
8
|
+
* Has no side effects. With literal `themes`, `defaultTheme` must name one of
|
|
9
|
+
* them; a dynamic `Record<string, NamedTheme>` keeps `defaultTheme` as `string`
|
|
10
10
|
* and defers to runtime validation.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* const config = defineTerraConfig({
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* themes: { indigo: { light: "#4f46e5", dark: "#818cf8" } },
|
|
15
|
+
* defaultTheme: "indigo",
|
|
16
16
|
* });
|
|
17
17
|
* configureTerraUI(config);
|
|
18
18
|
*/
|
|
19
19
|
export declare function defineTerraConfig<const T extends TerraConfig>(config: T & {
|
|
20
|
-
|
|
20
|
+
defaultTheme?: DeclaredThemeNames<T>;
|
|
21
|
+
schemes?: never;
|
|
22
|
+
accents?: never;
|
|
23
|
+
defaultAccent?: never;
|
|
21
24
|
}): T;
|
|
22
25
|
export {};
|
|
23
26
|
//# sourceMappingURL=define-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../../../../src/theme/define-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAS,CAAC;AAE3C,
|
|
1
|
+
{"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../../../../src/theme/define-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAS,CAAC;AAE3C,yFAAyF;AACzF,KAAK,kBAAkB,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACtD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,CAAC,GAAG,MAAM,GAChB,KAAK,GACP,KAAK,CAAC;AAEV;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,CAAC,SAAS,WAAW,EAC3D,MAAM,EAAE,CAAC,GAAG;IACV,YAAY,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;IACrC,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB,GACA,CAAC,CAEH"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Thrown for invalid pure configuration input — before any registry, selection,
|
|
3
3
|
* or native state is touched. `path` points at the offending config entry, e.g.
|
|
4
|
-
* `
|
|
4
|
+
* `themes.indigo.dark.seed` or `defaultTheme`.
|
|
5
5
|
*/
|
|
6
6
|
export declare class TerraConfigError extends Error {
|
|
7
7
|
readonly path: string;
|
|
@@ -10,14 +10,14 @@ export type { AppBreakpoints, BreakpointName } from "./breakpoints.js";
|
|
|
10
10
|
export { breakpoints, resolveBreakpointValue } from "./breakpoints.js";
|
|
11
11
|
export { defineTerraConfig } from "./define-config.js";
|
|
12
12
|
export { TerraConfigError } from "./errors.js";
|
|
13
|
-
export { configureTerraUI,
|
|
13
|
+
export { configureTerraUI, getDefaultRadius, getIcon, getImageComponent, getIsConfigured, getRequiredIcon, getSurfaceElevation, getThemeNames, resolveTheme, } from "./registry.js";
|
|
14
14
|
export { createTerraThemes } from "./resolve-config.js";
|
|
15
15
|
export type { ThemeSelection } from "./runtime.js";
|
|
16
|
-
export {
|
|
16
|
+
export { applyScheme, getCurrentTheme, getThemeMode, getThemeSelection, setTheme, setThemeMode, } from "./runtime.js";
|
|
17
17
|
export type { ResolvedScreenMargin } from "./screen-margin.js";
|
|
18
18
|
export { resolveScreenMargin } from "./screen-margin.js";
|
|
19
19
|
export type { ResolvedScreenPadding } from "./screen-padding.js";
|
|
20
20
|
export { resolveScreenPadding } from "./screen-padding.js";
|
|
21
21
|
export { defaultDarkTheme, defaultLightTheme } from "./theme.js";
|
|
22
|
-
export type {
|
|
22
|
+
export type { AccentColorToken, ActionColorToken, BackgroundColorToken, BorderColorToken, ButtonDefaults, CanonicalThemeColor, ColorToken, ComponentDefaults, ContentColorToken, CreateTerraThemesOptions, DefaultRadiusToken, ElevationKey, ElevationScale, ElevationStyle, FontWeightToken, LayoutTokens, NamedTheme, NeutralColorToken, OpacityTokens, RadiusComponent, RadiusKey, Scheme, ScreenPaddingTokens, SpacingKey, StatusColorToken, SurfaceColorToken, SurfaceDefaults, TerraColorRegistry, TerraColorRegistryCollision, TerraConfig, TerraCustomColorName, TerraIconComponent, TerraIconName, TerraIconProps, TerraImageComponent, TerraImageContentFit, TerraImageProps, TerraSemanticIconName, TerraTheme, TerraThemeInput, TerraThemeOverride, TextColorToken, TextVariant, ThemeColor, ThemeMode, ThemeRadiusOverride, ThemeSchemeInput, ThemeSeed, ThemeSpacingOverride, TypeStyle, Typography, } from "./types.js";
|
|
23
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/index.ts"],"names":[],"mappings":"AAQA,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,MAA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eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,UAAU,EACV,SAAS,EACT,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,UAAU,GACX,MAAM,YAAS,CAAC"}
|
|
@@ -6,8 +6,8 @@ declare module "react-native-unistyles" {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
export declare const getIsConfigured: () => boolean;
|
|
9
|
-
/** Names of the registered
|
|
10
|
-
export declare const
|
|
9
|
+
/** Names of the registered themes, in declaration order. Returns a fresh array. */
|
|
10
|
+
export declare const getThemeNames: () => string[];
|
|
11
11
|
export declare const getImageComponent: () => TerraImageComponent;
|
|
12
12
|
export declare const getIcon: (name: string) => TerraIconComponent | undefined;
|
|
13
13
|
export declare const getRequiredIcon: (name: TerraSemanticIconName) => TerraIconComponent;
|
|
@@ -23,12 +23,12 @@ export declare const getDefaultRadius: (component: RadiusComponent) => DefaultRa
|
|
|
23
23
|
export declare const getSurfaceElevation: () => ElevationKey;
|
|
24
24
|
/**
|
|
25
25
|
* Resolves one scheme's theme from the installed configuration with the named
|
|
26
|
-
*
|
|
27
|
-
* not the configured `
|
|
26
|
+
* theme selected. Omitting `name` selects the base theme (defaults + shared —
|
|
27
|
+
* not the configured `defaultTheme`). An unknown name warns in development
|
|
28
28
|
* and falls back to the base theme. Pure with respect to runtime state: it
|
|
29
29
|
* never changes the applied selection.
|
|
30
30
|
*/
|
|
31
|
-
export declare function resolveTheme(scheme: Scheme,
|
|
31
|
+
export declare function resolveTheme(scheme: Scheme, name?: string): TerraTheme;
|
|
32
32
|
/**
|
|
33
33
|
* Configure Terra UI's themes. Call ONCE, as early as possible — before any
|
|
34
34
|
* component renders (e.g. top of the app entry, imported from
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../../src/theme/registry.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAEV,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,MAAM,EACN,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,UAAU,
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../../src/theme/registry.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAEV,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,MAAM,EACN,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,UAAU,EAEX,MAAM,YAAS,CAAC;AAmBjB,OAAO,QAAQ,wBAAwB,CAAC;IACtC,UAAiB,eAAe;QAC9B,KAAK,EAAE,UAAU,CAAC;QAClB,IAAI,EAAE,UAAU,CAAC;KAClB;CACF;AA8BD,eAAO,MAAM,eAAe,QAAO,OAA0C,CAAC;AAE9E,mFAAmF;AACnF,eAAO,MAAM,aAAa,QAAO,MAAM,EAA0C,CAAC;AAElF,eAAO,MAAM,iBAAiB,QAAO,mBAA8C,CAAC;AAEpF,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,KAAG,kBAAkB,GAAG,SACS,CAAC;AAEtE,eAAO,MAAM,eAAe,GAAI,MAAM,qBAAqB,KAAG,kBAClB,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,WAAW,eAAe,KAAG,kBAC3B,CAAC;AAEpC;;;GAGG;AACH,eAAO,MAAM,mBAAmB,QAAO,YAAyC,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAWtE;AAID;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,WAAgB,GAAG,IAAI,CAW/D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAMvC"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pure theme resolution — normalization, layer processing, derived values and
|
|
3
|
-
* theme creation. Shared by startup configuration, runtime
|
|
3
|
+
* theme creation. Shared by startup configuration, runtime theme changes and
|
|
4
4
|
* previews so every consumer sees the same colors for the same input.
|
|
5
5
|
*
|
|
6
6
|
* Precedence, identical for both schemes:
|
|
7
7
|
*
|
|
8
|
-
* default tokens → shared →
|
|
9
|
-
*
|
|
8
|
+
* default tokens → shared → generated accent → selected theme tokens
|
|
9
|
+
* Generation uses the selected theme's resolved surfaces and pressed opacity.
|
|
10
10
|
*
|
|
11
11
|
* This module must stay free of registry, provider, Unistyles and renderer
|
|
12
12
|
* imports so `createTerraThemes` works without any native configuration.
|
|
13
13
|
*/
|
|
14
14
|
import { type ContrastDiagnostic } from "../utils/accent-generator";
|
|
15
15
|
import { type ThemeSource } from "./theme.js";
|
|
16
|
-
import type {
|
|
16
|
+
import type { CreateTerraThemesOptions, ElevationKey, Scheme, TerraTheme, TerraThemeInput, TerraThemeOverride, ThemeSchemeInput } from "./types.js";
|
|
17
17
|
/**
|
|
18
18
|
* A theme mid-resolution: its source form plus provenance for every elevation
|
|
19
19
|
* level whose `shadowColor` a layer pinned explicitly. Default shadow colors are
|
|
@@ -25,8 +25,8 @@ export interface ThemeLayerState {
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Applies one override layer onto `state` and returns the next state. Every
|
|
28
|
-
* layer — shared,
|
|
29
|
-
*
|
|
28
|
+
* layer — shared, generated accent, or selected theme tokens — goes through
|
|
29
|
+
* here, so they all follow the same rules:
|
|
30
30
|
* - deprecated names are normalized within the layer (canonical wins);
|
|
31
31
|
* - `undefined`/`null` leaves are no override; arrays replace; objects merge;
|
|
32
32
|
* - `spacing.base` / `radius.base` regenerate their scale, then that layer's
|
|
@@ -36,37 +36,37 @@ export interface ThemeLayerState {
|
|
|
36
36
|
* Inputs are never mutated.
|
|
37
37
|
*/
|
|
38
38
|
export declare function applyThemeLayer(state: ThemeLayerState, override?: TerraThemeOverride): ThemeLayerState;
|
|
39
|
-
export type
|
|
39
|
+
export type NormalizedThemeScheme = {
|
|
40
40
|
readonly kind: "none";
|
|
41
41
|
} | {
|
|
42
42
|
readonly kind: "seed";
|
|
43
43
|
readonly seed: string;
|
|
44
|
-
readonly
|
|
44
|
+
readonly patch?: TerraThemeOverride;
|
|
45
45
|
} | {
|
|
46
46
|
readonly kind: "patch";
|
|
47
47
|
readonly patch: TerraThemeOverride;
|
|
48
48
|
};
|
|
49
|
-
interface
|
|
50
|
-
readonly light:
|
|
51
|
-
readonly dark:
|
|
49
|
+
interface NormalizedThemeEntry {
|
|
50
|
+
readonly light: NormalizedThemeScheme;
|
|
51
|
+
readonly dark: NormalizedThemeScheme;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* A validated, immutable theme configuration. `base` is the fully layered
|
|
55
|
-
* `defaults → shared
|
|
56
|
-
* re-resolved from it rather than from a previously resolved
|
|
55
|
+
* `defaults → shared` state per scheme; every theme selection is
|
|
56
|
+
* re-resolved from it rather than from a previously resolved theme.
|
|
57
57
|
*/
|
|
58
58
|
export interface NormalizedThemeConfig {
|
|
59
|
-
readonly
|
|
60
|
-
readonly
|
|
61
|
-
/** @internal Immutable `defaults → shared
|
|
59
|
+
readonly themeNames: readonly string[];
|
|
60
|
+
readonly defaultTheme: string | null;
|
|
61
|
+
/** @internal Immutable `defaults → shared` state per scheme. */
|
|
62
62
|
readonly base: Readonly<Record<Scheme, ThemeLayerState>>;
|
|
63
|
-
/** @internal Per-
|
|
64
|
-
readonly
|
|
63
|
+
/** @internal Per-theme, per-scheme normalized inputs. */
|
|
64
|
+
readonly themes: Readonly<Record<string, NormalizedThemeEntry>>;
|
|
65
65
|
}
|
|
66
|
-
export declare function
|
|
66
|
+
export declare function normalizeThemeScheme(input: ThemeSchemeInput | undefined, path: string): NormalizedThemeScheme;
|
|
67
67
|
/**
|
|
68
68
|
* Validates a theme input and pre-computes the immutable per-scheme base
|
|
69
|
-
* (`defaults → shared
|
|
69
|
+
* (`defaults → shared`). Throws {@link TerraConfigError} for invalid
|
|
70
70
|
* input — before any state exists to mutate. Never mutates `input` or the
|
|
71
71
|
* exported defaults.
|
|
72
72
|
*/
|
|
@@ -77,20 +77,20 @@ export interface ResolvedThemes {
|
|
|
77
77
|
diagnostics: ContrastDiagnostic[];
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
|
-
* Resolves both schemes for `
|
|
80
|
+
* Resolves both schemes for `themeName` from the config's immutable base. `null`
|
|
81
81
|
* selects the base themes; an unknown name throws {@link TerraConfigError}.
|
|
82
82
|
* Returned themes are freshly built and independently owned.
|
|
83
83
|
*/
|
|
84
|
-
export declare function resolveThemes(config: NormalizedThemeConfig,
|
|
84
|
+
export declare function resolveThemes(config: NormalizedThemeConfig, themeName: string | null): ResolvedThemes;
|
|
85
85
|
/** Resolves one scheme without generating and finalizing the other. */
|
|
86
|
-
export declare function resolveThemeScheme(config: NormalizedThemeConfig, scheme: Scheme,
|
|
86
|
+
export declare function resolveThemeScheme(config: NormalizedThemeConfig, scheme: Scheme, themeName: string | null): {
|
|
87
87
|
theme: TerraTheme;
|
|
88
88
|
diagnostics: ContrastDiagnostic[];
|
|
89
89
|
};
|
|
90
90
|
/**
|
|
91
91
|
* Pure theme creation — no Unistyles configuration or registry involved.
|
|
92
|
-
* `options.
|
|
93
|
-
* themes. Invalid input and unknown
|
|
92
|
+
* `options.theme` omitted → the input's `defaultTheme`; `null` → the base
|
|
93
|
+
* themes. Invalid input and unknown themes throw {@link TerraConfigError}.
|
|
94
94
|
* In development, contrast diagnostics are reported once each via
|
|
95
95
|
* `console.warn`; requested colors are never altered.
|
|
96
96
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-config.d.ts","sourceRoot":"","sources":["../../../../src/theme/resolve-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAGL,KAAK,kBAAkB,EAMxB,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAKL,KAAK,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election } from "./selection-store.js";
|
|
3
3
|
export { getThemeSelection, subscribeThemeSelection } from "./selection-store.js";
|
|
4
4
|
/**
|
|
5
|
-
* Apply a registered
|
|
5
|
+
* Apply a registered theme (`null` restores the base themes) by updating both
|
|
6
6
|
* registered themes. An unknown name warns in development and changes nothing.
|
|
7
7
|
*
|
|
8
8
|
* If the native update fails part-way (see `updateThemes` in the adapter), the
|
|
9
9
|
* error propagates and the previous selection stays published; calling
|
|
10
|
-
* `
|
|
10
|
+
* `setTheme(getCurrentTheme() ?? null)` rewrites both themes.
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
13
|
-
/** The applied
|
|
14
|
-
export declare const
|
|
12
|
+
export declare function setTheme(name: string | null): void;
|
|
13
|
+
/** The applied theme name, or `undefined` for the base themes. */
|
|
14
|
+
export declare const getCurrentTheme: () => string | undefined;
|
|
15
15
|
/**
|
|
16
16
|
* Choose how the active scheme is selected: `system` follows the OS appearance;
|
|
17
17
|
* `light` / `dark` pin a scheme until the next call.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/theme/runtime.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAS,CAAC;AAGjD,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAmB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,sBAAmB,CAAC;AAE/E;;;;;;;GAOG;AACH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/theme/runtime.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAS,CAAC;AAGjD,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAmB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,sBAAmB,CAAC;AAE/E;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAalD;AAED,kEAAkE;AAClE,eAAO,MAAM,eAAe,QAAO,MAAM,GAAG,SAA0C,CAAC;AAEvF;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAGlD;AAED,6EAA6E;AAC7E,eAAO,MAAM,YAAY,QAAO,SAAqC,CAAC;AAEtE;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAEhD"}
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* those has to import the other.
|
|
5
5
|
*
|
|
6
6
|
* Holds two things, both private to `theme/`:
|
|
7
|
-
* - the installed {@link NormalizedThemeConfig} — immutable; every
|
|
7
|
+
* - the installed {@link NormalizedThemeConfig} — immutable; every theme
|
|
8
8
|
* selection is re-resolved from it, never layered on a previous result;
|
|
9
|
-
* - the selection snapshot (`
|
|
9
|
+
* - the selection snapshot (`themeName`, `mode`) behind a `useSyncExternalStore`
|
|
10
10
|
* compatible subscribe/get pair. The snapshot object keeps its identity until
|
|
11
11
|
* a value actually changes, so subscribers only re-render on real changes.
|
|
12
12
|
*
|
|
@@ -18,10 +18,10 @@ import type { ThemeMode } from "./types.js";
|
|
|
18
18
|
export declare const getInstalledConfig: () => NormalizedThemeConfig;
|
|
19
19
|
/** @internal Replaces the installed config; only `registry.ts` should call this. */
|
|
20
20
|
export declare function setInstalledConfig(config: NormalizedThemeConfig): void;
|
|
21
|
-
/** The current runtime selection: which
|
|
21
|
+
/** The current runtime selection: which theme is applied and how the scheme is chosen. */
|
|
22
22
|
export interface ThemeSelection {
|
|
23
|
-
/** Applied
|
|
24
|
-
readonly
|
|
23
|
+
/** Applied theme name, or `undefined` for the base themes. */
|
|
24
|
+
readonly themeName: string | undefined;
|
|
25
25
|
/** `system` follows the OS appearance; `light` / `dark` pin a scheme. */
|
|
26
26
|
readonly mode: ThemeMode;
|
|
27
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection-store.d.ts","sourceRoot":"","sources":["../../../../src/theme/selection-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,KAAK,qBAAqB,EAAuB,MAAM,qBAAkB,CAAC;AACnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAS,CAAC;AAUzC,0DAA0D;AAC1D,eAAO,MAAM,kBAAkB,QAAO,qBAAwC,CAAC;AAE/E,oFAAoF;AACpF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAEtE;AAID,
|
|
1
|
+
{"version":3,"file":"selection-store.d.ts","sourceRoot":"","sources":["../../../../src/theme/selection-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,KAAK,qBAAqB,EAAuB,MAAM,qBAAkB,CAAC;AACnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAS,CAAC;AAUzC,0DAA0D;AAC1D,eAAO,MAAM,kBAAkB,QAAO,qBAAwC,CAAC;AAE/E,oFAAoF;AACpF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAEtE;AAID,0FAA0F;AAC1F,MAAM,WAAW,cAAc;IAC7B,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;CAC1B;AAMD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,QAAO,cAA2B,CAAC;AAEjE,wEAAwE;AACxE,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAKxE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CASzE"}
|