---
title: "Code Listings - Paper Gallery"
description: "A short paper whose evidence is code: terminal sessions and a diff in Code Mockup windows, telling how one missing line made every OKLCH contrast too dark."
slug: "paper-code"
---

import { DocPage, PageHeader, DocLink, SourceFiles } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="paper-code" title="Code Listings" component="paper">
  When the evidence is code, the paper shows it in <DocLink href="mockup-code.html">Code Mockup</DocLink> windows: a probe in a terminal, the fix as a diff, the test that pins it. The story is real - a missing gamma step in this system's own contrast measurement, found while calibrating the theme checker.
</PageHeader>

```html example label="The missing gamma step" schema="none" hint="Three Code Mockup windows: a terminal probe (data-prefix, data-tone), the fix as a numbered diff (data-diff remove / add with del and ins), and the test run. The windows scroll sideways on a phone; the prompts are generated content, so a copy takes only the command."
<article class="paper" data-variant="minimal" aria-labelledby="pc-title">
  <header class="paper-hero">
    <p class="paper-venue"
      ><span class="badge" data-variant="secondary">Bug report</span
      ><span>defuss-shadcn · <time datetime="2026-10-07">7 October 2026</time></span></p
    >
    <h1 class="paper-title" id="pc-title"
      >The Missing Gamma Step<span class="paper-title-sub">How one line made every OKLCH contrast too dark</span></h1
    >
    <ul class="paper-authors"
      ><li>Claude</li
      ><li>Aron Homberg</li></ul
    >
  </header>

  <section class="paper-abstract" aria-labelledby="pc-abstract">
    <h2 id="pc-abstract">Abstract</h2>
    <p
      >The verifier measures the contrast of every theme's sidebar text. Its OKLCH conversion returned linear-light
      values and skipped the sRGB transfer, so a mid grey came out at 55 instead of 128 and every OKLCH contrast was
      measured too dark. The tests checked only black and white, where linear and gamma-encoded values agree. A probe
      found it; one function fixed it; a mid-tone test now pins it.</p
    >
  </section>

  <nav class="paper-toc" aria-labelledby="pc-toc">
    <h2 id="pc-toc">Contents</h2>
    <ol>
      <li
        ><a href="#pc-s1"><span class="paper-num">1&nbsp;</span>The probe</a></li
      >
      <li
        ><a href="#pc-s2"><span class="paper-num">2&nbsp;</span>The fix</a></li
      >
      <li
        ><a href="#pc-s3"><span class="paper-num">3&nbsp;</span>The test</a></li
      >
      <li
        ><a href="#pc-cite"><span class="paper-num">·&nbsp;</span>Citation and references</a></li
      >
    </ol>
  </nav>

  <section class="paper-section" aria-labelledby="pc-s1">
    <h2 id="pc-s1"><span class="paper-num">1&nbsp;</span>The probe</h2>
    <p>Reference colours from CSS Color 4, converted by the verifier's parser:</p>
    <div class="mockup-code" data-chrome="mac" data-title="zsh - defuss-shadcn">
      <pre data-prefix="$"><code>bun tmp/oklch-probe.ts</code></pre>
      <pre><code>red   [ 255, 0, 0 ] want 255,0,0</code></pre>
      <pre><code>green [ 0, 255, 0 ] want 0,255,0</code></pre>
      <pre><code>blue  [ 0, 0, 255 ] want 0,0,255</code></pre>
      <pre
        data-tone="destructive"
        data-highlight
      ><code>white [ 255, 255, 255 ] gray50 [ 55, 55, 55 ] want ~128</code></pre>
    </div>
    <p
      >The primaries match because 0 and 1 are the same in linear and gamma space; only the mid tone exposes the
      error.</p
    >
  </section>

  <section class="paper-section" aria-labelledby="pc-s2">
    <h2 id="pc-s2"><span class="paper-num">2&nbsp;</span>The fix</h2>
    <div class="mockup-code" data-numbers data-title="scripts/lib/contrast.ts">
      <pre><code>  const lin = [ /* LMS → linear sRGB */ ];</code></pre>
      <pre
        data-diff="remove"
      ><code>  return lin.map((v) =&gt; Math.round(Math.min(1, Math.max(0, v)) * 255)) as RGB;</code></pre>
      <pre
        data-diff="add"
      ><code>  const encode = (v: number) =&gt; (v &lt;= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055);</code></pre>
      <pre
        data-diff="add"
      ><code>  return lin.map((v) =&gt; Math.round(Math.min(1, Math.max(0, <ins>encode</ins>(Math.min(1, Math.max(0, v))))) * 255)) as RGB;</code></pre>
    </div>
  </section>

  <section class="paper-section" aria-labelledby="pc-s3">
    <h2 id="pc-s3"><span class="paper-num">3&nbsp;</span>The test</h2>
    <div class="mockup-code" data-title="tests/contrast.test.ts">
      <pre data-prefix="$"><code>bun test tests/contrast.test.ts</code></pre>
      <pre data-tone="success"><code>✓ gamma-encodes oklch: mid tones match the CSS Color 4 reference</code></pre>
      <pre data-tone="success"><code>✓ parses oklch percentages and alpha, and hsl</code></pre>
      <pre data-tone="muted"><code>22 pass · 0 fail</code></pre>
    </div>
    <p
      >The sidebar contrast gate still passes every preset after the fix: their sidebar pairs were readable all along,
      only the measurement was wrong.</p
    >
  </section>
  <section class="paper-bibtex" aria-labelledby="pc-cite">
    <h2 id="pc-cite">Citation and references</h2>
    <figure class="bibtex" data-formats="bibtex apa mla ieee" aria-label="Cite this paper">
      <figcaption>Cite this paper</figcaption>
      <pre><code class="bibtex-source">@techreport{homberg2026gamma,
  title = {The Missing Gamma Step: How One Line Made Every OKLCH Contrast Too Dark},
  author = {Claude and Homberg, Aron},
  institution = {defuss},
  year = {2026},
  month = oct,
  url = {https://shadcn.defuss.org/papers/paper-code.html}
}</code></pre>
    </figure>
    <figure class="bibtex" data-formats="ieee apa bibtex" data-format="ieee" aria-label="References">
      <figcaption>References</figcaption>
      <pre><code class="bibtex-source">@techreport{iec1999srgb,
  author = {{IEC}},
  title = {IEC 61966-2-1:1999 - Multimedia systems and equipment - Colour measurement and management - Part 2-1: Default RGB colour space - sRGB},
  institution = {International Electrotechnical Commission},
  year = {1999}
}

@misc{ottosson2020oklab,
  author = {Ottosson, Björn},
  title = {A perceptual color space for image processing},
  year = {2020},
  url = {https://bottosson.github.io/posts/oklab/}
}

@misc{w3c2023wcag22,
  author = {{W3C}},
  title = {Web Content Accessibility Guidelines (WCAG) 2.2},
  year = {2023},
  howpublished = {W3C Recommendation},
  url = {https://www.w3.org/TR/WCAG22/}
}

@misc{homberg2026defussshadcn,
  author = {Homberg, Aron},
  title = {defuss-shadcn: shadcn-style components as semantic HTML},
  year = {2026},
  howpublished = {GitHub},
  url = {https://github.com/kyr0/defuss-shadcn}
}</code></pre>
    </figure>
  </section>
</article>
```

