npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

layui-theme-dark

v2.10.0

Published

layui 深色主题

Readme

layui-theme-dark

Github | Demo

layui 深色主题

使用

dist 文件夹中的 layui-theme-dark-selector.css 添加到 layui 样式之后,通过改变 HTML 标签的类名切换主题

/** JavaScript */
// 设置为深色主题
document.documentElement.classList.add('dark')
// 恢复浅色主题
document.documentElement.classList.remove('dark')
// 切换深/浅色主题
document.documentElement.classList.toggle('dark')
<!-- HTML -->
<!--light-->
<html> ... </html>

<!--dark-->
<html class="dark"> ... </html>

CDN

<link rel="stylesheet" href="https://unpkg.com/layui-theme-dark/dist/layui-theme-dark-selector.css">
var darkThemeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');

darkThemeMediaQuery.addEventListener(function(e){
  if(e.matches) {
    document.documentElement.classList.add('dark')
  }else{
    document.documentElement.classList.remove('dark')
  }
});
var APPERANCE_KEY = 'layui-theme-mode-prefer-dark'

var savedPreferDark = localStorage.getItem(APPERANCE_KEY)

if(
  savedPreferDark === 'true' ||
  (!savedPreferDark && window.matchMedia('(prefers-color-scheme: dark)').matches)
){
  document.documentElement.classList.add('dark')
}

document.querySelector('#toggle-dark').addEventListener('click', function(){
  var cls = document.documentElement.classList;
  cls.toggle('dark');
  localStorage.setItem(APPERANCE_KEY, String(cls.contains('dark')))
})

第三方模块

对一些使用广泛的第三方模块行了支持,存放在 ext 目录,默认未集成

构建

  • 拉取代码
git clone https://github.com/Sight-wcg/layui-theme-dark.git
  • 安装依赖
cd layui-theme-dark

npm install
  • 运行
npm run dev
  • 构建
npm run build

浏览器支持

Chrome 43+ Edge 16+ Firefox 31+ Safari 10+

常见问题

  • 方案一:将切换主题的代码放在 <head> 标签中(推荐)

    <script>
    (function(){
      window.APPERANCE_KEY = 'theme-mode'
      var headTagEl = document.getElementsByTagName('head')
      var linkTagEl = document.createElement('link')
      var savedPreferTheme= localStorage.getItem(APPERANCE_KEY)
    
      if(savedPreferTheme === 'dark'){
        linkTagEl.href = '' // 这里写文件链接
        linkTagEl.rel='stylesheet'
        linkTagEl.id='layui_theme_css'
        headTagEl[0].appendChild(linkTagEl)
        document.documentElement.className += ' dark'
      }
    })();
    </script>
  • 方案二:创建 iframe 时,使用 display:none 隐藏 iframe 元素, 然后在 iframe 的 onload 事件回调中更改 display 属性为 display:block

    <iframe onload="this.style.display='block';" style="display:none;" >

    iframe 类型的 Admin 模板中的子页面,通过切换 href 属性动态引入样式文件会更方便,参考以下代码:layui-theme-dark/commit/8b36a8

  • 方案一:增加透明度,适用于简单图片和纯色背景

    .dark body img {
       opacity: 0.8;
    }
  • 方案二:叠加一个灰色半透明的层,适用于背景图,非纯色背景等

    .dark body .dark-mode-image-overlay {
      position: relative;
    }
    
    .daek body .dark-mode-image-overlay::before {
      content: '';
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(50, 50, 50, 0.5);
    }

根据使用后的效果、适配成本和难度酌情使用

一些可能有用的链接

许可证

MIT © 2023-present morning-star