diff --git a/eruda.d.ts b/eruda.d.ts index 911007c99..f32ec7dae 100644 --- a/eruda.d.ts +++ b/eruda.d.ts @@ -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 { /** diff --git a/src/eruda.js b/src/eruda.js index dacaf8503..a2dadf119 100644 --- a/src/eruda.js +++ b/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, diff --git a/src/lib/themes.js b/src/lib/themes.js index bccd41553..c0aa4693d 100644 --- a/src/lib/themes.js +++ b/src/lib/themes.js @@ -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', diff --git a/src/lib/util.js b/src/lib/util.js index 50f882c03..e0a2efb54 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -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 {