local-diff-san 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: local-diff-san
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Single-pane word-flow and character-level local file and Git HEAD diff viewer for Sanskrit & Indic scholarship
5
5
  Author-email: Sanskrit Coders <sanskrit-programmers@googlegroups.com>
6
6
  License: MIT
@@ -20,7 +20,7 @@ Requires-Python: >=3.10
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
22
  Requires-Dist: fastapi>=0.100
23
- Requires-Dist: pull_requests_san>=0.1.1
23
+ Requires-Dist: pull_requests_san>=0.1.3
24
24
  Requires-Dist: pydantic>=2.0
25
25
  Requires-Dist: uvicorn>=0.23
26
26
  Dynamic: license-file
@@ -49,12 +49,15 @@ local-diff-san old_file.md new_file.md
49
49
  local-diff-san
50
50
  local-diff-san path/to/dir
51
51
 
52
+ # Export a standalone static HTML website (pure JS client-side file/text diffing)
53
+ local-diff-san --export-static docs/index.html
54
+
52
55
  # Or invoke as a Python module
53
56
  python -m local_diff_san old_file.md new_file.md
54
57
  ```
55
58
 
56
59
  ## Key Features
57
60
 
58
- - **Single-pane word-flow diff** (default) with intra-word character highlights and **2-pane LHS/RHS mode** (`Alt+S`), powered by `pull_requests_san.diff`.
61
+ - **Single-pane word-flow diff** (default) with intra-word character highlights and **2-pane LHS/RHS mode** (`Alt+S`), powered by `pull_requests_san.diff` on the CLI or pure-JS `DiffSanEngine` in static browser mode.
59
62
  - **Vedic grapheme (`\X`) & raw codepoint modes** keeping Vedic svara marks (`U+1CD3` `᳓`, etc.) attached to their akṣara.
60
- - **Unicode normalization (`NFC`/`NFD`/`NFKC`/`NFKD`) & `Ignore punct`**, customizable **Settings color pickers** (persisted across `pull_requests_san` and `local-diff-san`), **GoldenDict** lookup, and click-to-jump **IntelliJ IDEA** line opening.
63
+ - **Expandable collapsed context lines** (`↓ Expand 20 below`, `↑ Expand 20 above`, `↕ Expand all`), Unicode normalization (`NFC`/`NFD`/`NFKC`/`NFKD`), `Ignore punct`, customizable **Settings color pickers** (persisted across `pull_requests_san` and `local-diff-san`), **GoldenDict** lookup, and click-to-jump **IntelliJ IDEA** line opening.
@@ -22,12 +22,15 @@ local-diff-san old_file.md new_file.md
22
22
  local-diff-san
23
23
  local-diff-san path/to/dir
24
24
 
25
+ # Export a standalone static HTML website (pure JS client-side file/text diffing)
26
+ local-diff-san --export-static docs/index.html
27
+
25
28
  # Or invoke as a Python module
26
29
  python -m local_diff_san old_file.md new_file.md
27
30
  ```
28
31
 
29
32
  ## Key Features
30
33
 
31
- - **Single-pane word-flow diff** (default) with intra-word character highlights and **2-pane LHS/RHS mode** (`Alt+S`), powered by `pull_requests_san.diff`.
34
+ - **Single-pane word-flow diff** (default) with intra-word character highlights and **2-pane LHS/RHS mode** (`Alt+S`), powered by `pull_requests_san.diff` on the CLI or pure-JS `DiffSanEngine` in static browser mode.
32
35
  - **Vedic grapheme (`\X`) & raw codepoint modes** keeping Vedic svara marks (`U+1CD3` `᳓`, etc.) attached to their akṣara.
33
- - **Unicode normalization (`NFC`/`NFD`/`NFKC`/`NFKD`) & `Ignore punct`**, customizable **Settings color pickers** (persisted across `pull_requests_san` and `local-diff-san`), **GoldenDict** lookup, and click-to-jump **IntelliJ IDEA** line opening.
36
+ - **Expandable collapsed context lines** (`↓ Expand 20 below`, `↑ Expand 20 above`, `↕ Expand all`), Unicode normalization (`NFC`/`NFD`/`NFKC`/`NFKD`), `Ignore punct`, customizable **Settings color pickers** (persisted across `pull_requests_san` and `local-diff-san`), **GoldenDict** lookup, and click-to-jump **IntelliJ IDEA** line opening.
@@ -12,6 +12,7 @@ from local_diff_san.core import (
12
12
  read_git_blob,
13
13
  resolve_spec_from_paths,
14
14
  )
15
+ from local_diff_san.server import export_static_html, render_static_html
15
16
 
