-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool-9-JavaScript-Minifier-Beautifier.html
More file actions
515 lines (447 loc) · 19.5 KB
/
tool-9-JavaScript-Minifier-Beautifier.html
File metadata and controls
515 lines (447 loc) · 19.5 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tool 9 - JavaScript Minifier Beautifier - Developer Toolbox</title>
<link rel="stylesheet" href="assets/core.css">
<style>
.js-grid {
display: grid;
grid-template-columns: 1fr;
gap: 2rem;
margin-top: 2rem;
min-height: 600px;
}
@media (min-width: 900px) {
.js-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: 400px;
resize: none;
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-wrap;
}
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-bottom: 0.5rem;
flex-wrap: wrap;
padding: 1rem;
background: rgba(0, 0, 0, 0.2);
border-radius: var(--radius-md);
border: 1px solid var(--border-color);
}
select {
padding: 0.5rem;
background: var(--bg-main);
border: 1px solid var(--border-color);
color: var(--text-primary);
border-radius: var(--radius-sm);
outline: none;
font-family: var(--font-mono);
}
.stats-panel {
background: rgba(0, 0, 0, 0.2);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
padding: 1rem;
display: flex;
justify-content: space-around;
align-items: center;
margin-top: auto;
}
.stat-item {
text-align: center;
}
.stat-label {
font-size: 0.8rem;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 0.3rem;
}
.stat-value {
font-family: var(--font-mono);
font-size: 1.2rem;
color: var(--accent-primary);
font-weight: bold;
}
.savings-good {
color: #33d9b2;
}
.savings-none {
color: var(--text-secondary);
}
/* 3D background container */
#canvas-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
opacity: 0.4;
pointer-events: none;
}
</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>9. JavaScript Minifier Beautifier</h1>
<p style="color: var(--text-secondary); margin-top: 0.5rem;">Compress JS for production or beautify
messy code to make it readable.</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 class="options-row glass-panel">
<span style="color: var(--text-secondary);">Beautifier Options:</span>
<div>
<label for="indent-size" style="margin-right:0.5rem; font-size:0.9rem;">Indent:</label>
<select id="indent-size">
<option value="2">2 Spaces</option>
<option value="4" selected>4 Spaces</option>
<option value="8">8 Spaces</option>
<option value="tab">Tabs</option>
</select>
</div>
</div>
<div class="js-grid">
<!-- Input Panel -->
<div class="glass-panel panel-container">
<div class="panel-header">
<h3>Input JavaScript</h3>
<div class="btn-controls">
<button id="btn-clear" class="btn">Clear</button>
<button id="btn-paste" class="btn">Paste</button>
<button id="btn-format" class="btn btn-primary"
style="background:#03DAC6; color:#000;">Beautify</button>
</div>
</div>
<textarea id="js-input" placeholder="Paste your raw or minified JavaScript here...
function hello(){console.log('world');}
"></textarea>
</div>
<!-- Output Panel -->
<div class="glass-panel panel-container">
<div class="panel-header">
<h3>Output JavaScript</h3>
<div class="btn-controls">
<button id="btn-minify" class="btn btn-primary">Minify</button>
<button id="btn-copy" class="btn">Copy</button>
</div>
</div>
<textarea id="js-output" readonly placeholder="Processed JS will appear here..."></textarea>
<div class="stats-panel">
<div class="stat-item">
<div class="stat-label">Original Size</div>
<div class="stat-value" id="stat-orig">0 B</div>
</div>
<div class="stat-item">
<div class="stat-label">New Size</div>
<div class="stat-value" id="stat-new">0 B</div>
</div>
<div class="stat-item">
<div class="stat-label">Savings</div>
<div class="stat-value savings-none" id="stat-savings">0%</div>
</div>
</div>
</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>
<!-- 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>
<!-- JS Beautify via CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify.min.js"></script>
<!-- Terser (Minifier) via CDN -->
<script src="https://cdn.jsdelivr.net/npm/terser@5.19.2/dist/bundle.min.js"></script>
<script src="assets/core.js"></script>
<script>
// --- Core Formatting / Minifying Logic ---
const inputArea = document.getElementById('js-input');
const outputArea = document.getElementById('js-output');
const origSize = document.getElementById('stat-orig');
const newSize = document.getElementById('stat-new');
const savingsEl = document.getElementById('stat-savings');
const indentSelect = document.getElementById('indent-size');
function formatBytes(bytes) {
if (bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function updateStats(oldText, newText) {
const oldLen = new Blob([oldText]).size;
const newLen = new Blob([newText]).size;
origSize.textContent = formatBytes(oldLen);
newSize.textContent = formatBytes(newLen);
if (oldLen > 0 && newLen < oldLen) {
const savings = ((oldLen - newLen) / oldLen * 100).toFixed(1);
savingsEl.textContent = `${savings}% (${formatBytes(oldLen - newLen)})`;
savingsEl.className = 'stat-value savings-good';
} else if (oldLen > 0 && newLen > oldLen) {
const increase = ((newLen - oldLen) / oldLen * 100).toFixed(1);
savingsEl.textContent = `+${increase}%`;
savingsEl.className = 'stat-value score-inline'; // red if bigger
} else {
savingsEl.textContent = '0%';
savingsEl.className = 'stat-value savings-none';
}
}
document.getElementById('btn-format').addEventListener('click', () => {
const val = inputArea.value;
if (!val) return;
let indentChar = " ";
let indentSize = parseInt(indentSelect.value) || 4;
if (indentSelect.value === 'tab') {
indentChar = "\t";
indentSize = 1;
}
try {
const formatted = js_beautify(val, {
indent_size: indentSize,
indent_char: indentChar,
space_in_empty_paren: true
});
outputArea.value = formatted;
updateStats(val, formatted);
if (window.triggerLineAnim) window.triggerLineAnim('straighten');
} catch (e) {
outputArea.value = "Error formatting JS.";
}
});
document.getElementById('btn-minify').addEventListener('click', async () => {
const val = inputArea.value;
if (!val) return;
outputArea.value = "Minifying...";
try {
// await terser minification
const result = await Terser.minify(val);
if (result.error) throw result.error;
outputArea.value = result.code;
updateStats(val, result.code);
if (window.triggerLineAnim) window.triggerLineAnim('tangle');
} catch (e) {
outputArea.value = "Error minifying JS: " + e.message;
}
});
// Setup common Buttons
const setupBtn = (id, action, targetInput) => {
const btn = document.getElementById(id);
if (!btn) return;
btn.addEventListener('click', async () => {
const originalText = btn.textContent;
if (action === 'clear') {
inputArea.value = '';
outputArea.value = '';
origSize.textContent = '0 B';
newSize.textContent = '0 B';
savingsEl.textContent = '0%';
savingsEl.className = 'stat-value savings-none';
if (window.triggerLineAnim) window.triggerLineAnim('reset');
} else if (action === 'paste') {
try {
const text = await navigator.clipboard.readText();
targetInput.value = text;
} catch (err) {
console.error('Failed to read clipboard', err);
}
} else if (action === 'copy') {
if (!targetInput.value) return;
navigator.clipboard.writeText(targetInput.value);
btn.textContent = 'Copied!';
setTimeout(() => btn.textContent = originalText, 1500);
}
});
};
setupBtn('btn-clear', 'clear', inputArea);
setupBtn('btn-paste', 'paste', inputArea);
setupBtn('btn-copy', 'copy', outputArea);
// --- 3D Background Setup (Tangled vs Straight Splines) ---
let scene, camera, renderer, linesGroup;
let linePaths = []; // store original straight paths
let lineTubes = []; // store meshes
// Custom curve class for animation
class AnimatedCurve extends THREE.Curve {
constructor(points) {
super();
this.points = points;
this.tangleness = 0; // 0 = straight, 1 = tangled
this.randomOffsets = points.map(() => new THREE.Vector3(
(Math.random() - 0.5) * 5,
(Math.random() - 0.5) * 5,
(Math.random() - 0.5) * 5
));
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const pt = optionalTarget;
const segments = this.points.length - 1;
const i = Math.floor(t * segments);
const i2 = Math.min(i + 1, segments);
const weight = (t * segments) - i;
// Straight pos
const p0 = this.points[i];
const p1 = this.points[i2];
const straightPos = new THREE.Vector3().copy(p0).lerp(p1, weight);
// Tangled pos (add noise based on tangleness)
const t0 = this.randomOffsets[i];
const t1 = this.randomOffsets[i2];
const noise = new THREE.Vector3().copy(t0).lerp(t1, weight);
noise.multiplyScalar(this.tangleness * Math.sin(t * Math.PI)); // pinch ends
pt.copy(straightPos).add(noise);
return pt;
}
}
const buildTube = (curve, color) => {
const geometry = new THREE.TubeGeometry(curve, 64, 0.05, 8, false);
const material = new THREE.MeshStandardMaterial({
color: color,
metalness: 0.5,
roughness: 0.2,
wireframe: false
});
const tube = new THREE.Mesh(geometry, material);
return { mesh: tube, curve: curve, mat: material };
};
window.triggerLineAnim = (action) => {
if (!lineTubes.length) return;
let targetTangleness = 0;
if (action === 'tangle') targetTangleness = 1;
else if (action === 'straighten') targetTangleness = 0;
else targetTangleness = 0.3; // reset intermediate state
lineTubes.forEach((lt, i) => {
gsap.to(lt.curve, {
tangleness: targetTangleness,
duration: 1.5 + (Math.random() * 0.5),
ease: "power2.inOut",
onUpdate: () => {
// Rebuild geometry to update shape
const newGeo = new THREE.TubeGeometry(lt.curve, 64, 0.05, 8, false);
lt.mesh.geometry.dispose();
lt.mesh.geometry = newGeo;
}
});
});
};
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 = 15;
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.4);
scene.add(ambientLight);
const pointLight = new THREE.PointLight(0xBB86FC, 1, 50);
pointLight.position.set(5, 5, 5);
scene.add(pointLight);
const pointLight2 = new THREE.PointLight(0x03DAC6, 1, 50);
pointLight2.position.set(-5, -5, 5);
scene.add(pointLight2);
linesGroup = new THREE.Group();
// Create 10 horizontal lines
const colors = [0xBB86FC, 0x03DAC6, 0xffb142, 0x33d9b2, 0xff5252];
for (let i = 0; i < 10; i++) {
const yPos = (i - 4.5) * 0.8;
const points = [];
for (let j = 0; j <= 10; j++) {
const xPos = -8 + (j * 1.6);
points.push(new THREE.Vector3(xPos, yPos, 0));
}
const curve = new AnimatedCurve(points);
curve.tangleness = 0.3; // Start slightly tangled
const tubeObj = buildTube(curve, colors[i % colors.length]);
lineTubes.push(tubeObj);
linesGroup.add(tubeObj.mesh);
}
// Tilt the group
linesGroup.rotation.x = 0.2;
linesGroup.rotation.y = 0.2;
scene.add(linesGroup);
const animate = () => {
requestAnimationFrame(animate);
linesGroup.rotation.y = Math.sin(Date.now() * 0.0005) * 0.1 + 0.2;
linesGroup.rotation.x = Math.cos(Date.now() * 0.0005) * 0.1 + 0.2;
// Slowly cycle offset for flowing effect
if (lineTubes[0].curve.tangleness > 0.1) {
lineTubes.forEach(lt => {
lt.curve.randomOffsets.forEach(v => {
v.x += Math.sin(Date.now() * 0.001) * 0.01;
});
const newGeo = new THREE.TubeGeometry(lt.curve, 64, 0.05, 8, false);
lt.mesh.geometry.dispose();
lt.mesh.geometry = newGeo;
});
}
renderer.render(scene, camera);
};
animate();
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
};
if (document.getElementById('canvas-container')) {
init3D();
}
</script>
</body>
</html>