@dasl/tile-loader 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +1463 -36
  2. package/dist/at.d.ts +126 -12
  3. package/dist/at.d.ts.map +1 -1
  4. package/dist/at.js +582 -90
  5. package/dist/at.js.map +1 -1
  6. package/dist/car.d.ts +21 -2
  7. package/dist/car.d.ts.map +1 -1
  8. package/dist/car.js +82 -15
  9. package/dist/car.js.map +1 -1
  10. package/dist/content-scheme.d.ts +17 -3
  11. package/dist/content-scheme.d.ts.map +1 -1
  12. package/dist/content-scheme.js +32 -6
  13. package/dist/content-scheme.js.map +1 -1
  14. package/dist/guard.d.ts +342 -0
  15. package/dist/guard.d.ts.map +1 -0
  16. package/dist/guard.js +1544 -0
  17. package/dist/guard.js.map +1 -0
  18. package/dist/index.d.ts +416 -16
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +999 -74
  21. package/dist/index.js.map +1 -1
  22. package/dist/lib/cid.d.ts +25 -0
  23. package/dist/lib/cid.d.ts.map +1 -0
  24. package/dist/lib/cid.js +65 -0
  25. package/dist/lib/cid.js.map +1 -0
  26. package/dist/lib/defaults.d.ts +8 -0
  27. package/dist/lib/defaults.d.ts.map +1 -0
  28. package/dist/lib/defaults.js +14 -0
  29. package/dist/lib/defaults.js.map +1 -0
  30. package/dist/lib/destinations.d.ts +25 -0
  31. package/dist/lib/destinations.d.ts.map +1 -0
  32. package/dist/lib/destinations.js +94 -0
  33. package/dist/lib/destinations.js.map +1 -0
  34. package/dist/lib/drisl.d.ts +10 -0
  35. package/dist/lib/drisl.d.ts.map +1 -0
  36. package/dist/lib/drisl.js +169 -0
  37. package/dist/lib/drisl.js.map +1 -0
  38. package/dist/lib/errors.d.ts +80 -0
  39. package/dist/lib/errors.d.ts.map +1 -0
  40. package/dist/lib/errors.js +44 -0
  41. package/dist/lib/errors.js.map +1 -0
  42. package/dist/lib/fetching.d.ts +24 -0
  43. package/dist/lib/fetching.d.ts.map +1 -0
  44. package/dist/lib/fetching.js +135 -0
  45. package/dist/lib/fetching.js.map +1 -0
  46. package/dist/lib/limits.d.ts +34 -0
  47. package/dist/lib/limits.d.ts.map +1 -0
  48. package/dist/lib/limits.js +33 -0
  49. package/dist/lib/limits.js.map +1 -0
  50. package/dist/lib/pointer.d.ts +83 -0
  51. package/dist/lib/pointer.d.ts.map +1 -0
  52. package/dist/lib/pointer.js +244 -0
  53. package/dist/lib/pointer.js.map +1 -0
  54. package/dist/lib/tab-order.d.ts +16 -0
  55. package/dist/lib/tab-order.d.ts.map +1 -0
  56. package/dist/lib/tab-order.js +66 -0
  57. package/dist/lib/tab-order.js.map +1 -0
  58. package/dist/link.d.ts +110 -13
  59. package/dist/link.d.ts.map +1 -1
  60. package/dist/link.js +336 -43
  61. package/dist/link.js.map +1 -1
  62. package/dist/memory.d.ts +1 -0
  63. package/dist/memory.d.ts.map +1 -1
  64. package/dist/memory.js +5 -0
  65. package/dist/memory.js.map +1 -1
  66. package/dist/mount.d.ts +54 -0
  67. package/dist/mount.d.ts.map +1 -0
  68. package/dist/mount.js +289 -0
  69. package/dist/mount.js.map +1 -0
  70. package/dist/size.d.ts +43 -2
  71. package/dist/size.d.ts.map +1 -1
  72. package/dist/size.js +296 -15
  73. package/dist/size.js.map +1 -1
  74. package/package.json +13 -3
  75. package/src/at.ts +590 -84
  76. package/src/car.ts +79 -16
  77. package/src/content-scheme.ts +38 -7
  78. package/src/guard.ts +1659 -0
  79. package/src/index.ts +1124 -74
  80. package/src/lib/cid.ts +65 -0
  81. package/src/lib/defaults.ts +12 -0
  82. package/src/lib/destinations.ts +79 -0
  83. package/src/lib/drisl.ts +160 -0
  84. package/src/lib/errors.ts +111 -0
  85. package/src/lib/fetching.ts +138 -0
  86. package/src/lib/limits.ts +61 -0
  87. package/src/lib/pointer.ts +290 -0
  88. package/src/lib/tab-order.ts +66 -0
  89. package/src/link.ts +365 -48
  90. package/src/memory.ts +5 -0
  91. package/src/mount.ts +359 -0
  92. package/src/size.ts +304 -16
package/README.md CHANGED
@@ -39,7 +39,8 @@ out of it is a request to your page, which opens nothing unless you say so:
39
39
 
40
40
  ```js
41
41
  import { tileLinks, linkPrompt } from '@dasl/tile-loader/link';
42
- tileLinks(tile, { open: linkPrompt(document.querySelector('#under-the-tile')) });
42
+ const frame = tile.renderContent();
43
+ tileLinks(tile, { frame, open: linkPrompt(document.body) });
43
44
  ```
44
45
 
45
46
  `loadDomain` must point at a running [`@dasl/tile-server`](../tile-server) — that's
@@ -74,16 +75,60 @@ Four cooperating layers, all talking over `postMessage`:
74
75
  - `conf.namedOrigin` (`conf.tileHost` before 3.1, still accepted): a tile origin to run tiles on, by name
75
76
  (`notes.tiles.example`), instead of a fresh random one per load; for a
76
77
  deployment whose tiles share an origin or keep their storage. The tile server
77
- has to recognise the name.
78
+ has to take the name for a tile origin: list it in the `namedOrigins` of
79
+ [`@dasl/tile-server`](../tile-server). A tile on a name it does not take
80
+ does not start: the dock will not frame it. A name that is a tile's CID is
81
+ not one to give here, and throws: see `conf.cidOrigins`.
82
+ - `conf.cidOrigins`: `true` to run each tile on the origin its own content
83
+ names, the CID of its manifest, which is kept: what the tile stores there it
84
+ finds again the next time it runs. `false` when left out. See "Origins named
85
+ by a tile's CID". Not with `namedOrigin` (it throws).
78
86
  - `conf.webrtcGuard`: `'exhaust'` (default) has the shuttle spend Chromium's
79
87
  per-process WebRTC budget before the tile loads (see Security model); `'none'`
80
88
  skips it, for hosts that block WebRTC themselves (an Electron app with the
81
89
  policy switches set, say).
90
+ - `conf.startDeadline`: how long a tile gets to start, in milliseconds, before
91
+ it fires an `error` event with the reason `timeout` (see `Tile`). 15 seconds
92
+ when left out; `0` for no deadline. It only reports: nothing is stopped.
93
+ Time that a tile's frame spends out of the document is not counted, nor
94
+ the time a tile from AT takes to be fetched (see `Tile`).
95
+ - `conf.budget`: what one tile may ask of your page. Every tile's messages,
96
+ and the resolving of every tile's resources, are handled on your page's one
97
+ main thread, so each tile is held to a share of it:
98
+ - `messagesPerSecond` (200) and `messageBurst` (400): the messages a tile
99
+ may send, over time and at once. What is over is dropped. Its requests
100
+ for its own resources are not counted here.
101
+ - `requestsInFlight` (16): how many of a tile's resources are resolved at
102
+ one time; further requests wait their turn, in order. `requestsQueued`
103
+ (2000): how many may wait; a tile that asks for more is refused them.
104
+ - `logLines` (10): how many lines a tile may have logged to your console.
82
105
 
83
- - **`init()`** — wire up the message plumbing. Call once.
106
+ Each is for one tile, for as long as it is in one frame (rendered again, a
107
+ tile starts afresh), and each is a guess at what no ordinary tile comes
108
+ near; `Infinity` lifts a limit. `requestsInFlight` is the one an ordinary
109
+ tile can feel: with a loader that fetches each resource as it is asked
110
+ for, a tile that asks for many at once gets them sixteen at a time.
111
+
112
+ They bound what your page does for a tile at one time, not all that a tile
113
+ can cost it: every message still reaches your page before it is dropped, a
114
+ message is as large as the tile makes it, and requests that your loader
115
+ answers at once are answered as fast as the tile sends them.
116
+
117
+ - **`init()`** — wire up the message plumbing. Once is enough; calling it
118
+ again does nothing.
119
+ - **`destroy()`** — take the plumbing down again. A mothership that listens is
120
+ held by the page, with its loaders and all they hold, for as long as the
121
+ page lives; one that is destroyed is yours to keep or drop. Its tiles get no
122
+ more answers, so close them first. `init()` starts it again. A page with
123
+ one mothership for all its tiles, which is the way to do it, never needs
124
+ this.
84
125
  - **`addLoader(loader)`** / **`removeLoader(loader)`** — register a loader (below).
85
126
  Loaders are tried in order until one returns a tile.
86
- - **`await loadTile(url)`** — returns a `Tile`, or `false` if no loader matched.
127
+ - **`await loadTile(url, options?)`** — returns a `Tile`, or `false` if no loader
128
+ has one. `options.cid` and `options.manifestCid` say which tile you expect.
129
+ Called with options (even `{}`), a tile that could not be loaded is a
130
+ rejection with a `TileLoadError` that says why; called with the URL alone
131
+ it is `false`, and the error is logged. See "Loading a tile".
87
132
  - **`hardenResponse(headers)`** — the headers every tile document ships with: the
88
133
  resource's own plus the policy from `@dasl/tile-lexicon`. Override to add
89
134
  more, never to remove.
@@ -92,44 +137,150 @@ Four cooperating layers, all talking over `postMessage`:
92
137
 
93
138
  - **`await renderCard(options?)`** — a DOM element showing the tile's card
94
139
  (metadata only; safe to render many at once). `options.contentHeight` presets the
95
- height used when the card is clicked to expand.
96
- - **`renderContent(height?)`** — the sandboxed iframe that runs the tile.
140
+ height used when the card is clicked to expand, and `options.frame` is what
141
+ you ask of the frame it then opens, as for `renderContent()`.
142
+ - **`renderContent(height?, options?)`** — the sandboxed iframe that runs the
143
+ tile. `options` say what else the frame is to be: see "The frame a tile
144
+ runs in".
97
145
  - **`await close()`** — you are done with the tile: its runtime tidies up, its
98
146
  frame is removed, and the tile forgets it (a `close` event says when). It can
99
147
  be rendered again afterwards. See "When a tile goes away".
