<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MG Ventures Engineering]]></title><description><![CDATA[MG Ventures Engineering]]></description><link>https://mgventures.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Dec 2026 00:15:19 GMT</lastBuildDate><atom:link href="https://mgventures.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Why I Lock Every Local Browser Tool with CSP connect-src 'none' (And How It Runs PDF.js & .docx Offline)]]></title><description><![CDATA[Almost every online PDF converter, contract diff site, and CSV cleaner has the same reassuring footer: "We respect your privacy. Uploaded files are…]]></description><link>https://mgventures.hashnode.dev/why-i-lock-every-local-browser-tool-with-csp-connect-src-none-and-how-it-runs-pdf-js-docx-offline</link><guid isPermaLink="true">https://mgventures.hashnode.dev/why-i-lock-every-local-browser-tool-with-csp-connect-src-none-and-how-it-runs-pdf-js-docx-offline</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Security]]></category><category><![CDATA[privacy]]></category><category><![CDATA[pdf]]></category><dc:creator><![CDATA[MG Ventures]]></dc:creator><pubDate>Fri, 04 Dec 2026 02:50:58 GMT</pubDate><content:encoded><![CDATA[<p>Almost every online PDF converter, contract diff site, and CSV cleaner has the same reassuring footer:</p>
<blockquote>
<p><em>"We respect your privacy. Uploaded files are automatically deleted after 1 hour."</em></p>
</blockquote>
<p>If you're a freelancer reviewing an NDA, a consultant comparing client MSAs, or an indie maker reconciling Stripe and Gumroad revenue CSVs, that promise isn't good enough. Once a confidential file crosses the wire to someone else's server, you no longer control it.</p>
<p>Over the past few weeks, I built a small suite of <strong>single-file, 100% offline HTML utilities</strong>—no backend, no build step for the end user, no Electron bloat, and no OS code-signing warnings—and made one non-negotiable architectural rule:</p>
<p><strong>Every tool must technically prove it cannot phone home, using a strict <code>&lt;meta&gt;</code> Content Security Policy.</strong></p>
<hr />
<h2>1. One <code>&lt;meta&gt;</code> Tag Beats a 10-Page Privacy Policy</h2>
<p>For pure-JS tools (like my offline multi-platform sales CSV reconciler), the entire security guarantee fits in a single line inside <code>&lt;head&gt;</code>:</p>
<pre><code class="language-html">&lt;meta
  http-equiv="Content-Security-Policy"
  content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; connect-src 'none'; base-uri 'none'; form-action 'none';"
