mirror of
https://github.com/liriliri/eruda.git
synced 2026-02-02 09:49:00 +08:00
feat: isDarkTheme, getTheme util
This commit is contained in:
8
eruda.d.ts
vendored
8
eruda.d.ts
vendored
@@ -50,7 +50,7 @@ declare module 'eruda' {
|
||||
|
||||
/**
|
||||
* Eruda Plugin
|
||||
* @see https://github.com/liriliri/eruda/blob/master/doc/PLUGIN.md
|
||||
* @see https://eruda.liriliri.io/docs/plugin.html
|
||||
*/
|
||||
export interface Tool {
|
||||
/**
|
||||
@@ -389,16 +389,18 @@ declare module 'eruda' {
|
||||
|
||||
/**
|
||||
* Eruda Util
|
||||
* @see https://github.com/liriliri/eruda/blob/master/doc/UTIL_API.md
|
||||
* @see https://eruda.liriliri.io/docs/plugin.html#utility
|
||||
*/
|
||||
export interface Util {
|
||||
evalCss(css: string): HTMLStyleElement
|
||||
isErudaEl(val: any): boolean
|
||||
isDarkTheme(theme?: string): boolean
|
||||
getTheme(): string
|
||||
}
|
||||
|
||||
/**
|
||||
* Eruda APIs
|
||||
* @see https://github.com/liriliri/eruda/blob/master/doc/API.md
|
||||
* @see https://eruda.liriliri.io/docs/api.html
|
||||
*/
|
||||
export interface ErudaApis {
|
||||
/**
|
||||
|
||||
27
src/eruda.js
27
src/eruda.js
@@ -12,9 +12,12 @@ import Settings from './Settings/Settings'
|
||||
import emitter from './lib/emitter'
|
||||
import logger from './lib/logger'
|
||||
import * as util from './lib/util'
|
||||
import { isDarkTheme } from './lib/themes'
|
||||
import themes from './lib/themes'
|
||||
import isFn from 'licia/isFn'
|
||||
import isNum from 'licia/isNum'
|
||||
import isObj from 'licia/isObj'
|
||||
import each from 'licia/each'
|
||||
import isMobile from 'licia/isMobile'
|
||||
import viewportScale from 'licia/viewportScale'
|
||||
import detectBrowser from 'licia/detectBrowser'
|
||||
@@ -22,6 +25,7 @@ import $ from 'licia/$'
|
||||
import toArr from 'licia/toArr'
|
||||
import upperFirst from 'licia/upperFirst'
|
||||
import nextTick from 'licia/nextTick'
|
||||
import isEqual from 'licia/isEqual'
|
||||
import extend from 'licia/extend'
|
||||
import evalCss from './lib/evalCss'
|
||||
import chobitsu from './lib/chobitsu'
|
||||
@@ -51,7 +55,28 @@ export default {
|
||||
},
|
||||
_isInit: false,
|
||||
version: VERSION,
|
||||
util,
|
||||
util: {
|
||||
isErudaEl: util.isErudaEl,
|
||||
evalCss,
|
||||
isDarkTheme(theme) {
|
||||
if (!theme) {
|
||||
theme = this.getTheme()
|
||||
}
|
||||
return isDarkTheme(theme)
|
||||
},
|
||||
getTheme: () => {
|
||||
const curTheme = evalCss.getCurTheme()
|
||||
|
||||
let result = 'Light'
|
||||
each(themes, (theme, name) => {
|
||||
if (isEqual(theme, curTheme)) {
|
||||
result = name
|
||||
}
|
||||
})
|
||||
|
||||
return result
|
||||
},
|
||||
},
|
||||
chobitsu,
|
||||
Tool,
|
||||
Console,
|
||||
|
||||
@@ -228,7 +228,7 @@ export default {
|
||||
'#994cc3', '#aa0982', '#7d818b', '#994cc3', '#546e7a',
|
||||
'#994cc3', '#4876d6', '#4876d6', '#637777',
|
||||
]),
|
||||
'AMOLED': createDarkTheme([
|
||||
AMOLED: createDarkTheme([
|
||||
'#000000', '#8F93A2', '#FFFFFF', '#68FFAE', '#000000',
|
||||
'#41465b', '#4B526D', '#000000', '#DEFDF7', '#9CFFCF',
|
||||
'#D596FF', '#A76DF7', '#9FC5FF', '#86F3C7', '#8F93A2',
|
||||
|
||||
@@ -9,7 +9,6 @@ import root from 'licia/root'
|
||||
import toNum from 'licia/toNum'
|
||||
import trim from 'licia/trim'
|
||||
import html from 'licia/html'
|
||||
import evalCssUtil from './evalCss'
|
||||
|
||||
// https://stackoverflow.com/questions/46318395/detecting-mobile-device-notch
|
||||
export function hasSafeArea() {
|
||||
@@ -108,8 +107,6 @@ export function isChobitsuEl(el) {
|
||||
return false
|
||||
}
|
||||
|
||||
export const evalCss = evalCssUtil
|
||||
|
||||
export function classPrefix(str) {
|
||||
if (/<[^>]*>/g.test(str)) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user