2022-09-25 16:41:09 +00:00
|
|
|
import lodash from 'lodash'
|
|
|
|
import fs from 'fs'
|
2023-03-07 17:52:11 +00:00
|
|
|
import { Data } from '#miao'
|
2022-09-25 16:41:09 +00:00
|
|
|
|
2022-10-06 22:20:46 +00:00
|
|
|
let HelpTheme = {
|
2022-09-25 16:41:09 +00:00
|
|
|
async getThemeCfg (theme, exclude) {
|
|
|
|
let dirPath = './plugins/miao-plugin/resources/help/theme/'
|
|
|
|
let ret = []
|
|
|
|
let names = []
|
|
|
|
let dirs = fs.readdirSync(dirPath)
|
|
|
|
lodash.forEach(dirs, (dir) => {
|
|
|
|
if (fs.existsSync(`${dirPath}${dir}/main.png`)) {
|
|
|
|
names.push(dir)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (lodash.isArray(theme)) {
|
|
|
|
ret = lodash.intersection(theme, names)
|
|
|
|
} else if (theme === 'all') {
|
|
|
|
ret = names
|
|
|
|
}
|
|
|
|
if (exclude && lodash.isArray(exclude)) {
|
|
|
|
ret = lodash.difference(ret, exclude)
|
|
|
|
}
|
|
|
|
if (ret.length === 0) {
|
|
|
|
ret = ['default']
|
|
|
|
}
|
|
|
|
let name = lodash.sample(ret)
|
|
|
|
let resPath = '{{_res_path}}/help/theme/'
|
|
|
|
return {
|
|
|
|
main: `${resPath}${name}/main.png`,
|
|
|
|
bg: fs.existsSync(`${dirPath}${name}/bg.jpg`) ? `${resPath}${name}/bg.jpg` : `${resPath}default/bg.jpg`,
|
2023-03-07 17:52:11 +00:00
|
|
|
style: (await Data.importModule(`resources/help/theme/${name}/config.js`, 'miao')).style || {}
|
2022-09-25 16:41:09 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
async getThemeData (diyStyle, sysStyle) {
|
2022-10-04 14:51:44 +00:00
|
|
|
let helpConfig = lodash.extend({}, sysStyle, diyStyle)
|
2022-09-25 16:41:09 +00:00
|
|
|
let colCount = Math.min(5, Math.max(parseInt(helpConfig?.colCount) || 3, 2))
|
|
|
|
let colWidth = Math.min(500, Math.max(100, parseInt(helpConfig?.colWidth) || 265))
|
|
|
|
let width = Math.min(2500, Math.max(800, colCount * colWidth + 30))
|
2022-10-06 22:20:46 +00:00
|
|
|
let theme = await HelpTheme.getThemeCfg(diyStyle.theme || sysStyle.theme, diyStyle.themeExclude || sysStyle.themeExclude)
|
2022-09-25 16:41:09 +00:00
|
|
|
let themeStyle = theme.style || {}
|
|
|
|
let ret = [`
|
|
|
|
body{background-image:url(${theme.bg});width:${width}px;}
|
|
|
|
.container{background-image:url(${theme.main});width:${width}px;}
|
|
|
|
.help-table .td,.help-table .th{width:${100 / colCount}%}
|
|
|
|
`]
|
|
|
|
let css = function (sel, css, key, def, fn) {
|
2022-09-27 03:05:32 +00:00
|
|
|
let val = Data.def(themeStyle[key], diyStyle[key], sysStyle[key], def)
|
2022-09-25 16:41:09 +00:00
|
|
|
if (fn) {
|
|
|
|
val = fn(val)
|
|
|
|
}
|
|
|
|
ret.push(`${sel}{${css}:${val}}`)
|
|
|
|
}
|
|
|
|
css('.help-title,.help-group', 'color', 'fontColor', '#ceb78b')
|
2022-09-25 19:32:58 +00:00
|
|
|
css('.help-title,.help-group', 'text-shadow', 'fontShadow', 'none')
|
2022-09-25 16:41:09 +00:00
|
|
|
css('.help-desc', 'color', 'descColor', '#eee')
|
|
|
|
css('.cont-box', 'background', 'contBgColor', 'rgba(43, 52, 61, 0.8)')
|
2022-09-27 02:25:31 +00:00
|
|
|
css('.cont-box', 'backdrop-filter', 'contBgBlur', 3, (n) => diyStyle.bgBlur === false ? 'none' : `blur(${n}px)`)
|
2022-09-25 16:41:09 +00:00
|
|
|
css('.help-group', 'background', 'headerBgColor', 'rgba(34, 41, 51, .4)')
|
|
|
|
css('.help-table .tr:nth-child(odd)', 'background', 'rowBgColor1', 'rgba(34, 41, 51, .2)')
|
|
|
|
css('.help-table .tr:nth-child(even)', 'background', 'rowBgColor2', 'rgba(34, 41, 51, .4)')
|
|
|
|
return {
|
|
|
|
style: `<style>${ret.join('\n')}</style>`,
|
|
|
|
colCount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-06 22:20:46 +00:00
|
|
|
export default HelpTheme
|