@studiotoolkit/color-palette 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.
@@ -26,6 +26,6 @@ interface ColorPaletteProps {
26
26
  /** Brightness for Part 2 (middle band) (0 = black, 50 = mid-tone, 100 = white). Default 50. */
27
27
  brightness2?: number;
28
28
  }
29
- export default function ColorPalette({ paletteData, showCopyButton, displayType, width, boxBorderSize, boxBorderColor, displayTitle, fontColor, fontSize, backgroundColor, displayHexcode, parts, saturation1, brightness1, saturation2, brightness2, }: ColorPaletteProps): import("react/jsx-runtime").JSX.Element | null;
29
+ export default function ColorPalette({ paletteData, showCopyButton, displayType, width, boxBorderSize, boxBorderColor, displayTitle, fontColor, fontSize, backgroundColor, displayHexcode, parts, saturation1, brightness1, saturation2, brightness2, }: ColorPaletteProps): import("react").JSX.Element | null;
30
30
  export {};
31
31
  //# sourceMappingURL=ColorPalette.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ColorPalette.d.ts","sourceRoot":"","sources":["../src/ColorPalette.tsx"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAE5B,KAAK,WAAW,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;CAAE,CAAC;AAC3D,KAAK,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAExE,UAAU,iBAAiB;IACzB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,yIAAyI;IACzI,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAClB,mGAAmG;IACnG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4FAA4F;IAC5F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sGAAsG;IACtG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+FAA+F;IAC/F,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAmMD,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,WAAW,EACX,cAAsB,EACtB,WAAqB,EACrB,KAAU,EACV,aAAiB,EACjB,cAAuB,EACvB,YAAmB,EACnB,SAAkB,EAClB,QAAa,EACb,eAA+B,EAC/B,cAAqB,EACrB,KAAS,EACT,WAAgB,EAChB,WAAgB,EAChB,WAAgB,EAChB,WAAgB,GACjB,EAAE,iBAAiB,kDAgJnB"}
