@dasl/tile-loader 2.6.0 → 3.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.
package/README.md CHANGED
@@ -34,18 +34,31 @@ document.body.append(await tile.renderCard()); // lightweight, metadata-only
34
34
  document.body.append(tile.renderContent()); // sandboxed iframe
35
35
  ```
36
36
 
37
+ A tile opens no window and its frame shows the tile and nothing else. A link
38
+ out of it is a request to your page, which opens nothing unless you say so:
39
+
40
+ ```js
41
+ import { tileLinks, linkPrompt } from '@dasl/tile-loader/link';
42
+ tileLinks(tile, { open: linkPrompt(document.querySelector('#under-the-tile')) });
43
+ ```
44
+
37
45
  `loadDomain` must point at a running [`@dasl/tile-server`](../tile-server) — that's
38
46
  the origin the sandboxed content is loaded from.
39
47
 
40
48
  ## Architecture
41
49
 
42
- Three cooperating layers, all talking over `postMessage`:
50
+ Four cooperating layers, all talking over `postMessage`:
43
51
 
44
52
  - **Mothership** (this module, in your page) — the entry point. You configure it
45
53
  with loaders, hand it a URL, and it produces a `Tile`. It holds all the
46
54
  privileged capabilities (fetching, file access via loaders); the other layers
47
55
  stay generic.
48
- - **Shuttle** (served by the tile server) — a sandboxed iframe on a fresh random
56
+ - **Dock** (served by the tile server, on its own host) — the frame the
57
+ mothership makes. It frames the shuttle on a fresh random origin and keeps it
58
+ there: the tile can script its shuttle but not the dock, whose policy lets
59
+ that frame be at the runtime's URL and nowhere else. It relays messages
60
+ between the mothership and that one shuttle.
61
+ - **Shuttle** (served by the tile server) — a sandboxed iframe on the tile's
49
62
  origin. It installs the service worker and hosts the inner iframe the tile
50
63
  renders into, shuttling messages between the worker and the mothership.
51
64
  - **Worker** (a service worker, served by the tile server) — intercepts the inner
@@ -58,6 +71,10 @@ Three cooperating layers, all talking over `postMessage`:
58
71
 
59
72
  - `conf.loadDomain`: the host of your tile server (defaults to `load.webtil.es`);
60
73
  give a full origin (`http://load.localhost:4321`) when it is not https on 443.
74
+ - `conf.tileHost`: a tile origin to run tiles on, by name
75
+ (`notes.tiles.example`), instead of a fresh random one per load; for a
76
+ deployment whose tiles share an origin or keep their storage. The tile server
77
+ has to recognise the name.
61
78
  - `conf.webrtcGuard`: `'exhaust'` (default) has the shuttle spend Chromium's
62
79
  per-process WebRTC budget before the tile loads (see Security model); `'none'`
