import { warnOnce } from 'botframework-webchat-core'; import defaultStyleOptions from './defaultStyleOptions'; import StyleOptions, { StrictStyleOptions } from './StyleOptions'; const hideScrollToEndButtonDeprecation = warnOnce( '"styleOptions.hideScrollToEndButton" has been deprecated. To hide scroll to end button, set "scrollToEndBehavior" to false. This deprecation migration will be removed on or after 2023-06-02.' ); const newMessagesButtonFontSizeDeprecation = warnOnce( '"styleOptions.newMessagesButtonFontSize" has been renamed to "styleOptions.scrollToEndButtonFontSize". This deprecation migration will be removed on or after 2023-06-02.' ); const suggestedActionBackgroundDeprecation = warnOnce( '"styleOptions.suggestedActionBackground" has been deprecated. Please use "styleOptions.suggestedActionBackgroundColor" instead. This deprecation migration will be removed on or after 2021-09-16.' ); const suggestedActionXXXBackgroundDeprecation = warnOnce( '"styleOptions.suggestedActionXXXBackground" has been deprecated. Please use "styleOptions.suggestedActionBackgroundColorOnXXX" instead. This deprecation migration will be removed on or after 2021-09-16.' ); const suggestedActionDisabledDeprecation = warnOnce( '"styleOptions.suggestedActionDisabledXXX" has been renamed to "styleOptions.suggestedActionXXXOnDisabled". This deprecation migration will be removed on or after 2021-09-16.' ); // TODO: [P4] We should add a notice for people who want to use "styleSet" instead of "styleOptions". // "styleSet" is actually CSS stylesheet and it is based on the DOM tree. // DOM tree may change from time to time, thus, maintaining "styleSet" becomes a constant effort. // eslint-disable-next-line complexity export default function normalizeStyleOptions({ hideScrollToEndButton, newMessagesButtonFontSize, ...options }: StyleOptions = {}): StrictStyleOptions { const filledOptions: Required = { ...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; 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': 'â¤ī¸', '