-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.html
More file actions
480 lines (433 loc) · 20.6 KB
/
Copy pathstorage.html
File metadata and controls
480 lines (433 loc) · 20.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<title>frame</title>
<link rel="icon" href="/favicon.ico" sizes="any" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@700&family=Space+Grotesk:wght@400;500;600;700&family=Space+Mono:wght@400;700&display=swap" rel="stylesheet" />
<style>
* { box-sizing: border-box; }
html, body { margin: 0; background: #ffffff; min-height: 100%; }
body {
color: #000000;
-webkit-font-smoothing: antialiased;
font-family: 'Space Grotesk', sans-serif;
display: flex;
align-items: flex-start;
justify-content: center;
padding: max(64px, calc(env(safe-area-inset-top, 0px) + 52px)) max(16px, env(safe-area-inset-right, 0px)) max(48px, calc(env(safe-area-inset-bottom, 0px) + 28px)) max(16px, env(safe-area-inset-left, 0px));
}
.home-link { color: inherit; text-decoration: none; }
.brand {
position: fixed; top: max(8px, env(safe-area-inset-top, 0px)); left: max(8px, env(safe-area-inset-left, 0px)); margin: 0; z-index: 6;
font-family: 'Chakra Petch', sans-serif; font-weight: 700; color: #000000;
font-size: clamp(18px, 5vw, 40px); letter-spacing: 0.08em; line-height: 1;
}
.panel { width: min(100%, 560px); }
.title {
font-family: 'Chakra Petch', sans-serif; font-weight: 700;
letter-spacing: 0.03em; font-size: clamp(1.5rem, 6vw, 2.1rem);
margin: 0; text-align: center;
}
.subtitle { color: #666666; font-weight: 500; text-align: center; margin: 8px 0 0; font-size: clamp(0.9rem, 3.2vw, 1rem); }
.divider { width: 100%; height: 0; border-top: 1.5px solid #000000; margin: clamp(16px, 3vh, 22px) 0; }
.section-label {
font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
font-size: 0.72rem; color: #888888; margin: clamp(24px, 4vh, 32px) 0 14px;
}
.dev { margin-bottom: clamp(14px, 2.6vh, 20px); }
.dev-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.dev-name { font-family: 'Space Mono', monospace; font-weight: 700; font-size: clamp(1rem, 4.2vw, 1.2rem); }
.dev-browser { font-family: 'Space Mono', monospace; font-weight: 700; color: #888888; font-size: clamp(0.82rem, 3.2vw, 0.95rem); }
.dev-tag {
font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
padding: 2px 7px; border: 1px solid #000000;
}
.dev-tag.on { background: #17a34a; border-color: #17a34a; color: #ffffff; }
/* Pixel grid (one square per stored item) */
.pxwrap {
display: grid;
grid-template-columns: repeat(auto-fill, 28px);
grid-auto-rows: 28px;
gap: 6px;
margin: 14px 0 10px;
justify-content: start;
}
.px {
width: 28px; height: 28px; border-radius: 5px; cursor: pointer;
transition: transform 0.08s ease; touch-action: manipulation;
}
.px:hover, .px:focus-visible { transform: scale(1.15); }
.px:focus-visible { outline: 2px solid #000; outline-offset: 1px; }
.legend2 { font-family: 'Space Mono', monospace; font-size: clamp(0.75rem, 3vw, 0.88rem); color: #444444; margin-top: 4px; }
.legend2 b { color: #000000; }
/* True-scale iOS-style bar: scroll sideways (no scrollbar) to compare size */
.ios-scroll {
width: 100%; overflow-x: auto; overflow-y: hidden;
margin: 14px 0 10px;
-ms-overflow-style: none; scrollbar-width: none;
cursor: grab; touch-action: pan-x;
}
.ios-scroll::-webkit-scrollbar { display: none; }
.ios-scroll.dragging { cursor: grabbing; }
.iosbar {
display: flex; height: 34px; border-radius: 6px;
overflow: hidden; background: #e9ecef;
min-width: 100%;
}
.ios-seg { height: 100%; flex: 0 0 auto; cursor: pointer; box-shadow: inset -1px 0 0 rgba(255,255,255,0.9); }
.ios-free { height: 100%; flex: 0 0 auto; background: #e9ecef; cursor: pointer; }
.ios-legend { display: flex; flex-wrap: wrap; gap: 12px 16px; margin-top: 4px; }
.ios-key {
display: inline-flex; align-items: center; gap: 7px;
font-size: clamp(0.76rem, 2.8vw, 0.88rem); color: #333333; font-weight: 500;
}
.ios-key .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.ios-caption {
font-family: 'Space Mono', monospace; font-size: clamp(0.75rem, 3vw, 0.88rem);
color: #444444; margin-top: 10px;
}
.ios-caption b { color: #000000; }
.ios-hint {
font-size: 0.72rem; color: #999999; margin-top: 6px;
}
.empty { border: 1.5px dashed #cccccc; padding: 16px; text-align: center; color: #888888; font-size: 0.9rem; }
/* Tooltip */
.tooltip {
position: fixed; z-index: 60; pointer-events: none; opacity: 0;
transform: translate(-50%, -120%);
background: #000000; color: #ffffff; padding: 9px 11px; border-radius: 10px;
box-shadow: 0 6px 20px rgba(0,0,0,0.28);
max-width: 260px; transition: opacity 0.1s ease;
}
.tooltip.show { opacity: 1; }
.tooltip .t-name {
font-family: 'Space Mono', monospace; font-weight: 700;
font-size: 0.82rem; word-break: break-all; display: flex; align-items: center; gap: 7px;
}
.tooltip .t-name .sw { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.tooltip .t-meta { color: #bbbbbb; font-size: 0.74rem; margin-top: 4px; font-family: 'Space Mono', monospace; }
.corner {
position: fixed; width: clamp(28px, 6vw, 56px); height: clamp(28px, 6vw, 56px);
border-color: #000000; border-style: solid; border-width: 0; pointer-events: none;
}
.corner.tl { top: env(safe-area-inset-top, 0px); left: env(safe-area-inset-left, 0px); border-top-width: 2.5px; border-left-width: 2.5px; }
.corner.tr { top: env(safe-area-inset-top, 0px); right: env(safe-area-inset-right, 0px); border-top-width: 2.5px; border-right-width: 2.5px; }
.corner.bl { bottom: env(safe-area-inset-bottom, 0px); left: env(safe-area-inset-left, 0px); border-bottom-width: 2.5px; border-left-width: 2.5px; }
.corner.br { bottom: env(safe-area-inset-bottom, 0px); right: env(safe-area-inset-right, 0px); border-bottom-width: 2.5px; border-right-width: 2.5px; }
/* mobile: safe-area, overflow, touch */
html { overflow-x: hidden; }
@media (max-width: 480px) {
.row { grid-template-columns: minmax(72px, 34%) 1fr !important; }
}
@media (max-width: 480px) {
.tooltip { max-width: min(260px, calc(100vw - 24px)); }
.iosbar { height: 40px; }
}
/* storage mobile */
</style>
</head>
<body>
<script src="/frame.js"></script>
<script>
(function () {
FRAME.gate().then(function (active) { if (!active) return; });
})();
</script>
<span class="corner tl"></span>
<span class="corner tr"></span>
<span class="corner bl"></span>
<span class="corner br"></span>
<h1 class="brand"><a class="home-link" href="/">FRAME</a></h1>
<main class="panel">
<h2 class="title">Storage</h2>
<p class="subtitle">Real usage reported by this browser.</p>
<div class="divider"></div>
<div class="section-label">This device</div>
<div id="thisDevice"></div>
<div class="section-label">Connected devices</div>
<div id="connected"></div>
</main>
<div class="tooltip" id="tooltip" role="status" aria-live="polite">
<div class="t-name"><span class="sw" id="ttSw"></span><span id="ttName"></span></div>
<div class="t-meta" id="ttMeta"></div>
</div>
<script>
(function () {
var PIXELS = 240;
var tip = document.getElementById("tooltip");
var ttSw = document.getElementById("ttSw");
var ttName = document.getElementById("ttName");
var ttMeta = document.getElementById("ttMeta");
var pinned = false;
function hb(n) { return FRAME.humanBytesLong ? FRAME.humanBytesLong(n) : n + " bytes"; }
function categorize(name, isUsage) {
if (isUsage) {
var n = String(name).toLowerCase();
if (n.indexOf("indexeddb") >= 0) return { label: "IndexedDB", color: "#9b59b6" };
if (n.indexOf("cache") >= 0) return { label: "Caches", color: "#ff8a00" };
if (n.indexOf("serviceworker") >= 0) return { label: "Service worker", color: "#ff5fa2" };
if (n.indexOf("filesystem") >= 0) return { label: "File system", color: "#0891b2" };
return { label: name, color: "#7c5cff" };
}
if (name === "frame.identities") return { label: "Identities", color: "#1a73e8" };
if (name === "frame.activeId") return { label: "Active identity", color: "#17a34a" };
if (name === "frame.shell") return { label: "FRAME instance", color: "#111111" };
if (name === "frame.receipts.chain.v1") return { label: "Receipt chain", color: "#0f7a3d" };
if (name === "frame.grants.v1") return { label: "Grants", color: "#7c3aed" };
if (name.indexOf("frame.dapp.") === 0) return { label: "dApp", color: "#ff8a00" };
if (name.indexOf("frame.") === 0) return { label: "FRAME data", color: "#14b8a6" };
return { label: "Site data", color: "#999999" };
}
function buildSegments(est) {
var segs = [];
FRAME.localStorageEntries().forEach(function (e) {
if (e.bytes <= 0) return;
var c = categorize(e.name, false);
segs.push({ name: e.name, bytes: e.bytes, label: c.label, color: c.color });
});
if (est && est.usageDetails) {
Object.keys(est.usageDetails).forEach(function (k) {
var b = est.usageDetails[k];
if (!b || b <= 0) return;
var c = categorize(k, true);
segs.push({ name: k, bytes: b, label: c.label, color: c.color });
});
}
return segs;
}
function positionTip(x, y) {
var pad = 12;
var w = tip.offsetWidth || 200;
var h = tip.offsetHeight || 60;
var nx = Math.min(Math.max(x, pad + w / 2), window.innerWidth - pad - w / 2);
var ny = Math.max(y, pad + h + 8);
tip.style.left = nx + "px";
tip.style.top = ny + "px";
}
function showTip(seg, total, x, y) {
ttSw.style.background = seg.color;
ttName.textContent = seg.name;
var pct = total > 0 ? (seg.bytes / total * 100) : 0;
var pctTxt = pct >= 1 ? pct.toFixed(1) : pct.toPrecision(2);
ttMeta.textContent = seg.label + " \u00b7 " + hb(seg.bytes) + " \u00b7 " + pctTxt + "% of used";
positionTip(x, y);
tip.classList.add("show");
}
function showFreeTip(free, x, y) {
ttSw.style.background = "#e9ecef";
ttName.textContent = "Unused";
var pct = free.quota > 0 ? (free.bytes / free.quota * 100) : 0;
var pctTxt = pct >= 1 ? pct.toFixed(1) : pct.toPrecision(2);
ttMeta.textContent = hb(free.bytes) + " free \u00b7 " + pctTxt + "% of allowance";
positionTip(x, y);
tip.classList.add("show");
}
function hideTip() { tip.classList.remove("show"); }
function renderMap(container, segs) {
var total = 0; segs.forEach(function (s) { total += s.bytes; });
var wrap = document.createElement("div");
wrap.className = "pxwrap";
if (total <= 0) {
var pctLine0 = document.createElement("div");
pctLine0.className = "legend2";
pctLine0.textContent = "No stored data yet.";
container.appendChild(pctLine0);
return;
}
// One square per stored item.
segs.slice().sort(function (a, b) { return b.bytes - a.bytes; }).forEach(function (s) {
var px = document.createElement("div");
px.className = "px";
px.style.background = s.color;
px._seg = s;
wrap.appendChild(px);
});
wrap.addEventListener("pointerover", function (e) {
if (pinned) return;
var t = e.target;
if (t && t.classList.contains("px") && t._seg) showTip(t._seg, total, e.clientX, e.clientY);
});
wrap.addEventListener("pointermove", function (e) {
if (pinned) return;
if (tip.classList.contains("show")) positionTip(e.clientX, e.clientY);
});
wrap.addEventListener("pointerleave", function () { if (!pinned) hideTip(); });
wrap.addEventListener("click", function (e) {
var t = e.target;
if (t && t.classList.contains("px") && t._seg) {
pinned = true;
showTip(t._seg, total, e.clientX, e.clientY);
e.stopPropagation();
}
});
container.appendChild(wrap);
}
function renderIosBar(container, segs, usage, quota) {
var usedTotal = 0; segs.forEach(function (s) { usedTotal += s.bytes; });
// Prefer summed segments for "used" when they account for local data;
// fall back to estimate usage so caption matches the bar.
var usedBytes = Math.max(usedTotal, usage || 0);
var quotaBytes = (quota && quota > 0) ? quota : null;
var freeBytes = quotaBytes != null ? Math.max(0, quotaBytes - usedBytes) : 0;
var scroller = document.createElement("div");
scroller.className = "ios-scroll";
var bar = document.createElement("div");
bar.className = "iosbar";
// True scale for used; free extends proportionally but is capped for DOM size.
// Drag / scroll horizontally to compare; no visible scrollbar.
var viewW = Math.max(container.clientWidth || 320, 280);
var MIN_USED_PX = Math.max(110, Math.round(viewW * 0.32));
var MAX_FREE_PX = Math.round(viewW * 40);
var scale = usedBytes > 0 ? (MIN_USED_PX / usedBytes) : (viewW / Math.max(quotaBytes || viewW, 1));
var sorted = segs.slice().sort(function (a, b) { return b.bytes - a.bytes; });
sorted.forEach(function (s) {
var seg = document.createElement("div");
seg.className = "ios-seg";
var w = Math.max(s.bytes * scale, s.bytes > 0 ? 1 : 0);
seg.style.width = w + "px";
seg.style.background = s.color;
seg._seg = s;
bar.appendChild(seg);
});
if (quotaBytes) {
var freeSeg = document.createElement("div");
freeSeg.className = "ios-free";
var freeW = freeBytes * scale;
freeSeg.style.width = Math.max(Math.min(freeW, MAX_FREE_PX), 12) + "px";
freeSeg._free = { bytes: freeBytes, quota: quotaBytes };
bar.appendChild(freeSeg);
} else {
bar.style.width = "100%";
}
bar.addEventListener("pointerover", function (e) {
if (pinned) return;
var t = e.target;
if (t && t.classList.contains("ios-seg") && t._seg) showTip(t._seg, usedBytes, e.clientX, e.clientY);
else if (t && t.classList.contains("ios-free") && t._free) showFreeTip(t._free, e.clientX, e.clientY);
});
bar.addEventListener("pointermove", function (e) {
if (pinned) return;
if (tip.classList.contains("show")) positionTip(e.clientX, e.clientY);
});
bar.addEventListener("pointerleave", function () { if (!pinned) hideTip(); });
bar.addEventListener("click", function (e) {
var t = e.target;
if (t && t.classList.contains("ios-seg") && t._seg) {
pinned = true; showTip(t._seg, usedBytes, e.clientX, e.clientY); e.stopPropagation();
} else if (t && t.classList.contains("ios-free") && t._free) {
pinned = true; showFreeTip(t._free, e.clientX, e.clientY); e.stopPropagation();
}
});
// Drag-to-scroll (no scrollbar UI)
var drag = { on: false, x: 0, left: 0 };
scroller.addEventListener("pointerdown", function (e) {
if (e.button !== 0) return;
drag.on = true; drag.x = e.clientX; drag.left = scroller.scrollLeft;
scroller.classList.add("dragging");
try { scroller.setPointerCapture(e.pointerId); } catch (err) {}
});
scroller.addEventListener("pointermove", function (e) {
if (!drag.on) return;
scroller.scrollLeft = drag.left - (e.clientX - drag.x);
});
function endDrag() { drag.on = false; scroller.classList.remove("dragging"); }
scroller.addEventListener("pointerup", endDrag);
scroller.addEventListener("pointercancel", endDrag);
// Wheel zoom: change scale comparison by adjusting scroll width via CSS zoom on bar
var zoom = 1;
scroller.addEventListener("wheel", function (e) {
if (!(e.ctrlKey || e.metaKey || Math.abs(e.deltaY) > 0)) return;
// Horizontal intent or pinch-zoom modifiers → scale the bar
if (e.ctrlKey || e.metaKey) {
e.preventDefault();
var prev = zoom;
zoom = Math.min(8, Math.max(0.25, zoom * (e.deltaY < 0 ? 1.12 : 0.9)));
bar.style.transform = "scaleX(" + zoom + ")";
bar.style.transformOrigin = "left center";
// Keep roughly under cursor
var ratio = scroller.scrollLeft / Math.max(1, scroller.scrollWidth - scroller.clientWidth);
requestAnimationFrame(function () {
scroller.scrollLeft = ratio * Math.max(0, scroller.scrollWidth - scroller.clientWidth);
});
void prev;
} else {
// Natural sideways browse
if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) {
scroller.scrollLeft += e.deltaY;
}
}
}, { passive: false });
scroller.appendChild(bar);
container.appendChild(scroller);
var seen = {};
var legend = document.createElement("div");
legend.className = "ios-legend";
sorted.forEach(function (s) {
if (seen[s.label]) return;
seen[s.label] = true;
var item = document.createElement("span");
item.className = "ios-key";
item.innerHTML = '<span class="dot" style="background:' + s.color + '"></span>' + s.label;
legend.appendChild(item);
});
container.appendChild(legend);
var cap = document.createElement("div");
cap.className = "ios-caption";
if (quotaBytes) {
cap.innerHTML = "<b>" + hb(usedBytes) + "</b> used of <b>" + hb(quotaBytes) + "</b> \u00b7 <b>" + hb(freeBytes) + "</b> free";
} else {
cap.innerHTML = "<b>" + hb(usedBytes) + "</b> used \u00b7 allowance not reported";
}
container.appendChild(cap);
var hint = document.createElement("div");
hint.className = "ios-hint";
hint.textContent = "Drag or scroll sideways for true size. Ctrl/⌘ + wheel to zoom the comparison.";
container.appendChild(hint);
}
document.addEventListener("click", function () { if (pinned) { pinned = false; hideTip(); } });
var thisDevice = document.getElementById("thisDevice");
function renderThisDevice(est) {
var localBytes = FRAME.localStorageBytes();
var estUsage = (est && typeof est.usage === "number") ? est.usage : 0;
var usage = Math.max(estUsage, localBytes);
var quota = (est && typeof est.quota === "number") ? est.quota : null;
var dev = document.createElement("div");
dev.className = "dev";
var head = document.createElement("div");
head.className = "dev-head";
head.innerHTML = '<span class="dev-name">this browser</span>' +
'<span class="dev-browser">(' + FRAME.browserName() + ')</span>' +
'<span class="dev-tag on">this device</span>';
dev.appendChild(head);
var segs = buildSegments(est);
renderMap(dev, segs);
renderIosBar(dev, segs, usage, quota);
thisDevice.appendChild(dev);
}
function renderConnected() {
var container = document.getElementById("connected");
var empty = document.createElement("div");
empty.className = "empty";
empty.textContent = "No connected devices. Device-to-device sync is not available from the browser yet.";
container.appendChild(empty);
}
function go(est) {
renderThisDevice(est);
renderConnected();
}
if (navigator.storage && navigator.storage.estimate) {
navigator.storage.estimate().then(go).catch(function () { go(null); });
} else {
go(null);
}
})();
</script>
</body>
</html>