in packages/api/src/normalizeStyleOptions.ts [31:187]
export default function normalizeStyleOptions({
hideScrollToEndButton,
newMessagesButtonFontSize,
...options
}: StyleOptions = {}): StrictStyleOptions {
const filledOptions: Required<StyleOptions> = { ...defaultStyleOptions, ...options };
// Keep this list flat (no nested style) and serializable (no functions)
const { bubbleFromUserNubOffset, bubbleNubOffset, emojiSet } = filledOptions;
let normalizedBubbleFromUserNubOffset: number;
let normalizedBubbleNubOffset: number;
let normalizedEmojiSet: false | Record<string, string>;
if (bubbleFromUserNubOffset === 'top') {
normalizedBubbleFromUserNubOffset = 0;
} else if (typeof bubbleFromUserNubOffset !== 'number') {
normalizedBubbleFromUserNubOffset = -0;
} else {
normalizedBubbleFromUserNubOffset = bubbleFromUserNubOffset;
}
if (bubbleNubOffset === 'top') {
normalizedBubbleNubOffset = 0;
} else if (typeof bubbleNubOffset !== 'number') {
normalizedBubbleNubOffset = -0;
} else {
normalizedBubbleNubOffset = bubbleNubOffset;
}
if (emojiSet === true) {
normalizedEmojiSet = {
':)': 'đ',
':-)': 'đ',
'(:': 'đ',
'(-:': 'đ',
':-|': 'đ',
':|': 'đ',
':-(': 'âšī¸',
':(': 'âšī¸',
':-D': 'đ',
':D': 'đ',
':-p': 'đ',
':p': 'đ',
':-P': 'đ',
':P': 'đ',
':-o': 'đ˛',
':o': 'đ˛',
':O': 'đ˛',
':-O': 'đ˛',
':-0': 'đ˛',
':0': 'đ˛',
';-)': 'đ',
';)': 'đ',
'<3': 'â¤ī¸',
'</3': 'đ',
'<\\3': 'đ'
};
} else if (Object.prototype.toString.call(emojiSet) !== '[object Object]') {
console.warn('botframework-webchat: emojiSet must be a boolean or an object with emoticon: emojiValues');
normalizedEmojiSet = false;
} else {
normalizedEmojiSet = emojiSet;
}
if (hideScrollToEndButton) {
hideScrollToEndButtonDeprecation();
// Only set if the "scrollToEndButtonBehavior" is not set.
// If it has been set, the developer should know the older "hideScrollToEndButton" option is deprecated.
filledOptions.scrollToEndButtonBehavior = options.scrollToEndButtonBehavior || false;
}
let patchedScrollToEndButtonBehavior = filledOptions.scrollToEndButtonBehavior;
if (patchedScrollToEndButtonBehavior !== 'any' && patchedScrollToEndButtonBehavior !== false) {
patchedScrollToEndButtonBehavior === 'unread' ||
console.warn(
'Web Chat: "scrollToEndButtonBehavior" must be either "unread", "any", or false, will set to "unread".'
);
patchedScrollToEndButtonBehavior = 'unread';
}
if (newMessagesButtonFontSize) {
newMessagesButtonFontSizeDeprecation();
// Only set if the "scrollToEndButtonFontSize" is not set.
filledOptions.scrollToEndButtonFontSize = options.scrollToEndButtonFontSize || newMessagesButtonFontSize;
}
options.suggestedActionBackground && suggestedActionBackgroundDeprecation();
if (options.suggestedActionActiveBackground) {
suggestedActionXXXBackgroundDeprecation();
filledOptions.suggestedActionBackgroundColorOnActive =
options.suggestedActionBackgroundColorOnActive || options.suggestedActionActiveBackground;
}
if (options.suggestedActionFocusBackground) {
suggestedActionXXXBackgroundDeprecation();
filledOptions.suggestedActionBackgroundColorOnFocus =
options.suggestedActionBackgroundColorOnFocus || options.suggestedActionFocusBackground;
}
if (options.suggestedActionHoverBackground) {
suggestedActionXXXBackgroundDeprecation();
filledOptions.suggestedActionBackgroundColorOnHover =
options.suggestedActionBackgroundColorOnHover || options.suggestedActionHoverBackground;
}
if (options.suggestedActionDisabledBackground) {
suggestedActionXXXBackgroundDeprecation();
filledOptions.suggestedActionBackgroundColorOnDisabled =
options.suggestedActionBackgroundColorOnDisabled || options.suggestedActionDisabledBackground;
}
if (options.suggestedActionDisabledBorderColor) {
suggestedActionDisabledDeprecation();
filledOptions.suggestedActionBorderColorOnDisabled =
options.suggestedActionBorderColorOnDisabled || options.suggestedActionDisabledBorderColor;
}
if (options.suggestedActionDisabledBorderStyle) {
suggestedActionDisabledDeprecation();
filledOptions.suggestedActionBorderStyleOnDisabled =
options.suggestedActionBorderStyleOnDisabled || options.suggestedActionDisabledBorderStyle;
}
if (options.suggestedActionDisabledBorderWidth) {
suggestedActionDisabledDeprecation();
filledOptions.suggestedActionBorderWidthOnDisabled =
options.suggestedActionBorderWidthOnDisabled || options.suggestedActionDisabledBorderWidth;
}
if (options.suggestedActionDisabledTextColor) {
suggestedActionDisabledDeprecation();
filledOptions.suggestedActionTextColorOnDisabled =
options.suggestedActionTextColorOnDisabled || options.suggestedActionDisabledTextColor;
}
return {
...filledOptions,
bubbleFromUserNubOffset: normalizedBubbleFromUserNubOffset,
bubbleNubOffset: normalizedBubbleNubOffset,
emojiSet: normalizedEmojiSet,
scrollToEndButtonBehavior: patchedScrollToEndButtonBehavior
};
}