@studiotoolkit/color-wheel 1.0.2 → 1.0.3

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.
@@ -30,6 +30,6 @@ interface ColorWheelProps {
30
30
  width?: number;
31
31
  height?: number;
32
32
  }
33
- export default function ColorWheel({ onColorsChange, harmonyMode: propHarmonyMode, saturation: propSaturation, brightness: propBrightness, circleRadius: propCircleRadius, wheelThickness: propWheelThickness, dotSize: propDotSize, dotPosition: propDotPosition, handleThickness: propHandleThickness, handleColor: propHandleColor, harmonyPolygon: propHarmonyPolygon, polygonColor: propPolygonColor, polygonThickness: propPolygonThickness, centerDot: propCenterDot, showCenterDot: propShowCenterDot, borderColor: propBorderColor, canvasBackgroundColor: propCanvasBackgroundColor, width, height, }: ColorWheelProps): import("react/jsx-runtime").JSX.Element;
33
+ export default function ColorWheel({ onColorsChange, harmonyMode: propHarmonyMode, saturation: propSaturation, brightness: propBrightness, circleRadius: propCircleRadius, wheelThickness: propWheelThickness, dotSize: propDotSize, dotPosition: propDotPosition, handleThickness: propHandleThickness, handleColor: propHandleColor, harmonyPolygon: propHarmonyPolygon, polygonColor: propPolygonColor, polygonThickness: propPolygonThickness, centerDot: propCenterDot, showCenterDot: propShowCenterDot, borderColor: propBorderColor, canvasBackgroundColor: propCanvasBackgroundColor, width, height, }: ColorWheelProps): import("react").JSX.Element;
34
34
  export {};
35
35
  //# sourceMappingURL=ColorWheel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ColorWheel.d.ts","sourceRoot":"","sources":["../src/ColorWheel.tsx"],"names":[],"mappings":"AACA,OAAO,kBAAkB,CAAC;AAG1B,KAAK,WAAW,GACZ,eAAe,GACf,WAAW,GACX,eAAe,GACf,OAAO,GACP,SAAS,GACT,QAAQ,GACR,QAAQ,CAAC;AACb,KAAK,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;AAEhD,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACzB;AAUD,UAAU,eAAe;IACvB,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;IAClD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAwHD,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,cAAc,EACd,WAAW,EAAE,eAAe,EAC5B,UAAU,EAAE,cAAc,EAC1B,UAAU,EAAE,cAAc,EAC1B,YAAY,EAAE,gBAAgB,EAC9B,cAAc,EAAE,kBAAkB,EAClC,OAAO,EAAE,WAAW,EACpB,WAAW,EAAE,eAAe,EAC5B,eAAe,EAAE,mBAAmB,EACpC,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,kBAAkB,EAClC,YAAY,EAAE,gBAAgB,EAC9B,gBAAgB,EAAE,oBAAoB,EACtC,SAAS,EAAE,aAAa,EACxB,aAAa,EAAE,iBAAyB,EACxC,WAAW,EAAE,eAA2B,EACxC,qBAAqB,EAAE,yBAAyC,EAChE,KAAW,EACX,MAAY,GACb,EAAE,eAAe,2CAuejB"}
1
+ {"version":3,"file":"ColorWheel.d.ts","sourceRoot":"","sources":["../src/ColorWheel.tsx"],"names":[],"mappings":"AACA,OAAO,kBAAkB,CAAC;AAG1B,KAAK,WAAW,GACZ,eAAe,GACf,WAAW,GACX,eAAe,GACf,OAAO,GACP,SAAS,GACT,QAAQ,GACR,QAAQ,CAAC;AACb,KAAK,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;AAEhD,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACzB;AAUD,UAAU,eAAe;IACvB,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;IAClD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAwHD,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,cAAc,EACd,WAAW,EAAE,eAAe,EAC5B,UAAU,EAAE,cAAc,EAC1B,UAAU,EAAE,cAAc,EAC1B,YAAY,EAAE,gBAAgB,EAC9B,cAAc,EAAE,kBAAkB,EAClC,OAAO,EAAE,WAAW,EACpB,WAAW,EAAE,eAAe,EAC5B,eAAe,EAAE,mBAAmB,EACpC,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,kBAAkB,EAClC,YAAY,EAAE,gBAAgB,EAC9B,gBAAgB,EAAE,oBAAoB,EACtC,SAAS,EAAE,aAAa,EACxB,aAAa,EAAE,iBAAyB,EACxC,WAAW,EAAE,eAA2B,EACxC,qBAAqB,EAAE,yBAAyC,EAChE,KAAW,EACX,MAAY,GACb,EAAE,eAAe,+BAuejB"}
@@ -5,7 +5,7 @@ interface ThemeContextType {
5
5
  }
6
6
  export declare function ThemeProvider({ children }: {
7
7
  children: ReactNode;
8
- }): import("react/jsx-runtime").JSX.Element;
8
+ }): import("react").JSX.Element;
9
9
  export declare function useTheme(): ThemeContextType;
10
10
  export {};
11
11
  //# sourceMappingURL=ThemeContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../src/ThemeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvF,UAAU,gBAAgB;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,KAAK,IAAI,CAAC;CAChE;AAOD,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CASlE;AAED,wBAAgB,QAAQ,qBAEvB"}
