@cdx-ui/styles 0.0.1-beta.53 → 0.0.1-beta.55

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 (46) hide show
  1. package/css/theme.css +2 -2
  2. package/lib/commonjs/applyThemeOverride.js +154 -0
  3. package/lib/commonjs/applyThemeOverride.js.map +1 -0
  4. package/lib/commonjs/index.js +69 -73
  5. package/lib/commonjs/index.js.map +1 -1
  6. package/lib/commonjs/palette.js +180 -0
  7. package/lib/commonjs/palette.js.map +1 -0
  8. package/lib/commonjs/theming.js +218 -0
  9. package/lib/commonjs/theming.js.map +1 -0
  10. package/lib/commonjs/types.js +75 -0
  11. package/lib/commonjs/types.js.map +1 -0
  12. package/lib/module/applyThemeOverride.js +149 -0
  13. package/lib/module/applyThemeOverride.js.map +1 -0
  14. package/lib/module/index.js +8 -62
  15. package/lib/module/index.js.map +1 -1
  16. package/lib/module/palette.js +176 -0
  17. package/lib/module/palette.js.map +1 -0
  18. package/lib/module/theming.js +202 -0
  19. package/lib/module/theming.js.map +1 -0
  20. package/lib/module/types.js +71 -0
  21. package/lib/module/types.js.map +1 -0
  22. package/lib/runtime/prestige-vs-default.json +1 -0
  23. package/lib/runtime/pulse-vs-default.json +1 -0
  24. package/lib/runtime/token-to-css-var.json +632 -0
  25. package/lib/typescript/applyThemeOverride.d.ts +26 -0
  26. package/lib/typescript/applyThemeOverride.d.ts.map +1 -0
  27. package/lib/typescript/index.d.ts +7 -89
  28. package/lib/typescript/index.d.ts.map +1 -1
  29. package/lib/typescript/palette.d.ts +48 -0
  30. package/lib/typescript/palette.d.ts.map +1 -0
  31. package/lib/typescript/theming.d.ts +40 -0
  32. package/lib/typescript/theming.d.ts.map +1 -0
  33. package/lib/typescript/types.d.ts +90 -0
  34. package/lib/typescript/types.d.ts.map +1 -0
  35. package/package.json +27 -8
  36. package/runtime/prestige-vs-default.json +1 -0
  37. package/runtime/pulse-vs-default.json +1 -0
  38. package/runtime/token-to-css-var.json +632 -0
  39. package/src/__tests__/applyThemeOverride.test.ts +488 -0
  40. package/src/__tests__/generateColorScale.test.ts +202 -0
  41. package/src/__tests__/theming.test.ts +525 -0
  42. package/src/applyThemeOverride.ts +139 -0
  43. package/src/index.ts +33 -103
  44. package/src/palette.ts +226 -0
  45. package/src/theming.ts +230 -0
  46. package/src/types.ts +112 -0
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "DEFAULT_PRESET", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _applyThemeOverride.DEFAULT_PRESET;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "applyThemeOverride", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _applyThemeOverride.applyThemeOverride;
16
+ }
17
+ });
18
+ exports.isSchemaVersionSupported = isSchemaVersionSupported;
19
+ exports.presetPatchToUniwindMaps = presetPatchToUniwindMaps;
20
+ exports.themeOverrideToUniwindMaps = themeOverrideToUniwindMaps;
21
+ var _palette = require("./palette");
22
+ var _types = require("./types");
23
+ var _applyThemeOverride = require("./applyThemeOverride");
24
+ // ---------------------------------------------------------------------------
25
+ // Re-export orchestrator
26
+ // ---------------------------------------------------------------------------
27
+
28
+ // ---------------------------------------------------------------------------
29
+ // Types
30
+ // ---------------------------------------------------------------------------
31
+
32
+ /** Per-mode CSS variable maps ready for `Uniwind.updateCSSVariables`. */
33
+
34
+ /** Runtime map: token dot-paths → CSS custom property names. */
35
+
36
+ // ---------------------------------------------------------------------------
37
+ // Schema version gate
38
+ // ---------------------------------------------------------------------------
39
+
40
+ /**
41
+ * Check whether a `ThemeOverride`'s schema version is supported by the current
42
+ * build of `@cdx-ui/styles`.
43
+ */
44
+ function isSchemaVersionSupported(override) {
45
+ const version = override.$extensions['com.forge.ui.themeOverride'].schemaVersion;
46
+ return _types.SUPPORTED_OVERRIDE_SCHEMA_VERSIONS.includes(version);
47
+ }
48
+
49
+ // ---------------------------------------------------------------------------
50
+ // DTCG tree walker
51
+ // ---------------------------------------------------------------------------
52
+
53
+ function isTokenValue(node) {
54
+ return typeof node === 'object' && node !== null && '$value' in node && '$type' in node;
55
+ }
56
+
57
+ /**
58
+ * Recursively walk a nested DTCG object and collect all `$value` leaves with
59
+ * their full dot-path.
60
+ */
61
+ function flattenDtcg(node, prefix, result) {
62
+ for (const key of Object.keys(node)) {
63
+ if (key.startsWith('$')) continue;
64
+ const child = node[key];
65
+ const path = prefix ? `${prefix}.${key}` : key;
66
+ if (isTokenValue(child)) {
67
+ result[path] = child.$value;
68
+ } else if (typeof child === 'object' && child !== null) {
69
+ flattenDtcg(child, path, result);
70
+ }
71
+ }
72
+ }
73
+
74
+ // ---------------------------------------------------------------------------
75
+ // Shared mode-bucketing
76
+ // ---------------------------------------------------------------------------
77
+
78
+ function bucketByMode(flatTokens, runtimeMap, runtimePlatform) {
79
+ const light = {};
80
+ const dark = {};
81
+ for (const [dotPath, value] of Object.entries(flatTokens)) {
82
+ const strValue = String(value);
83
+ if (dotPath.startsWith('modes.light.')) {
84
+ const cssVar = runtimeMap[dotPath];
85
+ if (cssVar) light[cssVar] = strValue;
86
+ } else if (dotPath.startsWith('modes.dark.')) {
87
+ const cssVar = runtimeMap[dotPath];
88
+ if (cssVar) dark[cssVar] = strValue;
89
+ } else if (dotPath.startsWith('platform.')) {
90
+ const segments = dotPath.split('.');
91
+ const platform = segments[1];
92
+ if (platform !== runtimePlatform) continue;
93
+ const cssVar = runtimeMap[dotPath];
94
+ if (cssVar) {
95
+ light[cssVar] = strValue;
96
+ dark[cssVar] = strValue;
97
+ }
98
+ } else {
99
+ const cssVar = runtimeMap[dotPath];
100
+ if (cssVar) {
101
+ light[cssVar] = strValue;
102
+ dark[cssVar] = strValue;
103
+ }
104
+ }
105
+ }
106
+ return {
107
+ light,
108
+ dark
109
+ };
110
+ }
111
+
112
+ // ---------------------------------------------------------------------------
113
+ // Preset patch → Uniwind maps
114
+ // ---------------------------------------------------------------------------
115
+
116
+ /**
117
+ * Convert a nested DTCG preset patch (sparse, `$type`/`$value` leaves) into
118
+ * per-mode CSS variable maps suitable for `Uniwind.updateCSSVariables`.
119
+ *
120
+ * @param patch - A sparse DTCG token object (preset patch).
121
+ * @param runtimeMap - The generated token-to-CSS-var mapping.
122
+ * @param runtimePlatform - Current platform (`'web' | 'ios' | 'android'`).
123
+ */
124
+ function presetPatchToUniwindMaps(patch, runtimeMap, runtimePlatform) {
125
+ const flat = {};
126
+ flattenDtcg(patch, '', flat);
127
+ return bucketByMode(flat, runtimeMap, runtimePlatform);
128
+ }
129
+
130
+ // ---------------------------------------------------------------------------
131
+ // FI override → Uniwind maps
132
+ // ---------------------------------------------------------------------------
133
+
134
+ /**
135
+ * Non-color input keys from INPUT_TOKEN_MAP whose token path does NOT start
136
+ * with `color.`. These are handled separately from palette generation.
137
+ */
138
+ const FONT_INPUT_ENTRIES = Object.entries(_types.INPUT_TOKEN_MAP).filter(([, tokenPath]) => !tokenPath.startsWith('color.'));
139
+
140
+ /**
141
+ * Convert a hybrid FI override (`ThemeOverride`) into per-mode CSS variable
142
+ * maps suitable for `Uniwind.updateCSSVariables`.
143
+ *
144
+ * Processing:
145
+ * 1. Generate palettes from color `inputs` (via S4).
146
+ * 2. Map font inputs to token paths.
147
+ * 3. For each mode, merge palette + fonts + explicit `overrides.{mode}` entries.
148
+ * 4. Map all token dot-paths to CSS variable names via runtime map.
149
+ *
150
+ * @param override - A `ThemeOverride` object.
151
+ * @param runtimeMap - The generated token-to-CSS-var mapping.
152
+ * @param runtimePlatform - Current platform (`'web' | 'ios' | 'android'`).
153
+ */
154
+ function themeOverrideToUniwindMaps(override, runtimeMap
155
+ // runtimePlatform: Platform,
156
+ ) {
157
+ const light = {};
158
+ const dark = {};
159
+ const inputs = override.inputs;
160
+ const overrides = override.overrides;
161
+ if (!inputs && !overrides) {
162
+ return {
163
+ light,
164
+ dark
165
+ };
166
+ }
167
+
168
+ // --- Palette generation from colour inputs ---
169
+ let paletteTokens = {};
170
+ if (inputs) {
171
+ paletteTokens = (0, _palette.generatePalettesFromInputs)(inputs);
172
+ }
173
+
174
+ // --- Font input mapping ---
175
+ const fontTokens = {};
176
+ if (inputs) {
177
+ for (const [inputKey, tokenPath] of FONT_INPUT_ENTRIES) {
178
+ const value = inputs[inputKey];
179
+ if (value !== undefined) {
180
+ fontTokens[tokenPath] = String(value);
181
+ }
182
+ }
183
+ }
184
+
185
+ // --- Merge per mode ---
186
+ const modes = ['light', 'dark'];
187
+ for (const mode of modes) {
188
+ const bucket = mode === 'light' ? light : dark;
189
+
190
+ // 1. Palette-generated primitives (mode-independent → both buckets)
191
+ for (const [dotPath, hexValue] of Object.entries(paletteTokens)) {
192
+ const cssVar = runtimeMap[dotPath];
193
+ if (cssVar) bucket[cssVar] = hexValue;
194
+ }
195
+
196
+ // 2. Font input mappings (mode-independent → both buckets)
197
+ for (const [tokenPath, value] of Object.entries(fontTokens)) {
198
+ const modePrefixed = `modes.${mode}.${tokenPath}`;
199
+ const cssVar = runtimeMap[modePrefixed] ?? runtimeMap[tokenPath];
200
+ if (cssVar) bucket[cssVar] = value;
201
+ }
202
+
203
+ // 3. Explicit per-mode overrides (wins on collision)
204
+ const modeOverrides = overrides?.[mode];
205
+ if (modeOverrides) {
206
+ for (const [dotPath, value] of Object.entries(modeOverrides)) {
207
+ const modePrefixed = `modes.${mode}.${dotPath}`;
208
+ const cssVar = runtimeMap[modePrefixed] ?? runtimeMap[dotPath];
209
+ if (cssVar) bucket[cssVar] = String(value);
210
+ }
211
+ }
212
+ }
213
+ return {
214
+ light,
215
+ dark
216
+ };
217
+ }
218
+ //# sourceMappingURL=theming.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_palette","require","_types","_applyThemeOverride","isSchemaVersionSupported","override","version","$extensions","schemaVersion","SUPPORTED_OVERRIDE_SCHEMA_VERSIONS","includes","isTokenValue","node","flattenDtcg","prefix","result","key","Object","keys","startsWith","child","path","$value","bucketByMode","flatTokens","runtimeMap","runtimePlatform","light","dark","dotPath","value","entries","strValue","String","cssVar","segments","split","platform","presetPatchToUniwindMaps","patch","flat","FONT_INPUT_ENTRIES","INPUT_TOKEN_MAP","filter","tokenPath","themeOverrideToUniwindMaps","inputs","overrides","paletteTokens","generatePalettesFromInputs","fontTokens","inputKey","undefined","modes","mode","bucket","hexValue","modePrefixed","modeOverrides"],"sourceRoot":"../../src","sources":["theming.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAcA,IAAAE,mBAAA,GAAAF,OAAA;AAJA;AACA;AACA;;AAKA;AACA;AACA;;AAEA;;AAMA;;AAGA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACO,SAASG,wBAAwBA,CAACC,QAAuB,EAAW;EACzE,MAAMC,OAAO,GAAGD,QAAQ,CAACE,WAAW,CAAC,4BAA4B,CAAC,CAACC,aAAa;EAChF,OAAOC,yCAAkC,CAACC,QAAQ,CAACJ,OAAO,CAAC;AAC7D;;AAEA;AACA;AACA;;AAEA,SAASK,YAAYA,CAACC,IAAa,EAAsB;EACvD,OAAO,OAAOA,IAAI,KAAK,QAAQ,IAAIA,IAAI,KAAK,IAAI,IAAI,QAAQ,IAAIA,IAAI,IAAI,OAAO,IAAIA,IAAI;AACzF;;AAEA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CAClBD,IAAgB,EAChBE,MAAc,EACdC,MAAuC,EACjC;EACN,KAAK,MAAMC,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACN,IAAI,CAAC,EAAE;IACnC,IAAII,GAAG,CAACG,UAAU,CAAC,GAAG,CAAC,EAAE;IAEzB,MAAMC,KAAK,GAAGR,IAAI,CAACI,GAAG,CAAC;IACvB,MAAMK,IAAI,GAAGP,MAAM,GAAG,GAAGA,MAAM,IAAIE,GAAG,EAAE,GAAGA,GAAG;IAE9C,IAAIL,YAAY,CAACS,KAAK,CAAC,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I,CAAC;IACvC,IAAII,aAAa,EAAE;MACjB,KAAK,MAAM,CAAC7B,OAAO,EAAEC,KAAK,CAAC,IAAIb,MAAM,CAACc,OAAO,CAAC2B,aAAa,CAAC,EAAE;QAC5D,MAAMD,YAAY,GAAG,SAASH,IAAI,IAAIzB,OAAO,EAAE;QAC/C,MAAMK,MAAM,GAAGT,UAAU,CAACgC,YAAY,CAAC,IAAIhC,UAAU,CAACI,OAAO,CAAC;QAC9D,IAAIK,MAAM,EAAEqB,MAAM,CAACrB,MAAM,CAAC,GAAGD,MAAM,CAACH,KAAK,CAAC;MAC5C;IACF;EACF;EAEA,OAAO;IAAEH,KAAK;IAAEC;EAAK,CAAC;AACxB","ignoreList":[]}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.presetFonts = exports.SUPPORTED_OVERRIDE_SCHEMA_VERSIONS = exports.OVERRIDE_SCHEMA_VERSION = exports.INPUT_TOKEN_MAP = void 0;
7
+ // ---------------------------------------------------------------------------
8
+ // Types
9
+ // ---------------------------------------------------------------------------
10
+
11
+ /** A DTCG token leaf node. */
12
+
13
+ /** Recursive token group — every non-leaf node in a theme object. */
14
+
15
+ /** The three built-in Forge UI theme presets. */
16
+
17
+ /** Theme metadata stored under `$extensions.com.forge.ui.theme`. */
18
+
19
+ /** Override metadata stored under `$extensions.com.forge.ui.themeOverride`. */
20
+
21
+ /**
22
+ * A complete Forge UI theme object (DTCG-compatible).
23
+ *
24
+ * Presets (Poise, Prestige, Pulse) are full theme objects. At runtime the
25
+ * build-time default preset is augmented by FI overrides via
26
+ * `applyThemeOverrides`.
27
+ */
28
+
29
+ /**
30
+ * A theme override using the hybrid input + semantic structure.
31
+ *
32
+ * - `inputs` — flat map of abstract FI-selected brand values (e.g.
33
+ * `brandPrimary`, `displayFont`). Palette generation expands these into
34
+ * full token scales at runtime.
35
+ * - `overrides` — per-mode flat maps of token dot-paths to resolved values
36
+ * for direct semantic token overrides beyond what inputs generate.
37
+ * - `$extensions` — required metadata including base preset and schema version.
38
+ */
39
+
40
+ // ---------------------------------------------------------------------------
41
+ // Constants
42
+ // ---------------------------------------------------------------------------
43
+
44
+ /** Current override schema version. Consuming apps gate compatibility on this. */
45
+ const OVERRIDE_SCHEMA_VERSION = exports.OVERRIDE_SCHEMA_VERSION = '1.0.0';
46
+
47
+ /**
48
+ * Schema versions that consuming apps accept. Includes the current version and
49
+ * may include the immediately prior version during transition windows.
50
+ * @see docs/internal/token-architecture/16-override-structure.md § 4
51
+ */
52
+ const SUPPORTED_OVERRIDE_SCHEMA_VERSIONS = exports.SUPPORTED_OVERRIDE_SCHEMA_VERSIONS = ['1.0.0'];
53
+
54
+ /**
55
+ * Schema-level mapping from known input keys to the token path pattern each
56
+ * affects. Used by override application (S5) to route inputs to the correct
57
+ * palette/token namespace. Distinct from the full runtime map (S3).
58
+ */
59
+ const INPUT_TOKEN_MAP = exports.INPUT_TOKEN_MAP = {
60
+ brandPrimary: 'color.brand',
61
+ accentPrimary: 'color.accent',
62
+ basePrimary: 'color.base',
63
+ displayFont: 'font.display'
64
+ };
65
+
66
+ /**
67
+ * Allowed display font families per preset, consumed by the theme editor for
68
+ * font selection and by consuming apps for validation.
69
+ */
70
+ const presetFonts = exports.presetFonts = {
71
+ poise: ['Crimson Pro', 'Bitter', 'DM Sans'],
72
+ prestige: ['Libre Caslon Text', 'Cormorant', 'Libre Franklin'],
73
+ pulse: ['Outfit', 'Manrope', 'Public Sans']
74
+ };
75
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OVERRIDE_SCHEMA_VERSION","exports","SUPPORTED_OVERRIDE_SCHEMA_VERSIONS","INPUT_TOKEN_MAP","brandPrimary","accentPrimary","basePrimary","displayFont","presetFonts","poise","prestige","pulse"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;;;;;AAAA;AACA;AACA;;AAEA;;AAOA;;AAKA;;AAGA;;AAOA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;;AAiBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA;AACA;AACA;;AAEA;AACO,MAAMA,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,OAAgB;;AAEvD;AACA;AACA;AACA;AACA;AACO,MAAME,kCAAqD,GAAAD,OAAA,CAAAC,kCAAA,GAAG,CAAC,OAAO,CAAU;;AAEvF;AACA;AACA;AACA;AACA;AACO,MAAMC,eAAe,GAAAF,OAAA,CAAAE,eAAA,GAAG;EAC7BC,YAAY,EAAE,aAAa;EAC3BC,aAAa,EAAE,cAAc;EAC7BC,WAAW,EAAE,YAAY;EACzBC,WAAW,EAAE;AACf,CAA2C;;AAE3C;AACA;AACA;AACA;AACO,MAAMC,WAA8C,GAAAP,OAAA,CAAAO,WAAA,GAAG;EAC5DC,KAAK,EAAE,CAAC,aAAa,EAAE,QAAQ,EAAE,SAAS,CAAC;EAC3CC,QAAQ,EAAE,CAAC,mBAAmB,EAAE,WAAW,EAAE,gBAAgB,CAAC;EAC9DC,KAAK,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,aAAa;AAC5C,CAAU","ignoreList":[]}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ import prestigePatch from '../runtime/prestige-vs-default.json';
4
+ import pulsePatch from '../runtime/pulse-vs-default.json';
5
+ import defaultRuntimeMap from '../runtime/token-to-css-var.json';
6
+ import { isSchemaVersionSupported, presetPatchToUniwindMaps, themeOverrideToUniwindMaps } from './theming';
7
+
8
+ // ---------------------------------------------------------------------------
9
+ // Constants
10
+ // ---------------------------------------------------------------------------
11
+
12
+ /** The build-time default preset. Apps ship with Poise baked into CSS. */
13
+ export const DEFAULT_PRESET = 'poise';
14
+
15
+ // ---------------------------------------------------------------------------
16
+ // Preset patch lookup
17
+ // ---------------------------------------------------------------------------
18
+
19
+ const PRESET_PATCHES = {
20
+ poise: null,
21
+ prestige: prestigePatch,
22
+ pulse: pulsePatch
23
+ };
24
+
25
+ // ---------------------------------------------------------------------------
26
+ // Platform detection
27
+ // ---------------------------------------------------------------------------
28
+
29
+ function detectPlatform() {
30
+ try {
31
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
32
+ const {
33
+ Platform: RNPlatform
34
+ } = require('react-native');
35
+ const os = RNPlatform.OS;
36
+ if (os === 'ios' || os === 'android') return os;
37
+ return 'web';
38
+ } catch {
39
+ return 'web';
40
+ }
41
+ }
42
+
43
+ // ---------------------------------------------------------------------------
44
+ // Result type
45
+ // ---------------------------------------------------------------------------
46
+
47
+ // ---------------------------------------------------------------------------
48
+ // Options
49
+ // ---------------------------------------------------------------------------
50
+
51
+ // ---------------------------------------------------------------------------
52
+ // Orchestrator
53
+ // ---------------------------------------------------------------------------
54
+
55
+ /**
56
+ * Apply a `ThemeOverride` end-to-end: schema version gate, preset patch
57
+ * selection, palette generation, and `Uniwind.updateCSSVariables` calls.
58
+ *
59
+ * Encapsulates the full runtime theme application sequence so consuming
60
+ * apps don't need to orchestrate lower-level utilities or import Uniwind
61
+ * directly.
62
+ */
63
+ export function applyThemeOverride(override, options = {}) {
64
+ const {
65
+ runtimeMap = defaultRuntimeMap,
66
+ runtimePlatform = detectPlatform()
67
+ } = options;
68
+
69
+ // --- Schema version gate ---
70
+ if (!isSchemaVersionSupported(override)) {
71
+ return {
72
+ applied: false,
73
+ reason: 'unsupported_schema_version'
74
+ };
75
+ }
76
+ const basePreset = override.$extensions['com.forge.ui.themeOverride'].basePreset;
77
+ const hasInputs = override.inputs !== undefined && Object.keys(override.inputs).length > 0;
78
+ const hasOverrides = override.overrides !== undefined && Object.keys(override.overrides).length > 0;
79
+
80
+ // --- Metadata-only check ---
81
+ const isDefaultPreset = basePreset === DEFAULT_PRESET;
82
+ if (isDefaultPreset && !hasInputs && !hasOverrides) {
83
+ return {
84
+ applied: false,
85
+ reason: 'no_theme_changes'
86
+ };
87
+ }
88
+
89
+ // --- Preset patch step ---
90
+ let presetMaps = {
91
+ light: {},
92
+ dark: {}
93
+ };
94
+ if (!isDefaultPreset) {
95
+ const patch = PRESET_PATCHES[basePreset];
96
+ if (patch) {
97
+ presetMaps = presetPatchToUniwindMaps(patch, runtimeMap, runtimePlatform);
98
+ }
99
+ }
100
+
101
+ // --- FI override step ---
102
+ let overrideMaps = {
103
+ light: {},
104
+ dark: {}
105
+ };
106
+ if (hasInputs || hasOverrides) {
107
+ overrideMaps = themeOverrideToUniwindMaps(override, runtimeMap);
108
+ }
109
+
110
+ // --- Merge per mode (FI wins on collision) ---
111
+ const mergedLight = {
112
+ ...presetMaps.light,
113
+ ...overrideMaps.light
114
+ };
115
+ const mergedDark = {
116
+ ...presetMaps.dark,
117
+ ...overrideMaps.dark
118
+ };
119
+
120
+ // --- Non-default preset with no FI changes still needs patch application ---
121
+ if (Object.keys(mergedLight).length === 0 && Object.keys(mergedDark).length === 0) {
122
+ return {
123
+ applied: false,
124
+ reason: 'no_theme_changes'
125
+ };
126
+ }
127
+
128
+ // --- Apply via Uniwind ---
129
+ try {
130
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
131
+ const {
132
+ Uniwind
133
+ } = require('uniwind');
134
+ if (Object.keys(mergedLight).length > 0) {
135
+ Uniwind.updateCSSVariables('light', mergedLight);
136
+ }
137
+ if (Object.keys(mergedDark).length > 0) {
138
+ Uniwind.updateCSSVariables('dark', mergedDark);
139
+ }
140
+ } catch {
141
+ throw new Error('applyThemeOverride requires "uniwind" to be installed. ' + 'Add it as a dependency in your app.');
142
+ }
143
+ return {
144
+ applied: true,
145
+ light: mergedLight,
146
+ dark: mergedDark
147
+ };
148
+ }
149
+ //# sourceMappingURL=applyThemeOverride.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["prestigePatch","pulsePatch","defaultRuntimeMap","isSchemaVersionSupported","presetPatchToUniwindMaps","themeOverrideToUniwindMaps","DEFAULT_PRESET","PRESET_PATCHES","poise","prestige","pulse","detectPlatform","Platform","RNPlatform","require","os","OS","applyThemeOverride","override","options","runtimeMap","runtimePlatform","applied","reason","basePreset","$extensions","hasInputs","inputs","undefined","Object","keys","length","hasOverrides","overrides","isDefaultPreset","presetMaps","light","dark","patch","overrideMaps","mergedLight","mergedDark","Uniwind","updateCSSVariables","Error"],"sourceRoot":"../../src","sources":["applyThemeOverride.ts"],"mappings":";;AAAA,OAAOA,aAAa,MAAM,qCAAqC;AAC/D,OAAOC,UAAU,MAAM,kCAAkC;AACzD,OAAOC,iBAAiB,MAAM,kCAAkC;AAEhE,SACEC,wBAAwB,EACxBC,wBAAwB,EACxBC,0BAA0B,QAGrB,WAAW;;AAElB;AACA;AACA;;AAEA;AACA,OAAO,MAAMC,cAAsB,GAAG,OAAO;;AAE7C;AACA;AACA;;AAEA,MAAMC,cAAiD,GAAG;EACxDC,KAAK,EAAE,IAAI;EACXC,QAAQ,EAAET,aAAa;EACvBU,KAAK,EAAET;AACT,CAAC;;AAED;AACA;AACA;;AAEA,SAASU,cAAcA,CAAA,EAAa;EAClC,IAAI;IACF;IACA,MAAM;MAAEC,QAAQ,EAAEC;IAAW,CAAC,GAAGC,OAAO,CAAC,cAAc,CAAC;IACxD,MAAMC,EAAE,GAAGF,UAAU,CAACG,EAAY;IAClC,IAAID,EAAE,KAAK,KAAK,IAAIA,EAAE,KAAK,SAAS,EAAE,OAAOA,EAAE;IAC/C,OAAO,KAAK;EACd,CAAC,CAAC,MAAM;IACN,OAAO,KAAK;EACd;AACF;;AAEA;AACA;AACA;;AAMA;AACA;AACA;;AAOA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,kBAAkBA,CAChCC,QAAuB,EACvBC,OAAkC,GAAG,CAAC,CAAC,EACb;EAC1B,MAAM;IAAEC,UAAU,GAAGlB,iBAAiB;IAAEmB,eAAe,GAAGV,cAAc,CAAC;EAAE,CAAC,GAAGQ,OAAO;;EAEtF;EACA,IAAI,CAAChB,wBAAwB,CAACe,QAAQ,CAAC,EAAE;IACvC,OAA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,MAAMK,UAAU,GAAG;IAAE,GAAGN,UAAU,CAACE,IAAI;IAAE,GAAGE,YAAY,CAACF;EAAK,CAAC;;EAE/D;EACA,IAAIR,MAAM,CAACC,IAAI,CAACU,WAAW,CAAC,CAACT,MAAM,KAAK,CAAC,IAAIF,MAAM,CAACC,IAAI,CAACW,UAAU,CAAC,CAACV,MAAM,KAAK,CAAC,EAAE;IACjF,OAAO;MAAET,OAAO,EAAE,KAAK;MAAEC,MAAM,EAAE;IAAmB,CAAC;EACvD;;EAEA;EACA,IAAI;IACF;IACA,MAAM;MAAEmB;IAAQ,CAAC,GAAG5B,OAAO,CAAC,SAAS,CAAC;IACtC,IAAIe,MAAM,CAACC,IAAI,CAACU,WAAW,CAAC,CAACT,MAAM,GAAG,CAAC,EAAE;MACvCW,OAAO,CAACC,kBAAkB,CAAC,OAAO,EAAEH,WAAW,CAAC;IAClD;IACA,IAAIX,MAAM,CAACC,IAAI,CAACW,UAAU,CAAC,CAACV,MAAM,GAAG,CAAC,EAAE;MACtCW,OAAO,CAACC,kBAAkB,CAAC,MAAM,EAAEF,UAAU,CAAC;IAChD;EACF,CAAC,CAAC,MAAM;IACN,MAAM,IAAIG,KAAK,CACb,yDAAyD,GACvD,qCACJ,CAAC;EACH;EAEA,OAAO;IAAEtB,OAAO,EAAE,IAAI;IAAEc,KAAK,EAAEI,WAAW;IAAEH,IAAI,EAAEI;EAAW,CAAC;AAChE","ignoreList":[]}
@@ -1,74 +1,20 @@
1
1
  "use strict";
