-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool-75-Bundle-Size-Analyzer-Offline-Cache.html
More file actions
413 lines (338 loc) · 17.6 KB
/
tool-75-Bundle-Size-Analyzer-Offline-Cache.html
File metadata and controls
413 lines (338 loc) · 17.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tool 75 - Bundle Size Analyzer Offline Cache - Developer Toolbox</title>
<link rel="stylesheet" href="assets/core.css">
<style>
.split-view {
display: grid;
grid-template-columns: 1fr;
gap: 1.5rem;
margin-bottom: 2rem;
margin-top: 1rem;
}
@media (min-width: 900px) {
.split-view { grid-template-columns: 350px 1fr; }
}
.controls-panel {
background: rgba(0,0,0,0.4);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
padding: 1.5rem;
display: flex;
flex-direction: column;
gap: 1rem;
max-height: 800px;
}
.search-box {
background: var(--bg-main);
color: var(--text-main);
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
padding: 1rem;
font-size: 1.1rem;
outline: none;
width: 100%;
}
.search-box:focus { border-color: var(--primary-color); }
.search-results {
list-style: none; padding: 0; margin: 0; overflow-y: auto; max-height: 250px;
border: 1px solid var(--border-color); border-radius: 4px; background: rgba(0,0,0,0.2);
}
.search-item {
padding: 0.8rem; border-bottom: 1px solid rgba(255,255,255,0.05); cursor: pointer; display: flex; justify-content: space-between; align-items: center;
}
.search-item:hover { background: rgba(86,182,194,0.1); }
.search-item strong { color: #56b6c2; }
.search-item span { font-size: 0.8rem; color: var(--text-secondary); }
.result-panel {
background: rgba(86,182,194,0.05);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
padding: 1.5rem;
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.headline { font-size: 2rem; margin: 0; color: #fff; display: flex; align-items: baseline; gap: 1rem;}
.headline .ver { font-size: 1rem; color: var(--text-secondary); font-weight: normal; }
.size-grid {
display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
}
.size-card { background: rgba(0,0,0,0.4); border: 1px solid var(--border-color); padding: 1.5rem; border-radius: 8px; text-align: center; }
.size-val { font-size: 2.5rem; font-weight: bold; color: var(--primary-color); }
.size-lbl { font-size: 0.85rem; color: var(--text-secondary); text-transform: uppercase; margin-top: 0.5rem;}
.ts-badge {
display: inline-block; padding: 4px 10px; border-radius: 4px; font-size: 0.8rem; font-weight: bold; margin-top: 1rem;
}
.ts-badge.yes { background: rgba(126,231,135,0.2); color: #7ee787; border: 1px solid #7ee787; }
.ts-badge.no { background: rgba(255,85,85,0.2); color: #ff5555; border: 1px solid #ff5555; }
.alt-table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; font-size: 0.9rem;}
.alt-table th { text-align: left; padding: 8px; border-bottom: 2px solid #444; color: var(--text-secondary); }
.alt-table td { padding: 8px; border-bottom: 1px solid #222; }
.alt-table tr.current { background: rgba(86,182,194,0.1); border-left: 3px solid var(--primary-color); }
/* 3D Canvas wrapper */
.graph-container {
background: #000;
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
height: 300px;
position: relative;
overflow: hidden;
box-shadow: inset 0 0 50px rgba(0,0,0,0.8);
margin-top: 1rem;
}
#chart-overlay {
position: absolute; bottom: 10px; width: 100%; text-align: center; color: var(--text-secondary); font-size: 0.8rem; pointer-events: none;
}
</style>
</head>
<body class="theme-dark">
<main class="main-content" style="padding-top:2rem;">
<div class="container" style="max-width: 1400px;">
<div class="tool-header">
<div>
<a href="index.html" class="back-link">← Back to Toolbox</a>
<h1>75. Bundle Size Analyzer Offline Cache</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">
<div class="split-view">
<!-- Left: Search -->
<div class="controls-panel">
<h3 style="margin:0; color:var(--primary-color);">Search Cache</h3>
<p style="font-size:0.8rem; color:var(--text-secondary); margin-top:0;">Look up metadata for popular packages entirely offline.</p>
<input type="text" id="search-box" class="search-box" placeholder="e.g. react, lodash, moment...">
<ul class="search-results" id="search-results">
<!-- Populated by JS -->
</ul>
<div style="font-size:0.75rem; color:#888; text-align:center; margin-top:auto;">
*Using static snapshot DB.<br>Minified + Gzipped sizes shown.
</div>
</div>
<!-- Right: Analysis -->
<div class="result-panel">
<div id="empty-state" style="text-align:center; padding: 4rem 0; color:var(--text-secondary);">
<div style="font-size:3rem; margin-bottom:1rem; opacity:0.5;">📦</div>
Select a package from the left to analyze its footprint.
</div>
<div id="data-state" style="display:none; flex-direction:column; gap:1.5rem;">
<div style="display:flex; justify-content:space-between; align-items:flex-start;">
<div>
<h2 class="headline" id="pkg-name">lodash <span class="ver" id="pkg-ver">v4.17.21</span></h2>
<div class="ts-badge yes" id="pkg-ts">✓ Tree-shakable</div>
</div>
</div>
<div class="size-grid">
<div class="size-card">
<div class="size-val" id="sz-min">71.5 <span style="font-size:1rem;">KB</span></div>
<div class="size-lbl">Minified</div>
</div>
<div class="size-card">
<div class="size-val" style="color:#7ee787;" id="sz-gz">24.4 <span style="font-size:1rem;">KB</span></div>
<div class="size-lbl">Minified + Gzipped</div>
</div>
</div>
<div class="alt-section">
<h4 style="margin:0 0 0.5rem 0; color:var(--text-main);">Alternative Comparison</h4>
<table class="alt-table">
<thead>
<tr>
<th>Library</th>
<th>Gzipped Size</th>
<th>Tree-Shakable</th>
</tr>
</thead>
<tbody id="alt-tbody">
<!-- JS -->
</tbody>
</table>
</div>
</div>
<!-- 3D Visualization -->
<div class="graph-container" id="graph-container">
<div id="chart-overlay">3D Size Comparison (Drag to rotate)</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>
<script src="assets/core.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.134.0/examples/js/controls/OrbitControls.js"></script>
<script>
// Static Cache DB
const db = [
{ id: 'react', name: 'react', ver: '18.2.0', min: 6.4, gz: 2.5, ts: false, category: 'framework' },
{ id: 'react-dom', name: 'react-dom', ver: '18.2.0', min: 130.2, gz: 42.0, ts: false, category: 'framework' },
{ id: 'vue', name: 'vue', ver: '3.3.4', min: 104.9, gz: 39.5, ts: true, category: 'framework' },
{ id: 'lit', name: 'lit', ver: '2.8.0', min: 16.2, gz: 5.6, ts: true, category: 'framework' },
{ id: 'moment', name: 'moment', ver: '2.29.4', min: 289.4, gz: 72.3, ts: false, category: 'date' },
{ id: 'dayjs', name: 'dayjs', ver: '1.11.9', min: 6.9, gz: 2.9, ts: false, category: 'date' },
{ id: 'date-fns', name: 'date-fns', ver: '2.30.0', min: 91.0, gz: 22.1, ts: true, category: 'date' },
{ id: 'lodash', name: 'lodash', ver: '4.17.21', min: 71.5, gz: 24.4, ts: false, category: 'util' },
{ id: 'lodash-es', name: 'lodash-es', ver: '4.17.21', min: 96.4, gz: 28.1, ts: true, category: 'util' },
{ id: 'radash', name: 'radash', ver: '11.0.0', min: 15.2, gz: 4.8, ts: true, category: 'util' },
{ id: 'axios', name: 'axios', ver: '1.4.0', min: 32.5, gz: 11.8, ts: true, category: 'fetch' },
{ id: 'ky', name: 'ky', ver: '0.33.3', min: 10.1, gz: 3.5, ts: true, category: 'fetch' },
{ id: 'chart.js', name: 'chart.js', ver: '4.3.3', min: 219.1, gz: 68.3, ts: true, category: 'chart' },
{ id: 'd3', name: 'd3', ver: '7.8.5', min: 284.1, gz: 86.8, ts: true, category: 'chart' }
];
const searchBox = document.getElementById('search-box');
const searchResults = document.getElementById('search-results');
const emptyState = document.getElementById('empty-state');
const dataState = document.getElementById('data-state');
const pkgName = document.getElementById('pkg-name');
const pkgVer = document.getElementById('pkg-ver');
const pkgTs = document.getElementById('pkg-ts');
const szMin = document.getElementById('sz-min');
const szGz = document.getElementById('sz-gz');
const altTbody = document.getElementById('alt-tbody');
let activePkg = null;
function renderList(query) {
searchResults.innerHTML = '';
const q = query.toLowerCase();
let filtered = db;
if(q) {
filtered = db.filter(p => p.name.includes(q) || p.category.includes(q));
}
filtered.forEach(p => {
const li = document.createElement('li');
li.className = 'search-item';
li.innerHTML = `<strong>${p.name}</strong> <span>${p.gz} KB (gz)</span>`;
li.addEventListener('click', () => loadPackage(p));
searchResults.appendChild(li);
});
}
function loadPackage(pkg) {
activePkg = pkg;
emptyState.style.display = 'none';
dataState.style.display = 'flex';
pkgName.innerHTML = `${pkg.name} <span class="ver" id="pkg-ver">v${pkg.ver}</span>`;
if(pkg.ts) {
pkgTs.className = 'ts-badge yes'; pkgTs.textContent = '✓ Tree-shakable';
} else {
pkgTs.className = 'ts-badge no'; pkgTs.textContent = '✗ Not Tree-shakable';
}
szMin.innerHTML = `${pkg.min} <span style="font-size:1rem;">KB</span>`;
szGz.innerHTML = `${pkg.gz} <span style="font-size:1rem;">KB</span>`;
// Alternatives
const alts = db.filter(p => p.category === pkg.category).sort((a,b) => a.gz - b.gz);
altTbody.innerHTML = '';
alts.forEach(a => {
const tr = document.createElement('tr');
if(a.id === pkg.id) tr.className = 'current';
tr.innerHTML = `
<td>${a.name} ${a.id === pkg.id ? '(Active)' : ''}</td>
<td style="color:${a.gz < pkg.gz ? '#7ee787' : 'inherit'}">${a.gz} KB</td>
<td>${a.ts ? '✓' : '✗'}</td>
`;
altTbody.appendChild(tr);
});
trigger3DAnimation(alts, pkg.id);
}
searchBox.addEventListener('input', (e) => renderList(e.target.value));
renderList('');
// 3D Visualization (Bar Graphs)
let scene, camera, renderer, controls, graphGroup;
let bars = [];
let labels = [];
function init3D() {
const container = document.getElementById('graph-container');
const cw = container.clientWidth;
const ch = container.clientHeight;
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(50, cw / ch, 1, 100);
camera.position.set(0, 5, 12);
camera.lookAt(0, 0, 0);
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setSize(cw, ch);
container.appendChild(renderer.domElement);
if(window.THREE.OrbitControls) {
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
controls.maxPolarAngle = Math.PI / 2 + 0.1; // allow slightly below ground
}
const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(5, 10, 5);
scene.add(light);
scene.add(new THREE.AmbientLight(0x404040, 1.5));
// Grid / Base
const gridHelper = new THREE.GridHelper(20, 20, 0x444444, 0x222222);
scene.add(gridHelper);
graphGroup = new THREE.Group();
scene.add(graphGroup);
window.addEventListener('resize', () => {
if(!container) return;
const rw = container.clientWidth;
const rh = container.clientHeight;
camera.aspect = rw / rh;
camera.updateProjectionMatrix();
renderer.setSize(rw, rh);
});
animate3D();
}
function trigger3DAnimation(alts, activeId) {
// clear old
bars.forEach(b => graphGroup.remove(b));
bars = [];
const spacing = 2;
const startX = -((alts.length - 1) * spacing) / 2;
// Find max for scaling
const maxGz = Math.max(...alts.map(a => a.gz));
const maxHeight = 8; // 3d units
alts.forEach((a, i) => {
const targetH = Math.max((a.gz / maxGz) * maxHeight, 0.2); // avoid flat
// Active block is Cyan, others are gray, smallest is green (if not active)
let color = 0x555555;
if(a.id === activeId) color = 0x56b6c2;
else if(a.gz === alts[0].gz) color = 0x7ee787; // the winner
const bGeo = new THREE.BoxGeometry(1.2, 1, 1.2); // start height 1, scale Y later
// shift origin to bottom for correct scaling
bGeo.translate(0, 0.5, 0);
const bMat = new THREE.MeshPhongMaterial({ color: color, shininess: 80 });
const bar = new THREE.Mesh(bGeo, bMat);
bar.position.set(startX + (i * spacing), 0, 0);
bar.scale.y = 0.01; // start tiny
bar.userData = { targetY: targetH };
graphGroup.add(bar);
bars.push(bar);
});
}
function animate3D() {
requestAnimationFrame(animate3D);
if(controls) controls.update();
// Grow bars
bars.forEach(b => {
if(b.scale.y < b.userData.targetY) {
b.scale.y += (b.userData.targetY - b.scale.y) * 0.1;
}
});
// slow rotate if nobody touching
if(graphGroup && (!controls || !controls.state || controls.state === -1)) {
// graphGroup.rotation.y += 0.002;
}
renderer.render(scene, camera);
}
document.addEventListener('DOMContentLoaded', init3D);
</script>
</body>
</html>