&gt;
</code></pre>
<p>When you open this file in Chrome, Edge, Safari, or Firefox—even under <code>file://</code> in airplane mode—the browser engine itself blocks:</p>
<ul>
<li>Every <code>fetch()</code>, <code>XMLHttpRequest</code>, <code>WebSocket</code>, and <code>EventSource</code> (<code>connect-src 'none'</code>)</li>
<li>Every external script, CDN stylesheet, web font, or tracking pixel (<code>default-src 'none'</code>)</li>
<li>Every sneaky form submission (<code>form-action 'none'</code>)</li>
</ul>
<p>Users don't have to take my word for it: they can open DevTools → Network, drop a sensitive document, and verify <strong>0 bytes sent</strong>.</p>
<hr />
<h2>2. The Hard Part: Keeping <code>connect-src 'none'</code> While Parsing PDFs and Word (<code>.docx</code>)</h2>
<p>Pure CSV parsing is easy under strict CSP. Parsing <strong>PDF</strong> and <strong>Word (<code>.docx</code>)</strong> files completely offline inside one <code>.html</code> file is where things get interesting.</p>
<h3>Trick A: Running Mozilla <code>PDF.js</code> Without External Worker Requests</h3>
<p>Normally, <code>pdf.js</code> loads <code>pdf.worker.min.js</code> over HTTP—which fails under <code>file://</code> CORS rules and strict CSP.</p>
<p>The fix is to inline <code>pdf.min.js</code>, embed <code>pdf.worker.min.js</code> as Base64, convert it into an in-memory <code>Blob</code> URL at startup, and loosen CSP <strong>only</strong> for <code>worker-src blob:</code> and <code>script-src 'unsafe-inline' blob:</code> while keeping <strong><code>connect-src 'none'</code></strong>:</p>
<pre><code class="language-javascript">const bin = atob(EMBEDDED_WORKER_BASE64);
const bytes = new Uint8Array(bin.length);
for (let i = 0; i &lt; bin.length; i++) bytes[i] = bin.charCodeAt(i);
const blob = new Blob([bytes], { type: "application/javascript" });
window.pdfjsLib.GlobalWorkerOptions.workerSrc = URL.createObjectURL(blob);
</code></pre>
<p>Also remember to pass <code>isEvalSupported: false</code> to <code>pdfjsLib.getDocument(...)</code> so PDF.js never attempts <code>eval()</code> under a locked-down CSP!</p>
<h3>Trick B: Zero-Dependency <code>.docx</code> Extraction via <code>DecompressionStream</code></h3>
<p>A <code>.docx</code> file is a PKZIP archive containing <code>word/document.xml</code>. Instead of bundling heavy ZIP/Office libraries, modern browsers ship with <code>DecompressionStream("deflate-raw")</code>.</p>
<p>About 60 lines of PKZIP Central Directory parsing + raw deflate decompression extracts live contract paragraphs natively—and stripping <code>&lt;w:del&gt;...&lt;/w:del&gt;</code> tags before collecting <code>&lt;w:t&gt;</code> prevents Word's tracked-change deletions from silently leaking back into your diffs:</p>
<pre><code class="language-javascript">const cleaned = xmlText.replace(/&lt;w:del\b[^&gt;]*&gt;[\s\S]*?&lt;\/w:del&gt;/g, "");
</code></pre>
<hr />
<h2>3. Why Single-File HTML Beats <code>.exe</code> / <code>.dmg</code> for Small Indie Utilities</h2>
<p>Historically, offline desktop tools shipped as <code>.exe</code> or <code>.dmg</code> binaries. Today, independent makers hit two massive walls with native binaries:</p>
<ol>
<li><strong>OS Gatekeepers:</strong> Unsigned <code>.exe</code> and <code>.app</code> files trigger scary Windows SmartScreen / macOS Gatekeeper warnings unless you pay hundreds of dollars a year for EV code signing + Apple Developer notarization.</li>
<li><strong>Zero-Friction Demos:</strong> With a single HTML architecture, the exact same engine doubles as a <strong>1-click live browser demo on GitHub Pages</strong>—so users can test their own files before downloading anything.</li>
</ol>
<hr />
<h2>Live 1-Click Offline Demos (Try With DevTools Open!)</h2>
<p>All demos below run strictly inside your browser with <code>CSP: connect-src 'none'</code> and zero signup:</p>
<ul>
<li><strong>MG Ventures Offline Local Tools Hub (All 5 Tools, EN/JP):</strong> <a href="https://mscsupport2026-lab.github.io/">https://mscsupport2026-lab.github.io/</a></li>
<li><strong>DiffLocal (Word <code>.docx</code> ↔ PDF Contract Diff Demo):</strong> <a href="https://mscsupport2026-lab.github.io/difflocal-demo/">https://mscsupport2026-lab.github.io/difflocal-demo/</a></li>
<li><strong>CreatorCSV Local (Gumroad / Stripe / Patreon Sales CSV Demo):</strong> <a href="https://mscsupport2026-lab.github.io/creator-csv-demo/">https://mscsupport2026-lab.github.io/creator-csv-demo/</a></li>
</ul>
<p><em>(Full disclosure: The live browser demos are free to use with no signup; I also offer downloadable perpetual offline Pro editions with unlimited length, printable Audit HTML/CSV reports, and QuickBooks/Xero/Wave exports as one-time purchases on <a href="https://mscassist.gumroad.com/">Gumroad</a>—<a href="https://mscassist.gumroad.com/l/difflocal-pro">DiffLocal Pro ($39)</a> and <a href="https://mscassist.gumroad.com/l/ubtuhq">CreatorCSV Local Pro ($29)</a>. PDF parsing uses Mozilla PDF.js under Apache 2.0. Parts of the drafting and test scaffolding were assisted by AI tools and verified with automated tests.)</em></p>
<p>Have you shipped single-file HTML utilities with strict CSP locks? What browser edge cases surprised you most? Let's compare notes in the comments!</p>
]]></content:encoded></item><item><title><![CDATA[Stop Paying $20/mo to Clean Sales CSVs: Building a CSP-Locked Offline Converter for Gumroad, Stripe & Patreon]]></title><description><![CDATA[Handling Stripe payout double-counting, Gumroad refunds, previous-business-day FX fallback, and QuickBooks/Xero/Wave CSV formats in a single offline HTML…]]></description><link>https://mgventures.hashnode.dev/stop-paying-20-mo-to-clean-sales-csvs-building-a-csp-locked-offline-converter-for-gumroad-stripe-patreon</link><guid isPermaLink="true">https://mgventures.hashnode.dev/stop-paying-20-mo-to-clean-sales-csvs-building-a-csp-locked-offline-converter-for-gumroad-stripe-patreon</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[indie hackers]]></category><category><![CDATA[Productivity]]></category><category><![CDATA[csv]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[MG Ventures]]></dc:creator><pubDate>Tue, 01 Dec 2026 00:01:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0e0a0bc9639374e8e70af1/c845e6e2-733f-49a6-be83-e9ca2db379d0.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you sell digital products across <strong>Gumroad, Stripe, Patreon, and Etsy</strong>, bookkeeping at tax time is weirdly painful.</p>
<p>You usually end up choosing between:</p>
<ol>
<li>Paying <strong>$15–$30/month forever</strong> for a SaaS bookkeeping connector just to import a few dozen monthly rows.</li>
<li>Wrestling with broken Excel formulas every quarter—or uploading private revenue exports to random online CSV tools.</li>
</ol>
<p>So I built <strong>CreatorCSV Local</strong>: a zero-dependency, single-file HTML tool locked down with <code>Content-Security-Policy: default-src 'none'</code> that reconciles multi-platform creator sales CSVs completely offline and exports ready-to-import CSVs for <strong>QuickBooks Online, Xero, and Wave</strong>.</p>
<p>You can test the live browser-local Gumroad demo right now (no signup, zero network calls):
<strong><a href="https://mscsupport2026-lab.github.io/creator-csv-demo/">Live 1-Click Offline Demo (GitHub Pages)</a></strong></p>
<p>Here are the four real-world bookkeeping edge cases I had to handle in pure JavaScript while building it.</p>
<hr />
<h2>1. The Stripe Balance CSV "Double-Counting" Trap</h2>
<p>If you export <strong>Balance Transactions</strong> from Stripe and blindly sum the <code>Amount</code> column, your accounting software will end up completely wrong—because Stripe mixes <strong>customer charges</strong> and <strong>bank transfer <code>payout</code> rows</strong> in the same CSV!</p>
<p>A bank payout is an internal balance transfer, <em>not</em> negative revenue. Excluding rows where <code>Type === "payout"</code> (and surfacing a clear warning count so the user can audit what was filtered) prevents silent double-counting:</p>
<pre><code class="language-javascript">for (let i = 0; i &lt; rows.length; i++) {
  const r = rows[i];
  const txType = typeCol ? String(r[typeCol] || "").toLowerCase() : "";

  // Stripe balance transactions include bank payouts (transfers, not revenue)
  if (txType === "payout") {
    payoutSkipped += 1;
    continue;
  }

  const gross = parseNumber(grossCol ? r[grossCol] : 0);
  const fee = Math.abs(parseNumber(feeCol ? r[feeCol] : 0));
  const net = netCol &amp;&amp; r[netCol] !== "" ? parseNumber(r[netCol]) : gross - fee;
  // ...
}
</code></pre>
<p>Similarly, on <strong>Gumroad</strong>, refunded purchases can still show a positive <code>Price ($)</code> while carrying <code>Refunded = true</code>. Catching that flag explicitly avoids overstating gross sales:</p>
<pre><code class="language-javascript">const refunded = refundedCol &amp;&amp; /^(true|yes|1)$/i.test(String(r[refundedCol] || "").trim());
if (refunded &amp;&amp; gross &gt; 0) {
  warnings.push(`Gumroad row ${i + 2} is flagged Refunded=true; excluded as $0 net revenue.`);
}
</code></pre>
<hr />
<h2>2. Historical FX Conversion on Weekends &amp; Bank Holidays</h2>
<p>When a customer buys your product in <strong>EUR</strong> or <strong>GBP</strong> on a Sunday, official central-bank daily FX tables don't have a row for that date.</p>
<p>A clean offline pattern is to look up the exact ISO date first, and if missing, walk backward up to 10 calendar days to pick up the <strong>previous business day's rate</strong>—while recording the exact rate source (<code>FX prev-day(2026-02-10)</code>) in the exported ledger so your CPA can verify every single row:</p>
<pre><code class="language-javascript">export function lookupFxRate(dateIso, fromCurrency, fxConfig = {}) {
  const base = String(fxConfig.baseCurrency || "USD").toUpperCase();
  const cur = String(fromCurrency || base).toUpperCase();
  if (cur === base) return { rate: 1, source: base };

  const table = fxConfig.fxRates &amp;&amp; fxConfig.fxRates[cur];
  if (table &amp;&amp; table.size &gt; 0 &amp;&amp; /^\d{4}-\d{2}-\d{2}$/.test(dateIso)) {
    if (table.has(dateIso)) return { rate: table.get(dateIso), source: `FX(${dateIso})` };

    const [y, m, d] = dateIso.split("-").map(Number);
    const dt = new Date(Date.UTC(y, m - 1, d));
    for (let offset = 1; offset &lt;= 10; offset++) {
      const prev = new Date(dt.getTime() - offset * 86400000);
      const key = `${prev.getUTCFullYear()}-${String(prev.getUTCMonth() + 1).padStart(2, "0")}-${String(prev.getUTCDate()).padStart(2, "0")}`;
      if (table.has(key)) return { rate: table.get(key), source: `FX prev-day(${key})` };
    }
  }
  // Falls back to user-configured fixed rates if no FX CSV is uploaded
  // ...
}
</code></pre>
<hr />
<h2>3. QuickBooks vs. Xero vs. Wave: Subtle CSV Format Differences</h2>
<p>Even after splitting <strong>Gross Revenue</strong> and <strong>Platform Fees</strong> into separate accounting lines (so you don't accidentally book net payout as gross income), each major accounting app expects a different CSV dialect:</p>
<table>
<thead>
<tr>
<th align="left">Software</th>
<th align="left">Expected Header</th>
<th align="left">Date Format</th>
<th align="left">Sign Convention</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><strong>QuickBooks Online (4-col)</strong></td>
<td align="left"><code>Date,Description,Credit,Debit</code></td>
<td align="left"><code>MM/DD/YYYY</code></td>
<td align="left">Positive in <code>Credit</code>, fees in <code>Debit</code></td>
</tr>
<tr>
<td align="left"><strong>Xero Bank Statement</strong></td>
<td align="left"><code>*Date,*Amount,Payee,Description,Reference,Cheque Number</code></td>
<td align="left"><code>YYYY-MM-DD</code></td>
<td align="left">Signed <code>*Amount</code> (fees negative)</td>
</tr>
<tr>
<td align="left"><strong>Wave Accounting</strong></td>
<td align="left"><code>Date,Description,Amount</code></td>
<td align="left"><code>YYYY-MM-DD</code></td>
<td align="left">Signed <code>Amount</code> (fees negative)</td>
</tr>
</tbody></table>
<p>Generating all three (plus a full audit ledger with FX sources) from a single normalized <code>buildAccountingLines()</code> pipeline keeps totals reconciled to the cent across every export.</p>
<hr />
<h2>4. Locking Financial Data Locally with <code>CSP: default-src 'none'</code></h2>
<p>Revenue CSVs contain customer emails, order IDs, and income figures. Rather than asking creators to trust a backend privacy policy, the entire app is compiled into one static HTML file with:</p>
<pre><code class="language-html">&lt;meta
  http-equiv="Content-Security-Policy"
  content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none';"
&gt;
</code></pre>
<p>The browser itself blocks every network request—no <code>fetch</code>, no <code>XMLHttpRequest</code>, no third-party CDN, no analytics beacons. Double-click the <code>.html</code> file on Windows, macOS, or Linux in airplane mode and it works identically.</p>
<hr />
<h2>Try the Free Demo</h2>
<ul>
<li><strong>Free 1-Click Gumroad CSV Demo (Live in Browser):</strong> <a href="https://mscsupport2026-lab.github.io/creator-csv-demo/">https://mscsupport2026-lab.github.io/creator-csv-demo/</a><ul>
<li>Click <strong>"Load Sample Data"</strong> to test fee splitting and refund detection instantly, or drop your own Gumroad CSV.</li>
</ul>
</li>
<li><strong>GitHub Demo Repo:</strong> <a href="https://github.com/mscsupport2026-lab/creator-csv-demo">https://github.com/mscsupport2026-lab/creator-csv-demo</a></li>
</ul>
<p><em>(Full disclosure: The live demo handles Gumroad sales CSVs for free. If you also need Patreon, Stripe payout deduplication, Etsy, a Universal Custom Column Mapper for Ko-fi/Lemon Squeezy, Multi-Currency historical FX CSVs, and 1-click QuickBooks/Xero/Wave exports in a downloadable offline <code>.html</code> file, <strong>CreatorCSV Local Pro</strong> is available for a one-time $29 on <a href="https://mscassist.gumroad.com/l/ubtuhq">Gumroad</a>. Disclaimer: This is strictly a local CSV formatting utility, not tax or accounting advice. Parts of the drafting and test scaffolding were assisted by AI tools and verified with automated tests.)</em></p>
<p>Which platform's sales CSV has given you the biggest headache at tax time? Drop it in the comments—I'm always looking for weird CSV edge cases to handle cleanly!</p>
]]></content:encoded></item><item><title><![CDATA[How I Built a 100% Offline Word (.docx) vs PDF Contract Diff Tool in a Single HTML File]]></title><description><![CDATA[Parsing .docx natively with DecompressionStream, fixing PDF.js English word-gluing bugs, and enforcing zero cloud uploads with CSP connect-src 'none'.]]></description><link>https://mgventures.hashnode.dev/how-i-built-a-100-offline-word-docx-vs-pdf-contract-diff-tool-in-a-single-html-file</link><guid isPermaLink="true">https://mgventures.hashnode.dev/how-i-built-a-100-offline-word-docx-vs-pdf-contract-diff-tool-in-a-single-html-file</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Security]]></category><category><![CDATA[privacy]]></category><category><![CDATA[pdf]]></category><dc:creator><![CDATA[MG Ventures]]></dc:creator><pubDate>Mon, 30 Nov 2026 23:57:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0e0a0bc9639374e8e70af1/6ef5908d-c50f-4503-b182-b3de1ae68554.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If a client emails you a redlined NDA or consulting contract as a <strong>PDF</strong> while your original draft is in <strong>Word (<code>.docx</code>)</strong>, comparing them usually forces an uncomfortable choice:</p>
<ol>
<li>Upload confidential legal agreements to a free online diff website (potentially violating NDA terms).</li>
<li>Pay $15–$40/month (or $199+/year) for desktop diff software you only open a few times a month.</li>
</ol>
<p>I wanted something radically simpler: <strong>a single, self-contained <code>.html</code> file</strong> that you can open directly in any browser—even in airplane mode—drop a <code>.docx</code> on the left and a <code>.pdf</code> on the right, and get a clean word-level diff with <strong>zero network calls</strong>.</p>
<p>You can try the live browser-local demo right now (it runs strictly in your browser with no backend):
<strong><a href="https://mscsupport2026-lab.github.io/difflocal-demo/">Live 1-Click Offline Demo (GitHub Pages)</a></strong></p>
<p>Here are the four most interesting engineering hurdles I ran into while building it—and the exact JavaScript patterns that solved them.</p>
<hr />
<h2>1. Parsing <code>.docx</code> in ~60 Lines of Zero-Dependency JavaScript</h2>
<p>A <code>.docx</code> file is just a PKZIP archive containing <code>word/document.xml</code>. Most tutorials tell you to pull in <code>jszip</code> + <code>mammoth</code>, but modern browsers already ship with <code>DecompressionStream("deflate-raw")</code>.</p>
<p>By scanning the ZIP <strong>End of Central Directory (EOCD)</strong> record (<code>0x06054b50</code>) from the end of the file, we can safely handle <code>.docx</code> files saved by Microsoft Word, Google Docs, and LibreOffice—even when they use Data Descriptors (where compressed size isn't written in the local file header):</p>
<pre><code class="language-javascript">async function inflateRawBytes(compressedBytes) {
  const ds = new DecompressionStream("deflate-raw");
  const writer = ds.writable.getWriter();
  writer.write(compressedBytes);
  writer.close();

  const chunks = [];
  const reader = ds.readable.getReader();
  let total = 0;
  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    chunks.push(value);
    total += value.length;
  }

  const out = new Uint8Array(total);
  let offset = 0;
  for (const c of chunks) {
    out.set(c, offset);
    offset += c.length;
  }
  return out;
}
</code></pre>
<h3>The Hidden Word Bug: Tracked Deletions (<code>&lt;w:del&gt;</code>)</h3>
<p>When someone edits a <code>.docx</code> with <strong>Track Changes</strong> enabled, deleted text often remains inside <code>word/document.xml</code> wrapped in <code>&lt;w:del&gt;...&lt;/w:del&gt;</code>. If you naively extract all text nodes, deleted clauses silently ghost back into your diff!</p>
<p>Stripping <code>&lt;w:del&gt;</code> blocks <em>before</em> collecting <code>&lt;w:t&gt;</code> runs guarantees you only compare the live contract text:</p>
<pre><code class="language-javascript">export function parseDocxXmlToParagraphs(xmlText) {
  const cleaned = String(xmlText || "").replace(/&lt;w:del\b[^&gt;]*&gt;[\s\S]*?&lt;\/w:del&gt;/g, "");
  const paragraphs = [];
  const pRegex = /&lt;w:p\b[^&gt;]*&gt;([\s\S]*?)&lt;\/w:p&gt;/g;
  let pm;
  while ((pm = pRegex.exec(cleaned)) !== null) {
    const pBody = pm[1]
      .replace(/&lt;w:tab\b[^&gt;]*\/&gt;/g, " ")
      .replace(/&lt;w:br\b[^&gt;]*\/&gt;/g, "\n");
    const tRegex = /&lt;w:t\b[^&gt;]*&gt;([\s\S]*?)&lt;\/w:t&gt;/g;
    let text = "";
    let tm;
    while ((tm = tRegex.exec(pBody)) !== null) {
      text += decodeXmlEntities(tm[1]);
    }
    for (const ln of text.split("\n").map((s) =&gt; s.trim()).filter(Boolean)) {
      paragraphs.push(ln);
    }
  }
  return paragraphs;
}
</code></pre>
<hr />
<h2>2. Fixing the Classic <code>PDF.js</code> English Word-Gluing Bug</h2>
<p>When you extract text from a PDF via <code>page.getTextContent()</code> in Mozilla <code>PDF.js</code>, many PDF generators split words via X-coordinate positioning instead of literal <code>" "</code> space characters.</p>
<p>If you simply concatenate items on the same baseline (<code>last.text += it.str</code>), <code>"Consulting Agreement"</code> turns into <code>"ConsultingAgreement"</code>—causing massive false positives when comparing against <code>.docx</code>.</p>
<p>The fix is to compute each glyph run's visual font size and compare the horizontal gap <code>it.x - last.endX</code> against a fraction of the font size (<code>0.18 * fontSize</code>):</p>
<pre><code class="language-javascript">const gap = it.x - last.endX;
const needsSpace =
  gap &gt; it.fontSize * 0.18 &amp;&amp;
  !/\s$/.test(last.text) &amp;&amp;
  !/^\s/.test(it.str);

