@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,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Brand data model types for Salesforce CMS Brand tokens.
|
|
8
|
+
*
|
|
9
|
+
* Evolution policy: Add new fields as optional. Never rename or remove fields.
|
|
10
|
+
* Never change field semantics. Brand tokens are portable across hosts.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* A brand reference string in the form "{!$brand.path.to.token}".
|
|
14
|
+
*/
|
|
15
|
+
export type BrandRef = string;
|
|
16
|
+
/**
|
|
17
|
+
* A value that can be either a literal or a reference to another brand token.
|
|
18
|
+
*/
|
|
19
|
+
export type Ref<T> = T | BrandRef;
|
|
20
|
+
/**
|
|
21
|
+
* A dimension with a unit and value (e.g., rem, px).
|
|
22
|
+
*/
|
|
23
|
+
export interface BrandDimension {
|
|
24
|
+
unit: string;
|
|
25
|
+
value: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A box model with all four edges.
|
|
29
|
+
*/
|
|
30
|
+
export interface BrandBox {
|
|
31
|
+
top: BrandDimension;
|
|
32
|
+
bottom: BrandDimension;
|
|
33
|
+
left: BrandDimension;
|
|
34
|
+
right: BrandDimension;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Letter spacing can be a dimension or the literal string "normal".
|
|
38
|
+
*/
|
|
39
|
+
export type BrandLetterSpacingValue = BrandDimension | "normal";
|
|
40
|
+
/**
|
|
41
|
+
* A font family definition with name, category, and optional fallbacks.
|
|
42
|
+
*/
|
|
43
|
+
export interface BrandFontFamily {
|
|
44
|
+
name: string;
|
|
45
|
+
category: string;
|
|
46
|
+
fallbacks?: string[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A typography entry with font family, size, weight, spacing, line height, and transform.
|
|
50
|
+
*/
|
|
51
|
+
export interface BrandTypographyEntry {
|
|
52
|
+
fontFamily: Ref<string>;
|
|
53
|
+
fontSize: Ref<BrandDimension>;
|
|
54
|
+
fontWeight: Ref<number>;
|
|
55
|
+
letterSpacing: BrandLetterSpacingValue;
|
|
56
|
+
lineHeight: number;
|
|
57
|
+
textTransform: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Button color group with background, border, and text colors.
|
|
61
|
+
* Tertiary buttons may omit backgroundColor, backgroundHoverColor, borderColor, borderHoverColor.
|
|
62
|
+
*/
|
|
63
|
+
export interface BrandButtonColorGroup {
|
|
64
|
+
backgroundColor?: Ref<string>;
|
|
65
|
+
backgroundHoverColor?: Ref<string>;
|
|
66
|
+
borderColor?: Ref<string>;
|
|
67
|
+
borderHoverColor?: Ref<string>;
|
|
68
|
+
textColor: Ref<string>;
|
|
69
|
+
textHoverColor: Ref<string>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Button style definition with namespaced Lightning keys.
|
|
73
|
+
*/
|
|
74
|
+
export interface BrandButtonStyle {
|
|
75
|
+
"lightning:borderRadius": Ref<BrandDimension>;
|
|
76
|
+
"lightning:borderWidth": Ref<BrandDimension>;
|
|
77
|
+
"lightning:buttonColorGroup": BrandButtonColorGroup;
|
|
78
|
+
"lightning:padding": BrandBox;
|
|
79
|
+
"lightning:typography": Ref<BrandTypographyEntry>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A brand logo asset. The `url` is a resolved, directly-loadable image URL;
|
|
83
|
+
* `source` carries the CMS content reference it was resolved from.
|
|
84
|
+
*/
|
|
85
|
+
export interface BrandLogo {
|
|
86
|
+
url: string;
|
|
87
|
+
altText?: string;
|
|
88
|
+
overrideAltText?: boolean;
|
|
89
|
+
source?: {
|
|
90
|
+
mimeType?: string;
|
|
91
|
+
size?: number;
|
|
92
|
+
type?: string;
|
|
93
|
+
ref?: {
|
|
94
|
+
contentKey?: string;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Root brand content body containing all tokens.
|
|
100
|
+
*/
|
|
101
|
+
export interface BrandContentBody {
|
|
102
|
+
colorScheme: Record<string, string>;
|
|
103
|
+
fontFamily: Record<string, BrandFontFamily>;
|
|
104
|
+
fontSize: Record<string, BrandDimension>;
|
|
105
|
+
fontWeight: Record<string, number>;
|
|
106
|
+
borderRadius: Record<string, BrandDimension>;
|
|
107
|
+
borderWeight: Record<string, BrandDimension>;
|
|
108
|
+
spacing: Record<string, BrandBox>;
|
|
109
|
+
letterSpacing: Record<string, BrandLetterSpacingValue>;
|
|
110
|
+
baseFontFamily: BrandRef;
|
|
111
|
+
baseFontSize: BrandDimension;
|
|
112
|
+
typography: {
|
|
113
|
+
heading: Record<string, BrandTypographyEntry>;
|
|
114
|
+
paragraph: Record<string, BrandTypographyEntry>;
|
|
115
|
+
button: Record<string, BrandTypographyEntry>;
|
|
116
|
+
label: Record<string, BrandTypographyEntry>;
|
|
117
|
+
input: Record<string, BrandTypographyEntry>;
|
|
118
|
+
};
|
|
119
|
+
buttonStyleGroup: {
|
|
120
|
+
primary: BrandButtonStyle;
|
|
121
|
+
secondary: BrandButtonStyle;
|
|
122
|
+
tertiary: BrandButtonStyle;
|
|
123
|
+
};
|
|
124
|
+
/** Optional brand logo asset. Absent when the brand defines no logo. */
|
|
125
|
+
logo?: BrandLogo;
|
|
126
|
+
"lightning:dataProviders"?: unknown[];
|
|
127
|
+
"sfdc_cms:title"?: string;
|
|
128
|
+
"sfdc_cms:einsteinBrandProperties"?: {
|
|
129
|
+
personality?: {
|
|
130
|
+
defaultPersonality?: string;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
"sfdc_cms:variants"?: unknown[];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The complete Brand model.
|
|
137
|
+
*/
|
|
138
|
+
export type Brand = BrandContentBody;
|
|
139
|
+
/**
|
|
140
|
+
* Metadata-like summary for gallery display or selection lists.
|
|
141
|
+
*/
|
|
142
|
+
export interface BrandSummary {
|
|
143
|
+
title: string;
|
|
144
|
+
managedContentId?: string;
|
|
145
|
+
managedContentKey?: string;
|
|
146
|
+
contentUrl?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Extracts the brand title from the CMS metadata.
|
|
150
|
+
*/
|
|
151
|
+
export declare function getBrandTitle(brand: Brand): string;
|
|
152
|
+
/**
|
|
153
|
+
* Returns the brand's logo URL, or undefined when the brand defines no logo.
|
|
154
|
+
*/
|
|
155
|
+
export declare function getBrandLogoUrl(brand: Brand): string | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Returns the brand logo's alt text, falling back to the brand title.
|
|
158
|
+
*/
|
|
159
|
+
export declare function getBrandLogoAltText(brand: Brand): string;
|
|
160
|
+
/**
|
|
161
|
+
* CMS delivery envelope for brand content.
|
|
162
|
+
* The outer wrapper returned by CMS delivery APIs.
|
|
163
|
+
*/
|
|
164
|
+
export interface BrandEnvelope {
|
|
165
|
+
managedContentId?: string;
|
|
166
|
+
title?: string;
|
|
167
|
+
contentKey?: string;
|
|
168
|
+
contentType?: {
|
|
169
|
+
fullyQualifiedName?: string;
|
|
170
|
+
};
|
|
171
|
+
language?: string;
|
|
172
|
+
publishedDate?: string;
|
|
173
|
+
resourceUrl?: string;
|
|
174
|
+
unauthenticatedUrl?: string;
|
|
175
|
+
urlName?: string;
|
|
176
|
+
channelSummary?: {
|
|
177
|
+
domainUrl?: string;
|
|
178
|
+
id?: string;
|
|
179
|
+
name?: string;
|
|
180
|
+
resourceUrl?: string;
|
|
181
|
+
type?: string;
|
|
182
|
+
};
|
|
183
|
+
contentBody: BrandContentBody;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Unwraps a CMS delivery envelope to extract the Brand content body.
|
|
187
|
+
*
|
|
188
|
+
* This function is idempotent:
|
|
189
|
+
* - If the input is an envelope (has `contentBody`), returns the inner `contentBody`.
|
|
190
|
+
* - If the input is already an unwrapped Brand (has `colorScheme`), returns it as-is.
|
|
191
|
+
* - Throws an error for null, undefined, or non-object inputs.
|
|
192
|
+
*
|
|
193
|
+
* @param raw - The raw data from CMS (may be envelope or already unwrapped)
|
|
194
|
+
* @returns The unwrapped Brand (BrandContentBody)
|
|
195
|
+
* @throws Error if input is null, undefined, or not an object
|
|
196
|
+
*/
|
|
197
|
+
export declare function unwrapBrandEnvelope(raw: unknown): Brand;
|
|
198
|
+
//# sourceMappingURL=brandTypes.d.ts.map
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Brand data model types for Salesforce CMS Brand tokens.
|
|
8
|
+
*
|
|
9
|
+
* Evolution policy: Add new fields as optional. Never rename or remove fields.
|
|
10
|
+
* Never change field semantics. Brand tokens are portable across hosts.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* A brand reference string in the form "{!$brand.path.to.token}".
|
|
14
|
+
*/
|
|
15
|
+
export type BrandRef = string;
|
|
16
|
+
/**
|
|
17
|
+
* A value that can be either a literal or a reference to another brand token.
|
|
18
|
+
*/
|
|
19
|
+
export type Ref<T> = T | BrandRef;
|
|
20
|
+
/**
|
|
21
|
+
* A dimension with a unit and value (e.g., rem, px).
|
|
22
|
+
*/
|
|
23
|
+
export interface BrandDimension {
|
|
24
|
+
unit: string;
|
|
25
|
+
value: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A box model with all four edges.
|
|
29
|
+
*/
|
|
30
|
+
export interface BrandBox {
|
|
31
|
+
top: BrandDimension;
|
|
32
|
+
bottom: BrandDimension;
|
|
33
|
+
left: BrandDimension;
|
|
34
|
+
right: BrandDimension;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Letter spacing can be a dimension or the literal string "normal".
|
|
38
|
+
*/
|
|
39
|
+
export type BrandLetterSpacingValue = BrandDimension | "normal";
|
|
40
|
+
/**
|
|
41
|
+
* A font family definition with name, category, and optional fallbacks.
|
|
42
|
+
*/
|
|
43
|
+
export interface BrandFontFamily {
|
|
44
|
+
name: string;
|
|
45
|
+
category: string;
|
|
46
|
+
fallbacks?: string[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A typography entry with font family, size, weight, spacing, line height, and transform.
|
|
50
|
+
*/
|
|
51
|
+
export interface BrandTypographyEntry {
|
|
52
|
+
fontFamily: Ref<string>;
|
|
53
|
+
fontSize: Ref<BrandDimension>;
|
|
54
|
+
fontWeight: Ref<number>;
|
|
55
|
+
letterSpacing: BrandLetterSpacingValue;
|
|
56
|
+
lineHeight: number;
|
|
57
|
+
textTransform: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Button color group with background, border, and text colors.
|
|
61
|
+
* Tertiary buttons may omit backgroundColor, backgroundHoverColor, borderColor, borderHoverColor.
|
|
62
|
+
*/
|
|
63
|
+
export interface BrandButtonColorGroup {
|
|
64
|
+
backgroundColor?: Ref<string>;
|
|
65
|
+
backgroundHoverColor?: Ref<string>;
|
|
66
|
+
borderColor?: Ref<string>;
|
|
67
|
+
borderHoverColor?: Ref<string>;
|
|
68
|
+
textColor: Ref<string>;
|
|
69
|
+
textHoverColor: Ref<string>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Button style definition with namespaced Lightning keys.
|
|
73
|
+
*/
|
|
74
|
+
export interface BrandButtonStyle {
|
|
75
|
+
"lightning:borderRadius": Ref<BrandDimension>;
|
|
76
|
+
"lightning:borderWidth": Ref<BrandDimension>;
|
|
77
|
+
"lightning:buttonColorGroup": BrandButtonColorGroup;
|
|
78
|
+
"lightning:padding": BrandBox;
|
|
79
|
+
"lightning:typography": Ref<BrandTypographyEntry>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A brand logo asset. The `url` is a resolved, directly-loadable image URL;
|
|
83
|
+
* `source` carries the CMS content reference it was resolved from.
|
|
84
|
+
*/
|
|
85
|
+
export interface BrandLogo {
|
|
86
|
+
url: string;
|
|
87
|
+
altText?: string;
|
|
88
|
+
overrideAltText?: boolean;
|
|
89
|
+
source?: {
|
|
90
|
+
mimeType?: string;
|
|
91
|
+
size?: number;
|
|
92
|
+
type?: string;
|
|
93
|
+
ref?: {
|
|
94
|
+
contentKey?: string;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Root brand content body containing all tokens.
|
|
100
|
+
*/
|
|
101
|
+
export interface BrandContentBody {
|
|
102
|
+
colorScheme: Record<string, string>;
|
|
103
|
+
fontFamily: Record<string, BrandFontFamily>;
|
|
104
|
+
fontSize: Record<string, BrandDimension>;
|
|
105
|
+
fontWeight: Record<string, number>;
|
|
106
|
+
borderRadius: Record<string, BrandDimension>;
|
|
107
|
+
borderWeight: Record<string, BrandDimension>;
|
|
108
|
+
spacing: Record<string, BrandBox>;
|
|
109
|
+
letterSpacing: Record<string, BrandLetterSpacingValue>;
|
|
110
|
+
baseFontFamily: BrandRef;
|
|
111
|
+
baseFontSize: BrandDimension;
|
|
112
|
+
typography: {
|
|
113
|
+
heading: Record<string, BrandTypographyEntry>;
|
|
114
|
+
paragraph: Record<string, BrandTypographyEntry>;
|
|
115
|
+
button: Record<string, BrandTypographyEntry>;
|
|
116
|
+
label: Record<string, BrandTypographyEntry>;
|
|
117
|
+
input: Record<string, BrandTypographyEntry>;
|
|
118
|
+
};
|
|
119
|
+
buttonStyleGroup: {
|
|
120
|
+
primary: BrandButtonStyle;
|
|
121
|
+
secondary: BrandButtonStyle;
|
|
122
|
+
tertiary: BrandButtonStyle;
|
|
123
|
+
};
|
|
124
|
+
/** Optional brand logo asset. Absent when the brand defines no logo. */
|
|
125
|
+
logo?: BrandLogo;
|
|
126
|
+
"lightning:dataProviders"?: unknown[];
|
|
127
|
+
"sfdc_cms:title"?: string;
|
|
128
|
+
"sfdc_cms:einsteinBrandProperties"?: {
|
|
129
|
+
personality?: {
|
|
130
|
+
defaultPersonality?: string;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
"sfdc_cms:variants"?: unknown[];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The complete Brand model.
|
|
137
|
+
*/
|
|
138
|
+
export type Brand = BrandContentBody;
|
|
139
|
+
/**
|
|
140
|
+
* Metadata-like summary for gallery display or selection lists.
|
|
141
|
+
*/
|
|
142
|
+
export interface BrandSummary {
|
|
143
|
+
title: string;
|
|
144
|
+
managedContentId?: string;
|
|
145
|
+
managedContentKey?: string;
|
|
146
|
+
contentUrl?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Extracts the brand title from the CMS metadata.
|
|
150
|
+
*/
|
|
151
|
+
export declare function getBrandTitle(brand: Brand): string;
|
|
152
|
+
/**
|
|
153
|
+
* Returns the brand's logo URL, or undefined when the brand defines no logo.
|
|
154
|
+
*/
|
|
155
|
+
export declare function getBrandLogoUrl(brand: Brand): string | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Returns the brand logo's alt text, falling back to the brand title.
|
|
158
|
+
*/
|
|
159
|
+
export declare function getBrandLogoAltText(brand: Brand): string;
|
|
160
|
+
/**
|
|
161
|
+
* CMS delivery envelope for brand content.
|
|
162
|
+
* The outer wrapper returned by CMS delivery APIs.
|
|
163
|
+
*/
|
|
164
|
+
export interface BrandEnvelope {
|
|
165
|
+
managedContentId?: string;
|
|
166
|
+
title?: string;
|
|
167
|
+
contentKey?: string;
|
|
168
|
+
contentType?: {
|
|
169
|
+
fullyQualifiedName?: string;
|
|
170
|
+
};
|
|
171
|
+
language?: string;
|
|
172
|
+
publishedDate?: string;
|
|
173
|
+
resourceUrl?: string;
|
|
174
|
+
unauthenticatedUrl?: string;
|
|
175
|
+
urlName?: string;
|
|
176
|
+
channelSummary?: {
|
|
177
|
+
domainUrl?: string;
|
|
178
|
+
id?: string;
|
|
179
|
+
name?: string;
|
|
180
|
+
resourceUrl?: string;
|
|
181
|
+
type?: string;
|
|
182
|
+
};
|
|
183
|
+
contentBody: BrandContentBody;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Unwraps a CMS delivery envelope to extract the Brand content body.
|
|
187
|
+
*
|
|
188
|
+
* This function is idempotent:
|
|
189
|
+
* - If the input is an envelope (has `contentBody`), returns the inner `contentBody`.
|
|
190
|
+
* - If the input is already an unwrapped Brand (has `colorScheme`), returns it as-is.
|
|
191
|
+
* - Throws an error for null, undefined, or non-object inputs.
|
|
192
|
+
*
|
|
193
|
+
* @param raw - The raw data from CMS (may be envelope or already unwrapped)
|
|
194
|
+
* @returns The unwrapped Brand (BrandContentBody)
|
|
195
|
+
* @throws Error if input is null, undefined, or not an object
|
|
196
|
+
*/
|
|
197
|
+
export declare function unwrapBrandEnvelope(raw: unknown): Brand;
|
|
198
|
+
//# sourceMappingURL=brandTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brandTypes.d.ts","sourceRoot":"","sources":["../../src/protocol/brandTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,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AC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACF,WAAW,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAmBvD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
function getBrandTitle(brand) {
|
|
2
|
+
return brand["sfdc_cms:title"] ?? "Untitled Brand";
|
|
3
|
+
}
|
|
4
|
+
function getBrandLogoUrl(brand) {
|
|
5
|
+
const url = brand.logo?.url;
|
|
6
|
+
return typeof url === "string" && url.length > 0 ? url : void 0;
|
|
7
|
+
}
|
|
8
|
+
function getBrandLogoAltText(brand) {
|
|
9
|
+
const alt = brand.logo?.altText;
|
|
10
|
+
return typeof alt === "string" && alt.length > 0 ? alt : getBrandTitle(brand);
|
|
11
|
+
}
|
|
12
|
+
function unwrapBrandEnvelope(raw) {
|
|
13
|
+
if (raw === null || raw === void 0) {
|
|
14
|
+
throw new Error("unwrapBrandEnvelope: input is null or undefined");
|
|
15
|
+
}
|
|
16
|
+
if (typeof raw !== "object") {
|
|
17
|
+
throw new Error(`unwrapBrandEnvelope: input is not an object (got ${typeof raw})`);
|
|
18
|
+
}
|
|
19
|
+
const obj = raw;
|
|
20
|
+
if ("contentBody" in obj && obj.contentBody !== null && typeof obj.contentBody === "object") {
|
|
21
|
+
return obj.contentBody;
|
|
22
|
+
}
|
|
23
|
+
return raw;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
getBrandLogoAltText,
|
|
27
|
+
getBrandLogoUrl,
|
|
28
|
+
getBrandTitle,
|
|
29
|
+
unwrapBrandEnvelope
|
|
30
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const chroma = require("chroma-js");
|
|
4
|
+
function darkenColor(sourceColor) {
|
|
5
|
+
if (!sourceColor) return void 0;
|
|
6
|
+
try {
|
|
7
|
+
if (!chroma.valid(sourceColor)) return void 0;
|
|
8
|
+
return chroma(sourceColor).darken(0.5).hex();
|
|
9
|
+
} catch {
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function derivePrimaryAccentDerived(primaryAccent) {
|
|
14
|
+
return darkenColor(primaryAccent);
|
|
15
|
+
}
|
|
16
|
+
function derivePrimaryAccentContrastDerived(primaryAccentContrast, primaryAccentDerived) {
|
|
17
|
+
if (!primaryAccentContrast || !primaryAccentDerived) return void 0;
|
|
18
|
+
try {
|
|
19
|
+
if (!chroma.valid(primaryAccentContrast) || !chroma.valid(primaryAccentDerived)) {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
const darkened = chroma(primaryAccentContrast).darken(0.5).hex();
|
|
23
|
+
const contrastRatio = chroma.contrast(darkened, primaryAccentDerived);
|
|
24
|
+
if (contrastRatio < 4.5) {
|
|
25
|
+
const isLight = chroma(primaryAccentDerived).luminance() > 0.5;
|
|
26
|
+
return isLight ? "#000000" : "#FFFFFF";
|
|
27
|
+
}
|
|
28
|
+
return darkened;
|
|
29
|
+
} catch {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function deriveBrandColors(colors) {
|
|
34
|
+
const primaryAccentDerived = derivePrimaryAccentDerived(colors.primaryAccent);
|
|
35
|
+
const primaryAccentContrastDerived = derivePrimaryAccentContrastDerived(
|
|
36
|
+
colors.primaryAccentContrast,
|
|
37
|
+
primaryAccentDerived
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
primaryAccentDerived,
|
|
41
|
+
primaryAccentContrastDerived
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function updateDerivedColors(brand) {
|
|
45
|
+
if (!brand.colorScheme || typeof brand.colorScheme !== "object") {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const colorScheme = brand.colorScheme;
|
|
49
|
+
const primaryAccent = typeof colorScheme.primaryAccent === "string" ? colorScheme.primaryAccent : void 0;
|
|
50
|
+
const primaryAccentContrast = typeof colorScheme.primaryAccentContrast === "string" ? colorScheme.primaryAccentContrast : void 0;
|
|
51
|
+
const derived = deriveBrandColors({ primaryAccent, primaryAccentContrast });
|
|
52
|
+
if (derived.primaryAccentDerived !== void 0) {
|
|
53
|
+
colorScheme.primaryAccentDerived = derived.primaryAccentDerived;
|
|
54
|
+
} else {
|
|
55
|
+
delete colorScheme.primaryAccentDerived;
|
|
56
|
+
}
|
|
57
|
+
if (derived.primaryAccentContrastDerived !== void 0) {
|
|
58
|
+
colorScheme.primaryAccentContrastDerived = derived.primaryAccentContrastDerived;
|
|
59
|
+
} else {
|
|
60
|
+
delete colorScheme.primaryAccentContrastDerived;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.darkenColor = darkenColor;
|
|
64
|
+
exports.deriveBrandColors = deriveBrandColors;
|
|
65
|
+
exports.derivePrimaryAccentContrastDerived = derivePrimaryAccentContrastDerived;
|
|
66
|
+
exports.derivePrimaryAccentDerived = derivePrimaryAccentDerived;
|
|
67
|
+
exports.updateDerivedColors = updateDerivedColors;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Brand } from './brandTypes.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* Darkens a color by 0.5 in LAB space, matching Salesforce Core's algorithm.
|
|
4
|
+
* Core uses: `chroma(hex).darken(0.5).hex()`
|
|
5
|
+
* This operates in LAB color space: L_new = L - (18 * 0.5) = L - 9
|
|
6
|
+
*
|
|
7
|
+
* @param sourceColor - 6-digit or 8-digit hex color (with or without #)
|
|
8
|
+
* @returns Lowercase 6-digit hex (e.g., "#0060ba"), or undefined if input is invalid
|
|
9
|
+
*/
|
|
10
|
+
export declare function darkenColor(sourceColor: string | undefined): string | undefined;
|
|
11
|
+
/** Derives primaryAccentDerived from primaryAccent (darkens by 0.5 in LAB space). */
|
|
12
|
+
export declare function derivePrimaryAccentDerived(primaryAccent: string | undefined): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Derives primaryAccentContrastDerived from primaryAccentContrast.
|
|
15
|
+
* Matches Core's algorithm exactly: darken(0.5), then contrast check with fallback.
|
|
16
|
+
* Core's getValidContrast: if contrast(darkened, bg) < 4.5, return '#000000' (light bg) or '#FFFFFF' (dark bg).
|
|
17
|
+
*/
|
|
18
|
+
export declare function derivePrimaryAccentContrastDerived(primaryAccentContrast: string | undefined, primaryAccentDerived: string | undefined): string | undefined;
|
|
19
|
+
/** Derives both brand colors (primaryAccentDerived first, then primaryAccentContrastDerived). */
|
|
20
|
+
export declare function deriveBrandColors(colors: {
|
|
21
|
+
primaryAccent?: string;
|
|
22
|
+
primaryAccentContrast?: string;
|
|
23
|
+
}): {
|
|
24
|
+
primaryAccentDerived: string | undefined;
|
|
25
|
+
primaryAccentContrastDerived: string | undefined;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Recomputes both derived accent colors from a brand's source colors and writes them
|
|
29
|
+
* back into `brand.colorScheme` in place. Matches Core's recompute-on-change behavior:
|
|
30
|
+
* a derived field is written when its source is valid and DELETED when the source is
|
|
31
|
+
* missing or invalid. No-op when the brand has no `colorScheme`.
|
|
32
|
+
*
|
|
33
|
+
* Hosts should call this on initial brand load and whenever `primaryAccent` or
|
|
34
|
+
* `primaryAccentContrast` is edited.
|
|
35
|
+
*
|
|
36
|
+
* @param brand - The brand model to mutate in place
|
|
37
|
+
*/
|
|
38
|
+
export declare function updateDerivedColors(brand: Brand): void;
|
|
39
|
+
//# sourceMappingURL=deriveColors.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Brand } from './brandTypes.js';
|
|
2
|
+
/**
|
|
3
|
+
* Darkens a color by 0.5 in LAB space, matching Salesforce Core's algorithm.
|
|
4
|
+
* Core uses: `chroma(hex).darken(0.5).hex()`
|
|
5
|
+
* This operates in LAB color space: L_new = L - (18 * 0.5) = L - 9
|
|
6
|
+
*
|
|
7
|
+
* @param sourceColor - 6-digit or 8-digit hex color (with or without #)
|
|
8
|
+
* @returns Lowercase 6-digit hex (e.g., "#0060ba"), or undefined if input is invalid
|
|
9
|
+
*/
|
|
10
|
+
export declare function darkenColor(sourceColor: string | undefined): string | undefined;
|
|
11
|
+
/** Derives primaryAccentDerived from primaryAccent (darkens by 0.5 in LAB space). */
|
|
12
|
+
export declare function derivePrimaryAccentDerived(primaryAccent: string | undefined): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Derives primaryAccentContrastDerived from primaryAccentContrast.
|
|
15
|
+
* Matches Core's algorithm exactly: darken(0.5), then contrast check with fallback.
|
|
16
|
+
* Core's getValidContrast: if contrast(darkened, bg) < 4.5, return '#000000' (light bg) or '#FFFFFF' (dark bg).
|
|
17
|
+
*/
|
|
18
|
+
export declare function derivePrimaryAccentContrastDerived(primaryAccentContrast: string | undefined, primaryAccentDerived: string | undefined): string | undefined;
|
|
19
|
+
/** Derives both brand colors (primaryAccentDerived first, then primaryAccentContrastDerived). */
|
|
20
|
+
export declare function deriveBrandColors(colors: {
|
|
21
|
+
primaryAccent?: string;
|
|
22
|
+
primaryAccentContrast?: string;
|
|
23
|
+
}): {
|
|
24
|
+
primaryAccentDerived: string | undefined;
|
|
25
|
+
primaryAccentContrastDerived: string | undefined;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Recomputes both derived accent colors from a brand's source colors and writes them
|
|
29
|
+
* back into `brand.colorScheme` in place. Matches Core's recompute-on-change behavior:
|
|
30
|
+
* a derived field is written when its source is valid and DELETED when the source is
|
|
31
|
+
* missing or invalid. No-op when the brand has no `colorScheme`.
|
|
32
|
+
*
|
|
33
|
+
* Hosts should call this on initial brand load and whenever `primaryAccent` or
|
|
34
|
+
* `primaryAccentContrast` is edited.
|
|
35
|
+
*
|
|
36
|
+
* @param brand - The brand model to mutate in place
|
|
37
|
+
*/
|
|
38
|
+
export declare function updateDerivedColors(brand: Brand): void;
|
|
39
|
+
//# sourceMappingURL=deriveColors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deriveColors.d.ts","sourceRoot":"","sources":["../../src/protocol/deriveColors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4BH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAa/E;AAED,qFAAqF;AACrF,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAEhG;AAED;;;;GAIG;AACH,wBAAgB,kCAAkC,CACjD,qBAAqB,EAAE,MAAM,GAAG,SAAS,EACzC,oBAAoB,EAAE,MAAM,GAAG,SAAS,GACtC,MAAM,GAAG,SAAS,CA0BpB;AAED,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACzC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAC/B,GAAG;IACH,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,4BAA4B,EAAE,MAAM,GAAG,SAAS,CAAC;CACjD,CAcA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CA8BtD"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import chroma from "chroma-js";
|
|
2
|
+
function darkenColor(sourceColor) {
|
|
3
|
+
if (!sourceColor) return void 0;
|
|
4
|
+
try {
|
|
5
|
+
if (!chroma.valid(sourceColor)) return void 0;
|
|
6
|
+
return chroma(sourceColor).darken(0.5).hex();
|
|
7
|
+
} catch {
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function derivePrimaryAccentDerived(primaryAccent) {
|
|
12
|
+
return darkenColor(primaryAccent);
|
|
13
|
+
}
|
|
14
|
+
function derivePrimaryAccentContrastDerived(primaryAccentContrast, primaryAccentDerived) {
|
|
15
|
+
if (!primaryAccentContrast || !primaryAccentDerived) return void 0;
|
|
16
|
+
try {
|
|
17
|
+
if (!chroma.valid(primaryAccentContrast) || !chroma.valid(primaryAccentDerived)) {
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
const darkened = chroma(primaryAccentContrast).darken(0.5).hex();
|
|
21
|
+
const contrastRatio = chroma.contrast(darkened, primaryAccentDerived);
|
|
22
|
+
if (contrastRatio < 4.5) {
|
|
23
|
+
const isLight = chroma(primaryAccentDerived).luminance() > 0.5;
|
|
24
|
+
return isLight ? "#000000" : "#FFFFFF";
|
|
25
|
+
}
|
|
26
|
+
return darkened;
|
|
27
|
+
} catch {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function deriveBrandColors(colors) {
|
|
32
|
+
const primaryAccentDerived = derivePrimaryAccentDerived(colors.primaryAccent);
|
|
33
|
+
const primaryAccentContrastDerived = derivePrimaryAccentContrastDerived(
|
|
34
|
+
colors.primaryAccentContrast,
|
|
35
|
+
primaryAccentDerived
|
|
36
|
+
);
|
|
37
|
+
return {
|
|
38
|
+
primaryAccentDerived,
|
|
39
|
+
primaryAccentContrastDerived
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function updateDerivedColors(brand) {
|
|
43
|
+
if (!brand.colorScheme || typeof brand.colorScheme !== "object") {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const colorScheme = brand.colorScheme;
|
|
47
|
+
const primaryAccent = typeof colorScheme.primaryAccent === "string" ? colorScheme.primaryAccent : void 0;
|
|
48
|
+
const primaryAccentContrast = typeof colorScheme.primaryAccentContrast === "string" ? colorScheme.primaryAccentContrast : void 0;
|
|
49
|
+
const derived = deriveBrandColors({ primaryAccent, primaryAccentContrast });
|
|
50
|
+
if (derived.primaryAccentDerived !== void 0) {
|
|
51
|
+
colorScheme.primaryAccentDerived = derived.primaryAccentDerived;
|
|
52
|
+
} else {
|
|
53
|
+
delete colorScheme.primaryAccentDerived;
|
|
54
|
+
}
|
|
55
|
+
if (derived.primaryAccentContrastDerived !== void 0) {
|
|
56
|
+
colorScheme.primaryAccentContrastDerived = derived.primaryAccentContrastDerived;
|
|
57
|
+
} else {
|
|
58
|
+
delete colorScheme.primaryAccentContrastDerived;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
darkenColor,
|
|
63
|
+
deriveBrandColors,
|
|
64
|
+
derivePrimaryAccentContrastDerived,
|
|
65
|
+
derivePrimaryAccentDerived,
|
|
66
|
+
updateDerivedColors
|
|
67
|
+
};
|