main
Caleb 0.4.0: wiki page runs the live calculator (README.html loads the current source from the page repo), UI static mode, sh… fc3ee8f
<!doctype html>
<html lang="en"><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="readme-max-height" content="32000">
<title>Hardware Calculator</title>
<style>
:root { --bg:#0d1117; --panel:#161b22; --line:#262d38; --ink:#e6edf3; --dim:#8b949e; --teal:#00b8b0; }
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--ink); font: 15px/1.6 -apple-system, 'Segoe UI', Inter, sans-serif; }
#page { padding: 22px 22px 30px; max-width: 1400px; margin: 0 auto; }
h1 { font-size: 26px; letter-spacing: .01em; } h2 { font-size: 18px; margin: 28px 0 8px; }
p, li { color: #c9d1d9; } p { margin: 6px 0; } ul { margin: 6px 0 6px 20px; } li { margin: 3px 0; }
code { font: 13px ui-monospace, Menlo, monospace; background: var(--panel); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; color: #d2dae4; }
pre { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 8px 0; overflow-x: auto; }
pre code { border: 0; background: none; padding: 0; }
a { color: #58a6ff; }
.lead { font-size: 16px; color: #dfe6ee; max-width: 900px; }
.live { margin-top: 18px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--dim); }
.bar .dot { width: 8px; height: 8px; border-radius: 50%; background: #3fb950; box-shadow: 0 0 6px #3fb950; }
.bar .dot.wait { background: #d29922; box-shadow: none; } .bar .dot.bad { background: #f85149; box-shadow: none; }
#app { display: block; width: 100%; height: 880px; border: 0; background: var(--bg); }
#app[hidden] { display: none; }
#msg { padding: 40px; text-align: center; color: var(--dim); }
</style></head>
<body><div id="page">
<h1>Hardware Calculator</h1>
<p class="lead">40 hardware design calculators whose every number traces to a standard, with a live schematic of the circuit you are sizing.
Trace width to IPC-2152, clearance to IPC-2221C, impedance to IPC-2141, crystal load caps and oscillator start-up margin to ST AN2867,
I²C pull-ups to NXP UM10204. Try it right here: this is the real app, loaded live from this page's source.</p>

<div class="live">
  <div class="bar"><span class="dot wait" id="dot"></span><span id="status">Loading the calculator from the page repo…</span></div>
  <div id="msg">Loading…</div>
  <iframe id="app" title="Hardware Calculator" hidden></iframe>
</div>

<h2>Install it for your AI and terminal</h2>
<p>The page above runs in your browser with no install. Install the app to let your AI open and fill calculations for you, use the CLI, and keep your settings.</p>
<pre><code>adom-wiki pkg install adom/hardware-calculator
hwcalc --ai-thread "&lt;name&gt;" start        # opens the calculator in a Hydrogen tab</code></pre>

<h2>Say it to your AI</h2>
<ul>
  <li>"with the hardware calculator, what trace width for 3 A at 20 °C rise on 2 oz?"</li>
  <li>"size the load caps for a 12 pF crystal and check the gain margin with 25 mA/V gm"</li>
  <li>"hardware calculator: clearance for 300 V on an external coated layer"</li>
  <li>"open the hardware calculator on a buck from 12 V to 3.3 V at 2 A, 500 kHz"</li>
</ul>
<p>Or from the terminal, no server needed: <code>hwcalc calc trace I=3 dT=20 oz=2</code>, <code>hwcalc calc crystal CL=12p Cs=4p --svg osc.svg</code>.</p>

<h2>Why you can trust it</h2>
<ul>
  <li><b>Standards checked for currency.</b> IPC-2221 is Rev C (Dec 2023), IPC-2152 is still Rev 0 (2009), and so on. Every source, its revision and the date it was checked is in <a href="https://wiki.adom.inc/adom/hardware-calculator/files/SOURCES.md" target="_blank">SOURCES.md</a>.</li>
  <li><b>No undisclosed fits.</b> Where a standard is chart-only (IPC-2152) the published curve fit is named; where a table is paywalled (IPC-2221 Table 6-1) the values were cross-checked against two independent reproductions.</li>
  <li><b>Tested against the sources' own worked examples</b>, for example AN2867's 8 MHz crystal: gm_crit 0.23 mA/V and gain margin 107. 140 automated checks run on every change.</li>
  <li><b>Honest limits.</b> Closed-form impedance says ±5–10 % and to confirm with your fab's field solver; unmodelled effects are stated under each result.</li>
</ul>

<h2>Contributing</h2>
<p>Anyone in the adom org can publish. Every change follows the <code>hwcalc-calculator-standards</code> skill (Skills tab, Dev): source fetched and revision
confirmed, a test reproducing the source's worked example, a labelled drawing for any circuit, and the sources register updated. Releases follow
<code>hwcalc-release</code> (Skills tab, Publish). A change pushed to this page's source shows up in the calculator above on the next page load.</p>
</div>

<script>
// Loads the app's own UI and formula modules from this page's repo on every visit (served no-store), so the embedded
// calculator is always the latest pushed source. The sandbox serves .js as octet-stream (no <script src>), so the code is
// fetched as text and inlined into a srcdoc frame (inline scripts are allowed; eval is not needed).
(async () => {
  const PAGE = 'https://wiki.adom.inc/adom/hardware-calculator', RAW = PAGE + '/render/';
  const $ = s => document.querySelector(s), setStatus = (t, cls) => { $('#status').textContent = t; $('#dot').className = 'dot' + (cls ? ' ' + cls : ''); };
  let pendingHash = '';
  addEventListener('message', e => {
    const m = e.data || {};
    if (m.type === 'readme-hash' && m.hash) { pendingHash = m.hash; const f = $('#app'); if (f.contentWindow) f.contentWindow.postMessage({ type: 'hwcalc-open', hash: m.hash }, '*'); }
  });
  try {
    const get = p => fetch(RAW + p, { cache: 'no-store' }).then(r => { if (!r.ok) throw new Error(p + ' ' + r.status); return r.text(); });
    const [html, calcs, schem, pkg] = await Promise.all([get('public/index.html'), get('calcs.js'), get('schematics.js'), get('package.json')]);
    let commit = ''; try { commit = (await (await fetch('https://wiki.adom.inc/api/pages/adom/hardware-calculator')).json()).page.last_commit_hash || ''; } catch {}
    const version = JSON.parse(pkg).version;
    const boot = { version, commit, pageUrl: PAGE, hash: pendingHash };
    const inline = code => '<script>' + code.replace(/<\/script/gi, '<\\/script') + '<\/script>';
    let doc = html.replace('<script src="calcs.js"></scr' + 'ipt>', () => '<script>window.HWCALC_STATIC = ' + JSON.stringify(boot) + '<\/script>' + inline(calcs))
                  .replace('<script src="schematics.js"></scr' + 'ipt>', () => inline(schem));
    if (!doc.includes('HWCALC_STATIC')) throw new Error('unexpected index.html layout');
    const f = $('#app'); f.srcdoc = doc; f.hidden = false; $('#msg').remove();
    f.addEventListener('load', () => { if (pendingHash) f.contentWindow.postMessage({ type: 'hwcalc-open', hash: pendingHash }, '*'); }, { once: true });
    setStatus(`Live: v${version}${commit ? ' @ ' + commit.slice(0, 7) : ''}, loaded from this page's source just now. Runs entirely in your browser.`);
  } catch (err) {
    setStatus('Could not load the calculator: ' + err.message, 'bad');
    $('#msg').textContent = 'The live calculator could not be loaded here. Install it instead: adom-wiki pkg install adom/hardware-calculator';
  }
})();
// Size the wiki frame to the content (measure the wrapper, never documentElement: that ratchets).
const fit = () => parent.postMessage({ type: 'readme-height', height: Math.ceil(document.getElementById('page').getBoundingClientRect().height) + 8 }, '*');
addEventListener('load', fit); new ResizeObserver(fit).observe(document.getElementById('page')); fit();
</script>
</body></html>