@cdx-ui/styles 0.0.1-beta.7 → 0.0.1-beta.70
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/README.md +116 -20
- package/css/theme.css +190 -83
- package/css/vanilla.css +117 -53
- package/lib/commonjs/applyThemeOverride.js +154 -0
- package/lib/commonjs/applyThemeOverride.js.map +1 -0
- package/lib/commonjs/index.js +82 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/palette.js +262 -0
- package/lib/commonjs/palette.js.map +1 -0
- package/lib/commonjs/theming.js +255 -0
- package/lib/commonjs/theming.js.map +1 -0
- package/lib/commonjs/types.js +75 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/useCdxFonts.js +7 -231
- package/lib/commonjs/useCdxFonts.js.map +1 -1
- package/lib/commonjs/useForgeFonts.js +237 -0
- package/lib/commonjs/useForgeFonts.js.map +1 -0
- package/lib/module/applyThemeOverride.js +149 -0
- package/lib/module/applyThemeOverride.js.map +1 -0
- package/lib/module/index.js +11 -20
- package/lib/module/index.js.map +1 -1
- package/lib/module/palette.js +257 -0
- package/lib/module/palette.js.map +1 -0
- package/lib/module/theming.js +239 -0
- package/lib/module/theming.js.map +1 -0
- package/lib/module/types.js +71 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/useCdxFonts.js +2 -220
- package/lib/module/useCdxFonts.js.map +1 -1
- package/lib/module/useForgeFonts.js +223 -0
- package/lib/module/useForgeFonts.js.map +1 -0
- package/lib/runtime/prestige-vs-default.json +1 -0
- package/lib/runtime/pulse-vs-default.json +1 -0
- package/lib/runtime/token-to-css-var.json +666 -0
- package/lib/typescript/applyThemeOverride.d.ts +26 -0
- package/lib/typescript/applyThemeOverride.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +8 -57
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/palette.d.ts +60 -0
- package/lib/typescript/palette.d.ts.map +1 -0
- package/lib/typescript/theming.d.ts +40 -0
- package/lib/typescript/theming.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +90 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/useCdxFonts.d.ts +2 -11
- package/lib/typescript/useCdxFonts.d.ts.map +1 -1
- package/lib/typescript/useForgeFonts.d.ts +12 -0
- package/lib/typescript/useForgeFonts.d.ts.map +1 -0
- package/package.json +27 -8
- package/runtime/prestige-vs-default.json +1 -0
- package/runtime/pulse-vs-default.json +1 -0
- package/runtime/token-to-css-var.json +666 -0
- package/src/__tests__/applyThemeOverride.test.ts +552 -0
- package/src/__tests__/generateColorScale.test.ts +296 -0
- package/src/__tests__/theming.test.ts +647 -0
- package/src/applyThemeOverride.ts +139 -0
- package/src/index.ts +36 -60
- package/src/palette.ts +307 -0
- package/src/theming.ts +268 -0
- package/src/types.ts +112 -0
- package/src/useCdxFonts.ts +2 -230
- package/src/useForgeFonts.ts +230 -0
- package/tokens/presets/.manifest.json +3 -3
- package/tokens/presets/poise.json +294 -38
- package/tokens/presets/prestige.json +1 -1
- package/tokens/presets/pulse.json +1 -1
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.deriveBaseColorKey = deriveBaseColorKey;
|
|
7
|
+
exports.generateColorScale = generateColorScale;
|
|
8
|
+
exports.generatePalettesFromInputs = generatePalettesFromInputs;
|
|
9
|
+
var _leonardoContrastColors = require("@adobe/leonardo-contrast-colors");
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Types
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
/** Palette step keys produced by `generateColorScale`. */
|
|
15
|
+
|
|
16
|
+
/** Token category that supports palette generation. */
|
|
17
|
+
|
|
18
|
+
/** Map of palette step → resolved hex color. */
|
|
19
|
+
|
|
20
|
+
/** Map of token dot-path → resolved hex color (e.g. `color.brand.500` → `#548cdc`). */
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Constants
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
const REFERENCE_BACKGROUND = '#ffffff';
|
|
27
|
+
const PALETTE_STEPS = ['50', '100', '200', '300', '400', '500', '600', '700', '800', '900', '950'];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Contrast ratios for each palette step against white (#ffffff).
|
|
31
|
+
*
|
|
32
|
+
* Step 700 targets WCAG AA for normal text (≥ 4.5:1).
|
|
33
|
+
*/
|
|
34
|
+
const CONTRAST_RATIOS = {
|
|
35
|
+
'50': 1.04,
|
|
36
|
+
'100': 1.16,
|
|
37
|
+
'200': 1.46,
|
|
38
|
+
'300': 1.85,
|
|
39
|
+
'400': 2.45,
|
|
40
|
+
'500': 3.4,
|
|
41
|
+
'600': 4.8,
|
|
42
|
+
'700': 6.4,
|
|
43
|
+
'800': 8.6,
|
|
44
|
+
'900': 12,
|
|
45
|
+
'950': 16.8
|
|
46
|
+
};
|
|
47
|
+
const HEX_REGEX = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
48
|
+
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Validation
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Validate and normalise a hex color string.
|
|
55
|
+
*
|
|
56
|
+
* Accepts `#RGB` (4 chars) or `#RRGGBB` (7 chars). Throws a descriptive
|
|
57
|
+
* `TypeError` for any other input.
|
|
58
|
+
*
|
|
59
|
+
* @returns The normalised 7-character hex string (e.g. `#aabbcc`).
|
|
60
|
+
*/
|
|
61
|
+
function validateHex(hex) {
|
|
62
|
+
if (typeof hex !== 'string') {
|
|
63
|
+
throw new TypeError(`Invalid hex color: expected a string, received ${typeof hex}`);
|
|
64
|
+
}
|
|
65
|
+
if (!HEX_REGEX.test(hex)) {
|
|
66
|
+
throw new TypeError(`Invalid hex color "${hex}": must be a 4-character (#RGB) or 7-character (#RRGGBB) hex string starting with "#"`);
|
|
67
|
+
}
|
|
68
|
+
if (hex.length === 4) {
|
|
69
|
+
const [, r, g, b] = hex;
|
|
70
|
+
return `#${r}${r}${g}${g}${b}${b}`.toLowerCase();
|
|
71
|
+
}
|
|
72
|
+
return hex.toLowerCase();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// Core generation — wraps Leonardo behind a thin interface
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Generate an 11-step contrast-based color scale from a single hex color.
|
|
81
|
+
*
|
|
82
|
+
* Uses `@adobe/leonardo-contrast-colors` internally. The generation algorithm
|
|
83
|
+
* is wrapped behind this function so the underlying library is swappable
|
|
84
|
+
* without changing the public API.
|
|
85
|
+
*
|
|
86
|
+
* @param hex - A valid hex color string (`#RGB` or `#RRGGBB`).
|
|
87
|
+
* @param category - The token namespace (`'brand'` or `'accent'`).
|
|
88
|
+
* @returns A `PaletteTokenMap` keyed by token dot-paths
|
|
89
|
+
* (e.g. `"color.brand.50"` through `"color.brand.950"` plus `"color.brand.input"`).
|
|
90
|
+
*/
|
|
91
|
+
function generateColorScale(hex, category) {
|
|
92
|
+
const normalised = validateHex(hex);
|
|
93
|
+
const ratiosObject = {};
|
|
94
|
+
for (const step of PALETTE_STEPS) {
|
|
95
|
+
ratiosObject[step] = CONTRAST_RATIOS[step];
|
|
96
|
+
}
|
|
97
|
+
const color = new _leonardoContrastColors.Color({
|
|
98
|
+
name: 'palette',
|
|
99
|
+
colorKeys: [normalised],
|
|
100
|
+
colorSpace: 'CAM02p',
|
|
101
|
+
ratios: ratiosObject,
|
|
102
|
+
smooth: true,
|
|
103
|
+
output: 'HEX'
|
|
104
|
+
});
|
|
105
|
+
const bg = new _leonardoContrastColors.BackgroundColor({
|
|
106
|
+
name: 'background',
|
|
107
|
+
colorKeys: [REFERENCE_BACKGROUND],
|
|
108
|
+
colorSpace: 'CAM02p',
|
|
109
|
+
smooth: true,
|
|
110
|
+
ratios: [],
|
|
111
|
+
output: 'HEX'
|
|
112
|
+
});
|
|
113
|
+
const theme = new _leonardoContrastColors.Theme({
|
|
114
|
+
colors: [color],
|
|
115
|
+
backgroundColor: bg,
|
|
116
|
+
lightness: 100,
|
|
117
|
+
contrast: 1,
|
|
118
|
+
saturation: 100,
|
|
119
|
+
output: 'HEX',
|
|
120
|
+
formula: 'wcag2'
|
|
121
|
+
});
|
|
122
|
+
const pairs = theme.contrastColorPairs;
|
|
123
|
+
const tokenPrefix = `color.${category}`;
|
|
124
|
+
const result = {};
|
|
125
|
+
for (const step of PALETTE_STEPS) {
|
|
126
|
+
result[`${tokenPrefix}.${step}`] = pairs[step].toLowerCase();
|
|
127
|
+
}
|
|
128
|
+
result[`${tokenPrefix}.input`] = normalised;
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
// Base color-key derivation
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
/** Saturation (0–1) applied to the brand hue to produce the base color key. */
|
|
137
|
+
const BASE_SATURATION = 0.05;
|
|
138
|
+
|
|
139
|
+
/** Convert a normalised hex string to HSL (`h` in degrees, `s`/`l` in 0–1). */
|
|
140
|
+
function hexToHsl(hex) {
|
|
141
|
+
const r = parseInt(hex.slice(1, 3), 16) / 255;
|
|
142
|
+
const g = parseInt(hex.slice(3, 5), 16) / 255;
|
|
143
|
+
const b = parseInt(hex.slice(5, 7), 16) / 255;
|
|
144
|
+
const max = Math.max(r, g, b);
|
|
145
|
+
const min = Math.min(r, g, b);
|
|
146
|
+
const delta = max - min;
|
|
147
|
+
const l = (max + min) / 2;
|
|
148
|
+
let h = 0;
|
|
149
|
+
let s = 0;
|
|
150
|
+
if (delta !== 0) {
|
|
151
|
+
s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min);
|
|
152
|
+
switch (max) {
|
|
153
|
+
case r:
|
|
154
|
+
h = (g - b) / delta + (g < b ? 6 : 0);
|
|
155
|
+
break;
|
|
156
|
+
case g:
|
|
157
|
+
h = (b - r) / delta + 2;
|
|
158
|
+
break;
|
|
159
|
+
default:
|
|
160
|
+
h = (r - g) / delta + 4;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
h *= 60;
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
h,
|
|
167
|
+
s,
|
|
168
|
+
l
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Convert HSL (`h` in degrees, `s`/`l` in 0–1) to a normalised hex string. */
|
|
173
|
+
function hslToHex({
|
|
174
|
+
h,
|
|
175
|
+
s,
|
|
176
|
+
l
|
|
177
|
+
}) {
|
|
178
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
179
|
+
const hp = (h % 360 + 360) % 360 / 60;
|
|
180
|
+
const x = c * (1 - Math.abs(hp % 2 - 1));
|
|
181
|
+
let r = 0;
|
|
182
|
+
let g = 0;
|
|
183
|
+
let b = 0;
|
|
184
|
+
if (hp < 1) [r, g, b] = [c, x, 0];else if (hp < 2) [r, g, b] = [x, c, 0];else if (hp < 3) [r, g, b] = [0, c, x];else if (hp < 4) [r, g, b] = [0, x, c];else if (hp < 5) [r, g, b] = [x, 0, c];else [r, g, b] = [c, 0, x];
|
|
185
|
+
const m = l - c / 2;
|
|
186
|
+
const toHex = v => Math.round((v + m) * 255).toString(16).padStart(2, '0');
|
|
187
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Derive the base palette color key from a brand color.
|
|
192
|
+
*
|
|
193
|
+
* The base scale shares the brand's hue and lightness but is nearly neutral:
|
|
194
|
+
* the brand color is converted to HSL and its saturation is lowered to
|
|
195
|
+
* {@link BASE_SATURATION} (5%). The resulting hex is the color key fed to
|
|
196
|
+
* {@link generateColorScale} for the `base` category.
|
|
197
|
+
*
|
|
198
|
+
* @param brandHex - A valid hex color string (`#RGB` or `#RRGGBB`).
|
|
199
|
+
* @returns The normalised hex color key for the base scale.
|
|
200
|
+
*/
|
|
201
|
+
function deriveBaseColorKey(brandHex) {
|
|
202
|
+
const {
|
|
203
|
+
h,
|
|
204
|
+
l
|
|
205
|
+
} = hexToHsl(validateHex(brandHex));
|
|
206
|
+
return hslToHex({
|
|
207
|
+
h,
|
|
208
|
+
s: BASE_SATURATION,
|
|
209
|
+
l
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ---------------------------------------------------------------------------
|
|
214
|
+
// Convenience wrapper
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Colour-input keys whose token path starts with `color.` — these trigger
|
|
219
|
+
* palette generation. Mirrors the colour entries from `INPUT_TOKEN_MAP`
|
|
220
|
+
* (defined in the package barrel) without creating a circular import.
|
|
221
|
+
*
|
|
222
|
+
* Keep in sync with `INPUT_TOKEN_MAP` in `./index.ts`.
|
|
223
|
+
*/
|
|
224
|
+
const COLOR_INPUT_ENTRIES = [['brandPrimary', 'color.brand'], ['accentPrimary', 'color.accent'], ['basePrimary', 'color.base']];
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Generate palettes for all colour inputs in a theme override `inputs` object.
|
|
228
|
+
*
|
|
229
|
+
* Iterates over known colour-input keys that map to a `color.*` token
|
|
230
|
+
* namespace. For each matching key present in `inputs`, runs
|
|
231
|
+
* `generateColorScale` and merges the results into a single flat map of
|
|
232
|
+
* token dot-paths to hex values — ready for the S5 override application
|
|
233
|
+
* merge step.
|
|
234
|
+
*
|
|
235
|
+
* Non-colour inputs (e.g. `displayFont`) are silently skipped.
|
|
236
|
+
*
|
|
237
|
+
* @param inputs - The `inputs` object from a `ThemeOverride`.
|
|
238
|
+
* @returns A merged `Record<string, string>` of all generated token
|
|
239
|
+
* dot-paths to hex values.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* const inputs = { brandPrimary: '#0052cc', accentPrimary: '#FF8C42', displayFont: 'Poppins' };
|
|
244
|
+
* const result = generatePalettesFromInputs(inputs);
|
|
245
|
+
* // {
|
|
246
|
+
* // "color.brand.50": "#...", …, "color.brand.input": "#0052cc",
|
|
247
|
+
* // "color.accent.50": "#...", …, "color.accent.input": "#ff8c42"
|
|
248
|
+
* // }
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
function generatePalettesFromInputs(inputs) {
|
|
252
|
+
const result = {};
|
|
253
|
+
for (const [inputKey, tokenPath] of COLOR_INPUT_ENTRIES) {
|
|
254
|
+
const value = inputs[inputKey];
|
|
255
|
+
if (typeof value !== 'string') continue;
|
|
256
|
+
const category = tokenPath.replace('color.', '');
|
|
257
|
+
const scale = generateColorScale(value, category);
|
|
258
|
+
Object.assign(result, scale);
|
|
259
|
+
}
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=palette.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_leonardoContrastColors","require","REFERENCE_BACKGROUND","PALETTE_STEPS","CONTRAST_RATIOS","HEX_REGEX","validateHex","hex","TypeError","test","length","r","g","b","toLowerCase","generateColorScale","category","normalised","ratiosObject","step","color","Color","name","colorKeys","colorSpace","ratios","smooth","output","bg","BackgroundColor","theme","Theme","colors","backgroundColor","lightness","contrast","saturation","formula","pairs","contrastColorPairs","tokenPrefix","result","BASE_SATURATION","hexToHsl","parseInt","slice","max","Math","min","delta","l","h","s","hslToHex","c","abs","hp","x","m","toHex","v","round","toString","padStart","deriveBaseColorKey","brandHex","COLOR_INPUT_ENTRIES","generatePalettesFromInputs","inputs","inputKey","tokenPath","value","replace","scale","Object","assign"],"sourceRoot":"../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;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMgB,mBAA2D,GAAG,CAClE,CAAC,cAAc,EAAE,aAAa,CAAC,EAC/B,CAAC,eAAe,EAAE,cAAc,CAAC,EACjC,CAAC,aAAa,EAAE,YAAY,CAAC,CACrB;;AAEV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,0BAA0BA,CACxCC,MAAuC,EACtB;EACjB,MAAM3B,MAAuB,GAAG,CAAC,CAAC;EAElC,KAAK,MAAM,CAAC4B,QAAQ,EAAEC,SAAS,CAAC,IAAIJ,mBAAmB,EAAE;IACvD,MAAMK,KAAK,GAAGH,MAAM,CAACC,QAAQ,CAAC;IAC9B,IAAI,OAAOE,KAAK,KAAK,QAAQ,EAAE;IAE/B,MAAMvD,QAAQ,GAAGsD,SAAS,CAACE,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAoB;IACnE,MAAMC,KAAK,GAAG1D,kBAAkB,CAACwD,KAAK,EAAEvD,QAAQ,CAAC;IAEjD0D,MAAM,CAACC,MAAM,CAAClC,MAAM,EAAEgC,KAAK,CAAC;EAC9B;EAEA,OAAOhC,MAAM;AACf","ignoreList":[]}
|
|
@@ -0,0 +1,255 @@
|
|
|
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
|
+
* Matches a token-reference alias value such as `{color.brand.700}` and
|
|
142
|
+
* captures the referenced token dot-path.
|
|
143
|
+
*/
|
|
144
|
+
const TOKEN_ALIAS_REGEX = /^\{([^}]+)\}$/;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Resolve an `overrides.{mode}` value into the string written to the CSS
|
|
148
|
+
* variable map.
|
|
149
|
+
*
|
|
150
|
+
* - **Token-reference alias** (`{color.brand.700}`) → resolves the referenced
|
|
151
|
+
* token path via the runtime map and returns a CSS `var()` reference
|
|
152
|
+
* (`var(--color-brand-700)`), so the override tracks its source through the
|
|
153
|
+
* cascade — the same mechanism the base theme uses for its semantic tokens.
|
|
154
|
+
* Returns `null` when the referenced path is absent from the runtime map
|
|
155
|
+
* (e.g. a non-primitive target), so the caller skips it; this enforces the
|
|
156
|
+
* primitive-only alias constraint at the resolution layer.
|
|
157
|
+
* - **Literal value** (`#F5F7F6`, `8`) → returned as-is (stringified).
|
|
158
|
+
*
|
|
159
|
+
* @see docs/internal/token-architecture/16-override-structure.md — Token-reference aliases vs. literal values
|
|
160
|
+
*/
|
|
161
|
+
function resolveOverrideValue(value, runtimeMap) {
|
|
162
|
+
if (typeof value === 'string') {
|
|
163
|
+
const aliasMatch = TOKEN_ALIAS_REGEX.exec(value);
|
|
164
|
+
if (aliasMatch) {
|
|
165
|
+
const referencedPath = aliasMatch[1].trim();
|
|
166
|
+
const targetCssVar = runtimeMap[referencedPath];
|
|
167
|
+
return targetCssVar ? `var(${targetCssVar})` : null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return String(value);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Convert a hybrid FI override (`ThemeOverride`) into per-mode CSS variable
|
|
175
|
+
* maps suitable for `Uniwind.updateCSSVariables`.
|
|
176
|
+
*
|
|
177
|
+
* Processing:
|
|
178
|
+
* 1. Generate palettes from color `inputs` (via S4).
|
|
179
|
+
* 2. Map font inputs to token paths.
|
|
180
|
+
* 3. For each mode, merge palette + fonts + explicit `overrides.{mode}` entries.
|
|
181
|
+
* 4. Map all token dot-paths to CSS variable names via runtime map.
|
|
182
|
+
*
|
|
183
|
+
* @param override - A `ThemeOverride` object.
|
|
184
|
+
* @param runtimeMap - The generated token-to-CSS-var mapping.
|
|
185
|
+
* @param runtimePlatform - Current platform (`'web' | 'ios' | 'android'`).
|
|
186
|
+
*/
|
|
187
|
+
function themeOverrideToUniwindMaps(override, runtimeMap
|
|
188
|
+
// runtimePlatform: Platform,
|
|
189
|
+
) {
|
|
190
|
+
const light = {};
|
|
191
|
+
const dark = {};
|
|
192
|
+
const inputs = override.inputs;
|
|
193
|
+
const overrides = override.overrides;
|
|
194
|
+
if (!inputs && !overrides) {
|
|
195
|
+
return {
|
|
196
|
+
light,
|
|
197
|
+
dark
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// --- Palette generation from colour inputs ---
|
|
202
|
+
let paletteTokens = {};
|
|
203
|
+
if (inputs) {
|
|
204
|
+
paletteTokens = (0, _palette.generatePalettesFromInputs)(inputs);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// --- Font input mapping ---
|
|
208
|
+
const fontTokens = {};
|
|
209
|
+
if (inputs) {
|
|
210
|
+
for (const [inputKey, tokenPath] of FONT_INPUT_ENTRIES) {
|
|
211
|
+
const value = inputs[inputKey];
|
|
212
|
+
if (value !== undefined) {
|
|
213
|
+
fontTokens[tokenPath] = String(value);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// --- Merge per mode ---
|
|
219
|
+
const modes = ['light', 'dark'];
|
|
220
|
+
for (const mode of modes) {
|
|
221
|
+
const bucket = mode === 'light' ? light : dark;
|
|
222
|
+
|
|
223
|
+
// 1. Palette-generated primitives (mode-independent → both buckets)
|
|
224
|
+
for (const [dotPath, hexValue] of Object.entries(paletteTokens)) {
|
|
225
|
+
const cssVar = runtimeMap[dotPath];
|
|
226
|
+
if (cssVar) bucket[cssVar] = hexValue;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// 2. Font input mappings (mode-independent → both buckets)
|
|
230
|
+
for (const [tokenPath, value] of Object.entries(fontTokens)) {
|
|
231
|
+
const modePrefixed = `modes.${mode}.${tokenPath}`;
|
|
232
|
+
const cssVar = runtimeMap[modePrefixed] ?? runtimeMap[tokenPath];
|
|
233
|
+
if (cssVar) bucket[cssVar] = value;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 3. Explicit per-mode overrides (wins on collision). Values may be
|
|
237
|
+
// token-reference aliases (resolved to a CSS var() reference) or
|
|
238
|
+
// literals; see resolveOverrideValue.
|
|
239
|
+
const modeOverrides = overrides?.[mode];
|
|
240
|
+
if (modeOverrides) {
|
|
241
|
+
for (const [dotPath, value] of Object.entries(modeOverrides)) {
|
|
242
|
+
const modePrefixed = `modes.${mode}.${dotPath}`;
|
|
243
|
+
const cssVar = runtimeMap[modePrefixed] ?? runtimeMap[dotPath];
|
|
244
|
+
if (!cssVar) continue;
|
|
245
|
+
const resolved = resolveOverrideValue(value, runtimeMap);
|
|
246
|
+
if (resolved !== null) bucket[cssVar] = resolved;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
light,
|
|
252
|
+
dark
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
//# 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","TOKEN_ALIAS_REGEX","resolveOverrideValue","aliasMatch","exec","referencedPath","trim","targetCssVar","themeOverrideToUniwindMaps","inputs","overrides","paletteTokens","generatePalettesFromInputs","fontTokens","inputKey","undefined","modes","mode","bucket","hexValue","modePrefixed","modeOverrides","resolved"],"sourceRoot":"../../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AAM,CAACc,OAAO,CAAC0B,UAAU,CAAC,EAAE;MAC3D,MAAMO,YAAY,GAAG,SAASH,IAAI,IAAIjB,SAAS,EAAE;MACjD,MAAMV,MAAM,GAAGT,UAAU,CAACuC,YAAY,CAAC,IAAIvC,UAAU,CAACmB,SAAS,CAAC;MAChE,IAAIV,MAAM,EAAE4B,MAAM,CAAC5B,MAAM,CAAC,GAAGJ,KAAK;IACpC;;IAEA;IACA;IACA;IACA,MAAMmC,aAAa,GAAGX,SAAS,GAAGO,IAAI,CAAC;IACvC,IAAII,aAAa,EAAE;MACjB,KAAK,MAAM,CAACpC,OAAO,EAAEC,KAAK,CAAC,IAAIb,MAAM,CAACc,OAAO,CAACkC,aAAa,CAAC,EAAE;QAC5D,MAAMD,YAAY,GAAG,SAASH,IAAI,IAAIhC,OAAO,EAAE;QAC/C,MAAMK,MAAM,GAAGT,UAAU,CAACuC,YAAY,CAAC,IAAIvC,UAAU,CAACI,OAAO,CAAC;QAC9D,IAAI,CAACK,MAAM,EAAE;QAEb,MAAMgC,QAAQ,GAAGpB,oBAAoB,CAAChB,KAAK,EAAEL,UAAU,CAAC;QACxD,IAAIyC,QAAQ,KAAK,IAAI,EAAEJ,MAAM,CAAC5B,MAAM,CAAC,GAAGgC,QAAQ;MAClD;IACF;EACF;EAEA,OAAO;IAAEvC,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":[]}
|