1
+ {"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../src/ThemeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvF,UAAU,gBAAgB;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,KAAK,IAAI,CAAC;CAChE;AAOD,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,+BASlE;AAED,wBAAgB,QAAQ,qBAEvB"}
@@ -0,0 +1,2 @@
1
+ .color-wheel-container{background-color:#fff;margin:0;font-family:sans-serif}[data-theme=dark] .color-wheel-container{background-color:#1a1a1a!important}.color-wheel-container h2{text-align:center;color:#fff;background:#222;margin:0;padding:15px}.layout{grid-template-columns:20% 30% 50%;height:100vh;display:grid}.panel{background-color:#fff;border-right:1px solid #ddd;padding:15px;overflow-y:auto}[data-theme=dark] .panel{color:#e0e0e0;border-right-color:#444;background-color:#1a1a1a!important}[data-theme=dark] .panel label{color:#e0e0e0}[data-theme=dark] .panel input,[data-theme=dark] .panel select{color:#e0e0e0;background-color:#2a2a2a;border:1px solid #444}[data-theme=dark] .panel hr{border-color:#444}.panel canvas{cursor:pointer;margin:auto;display:block}.panel label{margin-top:12px;font-weight:700;display:block}.panel input,.panel select{width:100%;margin-top:4px}.panel hr{margin:18px 0}.colors{flex-wrap:wrap;gap:12px;display:flex}.swatchBox{text-align:center;font-size:13px}.swatch{border:1px solid #ccc;border-radius:10px;width:70px;height:70px}.panel pre{background:#f3f3f3;border-radius:10px;max-height:320px;padding:10px;font-size:12px;overflow-x:auto}.panel h3{margin-top:0}
2
+ /*$vite$:1*/
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("react/jsx-runtime"),t=require("react"),me=t.createContext({isDark:!1,setIsDark:()=>{}});function Ye({children:S}){const[i,g]=t.useState(()=>localStorage.getItem("theme")==="dark");return t.useEffect(()=>{document.documentElement.setAttribute("data-theme",i?"dark":"light"),localStorage.setItem("theme",i?"dark":"light")},[i]),F.jsx(me.Provider,{value:{isDark:i,setIsDark:g},children:S})}function ge(){return t.useContext(me)}const he={complementary:[0,180],analogous:[-30,0,30],monochromatic:[0],split:[0,150,-150],triadic:[0,120,240],square:[0,90,180,270],simple:[0]},ze=[{name:"Harmony Mode",attribute:"harmony-mode",default:"split",show:!0,notes:""},{name:"Saturation",attribute:"saturation",default:100,show:!0,notes:""},{name:"Brightness",attribute:"brightness",default:50,show:!0,notes:""},{name:"Circle Radius",attribute:"circle-radius",default:1,show:!1,notes:"If not passed, default it is false"},{name:"Wheel Thickness",attribute:"wheel-thickness",default:80,show:!1,notes:"If not passed, default it is false"},{name:"Dot Size",attribute:"dot-size",default:5,show:!1,notes:"If not passed, default it is false"},{name:"Dot Position",attribute:"dot-position",default:"outer",show:!1,notes:"If not passed, default it is false"},{name:"Handle Thickness",attribute:"handle-thickness",default:2,show:!1,notes:"If not passed, default it is false"},{name:"Handle Color",attribute:"handle-color",default:"#000000",show:!1,notes:"If not passed, default it is false"},{name:"Show Harmony Polygon",attribute:"harmony-polygon",default:!1,show:!1,notes:"If not passed, default it is false"},{name:"Polygon Color",attribute:"polygon-color",default:"#000000",show:!1,notes:"If not passed, default it is false"},{name:"Polygon Thickness",attribute:"polygon-thickness",default:1,show:!1,notes:"If not passed, default it is false"},{name:"Center Dot",attribute:"center-dot",default:"#ffffff",show:!1,notes:"If not passed, default it is false"},{name:"Palette",attribute:"palette",default:null,show:!1,notes:"If not passed, default it is false"},{name:"Palette JSON",attribute:"palette-json",default:null,show:!1,notes:"If not passed, default it is false"}];function Ae({onColorsChange:S,harmonyMode:i,saturation:g,brightness:E,circleRadius:b,wheelThickness:y,dotSize:k,dotPosition:P,handleThickness:C,handleColor:I,harmonyPolygon:T,polygonColor:R,polygonThickness:D,centerDot:j,showCenterDot:H=!1,borderColor:U="#ffffff",canvasBackgroundColor:Y="transparent",width:W=450,height:L=450}){const O=t.useRef(null),[be,z]=t.useState(!1),{isDark:G}=ge(),l=e=>ze.find(s=>s.attribute===e),[c,ye]=t.useState(i||l("harmony-mode").default),[N,ke]=t.useState(g??l("saturation").default),[$,we]=t.useState(E??l("brightness").default),A=t.useCallback(()=>{const e=l("circle-radius").default;if(b!==void 0)return b;if(e===1){const s=Math.min(W,L),a=y??l("wheel-thickness").default,n=k??l("dot-size").default;return s/2-a/2-n-10}return e},[W,L,b,y,k]),[w,J]=t.useState(A()),[v,Se]=t.useState(y??l("wheel-thickness").default),[K,ve]=t.useState(k??l("dot-size").default),[X,Me]=t.useState(P||l("dot-position").default),[Q,Ee]=t.useState(C??l("handle-thickness").default),[V,Pe]=t.useState(I||(l("handle-color").default==="black"?"#000000":l("handle-color").default)),[Z,Ce]=t.useState(T??l("harmony-polygon").default),[x,Ie]=t.useState(R||(l("polygon-color").default==="black"?"#000000":l("polygon-color").default)),[p,Te]=t.useState(D??l("polygon-thickness").default),[ee,Re]=t.useState(j||(l("center-dot").default==="white"?"#ffffff":l("center-dot").default)),[te,De]=t.useState(H),[_,je]=t.useState(U),[M,We]=t.useState(Y),[d,se]=t.useState(0);t.useEffect(()=>{i!==void 0&&ye(i)},[i]),t.useEffect(()=>{g!==void 0&&ke(g)},[g]),t.useEffect(()=>{E!==void 0&&we(E)},[E]),t.useEffect(()=>{J(b!==void 0?b:A())},[b,A]),t.useEffect(()=>{y!==void 0&&Se(y)},[y]),t.useEffect(()=>{k!==void 0&&ve(k)},[k]),t.useEffect(()=>{P!==void 0&&Me(P)},[P]),t.useEffect(()=>{C!==void 0&&Ee(C)},[C]),t.useEffect(()=>{I!==void 0&&Pe(I)},[I]),t.useEffect(()=>{T!==void 0&&Ce(T)},[T]),t.useEffect(()=>{R!==void 0&&Ie(R)},[R]),t.useEffect(()=>{D!==void 0&&Te(D)},[D]),t.useEffect(()=>{j!==void 0&&Re(j)},[j]),t.useEffect(()=>{De(H)},[H]),t.useEffect(()=>{je(U)},[U]),t.useEffect(()=>{We(Y)},[Y]);const o={x:W/2,y:L/2},B=e=>(e+360)%360,ae=t.useCallback((e,s=N,a=$)=>`hsl(${e}, ${s}%, ${a}%)`,[N,$]),Le=(e,s,a)=>{s/=100,a/=100;const n=(1-Math.abs(2*a-1))*s,f=n*(1-Math.abs(e/60%2-1)),u=a-n/2;let r=0,h=0,m=0;return e<60?[r,h,m]=[n,f,0]:e<120?[r,h,m]=[f,n,0]:e<180?[r,h,m]=[0,n,f]:e<240?[r,h,m]=[0,f,n]:e<300?[r,h,m]=[f,0,n]:[r,h,m]=[n,0,f],{r:Math.round((r+u)*255),g:Math.round((h+u)*255),b:Math.round((m+u)*255)}},Oe=(e,s,a)=>"#"+[e,s,a].map(n=>n.toString(16).padStart(2,"0")).join(""),ne=t.useCallback(()=>X==="center"?w:X==="inner"?w-v/2:w+v/2,[X,w,v]),le=t.useCallback(e=>{const s=(e-90)*Math.PI/180,a=ne();return{x:o.x+a*Math.cos(s),y:o.y+a*Math.sin(s)}},[o.x,o.y,ne]),oe=(e,s)=>{const a=e-o.x,n=s-o.y,f=Math.atan2(n,a)*180/Math.PI;return B(f+90)},fe=t.useCallback(()=>{let e=[];c==="monochromatic"?e=[{h:d,l:30},{h:d,l:50},{h:d,l:70}]:e=he[c].map(a=>({h:B(d+a),l:$}));const s=e.map(a=>{const n=Le(a.h,N,a.l);return Oe(n.r,n.g,n.b)});return{[c]:s}},[c,d,N,$]),ie=t.useCallback(e=>{for(let s=0;s<360;s++)e.beginPath(),e.strokeStyle=`hsl(${s},100%,50%)`,e.lineWidth=v,e.arc(o.x,o.y,w,(s-90)*Math.PI/180,(s-89)*Math.PI/180),e.stroke()},[o.x,o.y,w,v]),ue=t.useCallback((e,s)=>{!Z||s.length<3||(e.beginPath(),e.moveTo(s[0].x,s[0].y),s.slice(1).forEach(a=>{e.lineTo(a.x,a.y)}),e.closePath(),e.strokeStyle=x,e.lineWidth=p,e.stroke())},[Z,x,p]),ce=t.useCallback(e=>{if(c==="simple")return;const s=he[c],a=[];s.forEach(n=>{const f=B(d+n),u=le(f);a.push(u),e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(u.x,u.y),e.strokeStyle=V,e.lineWidth=Q,e.stroke(),e.beginPath(),e.arc(u.x,u.y,K,0,Math.PI*2),e.fillStyle=ae(f),e.fill(),e.strokeStyle="white",e.stroke()}),ue(e,a),te&&(e.beginPath(),e.arc(o.x,o.y,5,0,Math.PI*2),e.fillStyle=ee,e.fill(),e.strokeStyle="white",e.lineWidth=1,e.stroke())},[c,d,o.x,o.y,K,Q,V,ee,te,le,ae,ue]),de=t.useCallback(()=>{const e=O.current;if(!e)return;const s=e.getContext("2d");s&&(s.clearRect(0,0,e.width,e.height),M&&M!=="transparent"?(s.fillStyle=M,s.fillRect(0,0,e.width,e.height)):M==="transparent"&&(s.fillStyle=G?"#1a1a1a":"#ffffff",s.fillRect(0,0,e.width,e.height)),ie(s),ce(s),_&&(s.strokeStyle=_,s.lineWidth=1,s.strokeRect(0,0,e.width,e.height)))},[ie,ce,_,M,G]),Ne=()=>z(!0),$e=()=>z(!1),qe=()=>z(!1),He=e=>{if(!be)return;const s=O.current;if(!s)return;const a=s.getBoundingClientRect(),n=oe(e.clientX-a.left,e.clientY-a.top);se(n)},Ue=e=>{const s=O.current;if(!s)return;const a=s.getBoundingClientRect(),n=oe(e.clientX-a.left,e.clientY-a.top);se(n)};t.useEffect(()=>{de()},[de]);const q=t.useMemo(()=>fe(),[fe]);t.useEffect(()=>{S&&S(q)},[q,S]);const re=t.useCallback(()=>q,[q]);return t.useEffect(()=>(window.getColorWheelPalette=re,()=>{delete window.getColorWheelPalette}),[re]),F.jsx("div",{className:"color-wheel-container",children:F.jsx("canvas",{ref:O,width:W,height:L,onMouseDown:Ne,onMouseUp:$e,onMouseLeave:qe,onMouseMove:He,onClick:Ue,style:{display:"block",margin:"0 auto",cursor:"pointer"}})})}exports.ColorWheel=Ae;exports.ThemeProvider=Ye;exports.useTheme=ge;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime");var n=(0,e.createContext)({isDark:!1,setIsDark:()=>{}});function r({children:r}){let[i,a]=(0,e.useState)(()=>localStorage.getItem(`theme`)===`dark`);return(0,e.useEffect)(()=>{document.documentElement.setAttribute(`data-theme`,i?`dark`:`light`),localStorage.setItem(`theme`,i?`dark`:`light`)},[i]),(0,t.jsx)(n.Provider,{value:{isDark:i,setIsDark:a},children:r})}function i(){return(0,e.useContext)(n)}var a={complementary:[0,180],analogous:[-30,0,30],monochromatic:[0],split:[0,150,-150],triadic:[0,120,240],square:[0,90,180,270],simple:[0]},o=[{name:`Harmony Mode`,attribute:`harmony-mode`,default:`split`,show:!0,notes:``},{name:`Saturation`,attribute:`saturation`,default:100,show:!0,notes:``},{name:`Brightness`,attribute:`brightness`,default:50,show:!0,notes:``},{name:`Circle Radius`,attribute:`circle-radius`,default:1,show:!1,notes:`If not passed, default it is false`},{name:`Wheel Thickness`,attribute:`wheel-thickness`,default:80,show:!1,notes:`If not passed, default it is false`},{name:`Dot Size`,attribute:`dot-size`,default:5,show:!1,notes:`If not passed, default it is false`},{name:`Dot Position`,attribute:`dot-position`,default:`outer`,show:!1,notes:`If not passed, default it is false`},{name:`Handle Thickness`,attribute:`handle-thickness`,default:2,show:!1,notes:`If not passed, default it is false`},{name:`Handle Color`,attribute:`handle-color`,default:`#000000`,show:!1,notes:`If not passed, default it is false`},{name:`Show Harmony Polygon`,attribute:`harmony-polygon`,default:!1,show:!1,notes:`If not passed, default it is false`},{name:`Polygon Color`,attribute:`polygon-color`,default:`#000000`,show:!1,notes:`If not passed, default it is false`},{name:`Polygon Thickness`,attribute:`polygon-thickness`,default:1,show:!1,notes:`If not passed, default it is false`},{name:`Center Dot`,attribute:`center-dot`,default:`#ffffff`,show:!1,notes:`If not passed, default it is false`},{name:`Palette`,attribute:`palette`,default:null,show:!1,notes:`If not passed, default it is false`},{name:`Palette JSON`,attribute:`palette-json`,default:null,show:!1,notes:`If not passed, default it is false`}];function s({onColorsChange:n,harmonyMode:r,saturation:s,brightness:c,circleRadius:l,wheelThickness:u,dotSize:d,dotPosition:f,handleThickness:p,handleColor:m,harmonyPolygon:h,polygonColor:g,polygonThickness:_,centerDot:v,showCenterDot:y=!1,borderColor:b=`#ffffff`,canvasBackgroundColor:x=`transparent`,width:S=450,height:C=450}){let w=(0,e.useRef)(null),[ee,T]=(0,e.useState)(!1),{isDark:E}=i(),D=e=>o.find(t=>t.attribute===e),[O,te]=(0,e.useState)(r||D(`harmony-mode`).default),[k,ne]=(0,e.useState)(s??D(`saturation`).default),[A,re]=(0,e.useState)(c??D(`brightness`).default),j=(0,e.useCallback)(()=>{let e=D(`circle-radius`).default;if(l!==void 0)return l;if(e===1){let e=Math.min(S,C),t=u??D(`wheel-thickness`).default,n=d??D(`dot-size`).default;return e/2-t/2-n-10}return e},[S,C,l,u,d]),[M,ie]=(0,e.useState)(j()),[N,ae]=(0,e.useState)(u??D(`wheel-thickness`).default),[oe,se]=(0,e.useState)(d??D(`dot-size`).default),[P,ce]=(0,e.useState)(f||D(`dot-position`).default),[F,le]=(0,e.useState)(p??D(`handle-thickness`).default),[I,ue]=(0,e.useState)(m||(D(`handle-color`).default===`black`?`#000000`:D(`handle-color`).default)),[L,de]=(0,e.useState)(h??D(`harmony-polygon`).default),[R,fe]=(0,e.useState)(g||(D(`polygon-color`).default===`black`?`#000000`:D(`polygon-color`).default)),[z,pe]=(0,e.useState)(_??D(`polygon-thickness`).default),[B,me]=(0,e.useState)(v||(D(`center-dot`).default===`white`?`#ffffff`:D(`center-dot`).default)),[V,he]=(0,e.useState)(y),[H,ge]=(0,e.useState)(b),[U,_e]=(0,e.useState)(x),[W,G]=(0,e.useState)(0);(0,e.useEffect)(()=>{r!==void 0&&te(r)},[r]),(0,e.useEffect)(()=>{s!==void 0&&ne(s)},[s]),(0,e.useEffect)(()=>{c!==void 0&&re(c)},[c]),(0,e.useEffect)(()=>{ie(l===void 0?j():l)},[l,j]),(0,e.useEffect)(()=>{u!==void 0&&ae(u)},[u]),(0,e.useEffect)(()=>{d!==void 0&&se(d)},[d]),(0,e.useEffect)(()=>{f!==void 0&&ce(f)},[f]),(0,e.useEffect)(()=>{p!==void 0&&le(p)},[p]),(0,e.useEffect)(()=>{m!==void 0&&ue(m)},[m]),(0,e.useEffect)(()=>{h!==void 0&&de(h)},[h]),(0,e.useEffect)(()=>{g!==void 0&&fe(g)},[g]),(0,e.useEffect)(()=>{_!==void 0&&pe(_)},[_]),(0,e.useEffect)(()=>{v!==void 0&&me(v)},[v]),(0,e.useEffect)(()=>{he(y)},[y]),(0,e.useEffect)(()=>{ge(b)},[b]),(0,e.useEffect)(()=>{_e(x)},[x]);let K={x:S/2,y:C/2},q=e=>(e+360)%360,J=(0,e.useCallback)((e,t=k,n=A)=>`hsl(${e}, ${t}%, ${n}%)`,[k,A]),ve=(e,t,n)=>{t/=100,n/=100;let r=(1-Math.abs(2*n-1))*t,i=r*(1-Math.abs(e/60%2-1)),a=n-r/2,o=0,s=0,c=0;return e<60?[o,s,c]=[r,i,0]:e<120?[o,s,c]=[i,r,0]:e<180?[o,s,c]=[0,r,i]:e<240?[o,s,c]=[0,i,r]:e<300?[o,s,c]=[i,0,r]:[o,s,c]=[r,0,i],{r:Math.round((o+a)*255),g:Math.round((s+a)*255),b:Math.round((c+a)*255)}},ye=(e,t,n)=>`#`+[e,t,n].map(e=>e.toString(16).padStart(2,`0`)).join(``),Y=(0,e.useCallback)(()=>P===`center`?M:P===`inner`?M-N/2:M+N/2,[P,M,N]),X=(0,e.useCallback)(e=>{let t=(e-90)*Math.PI/180,n=Y();return{x:K.x+n*Math.cos(t),y:K.y+n*Math.sin(t)}},[K.x,K.y,Y]),Z=(e,t)=>{let n=e-K.x,r=t-K.y,i=Math.atan2(r,n)*180/Math.PI;return q(i+90)},Q=(0,e.useCallback)(()=>{let e=[];e=O===`monochromatic`?[{h:W,l:30},{h:W,l:50},{h:W,l:70}]:a[O].map(e=>({h:q(W+e),l:A}));let t=e.map(e=>{let t=ve(e.h,k,e.l);return ye(t.r,t.g,t.b)});return{[O]:t}},[O,W,k,A]),be=(0,e.useCallback)(e=>{for(let t=0;t<360;t++)e.beginPath(),e.strokeStyle=`hsl(${t},100%,50%)`,e.lineWidth=N,e.arc(K.x,K.y,M,(t-90)*Math.PI/180,(t-89)*Math.PI/180),e.stroke()},[K.x,K.y,M,N]),xe=(0,e.useCallback)((e,t)=>{!L||t.length<3||(e.beginPath(),e.moveTo(t[0].x,t[0].y),t.slice(1).forEach(t=>{e.lineTo(t.x,t.y)}),e.closePath(),e.strokeStyle=R,e.lineWidth=z,e.stroke())},[L,R,z]),Se=(0,e.useCallback)(e=>{if(O===`simple`)return;let t=a[O],n=[];t.forEach(t=>{let r=q(W+t),i=X(r);n.push(i),e.beginPath(),e.moveTo(K.x,K.y),e.lineTo(i.x,i.y),e.strokeStyle=I,e.lineWidth=F,e.stroke(),e.beginPath(),e.arc(i.x,i.y,oe,0,Math.PI*2),e.fillStyle=J(r),e.fill(),e.strokeStyle=`white`,e.stroke()}),xe(e,n),V&&(e.beginPath(),e.arc(K.x,K.y,5,0,Math.PI*2),e.fillStyle=B,e.fill(),e.strokeStyle=`white`,e.lineWidth=1,e.stroke())},[O,W,K.x,K.y,oe,F,I,B,V,X,J,xe]),Ce=(0,e.useCallback)(()=>{let e=w.current;if(!e)return;let t=e.getContext(`2d`);t&&(t.clearRect(0,0,e.width,e.height),U&&U!==`transparent`?(t.fillStyle=U,t.fillRect(0,0,e.width,e.height)):U===`transparent`&&(t.fillStyle=E?`#1a1a1a`:`#ffffff`,t.fillRect(0,0,e.width,e.height)),be(t),Se(t),H&&(t.strokeStyle=H,t.lineWidth=1,t.strokeRect(0,0,e.width,e.height)))},[be,Se,H,U,E]),we=()=>T(!0),Te=()=>T(!1),Ee=()=>T(!1),De=e=>{if(!ee)return;let t=w.current;if(!t)return;let n=t.getBoundingClientRect(),r=Z(e.clientX-n.left,e.clientY-n.top);G(r)},Oe=e=>{let t=w.current;if(!t)return;let n=t.getBoundingClientRect(),r=Z(e.clientX-n.left,e.clientY-n.top);G(r)};(0,e.useEffect)(()=>{Ce()},[Ce]);let $=(0,e.useMemo)(()=>Q(),[Q]);(0,e.useEffect)(()=>{n&&n($)},[$,n]);let ke=(0,e.useCallback)(()=>$,[$]);return(0,e.useEffect)(()=>(window.getColorWheelPalette=ke,()=>{delete window.getColorWheelPalette}),[ke]),(0,t.jsx)(`div`,{className:`color-wheel-container`,children:(0,t.jsx)(`canvas`,{ref:w,width:S,height:C,onMouseDown:we,onMouseUp:Te,onMouseLeave:Ee,onMouseMove:De,onClick:Oe,style:{display:`block`,margin:`0 auto`,cursor:`pointer`}})})}exports.ColorWheel=s,exports.ThemeProvider=r,exports.useTheme=i;
package/dist/index.mjs CHANGED
@@ -1,364 +1,377 @@
1
- import { jsx as J } from "react/jsx-runtime";
2
- import { useContext as Ae, useState as o, useEffect as a, createContext as Xe, useRef as _e, useCallback as d, useMemo as qe } from "react";
3
- const ye = Xe({
4
- isDark: !1,
5
- setIsDark: () => {
6
- }
1
+ import { createContext as e, useCallback as t, useContext as n, useEffect as r, useMemo as i, useRef as a, useState as o } from "react";
2
+ import { jsx as s } from "react/jsx-runtime";
3
+ // src/ThemeContext.tsx
4
+ var c = e({
5
+ isDark: !1,
6
+ setIsDark: () => {}
7
7
  });
8
- function Ke({ children: P }) {
9
- const [u, b] = o(() => localStorage.getItem("theme") === "dark");
10
- return a(() => {
11
- document.documentElement.setAttribute("data-theme", u ? "dark" : "light"), localStorage.setItem("theme", u ? "dark" : "light");
12
- }, [u]), /* @__PURE__ */ J(ye.Provider, { value: { isDark: u, setIsDark: b }, children: P });
8
+ function l({ children: e }) {
9
+ let [t, n] = o(() => localStorage.getItem("theme") === "dark");
10
+ return r(() => {
11
+ document.documentElement.setAttribute("data-theme", t ? "dark" : "light"), localStorage.setItem("theme", t ? "dark" : "light");
12
+ }, [t]), /* @__PURE__ */ s(c.Provider, {
13
+ value: {
14
+ isDark: t,
15
+ setIsDark: n
16
+ },
17
+ children: e
18
+ });
13
19
  }
14
- function Be() {
15
- return Ae(ye);
20
+ function ee() {
21
+ return n(c);
16
22
  }
17
- const ge = {
18
- complementary: [0, 180],
19
- analogous: [-30, 0, 30],
20
- monochromatic: [0],
21
- split: [0, 150, -150],
22
- triadic: [0, 120, 240],
23
- square: [0, 90, 180, 270],
24
- simple: [0]
25
- }, Fe = [
26
- {
27
- name: "Harmony Mode",
28
- attribute: "harmony-mode",
29
- default: "split",
30
- show: !0,
31
- notes: ""
32
- },
33
- {
34
- name: "Saturation",
35
- attribute: "saturation",
36
- default: 100,
37
- show: !0,
38
- notes: ""
39
- },
40
- {
41
- name: "Brightness",
42
- attribute: "brightness",
43
- default: 50,
44
- show: !0,
45
- notes: ""
46
- },
47
- {
48
- name: "Circle Radius",
49
- attribute: "circle-radius",
50
- default: 1,
51
- show: !1,
52
- notes: "If not passed, default it is false"
53
- },
54
- {
55
- name: "Wheel Thickness",
56
- attribute: "wheel-thickness",
57
- default: 80,
58
- show: !1,
59
- notes: "If not passed, default it is false"
60
- },
61
- {
62
- name: "Dot Size",
63
- attribute: "dot-size",
64
- default: 5,
65
- show: !1,
66
- notes: "If not passed, default it is false"
67
- },
68
- {
69
- name: "Dot Position",
70
- attribute: "dot-position",
71
- default: "outer",
72
- show: !1,
73
- notes: "If not passed, default it is false"
74
- },
75
- {
76
- name: "Handle Thickness",
77
- attribute: "handle-thickness",
78
- default: 2,
79
- show: !1,
80
- notes: "If not passed, default it is false"
81
- },
82
- {
83
- name: "Handle Color",
84
- attribute: "handle-color",
85
- default: "#000000",
86
- show: !1,
87
- notes: "If not passed, default it is false"
88
- },
89
- {
90
- name: "Show Harmony Polygon",
91
- attribute: "harmony-polygon",
92
- default: !1,
93
- show: !1,
94
- notes: "If not passed, default it is false"
95
- },
96
- {
97
- name: "Polygon Color",
98
- attribute: "polygon-color",
99
- default: "#000000",
100
- show: !1,
101
- notes: "If not passed, default it is false"
102
- },
103
- {
104
- name: "Polygon Thickness",
105
- attribute: "polygon-thickness",
106
- default: 1,
107
- show: !1,
108
- notes: "If not passed, default it is false"
109
- },
110
- {
111
- name: "Center Dot",
112
- attribute: "center-dot",
113
- default: "#ffffff",
114
- show: !1,
115
- notes: "If not passed, default it is false"
116
- },
117
- {
118
- name: "Palette",
119
- attribute: "palette",
120
- default: null,
121
- show: !1,
122
- notes: "If not passed, default it is false"
123
- },
124
- {
125
- name: "Palette JSON",
126
- attribute: "palette-json",
127
- default: null,
128
- show: !1,
129
- notes: "If not passed, default it is false"
130
- }
23
+ // src/ColorWheel.tsx
24
+ var u = {
25
+ complementary: [0, 180],
26
+ analogous: [
27
+ -30,
28
+ 0,
29
+ 30
30
+ ],
31
+ monochromatic: [0],
32
+ split: [
33
+ 0,
34
+ 150,
35
+ -150
36
+ ],
37
+ triadic: [
38
+ 0,
39
+ 120,
40
+ 240
41
+ ],
42
+ square: [
43
+ 0,
44
+ 90,
45
+ 180,
46
+ 270
47
+ ],
48
+ simple: [0]
49
+ }, te = [
50
+ {
51
+ name: "Harmony Mode",
52
+ attribute: "harmony-mode",
53
+ default: "split",
54
+ show: !0,
55
+ notes: ""
56
+ },
57
+ {
58
+ name: "Saturation",
59
+ attribute: "saturation",
60
+ default: 100,
61
+ show: !0,
62
+ notes: ""
63
+ },
64
+ {
65
+ name: "Brightness",
66
+ attribute: "brightness",
67
+ default: 50,
68
+ show: !0,
69
+ notes: ""
70
+ },
71
+ {
72
+ name: "Circle Radius",
73
+ attribute: "circle-radius",
74
+ default: 1,
75
+ show: !1,
76
+ notes: "If not passed, default it is false"
77
+ },
78
+ {
79
+ name: "Wheel Thickness",
80
+ attribute: "wheel-thickness",
81
+ default: 80,
82
+ show: !1,
83
+ notes: "If not passed, default it is false"
84
+ },
85
+ {
86
+ name: "Dot Size",
87
+ attribute: "dot-size",
88
+ default: 5,
89
+ show: !1,
90
+ notes: "If not passed, default it is false"
91
+ },
92
+ {
93
+ name: "Dot Position",
94
+ attribute: "dot-position",
95
+ default: "outer",
96
+ show: !1,
97
+ notes: "If not passed, default it is false"
98
+ },
99
+ {
100
+ name: "Handle Thickness",
101
+ attribute: "handle-thickness",
102
+ default: 2,
103
+ show: !1,
104
+ notes: "If not passed, default it is false"
105
+ },
106
+ {
107
+ name: "Handle Color",
108
+ attribute: "handle-color",
109
+ default: "#000000",
110
+ show: !1,
111
+ notes: "If not passed, default it is false"
112
+ },
113
+ {
114
+ name: "Show Harmony Polygon",
115
+ attribute: "harmony-polygon",
116
+ default: !1,
117
+ show: !1,
118
+ notes: "If not passed, default it is false"
119
+ },
120
+ {
121
+ name: "Polygon Color",
122
+ attribute: "polygon-color",
123
+ default: "#000000",
124
+ show: !1,
125
+ notes: "If not passed, default it is false"
126
+ },
127
+ {
128
+ name: "Polygon Thickness",
129
+ attribute: "polygon-thickness",
130
+ default: 1,
131
+ show: !1,
132
+ notes: "If not passed, default it is false"
133
+ },
134
+ {
135
+ name: "Center Dot",
136
+ attribute: "center-dot",
137
+ default: "#ffffff",
138
+ show: !1,
139
+ notes: "If not passed, default it is false"
140
+ },
141
+ {
142
+ name: "Palette",
143
+ attribute: "palette",
144
+ default: null,
145
+ show: !1,
146
+ notes: "If not passed, default it is false"
147
+ },
148
+ {
149
+ name: "Palette JSON",
150
+ attribute: "palette-json",
151
+ default: null,
152
+ show: !1,
153
+ notes: "If not passed, default it is false"
154
+ }
131
155
  ];
132
- function Qe({
133
- onColorsChange: P,
134
- harmonyMode: u,
135
- saturation: b,
136
- brightness: C,
137
- circleRadius: w,
138
- wheelThickness: k,
139
- dotSize: v,
140
- dotPosition: R,
141
- handleThickness: T,
142
- handleColor: D,
143
- harmonyPolygon: E,
144
- polygonColor: L,
145
- polygonThickness: W,
146
- centerDot: N,
147
- showCenterDot: z = !1,
148
- borderColor: A = "#ffffff",
149
- canvasBackgroundColor: X = "transparent",
150
- width: O = 450,
151
- height: $ = 450
152
- }) {
153
- const j = _e(null), [be, _] = o(!1), { isDark: K } = Be(), l = (e) => Fe.find((t) => t.attribute === e), [c, we] = o(
154
- u || l("harmony-mode").default
155
- ), [H, ke] = o(
156
- b ?? l("saturation").default
157
- ), [U, ve] = o(
158
- C ?? l("brightness").default
159
- ), q = d(() => {
160
- const e = l("circle-radius").default;
161
- if (w !== void 0) return w;
162
- if (e === 1) {
163
- const t = Math.min(O, $), s = k ?? l("wheel-thickness").default, n = v ?? l("dot-size").default;
164
- return t / 2 - s / 2 - n - 10;
165
- }
166
- return e;
167
- }, [O, $, w, k, v]), [M, Q] = o(q()), [I, Me] = o(
168
- k ?? l("wheel-thickness").default
169
- ), [V, Pe] = o(
170
- v ?? l("dot-size").default
171
- ), [B, Ie] = o(
172
- R || l("dot-position").default
173
- ), [Z, Se] = o(
174
- T ?? l("handle-thickness").default
175
- ), [x, Ce] = o(
176
- D || (l("handle-color").default === "black" ? "#000000" : l("handle-color").default)
177
- ), [p, Re] = o(
178
- E ?? l("harmony-polygon").default
179
- ), [ee, Te] = o(
180
- L || (l("polygon-color").default === "black" ? "#000000" : l("polygon-color").default)
181
- ), [te, De] = o(
182
- W ?? l("polygon-thickness").default
183
- ), [se, Ee] = o(
184
- N || (l("center-dot").default === "white" ? "#ffffff" : l("center-dot").default)
185
- ), [ne, Le] = o(z), [F, We] = o(A), [S, Ne] = o(
186
- X
187
- ), [h, ae] = o(0);
188
- a(() => {
189
- u !== void 0 && we(u);
190
- }, [u]), a(() => {
191
- b !== void 0 && ke(b);
192
- }, [b]), a(() => {
193
- C !== void 0 && ve(C);
194
- }, [C]), a(() => {
195
- Q(w !== void 0 ? w : q());
196
- }, [w, q]), a(() => {
197
- k !== void 0 && Me(k);
198
- }, [k]), a(() => {
199
- v !== void 0 && Pe(v);
200
- }, [v]), a(() => {
201
- R !== void 0 && Ie(R);
202
- }, [R]), a(() => {
203
- T !== void 0 && Se(T);
204
- }, [T]), a(() => {
205
- D !== void 0 && Ce(D);
206
- }, [D]), a(() => {
207
- E !== void 0 && Re(E);
208
- }, [E]), a(() => {
209
- L !== void 0 && Te(L);
210
- }, [L]), a(() => {
211
- W !== void 0 && De(W);
212
- }, [W]), a(() => {
213
- N !== void 0 && Ee(N);
214
- }, [N]), a(() => {
215
- Le(z);
216
- }, [z]), a(() => {
217
- We(A);
218
- }, [A]), a(() => {
219
- Ne(X);
220
- }, [X]);
221
- const i = { x: O / 2, y: $ / 2 }, G = (e) => (e + 360) % 360, oe = d(
222
- (e, t = H, s = U) => `hsl(${e}, ${t}%, ${s}%)`,
223
- [H, U]
224
- ), Oe = (e, t, s) => {
225
- t /= 100, s /= 100;
226
- const n = (1 - Math.abs(2 * s - 1)) * t, f = n * (1 - Math.abs(e / 60 % 2 - 1)), r = s - n / 2;
227
- let m = 0, g = 0, y = 0;
228
- return e < 60 ? [m, g, y] = [n, f, 0] : e < 120 ? [m, g, y] = [f, n, 0] : e < 180 ? [m, g, y] = [0, n, f] : e < 240 ? [m, g, y] = [0, f, n] : e < 300 ? [m, g, y] = [f, 0, n] : [m, g, y] = [n, 0, f], {
229
- r: Math.round((m + r) * 255),
230
- g: Math.round((g + r) * 255),
231
- b: Math.round((y + r) * 255)
232
- };
233
- }, $e = (e, t, s) => "#" + [e, t, s].map((n) => n.toString(16).padStart(2, "0")).join(""), le = d(() => B === "center" ? M : B === "inner" ? M - I / 2 : M + I / 2, [B, M, I]), ie = d(
234
- (e) => {
235
- const t = (e - 90) * Math.PI / 180, s = le();
236
- return {
237
- x: i.x + s * Math.cos(t),
238
- y: i.y + s * Math.sin(t)
239
- };
240
- },
241
- [i.x, i.y, le]
242
- ), fe = (e, t) => {
243
- const s = e - i.x, n = t - i.y, f = Math.atan2(n, s) * 180 / Math.PI;
244
- return G(f + 90);
245
- }, de = d(() => {
246
- let e = [];
247
- c === "monochromatic" ? e = [
248
- { h, l: 30 },
249
- { h, l: 50 },
250
- { h, l: 70 }
251
- ] : e = ge[c].map((s) => ({
252
- h: G(h + s),
253
- l: U
254
- }));
255
- const t = e.map((s) => {
256
- const n = Oe(s.h, H, s.l);
257
- return $e(n.r, n.g, n.b);
258
- });
259
- return {
260
- [c]: t
261
- };
262
- }, [c, h, H, U]), ue = d(
263
- (e) => {
264
- for (let t = 0; t < 360; t++)
265
- e.beginPath(), e.strokeStyle = `hsl(${t},100%,50%)`, e.lineWidth = I, e.arc(
266
- i.x,
267
- i.y,
268
- M,
269
- (t - 90) * Math.PI / 180,
270
- (t - 89) * Math.PI / 180
271
- ), e.stroke();
272
- },
273
- [i.x, i.y, M, I]
274
- ), re = d(
275
- (e, t) => {
276
- !p || t.length < 3 || (e.beginPath(), e.moveTo(t[0].x, t[0].y), t.slice(1).forEach((s) => {
277
- e.lineTo(s.x, s.y);
278
- }), e.closePath(), e.strokeStyle = ee, e.lineWidth = te, e.stroke());
279
- },
280
- [p, ee, te]
281
- ), ce = d(
282
- (e) => {
283
- if (c === "simple")
284
- return;
285
- const t = ge[c], s = [];
286
- t.forEach((n) => {
287
- const f = G(h + n), r = ie(f);
288
- s.push(r), e.beginPath(), e.moveTo(i.x, i.y), e.lineTo(r.x, r.y), e.strokeStyle = x, e.lineWidth = Z, e.stroke(), e.beginPath(), e.arc(r.x, r.y, V, 0, Math.PI * 2), e.fillStyle = oe(f), e.fill(), e.strokeStyle = "white", e.stroke();
289
- }), re(e, s), ne && (e.beginPath(), e.arc(i.x, i.y, 5, 0, Math.PI * 2), e.fillStyle = se, e.fill(), e.strokeStyle = "white", e.lineWidth = 1, e.stroke());
290
- },
291
- [
292
- c,
293
- h,
294
- i.x,
295
- i.y,
296
- V,
297
- Z,
298
- x,
299
- se,
300
- ne,
301
- ie,
302
- oe,
303
- re
304
- ]
305
- ), he = d(() => {
306
- const e = j.current;
307
- if (!e) return;
308
- const t = e.getContext("2d");
309
- t && (t.clearRect(0, 0, e.width, e.height), S && S !== "transparent" ? (t.fillStyle = S, t.fillRect(0, 0, e.width, e.height)) : S === "transparent" && (t.fillStyle = K ? "#1a1a1a" : "#ffffff", t.fillRect(0, 0, e.width, e.height)), ue(t), ce(t), F && (t.strokeStyle = F, t.lineWidth = 1, t.strokeRect(0, 0, e.width, e.height)));
310
- }, [
311
- ue,
312
- ce,
313
- F,
314
- S,
315
- K
316
- ]), je = () => _(!0), He = () => _(!1), Ue = () => _(!1), Ye = (e) => {
317
- if (!be) return;
318
- const t = j.current;
319
- if (!t) return;
320
- const s = t.getBoundingClientRect(), n = fe(e.clientX - s.left, e.clientY - s.top);
321
- ae(n);
322
- }, ze = (e) => {
323
- const t = j.current;
324
- if (!t) return;
325
- const s = t.getBoundingClientRect(), n = fe(e.clientX - s.left, e.clientY - s.top);
326
- ae(n);
327
- };
328
- a(() => {
329
- he();
330
- }, [he]);
331
- const Y = qe(() => de(), [de]);
332
- a(() => {
333
- P && P(Y);
334
- }, [Y, P]);
335
- const me = d(
336
- () => Y,
337
- [Y]
338
- );
339
- return a(() => (window.getColorWheelPalette = me, () => {
340
- delete window.getColorWheelPalette;
341
- }), [me]), /* @__PURE__ */ J("div", { className: "color-wheel-container", children: /* @__PURE__ */ J(
342
- "canvas",
343
- {
344
- ref: j,
345
- width: O,
346
- height: $,
347
- onMouseDown: je,
348
- onMouseUp: He,
349
- onMouseLeave: Ue,
350
- onMouseMove: Ye,
351
- onClick: ze,
352
- style: {
353
- display: "block",
354
- margin: "0 auto",
355
- cursor: "pointer"
356
- }
357
- }
358
- ) });
156
+ function d({ onColorsChange: e, harmonyMode: n, saturation: c, brightness: l, circleRadius: d, wheelThickness: f, dotSize: p, dotPosition: m, handleThickness: h, handleColor: g, harmonyPolygon: _, polygonColor: v, polygonThickness: y, centerDot: b, showCenterDot: x = !1, borderColor: S = "#ffffff", canvasBackgroundColor: C = "transparent", width: w = 450, height: T = 450 }) {
157
+ let E = a(null), [ne, D] = o(!1), { isDark: O } = ee(), k = (e) => te.find((t) => t.attribute === e), [A, re] = o(n || k("harmony-mode").default), [j, ie] = o(c ?? k("saturation").default), [M, ae] = o(l ?? k("brightness").default), N = t(() => {
158
+ let e = k("circle-radius").default;
159
+ if (d !== void 0) return d;
160
+ if (e === 1) {
161
+ let e = Math.min(w, T), t = f ?? k("wheel-thickness").default, n = p ?? k("dot-size").default;
162
+ return e / 2 - t / 2 - n - 10;
163
+ }
164
+ return e;
165
+ }, [
166
+ w,
167
+ T,
168
+ d,
169
+ f,
170
+ p
171
+ ]), [P, oe] = o(N()), [F, se] = o(f ?? k("wheel-thickness").default), [I, ce] = o(p ?? k("dot-size").default), [L, le] = o(m || k("dot-position").default), [R, ue] = o(h ?? k("handle-thickness").default), [z, de] = o(g || (k("handle-color").default === "black" ? "#000000" : k("handle-color").default)), [B, fe] = o(_ ?? k("harmony-polygon").default), [V, pe] = o(v || (k("polygon-color").default === "black" ? "#000000" : k("polygon-color").default)), [H, me] = o(y ?? k("polygon-thickness").default), [U, he] = o(b || (k("center-dot").default === "white" ? "#ffffff" : k("center-dot").default)), [W, ge] = o(x), [G, _e] = o(S), [K, ve] = o(C), [q, J] = o(0);
172
+ r(() => {
173
+ n !== void 0 && re(n);
174
+ }, [n]), r(() => {
175
+ c !== void 0 && ie(c);
176
+ }, [c]), r(() => {
177
+ l !== void 0 && ae(l);
178
+ }, [l]), r(() => {
179
+ oe(d === void 0 ? N() : d);
180
+ }, [d, N]), r(() => {
181
+ f !== void 0 && se(f);
182
+ }, [f]), r(() => {
183
+ p !== void 0 && ce(p);
184
+ }, [p]), r(() => {
185
+ m !== void 0 && le(m);
186
+ }, [m]), r(() => {
187
+ h !== void 0 && ue(h);
188
+ }, [h]), r(() => {
189
+ g !== void 0 && de(g);
190
+ }, [g]), r(() => {
191
+ _ !== void 0 && fe(_);
192
+ }, [_]), r(() => {
193
+ v !== void 0 && pe(v);
194
+ }, [v]), r(() => {
195
+ y !== void 0 && me(y);
196
+ }, [y]), r(() => {
197
+ b !== void 0 && he(b);
198
+ }, [b]), r(() => {
199
+ ge(x);
200
+ }, [x]), r(() => {
201
+ _e(S);
202
+ }, [S]), r(() => {
203
+ ve(C);
204
+ }, [C]);
205
+ let Y = {
206
+ x: w / 2,
207
+ y: T / 2
208
+ }, X = (e) => (e + 360) % 360, Z = t((e, t = j, n = M) => `hsl(${e}, ${t}%, ${n}%)`, [j, M]), ye = (e, t, n) => {
209
+ t /= 100, n /= 100;
210
+ let r = (1 - Math.abs(2 * n - 1)) * t, i = r * (1 - Math.abs(e / 60 % 2 - 1)), a = n - r / 2, o = 0, s = 0, c = 0;
211
+ return e < 60 ? [o, s, c] = [
212
+ r,
213
+ i,
214
+ 0
215
+ ] : e < 120 ? [o, s, c] = [
216
+ i,
217
+ r,
218
+ 0
219
+ ] : e < 180 ? [o, s, c] = [
220
+ 0,
221
+ r,
222
+ i
223
+ ] : e < 240 ? [o, s, c] = [
224
+ 0,
225
+ i,
226
+ r
227
+ ] : e < 300 ? [o, s, c] = [
228
+ i,
229
+ 0,
230
+ r
231
+ ] : [o, s, c] = [
232
+ r,
233
+ 0,
234
+ i
235
+ ], {
236
+ r: Math.round((o + a) * 255),
237
+ g: Math.round((s + a) * 255),
238
+ b: Math.round((c + a) * 255)
239
+ };
240
+ }, be = (e, t, n) => "#" + [
241
+ e,
242
+ t,
243
+ n
244
+ ].map((e) => e.toString(16).padStart(2, "0")).join(""), xe = t(() => L === "center" ? P : L === "inner" ? P - F / 2 : P + F / 2, [
245
+ L,
246
+ P,
247
+ F
248
+ ]), Se = t((e) => {
249
+ let t = (e - 90) * Math.PI / 180, n = xe();
250
+ return {
251
+ x: Y.x + n * Math.cos(t),
252
+ y: Y.y + n * Math.sin(t)
253
+ };
254
+ }, [
255
+ Y.x,
256
+ Y.y,
257
+ xe
258
+ ]), Ce = (e, t) => {
259
+ let n = e - Y.x, r = t - Y.y, i = Math.atan2(r, n) * 180 / Math.PI;
260
+ return X(i + 90);
261
+ }, we = t(() => {
262
+ let e = [];
263
+ e = A === "monochromatic" ? [
264
+ {
265
+ h: q,
266
+ l: 30
267
+ },
268
+ {
269
+ h: q,
270
+ l: 50
271
+ },
272
+ {
273
+ h: q,
274
+ l: 70
275
+ }
276
+ ] : u[A].map((e) => ({
277
+ h: X(q + e),
278
+ l: M
279
+ }));
280
+ let t = e.map((e) => {
281
+ let t = ye(e.h, j, e.l);
282
+ return be(t.r, t.g, t.b);
283
+ });
284
+ return { [A]: t };
285
+ }, [
286
+ A,
287
+ q,
288
+ j,
289
+ M
290
+ ]), Te = t((e) => {
291
+ for (let t = 0; t < 360; t++) e.beginPath(), e.strokeStyle = `hsl(${t},100%,50%)`, e.lineWidth = F, e.arc(Y.x, Y.y, P, (t - 90) * Math.PI / 180, (t - 89) * Math.PI / 180), e.stroke();
292
+ }, [
293
+ Y.x,
294
+ Y.y,
295
+ P,
296
+ F
297
+ ]), Ee = t((e, t) => {
298
+ !B || t.length < 3 || (e.beginPath(), e.moveTo(t[0].x, t[0].y), t.slice(1).forEach((t) => {
299
+ e.lineTo(t.x, t.y);
300
+ }), e.closePath(), e.strokeStyle = V, e.lineWidth = H, e.stroke());
301
+ }, [
302
+ B,
303
+ V,
304
+ H
305
+ ]), De = t((e) => {
306
+ if (A === "simple") return;
307
+ let t = u[A], n = [];
308
+ t.forEach((t) => {
309
+ let r = X(q + t), i = Se(r);
310
+ n.push(i), e.beginPath(), e.moveTo(Y.x, Y.y), e.lineTo(i.x, i.y), e.strokeStyle = z, e.lineWidth = R, e.stroke(), e.beginPath(), e.arc(i.x, i.y, I, 0, Math.PI * 2), e.fillStyle = Z(r), e.fill(), e.strokeStyle = "white", e.stroke();
311
+ }), Ee(e, n), W && (e.beginPath(), e.arc(Y.x, Y.y, 5, 0, Math.PI * 2), e.fillStyle = U, e.fill(), e.strokeStyle = "white", e.lineWidth = 1, e.stroke());
312
+ }, [
313
+ A,
314
+ q,
315
+ Y.x,
316
+ Y.y,
317
+ I,
318
+ R,
319
+ z,
320
+ U,
321
+ W,
322
+ Se,
323
+ Z,
324
+ Ee
325
+ ]), Oe = t(() => {
326
+ let e = E.current;
327
+ if (!e) return;
328
+ let t = e.getContext("2d");
329
+ t && (t.clearRect(0, 0, e.width, e.height), K && K !== "transparent" ? (t.fillStyle = K, t.fillRect(0, 0, e.width, e.height)) : K === "transparent" && (t.fillStyle = O ? "#1a1a1a" : "#ffffff", t.fillRect(0, 0, e.width, e.height)), Te(t), De(t), G && (t.strokeStyle = G, t.lineWidth = 1, t.strokeRect(0, 0, e.width, e.height)));
330
+ }, [
331
+ Te,
332
+ De,
333
+ G,
334
+ K,
335
+ O
336
+ ]), ke = () => D(!0), Ae = () => D(!1), je = () => D(!1), Me = (e) => {
337
+ if (!ne) return;
338
+ let t = E.current;
339
+ if (!t) return;
340
+ let n = t.getBoundingClientRect(), r = Ce(e.clientX - n.left, e.clientY - n.top);
341
+ J(r);
342
+ }, Ne = (e) => {
343
+ let t = E.current;
344
+ if (!t) return;
345
+ let n = t.getBoundingClientRect(), r = Ce(e.clientX - n.left, e.clientY - n.top);
346
+ J(r);
347
+ };
348
+ r(() => {
349
+ Oe();
350
+ }, [Oe]);
351
+ let Q = i(() => we(), [we]);
352
+ r(() => {
353
+ e && e(Q);
354
+ }, [Q, e]);
355
+ let $ = t(() => Q, [Q]);
356
+ return r(() => (window.getColorWheelPalette = $, () => {
357
+ delete window.getColorWheelPalette;
358
+ }), [$]), /* @__PURE__ */ s("div", {
359
+ className: "color-wheel-container",
360
+ children: /* @__PURE__ */ s("canvas", {
361
+ ref: E,
362
+ width: w,
363
+ height: T,
364
+ onMouseDown: ke,
365
+ onMouseUp: Ae,
366
+ onMouseLeave: je,
367
+ onMouseMove: Me,
368
+ onClick: Ne,
369
+ style: {
370
+ display: "block",
371
+ margin: "0 auto",
372
+ cursor: "pointer"
373
+ }
374
+ })
375
+ });
359
376
  }
360
- export {
361
- Qe as ColorWheel,
362
- Ke as ThemeProvider,
363
- Be as useTheme
364
- };
377
+ export { d as ColorWheel, l as ThemeProvider, ee as useTheme };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiotoolkit/color-wheel",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "license": "MIT",
5
5
  "description": "Interactive color wheel React component for creating and manipulating color harmonies with multiple harmony modes",
6
6
  "author": "StudioToolkit",
@@ -53,17 +53,6 @@
53
53
  "engines": {
54
54
  "node": ">=16.0.0"
55
55
  },
56
- "peerDependencies": {
57
- "react": "^18.0.0 || ^19.0.0",
58
- "react-dom": "^18.0.0 || ^19.0.0"
59
- },
60
- "devDependencies": {
61
- "@types/react": "^18.2.0 || ^19.0.0",
62
- "@types/react-dom": "^18.2.0 || ^19.0.0",
63
- "@vitejs/plugin-react": "^4.2.0",
64
- "typescript": "^5.3.3",
65
- "vite": "^5.0.0"
66
- },
67
56
  "scripts": {
68
57
  "build": "npx tsc --project tsconfig.json && vite build && cp src/ColorWheel.css dist/style.css",
69
58
  "dev": "vite build --watch",
@@ -72,6 +61,20 @@
72
61
  "lint:fix": "eslint src --ext .ts,.tsx --fix",
73
62
  "test": "vitest run",
74
63
  "test:watch": "vitest",
75
- "test:ui": "vitest --ui"
64
+ "test:ui": "vitest --ui",
65
+ "prepublishOnly": "pnpm run build && pnpm test"
66
+ },
67
+ "peerDependencies": {
68
+ "react": "^18.0.0 || ^19.0.0",
69
+ "react-dom": "^18.0.0 || ^19.0.0"
70
+ },
71
+ "devDependencies": {
72
+ "@types/react": "^19.3.0",
73
+ "@types/react-dom": "^19.3.0",
74
+ "@vitejs/plugin-react": "^6.2.1",
75
+ "react": "^19.3.1",
76
+ "react-dom": "^19.3.1",
77
+ "typescript": "^6.0.3",
78
+ "vite": "^8.3.6"
76
79
  }
77
- }
80
+ }