2
2
 
3
3
  // ---------------------------------------------------------------------------
4
- // Types
4
+ // Types & Constants
5
5
  // ---------------------------------------------------------------------------
6
6
 
7
- /** A DTCG token leaf node. */
8
-
9
- /** Recursive token group — every non-leaf node in a theme object. */
10
-
11
- /** The three built-in Forge UI theme presets. */
12
-
13
- /** Theme metadata stored under `$extensions.com.forge.ui.theme`. */
14
-
15
- /** Override metadata stored under `$extensions.com.forge.ui.themeOverride`. */
16
-
17
- /**
18
- * A complete Forge UI theme object (DTCG-compatible).
19
- *
20
- * Presets (Poise, Prestige, Pulse) are full theme objects. At runtime the
21
- * build-time default preset is augmented by FI overrides via
22
- * `applyThemeOverrides`.
23
- */
24
-
25
- /**
26
- * A theme override using the hybrid input + semantic structure.
27
- *
28
- * - `inputs` — flat map of abstract FI-selected brand values (e.g.
29
- * `brandPrimary`, `displayFont`). Palette generation expands these into
30
- * full token scales at runtime.
31
- * - `overrides` — per-mode flat maps of token dot-paths to resolved values
32
- * for direct semantic token overrides beyond what inputs generate.
33
- * - `$extensions` — required metadata including base preset and schema version.
34
- */
35
-
7
+ export { OVERRIDE_SCHEMA_VERSION, SUPPORTED_OVERRIDE_SCHEMA_VERSIONS, INPUT_TOKEN_MAP, presetFonts } from './types';
36
8
  // ---------------------------------------------------------------------------
