@salesforce/ui-theme-manager 11.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +82 -0
- package/README.md +29 -0
- package/dist/authoring/core/ThemeManagerPanelRoot.d.cts +43 -0
- package/dist/authoring/core/ThemeManagerPanelRoot.d.ts +43 -0
- package/dist/authoring/core/ThemeManagerPanelRoot.d.ts.map +1 -0
- package/dist/authoring/core/components/AssetsSection.d.cts +12 -0
- package/dist/authoring/core/components/AssetsSection.d.ts +12 -0
- package/dist/authoring/core/components/AssetsSection.d.ts.map +1 -0
- package/dist/authoring/core/components/BordersSection.d.cts +9 -0
- package/dist/authoring/core/components/BordersSection.d.ts +9 -0
- package/dist/authoring/core/components/BordersSection.d.ts.map +1 -0
- package/dist/authoring/core/components/ButtonSection.d.cts +9 -0
- package/dist/authoring/core/components/ButtonSection.d.ts +9 -0
- package/dist/authoring/core/components/ButtonSection.d.ts.map +1 -0
- package/dist/authoring/core/components/ColorEditors.d.cts +8 -0
- package/dist/authoring/core/components/ColorEditors.d.ts +8 -0
- package/dist/authoring/core/components/ColorEditors.d.ts.map +1 -0
- package/dist/authoring/core/components/ColorField.d.cts +45 -0
- package/dist/authoring/core/components/ColorField.d.ts +45 -0
- package/dist/authoring/core/components/ColorField.d.ts.map +1 -0
- package/dist/authoring/core/components/SaveBar.d.cts +8 -0
- package/dist/authoring/core/components/SaveBar.d.ts +8 -0
- package/dist/authoring/core/components/SaveBar.d.ts.map +1 -0
- package/dist/authoring/core/components/SearchBox.d.cts +16 -0
- package/dist/authoring/core/components/SearchBox.d.ts +16 -0
- package/dist/authoring/core/components/SearchBox.d.ts.map +1 -0
- package/dist/authoring/core/components/TabSwitcher.d.cts +13 -0
- package/dist/authoring/core/components/TabSwitcher.d.ts +13 -0
- package/dist/authoring/core/components/TabSwitcher.d.ts.map +1 -0
- package/dist/authoring/core/components/ThemeGallery.d.cts +9 -0
- package/dist/authoring/core/components/ThemeGallery.d.ts +9 -0
- package/dist/authoring/core/components/ThemeGallery.d.ts.map +1 -0
- package/dist/authoring/core/components/TypographySection.d.cts +9 -0
- package/dist/authoring/core/components/TypographySection.d.ts +9 -0
- package/dist/authoring/core/components/TypographySection.d.ts.map +1 -0
- package/dist/authoring/core/index.d.cts +8 -0
- package/dist/authoring/core/index.d.ts +8 -0
- package/dist/authoring/core/index.d.ts.map +1 -0
- package/dist/authoring/core/labels.d.cts +89 -0
- package/dist/authoring/core/labels.d.ts +89 -0
- package/dist/authoring/core/labels.d.ts.map +1 -0
- package/dist/authoring/react/index.d.cts +16 -0
- package/dist/authoring/react/index.d.ts +16 -0
- package/dist/authoring/react/index.d.ts.map +1 -0
- package/dist/authoring/react/index.js +1 -0
- package/dist/authoring/react/styles.css +1 -0
- package/dist/authoring/web-component/index.d.cts +34 -0
- package/dist/authoring/web-component/index.d.ts +34 -0
- package/dist/authoring/web-component/index.d.ts.map +1 -0
- package/dist/authoring/web-component/index.js +729 -0
- package/dist/protocol/brandCss.cjs +255 -0
- package/dist/protocol/brandCss.d.cts +42 -0
- package/dist/protocol/brandCss.d.ts +42 -0
- package/dist/protocol/brandCss.d.ts.map +1 -0
- package/dist/protocol/brandCss.js +255 -0
- package/dist/protocol/brandResolver.cjs +61 -0
- package/dist/protocol/brandResolver.d.cts +28 -0
- package/dist/protocol/brandResolver.d.ts +28 -0
- package/dist/protocol/brandResolver.d.ts.map +1 -0
- package/dist/protocol/brandResolver.js +61 -0
- package/dist/protocol/brandSearch.cjs +64 -0
- package/dist/protocol/brandSearch.d.cts +133 -0
- package/dist/protocol/brandSearch.d.ts +133 -0
- package/dist/protocol/brandSearch.d.ts.map +1 -0
- package/dist/protocol/brandSearch.js +64 -0
- package/dist/protocol/brandTypes.cjs +30 -0
- package/dist/protocol/brandTypes.d.cts +198 -0
- package/dist/protocol/brandTypes.d.ts +198 -0
- package/dist/protocol/brandTypes.d.ts.map +1 -0
- package/dist/protocol/brandTypes.js +30 -0
- package/dist/protocol/deriveColors.cjs +67 -0
- package/dist/protocol/deriveColors.d.cts +39 -0
- package/dist/protocol/deriveColors.d.ts +39 -0
- package/dist/protocol/deriveColors.d.ts.map +1 -0
- package/dist/protocol/deriveColors.js +67 -0
- package/dist/protocol/index.cjs +55 -0
- package/dist/protocol/index.d.cts +20 -0
- package/dist/protocol/index.d.ts +20 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +55 -0
- package/dist/protocol/messageTypes.cjs +32 -0
- package/dist/protocol/messageTypes.d.cts +86 -0
- package/dist/protocol/messageTypes.d.ts +86 -0
- package/dist/protocol/messageTypes.d.ts.map +1 -0
- package/dist/protocol/messageTypes.js +32 -0
- package/dist/protocol/ootbThemes.cjs +229 -0
- package/dist/protocol/ootbThemes.d.cts +6 -0
- package/dist/protocol/ootbThemes.d.ts +6 -0
- package/dist/protocol/ootbThemes.d.ts.map +1 -0
- package/dist/protocol/ootbThemes.js +229 -0
- package/dist/protocol/themeCss.cjs +47 -0
- package/dist/protocol/themeCss.d.cts +18 -0
- package/dist/protocol/themeCss.d.ts +18 -0
- package/dist/protocol/themeCss.d.ts.map +1 -0
- package/dist/protocol/themeCss.js +47 -0
- package/dist/protocol/types.d.cts +74 -0
- package/dist/protocol/types.d.ts +74 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/utils.cjs +10 -0
- package/dist/protocol/utils.d.cts +20 -0
- package/dist/protocol/utils.d.ts +20 -0
- package/dist/protocol/utils.d.ts.map +1 -0
- package/dist/protocol/utils.js +10 -0
- package/dist/runtime/fontFace.cjs +43 -0
- package/dist/runtime/fontFace.d.cts +15 -0
- package/dist/runtime/fontFace.d.ts +15 -0
- package/dist/runtime/fontFace.d.ts.map +1 -0
- package/dist/runtime/fontFace.js +43 -0
- package/dist/runtime/previewContent.cjs +344 -0
- package/dist/runtime/previewContent.d.cts +43 -0
- package/dist/runtime/previewContent.d.ts +43 -0
- package/dist/runtime/previewContent.d.ts.map +1 -0
- package/dist/runtime/previewContent.js +344 -0
- package/dist/runtime/previewRuntime.d.cts +10 -0
- package/dist/runtime/previewRuntime.d.ts +10 -0
- package/dist/runtime/previewRuntime.d.ts.map +1 -0
- package/dist/runtime/theme-preview-runtime.js +466 -0
- package/package.json +74 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const brandResolver = require("./brandResolver.cjs");
|
|
4
|
+
function formatDimension(dim) {
|
|
5
|
+
return `${dim.value}${dim.unit}`;
|
|
6
|
+
}
|
|
7
|
+
function buildFontStack(font) {
|
|
8
|
+
if (typeof font === "string" && font.startsWith("{!$brand")) {
|
|
9
|
+
return "system-ui, -apple-system, sans-serif";
|
|
10
|
+
}
|
|
11
|
+
if (typeof font === "string") {
|
|
12
|
+
const quoted = font.includes(" ") ? `"${font}"` : font;
|
|
13
|
+
return `${quoted}, sans-serif`;
|
|
14
|
+
}
|
|
15
|
+
if (typeof font === "object" && font && "name" in font) {
|
|
16
|
+
const fontObj = font;
|
|
17
|
+
const parts = [];
|
|
18
|
+
const quotedName = fontObj.name.includes(" ") ? `"${fontObj.name}"` : fontObj.name;
|
|
19
|
+
parts.push(quotedName);
|
|
20
|
+
if (fontObj.fallbacks && fontObj.fallbacks.length > 0) {
|
|
21
|
+
for (const fallback of fontObj.fallbacks) {
|
|
22
|
+
const quoted = fallback.includes(" ") ? `"${fallback}"` : fallback;
|
|
23
|
+
parts.push(quoted);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (fontObj.category) {
|
|
27
|
+
parts.push(fontObj.category);
|
|
28
|
+
}
|
|
29
|
+
return parts.join(", ");
|
|
30
|
+
}
|
|
31
|
+
return "system-ui, -apple-system, sans-serif";
|
|
32
|
+
}
|
|
33
|
+
function brandToVariables(brand) {
|
|
34
|
+
const vars = {};
|
|
35
|
+
if (brand.colorScheme.primaryAccent) {
|
|
36
|
+
vars["--tm-color-primary"] = brand.colorScheme.primaryAccent;
|
|
37
|
+
}
|
|
38
|
+
if (brand.colorScheme.primaryAccentDerived) {
|
|
39
|
+
vars["--tm-color-secondary"] = brand.colorScheme.primaryAccentDerived;
|
|
40
|
+
}
|
|
41
|
+
if (brand.colorScheme.root) {
|
|
42
|
+
vars["--tm-color-background"] = brand.colorScheme.root;
|
|
43
|
+
}
|
|
44
|
+
if (brand.colorScheme.neutral) {
|
|
45
|
+
vars["--tm-color-surface"] = brand.colorScheme.neutral;
|
|
46
|
+
vars["--tm-color-text-secondary"] = brand.colorScheme.neutral;
|
|
47
|
+
}
|
|
48
|
+
if (brand.colorScheme.contrast) {
|
|
49
|
+
vars["--tm-color-text"] = brand.colorScheme.contrast;
|
|
50
|
+
}
|
|
51
|
+
if (brand.colorScheme.primaryAccentContrast) {
|
|
52
|
+
vars["--tm-color-accent"] = brand.colorScheme.primaryAccentContrast;
|
|
53
|
+
}
|
|
54
|
+
if (brand.baseFontFamily) {
|
|
55
|
+
const baseFont = brand.baseFontFamily;
|
|
56
|
+
vars["--tm-font-body"] = buildFontStack(baseFont);
|
|
57
|
+
}
|
|
58
|
+
const heading1 = brand.typography?.heading?.heading1;
|
|
59
|
+
if (heading1?.fontFamily) {
|
|
60
|
+
const headingFont = heading1.fontFamily;
|
|
61
|
+
vars["--tm-font-heading"] = buildFontStack(headingFont);
|
|
62
|
+
}
|
|
63
|
+
if (brand.baseFontSize) {
|
|
64
|
+
vars["--tm-font-size-base"] = formatDimension(brand.baseFontSize);
|
|
65
|
+
}
|
|
66
|
+
if (brand.fontWeight?.normal !== void 0) {
|
|
67
|
+
vars["--tm-body-weight"] = String(brand.fontWeight.normal);
|
|
68
|
+
}
|
|
69
|
+
if (brand.fontWeight?.bold !== void 0) {
|
|
70
|
+
vars["--tm-heading-weight"] = String(brand.fontWeight.bold);
|
|
71
|
+
}
|
|
72
|
+
const paragraph1 = brand.typography?.paragraph?.paragraph1;
|
|
73
|
+
if (paragraph1?.lineHeight !== void 0) {
|
|
74
|
+
vars["--tm-line-height"] = String(paragraph1.lineHeight);
|
|
75
|
+
}
|
|
76
|
+
if (brand.spacing?.medium?.top) {
|
|
77
|
+
vars["--tm-spacing-base"] = formatDimension(brand.spacing.medium.top);
|
|
78
|
+
}
|
|
79
|
+
if (brand.borderRadius?.round) {
|
|
80
|
+
const roundRadius = formatDimension(brand.borderRadius.round);
|
|
81
|
+
vars["--tm-border-radius"] = roundRadius;
|
|
82
|
+
vars["--tm-border-radius-small"] = roundRadius;
|
|
83
|
+
vars["--tm-border-radius-large"] = roundRadius;
|
|
84
|
+
}
|
|
85
|
+
const primaryButton = brand.buttonStyleGroup?.primary;
|
|
86
|
+
if (primaryButton) {
|
|
87
|
+
const colorGroup = primaryButton["lightning:buttonColorGroup"];
|
|
88
|
+
if (colorGroup?.backgroundColor) {
|
|
89
|
+
const bg = colorGroup.backgroundColor;
|
|
90
|
+
vars["--tm-button-primary-bg"] = typeof bg === "string" ? bg : "";
|
|
91
|
+
}
|
|
92
|
+
if (colorGroup?.textColor) {
|
|
93
|
+
const text = colorGroup.textColor;
|
|
94
|
+
vars["--tm-button-primary-text"] = typeof text === "string" ? text : "";
|
|
95
|
+
}
|
|
96
|
+
if (colorGroup?.borderColor) {
|
|
97
|
+
const border = colorGroup.borderColor;
|
|
98
|
+
vars["--tm-button-primary-border"] = typeof border === "string" ? border : "";
|
|
99
|
+
}
|
|
100
|
+
const borderRadius = primaryButton["lightning:borderRadius"];
|
|
101
|
+
if (borderRadius && typeof borderRadius === "object" && "unit" in borderRadius) {
|
|
102
|
+
vars["--tm-button-radius"] = formatDimension(borderRadius);
|
|
103
|
+
}
|
|
104
|
+
const borderWidth = primaryButton["lightning:borderWidth"];
|
|
105
|
+
if (borderWidth && typeof borderWidth === "object" && "unit" in borderWidth) {
|
|
106
|
+
vars["--tm-button-primary-border-width"] = formatDimension(borderWidth);
|
|
107
|
+
}
|
|
108
|
+
const padding = primaryButton["lightning:padding"];
|
|
109
|
+
if (padding?.left) {
|
|
110
|
+
vars["--tm-button-padding-x"] = formatDimension(padding.left);
|
|
111
|
+
}
|
|
112
|
+
if (padding?.top) {
|
|
113
|
+
vars["--tm-button-padding-y"] = formatDimension(padding.top);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const secondaryButton = brand.buttonStyleGroup?.secondary;
|
|
117
|
+
if (secondaryButton) {
|
|
118
|
+
const colorGroup = secondaryButton["lightning:buttonColorGroup"];
|
|
119
|
+
if (colorGroup?.backgroundColor) {
|
|
120
|
+
const bg = colorGroup.backgroundColor;
|
|
121
|
+
vars["--tm-button-secondary-bg"] = typeof bg === "string" ? bg : "";
|
|
122
|
+
}
|
|
123
|
+
if (colorGroup?.textColor) {
|
|
124
|
+
const text = colorGroup.textColor;
|
|
125
|
+
vars["--tm-button-secondary-text"] = typeof text === "string" ? text : "";
|
|
126
|
+
}
|
|
127
|
+
if (colorGroup?.borderColor) {
|
|
128
|
+
const border = colorGroup.borderColor;
|
|
129
|
+
vars["--tm-button-secondary-border"] = typeof border === "string" ? border : "";
|
|
130
|
+
}
|
|
131
|
+
const borderRadius = secondaryButton["lightning:borderRadius"];
|
|
132
|
+
if (borderRadius && typeof borderRadius === "object" && "unit" in borderRadius) {
|
|
133
|
+
vars["--tm-button-secondary-radius"] = formatDimension(borderRadius);
|
|
134
|
+
}
|
|
135
|
+
const borderWidth = secondaryButton["lightning:borderWidth"];
|
|
136
|
+
if (borderWidth && typeof borderWidth === "object" && "unit" in borderWidth) {
|
|
137
|
+
vars["--tm-button-secondary-border-width"] = formatDimension(borderWidth);
|
|
138
|
+
}
|
|
139
|
+
const padding = secondaryButton["lightning:padding"];
|
|
140
|
+
if (padding?.left) {
|
|
141
|
+
vars["--tm-button-secondary-padding-x"] = formatDimension(padding.left);
|
|
142
|
+
}
|
|
143
|
+
if (padding?.top) {
|
|
144
|
+
vars["--tm-button-secondary-padding-y"] = formatDimension(padding.top);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const tertiaryButton = brand.buttonStyleGroup?.tertiary;
|
|
148
|
+
if (tertiaryButton) {
|
|
149
|
+
const colorGroup = tertiaryButton["lightning:buttonColorGroup"];
|
|
150
|
+
if (colorGroup?.backgroundColor) {
|
|
151
|
+
const bg = colorGroup.backgroundColor;
|
|
152
|
+
vars["--tm-button-tertiary-bg"] = typeof bg === "string" ? bg : "";
|
|
153
|
+
}
|
|
154
|
+
if (colorGroup?.textColor) {
|
|
155
|
+
const text = colorGroup.textColor;
|
|
156
|
+
vars["--tm-button-tertiary-text"] = typeof text === "string" ? text : "";
|
|
157
|
+
}
|
|
158
|
+
if (colorGroup?.borderColor) {
|
|
159
|
+
const border = colorGroup.borderColor;
|
|
160
|
+
vars["--tm-button-tertiary-border"] = typeof border === "string" ? border : "";
|
|
161
|
+
}
|
|
162
|
+
const borderRadius = tertiaryButton["lightning:borderRadius"];
|
|
163
|
+
if (borderRadius && typeof borderRadius === "object" && "unit" in borderRadius) {
|
|
164
|
+
vars["--tm-button-tertiary-radius"] = formatDimension(borderRadius);
|
|
165
|
+
}
|
|
166
|
+
const borderWidth = tertiaryButton["lightning:borderWidth"];
|
|
167
|
+
if (borderWidth && typeof borderWidth === "object" && "unit" in borderWidth) {
|
|
168
|
+
vars["--tm-button-tertiary-border-width"] = formatDimension(borderWidth);
|
|
169
|
+
}
|
|
170
|
+
const padding = tertiaryButton["lightning:padding"];
|
|
171
|
+
if (padding?.left) {
|
|
172
|
+
vars["--tm-button-tertiary-padding-x"] = formatDimension(padding.left);
|
|
173
|
+
}
|
|
174
|
+
if (padding?.top) {
|
|
175
|
+
vars["--tm-button-tertiary-padding-y"] = formatDimension(padding.top);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
for (let i = 1; i <= 6; i++) {
|
|
179
|
+
const heading = brand.typography?.heading?.[`heading${i}`];
|
|
180
|
+
if (heading && typeof heading === "object") {
|
|
181
|
+
if (heading.fontFamily) {
|
|
182
|
+
vars[`--tm-heading${i}-font`] = buildFontStack(heading.fontFamily);
|
|
183
|
+
}
|
|
184
|
+
if (heading.fontSize && typeof heading.fontSize === "object" && "unit" in heading.fontSize) {
|
|
185
|
+
vars[`--tm-heading${i}-size`] = formatDimension(heading.fontSize);
|
|
186
|
+
}
|
|
187
|
+
if (heading.fontWeight !== void 0) {
|
|
188
|
+
vars[`--tm-heading${i}-weight`] = String(heading.fontWeight);
|
|
189
|
+
}
|
|
190
|
+
if (heading.lineHeight !== void 0) {
|
|
191
|
+
vars[`--tm-heading${i}-line-height`] = String(heading.lineHeight);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const para1 = brand.typography?.paragraph?.paragraph1;
|
|
196
|
+
if (para1) {
|
|
197
|
+
if (para1.fontFamily) {
|
|
198
|
+
vars["--tm-paragraph1-font"] = buildFontStack(para1.fontFamily);
|
|
199
|
+
}
|
|
200
|
+
if (para1.fontSize && typeof para1.fontSize === "object" && "unit" in para1.fontSize) {
|
|
201
|
+
vars["--tm-paragraph1-size"] = formatDimension(para1.fontSize);
|
|
202
|
+
}
|
|
203
|
+
if (para1.fontWeight !== void 0) {
|
|
204
|
+
vars["--tm-paragraph1-weight"] = String(para1.fontWeight);
|
|
205
|
+
}
|
|
206
|
+
if (para1.lineHeight !== void 0) {
|
|
207
|
+
vars["--tm-paragraph1-line-height"] = String(para1.lineHeight);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const para2 = brand.typography?.paragraph?.paragraph2;
|
|
211
|
+
if (para2) {
|
|
212
|
+
if (para2.fontFamily) {
|
|
213
|
+
vars["--tm-paragraph2-font"] = buildFontStack(para2.fontFamily);
|
|
214
|
+
}
|
|
215
|
+
if (para2.fontSize && typeof para2.fontSize === "object" && "unit" in para2.fontSize) {
|
|
216
|
+
vars["--tm-paragraph2-size"] = formatDimension(para2.fontSize);
|
|
217
|
+
}
|
|
218
|
+
if (para2.fontWeight !== void 0) {
|
|
219
|
+
vars["--tm-paragraph2-weight"] = String(para2.fontWeight);
|
|
220
|
+
}
|
|
221
|
+
if (para2.lineHeight !== void 0) {
|
|
222
|
+
vars["--tm-paragraph2-line-height"] = String(para2.lineHeight);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (brand.borderRadius?.square) {
|
|
226
|
+
vars["--tm-border-radius-square"] = formatDimension(brand.borderRadius.square);
|
|
227
|
+
}
|
|
228
|
+
if (brand.borderRadius?.round) {
|
|
229
|
+
vars["--tm-border-radius-round"] = formatDimension(brand.borderRadius.round);
|
|
230
|
+
}
|
|
231
|
+
if (brand.borderWeight?.medium) {
|
|
232
|
+
vars["--tm-border-weight-medium"] = formatDimension(brand.borderWeight.medium);
|
|
233
|
+
}
|
|
234
|
+
if (brand.borderWeight?.none) {
|
|
235
|
+
vars["--tm-border-weight-none"] = formatDimension(brand.borderWeight.none);
|
|
236
|
+
}
|
|
237
|
+
return vars;
|
|
238
|
+
}
|
|
239
|
+
function generateBrandCss(brand) {
|
|
240
|
+
const resolved = brandResolver.resolveBrandTokens(brand);
|
|
241
|
+
const vars = brandToVariables(resolved);
|
|
242
|
+
const cssVars = Object.entries(vars).map(([key, value]) => ` ${key}: ${value};`).join("\n");
|
|
243
|
+
const title = brand["sfdc_cms:title"] ?? "Untitled Brand";
|
|
244
|
+
return `/**
|
|
245
|
+
* Brand: ${title}
|
|
246
|
+
* Generated by Salesforce UI Theme Manager
|
|
247
|
+
*/
|
|
248
|
+
|
|
249
|
+
:root {
|
|
250
|
+
${cssVars}
|
|
251
|
+
}
|
|
252
|
+
`;
|
|
253
|
+
}
|
|
254
|
+
exports.brandToVariables = brandToVariables;
|
|
255
|
+
exports.generateBrandCss = generateBrandCss;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Brand } from './brandTypes.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* Maps a resolved Brand object to CSS custom properties using the `--tm-*` prefix.
|
|
4
|
+
* Reuses existing --tm-* variable names for semantic compatibility with the Theme preview.
|
|
5
|
+
*
|
|
6
|
+
* Mapping decisions:
|
|
7
|
+
* - colorScheme.primaryAccent -> --tm-color-primary
|
|
8
|
+
* - colorScheme.primaryAccentDerived -> --tm-color-secondary
|
|
9
|
+
* - colorScheme.root -> --tm-color-background
|
|
10
|
+
* - colorScheme.neutral -> --tm-color-surface
|
|
11
|
+
* - colorScheme.contrast -> --tm-color-text
|
|
12
|
+
* - colorScheme.neutral -> --tm-color-text-secondary (reused; no better match in sample)
|
|
13
|
+
* - colorScheme.primaryAccentContrast -> --tm-color-accent
|
|
14
|
+
* - baseFontFamily (resolved to font name) -> --tm-font-body
|
|
15
|
+
* - typography.heading.heading1.fontFamily (resolved) -> --tm-font-heading
|
|
16
|
+
* - baseFontSize -> --tm-font-size-base
|
|
17
|
+
* - fontWeight.normal -> --tm-body-weight
|
|
18
|
+
* - fontWeight.bold -> --tm-heading-weight
|
|
19
|
+
* - typography.paragraph.paragraph1.lineHeight -> --tm-line-height
|
|
20
|
+
* - spacing.medium -> --tm-spacing-base
|
|
21
|
+
* - borderRadius.round -> --tm-border-radius
|
|
22
|
+
* - borderRadius.round (reused) -> --tm-border-radius-small
|
|
23
|
+
* - borderRadius.round (reused) -> --tm-border-radius-large
|
|
24
|
+
* - buttonStyleGroup.primary buttonColorGroup.backgroundColor -> --tm-button-primary-bg
|
|
25
|
+
* - buttonStyleGroup.primary buttonColorGroup.textColor -> --tm-button-primary-text
|
|
26
|
+
* - buttonStyleGroup.primary lightning:borderRadius -> --tm-button-radius
|
|
27
|
+
* - buttonStyleGroup.primary lightning:padding left/right -> --tm-button-padding-x
|
|
28
|
+
* - buttonStyleGroup.primary lightning:padding top/bottom -> --tm-button-padding-y
|
|
29
|
+
*
|
|
30
|
+
* @param brand - The brand object (should be resolved first)
|
|
31
|
+
* @returns Record of CSS variable names to values
|
|
32
|
+
*/
|
|
33
|
+
export declare function brandToVariables(brand: Brand): Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Generates a complete CSS stylesheet string with `:root` selector and
|
|
36
|
+
* all brand variables.
|
|
37
|
+
*
|
|
38
|
+
* @param brand - The brand to convert (will be resolved automatically)
|
|
39
|
+
* @returns CSS string ready for injection or file output
|
|
40
|
+
*/
|
|
41
|
+
export declare function generateBrandCss(brand: Brand): string;
|
|
42
|
+
//# sourceMappingURL=brandCss.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Brand } from './brandTypes.js';
|
|
2
|
+
/**
|
|
3
|
+
* Maps a resolved Brand object to CSS custom properties using the `--tm-*` prefix.
|
|
4
|
+
* Reuses existing --tm-* variable names for semantic compatibility with the Theme preview.
|
|
5
|
+
*
|
|
6
|
+
* Mapping decisions:
|
|
7
|
+
* - colorScheme.primaryAccent -> --tm-color-primary
|
|
8
|
+
* - colorScheme.primaryAccentDerived -> --tm-color-secondary
|
|
9
|
+
* - colorScheme.root -> --tm-color-background
|
|
10
|
+
* - colorScheme.neutral -> --tm-color-surface
|
|
11
|
+
* - colorScheme.contrast -> --tm-color-text
|
|
12
|
+
* - colorScheme.neutral -> --tm-color-text-secondary (reused; no better match in sample)
|
|
13
|
+
* - colorScheme.primaryAccentContrast -> --tm-color-accent
|
|
14
|
+
* - baseFontFamily (resolved to font name) -> --tm-font-body
|
|
15
|
+
* - typography.heading.heading1.fontFamily (resolved) -> --tm-font-heading
|
|
16
|
+
* - baseFontSize -> --tm-font-size-base
|
|
17
|
+
* - fontWeight.normal -> --tm-body-weight
|
|
18
|
+
* - fontWeight.bold -> --tm-heading-weight
|
|
19
|
+
* - typography.paragraph.paragraph1.lineHeight -> --tm-line-height
|
|
20
|
+
* - spacing.medium -> --tm-spacing-base
|
|
21
|
+
* - borderRadius.round -> --tm-border-radius
|
|
22
|
+
* - borderRadius.round (reused) -> --tm-border-radius-small
|
|
23
|
+
* - borderRadius.round (reused) -> --tm-border-radius-large
|
|
24
|
+
* - buttonStyleGroup.primary buttonColorGroup.backgroundColor -> --tm-button-primary-bg
|
|
25
|
+
* - buttonStyleGroup.primary buttonColorGroup.textColor -> --tm-button-primary-text
|
|
26
|
+
* - buttonStyleGroup.primary lightning:borderRadius -> --tm-button-radius
|
|
27
|
+
* - buttonStyleGroup.primary lightning:padding left/right -> --tm-button-padding-x
|
|
28
|
+
* - buttonStyleGroup.primary lightning:padding top/bottom -> --tm-button-padding-y
|
|
29
|
+
*
|
|
30
|
+
* @param brand - The brand object (should be resolved first)
|
|
31
|
+
* @returns Record of CSS variable names to values
|
|
32
|
+
*/
|
|
33
|
+
export declare function brandToVariables(brand: Brand): Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Generates a complete CSS stylesheet string with `:root` selector and
|
|
36
|
+
* all brand variables.
|
|
37
|
+
*
|
|
38
|
+
* @param brand - The brand to convert (will be resolved automatically)
|
|
39
|
+
* @returns CSS string ready for injection or file output
|
|
40
|
+
*/
|
|
41
|
+
export declare function generateBrandCss(brand: Brand): string;
|
|
42
|
+
//# sourceMappingURL=brandCss.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brandCss.d.ts","sourceRoot":"","sources":["../../src/protocol/brandCss.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAmC,MAAM,cAAc,CAAC;AAyD3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAiPrE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAkBrD"}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { resolveBrandTokens } from "./brandResolver.js";
|
|
2
|
+
function formatDimension(dim) {
|
|
3
|
+
return `${dim.value}${dim.unit}`;
|
|
4
|
+
}
|
|
5
|
+
function buildFontStack(font) {
|
|
6
|
+
if (typeof font === "string" && font.startsWith("{!$brand")) {
|
|
7
|
+
return "system-ui, -apple-system, sans-serif";
|
|
8
|
+
}
|
|
9
|
+
if (typeof font === "string") {
|
|
10
|
+
const quoted = font.includes(" ") ? `"${font}"` : font;
|
|
11
|
+
return `${quoted}, sans-serif`;
|
|
12
|
+
}
|
|
13
|
+
if (typeof font === "object" && font && "name" in font) {
|
|
14
|
+
const fontObj = font;
|
|
15
|
+
const parts = [];
|
|
16
|
+
const quotedName = fontObj.name.includes(" ") ? `"${fontObj.name}"` : fontObj.name;
|
|
17
|
+
parts.push(quotedName);
|
|
18
|
+
if (fontObj.fallbacks && fontObj.fallbacks.length > 0) {
|
|
19
|
+
for (const fallback of fontObj.fallbacks) {
|
|
20
|
+
const quoted = fallback.includes(" ") ? `"${fallback}"` : fallback;
|
|
21
|
+
parts.push(quoted);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (fontObj.category) {
|
|
25
|
+
parts.push(fontObj.category);
|
|
26
|
+
}
|
|
27
|
+
return parts.join(", ");
|
|
28
|
+
}
|
|
29
|
+
return "system-ui, -apple-system, sans-serif";
|
|
30
|
+
}
|
|
31
|
+
function brandToVariables(brand) {
|
|
32
|
+
const vars = {};
|
|
33
|
+
if (brand.colorScheme.primaryAccent) {
|
|
34
|
+
vars["--tm-color-primary"] = brand.colorScheme.primaryAccent;
|
|
35
|
+
}
|
|
36
|
+
if (brand.colorScheme.primaryAccentDerived) {
|
|
37
|
+
vars["--tm-color-secondary"] = brand.colorScheme.primaryAccentDerived;
|
|
38
|
+
}
|
|
39
|
+
if (brand.colorScheme.root) {
|
|
40
|
+
vars["--tm-color-background"] = brand.colorScheme.root;
|
|
41
|
+
}
|
|
42
|
+
if (brand.colorScheme.neutral) {
|
|
43
|
+
vars["--tm-color-surface"] = brand.colorScheme.neutral;
|
|
44
|
+
vars["--tm-color-text-secondary"] = brand.colorScheme.neutral;
|
|
45
|
+
}
|
|
46
|
+
if (brand.colorScheme.contrast) {
|
|
47
|
+
vars["--tm-color-text"] = brand.colorScheme.contrast;
|
|
48
|
+
}
|
|
49
|
+
if (brand.colorScheme.primaryAccentContrast) {
|
|
50
|
+
vars["--tm-color-accent"] = brand.colorScheme.primaryAccentContrast;
|
|
51
|
+
}
|
|
52
|
+
if (brand.baseFontFamily) {
|
|
53
|
+
const baseFont = brand.baseFontFamily;
|
|
54
|
+
vars["--tm-font-body"] = buildFontStack(baseFont);
|
|
55
|
+
}
|
|
56
|
+
const heading1 = brand.typography?.heading?.heading1;
|
|
57
|
+
if (heading1?.fontFamily) {
|
|
58
|
+
const headingFont = heading1.fontFamily;
|
|
59
|
+
vars["--tm-font-heading"] = buildFontStack(headingFont);
|
|
60
|
+
}
|
|
61
|
+
if (brand.baseFontSize) {
|
|
62
|
+
vars["--tm-font-size-base"] = formatDimension(brand.baseFontSize);
|
|
63
|
+
}
|
|
64
|
+
if (brand.fontWeight?.normal !== void 0) {
|
|
65
|
+
vars["--tm-body-weight"] = String(brand.fontWeight.normal);
|
|
66
|
+
}
|
|
67
|
+
if (brand.fontWeight?.bold !== void 0) {
|
|
68
|
+
vars["--tm-heading-weight"] = String(brand.fontWeight.bold);
|
|
69
|
+
}
|
|
70
|
+
const paragraph1 = brand.typography?.paragraph?.paragraph1;
|
|
71
|
+
if (paragraph1?.lineHeight !== void 0) {
|
|
72
|
+
vars["--tm-line-height"] = String(paragraph1.lineHeight);
|
|
73
|
+
}
|
|
74
|
+
if (brand.spacing?.medium?.top) {
|
|
75
|
+
vars["--tm-spacing-base"] = formatDimension(brand.spacing.medium.top);
|
|
76
|
+
}
|
|
77
|
+
if (brand.borderRadius?.round) {
|
|
78
|
+
const roundRadius = formatDimension(brand.borderRadius.round);
|
|
79
|
+
vars["--tm-border-radius"] = roundRadius;
|
|
80
|
+
vars["--tm-border-radius-small"] = roundRadius;
|
|
81
|
+
vars["--tm-border-radius-large"] = roundRadius;
|
|
82
|
+
}
|
|
83
|
+
const primaryButton = brand.buttonStyleGroup?.primary;
|
|
84
|
+
if (primaryButton) {
|
|
85
|
+
const colorGroup = primaryButton["lightning:buttonColorGroup"];
|
|
86
|
+
if (colorGroup?.backgroundColor) {
|
|
87
|
+
const bg = colorGroup.backgroundColor;
|
|
88
|
+
vars["--tm-button-primary-bg"] = typeof bg === "string" ? bg : "";
|
|
89
|
+
}
|
|
90
|
+
if (colorGroup?.textColor) {
|
|
91
|
+
const text = colorGroup.textColor;
|
|
92
|
+
vars["--tm-button-primary-text"] = typeof text === "string" ? text : "";
|
|
93
|
+
}
|
|
94
|
+
if (colorGroup?.borderColor) {
|
|
95
|
+
const border = colorGroup.borderColor;
|
|
96
|
+
vars["--tm-button-primary-border"] = typeof border === "string" ? border : "";
|
|
97
|
+
}
|
|
98
|
+
const borderRadius = primaryButton["lightning:borderRadius"];
|
|
99
|
+
if (borderRadius && typeof borderRadius === "object" && "unit" in borderRadius) {
|
|
100
|
+
vars["--tm-button-radius"] = formatDimension(borderRadius);
|
|
101
|
+
}
|
|
102
|
+
const borderWidth = primaryButton["lightning:borderWidth"];
|
|
103
|
+
if (borderWidth && typeof borderWidth === "object" && "unit" in borderWidth) {
|
|
104
|
+
vars["--tm-button-primary-border-width"] = formatDimension(borderWidth);
|
|
105
|
+
}
|
|
106
|
+
const padding = primaryButton["lightning:padding"];
|
|
107
|
+
if (padding?.left) {
|
|
108
|
+
vars["--tm-button-padding-x"] = formatDimension(padding.left);
|
|
109
|
+
}
|
|
110
|
+
if (padding?.top) {
|
|
111
|
+
vars["--tm-button-padding-y"] = formatDimension(padding.top);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const secondaryButton = brand.buttonStyleGroup?.secondary;
|
|
115
|
+
if (secondaryButton) {
|
|
116
|
+
const colorGroup = secondaryButton["lightning:buttonColorGroup"];
|
|
117
|
+
if (colorGroup?.backgroundColor) {
|
|
118
|
+
const bg = colorGroup.backgroundColor;
|
|
119
|
+
vars["--tm-button-secondary-bg"] = typeof bg === "string" ? bg : "";
|
|
120
|
+
}
|
|
121
|
+
if (colorGroup?.textColor) {
|
|
122
|
+
const text = colorGroup.textColor;
|
|
123
|
+
vars["--tm-button-secondary-text"] = typeof text === "string" ? text : "";
|
|
124
|
+
}
|
|
125
|
+
if (colorGroup?.borderColor) {
|
|
126
|
+
const border = colorGroup.borderColor;
|
|
127
|
+
vars["--tm-button-secondary-border"] = typeof border === "string" ? border : "";
|
|
128
|
+
}
|
|
129
|
+
const borderRadius = secondaryButton["lightning:borderRadius"];
|
|
130
|
+
if (borderRadius && typeof borderRadius === "object" && "unit" in borderRadius) {
|
|
131
|
+
vars["--tm-button-secondary-radius"] = formatDimension(borderRadius);
|
|
132
|
+
}
|
|
133
|
+
const borderWidth = secondaryButton["lightning:borderWidth"];
|
|
134
|
+
if (borderWidth && typeof borderWidth === "object" && "unit" in borderWidth) {
|
|
135
|
+
vars["--tm-button-secondary-border-width"] = formatDimension(borderWidth);
|
|
136
|
+
}
|
|
137
|
+
const padding = secondaryButton["lightning:padding"];
|
|
138
|
+
if (padding?.left) {
|
|
139
|
+
vars["--tm-button-secondary-padding-x"] = formatDimension(padding.left);
|
|
140
|
+
}
|
|
141
|
+
if (padding?.top) {
|
|
142
|
+
vars["--tm-button-secondary-padding-y"] = formatDimension(padding.top);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const tertiaryButton = brand.buttonStyleGroup?.tertiary;
|
|
146
|
+
if (tertiaryButton) {
|
|
147
|
+
const colorGroup = tertiaryButton["lightning:buttonColorGroup"];
|
|
148
|
+
if (colorGroup?.backgroundColor) {
|
|
149
|
+
const bg = colorGroup.backgroundColor;
|
|
150
|
+
vars["--tm-button-tertiary-bg"] = typeof bg === "string" ? bg : "";
|
|
151
|
+
}
|
|
152
|
+
if (colorGroup?.textColor) {
|
|
153
|
+
const text = colorGroup.textColor;
|
|
154
|
+
vars["--tm-button-tertiary-text"] = typeof text === "string" ? text : "";
|
|
155
|
+
}
|
|
156
|
+
if (colorGroup?.borderColor) {
|
|
157
|
+
const border = colorGroup.borderColor;
|
|
158
|
+
vars["--tm-button-tertiary-border"] = typeof border === "string" ? border : "";
|
|
159
|
+
}
|
|
160
|
+
const borderRadius = tertiaryButton["lightning:borderRadius"];
|
|
161
|
+
if (borderRadius && typeof borderRadius === "object" && "unit" in borderRadius) {
|
|
162
|
+
vars["--tm-button-tertiary-radius"] = formatDimension(borderRadius);
|
|
163
|
+
}
|
|
164
|
+
const borderWidth = tertiaryButton["lightning:borderWidth"];
|
|
165
|
+
if (borderWidth && typeof borderWidth === "object" && "unit" in borderWidth) {
|
|
166
|
+
vars["--tm-button-tertiary-border-width"] = formatDimension(borderWidth);
|
|
167
|
+
}
|
|
168
|
+
const padding = tertiaryButton["lightning:padding"];
|
|
169
|
+
if (padding?.left) {
|
|
170
|
+
vars["--tm-button-tertiary-padding-x"] = formatDimension(padding.left);
|
|
171
|
+
}
|
|
172
|
+
if (padding?.top) {
|
|
173
|
+
vars["--tm-button-tertiary-padding-y"] = formatDimension(padding.top);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
for (let i = 1; i <= 6; i++) {
|
|
177
|
+
const heading = brand.typography?.heading?.[`heading${i}`];
|
|
178
|
+
if (heading && typeof heading === "object") {
|
|
179
|
+
if (heading.fontFamily) {
|
|
180
|
+
vars[`--tm-heading${i}-font`] = buildFontStack(heading.fontFamily);
|
|
181
|
+
}
|
|
182
|
+
if (heading.fontSize && typeof heading.fontSize === "object" && "unit" in heading.fontSize) {
|
|
183
|
+
vars[`--tm-heading${i}-size`] = formatDimension(heading.fontSize);
|
|
184
|
+
}
|
|
185
|
+
if (heading.fontWeight !== void 0) {
|
|
186
|
+
vars[`--tm-heading${i}-weight`] = String(heading.fontWeight);
|
|
187
|
+
}
|
|
188
|
+
if (heading.lineHeight !== void 0) {
|
|
189
|
+
vars[`--tm-heading${i}-line-height`] = String(heading.lineHeight);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const para1 = brand.typography?.paragraph?.paragraph1;
|
|
194
|
+
if (para1) {
|
|
195
|
+
if (para1.fontFamily) {
|
|
196
|
+
vars["--tm-paragraph1-font"] = buildFontStack(para1.fontFamily);
|
|
197
|
+
}
|
|
198
|
+
if (para1.fontSize && typeof para1.fontSize === "object" && "unit" in para1.fontSize) {
|
|
199
|
+
vars["--tm-paragraph1-size"] = formatDimension(para1.fontSize);
|
|
200
|
+
}
|
|
201
|
+
if (para1.fontWeight !== void 0) {
|
|
202
|
+
vars["--tm-paragraph1-weight"] = String(para1.fontWeight);
|
|
203
|
+
}
|
|
204
|
+
if (para1.lineHeight !== void 0) {
|
|
205
|
+
vars["--tm-paragraph1-line-height"] = String(para1.lineHeight);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const para2 = brand.typography?.paragraph?.paragraph2;
|
|
209
|
+
if (para2) {
|
|
210
|
+
if (para2.fontFamily) {
|
|
211
|
+
vars["--tm-paragraph2-font"] = buildFontStack(para2.fontFamily);
|
|
212
|
+
}
|
|
213
|
+
if (para2.fontSize && typeof para2.fontSize === "object" && "unit" in para2.fontSize) {
|
|
214
|
+
vars["--tm-paragraph2-size"] = formatDimension(para2.fontSize);
|
|
215
|
+
}
|
|
216
|
+
if (para2.fontWeight !== void 0) {
|
|
217
|
+
vars["--tm-paragraph2-weight"] = String(para2.fontWeight);
|
|
218
|
+
}
|
|
219
|
+
if (para2.lineHeight !== void 0) {
|
|
220
|
+
vars["--tm-paragraph2-line-height"] = String(para2.lineHeight);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (brand.borderRadius?.square) {
|
|
224
|
+
vars["--tm-border-radius-square"] = formatDimension(brand.borderRadius.square);
|
|
225
|
+
}
|
|
226
|
+
if (brand.borderRadius?.round) {
|
|
227
|
+
vars["--tm-border-radius-round"] = formatDimension(brand.borderRadius.round);
|
|
228
|
+
}
|
|
229
|
+
if (brand.borderWeight?.medium) {
|
|
230
|
+
vars["--tm-border-weight-medium"] = formatDimension(brand.borderWeight.medium);
|
|
231
|
+
}
|
|
232
|
+
if (brand.borderWeight?.none) {
|
|
233
|
+
vars["--tm-border-weight-none"] = formatDimension(brand.borderWeight.none);
|
|
234
|
+
}
|
|
235
|
+
return vars;
|
|
236
|
+
}
|
|
237
|
+
function generateBrandCss(brand) {
|
|
238
|
+
const resolved = resolveBrandTokens(brand);
|
|
239
|
+
const vars = brandToVariables(resolved);
|
|
240
|
+
const cssVars = Object.entries(vars).map(([key, value]) => ` ${key}: ${value};`).join("\n");
|
|
241
|
+
const title = brand["sfdc_cms:title"] ?? "Untitled Brand";
|
|
242
|
+
return `/**
|
|
243
|
+
* Brand: ${title}
|
|
244
|
+
* Generated by Salesforce UI Theme Manager
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
:root {
|
|
248
|
+
${cssVars}
|
|
249
|
+
}
|
|
250
|
+
`;
|
|
251
|
+
}
|
|
252
|
+
export {
|
|
253
|
+
brandToVariables,
|
|
254
|
+
generateBrandCss
|
|
255
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const BRAND_REF_PATTERN = /^\{!\$brand\.([^}]+)\}$/;
|
|
4
|
+
const MAX_RESOLVE_DEPTH = 10;
|
|
5
|
+
function isBrandRef(value) {
|
|
6
|
+
return typeof value === "string" && BRAND_REF_PATTERN.test(value);
|
|
7
|
+
}
|
|
8
|
+
function resolveRef(brand, ref, depth = 0) {
|
|
9
|
+
if (depth > MAX_RESOLVE_DEPTH) {
|
|
10
|
+
throw new Error(`Max resolution depth exceeded resolving: ${ref}`);
|
|
11
|
+
}
|
|
12
|
+
if (!isBrandRef(ref)) {
|
|
13
|
+
return ref;
|
|
14
|
+
}
|
|
15
|
+
const match = ref.match(BRAND_REF_PATTERN);
|
|
16
|
+
if (!match || !match[1]) {
|
|
17
|
+
return ref;
|
|
18
|
+
}
|
|
19
|
+
const path = match[1];
|
|
20
|
+
const parts = path.split(".");
|
|
21
|
+
let current = brand;
|
|
22
|
+
for (const part of parts) {
|
|
23
|
+
if (current == null || typeof current !== "object") {
|
|
24
|
+
throw new Error(`Invalid reference path: ${ref} (failed at ${part})`);
|
|
25
|
+
}
|
|
26
|
+
current = current[part];
|
|
27
|
+
if (current === void 0) {
|
|
28
|
+
throw new Error(`Reference not found: ${ref} (${part} is undefined)`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (isBrandRef(current)) {
|
|
32
|
+
return resolveRef(brand, current, depth + 1);
|
|
33
|
+
}
|
|
34
|
+
return current;
|
|
35
|
+
}
|
|
36
|
+
function resolveValue(brand, value) {
|
|
37
|
+
if (value == null) {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
if (isBrandRef(value)) {
|
|
41
|
+
const resolved = resolveRef(brand, value);
|
|
42
|
+
return resolveValue(brand, resolved);
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(value)) {
|
|
45
|
+
return value.map((item) => resolveValue(brand, item));
|
|
46
|
+
}
|
|
47
|
+
if (typeof value === "object") {
|
|
48
|
+
const result = {};
|
|
49
|
+
for (const [key, val] of Object.entries(value)) {
|
|
50
|
+
result[key] = resolveValue(brand, val);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
function resolveBrandTokens(brand) {
|
|
57
|
+
return resolveValue(brand, brand);
|
|
58
|
+
}
|
|
59
|
+
exports.isBrandRef = isBrandRef;
|
|
60
|
+
exports.resolveBrandTokens = resolveBrandTokens;
|
|
61
|
+
exports.resolveRef = resolveRef;
|