last.text += (needsSpace ? " " : "") + it.str;
last.endX = Math.max(last.endX, it.x + it.width);
</code></pre>
<p>That tiny geometric check eliminated almost all false word-merge diffs across real-world PDFs exported from Word, Google Docs, and DocuSign.</p>
<hr />
<h2>3. Absorbing Word ↔ PDF Typography Noise (Ligatures &amp; Smart Quotes)</h2>
<p>Even after clean extraction, comparing <code>.docx</code> against <code>.pdf</code> produces noisy diffs because PDF exporters often convert <code>"fi"</code> / <code>"fl"</code> into Unicode ligatures (<code>\uFB01</code>, <code>\uFB02</code>), swap straight quotes for curly quotes (<code>“</code> <code>”</code>), or emit non-breaking spaces (<code>\u00A0</code>).</p>
<p>Running a lightweight normalization layer before LCS comparison keeps the redline focused on <strong>real business changes</strong>—like <code>$5,000 Net 15</code> quietly changing to <code>$4,500 Net 45</code>, or IP ownership shifting from <em>"upon full payment"</em> to <em>"upon creation"</em>:</p>
<pre><code class="language-javascript">export function normalizeForComparisonEn(text, options = {}) {
  let s = String(text || "");
  if (options.ignoreTypographyAndSpace !== false) {
    s = s
      .replace(/\uFB00/g, "ff")
      .replace(/\uFB01/g, "fi")
      .replace(/\uFB02/g, "fl")
      .replace(/\uFB03/g, "ffi")
      .replace(/\uFB04/g, "ffl")
      .replace(/[\u2018\u2019\u201A]/g, "'")
      .replace(/[\u201C\u201D\u201E]/g, '"')
      .replace(/[\u2013\u2014\u2212\u2010]/g, "-")
      .replace(/\u00A0/g, " ")
      .replace(/\s+/g, " ")
      .trim();
  }
  if (options.ignoreCase === true) s = s.toLowerCase();
  return s;
}
</code></pre>
<hr />
<h2>4. Proving "Zero Cloud Uploads" Technically (CSP + Blob Worker)</h2>
<p>Saying <em>"we respect your privacy"</em> on a marketing page means nothing if an app still loads external scripts or analytics.</p>
<p>Instead, I compiled <code>pdf.min.js</code> inline, embedded <code>pdf.worker.min.js</code> as a Base64-decoded <code>Blob</code> URL, and locked the entire document with a strict <code>&lt;meta&gt;</code> Content Security Policy:</p>
<pre><code class="language-html">&lt;meta
  http-equiv="Content-Security-Policy"
  content="default-src 'none'; script-src 'unsafe-inline' blob:; worker-src blob:; style-src 'unsafe-inline'; img-src data:; connect-src 'none'; base-uri 'none'; form-action 'none';"
