Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@tokens-studio/color-picker
Advanced tools
Colorjs.io-based color picker as a reusable webcomponent
Colorjs.io color picker as a reusable Web Component.
This is a Web Component port of the VueJS picker from Colorjs.io so that it can be used in an encapsulated and reusable manner.
With NPM:
npm install @tokens-studio/color-picker
// import the Web Component class and define it yourself
import { TSColorPicker } from '@tokens-studio/color-picker';
// or optionally pre-register it and use <ts-color-picker>
import '@tokens-studio/color-picker/define';
<ts-color-picker space="hsl"></ts-color-picker>
The space attribute can be passed optionally to set the initial color space.
The following properties can be manually set as well which will cause re-renders:
name | type | default | description |
---|---|---|---|
spaceId | string | 'hsl' | The id of the color space, same type as "space" attribute for setting the initial ColorSpace |
coords | Array<number> (3) | [50, 50 ,50] | Coordinates/channels e.g. for hsl: hue, saturation, lightness |
alpha | number | 1 | Alpha channel value of the color |
precision | number | 3 | Precision for outputting the colors |
The easiest way to set the color programmatically, if you're not sure about coords
and you've only got the color as CSS string:
import Color from 'colorjs.io';
const cssString = "rgb(255, 0, 0)";
const colorPickerEl = document.querySelector('ts-color-picker');
const color = new Color(cssString);
const converted = color.to(colorPickerEl.spaceId);
colorPickerEl.coords = converted.coords;
colorPickerEl.alpha = converted.alpha * 100;
This Web Component is published to NPM as an ES Module. It's usable in any modern JavaScript context out of the box with the exception that it uses bare import specifiers, for example:
import { render } from 'lit';
By default, browsers won't know how to resolve the specifier 'lit'
, only absolute and relative paths are allowed.
This means you either need:
@rollup/plugin-node-resolve
)The easiest solution if you're not familiar with bundlers and dev servers is to create an import map e.g. using JSPM.
If you've installed this module from NPM into your local project:
npx jspm install -p nodemodules @tokens-studio/color-picker
Which creates an importmap.json
file, the contents of which you can put inside an importmap
script in your HTML:
<script type="importmap">
... import map contents here ...
</script>
Alternatively, if you don't want to install from NPM locally and would rather just consume from a CDN:
npx jspm install @tokens-studio/color-picker
0.0.1
@tokens-studio/color-picker
.FAQs
Colorjs.io-based color picker as a reusable webcomponent
The npm package @tokens-studio/color-picker receives a total of 2 weekly downloads. As such, @tokens-studio/color-picker popularity was classified as not popular.
We found that @tokens-studio/color-picker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.