16
17
  __all__ = [
17
18
  "DEFAULT_REV",
@@ -21,7 +22,9 @@ __all__ = [
21
22
  "compare_file_with_head",
22
23
  "compare_two_files",
23
24
  "discover_git_dir_entries",
25
+ "export_static_html",
24
26
  "find_git_root",
25
27
  "read_git_blob",
28
+ "render_static_html",
26
29
  "resolve_spec_from_paths",
27
30
  ]
@@ -24,9 +24,25 @@ from local_diff_san import core
24
24
  _TEMPLATE_PATH = Path(__file__).with_name("templates") / "local_diff.html"
25
25
 
26
26
 
27
- def load_html_template() -> str:
28
- """Read the local diff viewer HTML template with shared diff CSS/JS injected."""
29
- return render_html_with_shared_assets(_TEMPLATE_PATH.read_text(encoding="utf-8"))
27
+ def load_html_template(*, static_mode: bool = False) -> str:
28
+ """Read the local diff viewer HTML template with shared diff CSS/JS/engine assets injected."""
29
+ raw = _TEMPLATE_PATH.read_text(encoding="utf-8")
30
+ flag = "true" if static_mode else "false"
31
+ raw = raw.replace("/* {{LOCAL_DIFF_STATIC_FLAG}} */ false", flag)
32
+ return render_html_with_shared_assets(raw)
33
+
34
+
35
+ def render_static_html() -> str:
36
+ """Render a self-contained static HTML website bundle for client-side file/text diffing."""
37
+ return load_html_template(static_mode=True)
38
+
39
+
40
+ def export_static_html(output_path: str | Path) -> Path:
41
+ """Write the self-contained static website HTML bundle to ``output_path``."""
42
+ dest = Path(output_path).expanduser().resolve()
43
+ dest.parent.mkdir(parents=True, exist_ok=True)
44
+ dest.write_text(render_static_html(), encoding="utf-8")
45
+ return dest
30
46
 
31
47
 
32
48
  def _resolve_idea_binary() -> str | None:
@@ -188,10 +204,16 @@ def main(argv: Sequence[str] | None = None) -> int:
188
204
  )
189
205
  p.add_argument("--rev", default=core.DEFAULT_REV, help="Git revision to compare against (default: HEAD).")
190
206
  p.add_argument("--head", action="store_true", help="Always compare passed path(s) against --rev even when 2 files are given.")
207
+ p.add_argument("--export-static", default="", help="Write a self-contained pure-JS static HTML page to FILE and exit.")
191
208
  p.add_argument("--port", type=int, default=8772, help="Port to bind on 127.0.0.1 (default: 8772 or next free port).")
192
209
  p.add_argument("--no-browser", action="store_true", help="Do not auto-open browser window.")
193
210
  args = p.parse_args(argv)
194
211
 
212
+ if args.export_static:
213
+ out = export_static_html(args.export_static)
214
+ print(f"Exported standalone static local-diff-san page to {out}", flush=True)
215
+ return 0
216
+
195
217
  spec = core.resolve_spec_from_paths(args.paths, rev=args.rev, force_head=args.head)
196
218
  try:
197
219
  core.build_diff_workspace(spec)
@@ -27,20 +27,77 @@
27
27
  }
28
28
  .label-chip.left { background: var(--red-row); color: var(--del-text); border-color: var(--del-word-border); }
29
29
  .label-chip.right { background: var(--ins-row); color: var(--ins-text); border-color: var(--ins-word-border); }
30
+ .static-inputs-grid {
31
+ display: grid;
32
+ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
33
+ gap: 12px;
34
+ }
35
+ @media (max-width: 900px) {
36
+ .static-inputs-grid { grid-template-columns: 1fr; }
37
+ }
38
+ .static-input-card {
39
+ background: var(--surface-2);
40
+ border: 1.5px dashed var(--border);
41
+ border-radius: 8px;
42
+ padding: 10px;
43
+ display: flex;
44
+ flex-direction: column;
45
+ gap: 7px;
46
+ }
47
+ .static-input-card.dragover {
48
+ border-color: var(--accent);
49
+ background: var(--accent-soft);
50
+ }
51
+ .static-textarea {
52
+ width: 100%;
53
+ min-height: 120px;
54
+ resize: vertical;
55
+ font-family: var(--dev);
56
+ font-size: calc(var(--dev-font-size) - 2px);
57
+ line-height: 1.5;
58
+ }
59
+ .workspace.static-no-sidebar {
60
+ grid-template-columns: minmax(0, 1fr);
61
+ }
30
62
  table.local-single col.col-num { width: 56px; }
31
63
  table.local-single col.col-single-code { width: calc(100% - 112px); }
32
64
  table.local-two col.col-num { width: 58px; }
33
65
  table.local-two col.col-code { width: calc(50% - 58px); }
66
+ .about-footer {
67
+ margin-top: 6px;
68
+ padding: 10px 14px;
69
+ border-top: 1px solid var(--border);
70
+ background: var(--surface);
71
+ border-radius: 8px;
72
+ color: var(--muted);
73
+ font-size: 15px;
74
+ line-height: 1.5;
75
+ display: flex;
76
+ flex-direction: column;
77
+ gap: 5px;
78
+ }
79
+ .about-footer a { color: var(--blue); text-decoration: none; font-weight: 500; }
80
+ .about-footer a:hover { text-decoration: underline; }
81
+ .about-footer code {
82
+ font-family: var(--mono);
83
+ font-size: 13.5px;
84
+ background: var(--surface-2);
85
+ border: 1px solid var(--border);
86
+ border-radius: 4px;
87
+ padding: 1px 6px;
88
+ color: var(--text);
89
+ }
34
90
  </style>
35
91
  </head>
36
92
  <body>
37
93
  <header>
38
94
  <div class="row">
