huebert 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/ColorPicker.d.ts +19 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Justin Leone
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Huebert (Yet Another Color Picker)
|
|
2
|
+
|
|
3
|
+
Huebert is a fast and minimal React color picker. It picks hex colors with optional alpha channel, and has the option to include swatches as presets.
|
|
4
|
+
|
|
5
|
+
The `perf` (Performance Mode) option makes it so that onChange does not get called while using the pointer to pick colors on the various gradient controls. Instead, onChange is only called after pointer up.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "./ColorPicker.css";
|
|
2
|
+
export interface ColorPickerProps {
|
|
3
|
+
/** The color to pick */
|
|
4
|
+
color: string;
|
|
5
|
+
/** Change handler for color */
|
|
6
|
+
onChange: (color: string) => void;
|
|
7
|
+
/** Enables alpha channel @default false */
|
|
8
|
+
alpha?: boolean;
|
|
9
|
+
/** List of color swatches. We assume they are without alpha. @default [] */
|
|
10
|
+
swatches?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Performance mode. When enabled, dragging on the either of the Saturation/Lightness,
|
|
13
|
+
* Alpha, or Hue sliders will not call onChange until the pointer is released.
|
|
14
|
+
*
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
perf?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare const ColorPicker: React.FC<ColorPickerProps>;
|
package/dist/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.Huebert{display:flex;flex-direction:column;width:230px}.Huebert .SVPicker{background:linear-gradient(to bottom,transparent,black),linear-gradient(to right,white,var(--sat-color));width:100%;height:230px}.Huebert .SVPicker div{position:relative;background:var(--opaque-color);border:2px solid #fff;border-radius:20px;width:20px;height:20px;transform:translate(-50%,-50%)}.Huebert .HuePicker{background:linear-gradient(90deg,red,#ff0,#0f0,#0ff,#00f,#f0f,red);width:100%;height:24px}.Huebert .HuePicker div{position:relative;background:var(--sat-color);border:2px solid #fff;border-radius:6px;width:6px;height:100%;top:50%;transform:translate(-50%,-50%)}.Huebert .HuebertInput{text-align:center;font-family:monospace}.Huebert .AlphaPicker{background:linear-gradient(to right,transparent,var(--opaque-color)),repeating-conic-gradient(#888 0% 25%,white 0% 50%)0 0/12px 12px;width:100%;height:24px}.Huebert .AlphaPicker div{position:relative;background:0 0;border:2px solid #fff;border-radius:6px;width:6px;height:100%;top:50%;transform:translate(-50%,-50%)}.Huebert .HuebertSwatches{display:flex;flex-wrap:wrap;justify-content:center;width:100%}.Huebert .HuebertSwatches .HuebertSwatch{border:none;border-radius:5px;width:25px;height:25px;margin:5px}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ColorPicker";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{convertHsvToRgb as S,convertRgbToHsv as D,parseHex as p,serializeHex as X,serializeHex8 as R}from"culori/fn";import{useEffect as F,useMemo as E,useState as Z}from"react";import{useRef as T}from"react";var Y=(e,t=0,g=1)=>Math.min(g,Math.max(e,t)),q=(e)=>{let t=e.currentTarget.getBoundingClientRect();return{pctX:Y((e.clientX-t.left)/t.width),pctY:Y((e.clientY-t.top)/t.height)}},v=(e)=>{let t=T(!1);return{onPointerDown:(i)=>{i.currentTarget.setPointerCapture(i.pointerId),t.current=!0,e(q(i))},onPointerMove:(i)=>{if(!t.current)return;e(q(i))},onPointerUp:(i)=>{i.currentTarget.releasePointerCapture(i.pointerId),t.current=!1}}};import{jsxDEV as H}from"react/jsx-dev-runtime";var k=({updateDrag:e,alpha:t=1})=>{let g=v(e);return H("div",{className:"AlphaPicker",...g,children:H("div",{style:{left:`${Math.round(t*100)}%`}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},J=k;import{jsxDEV as K}from"react/jsx-dev-runtime";var z=({updateDrag:e,h:t=0})=>{let g=v(e);return K("div",{className:"HuePicker",...g,children:K("div",{style:{left:`${t/3.6}%`}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},O=z;import{jsxDEV as Q}from"react/jsx-dev-runtime";var G=({updateDrag:e,s:t,v:g})=>{let m=v(e);return Q("div",{className:"SVPicker",...m,children:Q("div",{style:{left:`${Math.round(t*100)}%`,top:`${Math.round((1-g)*100)}%`}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},W=G;import{jsxDEV as P}from"react/jsx-dev-runtime";var mn=({color:e,onChange:t,swatches:g=[],alpha:m=!1,perf:y=!1})=>{let[i,r]=Z(D(p(e))),[$,I]=Z(!1),N=E(()=>m?R:X,[m]),U=(n)=>N(S(n)),u=U(i);F(()=>{if($&&y)return;let n=p(e);if(u!==N(n))r(D(n))},[u,e,$,y,N]);let M=(n)=>{if(r(n),y&&$)return;t(U(n))},_=({pctX:n,pctY:d})=>M({...i,s:n,v:1-d}),A=({pctX:n})=>M({...i,h:n*360%360}),B=({pctX:n})=>M({...i,alpha:n}),L=(n)=>{let d=p(n.currentTarget.value);if(d!==void 0){let b=D(d);M(b)}else n.currentTarget.blur(),n.currentTarget.value=u};return P("div",{className:"Huebert",style:{"--sat-color":`hsl(${i.h??0} 100% 50%)`,"--opaque-color":u.slice(0,7)},children:[P("div",{style:{display:"contents"},onPointerDownCapture:()=>I(!0),onPointerUpCapture:()=>{if(I(!1),y)t(u)},children:[P(W,{updateDrag:_,s:i.s,v:i.v},void 0,!1,void 0,this),P(O,{updateDrag:A,h:i.h},void 0,!1,void 0,this),m&&P(J,{updateDrag:B,alpha:i.alpha},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("input",{className:"HuebertInput",onBlur:L,onKeyDown:(n)=>{if(n.key==="Enter")L(n)},defaultValue:u},u,!1,void 0,this),g.length>0&&P("div",{className:"HuebertSwatches",children:g.map((n,d)=>P("button",{className:"HuebertSwatch",style:{background:n},onClick:()=>{let b=D(p(n)),f={mode:"hsv",h:i.h,s:b.s,v:b.v};if(m)f.alpha=1;if(b.v>0&&b.s>0)f.h=b.h;M(f)}},d,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};export{mn as ColorPicker};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "huebert",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"sideEffects": [
|
|
18
|
+
"*.css"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "bun build.ts"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"culori": "^4.0.2"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": ">=17",
|
|
28
|
+
"react-dom": ">=17"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/bun": "latest",
|
|
32
|
+
"@types/culori": "^4.0.1",
|
|
33
|
+
"@types/react": "^19",
|
|
34
|
+
"@types/react-dom": "^19",
|
|
35
|
+
"typescript": "^5"
|
|
36
|
+
}
|
|
37
|
+
}
|