@retailmenot/anchor
Version:
A React UI Library by RetailMeNot
73 lines (61 loc) • 2.44 kB
JavaScript
import { e as _typeof } from './anchor-chunk-7b9d8557.js';
import { RootTheme } from './theme.js';
import './anchor-chunk-210b63ef.js';
import './skeleton.js';
import './anchor-chunk-27f34e54.js';
import 'react';
import 'classnames';
import '@xstyled/styled-components';
import '@xstyled/system';
import 'polished';
import './anchor-chunk-e1ca097b.js';
import './anchor-chunk-cd7ef49a.js';
import './anchor-chunk-20e4020f.js';
function deepClone(data) {
if (typeof data === null || _typeof(data) !== 'object' || Array.isArray(data)) {
return data;
} // Using constructor(), creates a new instance of the object in memory rather than a reference
var tmpObj = data.constructor();
for (var key in data) {
if (data.hasOwnProperty(key)) {
tmpObj[key] = deepClone(data[key]);
}
}
return tmpObj;
} // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
function recursiveUpdate(settingStep, newThemeStep) {
for (var key in settingStep) {
// If the user has passed undefined as a value, delete the associated property
if (settingStep.hasOwnProperty(key) && settingStep[key] === undefined) {
delete newThemeStep[key];
} // Else if the value isn't an object literal then update the theme with that value
else if (settingStep.hasOwnProperty(key) && (_typeof(settingStep[key]) !== 'object' || Array.isArray(settingStep[key]))) {
newThemeStep[key] = settingStep[key];
} // Else if the key doesn't already exist in the new theme, add it, and continue recursion
else if (settingStep.hasOwnProperty(key) && !newThemeStep[key]) {
newThemeStep[key] = {};
recursiveUpdate(settingStep[key], newThemeStep[key]);
} // Else continue recursion
else {
recursiveUpdate(settingStep[key], newThemeStep[key]);
}
}
}
function themeMerge(settings) {
var baseTheme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : RootTheme;
var newTheme = deepClone(baseTheme);
for (var key in settings) {
if (settings[key]) {
if (!newTheme.hasOwnProperty(key)) {
// Adds new keys to the root of the object
newTheme[key] = settings[key];
} else {
// Updates baseTheme defaults with new values
recursiveUpdate(settings[key], newTheme[key]);
}
}
}
return newTheme;
}
export { themeMerge };
//# sourceMappingURL=thememerge.js.map