39
95
  <strong style="font-size:21px;">local-diff-san</strong>
40
- <label>Mode:
96
+ <label id="modeSelectWrap">Mode:
41
97
  <select id="compareModeSelect" onchange="onCompareModeSwitch()">
42
98
  <option value="git">Git vs Rev</option>
43
99
  <option value="pair">2 Local Files</option>
100
+ <option value="texts">Upload / Paste Texts (Pure JS)</option>
44
101
  </select>
45
102
  </label>
46
103
  <span id="gitInputsRow" class="row" style="gap:6px;">
@@ -51,8 +108,14 @@
51
108
  <label>Left: <input id="leftPathInput" type="text" placeholder="left/old file..." style="width:260px;" onkeydown="if(event.key==='Enter') submitCompareSpec()" /></label>
52
109
  <label>Right: <input id="rightPathInput" type="text" placeholder="right/new file..." style="width:260px;" onkeydown="if(event.key==='Enter') submitCompareSpec()" /></label>
53
110
  </span>
111
+ <span id="staticActionsRow" class="row" style="gap:6px; display:none;">
112
+ <button id="toggleStaticInputsBtn" class="small" type="button" onclick="toggleStaticInputs()">▾ Hide Inputs</button>
113
+ <button id="loadSampleBtn" class="small" type="button" onclick="loadSanskritSample()">Load Sample</button>
114
+ <button id="swapTextsBtn" class="small" type="button" onclick="swapStaticTexts()">⇄ Swap</button>
115
+ <button id="clearTextsBtn" class="small" type="button" onclick="clearStaticTexts()">Clear</button>
116
+ </span>
54
117
  <button id="compareBtn" class="primary" type="button" onclick="submitCompareSpec()">Compare</button>
55
- <button id="refreshBtn" class="small" type="button" title="Reload from disk & Git (Ctrl+R)" onclick="refreshDiff()">↻ Refresh <span class="kbd-hint">Ctrl+R</span></button>
118
+ <button id="refreshBtn" class="small" type="button" title="Reload diff (Ctrl+R)" onclick="refreshDiff()">↻ Refresh <span class="kbd-hint">Ctrl+R</span></button>
56
119
  <button id="reloadBtn" class="small" type="button" onclick="window.location.reload()">↻ Reload UI</button>
57
120
  <span id="statusText" style="color:var(--muted); font-size:16px;"></span>
58
121
  </div>
@@ -80,6 +143,9 @@
80
143
  <label style="display:inline-flex; align-items:center; gap:5px; cursor:pointer;" title="Single pane inline word flow (Alt+S)">
81
144
  <input id="singlePaneChk" type="checkbox" checked onchange="toggleSinglePane(this.checked)" /> Single pane <span class="kbd-hint">Alt+S</span>
82
145
  </label>
146
+ <label style="display:inline-flex; align-items:center; gap:5px; cursor:pointer;" title="Collapse long runs of unchanged context lines with expandable gaps">
147
+ <input id="collapseContextChk" type="checkbox" checked onchange="renderWorkspace()" /> Collapse unchanged
148
+ </label>
83
149
  <label style="display:inline-flex; align-items:center; gap:5px; cursor:pointer;">
84
150
  <input id="changedOnlyChk" type="checkbox" onchange="renderWorkspace()" /> Changed lines only
85
151
  </label>
@@ -92,8 +158,8 @@
92
158
  </header>
93
159
  <div id="settingsPane" class="settings-drawer" style="display:none;"></div>
94
160
 
95
- <div class="workspace">
96
- <aside class="sidebar">
161
+ <div id="workspaceEl" class="workspace">
162
+ <aside id="sidebarEl" class="sidebar">
97
163
  <div class="sidebar-section sidebar-local-files">
98
164
  <div class="pane-title">
99
165
  <span>Compared Files (<span id="fileCountLabel">0</span>)</span>
@@ -105,17 +171,59 @@
105
171
 
106
172
  <main id="mainPane">
107
173
  <div id="errorBanner" class="error-banner"></div>
174
+ <div id="staticTextInputsPanel" class="card" style="display:none;">
175
+ <div class="static-inputs-grid">
176
+ <div class="static-input-card" ondragover="event.preventDefault(); this.classList.add('dragover')" ondragleave="this.classList.remove('dragover')" ondrop="handleDropFile(event, 'left')">
177
+ <div class="row" style="justify-content:space-between;">
178
+ <strong>Old / Left File or Text</strong>
179
+ <input id="staticLeftFile" type="file" onchange="handlePickFile(this, 'left')" style="max-width:250px; font-size:14px;" />
180
+ </div>
181
+ <div class="mono" id="staticLeftLabel" style="font-size:14px; color:var(--muted);">left.md (paste text or upload / drop a file)</div>
182
+ <textarea id="staticLeftText" class="static-textarea" placeholder="Paste or drop left/old Sanskrit text..." oninput="scheduleStaticDiff()"></textarea>
183
+ </div>
184
+ <div class="static-input-card" ondragover="event.preventDefault(); this.classList.add('dragover')" ondragleave="this.classList.remove('dragover')" ondrop="handleDropFile(event, 'right')">
185
+ <div class="row" style="justify-content:space-between;">
186
+ <strong>New / Right File or Text</strong>
187
+ <input id="staticRightFile" type="file" onchange="handlePickFile(this, 'right')" style="max-width:250px; font-size:14px;" />
188
+ </div>
189
+ <div class="mono" id="staticRightLabel" style="font-size:14px; color:var(--muted);">right.md (paste text or upload / drop a file)</div>
190
+ <textarea id="staticRightText" class="static-textarea" placeholder="Paste or drop right/new Sanskrit text..." oninput="scheduleStaticDiff()"></textarea>
191
+ </div>
192
+ </div>
193
+ </div>
108
194
  <div id="diffContainer">
