-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool-27-Text-Diff-Checker.html
More file actions
311 lines (259 loc) · 11.7 KB
/
tool-27-Text-Diff-Checker.html
File metadata and controls
311 lines (259 loc) · 11.7 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tool 27 - Text Diff Checker - Developer Toolbox</title>
<link rel="stylesheet" href="assets/core.css">
<style>
.split-view {
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
margin-bottom: 2rem;
}
@media (min-width: 900px) {
.split-view { grid-template-columns: 1fr 1fr; }
}
textarea {
width: 100%;
height: 250px;
background: var(--bg-main);
color: var(--text-primary);
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
padding: 1rem;
font-family: var(--font-mono);
font-size: 14px;
resize: vertical;
}
.diff-output {
background: var(--bg-surface);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
padding: 1.5rem;
font-family: var(--font-mono);
font-size: 14px;
white-space: pre-wrap;
word-wrap: break-word;
min-height: 200px;
line-height: 1.5;
}
.diff-added {
background-color: rgba(46, 160, 67, 0.2);
color: #7ee787;
}
.diff-removed {
background-color: rgba(248, 81, 73, 0.2);
color: #ff7b72;
text-decoration: line-through;
}
.theme-light .diff-added {
background-color: rgba(46, 160, 67, 0.2);
color: #1a7f37;
}
.theme-light .diff-removed {
background-color: rgba(248, 81, 73, 0.2);
color: #cf222e;
}
.toolbar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.btn-group { display: flex; gap: 0.5rem; }
</style>
</head>
<body class="theme-dark">
<div class="tool-canvas-container" 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>27. Text Diff Checker</h1>
</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 class="glass-panel" style="margin-bottom: 2rem;">
<div class="toolbar">
<div class="btn-group">
<button class="btn btn-primary" id="compare-words-btn">Compare Words</button>
<button class="btn" id="compare-chars-btn">Compare Chars</button>
<button class="btn" id="compare-lines-btn">Compare Lines</button>
</div>
<button class="btn" id="clear-btn">Clear All</button>
</div>
<div class="split-view">
<div>
<h3>Original Text</h3>
<textarea id="text-original" placeholder="Paste original text here...">The quick brown fox jumps over the lazy dog.
This is a test document to show how the diff works.</textarea>
</div>
<div>
<h3>Modified Text</h3>
<textarea id="text-modified" placeholder="Paste modified text here...">The fast brown fox leaped over the lazy dog.
This is a test document to show how the diff checker works.</textarea>
</div>
</div>
</div>
<div class="glass-panel">
<h3>Diff Results (<span id="diff-mode-label">Words</span>)</h3>
<div class="diff-output" id="diff-output"></div>
</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>
<script src="assets/core.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsdiff/5.1.0/diff.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const original = document.getElementById('text-original');
const modified = document.getElementById('text-modified');
const diffOut = document.getElementById('diff-output');
const diffModeLabel = document.getElementById('diff-mode-label');
const btnWords = document.getElementById('compare-words-btn');
const btnChars = document.getElementById('compare-chars-btn');
const btnLines = document.getElementById('compare-lines-btn');
const clearBtn = document.getElementById('clear-btn');
let currentMode = 'words';
const setActiveBtn = (activeBtn) => {
[btnWords, btnChars, btnLines].forEach(btn => btn.classList.remove('btn-primary'));
activeBtn.classList.add('btn-primary');
};
const computeDiff = () => {
const text1 = original.value;
const text2 = modified.value;
let diff;
if(currentMode === 'words') {
diff = Diff.diffWords(text1, text2);
} else if(currentMode === 'chars') {
diff = Diff.diffChars(text1, text2);
} else {
diff = Diff.diffLines(text1, text2);
}
diffOut.innerHTML = '';
let diffCount = 0;
diff.forEach((part) => {
const span = document.createElement('span');
if (part.added) {
span.className = 'diff-added';
diffCount++;
} else if (part.removed) {
span.className = 'diff-removed';
diffCount++;
}
span.textContent = part.value;
diffOut.appendChild(span);
});
// Update 3D visualization
if(window.update3DDiff) {
window.update3DDiff(diffCount);
}
};
btnWords.addEventListener('click', () => { currentMode = 'words'; diffModeLabel.textContent = 'Words'; setActiveBtn(btnWords); computeDiff(); });
btnChars.addEventListener('click', () => { currentMode = 'chars'; diffModeLabel.textContent = 'Chars'; setActiveBtn(btnChars); computeDiff(); });
btnLines.addEventListener('click', () => { currentMode = 'lines'; diffModeLabel.textContent = 'Lines'; setActiveBtn(btnLines); computeDiff(); });
original.addEventListener('input', computeDiff);
modified.addEventListener('input', computeDiff);
clearBtn.addEventListener('click', () => {
original.value = '';
modified.value = '';
computeDiff();
});
// Init
computeDiff();
});
// 3D Visualization: Two blocks with protruding bricks
let scene, camera, renderer, leftBlockGroup, rightBlockGroup;
let diffAnimateValue = 0;
function init3D() {
const container = document.getElementById('canvas-container');
if(!container || !window.THREE) return;
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.set(0, 4, 12);
camera.lookAt(0, 0, 0);
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
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(5, 5, 5);
scene.add(dirLight);
leftBlockGroup = new THREE.Group();
rightBlockGroup = new THREE.Group();
leftBlockGroup.position.x = -2.5;
rightBlockGroup.position.x = 2.5;
scene.add(leftBlockGroup);
scene.add(rightBlockGroup);
createBaseBlocks();
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
animate();
}
function createBaseBlocks() {
// Left main block
const baseGeo = new THREE.BoxGeometry(3, 4, 1);
const baseMat = new THREE.MeshPhongMaterial({ color: 0x334455, transparent: true, opacity: 0.8 });
const p1 = new THREE.Mesh(baseGeo, baseMat);
leftBlockGroup.add(p1);
// Right main block
const p2 = new THREE.Mesh(baseGeo, baseMat);
rightBlockGroup.add(p2);
}
window.update3DDiff = (diffCount) => {
if(!scene) return;
// clear old differences
while(leftBlockGroup.children.length > 1) { leftBlockGroup.remove(leftBlockGroup.children[1]); }
while(rightBlockGroup.children.length > 1) { rightBlockGroup.remove(rightBlockGroup.children[1]); }
// Add protruding blocks based on diff
const maxBlocks = Math.min(diffCount, 20); // Cap it so it doesn't lag
const redMat = new THREE.MeshPhongMaterial({ color: 0xff3333 });
const greenMat = new THREE.MeshPhongMaterial({ color: 0x33ff33 });
const diffGeo = new THREE.BoxGeometry(0.8, 0.3, 1.5); // Extends deeper
for(let i=0; i<maxBlocks; i++) {
const yPos = (Math.random() * 3) - 1.5;
const xPos = (Math.random() * 2) - 1;
// Add red to left
const b1 = new THREE.Mesh(diffGeo, redMat);
b1.position.set(xPos, yPos, 0);
leftBlockGroup.add(b1);
// Add green to right
const b2 = new THREE.Mesh(diffGeo, greenMat);
b2.position.set(xPos, yPos, 0);
rightBlockGroup.add(b2);
}
};
function animate() {
requestAnimationFrame(animate);
if(leftBlockGroup && rightBlockGroup) {
leftBlockGroup.rotation.y = Math.sin(Date.now() * 0.001) * 0.2;
rightBlockGroup.rotation.y = -Math.sin(Date.now() * 0.001) * 0.2;
leftBlockGroup.position.y = Math.sin(Date.now() * 0.002) * 0.1;
rightBlockGroup.position.y = Math.sin(Date.now() * 0.002 + Math.PI) * 0.1;
}
renderer.render(scene, camera);
}
document.addEventListener('DOMContentLoaded', init3D);
</script>
</body>
</html>