1
+ {"version":3,"file":"ColorPalette.d.ts","sourceRoot":"","sources":["../src/ColorPalette.tsx"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAE5B,KAAK,WAAW,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;CAAE,CAAC;AAC3D,KAAK,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAExE,UAAU,iBAAiB;IACzB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,yIAAyI;IACzI,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAClB,mGAAmG;IACnG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4FAA4F;IAC5F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sGAAsG;IACtG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+FAA+F;IAC/F,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAmMD,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,WAAW,EACX,cAAsB,EACtB,WAAqB,EACrB,KAAU,EACV,aAAiB,EACjB,cAAuB,EACvB,YAAmB,EACnB,SAAkB,EAClB,QAAa,EACb,eAA+B,EAC/B,cAAqB,EACrB,KAAS,EACT,WAAgB,EAChB,WAAgB,EAChB,WAAgB,EAChB,WAAgB,GACjB,EAAE,iBAAiB,sCAgJnB"}
@@ -0,0 +1,2 @@
1
+ .color-palette-container{background-color:#fff;padding:5px}[data-theme=dark] .color-palette-container{background-color:#1a1a1a!important}.palette-section{margin-bottom:8px}.palette-section-header{justify-content:space-between;align-items:center;margin-bottom:8px;display:flex}.palette-section h3{margin:0;font-size:16px}.copy-section-button{color:#fff;cursor:pointer;background:#27ae60;border:none;border-radius:4px;padding:4px 10px;font-size:12px}.copy-section-button:hover{background:#1e8449}.colors{flex-wrap:wrap;gap:6px;display:flex}.swatchBox{text-align:center;font-size:12px}.palette-table{border-collapse:collapse;border:1px solid #ddd}.palette-table .color-cell{border:1px solid #ddd;padding:0}.palette-table .hex-cell{text-align:center;color:#333;background:#fff;border:1px solid #ddd;padding:4px 2px;font-family:monospace;font-size:11px}.hex-label{color:#333;font-family:monospace;font-size:11px;display:block}[data-theme=dark] .palette-section h3{color:#e0e0e0}[data-theme=dark] .copy-section-button{background:#2ecc71}[data-theme=dark] .copy-section-button:hover{background:#27ae60}[data-theme=dark] .palette-table,[data-theme=dark] .palette-table .color-cell{border-color:#444}[data-theme=dark] .palette-table .hex-cell{color:#e0e0e0;background:#2a2a2a;border-color:#444}[data-theme=dark] .hex-label{color:#e0e0e0}
2
+ /*$vite$:1*/
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),O=e=>({r:parseInt(e.slice(1,3),16)/255,g:parseInt(e.slice(3,5),16)/255,b:parseInt(e.slice(5,7),16)/255}),z=({r:e,g:r,b:t})=>"#"+[e,r,t].map(s=>Math.round(Math.max(0,Math.min(1,s))*255).toString(16).padStart(2,"0")).join(""),C=({r:e,g:r,b:t})=>{const s=Math.max(e,r,t),o=Math.min(e,r,t),l=(s+o)/2;if(s===o)return{h:0,s:0,l};const c=s-o,a=l>.5?c/(2-s-o):c/(s+o);let n=0;return s===e?n=((r-t)/c+(r<t?6:0))/6:s===r?n=((t-e)/c+2)/6:n=((e-r)/c+4)/6,{h:n,s:a,l}},H=({h:e,s:r,l:t})=>{if(r===0)return{r:t,g:t,b:t};const s=t<.5?t*(1+r):t+r-t*r,o=2*t-s,l=(c,a,n)=>(n<0&&(n+=1),n>1&&(n-=1),n<1/6?c+(a-c)*6*n:n<1/2?a:n<2/3?c+(a-c)*(2/3-n)*6:c);return{r:l(o,s,e+1/3),g:l(o,s,e),b:l(o,s,e-1/3)}},h=(e,r,t)=>{const s=O(e),o=C(s),l=Math.max(0,Math.min(100,r)),c=Math.max(0,Math.min(100,t)),a=l/100,n=c/100;return z(H({h:o.h,s:a,l:n}))};function T({hex:e,parts:r,saturation1:t,brightness1:s,saturation2:o,brightness2:l,displayType:c,width:a,borderSize:n,borderColor:p}){const d=[];r===1?d.push(h(e,t,s)):r===2?(d.push(h(e,t,s)),d.push(h(e,o,l))):(d.push(h(e,t,s)),d.push(h(e,o,l)),d.push(e));const x={width:a,height:a,overflow:"hidden",flexShrink:0,position:"relative",border:`${n}px solid ${p}`,boxSizing:"border-box",...c==="circle"?{borderRadius:"50%"}:c==="square"?{borderRadius:0}:c==="triangle"?{borderRadius:0,clipPath:"polygon(50% 0%, 0% 100%, 100% 100%)",border:"none"}:{borderRadius:10}};if(r===1)return i.jsx("div",{style:{...x,background:h(e,t,s)}});const j=100/d.length;return i.jsx("div",{style:x,children:d.map((v,g)=>i.jsx("div",{style:{position:"absolute",left:0,right:0,top:`${g*j}%`,height:`${j}%`,background:v}},g))})}function k({paletteData:e,showCopyButton:r=!1,displayType:t="block",width:s=60,boxBorderSize:o=1,boxBorderColor:l="#ccc",displayTitle:c=!0,fontColor:a="#333",fontSize:n=11,backgroundColor:p="transparent",displayHexcode:d=!0,parts:x=1,saturation1:j=50,brightness1:v=50,saturation2:g=50,brightness2:w=50}){if(!e)return null;const A=async(u,m)=>{try{await navigator.clipboard.writeText(JSON.stringify({[u]:m},null,2))}catch{}},N=x,$=j,M=v,R=g,P=w;return i.jsx("div",{className:"color-palette-container",style:p!=="transparent"?{backgroundColor:p}:void 0,children:Object.keys(e).map(u=>{if(Array.isArray(e[u])&&e[u].length>0){const m=e[u];return i.jsxs("div",{className:"palette-section",children:[i.jsxs("div",{className:"palette-section-header",children:[c&&i.jsx("h3",{children:u}),r&&i.jsx("button",{onClick:()=>A(u,m),className:"copy-section-button",children:"Copy"})]}),t==="table"?i.jsx("table",{className:"palette-table",children:i.jsxs("tbody",{children:[Array.from({length:N}).map((b,f)=>i.jsx("tr",{children:m.map((S,B)=>{let y=S;return f===0?y=h(S,$,M):f===1&&(y=h(S,R,P)),i.jsx("td",{className:"color-cell",style:{background:y,width:`${s}px`,height:`${s}px`,borderWidth:`${o}px`,borderColor:l}},B)})},`part-${f}`)),d&&i.jsx("tr",{children:m.map((b,f)=>i.jsx("td",{className:"hex-cell",style:{...a!=="#333"&&{color:a},fontSize:`${n}px`},children:b},f))})]})}):i.jsx("div",{className:`colors display-${t}`,children:m.map((b,f)=>i.jsxs("div",{className:"swatchBox",children:[i.jsx(T,{hex:b,parts:N,saturation1:$,brightness1:M,saturation2:R,brightness2:P,displayType:t,width:s,borderSize:o,borderColor:l}),d&&i.jsx("span",{className:"hex-label",style:{...a!=="#333"&&{color:a},fontSize:`${n}px`},children:b})]},f))})]},u)}return null})})}exports.ColorPalette=k;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react/jsx-runtime");var t=e=>({r:parseInt(e.slice(1,3),16)/255,g:parseInt(e.slice(3,5),16)/255,b:parseInt(e.slice(5,7),16)/255}),n=({r:e,g:t,b:n})=>`#`+[e,t,n].map(e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,`0`)).join(``),r=({r:e,g:t,b:n})=>{let r=Math.max(e,t,n),i=Math.min(e,t,n),a=(r+i)/2;if(r===i)return{h:0,s:0,l:a};let o=r-i,s=a>.5?o/(2-r-i):o/(r+i),c=0;return c=r===e?((t-n)/o+(t<n?6:0))/6:r===t?((n-e)/o+2)/6:((e-t)/o+4)/6,{h:c,s,l:a}},i=({h:e,s:t,l:n})=>{if(t===0)return{r:n,g:n,b:n};let r=n<.5?n*(1+t):n+t-n*t,i=2*n-r,a=(e,t,n)=>(n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e);return{r:a(i,r,e+1/3),g:a(i,r,e),b:a(i,r,e-1/3)}},a=(e,a,o)=>{let s=r(t(e)),c=Math.max(0,Math.min(100,a)),l=Math.max(0,Math.min(100,o)),u=c/100,d=l/100;return n(i({h:s.h,s:u,l:d}))};function o({hex:t,parts:n,saturation1:r,brightness1:i,saturation2:o,brightness2:s,displayType:c,width:l,borderSize:u,borderColor:d}){let f=[];n===1?f.push(a(t,r,i)):n===2?(f.push(a(t,r,i)),f.push(a(t,o,s))):(f.push(a(t,r,i)),f.push(a(t,o,s)),f.push(t));let p={width:l,height:l,overflow:`hidden`,flexShrink:0,position:`relative`,border:`${u}px solid ${d}`,boxSizing:`border-box`,...c===`circle`?{borderRadius:`50%`}:c===`square`?{borderRadius:0}:c===`triangle`?{borderRadius:0,clipPath:`polygon(50% 0%, 0% 100%, 100% 100%)`,border:`none`}:{borderRadius:10}};if(n===1)return(0,e.jsx)(`div`,{style:{...p,background:a(t,r,i)}});let m=100/f.length;return(0,e.jsx)(`div`,{style:p,children:f.map((t,n)=>(0,e.jsx)(`div`,{style:{position:`absolute`,left:0,right:0,top:`${n*m}%`,height:`${m}%`,background:t}},n))})}function s({paletteData:t,showCopyButton:n=!1,displayType:r=`block`,width:i=60,boxBorderSize:s=1,boxBorderColor:c=`#ccc`,displayTitle:l=!0,fontColor:u=`#333`,fontSize:d=11,backgroundColor:f=`transparent`,displayHexcode:p=!0,parts:m=1,saturation1:h=50,brightness1:g=50,saturation2:_=50,brightness2:v=50}){if(!t)return null;let y=async(e,t)=>{try{await navigator.clipboard.writeText(JSON.stringify({[e]:t},null,2))}catch{}},b=m,x=h,S=g,C=_,w=v;return(0,e.jsx)(`div`,{className:`color-palette-container`,style:f===`transparent`?void 0:{backgroundColor:f},children:Object.keys(t).map(f=>{if(Array.isArray(t[f])&&t[f].length>0){let m=t[f];return(0,e.jsxs)(`div`,{className:`palette-section`,children:[(0,e.jsxs)(`div`,{className:`palette-section-header`,children:[l&&(0,e.jsx)(`h3`,{children:f}),n&&(0,e.jsx)(`button`,{onClick:()=>y(f,m),className:`copy-section-button`,children:`Copy`})]}),r===`table`?(0,e.jsx)(`table`,{className:`palette-table`,children:(0,e.jsxs)(`tbody`,{children:[Array.from({length:b}).map((t,n)=>(0,e.jsx)(`tr`,{children:m.map((t,r)=>{let o=t;return n===0?o=a(t,x,S):n===1&&(o=a(t,C,w)),(0,e.jsx)(`td`,{className:`color-cell`,style:{background:o,width:`${i}px`,height:`${i}px`,borderWidth:`${s}px`,borderColor:c}},r)})},`part-${n}`)),p&&(0,e.jsx)(`tr`,{children:m.map((t,n)=>(0,e.jsx)(`td`,{className:`hex-cell`,style:{...u!==`#333`&&{color:u},fontSize:`${d}px`},children:t},n))})]})}):(0,e.jsx)(`div`,{className:`colors display-${r}`,children:m.map((t,n)=>(0,e.jsxs)(`div`,{className:`swatchBox`,children:[(0,e.jsx)(o,{hex:t,parts:b,saturation1:x,brightness1:S,saturation2:C,brightness2:w,displayType:r,width:i,borderSize:s,borderColor:c}),p&&(0,e.jsx)(`span`,{className:`hex-label`,style:{...u!==`#333`&&{color:u},fontSize:`${d}px`},children:t})]},n))})]},f)}return null})})}exports.ColorPalette=s;
package/dist/index.mjs CHANGED
@@ -1,219 +1,153 @@
1
- import { jsx as a, jsxs as N } from "react/jsx-runtime";
2
- const H = (e) => ({
3
- r: parseInt(e.slice(1, 3), 16) / 255,
4
- g: parseInt(e.slice(3, 5), 16) / 255,
5
- b: parseInt(e.slice(5, 7), 16) / 255
6
- }), O = ({ r: e, g: n, b: t }) => "#" + [e, n, t].map(
7
- (r) => Math.round(Math.max(0, Math.min(1, r)) * 255).toString(16).padStart(2, "0")
8
- ).join(""), k = ({
9
- r: e,
10
- g: n,
11
- b: t
12
- }) => {
13
- const r = Math.max(e, n, t), i = Math.min(e, n, t), o = (r + i) / 2;
14
- if (r === i) return { h: 0, s: 0, l: o };
15
- const s = r - i, l = o > 0.5 ? s / (2 - r - i) : s / (r + i);
16
- let c = 0;
17
- return r === e ? c = ((n - t) / s + (n < t ? 6 : 0)) / 6 : r === n ? c = ((t - e) / s + 2) / 6 : c = ((e - n) / s + 4) / 6, { h: c, s: l, l: o };
18
- }, C = ({
19
- h: e,
20
- s: n,
21
- l: t
22
- }) => {
23
- if (n === 0) return { r: t, g: t, b: t };
24
- const r = t < 0.5 ? t * (1 + n) : t + n - t * n, i = 2 * t - r, o = (s, l, c) => (c < 0 && (c += 1), c > 1 && (c -= 1), c < 1 / 6 ? s + (l - s) * 6 * c : c < 1 / 2 ? l : c < 2 / 3 ? s + (l - s) * (2 / 3 - c) * 6 : s);
25
- return {
26
- r: o(i, r, e + 1 / 3),
27
- g: o(i, r, e),
28
- b: o(i, r, e - 1 / 3)
29
- };
30
- }, u = (e, n, t) => {
31
- const r = H(e), i = k(r), o = Math.max(0, Math.min(100, n)), s = Math.max(0, Math.min(100, t)), l = o / 100, c = s / 100;
32
- return O(C({ h: i.h, s: l, l: c }));
1
+ import { jsx as e, jsxs as t } from "react/jsx-runtime";
2
+ // src/ColorPalette.tsx
3
+ var n = (e) => ({
4
+ r: parseInt(e.slice(1, 3), 16) / 255,
5
+ g: parseInt(e.slice(3, 5), 16) / 255,
6
+ b: parseInt(e.slice(5, 7), 16) / 255
7
+ }), r = ({ r: e, g: t, b: n }) => "#" + [
8
+ e,
9
+ t,
10
+ n
11
+ ].map((e) => Math.round(Math.max(0, Math.min(1, e)) * 255).toString(16).padStart(2, "0")).join(""), i = ({ r: e, g: t, b: n }) => {
12
+ let r = Math.max(e, t, n), i = Math.min(e, t, n), a = (r + i) / 2;
13
+ if (r === i) return {
14
+ h: 0,
15
+ s: 0,
16
+ l: a
17
+ };
18
+ let o = r - i, s = a > .5 ? o / (2 - r - i) : o / (r + i), c = 0;
19
+ return c = r === e ? ((t - n) / o + (t < n ? 6 : 0)) / 6 : r === t ? ((n - e) / o + 2) / 6 : ((e - t) / o + 4) / 6, {
20
+ h: c,
21
+ s,
22
+ l: a
23
+ };
24
+ }, a = ({ h: e, s: t, l: n }) => {
25
+ if (t === 0) return {
26
+ r: n,
27
+ g: n,
28
+ b: n
29
+ };
30
+ let r = n < .5 ? n * (1 + t) : n + t - n * t, i = 2 * n - r, a = (e, t, n) => (n < 0 && (n += 1), n > 1 && --n, n < 1 / 6 ? e + (t - e) * 6 * n : n < 1 / 2 ? t : n < 2 / 3 ? e + (t - e) * (2 / 3 - n) * 6 : e);
31
+ return {
32
+ r: a(i, r, e + 1 / 3),
33
+ g: a(i, r, e),
34
+ b: a(i, r, e - 1 / 3)
35
+ };
36
+ }, o = (e, t, o) => {
37
+ let s = i(n(e)), c = Math.max(0, Math.min(100, t)), l = Math.max(0, Math.min(100, o)), u = c / 100, d = l / 100;
38
+ return r(a({
39
+ h: s.h,
40
+ s: u,
41
+ l: d
42
+ }));
33
43
  };
34
- function I({
35
- hex: e,
36
- parts: n,
37
- saturation1: t,
38
- brightness1: r,
39
- saturation2: i,
40
- brightness2: o,
41
- displayType: s,
42
- width: l,
43
- borderSize: c,
44
- borderColor: b
45
- }) {
46
- const d = [];
47
- n === 1 ? d.push(u(e, t, r)) : n === 2 ? (d.push(u(e, t, r)), d.push(u(e, i, o))) : (d.push(u(e, t, r)), d.push(u(e, i, o)), d.push(e));
48
- const g = {
49
- width: l,
50
- height: l,
51
- overflow: "hidden",
52
- flexShrink: 0,
53
- position: "relative",
54
- border: `${c}px solid ${b}`,
55
- boxSizing: "border-box",
56
- ...s === "circle" ? { borderRadius: "50%" } : s === "square" ? { borderRadius: 0 } : s === "triangle" ? {
57
- borderRadius: 0,
58
- clipPath: "polygon(50% 0%, 0% 100%, 100% 100%)",
59
- border: "none"
60
- } : { borderRadius: 10 }
61
- // block default
62
- };
63
- if (n === 1)
64
- return /* @__PURE__ */ a(
65
- "div",
66
- {
67
- style: {
68
- ...g,
69
- background: u(e, t, r)
70
- }
71
- }
72
- );
73
- const v = 100 / d.length;
74
- return /* @__PURE__ */ a("div", { style: g, children: d.map(($, S) => /* @__PURE__ */ a(
75
- "div",
76
- {
77
- style: {
78
- position: "absolute",
79
- left: 0,
80
- right: 0,
81
- top: `${S * v}%`,
82
- height: `${v}%`,
83
- background: $
84
- }
85
- },
86
- S
87
- )) });
44
+ function s({ hex: t, parts: n, saturation1: r, brightness1: i, saturation2: a, brightness2: s, displayType: c, width: l, borderSize: u, borderColor: d }) {
45
+ let f = [];
46
+ n === 1 ? f.push(o(t, r, i)) : n === 2 ? (f.push(o(t, r, i)), f.push(o(t, a, s))) : (f.push(o(t, r, i)), f.push(o(t, a, s)), f.push(t));
47
+ let p = {
48
+ width: l,
49
+ height: l,
50
+ overflow: "hidden",
51
+ flexShrink: 0,
52
+ position: "relative",
53
+ border: `${u}px solid ${d}`,
54
+ boxSizing: "border-box",
55
+ ...c === "circle" ? { borderRadius: "50%" } : c === "square" ? { borderRadius: 0 } : c === "triangle" ? {
56
+ borderRadius: 0,
57
+ clipPath: "polygon(50% 0%, 0% 100%, 100% 100%)",
58
+ border: "none"
59
+ } : { borderRadius: 10 }
60
+ };
61
+ if (n === 1) return /* @__PURE__ */ e("div", { style: {
62
+ ...p,
63
+ background: o(t, r, i)
64
+ } });
65
+ let m = 100 / f.length;
66
+ return /* @__PURE__ */ e("div", {
67
+ style: p,
68
+ children: f.map((t, n) => /* @__PURE__ */ e("div", { style: {
69
+ position: "absolute",
70
+ left: 0,
71
+ right: 0,
72
+ top: `${n * m}%`,
73
+ height: `${m}%`,
74
+ background: t
75
+ } }, n))
76
+ });
88
77
  }
89
- function L({
90
- paletteData: e,
91
- showCopyButton: n = !1,
92
- displayType: t = "block",
93
- width: r = 60,
94
- boxBorderSize: i = 1,
95
- boxBorderColor: o = "#ccc",
96
- displayTitle: s = !0,
97
- fontColor: l = "#333",
98
- fontSize: c = 11,
99
- backgroundColor: b = "transparent",
100
- displayHexcode: d = !0,
101
- parts: g = 1,
102
- saturation1: v = 50,
103
- brightness1: $ = 50,
104
- saturation2: S = 50,
105
- brightness2: A = 50
106
- }) {
107
- if (!e) return null;
108
- const B = async (h, m) => {
109
- try {
110
- await navigator.clipboard.writeText(
111
- JSON.stringify({ [h]: m }, null, 2)
112
- );
113
- } catch {
114
- }
115
- }, x = g, R = v, w = $, j = S, P = A;
116
- return /* @__PURE__ */ a(
117
- "div",
118
- {
119
- className: "color-palette-container",
120
- style: b !== "transparent" ? { backgroundColor: b } : void 0,
121
- children: Object.keys(e).map((h) => {
122
- if (Array.isArray(e[h]) && e[h].length > 0) {
123
- const m = e[h];
124
- return /* @__PURE__ */ N("div", { className: "palette-section", children: [
125
- /* @__PURE__ */ N("div", { className: "palette-section-header", children: [
126
- s && /* @__PURE__ */ a("h3", { children: h }),
127
- n && /* @__PURE__ */ a(
128
- "button",
129
- {
130
- onClick: () => B(h, m),
131
- className: "copy-section-button",
132
- children: "Copy"
133
- }
134
- )
135
- ] }),
136
- t === "table" ? (
137
- /* ── Table layout ── */
138
- /* @__PURE__ */ a("table", { className: "palette-table", children: /* @__PURE__ */ N("tbody", { children: [
139
- Array.from({ length: x }).map(
140
- (p, f) => /* @__PURE__ */ a("tr", { children: m.map((y, z) => {
141
- let M = y;
142
- return f === 0 ? M = u(
143
- y,
144
- R,
145
- w
146
- ) : f === 1 && (M = u(
147
- y,
148
- j,
149
- P
150
- )), /* @__PURE__ */ a(
151
- "td",
152
- {
153
- className: "color-cell",
154
- style: {
155
- background: M,
156
- width: `${r}px`,
157
- height: `${r}px`,
158
- borderWidth: `${i}px`,
159
- borderColor: o
160
- }
161
- },
162
- z
163
- );
164
- }) }, `part-${f}`)
165
- ),
166
- d && /* @__PURE__ */ a("tr", { children: m.map((p, f) => /* @__PURE__ */ a(
167
- "td",
168
- {
169
- className: "hex-cell",
170
- style: {
171
- ...l !== "#333" && { color: l },
172
- fontSize: `${c}px`
173
- },
174
- children: p
175
- },
176
- f
177
- )) })
178
- ] }) })
179
- ) : (
180
- /* ── Swatch layout ── */
181
- /* @__PURE__ */ a("div", { className: `colors display-${t}`, children: m.map((p, f) => /* @__PURE__ */ N("div", { className: "swatchBox", children: [
182
- /* @__PURE__ */ a(
183
- I,
184
- {
185
- hex: p,
186
- parts: x,
187
- saturation1: R,
188
- brightness1: w,
189
- saturation2: j,
190
- brightness2: P,
191
- displayType: t,
192
- width: r,
193
- borderSize: i,
194
- borderColor: o
195
- }
196
- ),
197
- d && /* @__PURE__ */ a(
198
- "span",
199
- {
200
- className: "hex-label",
201
- style: {
202
- ...l !== "#333" && { color: l },
203
- fontSize: `${c}px`
204
- },
205
- children: p
206
- }
207
- )
208
- ] }, f)) })
209
- )
210
- ] }, h);
211
- }
212
- return null;
213
- })
214
- }
215
- );
78
+ function c({ paletteData: n, showCopyButton: r = !1, displayType: i = "block", width: a = 60, boxBorderSize: c = 1, boxBorderColor: l = "#ccc", displayTitle: u = !0, fontColor: d = "#333", fontSize: f = 11, backgroundColor: p = "transparent", displayHexcode: m = !0, parts: h = 1, saturation1: g = 50, brightness1: _ = 50, saturation2: v = 50, brightness2: y = 50 }) {
79
+ if (!n) return null;
80
+ let b = async (e, t) => {
81
+ try {
82
+ await navigator.clipboard.writeText(JSON.stringify({ [e]: t }, null, 2));
83
+ } catch {}
84
+ }, x = h, S = g, C = _, w = v, T = y;
85
+ return /* @__PURE__ */ e("div", {
86
+ className: "color-palette-container",
87
+ style: p === "transparent" ? void 0 : { backgroundColor: p },
88
+ children: Object.keys(n).map((p) => {
89
+ if (Array.isArray(n[p]) && n[p].length > 0) {
90
+ let h = n[p];
91
+ return /* @__PURE__ */ t("div", {
92
+ className: "palette-section",
93
+ children: [/* @__PURE__ */ t("div", {
94
+ className: "palette-section-header",
95
+ children: [u && /* @__PURE__ */ e("h3", { children: p }), r && /* @__PURE__ */ e("button", {
96
+ onClick: () => b(p, h),
97
+ className: "copy-section-button",
98
+ children: "Copy"
99
+ })]
100
+ }), i === "table" ? /* @__PURE__ */ e("table", {
101
+ className: "palette-table",
102
+ children: /* @__PURE__ */ t("tbody", { children: [Array.from({ length: x }).map((t, n) => /* @__PURE__ */ e("tr", { children: h.map((t, r) => {
103
+ let i = t;
104
+ return n === 0 ? i = o(t, S, C) : n === 1 && (i = o(t, w, T)), /* @__PURE__ */ e("td", {
105
+ className: "color-cell",
106
+ style: {
107
+ background: i,
108
+ width: `${a}px`,
109
+ height: `${a}px`,
110
+ borderWidth: `${c}px`,
111
+ borderColor: l
112
+ }
113
+ }, r);
114
+ }) }, `part-${n}`)), m && /* @__PURE__ */ e("tr", { children: h.map((t, n) => /* @__PURE__ */ e("td", {
115
+ className: "hex-cell",
116
+ style: {
117
+ ...d !== "#333" && { color: d },
118
+ fontSize: `${f}px`
119
+ },
120
+ children: t
121
+ }, n)) })] })
122
+ }) : /* @__PURE__ */ e("div", {
123
+ className: `colors display-${i}`,
124
+ children: h.map((n, r) => /* @__PURE__ */ t("div", {
125
+ className: "swatchBox",
126
+ children: [/* @__PURE__ */ e(s, {
127
+ hex: n,
128
+ parts: x,
129
+ saturation1: S,
130
+ brightness1: C,
131
+ saturation2: w,
132
+ brightness2: T,
133
+ displayType: i,
134
+ width: a,
135
+ borderSize: c,
136
+ borderColor: l
137
+ }), m && /* @__PURE__ */ e("span", {
138
+ className: "hex-label",
139
+ style: {
140
+ ...d !== "#333" && { color: d },
141
+ fontSize: `${f}px`
142
+ },
143
+ children: n
144
+ })]
145
+ }, r))
146
+ })]
147
+ }, p);
148
+ }
149
+ return null;
150
+ })
151
+ });
216
152
  }
217
- export {
218
- L as ColorPalette
219
- };
153
+ export { c as ColorPalette };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiotoolkit/color-palette",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "license": "MIT",
5
5
  "description": "React component for displaying and managing color palettes with multiple display modes and customization options",
6
6
  "author": "StudioToolkit",
@@ -50,17 +50,6 @@
50
50
  "engines": {
51
51
  "node": ">=16.0.0"
52
52
  },
53
- "peerDependencies": {
54
- "react": "^18.0.0 || ^19.0.0",
55
- "react-dom": "^18.0.0 || ^19.0.0"
56
- },
57
- "devDependencies": {
58
- "@types/react": "^18.2.0 || ^19.0.0",
59
- "@types/react-dom": "^18.2.0 || ^19.0.0",
60
- "@vitejs/plugin-react": "^4.2.0",
61
- "typescript": "^5.3.3",
62
- "vite": "^5.0.0"
63
- },
64
53
  "scripts": {
65
54
  "build": "npx tsc --project tsconfig.json && vite build && cp src/ColorPalette.css dist/style.css",
66
55
  "dev": "vite build --watch",
@@ -69,6 +58,20 @@
69
58
  "lint:fix": "eslint src --ext .ts,.tsx --fix",
70
59
  "test": "vitest run",
71
60
  "test:watch": "vitest",
72
- "test:ui": "vitest --ui"
61
+ "test:ui": "vitest --ui",
62
+ "prepublishOnly": "pnpm run build && pnpm test"
63
+ },
64
+ "peerDependencies": {
65
+ "react": "^18.0.0 || ^19.0.0",
66
+ "react-dom": "^18.0.0 || ^19.0.0"
67
+ },
68
+ "devDependencies": {
69
+ "@types/react": "^19.3.0",
70
+ "@types/react-dom": "^19.3.0",
71
+ "@vitejs/plugin-react": "^6.2.1",
72
+ "react": "^19.3.1",
73
+ "react-dom": "^19.3.1",
74
+ "typescript": "^6.0.3",
75
+ "vite": "^8.3.6"
73
76
  }
74
- }
77
+ }