build-plugin-fusion
Version:
plugin for build scripts while use fusion component
13 lines • 1.47 kB
JavaScript
module.exports = function (themesCssVars, defaultTheme, cssVariable) {
var themesDataStr = Object.keys(themesCssVars).map(function (themeKey) {
var cssVars = themesCssVars[themeKey];
return !cssVariable
? "'".concat(themeKey, "': ':root {").concat(Object.entries(cssVars).map(function (_a) {
var k = _a[0], v = _a[1];
return "".concat(k, ": ").concat(v);
}).join(';'), "}'")
: "'".concat(themeKey, "': '").concat(cssVars, "'");
}).join(',');
return "\nconst themesData = {\n ".concat(themesDataStr, "\n};\n// Append Style fn\nlet style;\nfunction appendStyle(styles) {\n if (style) style.remove();\n style = document.createElement('style');\n style.type = 'text/css';\n\n if (style.styleSheet) {\n // This is required for IE8 and below.\n style.styleSheet.cssText = styles;\n } else {\n style.appendChild(document.createTextNode(styles));\n }\n // Append style to the head element\n document.getElementsByTagName('head')[0].appendChild(style);\n}\n// Change theme fn\nfunction changeTheme(currentTheme) {\n // Get current theme\n const theme = themesData[currentTheme];\n if (theme) {\n appendStyle(theme);\n } else {\n console.warn('can not find theme:' + currentTheme);\n }\n}\n").concat(defaultTheme ? "changeTheme('".concat(defaultTheme, "');") : '', "\nwindow.__changeTheme__ = changeTheme;");
};
//# sourceMappingURL=getThemeCode.js.map