-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext-diff.html
More file actions
563 lines (514 loc) Β· 32.2 KB
/
Copy pathtext-diff.html
File metadata and controls
563 lines (514 loc) Β· 32.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
<!DOCTYPE html>
<html lang="en">
<head>
<include src="_partials/meta-base.html"></include>
<title>Text Diff β HTML Tools</title>
<meta name="description" content="Compare two plain-text inputs line-by-line with word-level inline highlighting, split view, and scroll sync. Runs in your browser β no installs, no servers, no tracking.">
<link rel="canonical" href="https://tools.mazipan.space/text-diff">
<meta property="og:title" content="Text Diff β HTML Tools">
<meta property="og:description" content="Compare two plain-text inputs line-by-line with word-level inline highlighting, split view, and scroll sync. Runs in your browser β no installs, no servers, no tracking.">
<meta property="og:url" content="https://tools.mazipan.space/text-diff">
<meta name="twitter:title" content="Text Diff β HTML Tools">
<meta name="twitter:description" content="Compare two plain-text inputs line-by-line with word-level inline highlighting, split view, and scroll sync. Runs in your browser β no installs, no servers, no tracking.">
<include src="_partials/meta-social.html"></include>
<link rel="icon" type="image/png" sizes="32x32" href="favicon-text-diff.png">
<include src="_partials/head-fonts.html"></include>
<link rel="stylesheet" href="styles.css">
<style>
.diff-added { background: rgba(63,185,80,.12); border-left: 3px solid #3fb950; }
.diff-removed { background: rgba(248,81,73,.12); border-left: 3px solid #f85149; }
.diff-changed { background: rgba(210,153,34,.12); border-left: 3px solid #d2991e; }
.badge-added { background: rgba(63,185,80,.15); color: #3fb950; }
.badge-removed { background: rgba(248,81,73,.15); color: #f85149; }
.badge-changed { background: rgba(210,153,34,.15); color: #d2991e; }
mark.wd-rem { background: rgba(248,81,73,.40); color: inherit; border-radius: 2px; padding: 0 1px; }
mark.wd-add { background: rgba(63,185,80,.40); color: inherit; border-radius: 2px; padding: 0 1px; }
.split-panel {
height: 24rem;
overflow: auto;
border: 1px solid #374151;
border-radius: 0.5rem;
background: #111827;
font-family: 'SFMono-Regular', Consolas, monospace;
font-size: 0.8rem;
line-height: 1.6;
resize: vertical;
}
.diff-row { display: flex; min-width: max-content; width: 100%; }
.line-no {
min-width: 3rem;
color: #4b5563;
text-align: right;
padding: 0 0.5rem 0 0.75rem;
user-select: none;
flex-shrink: 0;
}
.line-txt {
flex: 1;
white-space: pre;
padding: 0 0.75rem 0 0.25rem;
}
.line-empty {
background: repeating-linear-gradient(
135deg,
rgba(255,255,255,.025) 0px,
rgba(255,255,255,.025) 4px,
transparent 4px,
transparent 8px
);
}
</style>
<include src="_partials/head-theme.html"></include>
<!-- BEGIN:json-ld generated by scripts/generate-sections.mjs β re-run after editing tools.json -->
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebApplication","name":"Text Diff","url":"https://tools.mazipan.space/text-diff","description":"Compare two plain-text inputs line-by-line with word-level inline highlighting, split view, line numbers, and scroll sync. Runs in your browser β no installs, no tracking.","applicationCategory":"DeveloperApplication","operatingSystem":"Any","browserRequirements":"Requires JavaScript","offers":{"@type":"Offer","price":"0","priceCurrency":"USD"},"isPartOf":{"@type":"WebSite","name":"HTML Tools","url":"https://tools.mazipan.space/"}}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"HTML Tools","item":"https://tools.mazipan.space/"},{"@type":"ListItem","position":2,"name":"Text Diff","item":"https://tools.mazipan.space/text-diff"}]}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":"How is this different from JSON Diff?","acceptedAnswer":{"@type":"Answer","text":"JSON Diff understands JSON structure β it compares keys, values, and nested objects semantically. Text Diff is format-agnostic: it diffs any two plain-text files line by line, so it works on code, prose, config files, or anything else."}},{"@type":"Question","name":"What does 'Ignore whitespace' do?","acceptedAnswer":{"@type":"Answer","text":"When checked, leading and trailing whitespace on each line is trimmed before comparing. A line that only changed indentation won't show as modified."}},{"@type":"Question","name":"What does 'Show unchanged lines' do?","acceptedAnswer":{"@type":"Answer","text":"By default only changed lines are shown (like git diff --unified=0). Enabling this option also renders unchanged context lines between hunks so you can see where each change sits."}},{"@type":"Question","name":"What format does 'Copy diff' produce?","acceptedAnswer":{"@type":"Answer","text":"A plain +/- prefixed text block: lines prefixed with + were added, - were removed, and unchanged context lines (if shown) have no prefix. It's human-readable without any special tooling."}},{"@type":"Question","name":"Does any text leave my browser?","acceptedAnswer":{"@type":"Answer","text":"No. The comparison runs entirely in your browser using a vanilla-JS LCS algorithm β there's no upload, no server, no network request of any kind."}}]}</script>
<!-- END:json-ld -->
</head>
<body class="bg-gray-950 text-gray-200 min-h-screen flex flex-col">
<header class="border-b border-gray-800 px-6 py-4">
<nav aria-label="Breadcrumb" class="max-w-[1100px] mx-auto flex items-center gap-3">
<a href="index.html" class="no-underline text-white font-bold text-lg tracking-tight hover:text-blue-400 transition-colors">
HTML Tools
</a>
<span class="text-gray-700">/</span>
<span class="text-gray-400 text-sm" aria-current="page">π Text Diff</span>
</nav>
</header>
<main class="max-w-[1100px] mx-auto w-full flex-1 py-8 px-6">
<header class="mb-7">
<h1 class="text-3xl font-bold text-white flex items-center gap-3">π Text Diff</h1>
<p class="mt-1.5 text-sm text-gray-500">Paste two plain-text blocks then compare line-by-line with word-level inline highlighting.</p>
</header>
<!-- Inputs -->
<div class="flex justify-end mb-2">
<button onclick="loadSample()" class="btn btn-secondary">π₯ Load sample</button>
</div>
<div class="grid grid-cols-2 gap-4 mb-4 max-md:grid-cols-1">
<div>
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wide block mb-2">Original</label>
<textarea id="left" placeholder="Paste original text hereβ¦" spellcheck="false"
class="w-full h-72 rounded-lg border border-gray-700 bg-gray-900 text-gray-200
font-mono text-[0.8rem] leading-relaxed p-4 resize-y outline-none
focus:border-blue-400 transition-colors"></textarea>
</div>
<div>
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wide block mb-2">Modified</label>
<textarea id="right" placeholder="Paste modified text hereβ¦" spellcheck="false"
class="w-full h-72 rounded-lg border border-gray-700 bg-gray-900 text-gray-200
font-mono text-[0.8rem] leading-relaxed p-4 resize-y outline-none
focus:border-blue-400 transition-colors"></textarea>
</div>
</div>
<!-- Toolbar -->
<div class="flex flex-wrap items-center gap-3 mb-6">
<button onclick="runCompare()" class="btn btn-primary">π Compare</button>
<button onclick="runReset()" class="btn btn-danger">β©οΈ Reset</button>
<button id="copy-btn" onclick="copyDiff()" class="btn btn-secondary" style="display:none">π Copy diff</button>
<label class="flex items-center gap-2 cursor-pointer select-none text-sm text-gray-400 hover:text-gray-200 transition-colors">
<input type="checkbox" id="ignore-ws"
class="w-4 h-4 rounded border-gray-600 bg-gray-800 accent-blue-400 cursor-pointer">
Ignore whitespace
</label>
</div>
<!-- Diff output -->
<div id="diff-output" style="display:none">
<!-- Summary badges -->
<div id="diff-summary" class="flex flex-wrap items-center gap-2 mb-4"></div>
<!-- Split view -->
<div class="flex items-center justify-between mb-2">
<div class="grid grid-cols-2 gap-4 flex-1 max-md:grid-cols-1">
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wide">Original</label>
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wide">Modified</label>
</div>
<label class="flex items-center gap-1.5 text-xs text-gray-400 hover:text-gray-200 cursor-pointer select-none ml-4">
<input type="checkbox" id="lock-scroll" checked
class="w-3.5 h-3.5 accent-blue-400 cursor-pointer">
Lock scroll
</label>
</div>
<div class="grid grid-cols-2 gap-4 max-md:grid-cols-1">
<div id="left-panel" class="split-panel"></div>
<div id="right-panel" class="split-panel"></div>
</div>
</div>
</main>
<section class="max-w-[1100px] mx-auto w-full px-6 py-8 border-t border-gray-800">
<div class="grid gap-6 md:grid-cols-2">
<div>
<h2 class="text-xl font-bold text-white mb-4">About Text Diff</h2>
<p class="text-gray-400 leading-relaxed">Paste two blocks of plain text β source code, config files, prose, or anything β to get a side-by-side split view highlighting exactly which lines were added, removed, or changed. Changed line pairs get word-level inline highlighting so you can spot typos and small edits at a glance.</p>
</div>
<div>
<h2 class="text-xl font-bold text-white mb-4">How to use</h2>
<ol class="text-gray-400 leading-relaxed space-y-2 list-decimal list-inside">
<li>Paste the original text in the left panel.</li>
<li>Paste the updated version in the right panel.</li>
<li>Click <strong class="text-gray-300">π Compare</strong> to run the diff.</li>
<li>Toggle <strong class="text-gray-300">Show unchanged lines</strong> to add context around each hunk.</li>
<li>Use <strong class="text-gray-300">π Copy diff</strong> to copy a <code class="text-gray-300">+/-</code> formatted summary.</li>
</ol>
</div>
<div>
<h2 class="text-xl font-bold text-white mb-4">Common use cases</h2>
<ul class="text-gray-400 leading-relaxed space-y-2 list-disc list-inside">
<li>Spotting differences between two versions of a config file.</li>
<li>Reviewing what changed in a copied-and-pasted code snippet.</li>
<li>Comparing two drafts of a document or email.</li>
<li>Verifying that a search-and-replace only touched the lines you intended.</li>
</ul>
</div>
<div>
<h2 class="text-xl font-bold text-white mb-4">Tips</h2>
<ul class="text-gray-400 leading-relaxed space-y-2 list-disc list-inside">
<li>Tick <strong class="text-gray-300">Ignore whitespace</strong> when only indentation changed and you care about content only.</li>
<li>Amber lines are <em>changed</em> β the specific words that differ are highlighted brighter within the line.</li>
<li>Scroll either panel; the other follows when <strong class="text-gray-300">Lock scroll</strong> is checked.</li>
</ul>
</div>
</div>
</section>
<!-- BEGIN:faq generated by scripts/generate-sections.mjs β re-run after editing tools.json -->
<section class="max-w-[1100px] mx-auto w-full px-6 py-8 border-t border-gray-800">
<h2 class="text-xl font-bold text-white mb-6">FAQ</h2>
<div class="space-y-2">
<details class="disclosure">
<summary>How is this different from JSON Diff?</summary>
<div class="disclosure-content"><div class="disclosure-body">JSON Diff understands JSON structure β it compares keys, values, and nested objects semantically. Text Diff is format-agnostic: it diffs any two plain-text files line by line, so it works on code, prose, config files, or anything else.</div></div>
</details>
<details class="disclosure">
<summary>What does 'Ignore whitespace' do?</summary>
<div class="disclosure-content"><div class="disclosure-body">When checked, leading and trailing whitespace on each line is trimmed before comparing. A line that only changed indentation won't show as modified.</div></div>
</details>
<details class="disclosure">
<summary>What does 'Show unchanged lines' do?</summary>
<div class="disclosure-content"><div class="disclosure-body">By default only changed lines are shown (like git diff --unified=0). Enabling this option also renders unchanged context lines between hunks so you can see where each change sits.</div></div>
</details>
<details class="disclosure">
<summary>What format does 'Copy diff' produce?</summary>
<div class="disclosure-content"><div class="disclosure-body">A plain +/- prefixed text block: lines prefixed with + were added, - were removed, and unchanged context lines (if shown) have no prefix. It's human-readable without any special tooling.</div></div>
</details>
<details class="disclosure">
<summary>Does any text leave my browser?</summary>
<div class="disclosure-content"><div class="disclosure-body">No. The comparison runs entirely in your browser using a vanilla-JS LCS algorithm β there's no upload, no server, no network request of any kind.</div></div>
</details>
</div>
</section>
<!-- END:faq -->
<!-- BEGIN:more-tools generated by scripts/generate-sections.mjs β re-run after editing tools.json -->
<section class="max-w-[1100px] mx-auto w-full px-6 py-8 border-t border-gray-800">
<h2 class="text-xl font-bold text-white mb-6">More tools</h2>
<div class="space-y-4">
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">JSON</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/json-formatter" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">ποΈ JSON Formatter</a>
<a href="/json-to-ts" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π· JSON to TypeScript</a>
<a href="/json-diff" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π JSON Diff</a>
<a href="/json-sort" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π€ JSON Sort</a>
<a href="/csv-to-json" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π JSON β CSV</a>
<a href="/json-to-yaml" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π JSON β YAML</a>
<a href="/json-to-schema" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π‘οΈ JSON to Validator Schema</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Code</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/regex-tester" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π§ͺ Regex Tester</a>
<a href="/svg-to-jsx" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ SVG to JSX</a>
<a href="/svg-rasterizer" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π· SVG to Raster</a>
<a href="/cron-decoder" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">β±οΈ Cron Decoder</a>
<a href="/snippet-to-image" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΈ Code Snippet to Image</a>
<a href="/markdown-preview" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Markdown Preview</a>
<a href="/semver-checker" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π·οΈ SemVer Checker</a>
<a href="/jwt-decoder" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π JWT Decoder</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Ornaments</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/gradients" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π¨ Gradients</a>
<a href="/blob" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π«§ Blob Generator</a>
<a href="/waves" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">γ°οΈ Wave Generator</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Image</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/image-compressor" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">ποΈ Image Compressor</a>
<a href="/image-resizer" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Image Resizer</a>
<a href="/image-cropper" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ Image Cropper</a>
<a href="/image-converter" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΌοΈ Image Format Converter</a>
<a href="/image-watermark" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Image Watermark</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Audio</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/mp3-tag-editor" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π΅ MP3 Tag Editor</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Web / SEO</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/meta-tag-preview" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Meta Tag Preview</a>
<a href="/user-agent-parser" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π΅οΈ User Agent Parser</a>
<a href="/og-image-builder" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΌοΈ OG Image Builder</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Generators</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/qr-code-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π± QR Code Generator</a>
<a href="/lorem-ipsum" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Lorem Ipsum Generator</a>
<a href="/avatar-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π€ Avatar Generator</a>
<a href="/favicon-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">β Favicon Generator</a>
<a href="/uuid-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πͺͺ UUID Generator</a>
<a href="/wheel-of-names" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π‘ Wheel of Names</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">PDF</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/pdf-merger" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π PDF Merger</a>
<a href="/image-to-pdf" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Image to PDF</a>
<a href="/pdf-compressor" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π€ PDF Compressor</a>
<a href="/pdf-splitter" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ PDF Splitter</a>
<a href="/pdf-page-manager" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">ποΈ PDF Page Manager</a>
<a href="/pdf-watermark" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π§ PDF Watermark</a>
<a href="/pdf-signature" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ PDF Signature</a>
<a href="/pdf-to-image" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΌοΈ PDF to Image</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Time</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/pomodoro-timer" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π
Pomodoro Timer</a>
</div>
</div>
</div>
</section>
<!-- END:more-tools -->
<footer class="max-w-[1100px] mx-auto w-full py-8 px-6 border-t border-gray-800 text-center text-sm text-gray-600">
<div>© <span id="year"></span> <a href="https://mazipan.space" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Irfan Maulana</a> & Claude</div>
<div><span id="deploy-time"></span></div>
<div><span id="commit-sha"></span><a href="https://github.com/mazipan/html-tools" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Source</a></div>
<div><a href="design-system.html" rel="nofollow" class="text-blue-400 transition-colors">Design system</a></div>
<div><a href="https://baca-quran.id" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Baca Quran</a> Β· <a href="https://games.mazipan.space" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Games</a></div>
</footer>
<include src="_partials/footer-script.html"></include>
<script>
const leftEl = document.getElementById('left');
const rightEl = document.getElementById('right');
const diffOutput = document.getElementById('diff-output');
const diffSummary = document.getElementById('diff-summary');
const leftPanel = document.getElementById('left-panel');
const rightPanel = document.getElementById('right-panel');
const copyBtn = document.getElementById('copy-btn');
const ignoreWsCb = document.getElementById('ignore-ws');
let lastRows = null;
let isSyncing = false;
// ββ Scroll sync ββββββββββββββββββββββββββββββββββββββββββββββββ
function setupScrollSync() {
function sync(src, tgt) {
src.addEventListener('scroll', () => {
if (!document.getElementById('lock-scroll').checked || isSyncing) return;
isSyncing = true;
tgt.scrollTop = src.scrollTop;
tgt.scrollLeft = src.scrollLeft;
requestAnimationFrame(() => { isSyncing = false; });
});
}
sync(leftPanel, rightPanel);
sync(rightPanel, leftPanel);
}
setupScrollSync();
// ββ Helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββ
function escHtml(s) {
return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
}
// ββ LCS-based line diff ββββββββββββββββββββββββββββββββββββββββ
function computeLineDiff(aLines, bLines, ignoreWS) {
const norm = s => ignoreWS ? s.trim() : s;
const A = aLines.map(norm), B = bLines.map(norm);
const m = A.length, n = B.length;
const dp = Array.from({length: m+1}, () => new Int32Array(n+1));
for (let i = m-1; i >= 0; i--)
for (let j = n-1; j >= 0; j--)
dp[i][j] = A[i] === B[j] ? dp[i+1][j+1]+1 : Math.max(dp[i+1][j], dp[i][j+1]);
const ops = [];
let i = 0, j = 0;
while (i < m || j < n) {
if (i < m && j < n && A[i] === B[j]) {
ops.push({op:'eq', ai:i, bi:j}); i++; j++;
} else if (j < n && (i >= m || dp[i][j+1] >= dp[i+1][j])) {
ops.push({op:'ins', bi:j}); j++;
} else {
ops.push({op:'del', ai:i}); i++;
}
}
// Group consecutive del/ins β pair them as 'changed', remainder as pure add/remove
const rows = [];
let k = 0;
while (k < ops.length) {
const op = ops[k];
if (op.op === 'eq') {
rows.push({type:'unchanged', leftLine:aLines[op.ai], rightLine:bLines[op.bi], leftNo:op.ai+1, rightNo:op.bi+1});
k++;
} else {
const dels = [], inss = [];
while (k < ops.length && ops[k].op !== 'eq') {
(ops[k].op === 'del' ? dels : inss).push(ops[k]); k++;
}
const paired = Math.min(dels.length, inss.length);
for (let p = 0; p < paired; p++)
rows.push({type:'changed', leftLine:aLines[dels[p].ai], rightLine:bLines[inss[p].bi], leftNo:dels[p].ai+1, rightNo:inss[p].bi+1});
for (let p = paired; p < dels.length; p++)
rows.push({type:'removed', leftLine:aLines[dels[p].ai], rightLine:null, leftNo:dels[p].ai+1, rightNo:null});
for (let p = paired; p < inss.length; p++)
rows.push({type:'added', leftLine:null, rightLine:bLines[inss[p].bi], leftNo:null, rightNo:inss[p].bi+1});
}
}
return rows;
}
// ββ Word-level diff for changed line pairs βββββββββββββββββββββ
function wordDiff(aText, bText) {
const tokA = aText.match(/\S+|\s+/g) || [];
const tokB = bText.match(/\S+|\s+/g) || [];
const m = tokA.length, n = tokB.length;
const dp = Array.from({length: m+1}, () => new Int32Array(n+1));
for (let i = m-1; i >= 0; i--)
for (let j = n-1; j >= 0; j--)
dp[i][j] = tokA[i] === tokB[j] ? dp[i+1][j+1]+1 : Math.max(dp[i+1][j], dp[i][j+1]);
let lHtml = '', rHtml = '', i = 0, j = 0;
while (i < m || j < n) {
if (i < m && j < n && tokA[i] === tokB[j]) {
lHtml += escHtml(tokA[i]); rHtml += escHtml(tokB[j]); i++; j++;
} else if (j < n && (i >= m || dp[i][j+1] >= dp[i+1][j])) {
rHtml += `<mark class="wd-add">${escHtml(tokB[j])}</mark>`; j++;
} else {
lHtml += `<mark class="wd-rem">${escHtml(tokA[i])}</mark>`; i++;
}
}
return {lHtml, rHtml};
}
// ββ Render split panels ββββββββββββββββββββββββββββββββββββββββ
function renderPanels(rows) {
let lHtml = '', rHtml = '';
for (const row of rows) {
const isLeft = row.type !== 'added';
const isRight = row.type !== 'removed';
const cls = row.type === 'unchanged' ? '' : `diff-${row.type}`;
let lTxt, rTxt;
if (row.type === 'unchanged') {
const esc = escHtml(row.leftLine);
lTxt = `<span class="text-gray-600">${esc}</span>`;
rTxt = `<span class="text-gray-600">${escHtml(row.rightLine)}</span>`;
} else if (row.type === 'changed') {
const {lHtml: lw, rHtml: rw} = wordDiff(row.leftLine, row.rightLine);
lTxt = lw; rTxt = rw;
} else {
lTxt = isLeft ? escHtml(row.leftLine) : '';
rTxt = isRight ? escHtml(row.rightLine) : '';
}
lHtml += `<div class="diff-row${isLeft && cls ? ' '+cls : ''}${!isLeft ? ' line-empty' : ''}">`
+ `<span class="line-no">${row.leftNo ?? ''}</span>`
+ `<span class="line-txt">${lTxt}</span></div>`;
rHtml += `<div class="diff-row${isRight && cls ? ' '+cls : ''}${!isRight ? ' line-empty' : ''}">`
+ `<span class="line-no">${row.rightNo ?? ''}</span>`
+ `<span class="line-txt">${rTxt}</span></div>`;
}
leftPanel.innerHTML = lHtml || '<div class="p-4 text-gray-600 text-sm">No changes to show.</div>';
rightPanel.innerHTML = rHtml || '<div class="p-4 text-gray-600 text-sm">No changes to show.</div>';
}
// ββ Summary badges βββββββββββββββββββββββββββββββββββββββββββββ
function renderSummary(rows) {
let added = 0, removed = 0, changed = 0;
for (const r of rows) {
if (r.type === 'added') added++;
else if (r.type === 'removed') removed++;
else if (r.type === 'changed') changed++;
}
const badge = (cls, label) =>
`<span class="badge-${cls} text-xs font-semibold px-2.5 py-1 rounded-full">${label}</span>`;
diffSummary.innerHTML = added === 0 && removed === 0 && changed === 0
? '<span class="text-xs text-gray-500">No differences found.</span>'
: [
added ? badge('added', `+${added} added`) : '',
removed ? badge('removed', `-${removed} removed`) : '',
changed ? badge('changed', `~${changed} changed`) : '',
].join('');
}
// ββ Actions ββββββββββββββββββββββββββββββββββββββββββββββββββββ
function loadSample() {
leftEl.value = `The quick brown fox jumps over the lazy dog.
A journey of a thousand miles begins with a single step.
All that glitters is not gold.
To be or not to be, that is the question.
The only thing we have to fear is fear itself.
Fortune favors the bold.
In the middle of difficulty lies opportunity.
It always seems impossible until it is done.
The best time to plant a tree was twenty years ago.
The second best time is now.`;
rightEl.value = `The quick brown fox jumps over the lazy dog.
A journey of a thousand miles begins with a single step.
All that glitters is not gold.
To be or not to be, that is the answer.
The only thing we have to fear is fear itself.
Fortune favors the prepared mind.
In the middle of every difficulty lies opportunity.
It always seems impossible until it is done.
The best time to plant a tree was twenty years ago.
The second best time is today.
Small steps every day lead to big results.`;
}
function runCompare() {
const a = leftEl.value;
const b = rightEl.value;
if (!a && !b) return;
const aLines = a.split('\n');
const bLines = b.split('\n');
const ignoreWS = ignoreWsCb.checked;
lastRows = computeLineDiff(aLines, bLines, ignoreWS);
renderSummary(lastRows);
renderPanels(lastRows);
diffOutput.style.display = '';
copyBtn.style.display = '';
leftPanel.scrollTop = 0;
rightPanel.scrollTop = 0;
}
function runReset() {
leftEl.value = '';
rightEl.value = '';
diffOutput.style.display = 'none';
copyBtn.style.display = 'none';
lastRows = null;
}
async function copyDiff() {
if (!lastRows) return;
const lines = [];
for (const row of lastRows) {
if (row.type === 'unchanged') {
lines.push(' ' + row.leftLine);
} else if (row.type === 'removed') {
lines.push('-' + row.leftLine);
} else if (row.type === 'added') {
lines.push('+' + row.rightLine);
} else {
lines.push('-' + row.leftLine);
lines.push('+' + row.rightLine);
}
}
try {
await navigator.clipboard.writeText(lines.join('\n'));
const orig = copyBtn.textContent;
copyBtn.textContent = 'β
Copied!';
setTimeout(() => { copyBtn.textContent = orig; }, 1500);
} catch {
/* clipboard not available */
}
}
</script>
</body>
</html>