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 🙏

© 2025 – Pkg Stats / Ryan Hefner

color-picker-webgl

v1.0.2

Published

基于webgl绘制的颜色选择器,无依赖项,兼容es5,小巧,高效

Downloads

7

Readme

ColorPicker-WebGl

无依赖项 这是一个基于 WebGL 的颜色选择器(高效绘制,无卡顿) 兼容ES5

ColorPicker-WebGl

安装

npm i color-picker-webgl

示例

<div>
  <p id="show-color"></p>
  <div id="black" style="width: 32px; height: 32px;"></div>
</div>
<div id="parent" style="display: flex"></div>
<script type="module">
  import ColorPicker from './index.js';
  const colorPicker = new ColorPicker();
  const parent = document.querySelector('#parent');
  const show = document.querySelector('#show-color');
  const black = document.querySelector('#black');
  colorPicker.radius = 600; // 默认半径为400px
  colorPicker.install(parent);
  const update = () => {
    const { hsb } = colorPicker
    const rgb = hsbToRgb(hsb[0], hsb[1], hsb[2])
    black.style.backgroundColor = show.textContent = `rgb(${rgb[0]},${rgb[1]},${rgb[2]})`
    requestAnimationFrame(update)
  }
  update();
  function hsbToRgb(h, s, b) {
    if (s === 0) return [255, 255, 255]
    if (b === 0) return [0, 0, 0]
    s /= 100
    b /= 100
    const rgb = new Array(3)
    for (let i = -1, o = 240; ++i < 3; o -= 120) {
      let r = 0
      const t = Math.abs(((h + o) % 360) - 240)
      if (t <= 60) r = 255
      else if (60 < t && t < 120)
        r = (1 - (t - 60) / 60) * 255
      r += (255 - r) * (1 - s)
      rgb[i] = r * b
    }
    return rgb
  }
</script>

API[实列属性和方法]

hsb

hsb属性是一个数组,包含当前颜色盘所在位置映射的 hsb 值

setUniformData(key: keyof UniformData, value: number)

设置uniform数据,包含颜色盘的明度信息和按钮大小等

install()

渲染颜色盘,本质是 requestAnimationFrame 的循环调用,事件的注册也在这里,如果是用 Vue 等框架,可以直接在组件挂载时调用 install 方法,在组件销毁时调用 uninstall 方法

uninstall()

调用 cancelAnimationFrame 停止 requestAnimationFrame 并清除事件监听