Refactor css loading code

This commit is contained in:
Tyler Long
2018-03-13 14:31:56 +08:00
parent f62736c749
commit 259d2a9b5c

View File

@@ -36,16 +36,9 @@ import gitGraphParser from './diagrams/gitGraph/parser/gitGraph'
import gitGraphRenderer from './diagrams/gitGraph/gitGraphRenderer' import gitGraphRenderer from './diagrams/gitGraph/gitGraphRenderer'
import gitGraphAst from './diagrams/gitGraph/gitGraphAst' import gitGraphAst from './diagrams/gitGraph/gitGraphAst'
import darkTheme from './themes/dark/index.scss' const themes = {}
import defaultTheme from './themes/default/index.scss' for (const themeName of ['default', 'forest', 'dark', 'neutral']) {
import forestTheme from './themes/forest/index.scss' themes[themeName] = require(`./themes/${themeName}/index.scss`)
import neutralTheme from './themes/neutral/index.scss'
const themes = {
dark: darkTheme,
default: defaultTheme,
forest: forestTheme,
neutral: neutralTheme
} }
/** /**
@@ -60,7 +53,7 @@ const themes = {
* ``` * ```
*/ */
const config = { const config = {
theme: defaultTheme, theme: themes.default,
/** /**
* logLevel , decides the amount of logging to be used. * logLevel , decides the amount of logging to be used.
@@ -410,7 +403,7 @@ const render = function (id, txt, cb, container) {
const firstChild = svg.firstChild const firstChild = svg.firstChild
const style1 = document.createElement('style') const style1 = document.createElement('style')
style1.innerHTML = scope(themes[config.theme] || defaultTheme, `#${id}`) style1.innerHTML = scope(themes[config.theme] || themes.default, `#${id}`)
svg.insertBefore(style1, firstChild) svg.insertBefore(style1, firstChild)
const style2 = document.createElement('style') const style2 = document.createElement('style')