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

textcolor

v1.0.2

Published

JavaScript library for find the font color according to the background color

Downloads

106

Readme

TEXTColor.js

我把该函数封装起来了,你可以通过npm install或者引入github目录下的textcolor.js使用。

效果

使用场景

自定义主题色时,往往会遇到一个问题就是背景色可能会和文字的颜色重叠。

安装

方法一:通过npm引入

npm install textcolor --save

方法二:通过<script>引入

<script type="type/javascript" src="https://unpkg.com/[email protected]/textcolor.js" ></script>

用法

import TEXTColor from 'textcolor-js'

let hex = '#000000';        // or '#666' or 'rgb(12,34,56)'
let textcolor = TEXTColor.findTextColor(hex);
console.log(textcolor)      // #ffffff

参考example目录下的demo.html

引入TEXTColor.js后,可以根据TEXTColor.colorRgb方法,传入十六进制色值hex(如:#555、#123456)或者rgb(12,34,56)使用,返回相应的文字色值textcolor

为了方便更直观的察觉背景色变化对文字的影响,我在demo.html内引入了颜色选择器colorpicker.js。可以下载该案例查看背景色的改变对文字改变的影响。

JavaScript:

var textDom = document.getElementById('color-text');
var obj = document.getElementById("picker");
var a = Colorpicker.create({
    el: "color-picker",
    color: "#0081ff",
    change: function (elem, hex) {
        >textDom.style.color = TEXTColor.findTextColor(hex);
        elem.style.backgroundColor = hex;
    }
})

HTML:

<div class="container">
    <h2>点击下方选择颜色</h2>
    <div class="picker" id="color-picker">
        <div id="color-text">文字颜色</div>
    </div>
</div>