PageSourceSearch

https://conversiontab.com/build/assets/color-code-converter-page-C9tqXdNA.js

js conversiontab.com collected 2026-10-01 12:31:56 UTC 13,234 bytes, 2 lines download raw bytes

1import{c as J}from"./index-bsugPHvp.js";import{h as V,b as nt,a as ot,c as ct,d as ft,r as lt,e as rt,i as gt,f as Ct,g as bt,G as st}from"./colorcodes-Dfh5dT81.js";import{copyText as vt,COPY_VISUAL_MS as at,bindHashStyleCopy as Q,hashCopyButtonHtml as yt}from"./hashStyleCopy-9BQjpJfE.js";import{a as xt}from"./transientNotice-Ds_di7lD.js";import"./ctFullscreenAd-wL9Ec5Hb.js";import"./app-Dsk0FNLH.js";const R=[{value:"rgb",label:"RGB"},{value:"hsv",label:"HSV"},{value:"hsl",label:"HSL"},{value:"cmyk",label:"CMYK"},{value:"hue",label:"HUE"},{value:"hex",label:"HEX"}],Et=["rgb","hex","hue","hsv","hsl","cmyk"],it={rgb:"RGB",hex:"HEX",hue:"Hue",hsv:"HSV",hsl:"HSL",cmyk:"CMYK"},O={rgb:["R","G","B"],hsv:["H","S","V"],hsl:["H","S","L"],cmyk:["C","M","Y","K"],hex:["HEX"],hue:["Hue"]},Y={rgb:["Red","Green","Blue"],hsv:["Hue","Saturation","Value"],hsl:["Hue","Saturation","Lightness"],cmyk:["Cyan","Magenta","Yellow","Key"],hex:["HEX color"],hue:["Hue"]},Lt={rgb:["r","g","b"],hsv:["h","s","v"],hsl:["h","s","l"],cmyk:["c","m","y","k"],hex:["hex"],hue:["hue"]},A={rgb:"0,0,0",hsv:"0,0,0",hsl:"0,0,0",cmyk:"0,0,0,0",hue:"0",hex:"#000000"},St={hsv:bt,hsl:Ct,cmyk:gt,hue:rt,hex:V},H={rgb:3,hsv:3,hsl:3,cmyk:4};function G(n,t){const e=String(n||"").split(",").map(u=>parseInt(u.trim(),10));return Array.from({length:t},(u,c)=>Number.isNaN(e[c])?0:e[c])}function ut(n,t){return n==="rgb"?[0,255]:n==="cmyk"?[0,100]:n==="hsv"||n==="hsl"?t===0?[0,360]:[0,100]:[0,255]}function q(n,t,e){return`ctCol${n?"Out":"In"}-${t}-${e}`}function Z(n,t,e){if(!(n instanceof HTMLElement))return!1;const u=H[t]||1;return n.querySelectorAll(".ct-col-io-input").length!==u?!1:!!n.querySelector(`#${q(e,t,0)}`)}function K(n,t,{readOnly:e,onValuesChange:u}){const c=H[n];if(!c)return null;const g=O[n],C=document.createElement("div");C.className="ct-col-multi-row";const s=[],i=()=>{if(!u)return;const a=s.map(p=>{const h=parseInt(p.value,10);return Number.isNaN(h)?0:h});u(a)};for(let a=0;a<c;a++){const p=document.createElement("div");p.className="input-group input-group-sm ct-col-io-channel";const h=q(e,n,a),d=document.createElement("label");d.className="input-group-text ct-col-io-prefix",d.htmlFor=h,d.textContent=g[a];const l=document.createElement("input");l.type="number",l.id=h,l.className="form-control font-monospace ct-col-multi-input ct-col-io-input",l.setAttribute("aria-label",(Y[n]||g)[a]||g[a]),e&&(l.readOnly=!0,l.tabIndex=-1);const[y,b]=ut(n,a);l.min=String(y),l.max=String(b),l.value=String(t[a]??0),e||(l.addEventListener("input",i),l.addEventListener("change",i)),s.push(l),p.appendChild(d),p.appendChild(l),C.appendChild(p)}return C}function tt(n,{readOnly:t,type:e,min:u,max:c,value:g,onInput:C,placeholder:s,inputId:i,ariaLabel:a}){const p=document.createElement("div");p.className="input-group ct-col-io-input-group";const h=i||`ctCol-single-${n.toLowerCase()}-${t?"out":"in"}`,d=document.createElement("label");d.className="input-group-text ct-col-io-prefix",d.htmlFor=h,d.textContent=n;const l=document.createElement("input");return l.type=e==="number"?"number":"text",l.id=h,l.className="form-control font-monospace ct-col-single-input ct-col-io-input",l.setAttribute("aria-label",a||n),t&&(l.readOnly=!0,l.tabIndex=-1),s&&(l.placeholder=s),u!=null&&(l.min=String(u)),c!=null&&(l.max=String(c)),l.value=g,!t&&C&&(l.addEventListener("input",()=>C(l)),l.addEventListener("change",()=>C(l))),p.appendChild(d),p.appendChild(l),p}function dt(n){return/^#?([0-9a-f]{3}){1,2}$/i.test(n||"")}function $t(n){const t=String(n||"").split(",").map(e=>parseInt(e.trim(),10));return t.length===3&&t.every(e=>!Number.isNaN(e)&&e>=0&&e<=255)?{r:t[0],g:t[1],b:t[2]}:{r:0,g:0,b:0}}function W(n){const t=nt(n),e=ot(n),u=ct(n),c=ft(n),g=lt(n)||0;return{rgb:`${n.r},${n.g},${n.b}`,hex:c,hue:String(g),hsv:`${t.h},${t.s},${t.v}`,hsl:`${e.h},${e.s},${e.l}`,cmyk:`${u.c},${u.m},${u.y},${u.k}`}}function et(n,t){const e=W(n);return t==="rgb"?e.rgb:t==="hex"?e.hex:t==="hue"?e.hue:t==="hsv"?e.hsv:t==="hsl"?e.hsl:t==="cmyk"?e.cmyk:e.rgb}function Nt(n){const t=String(n||"").trim();return/^#[0-9a-f]{6}$/i.test(t)?t.slice(0,1)+t.slice(1).toLowerCase():"#000000"}function j(n){xt(n,{variant:"warning"})}function Tt(n){if(!n)return"";const t=[];
1return n.querySelectorAll("tr").forEach(e=>{var g,C,s,i;const u=(C=(g=e.querySelector("th"))==null?void 0:g.textContent)==null?void 0:C.trim(),c=(i=(s=e.querySelector("[data-ct-col-value]"))==null?void 0:s.textContent)==null?void 0:i.trim();u&&c&&c!=="—"&&t.push(`${u}: ${c}`)}),t.join(`
2`)}function It(n){if(!n)return;const t=n.querySelectorAll(".ct-col-other-fmt-copy-btn");t.forEach(e=>{var u,c;e.classList.add("ct-hash-copy-btn--success"),(u=e.querySelector(".ct-hash-copy-ic--default"))==null||u.classList.add("d-none"),(c=e.querySelector(".ct-hash-copy-ic--done"))==null||c.classList.remove("d-none"),e.setAttribute("title","Copied!")}),window.setTimeout(()=>{t.forEach(e=>{var u,c;e.classList.remove("ct-hash-copy-btn--success"),(u=e.querySelector(".ct-hash-copy-ic--default"))==null||u.classList.remove("d-none"),(c=e.querySelector(".ct-hash-copy-ic--done"))==null||c.classList.add("d-none"),e.setAttribute("title","Copy to clipboard")})},at)}function Bt(n,t,e,u){if(!n)return;const c=Et.filter(s=>s!==e&&s!==u),g=[...n.querySelectorAll("tr[data-ct-col-fmt]")];if(g.length===c.length&&c.every((s,i)=>{var a;return((a=g[i])==null?void 0:a.getAttribute("data-ct-col-fmt"))===s})){c.forEach((s,i)=>{const a=g[i],p=t[s]??"—",h=a.querySelector("[data-ct-col-value]");h&&(h.textContent=p);const d=a.querySelector("button.ct-col-other-fmt-copy-btn, button.ct-hash-copy-btn");if(d){const l=d.cloneNode(!0);d.replaceWith(l),Q(l,()=>{const y=t[s];return y!=null&&String(y)!=="—"?String(y):""},j)}});return}n.innerHTML="";for(const s of c){const i=it[s]||s,a=t[s]??"—",p=document.createElement("tr");p.dataset.ctColFmt=s;const h=document.createElement("th");h.scope="row",h.className="small",h.textContent=i;const d=document.createElement("td");d.className="ct-col-other-fmt-value";const l=document.createElement("div");l.className="ct-col-other-fmt-value__inner";const y=document.createElement("span");y.className="font-monospace small ct-col-other-fmt-value__text",y.dataset.ctColValue="1",y.textContent=a,l.appendChild(y),l.insertAdjacentHTML("beforeend",yt(`ctColOtherCopy-${s}`,`Copy ${i} value`,!1,"ct-col-other-fmt-copy-btn")),d.appendChild(l),p.appendChild(h),p.appendChild(d),n.appendChild(p);const b=l.querySelector("button");Q(b,()=>{const E=t[s];return E!=null&&String(E)!=="—"?String(E):""},j)}}function Ht(n,t,e){if(!t||!e||!dt(n)){t&&(t.innerHTML=""),e&&(e.innerHTML="");return}if((n.startsWith("#")?n.toLowerCase():`#${n.toLowerCase()}`)==="#000000"&&t.children.length>0&&e.children.length>0&&t.dataset.ctColMonoHydrated!=="1"){t.dataset.ctColMonoHydrated="1";return}t.innerHTML="",e.innerHTML="",t.dataset.ctColMonoHydrated="1";const g=J.scale(["black",n,"white"]).mode("lab").colors(20),C=[...new Set(g.map(s=>J(s).hex()))].slice(0,10);for(const s of C){const i=document.createElement("div");i.className="rounded border",i.style.cssText=`width:28px;height:28px;background:${s}`,i.title=s,t.appendChild(i)}for(let s=0;s<C.length;s++){if(s===0||s===C.length-1)continue;const i=C[s],a=V(i),p=nt(a),h=ot(a),d=ct(a),l=lt(a)||0;let y="—";try{y=st(i)}catch{y="—"}const b=document.createElement("tr"),E=document.createElement("td"),x=document.createElement("div");x.className="rounded border ct-col-mono-swatch",x.style.cssText=`width:100%;min-width:48px;height:28px;background:${i}`,x.title=i,E.appendChild(x);const w=document.createElement("td");w.className="small",w.textContent=y;const k=document.createElement("td");k.className="font-monospace small",k.textContent=i;const T=document.createElement("td");T.className="font-monospace small",T.textContent=`${a.r},${a.g},${a.b}`;const $=document.createElement("td");$.className="font-monospace small",$.textContent=`${a.r},${a.g},${a.b},1`;const I=document.createElement("td");I.className="font-monospace small",I.textContent=`${p.h},${p.s},${p.v}`;const L=document.createElement("td");L.className="font-monospace small",L.textContent=`${h.h},${h.s},${h.l}`;const B=document.createElement("td");B.className="font-monospace small",B.textContent=`${d.c},${d.m},${d.y},${d.k}`;const F=document.createElement("td");F.className="font-monospace small",F.textContent=String(l),b.appendChild(E),b.appendChild(w),b.appendChild(k),b.appendChild(T),b.appendChild($),b.appendChild(I),b.appendChild(L),b.appendChild(B),b.appendChild(F),e.appendChild(b)}}function Ot(){var U,D;const n=document.getElementById("ct-color-converter-root");
2if(!n)return;let t=(n.getAttribute("data-ct-from")||"rgb").toLowerCase(),e=(n.getAttribute("data-ct-to")||"hex").toLowerCase();R.some(o=>o.value===t)||(t="rgb"),R.some(o=>o.value===e)||(e="hex"),t===e&&(e=t==="hex"?"rgb":"hex");let u={r:0,g:0,b:0},c=A[t],g=A[e];const C=document.getElementById("ctColInType"),s=document.getElementById("ctColOutType"),i=document.getElementById("ctColInFields"),a=document.getElementById("ctColOutFields"),p=document.getElementById("ctColInTitle"),h=document.getElementById("ctColOutTitle"),d=document.getElementById("ctColPicker"),l=document.getElementById("ctColPreviewFmtLbl"),y=document.getElementById("ctColPreviewValLbl"),b=document.getElementById("ctColNameLbl"),E=document.getElementById("ctColOtherFmtBody"),x=document.getElementById("ctColOtherFmtCopyAll"),w=document.getElementById("ctColMonoSwatches"),k=document.getElementById("ctColMonoBody");if(!C||!s||!i||!a)return;const T=o=>{var r;return((r=R.find(m=>m.value===o))==null?void 0:r.label)||o};function $(){p&&(p.textContent=`Input (${T(t)})`),h&&(h.textContent=`Output (${T(e)})`)}function I(){C.innerHTML="",s.innerHTML="";for(const o of R){const r=document.createElement("option");r.value=o.value,r.textContent=o.label,o.value===t&&(r.selected=!0),C.appendChild(r)}for(const o of R){if(o.value===t)continue;const r=document.createElement("option");r.value=o.value,r.textContent=o.label,o.value===e&&(r.selected=!0),s.appendChild(r)}}function L(){if(t==="rgb"){u=$t(c);return}if(t==="hex"){let f=String(c||"").trim();!f.startsWith("#")&&/^[0-9a-f]{6}$/i.test(f)&&(f=`#${f}`),u=V(f);return}if(t==="hue"){const f=parseInt(String(c).trim(),10);u=rt(Number.isNaN(f)?0:f);return}const o=Lt[t],r=String(c||"").split(",").map(f=>parseInt(f.trim(),10)),m={};o.forEach((f,S)=>{m[f]=Number.isNaN(r[S])?0:r[S]});const v=St[t];u=v(m)}function B(o,r,m){const v=H[r],f=[...o.querySelectorAll(".ct-col-io-input")];if(v){const S=G(m,v);f.forEach((P,ht)=>{P.value=String(S[ht]??0)});return}f[0]&&(f[0].value=m)}function F(o){if(!a)return;if(g=o[e],Z(a,e,!0)){B(a,e,o[e]);return}a.innerHTML="";const r=H[e];if(r){const f=G(o[e],r),S=K(e,f,{readOnly:!0});S&&a.appendChild(S);return}const m=e==="hue",v=tt(O[e][0],{readOnly:!0,type:m?"number":"text",min:m?0:null,max:m?360:null,value:o[e],inputId:q(!0,e,0),ariaLabel:(Y[e]||O[e])[0]});a.appendChild(v)}function mt(o){const r=o.hex;if(d&&/^#[0-9a-f]{6}$/i.test(r)&&(d.value=Nt(r)),l&&(l.textContent=it[t]||T(t)),y&&(y.textContent=o[t]??c),b)try{const m=dt(r)?st(r):"—";b.textContent=m,b.title=m!=="—"?m:""}catch{b.textContent="—",b.title=""}}function N(){const o=W(u);F(o),mt(o),Bt(E,o,t,e),Ht(o.hex,w,k)}function X(o){c=o.join(","),L(),N()}function _(o){c=o.value,L(),N()}function pt(){if(i.dataset.ctColBound==="1")return;const o=H[t],r=[...i.querySelectorAll(".ct-col-io-input")];if(o){const m=()=>{X(r.map(v=>{const f=parseInt(v.value,10);return Number.isNaN(f)?0:f}))};r.forEach((v,f)=>{const[S,P]=ut(t,f);v.min=String(S),v.max=String(P),v.addEventListener("input",m),v.addEventListener("change",m)})}else if(r[0]){const m=r[0];t==="hue"&&(m.min="0",m.max="360"),m.addEventListener("input",()=>_(m)),m.addEventListener("change",()=>_(m))}i.dataset.ctColBound="1"}function M(){const o=H[t];if(Z(i,t,!1)){B(i,t,c),pt();return}if(i.innerHTML="",i.dataset.ctColBound="0",o){const r=G(c,o),m=K(t,r,{readOnly:!1,onValuesChange:X});m&&i.appendChild(m),i.dataset.ctColBound="1";return}if(t==="hex"||t==="hue"){const r=t==="hue",m=tt(O[t][0],{readOnly:!1,type:r?"number":"text",min:r?0:null,max:r?360:null,value:c,placeholder:r?void 0:"#RRGGBB",inputId:q(!1,t,0),ariaLabel:(Y[t]||O[t])[0],onInput:_});i.appendChild(m),i.dataset.ctColBound="1"}}I(),$(),L(),M(),N(),C.addEventListener("change",()=>{t=C.value,t===e&&(e=t==="hex"?"rgb":"hex"),c=et(u,t),I(),$(),M(),N()}),s.addEventListener("change",()=>{e=s.value,g=W(u)[e]??A[e],$(),N()}),(U=document.getElementById("ctColReset"))==null||U.addEventListener("click",()=>{c=A[t],g=A[e],u={r:0,g:0,b:0},L(),M(),N()}),(D=document.getElementById("ctColSwap"))==null||D.addEventListener("click",()=>{const o=t;t=e,e=o;const r=c;c=g,g=r,I(),$(),L(),M(),N()});const z=()=>{d&&(c=et(V(d.value),t),L(),M(),N())};d==null||d.addEventListener("input",z),d==null||d.addEventListener("change",z),x==null||x.addEventListener("click",async()=>{const o=Tt(E);if(!o)return;const r=x.getAttribute("data-copy-label")||"Copy all";if(!await vt(o)){j("Copy failed.");return}const v=x.querySelector("span");x.disabled=!0,v&&(v.textContent="Copied!"),It(E),window.setTimeout(()=>{x.disabled=!1,v&&(v.textContent=r)},at)})}export{Ot as initColorCodeConverterPage};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.