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 🙏

© 2024 – Pkg Stats / Ryan Hefner

material-color-css

v0.1.18

Published

Provides an easy way to apply Material Design dynamic color schemes to your project through CSS.

Downloads

52

Readme

基于 Material Design 动态颜色程序的 CSS 生成模块。采用实时更新 CSS 和 CSS 变量引用的方式让网页实现动态颜色变得更简单。

效果网页

开始

npm i material-color-css

将生成的 CSS 移动到根目录

windows

move "./node_modules/material-color-css/public" "."

Unix/Linux/macOS

mv "./node_modules/material-color-css/public" "."

将 CSS 写到 /public/css/style.css 并引入 index.html 或 将 /public/css/material-colors.css 直接引入你的 css 文件

使用

material-colors.css 中 CSS 变量名如下构成

--< light / dark>-< default / medium / high >-< color name>
// --模式-对比度-颜色名

如果网页没有切换深/浅模式 和 对比度 的需求,建议保持前两个参数不变,选择同一类下的颜色

具体颜色选择方法,请参考 Material Design 中 color roles一节

将变量引入 CSS 文件,即可使用

//your css
@import url("material-colors.css");

body {
    background-color: var(--token-name);
    color: var(--token-name);
  }

更新颜色

//your js
import { updateColors,updateColorFromImage } from "material-color-css"

updateColors(sourceColor, scheme)
// sourceColor 应该为 十六进制格式颜色 如 "#431104"
// scheme 为可选项, 默认为"tonalspot", 该参数是使用不同的颜色模板,作为参数时需要去除空格

updateColorFromImage(file, scheme)
//file 为图片文件

e.g.
const button = document.querySelector("button");
button.addEventListener("click", () => {
  console.log("clicked");
  updateColors("#ffffff");
});

document.querySelector("input[type='file']").addEventListener("change", (e) => {
  const file = e.target.files[0];
  updateColorFromImage(file);
});

颜色模板

共有九种不同的颜色模板,官方介绍如下,可通过网页查看效果

  • Content

    A scheme that places the source color in Scheme.primaryContainer.

    • Primary Container is the source color, adjusted for color relativity.
    • It maintains constant appearance in light mode and dark mode.
    • This adds ~5 tone in light mode, and subtracts ~5 tone in dark mode.
    • Tertiary Container is the complement to the source color, using
    • TemperatureCache. It also maintains constant appearance.
  • Expressive

    A Dynamic Color theme that is intentionally detached from the source color.

  • Fidelity

    A scheme that places the source color in Scheme.primaryContainer.

    • Primary Container is the source color, adjusted for color relativity.
    • It maintains constant appearance in light mode and dark mode.
    • This adds ~5 tone in light mode, and subtracts ~5 tone in dark mode.
    • Tertiary Container is the complement to the source color, using
    • TemperatureCache. It also maintains constant appearance.
  • Fruit salad

    A playful theme - the source color's hue does not appear in the theme.

  • Monochrome

    A Dynamic Color theme that is grayscale.

  • Neutral

    A Dynamic Color theme that is near grayscale.

  • Rainbow

    A playful theme - the source color's hue does not appear in the theme.

  • Tonal spot

    A Dynamic Color theme with low to medium colorfulness and a Tertiary

    • TonalPalette with a hue related to the source color.
    • The default Material You theme on Android 12 and 13.
  • Vibrant

    A Dynamic Color theme that maxes out colorfulness at each position in the Primary Tonal Palette.

注意

Material Design 动态颜色程序 的 NPM 包已经长时间没有更新,在使用 Rainbow 和 FruitSalad 模板时存在未定义问题,参见issue

解决方案:

// 参考 issue 修改模块中的引用 或 采用 git clone方式使用本库。

已创建依赖项分支,本模块可直接使用