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

theme-color-switch

v1.3.1

Published

This a script to switch color specific styles less file and which you can use to change theme dynamically in browser

Downloads

8

Readme

theme-color-switch

This a script to switch color specific styles less file and which you can use to change theme dynamically in browser.

Also you can use these less syntax functions for color conversion.

Install

$ npm install theme-color-switch

Demo

Try out the demo

Example:

const less = require('theme-color-switch');
const colorSource = require('!raw-loader!./public/color.less'); // theme file content which generate by theme-color-generator
less.render(
   colorSource,
   {
       modifyVars: {
           '@theme-color': '#0035ff' // the variables in theme file which you want to change
       },
   },
   function(e, output) {
      if (e) {
          console.error(`Failed to update theme`);
      }
      if (output && output.css) {
          addCSS(output.css);
      }
   }
);

Note: You need to generate color.less file with theme-color-generator ( as color.js in example ) first, then toggle color with this package as Theme.js in example

Now you can change colors by modify less avriables as the example

如只想使用主题切换的,上面的内容就已完成。

颜色函数:想要用js执行less颜色函数实时转化颜色的,请往下看(详细说明请访问less官网)。

  1. 返回Color对象的可以使用toCSS()属性来获取输出值。也可以作为下一个函数的颜色参数。
  2. 返回Dimension对象的可以作为number类型传给下一个函数。

使用示例

import { shade, tint, fade } from 'theme-color-switch';

let shadeColor = shade('#007fff', '50%').toCSS();
let fadeAndTintColor = fade(tint('#007fff', '30%'), '10%').toCSS();

颜色定义函数

rgb

Returns: Color
Example: rgb(90, 129, 32)
Output: #5a8120

rgba

Returns: Color
Example: rgba(90, 129, 32, 0.5)
Output: rgba(90, 129, 32, 0.5)

argb

Returns: Color
Example: argb(rgba(90, 23, 148, 0.5))
Output: #805a1794

hsl

Returns: Color
Example: hsl(90, 100%, 50%)
Output: #80ff00

hsla

Returns: Color
Example: hsla(90, 100%, 50%, 0.5)
Output: rgba(128, 255, 0, 0.5)

hsv

Returns: Color
Example: hsv(90, 100%, 50%)
Output: #408000

hsva

Returns: Color
Example: hsva(90, 100%, 50%, 0.5)
Output: rgba(64, 128, 0, 0.5)

颜色通道函数

hue

Returns: Dimension
Example: hue(hsl(90, 100%, 50%))
Output: 90

saturation

Returns: Dimension
Example: saturation(hsl(90, 100%, 50%))
Output: 100%

lightness

Returns: Dimension
Example: lightness(hsl(90, 100%, 50%))
Output: 50%

hsvhue

Returns: Dimension
Example: hsvhue(hsv(90, 100%, 50%))
Output: 90

hsvsaturation

Returns: Dimension
Example: hsvsaturation(hsv(90, 100%, 50%))
Output: 100%

hsvvalue

Returns: Dimension
Example: hsvhue(hsv(90, 100%, 50%))
Output: 90

red

Returns: Dimension
Example: red(rgb(10, 20, 30))
Output: 10

green

Returns: Dimension
Example: green(rgb(10, 20, 30))
Output: 20

blue

Returns: Dimension
Example: blue(rgb(10, 20, 30))
Output: 30

alpha

Returns: Dimension
Example: alpha(rgba(10, 20, 30, 0.5))
Output: 0.5

luma

Returns: Dimension
Example: luma(rgb(100, 200, 30))
Output: 44%

luminance

Returns: Dimension
Example: luminance(rgb(100, 200, 30))
Output: 65%

颜色操作函数

saturate

Returns: Color
Example: saturate(#80e619, 20%)
Output: #80ff00

desaturate

Returns: Color
Example: desaturate(#80e619, 20%)
Output: #80cd32

lighten

Returns: Color
Example: lighten(#80e619, 20%)
Output: #b3f075

darken

Returns: Color
Example: darken(#80e619, 20%)
Output: #4d8a0f

fadein

Returns: Color
Example: fadein(rgba(128, 242, 13, 0.5), 10%)
Output: rgba(128, 242, 13, 0.6)

fadeout

Returns: Color
Example: fadeout(rgba(128, 242, 13, 0.5), 10%)
Output: rgba(128, 242, 13, 0.4)

fade

Returns: Color
Example: fade(#80f20d, 10%)
Output: rgba(128, 242, 13, 0.1)

spin

Returns: Color
Example: spin(#f2330d, 30)
Output: #f2a60d

mix

Returns: Color
Example: mix(#ff0000, #0000ff, 50%)
Output: #800080

tint

Returns: Color
Example: tint(#007fff, 50%)
Output: #80bfff

shade

Returns: Color
Example: shade(#007fff, 50%)
Output: #004080

greyscale

Returns: Color
Example: greyscale(#80f20d)
Output: #808080

contrast

Returns: Color
Example:

p {
    a: contrast(#bbbbbb);
    b: contrast(#222222, #101010);
    c: contrast(#222222, #101010, #dddddd);
    d: contrast(hsl(90, 100%, 50%), #000000, #ffffff, 30%);
    e: contrast(hsl(90, 100%, 50%), #000000, #ffffff, 80%);
}

Output:

p {
    a: #000000 // black
    b: #ffffff // white
    c: #dddddd
    d: #000000 // black
    e: #ffffff // white
}

颜色转换函数

color

Returns: Color
Example | Output
:--|:--
color('#5a8120') | #5a8120
color('rgb(90, 129, 32)') | #5a8120
color('rgba(90, 129, 32, 0.5)') | rgba(90, 129, 32, 0.5)