@codeleap/styles 7.0.0 → 7.0.1

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 (93) hide show
  1. package/dist/classes/Cacher.js +166 -0
  2. package/dist/classes/Cacher.js.map +1 -0
  3. package/dist/classes/StaleControl.js +101 -0
  4. package/dist/classes/StaleControl.js.map +1 -0
  5. package/dist/classes/StyleCache.js +91 -0
  6. package/dist/classes/StyleCache.js.map +1 -0
  7. package/dist/classes/StylePersistor.js +54 -0
  8. package/dist/classes/StylePersistor.js.map +1 -0
  9. package/dist/classes/StyleRegistry.js +470 -0
  10. package/dist/classes/StyleRegistry.js.map +1 -0
  11. package/dist/classes/index.js +3 -0
  12. package/dist/classes/index.js.map +1 -0
  13. package/dist/constants.js +24 -0
  14. package/dist/constants.js.map +1 -0
  15. package/dist/hooks/index.js +5 -0
  16. package/dist/hooks/index.js.map +1 -0
  17. package/dist/hooks/useCompositionStyles.js +27 -0
  18. package/dist/hooks/useCompositionStyles.js.map +1 -0
  19. package/dist/hooks/useNestedStylesByKey.js +17 -0
  20. package/dist/hooks/useNestedStylesByKey.js.map +1 -0
  21. package/dist/hooks/useStyleObserver.js +22 -0
  22. package/dist/hooks/useStyleObserver.js.map +1 -0
  23. package/dist/hooks/useTheme.js +24 -0
  24. package/dist/hooks/useTheme.js.map +1 -0
  25. package/dist/index.js +12 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/lib/calc.js +44 -0
  28. package/dist/lib/calc.js.map +1 -0
  29. package/dist/lib/createStyles.js +58 -0
  30. package/dist/lib/createStyles.js.map +1 -0
  31. package/dist/lib/createTheme.js +143 -0
  32. package/dist/lib/createTheme.js.map +1 -0
  33. package/dist/lib/cssVariables.js +73 -0
  34. package/dist/lib/cssVariables.js.map +1 -0
  35. package/dist/lib/index.js +5 -0
  36. package/dist/lib/index.js.map +1 -0
  37. package/dist/theme/generateColorScheme.js +38 -0
  38. package/dist/theme/generateColorScheme.js.map +1 -0
  39. package/dist/theme/index.js +4 -0
  40. package/dist/theme/index.js.map +1 -0
  41. package/dist/theme/themeStore.js +139 -0
  42. package/dist/theme/themeStore.js.map +1 -0
  43. package/dist/theme/validateTheme.js +33 -0
  44. package/dist/theme/validateTheme.js.map +1 -0
  45. package/dist/tools/colors.js +138 -0
  46. package/dist/tools/colors.js.map +1 -0
  47. package/dist/tools/deepClone.js +8 -0
  48. package/dist/tools/deepClone.js.map +1 -0
  49. package/dist/tools/deepmerge.js +13 -0
  50. package/dist/tools/deepmerge.js.map +1 -0
  51. package/dist/tools/hashKey.js +16 -0
  52. package/dist/tools/hashKey.js.map +1 -0
  53. package/dist/tools/index.js +7 -0
  54. package/dist/tools/index.js.map +1 -0
  55. package/dist/tools/minifier.js +34 -0
  56. package/dist/tools/minifier.js.map +1 -0
  57. package/dist/tools/multiplierProperty.js +9 -0
  58. package/dist/tools/multiplierProperty.js.map +1 -0
  59. package/dist/types/cache.js +2 -0
  60. package/dist/types/cache.js.map +1 -0
  61. package/dist/types/component.js +2 -0
  62. package/dist/types/component.js.map +1 -0
  63. package/dist/types/core.js +3 -0
  64. package/dist/types/core.js.map +1 -0
  65. package/dist/types/icon.js +3 -0
  66. package/dist/types/icon.js.map +1 -0
  67. package/dist/types/index.js +6 -0
  68. package/dist/types/index.js.map +1 -0
  69. package/dist/types/spacing.js +28 -0
  70. package/dist/types/spacing.js.map +1 -0
  71. package/dist/types/store.js +2 -0
  72. package/dist/types/store.js.map +1 -0
  73. package/dist/types/style.js +2 -0
  74. package/dist/types/style.js.map +1 -0
  75. package/dist/types/theme.js +2 -0
  76. package/dist/types/theme.js.map +1 -0
  77. package/dist/utils.js +97 -0
  78. package/dist/utils.js.map +1 -0
  79. package/dist/variants/borderCreator.js +26 -0
  80. package/dist/variants/borderCreator.js.map +1 -0
  81. package/dist/variants/createAppVariants.js +17 -0
  82. package/dist/variants/createAppVariants.js.map +1 -0
  83. package/dist/variants/defaultVariants.js +137 -0
  84. package/dist/variants/defaultVariants.js.map +1 -0
  85. package/dist/variants/dynamicVariants.js +89 -0
  86. package/dist/variants/dynamicVariants.js.map +1 -0
  87. package/dist/variants/index.js +7 -0
  88. package/dist/variants/index.js.map +1 -0
  89. package/dist/variants/mediaQuery.js +56 -0
  90. package/dist/variants/mediaQuery.js.map +1 -0
  91. package/dist/variants/spacing.js +81 -0
  92. package/dist/variants/spacing.js.map +1 -0
  93. package/package.json +3 -3
