@nild/components 0.0.55 → 0.0.56
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/dist/color-picker/Area.js +1 -1
- package/dist/color-picker/ColorPicker.js +1 -1
- package/dist/color-picker/Panel.d.ts +8 -5
- package/dist/color-picker/Panel.js +1 -1
- package/dist/color-picker/PresetGrid.js +1 -1
- package/dist/color-picker/ValueControls.js +1 -1
- package/dist/color-picker/_shared/checkerboard.d.ts +2 -5
- package/dist/color-picker/_shared/color.d.ts +8 -7
- package/dist/color-picker/_shared/color.js +1 -1
- package/dist/color-picker/hooks/useColorArea.d.ts +5 -4
- package/dist/color-picker/hooks/useColorArea.js +1 -1
- package/dist/color-picker/hooks/useColorPickerState.d.ts +9 -6
- package/dist/color-picker/hooks/useColorPickerState.js +1 -1
- package/dist/color-picker/interfaces/index.d.ts +4 -2
- package/dist/node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/hsv/convertHsvToRgb.js +1 -0
- package/dist/node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/hsv/convertRgbToHsv.js +1 -0
- package/dist/node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/hsv/definition.js +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as
|
|
1
|
+
import{jsxs as u,jsx as r}from"react/jsx-runtime";import a from"./style/index.js";const l=({controller:t,disabled:e=!1,formattedValue:o})=>{const{areaRef:s,areaSaturationStyle:n,areaStyle:i,areaThumbStyle:d,areaValueStyle:y,onKeyDown:m,onPointerDown:c}=t;return u("div",{"aria-label":"Saturation and value","aria-valuetext":o,className:a.area({disabled:e}),"data-disabled":e||void 0,onKeyDown:m,onPointerDown:c,ref:s,role:"application",style:i,tabIndex:e?-1:0,children:[r("span",{className:a.areaLayer(),style:n}),r("span",{className:a.areaLayer(),style:y}),r("span",{className:a.areaThumb(),style:d})]})};l.displayName="ColorPicker.Area";export{l as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as
|
|
1
|
+
import{jsxs as Q,jsx as r}from"react/jsx-runtime";import{useEffectCallback as t}from"@nild/hooks";import{forwardRef as W,useMemo as X,useRef as Y,useState as Z}from"react";import"@nild/shared";import $ from"../_shared/utils/register-slots/index.js";import i from"../popup/index.js";import{DEFAULT_PRESET_COLORS as ee}from"./_shared/color.js";import oe from"./DefaultTrigger.js";import ae from"./hooks/useColorArea.js";import re from"./hooks/useColorPickerState.js";import te from"./Panel.js";import{isTriggerElement as se}from"./Trigger.js";const le=$({trigger:{isMatched:se}}),C=W((g,h)=>{const{className:b,children:u,value:v,defaultValue:E,format:k,defaultFormat:D="hex",onChange:F,onFormatChange:w,presets:x=ee,size:y="medium",disabled:o=!1,placement:I="bottom-start",offset:V=8,portalClassName:N,onKeyDown:f,...R}=g,{slots:T}=X(()=>le(u),[u]),p=Y(null),[P,s]=Z(!1),l=P&&!o,{color:c,commitColor:d,css:n,draftValue:H,format:K,formattedValue:O,hex:S,hue:j,inputInvalid:q,opaqueCss:z,completeInput:L,updateFormat:M,updateHue:_,updateInput:A}=re({defaultFormat:D,defaultValue:E,format:k,onChange:F,onFormatChange:w,value:v}),B=ae({color:c,colorCss:n,disabled:o,onCommitColor:d}),m=t((e=!1)=>{var a;s(!1),e&&((a=p.current)==null||a.focus())}),U=t(()=>{o||s(!0)}),G=t(e=>{e.key==="Escape"&&(e.preventDefault(),m(!0))}),J=t(e=>{if(f?.(e),!(e.defaultPrevented||o))switch(e.key){case"Enter":case" ":e.preventDefault(),s(a=>!a);break;case"Escape":l&&(e.preventDefault(),m(!0));break}});return Q(i,{action:"click",arrowed:!1,disabled:o,offset:V,open:l,placement:I,onClose:()=>m(),onOpen:U,children:[r(i.Trigger,{children:r(oe,{...R,className:b,colorCss:n,customTrigger:T.trigger.el,disabled:o,open:l,ref:h,size:y,triggerRef:p,onKeyDown:J})}),r(i.Portal,{className:N,children:r(te,{area:B,color:c,colorCss:n,disabled:o,draftValue:H,format:K,formattedValue:O,hue:j,inputInvalid:q,opaqueColorCss:z,presets:x,selectedHex:S,onCommitColor:d,onFormatChange:M,onHueChange:_,onInputBlur:L,onInputChange:A,onKeyDown:G})})]})});C.displayName="ColorPicker";export{C as default};
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { KeyboardEventHandler } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ColorFormat, ColorPickerPreset } from './interfaces';
|
|
3
|
+
import { HsvaColor } from './_shared/color';
|
|
4
4
|
import { ColorAreaController } from './hooks/useColorArea';
|
|
5
5
|
import { CommitColor } from './hooks/useColorPickerState';
|
|
6
6
|
interface PanelProps {
|
|
7
7
|
area: ColorAreaController;
|
|
8
|
-
color:
|
|
8
|
+
color: HsvaColor;
|
|
9
|
+
colorCss: string;
|
|
9
10
|
draftValue: string;
|
|
10
11
|
format: ColorFormat;
|
|
11
12
|
formattedValue: string;
|
|
12
|
-
|
|
13
|
+
hue: number;
|
|
14
|
+
opaqueColorCss: string;
|
|
13
15
|
presets: ColorPickerPreset[];
|
|
14
16
|
selectedHex: string;
|
|
15
17
|
className?: string;
|
|
@@ -17,12 +19,13 @@ interface PanelProps {
|
|
|
17
19
|
inputInvalid?: boolean;
|
|
18
20
|
onCommitColor: CommitColor;
|
|
19
21
|
onFormatChange: (format: ColorFormat) => void;
|
|
22
|
+
onHueChange: (hue: number) => void;
|
|
20
23
|
onInputBlur: () => void;
|
|
21
24
|
onInputChange: (value: string | number) => void;
|
|
22
25
|
onKeyDown: KeyboardEventHandler<HTMLDivElement>;
|
|
23
26
|
}
|
|
24
27
|
declare const Panel: {
|
|
25
|
-
({ area, className, color, disabled, draftValue, format, formattedValue,
|
|
28
|
+
({ area, className, color, colorCss, disabled, draftValue, format, formattedValue, hue, inputInvalid, onCommitColor, onFormatChange, onHueChange, onInputBlur, onInputChange, onKeyDown, opaqueColorCss, presets, selectedHex, }: PanelProps): JSX.Element;
|
|
26
29
|
displayName: string;
|
|
27
30
|
};
|
|
28
31
|
export default Panel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as a,jsxs as o}from"react/jsx-runtime";import{cnMerge as H}from"@nild/shared";import{useMemo as S}from"react";import{getCheckerboardStyle as V}from"./_shared/checkerboard.js";import{getHueCss as j}from"./_shared/color.js";import M from"./Area.js";import P from"./PresetGrid.js";import m from"./SliderControl.js";import e from"./style/index.js";import T from"./Swatch.js";import A from"./ValueControls.js";const B=V("linear-gradient(to right, transparent, var(--nd-color-picker-alpha-color))"),d=({area:c,className:p,color:l,colorCss:t,disabled:r=!1,draftValue:u,format:h,formattedValue:C,hue:s,inputInvalid:f=!1,onCommitColor:n,onFormatChange:b,onHueChange:g,onInputBlur:k,onInputChange:v,onKeyDown:x,opaqueColorCss:i,presets:N,selectedHex:y})=>{const w=S(()=>({"--nd-color-picker-alpha-color":i}),[i]);return a("div",{"aria-label":"Color picker",className:H(p,e.panel()),onKeyDown:x,role:"dialog",tabIndex:-1,children:o("div",{className:e.stack(),children:[a(M,{controller:c,disabled:r,formattedValue:C}),o("div",{className:e.sliderPreviewRow(),children:[o("div",{className:e.sliderStack(),children:[a(m,{disabled:r,label:"Hue",max:360,min:0,step:1,trackClassName:e.hueTrack(),thumbStyle:{backgroundColor:j(s)},value:s,onChange:g}),a(m,{disabled:r,label:"Alpha",max:1,min:0,step:.01,style:w,trackClassName:e.alphaTrack(),trackStyle:B,thumbStyle:{backgroundColor:t},value:l.alpha,onChange:I=>n({...l,alpha:I})})]}),a("span",{className:e.previewSwatch(),children:a(T,{css:t})})]}),a(A,{disabled:r,draftValue:u,format:h,inputInvalid:f,onFormatChange:b,onInputBlur:k,onInputChange:v}),a(P,{disabled:r,presets:N,selectedHex:y,onCommitColor:n})]})})};d.displayName="ColorPicker.Panel";export{d as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as a,jsxs as u}from"react/jsx-runtime";import{Icon as C}from"@nild/icons";import f from"@nild/icons/CheckSmall";import{useMemo as h}from"react";import{parseColorValue as b,getColorState as x,getReadableTextColor as k}from"./_shared/color.js";import o from"./style/index.js";import v from"./Swatch.js";const c=({disabled:i=!1,onCommitColor:m,presets:t,selectedHex:n})=>{const p=h(()=>t.flatMap(e=>{const r=typeof e=="string"?e:e.value,s=b(r);if(!s)return[];const l=x(s,"hex");return{checkColor:k(s),color:s,css:l.css,hex:l.hex.toLowerCase(),label:typeof e=="string"?e:e.label??r,value:r}}),[t]),d=n.toLowerCase();return a("div",{"aria-label":"Preset colors",className:o.presets(),children:p.map(e=>{const r=e.hex===d;return u("button",{"aria-label":e.label,"aria-pressed":r,className:o.preset(),disabled:i,onClick:()=>m(e.color),type:"button",children:[a(v,{css:e.css}),r&&a("span",{"aria-hidden":"true",className:o.presetCheck(),style:{color:e.checkColor},children:a(C,{className:o.presetCheckIcon(),component:f})})]},e.value)})})};c.displayName="ColorPicker.PresetGrid";export{c as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as
|
|
1
|
+
import{jsxs as o,jsx as a}from"react/jsx-runtime";import v from"../input/index.js";import l from"../segment/index.js";import e from"./style/index.js";const n=({disabled:i=!1,draftValue:s,format:t,inputInvalid:r=!1,onFormatChange:m,onInputBlur:d,onInputChange:u})=>o("div",{className:e.inputStack(),children:[o(l,{"aria-label":"Color format",block:!0,className:e.formatSegment(),disabled:i,size:"small",value:t,onChange:m,children:[a(l.Item,{value:"hex",children:"HEX"}),a(l.Item,{value:"rgb",children:"RGB"}),a(l.Item,{value:"hsv",children:"HSV"}),a(l.Item,{value:"hsl",children:"HSL"})]}),a(v,{"aria-invalid":r||void 0,"aria-label":"Color value",className:e.valueInput({invalid:r}),disabled:i,size:"small",value:s,onBlur:d,onChange:u})]});n.displayName="ColorPicker.ValueControls";export{n as default};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type CheckerboardStyle =
|
|
3
|
-
'--nd-color-picker-checker-base'?: string;
|
|
4
|
-
'--nd-color-picker-checker-color'?: string;
|
|
5
|
-
};
|
|
1
|
+
import { CSSPropertiesWithVars } from '@nild/shared';
|
|
2
|
+
export type CheckerboardStyle = CSSPropertiesWithVars;
|
|
6
3
|
export declare const CHECKERBOARD_STYLE: CheckerboardStyle;
|
|
7
4
|
export declare const getCheckerboardStyle: (overlayImage?: string) => CheckerboardStyle;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { ColorFormat, ColorPickerMeta } from '../interfaces';
|
|
2
|
-
export interface
|
|
2
|
+
export interface HsvaColor {
|
|
3
3
|
h: number;
|
|
4
4
|
s: number;
|
|
5
|
-
|
|
5
|
+
v: number;
|
|
6
6
|
alpha: number;
|
|
7
7
|
}
|
|
8
8
|
export interface ColorState {
|
|
9
|
+
css: string;
|
|
9
10
|
formattedValue: string;
|
|
10
11
|
hex: string;
|
|
11
12
|
meta: ColorPickerMeta;
|
|
13
|
+
opaqueCss: string;
|
|
12
14
|
}
|
|
13
15
|
export declare const normalizeHue: (hue: number | undefined) => number;
|
|
14
16
|
export declare const createHexColor: (r: number, g: number, b: number, alpha?: number) => string;
|
|
@@ -16,9 +18,8 @@ export declare const DEFAULT_COLOR: string;
|
|
|
16
18
|
export declare const DEFAULT_PRESET_COLORS: string[];
|
|
17
19
|
export declare const BLACK_COLOR: string;
|
|
18
20
|
export declare const WHITE_COLOR: string;
|
|
19
|
-
export declare const parseColorValue: (value: string | undefined) =>
|
|
20
|
-
export declare const normalizeColor: (color:
|
|
21
|
+
export declare const parseColorValue: (value: string | undefined) => HsvaColor | undefined;
|
|
22
|
+
export declare const normalizeColor: (color: HsvaColor) => HsvaColor;
|
|
21
23
|
export declare const getHueCss: (hue: number) => string;
|
|
22
|
-
export declare const
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const getColorState: (color: HslaColor, format: ColorFormat) => ColorState;
|
|
24
|
+
export declare const getReadableTextColor: (color: HsvaColor) => string;
|
|
25
|
+
export declare const getColorState: (color: HsvaColor, format: ColorFormat) => ColorState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useMode as
|
|
1
|
+
import{useMode as M}from"../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/modes.js";import O from"../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/converter.js";import{formatHex8 as z,formatHex as A}from"../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/formatter.js";import F from"../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/rgb/definition.js";import B from"../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/hsl/definition.js";import D from"../../node_modules/.pnpm/culori@4.0.2/node_modules/culori/src/hsv/definition.js";const U="#";M(F),M(B),M(D);const E=O("rgb"),W=O("hsv"),q=O("hsl"),I=160,v=(a,r,o)=>Math.min(Math.max(a,r),o),t=(a,r=0)=>v(a??r,0,1),c=a=>a===void 0||Number.isNaN(a)?0:(a%360+360)%360,C=a=>v(Math.round(a),0,255).toString(16).padStart(2,"0"),m=(a,r=2)=>Number(a.toFixed(r)),l=(a,r=2)=>`${m(a,r)}`,K=a=>({r:v(Math.round(a.r*255),0,255),g:v(Math.round(a.g*255),0,255),b:v(Math.round(a.b*255),0,255)}),H=a=>{const r=a?.trim();if(!r)return;const o=r.endsWith("%"),s=Number(o?r.slice(0,-1):r);if(!Number.isNaN(s))return o||Math.abs(s)>1?s/100:s},P=a=>H(a)??1,k=a=>a.includes(",")?a.split(",").map(r=>r.trim()):a.split(/\s+/u).filter(Boolean),y=a=>{const r=/^hsva?\((.*)\)$/iu.exec(a);if(!r)return;const[o,s]=r[1].split("/").map(p=>p.trim()),[e,N,x,g]=k(o),$=Number(e?.replace(/deg$/iu,"")),n=H(N),i=H(x),u=P(s??g);if(!(Number.isNaN($)||n===void 0||i===void 0))return L({alpha:u,h:$,s:n,v:i})},Q=a=>E({mode:"hsv",h:a.h,s:a.s,v:a.v,alpha:a.alpha}),b=(a,r,o,s=1)=>{const e=`${U}${C(a)}${C(r)}${C(o)}`;return s<1?`${e}${C(s*255)}`:e},X=b(22,119,255),j=[[22,119,255],[19,194,194],[82,196,26],[250,173,20],[245,34,45],[114,46,209],[0,0,0],[255,255,255]].map(([a,r,o])=>b(a,r,o)),S=b(0,0,0),T=b(255,255,255),w=a=>{const r=a?.trim();if(!r)return;const o=y(r);if(o)return o;const s=E(r),e=W(r);if(!(!s||!e))return{h:c(e.h),s:t(e.s),v:t(e.v),alpha:t(e.alpha??s.alpha,1)}},L=a=>({h:c(a.h),s:t(a.s),v:t(a.v),alpha:t(a.alpha,1)}),V=a=>{const r=L(a);return{...K(Q(r)),normalizedColor:r}},_=({r:a,g:r,b:o},s=1)=>s<1?`rgba(${a}, ${r}, ${o}, ${l(s)})`:`rgb(${a}, ${r}, ${o})`,G=({r:a,g:r,b:o},s)=>{const e={mode:"rgb",r:a/255,g:r/255,b:o/255,alpha:s};return s<1?z(e):A(e)},J=a=>`hsl(${l(c(a))} 100% 50%)`,Y=a=>{const{r,g:o,b:s}=V({...a,alpha:1});return(r*299+o*587+s*114)/1e3>=I?S:T},Z=(a,r)=>{const{normalizedColor:o,...s}=V(a),{r:e,g:N,b:x}=s,g=o.alpha<1,$=l(o.alpha),n=_(s,o.alpha),i=G(s,o.alpha),u={css:n,hex:i,opaqueCss:_(s)},p={alpha:m(o.alpha),css:n,valid:!0};if(r==="rgb")return{...u,formattedValue:n,meta:{...p,b:x,format:r,g:N,r:e}};if(r==="hsv"){const h=l(o.h),d=l(o.s*100),f=l(o.v*100);return{...u,formattedValue:g?`hsva(${h}, ${d}%, ${f}%, ${$})`:`hsv(${h}, ${d}%, ${f}%)`,meta:{...p,format:r,h:m(o.h),s:m(o.s*100),v:m(o.v*100)}}}if(r==="hsl"){const h=q({mode:"hsv",h:o.h,s:o.s,v:o.v,alpha:o.alpha}),d=l(c(h.h??o.h)),f=l(t(h.s)*100),R=l(t(h.l)*100);return{...u,formattedValue:g?`hsla(${d}, ${f}%, ${R}%, ${$})`:`hsl(${d}, ${f}%, ${R}%)`,meta:{...p,format:r,h:m(o.h),l:m(t(h.l)*100),s:m(t(h.s)*100)}}}return{...u,formattedValue:i,meta:{...p,format:r,hex:i}}};export{S as BLACK_COLOR,X as DEFAULT_COLOR,j as DEFAULT_PRESET_COLORS,T as WHITE_COLOR,b as createHexColor,Z as getColorState,J as getHueCss,Y as getReadableTextColor,L as normalizeColor,c as normalizeHue,w as parseColorValue};
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { CSSProperties, KeyboardEvent, PointerEvent as ReactPointerEvent, RefObject } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { HsvaColor } from '../_shared/color';
|
|
3
3
|
import { CommitColor } from './useColorPickerState';
|
|
4
4
|
interface UseColorAreaOptions {
|
|
5
|
-
color:
|
|
5
|
+
color: HsvaColor;
|
|
6
|
+
colorCss: string;
|
|
6
7
|
disabled?: boolean;
|
|
7
8
|
onCommitColor: CommitColor;
|
|
8
9
|
}
|
|
9
10
|
export interface ColorAreaController {
|
|
10
|
-
areaLightnessStyle: CSSProperties;
|
|
11
11
|
areaRef: RefObject<HTMLDivElement>;
|
|
12
12
|
areaSaturationStyle: CSSProperties;
|
|
13
13
|
areaStyle: CSSProperties;
|
|
14
14
|
areaThumbStyle: CSSProperties;
|
|
15
|
+
areaValueStyle: CSSProperties;
|
|
15
16
|
onKeyDown: (evt: KeyboardEvent<HTMLDivElement>) => void;
|
|
16
17
|
onPointerDown: (evt: ReactPointerEvent<HTMLDivElement>) => void;
|
|
17
18
|
}
|
|
18
|
-
declare const useColorArea: ({ color, disabled, onCommitColor }: UseColorAreaOptions) => ColorAreaController;
|
|
19
|
+
declare const useColorArea: ({ color, colorCss, disabled, onCommitColor, }: UseColorAreaOptions) => ColorAreaController;
|
|
19
20
|
export default useColorArea;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffectCallback as
|
|
1
|
+
import{useEffectCallback as l,useEventListener as d}from"@nild/hooks";import{useRef as R,useState as S,useMemo as m}from"react";import{normalizeColor as b,getHueCss as A,BLACK_COLOR as L,WHITE_COLOR as E}from"../_shared/color.js";const T=(r,u,o)=>{const n=u.getBoundingClientRect(),i=n.width<=0?0:(r.clientX-n.left)/n.width,s=n.height<=0?0:(r.clientY-n.top)/n.height;return b({...o,s:i,v:1-s})},I={backgroundImage:`linear-gradient(to top, ${L}, transparent)`},O={backgroundImage:`linear-gradient(to right, ${E}, transparent)`},$=({color:r,colorCss:u,disabled:o=!1,onCommitColor:n})=>{var i;const s=R(null),[c,g]=S(!1),f=l(e=>{const a=s.current;if(!a||o)return r;const t=T(e,a,r);return n(t),t}),h=l(e=>{var a,t;o||e.button!==void 0&&e.button!==0||(e.preventDefault(),e.currentTarget.focus(),(t=(a=e.currentTarget).setPointerCapture)==null||t.call(a,e.pointerId),g(!0),f(e))}),C=l(e=>{c&&(e.preventDefault(),f(e))}),v=l(e=>{c&&(e.preventDefault(),f(e),g(!1))}),k=l(e=>{if(o)return;const a=e.shiftKey?.1:.01;let t;switch(e.key){case"ArrowRight":t={...r,s:r.s+a};break;case"ArrowLeft":t={...r,s:r.s-a};break;case"ArrowUp":t={...r,v:r.v+a};break;case"ArrowDown":t={...r,v:r.v-a};break;case"Home":t={...r,s:0};break;case"End":t={...r,s:1};break}t&&(e.preventDefault(),n(b(t)))}),w=m(()=>({backgroundColor:A(r.h)}),[r.h]),D=m(()=>({backgroundColor:u,left:`${r.s*100}%`,top:`${(1-r.v)*100}%`}),[r.s,r.v,u]),y=((i=s.current)==null?void 0:i.ownerDocument.defaultView)??null,p=c?y:null;return d(p,"pointermove",C),d(p,"pointerup",v),d(p,"pointercancel",v),{areaRef:s,areaSaturationStyle:O,areaStyle:w,areaThumbStyle:D,areaValueStyle:I,onKeyDown:k,onPointerDown:h}};export{$ as default};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ColorState,
|
|
2
|
-
import { ColorFormat,
|
|
3
|
-
export type CommitColor = (nextColor:
|
|
1
|
+
import { ColorState, HsvaColor } from '../_shared/color';
|
|
2
|
+
import { ColorFormat, ColorPickerProps } from '../interfaces';
|
|
3
|
+
export type CommitColor = (nextColor: HsvaColor, nextFormat?: ColorFormat) => ColorState;
|
|
4
4
|
interface UseColorPickerStateOptions {
|
|
5
5
|
value?: string;
|
|
6
6
|
defaultValue?: string;
|
|
@@ -9,17 +9,20 @@ interface UseColorPickerStateOptions {
|
|
|
9
9
|
onChange?: ColorPickerProps['onChange'];
|
|
10
10
|
onFormatChange?: ColorPickerProps['onFormatChange'];
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
color:
|
|
12
|
+
interface ColorPickerStateController {
|
|
13
|
+
color: HsvaColor;
|
|
14
14
|
commitColor: CommitColor;
|
|
15
|
+
css: string;
|
|
15
16
|
draftValue: string;
|
|
16
17
|
format: ColorFormat;
|
|
17
18
|
formattedValue: string;
|
|
18
19
|
hex: string;
|
|
20
|
+
hue: number;
|
|
19
21
|
inputInvalid: boolean;
|
|
20
|
-
|
|
22
|
+
opaqueCss: string;
|
|
21
23
|
completeInput: () => void;
|
|
22
24
|
updateFormat: (format: ColorFormat) => void;
|
|
25
|
+
updateHue: (hue: number) => void;
|
|
23
26
|
updateInput: (value: string | number) => void;
|
|
24
27
|
}
|
|
25
28
|
declare const useColorPickerState: ({ value: externalValue, defaultValue, format: externalFormat, defaultFormat, onChange, onFormatChange, }: UseColorPickerStateOptions) => ColorPickerStateController;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useControllableState as
|
|
1
|
+
import{useControllableState as O,useEffectCallback as f,useIsomorphicLayoutEffect as b}from"@nild/hooks";import{useState as h,useMemo as G,useRef as S}from"react";import{parseColorValue as C,getColorState as g,normalizeColor as J,normalizeHue as q,DEFAULT_COLOR as K}from"../_shared/color.js";const N=C(K),z=i=>C(i)??N,P=({value:i,defaultValue:R,format:v,defaultFormat:y="hex",onChange:x,onFormatChange:I})=>{const[l,A]=O(v,y),[n,D]=O(i,R),H=i!==void 0,[t,j]=h(()=>z(n)),{css:M,formattedValue:a,hex:T,opaqueCss:U}=G(()=>g(t,l),[t,l]),[V,E]=h(t.h),[F,d]=h(a),[_,s]=h(!1),c=S(null),p=S(null),m=f((e,r=l)=>{const u=J(e),o=g(u,r),L=!Object.is(n,o.formattedValue);return(!H||!L)&&j(u),L?(p.current=[o.formattedValue,u],D(o.formattedValue),x?.(o.formattedValue,o.meta)):p.current=null,o}),$=f(e=>{Object.is(l,e)||(A(e),I?.(e),c.current=null,m(t,e))}),k=f(e=>{E(e),m({...t,h:e})}),w=f(e=>{const r=`${e}`,u=C(r);if(d(r),!u){s(!0);return}s(!1),c.current=m(u).formattedValue}),B=f(()=>{c.current=null;const e=C(F);if(!e){d(a),s(!1);return}const r=m(e);d(r.formattedValue),s(!1)});return b(()=>{const e=p.current;p.current=null,j(e&&Object.is(n,e[0])?e[1]:z(n))},[n]),b(()=>{q(V)!==q(t.h)&&E(t.h)},[t.h,V]),b(()=>{if(c.current===a){c.current=null;return}d(a),s(!1)},[a]),{color:t,commitColor:m,css:M,draftValue:F,format:l,formattedValue:a,hex:T,hue:V,inputInvalid:_,opaqueCss:U,completeInput:B,updateFormat:$,updateHue:k,updateInput:w}};export{P as default};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OffsetOptions, Placement } from '@floating-ui/dom';
|
|
2
2
|
import { ButtonHTMLAttributes, HTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
3
|
-
export type ColorFormat = 'hex' | 'rgb' | 'hsl';
|
|
3
|
+
export type ColorFormat = 'hex' | 'rgb' | 'hsv' | 'hsl';
|
|
4
4
|
export type ColorPickerSize = 'small' | 'medium' | 'large';
|
|
5
5
|
|
|
6
6
|
export type ColorPickerMeta<T extends ColorFormat = ColorFormat> = T extends ColorFormat
|
|
@@ -13,7 +13,9 @@ export type ColorPickerMeta<T extends ColorFormat = ColorFormat> = T extends Col
|
|
|
13
13
|
? { hex: string }
|
|
14
14
|
: T extends 'rgb'
|
|
15
15
|
? { r: number; g: number; b: number }
|
|
16
|
-
:
|
|
16
|
+
: T extends 'hsv'
|
|
17
|
+
? { h: number; s: number; v: number }
|
|
18
|
+
: { h: number; s: number; l: number })
|
|
17
19
|
: never;
|
|
18
20
|
|
|
19
21
|
export type ColorPickerPreset = string | { label?: string; value: string };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import g from"../util/normalizeHue.js";function i({h:s,s:b,v:a,alpha:c}){s=g(s!==void 0?s:0),b===void 0&&(b=0),a===void 0&&(a=0);let t=Math.abs(s/60%2-1),o;switch(Math.floor(s/60)){case 0:o={r:a,g:a*(1-b*t),b:a*(1-b)};break;case 1:o={r:a*(1-b*t),g:a,b:a*(1-b)};break;case 2:o={r:a*(1-b),g:a,b:a*(1-b*t)};break;case 3:o={r:a*(1-b),g:a*(1-b*t),b:a};break;case 4:o={r:a*(1-b*t),g:a*(1-b),b:a};break;case 5:o={r:a,g:a*(1-b),b:a*(1-b*t)};break;default:o={r:a*(1-b),g:a*(1-b),b:a*(1-b)}}return o.mode="rgb",c!==void 0&&(o.alpha=c),o}export{i as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function l({r:d,g:t,b:o,alpha:v}){d===void 0&&(d=0),t===void 0&&(t=0),o===void 0&&(o=0);let a=Math.max(d,t,o),e=Math.min(d,t,o),h={mode:"hsv",s:a===0?0:1-e/a,v:a};return a-e!==0&&(h.h=(a===d?(t-o)/(a-e)+(t<o)*6:a===t?(o-d)/(a-e)+2:(d-t)/(a-e)+4)*60),v!==void 0&&(h.alpha=v),h}export{l as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"./convertHsvToRgb.js";import a from"./convertRgbToHsv.js";import{fixupHueShorter as o}from"../fixup/hue.js";import{fixupAlpha as i}from"../fixup/alpha.js";import{interpolatorLinear as r}from"../interpolate/linear.js";import{differenceHueSaturation as t}from"../difference.js";import{averageAngle as f}from"../average.js";const p={mode:"hsv",toMode:{rgb:e},parse:["--hsv"],serialize:"--hsv",fromMode:{rgb:a},channels:["h","s","v","alpha"],ranges:{h:[0,360]},gamut:"rgb",interpolate:{h:{use:r,fixup:o},s:r,v:r,alpha:{use:r,fixup:i}},difference:{h:t},average:{h:f}};export{p as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nild/components",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.56",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"react": "^18.2.0",
|
|
34
34
|
"react-dom": "^18.2.0",
|
|
35
35
|
"@nild/shared": "^0.0.18",
|
|
36
|
-
"@nild/
|
|
37
|
-
"@nild/
|
|
36
|
+
"@nild/icons": "^0.0.21",
|
|
37
|
+
"@nild/hooks": "^0.0.21"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "vite build --mode PROD",
|