37
- // Constants
9
+ // Palette generation
38
10
  // ---------------------------------------------------------------------------
39
11
 
40
- /** Current override schema version. Consuming apps gate compatibility on this. */
41
- export const OVERRIDE_SCHEMA_VERSION = '1.0.0';
42
-
43
- /**
44
- * Schema versions that consuming apps accept. Includes the current version and
45
- * may include the immediately prior version during transition windows.
46
- * @see docs/internal/token-architecture/16-override-structure.md § 4
47
- */
48
- export const SUPPORTED_OVERRIDE_SCHEMA_VERSIONS = ['1.0.0'];
49
-
50
- /**
51
- * Schema-level mapping from known input keys to the token path pattern each
52
- * affects. Used by override application (S5) to route inputs to the correct
53
- * palette/token namespace. Distinct from the full runtime map (S3).
54
- */
55
- export const INPUT_TOKEN_MAP = {
56
- brandPrimary: 'color.brand',
57
- accentPrimary: 'color.accent',
58
- basePrimary: 'color.base',
59
- displayFont: 'font.display'
60
- };
61
-
62
- /**
63
- * Allowed display font families per preset, consumed by the theme editor for
64
- * font selection and by consuming apps for validation.
65
- */
66
- export const presetFonts = {
67
- poise: ['Crimson Pro', 'Bitter', 'DM Sans'],
68
- prestige: ['Libre Caslon Text', 'Cormorant', 'Libre Franklin'],
69
- pulse: ['Outfit', 'Manrope', 'Public Sans']
70
- };
12
+ export { generateColorScale, generatePalettesFromInputs } from './palette';
13
+ // ---------------------------------------------------------------------------
14
+ // Theming utilities
15
+ // ---------------------------------------------------------------------------
71
16
 