@@ -0,0 +1,24 @@
1
+ import { themeStoreComputed } from '../theme';
2
+ import { useStore } from '@nanostores/react';
3
+ /**
4
+ * Subscribes to the global theme state and returns either the full `ThemeState`
5
+ * (when called without arguments) or a derived value (when called with a selector).
6
+ * Uses nanostores' `useStore` under the hood, so re-renders are triggered only when
7
+ * the selected slice changes by reference.
8
+ *
9
+ * @example
10
+ * // Full state
11
+ * const { theme, colorScheme } = useTheme()
12
+ *
13
+ * @example
14
+ * // Derived slice — component only re-renders when colorScheme changes
15
+ * const colorScheme = useTheme(s => s.colorScheme)
16
+ */
17
+ export const useTheme = (selector) => {
18
+ const state = useStore(themeStoreComputed);
19
+ if (!selector) {
20
+ return state;
21
+ }
22
+ return selector(state);
23
+ };
24
+ //# sourceMappingURL=useTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTheme.js","sourceRoot":"","sources":["../../src/hooks/useTheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,kBAAkB,EAAE,MAAM,UAAU,CAAA;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAI5C;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,QAA2B,EACxB,EAAE;IACL,MAAM,KAAK,GAAG,QAAQ,CAAC,kBAAkB,CAAC,CAAA;IAE1C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,KAAU,CAAA;IACnB,CAAC;IAED,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import './constants';
2
+ import './utils';
3
+ export * from './classes';
4
+ export * from './hooks';
5
+ export * from './lib';
6
+ export * from './theme';
7
+ export * from './tools';
8
+ export * from './types';
9
+ export * from './variants';
10
+ export * from './constants';
11
+ export * from './utils';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AACpB,OAAO,SAAS,CAAA;AAEhB,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA;AACrB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Chainable builder for CSS `calc()` expressions. Each arithmetic method appends
3
+ * to the expression and returns `this`, so calls can be chained. Call `build()`
4
+ * at the end to get the final `calc(...)` string.
5
+ *
6
+ * @example
7
+ * calc(100, '%').sub(16).build() // → 'calc((100%) - (16px))'
8
+ */
9
+ class CalcBuilder {
10
+ constructor(initial, unit = 'px') {
11
+ this.expression = `${initial}${unit}`;
12
+ }
13
+ wrap(value) {
14
+ return `(${value})`;
15
+ }
16
+ sub(value, unit = 'px') {
17
+ const val = `${value}${unit}`;
18
+ this.expression = `${this.wrap(this.expression)} - ${this.wrap(val)}`;
19
+ return this;
20
+ }
21
+ add(value, unit = 'px') {
22
+ const val = `${value}${unit}`;
23
+ this.expression = `${this.wrap(this.expression)} + ${this.wrap(val)}`;
24
+ return this;
25
+ }
26
+ mult(value) {
27
+ this.expression = `${this.wrap(this.expression)} * ${value}`;
28
+ return this;
29
+ }
30
+ div(value) {
31
+ this.expression = `${this.wrap(this.expression)} / ${value}`;
32
+ return this;
33
+ }
34
+ build() {
35
+ return `calc(${this.expression})`;
36
+ }
37
+ }
38
+ /**
39
+ * Entry point for building CSS `calc()` expressions. Pass an initial numeric value
40
+ * and optional unit (default `'px'`), then chain `.add()`, `.sub()`, `.mult()`, `.div()`,
41
+ * and finally call `.build()` to get the complete string.
42
+ */
43
+ export const calc = (base, unit = 'px') => new CalcBuilder(base, unit);
44
+ //# sourceMappingURL=calc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calc.js","sourceRoot":"","sources":["../../src/lib/calc.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,WAAW;IAGf,YAAY,OAAe,EAAE,OAAa,IAAI;QAC5C,IAAI,CAAC,UAAU,GAAG,GAAG,OAAO,GAAG,IAAI,EAAE,CAAA;IACvC,CAAC;IAEO,IAAI,CAAC,KAAa;QACxB,OAAO,IAAI,KAAK,GAAG,CAAA;IACrB,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,OAAa,IAAI;QAClC,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,IAAI,EAAE,CAAA;QAC7B,IAAI,CAAC,UAAU,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;QACrE,OAAO,IAAI,CAAA;IACb,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,OAAa,IAAI;QAClC,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,IAAI,EAAE,CAAA;QAC7B,IAAI,CAAC,UAAU,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;QACrE,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,CAAC,KAAa;QAChB,IAAI,CAAC,UAAU,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,EAAE,CAAA;QAC5D,OAAO,IAAI,CAAA;IACb,CAAC;IAED,GAAG,CAAC,KAAa;QACf,IAAI,CAAC,UAAU,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,EAAE,CAAA;QAC5D,OAAO,IAAI,CAAA;IACb,CAAC;IAED,KAAK;QACH,OAAO,QAAQ,IAAI,CAAC,UAAU,GAAG,CAAA;IACnC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,OAAa,IAAI,EAAE,EAAE,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA"}
@@ -0,0 +1,58 @@
1
+ import { themeStore } from '../theme';
2
+ /**
3
+ * Symbol used to attach a context-aware factory function to a styles proxy.
4
+ * `CodeleapStyleRegistry.registerVariants` reads this symbol from each entry to
5
+ * identify which variants require a `ComponentContext` at resolution time.
6
+ * Not intended for direct use by consumers.
7
+ */
8
+ export const CONTEXT_FACTORY_SYMBOL = Symbol('contextFactory');
9
+ /**
10
+ * Creates a reactive styles object that automatically updates when theme changes.
11
+ * Uses a proxy to re-compute styles on each access, ensuring theme changes are reflected.
12
+ *
13
+ * @template K - Style keys (extends string)
14
+ * @template V - Additional value type (extends AnyRecord)
15
+ * @param {StylesShape<K, V> | ((theme: ITheme) => StylesShape<K, V>)} styles - Static styles object or function that receives theme
16
+ * @returns {StylesShape<K, V>} Proxied styles object that recomputes on theme changes
17
+ */
18
+ export function createStyles(styles) {
19
+ const compute = () => {
20
+ const current = themeStore.theme;
21
+ if (typeof styles === 'function') {
22
+ return !current ? {} : styles(current);
23
+ }
24
+ else {
25
+ return styles;
26
+ }
27
+ };
28
+ // We use a proxy here so that the color scheme is recomputed every time the
29
+ // theme changes. This is necessary because the theme is a singleton which does not cause
30
+ // a re-render when it changes. The end-user will only have to worry about remounting the root component
31
+ // when the theme changes in order to get the new color scheme due to this proxy.
32
+ return new Proxy(compute(), {
33
+ get(target, prop) {
34
+ return compute()[prop];
35
+ },
36
+ });
37
+ }
38
+ /**
39
+ * Like `createStyles`, but the factory also receives a `ComponentContext` so that
40
+ * individual style values can vary based on runtime boolean/numeric state (e.g.,
41
+ * `isDisabled`, `isSelected`). The resulting proxy exposes a `CONTEXT_FACTORY_SYMBOL`
42
+ * getter so the registry can invoke the factory with the actual context at render time.
43
+ * Use this instead of `createStyles` when variant styles depend on component state.
44
+ */
45
+ export function createStylesWithContext(styles) {
46
+ const compute = (context = {}) => {
47
+ const current = themeStore.theme;
48
+ return !current ? {} : styles(current, context);
49
+ };
50
+ return new Proxy(compute(), {
51
+ get(target, prop) {
52
+ if (prop === CONTEXT_FACTORY_SYMBOL)
53
+ return styles;
54
+ return compute()[prop];
55
+ },
56
+ });
57
+ }
58
+ //# sourceMappingURL=createStyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createStyles.js","sourceRoot":"","sources":["../../src/lib/createStyles.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAMrC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAE9D;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAkE;IAElE,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAA;QAEhC,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;YACjC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAuB,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAC7D,CAAC;aAAM,CAAC;YACN,OAAO,MAAM,CAAA;QACf,CAAC;IACH,CAAC,CAAA;IAED,4EAA4E;IAC5E,yFAAyF;IACzF,wGAAwG;IACxG,iFAAiF;IACjF,OAAO,IAAI,KAAK,CAAC,OAAO,EAAuB,EAAE;QAC/C,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,OAAQ,OAAO,EAA0B,CAAC,IAAc,CAAC,CAAA;QAC3D,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAwD;IAExD,MAAM,OAAO,GAAG,CAAC,UAAa,EAAO,EAAE,EAAE;QACvC,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAA;QAChC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAuB,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACtE,CAAC,CAAA;IAED,OAAO,IAAI,KAAK,CAAC,OAAO,EAAuB,EAAE;QAC/C,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,IAAI,IAAI,KAAK,sBAAsB;gBAAE,OAAO,MAAM,CAAA;YAClD,OAAQ,OAAO,EAA0B,CAAC,IAAc,CAAC,CAAA;QAC3D,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,143 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { borderCreator, createMediaQueries, defaultVariants, spacingFactory } from '../variants';
13
+ import { minifier, multiplierProperty } from '../tools';
14
+ import { themeStore } from '../theme';
15
+ import { applyColorSchemeToDOM, buildCssVarProxy, flattenColorMap, DOM_COLOR_SCHEME_KEY } from './cssVariables';
16
+ const colorSchemeKey = '@styles.theme.colorScheme';
17
+ const alternateColorsKey = '@styles.theme.alternateColors';
18
+ /**
19
+ * Builds and registers the runtime `AppTheme<T>` object from a raw `Theme` definition.
20
+ *
21
+ * Key behaviours:
22
+ * - On web (`theme.isBrowser = true`), `theme.colors` is replaced with a CSS-var proxy
23
+ * so all color references become `var(--cl-<token>)` strings. The active scheme's
24
+ * real values are still accessible via `theme.currentSchemeColors`.
25
+ * - Persists the selected color scheme to storage and restores it on next load.
26
+ * Falls back to `getSystemColorScheme()` if no persisted value exists.
27
+ * - `alternateColors` from storage are merged with those in the theme definition
28
+ * (runtime-injected schemes take priority).
29
+ * - The constructed theme is immediately set on `themeStore` so hooks and the registry
30
+ * can read it synchronously during the same render pass.
31
+ *
32
+ * @param theme - Raw theme object (output of `validateTheme` or a compliant literal).
33
+ * @param themePersistor - Storage adapter for persisting color-scheme selection and injected schemes.
34
+ */
35
+ export const createTheme = (theme, themePersistor) => {
36
+ var _a, _b, _c, _d, _e;
37
+ const { colors, breakpoints, presets, radius, stroke, size, effects, typography, icons, baseColors, values } = theme, otherThemeValues = __rest(theme, ["colors", "breakpoints", "presets", "radius", "stroke", "size", "effects", "typography", "icons", "baseColors", "values"]);
38
+ const persistor = {
39
+ get: (key) => {
40
+ const value = themePersistor.get(key);
41
+ if (!value)
42
+ return null;
43
+ return minifier.decompress(value);
44
+ },
45
+ set: (key, value) => {
46
+ return themePersistor.set(key, !value ? '' : minifier.compress(value));
47
+ },
48
+ getNoCompress: (key) => {
49
+ if (themePersistor.getNoCompress)
50
+ return themePersistor.getNoCompress(key);
51
+ if (typeof localStorage !== 'undefined')
52
+ return localStorage.getItem(key);
53
+ return null;
54
+ },
55
+ setNoCompress: (key, value) => {
56
+ if (themePersistor.setNoCompress)
57
+ return themePersistor.setNoCompress(key, value);
58
+ if (typeof localStorage !== 'undefined')
59
+ localStorage.setItem(key, value);
60
+ },
61
+ };
62
+ themeStore.setColorScheme((_c = (_a = persistor.get(colorSchemeKey)) !== null && _a !== void 0 ? _a : (_b = themePersistor.getSystemColorScheme) === null || _b === void 0 ? void 0 : _b.call(themePersistor)) !== null && _c !== void 0 ? _c : 'default');
63
+ const persistedAlternateColors = persistor.get(alternateColorsKey);
64
+ const alternateColors = Object.assign(Object.assign({}, (persistedAlternateColors !== null && persistedAlternateColors !== void 0 ? persistedAlternateColors : {})), otherThemeValues === null || otherThemeValues === void 0 ? void 0 : otherThemeValues.alternateColors);
65
+ themeStore.setAlternateColorsScheme(alternateColors);
66
+ // On web: build CSS var proxy once — theme.colors returns var(--cl-X) strings.
67
+ // On RN (isBrowser falsy): keep raw RGBA values as before.
68
+ const cssVarColors = theme.isBrowser ? buildCssVarProxy(colors) : colors;
69
+ // Apply persisted scheme to DOM immediately (browser-only, no-op on server/RN)
70
+ applyColorSchemeToDOM((_d = persistor.getNoCompress(DOM_COLOR_SCHEME_KEY)) !== null && _d !== void 0 ? _d : 'default');
71
+ const baseSpacing = (_e = theme.baseSpacing) !== null && _e !== void 0 ? _e : 1;
72
+ const themeObj = Object.assign(Object.assign({}, otherThemeValues), { get alternateColors() {
73
+ return themeStore.alternateColorsScheme;
74
+ },
75
+ baseColors,
76
+ currentColorScheme() {
77
+ return themeStore.colorScheme;
78
+ }, breakpoints: breakpoints !== null && breakpoints !== void 0 ? breakpoints : {},
79
+ // On web: var(--cl-X) strings — browser CSS handles color switching.
80
+ // On RN: raw RGBA values, scheme-reactive as before.
81
+ colors: cssVarColors,
82
+ // Always the active scheme's real RGBA values — use when you need the actual color in JS.
83
+ get currentSchemeColors() {
84
+ var _a, _b;
85
+ const colorScheme = (_a = themeStore.colorScheme) !== null && _a !== void 0 ? _a : 'default';
86
+ if (colorScheme === 'default')
87
+ return colors;
88
+ const scheme = (_b = themeStore.alternateColorsScheme) === null || _b === void 0 ? void 0 : _b[colorScheme];
89
+ if (!scheme) {
90
+ console.warn(`Color scheme ${colorScheme} not found in theme`);
91
+ }
92
+ return (scheme !== null && scheme !== void 0 ? scheme : colors);
93
+ },
94
+ getCssVariables(schemeName) {
95
+ var _a, _b;
96
+ const map = !schemeName || schemeName === 'default'
97
+ ? colors
98
+ : (_b = (_a = themeStore.alternateColorsScheme) === null || _a === void 0 ? void 0 : _a[schemeName]) !== null && _b !== void 0 ? _b : colors;
99
+ return flattenColorMap(map);
100
+ },
101
+ setColorScheme(colorScheme) {
102
+ var _a;
103
+ const hasScheme = colorScheme === 'default' ? true : !!((_a = themeStore.alternateColorsScheme) === null || _a === void 0 ? void 0 : _a[colorScheme]);
104
+ if (!hasScheme) {
105
+ console.warn(`Color scheme ${colorScheme} not found in theme`);
106
+ return;
107
+ }
108
+ themeStore.setColorScheme(colorScheme);
109
+ persistor.set(colorSchemeKey, colorScheme);
110
+ // Store uncompressed for the FOUC prevention script (lz can't run inline)
111
+ persistor.setNoCompress(DOM_COLOR_SCHEME_KEY, colorScheme);
112
+ applyColorSchemeToDOM(colorScheme);
113
+ },
114
+ injectColorScheme(name, colorMap) {
115
+ themeStore.injectColorScheme(name, colorMap);
116
+ const persistedAlternateColors = persistor.get(alternateColorsKey);
117
+ const unpersistedAlternateColors = Object.assign(Object.assign({}, (persistedAlternateColors !== null && persistedAlternateColors !== void 0 ? persistedAlternateColors : {})), { [name]: colorMap });
118
+ persistor.set(alternateColorsKey, unpersistedAlternateColors);
119
+ },
120
+ ejectColorScheme(name) {
121
+ themeStore.ejectColorScheme(name);
122
+ const persistedAlternateColors = persistor.get(alternateColorsKey);
123
+ if (name in persistedAlternateColors) {
124
+ delete persistedAlternateColors[name];
125
+ }
126
+ persistor.set(alternateColorsKey, persistedAlternateColors);
127
+ },
128
+ baseSpacing, value: (n = 1) => baseSpacing * n, spacing: Object.assign(Object.assign(Object.assign(Object.assign({ value: (n = 1) => baseSpacing * n, gap: multiplierProperty(baseSpacing, 'gap') }, spacingFactory(baseSpacing, 'padding')), spacingFactory(baseSpacing, 'margin')), spacingFactory(baseSpacing, 'p', true)), spacingFactory(baseSpacing, 'm', true)), inset: {
129
+ top: multiplierProperty(baseSpacing, 'top'),
130
+ bottom: multiplierProperty(baseSpacing, 'bottom'),
131
+ left: multiplierProperty(baseSpacing, 'left'),
132
+ right: multiplierProperty(baseSpacing, 'right'),
133
+ }, presets: Object.assign(Object.assign({}, defaultVariants), presets), radius: radius !== null && radius !== void 0 ? radius : {}, stroke: stroke !== null && stroke !== void 0 ? stroke : {}, size: size !== null && size !== void 0 ? size : {}, effects: effects !== null && effects !== void 0 ? effects : {}, media: createMediaQueries(breakpoints), border: borderCreator, typography: typography !== null && typography !== void 0 ? typography : {}, icons: icons, values: values !== null && values !== void 0 ? values : {}, sized: (size) => {
134
+ const value = typeof size == 'number' ? size * baseSpacing : size;
135
+ return {
136
+ width: value,
137
+ height: value,
138
+ };
139
+ } });
140
+ themeStore.setTheme(themeObj);
141
+ return themeObj;
142
+ };
143
+ //# sourceMappingURL=createTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTheme.js","sourceRoot":"","sources":["../../src/lib/createTheme.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAChG,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAU/G,MAAM,cAAc,GAAG,2BAA2B,CAAA;AAClD,MAAM,kBAAkB,GAAG,+BAA+B,CAAA;AAE1D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAkB,KAAQ,EAAE,cAA8B,EAAe,EAAE;;IACpG,MAAM,EACJ,MAAM,EACN,WAAW,EACX,OAAO,EACP,MAAM,EACN,MAAM,EACN,IAAI,EACJ,OAAO,EACP,UAAU,EACV,KAAK,EACL,UAAU,EACV,MAAM,KAEJ,KAAK,EADJ,gBAAgB,UACjB,KAAK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IAAI,GAAI,EAAE,EAEhB,OAAO,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,EAEtB,KAAK,EAAE,kBAAkB,CAAC,WAAW,CAAC,EAEtC,MAAM,EAAE,aAAa,EAErB,UAAU,EAAE,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,EAAE,EAE5B,KAAK,EAAE,KAAK,EAEZ,MAAM,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,EAEpB,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;YACd,MAAM,KAAK,GAAG,OAAO,IAAI,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAA;YAEjE,OAAO;gBACL,KAAK,EAAE,KAAK;gBACZ,MAAM,EAAE,KAAK;aACd,CAAA;QACH,CAAC,GACa,CAAA;IAEhB,UAAU,CAAC,QAAQ,CAAC,QAA6B,CAAC,CAAA;IAElD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * CSS custom-property prefix used for all codeleap design-token variables.
3
+ * Color tokens are injected as `--cl-<tokenPath>` on `:root` (or a scheme-specific
4
+ * `[data-color-scheme]` selector). Changing this value after tokens are injected
5
+ * will break existing CSS that references `var(--cl-*)`.
6
+ */
7
+ export const CSS_VAR_PREFIX = '--cl-';
8
+ /**
9
+ * Storage key used to persist the active color scheme name in an uncompressed format
10
+ * (plain string, not LZ-encoded). Stored separately so a lightweight inline script
11
+ * can read it before React hydrates and set `data-color-scheme` on `<html>` to prevent
12
+ * a flash of the wrong color scheme (FOUC).
13
+ */
14
+ export const DOM_COLOR_SCHEME_KEY = '@styles.dom.colorScheme';
15
+ /**
16
+ * Recursively flattens a nested color token object into a flat map of CSS custom-property
17
+ * names to their values. Nesting levels are joined with `-` (e.g., `{ primary: { solid: '#fff' } }`
18
+ * → `{ '--cl-primary-solid': '#fff' }`). Non-string leaf values are silently skipped.
19
+ */
20
+ export function flattenColorMap(obj, path = '', prefix = CSS_VAR_PREFIX) {
21
+ const result = {};
22
+ for (const [key, value] of Object.entries(obj)) {
23
+ const cssPath = path ? `${path}-${key}` : key;
24
+ if (typeof value === 'string') {
25
+ result[`${prefix}${cssPath}`] = value;
26
+ }
27
+ else if (value && typeof value === 'object') {
28
+ Object.assign(result, flattenColorMap(value, cssPath, prefix));
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+ /**
34
+ * Recursively replaces every string leaf in `obj` with a `var(--cl-<path>)` reference,
35
+ * preserving the original object shape. Used on web to replace raw color values with
36
+ * CSS variable references so that color-scheme switching via `data-color-scheme` CSS
37
+ * selectors works without JavaScript re-renders.
38
+ */
39
+ export function buildCssVarProxy(obj, path = '', prefix = CSS_VAR_PREFIX) {
40
+ if (typeof obj !== 'object' || obj === null)
41
+ return obj;
42
+ const result = {};
43
+ for (const [key, value] of Object.entries(obj)) {
44
+ const cssPath = path ? `${path}-${key}` : key;
45
+ if (typeof value === 'string') {
46
+ result[key] = `var(${prefix}${cssPath})`;
47
+ }
48
+ else if (value && typeof value === 'object') {
49
+ result[key] = buildCssVarProxy(value, cssPath, prefix);
50
+ }
51
+ else {
52
+ result[key] = value;
53
+ }
54
+ }
55
+ return result;
56
+ }
57
+ /**
58
+ * Sets or removes `data-color-scheme` on `document.documentElement` to trigger the
59
+ * matching CSS selector that applies alternate-scheme custom-property overrides.
60
+ * The `'default'` scheme removes the attribute entirely so the `:root` base variables
61
+ * apply. No-ops on non-browser environments (SSR, React Native).
62
+ */
63
+ export function applyColorSchemeToDOM(colorScheme) {
64
+ if (typeof document === 'undefined')
65
+ return;
66
+ if (colorScheme === 'default') {
67
+ delete document.documentElement.dataset.colorScheme;
68
+ }
69
+ else {
70
+ document.documentElement.dataset.colorScheme = colorScheme;
71
+ }
72
+ }
73
+ //# sourceMappingURL=cssVariables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cssVariables.js","sourceRoot":"","sources":["../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CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAA;QAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,MAAM,GAAG,OAAO,GAAG,CAAA;QAC1C,CAAC;aAAM,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9C,MAAM,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACrB,CAAC;IACH,CAAC;IACD,OAAO,MAAW,CAAA;AACpB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,WAAmB;IACvD,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAM;IAC3C,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,CAAA;IACrD,CAAC;SAAM,CAAC;QACN,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,GAAG,WAAW,CAAA;IAC5D,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { createStyles, createStylesWithContext, CONTEXT_FACTORY_SYMBOL } from './createStyles';
2
+ export { createTheme } from './createTheme';
3
+ export { calc } from './calc';
4
+ export { flattenColorMap, buildCssVarProxy, applyColorSchemeToDOM, CSS_VAR_PREFIX, DOM_COLOR_SCHEME_KEY } from './cssVariables';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAC9F,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,38 @@
1
+ import { colorTools } from '../tools';
2
+ const lightnesses = [95, 85, 75, 60, 45, 30, 27, 21, 16, 10];
3
+ const defaultLightnessMap = Object.fromEntries(lightnesses.map((l, i) => {
4
+ const step = ((i + 1) * 100).toString();
5
+ return [step, l];
6
+ }));
7
+ const alphas = [0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90];
8
+ const defaultAlphasMap = Object.fromEntries(alphas.map((a, i) => {
9
+ const step = ((i + 1) * 100).toString();
10
+ return [step, a];
11
+ }));
12
+ /**
13
+ * Derives a 20-token color ramp from a single anchor hex color.
14
+ *
15
+ * Produces two groups of tokens:
16
+ * - **10 solid tokens** (`{prefix}Solid100` … `{prefix}Solid1000`) — vary the lightness
17
+ * of the anchor's hue/saturation from ~95 L (lightest) to ~10 L (darkest).
18
+ * - **10 transparent tokens** (`{prefix}Transparent100` … `{prefix}Transparent1000`) —
19
+ * keep the anchor's exact RGB channels but increase alpha from 0.05 to 0.90.
20
+ *
21
+ * Default lightness steps: `[95, 85, 75, 60, 45, 30, 27, 21, 16, 10]`.
22
+ * Default alpha steps: `[0.05, 0.10, …, 0.90]`.
23
+ * Both can be overridden by passing custom maps (step → value).
24
+ */
25
+ export function generateColorScheme(anchorHex, prefix = 'primary', lightnesses = defaultLightnessMap, alphas = defaultAlphasMap) {
26
+ const { h, s } = colorTools.hexToHSL(anchorHex);
27
+ const baseRGB = colorTools.hexToRGB(anchorHex);
28
+ const scheme = {};
29
+ Object.entries(lightnesses).forEach(([step, lightness]) => {
30
+ const rgb = colorTools.hslToRGB(h, s, lightness);
31
+ scheme[`${prefix}Solid${step}`] = `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 1.00)`;
32
+ });
33
+ Object.entries(alphas).forEach(([step, alpha]) => {
34
+ scheme[`${prefix}Transparent${step}`] = `rgba(${baseRGB.r}, ${baseRGB.g}, ${baseRGB.b}, ${alpha.toFixed(2)})`;
35
+ });
36
+ return scheme;
37
+ }
38
+ //# sourceMappingURL=generateColorScheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateColorScheme.js","sourceRoot":"","sources":["../../src/theme/generateColorScheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAGrC,MAAM,WAAW,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;AAE5D,MAAM,mBAAmB,GAAG,MAAM,CAAC,WAAW,CAC5C,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;IACvB,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAA;IACvC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;AAClB,CAAC,CAAC,CACH,CAAA;AAED,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;AAE3E,MAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,CACzC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;IAClB,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAA;IACvC,OAAO,CAAC,I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 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA"}
@@ -0,0 +1,139 @@
1
+ import { map, computed, atom } from 'nanostores';
2
+ /**
3
+ * Global theme store that manages application theme, color schemes, and variants.
4
+ * Uses nanostores for reactive state management.
5
+ */
6
+ export class ThemeStore {
7
+ constructor() {
8
+ this.alternateColorsSchemeStore = map({});
9
+ this.colorSchemeStore = atom(null);
10
+ this.themeStore = atom(null);
11
+ this.variantsStore = map({});
12
+ }
13
+ /**
14
+ * Gets the current theme.
15
+ * @returns {ITheme | null} Current theme or null if not set
16
+ */
17
+ get theme() {
18
+ return this.themeStore.get();
19
+ }
20
+ /**
21
+ * Gets the current theme with typed interface.
22
+ * @returns {AppTheme<Theme>} Current theme cast to AppTheme type
23
+ */
24
+ get themeTyped() {
25
+ const theme = this.themeStore.get();
26
+ return theme ? theme : null;
27
+ }
28
+ /**
29
+ * Gets the current color scheme name.
30
+ * @returns {string | null} Current color scheme name or null if not set
31
+ */
32
+ get colorScheme() {
33
+ return this.colorSchemeStore.get();
34
+ }
35
+ /**
36
+ * Gets the current variants configuration.
37
+ * @returns {IAppVariants} Current variants object
38
+ */
39
+ get variants() {
40
+ return this.variantsStore.get();
41
+ }
42
+ /**
43
+ * Gets all alternate color schemes.
44
+ * @returns {{ [key: string]: ColorMap }} Object containing all alternate color schemes
45
+ */
46
+ get alternateColorsScheme() {
47
+ var _a;
48
+ return (_a = this.alternateColorsSchemeStore.get()) !== null && _a !== void 0 ? _a : {};
49
+ }
50
+ /**
51
+ * Sets the variants configuration.
52
+ * @template T
53
+ * @param {T} variants - Variants configuration to set
54
+ */
55
+ setVariants(variants) {
56
+ this.variantsStore.set(variants);
57
+ }
58
+ /**
59
+ * Sets the current color scheme.
60
+ * @param {string} colorScheme - Color scheme name to set
61
+ */
62
+ setColorScheme(colorScheme) {
63
+ this.colorSchemeStore.set(colorScheme);
64
+ }
65
+ /**
66
+ * Sets the current theme.
67
+ * @param {ITheme} theme - Theme object to set
68
+ */
69
+ setTheme(theme) {
70
+ this.themeStore.set(theme);
71
+ }
72
+ /**
73
+ * Sets all alternate color schemes.
74
+ * @param {{ [key: string]: ColorMap }} colors - Object containing color schemes
75
+ */
76
+ setAlternateColorsScheme(colors) {
77
+ this.alternateColorsSchemeStore.set(colors);
78
+ }
79
+ /**
80
+ * Gets the base color scheme colors (first available scheme).
81
+ * @private
82
+ * @returns {ColorMap} Base color scheme colors
83
+ */
84
+ getBaseSchemeColors() {
85
+ var _a, _b;
86
+ const alternateColors = (_a = this.alternateColorsScheme) !== null && _a !== void 0 ? _a : {};
87
+ const colorSchemeKeys = Object.keys(alternateColors);
88
+ if (colorSchemeKeys.length === 0) {
89
+ return {};
90
+ }
91
+ return (_b = alternateColors[colorSchemeKeys[0]]) !== null && _b !== void 0 ? _b : {};
92
+ }
93
+ /**
94
+ * Injects a new color scheme, merging with base scheme colors.
95
+ * @param {string} name - Name of the color scheme
96
+ * @param {ColorMap} colors - Color map to inject
97
+ * @returns {{ [key: string]: ColorMap }} Updated alternate colors object
98
+ */
99
+ injectColorScheme(name, colors) {
100
+ var _a;
101
+ const baseSchemeColors = this.getBaseSchemeColors();
102
+ const currentAlternateColors = (_a = this.alternateColorsScheme) !== null && _a !== void 0 ? _a : {};
103
+ const alternateColors = Object.assign(Object.assign({}, currentAlternateColors), { [name]: Object.assign(Object.assign({}, baseSchemeColors), colors) });
104
+ this.setAlternateColorsScheme(alternateColors);
105
+ return alternateColors;
106
+ }
107
+ /**
108
+ * Removes a color scheme by name.
109
+ * @param {string} name - Name of the color scheme to remove
110
+ * @returns {{ [key: string]: ColorMap }} Updated alternate colors object
111
+ */
112
+ ejectColorScheme(name) {
113
+ var _a;
114
+ const currentAlternateColors = (_a = this.alternateColorsScheme) !== null && _a !== void 0 ? _a : {};
115
+ if (name in currentAlternateColors) {
116
+ delete currentAlternateColors[name];
117
+ }
118
+ this.setAlternateColorsScheme(currentAlternateColors);
119
+ return currentAlternateColors;
120
+ }
121
+ }
122
+ /**
123
+ * Global theme store instance.
124
+ */
125
+ export const themeStore = new ThemeStore();
126
+ /**
127
+ * Derived nanostores `computed` that combines `themeStore` and `colorSchemeStore`
128
+ * into a single `ThemeState` atom. Components subscribe to this via `useTheme`
129
+ * so they re-render only when either the theme object or the active color scheme
130
+ * changes — not on every `ThemeStore` method call.
131
+ */
132
+ export const themeStoreComputed = computed([
133
+ themeStore.themeStore,
134
+ themeStore.colorSchemeStore,
135
+ ], (theme, colorScheme) => ({
136
+ theme: theme,
137
+ colorScheme,
138
+ }));
139
+ //# sourceMappingURL=themeStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themeStore.js","sourceRoot":"","sources":["../../src/theme/themeStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAUhD;;;GAGG;AACH,MAAM,OAAO,UAAU;IAAvB;QACmB,+BAA0B,GAAG,GAAG,CAA8B,EAAE,CAAC,CAAA;QAElE,qBAAgB,GAAG,IAAI,CAAgB,IAAI,CAAC,CAAA;QAE5C,eAAU,GAAG,IAAI,CAAgB,IAAI,CAAC,CAAA;QAEtC,kBAAa,GAAG,GAAG,CAAe,EAAkB,CAAC,CAAA;IAoIvE,CAAC;IAlIC;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,CAAA;IAC9B,CAAC;IAED;;;OAGG;IACH,IAAI,UAAU;QACZ,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,CAAA;QACnC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAmC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC3D,CAAC;IAED;;;OAGG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,gBAAgB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,CAAA;QAE/D,MAAM,eAAe,mCAChB,sBAAsB,KAEzB,CAAC,IAAI,CAAC,kCACD,gBAAgB,GAChB,MAAM,IAEZ,CAAA;QAED,IAAI,CAAC,wBAAwB,CAAC,eAAe,CAAC,CAAA;QAE9C,OAAO,eAAe,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,IAAW;;QAC1B,MAAM,sBAAsB,GAAG,MAAA,IAAI,CAAC,qBAAqB,mCAAI,EAAE,CAAA;QAE/D,IAAI,IAAI,IAAI,sBAAsB,EAAE,CAAC;YACnC,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAA;QACrC,CAAC;QAED,IAAI,CAAC,wBAAwB,CAAC,sBAAsB,CAAC,CAAA;QAErD,OAAO,sBAAsB,CAAA;IAC/B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAA;AAE1C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACzC,UAAU,CAAC,UAAU;IACrB,UAAU,CAAC,gBAAgB;CAC5B,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;IAC1B,KAAK,EAAE,KAAmC;IAC1C,WAAW;CACZ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Validates and normalizes a theme object.
3
+ * Ensures all alternate color schemes include the same keys as `colors`,
4
+ * and merges `baseColors` into `colors` and `alternateColors`.
5
+ *
6
+ * @template T extends Theme
7
+ * @param {T} theme - The theme to validate.
8
+ * @throws {Error} If an alternate scheme is missing a required color.
9
+ * @returns {T & {
10
+ * alternateColors: Record<string, Record<string, string>>,
11
+ * colors: Record<string, string>
12
+ * }} The validated theme with merged colors.
13
+ */
14
+ export function validateTheme(theme) {
15
+ const baseColors = theme.baseColors;
16
+ const colors = theme.colors;
17
+ const alternateColors = theme.alternateColors;
18
+ const requiredColors = Object.keys(colors);
19
+ const mergedAlternateColors = {};
20
+ if (alternateColors) {
21
+ for (const [colorSchemeName, colorSchemeColors] of Object.entries(alternateColors)) {
22
+ const colorSchemeColorNames = Object.keys(colorSchemeColors);
23
+ for (const requiredColor of requiredColors) {
24
+ if (!colorSchemeColorNames.includes(requiredColor)) {
25
+ throw new Error(`Alternate color scheme ${colorSchemeName} is missing color ${requiredColor}`);
26
+ }
27
+ }
28
+ mergedAlternateColors[colorSchemeName] = Object.assign(Object.assign({}, baseColors), colorSchemeColors);
29
+ }
30
+ }
31
+ return Object.assign(Object.assign({}, theme), { alternateColors: mergedAlternateColors, colors: Object.assign(Object.assign({}, baseColors), colors) });
32
+ }
33
+ //# sourceMappingURL=validateTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateTheme.js","sourceRoot":"","sources":["../../src/theme/validateTheme.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAkB,KAAQ;IACrD,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAA;IAEnC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;IAE3B,MAAM,eAAe,GAAG,KAAK,CAAC,eAAe,CAAA;IAE7C,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAE1C,MAAM,qBAAqB,GAAwB,EAAE,CAAA;IAErD,IAAI,eAAe,EAAE,CAAC;QACpB,KAAK,MAAM,CAAC,eAAe,EAAE,iBAAiB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;YACnF,MAAM,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;YAE5D,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE,CAAC;gBAC3C,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;oBACnD,MAAM,IAAI,KAAK,CAAC,0BAA0B,eAAe,qBAAqB,aAAa,EAAE,CAAC,CAAA;gBAChG,CAAC;YACH,CAAC;YAED,qBAAqB,CAAC,eAAe,CAAC,mCACjC,UAAU,GACV,iBAAiB,CACrB,CAAA;QACH,CAAC;IACH,CAAC;IAED,uCACK,KAAK,KACR,eAAe,EAAE,qBAAqB,EACtC,MAAM,kCACD,UAAU,GACV,MAAM,KAEZ;AACH,CAAC"}