&gt;
</code></pre>
<p>Because <code>connect-src 'none'</code> is enforced by the browser engine itself, even if you inspect DevTools → Network while dropping confidential <code>.docx</code> and <code>.pdf</code> files, <strong>zero outbound requests can occur</strong>—and the file runs identically under <code>file://</code> with Wi-Fi turned off.</p>
<hr />
<h2>Try It Yourself (No Signup Needed)</h2>
<ul>
<li><strong>Free 1-Click Live Demo (up to 40 paragraphs):</strong> <a href="https://mscsupport2026-lab.github.io/difflocal-demo/">https://mscsupport2026-lab.github.io/difflocal-demo/</a><ul>
<li>Click <strong>"Load Sample Contract"</strong> to immediately see silent clause edits highlighted, or drag &amp; drop your own <code>.docx</code> / text-layer <code>.pdf</code> files.</li>
</ul>
</li>
<li><strong>GitHub Demo Repo:</strong> <a href="https://github.com/mscsupport2026-lab/difflocal-demo">https://github.com/mscsupport2026-lab/difflocal-demo</a></li>
</ul>
<p><em>(Full disclosure: The free demo compares the first 40 paragraphs right in your browser. If you need unlimited contract length, 1-click Printable Audit HTML Reports, Excel/Sheets Review Checklist CSV exports, and the downloadable standalone offline <code>.html</code> file, I also offer <strong>DiffLocal Pro</strong> as a one-time $39 purchase on <a href="https://mscassist.gumroad.com/l/difflocal-pro">Gumroad</a>. Note: This tool uses Mozilla PDF.js under Apache 2.0 and does not support scanned image-only PDFs without OCR text. Parts of the drafting and test scaffolding were assisted by AI tools and verified with automated tests.)</em></p>
<p>If you have thoughts on handling multi-column PDF layouts or table-cell diffs cleanly in pure JS, I'd love to hear your approach in the comments!</p>
]]></content:encoded></item></channel></rss>