17
+ export { isSchemaVersionSupported, presetPatchToUniwindMaps, themeOverrideToUniwindMaps, applyThemeOverride, DEFAULT_PRESET } from './theming';
72
18
  // ---------------------------------------------------------------------------
73
19
  // Hooks
74
20
  // ---------------------------------------------------------------------------
@@ -1 +1 @@
1
- {"version":3,"names":["OVERRIDE_SCHEMA_VERSION","SUPPORTED_OVERRIDE_SCHEMA_VERSIONS","INPUT_TOKEN_MAP","brandPrimary","accentPrimary","basePrimary","displayFont","presetFonts","poise","prestige","pulse","useForgeFonts","useCdxFonts"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA;AACA;;AAEA;;AAOA;;AAKA;;AAGA;;AAOA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;;AAiBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA;AACA;AACA;;AAEA;AACA,OAAO,MAAMA,uBAAuB,GAAG,OAAgB;;AAEvD;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kCAAqD,GAAG,CAAC,OAAO,CAAU;;AAEvF;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAG;EAC7BC,YAAY,EAAE,aAAa;EAC3BC,aAAa,EAAE,cAAc;EAC7BC,WAAW,EAAE,YAAY;EACzBC,WAAW,EAAE;AACf,CAA2C;;AAE3C;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAA8C,GAAG;EAC5DC,KAAK,EAAE,CAAC,aAAa,EAAE,QAAQ,EAAE,SAAS,CAAC;EAC3CC,QAAQ,EAAE,CAAC,mBAAmB,EAAE,WAAW,EAAE,gBAAgB,CAAC;EAC9DC,KAAK,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,aAAa;AAC5C,CAAU;;AAEV;AACA;AACA;;AAEA,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,WAAW,QAAQ,eAAe","ignoreList":[]}
1
+ {"version":3,"names":["OVERRIDE_SCHEMA_VERSION","SUPPORTED_OVERRIDE_SCHEMA_VERSIONS","INPUT_TOKEN_MAP","presetFonts","generateColorScale","generatePalettesFromInputs","isSchemaVersionSupported","presetPatchToUniwindMaps","themeOverrideToUniwindMaps","applyThemeOverride","DEFAULT_PRESET","useForgeFonts","useCdxFonts"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA;AACA;;AAEA,SACEA,uBAAuB,EACvBC,kCAAkC,EAClCC,eAAe,EACfC,WAAW,QACN,SAAS;AAahB;AACA;AACA;;AAEA,SAASC,kBAAkB,EAAEC,0BAA0B,QAAQ,WAAW;AAG1E;AACA;AACA;;AAEA,SACEC,wBAAwB,EACxBC,wBAAwB,EACxBC,0BAA0B,EAC1BC,kBAAkB,EAClBC,cAAc,QACT,WAAW;AAIlB;AACA;AACA;;AAEA,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,WAAW,QAAQ,eAAe","ignoreList":[]}