109
195
  <div class="card">Loading diff...</div>
110
196
  </div>
111
- <div style="color:var(--muted); font-size:15px; padding:4px 0;">Shortcuts: Alt+S Single/2-Pane • Ctrl+R Refresh from disk/Git • j/k/↑/↓ Navigate files • Esc Close Settings</div>
197
+ <div id="shortcutFooter" style="color:var(--muted); font-size:15px; padding:4px 0;">Shortcuts: Alt+S Single/2-Pane • Ctrl+R Refresh • j/k/↑/↓ Navigate files • Esc Close Settings</div>
198
+ <footer id="aboutFooter" class="about-footer">
199
+ <div>
200
+ <strong>diff_san</strong> (<a href="https://github.com/sanskrit-coders/diff_san" target="_blank" rel="noopener noreferrer">github.com/sanskrit-coders/diff_san</a>) —
201
+ Sanskrit &amp; Indic <strong>character-level</strong>, <strong>Vedic grapheme (<code>\X</code>)</strong>, and <strong>single-pane inline word-flow</strong> diff viewer with intra-word highlights across reflowed lines, optional 2-pane LHS/RHS mode, Unicode normalization, punctuation-ignore mode, and expandable context lines. Runs locally in pure JS with zero server uploads.
202
+ </div>
203
+ <div>
204
+ Python / CLI packages on PyPI:
205
+ <a href="https://pypi.org/project/local-diff-san/" target="_blank" rel="noopener noreferrer"><code>pip install local-diff-san</code></a> (compare local files or Git <code>HEAD</code> revisions)
206
+ · <a href="https://pypi.org/project/pull-requests-san/" target="_blank" rel="noopener noreferrer"><code>pip install pull_requests_san</code></a> (GitHub PR reviewer).
207
+ </div>
208
+ </footer>
112
209
  </main>
113
210
  </div>
114
211
 
115
212
  <script>
213
+ // {{SHARED_DIFF_ENGINE_JS}}
116
214
  // {{SHARED_DIFF_JS}}
215
+ const IS_STATIC_HOST = /* {{LOCAL_DIFF_STATIC_FLAG}} */ false || (typeof window !== "undefined" && window.location && window.location.protocol === "file:");
117
216
  let workspaceData = null;
118
217
  let selectedItemId = null;
218
+ let staticLeftName = "left.md";
219
+ let staticRightName = "right.md";
220
+ let staticInputsCollapsed = false;
221
+ let staticDiffTimer = null;
222
+
223
+ function isClientTextMode() {
224
+ if (IS_STATIC_HOST) return true;
225
+ return (document.getElementById("compareModeSelect")?.value || "git") === "texts";
226
+ }
119
227
 
