UNPKG

@varlet/ui

Version:

A Vue3 component library based on Material Design 2 and 3, supporting mobile and desktop.

44 lines (43 loc) 1.33 kB
import { withInstall, withPropsDefaultsSetter } from "../utils/components.mjs"; import { formatStyleVars } from "../utils/elements.mjs"; import { props as styleProviderProps } from "./props.mjs"; import VarStyleProvider from "./StyleProvider.mjs"; const styleId = "varlet-style-vars"; function removeStyle() { const style = document.head.querySelector(`#${styleId}`); if (style) { document.head.removeChild(style); } } function insertStyle(content) { const style = document.createElement("style"); style.id = styleId; style.innerHTML = content; document.head.appendChild(style); } function StyleProvider(styleVars) { if (styleVars == null) { removeStyle(); return; } const styles = formatStyleVars(styleVars != null ? styleVars : {}); const content = Object.entries(styles).reduce((content2, [key, value]) => { content2 += `${key}:${value};`; return content2; }, `:root:root { `); removeStyle(); insertStyle(`${content} }`); } StyleProvider.Component = VarStyleProvider; withInstall(VarStyleProvider); withInstall(VarStyleProvider, StyleProvider); withPropsDefaultsSetter(StyleProvider, styleProviderProps); const _StyleProviderComponent = VarStyleProvider; var stdin_default = StyleProvider; export { _StyleProviderComponent, stdin_default as default, styleProviderProps };