Skip to content

Commit 161d4fe

Browse files
committed
feat(demo): adaptive density note explaining tag overhead + horizontal scroll for grid child
1 parent 2723151 commit 161d4fe

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

docs/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@
233233
.demo-output::-webkit-scrollbar-thumb:hover { background: var(--accent); }
234234
.demo-output::-webkit-scrollbar-corner { background: transparent; }
235235
.demo-stats { font-size: 12px; color: var(--text-faint); font-family: "SF Mono", monospace; }
236+
.demo-note { font-size: 12.5px; line-height: 1.5; margin-top: 4px; padding: 10px 12px; border-radius: 6px; display: none; }
237+
.demo-note.show { display: block; }
238+
.demo-note.warn { background: rgba(245,166,35,0.08); border: 1px solid rgba(245,166,35,0.3); color: #d99a3a; }
239+
.demo-note.good { background: rgba(0,212,168,0.08); border: 1px solid rgba(0,212,168,0.3); color: var(--accent); }
240+
.demo-note strong { color: inherit; }
236241
.demo-actions { display: flex; align-items: center; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
237242
.demo-result { font-size: 14px; font-family: "SF Mono", monospace; color: var(--text-dim); }
238243
.demo-details { margin-top: 32px; }
@@ -366,6 +371,7 @@ <h2>Encode anything into DNA, right now.</h2>
366371
<div class="demo-label">2. DNA oligos (output)</div>
367372
<pre id="demo-output" class="demo-output mono">Click "Encode" to see the oligos.</pre>
368373
<div class="demo-stats" id="demo-output-stats">— oligos · — bases · — bits/base</div>
374+
<div class="demo-note" id="demo-density-note"></div>
369375
</div>
370376
</div>
371377

@@ -528,6 +534,19 @@ <h2>Encode anything into DNA, right now.</h2>
528534
$("demo-output-stats").textContent = `${oligos.length} oligos · ${totalBases} bases · ${density.toFixed(3)} bits/base`;
529535
$("demo-result").textContent = "✓ encoded";
530536
$("demo-result").style.color = "var(--accent)";
537+
538+
// --- Adaptive density note: explain the tag-overhead effect ---
539+
const note = $("demo-density-note");
540+
const tagBytes = new TextEncoder().encode(tag).length;
541+
const payloadPct = bytes.length === 0 ? 0 : Math.round(bytes.length / (tagBytes + bytes.length) * 100);
542+
note.className = "demo-note show";
543+
if (bytes.length < 200) {
544+
note.classList.add("warn");
545+
note.innerHTML = `⚠️ <strong>Low density is expected here.</strong> Only <strong>${payloadPct}%</strong> of these bases are your text — the rest is the fixed ${tagBytes}-byte self-describing tag. That tag is the same size whether you encode 7 bytes or 7 MB. Try pasting <strong>500+ characters</strong> to watch the density climb toward the real ~1.75 bits/base.`;
546+
} else {
547+
note.classList.add("good");
548+
note.innerHTML = `✓ <strong>${payloadPct}% payload.</strong> At this size the fixed ${tagBytes}-byte tag is becoming negligible. On a real file (≥10 KB) density approaches <strong>~1.75 bits/base</strong> — about 88% of the Shannon limit for the 4-letter DNA channel.`;
549+
}
531550
} catch (e) {
532551
$("demo-output").textContent = `Error: ${e.message}`;
533552
$("demo-result").textContent = "✗ failed";
@@ -559,6 +578,8 @@ <h2>Encode anything into DNA, right now.</h2>
559578
$("demo-output").textContent = "Click \"Encode\" to see the oligos.";
560579
$("demo-output-stats").textContent = "— oligos · — bases · — bits/base";
561580
$("demo-result").textContent = "";
581+
$("demo-density-note").className = "demo-note";
582+
$("demo-density-note").innerHTML = "";
562583
lastOligos = null;
563584
updateInputStats();
564585
}

0 commit comments

Comments
 (0)