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AAE;AACN,UAAA,SAAS,EAAE,IADL;AAEN,UAAA,IAAI,EAAE,IAFA;AAGN,UAAA,OAAO,EAAE,MAAM,KAAK,UAAL;AAHT;AADH;AAHkB,KAAR,CAAnB;AAWD;;AAED,MAAI,YAAJ,GAAgB;AACd,UAAM,MAAM,GAAG,KAAK,IAAL,GAAY,MAAZ,GAAqB,OAApC;AAEA,WAAO,KAAK,MAAL,CAAY,MAAZ,CAAP;AACD;;AAED,MAAI,eAAJ,GAAmB;AACjB,UAAM,KAAK,GAAG,KAAK,WAAnB;AACA;;AACA,UAAM,OAAO,GAAG,KAAK,OAAL,IAAgB,EAAhC;AACA,QAAI,GAAJ;;AAEA,QAAI,OAAO,CAAC,UAAR,IAAsB,IAA1B,EAAgC;AAC9B,MAAA,GAAG,GAAG,OAAO,CAAC,UAAR,CAAmB,GAAnB,CAAuB,KAAvB,CAAN;AACA;;AACA,UAAI,GAAG,IAAI,IAAX,EAAiB,OAAO,GAAP;AAClB;;AAED,IAAA,GAAG,GAAG,UAAU,CAAC,SAAX,CAAqB,KAArB,EAA4B,OAAO,CAAC,gBAApC,CAAN;;AAEA,QAAI,OAAO,CAAC,WAAR,IAAuB,IAA3B,EAAiC;AAC/B,MAAA,GAAG,GAAG,OAAO,CAAC,WAAR,CAAoB,GAApB,CAAN;AACD;;AAED,QAAI,OAAO,CAAC,UAAR,IAAsB,IAA1B,EAAgC;AAC9B,MAAA,OAAO,CAAC,UAAR,CAAmB,GAAnB,CAAuB,KAAvB,EAA8B,GAA9B;AACD;;AAED,WAAO,GAAP;AACD;;AAED,MAAI,WAAJ,GAAe;AACb;AACA,UAAM,KAAK,GAAG,KAAK,YAAL,IAAqB,EAAnC;AACA,WAAO,UAAU,CAAC,KAAX,CAAiB,KAAjB,CAAP;AACD;;AAvP+B;AACzB,KAAA,CAAA,QAAA,GAAW,OAAX","sourcesContent":["/* eslint-disable no-multi-spaces */\n// Extensions\nimport { Service } from '../service'\n\n// Utilities\nimport * as ThemeUtils from './utils'\n\n// Types\nimport Vue from 'vue'\nimport {\n VuetifyParsedTheme,\n VuetifyThemeOptions,\n VuetifyThemes,\n VuetifyThemeVariant,\n} from 'vuetify/types/services/theme'\n\nexport class Theme extends Service {\n static property = 'theme'\n\n public disabled = false\n\n public options: VuetifyThemeOptions['options']\n\n public styleEl?: HTMLStyleElement\n\n public themes: VuetifyThemes = {\n light: {\n primary: '#1976D2', // blue.darken2\n secondary: '#424242', // grey.darken3\n accent: '#82B1FF', // blue.accent1\n error: '#FF5252', // red.accent2\n info: '#2196F3', // blue.base\n success: '#4CAF50', // green.base\n warning: '#FB8C00', // amber.base\n },\n dark: {\n primary: '#2196F3', // blue.base\n secondary: '#424242', // grey.darken3\n accent: '#FF4081', // pink.accent-2\n error: '#FF5252', // red.accent2\n info: '#2196F3', // blue.base\n success: '#4CAF50', // green.base\n warning: '#FB8C00', // amber.base\n },\n }\n\n public defaults: VuetifyThemes = this.themes\n\n private isDark = null as boolean | null\n\n private vueInstance = null as Vue | null\n\n constructor (options: Partial<VuetifyThemeOptions> = {}) {\n super()\n if (options.disable) {\n this.disabled = true\n\n return\n }\n\n this.options = {\n ...this.options,\n ...options.options,\n }\n\n this.dark = Boolean(options.dark)\n const themes = options.themes || {}\n\n this.themes = {\n dark: this.fillVariant(themes.dark, true),\n light: this.fillVariant(themes.light, false),\n }\n }\n\n // When setting css, check for element\n // and apply new values\n set css (val: string) {\n this.checkOrCreateStyleElement() && (this.styleEl!.innerHTML = val)\n }\n\n set dark (val: boolean) {\n const oldDark = this.isDark\n\n this.isDark = val\n // Only apply theme after dark\n // has already been set before\n oldDark != null && this.applyTheme()\n }\n\n get dark () {\n return Boolean(this.isDark)\n }\n\n // Apply current theme default\n // only called on client side\n public applyTheme (): void {\n if (this.disabled) return this.clearCss()\n\n this.css = this.generatedStyles\n }\n\n public clearCss (): void {\n this.css = ''\n }\n\n // Initialize theme for SSR and SPA\n // Attach to ssrContext head or\n // apply new theme to document\n public init (root: Vue, ssrContext?: any): void {\n if (this.disabled) return\n\n const meta = Boolean((root as any).$meta) // TODO: don't import public types from /src\n const ssr = Boolean(ssrContext)\n\n /* istanbul ignore else */\n if (meta) {\n this.initNuxt(root)\n } else if (ssr) {\n this.initSSR(ssrContext)\n }\n\n this.initTheme()\n }\n\n // Allows for you to set target theme\n public setTheme (theme: 'light' | 'dark', value: object) {\n this.themes[theme] = Object.assign(this.themes[theme], value)\n this.applyTheme()\n }\n\n // Reset theme defaults\n public resetThemes () {\n this.themes.light = Object.assign({}, this.defaults.light)\n this.themes.dark = Object.assign({}, this.defaults.dark)\n this.applyTheme()\n }\n\n // Check for existence of style element\n private checkOrCreateStyleElement (): boolean {\n this.styleEl = document.getElementById('vuetify-theme-stylesheet') as HTMLStyleElement\n\n /* istanbul ignore next */\n if (this.styleEl) return true\n\n this.genStyleElement() // If doesn't have it, create it\n\n return Boolean(this.styleEl)\n }\n\n private fillVariant (\n theme: Partial<VuetifyThemeVariant> = {},\n dark: boolean\n ): VuetifyThemeVariant {\n const defaultTheme = this.themes[dark ? 'dark' : 'light']\n\n return Object.assign({},\n defaultTheme,\n theme\n )\n }\n\n // Generate the style element\n // if applicable\n private genStyleElement (): void {\n if (typeof document === 'undefined') return\n\n /* istanbul ignore next */\n const options = this.options || {}\n\n this.styleEl = document.createElement('style')\n this.styleEl.type = 'text/css'\n this.styleEl.id = 'vuetify-theme-stylesheet'\n\n if (options.cspNonce) {\n this.styleEl.setAttribute('nonce', options.cspNonce)\n }\n\n document.head.appendChild(this.styleEl)\n }\n\n private initNuxt (root: Vue) {\n const options = this.options || {}\n root.$children.push(new Vue({\n head: {\n style: [\n {\n cssText: this.generatedStyles,\n type: 'text/css',\n id: 'vuetify-theme-stylesheet',\n nonce: options.cspNonce,\n },\n ],\n },\n } as any))\n }\n\n private initSSR (ssrContext?: any) {\n const options = this.options || {}\n // SSR\n const nonce = options.cspNonce ? ` nonce=\"${options.cspNonce}\"` : ''\n ssrContext.head = ssrContext.head || ''\n ssrContext.head += `<style type=\"text/css\" id=\"vuetify-theme-stylesheet\"${nonce}>${this.generatedStyles}</style>`\n }\n\n private initTheme () {\n // Only watch for reactivity on client side\n if (typeof document === 'undefined') return\n\n // If we get here somehow, ensure\n // existing instance is removed\n if (this.vueInstance) this.vueInstance.$destroy()\n\n // Use Vue instance to track reactivity\n // TODO: Update to use RFC if merged\n // https://github.com/vuejs/rfcs/blob/advanced-reactivity-api/active-rfcs/0000-advanced-reactivity-api.md\n this.vueInstance = new Vue({\n data: { themes: this.themes },\n\n watch: {\n themes: {\n immediate: true,\n deep: true,\n handler: () => this.applyTheme(),\n },\n },\n })\n }\n\n get currentTheme () {\n const target = this.dark ? 'dark' : 'light'\n\n return this.themes[target]\n }\n\n get generatedStyles (): string {\n const theme = this.parsedTheme\n /* istanbul ignore next */\n const options = this.options || {}\n let css\n\n if (options.themeCache != null) {\n css = options.themeCache.get(theme)\n /* istanbul ignore if */\n if (css != null) return css\n }\n\n css = ThemeUtils.genStyles(theme, options.customProperties)\n\n if (options.minifyTheme != null) {\n css = options.minifyTheme(css)\n }\n\n if (options.themeCache != null) {\n options.themeCache.set(theme, css)\n }\n\n return css\n }\n\n get parsedTheme (): VuetifyParsedTheme {\n /* istanbul ignore next */\n const theme = this.currentTheme || {}\n return ThemeUtils.parse(theme)\n }\n}\n"],"sourceRoot":"","file":"index.js"} |