63
80
  skips it, for hosts that block WebRTC themselves (an Electron app with the
@@ -77,6 +94,9 @@ Three cooperating layers, all talking over `postMessage`:
77
94
  (metadata only; safe to render many at once). `options.contentHeight` presets the
78
95
  height used when the card is clicked to expand.
79
96
  - **`renderContent(height?)`** — the sandboxed iframe that runs the tile.
97
+ - The **`stopped`** event (`ev.reason`: `blocked` or `navigated`) — the dock
98
+ stopped the tile because its runtime tried to leave its frame. The tile is
99
+ gone; render it again if you want it back.
80
100
  - **`sendProtocol(protocol, kind, payload?)`** and the **`protocol`** event
81
101
  (`ev.protocol`, `ev.kind`, `ev.payload`) — talk to the rendered tile over
82
102
  [tiles protocols](https://dasl.ing/tiles-protocols.html). The loader attaches
@@ -90,11 +110,22 @@ Three cooperating layers, all talking over `postMessage`:
90
110
  the tile what it got. `apply: false` is for a host that sizes its own box
91
111
  (it gets each request in `onRequest`); `width: 'tile'` hands the width over
92
112
  too. The rules are `resolveSize` in `@dasl/tile-lexicon`.
113
+ - For [tp-link](https://dasl.ing/tp-link.html), `@dasl/tile-loader/link` is
114
+ the context's side of a tile asking for a link to be opened:
115
+ `tileLinks(tile, { open })` calls `open(url, { activated, id })` for each
116
+ request (the user followed a link out of the tile, or the tile asked from
117
+ script) and tells the tile whether you opened it. Without `open`, nothing
118
+ opens. The URL is the tile's to choose, so show the user where it leads:
119
+ `linkPrompt(container)` is a handler that puts the whole address in
120
+ `container` as a link of your own for the user to follow, and refuses
121
+ requests made when the user had not touched the page. `openInNewTab(url)`
122
+ opens a web link cut off from your page. Only `http:` and `https:` reach
123
+ `open` unless you pass `schemes`.
93
124
  - For [tp-data](https://dasl.ing/tp-data.html), `@dasl/tile-loader/data` names
94
125
  the two kinds: `const data = tileData(tile)`, then `data.send(payload)`,
95
126
  `data.onData(fn)` and `data.onReady(fn)` (each `on…` returns a function that
96
- stops it). `Tile.sendData()` and the `data` / `data-ready` events still work
97
- and are deprecated: they go in the next major version.
127
+ stops it). `Tile.sendData()` and the `data` / `data-ready` events, deprecated
128
+ in 2.4, are gone in 3.0.
98
129
  - **`url`**, **`manifest`** — the tile's URL and MASL metadata.
99
130
 
100
131
  ### Loaders
@@ -125,7 +156,8 @@ A tile's origin is a dead end, by three layers that all read one policy
125
156
  every response it resolves with the tile CSP: `connect-src` for WebSocket,
126
157
  EventSource, beacons and WebTransport; `frame-src` and `form-action` for
127
158
  navigations to other origins; `webrtc 'block'` for the day browsers implement
128
- it; the `sandbox` flags; `X-DNS-Prefetch-Control: off`. A CSP the tile declares
159
+ it; the `sandbox` flags, with no popups and no top navigation;
160
+ `X-DNS-Prefetch-Control: off`. A CSP the tile declares
129
161
  stays and is enforced alongside. The worker's own improvised responses, and
130
162
  the server's 404s, carry a `default-src 'none'; sandbox` dead end.
131
163
  - **WebRTC is spent before the tile loads.** No browser implements CSP's
@@ -141,9 +173,22 @@ A tile's origin is a dead end, by three layers that all read one policy
141
173
  host that can block it at the engine level should (mollusc's `network:
142
174
  "loopback"`, say).
143
175
 
176
+ - **The runtime's frame goes nowhere.** The tile shares an origin with its
177
+ shuttle and can script it, into following a link for one. What governs where
178
+ a frame goes is its parent's `frame-src`, so the shuttle's parent is not
179
+ your page but the dock, on the tile server's own origin: its policy names the
180
+ runtime's URL on that tile's origin and nothing else, and it stops a tile
181
+ whose runtime tries to leave (the `stopped` event). A `frame-src` of your
182
+ own that only allows the tile server's host is a second lock on the same
183
+ door.
184
+ - **A tile opens nothing.** No popups in the sandbox, so no window to send
185
+ anywhere. A link out is a request over the link protocol, and your page
186
+ decides (`tileLinks`), opening it somewhere of its own.
187
+
144
188
  The mothership's side of the contract is to only ever answer a worker's
145
- `resolve-path` with `{ status, headers, body }`, and to act on protocol
146
- messages only from windows it created. [`@dasl/containment-tile`](../containment-tile)
189
+ `resolve-path` with `{ status, headers, body }`, to act on messages only from
190
+ the docks it created, on the tile server's origin, and to post to that origin
191
+ alone. [`@dasl/containment-tile`](../containment-tile)
147
192
  is the red-team tile that checks all of this end to end, in a real browser.
148
193
 
149
194
  ## Part of DASL tiles
package/dist/data.js CHANGED
@@ -12,8 +12,8 @@
12
12
  // data.onReady(() => data.send({ name: 'world' }));
13
13
  // const stop = data.onData((payload) => console.log(payload));
14
14
  //
15
- // It replaces `Tile.sendData()` and the `data` / `data-ready` events, which
16
- // the loader still has but deprecates.
15
+ // (Before 3.0 the loader had `Tile.sendData()` and `data` / `data-ready`
16
+ // events for this. They are gone: this module is the way.)
17
17
  /** The tiles protocol this module speaks. */
18
18
  export const DATA_PROTOCOL = 'data';
19
19
  /** tp-data on a tile: send it payloads, hear the ones it sends and when it is ready. */
package/dist/data.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"data.js","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,0EAA0E;AAC1E,wBAAwB;AACxB,EAAE;AACF,+EAA+E;AAC/E,yEAAyE;AACzE,6EAA6E;AAC7E,4DAA4D;AAC5D,EAAE;AACF,uDAAuD;AACvD,iCAAiC;AACjC,sDAAsD;AACtD,iEAAiE;AACjE,EAAE;AACF,4EAA4E;AAC5E,uCAAuC;AAIvC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AAWpC,wFAAwF;AACxF,MAAM,UAAU,QAAQ,CAAE,IAAU;IAClC,MAAM,EAAE,GAAG,CAAC,IAAY,EAAE,OAAmC,EAAE,EAAE;QAC/D,MAAM,QAAQ,GAAG,CAAC,EAAS,EAAE,EAAE;YAC7B,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAmB,CAAC;YAC7D,IAAI,QAAQ,KAAK,aAAa,IAAI,GAA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,IAAI;gBAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACnE,CAAC,CAAC;QACF,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC5C,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC9D,CAAC,CAAC;IACF,OAAO;QACL,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC;QACvE,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC;QAC3C,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;KACnD,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -2,6 +2,14 @@ import type { AnyMasl, MaslHeaders, MaslResponse } from "@dasl/tile-lexicon";
2
2
  export interface MothershipConfig {
3
3
  /** Host of the loading server (`load.webtil.es`), with a scheme and port when not https://. */
4
4
  loadDomain?: string;
5
+ /**
6
+ * The tile origin to run tiles on, as a host (`notes.tiles.example`, with
7
+ * the port if there is one), instead of a fresh random one for every load.
8
+ * For a deployment that means tiles to share an origin or to find their
9
+ * storage again; the loading server has to know the name as one of its tile
10
+ * origins. Leave it out and every tile gets an origin of its own.
11
+ */
12
+ tileHost?: string;
5
13
  /**
6
14
  * Whether the shuttle spends the renderer's WebRTC budget before the tile
7
15
  * loads (the default). A host that blocks WebRTC itself (an Electron app with
@@ -15,20 +23,21 @@ export interface TileLoader {
15
23
  export interface TilePathLoader {
16
24
  resolvePath(path: string): Promise<MaslResponse>;
17
25
  }
26
+ /**
27
+ * The dock stopped a tile, because its runtime tried to leave the frame it
28
+ * runs in: `blocked` when the navigation was refused, `navigated` when the
29
+ * frame loaded something else all the same. The tile is gone either way; a
30
+ * host that wants it back renders it again.
31
+ */
32
+ export interface StoppedEvent extends Event {
33
+ reason: 'blocked' | 'navigated';
34
+ }
18
35
  /** A tiles-protocol message from a tile: `protocol` ("data"), `kind` ("payload", "ready"), and its `payload`. The mothership attaches no meaning to any of them. */
19
36
  export interface ProtocolEvent extends Event {
20
37
  protocol: string;
21
38
  kind: string;
22
39
  payload: unknown;
23
40
  }
24
- /**
25
- * A tp-data message from a tile; `payload` is what the tile sent.
26
- * @deprecated The `data` and `data-ready` events go in the next major
27
- * version. Use `tileData()` from `@dasl/tile-loader/data`, or the `protocol` event.
28
- */
29
- export interface DataEvent extends Event {
30
- payload: unknown;
31
- }
32
41
  export declare class TileMothership {
33
42
  #private;
34
43
  constructor(conf?: MothershipConfig);
@@ -45,6 +54,12 @@ export declare class TileMothership {
45
54
  startShuttle(id: string): void;
46
55
  addLoader(loader: TileLoader): void;
47
56
  removeLoader(loader: TileLoader): void;
57
+ /** The origin of the loading server: where the dock is, and so who we talk to. */
58
+ getLoadOrigin(): string;
59
+ /**
60
+ * What a tile's frame loads: the dock, on the loading server. Asked like
61
+ * this it picks a fresh origin for the tile and frames the runtime there.
62
+ */
48
63
  getLoadSource(): string;
49
64
  loadTile(url: string): Promise<Tile | false>;
50
65
  }
@@ -64,12 +79,6 @@ export declare class Tile extends EventTarget {
64
79
  * means is up to the caller (see `@dasl/tile-loader/data` for tp-data).
65
80
  */
66
81
  sendProtocol(protocol: string, kind: string, payload?: unknown): void;
67
- /**
68
- * Sends a tp-data payload to the tile (https://dasl.ing/tp-data.html).
69
- * @deprecated Goes in the next major version. Use `tileData(tile).send()`
70
- * from `@dasl/tile-loader/data`, or `sendProtocol('data', 'payload', payload)`.
71
- */
72
- sendData(payload: unknown): void;
73
82
  attachIframe(ifr: HTMLIFrameElement): void;
74
83
  renderContent(height?: number): HTMLIFrameElement;
75
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[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GAAG,OAAO,CAAC,YAAY,CAAC;IAIjD,UAAU,CAAE,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAgD7E,aAAa,IAAK,MAAM;IAGxB;;;;OAIG;IACH,YAAY,CAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAI/D,YAAY,CAAE,GAAG,EAAE,iBAAiB;IAIpC,aAAa,CAAE,MAAM,SAAM,GAAG,iBAAiB;CAahD"}
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
  ╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝
8
8
  •--~~~## MOTHERSHIP ##~~~--•
9
9
 
10
- The tile-loading architecture has three levels that all communicate together:
10
+ The tile-loading architecture has four levels that all communicate together:
11
11
 
12
12
  - At the top, the MOTHERSHIP. This has access to things in the real world like
13
13
  fetching from the internet or reading from the file system. It's the interface
@@ -17,7 +17,14 @@ The tile-loading architecture has three levels that all communicate together:
17
17
  the configurability so that the other components can be deployed in entirely
18
18
  generic ways.
19
19
  - The mothership instantiates tiles by creating insulated contexts (a sandboxed
20
- iframe, an incognito window…) and loading a SHUTTLE in it. The role of the
20
+ iframe, an incognito window…) and loading the DOCK in it: a page on the
21
+ loading server's own origin, which frames the shuttle on the tile's origin
22
+ and keeps it there. The tile can script its shuttle but not the dock, so
23
+ the dock is what holds the frame in place (it can be navigated nowhere),
24
+ keeps everything below it from opening windows, and passes messages only
25
+ between the mothership and that one shuttle. The mothership only ever
26
+ talks to the dock.
27
+ - In the dock, the SHUTTLE. The role of the
21
28
  shuttle is to set up a service worker and an iframe to load the root of the
22
29
  tile into. It only exists because you need something to carry a service worker
23
30
  in. The only other thing that it does is (*drumroll*) shuttle messages back
@@ -27,7 +34,7 @@ The tile-loading architecture has three levels that all communicate together:
27
34
  requests up, which the shuttle then hands over to the mothership.
28
35
  */
29
36
  import { el } from "./lib/el.js";
30
- import { tileResponseHeaders } from "@dasl/tile-lexicon";
37
+ import { tileResponseHeaders, dockPath } from "@dasl/tile-lexicon";
31
38
  const TILES_PFX = 'tiles-';
32
39
  const SHUTTLE_PFX = 'tiles-shuttle-';
33
40
  const SND_SHUTTLE_LOAD = `${SHUTTLE_PFX}load`; // tell worker to roll
@@ -40,12 +47,15 @@ const RCV_WORKER_READY = `${WORKER_PFX}ready`; // worker ready
40
47
  const RCV_WORKER_REQUEST = `${WORKER_PFX}request`; // worker requested something
41
48
  const SND_WORKER_RESPONSE = `${WORKER_PFX}response`; // respond to a worker
42
49
  const TILES_WARNING = `${TILES_PFX}warn`; // worker warnings
43
- const TILES_ERROR = `${TILES_PFX}error`; // shuttle errors
50
+ const TILES_ERROR = `${SHUTTLE_PFX}error`; // shuttle errors
51
+ const RCV_DOCK_STOPPED = 'tiles-dock-stopped'; // the dock stopped the tile
44
52
  // Tiles protocols (https://dasl.ing/tp-data.html and friends): the shuttle
45
53
  // relays `tiles-protocol-up-<protocol>-<kind>` from the tile to us, and
46
54
  // `tiles-protocol-down-<protocol>-<kind>` from us to the tile.
47
55
  const PROTOCOL_UP = 'tiles-protocol-up-';
48
56
  const PROTOCOL_DOWN = 'tiles-protocol-down-';
57
+ // Warnings and errors come as a list; anything else is logged as it is.
58
+ const asList = (msg) => (Array.isArray(msg) ? msg : [msg]);
49
59
  export class TileMothership {
50
60
  #loaders = [];
51
61
  #conf;
@@ -57,33 +67,47 @@ export class TileMothership {
57
67
  init() {
58
68
  window.addEventListener('message', async (ev) => {
59
69
  const { action } = ev.data || {};
70
+ if (typeof action !== 'string')
71
+ return;
72
+ // Any frame can post a message, and say anything in it: the window
73
+ // it comes from says which tile is talking. That window is the tile's
74
+ // dock, on the loading server's origin, and it stays there; a message
75
+ // from one of our frames that is somewhere else is not from a dock.
76
+ // Messages still carry an id; we don't read it.
77
+ const id = this.#idForWindow(ev.source);
78
+ if (!id || ev.origin !== this.getLoadOrigin())
79
+ return;
80
+ const tile = this.#id2tile.get(id);
60
81
  if (action === TILES_WARNING) {
61
- const { msg, id } = ev.data;
62
- console.warn(`[W:${id}]`, ...msg);
82
+ console.warn(`[W:${id}]`, ...asList(ev.data.msg));
63
83
  }
64
- if (action === TILES_ERROR) {
65
- const { msg, id } = ev.data;
66
- console.error(`[S:${id}]`, ...msg);
84
+ else if (action === TILES_ERROR) {
85
+ console.error(`[S:${id}]`, ...asList(ev.data.msg));
86
+ }
87
+ else if (action === RCV_DOCK_STOPPED) {
88
+ const reason = ev.data.payload?.reason === 'blocked' ? 'blocked' : 'navigated';
89
+ console.error(`[D:${id}] The tile's runtime tried to navigate (${reason}); the tile was stopped.`);
90
+ tile.dispatchEvent(Object.assign(new Event('stopped'), { reason }));
67
91
  }
68
92
  else if (action === RCV_SHUTTLE_READY) {
69
- const { id } = ev.data;
70
93
  this.sendToShuttle(id, SND_WORKER_LOAD, { id });
71
94
  }
72
95
  else if (action === RCV_WORKER_READY) {
73
- const { id } = ev.data;
74
- const tile = this.#id2tile.get(id);
75
- if (!tile)
76
- throw new Error(`No tile shuttle with ID ${id}`);
77
96
  tile.dispatchEvent(new Event('load'));
78
97
  }
79
98
  else if (action === RCV_WORKER_REQUEST) {
80
- const { type, id, payload } = ev.data;
99
+ const { type, payload } = ev.data;
81
100
  if (type === 'resolve-path') {
82
101
  const { path, requestId } = payload;
83
- const tile = this.#id2tile.get(id);
84
- if (!tile)
85
- throw new Error(`No tile shuttle with ID ${id}`);
86
- const res = await tile.resolvePath(path);
102
+ let res;
103
+ try {
104
+ res = await tile.resolvePath(path);
105
+ }
106
+ catch (err) {
107
+ // Answer all the same, or the worker waits for ever.
108
+ console.error(`Could not resolve ${path}:`, err);
109
+ res = { ok: false, status: 502, statusText: 'Bad Gateway' };
110
+ }
87
111
  // Every document the worker serves, 404s included, carries the
88
112
  // policy: the tile can script anything on its origin, so nothing
89
113
  // on it may be unconfined.
@@ -93,12 +117,7 @@ export class TileMothership {
93
117
  this.sendToShuttle(id, SND_WORKER_RESPONSE, { requestId, response });
94
118
  }
95
119
  }
96
- else if (typeof action === 'string' && action.startsWith(PROTOCOL_UP)) {
97
- // Protocol messages carry no id: the shuttle window they come from
98
- // says which tile is talking, and nothing else gets to pretend.
99
- const tile = this.tileForWindow(ev.source);
100
- if (!tile)
101
- return;
120
+ else if (action.startsWith(PROTOCOL_UP)) {
102
121
  const rest = action.slice(PROTOCOL_UP.length);
103
122
  const dash = rest.indexOf('-');
104
123
  if (dash < 1)
@@ -107,11 +126,6 @@ export class TileMothership {
107
126
  const kind = rest.slice(dash + 1);
108
127
  const { payload } = ev.data;
109
128
  tile.dispatchEvent(Object.assign(new Event('protocol'), { protocol, kind, payload }));
110
- // Deprecated: tp-data also raised as events of its own, until the
111
- // next major version (see @dasl/tile-loader/data).
112
- if (protocol === 'data') {
113
- tile.dispatchEvent(Object.assign(new Event(kind === 'payload' ? 'data' : `data-${kind}`), { payload }));
114
- }
115
129
  }
116
130
  });
117
131
  }
@@ -124,18 +138,26 @@ export class TileMothership {
124
138
  return tileResponseHeaders(headers);
125
139
  }
126
140
  tileForWindow(source) {
141
+ const id = this.#idForWindow(source);
142
+ if (id)
143
+ return this.#id2tile.get(id);
144
+ }
145
+ #idForWindow(source) {
127
146
  if (!source)
128
147
  return;
129
148
  for (const [id, ifr] of this.#id2shuttle) {
130
149
  if (ifr.contentWindow === source)
131
- return this.#id2tile.get(id);
150
+ return id;
132
151
  }
133
152
  }
134
153
  sendToShuttle(id, action, payload) {
135
154
  const ifr = this.#id2shuttle.get(id);
136
155
  if (!ifr)
137
156
  return console.error(`No shuttle for ID ${id}`);
138
- ifr.contentWindow?.postMessage({ id, action, payload }, '*');
157
+ // To the dock and no one else: should the frame ever be anywhere but on
158
+ // the loading server, what we say (the tile's documents, the host's
159
+ // data) does not go with it.
160
+ ifr.contentWindow?.postMessage({ id, action, payload }, this.getLoadOrigin());
139
161
  }
140
162
  registerShuttleFrame(ifr, tile) {
141
163
  const id = crypto.randomUUID(); // we might want to make that pluggable
@@ -159,10 +181,20 @@ export class TileMothership {
159
181
  removeLoader(loader) {
160
182
  this.#loaders = this.#loaders.filter(ldr => ldr !== loader);
161
183
  }
162
- getLoadSource() {
184
+ /** The origin of the loading server: where the dock is, and so who we talk to. */
185
+ getLoadOrigin() {
163
186
  const domain = this.#conf.loadDomain || 'load.webtil.es';
164
- const base = /^https?:\/\//.test(domain) ? domain : `https://${domain}`;
165
- return new URL('/.well-known/web-tiles/', base).href;
187
+ return new URL(/^https?:\/\//.test(domain) ? domain : `https://${domain}`).origin;
188
+ }
189
+ /**
190
+ * What a tile's frame loads: the dock, on the loading server. Asked like
191
+ * this it picks a fresh origin for the tile and frames the runtime there.
192
+ */
193
+ getLoadSource() {
194
+ const url = new URL(dockPath, this.getLoadOrigin());
195
+ if (this.#conf.tileHost)
196
+ url.searchParams.set('tile', this.#conf.tileHost);
197
+ return url.href;
166
198
  }
167
199
  // Load a tile.
168
200
  async loadTile(url) {
@@ -269,14 +301,6 @@ export class Tile extends EventTarget {
269
301
  throw new Error('The tile is not rendered yet.');
270
302
  this.#mothership.sendToShuttle(this.#shuttleId, `${PROTOCOL_DOWN}${protocol}-${kind}`, payload);
271
303
  }
272
- /**
273
- * Sends a tp-data payload to the tile (https://dasl.ing/tp-data.html).
274
- * @deprecated Goes in the next major version. Use `tileData(tile).send()`
275
- * from `@dasl/tile-loader/data`, or `sendProtocol('data', 'payload', payload)`.
276
- */
277
- sendData(payload) {
278
- this.sendProtocol('data', 'payload', payload);
279
- }
280
304
  attachIframe(ifr) {
281
305
  this.#shuttleId = this.#mothership.registerShuttleFrame(ifr, this);
282
306
  ifr.addEventListener('load', () => this.#mothership.startShuttle(this.#shuttleId));
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BE;AAEF,OAAO,EAAE,EAAE,EAAE,MAAM,a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AAE,CAAC,QAAQ,EAAE;YACvB,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE;YACrC,KAAK,EAAE;gBACL,OAAO,EAAE,OAAO;gBAChB,KAAK,EAAE,MAAM;gBACb,MAAM,EAAE,GAAG,MAAM,IAAI;gBACrB,MAAM,EAAE,MAAM;aACf;SACF,CAAsB,CAAC;QACxB,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACvB,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
package/dist/link.d.ts ADDED
@@ -0,0 +1,61 @@
1
+ import type { Tile } from './index.js';
2
+ /** The tiles protocol this module speaks. */
3
+ export declare const LINK_PROTOCOL = "link";
4
+ export interface LinkRequest {
5
+ /**
6
+ * Whether the user has just interacted with the page (a click in the tile
7
+ * counts for the page framing it). False means the tile is asking by
8
+ * itself; a host has every reason to refuse then.
9
+ */
10
+ activated: boolean;
11
+ /**
12
+ * Set when the tile asked from script and waits for an answer. A handler
13
+ * that returns nothing answers later itself, with
14
+ * `tile.sendProtocol('link', 'result', { id, opened })`.
15
+ */
16
+ id?: string;
17
+ }
18
+ /**
19
+ * Decides about one link: `true` if the host opened it, `false` if it did
20
+ * not. A host that answers the tile itself, later, returns nothing.
21
+ */
22
+ export type LinkHandler = (url: URL, request: LinkRequest) => boolean | void | Promise<boolean | void>;
23
+ export interface TileLinksOptions {
24
+ /** What to do with a link the tile asks for. Without one, nothing opens. */
25
+ open?: LinkHandler;
26
+ /** The URL schemes that reach `open`; any other is refused. Default: `http:` and `https:`. */
27
+ schemes?: string[];
28
+ }
29
+ export interface TileLinksControl {
30
+ /** Stops listening. Links out of the tile then do nothing, and go unanswered. */
31
+ stop(): void;
32
+ }
33
+ /** Hears a rendered tile's requests to open links, and answers them. */
34
+ export declare function tileLinks(tile: Tile, options?: TileLinksOptions): TileLinksControl;
35
+ /**
36
+ * Opens `url` in a new tab or window, cut off from the page that opens it (no
37
+ * opener, no referrer). Only `http:` and `https:`. Browsers only allow it
38
+ * right after the user did something, so call it from a click of theirs.
39
+ */
40
+ export declare function openInNewTab(url: URL): boolean;
41
+ export interface LinkPromptOptions {
42
+ /** The words before the destination. Default: "This tile wants to open". */
43
+ label?: string;
44
+ /** The word on the button that refuses. Default: "Dismiss". */
45
+ dismiss?: string;
46
+ }
47
+ /**
48
+ * A link handler that leaves it to the user: it shows, in `container`, where
49
+ * the tile wants to go, as a link of the host's own that the user can follow,
50
+ * with a button to dismiss it. The whole address is shown, since the address
51
+ * is where a tile would hide what it wants to send out. Nothing opens unless
52
+ * the user follows the link, and it opens in a new tab, never in the tile.
53
+ *
54
+ * A request that arrives when the user has not touched the page is refused
55
+ * outright, and a new request replaces one still showing.
56
+ *
57
+ * The prompt is plain elements with a few class names (`tile-link-prompt`,
58
+ * `tile-link-url`, `tile-link-dismiss`) for a host to style.
59
+ */
60
+ export declare function linkPrompt(container: HTMLElement, options?: LinkPromptOptions): LinkHandler;
61
+ //# sourceMappingURL=link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAiB,IAAI,EAAE,MAAM,YAAY,CAAC;AAEtD,6CAA6C;AAC7C,eAAO,MAAM,aAAa,SAAS,CAAC;AAKpC,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,SAAS,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;AAEvG,MAAM,WAAW,gBAAgB;IAC/B,4EAA4E;IAC5E,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,8FAA8F;IAC9F,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,iFAAiF;IACjF,IAAI,IAAK,IAAI,CAAC;CACf;AAED,wEAAwE;AACxE,wBAAgB,SAAS,CAAE,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,gBAAqB,GAAG,gBAAgB,CA6CvF;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAI/C;AAED,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAE,SAAS,EAAE,WAAW,EAAE,OAAO,GAAE,iBAAsB,GAAG,WAAW,CAsChG"}