@nangmanhunter/colors-convert 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/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var R=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var d=(r,o)=>{for(var e in o)R(r,e,{get:o[e],enumerable:!0})},S=(r,o,e,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of y(o))!T.call(r,t)&&t!==e&&R(r,t,{get:()=>o[t],enumerable:!(s=M(o,t))||s.enumerable});return r};var $=r=>S(R({},"__esModule",{value:!0}),r);var k={};d(k,{inHexToHsl:()=>q,inHexToHsv:()=>z,inHexToRgb:()=>c,inHslToHex:()=>U,inHslToHsv:()=>j,inHslToRgb:()=>g,inHsvToHex:()=>C,inHsvToHsl:()=>I,inHsvToRgb:()=>a,inRgbToHex:()=>b,inRgbToHsl:()=>l,inRgbToHsv:()=>x});module.exports=$(k);function c(r){let o=r.replace("#",""),e=parseInt(o,16);return{r:e>>16&255,g:e>>8&255,b:e&255}}function l(r){let o=r.r/255,e=r.g/255,s=r.b/255,t=Math.max(o,e,s),i=Math.min(o,e,s),H=t-i,n=0,p=(t+i)/2,m=0;return H!==0&&(m=p>.5?H/(2-t-i):H/(t+i),t===o?n=(e-s)/H+(e<s?6:0):t===e?n=(s-o)/H+2:t===s&&(n=(o-e)/H+4),n=n*60),{h:Math.round(n),s:Math.round(m*100),l:Math.round(p*100)}}function q(r){return l(c(r))}function x(r){let o=r.r/255,e=r.g/255,s=r.b/255,t=Math.max(o,e,s),i=Math.min(o,e,s),H=t-i,n=0,p=t===0?0:H/t,m=t;return H!==0&&(t===o?n=(e-s)/H+(e<s?6:0):t===e?n=(s-o)/H+2:t===s&&(n=(o-e)/H+4),n=n*60),{h:Math.round(n),s:Math.round(p*100),v:Math.round(m*100)}}function z(r){return x(c(r))}function a(r){let{h:o,s:e,v:s}=r;if(e===0){let u=Math.round(s*255);return{r:u,g:u,b:u}}let t=Math.floor(o/60)%6,i=o/60-Math.floor(o/60),H=s*(1-e),n=s*(1-i*e),p=s*(1-(1-i)*e),m=[[s,p,H],[n,s,H],[H,s,p],[H,n,s],[p,H,s],[s,H,n]],[f,v,h]=m[t];return{r:Math.round(f*255),g:Math.round(v*255),b:Math.round(h*255)}}function b(r){let{r:o,g:e,b:s}=r,t=p=>Math.max(0,Math.min(255,Math.round(p))),i=t(o).toString(16).padStart(2,"0"),H=t(e).toString(16).padStart(2,"0"),n=t(s).toString(16).padStart(2,"0");return`#${i}${H}${n}`.toUpperCase()}function C(r){return b(a(r))}function I(r){return l(a(r))}function g(r){let{h:o,s:e,l:s}=r;if(e===0){let f=Math.round(s*255);return{r:f,g:f,b:f}}let t=(1-Math.abs(2*s-1))*e,i=t*(1-Math.abs(o/60%2-1)),H=s-t/2,n=0,p=0,m=0;return 0<=o&&o<60?(n=t,p=i,m=0):60<=o&&o<120?(n=i,p=t,m=0):120<=o&&o<180?(n=0,p=t,m=i):180<=o&&o<240?(n=0,p=i,m=t):240<=o&&o<300?(n=i,p=0,m=t):300<=o&&o<=360&&(n=t,p=0,m=i),{r:Math.round((n+H)*255),g:Math.round((p+H)*255),b:Math.round((m+H)*255)}}function U(r){return b(g(r))}function j(r){return x(g(r))}0&&(module.exports={inHexToHsl,inHexToHsv,inHexToRgb,inHslToHex,inHslToHsv,inHslToRgb,inHsvToHex,inHsvToHsl,inHsvToRgb,inRgbToHex,inRgbToHsl,inRgbToHsv});
@@ -0,0 +1,42 @@
1
+ interface Rgb {
2
+ r: number;
3
+ g: number;
4
+ b: number;
5
+ }
6
+ type Hex = `#${string}`;
7
+ interface Hsv {
8
+ h: number;
9
+ s: number;
10
+ v: number;
11
+ }
12
+ interface Hsl {
13
+ h: number;
14
+ s: number;
15
+ l: number;
16
+ }
17
+
18
+ declare function inHexToRgb(hex: Hex): Rgb;
19
+
20
+ declare function inHexToHsl(hex: Hex): Hsl;
21
+
22
+ declare function inHexToHsv(hex: Hex): Hsv;
23
+
24
+ declare function inHsvToRgb(hsv: Hsv): Rgb;
25
+
26
+ declare function inHsvToHex(hsv: Hsv): Hex;
27
+
28
+ declare function inHsvToHsl(hsv: Hsv): Hsl;
29
+
30
+ declare function inHslToRgb(hsl: Hsl): Rgb;
31
+
32
+ declare function inHslToHex(hsl: Hsl): Hex;
33
+
34
+ declare function inHslToHsv(hsl: Hsl): Hsv;
35
+
36
+ declare function inRgbToHex(rgb: Rgb): Hex;
37
+
38
+ declare function inRgbToHsl(rgb: Rgb): Hsl;
39
+
40
+ declare function inRgbToHsv(rgb: Rgb): Hsv;
41
+
42
+ export { type Hex, type Hsl, type Hsv, type Rgb, inHexToHsl, inHexToHsv, inHexToRgb, inHslToHex, inHslToHsv, inHslToRgb, inHsvToHex, inHsvToHsl, inHsvToRgb, inRgbToHex, inRgbToHsl, inRgbToHsv };
@@ -0,0 +1,42 @@
1
+ interface Rgb {
2
+ r: number;
3
+ g: number;
4
+ b: number;
5
+ }
6
+ type Hex = `#${string}`;
7
+ interface Hsv {
8
+ h: number;
9
+ s: number;
10
+ v: number;
11
+ }
12
+ interface Hsl {
13
+ h: number;
14
+ s: number;
15
+ l: number;
16
+ }
17
+
18
+ declare function inHexToRgb(hex: Hex): Rgb;
19
+
20
+ declare function inHexToHsl(hex: Hex): Hsl;
21
+
22
+ declare function inHexToHsv(hex: Hex): Hsv;
23
+
24
+ declare function inHsvToRgb(hsv: Hsv): Rgb;
25
+
26
+ declare function inHsvToHex(hsv: Hsv): Hex;
27
+
28
+ declare function inHsvToHsl(hsv: Hsv): Hsl;
29
+
30
+ declare function inHslToRgb(hsl: Hsl): Rgb;
31
+
32
+ declare function inHslToHex(hsl: Hsl): Hex;
33
+
34
+ declare function inHslToHsv(hsl: Hsl): Hsv;
35
+
36
+ declare function inRgbToHex(rgb: Rgb): Hex;
37
+
38
+ declare function inRgbToHsl(rgb: Rgb): Hsl;
39
+
40
+ declare function inRgbToHsv(rgb: Rgb): Hsv;
41
+
42
+ export { type Hex, type Hsl, type Hsv, type Rgb, inHexToHsl, inHexToHsv, inHexToRgb, inHslToHex, inHslToHsv, inHslToRgb, inHsvToHex, inHsvToHsl, inHsvToRgb, inRgbToHex, inRgbToHsl, inRgbToHsv };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ function c(s){let o=s.replace("#",""),e=parseInt(o,16);return{r:e>>16&255,g:e>>8&255,b:e&255}}function l(s){let o=s.r/255,e=s.g/255,t=s.b/255,r=Math.max(o,e,t),i=Math.min(o,e,t),H=r-i,n=0,p=(r+i)/2,m=0;return H!==0&&(m=p>.5?H/(2-r-i):H/(r+i),r===o?n=(e-t)/H+(e<t?6:0):r===e?n=(t-o)/H+2:r===t&&(n=(o-e)/H+4),n=n*60),{h:Math.round(n),s:Math.round(m*100),l:Math.round(p*100)}}function d(s){return l(c(s))}function x(s){let o=s.r/255,e=s.g/255,t=s.b/255,r=Math.max(o,e,t),i=Math.min(o,e,t),H=r-i,n=0,p=r===0?0:H/r,m=r;return H!==0&&(r===o?n=(e-t)/H+(e<t?6:0):r===e?n=(t-o)/H+2:r===t&&(n=(o-e)/H+4),n=n*60),{h:Math.round(n),s:Math.round(p*100),v:Math.round(m*100)}}function C(s){return x(c(s))}function a(s){let{h:o,s:e,v:t}=s;if(e===0){let u=Math.round(t*255);return{r:u,g:u,b:u}}let r=Math.floor(o/60)%6,i=o/60-Math.floor(o/60),H=t*(1-e),n=t*(1-i*e),p=t*(1-(1-i)*e),m=[[t,p,H],[n,t,H],[H,t,p],[H,n,t],[p,H,t],[t,H,n]],[f,R,v]=m[r];return{r:Math.round(f*255),g:Math.round(R*255),b:Math.round(v*255)}}function b(s){let{r:o,g:e,b:t}=s,r=p=>Math.max(0,Math.min(255,Math.round(p))),i=r(o).toString(16).padStart(2,"0"),H=r(e).toString(16).padStart(2,"0"),n=r(t).toString(16).padStart(2,"0");return`#${i}${H}${n}`.toUpperCase()}function A(s){return b(a(s))}function F(s){return l(a(s))}function g(s){let{h:o,s:e,l:t}=s;if(e===0){let f=Math.round(t*255);return{r:f,g:f,b:f}}let r=(1-Math.abs(2*t-1))*e,i=r*(1-Math.abs(o/60%2-1)),H=t-r/2,n=0,p=0,m=0;return 0<=o&&o<60?(n=r,p=i,m=0):60<=o&&o<120?(n=i,p=r,m=0):120<=o&&o<180?(n=0,p=r,m=i):180<=o&&o<240?(n=0,p=i,m=r):240<=o&&o<300?(n=i,p=0,m=r):300<=o&&o<=360&&(n=r,p=0,m=i),{r:Math.round((n+H)*255),g:Math.round((p+H)*255),b:Math.round((m+H)*255)}}function N(s){return b(g(s))}function V(s){return x(g(s))}export{d as inHexToHsl,C as inHexToHsv,c as inHexToRgb,N as inHslToHex,V as inHslToHsv,g as inHslToRgb,A as inHsvToHex,F as inHsvToHsl,a as inHsvToRgb,b as inRgbToHex,l as inRgbToHsl,x as inRgbToHsv};
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@nangmanhunter/colors-convert",
3
+ "version": "1.0.0",
4
+ "description": "Strict mathematical color converter for HEX, RGB, HSV, and HSL",
5
+ "author": "NangmanHunter",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "keywords": [],
15
+ "devDependencies": {
16
+ "tsup": "^8.5.1",
17
+ "typescript": "^6.0.3"
18
+ },
19
+ "scripts": {
20
+ "build": "tsup"
21
+ }
22
+ }