148
+ - **`ephemeral`** — whether the origin the tile runs on is made for one load,
149
+ and wiped when it is closed: `false` on a named origin, and on the origin a
150
+ tile's CID names (see "Origins named by a tile's CID").
151
+ - The **`load`** event — the tile's runtime is up, and its root document is
152
+ being fetched for it. It says that all went well so far, not that anything
153
+ is on screen; and for a tile that cannot start it never comes, which is
154
+ what `error` is for.
155
+ - The **`error`** event (`ev.reason`) — the tile is not starting:
156
+ - `timeout`: the deadline passed (`conf.startDeadline`, counted from when
157
+ the tile's frame is attached, and again from when that frame loads) and
158
+ the tile's root document had still not been handed to its runtime.
159
+ `ev.stage` says what the tile was waiting for: `dock` (nothing was heard
160
+ from its frame at all: the tile server is down, out of reach or not
161
+ answering), `shuttle` (the dock was there: the tile's origin refuses the
162
+ connection or cannot be found, or the runtime on it never ran), `worker`
163
+ (the runtime was there, its service worker had not said it was ready) or
164
+ `content` (it had fired `load`, and its root document had not come). Two
165
+ cases give no way to tell the first two apart, and are `dock`: a tile
166
+ server from before its dock said it was ready, and a tile origin that
167
+ takes the connection and never answers, as nothing is heard from a frame
168
+ before it has loaded. Nothing is stopped: a tile that was only slow goes
169
+ on to load, and fires `load` after its `error`. A busy machine or a slow
170
+ network takes a healthy tile past a short deadline. So does a frame that
171
+ the browser has not begun to load: with `loading="lazy"` on it, a tile
172
+ far below the fold is late before anyone has asked for it.
173
+ - `version`: the tile server runs a generation of the runtime that this
174
+ loader does not speak (`ev.generation` is the one its dock named): the
175
+ loader in the page is too old for the server, or too new. A page that
176
+ was loaded before the server changed is the usual case, and reloading it
177
+ the cure; offer that, rather than do it unasked, since a page whose own
178
+ loader is the one behind is no better for a reload. Nothing is stopped
179
+ for it, but little can be expected.
180
+ - `worker`: the runtime could not start the tile's service worker. Some
181
+ browsers refuse one to a frame of another site once the user has blocked
182
+ cross-site storage (Firefox's "cross-site cookies").
183
+ - `unsupported`: the browser lacks what the runtime needs (service workers
184
+ and `Promise.withResolvers`: Chrome 119, Firefox 121, Safari 17.4).
185
+ - `content`: the tile's root document is not to be had: its loader failed,
186
+ or said there is none. One that its loader never answers is reported by
187
+ the deadline (`timeout`, stage `content`); with no deadline, or a long
188
+ one, the tile's worker gives up on it after a minute, and that is
189
+ reported as `content`.
190
+ - `integrity`: the tile runs on the origin its CID names (`cidOrigins`),
191
+ and the runtime there refused the manifest it was handed: not the one
192
+ that CID names, or not one it reads (a .tile file whose header is not
193
+ written in DRISL's one form). Nothing of the tile is served.
194
+
195
+ For a tile on the origin its CID names, `version` also means that the
196
+ tile server's dock did not say that its runtime holds such an origin to
197
+ its tile (a server from before 4.0, or another that does not): the tile is
198
+ not run there, and nothing of it is handed down.
199
+
200
+ A start (a frame the tile is attached to, each time it loads) fires one
201
+ `error` at most, and none once `close()` is called: closing ends the start,
202
+ however far it got. The frame is left as it is: show something in its
203
+ place, offer to try again (`close()`, then render the tile once more), or
204
+ wait. `worker` and `unsupported` are the runtime's own account, as is a
205
+ root document that was never answered: they take a tile server recent
206
+ enough to give it, and with an older one those starts end in `timeout`.
207
+ That account passes through the tile's origin on its way to your page, and
208
+ a dock passes on what its frame says under any name: what runs on that
209
+ origin can have the start reported as failed, for any of these reasons.
210
+ On an origin made for the one load, nothing of the tile's runs before it
211
+ has started and no other tile is there; tiles that share a named origin
212
+ can do it to one another.
213
+
214
+ A tile from AT has one more `error`, before its runtime is told to load:
215
+ its content could not be had, and `ev.error` is the `TileLoadError` that
216
+ says why (see "Loading a tile"). That one has no `ev.reason`, and the
217
+ others have no `ev.error`, so `ev.error ? ev.error.code : ev.reason` tells
218
+ them apart (in TypeScript, `TileLoadErrorEvent` and `TileErrorEvent`). It
219
+ is that start's one `error`. The deadline does not run while such a tile
220
+ is being fetched: it runs from when all of it is here, and again from
221
+ when its frame loads after that.
100
222
  - The **`stopped`** event (`ev.reason`: `blocked` or `navigated`) — the dock
101
223
  stopped the tile because its runtime tried to leave its frame. The tile is
102
224
  gone; render it again if you want it back.
103
225
  - **`sendProtocol(protocol, kind, payload?)`** and the **`protocol`** event
104
226
  (`ev.protocol`, `ev.kind`, `ev.payload`) — talk to the rendered tile over
105
227
  [tiles protocols](https://dasl.ing/tiles-protocols.html). The loader attaches
106
- no meaning to any protocol.
228
+ no meaning to any protocol. `ev.dock`, when the tile's dock said it, is
229
+ `{ activated }`: whether the user had just pressed or typed inside that tile
230
+ (see "What `activated` means").
107
231
  - For [tp-size](https://dasl.ing/tp-size.html), `@dasl/tile-loader/size` is the
108
232
  context's side of a tile negotiating its size:
109
233
  `tileSize(tile, frame, { limits: { maxHeight: 800 } })` starts the frame at
110
234
  the size the manifest's `sizing` asks for, follows what the tile asks for
111
235
  from then on (its own requests, or its content's size when the manifest
112
236
  declares `fit`), inside your limits and never under the floor, and tells
113
- the tile what it got. `apply: false` is for a host that sizes its own box
114
- (it gets each request in `onRequest`); `width: 'tile'` hands the width over
115
- too. The rules are `resolveSize` in `@dasl/tile-lexicon`.
237
+ the tile what it got. A size is applied only where it moves nothing under
238
+ the user's pointer, and waits until it can be (see "A tile's size moves
239
+ nothing under the pointer"). A host that sizes its own box passes a
240
+ function, `apply: (size) => …`, and is handed each size when it may be
241
+ applied; `apply: false` leaves the box and the moment to the host (it gets
242
+ each request in `onRequest`, and nothing is held for it). `width: 'tile'`
243
+ hands the width over too. The rules are `resolveSize` in
244
+ `@dasl/tile-lexicon`.
116
245
  - For [tp-link](https://dasl.ing/tp-link.html), `@dasl/tile-loader/link` is
117
246
  the context's side of a tile asking for a link to be opened:
118
247
  `tileLinks(tile, { open })` calls `open(url, { activated, id })` for each
119
248
  request (the user followed a link out of the tile, or the tile asked from
120
249
  script) and tells the tile whether you opened it. Without `open`, nothing
121
- opens. The URL is the tile's to choose, so show the user where it leads:
122
- `linkPrompt(container)` is a handler that puts the whole address in
123
- `container` as a link of your own for the user to follow, and refuses
124
- requests made when the user had not touched the page. `openInNewTab(url)`
125
- opens a web link cut off from your page. Only `http:` and `https:` reach
126
- `open` unless you pass `schemes`.
250
+ opens. `activated` says whether the user had just pressed or typed inside
251
+ that tile (see "What `activated` means"); refuse a request without it.
252
+ The URL is the tile's to choose, so show the user where it leads:
253
+ `linkPrompt(container)` is a handler that asks them, in a dialog of your
254
+ page's own that names the destination's host and offers a link to follow
255
+ (see "The link prompt"). Pass the tile's `frame` to `tileLinks` and a prompt
256
+ keeps clear of it. `openInNewTab(url)` opens a web link cut off from your
257
+ page. Only `http:` and `https:` reach `open` unless you pass `schemes`
258
+ (`['https:', 'mailto:', 'myapp:']`), and no address longer than 8192
259
+ characters unless you pass `maxLength`. While `open` is deciding about one
260
+ link (it returned a promise that has not settled), other requests are
261
+ refused; `oneAtATime: false` hands them to `open` as well, as many as the
262
+ tile's message budget lets through (`conf.budget`), so bound what you keep
263
+ waiting. With
264
+ `activated` come the two words it is made of, each by itself:
265
+ `dockActivated` and `pageActivated` (see "What `activated` means").
266
+
267
+ To take links over entirely, give `tileLinks` a handler of your own, or do
268
+ not call `tileLinks` at all and listen to the Tile's `protocol` event: every
269
+ request the tile's runtime sends arrives there, as protocol `link`, kind
270
+ `open`, a payload of `{ url, id }` and the dock's word in `ev.dock`, whatever
271
+ its scheme or length. Answer one with an `id` with
272
+ `tile.sendProtocol('link', 'result', { id, opened })`; the tile keeps the
273
+ first answer, and takes none after 30 seconds.
127
274
  - For [tp-data](https://dasl.ing/tp-data.html), `@dasl/tile-loader/data` names
128
275
  the two kinds: `const data = tileData(tile)`, then `data.send(payload)`,
129
276
  `data.onData(fn)` and `data.onReady(fn)` (each `on…` returns a function that
130
277
  stops it). `Tile.sendData()` and the `data` / `data-ready` events, deprecated
131
278
  in 2.4, are gone in 3.0.
132
279
  - **`url`**, **`manifest`** — the tile's URL and MASL metadata.
280
+ - **`cid`**, **`manifestCid`**, **`pinned`** — which tile it is, by CID, as its
281
+ loader computed it, and whether that was checked against what you expected.
282
+ A tile from AT also has the **`ready`** and **`error`** events. See "Loading
283
+ a tile".
133
284
 
134
285
  ### Loaders
135
286
 
@@ -142,10 +293,951 @@ Each is a subpath export; add the ones you need:
142
293
  | `@dasl/tile-loader/webxdc` — `WebXDCTileLoader` | WebXDC `.xdc` bundles over HTTP | `http(s)://…` |
143
294
  | `@dasl/tile-loader/memory` — `MemoryTileLoader` | in-memory manifests (testing/experiments) | `memory://<id>` |
144
295
 
296
+ `MemoryTileLoader` holds what `addTile(id, manifest)` gives it until
297
+ `removeTile(id)` takes it back.
298
+
145
299
  `@dasl/tile-loader/content-scheme` exports `ContentSchemeTileLoader`, the base class
146
300
  the HTTP-fetching loaders extend. The `TileLoader` and `TilePathLoader` interfaces
147
301
  are exported from the package root for writing your own.
148
302
 
303
+ ## The frame a tile runs in
304
+
305
+ `renderContent(height?, options?)` makes the frame, and `renderCard({ frame })`
306
+ hands the same options to the frame its card opens. Each option is checked,
307
+ and one the loader cannot honour throws (a card is refused when it is made),
308
+ so that you are never left believing in a frame you do not have.
309
+
310
+ | Option | When left out | What it is |
311
+ | --- | --- | --- |
312
+ | `sandbox` | `'allow-scripts allow-same-origin allow-forms'` | the frame's sandbox attribute in full |
313
+ | `credentialless` | `true` on an origin made for the load, `false` on a named origin and on the origin a tile's CID names (`tile.ephemeral`) | whether the frame is credentialless |
314
+ | `tabindex` | none: the frame is in the tab order, unless the focus guard is on it | the frame's tabindex, `-1` to have Tab pass over the tile |
315
+ | `refuse` | `['sync-xhr']` | features of the browser to take from the tile, the list in full |
316
+
317
+ A frame of your own making (`attachIframe()`) gets none of these: give it the
318
+ attributes yourself (`sandbox`, `credentialless`, `tabindex`, `allow`), before
319
+ the frame goes in the document. `allow="sync-xhr 'none'"` is what the loader
320
+ writes when nothing is said of `refuse`.
321
+
322
+ ### `sandbox`
323
+
324
+ The runtime the frame loads has a sandbox of its own (`tileSandbox` in
325
+ `@dasl/tile-lexicon`: `allow-downloads allow-forms allow-modals
326
+ allow-same-origin allow-scripts`), and a frame's sandbox only ever takes
327
+ away: a tile gets what both grant. The frame leaves out dialogs and
328
+ downloads, so a tile in your page:
329
+
330
+ - raises no dialog: `alert()` returns at once, `confirm()` false, `prompt()`
331
+ null, `print()` does nothing, and a page that asks to hold the user when
332
+ they leave (`beforeunload`) is not heard. The same through the runtime's
333
+ page above the tile, which the tile can script;
334
+ - starts no download, by itself or on a press: not from a link with
335
+ `download`, a `blob:` or `data:` address, or a file served as an
336
+ attachment.
337
+
338
+ It keeps what it runs on: scripts, its own origin and so its worker and its
339
+ storage (`localStorage`, IndexedDB, the Cache API), forms it submits to
340
+ itself, the link, size and data protocols, closing and the wipe. And what the
341
+ sandbox has no say in stays as it was: on a press, a tile can still open a
342
+ file picker, play sound and video, and write to the clipboard with
343
+ `execCommand('copy')`; it gets no fullscreen and no reading of the clipboard
344
+ unless your frame's `allow` attribute gives them, and no pointer lock, popups
345
+ or navigation of your page, which the runtime's own sandbox refuses.
346
+
347
+ A page where someone runs one tile on purpose, a workbench, may want dialogs
348
+ and downloads back (Blastile's preview asks for them):
349
+
350
+ ```js
351
+ tile.renderContent(300, { sandbox: 'allow-scripts allow-same-origin allow-forms allow-modals allow-downloads' });
352
+ ```
353
+
354
+ `allow-scripts` and `allow-same-origin` have to be in it: without them the
355
+ runtime's service worker cannot run and no tile loads. `allow-forms` is yours
356
+ to leave out, and then a tile's forms do nothing. A token the runtime does
357
+ not grant would do nothing under it, so the loader refuses it.
358
+
359
+ ### `credentialless`
360
+
361
+ A tile's origin is a subdomain of the loading server's site
362
+ (`<random>.example.site`), and cookies go by site, not by origin: in a plain
363
+ frame a tile reads the cookies that site keeps for its whole domain, and
364
+ sets cookies there. In a credentialless frame Chromium gives everything
365
+ inside cookies and storage of their own, empty to begin with and gone with
366
+ the page: the tile sees none of the site's cookies, what it sets stays in that
367
+ jar, and the browser's password manager keeps out of the frame. Firefox and
368
+ Safari ignore the attribute: there it protects nothing.
369
+
370
+ So the frame is credentialless, unless the tile runs on a named origin
371
+ (below). A host that wants it otherwise says so, either way:
372
+
373
+ ```js
374
+ tile.renderContent(300, { credentialless: false });
375
+ ```
376
+
377
+ `true` or `false`; anything else throws, the empty text of an attribute that
378
+ is there included. What to know of it:
379
+
380
+ - The tiles of one page share that jar, about 11 kB in Chrome, and all of it
381
+ goes to the loading server with every request a tile there makes. Over
382
+ HTTP/2 Chrome sends each cookie as a field of its own, and a server counts
383
+ that as about 19 kB of headers. A loading server that refuses a request of
384
+ that size, or a front before it that does (Node reads 16 kB by default,
385
+ Caddy 16 KiB from 2.11.6 on, some fronts 8 kB to a line), leaves one tile
386
+ able to keep the next ones on its page from loading, until the page is
387
+ loaded again. `@dasl/tile-server`'s command reads 1 MiB; its README says
388
+ what a front has to take.
389
+ - A tile on a named origin (`namedOrigin`), or on the origin its CID names
390
+ (`cidOrigins`), is there to find its storage again, and a credentialless
391
+ frame loses it with every page: its frame is a plain one unless you ask.
392
+ In Chrome a plain frame has the cookies of the loading server's domain,
393
+ which Chrome does not keep apart by site unless its user blocks third-party
394
+ cookies: see "Origins named by a tile's CID".
395
+
396
+ Closing a tile in such a frame wipes its origin from a credentialless frame
397
+ too, since that is where what it stored is.
398
+
399
+ ### `tabindex`
400
+
401
+ Whoever has the focus in a tile types into the tile. Every key goes to it,
402
+ Tab and Escape with the rest, and your page hears none of them, so a tile
403
+ that will not let Tab go keeps the keyboard; and each key pressed there
404
+ counts as its user having acted in the tile. On a page with more on it than
405
+ tiles, someone tabbing down it should end up in neither position: `-1` has
406
+ the Tab key pass over the tile. A click in the tile gives it the keyboard as
407
+ before.
408
+
409
+ Then nobody reaches the tile with the keyboard alone unless you give them the
410
+ means, so do: a control of your own that puts the keyboard in the frame
411
+ through its window (`frame.contentWindow.focus()`).
412
+
413
+ The focus guard (see "The keyboard" below) does all of this itself: a frame
414
+ it guards is out of the tab order whatever its `tabindex` says, and in its
415
+ place in the tab order the guard puts a stop of its own, which is the way
416
+ in. Where you would rather have your own, tell the guard (`tabOrder:
417
+ 'out'`) and let it put the keyboard in, or it takes that focus for a
418
+ script's and gives it back:
419
+
420
+ ```js
421
+ import { guardFocus } from '@dasl/tile-loader/guard';
422
+
423
+ const frame = tile.renderContent(300);
424
+ const guard = guardFocus(tile, frame, { tabOrder: 'out' });
425
+ const enter = document.createElement('button');
426
+ enter.textContent = `Use the keyboard in ${tile.manifest.name || 'this tile'}`;
427
+ enter.addEventListener('click', () => guard.focus());
428
+ document.body.append(enter, frame);
429
+ ```
430
+
431
+ After that the next Tab goes to the first thing in the tile that takes it.
432
+ Tab past the last, or Shift+Tab before the first, comes back to your page if
433
+ the tile lets it: from inside, only the tile and the browser's own shortcuts
434
+ let the keyboard out. `engage()` has a way in of its own, its layer.
435
+
436
+ With the guard, a user who goes in with a press (a click or a tap on your
437
+ control) has the keyboard put on into the tile itself by its dock, so that
438
+ what they type next reaches the tile at once: its document, and a field of
439
+ it once they press or Tab into one, or the tile puts the keyboard there. A
440
+ Tab from there goes on from wherever they were in the tile last, if they
441
+ had been in it. One who goes in from the keyboard (Enter or Space on your
442
+ control) has it left where the next Tab goes to the first thing in the
443
+ tile, and what they type before that Tab reaches nothing. Call
444
+ `guard.focus()` from your control's own handler: called from anywhere else
445
+ (after an `await`, say), the guard cannot tell a press from a key, and
446
+ takes it for a key.
447
+
448
+ From the keyboard, that works in Chrome alone. In answer to a key, Firefox
449
+ and WebKit (Safari, and every WebView on iOS) do not let a page put the
450
+ keyboard into a frame: Enter or Space on your control leaves the keyboard on
451
+ your control, and a user with only a keyboard has no way in. (Measured in
452
+ Firefox 160, headless, where a press does go in, and in the WebKit of macOS
453
+ 15.7, in a WKWebView kept off screen, which was sent keys and no press.) The
454
+ guard's own stop does not go in that way, and works in all three: keep it
455
+ (the default) unless you need a way in of your own.
456
+
457
+ This is about the Tab key and no more: a tile's script can still put the
458
+ focus in the tile itself, with no click and no key, and `tabindex` does
459
+ nothing about that (the focus guard does). The option takes a whole number
460
+ from -32767 to 32767; anything else throws, since a browser would read it as
461
+ no tabindex at all.
462
+
463
+ ### `refuse`
464
+
465
+ A browser hands some features to every frame unasked. In Chrome 157 a tile
466
+ has fifteen of them unless they are refused: picture-in-picture and the
467
+ gamepad among them, so that it can put a window of its own over whatever its
468
+ user is doing, or read a game controller, and synchronous requests, unload
469
+ handlers and the client hints that say which browser and device this is.
470
+ Refuse a feature, and it is refused to everything in the frame, the frames
471
+ the tile makes included, whatever those ask for.
472
+
473
+ `refuse` is the list in full, as `sandbox` is the attribute in full. When
474
+ nothing is said it is `['sync-xhr']`: a synchronous request holds up the
475
+ thread the tile shares with its runtime, and never brings a tile its own
476
+ files (Chrome and Safari do not hand it to the tile's worker, so the
477
+ loading server answers it with a 404; Firefox hands it to a worker whose
478
+ answer has to come through the very thread it holds, so it fails a minute
479
+ later). What a tile loses is a synchronous request for a `blob:` or `data:`
480
+ address; and one for its own files, which had the loading server's 404, now
481
+ throws a `NetworkError` at once, which stops a script that does not catch
482
+ it. A list of your own takes the place of that one, so name `sync-xhr`
483
+ in it to keep it refused; `[]` refuses nothing, and the frame then has no
484
+ `allow` attribute:
485
+
486
+ ```js
487
+ import { REFUSABLE } from '@dasl/tile-loader';
488
+
489
+ tile.renderContent(300, { refuse: ['sync-xhr', 'picture-in-picture', 'gamepad'] });
490
+ tile.renderContent(300, { refuse: REFUSABLE }); // everything the loader knows
491
+ tile.renderContent(300, { refuse: [] }); // nothing: synchronous requests given back
492
+ ```
493
+
494
+ Each name goes into the frame's `allow` attribute as `'none'`. It only takes
495
+ away: nothing given here grants a feature. The names the loader knows are
496
+ those of `REFUSABLE` (from `refusableFeatures` in `@dasl/tile-lexicon`), and
497
+ a name it does not know throws. An `allow` attribute you set on the frame
498
+ yourself replaces the one the loader wrote, its default with it.
499
+
500
+ A browser goes by the names it knows and passes over the others, so the same
501
+ list takes away less outside Chrome. What each name does, as of 22 November
502
+ 2026: "refused" where that was seen in Chrome 157, Firefox 160 or the WebKit
503
+ of Safari 26.4 (in a WKWebView on macOS 15.7), as said below the table;
504
+ "refused (source)" where the browser's own code says so and nothing was run;
505
+ "not refused" where the browser has the feature and no policy for it, so
506
+ that the name does nothing there; "none" where the browser has no such
507
+ feature. Below "unasked" are the features a frame has in Chrome without
508
+ being given them; in Chrome a tile has the others only where your own
509
+ frame's `allow` attribute gives them. Firefox 160 gives a frame four of them
510
+ unasked: `aria-notify`, `gamepad`, `picture-in-picture` and
511
+ `storage-access`.
512
+
513
+ | Name | What it is | Chrome | Firefox | Safari |
514
+ | --- | --- | --- | --- | --- |
515
+ | `accelerometer` | motion sensors | refused | none | refused (source) |
516
+ | `gyroscope` | | refused | none | refused (source) |
517
+ | `magnetometer` | | refused | none | refused (source) |
518
+ | `autoplay` | sound and video without a press | refused | not refused | not refused |
519
+ | `camera` | | refused | refused | refused (source) |
520
+ | `microphone` | | refused | refused | refused (source) |
521
+ | `clipboard-read` | reading the clipboard | refused | not refused | not refused |
522
+ | `clipboard-write` | writing to it | refused | not refused | not refused |
523
+ | `display-capture` | sharing the screen | refused | refused | refused (source) |
524
+ | `encrypted-media` | DRM | refused | not refused | not refused |
525
+ | `fullscreen` | | refused | refused | refused (source) |
526
+ | `geolocation` | | refused | refused | refused (source) |
527
+ | `midi` | MIDI devices | refused | not refused | none |
528
+ | `screen-wake-lock` | keeping the screen on | refused | refused | refused (source) |
529
+ | `web-share` | the system's share sheet | refused | refused | refused (source) |
530
+ | `xr-spatial-tracking` | WebXR | refused | none | refused (source), where Safari has it |
531
+ | **unasked:** | | | | |
532
+ | `gamepad` | game controllers | refused | refused | refused |
533
+ | `picture-in-picture` | a video in a window of its own | refused | refused | not refused |
534
+ | `sync-xhr` | synchronous requests; refused when nothing is said | refused | not refused | refused |
535
+ | `media-playback-while-not-visible` | playing on while out of view | refused | not refused | not refused |
536
+ | `unload` | unload handlers | refused | not refused | not refused |
537
+ | `storage-access` | asking for the site's cookies (the sandbox refuses it anyway) | refused | refused | refused (source) |
538
+ | `aria-notify` | announcements to a screen reader | refused | refused | none |
539
+ | `deferred-fetch-minimal` | requests put off until the page has gone (`fetchLater`) | refused | none | none |
540
+ | `private-state-token-issuance` | private state tokens | refused | none | none |
541
+ | `private-state-token-redemption` | | refused | none | none |
542
+ | `ch-ua` | client hints: which browser, in a request's headers | refused | none | none |
543
+ | `ch-ua-mobile` | whether it is a phone | refused | none | none |
544
+ | `ch-ua-platform` | which system | refused | none | none |
545
+ | `ch-ua-high-entropy-values` | the details: versions, model, architecture | refused | none | none |
546
+ | `ch-save-data` | whether the user saves data | refused | none | none |
547
+
548
+ Seen: every name refused in Chrome (with `refuse: REFUSABLE`,
549
+ `document.featurePolicy.allowedFeatures()` is empty in the tile, in a frame
550
+ it makes asking for every feature with `*`, and in its runtime's page above
551
+ it); the same in Firefox, which shows a page what it allows once a
552
+ preference says so (`dom.security.permissionsPolicy.webidl.enabled`, which
553
+ changes nothing it enforces): the names it knows are those it refuses in the
554
+ table, and with `refuse: REFUSABLE` its `allowedFeatures()` is empty in the
555
+ same three places, `navigator.getGamepads()` throws and
556
+ `document.pictureInPictureEnabled` is false, as `picture-in-picture` alone
557
+ makes it; a synchronous request there still holds the tile for a minute. In
558
+ Safari's WebKit the gamepad and synchronous requests are refused,
559
+ `document.pictureInPictureEnabled` stays true, and there is no `ariaNotify`
560
+ and no `fetchLater` yet. Refusing the client hints leaves
561
+ `navigator.userAgentData.brands` as it was, which the runtime reads to tell
562
+ Chromium, and `getHighEntropyValues()` then gives the brands, the platform
563
+ and whether it is a phone, and nothing more. Read in the browsers' code:
564
+ Chromium's `permissions_policy_features.json5` and WebKit's
565
+ `Source/WebCore/html/PermissionsPolicy.cpp`; and MDN's pages on
566
+ `Permissions-Policy`, with its compatibility data. Neither Firefox nor Safari
567
+ reads a `Permissions-Policy` header (both were seen to pass over one; Firefox
568
+ bug 1531012): the `allow` attribute is the one setting that every engine
569
+ takes. Browsers move, and Firefox only lately came to picture-in-picture:
570
+ check again before you count on a row.
571
+
572
+ #### What `refuse` cannot take away
573
+
574
+ Outside Chrome, some of what a tile has unasked no setting of a page
575
+ reaches. A host that cannot live with it there has no way but not to show
576
+ tiles in that browser, or, in an app, the WebView's own settings:
577
+
578
+ - **Safari, and every WebView on iOS:** picture-in-picture (a tile can pop a
579
+ video of its own out over everything, on a press), unload handlers, sound
580
+ and video by the browser's own rules, encrypted media, and the clipboard
581
+ on a press: writing to it, and reading it once the user picks the
582
+ browser's "Paste".
583
+ - **Firefox:** synchronous requests (one holds the tile's thread for a
584
+ minute, and then fails), unload handlers, sound and video by the browser's
585
+ own rules, encrypted media, and the clipboard on a press, as in Safari.
586
+ - **Every browser:** copying on a press with `execCommand('copy')`, and what
587
+ a live region of the tile's own announces to a screen reader, which no
588
+ policy governs.
589
+ - **In an app's WebView:** on iOS, `allowsPictureInPictureMediaPlayback =
590
+ false` and `mediaTypesRequiringUserActionForPlayback = .all` on the
591
+ `WKWebViewConfiguration`; on Android, deny in
592
+ `WebChromeClient.onPermissionRequest()` and
593
+ `onGeolocationPermissionsShowPrompt()`, and
594
+ `setMediaPlaybackRequiresUserGesture(true)`.
595
+
596
+ ## Keeping a tile from steering the user
597
+
598
+ A tile cannot reach your page, but it runs in the middle of it, and the person
599
+ using your page is using the tile too. What a running tile can do to them, and
600
+ what this package does about it:
601
+
602
+ ### What `activated` means
603
+
604
+ A link request says whether the user asked for it: `activated`. Your page's own
605
+ `navigator.userActivation` cannot tell you that. It is true for a few seconds
606
+ after a press or a key anywhere on the page, so a tile that keeps asking would
607
+ be "activated" by a click on one of your own buttons, or in another tile.
608
+
609
+ The tile's dock knows better. A press or a key activates the frame it lands in
610
+ and the frames above it; the dock is a frame of the loading server's between
611
+ your page and the tile, and the tile cannot script it. Its activation is the
612
+ user having acted inside that tile. (A browser may also count a press for
613
+ every frame of the pressed page's origin, and every dock has the loading
614
+ server's: the dock sees a press that lands on a page of its own, as on a tile
615
+ that is still loading, and for as long as that one counts no dock says the
616
+ user acted. Do not serve the page that shows tiles from the loading server's
617
+ own origin: a press on it would be such a press, and no dock could see it.)
618
+ The dock says so on every protocol message it passes up (`ev.dock.activated`
619
+ on the `protocol` event), and `tileLinks` gives you `activated` only when your
620
+ page and the dock both say yes. It gives you each of the two as well, for a
621
+ rule of your own: `dockActivated`, left out where the dock said nothing, and
622
+ `pageActivated`, left out where the browser has no `navigator.userActivation`
623
+ (some WebViews, where `activated` is then always false; the dock is in the
624
+ same browser and cannot tell there either, so its word is then always false).
625
+
626
+ It still does not mean "the user asked for this link": any press or key inside
627
+ the tile makes its requests activated for a few seconds, and the tile picks
628
+ which address to send. Show the user where a link goes, and let them decide.
629
+
630
+ The focus guard asks the dock something more of the keyboard (see "The
631
+ keyboard"); `activated` is the same for that.
632
+
633
+ A loading server from before its dock said this (`@dasl/tile-server` 3.1 and
634
+ earlier) leaves `activated` with the meaning it had: the user did something on
635
+ the page, somewhere. Nothing that arrives in the dock's name is ever used to
636
+ grant what your page's own activation would not. `dockActivated` is that word
637
+ as it arrived: from such a loading server it is whatever the tile put there,
638
+ so read it to refuse, never by itself to grant.
639
+
640
+ ### A tile's size moves nothing under the pointer
641
+
642
+ A frame that changes height moves everything below it, and a tile picks the
643
+ moment it asks: between the two clicks of a double-click, say. What was under
644
+ the pointer is then somewhere else, and a control of yours, or the tile, is
645
+ there instead. So `tileSize` decides when a size is applied as well as what it
646
+ is:
647
+
648
+ - Never as the request arrives, but two frames on, once the page has heard
649
+ where the pointer is.
650
+ - With a mouse, a change waits while the pointer is on what it would move: the
651
+ page at or below the frame's bottom edge and, for a shrink, anywhere in the
652
+ tile. It is made as soon as the pointer is somewhere else, or out of the
653
+ window. Meanwhile the tile is told the size it still has, and it is told the
654
+ new one when it gets it.
655
+ - A growth with the pointer in the tile goes ahead, and the strip the tile
656
+ gains takes no press for a moment.
657
+ - A finger gives no warning, and neither does a mouse the page has not seen
658
+ yet: the change is made, and what it moved takes no press for a moment. So
659
+ it is on a screen that takes fingers as well as a mouse, wherever the mouse
660
+ is: a finger that taps in the tile is never seen.
661
+ - A tile gets one change per quarter second at most, eight in a row, and one
662
+ more every three seconds.
663
+
664
+ What it costs a tile that means no harm: one that fits its content does not
665
+ shrink while the mouse is in it, and does not follow its content while the
666
+ mouse rests on the page below it. It scrolls inside its frame meanwhile, and
667
+ catches up when the mouse moves on.
668
+
669
+ The numbers are first guesses: `SIZE_GATE` has them, and `gate: { … }`
670
+ overrides any. Everything below the frame is taken to move, the whole width of
671
+ the window; if your layout has columns, pass the one the frame is in as
672
+ `column`, and a pointer beside it holds nothing up. A change of width (`width:
673
+ 'tile'`) is treated as moving the frame's whole row.
674
+
675
+ If you size the frame's box yourself, do it when you are told to:
676
+
677
+ ```js
678
+ tileSize(tile, frame, { limits, apply: (size) => setBoxHeight(size.height) });
679
+ ```
680
+
681
+ `apply: false` with `onRequest` works as it did, and is as open as it was: the
682
+ moment is yours, and nothing is held for you.
683
+
684
+ What keeps presses off a piece of the page is a block of your page's own,
685
+ with the class `tile-shield`, all but invisible. Leave it its background: a
686
+ block that paints nothing does not take a press over a frame.
687
+
688
+ ### The link prompt
689
+
690
+ A tile chooses the address it asks for, the moment it asks, and where its user
691
+ is pressing at that moment. A prompt that comes up under a press that was
692
+ already on its way has asked nobody anything, and one that shows an address as
693
+ it was written can be made to read like somewhere else. `linkPrompt` is a
694
+ handler for `tileLinks` that holds against both:
695
+
696
+ - It says where. The host's name stands alone on a line, large. A user name
697
+ in the address (`https://your.site@elsewhere.example/`), plain http and a
698
+ name in its encoded form are called out, and the whole address is there to
699
+ read, cut in the middle if it is very long.
700
+ - One at a time, for the whole page. While a prompt is showing, a request from
701
+ any tile is refused: nothing replaces what the user is reading. And for two
702
+ seconds after the user has dismissed one, nothing comes up in its place: a
703
+ tile that is told no and asks again at once, for an address that puts the
704
+ link where the button that dismisses was, gets nothing. A request that is
705
+ not `activated` is refused outright.
706
+ - It is a modal dialog, on top of the page. Nothing a tile does to its size or
707
+ to the page's scroll moves it.
708
+ - The link in it does nothing for 0.8 seconds, and any press or key in that
709
+ time starts the wait again. The second click of a double click opens
710
+ nothing, and neither does the tenth of a run. A press counts from when it
711
+ was made, not from when a page that was busy came to hear of it. Focus
712
+ starts on the button that dismisses, which works at once, as Escape does. A
713
+ press beside the dialog does nothing.
714
+ - The link also waits until the pointer has really moved, or the keyboard
715
+ has been taken to it (with Tab, or by a screen reader). A pointer that
716
+ rests where the link came up opens nothing, however long the tile has its
717
+ user wait.
718
+ - It keeps clear of the tile that asked, if you named its frame
719
+ (`tileLinks(tile, { frame, open })`): the dialog goes above or below the
720
+ frame, where there is room, and in the middle where there is none. That
721
+ keeps it off the tile, not off the pointer: a tile can move itself, or
722
+ scroll your page, between the press and the prompt, which is why the link
723
+ waits for the pointer wherever the dialog is.
724
+ - When a press has dismissed it, the place where it was takes no press for a
725
+ moment. The second click of a double click on the button does not go
726
+ through to your page, where a tile may have put something of yours while
727
+ the dialog was up.
728
+
729
+ The dialog element is put in the `container` you give, so it is styled with
730
+ that part of your page and goes with it; it is shown on top of the page
731
+ wherever the container is. Its parts have class names to style them by
732
+ (`tile-link-dialog`, `tile-link-host`, `tile-link-note`, `tile-link-url`,
733
+ `tile-link-open`, `tile-link-dismiss`), its words are options (`label`,
734
+ `dismiss`, `open`, `notes`), and so are its numbers (`armMs`, `travel`,
735
+ `restMs`, `maxShown`; `LINK_PROMPT` has the defaults, which are first
736
+ guesses). With a public suffix list of your own,
737
+ `registrableDomain: (host) => …` lets it set the site apart from its
738
+ subdomains.
739
+
740
+ What it does not do: on a touch screen, where no pointer rests anywhere, only
741
+ the waits stand between a tap and the link: a second tap where the link came
742
+ up, later than 0.8 seconds, opens it. With the keyboard, Tab, a pause and
743
+ Enter open it, as they are meant to; so they do for someone who was tabbing
744
+ through a form in the tile when the prompt came up. Someone who presses by
745
+ other means than a pointer they move, the keyboard or a finger (a switch,
746
+ their voice) may find the link does not answer, and has the keyboard's way.
747
+ And the destination is still the tile's to choose: the prompt makes sure it
748
+ is read.
749
+
750
+ A dialog of your own, in place of this one, needs the same things when a
751
+ request comes from a tile: a wait before its confirming button works, started
752
+ again by anything pressed too soon; a confirming button that a pointer which
753
+ has not moved cannot press; one request at a time, and none right after a
754
+ refusal; and nothing of yours under it that takes the second click of a
755
+ double click on its buttons.
756
+
757
+ ### The keyboard
758
+
759
+ A tile's script can call `focus()` on a field of its own with nobody having
760
+ touched anything. Where that takes the keyboard, what the user types next,
761
+ meaning it for a field of yours, goes to the tile; in Firefox nothing in a
762
+ frame's sandbox governs that. Chrome, from 158 on, refuses a sandboxed frame
763
+ `focus-without-user-activation` unless its `allow` attribute names it. A
764
+ tile's document is in a frame of the shuttle's, in one of the dock's, in the
765
+ loader's, all of them sandboxed, and none of them names it: there such a
766
+ `focus()` leaves the keyboard where it was, and naming it on the loader's
767
+ frame alone changes nothing (measured in Chrome 158, headless). In WebKit a
768
+ frame of another origin did not take the keyboard that way either, sandboxed
769
+ or not (measured in a WKWebView on macOS 15.7, not in Safari). If your page
770
+ has fields of its own, turn the guard on when you render the tile:
771
+
772
+ ```js
773
+ import { guardFocus } from '@dasl/tile-loader/guard';
774
+ const frame = tile.renderContent();
775
+ guardFocus(tile, frame);
776
+ ```
777
+
778
+ A guarded tile is out of the tab order: someone tabbing down your page
779
+ passes over its frame, and never ends up typing into the tile, or handing it
780
+ their keys, by chance. In the frame's place in the tab order the guard puts
781
+ a stop of its own, right before the frame: a button of your page's (the
782
+ class `tile-enter`, `ENTER_CLASS`) that takes no room and cannot be seen
783
+ until it has the keyboard. Then it lies over the tile, with a ring round it
784
+ as the guard's layer has (below), and says "Use the keyboard in" and the
785
+ tile's name (its first 60 characters), or "this tile" for a tile with none,
786
+ which is also its name for assistive technology; `enterLabel` gives your
787
+ own words. It takes no press while it shows: a press or a tap where it lies
788
+ goes into the tile, to what is under it, as it would with no stop.
789
+
790
+ Enter or Space on the stop lets the frame into the tab order for the user's
791
+ next Tab, and the stop then says "Press Tab to go in" (`tabLabel` gives your
792
+ own words). That Tab goes from the stop into the tile, as a Tab into any
793
+ frame in the tab order does, and your page sees it. So does a press that the
794
+ browser aims at the stop itself, as it does for a screen reader, which also
795
+ puts the keyboard on the stop where it was not. It is the same in Chrome,
796
+ Firefox and WebKit, which is why the stop does not put the keyboard in the
797
+ frame itself (see "`tabindex`" above). The frame is out of
798
+ the tab order again as soon as the keyboard has left the stop, into the
799
+ tile or anywhere else, ten seconds after the stop was pressed, or once
800
+ another layer lies over the tile (below), and the stop then says what it
801
+ said before. While it
802
+ is in, only a Tab forward from the stop counts as the user going into it,
803
+ and once that Tab has taken them in it counts for nothing more: should the
804
+ keyboard go on into another frame and the tile take it back, that is judged
805
+ afresh. So it is where the keyboard went anywhere else before the tile had
806
+ it (another tile taking it on the way, say).
807
+
808
+ While another layer lies over the tile (the guard's own after a refusal, or
809
+ `engage`'s over a tile that is not picked), that layer is where Tab stops,
810
+ and the guard's stop is out of the tab order. The stop goes into the shadow
811
+ tree the frame is in, is put right before the frame once the frame is in
812
+ your page (and again if anything comes between them), leaves your page with
813
+ the frame and comes back with it, and goes when the guard stops. Its look is
814
+ the layer's, a sheet whose rules weigh nothing: your rules for `.tile-enter`
815
+ and `.tile-pick-label` win.
816
+
817
+ What that costs keyboard users: two keys more to start typing in a tile,
818
+ Enter on the stop and then Tab, where Tab alone took them in before, and
819
+ what they type before that Tab reaches nothing. In Chrome and Firefox that
820
+ Tab lands on the first field of the tile. In WebKit it lands on the tile's
821
+ page, where what is typed reaches the tile but no field of it, and the next
822
+ Tab goes to the first field. Tab out of a tile's last field goes on to the
823
+ next tile's stop, or to what comes after the tile on your page. Shift+Tab
824
+ out of a tile's first field lands on that tile's own stop, which shows over
825
+ the tile again: one more Shift+Tab goes on back, and Enter and Tab there go
826
+ back in. (Measured in Chrome 157 and Firefox 160, headless, and in the
827
+ WebKit of macOS 15.7 in a WKWebView kept off screen and sent keys: the same
828
+ keys in all three.) Nothing typed on the way in lands in a page of the
829
+ dock's, so a press into another guarded tile just after is judged as any
830
+ other: in Chrome, one 0.8 s after was the user's. After your own way in from
831
+ the keyboard it is refused for a few seconds (see below).
832
+
833
+ What it costs mouse and touch users: nothing, unless they press Tab. One who
834
+ presses Tab out of a tile, or Shift+Tab, has the keyboard on a stop, which
835
+ shows over its tile and takes no press: their next press or tap goes where
836
+ they aim it, into that tile as anywhere else, and what they type before it
837
+ is lost.
838
+
839
+ What it costs screen reader users: one more button for each tile, and on a
840
+ phone a swipe through the page stops on it. Reading what is in a tile works
841
+ as before, but one whose screen reader takes the keyboard into the tile by
842
+ its own means has it given back (below): the stop is their way in, activated
843
+ and then followed by Tab. What was measured is Chrome's accessibility tree,
844
+ which has a button for each stop, named for its tile, focusable (also while
845
+ it takes no press), focused where the keyboard is, and named "Press Tab to
846
+ go in" once pressed. No screen reader was run: whether one reads out the new
847
+ name, and how a press of one on the stop goes, were not tried (the loader's
848
+ own tests, which run without a browser, hold that a press aimed at the stop
849
+ lets the frame in as a key does). A checker of accessibility may flag the
850
+ frame (a frame out of the tab order with things in it that take the
851
+ keyboard), though the stop is a way in. And the stop is an element of yours
852
+ in the box that holds the frame: a framework that owns that box may take it
853
+ away, and the guard puts it back when it next looks.
854
+
855
+ Firefox and WebKit do not let a page put the keyboard into a frame in answer
856
+ to a key: there `focus()` called from a key leaves the keyboard where it
857
+ was (measured in Firefox 160, headless, driven over WebDriver BiDi, where it
858
+ goes in when called from a press, and in the WebKit of macOS 15.7 in a
859
+ WKWebView, which was sent keys and no press; neither in a window of its
860
+ own). The guard's stop does not depend on it, and works there. What still
861
+ goes in that way does nothing there from the keyboard: Enter or Space on a
862
+ control of yours that calls `focus()` (with `tabOrder: 'out'`), and a pick
863
+ by Enter or Space on `engage`'s layer or on the guard's own layer after a
864
+ refusal (below). A press or a tap on any of them works in Firefox.
865
+
866
+ So say otherwise if you have to: `tabOrder: 'out'` keeps the frame out of
867
+ the tab order with no stop of the guard's, for a page that has its own way
868
+ in (it calls `focus()` on what `guardFocus` returned); `tabOrder: 'keep'`
869
+ leaves the frame in the tab order as you made it, as the guard did in
870
+ `@dasl/tile-loader` 3 and earlier. A `tabindex` you give the frame through
871
+ `renderContent()` does not keep it in: only `tabOrder: 'keep'` does.
872
+
873
+ Focus arriving in the tile's frame stays there when the user went in by your
874
+ way in, tabbed into it (from the guard's stop, or into a frame you keep in
875
+ the tab order), or pressed in it. Your page sees the Tab key, and where it
876
+ took the user: one that took them to another field of yours is not one into
877
+ the tile, and nor is one while the frame is out of the tab order, which
878
+ cannot have taken them there. It cannot see the press, so the guard asks the
879
+ tile's dock, which knows whether the user pressed or typed inside that tile
880
+ (see "What `activated` means"). In every other case focus goes back to the
881
+ element that had it: when the user was typing in a field of yours a moment
882
+ ago, when a mouse is somewhere else on the page, and when the dock says the
883
+ user did not act in the tile. Where nothing of yours had it then (the user
884
+ had pressed on the plain text of the page, say, or gone on into another
885
+ tile), it goes back to the page and to no element: not to a button they used
886
+ a while ago, which their next Space or Enter would press. That holds each
887
+ time the keyboard arrives, also when it comes from another frame of your
888
+ page: a tile the user went into once does not get to take the keyboard back
889
+ from the next one they go into.
890
+
891
+ Your page sees nothing of the keyboard going from one frame of yours into the
892
+ tile, and the guard finds it there only when it next looks (`pollMs`). So
893
+ while the keyboard is in a frame of your page, the guard has the tile's dock
894
+ watch it come in. Each time it comes in, the dock notes whether the user had
895
+ just pressed or typed in the tile. Where they had not, the dock says so at
896
+ once, without waiting to be asked, and the keyboard is given back as for the
897
+ dock's no. Keys the user typed into the tile before it was given back would
898
+ make them look as if they had acted there afterwards, so that no stands: the
899
+ dock goes on saying no each time the keyboard comes into the tile, until
900
+ those keys no longer count (about five seconds after the last of them), and
901
+ goes on watching for that long after the guard has stopped asking. A Tab on
902
+ your page into the tile, or your own way in, is the user going in, and ends
903
+ it at once. All of this only ever refuses: where the dock says the user had
904
+ acted, or cannot say, the guard goes by what it did before. The dock looks
905
+ every few milliseconds while it watches, which costs a little (in Chrome on a
906
+ laptop, under one percent of a core for each tile watching), and only while
907
+ the keyboard is in a frame of your page and for those few seconds after; a
908
+ loading server whose dock does not watch (`@dasl/tile-server` 3.2 and
909
+ earlier) leaves the guard with the dock's word as it stands when the guard
910
+ asks.
911
+
912
+ What that costs: a press or a tap of the user's into the tile is refused,
913
+ and the keyboard given back, in the few seconds after a key of theirs reached
914
+ the tile before it was given back, or after a press of theirs into it was
915
+ refused: the dock cannot tell such a press from keys typed into the tile. It
916
+ is refused too in the few seconds after the user went into any tile of the
917
+ page by your way in from the keyboard, and pressed Tab or typed (those keys
918
+ land in a page of the dock's own), as it was before; when the docks of the
919
+ page were kept busy for a moment as it came
920
+ (on a slow phone, a page adding another tile does that for a few hundred
921
+ milliseconds); and after a press into the tile that did not bring the
922
+ keyboard along, at such a moment. The dock's word comes within a few
923
+ milliseconds, so a key reaches the tile only when it is typed that quickly,
924
+ or when the dock is slow to answer.
925
+
926
+ Each of those refusals is only the dock's best guess: someone did act in the
927
+ tile, and it may have been the user. The dock says so, and the guard does
928
+ not count such a refusal against the tile. Instead a layer of your page's
929
+ lies over the tile until the user picks it: a press or a tap on it, or Enter
930
+ or Space while it has the keyboard, puts the keyboard in the tile as your
931
+ way in does, and ends the dock's no. Picked with a press or a tap, the
932
+ keyboard goes on into the tile, where what they type next reaches it; picked
933
+ with Enter or Space, it is where their Tab goes on into the tile (in Chrome:
934
+ in Firefox and WebKit a pick from the keyboard leaves the keyboard outside
935
+ the tile, see above). So a user who presses again picks the tile, what they
936
+ type then reaches it, and their next press goes where they aim. Until it is
937
+ picked, the keyboard coming into that tile is never taken for the user's
938
+ doing: it is given back and counted, so the layer spares the tile at most
939
+ one giving back. Neither the tile nor anything but the user lifts it: only a
940
+ press, a tap or a key the browser says is theirs, or your own way in
941
+ (`focus()`); or the dock, once its no is over. The guard asks it now and
942
+ then (every half second at most) while the keyboard is out of the tile, and
943
+ the layer lifts on its own when the dock says that what its no went by has
944
+ run out with the keyboard elsewhere: about five seconds after the user's
945
+ last press into the tile, unless they are on the layer itself. Then the next
946
+ press into the tile is judged as any other. Such a refusal in the minute
947
+ after a layer lifted on its own (`spareMs`) is counted all the same, with a
948
+ layer as well: a tile that could have its dock's nos taken for guesses, and
949
+ waited each time for the layer to go, is held to the same count as before. A
950
+ pick of the user's, or your way in, spares the next one again. The layer is
951
+ right after the frame, in the element that holds it, which is made a
952
+ positioned box (`position: relative`) while the layer is there if it is not
953
+ one already; the layer is where Tab stops meanwhile, in place of the guard's
954
+ stop (and of the frame, which is out of the tab order then even with
955
+ `tabOrder: 'keep'`). It is the same kind of layer as `engage`'s (see "Press
956
+ to use"), with the class `tile-engage` and its own, `tile-pick`
957
+ (`PICK_CLASS`). It shows that the tile waits for the user: a ring round the
958
+ tile, and in the middle a label (`tile-pick-label`, `PICK_LABEL_CLASS`) that
959
+ says "Tap or click to use", which is also its name for assistive technology;
960
+ `pickLabel` gives your own words. That look is a style sheet the guard gives
961
+ your page once, whose rules weigh nothing (`:where`), so that any rule of
962
+ yours for `.tile-pick` or `.tile-pick-label` wins; it is an adopted sheet
963
+ where the browser has those, which a policy that refuses inline style does
964
+ not refuse, and a style element first in the head otherwise. A frame in a
965
+ shadow tree has its layer there, and the sheet is given to that tree once as
966
+ well, where your rules for it go too. The faint background the layer needs
967
+ to take a press over a frame is set on the element itself. With `pick:
968
+ false` such a refusal is counted like any other, and three in ten seconds
969
+ stop the tile. A loading server whose dock does not say whether it was sure
970
+ (`@dasl/tile-server` 3.2 and earlier) has every refusal counted, as before.
971
+
972
+ A way in of your own goes through the guard: a control of yours calls
973
+ `focus()` on what `guardFocus` returned, not on the frame, and the keyboard
974
+ it puts in the tile is the user's, as if they had tabbed in (see "The frame
975
+ a tile runs in"). Give the guard `tabOrder: 'out'` then, unless you want its
976
+ stop as well. From the keyboard it goes in in Chrome alone (see
977
+ "`tabindex`").
978
+
979
+ Whatever the frame, do not put the keyboard in it by calling `focus()` on the
980
+ frame itself while a guard is on a tile of your page: in Chrome the page then
981
+ goes on naming that frame as the one with the keyboard after it has gone to
982
+ another, and a guard goes by what the page names. Where a frame has no guard
983
+ to ask, go in through its window: `frame.contentWindow.focus()`.
984
+
985
+ What it costs a tile that means no harm: its own `focus()` with no press in
986
+ it (an `autofocus`) does not stick. And a click into the tile within a second
987
+ of a key typed in a field of yours is given back once; the user clicks again.
988
+
989
+ What it may cost a user: someone whose screen reader takes the keyboard into
990
+ the tile by its own means, with no Tab and no press that your page or the
991
+ dock sees, has it given back as a script's would be, each time. That has not
992
+ been tried with a screen reader; try it with yours before you turn this on.
993
+
994
+ Nor does your page see a Tab pressed inside another frame. A guarded tile
995
+ is out of the tab order, so nobody tabs out of one tile straight into it.
996
+ Where you keep it in (`tabOrder: 'keep'`), a user who does has the keyboard
997
+ given back, and counted, as a script's would be: three times in ten seconds
998
+ stops the tile.
999
+
1000
+ On a screen that takes fingers as well as a mouse (a touch laptop), your page
1001
+ sees nothing of a finger in a frame. Before the guard has seen any pointer, a
1002
+ tap into a guarded tile from your page itself is asked about. One from another
1003
+ frame of your page is given back and counted in the same way, and so is any
1004
+ tap into the tile once the guard last saw the mouse elsewhere: it cannot tell
1005
+ them from the tile's script taking the keyboard. The way in serves these users
1006
+ too.
1007
+
1008
+ What it does not do:
1009
+
1010
+ - Giving focus back does not win against a tile that takes it again at once:
1011
+ about half the keys still land in the tile. So a tile that takes the
1012
+ keyboard three times in ten seconds is reported (`onAbuse('focus', count)`)
1013
+ and stopped (see "A tile that keeps at it is stopped").
1014
+ - For about five seconds after a real press or key in the tile, the tile can
1015
+ take the keyboard back and keep it, where nothing was refused in between.
1016
+ - Until the guard has heard from the dock, a key the user types goes to the
1017
+ tile: a few milliseconds where the dock watches, up to `pollMs` where it
1018
+ does not and the keyboard came from another frame. A key typed in the few
1019
+ milliseconds before the dock first finds the keyboard in the tile counts as
1020
+ their having acted in it, and so does any key, where the dock does not
1021
+ watch. The dock gets `dockMs` to answer; one that has answered before and
1022
+ now does not is taken to say no, so keeping it busy gains a tile nothing.
1023
+ - With a loading server whose dock does not answer (`@dasl/tile-server` 3.1
1024
+ and earlier), the guard has only what your page can see. A mouse resting on
1025
+ the tile, and any touch screen, cannot be told from a press there, and the
1026
+ tile keeps the keyboard.
1027
+ - Where you keep guarded tiles in the tab order (`tabOrder: 'keep'`), a
1028
+ user who tabs out of one tile straight into the next, with nothing of
1029
+ yours to stop at between them, has the keyboard given back: your page saw
1030
+ no Tab, and the second tile's dock no key. Put something of yours that
1031
+ takes focus between two tiles.
1032
+
1033
+ A guard listens to your page, so it does not go with the tile the way
1034
+ `tileSize` does: it stops when the tile is closed (`tile.close()`), or when
1035
+ you call `stop()` on what it returned. Turn it on when you render the tile,
1036
+ before the tile runs. Its numbers are first guesses: `FOCUS_GUARD` has them,
1037
+ and the options override any (`tabMs`, `typingMs`, `grabs`, `withinMs`,
1038
+ `dockMs`, `pollMs`, `spareMs`). `pick: false` turns off the layer the user
1039
+ picks a tile on after a refusal the dock was not sure of, and `pickLabel`
1040
+ gives it your own words. `tabOrder` says where the frame is in the tab
1041
+ order (`'stop'`, the default, `'out'` or `'keep'`), `enterLabel` gives
1042
+ the guard's stop your own words, and `tabLabel` what it says once pressed.
1043
+
1044
+ ### Scrolling
1045
+
1046
+ A tile cannot scroll your page from script, but the browser does it for it:
1047
+ asking for an element of its own to be brought into view scrolls every
1048
+ scroller above it, your document included. That takes the page to the tile
1049
+ from anywhere, holds it there against the user's wheel, or brings a control
1050
+ of yours that sits under the tile up to a pointer that has not moved. No
1051
+ style on a container stops it, and nothing in the sandbox governs it.
1052
+
1053
+ ```js
1054
+ import { guardScroll } from '@dasl/tile-loader/guard';
1055
+ const scrolling = guardScroll(tile, frame);
1056
+
1057
+ scrolling.expect(); // before your own code scrolls the page
1058
+ window.scrollTo(0, 0);
1059
+ ```
1060
+
1061
+ `guardScroll` follows your document's vertical scroll position and accounts
1062
+ for every move of it:
1063
+
1064
+ - **the user's**: your page saw the input (a wheel, a key, a finger, a mouse
1065
+ button held, a pointer on the scrollbar), and the move goes that way and no
1066
+ further than the input asked. So is the line or two by which the browser
1067
+ keeps the caret in view while they type in a field of yours;
1068
+ - **your own**: you said so with `expect()`, or the page navigated, or the
1069
+ user tabbed on;
1070
+ - **layout**: the document's height changed by as much as the move or more;
1071
+ - **cannot tell**: none of those, but a mouse was in the tile and may have
1072
+ been wheeling there, or the keyboard is in the tile, or a finger may be on
1073
+ it. The same goes for every other frame of your page, another tile or a
1074
+ video: what the user does in one scrolls your page too, and your page sees
1075
+ none of it. The move stands, and what it slid under the pointer takes no
1076
+ press for a moment;
1077
+ - **the tile's**: none of those, and the tile is at or in the viewport
1078
+ afterwards, which is where its own scrolling leaves it. The move is taken
1079
+ back before it is painted, and nothing else happens: what was put back
1080
+ slid nothing under the pointer, so your page goes on taking presses,
1081
+ however often the tile asks;
1082
+ - **elsewhere**: unexplained and nowhere near the tile. Left alone, with the
1083
+ same moment without presses.
1084
+
1085
+ That moment is `clickGate(document)`, which you can also use by itself: after
1086
+ `arm()`, presses on your page are ignored for 0.6 seconds (2.5 after a jump
1087
+ of more than 150 pixels), an ignored press starts the moment again, and the
1088
+ pointer really moving ends it. A key is not a press. Mark an element of
1089
+ yours that must take presses regardless with `data-tile-gate="pass"`.
1090
+
1091
+ What it costs, and why it is something you turn on: your page has to say when
1092
+ it scrolls itself. A move of your own that you did not declare and that ends
1093
+ at the tile is taken back like the tile's. `own: 'patch'` declares them for
1094
+ you, by wrapping `scrollTo`, `scrollBy`, `scroll`, `scrollIntoView` and
1095
+ `focus` for as long as a guard that asked runs. A move with no input your
1096
+ page can see that ends at the tile is taken back too: a screen reader's, or
1097
+ the tap on a phone's status bar. `undo: false` keeps the accounting and the
1098
+ gate, and takes nothing back.
1099
+
1100
+ What it does not do. It holds against a tile that scrolls your page outright;
1101
+ one that picks its moment gets moves through, and you should know which:
1102
+
1103
+ - With a mouse in the tile or in another frame of your page, the keyboard
1104
+ in one, or possibly a finger on one, the tile's move stands and only the
1105
+ gate covers it: a press that comes later than the gate's moment lands on
1106
+ what the move put there. A mouse counts as in a frame from when your page
1107
+ saw it go in until the page has moved by that frame's height, or the mouse
1108
+ is seen somewhere else.
1109
+ - A tile can put the keyboard in itself, with no press: its moves then stand
1110
+ for that reason. Turn `guardFocus` on beside this guard, which gives the
1111
+ keyboard back.
1112
+ - The gate is ended by the pointer moving, and a pointer is usually moving
1113
+ just before a press. A tile that scrolls while the pointer is on its way
1114
+ to something in it has the press land on what it put there: the gate
1115
+ covers the pointer that had come to rest, as for the second click of a
1116
+ double click. `clickGate(document, { travel: Infinity })` has the gate
1117
+ last its time whatever the pointer does, at the price of presses lost
1118
+ after the user's own scrolling through a frame.
1119
+ - A move that comes with a change of the document's height of about its
1120
+ size is put down to layout. A tile that may change its own height can pair
1121
+ one with a move of the page by as much: that move stands, with the gate.
1122
+ - A button held down on your page, or let go a moment ago, explains a move
1123
+ (a drag, a click on something that scrolls). A single move by the tile
1124
+ that happens to fall there stands, and closes no gate. One that keeps
1125
+ trying does not get it: for a moment after a move of its was taken back,
1126
+ a press explains nothing.
1127
+ - A move with no input that your page can see is taken back when it ends at
1128
+ the tile, whoever made it. The browser keeping the caret in view while the
1129
+ user types in a field of yours is let be, a line or two at a time; a
1130
+ longer jump of the caret's (a paste, Page Down in a tall field) is not.
1131
+ - Taking a move back is a contest against a tile that keeps pulling. So one
1132
+ that pulls the page back against the way the user has just scrolled, three
1133
+ times in ten seconds, is reported (`onAbuse('scroll', count)`) and stopped
1134
+ (see "A tile that keeps at it is stopped").
1135
+ - Where two tiles you guard are at the viewport after a move, your page
1136
+ cannot tell which of them made it. The move is taken back all the same,
1137
+ and neither is reported or stopped for it: a tile is not closed for what
1138
+ its neighbour did. Getting away from one that keeps pulling is slower
1139
+ then, since putting the page back can cut short a wheel that was under
1140
+ way.
1141
+ - Only the document's own scrolling is followed. A feed that scrolls inside
1142
+ a box of its own is not covered.
1143
+
1144
+ `onMove` is called with every move and how it was accounted for, which is
1145
+ how to find out what the guard would do on your page before you let it take
1146
+ anything back. The numbers are first guesses: `SCROLL_GUARD` and `CLICK_GATE`
1147
+ have them, and the options override any.
1148
+
1149
+ ### A tile that keeps at it is stopped
1150
+
1151
+ Giving back what a tile took is a contest with one that takes it again, and
1152
+ the tile is the faster. `guardFocus` and `guardScroll` therefore end it at the
1153
+ third time in ten seconds:
1154
+
1155
+ - the tile's frame is hidden at once (a frame that is not rendered takes no
1156
+ focus and scrolls nothing);
1157
+ - the tile gets a `stopped` event with `ev.reason` `focus` or `scroll`, beside
1158
+ the dock's `blocked` and `navigated`;
1159
+ - the tile is closed as `tile.close()` closes it: its runtime cleans up, its
1160
+ frame is removed, and a `close` event follows.
1161
+
1162
+ Show a line where the tile was, with a way to run it again if you like:
1163
+ rendered again it is a tile like any other, and guarded afresh if you guard
1164
+ it afresh.
1165
+
1166
+ ```js
1167
+ tile.addEventListener('stopped', (ev) => {
1168
+ if (ev.reason === 'focus' || ev.reason === 'scroll') showNotice(`This tile was stopped: it kept taking the ${ev.reason === 'focus' ? 'keyboard' : 'page'}.`);
1169
+ });
1170
+ ```
1171
+
1172
+ What it costs: a tile that calls `focus()` on itself three times in ten
1173
+ seconds with no press in it, or scrolls the page to itself three times
1174
+ against the user's own scrolling, is closed, whatever it meant by it. The
1175
+ first two times still happen. `stop: false` on either guard has it only
1176
+ report (`onAbuse`), and leaves the tile to you.
1177
+
1178
+ ### Press to use
1179
+
1180
+ A tile takes whatever input lands on it. On a touch screen that is the finger
1181
+ that was scrolling your feed: one line of CSS in a tile, or one listener,
1182
+ keeps the page from moving for every drag that starts on the tile. Nothing
1183
+ you set on the frame gives that back.
1184
+
1185
+ `engage` puts a layer of your page's over the tile until the user picks it:
1186
+
1187
+ ```js
1188
+ import { engage, guardFocus, guardScroll } from '@dasl/tile-loader/guard';
1189
+
1190
+ const box = document.createElement('div'); // holds the frame, and nothing else
1191
+ const frame = tile.renderContent();
1192
+ box.append(frame);
1193
+ feed.append(box);
1194
+
1195
+ const picking = engage(tile, frame);
1196
+ guardFocus(tile, frame, { engaged: () => picking.engaged });
1197
+ guardScroll(tile, frame, { engaged: () => picking.engaged });
1198
+ ```
1199
+
1200
+ Until it is picked the tile runs and shows, and gets no input. A wheel or a
1201
+ finger on it scrolls your page, your page sees every pointer that crosses it,
1202
+ and the two guards know more: focus arriving in a tile nobody picked is the
1203
+ tile's own doing, and so is a move of the page while the pointer rests over
1204
+ it. A press on the layer picks the tile, and is spent on that. A press
1205
+ anywhere else on your page, the tile leaving the view, or Escape, puts the
1206
+ layer back; so does `release()`.
1207
+
1208
+ Tab does not go into a tile that is not picked (its frame has
1209
+ `tabindex="-1"` meanwhile, and gets back what it had when it is picked). It
1210
+ stops at the layer, which comes after the frame in its box: Enter or Space
1211
+ there picks the tile and puts the keyboard in its frame, and the next Tab
1212
+ goes to the first thing in the tile (in Chrome: Firefox and WebKit do not
1213
+ let the keyboard in that way, see "The keyboard"; a press works there). With
1214
+ the focus guard on as well, the frame stays out of the tab order once the
1215
+ tile is picked: the guard's stop is the way back in to a picked tile, and
1216
+ the layer to one that is not.
1217
+
1218
+ Start a tile the user has just started themselves with `start: 'engaged'`;
1219
+ one that starts by itself, in a feed, not picked.
1220
+
1221
+ What it costs: one press or tap to begin using a tile, every time the user
1222
+ has touched something else since. Nothing in the tile reacts to a pointer
1223
+ passing over it, or to the wheel, until it is picked.
1224
+
1225
+ What it does not do: once picked, a tile can hold a finger, take the
1226
+ keyboard and be scrolled through again, until the user presses elsewhere.
1227
+ The other guards still apply then.
1228
+
1229
+ The focus guard puts a layer of the same kind over a tile after a refusal
1230
+ its dock was not sure of (see "The keyboard"). On a tile that waits to be
1231
+ picked, that layer is under `engage`'s: where `engage`'s is back over the
1232
+ tile, the user picks the tile there, and then once more on the guard's,
1233
+ which puts the keyboard in.
1234
+
1235
+ The layer is an element of your page's (`tile-engage`, also `layer` on what
1236
+ `engage` returns), a button to assistive technology, named by `label`. It
1237
+ paints, too faintly to see, and has to: a block that paints nothing does not
1238
+ take a press over a frame. The frame has to be in its box before it loads,
1239
+ since moving a frame reloads it.
1240
+
149
1241
  ## When a tile goes away
150
1242
 
151
1243
  A page that shows many tiles over its life (a feed, a chat) should not pay for
@@ -161,18 +1253,273 @@ for loaders that hold it, the tile's whole content. There is nothing to call.
161
1253
  **In the browser.** Every tile runs on an origin made for that one load, with a
162
1254
  service worker registered there and whatever the tile chose to store. Removing
163
1255
  the frame does not remove those: they would stay, one origin's worth for every
164
- tile ever shown. `await tile.close()` is how they go. The runtime takes the
165
- tile down, unregisters its worker, and has the loading server wipe the origin
166
- (`Clear-Site-Data`); then the frame is removed. So call `close()` *instead of*
167
- removing the frame yourself: once the frame is out of the document the runtime
168
- is gone, and there is no one left to tidy.
1256
+ tile ever shown. `await tile.close()` is how they go: the frame is removed, the
1257
+ worker is unregistered, and the loading server has the browser wipe the origin
1258
+ (`Clear-Site-Data`).
1259
+
1260
+ It makes no difference whether the frame is still in your document when you
1261
+ call it, nor what the tile did to its own runtime. The frame's address names
1262
+ the origin the tile runs on, so the loader needs neither the frame nor anything
1263
+ in it: it loads the loading server's dock for that origin once more, out of
1264
+ sight, and has a runtime that never held the tile do the wiping. Remove the
1265
+ frame first and close the tile after, as a component's clean-up tends to, or
1266
+ the other way round. `close()` resolves to whether the origin was wiped (`true`
1267
+ too for a tile that never started), and warns in the console when it was not:
1268
+ the loading server could not be reached, say, or the tile left more behind
1269
+ than the browser cleared in the time it was given.
169
1270
 
170
- A host that removes the frame all the same is not left with nothing: on its way
171
- out the runtime lets its worker's registration go, best effort. What the tile
172
- stored stays until the browser evicts it.
1271
+ A few seconds later the loader has the origin wiped a second time, the same
1272
+ way, and `close()` does not wait for it. The first wipe comes after everything
1273
+ the tile's pages did. A worker of the tile's has a thread of its own, though,
1274
+ and a browser can take a moment to stop one after its page is gone (up to two
1275
+ seconds, in Chromium), in which it can still write to the origin: the second
1276
+ wipe is for that, and for a first one that did not go through. It costs the
1277
+ loading server five more small requests for each tile closed.
1278
+
1279
+ That goes for the frames `renderContent()` makes, and for a frame of your own
1280
+ that loads `tile.getLoadSource()` and is handed to `tile.attachIframe()`. A
1281
+ frame that loads an address you put together yourself, without an origin in
1282
+ it, can only be wiped while it is still in the document.
1283
+
1284
+ A host that never calls `close()` is not left with nothing: on its way out the
1285
+ runtime lets its worker's registration go, best effort. What the tile stored
1286
+ stays until the browser evicts it.
173
1287
 
174
1288
  A tile on a named origin (`namedOrigin`) is the exception throughout: that origin
175
- is kept on purpose, so `close()` wipes nothing there.
1289
+ is kept on purpose, so `close()` wipes nothing there. So is a tile on the origin
1290
+ its CID names (`cidOrigins`); `tile.ephemeral` says which a tile is.
1291
+
1292
+ ## Origins named by a tile's CID
1293
+
1294
+ ```js
1295
+ const mothership = new TileMothership({ loadDomain: 'load.webtil.es', cidOrigins: true });
1296
+ ```
1297
+
1298
+ With `cidOrigins`, a tile runs on the origin its own content names,
1299
+ `<cid>.<base>`, where `<cid>` is the CID of its manifest as this loader
1300
+ computed it from the bytes it loaded: the DRISL of the record's `tile` on AT
1301
+ (`tile.manifestCid`), the header of a .tile file as the file has it
1302
+ (`tile.cid`). No option takes a CID, and no address names one: a host cannot
1303
+ point a tile at another tile's origin. `tile.getLoadSource()` and the frames
1304
+ `renderContent()` makes name that origin, every time, and so does every page
1305
+ that runs the same tile.
1306
+
1307
+ What is that for: a tile that keeps what it stores, for as long as it is that
1308
+ tile. A game's saves, a document's notes, its preferences, a tile in a feed
1309
+ that keeps its state when it is scrolled away and back. Its worker stays
1310
+ registered there too.
1311
+
1312
+ What it takes:
1313
+
1314
+ - **The tile server's runtime holds the origin to its tile.** Anyone can name
1315
+ such an origin, and every byte served there comes from the page's loader,
1316
+ so the runtime on the origin checks what it is handed against its own name:
1317
+ the manifest's bytes against the CID, each resource against the CID the
1318
+ manifest lists for it, and serves the headers the manifest lists, never the
1319
+ loader's (a `hardenResponse()` of yours adds nothing there). The loader
1320
+ hands it the manifest, and runs a tile there only once the dock has said
1321
+ that its runtime does this (`@dasl/tile-server` 4.0 and later): otherwise
1322
+ the tile fires `error` with `version`, and a refusal from the runtime is
1323
+ `integrity`. The loading server has to be at `load.<base>`.
1324
+ - **A tile with nothing to be named by** runs on an origin made for the load,
1325
+ as without the option: a webxdc tile, one in memory, and one whose loader
1326
+ has no manifest bytes to give. `tile.ephemeral` is `false` for a tile on the
1327
+ origin its CID names, `true` otherwise.
1328
+ - **It is kept**: `close()` wipes nothing and resolves `false`, and the frame
1329
+ is plain unless you ask for `credentialless: true`, which keeps nothing past
1330
+ the page in Chromium.
1331
+
1332
+ What a tile keeps there, it keeps per tile content, per top-level site and per
1333
+ browser profile, and for as long as the browser keeps it:
1334
+
1335
+ - **A new version starts with nothing.** Another manifest has another CID,
1336
+ and another origin. Nothing carries data from one version to the next: a
1337
+ tile that must gives it to its host over a protocol (tp-data). The old
1338
+ version's origin stays in the browser until it is cleared. The same tile as
1339
+ a .tile file and on AT has two CIDs, and two origins.
1340
+ - **Every run of the tile on one site shares it**: its storage, its worker,
1341
+ and on one page each other's documents. What one run is given, all can have.
1342
+ Do not run on such an origin a tile whose runs must be kept apart (one tile
1343
+ shown across private conversations, say).
1344
+ - **Each site that shows it has its own.** Where the browser keeps storage
1345
+ apart by the top-level site:
1346
+
1347
+ | | Storage and the worker | Cookies of the loading server's domain, in a plain frame |
1348
+ | --- | --- | --- |
1349
+ | Chrome | per top-level site (and per whether an ancestor is of another site) | the same jar on every site, unless its user blocks third-party cookies: a channel between tiles across sites |
1350
+ | Firefox | per top-level site | per top-level site |
1351
+ | Safari | per top-level site; what script wrote may be deleted after seven days of use without a visit to the site | blocked |
1352
+ | A WKWebView | the app's own store | the app's |
1353
+ | Android's WebView | not known | not known |
1354
+
1355
+ Where the page that shows tiles is on the tile server's own site (as
1356
+ webtil.es and its tiles are), every frame is of the same site and a tile's
1357
+ store is that site's own: every page of the site shares it, a link to one
1358
+ included. So are the cookies of that site, in every browser: where it is
1359
+ your site too (as `t.mu.social` is under `mu.social`), a tile in a plain
1360
+ frame there reads the cookies of yours that a script can read, and sets
1361
+ cookies your site then receives. Keep such origins off there.
1362
+ - **Best effort.** Storage is cleared under pressure and by its user.
1363
+
1364
+ And what it costs:
1365
+
1366
+ - **The host name says which tile is shown**, to DNS resolvers, to the
1367
+ network unless the browser hides it (Encrypted Client Hello), and to the
1368
+ tile server and whatever is in front of it. A minted name says nothing.
1369
+ - **Pages of the same site, and every frame in them, can use what the tile
1370
+ kept.** Any page of the site the tile is shown under can run the genuine
1371
+ tile on its origin, with what it kept there, and feed it whatever it likes
1372
+ over the tile protocols, or answer none of its requests, or have its origin
1373
+ wiped. So can any frame in such a page, whatever site the frame is from: an
1374
+ ad, an embedded player, a widget, and whatever they frame in turn. The
1375
+ browser keeps the tile's store by the site at the top, and not by who
1376
+ frames the tile (measured in Chrome and Firefox). None can run any other
1377
+ tile there, nor other bytes or headers. Treat what a tile kept as the
1378
+ tile's, not as yours to trust, and run tiles on the origins their CIDs name
1379
+ only on pages whose frames you would let do this.
1380
+
1381
+ ## Loading a tile
1382
+
1383
+ A tile's address says where it is, and its author's servers say what is
1384
+ there. The loaders take neither on trust.
1385
+
1386
+ **What a tile is made of is checked.** A tile on AT is a record that names
1387
+ each of its resources by the CID of its bytes, and the bytes come from the
1388
+ author's PDS. The AT loader hashes every blob in your page and serves it only
1389
+ if it is what the record names, and as long as the record says. The blocks of
1390
+ a `.tile` file are checked the same way. What does not match is not served.
1391
+
1392
+ **Which tile it is, you can say.** An `at://` address can hold another record
1393
+ tomorrow. If your page embeds a tile that someone posted, keep the CIDs of
1394
+ what was posted, and hand them back when you show it:
1395
+
1396
+ ```js
1397
+ const posted = await tl.loadTile(url, {});
1398
+ save({ url, cid: posted.cid, manifestCid: posted.manifestCid });
1399
+
1400
+ // later, wherever the post is shown
1401
+ try {
1402
+ const tile = await tl.loadTile(url, { cid, manifestCid });
1403
+ }
1404
+ catch (err) {
1405
+ if (err.code === 'record-changed') {
1406
+ // Not the tile that was posted. err.actual and err.manifestCid are
1407
+ // what is there now, should your user choose to run that.
1408
+ }
1409
+ }
1410
+ ```
1411
+
1412
+ `cid` is the CID of the record, which is what a strong reference to it
1413
+ carries. `manifestCid` is the CID of the manifest alone. The loader computes
1414
+ both from the record as it came, and never uses the CID a PDS reports. With
1415
+ both, either will do, and both is what to keep: publishing the same content
1416
+ again writes a new record with a new date, so the record's CID changes when
1417
+ nothing else has, and the manifest's does not. Give each as what it is: the
1418
+ two are never the same, and one CID passed as both is refused. A caller that
1419
+ only has a string to pass can end the address with `?cid=…&manifestCid=…`.
1420
+ An address is often someone else's writing, so what it says there is read
1421
+ only when you pass neither CID yourself, and never adds to what you expect;
1422
+ `pinned` is then true of whatever the address asked for. A tile from a
1423
+ `.tile` file has a `cid` as well, the CID of the file's header (which is its
1424
+ manifest; nothing else in the file names it), and no `manifestCid`; a file
1425
+ that is expected has to have every block its header lists.
1426
+ `recordCid(value)`, from `@dasl/tile-loader/at`, gives the CID of a record or
1427
+ of a manifest you already hold. A tile whose loader has no CID to give (a
1428
+ `.xdc`, a tile from memory) is refused when one is expected.
1429
+
1430
+ **A tile on AT is fetched whole before it runs.** Loading a tile fetches its
1431
+ record. When you run it (`renderContent()`, `attachIframe()`), everything
1432
+ the record lists is fetched once, in the order of the record and a few at a
1433
+ time (one at a time for a resource whose size the record does not declare),
1434
+ and the tile's runtime is only started when all of it is in memory.
1435
+ From then on the tile is answered from memory. This is what keeps a tile
1436
+ from talking to its author's server: if each of its requests went to the PDS
1437
+ as it made it, which resources it asked for, and when, would be a message it
1438
+ could put anything into. The tile says how that went:
1439
+
1440
+ ```js
1441
+ tile.addEventListener('ready', () => { /* all of it is here; its runtime is starting */ });
1442
+ tile.addEventListener('error', (ev) => { /* ev.error is a TileLoadError; the tile does not run */ });
1443
+ ```
1444
+
1445
+ Rendering it again tries again, for what is missing. A tile that lists more
1446
+ than a tile may have (see the limits below) is not loaded at all
1447
+ (`over-budget`): fetching the rest as the tile asked would put the message
1448
+ back. Before a tile is run, a resource you ask for yourself (`renderCard()`
1449
+ does, for the icon and the screenshot) is fetched by itself, if it is no
1450
+ larger than `cardBytes`. Mind the cost: the first paint waits for the whole
1451
+ tile, resources a tile lists and never uses are downloaded all the same, and
1452
+ its bytes stay in your page's memory while you hold the `Tile`.
1453
+
1454
+ All of this is done by the tile that `ATTileLoader` gives you. If you make an
1455
+ `ATPathLoader` yourself and run it under a `Tile` of your own, call its
1456
+ `prepare()` and run the tile once that has resolved: until `prepare()` is
1457
+ called, each resource is fetched from the PDS as it is asked for.
1458
+
1459
+ **What went wrong has a name.** A `TileLoadError` (exported from the package
1460
+ root) has a `code`, and `retryable` says whether trying again can help. Go
1461
+ by the `code` for what you tell your user: the `message` is for a console,
1462
+ and can name a path or a host that the tile's author chose.
1463
+
1464
+ | `code` | What happened |
1465
+ | --- | --- |
1466
+ | `record-changed` | the tile is not the one you expected (`expected`, `actual`, `manifestCid`) |
1467
+ | `record-invalid` | not a tile's record, or not one that can be run or checked; a `.tile` that is not whole |
1468
+ | `not-found` | the handle, the DID, the record or a resource does not exist |
1469
+ | `integrity` | bytes are not what the CID that names them says (`path`, `expected`, `actual`) |
1470
+ | `over-budget` | the tile lists more than a tile may have (`limit`, and `amount` where it is known) |
1471
+ | `too-large` | an answer was longer than it may be (`limit`) |
1472
+ | `destination` | a DID, or a PDS, that the loader does not fetch from |
1473
+ | `rate-limited` | a server said 429 (`retryAfter`, in seconds, when it says); retryable |
1474
+ | `upstream` | a server failed, or answered what is no answer; retryable |
1475
+ | `timeout` | no answer in time; retryable |
1476
+ | `network` | the request failed: unreachable, refused by the browser, a redirect; retryable |
1477
+
1478
+ A resource the tile lists and that could not be had is answered 502 (503 when
1479
+ the PDS is busy, 504 when it was too slow, 507 when the tile is over its
1480
+ limits), never the 404 of a path the tile does not have.
1481
+
1482
+ **How much, and how long.** Every request has a time limit and every answer a
1483
+ size limit. These are first guesses; pass `limits` to a loader to replace any
1484
+ of them (`new ATTileLoader({ limits: { tileBytes: 8 * 1024 * 1024 } })`). They
1485
+ are `DEFAULT_LIMITS`, exported with the loaders.
1486
+
1487
+ | Limit | Default | What it bounds |
1488
+ | --- | --- | --- |
1489
+ | `didDocumentBytes` | 64 KiB | a DID document |
1490
+ | `recordBytes` | 1 MiB | a record |
1491
+ | `resourceBytes` | 10 MiB | one resource; one whose record declares its size is held to that |
1492
+ | `resources` | 256 | the resources of a tile that are not the same bytes |
1493
+ | `tileBytes` | 25 MiB | all the resources of a tile together |
1494
+ | `cardBytes` | 2 MiB | a resource asked for before the tile is run |
1495
+ | `archiveBytes` | 32 MiB | a `.tile` or `.xdc` file |
1496
+ | `concurrency` | 6 | requests for a tile's resources under way at once (one, for resources that declare no size) |
1497
+ | `requestMs` | 20 s | one request |
1498
+ | `prepareMs` | 60 s | all of a tile, or a whole file |
1499
+ | `retries` | 1 | how often a resource is asked for again after a server error or a failed request (never after a 429) |
1500
+ | `retryMs` | 300 ms | the wait before asking again, to which up to as much is added |
1501
+
1502
+ **Where the loader goes.** A DID document, which anyone can write, names the
1503
+ PDS, and it is your user's browser that goes there. The AT loader only asks a
1504
+ `did:web`'s host, a handle's own host and a PDS that are public names, and a
1505
+ PDS endpoint has to be https with no port, no credentials and no path. No
1506
+ loader follows a redirect, and the AT loader's requests carry no credentials
1507
+ and no referrer. The DID is resolved once for a tile, and all of the tile
1508
+ comes from the PDS it named then. For local development, say that a PDS on
1509
+ your own machine is fine, and where your PLC directory is:
1510
+
1511
+ ```js
1512
+ import { ATTileLoader, localEndpoint } from '@dasl/tile-loader/at';
1513
+ new ATTileLoader({ plcUrl: 'http://localhost:2582', destinations: { pds: localEndpoint } });
1514
+ ```
1515
+
1516
+ `destinations.pds` and `destinations.did` replace the rule for a PDS endpoint
1517
+ and for a host (`publicEndpoint` and `publicHost` are the defaults); only a
1518
+ host whose `fetch` goes through a proxy with checks of its own should pass
1519
+ another. A `fetch` of your own is handed a `signal`, which it should obey,
1520
+ and `redirect: 'error'`, and should give a body that streams; one that does
1521
+ none of this is still held to the time limits, and to the size limits once
1522
+ it has answered. Whether it sends credentials is its own business.
176
1523
 
177
1524
  ## Security model
178
1525
 
@@ -191,18 +1538,29 @@ A tile's origin is a dead end, by three layers that all read one policy
191
1538
  `X-DNS-Prefetch-Control: off`. A CSP the tile declares
192
1539
  stays and is enforced alongside. The worker's own improvised responses, and
193
1540
  the server's 404s, carry a `default-src 'none'; sandbox` dead end.
194
- - **WebRTC is spent before the tile loads.** No browser implements CSP's
195
- `webrtc` directive yet, and ICE is not a fetch. Chromium caps a renderer
196
- process at 500 `RTCPeerConnection`s and only frees a slot when the object is
197
- destroyed, so the shuttle creates and holds 500 closed ones (a few hundred
198
- milliseconds; the trick Delta Chat uses for webxdc). The tile, and any frame
199
- or popup it opens in that process, gets "Cannot create so many
200
- PeerConnections". The shuttle knows Chromium by its client hints or, in a
1541
+ - **WebRTC is closed in Chromium alone.** No browser implements CSP's
1542
+ `webrtc` directive yet, and ICE is not a fetch, so neither the worker nor
1543
+ the CSP has a say. Two things do, and only Chromium has them. The one that
1544
+ holds is `Connection-Allowlist`, which the tile server and the worker send
1545
+ with every document they serve on a tile's origin (see
1546
+ [`@dasl/tile-server`](../tile-server)): where Chromium enforces it, a
1547
+ document that carries it opens no WebRTC connection, and neither does a
1548
+ frame it makes from nothing (`about:blank`, `srcdoc`, `blob:`, `data:`),
1549
+ which inherits it, in whatever process that frame runs. It holds as long as
1550
+ nothing on the origin is served without it. The other is older, and is all
1551
+ there is in a Chromium that does not enforce the header. Chromium caps a
1552
+ renderer process at 500 `RTCPeerConnection`s and only frees a slot when the
1553
+ object is destroyed, so the shuttle creates and holds 500 closed ones (a
1554
+ few hundred milliseconds; the trick Delta Chat uses for webxdc), and the
1555
+ tile, with any frame it opens in that process, gets "Cannot create so many
1556
+ PeerConnections". That budget is one process's, and Chrome on the desktop
1557
+ gives a sandboxed frame a process of its own: by itself the guard does not
1558
+ close WebRTC there. The shuttle knows Chromium by its client hints or, in a
201
1559
  WebView without them, by the `Chrome/` token in the UA string, and logs when
202
- it skips. Firefox and Safari have no such cap: there, WebRTC egress
203
- (STUN/TURN hostnames, TURN credentials) stays open from a browser page, and a
204
- host that can block it at the engine level should (mollusc's `network:
205
- "loopback"`, say).
1560
+ it skips. Firefox and Safari have neither the header nor the cap: there
1561
+ nothing closes WebRTC (STUN/TURN hostnames, TURN credentials) from a browser
1562
+ page, and a host that can block it at the engine level should (mollusc's
1563
+ `network: "loopback"`, say).
206
1564
 
207
1565
  - **The runtime's frame goes nowhere.** The tile shares an origin with its
208
1566
  shuttle and can script it, into following a link for one. What governs where
@@ -212,9 +1570,23 @@ A tile's origin is a dead end, by three layers that all read one policy
212
1570
  whose runtime tries to leave (the `stopped` event). A `frame-src` of your
213
1571
  own that only allows the tile server's host is a second lock on the same
214
1572
  door.
1573
+ - **Your frame takes more away.** The frame `renderContent()` returns is
1574
+ sandboxed without dialogs and downloads, so a tile raises no dialog and
1575
+ starts no download in your page, and refuses a tile synchronous requests;
1576
+ it can be credentialless, out of the tab order, and refuse a tile more
1577
+ features of the browser, fewer of which other browsers than Chrome know.
1578
+ See "The frame a tile runs in". A frame's sandbox only takes away from
1579
+ what runs under it, so two things have to stay in it, `allow-scripts` and
1580
+ `allow-same-origin`: without them the runtime's service worker cannot
1581
+ run, and no tile loads.
215
1582
  - **A tile opens nothing.** No popups in the sandbox, so no window to send
216
1583
  anywhere. A link out is a request over the link protocol, and your page
217
1584
  decides (`tileLinks`), opening it somewhere of its own.
1585
+ - **What a tile sends is untrusted input.** The `payload` of a `protocol`
1586
+ event, which is also what `tileData()` hands to `onData`, is a structured
1587
+ clone of any shape and size, and the tile's to write. Check it before you
1588
+ use it, never put it in your page as markup or run it as code, and assume
1589
+ that whatever you send a tile can reach its author.
218
1590
 
219
1591
  The mothership's side of the contract is to only ever answer a worker's
220
1592
  `resolve-path` with `{ status, headers, body }`, to act on messages only from
@@ -222,6 +1594,61 @@ the docks it created, on the tile server's origin, and to post to that origin
222
1594
  alone. [`@dasl/containment-tile`](../containment-tile)
223
1595
  is the red-team tile that checks all of this end to end, in a real browser.
224
1596
 
1597
+ ## Tiles in a list
1598
+
1599
+ A running tile is a process of the browser's, sometimes two: some 18 MB each,
1600
+ and some 52 MB where the runtime spends the WebRTC budget first. The loader
1601
+ runs as many as it is asked to. A page with more tiles than it should run at
1602
+ once (a feed, a thread) leaves the asking to `@dasl/tile-loader/mount`:
1603
+
1604
+ ```js
1605
+ import { tileMounts } from '@dasl/tile-loader/mount';
1606
+ import { tileSize } from '@dasl/tile-loader/size';
1607
+
1608
+ const mounts = tileMounts({ maxLive: 4 });
1609
+ for (const post of document.querySelectorAll('.post')) {
1610
+ mounts.watch(post.querySelector('.tile'), {
1611
+ tile: () => tl.loadTile(post.dataset.tile),
1612
+ onMount: (tile, frame) => {
1613
+ const sizing = tileSize(tile, frame, { limits: { maxHeight: 800 } });
1614
+ return () => sizing.stop();
1615
+ },
1616
+ });
1617
+ }
1618
+ ```
1619
+
1620
+ - A tile is **mounted** in its place, an element of yours, when the place has
1621
+ been in view for a moment (`mountAfter`, 300 ms): what is only scrolled past
1622
+ is left alone, and its tile is not even loaded.
1623
+ - It is **closed** when its place has been out of view for a while
1624
+ (`closeAfter`, ten seconds), with `tile.close()`: the frame goes and the
1625
+ origin is wiped. Shown again, it starts afresh on another origin, so this is
1626
+ for tiles whose state you do not mean to keep.
1627
+ - No more than `maxLive` (six) are **live at once**. When another tile needs
1628
+ the room, the live one that has been out of view longest is closed for it.
1629
+ A tile in view is never closed for another: the other waits.
1630
+ - Tiles **start a few at a time** (`maxStarting`, three). A tile counts as
1631
+ starting until it fires `load`, or for `startLimit` (five seconds). The
1632
+ function that loads a tile is given no longer than that either: when it
1633
+ takes more, the tile's room goes to the ones that wait, and the tile is
1634
+ mounted when it does come, if its place is still in view.
1635
+
1636
+ While a tile is live its frame is the last child of its place, and the place
1637
+ has the attribute `data-tile-live`. Give the place the size the tile will
1638
+ have, so that the page does not move when a tile comes and goes, and use the
1639
+ attribute to hide what the place showed before (a card, a screenshot).
1640
+ `tile` is the tile or a function that loads it, called once, the first time
1641
+ it is needed; `render(tile)` makes the frame if `tile.renderContent()` is not
1642
+ what you want; `onMount(tile, frame)` is the moment for `tileSize` and
1643
+ `tileLinks`, and what it returns is called when the tile is put away;
1644
+ `onClose(tile, wiped)` says when it has been closed. `watch()` returns a
1645
+ function that stops watching the place and closes its tile, `mounts.stop()`
1646
+ does it for all of them, and `mounts.live` is how many are live. `root` and
1647
+ `rootMargin` are those of an `IntersectionObserver`.
1648
+
1649
+ The numbers are places to start from, not measurements of your page: set them
1650
+ for what the devices of your users carry.
1651
+
225
1652
  ## Part of DASL tiles
226
1653
 
227
1654
  - [`@dasl/tiles`](../tiles) — meta-package re-exporting the whole toolkit