Chase commited on
Commit
3203736
·
1 Parent(s): bf77c3f

Install app: web app manifest, icons from the favicon art, service worker caching the app shell and default scroll (cache names tied to version.json), Install app button in View and Settings, install action, glossary entry, README section

Browse files
CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ Unroll is released as v1.0.0. After it, bump the minor version for a feature pus
5
  with `node tools/stamp_version.mjs minor|patch` before you commit, then add an entry here.
6
  The 0.9.x entries below are the pre-release series that led up to 1.0.0. Version 0.9.0 was reconstructed from the git log.
7
 
 
 
 
 
 
8
  ## 1.0.0 (2026-10-16)
9
 
10
  First release. Unroll is an interactive 3D viewer that virtually unrolls Herculaneum scroll scans with ink layers.
 
5
  with `node tools/stamp_version.mjs minor|patch` before you commit, then add an entry here.
6
  The 0.9.x entries below are the pre-release series that led up to 1.0.0. Version 0.9.0 was reconstructed from the git log.
7
 
8
+ ## 1.1.0 (2026-10-16)
9
+
10
+ - Install app: a web app manifest, icons drawn from the favicon art and a service worker (`sw.js`) that keeps the app shell, three.js and the default scroll for offline use. Cache names carry the version and build sha from `version.json`, and old caches are deleted on update.
11
+ - An **Install app** button in the View panel and in Settings, the `install` action, `ui.install()` and `ui.installState()`, and a glossary entry.
12
+
13
  ## 1.0.0 (2026-10-16)
14
 
15
  First release. Unroll is an interactive 3D viewer that virtually unrolls Herculaneum scroll scans with ink layers.
README.md CHANGED
@@ -37,8 +37,19 @@ Unroll is a released tool: an interactive 3D viewer that virtually unrolls Hercu
37
  - Status: released, v1.0.0.
38
  - Version: 1.0.0 (`version.json`, [CHANGELOG.md](CHANGELOG.md)). The page shows it in the About panel and `window.unroll.version()` returns it.
39
  - Licence: Apache 2.0 for all code (`LICENSE`, `NOTICE`). The scan data in `data/` and `og.jpg` are CC BY-NC 4.0. three.js keeps its own licence (see `NOTICE`).
 
