{
  "schemaVersion": 1,
  "slug": "color-rgb-hex-calculator",
  "category": "conversion",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "0798f76a135fc27ad93339ba85c28a33a5cdf239468a4aa5f09c5ec70c947351",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/color-rgb-hex-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "Y = 0.2126 R′ + 0.7152 G′ + 0.0722 B′; C′ → s ÷ 12.92 (s ≤ 0.03928) | ((s + 0.055) ÷ 1.055)^2.4 (s > 0.03928); s = C ÷ 255",
    "vars": [
      [
        "C",
        "channel value (0–255)"
      ],
      [
        "s",
        "C ÷ 255"
      ],
      [
        "C′",
        "linearised channel value"
      ],
      [
        "R′,G′,B′",
        "linearised channels"
      ],
      [
        "Y",
        "relative luminance"
      ]
    ],
    "note": "Inputs must be three comma-separated whole-number sRGB channels from 0 to 255. Relative luminance is not a contrast ratio."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const out=(function(rgb){const empty={hex:null,r:null,g:null,b:null,luminance:null};const m=/^\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*$/.exec(String(rgb));if(!m)return{...empty,__error:'inputError'};const parts=m.slice(1).map(Number);if(parts.some(v=>!Number.isInteger(v)||v<0||v>255))return{...empty,__error:'inputError'};const [r,g,b]=parts,h2=n=>n.toString(16).padStart(2,'0').toUpperCase(),lin=x=>{const s=x/255;return s<=0.04045?s/12.92:Math.pow((s+0.055)/1.055,2.4);};return{hex:'#'+h2(r)+h2(g)+h2(b),r,g,b,luminance:0.2126*lin(r)+0.7152*lin(g)+0.0722*lin(b)};})(rgb);if(out.__error)return {...{\"result\":null,\"hex\":null,\"r\":null,\"g\":null,\"b\":null,\"luminance\":null},...out};out.result=out.hex;out.__color=out.hex;return out;",
    "inputs": [
      {
        "name": "rgb",
        "type": "text",
        "default": "59,130,246",
        "step": 1,
        "preserveEmpty": true
      }
    ],
    "outputs": [
      {
        "name": "result",
        "precision": 4,
        "trimTrailingZeros": true,
        "type": "text"
      },
      {
        "name": "hex",
        "precision": 0,
        "unit": "",
        "type": "text",
        "showWhen": {
          "rgb": []
        }
      },
      {
        "name": "r",
        "precision": 0,
        "unit": "",
        "notation": "auto"
      },
      {
        "name": "g",
        "precision": 0,
        "unit": "",
        "notation": "auto"
      },
      {
        "name": "b",
        "precision": 0,
        "unit": "",
        "notation": "auto"
      },
      {
        "name": "luminance",
        "precision": 4,
        "unit": "",
        "notation": "auto"
      }
    ],
    "interpret": null
  }
}
