yuebonui-vue3/src/utils/theme-change.js
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/**
* 动态加载用户自定义主题
* @author yuebon.com chen qingwen
*/
const version = require('element-ui/package.json').version // element-ui version from node_modules
const ORIGINAL_THEME = '#409EFF' // default color
export async function loadUserConfigTheme(val) {
let chalk = ''
const oldVal = chalk ? val : ORIGINAL_THEME
if (typeof val !== 'string') return
const themeCluster = getThemeCluster(val.replace('#', ''))
const originalCluster = getThemeCluster(oldVal.replace('#', ''))
const getHandler = (variable, id) => {
return () => {
const originalCluster = getThemeCluster(ORIGINAL_THEME.replace('#', ''))
const newStyle = updateStyle(variable, originalCluster, themeCluster)
let styleTag = document.getElementById(id)
if (!styleTag) {
styleTag = document.createElement('style')
styleTag.setAttribute('id', id)
document.head.appendChild(styleTag)
}
styleTag.innerText = newStyle
}
}
if (!chalk) {
const url = `https://unpkg.com/element-ui@${version}/lib/theme-chalk/index.css`
// eslint-disable-next-line no-const-assign
chalk = await getCSSString(url, 'chalk')
}
const chalkHandler = getHandler(chalk, 'chalk-style')
chalkHandler()
const styles = [].slice.call(document.querySelectorAll('style'))
.filter(style => {
const text = style.innerText
return new RegExp(oldVal, 'i').test(text) && !/Chalk Variables/.test(text)
})
styles.forEach(style => {
const { innerText } = style
if (typeof innerText !== 'string') return
style.innerText = updateStyle(innerText, originalCluster, themeCluster)
})
}
export function updateStyle(style, oldCluster, newCluster) {
let newStyle = style
oldCluster.forEach((color, index) => {
newStyle = newStyle.replace(new RegExp(color, 'ig'), newCluster[index])
})
return newStyle
}
export function getCSSString(url, variable) {
return new Promise(resolve => {
const xhr = new XMLHttpRequest()
xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && xhr.status === 200) {
后面还有 53 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。