120
228
  function getDiffMode() {
121
229
  return document.getElementById("diffModeSelect")?.value || "word";
@@ -140,15 +248,46 @@ function toggleSinglePane(checked) {
140
248
  renderWorkspace();
141
249
  }
142
250
 
251
+ function toggleStaticInputs(forceCollapse = null) {
252
+ staticInputsCollapsed = forceCollapse === null ? !staticInputsCollapsed : !!forceCollapse;
253
+ const panel = document.getElementById("staticTextInputsPanel");
254
+ const btn = document.getElementById("toggleStaticInputsBtn");
255
+ if (panel) panel.style.display = (isClientTextMode() && !staticInputsCollapsed) ? "flex" : "none";
256
+ if (btn) btn.textContent = staticInputsCollapsed ? "▸ Show Inputs" : "▾ Hide Inputs";
257
+ }
258
+
259
+ function applyModeLayoutUi() {
260
+ const modeVal = isClientTextMode() ? "texts" : (document.getElementById("compareModeSelect")?.value || "git");
261
+ const isTexts = modeVal === "texts";
262
+ const isPair = modeVal === "pair";
263
+ const gitRow = document.getElementById("gitInputsRow");
264
+ const pairRow = document.getElementById("pairInputsRow");
265
+ const staticRow = document.getElementById("staticActionsRow");
266
+ const staticPanel = document.getElementById("staticTextInputsPanel");
267
+ const sidebarEl = document.getElementById("sidebarEl");
268
+ const wsEl = document.getElementById("workspaceEl");
269
+ const compareBtn = document.getElementById("compareBtn");
270
+ const gdBtn = document.getElementById("gdSelectionBtn");
271
+ const modeWrap = document.getElementById("modeSelectWrap");
272
+
273
+ if (IS_STATIC_HOST) {
274
+ if (modeWrap) modeWrap.style.display = "none";
275
+ if (gdBtn) gdBtn.style.display = "none";
276
+ }
277
+ if (gitRow) gitRow.style.display = (!isTexts && !isPair) ? "flex" : "none";
278
+ if (pairRow) pairRow.style.display = (!isTexts && isPair) ? "flex" : "none";
279
+ if (staticRow) staticRow.style.display = isTexts ? "flex" : "none";
280
+ if (staticPanel) staticPanel.style.display = (isTexts && !staticInputsCollapsed) ? "flex" : "none";
281
+ if (compareBtn) compareBtn.style.display = isTexts ? "none" : "inline-block";
282
+ if (sidebarEl) sidebarEl.style.display = isTexts ? "none" : "flex";
283
+ if (wsEl && wsEl.classList) wsEl.classList.toggle("static-no-sidebar", isTexts);
284
+ }
285
+
143
286
  function syncSpecInputs(spec) {
144
- if (!spec) return;
287
+ if (!spec || isClientTextMode()) return;
145
288
  const isPair = spec.mode === "file_pair";
146
289
  const sel = document.getElementById("compareModeSelect");
147
290
  if (sel) sel.value = isPair ? "pair" : "git";
148
- const gitRow = document.getElementById("gitInputsRow");
149
- const pairRow = document.getElementById("pairInputsRow");
150
- if (gitRow) gitRow.style.display = isPair ? "none" : "flex";
151
- if (pairRow) pairRow.style.display = isPair ? "flex" : "none";
152
291
  if (isPair) {
153
292
  const lp = document.getElementById("leftPathInput");
154
293
  const rp = document.getElementById("rightPathInput");
@@ -160,15 +299,143 @@ function syncSpecInputs(spec) {
160
299
  if (gp) gp.value = (spec.paths && spec.paths[0]) || "";
161
300
  if (rv) rv.value = spec.rev || "HEAD";
162
301
  }
302
+ applyModeLayoutUi();
163
303
  }
164
304
 
165
305
  function onCompareModeSwitch() {
166
- const modeVal = document.getElementById("compareModeSelect")?.value || "git";
167
- const isPair = modeVal === "pair";
168
- const gitRow = document.getElementById("gitInputsRow");
169
- const pairRow = document.getElementById("pairInputsRow");
170
- if (gitRow) gitRow.style.display = isPair ? "none" : "flex";
171
- if (pairRow) pairRow.style.display = isPair ? "flex" : "none";
306
+ applyModeLayoutUi();
307
+ if (isClientTextMode()) {
308
+ computeStaticTextDiff();
309
+ }
310
+ }
311
+
312
+ function handlePickFile(inputEl, side) {
313
+ const file = inputEl?.files?.[0];
314
+ if (!file) return;
315
+ const reader = new FileReader();
316
+ reader.onload = () => {
317
+ if (side === "left") {
318
+ staticLeftName = file.name || "left.md";
319
+ const lbl = document.getElementById("staticLeftLabel");
320
+ const ta = document.getElementById("staticLeftText");
321
+ if (lbl) lbl.textContent = staticLeftName;
322
+ if (ta) ta.value = String(reader.result || "");
323
+ } else {
324
+ staticRightName = file.name || "right.md";
325
+ const lbl = document.getElementById("staticRightLabel");
326
+ const ta = document.getElementById("staticRightText");
327
+ if (lbl) lbl.textContent = staticRightName;
328
+ if (ta) ta.value = String(reader.result || "");
329
+ }
330
+ computeStaticTextDiff();
331
+ };
332
+ reader.readAsText(file);
333
+ }
334
+
335
+ function handleDropFile(ev, side) {
336
+ ev.preventDefault();
337
+ if (ev.currentTarget?.classList) ev.currentTarget.classList.remove("dragover");
338
+ const file = ev.dataTransfer?.files?.[0];
339
+ if (!file) return;
340
+ handlePickFile({ files: [file] }, side);
341
+ }
342
+
343
+ function scheduleStaticDiff() {
344
+ if (staticDiffTimer) clearTimeout(staticDiffTimer);
345
+ staticDiffTimer = setTimeout(() => { computeStaticTextDiff(); }, 120);
346
+ }
347
+
348
+ function swapStaticTexts() {
349
+ const lTa = document.getElementById("staticLeftText");
350
+ const rTa = document.getElementById("staticRightText");
351
+ const tmpTxt = lTa?.value || "";
352
+ if (lTa) lTa.value = rTa?.value || "";
353
+ if (rTa) rTa.value = tmpTxt;
354
+ const tmpName = staticLeftName;
355
+ staticLeftName = staticRightName;
356
+ staticRightName = tmpName;
357
+ const ll = document.getElementById("staticLeftLabel");
358
+ const rl = document.getElementById("staticRightLabel");
359
+ if (ll) ll.textContent = staticLeftName;
360
+ if (rl) rl.textContent = staticRightName;
361
+ computeStaticTextDiff();
362
+ }
363
+
364
+ function clearStaticTexts() {
365
+ const lTa = document.getElementById("staticLeftText");
366
+ const rTa = document.getElementById("staticRightText");
367
+ if (lTa) lTa.value = "";
368
+ if (rTa) rTa.value = "";
369
+ staticLeftName = "left.md";
370
+ staticRightName = "right.md";
371
+ computeStaticTextDiff();
372
+ }
373
+
374
+ function loadSanskritSample() {
375
+ const lTa = document.getElementById("staticLeftText");
376
+ const rTa = document.getElementById("staticRightText");
377
+ staticLeftName = "bhAgavatam_old.md";
378
+ staticRightName = "bhAgavatam_new.md";
379
+ const ll = document.getElementById("staticLeftLabel");
380
+ const rl = document.getElementById("staticRightLabel");
381
+ if (ll) ll.textContent = staticLeftName;
382
+ if (rl) rl.textContent = staticRightName;
383
+ if (lTa) {
384
+ lTa.value = [
385
+ "<details><summary>वीरराघवः [यान्त्रिकम्]</summary>",
386
+ "",
387
+ "**आविध्यति** । स सुरः शूलम् [^v5]आविध्याऽऽलोल्य[^v5] तरसा बलेन गरुडाय",
388
+ "इमा᳓म् अ᳓रण्या ते᳓जसा पा० प्रणयो ऽस्येति ।",
389
+ "[^v5]: K उद्धृत्य",
390
+ "</details>",
391
+ ].join("\n");
392
+ }
393
+ if (rTa) {
394
+ rTa.value = [
395
+ "<details><summary>वीरराघवः</summary>",
396
+ "",
397
+ "**आविध्यति** । स सुरः शूलम् आविध्याऽऽलोल्य तरसा बलेन गरुडाय",
398
+ "इमा᳓म् अर᳓ण्या ते᳓जसा पा॰ प्रणयोऽस्येति ॥",
399
+ "</details>",
400
+ ].join("\n");
401
+ }
402
+ computeStaticTextDiff();
403
+ }
404
+
405
+ function computeStaticTextDiff() {
406
+ showError("");
407
+ if (!window.DiffSanEngine) {
408
+ showError("Pure-JS diff engine failed to load.");
409
+ return;
410
+ }
411
+ const leftText = document.getElementById("staticLeftText")?.value || "";
412
+ const rightText = document.getElementById("staticRightText")?.value || "";
413
+ const opts = getDiffOptions();
414
+ const hunk = window.DiffSanEngine.buildFullFileHunk(leftText, rightText, {
415
+ charDiffMode: opts.diff_mode,
416
+ normalize: opts.normalize,
417
+ ignorePunct: opts.ignore_punct,
418
+ });
419
+ const unchanged = leftText === rightText;
420
+ const item = {
421
+ id: "static:0",
422
+ title: `${staticLeftName} ↔ ${staticRightName}`,
423
+ mode: "file_pair",
424
+ status: unchanged ? "unchanged" : "modified",
425
+ left_label: staticLeftName,
426
+ right_label: staticRightName,
427
+ left_path: null,
428
+ right_path: null,
429
+ additions: hunk.additions || 0,
430
+ deletions: hunk.deletions || 0,
431
+ is_binary: false,
432
+ hunks: [hunk],
433
+ };
434
+ workspaceData = { spec: { mode: "texts" }, repo_root: null, items: [item], active_item: item };
435
+ selectedItemId = item.id;
436
+ clearExpandedGaps("local:");
437
+ renderWorkspace();
438
+ setStatus("Computed in browser (Pure JS)", 1800);
172
439
  }
173
440
 
174
441
  function statusPillClass(st) {
@@ -179,6 +446,7 @@ function statusPillClass(st) {
179
446
  }
180
447
 
181
448
  function renderSidebar() {
449
+ if (isClientTextMode()) return;
182
450
  const items = workspaceData?.items || [];
183
451
  const cntEl = document.getElementById("fileCountLabel");
184
452
  if (cntEl) cntEl.textContent = String(items.length);
@@ -189,7 +457,7 @@ function renderSidebar() {
189
457
  return;
190
458
  }
191
459
  const activeId = workspaceData?.active_item?.id || selectedItemId || items[0].id;
192
- listEl.innerHTML = items.map((it, idx) => {
460
+ listEl.innerHTML = items.map(it => {
193
461
  const isAct = it.id === activeId;
194
462
  return `<div class="file-item ${isAct ? 'active' : ''}" onclick="selectItem('${esc(it.id)}')">
195
463
  <div class="mono" style="font-size:15.5px; font-weight:600; word-break:break-word;">${esc(it.title)}</div>
@@ -204,23 +472,30 @@ function renderSidebar() {
204
472
 
205
473
  function renderLocalLineCell(num, diskPath) {
206
474
  const numTxt = num != null ? num : "";
207
- if (num != null && diskPath) {
475
+ if (num != null && diskPath && !IS_STATIC_HOST) {
208
476
  const jsPath = esc(JSON.stringify(diskPath));
209
477
  return `<td class="ln clickable" title="Open in IntelliJ IDEA at line ${num}" onclick="openPathInIdea(${jsPath}, ${num})">${numTxt}</td>`;
210
478
  }
211
479
  return `<td class="ln">${numTxt}</td>`;
212
480
  }
213
481
 
482
+ function expandGapRow(gapKey, dir, count) {
483
+ setGapExpandedState(gapKey, dir, count);
484
+ renderWorkspace();
485
+ }
486
+
214
487
  function renderDiffItemHtml(item) {
215
488
  if (!item) {
216
489
  return `<div class="card">
217
490
  <div><strong>No changed files found</strong> against <span class="mono">${esc(workspaceData?.spec?.rev || 'HEAD')}</span>.</div>
218
- <div style="color:var(--muted); font-size:16px;">Switch to <strong>2 Local Files</strong> or enter a path above to compare.</div>
491
+ <div style="color:var(--muted); font-size:16px;">Switch to <strong>2 Local Files</strong> or <strong>Upload / Paste Texts (Pure JS)</strong> above.</div>
219
492
  </div>`;
220
493
  }
221
494
  const singlePane = isSinglePaneMode();
222
495
  const changedOnly = !!document.getElementById("changedOnlyChk")?.checked;
496
+ const collapseCtx = document.getElementById("collapseContextChk") ? !!document.getElementById("collapseContextChk").checked : true;
223
497
  const wrapClass = document.getElementById("wrapLinesChk")?.checked ? "wrap-on" : "wrap-off";
498
+ const collapseMode = changedOnly ? "changed_only" : (collapseCtx ? "long_runs" : "none");
224
499
 
225
500
  let bodyHtml = "";
226
501
  if (item.is_binary) {
@@ -228,13 +503,22 @@ function renderDiffItemHtml(item) {
228
503
  } else if (!(item.hunks || []).length) {
229
504
  bodyHtml = `<div style="padding:12px; color:var(--muted);">Empty file or no textual lines.</div>`;
230
505
  } else {
231
- bodyHtml = (item.hunks || []).map(h => {
506
+ bodyHtml = (item.hunks || []).map((h, hi) => {
232
507
  const useInline = singlePane && Array.isArray(h.inline_rows) && h.inline_rows.length;
233
508
  const baseRows = useInline ? h.inline_rows : (h.rows || []);
234
- const rows = changedOnly ? baseRows.filter(r => r.kind !== "context") : baseRows;
235
- if (changedOnly && !rows.length) return "";
509
+ const colspan = useInline ? 3 : 4;
510
+ const renderItems = buildGapAwareRenderItems(baseRows, {
511
+ gapPrefix: `local:${item.id}:${hi}`,
512
+ mode: collapseMode,
513
+ contextRadius: 3,
514
+ minCollapse: 8,
515
+ });
516
+ if (changedOnly && !renderItems.some(it => it.type === "row")) return "";
517
+
236
518
  if (useInline) {
237
- const rowsHtml = rows.map(r => {
519
+ const rowsHtml = renderItems.map(it => {
520
+ if (it.type === "gap") return renderGapRowHtml(it, colspan, "expandGapRow");
521
+ const r = it.r;
238
522
  const rowCls = `diff-row single-row-${esc(r.kind || 'modify')}`;
239
523
  return `<tr class="${rowCls}">
240
524
  ${renderLocalLineCell(r.left_num, item.left_path)}
@@ -248,7 +532,9 @@ function renderDiffItemHtml(item) {
248
532
  <tbody>${rowsHtml}</tbody>
249
533
  </table>`;
250
534
  }
251
- const rowsHtml = rows.map(r => {
535
+ const rowsHtml = renderItems.map(it => {
536
+ if (it.type === "gap") return renderGapRowHtml(it, colspan, "expandGapRow");
537
+ const r = it.r;
252
538
  const rowCls = `diff-row diff-row-${esc(r.kind || 'modify')}`;
253
539
  const lhsHtml = r.left_text == null ? "" : renderDiffSegments(r.lhs_segments);
254
540
  const rhsHtml = r.right_text == null ? "" : renderDiffSegments(r.rhs_segments);
@@ -272,10 +558,10 @@ function renderDiffItemHtml(item) {
272
558
  }
273
559
  }
274
560
 
275
- const leftBtn = item.left_path
561
+ const leftBtn = (item.left_path && !IS_STATIC_HOST)
276
562
  ? `<button class="small" type="button" onclick="openPathInIdea(${esc(JSON.stringify(item.left_path))}, null)">Open Left in IDEA</button>`
277
563
  : "";
278
- const rightBtn = item.right_path
564
+ const rightBtn = (item.right_path && !IS_STATIC_HOST)
279
565
  ? `<button class="small" type="button" onclick="openPathInIdea(${esc(JSON.stringify(item.right_path))}, null)">Open Right in IDEA</button>`
280
566
  : "";
281
567
 
@@ -301,6 +587,7 @@ function renderDiffItemHtml(item) {
301
587
  }
302
588
 
303
589
  function renderWorkspace() {
590
+ applyModeLayoutUi();
304
591
  renderSidebar();
305
592
  const container = document.getElementById("diffContainer");
306
593
  if (!container) return;
@@ -308,6 +595,10 @@ function renderWorkspace() {
308
595
  }
309
596
 
310
597
  async function fetchDiff(activeId = null) {
598
+ if (isClientTextMode()) {
599
+ computeStaticTextDiff();
600
+ return;
601
+ }
311
602
  showError("");
312
603
  const opts = getDiffOptions();
313
604
  const params = new URLSearchParams({
@@ -320,6 +611,7 @@ async function fetchDiff(activeId = null) {
320
611
  try {
321
612
  workspaceData = await apiJson(`/api/diff?${params.toString()}`, null, "Failed to compute diff");
322
613
  selectedItemId = workspaceData.active_item?.id || null;
614
+ clearExpandedGaps("local:");
323
615
  syncSpecInputs(workspaceData.spec);
324
616
  renderWorkspace();
325
617
  setStatus("Ready", 1800);
@@ -330,6 +622,10 @@ async function fetchDiff(activeId = null) {
330
622
  }
331
623
 
332
624
  async function submitCompareSpec() {
625
+ if (isClientTextMode()) {
626
+ computeStaticTextDiff();
627
+ return;
628
+ }
333
629
  showError("");
334
630
  const modeVal = document.getElementById("compareModeSelect")?.value || "git";
335
631
  const opts = getDiffOptions();
@@ -354,6 +650,7 @@ async function submitCompareSpec() {
354
650
  body: JSON.stringify(payload),
355
651
  }, "Compare failed");
356
652
  selectedItemId = workspaceData.active_item?.id || null;
653
+ clearExpandedGaps("local:");
357
654
  syncSpecInputs(workspaceData.spec);
358
655
  renderWorkspace();
359
656
  setStatus("Updated", 1800);
@@ -414,6 +711,15 @@ async function init() {
414
711
  const ipChk = document.getElementById("ignorePunctChk");
415
712
  if (ipChk && (savedIp === "true" || savedIp === "false")) ipChk.checked = savedIp === "true";
416
713
  } catch (_) {}
714
+
715
+ if (IS_STATIC_HOST) {
716
+ const cm = document.getElementById("compareModeSelect");
717
+ if (cm) cm.value = "texts";
718
+ applyModeLayoutUi();
719
+ loadSanskritSample();
720
+ return;
721
+ }
722
+
417
723
  try {
418
724
  const meta = await apiJson("/api/meta", null, "Failed to load metadata");
419
725
  syncSpecInputs(meta.spec);
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: local-diff-san
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Single-pane word-flow and character-level local file and Git HEAD diff viewer for Sanskrit & Indic scholarship
5
5
  Author-email: Sanskrit Coders <sanskrit-programmers@googlegroups.com>
6
6
  License: MIT
@@ -20,7 +20,7 @@ Requires-Python: >=3.10
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
22
  Requires-Dist: fastapi>=0.100
23
- Requires-Dist: pull_requests_san>=0.1.1
23
+ Requires-Dist: pull_requests_san>=0.1.3
24
24
  Requires-Dist: pydantic>=2.0
25
25
  Requires-Dist: uvicorn>=0.23
26
26
  Dynamic: license-file
@@ -49,12 +49,15 @@ local-diff-san old_file.md new_file.md
49
49
  local-diff-san
50
50
  local-diff-san path/to/dir
51
51
 
52
+ # Export a standalone static HTML website (pure JS client-side file/text diffing)
53
+ local-diff-san --export-static docs/index.html
54
+
52
55
  # Or invoke as a Python module
53
56
  python -m local_diff_san old_file.md new_file.md
54
57
  ```
55
58
 
56
59
  ## Key Features
57
60
 
58
- - **Single-pane word-flow diff** (default) with intra-word character highlights and **2-pane LHS/RHS mode** (`Alt+S`), powered by `pull_requests_san.diff`.
61
+ - **Single-pane word-flow diff** (default) with intra-word character highlights and **2-pane LHS/RHS mode** (`Alt+S`), powered by `pull_requests_san.diff` on the CLI or pure-JS `DiffSanEngine` in static browser mode.
59
62
  - **Vedic grapheme (`\X`) & raw codepoint modes** keeping Vedic svara marks (`U+1CD3` `᳓`, etc.) attached to their akṣara.
60
- - **Unicode normalization (`NFC`/`NFD`/`NFKC`/`NFKD`) & `Ignore punct`**, customizable **Settings color pickers** (persisted across `pull_requests_san` and `local-diff-san`), **GoldenDict** lookup, and click-to-jump **IntelliJ IDEA** line opening.
63
+ - **Expandable collapsed context lines** (`↓ Expand 20 below`, `↑ Expand 20 above`, `↕ Expand all`), Unicode normalization (`NFC`/`NFD`/`NFKC`/`NFKD`), `Ignore punct`, customizable **Settings color pickers** (persisted across `pull_requests_san` and `local-diff-san`), **GoldenDict** lookup, and click-to-jump **IntelliJ IDEA** line opening.
@@ -1,4 +1,4 @@
1
1
  fastapi>=0.100
2
- pull_requests_san>=0.1.1
2
+ pull_requests_san>=0.1.3
3
3
  pydantic>=2.0
4
4
  uvicorn>=0.23
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "local-diff-san"
7
- version = "0.1.0"
7
+ version = "0.1.2"
8
8
  description = "Single-pane word-flow and character-level local file and Git HEAD diff viewer for Sanskrit & Indic scholarship"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -24,7 +24,7 @@ classifiers = [
24
24
  ]
25
25
  dependencies = [
26
26
  "fastapi>=0.100",
27
- "pull_requests_san>=0.1.1",
27
+ "pull_requests_san>=0.1.3",
28
28
  "pydantic>=2.0",
29
29
  "uvicorn>=0.23",
30
30
  ]
File without changes
File without changes