@studiotoolkit/color-palette 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +102 -0
- package/dist/ColorPalette.d.ts +31 -0
- package/dist/ColorPalette.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +219 -0
- package/dist/style.css +1 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Studio Toolkit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Color Palette
|
|
2
|
+
|
|
3
|
+
React component for displaying and managing color palettes with multiple display modes and customization options.
|
|
4
|
+
|
|
5
|
+
**Play around and Generate component code here:**
|
|
6
|
+
https://studiotoolkit.github.io/build-color-palette
|
|
7
|
+
|
|
8
|
+
**Complete Demo:**
|
|
9
|
+
https://studiotoolkit.github.io/demo-all
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
<table>
|
|
14
|
+
<tr>
|
|
15
|
+
<td align="center"><img src="assets/Box.png" width="600"/><br/>Box</td>
|
|
16
|
+
</tr>
|
|
17
|
+
<tr>
|
|
18
|
+
<td align="center"><img src="assets/Circle.png" width="600"/><br/>Circle</td>
|
|
19
|
+
</tr>
|
|
20
|
+
<tr>
|
|
21
|
+
<td align="center"><img src="assets/Square.png" width="600"/><br/>Square</td>
|
|
22
|
+
</tr>
|
|
23
|
+
<tr>
|
|
24
|
+
<td align="center"><img src="assets/Triangle.png" width="600"/><br/>Triangle</td>
|
|
25
|
+
</tr>
|
|
26
|
+
<tr>
|
|
27
|
+
<td align="center"><img src="assets/Single-Tone.png" width="600"/><br/>Single Tone</td>
|
|
28
|
+
</tr>
|
|
29
|
+
<tr>
|
|
30
|
+
<td align="center"><img src="assets/Two-Tone.png" width="600"/><br/>Two Tone</td>
|
|
31
|
+
</tr>
|
|
32
|
+
<tr>
|
|
33
|
+
<tr>
|
|
34
|
+
<td align="center"><img src="assets/Settings.png" width="600"/><br/>Variation</td>
|
|
35
|
+
</tr>
|
|
36
|
+
<td align="center"><img src="assets/Parameters.png" width="600"/><br/>Parameters</td>
|
|
37
|
+
</tr>
|
|
38
|
+
|
|
39
|
+
</table>
|
|
40
|
+
|
|
41
|
+
- Multiple display modes: square, table, circle, triangle, block
|
|
42
|
+
- Multi-part color swatches (1, 2, or 3 parts) with saturation/brightness control
|
|
43
|
+
- Customizable dimensions (`width`)
|
|
44
|
+
- Border styling (`boxBorderSize`, `boxBorderColor`)
|
|
45
|
+
- Typography options (`displayTitle`, `fontColor`, `fontSize`)
|
|
46
|
+
- Background color customization (`backgroundColor`)
|
|
47
|
+
- Hex code display toggle (`displayHexcode`)
|
|
48
|
+
- Copy colors to clipboard (`showCopyButton`)
|
|
49
|
+
- Transform colors with adjustable saturation and brightness per part
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Using pnpm
|
|
55
|
+
pnpm add @studiotoolkit/color-palette
|
|
56
|
+
|
|
57
|
+
# Using npm
|
|
58
|
+
npm install @studiotoolkit/color-palette
|
|
59
|
+
|
|
60
|
+
# Using yarn
|
|
61
|
+
yarn add @studiotoolkit/color-palette
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**React Version:** `^18.0.0` or higher
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
### Basic Usage
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import { ColorPalette } from '@studiotoolkit/color-palette';
|
|
72
|
+
import '@studiotoolkit/color-palette/style.css';
|
|
73
|
+
|
|
74
|
+
function App() {
|
|
75
|
+
const paletteData = {
|
|
76
|
+
primary: ['#FF5733', '#33FF57', '#3357FF'],
|
|
77
|
+
secondary: ['#FFC300', '#DAF7A6', '#C70039'],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return <ColorPalette paletteData={paletteData} displayType="square" showCopyButton={true} />;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Steps to Use
|
|
85
|
+
|
|
86
|
+
1. Import the component and its styles
|
|
87
|
+
2. Prepare palette data as an object with string arrays
|
|
88
|
+
3. Add the `ColorPalette` component with desired display type
|
|
89
|
+
4. Customize appearance with optional props
|
|
90
|
+
5. Enable copy button to allow users to copy colors
|
|
91
|
+
|
|
92
|
+
## Contributors
|
|
93
|
+
|
|
94
|
+
[StudioToolkit](https://github.com/studiotoolkit)
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
Licensed under the MIT License.
|
|
99
|
+
|
|
100
|
+
## Keywords
|
|
101
|
+
|
|
102
|
+
color-palette, color-display, color-swatches, palette-viewer, color-management, design-tools, react-component, color-visualization
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "./ColorPalette.css";
|
|
2
|
+
type PaletteData = {
|
|
3
|
+
[key: string]: string[] | undefined;
|
|
4
|
+
};
|
|
5
|
+
type DisplayType = "square" | "table" | "circle" | "triangle" | "block";
|
|
6
|
+
interface ColorPaletteProps {
|
|
7
|
+
paletteData: PaletteData | null;
|
|
8
|
+
showCopyButton?: boolean;
|
|
9
|
+
displayType?: DisplayType;
|
|
10
|
+
width?: number;
|
|
11
|
+
boxBorderSize?: number;
|
|
12
|
+
boxBorderColor?: string;
|
|
13
|
+
displayTitle?: boolean;
|
|
14
|
+
fontColor?: string;
|
|
15
|
+
fontSize?: number;
|
|
16
|
+
backgroundColor?: string;
|
|
17
|
+
displayHexcode?: boolean;
|
|
18
|
+
/** How many color parts to show per swatch. 1 = transformed. 2 = transformed + transformed. 3 = transformed + transformed + original. */
|
|
19
|
+
parts?: 1 | 2 | 3;
|
|
20
|
+
/** Saturation for Part 1 (top band) (0 = fully desaturated, 100 = fully saturated). Default 50. */
|
|
21
|
+
saturation1?: number;
|
|
22
|
+
/** Brightness for Part 1 (top band) (0 = black, 50 = mid-tone, 100 = white). Default 50. */
|
|
23
|
+
brightness1?: number;
|
|
24
|
+
/** Saturation for Part 2 (middle band) (0 = fully desaturated, 100 = fully saturated). Default 50. */
|
|
25
|
+
saturation2?: number;
|
|
26
|
+
/** Brightness for Part 2 (middle band) (0 = black, 50 = mid-tone, 100 = white). Default 50. */
|
|
27
|
+
brightness2?: number;
|
|
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;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=ColorPalette.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +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;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
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 }));
|
|
33
|
+
};
|
|
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
|
+
)) });
|
|
88
|
+
}
|
|
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
|
+
);
|
|
216
|
+
}
|
|
217
|
+
export {
|
|
218
|
+
L as ColorPalette
|
|
219
|
+
};
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.color-palette-container{padding:5px;background-color:#fff}[data-theme=dark] .color-palette-container{background-color:#1a1a1a!important}.palette-section{margin-bottom:8px}.palette-section-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}.palette-section h3{margin:0;font-size:16px}.copy-section-button{padding:4px 10px;background:#27ae60;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:12px}.copy-section-button:hover{background:#1e8449}.colors{display:flex;flex-wrap:wrap;gap:6px}.swatchBox{text-align:center;font-size:12px}.palette-table{border-collapse:collapse;border:1px solid #ddd}.palette-table .color-cell{padding:0;border:1px solid #ddd}.palette-table .hex-cell{text-align:center;font-family:monospace;font-size:11px;color:#333;padding:4px 2px;border:1px solid #ddd;background:#fff}.hex-label{display:block;font-family:monospace;font-size:11px;color:#333}[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;border-color:#444;background:#2a2a2a}[data-theme=dark] .hex-label{color:#e0e0e0}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@studiotoolkit/color-palette",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "React component for displaying and managing color palettes with multiple display modes and customization options",
|
|
6
|
+
"author": "StudioToolkit",
|
|
7
|
+
"homepage": "https://studiotoolkit.github.io/build-color-palette",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/studiotoolkit/studiotoolkit",
|
|
11
|
+
"directory": "packages/color-palette"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/studiotoolkit/studiotoolkit/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"color-palette",
|
|
18
|
+
"color-display",
|
|
19
|
+
"color-swatches",
|
|
20
|
+
"palette-viewer",
|
|
21
|
+
"color-management",
|
|
22
|
+
"design-tools",
|
|
23
|
+
"react-component",
|
|
24
|
+
"color-visualization"
|
|
25
|
+
],
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"module": "./dist/index.mjs",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"sideEffects": [
|
|
30
|
+
"*.css"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.mjs",
|
|
36
|
+
"require": "./dist/index.js",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./style.css": "./dist/ColorPalette.css",
|
|
40
|
+
"./src/ColorPalette.css": "./src/ColorPalette.css",
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"README.md",
|
|
46
|
+
"LICENSE"
|
|
47
|
+
],
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=16.0.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"react": "^18.0.0",
|
|
56
|
+
"react-dom": "^18.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/react": "^18.2.0",
|
|
60
|
+
"@types/react-dom": "^18.2.0",
|
|
61
|
+
"@vitejs/plugin-react": "^4.2.0",
|
|
62
|
+
"typescript": "^5.3.3",
|
|
63
|
+
"vite": "^5.0.0"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "npx tsc --project tsconfig.json && vite build",
|
|
67
|
+
"dev": "vite build --watch",
|
|
68
|
+
"clean": "rm -rf dist",
|
|
69
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
70
|
+
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
71
|
+
"test": "vitest run",
|
|
72
|
+
"test:watch": "vitest",
|
|
73
|
+
"test:ui": "vitest --ui"
|
|
74
|
+
}
|
|
75
|
+
}
|