## Print layout

```html example label="Printed: a listing over two columns" mode="print" schema="none" hint="The preview boots in the Print device: an A4 sheet whose print styles apply. The test run is longer than a column; data-break-inside='allow' on its figure lets it run on into the next column instead of leaving the first half empty, each piece in a closed window frame, the caption under the last; its lines wrap (data-wrap), since a window that scrolls sideways cannot split. The window keeps its dark surface on paper: a printed paper prints its colors as designed. Switch to Full for the screen layout." previewStyle="align-items:stretch;padding:0;"
<article class="paper" data-variant="minimal" data-print="a4" aria-labelledby="pcp-title">
  <header class="paper-hero">
    <h1 class="paper-title" id="pcp-title">The Missing Gamma Step</h1>
  </header>
  <section
    class="paper-section typeset paper-wide"
    lang="en"
    data-align="justify"
    data-columns="2"
    aria-labelledby="pcp-s3"
  >
    <h2 id="pcp-s3" class="typeset-span"><span class="paper-num">3&nbsp;</span>The test</h2>
    <p
      >A mid-tone test now pins the conversion; the primaries, black and white could not tell linear light from gamma
      encoding.</p
    >
    <figure class="paper-figure" data-break-inside="allow">
      <div class="mockup-code" data-title="zsh - defuss-shadcn" data-wrap>
        <pre data-prefix="$"><code>bun test tests/contrast.test.ts</code></pre>
        <pre data-tone="success"><code>✓ parses 3/6/8-digit hex</code></pre>
        <pre data-tone="success"><code>✓ parses rgb()/rgba() with percentages</code></pre>
        <pre data-tone="success"><code>✓ parses oklch and clamps out-of-gamut</code></pre>
        <pre data-tone="success"><code>✓ gamma-encodes oklch: mid tones match the CSS Color 4 reference (extremes alone hid a linear-light bug)</code></pre>
        <pre data-tone="success"><code>✓ parses oklch percentages and alpha, and hsl</code></pre>
        <pre data-tone="success"><code>✓ returns null for unknown formats</code></pre>
        <pre data-tone="success"><code>✓ is 21:1 for black/white and 1:1 for identical colors</code></pre>
        <pre data-tone="success"><code>✓ is symmetric</code></pre>
        <pre data-tone="success"><code>✓ flags the known-bad catppuccin-light active pair (2.79)</code></pre>
        <pre data-tone="success"><code>✓ returns null when a color is unparsable</code></pre>
        <pre data-tone="muted"><code>[...]</code></pre>
        <pre data-tone="muted"><code>22 pass · 0 fail</code></pre>
      </div>
      <figcaption
        ><b>Figure 3.</b> The test run after the fix: the first ten of its 22 tests; [...] marks the rest.</figcaption
      >
    </figure>
    <p
      >The sidebar contrast gate still passes every preset after the fix: their sidebar pairs were readable all along,
      only the measurement was wrong.</p
    >
  </section>
</article>
```

<SourceFiles component="paper" />
</DocPage>
