Spaces:
Running
Running
Wait for Start before loading anything; polish the controls
Browse filesThe page no longer loads LiteRT.js or a model when it opens: a bar on the picture says what starting downloads, and nothing is fetched until Start is pressed. Overlay colours are tokens, the progress bar animates a transform, and pressed, hover and disabled states are fixed.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- index.html +172 -64
index.html
CHANGED
|
@@ -7,6 +7,12 @@
|
|
| 7 |
<meta name="description" content="Depth from a single photo, computed in your browser on WebGPU with LiteRT.js.">
|
| 8 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect width='8' height='16' fill='%2358626b'/%3E%3Crect x='8' width='8' height='16' fill='%23f66b19'/%3E%3Crect x='7.25' width='1.5' height='16' fill='%23fff'/%3E%3C/svg%3E">
|
| 9 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
:root {
|
| 11 |
color-scheme: light dark;
|
| 12 |
--ground: #f2f4f6;
|
|
@@ -17,9 +23,24 @@
|
|
| 17 |
--line: #d3d8dd;
|
| 18 |
--line-2: #aab1b9;
|
| 19 |
--accent: #c2410c;
|
|
|
|
| 20 |
--caution: #8a4b00;
|
| 21 |
--off: #6b747d;
|
| 22 |
--radius: 6px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
@media (prefers-color-scheme: dark) {
|
| 25 |
:root {
|
|
@@ -31,6 +52,7 @@
|
|
| 31 |
--line: #2b3035;
|
| 32 |
--line-2: #4a525a;
|
| 33 |
--accent: #ff8f3d;
|
|
|
|
| 34 |
--caution: #ffb86b;
|
| 35 |
}
|
| 36 |
}
|
|
@@ -39,9 +61,10 @@
|
|
| 39 |
[hidden] { display: none !important; }
|
| 40 |
.unseen { position: absolute; width: 1px; height: 1px; overflow: hidden; white-space: nowrap; clip-path: inset(50%); }
|
| 41 |
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
|
| 42 |
-
html { background: var(--ground); }
|
| 43 |
body {
|
| 44 |
margin: 0;
|
|
|
|
| 45 |
background: var(--ground);
|
| 46 |
color: var(--ink);
|
| 47 |
font: 0.875rem/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
@@ -58,8 +81,8 @@
|
|
| 58 |
padding: 18px 24px 24px;
|
| 59 |
}
|
| 60 |
header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 16px; margin-bottom: 14px; }
|
| 61 |
-
h1 { margin: 0; font-size: 1.125rem; font-weight: 650; letter-spacing: -0.01em; }
|
| 62 |
-
.lede { flex: 1 1 30ch; margin: 0; color: var(--ink-2); }
|
| 63 |
header nav { display: flex; gap: 16px; }
|
| 64 |
main { display: grid; grid-template-columns: minmax(0, 1fr) 296px; gap: 24px; align-items: start; }
|
| 65 |
|
|
@@ -70,7 +93,7 @@
|
|
| 70 |
aspect-ratio: 854 / 480;
|
| 71 |
overflow: hidden;
|
| 72 |
border-radius: var(--radius);
|
| 73 |
-
background:
|
| 74 |
touch-action: pan-y;
|
| 75 |
user-select: none;
|
| 76 |
-webkit-user-select: none;
|
|
@@ -99,8 +122,8 @@
|
|
| 99 |
bottom: 0;
|
| 100 |
left: 21px;
|
| 101 |
width: 2px;
|
| 102 |
-
background:
|
| 103 |
-
box-shadow:
|
| 104 |
}
|
| 105 |
.grip {
|
| 106 |
position: relative;
|
|
@@ -109,19 +132,20 @@
|
|
| 109 |
width: 34px;
|
| 110 |
height: 34px;
|
| 111 |
border-radius: 50%;
|
| 112 |
-
background:
|
| 113 |
-
color:
|
| 114 |
-
box-shadow:
|
| 115 |
}
|
| 116 |
-
.divider:focus-visible .grip { box-shadow:
|
| 117 |
.viewer:not([data-depth]) .divider, .viewer:not([data-depth]) #tag-depth { display: none; }
|
|
|
|
| 118 |
.tag {
|
| 119 |
position: absolute;
|
| 120 |
bottom: 10px;
|
| 121 |
padding: 3px 8px;
|
| 122 |
border-radius: 4px;
|
| 123 |
-
background:
|
| 124 |
-
color:
|
| 125 |
font-size: 0.75rem;
|
| 126 |
font-weight: 600;
|
| 127 |
pointer-events: none;
|
|
@@ -132,21 +156,21 @@
|
|
| 132 |
.probe {
|
| 133 |
padding: 3px 7px;
|
| 134 |
border-radius: 4px;
|
| 135 |
-
background:
|
| 136 |
-
color:
|
| 137 |
font-size: 0.8125rem;
|
| 138 |
font-weight: 600;
|
| 139 |
font-variant-numeric: tabular-nums;
|
| 140 |
white-space: nowrap;
|
| 141 |
-
box-shadow:
|
| 142 |
}
|
| 143 |
.spot {
|
| 144 |
width: 9px;
|
| 145 |
height: 9px;
|
| 146 |
margin: -4.5px 0 0 -4.5px;
|
| 147 |
-
border: 1.5px solid
|
| 148 |
border-radius: 50%;
|
| 149 |
-
box-shadow:
|
| 150 |
}
|
| 151 |
.progress {
|
| 152 |
position: absolute;
|
|
@@ -157,15 +181,23 @@
|
|
| 157 |
max-width: calc(100% - 28px);
|
| 158 |
padding: 9px 12px 10px;
|
| 159 |
border-radius: var(--radius);
|
| 160 |
-
background:
|
| 161 |
-
color:
|
| 162 |
font-size: 0.8125rem;
|
| 163 |
font-variant-numeric: tabular-nums;
|
| 164 |
transform: translateX(-50%);
|
| 165 |
}
|
| 166 |
-
.bar { height: 3px; margin-top: 7px; overflow: hidden; border-radius: 2px; background:
|
| 167 |
-
.bar i {
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
|
| 170 |
.notice {
|
| 171 |
position: absolute;
|
|
@@ -175,12 +207,41 @@
|
|
| 175 |
justify-items: center;
|
| 176 |
gap: 14px;
|
| 177 |
padding: 24px;
|
| 178 |
-
background:
|
| 179 |
-
color:
|
| 180 |
text-align: center;
|
| 181 |
}
|
| 182 |
.notice p { max-width: 44ch; margin: 0; font-size: 0.9375rem; text-wrap: balance; }
|
| 183 |
-
.notice .button { border-color:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
/* The colors as distances: laid out like the distance scale of a lens, which is also linear in
|
| 186 |
inverse depth and ends at infinity. */
|
|
@@ -212,7 +273,7 @@
|
|
| 212 |
.panel { display: grid; gap: 22px; }
|
| 213 |
.group { min-width: 0; margin: 0; padding: 0; border: 0; }
|
| 214 |
.group h2, .group legend, .switch { margin: 0 0 8px; padding: 0; font-size: 0.8125rem; font-weight: 600; }
|
| 215 |
-
.hint { margin: 7px 0 0; color: var(--ink-2); font-size: 0.8125rem; }
|
| 216 |
.samples { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
|
| 217 |
.samples button {
|
| 218 |
aspect-ratio: 16 / 9;
|
|
@@ -246,6 +307,7 @@
|
|
| 246 |
}
|
| 247 |
.button:hover { border-color: var(--ink-2); }
|
| 248 |
.button:active { background: var(--hover); }
|
|
|
|
| 249 |
.button[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--ground); }
|
| 250 |
.button:has(:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }
|
| 251 |
.button svg, .grip svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
|
|
@@ -278,8 +340,9 @@
|
|
| 278 |
.segmented input:checked + span small { color: inherit; opacity: 0.75; }
|
| 279 |
.segmented input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 3px; }
|
| 280 |
.segmented input:disabled { cursor: not-allowed; }
|
| 281 |
-
.segmented input:disabled + span {
|
| 282 |
-
|
|
|
|
| 283 |
.switch input {
|
| 284 |
position: relative;
|
| 285 |
flex: none;
|
|
@@ -301,15 +364,15 @@
|
|
| 301 |
width: 16px;
|
| 302 |
height: 16px;
|
| 303 |
border-radius: 50%;
|
| 304 |
-
background:
|
| 305 |
-
box-shadow:
|
| 306 |
transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
|
| 307 |
}
|
| 308 |
.switch input:checked { background: var(--accent); }
|
| 309 |
.switch input:checked::after { transform: translateX(16px); }
|
| 310 |
.panel[inert] { opacity: 0.5; }
|
| 311 |
footer { max-width: 86ch; margin-top: 26px; color: var(--ink-2); font-size: 0.8125rem; }
|
| 312 |
-
footer p { margin: 0; }
|
| 313 |
|
| 314 |
@media (max-width: 860px) {
|
| 315 |
.page { max-width: none; padding: 14px 16px 20px; }
|
|
@@ -318,7 +381,7 @@
|
|
| 318 |
}
|
| 319 |
@media (prefers-reduced-motion: reduce) {
|
| 320 |
*, *::before, *::after { transition: none !important; }
|
| 321 |
-
.progress.waiting .bar i { width: 100%; opacity: 0.5; animation: none; }
|
| 322 |
}
|
| 323 |
</style>
|
| 324 |
</head>
|
|
@@ -404,14 +467,14 @@
|
|
| 404 |
|
| 405 |
<div class="group">
|
| 406 |
<label class="switch">Depth in meters <input id="metric" type="checkbox" role="switch"></label>
|
| 407 |
-
<p class="hint">Adds a second model (95 MB) that estimates the camera
|
| 408 |
</div>
|
| 409 |
</aside>
|
| 410 |
</main>
|
| 411 |
|
| 412 |
<footer>
|
| 413 |
<p>
|
| 414 |
-
Depth Pro 2 is Apple
|
| 415 |
<a href="https://huggingface.co/byoussef/DepthPro2-litert" target="_blank" rel="noopener">LiteRT conversions</a>,
|
| 416 |
not endorsed by Apple, under the
|
| 417 |
<a href="https://huggingface.co/byoussef/DepthPro2-litert/blob/main/LICENSE" target="_blank" rel="noopener">Apple Machine Learning Research Model License</a>:
|
|
@@ -476,14 +539,14 @@
|
|
| 476 |
let pointer = null; // the place being probed, as fractions of the picture
|
| 477 |
let standing = ''; // a caution that holds for the whole visit
|
| 478 |
let asked = 0; // the photos asked for so far
|
| 479 |
-
let ready = false; //
|
| 480 |
|
| 481 |
// ---- Messages -----------------------------------------------------------------------------
|
| 482 |
|
| 483 |
function progress(text, fraction) {
|
| 484 |
$('progress').hidden = false;
|
| 485 |
$('progress').classList.toggle('waiting', fraction === undefined);
|
| 486 |
-
$('progress').style.setProperty('--done',
|
| 487 |
$('progress-text').textContent = text;
|
| 488 |
// Read out once a phase, not at every megabyte.
|
| 489 |
const phase = text.split(':')[0];
|
|
@@ -497,9 +560,10 @@
|
|
| 497 |
document.documentElement.dataset.state = $('notice').hidden ? 'ready' : 'blocked';
|
| 498 |
}
|
| 499 |
|
| 500 |
-
// A message over the picture, with what to do about it.
|
| 501 |
-
function notify(text, action, act) {
|
| 502 |
$('notice').hidden = false;
|
|
|
|
| 503 |
$('notice-text').textContent = text;
|
| 504 |
$('notice-action').hidden = !action;
|
| 505 |
$('notice-action').textContent = action ?? '';
|
|
@@ -523,7 +587,8 @@
|
|
| 523 |
|
| 524 |
// ---- The models ---------------------------------------------------------------------------
|
| 525 |
|
| 526 |
-
|
|
|
|
| 527 |
if (!navigator.gpu) {
|
| 528 |
throw new Error('This browser has no WebGPU, which the models run on. Chrome, Edge and Firefox on a computer have it.');
|
| 529 |
}
|
|
@@ -535,6 +600,11 @@
|
|
| 535 |
if (!adapter) {
|
| 536 |
throw new Error('This browser found no GPU for WebGPU. Turn on graphics acceleration in its settings, or try Chrome or Edge on another computer.');
|
| 537 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 538 |
try {
|
| 539 |
litert = await import(`${LITERT}/+esm`);
|
| 540 |
await litert.loadLiteRt(`${LITERT}/wasm/`);
|
|
@@ -1085,7 +1155,7 @@
|
|
| 1085 |
if (stream && video.srcObject === stream) video.srcObject = null;
|
| 1086 |
if (failure) {
|
| 1087 |
warn(failure.name === 'NotAllowedError'
|
| 1088 |
-
? 'The camera is blocked for this page. Allow it in the browser
|
| 1089 |
: 'No camera could be started.');
|
| 1090 |
}
|
| 1091 |
return;
|
|
@@ -1107,7 +1177,8 @@
|
|
| 1107 |
if (transfer && !needed(transfer.file)) transfer.controller.abort();
|
| 1108 |
for (const file of held.keys()) if (!needed(file)) held.delete(file);
|
| 1109 |
render();
|
| 1110 |
-
refresh();
|
|
|
|
| 1111 |
}
|
| 1112 |
|
| 1113 |
for (const [sample, label] of SAMPLES) {
|
|
@@ -1213,34 +1284,71 @@
|
|
| 1213 |
render();
|
| 1214 |
choose(SAMPLES[0][0]);
|
| 1215 |
|
| 1216 |
-
|
| 1217 |
-
|
| 1218 |
-
|
| 1219 |
-
|
| 1220 |
-
|
| 1221 |
-
|
| 1222 |
-
|
| 1223 |
-
|
| 1224 |
-
|
| 1225 |
-
|
| 1226 |
-
|
| 1227 |
-
|
| 1228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1229 |
}
|
| 1230 |
-
if (
|
| 1231 |
-
|
| 1232 |
-
|
| 1233 |
-
|
| 1234 |
-
|
| 1235 |
-
|
| 1236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1237 |
ready = true;
|
| 1238 |
refresh();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1239 |
}
|
|
|
|
| 1240 |
} catch (error) {
|
| 1241 |
-
|
| 1242 |
-
$('panel').inert = true;
|
| 1243 |
-
notify(error.message, error.reload ? 'Reload the page' : undefined, () => location.reload());
|
| 1244 |
}
|
| 1245 |
</script>
|
| 1246 |
</body>
|
|
|
|
| 7 |
<meta name="description" content="Depth from a single photo, computed in your browser on WebGPU with LiteRT.js.">
|
| 8 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect width='8' height='16' fill='%2358626b'/%3E%3Crect x='8' width='8' height='16' fill='%23f66b19'/%3E%3Crect x='7.25' width='1.5' height='16' fill='%23fff'/%3E%3C/svg%3E">
|
| 9 |
<style>
|
| 10 |
+
/* Hallmark · checked: 2026-11-24 · genre: modern-minimal (inferred)
|
| 11 |
+
* floor: 0 FAIL · fixed: 7 (10a, 26a, 26b, 34, 39a, 48, F1) · structural: 0 printed
|
| 12 |
+
* finish-review: subagent · 3 findings · 3 resolved
|
| 13 |
+
* built: the project · shape: app screen · redesign: polish · v2.0.0 */
|
| 14 |
+
/* Hallmark · dismissed 25 · the start bar holds one sentence beside its button, a caption and not running prose */
|
| 15 |
+
/* Hallmark · waive 28b · the video is hidden and only feeds the camera's frames to a canvas, never the LCP · a camera stream has no poster frame to show before the visitor turns the camera on */
|
| 16 |
:root {
|
| 17 |
color-scheme: light dark;
|
| 18 |
--ground: #f2f4f6;
|
|
|
|
| 23 |
--line: #d3d8dd;
|
| 24 |
--line-2: #aab1b9;
|
| 25 |
--accent: #c2410c;
|
| 26 |
+
--accent-ink: #ffffff;
|
| 27 |
--caution: #8a4b00;
|
| 28 |
--off: #6b747d;
|
| 29 |
--radius: 6px;
|
| 30 |
+
/* What lies over the picture is the same in both themes: the picture is its ground. */
|
| 31 |
+
--stage: #0c0e10;
|
| 32 |
+
--on-stage: #ffffff;
|
| 33 |
+
--on-stage-ink: #15181b;
|
| 34 |
+
--scrim: rgb(12 14 16 / 0.8);
|
| 35 |
+
--chip: rgb(12 14 16 / 0.74);
|
| 36 |
+
--chip-solid: rgb(12 14 16 / 0.88);
|
| 37 |
+
--track: rgb(255 255 255 / 0.22);
|
| 38 |
+
--shadow-edge: 0 0 0 1px rgb(0 0 0 / 0.28);
|
| 39 |
+
--shadow-knob: 0 1px 2px rgb(0 0 0 / 0.3);
|
| 40 |
+
--shadow-lift: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 12px rgb(0 0 0 / 0.28);
|
| 41 |
+
--shadow-label: 0 1px 2px rgb(0 0 0 / 0.3), 0 3px 10px rgb(0 0 0 / 0.25);
|
| 42 |
+
--shadow-spot: 0 0 0 1px rgb(0 0 0 / 0.5);
|
| 43 |
+
--ring-stage: 0 0 0 2px #15181b, 0 0 0 4px #ffffff;
|
| 44 |
}
|
| 45 |
@media (prefers-color-scheme: dark) {
|
| 46 |
:root {
|
|
|
|
| 52 |
--line: #2b3035;
|
| 53 |
--line-2: #4a525a;
|
| 54 |
--accent: #ff8f3d;
|
| 55 |
+
--accent-ink: #15181b;
|
| 56 |
--caution: #ffb86b;
|
| 57 |
}
|
| 58 |
}
|
|
|
|
| 61 |
[hidden] { display: none !important; }
|
| 62 |
.unseen { position: absolute; width: 1px; height: 1px; overflow: hidden; white-space: nowrap; clip-path: inset(50%); }
|
| 63 |
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
|
| 64 |
+
html { overflow-x: clip; background: var(--ground); accent-color: var(--accent); caret-color: var(--accent); }
|
| 65 |
body {
|
| 66 |
margin: 0;
|
| 67 |
+
overflow-x: clip;
|
| 68 |
background: var(--ground);
|
| 69 |
color: var(--ink);
|
| 70 |
font: 0.875rem/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
|
|
| 81 |
padding: 18px 24px 24px;
|
| 82 |
}
|
| 83 |
header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 16px; margin-bottom: 14px; }
|
| 84 |
+
h1 { margin: 0; font-size: 1.125rem; font-weight: 650; letter-spacing: -0.01em; text-wrap: balance; }
|
| 85 |
+
.lede { flex: 1 1 30ch; margin: 0; color: var(--ink-2); text-wrap: pretty; }
|
| 86 |
header nav { display: flex; gap: 16px; }
|
| 87 |
main { display: grid; grid-template-columns: minmax(0, 1fr) 296px; gap: 24px; align-items: start; }
|
| 88 |
|
|
|
|
| 93 |
aspect-ratio: 854 / 480;
|
| 94 |
overflow: hidden;
|
| 95 |
border-radius: var(--radius);
|
| 96 |
+
background: var(--stage);
|
| 97 |
touch-action: pan-y;
|
| 98 |
user-select: none;
|
| 99 |
-webkit-user-select: none;
|
|
|
|
| 122 |
bottom: 0;
|
| 123 |
left: 21px;
|
| 124 |
width: 2px;
|
| 125 |
+
background: var(--on-stage);
|
| 126 |
+
box-shadow: var(--shadow-edge);
|
| 127 |
}
|
| 128 |
.grip {
|
| 129 |
position: relative;
|
|
|
|
| 132 |
width: 34px;
|
| 133 |
height: 34px;
|
| 134 |
border-radius: 50%;
|
| 135 |
+
background: var(--on-stage);
|
| 136 |
+
color: var(--on-stage-ink);
|
| 137 |
+
box-shadow: var(--shadow-lift);
|
| 138 |
}
|
| 139 |
+
.divider:focus-visible .grip { box-shadow: var(--ring-stage); }
|
| 140 |
.viewer:not([data-depth]) .divider, .viewer:not([data-depth]) #tag-depth { display: none; }
|
| 141 |
+
.viewer:has(.notice.start:not([hidden])) .tag { display: none; }
|
| 142 |
.tag {
|
| 143 |
position: absolute;
|
| 144 |
bottom: 10px;
|
| 145 |
padding: 3px 8px;
|
| 146 |
border-radius: 4px;
|
| 147 |
+
background: var(--chip);
|
| 148 |
+
color: var(--on-stage);
|
| 149 |
font-size: 0.75rem;
|
| 150 |
font-weight: 600;
|
| 151 |
pointer-events: none;
|
|
|
|
| 156 |
.probe {
|
| 157 |
padding: 3px 7px;
|
| 158 |
border-radius: 4px;
|
| 159 |
+
background: var(--on-stage);
|
| 160 |
+
color: var(--on-stage-ink);
|
| 161 |
font-size: 0.8125rem;
|
| 162 |
font-weight: 600;
|
| 163 |
font-variant-numeric: tabular-nums;
|
| 164 |
white-space: nowrap;
|
| 165 |
+
box-shadow: var(--shadow-label);
|
| 166 |
}
|
| 167 |
.spot {
|
| 168 |
width: 9px;
|
| 169 |
height: 9px;
|
| 170 |
margin: -4.5px 0 0 -4.5px;
|
| 171 |
+
border: 1.5px solid var(--on-stage);
|
| 172 |
border-radius: 50%;
|
| 173 |
+
box-shadow: var(--shadow-spot);
|
| 174 |
}
|
| 175 |
.progress {
|
| 176 |
position: absolute;
|
|
|
|
| 181 |
max-width: calc(100% - 28px);
|
| 182 |
padding: 9px 12px 10px;
|
| 183 |
border-radius: var(--radius);
|
| 184 |
+
background: var(--chip-solid);
|
| 185 |
+
color: var(--on-stage);
|
| 186 |
font-size: 0.8125rem;
|
| 187 |
font-variant-numeric: tabular-nums;
|
| 188 |
transform: translateX(-50%);
|
| 189 |
}
|
| 190 |
+
.bar { height: 3px; margin-top: 7px; overflow: hidden; border-radius: 2px; background: var(--track); }
|
| 191 |
+
.bar i {
|
| 192 |
+
display: block;
|
| 193 |
+
height: 100%;
|
| 194 |
+
border-radius: 2px;
|
| 195 |
+
background: var(--on-stage);
|
| 196 |
+
transform: scaleX(var(--done, 0));
|
| 197 |
+
transform-origin: 0 50%;
|
| 198 |
+
transition: transform 0.15s linear;
|
| 199 |
+
}
|
| 200 |
+
.progress.waiting .bar i { width: 35%; transform: none; transition: none; animation: slide 1.15s cubic-bezier(0.4, 0, 0.2, 1) infinite; }
|
| 201 |
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
|
| 202 |
.notice {
|
| 203 |
position: absolute;
|
|
|
|
| 207 |
justify-items: center;
|
| 208 |
gap: 14px;
|
| 209 |
padding: 24px;
|
| 210 |
+
background: var(--scrim);
|
| 211 |
+
color: var(--on-stage);
|
| 212 |
text-align: center;
|
| 213 |
}
|
| 214 |
.notice p { max-width: 44ch; margin: 0; font-size: 0.9375rem; text-wrap: balance; }
|
| 215 |
+
.notice .button { border-color: var(--on-stage); background: var(--on-stage); color: var(--on-stage-ink); }
|
| 216 |
+
.notice .button:hover { border-color: var(--on-stage); background: color-mix(in srgb, var(--on-stage) 92%, var(--stage)); }
|
| 217 |
+
.notice .button:active { background: color-mix(in srgb, var(--on-stage) 84%, var(--stage)); }
|
| 218 |
+
.notice .button:focus-visible { outline-color: var(--on-stage); }
|
| 219 |
+
/* Before anything is loaded: a bar docked where the progress will show, and the picture left clear. */
|
| 220 |
+
.notice.start {
|
| 221 |
+
inset: auto auto 14px 50%;
|
| 222 |
+
display: flex;
|
| 223 |
+
align-items: center;
|
| 224 |
+
gap: 16px;
|
| 225 |
+
width: max-content;
|
| 226 |
+
max-width: calc(100% - 28px);
|
| 227 |
+
padding: 10px 10px 10px 16px;
|
| 228 |
+
border-radius: var(--radius);
|
| 229 |
+
background: var(--chip-solid);
|
| 230 |
+
text-align: left;
|
| 231 |
+
transform: translateX(-50%);
|
| 232 |
+
}
|
| 233 |
+
.notice.start p { max-width: 40ch; font-size: 0.875rem; text-wrap: pretty; }
|
| 234 |
+
.notice.start .button {
|
| 235 |
+
flex: none;
|
| 236 |
+
padding: 8px 20px;
|
| 237 |
+
border-color: var(--accent);
|
| 238 |
+
background: var(--accent);
|
| 239 |
+
color: var(--accent-ink);
|
| 240 |
+
font-size: 0.9375rem;
|
| 241 |
+
white-space: nowrap;
|
| 242 |
+
}
|
| 243 |
+
.notice.start .button:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 92%, var(--stage)); }
|
| 244 |
+
.notice.start .button:active { background: color-mix(in srgb, var(--accent) 84%, var(--stage)); }
|
| 245 |
|
| 246 |
/* The colors as distances: laid out like the distance scale of a lens, which is also linear in
|
| 247 |
inverse depth and ends at infinity. */
|
|
|
|
| 273 |
.panel { display: grid; gap: 22px; }
|
| 274 |
.group { min-width: 0; margin: 0; padding: 0; border: 0; }
|
| 275 |
.group h2, .group legend, .switch { margin: 0 0 8px; padding: 0; font-size: 0.8125rem; font-weight: 600; }
|
| 276 |
+
.hint { margin: 7px 0 0; color: var(--ink-2); font-size: 0.8125rem; text-wrap: pretty; }
|
| 277 |
.samples { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
|
| 278 |
.samples button {
|
| 279 |
aspect-ratio: 16 / 9;
|
|
|
|
| 307 |
}
|
| 308 |
.button:hover { border-color: var(--ink-2); }
|
| 309 |
.button:active { background: var(--hover); }
|
| 310 |
+
.button:disabled { border-color: var(--line); background: var(--hover); color: var(--ink-2); cursor: not-allowed; }
|
| 311 |
.button[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--ground); }
|
| 312 |
.button:has(:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }
|
| 313 |
.button svg, .grip svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
|
|
|
|
| 340 |
.segmented input:checked + span small { color: inherit; opacity: 0.75; }
|
| 341 |
.segmented input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 3px; }
|
| 342 |
.segmented input:disabled { cursor: not-allowed; }
|
| 343 |
+
.segmented input:disabled + span { background: var(--hover); color: var(--ink-2); text-decoration: line-through; cursor: not-allowed; }
|
| 344 |
+
/* Padded to the height of the other controls, and pulled back by as much, so nothing moves. */
|
| 345 |
+
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -8px 0; padding: 8px 0; cursor: pointer; }
|
| 346 |
.switch input {
|
| 347 |
position: relative;
|
| 348 |
flex: none;
|
|
|
|
| 364 |
width: 16px;
|
| 365 |
height: 16px;
|
| 366 |
border-radius: 50%;
|
| 367 |
+
background: var(--on-stage);
|
| 368 |
+
box-shadow: var(--shadow-knob);
|
| 369 |
transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
|
| 370 |
}
|
| 371 |
.switch input:checked { background: var(--accent); }
|
| 372 |
.switch input:checked::after { transform: translateX(16px); }
|
| 373 |
.panel[inert] { opacity: 0.5; }
|
| 374 |
footer { max-width: 86ch; margin-top: 26px; color: var(--ink-2); font-size: 0.8125rem; }
|
| 375 |
+
footer p { margin: 0; text-wrap: pretty; }
|
| 376 |
|
| 377 |
@media (max-width: 860px) {
|
| 378 |
.page { max-width: none; padding: 14px 16px 20px; }
|
|
|
|
| 381 |
}
|
| 382 |
@media (prefers-reduced-motion: reduce) {
|
| 383 |
*, *::before, *::after { transition: none !important; }
|
| 384 |
+
.progress.waiting .bar i { width: 100%; opacity: 0.5; transform: none; animation: none; }
|
| 385 |
}
|
| 386 |
</style>
|
| 387 |
</head>
|
|
|
|
| 467 |
|
| 468 |
<div class="group">
|
| 469 |
<label class="switch">Depth in meters <input id="metric" type="checkbox" role="switch"></label>
|
| 470 |
+
<p class="hint">Adds a second model (95 MB) that estimates the camera’s field of view. Without it the depth is relative.</p>
|
| 471 |
</div>
|
| 472 |
</aside>
|
| 473 |
</main>
|
| 474 |
|
| 475 |
<footer>
|
| 476 |
<p>
|
| 477 |
+
Depth Pro 2 is Apple’s model. The files here are unofficial
|
| 478 |
<a href="https://huggingface.co/byoussef/DepthPro2-litert" target="_blank" rel="noopener">LiteRT conversions</a>,
|
| 479 |
not endorsed by Apple, under the
|
| 480 |
<a href="https://huggingface.co/byoussef/DepthPro2-litert/blob/main/LICENSE" target="_blank" rel="noopener">Apple Machine Learning Research Model License</a>:
|
|
|
|
| 539 |
let pointer = null; // the place being probed, as fractions of the picture
|
| 540 |
let standing = ''; // a caution that holds for the whole visit
|
| 541 |
let asked = 0; // the photos asked for so far
|
| 542 |
+
let ready = false; // the visitor pressed Start, and LiteRT.js is up
|
| 543 |
|
| 544 |
// ---- Messages -----------------------------------------------------------------------------
|
| 545 |
|
| 546 |
function progress(text, fraction) {
|
| 547 |
$('progress').hidden = false;
|
| 548 |
$('progress').classList.toggle('waiting', fraction === undefined);
|
| 549 |
+
$('progress').style.setProperty('--done', fraction ?? 0);
|
| 550 |
$('progress-text').textContent = text;
|
| 551 |
// Read out once a phase, not at every megabyte.
|
| 552 |
const phase = text.split(':')[0];
|
|
|
|
| 560 |
document.documentElement.dataset.state = $('notice').hidden ? 'ready' : 'blocked';
|
| 561 |
}
|
| 562 |
|
| 563 |
+
// A message over the picture, with what to do about it; `docked`, a bar that leaves the picture clear.
|
| 564 |
+
function notify(text, action, act, docked = false) {
|
| 565 |
$('notice').hidden = false;
|
| 566 |
+
$('notice').classList.toggle('start', docked);
|
| 567 |
$('notice-text').textContent = text;
|
| 568 |
$('notice-action').hidden = !action;
|
| 569 |
$('notice-action').textContent = action ?? '';
|
|
|
|
| 587 |
|
| 588 |
// ---- The models ---------------------------------------------------------------------------
|
| 589 |
|
| 590 |
+
// The GPU this browser gives WebGPU, asked for without loading anything.
|
| 591 |
+
async function survey() {
|
| 592 |
if (!navigator.gpu) {
|
| 593 |
throw new Error('This browser has no WebGPU, which the models run on. Chrome, Edge and Firefox on a computer have it.');
|
| 594 |
}
|
|
|
|
| 600 |
if (!adapter) {
|
| 601 |
throw new Error('This browser found no GPU for WebGPU. Turn on graphics acceleration in its settings, or try Chrome or Edge on another computer.');
|
| 602 |
}
|
| 603 |
+
return adapter;
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
// Loads LiteRT.js and takes its GPU device; returns whether that computes in float16.
|
| 607 |
+
async function start(adapter) {
|
| 608 |
try {
|
| 609 |
litert = await import(`${LITERT}/+esm`);
|
| 610 |
await litert.loadLiteRt(`${LITERT}/wasm/`);
|
|
|
|
| 1155 |
if (stream && video.srcObject === stream) video.srcObject = null;
|
| 1156 |
if (failure) {
|
| 1157 |
warn(failure.name === 'NotAllowedError'
|
| 1158 |
+
? 'The camera is blocked for this page. Allow it in the browser’s site settings, then press Camera again.'
|
| 1159 |
: 'No camera could be started.');
|
| 1160 |
}
|
| 1161 |
return;
|
|
|
|
| 1177 |
if (transfer && !needed(transfer.file)) transfer.controller.abort();
|
| 1178 |
for (const file of held.keys()) if (!needed(file)) held.delete(file);
|
| 1179 |
render();
|
| 1180 |
+
if (ready) refresh();
|
| 1181 |
+
else if (adapter && !booting && !stopped) invite();
|
| 1182 |
}
|
| 1183 |
|
| 1184 |
for (const [sample, label] of SAMPLES) {
|
|
|
|
| 1284 |
render();
|
| 1285 |
choose(SAMPLES[0][0]);
|
| 1286 |
|
| 1287 |
+
// Nothing to choose: without the shader-f16 feature LiteRT computes in float32.
|
| 1288 |
+
function float32Only() {
|
| 1289 |
+
want.precision = 'fp32';
|
| 1290 |
+
document.querySelector('input[value="fp16"]').disabled = true;
|
| 1291 |
+
document.querySelector('input[value="fp32"]').checked = true;
|
| 1292 |
+
$('precision-hint').textContent = 'This GPU or browser has no float16 shaders, so the models run in float32.';
|
| 1293 |
+
}
|
| 1294 |
+
|
| 1295 |
+
function fail(error) {
|
| 1296 |
+
stopped = true;
|
| 1297 |
+
$('panel').inert = true;
|
| 1298 |
+
notify(error.message, error.reload ? 'Reload the page' : undefined, () => location.reload());
|
| 1299 |
+
}
|
| 1300 |
+
|
| 1301 |
+
// Until the visitor starts, nothing is loaded. The bar over the picture says what starting takes,
|
| 1302 |
+
// for the model and the options chosen so far.
|
| 1303 |
+
let adapter = null;
|
| 1304 |
+
let invited = 0;
|
| 1305 |
+
let booting = false;
|
| 1306 |
+
|
| 1307 |
+
async function invite() {
|
| 1308 |
+
const turn = ++invited;
|
| 1309 |
+
const models = [MODELS[want.model], ...(want.metric ? [MODELS.fov] : [])];
|
| 1310 |
+
const store = await globalThis.caches?.open('depthpro2-litert').catch(() => null);
|
| 1311 |
+
const missing = [];
|
| 1312 |
+
for (const model of models) {
|
| 1313 |
+
if (!await store?.match(FILES + model.file).catch(() => null)) missing.push(model);
|
| 1314 |
}
|
| 1315 |
+
if (turn !== invited || ready || booting || stopped) return;
|
| 1316 |
+
const named = (list) => list.map((model) => model.label).join(' and ').replace(/^./, (first) => first.toUpperCase());
|
| 1317 |
+
const megabytes = Math.round(missing.reduce((sum, model) => sum + model.bytes, 0) / 1e6);
|
| 1318 |
+
const text = missing.length
|
| 1319 |
+
? `${named(missing)} ${missing.length > 1 ? 'are' : 'is'} a ${megabytes} MB download` +
|
| 1320 |
+
(navigator.connection?.saveData ? ', and data saving is on.' : '.')
|
| 1321 |
+
: `${named(models)} ${models.length > 1 ? 'are' : 'is'} stored in this browser: nothing to download.`;
|
| 1322 |
+
notify(text, 'Start', begin, true);
|
| 1323 |
+
}
|
| 1324 |
+
|
| 1325 |
+
async function begin() {
|
| 1326 |
+
if (ready || booting) return;
|
| 1327 |
+
booting = true;
|
| 1328 |
+
$('notice').hidden = true;
|
| 1329 |
+
try {
|
| 1330 |
+
progress('Starting');
|
| 1331 |
+
const float16 = await start(adapter);
|
| 1332 |
+
if (!float16 && want.precision === 'fp16') float32Only();
|
| 1333 |
ready = true;
|
| 1334 |
refresh();
|
| 1335 |
+
} catch (error) {
|
| 1336 |
+
fail(error);
|
| 1337 |
+
}
|
| 1338 |
+
}
|
| 1339 |
+
|
| 1340 |
+
// A browser that finds no GPU takes two seconds to say so: past a moment, the wait shows.
|
| 1341 |
+
const waiting = setTimeout(() => progress('Checking the GPU'), 400);
|
| 1342 |
+
try {
|
| 1343 |
+
adapter = await survey().finally(() => clearTimeout(waiting));
|
| 1344 |
+
if (!adapter.features.has('shader-f16')) float32Only();
|
| 1345 |
+
if (/AppleWebKit/.test(navigator.userAgent) && !/Chrome|Chromium|Edg\//.test(navigator.userAgent)) {
|
| 1346 |
+
standing = 'Safari’s WebGPU gives wrong depth with these models (seen in Safari 27.2). Chrome and Firefox on a computer work.';
|
| 1347 |
+
warn('');
|
| 1348 |
}
|
| 1349 |
+
invite();
|
| 1350 |
} catch (error) {
|
| 1351 |
+
fail(error);
|
|
|
|
|
|
|
| 1352 |
}
|
| 1353 |
</script>
|
| 1354 |
</body>
|