40
  - Listed in the public repository: [ChaseHendrick/Scrolls](https://github.com/ChaseHendrick/Scrolls#released-tools).
41
 
 
 
 
 
 
 
 
 
 
 
42
  ## Scrolls, windings and layers
43
 
44
  The page is data driven. `scrolls/index.json` lists the scrolls and each one has a manifest (`scrolls/PHerc0139/manifest.json`) naming its windings, meshes, ink layers, sources, resolutions, credits and data terms. With more than one scroll a picker appears. `node tools/validate_scroll.mjs` checks the registry and every manifest with the same validator the page uses. See [docs/ADDING_A_SCROLL.md](docs/ADDING_A_SCROLL.md) to add one; `tools/precompute_template.py` is a starting point for building a package.
 
37
  - Status: released, v1.0.0.
38
  - Version: 1.0.0 (`version.json`, [CHANGELOG.md](CHANGELOG.md)). The page shows it in the About panel and `window.unroll.version()` returns it.
39
  - Licence: Apache 2.0 for all code (`LICENSE`, `NOTICE`). The scan data in `data/` and `og.jpg` are CC BY-NC 4.0. three.js keeps its own licence (see `NOTICE`).
40
+ - Install app: open [the app page](https://sharpmeow-unroll.static.hf.space/) and press **Install app** (View panel or Settings), or use the browser's install icon. It works offline after the first visit; see [Install app](#install-app).
41
  - Listed in the public repository: [ChaseHendrick/Scrolls](https://github.com/ChaseHendrick/Scrolls#released-tools).
42
 
43
+ ## Install app
44
+
45
+ Unroll is a progressive web app. Install it and it opens in its own window and works with no network connection.
46
+
47
+ 1. Open [sharpmeow-unroll.static.hf.space](https://sharpmeow-unroll.static.hf.space/) (the Space page embeds the app in a frame, where browsers do not offer installation; the **Install app** button there opens this page for you).
48
+ 2. Press **Install app** in the View panel or in Settings. In Chrome and Edge you can also use the install icon in the address bar. In Safari on iPhone and iPad: Share, then Add to Home Screen. In Safari on macOS: File, then Add to Dock.
49
+ 3. The page, three.js and the default scroll are kept on your device. Other scrolls and close-ups are kept after you view them once.
50
+
51
+ Agents can call `window.unrollView.action('install')` and read `window.unrollView.pwa.state()`. The service worker (`sw.js`) is registered as `sw.js?v=<version>-<sha>` from `version.json`, so each stamped build uses fresh caches (`unroll-shell-<tag>`, `unroll-data-<tag>`, `unroll-runtime-<tag>`) and deletes the old ones.
52
+
53
  ## Scrolls, windings and layers
54
 
55
  The page is data driven. `scrolls/index.json` lists the scrolls and each one has a manifest (`scrolls/PHerc0139/manifest.json`) naming its windings, meshes, ink layers, sources, resolutions, credits and data terms. With more than one scroll a picker appears. `node tools/validate_scroll.mjs` checks the registry and every manifest with the same validator the page uses. See [docs/ADDING_A_SCROLL.md](docs/ADDING_A_SCROLL.md) to add one; `tools/precompute_template.py` is a starting point for building a package.
api.json CHANGED
@@ -1,9 +1,9 @@
1
  {
2
  "name": "Unroll",
3
  "app": {
4
- "version": "1.0.0",
5
  "date": "2026-10-16",
6
- "sha": "08a393b"
7
  },
8
  "apiVersion": "1.0.0",
9
  "docs": {
 
1
  {
2
  "name": "Unroll",
3
  "app": {
4
+ "version": "1.1.0",
5
  "date": "2026-10-16",
6
+ "sha": "bf77c3f"
7
  },
8
  "apiVersion": "1.0.0",
9
  "docs": {
docs/AGENT_API_UI.md CHANGED
@@ -29,6 +29,7 @@ unrollView.action('destroy', true) // toggles take an optional boolean
29
  | `open` | `btnOpen` | | |
30
  | `bench` | `btnBench` | | |
31
  | `picture` | `btnShot` | | |
 
32
  | `skipIntro` | `skipIntro` | Enter or Esc during the intro | |
33
  | `destroy` | `btnTear` | T | optional boolean |
34
  | `tool.tear`, `tool.crush`, `tool.burn`, `tool.water` | `toolTear`, `btnCrush`, `toolBurn`, `toolWater` | X, C, B, W | |
 
29
  | `open` | `btnOpen` | | |
30
  | `bench` | `btnBench` | | |
31
  | `picture` | `btnShot` | | |
32
+ | `install` | `uiInstall` | | |
33
  | `skipIntro` | `skipIntro` | Enter or Esc during the intro | |
34
  | `destroy` | `btnTear` | T | optional boolean |
35
  | `tool.tear`, `tool.crush`, `tool.burn`, `tool.water` | `toolTear`, `btnCrush`, `toolBurn`, `toolWater` | X, C, B, W | |
glossary.json CHANGED
@@ -14,6 +14,7 @@
14
  {"id": "inkdetection", "term": "Ink detection model", "aliases": ["ink model", "ink detection", "model", "neural network", "neural networks"], "def": "A computer program trained on examples where the ink is known. Given the scan of a piece of papyrus, it estimates where ink is, even when the ink is nearly invisible to the eye in X-rays."},
15
  {"id": "ink9um", "term": "ink_9um", "aliases": ["INK_9UM", "ink_9um (9 µm)"], "def": "A public ink detection model trained by the Vesuvius Challenge to work on coarser 9 µm scans. On this page Chase Hendrick ran it on the 9.4 µm scan (9.362 µm voxels) as a comparison layer, shown in cyan."},
16
  {"id": "inklayer", "term": "Ink layer", "aliases": ["layer", "layers", "Published ink"], "def": "A picture laid over the 3D sheet. X-ray shows raw scan brightness; Published ink shows the Vesuvius Challenge ink map on the 2.4 µm scan; ink_9um shows the comparison map from the coarser scan."},
 
17
  {"id": "mesh", "term": "Mesh", "aliases": ["meshes", "OBJ", "PLY"], "def": "A 3D surface made of many small triangles. Each winding here is a mesh that follows the papyrus through the scan."},
18
  {"id": "papyrus", "term": "Papyrus", "aliases": [], "def": "Writing material made from the papyrus plant: strips pressed into sheets, glued end to end and rolled into a scroll."},
19
  {"id": "patch", "term": "Patch (piece)", "aliases": ["patch", "patches", "pieces read", "small square pieces"], "def": "A small square of the flattened papyrus, here 128 by 128 pixels. An ink model looks at one patch at a time and the results are stitched together. Where patches do not overlap enough, faint square seams show."},
 
14
  {"id": "inkdetection", "term": "Ink detection model", "aliases": ["ink model", "ink detection", "model", "neural network", "neural networks"], "def": "A computer program trained on examples where the ink is known. Given the scan of a piece of papyrus, it estimates where ink is, even when the ink is nearly invisible to the eye in X-rays."},
15
  {"id": "ink9um", "term": "ink_9um", "aliases": ["INK_9UM", "ink_9um (9 µm)"], "def": "A public ink detection model trained by the Vesuvius Challenge to work on coarser 9 µm scans. On this page Chase Hendrick ran it on the 9.4 µm scan (9.362 µm voxels) as a comparison layer, shown in cyan."},
16
  {"id": "inklayer", "term": "Ink layer", "aliases": ["layer", "layers", "Published ink"], "def": "A picture laid over the 3D sheet. X-ray shows raw scan brightness; Published ink shows the Vesuvius Challenge ink map on the 2.4 µm scan; ink_9um shows the comparison map from the coarser scan."},
17
+ {"id": "install", "term": "Install app", "aliases": ["PWA", "progressive web app", "offline", "install"], "def": "Adds Unroll to your computer or phone as its own app, with an icon and a window. It keeps the page and the default scroll on your device, so it opens with no network connection. Other scrolls are kept after you view them once. Find it in View or Settings, or call window.unrollView.action('install')."},
18
  {"id": "mesh", "term": "Mesh", "aliases": ["meshes", "OBJ", "PLY"], "def": "A 3D surface made of many small triangles. Each winding here is a mesh that follows the papyrus through the scan."},
19
  {"id": "papyrus", "term": "Papyrus", "aliases": [], "def": "Writing material made from the papyrus plant: strips pressed into sheets, glued end to end and rolled into a scroll."},
20
  {"id": "patch", "term": "Patch (piece)", "aliases": ["patch", "patches", "pieces read", "small square pieces"], "def": "A small square of the flattened papyrus, here 128 by 128 pixels. An ink model looks at one patch at a time and the results are stitched together. Where patches do not overlap enough, faint square seams show."},
icons/apple-touch-icon.png ADDED
icons/icon-192.png ADDED
icons/icon-512.png ADDED
icons/icon.svg ADDED
icons/maskable-512.png ADDED
icons/maskable.svg ADDED
index.html CHANGED
@@ -22,13 +22,19 @@
22
  <meta name="theme-color" content="#060505">
23
  <meta name="color-scheme" content="dark">
24
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23060505'/%3E%3Cpath d='M16 6a10 10 0 1 0 0.01 0M16 10a6 6 0 1 1-0.01 0M16 14a2 2 0 1 0 0.01 0' fill='none' stroke='%23ffb347' stroke-width='1.6'/%3E%3C/svg%3E">
 
 
 
 
 
 
25
  <meta name="twitter:card" content="summary_large_image">
26
  <link rel="preconnect" href="https://fonts.googleapis.com">
27
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
28
  <link href="https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
29
- <link rel="stylesheet" href="style.css?v=20261016h">
30
- <link rel="stylesheet" href="bench.css?v=20261016h">
31
- <link rel="stylesheet" href="ui.css?v=20261016h">
32
  <link rel="alternate" type="application/json+oembed" href="https://sharpmeow-unroll.static.hf.space/oembed.json" title="Unroll">
33
  <script>
34
  // embed mode is decided before the first paint so the compact layout never flashes
@@ -46,18 +52,18 @@ if (!/(^|[#&])s=/.test(location.hash)) ['scrolls/index.json', 'scrolls/PHerc0139
46
  { "imports": {
47
  "three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",
48
  "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/",
49
- "./lib/scrolls.js": "./lib/scrolls.js?v=20261016h",
50
- "./lib/manifest.js": "./lib/manifest.js?v=20261016h",
51
- "./lib/openown.js": "./lib/openown.js?v=20261016h",
52
- "./lib/formats.js": "./lib/formats.js?v=20261016h",
53
- "./lib/example.js": "./lib/example.js?v=20261016h",
54
- "./lib/bench-core.js": "./lib/bench-core.js?v=20261016h",
55
- "./lib/api.js": "./lib/api.js?v=20261016h",
56
- "./lib/apispec.js": "./lib/apispec.js?v=20261016h",
57
- "./lib/embed.js": "./lib/embed.js?v=20261016h",
58
- "./lib/version.js": "./lib/version.js?v=20261016h",
59
- "./tear.js": "./tear.js?v=20261016h",
60
- "./damage.js": "./damage.js?v=20261016h"
61
  } }
62
  </script>
63
  </head>
@@ -244,9 +250,9 @@ if (!/(^|[#&])s=/.test(location.hash)) ['scrolls/index.json', 'scrolls/PHerc0139
244
  </div>
245
  </section>
246
 
247
- <script type="module" src="app.js?v=20261016h"></script>
248
- <script type="module" src="polish.js?v=20261016h"></script>
249
- <script type="module" src="lib/bench.js?v=20261016h"></script>
250
- <script type="module" src="ui.js?v=20261016h"></script>
251
  </body>
252
  </html>
 
22
  <meta name="theme-color" content="#060505">
23
  <meta name="color-scheme" content="dark">
24
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23060505'/%3E%3Cpath d='M16 6a10 10 0 1 0 0.01 0M16 10a6 6 0 1 1-0.01 0M16 14a2 2 0 1 0 0.01 0' fill='none' stroke='%23ffb347' stroke-width='1.6'/%3E%3C/svg%3E">
25
+ <link rel="manifest" href="manifest.webmanifest">
26
+ <link rel="apple-touch-icon" href="icons/apple-touch-icon.png">
27
+ <meta name="apple-mobile-web-app-capable" content="yes">
28
+ <meta name="mobile-web-app-capable" content="yes">
29
+ <meta name="apple-mobile-web-app-title" content="Unroll">
30
+ <meta name="apple-mobile-web-app-status-bar-style" content="black">
31
  <meta name="twitter:card" content="summary_large_image">
32
  <link rel="preconnect" href="https://fonts.googleapis.com">
33
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
34
  <link href="https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
35
+ <link rel="stylesheet" href="style.css?v=20261016i">
36
+ <link rel="stylesheet" href="bench.css?v=20261016i">
37
+ <link rel="stylesheet" href="ui.css?v=20261016i">
38
  <link rel="alternate" type="application/json+oembed" href="https://sharpmeow-unroll.static.hf.space/oembed.json" title="Unroll">
39
  <script>
40
  // embed mode is decided before the first paint so the compact layout never flashes
 
52
  { "imports": {
53
  "three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",
54
  "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/",
55
+ "./lib/scrolls.js": "./lib/scrolls.js?v=20261016i",
56
+ "./lib/manifest.js": "./lib/manifest.js?v=20261016i",
57
+ "./lib/openown.js": "./lib/openown.js?v=20261016i",
58
+ "./lib/formats.js": "./lib/formats.js?v=20261016i",
59
+ "./lib/example.js": "./lib/example.js?v=20261016i",
60
+ "./lib/bench-core.js": "./lib/bench-core.js?v=20261016i",
61
+ "./lib/api.js": "./lib/api.js?v=20261016i",
62
+ "./lib/apispec.js": "./lib/apispec.js?v=20261016i",
63
+ "./lib/embed.js": "./lib/embed.js?v=20261016i",
64
+ "./lib/version.js": "./lib/version.js?v=20261016i",
65
+ "./tear.js": "./tear.js?v=20261016i",
66
+ "./damage.js": "./damage.js?v=20261016i"
67
  } }
68
  </script>
69
  </head>
 
250
  </div>
251
  </section>
252
 
253
+ <script type="module" src="app.js?v=20261016i"></script>
254
+ <script type="module" src="polish.js?v=20261016i"></script>
255
+ <script type="module" src="lib/bench.js?v=20261016i"></script>
256
+ <script type="module" src="ui.js?v=20261016i"></script>
257
  </body>
258
  </html>
manifest.webmanifest ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "./",
3
+ "name": "Unroll",
4
+ "short_name": "Unroll",
5
+ "description": "Unroll a carbonized Herculaneum scroll in 3D: windings traced in X-ray CT, with the ink found by neural networks. Works offline once installed.",
6
+ "start_url": "./",
7
+ "scope": "./",
8
+ "display": "standalone",
9
+ "display_override": ["fullscreen", "standalone"],
10
+ "orientation": "any",
11
+ "background_color": "#060505",
12
+ "theme_color": "#060505",
13
+ "categories": ["education", "science"],
14
+ "icons": [
15
+ { "src": "icons/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" },
16
+ { "src": "icons/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" },
17
+ { "src": "icons/maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" },
18
+ { "src": "icons/icon.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "any" }
19
+ ]
20
+ }
sw.js ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Unroll service worker: caches the app shell and the default scroll so an installed copy works offline.
2
+ // The page registers it as sw.js?v=<version>-<sha> from version.json, so every stamped build gets fresh cache names
3
+ // and the caches of older versions are deleted when the new worker activates.
4
+ const VERSION = new URL(self.location.href).searchParams.get('v') || 'dev';
5
+ const SHELL = `unroll-shell-${VERSION}`;
6
+ const DATA = `unroll-data-${VERSION}`;
7
+ const RUNTIME = `unroll-runtime-${VERSION}`;
8
+ const OURS = [SHELL, DATA, RUNTIME];
9
+
10
+ const SHELL_FILES = [
11
+ './', 'index.html', 'manifest.webmanifest', 'version.json', 'glossary.json',
12
+ 'style.css', 'bench.css', 'ui.css',
13
+ 'app.js', 'polish.js', 'ui.js', 'tear.js', 'damage.js',
14
+ 'lib/scrolls.js', 'lib/manifest.js', 'lib/openown.js', 'lib/formats.js', 'lib/example.js',
15
+ 'lib/bench-core.js', 'lib/bench.js', 'lib/bench-worker.js',
16
+ 'lib/api.js', 'lib/apispec.js', 'lib/embed.js', 'lib/version.js', 'api.json',
17
+ 'icons/icon.svg', 'icons/icon-192.png', 'icons/icon-512.png', 'icons/maskable-512.png', 'icons/apple-touch-icon.png',
18
+ ];
19
+ const THREE = 'https://cdn.jsdelivr.net/npm/three@0.160.0/';
20
+ const CDN_FILES = [
21
+ 'build/three.module.js', 'examples/jsm/controls/OrbitControls.js',
22
+ 'examples/jsm/postprocessing/EffectComposer.js', 'examples/jsm/postprocessing/RenderPass.js',
23
+ 'examples/jsm/postprocessing/UnrealBloomPass.js', 'examples/jsm/postprocessing/OutputPass.js',
24
+ ].map((p) => THREE + p);
25
+ // the default scroll: the same files index.html preloads
26
+ const DATA_FILES = [
27
+ 'scrolls/index.json', 'scrolls/PHerc0139/manifest.json',
28
+ 'data/scroll.json', 'data/scroll.i16p.gz', 'data/atlas_ink.webp', 'data/atlas_ct.webp',
29
+ ];
30
+
31
+ async function addAll(name, urls, opts) {
32
+ const c = await caches.open(name);
33
+ await Promise.all(urls.map(async (u) => {
34
+ try { const r = await fetch(new Request(u, opts)); if (r.ok || r.type === 'opaque') await c.put(u, r); }
35
+ catch (e) { /* one missing file must not block the install; it is fetched on first use instead */ }
36
+ }));
37
+ }
38
+
39
+ self.addEventListener('install', (e) => {
40
+ e.waitUntil((async () => {
41
+ const shell = await caches.open(SHELL);
42
+ await shell.addAll(SHELL_FILES.map((u) => new Request(u, { cache: 'reload' })));
43
+ await addAll(SHELL, CDN_FILES, { mode: 'cors' });
44
+ await addAll(DATA, DATA_FILES, { cache: 'reload' });
45
+ await self.skipWaiting();
46
+ })());
47
+ });
48
+
49
+ self.addEventListener('activate', (e) => {
50
+ e.waitUntil((async () => {
51
+ for (const k of await caches.keys()) if (k.startsWith('unroll-') && !OURS.includes(k)) await caches.delete(k);
52
+ await self.clients.claim();
53
+ })());
54
+ });
55
+
56
+ self.addEventListener('message', (e) => { if (e.data === 'version') e.source?.postMessage({ type: 'unroll-sw', version: VERSION }); });
57
+
58
+ const isData = (url) => /\/(data|scrolls)\//.test(url.pathname);
59
+ async function fromCache(req) {
60
+ // assets are requested as file.js?v=..., so fall back to a match that ignores the query string
61
+ return (await caches.match(req)) || (await caches.match(req, { ignoreSearch: true }));
62
+ }
63
+
64
+ self.addEventListener('fetch', (e) => {
65
+ const req = e.request;
66
+ if (req.method !== 'GET' || req.headers.has('range')) return;
67
+ const url = new URL(req.url);
68
+ const same = url.origin === self.location.origin;
69
+ const cdn = url.href.startsWith(THREE) || url.hostname === 'fonts.googleapis.com' || url.hostname === 'fonts.gstatic.com';
70
+ if (!same && !cdn) return;
71
+
72
+ if (req.mode === 'navigate') {
73
+ // network first so a new release shows up at once; the cached page when offline
74
+ e.respondWith(fetch(req).then((r) => { if (r.ok) caches.open(SHELL).then((c) => c.put('index.html', r.clone())); return r; })
75
+ .catch(async () => (await caches.match('index.html')) || (await caches.match('./')) || Response.error()));
76
+ return;
77
+ }
78
+ if (same && isData(url)) {
79
+ // scroll data never changes under one version: cache first, keep what was viewed for offline use
80
+ e.respondWith(fromCache(req).then((hit) => hit || fetch(req).then((r) => {
81
+ if (r.ok && r.status === 200) { const copy = r.clone(); caches.open(url.pathname.includes('/data/hi/') || !DATA_FILES.some((f) => url.pathname.endsWith(f)) ? RUNTIME : DATA).then((c) => c.put(req, copy)); }
82
+ return r;
83
+ })));
84
+ return;
85
+ }
86
+ // shell, three.js and fonts: stale while revalidate
87
+ e.respondWith(fromCache(req).then((hit) => {
88
+ const net = fetch(req).then((r) => {
89
+ if (r.ok || r.type === 'opaque') { const copy = r.clone(); caches.open(same ? SHELL : RUNTIME).then((c) => c.put(req, copy)); }
90
+ return r;
91
+ }).catch(() => hit || Response.error());
92
+ if (hit) { e.waitUntil(net.catch(() => {})); return hit; }
93
+ return net;
94
+ }));
95
+ });
ui.js CHANGED
@@ -46,7 +46,9 @@ function build() {
46
  const vgrid = document.createElement('div'); vgrid.className = 'ui-grid';
47
  const gear = mk('btnSettings', 'Settings', 'Settings: quality, motion, speed, glow, background, HUD, sensitivity, units (S)', () => toggleSettings());
48
  gear.setAttribute('aria-haspopup', 'dialog'); gear.setAttribute('aria-expanded', 'false'); gear.setAttribute('aria-controls', 'uiSettings');
49
- vgrid.append(gear, reset, full);
 
 
50
  if (tools) { for (const b of [...tools.children]) { if (LABELS[b.id]) for (const n of [...b.childNodes]) if (n.nodeType === 3) n.remove();
51
  if (LABELS[b.id] && !b.querySelector('.ui-lbl')) b.insertAdjacentHTML('beforeend', `<span class="ui-lbl">${LABELS[b.id]}</span>`); b.classList.add('ui-btn'); vgrid.append(b); } tools.remove(); }
52
  gView.append(vgrid);
@@ -163,6 +165,7 @@ const ACTIONS = {
163
  read: { id: 'btnRead', label: 'Read the current winding close up' },
164
  resetView: { id: 'uiReset', label: 'Reset the camera view' },
165
  fullscreen: { id: 'uiFull', label: 'Full screen on or off' },
 
166
  settings: { id: 'btnSettings', label: 'Open or close Settings', run: (on) => toggleSettings(on) },
167
  help: { id: 'btnHelp', label: 'Keyboard shortcuts' },
168
  about: { id: 'btnInfo', label: 'About this page' },
@@ -306,12 +309,15 @@ function buildSettings() {
306
  p.innerHTML = `<div class="sheet-head"><div><div class="mono dim">PREFERENCES</div><h2 id="uiSetTitle">Settings</h2></div>
307
  <button class="icon" id="uiSetClose" data-action="settings.close" aria-label="Close settings">✕</button></div>
308
  <div class="about-body"><form id="uiSetForm" class="ui-form">${Object.entries(SETTINGS).map(([k, d]) => row(k, d)).join('')}</form>
 
309
  <p><button type="button" class="chip" id="uiSetReset" data-action="settings.reset" aria-label="Reset settings to defaults">Reset to defaults</button></p>
310
  <p class="mono dim small">Saved in this browser. URL parameters such as <code>?quality=low&amp;speed=2</code> override them for one visit.</p>
311
  <h3 class="ui-gh">Keyboard shortcuts</h3><dl class="keys mono">${keys ? keys.innerHTML : ''}<dt><kbd>S</kbd></dt><dd>Settings</dd></dl></div>`;
312
  document.body.append(p);
313
  $('uiSetClose').onclick = () => toggleSettings(false);
314
  $('uiSetReset').onclick = () => settingsApi.reset();
 
 
315
  p.addEventListener('input', (e) => { const k = e.target.dataset.setting; if (k) settingsApi.set(k, e.target.type === 'checkbox' ? e.target.checked : e.target.value); });
316
  p.addEventListener('keydown', (e) => { if (e.key === 'Escape') { e.stopPropagation(); toggleSettings(false); } });
317
  addEventListener('keydown', (e) => {
@@ -345,6 +351,7 @@ const uiApi = {
345
  settings: settingsApi,
346
  actions: { list: () => Object.entries(ACTIONS).map(([name, a]) => ({ name, label: a.label, control: a.id || a.sel || null, arg: a.toggle ? 'optional boolean' : name === 'seek' ? 'number 0..1' : name === 'scroll' ? 'scroll id' : name === 'play' ? 'optional boolean' : null })), run: runAction },
347
  action: runAction,
 
348
  state, stateJSON: () => JSON.stringify(state()),
349
  };
350
  // window.unroll.ui: the same controls through the page API (every call returns { ok, ... })
@@ -360,6 +367,8 @@ const uiMethods = {
360
  skipIntro: () => ({ skipped: !!(window.unrollView?.skipIntro?.() ?? false) }),
361
  glossary: (q) => ({ opened: openGlossary(q) }),
362
  glossarySearch: (q) => { const el = $('uiGlossQ'); if (el) { el.value = String(q ?? ''); el.dispatchEvent(new Event('input', { bubbles: true })); } return { terms: glossaryApi.search(q) }; },
 
 
363
  state: () => ({ state: state() }),
364
  };
365
  const uiSpecs = {
@@ -374,6 +383,8 @@ const uiSpecs = {
374
  skipIntro: { summary: 'Skip the opening animation.' },
375
  glossary: { summary: 'Open the glossary under About, optionally at a term.', params: [{ name: 'term', type: 'string', desc: 'Term', required: false }] },
376
  glossarySearch: { summary: 'Filter the glossary by text; returns the matching terms.', params: [{ name: 'query', type: 'string', desc: 'Text' }] },
 
 
377
  state: { summary: 'The control panel state: layer, position, Destroy, panels, settings and actions.' },
378
  };
379
  // data-testid and data-api on every control this file adds, for tests/coverage.mjs
@@ -386,6 +397,8 @@ function tagApi() {
386
  T($('uiSetClose'), 'settings-close', 'ui.settingsPanel(false)');
387
  T($('uiSetReset'), 'settings-reset', 'ui.resetSettings()');
388
  T($('skipIntro'), 'skip-intro', 'ui.skipIntro()');
 
 
389
  T($('uiGlossOpen'), 'glossary-open', 'ui.glossary()');
390
  T(document.querySelector('#uiGloss > summary'), 'glossary-toggle', 'ui.glossary()');
391
  T($('uiGlossQ'), 'glossary-search', 'ui.glossarySearch(query)');
@@ -446,7 +459,7 @@ function ready() {
446
  if ($('btnHelp') && window.unrollView && $('btnTear') && (!$('loader') || $('loader').classList.contains('gone'))) { build(); expose(); skipButton(); benchIntro(); tagApi(); urlActions(); setInterval(expose, 2000); }
447
  else setTimeout(ready, 60);
448
  }
449
- ready();
450
 
451
  // ---------------------------------------------------------------- glossary (glossary.json), under About
452
  let GLOSS = [];
@@ -514,8 +527,60 @@ function glossaryLinks() {
514
  if (hint) { let busy = false; const go = () => { if (busy) return; busy = true; linkTerms(hint); busy = false; }; new MutationObserver(() => queueMicrotask(go)).observe(hint, { childList: true }); go(); }
515
  document.addEventListener('click', (e) => { const a = e.target.closest?.('a.ui-term'); if (a) { e.preventDefault(); openGlossary(a.dataset.term); } });
516
  }
517
- fetch('glossary.json?v=20261016c').then((r) => r.json()).then((j) => {
518
  GLOSS = j.terms.slice().sort((a, b) => a.term.localeCompare(b.term));
519
  const go = () => { if (!$('about') || !document.body.classList.contains('ui2')) return setTimeout(go, 200); buildGlossary(); glossaryLinks(); expose(); };
520
  go();
521
  }).catch((e) => console.warn('glossary', e));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  const vgrid = document.createElement('div'); vgrid.className = 'ui-grid';
47
  const gear = mk('btnSettings', 'Settings', 'Settings: quality, motion, speed, glow, background, HUD, sensitivity, units (S)', () => toggleSettings());
48
  gear.setAttribute('aria-haspopup', 'dialog'); gear.setAttribute('aria-expanded', 'false'); gear.setAttribute('aria-controls', 'uiSettings');
49
+ const inst = mk('uiInstall', 'Install app', 'Install Unroll as an app that works offline', () => runAction('install'));
50
+ inst.hidden = !pwa.canOffer();
51
+ vgrid.append(gear, reset, full, inst);
52
  if (tools) { for (const b of [...tools.children]) { if (LABELS[b.id]) for (const n of [...b.childNodes]) if (n.nodeType === 3) n.remove();
53
  if (LABELS[b.id] && !b.querySelector('.ui-lbl')) b.insertAdjacentHTML('beforeend', `<span class="ui-lbl">${LABELS[b.id]}</span>`); b.classList.add('ui-btn'); vgrid.append(b); } tools.remove(); }
54
  gView.append(vgrid);
 
165
  read: { id: 'btnRead', label: 'Read the current winding close up' },
166
  resetView: { id: 'uiReset', label: 'Reset the camera view' },
167
  fullscreen: { id: 'uiFull', label: 'Full screen on or off' },
168
+ install: { id: 'uiInstall', label: 'Install Unroll as an app (works offline)', run: () => pwa.install() },
169
  settings: { id: 'btnSettings', label: 'Open or close Settings', run: (on) => toggleSettings(on) },
170
  help: { id: 'btnHelp', label: 'Keyboard shortcuts' },
171
  about: { id: 'btnInfo', label: 'About this page' },
 
309
  p.innerHTML = `<div class="sheet-head"><div><div class="mono dim">PREFERENCES</div><h2 id="uiSetTitle">Settings</h2></div>
310
  <button class="icon" id="uiSetClose" data-action="settings.close" aria-label="Close settings">✕</button></div>
311
  <div class="about-body"><form id="uiSetForm" class="ui-form">${Object.entries(SETTINGS).map(([k, d]) => row(k, d)).join('')}</form>
312
+ <h3 class="ui-gh">App</h3><p class="ui-install-row"><button type="button" class="chip" id="uiSetInstall" data-action="install" aria-label="Install Unroll as an app">Install app</button> <span id="uiInstallNote" class="mono dim small" role="status"></span></p>
313
  <p><button type="button" class="chip" id="uiSetReset" data-action="settings.reset" aria-label="Reset settings to defaults">Reset to defaults</button></p>
314
  <p class="mono dim small">Saved in this browser. URL parameters such as <code>?quality=low&amp;speed=2</code> override them for one visit.</p>
315
  <h3 class="ui-gh">Keyboard shortcuts</h3><dl class="keys mono">${keys ? keys.innerHTML : ''}<dt><kbd>S</kbd></dt><dd>Settings</dd></dl></div>`;
316
  document.body.append(p);
317
  $('uiSetClose').onclick = () => toggleSettings(false);
318
  $('uiSetReset').onclick = () => settingsApi.reset();
319
+ $('uiSetInstall').onclick = () => runAction('install');
320
+ pwa.paint();
321
  p.addEventListener('input', (e) => { const k = e.target.dataset.setting; if (k) settingsApi.set(k, e.target.type === 'checkbox' ? e.target.checked : e.target.value); });
322
  p.addEventListener('keydown', (e) => { if (e.key === 'Escape') { e.stopPropagation(); toggleSettings(false); } });
323
  addEventListener('keydown', (e) => {
 
351
  settings: settingsApi,
352
  actions: { list: () => Object.entries(ACTIONS).map(([name, a]) => ({ name, label: a.label, control: a.id || a.sel || null, arg: a.toggle ? 'optional boolean' : name === 'seek' ? 'number 0..1' : name === 'scroll' ? 'scroll id' : name === 'play' ? 'optional boolean' : null })), run: runAction },
353
  action: runAction,
354
+ pwa: { state: () => pwa.state(), install: () => pwa.install(), version: () => pwa.version },
355
  state, stateJSON: () => JSON.stringify(state()),
356
  };
357
  // window.unroll.ui: the same controls through the page API (every call returns { ok, ... })
 
367
  skipIntro: () => ({ skipped: !!(window.unrollView?.skipIntro?.() ?? false) }),
368
  glossary: (q) => ({ opened: openGlossary(q) }),
369
  glossarySearch: (q) => { const el = $('uiGlossQ'); if (el) { el.value = String(q ?? ''); el.dispatchEvent(new Event('input', { bubbles: true })); } return { terms: glossaryApi.search(q) }; },
370
+ install: async () => ({ outcome: await pwa.install(), state: pwa.state() }),
371
+ installState: () => ({ state: pwa.state(), version: pwa.version, offline: !!navigator.serviceWorker?.controller }),
372
  state: () => ({ state: state() }),
373
  };
374
  const uiSpecs = {
 
383
  skipIntro: { summary: 'Skip the opening animation.' },
384
  glossary: { summary: 'Open the glossary under About, optionally at a term.', params: [{ name: 'term', type: 'string', desc: 'Term', required: false }] },
385
  glossarySearch: { summary: 'Filter the glossary by text; returns the matching terms.', params: [{ name: 'query', type: 'string', desc: 'Text' }] },
386
+ install: { summary: 'Install Unroll as an app that works offline (browser prompt, or a new tab when framed); returns the outcome.' },
387
+ installState: { summary: 'Install state (installed, ready, framed, ios, unavailable), the cached version and whether the service worker controls the page.' },
388
  state: { summary: 'The control panel state: layer, position, Destroy, panels, settings and actions.' },
389
  };
390
  // data-testid and data-api on every control this file adds, for tests/coverage.mjs
 
397
  T($('uiSetClose'), 'settings-close', 'ui.settingsPanel(false)');
398
  T($('uiSetReset'), 'settings-reset', 'ui.resetSettings()');
399
  T($('skipIntro'), 'skip-intro', 'ui.skipIntro()');
400
+ T($('uiInstall'), 'install-app', 'ui.install()');
401
+ T($('uiSetInstall'), 'settings-install-app', 'ui.install()');
402
  T($('uiGlossOpen'), 'glossary-open', 'ui.glossary()');
403
  T(document.querySelector('#uiGloss > summary'), 'glossary-toggle', 'ui.glossary()');
404
  T($('uiGlossQ'), 'glossary-search', 'ui.glossarySearch(query)');
 
459
  if ($('btnHelp') && window.unrollView && $('btnTear') && (!$('loader') || $('loader').classList.contains('gone'))) { build(); expose(); skipButton(); benchIntro(); tagApi(); urlActions(); setInterval(expose, 2000); }
460
  else setTimeout(ready, 60);
461
  }
462
+ setTimeout(ready, 0); // after the whole module has run, so pwa (defined below) exists
463
 
464
  // ---------------------------------------------------------------- glossary (glossary.json), under About
465
  let GLOSS = [];
 
527
  if (hint) { let busy = false; const go = () => { if (busy) return; busy = true; linkTerms(hint); busy = false; }; new MutationObserver(() => queueMicrotask(go)).observe(hint, { childList: true }); go(); }
528
  document.addEventListener('click', (e) => { const a = e.target.closest?.('a.ui-term'); if (a) { e.preventDefault(); openGlossary(a.dataset.term); } });
529
  }
530
+ fetch('glossary.json?v=20261016i').then((r) => r.json()).then((j) => {
531
  GLOSS = j.terms.slice().sort((a, b) => a.term.localeCompare(b.term));
532
  const go = () => { if (!$('about') || !document.body.classList.contains('ui2')) return setTimeout(go, 200); buildGlossary(); glossaryLinks(); expose(); };
533
  go();
534
  }).catch((e) => console.warn('glossary', e));
535
+
536
+ // ---------------------------------------------------------------- install as an app (PWA)
537
+ // sw.js is registered with the version and build sha from version.json in its URL, so each build gets its own caches.
538
+ const pwa = {
539
+ prompt: null, version: null, reg: null,
540
+ standalone: () => matchMedia('(display-mode: standalone)').matches || matchMedia('(display-mode: fullscreen)').matches || navigator.standalone === true,
541
+ framed: () => { try { return window.top !== window; } catch { return true; } },
542
+ ios: () => /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1),
543
+ state() {
544
+ if (this.standalone()) return 'installed';
545
+ if (this.prompt) return 'ready';
546
+ if (this.framed()) return 'framed';
547
+ if (this.ios()) return 'ios';
548
+ return 'unavailable';
549
+ },
550
+ canOffer() { return this.state() !== 'installed'; },
551
+ note() {
552
+ return { installed: 'Running as an installed app. The default scroll works offline.',
553
+ ready: 'Adds Unroll to your apps. The default scroll then works offline.',
554
+ framed: 'Opens the app page in a new tab, where your browser can install it.',
555
+ ios: 'In Safari: Share, then Add to Home Screen.',
556
+ unavailable: 'Use your browser menu: Install app or Add to Home Screen.' }[this.state()];
557
+ },
558
+ paint() {
559
+ const st = this.state();
560
+ for (const id of ['uiInstall', 'uiSetInstall']) { const b = $(id); if (!b) continue; b.hidden = st === 'installed' && id === 'uiInstall'; b.disabled = st === 'installed'; b.title = this.note(); }
561
+ const n = $('uiInstallNote'); if (n) n.textContent = this.note() + (this.version ? ` Version ${this.version}.` : '');
562
+ },
563
+ async install() {
564
+ const st = this.state();
565
+ if (st === 'installed') return 'installed';
566
+ if (st === 'ready') {
567
+ const p = this.prompt; this.prompt = null;
568
+ p.prompt(); const r = await p.userChoice.catch(() => ({ outcome: 'dismissed' }));
569
+ this.paint(); return r.outcome;
570
+ }
571
+ if (st === 'framed') { window.open(location.href.split('#')[0], '_blank', 'noopener'); return 'opened'; }
572
+ toggleSettings(true); this.paint(); $('uiInstallNote')?.focus?.();
573
+ return st;
574
+ },
575
+ };
576
+ addEventListener('beforeinstallprompt', (e) => { e.preventDefault(); pwa.prompt = e; pwa.paint(); });
577
+ addEventListener('appinstalled', () => { pwa.prompt = null; pwa.paint(); });
578
+ if ('serviceWorker' in navigator && isSecureContext) {
579
+ addEventListener('load', () => {
580
+ fetch('version.json', { cache: 'no-store' }).then((r) => r.json()).then((v) => {
581
+ pwa.version = v.version; pwa.paint();
582
+ const tag = v.sha ? `${v.version}-${v.sha}` : v.version;
583
+ return navigator.serviceWorker.register(`sw.js?v=${encodeURIComponent(tag)}`, { scope: './' });
584
+ }).then((reg) => { pwa.reg = reg; }).catch((e) => console.warn('service worker', e));
585
+ });
586
+ }
version.json CHANGED
@@ -1,8 +1,8 @@
1
  {
2
  "name": "unroll",
3
- "version": "1.0.0",
4
  "date": "2026-10-16",
5
- "sha": "08a393b",
6
  "license": "Apache-2.0",
7
  "data_license": "CC-BY-NC-4.0",
8
  "shaNote": "Short SHA of the commit this build was stamped on (its parent, since a commit cannot contain its own hash). Run node tools/stamp_version.mjs patch before each push.",
 
1
  {
2
  "name": "unroll",
3
+ "version": "1.1.0",
4
  "date": "2026-10-16",
5
+ "sha": "bf77c3f",
6
  "license": "Apache-2.0",
7
  "data_license": "CC-BY-NC-4.0",
8
  "shaNote": "Short SHA of the commit this build was stamped on (its parent, since a commit cannot contain its own hash). Run node tools/stamp_version.mjs patch before each push.",