-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool-10-Diff-Checker.html
More file actions
548 lines (465 loc) · 20.9 KB
/
Copy pathtool-10-Diff-Checker.html
File metadata and controls
548 lines (465 loc) · 20.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tool 10 - Diff Checker - Developer Toolbox</title>
<link rel="stylesheet" href="assets/core.css">
<!-- CodeMirror for diffs -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/merge/merge.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/theme/monokai.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/theme/idea.min.css">
<style>
.diff-grid {
display: grid;
grid-template-columns: 1fr;
gap: 2rem;
margin-top: 2rem;
min-height: 400px;
/* initial height before merge view */
}
@media (min-width: 900px) {
.diff-grid {
grid-template-columns: 1fr 1fr;
}
}
.panel-container {
display: flex;
flex-direction: column;
gap: 1rem;
height: 100%;
}
.panel-header {
display: flex;
justify-content: space-between;
align-items: center;
}
textarea {
flex: 1;
width: 100%;
height: 300px;
resize: vertical;
padding: 1rem;
background: rgba(0, 0, 0, 0.2);
border: 2px solid var(--border-color);
border-radius: var(--radius-md);
color: var(--text-primary);
font-family: var(--font-mono);
font-size: 0.9rem;
outline: none;
transition: all 0.3s;
line-height: 1.5;
white-space: pre;
}
textarea:focus {
border-color: var(--accent-primary);
box-shadow: 0 0 0 2px rgba(187, 134, 252, 0.2);
}
.btn-controls {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
.options-row {
display: flex;
gap: 1.5rem;
align-items: center;
margin-top: 1rem;
padding: 1rem;
background: rgba(0, 0, 0, 0.2);
border-radius: var(--radius-md);
border: 1px solid var(--border-color);
justify-content: center;
}
/* Diff Viewer Container */
#diff-view-container {
margin-top: 2rem;
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
overflow: hidden;
display: none;
/* hidden until compare clicked */
height: 600px;
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(10px);
}
.CodeMirror-merge {
border: none;
height: 100%;
}
.CodeMirror {
height: 100%;
font-family: var(--font-mono);
font-size: 0.9rem;
}
/* Theme overrides for CodeMirror Merge */
.theme-dark .CodeMirror-merge-copy {
color: var(--text-primary);
}
.theme-dark .CodeMirror-merge-l-inserted,
.theme-dark .CodeMirror-merge-r-inserted {
background-image: none;
background-color: rgba(51, 217, 178, 0.2);
}
.theme-dark .CodeMirror-merge-l-deleted,
.theme-dark .CodeMirror-merge-r-deleted {
background-image: none;
background-color: rgba(255, 82, 82, 0.2);
}
.theme-dark .CodeMirror-merge-l-chunk,
.theme-dark .CodeMirror-merge-r-chunk {
background: rgba(0, 0, 0, 0.3);
border-top: 1px solid rgba(255, 255, 255, 0.1);
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.theme-dark .CodeMirror-merge-pane-rightmost {
border-left: 1px solid var(--border-color);
}
/* 3D background container */
#canvas-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
opacity: 0.3;
pointer-events: none;
}
.stats-badge {
display: inline-block;
padding: 0.4rem 0.8rem;
border-radius: var(--radius-sm);
font-weight: bold;
font-family: var(--font-mono);
font-size: 0.9rem;
margin: 0 0.5rem;
}
.stats-add {
background: rgba(51, 217, 178, 0.2);
color: #33d9b2;
border: 1px solid #33d9b2;
}
.stats-del {
background: rgba(255, 82, 82, 0.2);
color: #ff5252;
border: 1px solid #ff5252;
}
#diff-stats {
display: none;
text-align: center;
margin-top: 1rem;
}
</style>
</head>
<body class="theme-dark">
<div id="canvas-container"></div>
<main class="main-content">
<div class="container">
<div class="tool-header">
<div>
<a href="index.html" class="back-link">← Back to Toolbox</a>
<h1>10. Diff Checker</h1>
<p style="color: var(--text-secondary); margin-top: 0.5rem;">Compare text, code, or configuration
files to see what changed.</p>
</div>
<div>
<select id="theme-select" aria-label="Select Theme">
<option value="dark">Dark Theme</option>
<option value="light">Light Theme</option>
<option value="solarized">Solarized</option>
<option value="neon">Neon Glow</option>
<option value="highcontrast">High Contrast</option>
</select>
</div>
</div>
<div id="input-section">
<div class="diff-grid">
<!-- Original Panel -->
<div class="glass-panel panel-container">
<div class="panel-header">
<h3>Original Text</h3>
<div class="btn-controls">
<button id="btn-clear-orig" class="btn">Clear</button>
<button id="btn-paste-orig" class="btn">Paste</button>
</div>
</div>
<textarea id="orig-input" placeholder="Paste the original text here..."></textarea>
</div>
<!-- Modified Panel -->
<div class="glass-panel panel-container">
<div class="panel-header">
<h3>Modified Text</h3>
<div class="btn-controls">
<button id="btn-clear-mod" class="btn">Clear</button>
<button id="btn-paste-mod" class="btn">Paste</button>
</div>
</div>
<textarea id="mod-input" placeholder="Paste the modified text here..."></textarea>
</div>
</div>
<div class="options-row">
<button id="btn-compare" class="btn btn-primary"
style="font-size: 1.1rem; padding: 0.8rem 2rem;">Compare Files</button>
</div>
</div>
<div id="diff-stats">
<span class="stats-badge stats-add"><span id="stat-add">0</span> Additions</span>
<span class="stats-badge stats-del"><span id="stat-del">0</span> Deletions</span>
<button id="btn-edit" class="btn" style="margin-left: 1rem;">Back to Edit</button>
</div>
<!-- CM Merge View mounts here -->
<div id="diff-view-container" class="glass-panel" style="padding:0;"></div>
</div>
</main>
<footer class="global-footer">
<div class="container">
Made with ❤️ by <a href="https://github.com/Aliriyaj007" target="_blank">Aliriyaj007</a>
</div>
</footer>
<!-- Three.js and GSAP for 3D Background -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<!-- CodeMirror dependencies for Diff -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/google-diff-match-patch/1.0.0/diff_match_patch.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/merge/merge.min.js"></script>
<script src="assets/core.js"></script>
<script>
// --- Core Diff Logic ---
const origInput = document.getElementById('orig-input');
const modInput = document.getElementById('mod-input');
const btnCompare = document.getElementById('btn-compare');
const btnEdit = document.getElementById('btn-edit');
const inputSection = document.getElementById('input-section');
const diffStats = document.getElementById('diff-stats');
const diffViewContainer = document.getElementById('diff-view-container');
const statAdd = document.getElementById('stat-add');
const statDel = document.getElementById('stat-del');
let mergeViewInstance = null;
// Sync CM theme with App Theme
const getCmTheme = () => {
const isDark = document.body.classList.contains('theme-light') ? false : true;
return isDark ? 'monokai' : 'idea';
};
// Theme sync listener via MutationObserver on body
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.attributeName === 'class' && mergeViewInstance) {
const theme = getCmTheme();
mergeViewInstance.editor().setOption("theme", theme);
mergeViewInstance.rightOriginal().setOption("theme", theme);
}
});
});
observer.observe(document.body, { attributes: true });
function calculateSimpleStats(text1, text2) {
const dmp = new diff_match_patch();
const diffs = dmp.diff_main(text1, text2);
dmp.diff_cleanupSemantic(diffs);
let added = 0;
let deleted = 0;
// Count lines approx
diffs.forEach(part => {
const lines = (part[1].match(/\n/g) || []).length + (part[1].length > 0 ? 1 : 0);
if (part[0] === 1) added += lines;
else if (part[0] === -1) deleted += lines;
});
return { added, deleted };
}
btnCompare.addEventListener('click', () => {
const orig = origInput.value;
const mod = modInput.value;
if (!orig && !mod) return;
// Hide inputs, show diff
inputSection.style.display = 'none';
diffViewContainer.style.display = 'block';
diffStats.style.display = 'block';
diffViewContainer.innerHTML = ''; // clear previous
mergeViewInstance = CodeMirror.MergeView(diffViewContainer, {
value: mod,
origRight: orig,
lineNumbers: true,
mode: "text/plain",
highlightDifferences: true,
connect: "align",
collapseIdentical: false,
theme: getCmTheme(),
revertButtons: false,
readOnly: true
});
// Stats
const stats = calculateSimpleStats(orig, mod);
statAdd.textContent = stats.added;
statDel.textContent = stats.deleted;
// Trigger 3D animation
if (window.triggerDiffAnim) window.triggerDiffAnim(stats.added, stats.deleted);
});
btnEdit.addEventListener('click', () => {
inputSection.style.display = 'block';
diffViewContainer.style.display = 'none';
diffStats.style.display = 'none';
if (mergeViewInstance) {
diffViewContainer.innerHTML = '';
mergeViewInstance = null;
}
if (window.triggerDiffAnim) window.triggerDiffAnim(0, 0, true); // reset
});
// Setup Buttons
const setupBtn = (id, targetInput) => {
const btn = document.getElementById(id);
if (!btn) return;
btn.addEventListener('click', async () => {
if (id.includes('clear')) {
targetInput.value = '';
} else if (id.includes('paste')) {
try {
const text = await navigator.clipboard.readText();
targetInput.value = text;
} catch (err) {
console.error('Failed to read clipboard', err);
}
}
});
};
setupBtn('btn-clear-orig', origInput);
setupBtn('btn-paste-orig', origInput);
setupBtn('btn-clear-mod', modInput);
setupBtn('btn-paste-mod', modInput);
// --- 3D Background Setup (Glowing Brick Walls) ---
let scene, camera, renderer, leftWall, rightWall;
let leftBricks = [];
let rightBricks = [];
const rows = 10;
const cols = 8;
// Colors corresponding to insertions/deletions
const colorAdd = new THREE.Color(0x33d9b2);
const colorDel = new THREE.Color(0xff5252);
const colorBase = new THREE.Color(0x333333);
const init3D = () => {
const container = document.getElementById('canvas-container');
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.z = 25;
camera.position.y = 5;
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
container.appendChild(renderer.domElement);
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
scene.add(ambientLight);
const dirLight = new THREE.DirectionalLight(0xffffff, 0.8);
dirLight.position.set(0, 10, 10);
scene.add(dirLight);
leftWall = new THREE.Group();
rightWall = new THREE.Group();
const brickGeo = new THREE.BoxGeometry(1.8, 0.8, 0.4);
// Build Left Wall (Original)
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
const mat = new THREE.MeshStandardMaterial({ color: 0x333333, roughness: 0.7 });
const brick = new THREE.Mesh(brickGeo, mat);
// Add slight random offset to simulate bricks
const xOff = (r % 2 === 0) ? 0 : 0.9;
brick.position.set((c * 2) - xOff, r, 0);
// store original position
brick.userData = { origPos: brick.position.clone(), isGlowing: false };
leftWall.add(brick);
leftBricks.push(brick);
}
}
// Build Right Wall (Modified)
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
const mat = new THREE.MeshStandardMaterial({ color: 0x333333, roughness: 0.7 });
const brick = new THREE.Mesh(brickGeo, mat);
const xOff = (r % 2 === 0) ? 0 : 0.9;
brick.position.set((c * 2) - xOff, r, 0);
brick.userData = { origPos: brick.position.clone(), isGlowing: false };
rightWall.add(brick);
rightBricks.push(brick);
}
}
// Position walls side by side, tilted like pages of a book
leftWall.position.set(-8, -4, 0);
leftWall.rotation.y = 0.3;
rightWall.position.set(2, -4, 0);
rightWall.rotation.y = -0.3;
scene.add(leftWall);
scene.add(rightWall);
// Animation logic based on diff stats
window.triggerDiffAnim = (adds, dels, reset = false) => {
// Reset all blocks
[...leftBricks, ...rightBricks].forEach(b => {
gsap.to(b.material.color, { r: colorBase.r, g: colorBase.g, b: colorBase.b, duration: 0.5 });
gsap.to(b.position, { z: b.userData.origPos.z, duration: 0.5 });
b.material.emissive.setHex(0x000000);
b.userData.isGlowing = false;
});
if (reset) return;
// Animate Left Wall (Deletions)
// Randomly select 'dels' number of blocks to turn red and push backward
const numDelBlocks = Math.min(dels, leftBricks.length);
const shuffledL = leftBricks.sort(() => 0.5 - Math.random());
for (let i = 0; i < numDelBlocks; i++) {
const b = shuffledL[i];
b.userData.isGlowing = true;
gsap.to(b.material.color, { r: colorDel.r, g: colorDel.g, b: colorDel.b, duration: 1, delay: i * 0.05 });
gsap.to(b.position, { z: -1, duration: 1, ease: "back.out(1.7)", delay: i * 0.05 });
// Emissive
setTimeout(() => { b.material.emissive.copy(colorDel).multiplyScalar(0.4); }, 1000 + (i * 50));
}
// Animate Right Wall (Additions)
// Randomly select 'adds' number of blocks to turn green and pull forward
const numAddBlocks = Math.min(adds, rightBricks.length);
const shuffledR = rightBricks.sort(() => 0.5 - Math.random());
for (let i = 0; i < numAddBlocks; i++) {
const b = shuffledR[i];
b.userData.isGlowing = true;
gsap.to(b.material.color, { r: colorAdd.r, g: colorAdd.g, b: colorAdd.b, duration: 1, delay: i * 0.05 });
gsap.to(b.position, { z: 1, duration: 1, ease: "back.out(1.7)", delay: i * 0.05 });
// Emissive
setTimeout(() => { b.material.emissive.copy(colorAdd).multiplyScalar(0.4); }, 1000 + (i * 50));
}
};
const animate = () => {
requestAnimationFrame(animate);
// Idle camera sway
camera.position.x = Math.sin(Date.now() * 0.0005) * 2;
camera.lookAt(0, 0, 0);
// Pulsate glowing bricks
const time = Date.now() * 0.005;
rightBricks.forEach(b => {
if (b.userData.isGlowing) {
b.material.emissiveIntensity = 0.4 + Math.sin(time + b.position.x) * 0.2;
}
});
leftBricks.forEach(b => {
if (b.userData.isGlowing) {
b.material.emissiveIntensity = 0.4 + Math.sin(time + b.position.x) * 0.2;
}
});
renderer.render(scene, camera);
};
animate();
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
if (window.innerWidth < 900) {
leftWall.position.set(-4, -8, -5);
rightWall.position.set(-4, 2, -5);
} else {
leftWall.position.set(-8, -4, 0);
rightWall.position.set(2, -4, 0);
}
});
window.dispatchEvent(new Event('resize'));
};
if (document.getElementById('canvas-container')) {
init3D();
}
</script>
</body>
</html>