@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,466 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme Preview Runtime (Bundled)
|
|
3
|
+
*
|
|
4
|
+
* Auto-generated by esbuild from the modular theme preview runtime.
|
|
5
|
+
* Do not edit this file directly - edit previewRuntime.ts.
|
|
6
|
+
*/
|
|
7
|
+
(function () {
|
|
8
|
+
|
|
9
|
+
"use strict";
|
|
10
|
+
(() => {
|
|
11
|
+
// src/runtime/fontFace.ts
|
|
12
|
+
var KNOWN_FONTS = {
|
|
13
|
+
"Salesforce Sans": "https://c1.sfdcstatic.com/etc/clientlibs/sfdc-aem-master/clientlibs_base/fonts/SalesforceSans.woff2"
|
|
14
|
+
};
|
|
15
|
+
function generateFontFaceRules(brand) {
|
|
16
|
+
const rules = [];
|
|
17
|
+
const processedFonts = /* @__PURE__ */ new Set();
|
|
18
|
+
const addFontFace = (font) => {
|
|
19
|
+
if (!font || typeof font !== "object") return;
|
|
20
|
+
if (!("name" in font)) return;
|
|
21
|
+
const fontObj = font;
|
|
22
|
+
const name = fontObj.name;
|
|
23
|
+
if (processedFonts.has(name)) return;
|
|
24
|
+
processedFonts.add(name);
|
|
25
|
+
const fontUrl = fontObj.url || fontObj.src || fontObj.fontUrl || fontObj.woff2;
|
|
26
|
+
if (fontUrl) {
|
|
27
|
+
rules.push(` @font-face {
|
|
28
|
+
font-family: "${name}";
|
|
29
|
+
src: url("${fontUrl}") format("woff2");
|
|
30
|
+
font-display: swap;
|
|
31
|
+
}`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (KNOWN_FONTS[name]) {
|
|
35
|
+
rules.push(` @font-face {
|
|
36
|
+
font-family: "${name}";
|
|
37
|
+
src: url("${KNOWN_FONTS[name]}") format("woff2");
|
|
38
|
+
font-display: swap;
|
|
39
|
+
}`);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
if (brand.baseFontFamily) {
|
|
43
|
+
addFontFace(brand.baseFontFamily);
|
|
44
|
+
}
|
|
45
|
+
const heading1 = brand.typography?.heading?.heading1;
|
|
46
|
+
if (heading1?.fontFamily) {
|
|
47
|
+
addFontFace(heading1.fontFamily);
|
|
48
|
+
}
|
|
49
|
+
return rules.length > 0 ? "\n" + rules.join("\n") + "\n" : "";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/protocol/brandResolver.ts
|
|
53
|
+
var BRAND_REF_PATTERN = /^\{!\$brand\.([^}]+)\}$/;
|
|
54
|
+
var MAX_RESOLVE_DEPTH = 10;
|
|
55
|
+
function isBrandRef(value) {
|
|
56
|
+
return typeof value === "string" && BRAND_REF_PATTERN.test(value);
|
|
57
|
+
}
|
|
58
|
+
function resolveRef(brand, ref, depth = 0) {
|
|
59
|
+
if (depth > MAX_RESOLVE_DEPTH) {
|
|
60
|
+
throw new Error(`Max resolution depth exceeded resolving: ${ref}`);
|
|
61
|
+
}
|
|
62
|
+
if (!isBrandRef(ref)) {
|
|
63
|
+
return ref;
|
|
64
|
+
}
|
|
65
|
+
const match = ref.match(BRAND_REF_PATTERN);
|
|
66
|
+
if (!match || !match[1]) {
|
|
67
|
+
return ref;
|
|
68
|
+
}
|
|
69
|
+
const path = match[1];
|
|
70
|
+
const parts = path.split(".");
|
|
71
|
+
let current = brand;
|
|
72
|
+
for (const part of parts) {
|
|
73
|
+
if (current == null || typeof current !== "object") {
|
|
74
|
+
throw new Error(`Invalid reference path: ${ref} (failed at ${part})`);
|
|
75
|
+
}
|
|
76
|
+
current = current[part];
|
|
77
|
+
if (current === void 0) {
|
|
78
|
+
throw new Error(`Reference not found: ${ref} (${part} is undefined)`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (isBrandRef(current)) {
|
|
82
|
+
return resolveRef(brand, current, depth + 1);
|
|
83
|
+
}
|
|
84
|
+
return current;
|
|
85
|
+
}
|
|
86
|
+
function resolveValue(brand, value) {
|
|
87
|
+
if (value == null) {
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
if (isBrandRef(value)) {
|
|
91
|
+
const resolved = resolveRef(brand, value);
|
|
92
|
+
return resolveValue(brand, resolved);
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(value)) {
|
|
95
|
+
return value.map((item) => resolveValue(brand, item));
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === "object") {
|
|
98
|
+
const result = {};
|
|
99
|
+
for (const [key, val] of Object.entries(value)) {
|
|
100
|
+
result[key] = resolveValue(brand, val);
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
function resolveBrandTokens(brand) {
|
|
107
|
+
return resolveValue(brand, brand);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/protocol/brandCss.ts
|
|
111
|
+
function formatDimension(dim) {
|
|
112
|
+
return `${dim.value}${dim.unit}`;
|
|
113
|
+
}
|
|
114
|
+
function buildFontStack(font) {
|
|
115
|
+
if (typeof font === "string" && font.startsWith("{!$brand")) {
|
|
116
|
+
return "system-ui, -apple-system, sans-serif";
|
|
117
|
+
}
|
|
118
|
+
if (typeof font === "string") {
|
|
119
|
+
const quoted = font.includes(" ") ? `"${font}"` : font;
|
|
120
|
+
return `${quoted}, sans-serif`;
|
|
121
|
+
}
|
|
122
|
+
if (typeof font === "object" && font && "name" in font) {
|
|
123
|
+
const fontObj = font;
|
|
124
|
+
const parts = [];
|
|
125
|
+
const quotedName = fontObj.name.includes(" ") ? `"${fontObj.name}"` : fontObj.name;
|
|
126
|
+
parts.push(quotedName);
|
|
127
|
+
if (fontObj.fallbacks && fontObj.fallbacks.length > 0) {
|
|
128
|
+
for (const fallback of fontObj.fallbacks) {
|
|
129
|
+
const quoted = fallback.includes(" ") ? `"${fallback}"` : fallback;
|
|
130
|
+
parts.push(quoted);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (fontObj.category) {
|
|
134
|
+
parts.push(fontObj.category);
|
|
135
|
+
}
|
|
136
|
+
return parts.join(", ");
|
|
137
|
+
}
|
|
138
|
+
return "system-ui, -apple-system, sans-serif";
|
|
139
|
+
}
|
|
140
|
+
function brandToVariables(brand) {
|
|
141
|
+
const vars = {};
|
|
142
|
+
if (brand.colorScheme.primaryAccent) {
|
|
143
|
+
vars["--tm-color-primary"] = brand.colorScheme.primaryAccent;
|
|
144
|
+
}
|
|
145
|
+
if (brand.colorScheme.primaryAccentDerived) {
|
|
146
|
+
vars["--tm-color-secondary"] = brand.colorScheme.primaryAccentDerived;
|
|
147
|
+
}
|
|
148
|
+
if (brand.colorScheme.root) {
|
|
149
|
+
vars["--tm-color-background"] = brand.colorScheme.root;
|
|
150
|
+
}
|
|
151
|
+
if (brand.colorScheme.neutral) {
|
|
152
|
+
vars["--tm-color-surface"] = brand.colorScheme.neutral;
|
|
153
|
+
vars["--tm-color-text-secondary"] = brand.colorScheme.neutral;
|
|
154
|
+
}
|
|
155
|
+
if (brand.colorScheme.contrast) {
|
|
156
|
+
vars["--tm-color-text"] = brand.colorScheme.contrast;
|
|
157
|
+
}
|
|
158
|
+
if (brand.colorScheme.primaryAccentContrast) {
|
|
159
|
+
vars["--tm-color-accent"] = brand.colorScheme.primaryAccentContrast;
|
|
160
|
+
}
|
|
161
|
+
if (brand.baseFontFamily) {
|
|
162
|
+
const baseFont = brand.baseFontFamily;
|
|
163
|
+
vars["--tm-font-body"] = buildFontStack(baseFont);
|
|
164
|
+
}
|
|
165
|
+
const heading1 = brand.typography?.heading?.heading1;
|
|
166
|
+
if (heading1?.fontFamily) {
|
|
167
|
+
const headingFont = heading1.fontFamily;
|
|
168
|
+
vars["--tm-font-heading"] = buildFontStack(headingFont);
|
|
169
|
+
}
|
|
170
|
+
if (brand.baseFontSize) {
|
|
171
|
+
vars["--tm-font-size-base"] = formatDimension(brand.baseFontSize);
|
|
172
|
+
}
|
|
173
|
+
if (brand.fontWeight?.normal !== void 0) {
|
|
174
|
+
vars["--tm-body-weight"] = String(brand.fontWeight.normal);
|
|
175
|
+
}
|
|
176
|
+
if (brand.fontWeight?.bold !== void 0) {
|
|
177
|
+
vars["--tm-heading-weight"] = String(brand.fontWeight.bold);
|
|
178
|
+
}
|
|
179
|
+
const paragraph1 = brand.typography?.paragraph?.paragraph1;
|
|
180
|
+
if (paragraph1?.lineHeight !== void 0) {
|
|
181
|
+
vars["--tm-line-height"] = String(paragraph1.lineHeight);
|
|
182
|
+
}
|
|
183
|
+
if (brand.spacing?.medium?.top) {
|
|
184
|
+
vars["--tm-spacing-base"] = formatDimension(brand.spacing.medium.top);
|
|
185
|
+
}
|
|
186
|
+
if (brand.borderRadius?.round) {
|
|
187
|
+
const roundRadius = formatDimension(brand.borderRadius.round);
|
|
188
|
+
vars["--tm-border-radius"] = roundRadius;
|
|
189
|
+
vars["--tm-border-radius-small"] = roundRadius;
|
|
190
|
+
vars["--tm-border-radius-large"] = roundRadius;
|
|
191
|
+
}
|
|
192
|
+
const primaryButton = brand.buttonStyleGroup?.primary;
|
|
193
|
+
if (primaryButton) {
|
|
194
|
+
const colorGroup = primaryButton["lightning:buttonColorGroup"];
|
|
195
|
+
if (colorGroup?.backgroundColor) {
|
|
196
|
+
const bg = colorGroup.backgroundColor;
|
|
197
|
+
vars["--tm-button-primary-bg"] = typeof bg === "string" ? bg : "";
|
|
198
|
+
}
|
|
199
|
+
if (colorGroup?.textColor) {
|
|
200
|
+
const text = colorGroup.textColor;
|
|
201
|
+
vars["--tm-button-primary-text"] = typeof text === "string" ? text : "";
|
|
202
|
+
}
|
|
203
|
+
if (colorGroup?.borderColor) {
|
|
204
|
+
const border = colorGroup.borderColor;
|
|
205
|
+
vars["--tm-button-primary-border"] = typeof border === "string" ? border : "";
|
|
206
|
+
}
|
|
207
|
+
const borderRadius = primaryButton["lightning:borderRadius"];
|
|
208
|
+
if (borderRadius && typeof borderRadius === "object" && "unit" in borderRadius) {
|
|
209
|
+
vars["--tm-button-radius"] = formatDimension(borderRadius);
|
|
210
|
+
}
|
|
211
|
+
const borderWidth = primaryButton["lightning:borderWidth"];
|
|
212
|
+
if (borderWidth && typeof borderWidth === "object" && "unit" in borderWidth) {
|
|
213
|
+
vars["--tm-button-primary-border-width"] = formatDimension(borderWidth);
|
|
214
|
+
}
|
|
215
|
+
const padding = primaryButton["lightning:padding"];
|
|
216
|
+
if (padding?.left) {
|
|
217
|
+
vars["--tm-button-padding-x"] = formatDimension(padding.left);
|
|
218
|
+
}
|
|
219
|
+
if (padding?.top) {
|
|
220
|
+
vars["--tm-button-padding-y"] = formatDimension(padding.top);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const secondaryButton = brand.buttonStyleGroup?.secondary;
|
|
224
|
+
if (secondaryButton) {
|
|
225
|
+
const colorGroup = secondaryButton["lightning:buttonColorGroup"];
|
|
226
|
+
if (colorGroup?.backgroundColor) {
|
|
227
|
+
const bg = colorGroup.backgroundColor;
|
|
228
|
+
vars["--tm-button-secondary-bg"] = typeof bg === "string" ? bg : "";
|
|
229
|
+
}
|
|
230
|
+
if (colorGroup?.textColor) {
|
|
231
|
+
const text = colorGroup.textColor;
|
|
232
|
+
vars["--tm-button-secondary-text"] = typeof text === "string" ? text : "";
|
|
233
|
+
}
|
|
234
|
+
if (colorGroup?.borderColor) {
|
|
235
|
+
const border = colorGroup.borderColor;
|
|
236
|
+
vars["--tm-button-secondary-border"] = typeof border === "string" ? border : "";
|
|
237
|
+
}
|
|
238
|
+
const borderRadius = secondaryButton["lightning:borderRadius"];
|
|
239
|
+
if (borderRadius && typeof borderRadius === "object" && "unit" in borderRadius) {
|
|
240
|
+
vars["--tm-button-secondary-radius"] = formatDimension(borderRadius);
|
|
241
|
+
}
|
|
242
|
+
const borderWidth = secondaryButton["lightning:borderWidth"];
|
|
243
|
+
if (borderWidth && typeof borderWidth === "object" && "unit" in borderWidth) {
|
|
244
|
+
vars["--tm-button-secondary-border-width"] = formatDimension(borderWidth);
|
|
245
|
+
}
|
|
246
|
+
const padding = secondaryButton["lightning:padding"];
|
|
247
|
+
if (padding?.left) {
|
|
248
|
+
vars["--tm-button-secondary-padding-x"] = formatDimension(padding.left);
|
|
249
|
+
}
|
|
250
|
+
if (padding?.top) {
|
|
251
|
+
vars["--tm-button-secondary-padding-y"] = formatDimension(padding.top);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const tertiaryButton = brand.buttonStyleGroup?.tertiary;
|
|
255
|
+
if (tertiaryButton) {
|
|
256
|
+
const colorGroup = tertiaryButton["lightning:buttonColorGroup"];
|
|
257
|
+
if (colorGroup?.backgroundColor) {
|
|
258
|
+
const bg = colorGroup.backgroundColor;
|
|
259
|
+
vars["--tm-button-tertiary-bg"] = typeof bg === "string" ? bg : "";
|
|
260
|
+
}
|
|
261
|
+
if (colorGroup?.textColor) {
|
|
262
|
+
const text = colorGroup.textColor;
|
|
263
|
+
vars["--tm-button-tertiary-text"] = typeof text === "string" ? text : "";
|
|
264
|
+
}
|
|
265
|
+
if (colorGroup?.borderColor) {
|
|
266
|
+
const border = colorGroup.borderColor;
|
|
267
|
+
vars["--tm-button-tertiary-border"] = typeof border === "string" ? border : "";
|
|
268
|
+
}
|
|
269
|
+
const borderRadius = tertiaryButton["lightning:borderRadius"];
|
|
270
|
+
if (borderRadius && typeof borderRadius === "object" && "unit" in borderRadius) {
|
|
271
|
+
vars["--tm-button-tertiary-radius"] = formatDimension(borderRadius);
|
|
272
|
+
}
|
|
273
|
+
const borderWidth = tertiaryButton["lightning:borderWidth"];
|
|
274
|
+
if (borderWidth && typeof borderWidth === "object" && "unit" in borderWidth) {
|
|
275
|
+
vars["--tm-button-tertiary-border-width"] = formatDimension(borderWidth);
|
|
276
|
+
}
|
|
277
|
+
const padding = tertiaryButton["lightning:padding"];
|
|
278
|
+
if (padding?.left) {
|
|
279
|
+
vars["--tm-button-tertiary-padding-x"] = formatDimension(padding.left);
|
|
280
|
+
}
|
|
281
|
+
if (padding?.top) {
|
|
282
|
+
vars["--tm-button-tertiary-padding-y"] = formatDimension(padding.top);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
for (let i = 1; i <= 6; i++) {
|
|
286
|
+
const heading = brand.typography?.heading?.[`heading${i}`];
|
|
287
|
+
if (heading && typeof heading === "object") {
|
|
288
|
+
if (heading.fontFamily) {
|
|
289
|
+
vars[`--tm-heading${i}-font`] = buildFontStack(heading.fontFamily);
|
|
290
|
+
}
|
|
291
|
+
if (heading.fontSize && typeof heading.fontSize === "object" && "unit" in heading.fontSize) {
|
|
292
|
+
vars[`--tm-heading${i}-size`] = formatDimension(heading.fontSize);
|
|
293
|
+
}
|
|
294
|
+
if (heading.fontWeight !== void 0) {
|
|
295
|
+
vars[`--tm-heading${i}-weight`] = String(heading.fontWeight);
|
|
296
|
+
}
|
|
297
|
+
if (heading.lineHeight !== void 0) {
|
|
298
|
+
vars[`--tm-heading${i}-line-height`] = String(heading.lineHeight);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const para1 = brand.typography?.paragraph?.paragraph1;
|
|
303
|
+
if (para1) {
|
|
304
|
+
if (para1.fontFamily) {
|
|
305
|
+
vars["--tm-paragraph1-font"] = buildFontStack(para1.fontFamily);
|
|
306
|
+
}
|
|
307
|
+
if (para1.fontSize && typeof para1.fontSize === "object" && "unit" in para1.fontSize) {
|
|
308
|
+
vars["--tm-paragraph1-size"] = formatDimension(para1.fontSize);
|
|
309
|
+
}
|
|
310
|
+
if (para1.fontWeight !== void 0) {
|
|
311
|
+
vars["--tm-paragraph1-weight"] = String(para1.fontWeight);
|
|
312
|
+
}
|
|
313
|
+
if (para1.lineHeight !== void 0) {
|
|
314
|
+
vars["--tm-paragraph1-line-height"] = String(para1.lineHeight);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const para2 = brand.typography?.paragraph?.paragraph2;
|
|
318
|
+
if (para2) {
|
|
319
|
+
if (para2.fontFamily) {
|
|
320
|
+
vars["--tm-paragraph2-font"] = buildFontStack(para2.fontFamily);
|
|
321
|
+
}
|
|
322
|
+
if (para2.fontSize && typeof para2.fontSize === "object" && "unit" in para2.fontSize) {
|
|
323
|
+
vars["--tm-paragraph2-size"] = formatDimension(para2.fontSize);
|
|
324
|
+
}
|
|
325
|
+
if (para2.fontWeight !== void 0) {
|
|
326
|
+
vars["--tm-paragraph2-weight"] = String(para2.fontWeight);
|
|
327
|
+
}
|
|
328
|
+
if (para2.lineHeight !== void 0) {
|
|
329
|
+
vars["--tm-paragraph2-line-height"] = String(para2.lineHeight);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (brand.borderRadius?.square) {
|
|
333
|
+
vars["--tm-border-radius-square"] = formatDimension(brand.borderRadius.square);
|
|
334
|
+
}
|
|
335
|
+
if (brand.borderRadius?.round) {
|
|
336
|
+
vars["--tm-border-radius-round"] = formatDimension(brand.borderRadius.round);
|
|
337
|
+
}
|
|
338
|
+
if (brand.borderWeight?.medium) {
|
|
339
|
+
vars["--tm-border-weight-medium"] = formatDimension(brand.borderWeight.medium);
|
|
340
|
+
}
|
|
341
|
+
if (brand.borderWeight?.none) {
|
|
342
|
+
vars["--tm-border-weight-none"] = formatDimension(brand.borderWeight.none);
|
|
343
|
+
}
|
|
344
|
+
return vars;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/protocol/brandTypes.ts
|
|
348
|
+
function getBrandTitle(brand) {
|
|
349
|
+
return brand["sfdc_cms:title"] ?? "Untitled Brand";
|
|
350
|
+
}
|
|
351
|
+
function getBrandLogoUrl(brand) {
|
|
352
|
+
const url = brand.logo?.url;
|
|
353
|
+
return typeof url === "string" && url.length > 0 ? url : void 0;
|
|
354
|
+
}
|
|
355
|
+
function getBrandLogoAltText(brand) {
|
|
356
|
+
const alt = brand.logo?.altText;
|
|
357
|
+
return typeof alt === "string" && alt.length > 0 ? alt : getBrandTitle(brand);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/protocol/messageTypes.ts
|
|
361
|
+
var MSG_UPDATE_THEME = "update-theme";
|
|
362
|
+
var MSG_UPDATE_COMPONENT_OVERRIDE = "update-component-override";
|
|
363
|
+
var MSG_UPDATE_BRAND = "update-brand";
|
|
364
|
+
|
|
365
|
+
// src/runtime/previewRuntime.ts
|
|
366
|
+
function applyThemeVariables(variables) {
|
|
367
|
+
requestAnimationFrame(() => {
|
|
368
|
+
const root = document.documentElement;
|
|
369
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
370
|
+
if (key.startsWith("--tm-") && value != null) {
|
|
371
|
+
root.style.setProperty(key, value);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function injectFontFaces(brand) {
|
|
377
|
+
const css = generateFontFaceRules(brand);
|
|
378
|
+
let styleEl = document.head.querySelector("#tm-font-faces");
|
|
379
|
+
if (!styleEl) {
|
|
380
|
+
styleEl = document.createElement("style");
|
|
381
|
+
styleEl.id = "tm-font-faces";
|
|
382
|
+
document.head.appendChild(styleEl);
|
|
383
|
+
}
|
|
384
|
+
styleEl.textContent = css;
|
|
385
|
+
}
|
|
386
|
+
function applyBrandLogo(brand) {
|
|
387
|
+
const section = document.querySelector("[data-brand-hero-section]");
|
|
388
|
+
if (!section) return;
|
|
389
|
+
const hero = section.querySelector("[data-brand-hero]");
|
|
390
|
+
const logoUrl = getBrandLogoUrl(brand);
|
|
391
|
+
let logo = section.querySelector("[data-brand-logo]");
|
|
392
|
+
if (logoUrl) {
|
|
393
|
+
if (!logo) {
|
|
394
|
+
logo = document.createElement("img");
|
|
395
|
+
logo.className = "brand-logo";
|
|
396
|
+
logo.setAttribute("data-brand-logo", "");
|
|
397
|
+
section.appendChild(logo);
|
|
398
|
+
}
|
|
399
|
+
logo.src = logoUrl;
|
|
400
|
+
logo.alt = getBrandLogoAltText(brand);
|
|
401
|
+
logo.hidden = false;
|
|
402
|
+
if (hero) hero.hidden = true;
|
|
403
|
+
} else {
|
|
404
|
+
if (logo) logo.hidden = true;
|
|
405
|
+
if (hero) hero.hidden = false;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function applyComponentOverride(component, overrides) {
|
|
409
|
+
requestAnimationFrame(() => {
|
|
410
|
+
const elements = document.querySelectorAll(
|
|
411
|
+
`[data-component-override="${component}"]`
|
|
412
|
+
);
|
|
413
|
+
elements.forEach((el) => {
|
|
414
|
+
if (overrides.styles) {
|
|
415
|
+
for (const [prop, value] of Object.entries(overrides.styles)) {
|
|
416
|
+
el.style.setProperty(prop, value);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (overrides.cssVariables) {
|
|
420
|
+
for (const [varName, value] of Object.entries(overrides.cssVariables)) {
|
|
421
|
+
el.style.setProperty(varName, value);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
function handlePreviewMessage(event) {
|
|
428
|
+
const message = event.data;
|
|
429
|
+
if (!message || !message.type) return;
|
|
430
|
+
switch (message.type) {
|
|
431
|
+
case MSG_UPDATE_THEME: {
|
|
432
|
+
const msg = message;
|
|
433
|
+
if (msg.variables) {
|
|
434
|
+
applyThemeVariables(msg.variables);
|
|
435
|
+
}
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
case MSG_UPDATE_BRAND: {
|
|
439
|
+
const msg = message;
|
|
440
|
+
const resolved = msg.brand ? resolveBrandTokens(msg.brand) : void 0;
|
|
441
|
+
if (resolved) {
|
|
442
|
+
injectFontFaces(resolved);
|
|
443
|
+
applyBrandLogo(resolved);
|
|
444
|
+
}
|
|
445
|
+
const variables = msg.variables ?? (resolved ? brandToVariables(resolved) : void 0);
|
|
446
|
+
if (variables) {
|
|
447
|
+
applyThemeVariables(variables);
|
|
448
|
+
}
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
case MSG_UPDATE_COMPONENT_OVERRIDE: {
|
|
452
|
+
const msg = message;
|
|
453
|
+
if (msg.component && msg.overrides) {
|
|
454
|
+
applyComponentOverride(msg.component, msg.overrides);
|
|
455
|
+
}
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (typeof window !== "undefined") {
|
|
461
|
+
window.addEventListener("message", handlePreviewMessage);
|
|
462
|
+
}
|
|
463
|
+
})();
|
|
464
|
+
|
|
465
|
+
})();
|
|
466
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@salesforce/ui-theme-manager",
|
|
3
|
+
"description": "Theme management system for Salesforce UI Bundles",
|
|
4
|
+
"version": "11.46.0",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./protocol": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/protocol/index.d.ts",
|
|
11
|
+
"default": "./dist/protocol/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/protocol/index.d.cts",
|
|
15
|
+
"default": "./dist/protocol/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"./runtime/preview": {
|
|
19
|
+
"types": "./dist/runtime/previewContent.d.ts",
|
|
20
|
+
"import": "./dist/runtime/previewContent.js"
|
|
21
|
+
},
|
|
22
|
+
"./authoring/react": {
|
|
23
|
+
"types": "./dist/authoring/react/index.d.ts",
|
|
24
|
+
"import": "./dist/authoring/react/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./authoring/react/styles.css": "./dist/authoring/react/styles.css",
|
|
27
|
+
"./authoring/web-component": {
|
|
28
|
+
"types": "./dist/authoring/web-component/index.d.ts",
|
|
29
|
+
"import": "./dist/authoring/web-component/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "vite build && node scripts/fix-dts-extensions.mjs && node src/runtime/bundle-preview-runtime.mjs && node src/authoring/react/bundle-authoring-react.mjs && node src/authoring/web-component/bundle-authoring-web-component.mjs",
|
|
38
|
+
"clean": "rm -rf dist",
|
|
39
|
+
"dev": "vite build --watch",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"test:watch": "vitest",
|
|
42
|
+
"test:coverage": "vitest run --coverage"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"react": "^19.2.0",
|
|
46
|
+
"react-dom": "^19.2.0"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"chroma-js": "^2.4.2"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@testing-library/dom": "^10.4.1",
|
|
53
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
54
|
+
"@testing-library/react": "^16.3.2",
|
|
55
|
+
"@types/chroma-js": "^2.4.4",
|
|
56
|
+
"@types/react": "19.2.14",
|
|
57
|
+
"@types/react-dom": "19.2.3",
|
|
58
|
+
"esbuild": "^0.24.0",
|
|
59
|
+
"happy-dom": "^17.6.1",
|
|
60
|
+
"jsdom": "^25.0.1",
|
|
61
|
+
"react": "^19.2.0",
|
|
62
|
+
"react-dom": "^19.2.0",
|
|
63
|
+
"ts-morph": "^25.0.0",
|
|
64
|
+
"vite": "^7.3.1",
|
|
65
|
+
"vite-plugin-dts": "^4.5.4",
|
|
66
|
+
"vitest": "^4.0.6"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=20.0.0"
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
}
|
|
74
|
+
}
|