|
233 | 233 | .demo-output::-webkit-scrollbar-thumb:hover { background: var(--accent); } |
234 | 234 | .demo-output::-webkit-scrollbar-corner { background: transparent; } |
235 | 235 | .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; } |
236 | 241 | .demo-actions { display: flex; align-items: center; gap: 12px; margin-top: 20px; flex-wrap: wrap; } |
237 | 242 | .demo-result { font-size: 14px; font-family: "SF Mono", monospace; color: var(--text-dim); } |
238 | 243 | .demo-details { margin-top: 32px; } |
@@ -366,6 +371,7 @@ <h2>Encode anything into DNA, right now.</h2> |
366 | 371 | <div class="demo-label">2. DNA oligos (output)</div> |
367 | 372 | <pre id="demo-output" class="demo-output mono">Click "Encode" to see the oligos.</pre> |
368 | 373 | <div class="demo-stats" id="demo-output-stats">— oligos · — bases · — bits/base</div> |
| 374 | + <div class="demo-note" id="demo-density-note"></div> |
369 | 375 | </div> |
370 | 376 | </div> |
371 | 377 |
|
@@ -528,6 +534,19 @@ <h2>Encode anything into DNA, right now.</h2> |
528 | 534 | $("demo-output-stats").textContent = `${oligos.length} oligos · ${totalBases} bases · ${density.toFixed(3)} bits/base`; |
529 | 535 | $("demo-result").textContent = "✓ encoded"; |
530 | 536 | $("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 | + } |
531 | 550 | } catch (e) { |
532 | 551 | $("demo-output").textContent = `Error: ${e.message}`; |
533 | 552 | $("demo-result").textContent = "✗ failed"; |
@@ -559,6 +578,8 @@ <h2>Encode anything into DNA, right now.</h2> |
559 | 578 | $("demo-output").textContent = "Click \"Encode\" to see the oligos."; |
560 | 579 | $("demo-output-stats").textContent = "— oligos · — bases · — bits/base"; |
561 | 580 | $("demo-result").textContent = ""; |
| 581 | + $("demo-density-note").className = "demo-note"; |
| 582 | + $("demo-density-note").innerHTML = ""; |
562 | 583 | lastOligos = null; |
563 | 584 | updateInputStats(); |
564 | 585 | } |
|
0 commit comments