@dasl/tile-loader 2.0.0 → 2.2.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 +42 -7
- package/dist/at.d.ts +6 -1
- package/dist/at.d.ts.map +1 -1
- package/dist/at.js +17 -11
- package/dist/at.js.map +1 -1
- package/dist/car.d.ts +2 -2
- package/dist/car.d.ts.map +1 -1
- package/dist/car.js +2 -2
- package/dist/car.js.map +1 -1
- package/dist/content-scheme.d.ts +5 -1
- package/dist/content-scheme.d.ts.map +1 -1
- package/dist/content-scheme.js +4 -5
- package/dist/content-scheme.js.map +1 -1
- package/dist/index.d.ts +37 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -4
- package/dist/index.js.map +1 -1
- package/dist/webxdc.d.ts +2 -2
- package/dist/webxdc.d.ts.map +1 -1
- package/dist/webxdc.js +2 -2
- package/dist/webxdc.js.map +1 -1
- package/package.json +3 -3
- package/src/at.ts +20 -11
- package/src/car.ts +3 -3
- package/src/content-scheme.ts +9 -2
- package/src/index.ts +83 -7
- package/src/webxdc.ts +3 -3
package/README.md
CHANGED
|
@@ -56,12 +56,20 @@ Three cooperating layers, all talking over `postMessage`:
|
|
|
56
56
|
|
|
57
57
|
### `new TileMothership(conf?)`
|
|
58
58
|
|
|
59
|
-
`conf.loadDomain
|
|
59
|
+
- `conf.loadDomain`: the host of your tile server (defaults to `load.webtil.es`);
|
|
60
|
+
give a full origin (`http://load.localhost:4321`) when it is not https on 443.
|
|
61
|
+
- `conf.webrtcGuard`: `'exhaust'` (default) has the shuttle spend Chromium's
|
|
62
|
+
per-process WebRTC budget before the tile loads (see Security model); `'none'`
|
|
63
|
+
skips it, for hosts that block WebRTC themselves (an Electron app with the
|
|
64
|
+
policy switches set, say).
|
|
60
65
|
|
|
61
66
|
- **`init()`** — wire up the message plumbing. Call once.
|
|
62
67
|
- **`addLoader(loader)`** / **`removeLoader(loader)`** — register a loader (below).
|
|
63
68
|
Loaders are tried in order until one returns a tile.
|
|
64
69
|
- **`await loadTile(url)`** — returns a `Tile`, or `false` if no loader matched.
|
|
70
|
+
- **`hardenResponse(headers)`** — the headers every tile document ships with: the
|
|
71
|
+
resource's own plus the policy from `@dasl/tile-lexicon`. Override to add
|
|
72
|
+
more, never to remove.
|
|
65
73
|
|
|
66
74
|
### `Tile`
|
|
67
75
|
|
|
@@ -69,6 +77,10 @@ Three cooperating layers, all talking over `postMessage`:
|
|
|
69
77
|
(metadata only; safe to render many at once). `options.contentHeight` presets the
|
|
70
78
|
height used when the card is clicked to expand.
|
|
71
79
|
- **`renderContent(height?)`** — the sandboxed iframe that runs the tile.
|
|
80
|
+
- **`sendData(payload)`** / **`sendProtocol(protocol, kind, payload)`** — talk to
|
|
81
|
+
the rendered tile over [tiles protocols](https://dasl.ing/tp-data.html). What the
|
|
82
|
+
tile sends up arrives as `protocol` events (`ev.protocol`, `ev.kind`,
|
|
83
|
+
`ev.payload`) and, for tp-data, as `data` / `data-ready` events (`ev.payload`).
|
|
72
84
|
- **`url`**, **`manifest`** — the tile's URL and MASL metadata.
|
|
73
85
|
|
|
74
86
|
### Loaders
|
|
@@ -88,12 +100,35 @@ are exported from the package root for writing your own.
|
|
|
88
100
|
|
|
89
101
|
## Security model
|
|
90
102
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
103
|
+
A tile's origin is a dead end, by three layers that all read one policy
|
|
104
|
+
([`@dasl/tile-lexicon`](../tile-lexicon)):
|
|
105
|
+
|
|
106
|
+
- **The worker answers everything.** Every request a tile document makes goes
|
|
107
|
+
to its service worker, which asks the mothership to resolve the path against
|
|
108
|
+
the tile's manifest and answers with that, or a 404. `fetch`, XHR, scripts,
|
|
109
|
+
styles, images, fonts, frames: all tile content, never the network.
|
|
110
|
+
- **The document refuses what the worker cannot see.** The mothership stamps
|
|
111
|
+
every response it resolves with the tile CSP: `connect-src` for WebSocket,
|
|
112
|
+
EventSource, beacons and WebTransport; `frame-src` and `form-action` for
|
|
113
|
+
navigations to other origins; `webrtc 'block'` for the day browsers implement
|
|
114
|
+
it; the `sandbox` flags; `X-DNS-Prefetch-Control: off`. A CSP the tile declares
|
|
115
|
+
stays and is enforced alongside. The worker's own improvised responses, and
|
|
116
|
+
the server's 404s, carry a `default-src 'none'; sandbox` dead end.
|
|
117
|
+
- **WebRTC is spent before the tile loads.** No browser implements CSP's
|
|
118
|
+
`webrtc` directive yet, and ICE is not a fetch. Chromium caps a renderer
|
|
119
|
+
process at 500 `RTCPeerConnection`s and only frees a slot when the object is
|
|
120
|
+
destroyed, so the shuttle creates and holds 500 closed ones (a few hundred
|
|
121
|
+
milliseconds; the trick Delta Chat uses for webxdc). The tile, and any frame
|
|
122
|
+
or popup it opens in that process, gets "Cannot create so many
|
|
123
|
+
PeerConnections". Firefox and Safari have no such cap: there, WebRTC egress
|
|
124
|
+
(STUN/TURN hostnames, TURN credentials) stays open from a browser page, and a
|
|
125
|
+
host that can block it at the engine level should (mollusc's `network:
|
|
126
|
+
"loopback"`, say).
|
|
127
|
+
|
|
128
|
+
The mothership's side of the contract is to only ever answer a worker's
|
|
129
|
+
`resolve-path` with `{ status, headers, body }`, and to act on protocol
|
|
130
|
+
messages only from windows it created. [`@dasl/containment-tile`](../containment-tile)
|
|
131
|
+
is the red-team tile that checks all of this end to end, in a real browser.
|
|
97
132
|
|
|
98
133
|
## Part of DASL tiles
|
|
99
134
|
|
package/dist/at.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { Tile } from "./index.js";
|
|
2
2
|
import type { TileMothership } from "./index.js";
|
|
3
3
|
import type { StoredMasl, MaslResponse } from "@dasl/tile-lexicon";
|
|
4
|
+
import type { LoaderOptions } from "./content-scheme.js";
|
|
5
|
+
type Fetch = typeof globalThis.fetch;
|
|
4
6
|
export declare class ATTileLoader {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(options?: LoaderOptions);
|
|
5
9
|
load(url: string, mothership: TileMothership): Promise<Tile | false | undefined>;
|
|
6
10
|
}
|
|
7
11
|
export declare class ATPathLoader {
|
|
8
12
|
#private;
|
|
9
|
-
constructor(did: string, manifest: StoredMasl);
|
|
13
|
+
constructor(did: string, manifest: StoredMasl, fetch?: Fetch);
|
|
10
14
|
resolvePath(path: string): Promise<MaslResponse>;
|
|
11
15
|
}
|
|
16
|
+
export {};
|
|
12
17
|
//# sourceMappingURL=at.d.ts.map
|
package/dist/at.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"at.d.ts","sourceRoot":"","sources":["../src/at.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"at.d.ts","sourceRoot":"","sources":["../src/at.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,KAAK,KAAK,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC;AAuCrC,qBAAa,YAAY;;gBAEV,OAAO,GAAE,aAAkB;IAGlC,IAAI,CAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,GAAG,SAAS,CAAC;CAWxF;AACD,qBAAa,YAAY;;gBAIV,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,GAAE,KAA8C;IAK/F,WAAW,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CASxD"}
|
package/dist/at.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Tile } from "./index.js";
|
|
2
2
|
import { NOT_FOUND, maslResponse } from "./lib/masl.js";
|
|
3
|
-
async function did2pds(did) {
|
|
3
|
+
async function did2pds(fetch, did) {
|
|
4
4
|
if (!/^did:plc:/.test(did))
|
|
5
5
|
return false; // we should add did:web
|
|
6
6
|
const res = await fetch(`https://plc.directory/${did}`);
|
|
@@ -10,8 +10,8 @@ async function did2pds(did) {
|
|
|
10
10
|
const pds = doc.service?.find(s => s.id === '#atproto_pds')?.serviceEndpoint;
|
|
11
11
|
return pds;
|
|
12
12
|
}
|
|
13
|
-
async function fetchFromPDS(did, query, params) {
|
|
14
|
-
const pds = await did2pds(did);
|
|
13
|
+
async function fetchFromPDS(fetch, did, query, params) {
|
|
14
|
+
const pds = await did2pds(fetch, did);
|
|
15
15
|
if (!pds)
|
|
16
16
|
return;
|
|
17
17
|
const url = new URL(pds);
|
|
@@ -20,14 +20,14 @@ async function fetchFromPDS(did, query, params) {
|
|
|
20
20
|
Object.entries(params).forEach(([k, v]) => prm.set(k, v));
|
|
21
21
|
return await fetch(url.toString());
|
|
22
22
|
}
|
|
23
|
-
async function getRecord(repo, collection, rkey) {
|
|
24
|
-
const res = await fetchFromPDS(repo, 'com.atproto.repo.getRecord', { repo, collection, rkey });
|
|
23
|
+
async function getRecord(fetch, repo, collection, rkey) {
|
|
24
|
+
const res = await fetchFromPDS(fetch, repo, 'com.atproto.repo.getRecord', { repo, collection, rkey });
|
|
25
25
|
if (!res || !res.ok)
|
|
26
26
|
return false;
|
|
27
27
|
return await res.json();
|
|
28
28
|
}
|
|
29
|
-
async function getBlob(did, cid) {
|
|
30
|
-
const res = await fetchFromPDS(did, 'com.atproto.sync.getBlob', { did, cid });
|
|
29
|
+
async function getBlob(fetch, did, cid) {
|
|
30
|
+
const res = await fetchFromPDS(fetch, did, 'com.atproto.sync.getBlob', { did, cid });
|
|
31
31
|
if (!res || !res.ok)
|
|
32
32
|
return false;
|
|
33
33
|
return await res.arrayBuffer();
|
|
@@ -35,28 +35,34 @@ async function getBlob(did, cid) {
|
|
|
35
35
|
// ### AT Loader
|
|
36
36
|
// at://did:plc:izttpdp3l6vss5crelt5kcux/ing.dasl.masl/3mceykgxbkk2r
|
|
37
37
|
export class ATTileLoader {
|
|
38
|
+
#fetch;
|
|
39
|
+
constructor(options = {}) {
|
|
40
|
+
this.#fetch = options.fetch ?? ((...args) => globalThis.fetch(...args));
|
|
41
|
+
}
|
|
38
42
|
async load(url, mothership) {
|
|
39
43
|
if (!/^at:\/\//.test(url))
|
|
40
44
|
return false;
|
|
41
45
|
const [repo, collection, rkey] = url.replace(/^at:\/\//, '').split('/');
|
|
42
46
|
if (collection !== 'ing.dasl.masl')
|
|
43
47
|
return;
|
|
44
|
-
const res = await getRecord(repo, collection, rkey);
|
|
48
|
+
const res = await getRecord(this.#fetch, repo, collection, rkey);
|
|
45
49
|
if (!res)
|
|
46
50
|
return false;
|
|
47
51
|
const manifest = res.value?.tile;
|
|
48
52
|
if (!manifest)
|
|
49
53
|
return false;
|
|
50
|
-
const loader = new ATPathLoader(repo, manifest);
|
|
54
|
+
const loader = new ATPathLoader(repo, manifest, this.#fetch);
|
|
51
55
|
return new Tile(mothership, url, manifest, loader);
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
export class ATPathLoader {
|
|
55
59
|
#did;
|
|
56
60
|
#manifest;
|
|
57
|
-
|
|
61
|
+
#fetch;
|
|
62
|
+
constructor(did, manifest, fetch = (...args) => globalThis.fetch(...args)) {
|
|
58
63
|
this.#did = did;
|
|
59
64
|
this.#manifest = manifest;
|
|
65
|
+
this.#fetch = fetch;
|
|
60
66
|
}
|
|
61
67
|
async resolvePath(path) {
|
|
62
68
|
const entry = this.#manifest?.resources?.[path];
|
|
@@ -64,7 +70,7 @@ export class ATPathLoader {
|
|
|
64
70
|
return NOT_FOUND;
|
|
65
71
|
const src = entry.src;
|
|
66
72
|
const cid = '$link' in src ? src.$link : src.ref.$link;
|
|
67
|
-
const data = await getBlob(this.#did, cid);
|
|
73
|
+
const data = await getBlob(this.#fetch, this.#did, cid);
|
|
68
74
|
if (!data)
|
|
69
75
|
return NOT_FOUND;
|
|
70
76
|
return maslResponse(entry, data);
|
package/dist/at.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"at.js","sourceRoot":"","sources":["../src/at.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"at.js","sourceRoot":"","sources":["../src/at.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAaxD,KAAK,UAAU,OAAO,CAAE,KAAY,EAAE,GAAW;IAC/C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC,CAAC,wBAAwB;IAClE,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,yBAAyB,GAAG,EAAE,CAAC,CAAC;IACxD,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;IAC1B,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,EAAiB,CAAC;IAC5C,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,cAAc,CAAC,EAAE,eAAe,CAAC;IAC7E,OAAO,GAAG,CAAC;AACb,CAAC;AACD,KAAK,UAAU,YAAY,CAAE,KAAY,EAAE,GAAW,EAAE,KAAa,EAAE,MAA8B;IACnG,MAAM,GAAG,GAAG,MAAM,OA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AS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,KAAK,CAAC,WAAW,CAAE,IAAY;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,KAAK,EAAE,GAAG;YAAE,OAAO,SAAS,CAAC;QAClC,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;QACtB,MAAM,GAAG,GAAG,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC;QACvD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,OAAO,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;CACF"}
|
package/dist/car.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ContentSchemeTileLoader } from "./content-scheme.js";
|
|
1
|
+
import { ContentSchemeTileLoader, type LoaderOptions } from "./content-scheme.js";
|
|
2
2
|
import { Tile } from "./index.js";
|
|
3
3
|
import type { TileMothership } from "./index.js";
|
|
4
4
|
import type { StoredMasl, MaslResponse } from "@dasl/tile-lexicon";
|
|
5
5
|
export declare class CARTileLoader extends ContentSchemeTileLoader {
|
|
6
|
-
constructor(schemes?: string[]);
|
|
6
|
+
constructor(schemes?: string[], options?: LoaderOptions);
|
|
7
7
|
processContent(carData: ArrayBuffer, scheme: string, url: string, mothership: TileMothership): Promise<Tile | false>;
|
|
8
8
|
}
|
|
9
9
|
export declare class CARPathLoader {
|
package/dist/car.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"car.d.ts","sourceRoot":"","sources":["../src/car.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"car.d.ts","sourceRoot":"","sources":["../src/car.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAW,MAAM,oBAAoB,CAAC;AAG5E,qBAAa,aAAc,SAAQ,uBAAuB;gBAC3C,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa;IAIlD,cAAc,CAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC;CA2B5H;AAED,qBAAa,aAAa;;gBAIX,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAK5F,WAAW,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAQxD"}
|
package/dist/car.js
CHANGED
|
@@ -5,8 +5,8 @@ import { Tile } from "./index.js";
|
|
|
5
5
|
import { NOT_FOUND, maslResponse } from "./lib/masl.js";
|
|
6
6
|
// ### CAR Tiles
|
|
7
7
|
export class CARTileLoader extends ContentSchemeTileLoader {
|
|
8
|
-
constructor(schemes) {
|
|
9
|
-
super(schemes);
|
|
8
|
+
constructor(schemes, options) {
|
|
9
|
+
super(schemes, options);
|
|
10
10
|
}
|
|
11
11
|
// NOTE: ignoring scheme for now, this is pure HTTP
|
|
12
12
|
async processContent(carData, scheme, url, mothership) {
|
package/dist/car.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"car.js","sourceRoot":"","sources":["../src/car.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,uBAAuB,
|
|
1
|
+
{"version":3,"file":"car.js","sourceRoot":"","sources":["../src/car.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAsB,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGxD,gBAAgB;AAChB,MAAM,OAAO,aAAc,SAAQ,uBAAuB;IACxD,YAAa,OAAkB,EAAE,OAAuB;QACtD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD,mDAAmD;IACnD,KAAK,CAAC,cAAc,CAAE,OAAoB,EAAE,MAAc,EAAE,GAAW,EAAE,UAA0B;QACjG,IAAI,GAAG,CAAC;QACR,IAAI,CAAC;YACH,GAAG,GAAG,cAAc,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACT,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACzB,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;QAC5B,MAAM,QAAQ,GAAG,IAAkB,CAAC;QACpC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C,CAAC;QAChD,IAAI,CAAC,KAAK,EAAE,GAAG;YAAE,OAAO,SAAS,CAAC;QAClC,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;QACtB,MAAM,GAAG,GAAG,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC;QACvD,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACxC,OAAO,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
package/dist/content-scheme.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { Tile, TileMothership } from "./index.js";
|
|
2
|
+
export interface LoaderOptions {
|
|
3
|
+
/** How to fetch: a host whose page has no network of its own routes these through its backend. */
|
|
4
|
+
fetch?: typeof globalThis.fetch;
|
|
5
|
+
}
|
|
2
6
|
export declare abstract class ContentSchemeTileLoader {
|
|
3
7
|
#private;
|
|
4
|
-
constructor(schemes?: string[]);
|
|
8
|
+
constructor(schemes?: string[], options?: LoaderOptions);
|
|
5
9
|
load(url: string, mothership: TileMothership): Promise<Tile | false | undefined>;
|
|
6
10
|
abstract processContent(data: ArrayBuffer, scheme: string, url: string, mothership: TileMothership): Promise<Tile | false>;
|
|
7
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-scheme.d.ts","sourceRoot":"","sources":["../src/content-scheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAKvD,8BAAsB,uBAAuB;;
|
|
1
|
+
{"version":3,"file":"content-scheme.d.ts","sourceRoot":"","sources":["../src/content-scheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAKvD,MAAM,WAAW,aAAa;IAC5B,kGAAkG;IAClG,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,8BAAsB,uBAAuB;;gBAG9B,OAAO,GAAE,MAAM,EAAqB,EAAE,OAAO,GAAE,aAAkB;IAIxE,IAAI,CAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,GAAG,SAAS,CAAC;IAkBvF,QAAQ,CAAC,cAAc,CAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC;CAC5H"}
|
package/dist/content-scheme.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
// ### Base Class for HTTP, file, etc. loaders
|
|
2
|
-
// Here the idea is that you can load from multiple schemes, but you might not
|
|
3
|
-
// want to.
|
|
4
1
|
export class ContentSchemeTileLoader {
|
|
5
2
|
#schemes;
|
|
6
|
-
|
|
3
|
+
#fetch;
|
|
4
|
+
constructor(schemes = ['http', 'file'], options = {}) {
|
|
7
5
|
this.#schemes = new Set(schemes);
|
|
6
|
+
this.#fetch = options.fetch ?? ((...args) => globalThis.fetch(...args));
|
|
8
7
|
}
|
|
9
8
|
async load(url, mothership) {
|
|
10
9
|
let u;
|
|
@@ -17,7 +16,7 @@ export class ContentSchemeTileLoader {
|
|
|
17
16
|
if (u.protocol === 'https:' || u.protocol === 'http:') {
|
|
18
17
|
if (!this.#schemes.has('http'))
|
|
19
18
|
return false;
|
|
20
|
-
const res = await fetch(url);
|
|
19
|
+
const res = await this.#fetch(url);
|
|
21
20
|
if (!res.ok)
|
|
22
21
|
return false;
|
|
23
22
|
return await this.processContent(await res.arrayBuffer(), u.protocol, url, mothership);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-scheme.js","sourceRoot":"","sources":["../src/content-scheme.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"content-scheme.js","sourceRoot":"","sources":["../src/content-scheme.ts"],"names":[],"mappings":"AAWA,MAAM,OAAgB,uBAAuB;IAC3C,QAAQ,CAAc;IACtB,MAAM,CAA0B;IAChC,YAAa,UAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,UAAyB,EAAE;QAC5E,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAC1E,CAAC;IACD,KAAK,CAAC,IAAI,CAAE,GAAW,EAAE,UAA0B;QACjD,IAAI,CAAM,CAAC;QACX,IAAI,CAAC;YAAC,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAAC,CAAC;QACzB,MAAM,CAAC;YAAC,OAAO,KAAK,CAAC;QAAC,CAAC,CAAC,kDAAkD;QAC1E,IAAI,CAAC,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YACtD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC7C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,OAAO,KAAK,CAAC;YAC1B,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;QACzF,CAAC;QACD,IAAI,CAAC,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YAC3B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC7C,MAAM;YACN,kBAAkB;YAClB,+BAA+B;QACjC,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CAEF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
|
-
import type { AnyMasl, MaslResponse } from "@dasl/tile-lexicon";
|
|
1
|
+
import type { AnyMasl, MaslHeaders, MaslResponse } from "@dasl/tile-lexicon";
|
|
2
|
+
export interface MothershipConfig {
|
|
3
|
+
/** Host of the loading server (`load.webtil.es`), with a scheme and port when not https://. */
|
|
4
|
+
loadDomain?: string;
|
|
5
|
+
/**
|
|
6
|
+
* Whether the shuttle spends the renderer's WebRTC budget before the tile
|
|
7
|
+
* loads (the default). A host that blocks WebRTC itself (an Electron app with
|
|
8
|
+
* the policy switches set, say) passes 'none' and skips the cost.
|
|
9
|
+
*/
|
|
10
|
+
webrtcGuard?: 'exhaust' | 'none';
|
|
11
|
+
}
|
|
2
12
|
export interface TileLoader {
|
|
3
13
|
load(url: string, mothership: TileMothership): Promise<Tile | false | undefined>;
|
|
4
14
|
}
|
|
5
15
|
export interface TilePathLoader {
|
|
6
16
|
resolvePath(path: string): Promise<MaslResponse>;
|
|
7
17
|
}
|
|
18
|
+
/** A tiles-protocol message from a tile: `protocol` ("data"), `kind` ("payload", "ready"), and its `payload`. */
|
|
19
|
+
export interface ProtocolEvent extends Event {
|
|
20
|
+
protocol: string;
|
|
21
|
+
kind: string;
|
|
22
|
+
payload: unknown;
|
|
23
|
+
}
|
|
24
|
+
/** A tp-data message from a tile; `payload` is what the tile sent. */
|
|
25
|
+
export interface DataEvent extends Event {
|
|
26
|
+
payload: unknown;
|
|
27
|
+
}
|
|
8
28
|
export declare class TileMothership {
|
|
9
29
|
#private;
|
|
10
|
-
constructor(conf?:
|
|
11
|
-
loadDomain?: string;
|
|
12
|
-
});
|
|
30
|
+
constructor(conf?: MothershipConfig);
|
|
13
31
|
init(): void;
|
|
32
|
+
/**
|
|
33
|
+
* The headers a tile document ships with: the resource's own, plus the
|
|
34
|
+
* policy from @dasl/tile-lexicon. A host that wants more on every response
|
|
35
|
+
* overrides this and calls super; nothing should ever return less.
|
|
36
|
+
*/
|
|
37
|
+
hardenResponse(headers?: MaslHeaders): MaslHeaders;
|
|
38
|
+
tileForWindow(source: MessageEventSource | null): Tile | undefined;
|
|
14
39
|
sendToShuttle(id: string, action: string, payload: unknown): void;
|
|
15
40
|
registerShuttleFrame(ifr: HTMLIFrameElement, tile: Tile): `${string}-${string}-${string}-${string}-${string}`;
|
|
16
41
|
startShuttle(id: string): void;
|
|
@@ -29,6 +54,14 @@ export declare class Tile extends EventTarget {
|
|
|
29
54
|
contentHeight?: number;
|
|
30
55
|
}): Promise<HTMLElement>;
|
|
31
56
|
getLoadSource(): string;
|
|
57
|
+
/**
|
|
58
|
+
* Sends a tiles-protocol message down to the rendered tile. Messages the
|
|
59
|
+
* tile sends up arrive as `protocol` events (and, for tp-data, as `data`
|
|
60
|
+
* and `data-ready` events) on this object.
|
|
61
|
+
*/
|
|
62
|
+
sendProtocol(protocol: string, kind: string, payload?: unknown): void;
|
|
63
|
+
/** Sends a tp-data payload to the tile (https://dasl.ing/tp-data.html). */
|
|
64
|
+
sendData(payload: unknown): void;
|
|
32
65
|
attachIframe(ifr: HTMLIFrameElement): void;
|
|
33
66
|
renderContent(height?: number): HTMLIFrameElement;
|
|
34
67
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW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AK,CAAC;CAOpD;AAED,qBAAa,IAAK,SAAQ,WAAW;;gBAMtB,UAAU,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc;IAoBnG,IAAI,GAAG,IAAK,MAAM,CAEjB;IACD,IAAI,QAAQ,IAAK,OAAO,CAEvB;IACK,WAAW,CAAE,IAAI,EAAE,MAAM,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,2EAA2E;IAC3E,QAAQ,CAAE,OAAO,EAAE,OAAO;IAG1B,YAAY,CAAE,GAAG,EAAE,iBAAiB;IAIpC,aAAa,CAAE,MAAM,SAAM,GAAG,iBAAiB;CAahD"}
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ The tile-loading architecture has three levels that all communicate together:
|
|
|
27
27
|
requests up, which the shuttle then hands over to the mothership.
|
|
28
28
|
*/
|
|
29
29
|
import { el } from "./lib/el.js";
|
|
30
|
+
import { tileResponseHeaders } from "@dasl/tile-lexicon";
|
|
30
31
|
const TILES_PFX = 'tiles-';
|
|
31
32
|
const SHUTTLE_PFX = 'tiles-shuttle-';
|
|
32
33
|
const SND_SHUTTLE_LOAD = `${SHUTTLE_PFX}load`; // tell worker to roll
|
|
@@ -40,6 +41,11 @@ const RCV_WORKER_REQUEST = `${WORKER_PFX}request`; // worker requested something
|
|
|
40
41
|
const SND_WORKER_RESPONSE = `${WORKER_PFX}response`; // respond to a worker
|
|
41
42
|
const TILES_WARNING = `${TILES_PFX}warn`; // worker warnings
|
|
42
43
|
const TILES_ERROR = `${TILES_PFX}error`; // shuttle errors
|
|
44
|
+
// Tiles protocols (https://dasl.ing/tp-data.html and friends): the shuttle
|
|
45
|
+
// relays `tiles-protocol-up-<protocol>-<kind>` from the tile to us, and
|
|
46
|
+
// `tiles-protocol-down-<protocol>-<kind>` from us to the tile.
|
|
47
|
+
const PROTOCOL_UP = 'tiles-protocol-up-';
|
|
48
|
+
const PROTOCOL_DOWN = 'tiles-protocol-down-';
|
|
43
49
|
export class TileMothership {
|
|
44
50
|
#loaders = [];
|
|
45
51
|
#conf;
|
|
@@ -78,14 +84,51 @@ export class TileMothership {
|
|
|
78
84
|
if (!tile)
|
|
79
85
|
throw new Error(`No tile shuttle with ID ${id}`);
|
|
80
86
|
const res = await tile.resolvePath(path);
|
|
87
|
+
// Every document the worker serves, 404s included, carries the
|
|
88
|
+
// policy: the tile can script anything on its origin, so nothing
|
|
89
|
+
// on it may be unconfined.
|
|
81
90
|
const response = res.ok
|
|
82
|
-
? { status: res.status, headers: res.headers, body: res.body }
|
|
83
|
-
: { status: res.status, headers:
|
|
91
|
+
? { status: res.status, headers: this.hardenResponse(res.headers), body: res.body }
|
|
92
|
+
: { status: res.status, headers: this.hardenResponse({ 'content-type': 'text/plain' }), body: undefined };
|
|
84
93
|
this.sendToShuttle(id, SND_WORKER_RESPONSE, { requestId, response });
|
|
85
94
|
}
|
|
86
95
|
}
|
|
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;
|
|
102
|
+
const rest = action.slice(PROTOCOL_UP.length);
|
|
103
|
+
const dash = rest.indexOf('-');
|
|
104
|
+
if (dash < 1)
|
|
105
|
+
return;
|
|
106
|
+
const protocol = rest.slice(0, dash);
|
|
107
|
+
const kind = rest.slice(dash + 1);
|
|
108
|
+
const { payload } = ev.data;
|
|
109
|
+
tile.dispatchEvent(Object.assign(new Event('protocol'), { protocol, kind, payload }));
|
|
110
|
+
if (protocol === 'data') {
|
|
111
|
+
tile.dispatchEvent(Object.assign(new Event(kind === 'payload' ? 'data' : `data-${kind}`), { payload }));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
87
114
|
});
|
|
88
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* The headers a tile document ships with: the resource's own, plus the
|
|
118
|
+
* policy from @dasl/tile-lexicon. A host that wants more on every response
|
|
119
|
+
* overrides this and calls super; nothing should ever return less.
|
|
120
|
+
*/
|
|
121
|
+
hardenResponse(headers) {
|
|
122
|
+
return tileResponseHeaders(headers);
|
|
123
|
+
}
|
|
124
|
+
tileForWindow(source) {
|
|
125
|
+
if (!source)
|
|
126
|
+
return;
|
|
127
|
+
for (const [id, ifr] of this.#id2shuttle) {
|
|
128
|
+
if (ifr.contentWindow === source)
|
|
129
|
+
return this.#id2tile.get(id);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
89
132
|
sendToShuttle(id, action, payload) {
|
|
90
133
|
const ifr = this.#id2shuttle.get(id);
|
|
91
134
|
if (!ifr)
|
|
@@ -99,7 +142,7 @@ export class TileMothership {
|
|
|
99
142
|
return id;
|
|
100
143
|
}
|
|
101
144
|
startShuttle(id) {
|
|
102
|
-
this.sendToShuttle(id, SND_SHUTTLE_LOAD, { id });
|
|
145
|
+
this.sendToShuttle(id, SND_SHUTTLE_LOAD, { id, webrtcGuard: this.#conf.webrtcGuard ?? 'exhaust' });
|
|
103
146
|
}
|
|
104
147
|
// Adds a loader that will handle matching requests to load a tile.
|
|
105
148
|
// - `loader` is an object that knows how to load a tile for a specific scheme
|
|
@@ -112,7 +155,9 @@ export class TileMothership {
|
|
|
112
155
|
this.#loaders = this.#loaders.filter(ldr => ldr !== loader);
|
|
113
156
|
}
|
|
114
157
|
getLoadSource() {
|
|
115
|
-
|
|
158
|
+
const domain = this.#conf.loadDomain || 'load.webtil.es';
|
|
159
|
+
const base = /^https?:\/\//.test(domain) ? domain : `https://${domain}`;
|
|
160
|
+
return new URL('/.well-known/web-tiles/', base).href;
|
|
116
161
|
}
|
|
117
162
|
// Load a tile.
|
|
118
163
|
async loadTile(url) {
|
|
@@ -209,6 +254,20 @@ export class Tile extends EventTarget {
|
|
|
209
254
|
getLoadSource() {
|
|
210
255
|
return this.#mothership.getLoadSource();
|
|
211
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Sends a tiles-protocol message down to the rendered tile. Messages the
|
|
259
|
+
* tile sends up arrive as `protocol` events (and, for tp-data, as `data`
|
|
260
|
+
* and `data-ready` events) on this object.
|
|
261
|
+
*/
|
|
262
|
+
sendProtocol(protocol, kind, payload) {
|
|
263
|
+
if (!this.#shuttleId)
|
|
264
|
+
throw new Error('The tile is not rendered yet.');
|
|
265
|
+
this.#mothership.sendToShuttle(this.#shuttleId, `${PROTOCOL_DOWN}${protocol}-${kind}`, payload);
|
|
266
|
+
}
|
|
267
|
+
/** Sends a tp-data payload to the tile (https://dasl.ing/tp-data.html). */
|
|
268
|
+
sendData(payload) {
|
|
269
|
+
this.sendProtocol('data', 'payload', payload);
|
|
270
|
+
}
|
|
212
271
|
attachIframe(ifr) {
|
|
213
272
|
this.#shuttleId = this.#mothership.registerShuttleFrame(ifr, this);
|
|
214
273
|
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,aAAa,CAAC;AAUjC,MAAM,SAAS,GAAG,QAAQ,CAAC;AAC3B,MAAM,WAAW,GAAG,gBAAgB,CAAC;AACrC,MAAM,gBAAgB,GAAG,GAAG,WAAW,MAAM,CAAC,CAAQ,sBAAsB;AAC5E,MAAM,iBAAiB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AAE;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/webxdc.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Tile } from "./index.js";
|
|
2
2
|
import type { TileMothership } from "./index.js";
|
|
3
|
-
import { ContentSchemeTileLoader } from "./content-scheme.js";
|
|
3
|
+
import { ContentSchemeTileLoader, type LoaderOptions } from "./content-scheme.js";
|
|
4
4
|
export declare class WebXDCTileLoader extends ContentSchemeTileLoader {
|
|
5
|
-
constructor(schemes?: string[]);
|
|
5
|
+
constructor(schemes?: string[], options?: LoaderOptions);
|
|
6
6
|
processContent(zipData: ArrayBuffer, _: string, url: string, mothership: TileMothership): Promise<Tile | false>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=webxdc.d.ts.map
|
package/dist/webxdc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webxdc.d.ts","sourceRoot":"","sources":["../src/webxdc.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"webxdc.d.ts","sourceRoot":"","sources":["../src/webxdc.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAWlF,qBAAa,gBAAiB,SAAQ,uBAAuB;gBAC9C,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa;IAGlD,cAAc,CAAE,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC;CAsCvH"}
|
package/dist/webxdc.js
CHANGED
|
@@ -12,8 +12,8 @@ import { MemoryPathLoader } from './memory.js';
|
|
|
12
12
|
// - It may have a manifest.toml (seriously), that may have a name entry and
|
|
13
13
|
// one pointing to the source.
|
|
14
14
|
export class WebXDCTileLoader extends ContentSchemeTileLoader {
|
|
15
|
-
constructor(schemes) {
|
|
16
|
-
super(schemes);
|
|
15
|
+
constructor(schemes, options) {
|
|
16
|
+
super(schemes, options);
|
|
17
17
|
}
|
|
18
18
|
async processContent(zipData, _, url, mothership) {
|
|
19
19
|
const zip = new JSZip();
|
package/dist/webxdc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webxdc.js","sourceRoot":"","sources":["../src/webxdc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,uBAAuB,
|
|
1
|
+
{"version":3,"file":"webxdc.js","sourceRoot":"","sources":["../src/webxdc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,uBAAuB,EAAsB,MAAM,qBAAqB,CAAC;AA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AkB;QAClB,OAAO;KACR,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dasl/tile-loader",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"description": "Browser architecture for safely loading DASL tiles (mothership, shuttle, worker)",
|
|
6
6
|
"author": "Robin Berjon <robin@berjon.com>",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"repository": {
|
|
55
55
|
"type": "git",
|
|
56
|
-
"url": "https://
|
|
56
|
+
"url": "https://tangled.org/robin.berjon.com/dasl-tiles",
|
|
57
57
|
"directory": "tile-loader"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@atcute/car": "^6.0.0",
|
|
66
66
|
"@atcute/cid": "^2.4.1",
|
|
67
|
-
"@dasl/tile-lexicon": "^2.
|
|
67
|
+
"@dasl/tile-lexicon": "^2.1.0",
|
|
68
68
|
"jszip": "^3.10.1",
|
|
69
69
|
"mime": "^4.1.0",
|
|
70
70
|
"smol-toml": "^1.6.1"
|
package/src/at.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { Tile } from "./index.js";
|
|
|
3
3
|
import type { TileMothership } from "./index.js";
|
|
4
4
|
import { NOT_FOUND, maslResponse } from "./lib/masl.js";
|
|
5
5
|
import type { StoredMasl, MaslResponse } from "@dasl/tile-lexicon";
|
|
6
|
+
import type { LoaderOptions } from "./content-scheme.js";
|
|
7
|
+
|
|
8
|
+
type Fetch = typeof globalThis.fetch;
|
|
6
9
|
|
|
7
10
|
interface DidDocument {
|
|
8
11
|
service?: Array<{ id?: string; type?: string; serviceEndpoint?: string }>;
|
|
@@ -11,7 +14,7 @@ interface ATRecord {
|
|
|
11
14
|
value?: { tile?: StoredMasl };
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
async function did2pds (did: string): Promise<string | false | undefined> {
|
|
17
|
+
async function did2pds (fetch: Fetch, did: string): Promise<string | false | undefined> {
|
|
15
18
|
if (!/^did:plc:/.test(did)) return false; // we should add did:web
|
|
16
19
|
const res = await fetch(`https://plc.directory/${did}`);
|
|
17
20
|
if (!res.ok) return false;
|
|
@@ -19,8 +22,8 @@ async function did2pds (did: string): Promise<string | false | undefined> {
|
|
|
19
22
|
const pds = doc.service?.find(s => s.id === '#atproto_pds')?.serviceEndpoint;
|
|
20
23
|
return pds;
|
|
21
24
|
}
|
|
22
|
-
async function fetchFromPDS (did: string, query: string, params: Record<string, string>): Promise<Response | undefined> {
|
|
23
|
-
const pds = await did2pds(did);
|
|
25
|
+
async function fetchFromPDS (fetch: Fetch, did: string, query: string, params: Record<string, string>): Promise<Response | undefined> {
|
|
26
|
+
const pds = await did2pds(fetch, did);
|
|
24
27
|
if (!pds) return;
|
|
25
28
|
const url = new URL(pds);
|
|
26
29
|
url.pathname = `/xrpc/${query}`;
|
|
@@ -28,13 +31,13 @@ async function fetchFromPDS (did: string, query: string, params: Record<string,
|
|
|
28
31
|
Object.entries(params).forEach(([k, v]) => prm.set(k, v));
|
|
29
32
|
return await fetch(url.toString());
|
|
30
33
|
}
|
|
31
|
-
async function getRecord (repo: string, collection: string, rkey: string): Promise<ATRecord | false> {
|
|
32
|
-
const res = await fetchFromPDS(repo, 'com.atproto.repo.getRecord', { repo, collection, rkey })
|
|
34
|
+
async function getRecord (fetch: Fetch, repo: string, collection: string, rkey: string): Promise<ATRecord | false> {
|
|
35
|
+
const res = await fetchFromPDS(fetch, repo, 'com.atproto.repo.getRecord', { repo, collection, rkey })
|
|
33
36
|
if (!res || !res.ok) return false;
|
|
34
37
|
return await res.json() as ATRecord;
|
|
35
38
|
}
|
|
36
|
-
async function getBlob (did: string, cid: string): Promise<ArrayBuffer | false> {
|
|
37
|
-
const res = await fetchFromPDS(did, 'com.atproto.sync.getBlob', { did, cid })
|
|
39
|
+
async function getBlob (fetch: Fetch, did: string, cid: string): Promise<ArrayBuffer | false> {
|
|
40
|
+
const res = await fetchFromPDS(fetch, did, 'com.atproto.sync.getBlob', { did, cid })
|
|
38
41
|
if (!res || !res.ok) return false;
|
|
39
42
|
return await res.arrayBuffer();
|
|
40
43
|
}
|
|
@@ -42,31 +45,37 @@ async function getBlob (did: string, cid: string): Promise<ArrayBuffer | false>
|
|
|
42
45
|
// ### AT Loader
|
|
43
46
|
// at://did:plc:izttpdp3l6vss5crelt5kcux/ing.dasl.masl/3mceykgxbkk2r
|
|
44
47
|
export class ATTileLoader {
|
|
48
|
+
#fetch: Fetch;
|
|
49
|
+
constructor (options: LoaderOptions = {}) {
|
|
50
|
+
this.#fetch = options.fetch ?? ((...args) => globalThis.fetch(...args));
|
|
51
|
+
}
|
|
45
52
|
async load (url: string, mothership: TileMothership): Promise<Tile | false | undefined> {
|
|
46
53
|
if (!/^at:\/\//.test(url)) return false;
|
|
47
54
|
const [repo, collection, rkey] = url.replace(/^at:\/\//, '').split('/');
|
|
48
55
|
if (collection !== 'ing.dasl.masl') return;
|
|
49
|
-
const res = await getRecord(repo, collection, rkey);
|
|
56
|
+
const res = await getRecord(this.#fetch, repo, collection, rkey);
|
|
50
57
|
if (!res) return false;
|
|
51
58
|
const manifest = res.value?.tile;
|
|
52
59
|
if (!manifest) return false;
|
|
53
|
-
const loader = new ATPathLoader(repo, manifest);
|
|
60
|
+
const loader = new ATPathLoader(repo, manifest, this.#fetch);
|
|
54
61
|
return new Tile(mothership, url, manifest, loader);
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
export class ATPathLoader {
|
|
58
65
|
#did: string;
|
|
59
66
|
#manifest: StoredMasl;
|
|
60
|
-
|
|
67
|
+
#fetch: Fetch;
|
|
68
|
+
constructor (did: string, manifest: StoredMasl, fetch: Fetch = (...args) => globalThis.fetch(...args)) {
|
|
61
69
|
this.#did = did;
|
|
62
70
|
this.#manifest = manifest;
|
|
71
|
+
this.#fetch = fetch;
|
|
63
72
|
}
|
|
64
73
|
async resolvePath (path: string): Promise<MaslResponse> {
|
|
65
74
|
const entry = this.#manifest?.resources?.[path];
|
|
66
75
|
if (!entry?.src) return NOT_FOUND;
|
|
67
76
|
const src = entry.src;
|
|
68
77
|
const cid = '$link' in src ? src.$link : src.ref.$link;
|
|
69
|
-
const data = await getBlob(this.#did, cid);
|
|
78
|
+
const data = await getBlob(this.#fetch, this.#did, cid);
|
|
70
79
|
if (!data) return NOT_FOUND;
|
|
71
80
|
return maslResponse(entry, data);
|
|
72
81
|
}
|
package/src/car.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { fromUint8Array } from '@atcute/car';
|
|
3
3
|
import { toCidLink, toString as stringifyCID } from '@atcute/cid';
|
|
4
|
-
import { ContentSchemeTileLoader } from "./content-scheme.js";
|
|
4
|
+
import { ContentSchemeTileLoader, type LoaderOptions } from "./content-scheme.js";
|
|
5
5
|
import { Tile } from "./index.js";
|
|
6
6
|
import type { TileMothership } from "./index.js";
|
|
7
7
|
import { NOT_FOUND, maslResponse } from "./lib/masl.js";
|
|
@@ -9,8 +9,8 @@ import type { StoredMasl, MaslResponse, CidLink } from "@dasl/tile-lexicon";
|
|
|
9
9
|
|
|
10
10
|
// ### CAR Tiles
|
|
11
11
|
export class CARTileLoader extends ContentSchemeTileLoader {
|
|
12
|
-
constructor (schemes?: string[]) {
|
|
13
|
-
super(schemes);
|
|
12
|
+
constructor (schemes?: string[], options?: LoaderOptions) {
|
|
13
|
+
super(schemes, options);
|
|
14
14
|
}
|
|
15
15
|
// NOTE: ignoring scheme for now, this is pure HTTP
|
|
16
16
|
async processContent (carData: ArrayBuffer, scheme: string, url: string, mothership: TileMothership): Promise<Tile | false> {
|
package/src/content-scheme.ts
CHANGED
|
@@ -4,10 +4,17 @@ import type { Tile, TileMothership } from "./index.js";
|
|
|
4
4
|
// ### Base Class for HTTP, file, etc. loaders
|
|
5
5
|
// Here the idea is that you can load from multiple schemes, but you might not
|
|
6
6
|
// want to.
|
|
7
|
+
export interface LoaderOptions {
|
|
8
|
+
/** How to fetch: a host whose page has no network of its own routes these through its backend. */
|
|
9
|
+
fetch?: typeof globalThis.fetch;
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
export abstract class ContentSchemeTileLoader {
|
|
8
13
|
#schemes: Set<string>;
|
|
9
|
-
|
|
14
|
+
#fetch: typeof globalThis.fetch;
|
|
15
|
+
constructor (schemes: string[] = ['http', 'file'], options: LoaderOptions = {}) {
|
|
10
16
|
this.#schemes = new Set(schemes);
|
|
17
|
+
this.#fetch = options.fetch ?? ((...args) => globalThis.fetch(...args));
|
|
11
18
|
}
|
|
12
19
|
async load (url: string, mothership: TileMothership): Promise<Tile | false | undefined> {
|
|
13
20
|
let u: URL;
|
|
@@ -15,7 +22,7 @@ export abstract class ContentSchemeTileLoader {
|
|
|
15
22
|
catch { return false; } // not a URL we understand; let another loader try
|
|
16
23
|
if (u.protocol === 'https:' || u.protocol === 'http:') {
|
|
17
24
|
if (!this.#schemes.has('http')) return false;
|
|
18
|
-
const res = await fetch(url);
|
|
25
|
+
const res = await this.#fetch(url);
|
|
19
26
|
if (!res.ok) return false;
|
|
20
27
|
return await this.processContent(await res.arrayBuffer(), u.protocol, url, mothership);
|
|
21
28
|
}
|
package/src/index.ts
CHANGED
|
@@ -29,7 +29,19 @@ The tile-loading architecture has three levels that all communicate together:
|
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
import { el } from "./lib/el.js";
|
|
32
|
-
import
|
|
32
|
+
import { tileResponseHeaders } from "@dasl/tile-lexicon";
|
|
33
|
+
import type { AnyMasl, MaslHeaders, MaslResponse } from "@dasl/tile-lexicon";
|
|
34
|
+
|
|
35
|
+
export interface MothershipConfig {
|
|
36
|
+
/** Host of the loading server (`load.webtil.es`), with a scheme and port when not https://. */
|
|
37
|
+
loadDomain?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the shuttle spends the renderer's WebRTC budget before the tile
|
|
40
|
+
* loads (the default). A host that blocks WebRTC itself (an Electron app with
|
|
41
|
+
* the policy switches set, say) passes 'none' and skips the cost.
|
|
42
|
+
*/
|
|
43
|
+
webrtcGuard?: 'exhaust' | 'none';
|
|
44
|
+
}
|
|
33
45
|
|
|
34
46
|
export interface TileLoader {
|
|
35
47
|
load (url: string, mothership: TileMothership): Promise<Tile | false | undefined>;
|
|
@@ -51,13 +63,29 @@ const RCV_WORKER_REQUEST = `${WORKER_PFX}request`; // worker requested someth
|
|
|
51
63
|
const SND_WORKER_RESPONSE = `${WORKER_PFX}response`; // respond to a worker
|
|
52
64
|
const TILES_WARNING = `${TILES_PFX}warn`; // worker warnings
|
|
53
65
|
const TILES_ERROR = `${TILES_PFX}error`; // shuttle errors
|
|
66
|
+
// Tiles protocols (https://dasl.ing/tp-data.html and friends): the shuttle
|
|
67
|
+
// relays `tiles-protocol-up-<protocol>-<kind>` from the tile to us, and
|
|
68
|
+
// `tiles-protocol-down-<protocol>-<kind>` from us to the tile.
|
|
69
|
+
const PROTOCOL_UP = 'tiles-protocol-up-';
|
|
70
|
+
const PROTOCOL_DOWN = 'tiles-protocol-down-';
|
|
71
|
+
|
|
72
|
+
/** A tiles-protocol message from a tile: `protocol` ("data"), `kind` ("payload", "ready"), and its `payload`. */
|
|
73
|
+
export interface ProtocolEvent extends Event {
|
|
74
|
+
protocol: string;
|
|
75
|
+
kind: string;
|
|
76
|
+
payload: unknown;
|
|
77
|
+
}
|
|
78
|
+
/** A tp-data message from a tile; `payload` is what the tile sent. */
|
|
79
|
+
export interface DataEvent extends Event {
|
|
80
|
+
payload: unknown;
|
|
81
|
+
}
|
|
54
82
|
|
|
55
83
|
export class TileMothership {
|
|
56
84
|
#loaders: TileLoader[] = [];
|
|
57
|
-
#conf:
|
|
85
|
+
#conf: MothershipConfig;
|
|
58
86
|
#id2shuttle = new Map<string, HTMLIFrameElement>();
|
|
59
87
|
#id2tile = new Map<string, Tile>();
|
|
60
|
-
constructor (conf:
|
|
88
|
+
constructor (conf: MothershipConfig = {}) {
|
|
61
89
|
this.#conf = conf;
|
|
62
90
|
}
|
|
63
91
|
init () {
|
|
@@ -88,14 +116,47 @@ export class TileMothership {
|
|
|
88
116
|
const tile = this.#id2tile.get(id);
|
|
89
117
|
if (!tile) throw new Error(`No tile shuttle with ID ${id}`);
|
|
90
118
|
const res = await tile.resolvePath(path);
|
|
119
|
+
// Every document the worker serves, 404s included, carries the
|
|
120
|
+
// policy: the tile can script anything on its origin, so nothing
|
|
121
|
+
// on it may be unconfined.
|
|
91
122
|
const response = res.ok
|
|
92
|
-
? { status: res.status, headers: res.headers, body: res.body }
|
|
93
|
-
: { status: res.status, headers:
|
|
123
|
+
? { status: res.status, headers: this.hardenResponse(res.headers), body: res.body }
|
|
124
|
+
: { status: res.status, headers: this.hardenResponse({ 'content-type': 'text/plain' }), body: undefined };
|
|
94
125
|
this.sendToShuttle(id, SND_WORKER_RESPONSE, { requestId, response });
|
|
95
126
|
}
|
|
96
127
|
}
|
|
128
|
+
else if (typeof action === 'string' && action.startsWith(PROTOCOL_UP)) {
|
|
129
|
+
// Protocol messages carry no id: the shuttle window they come from
|
|
130
|
+
// says which tile is talking, and nothing else gets to pretend.
|
|
131
|
+
const tile = this.tileForWindow(ev.source);
|
|
132
|
+
if (!tile) return;
|
|
133
|
+
const rest = action.slice(PROTOCOL_UP.length);
|
|
134
|
+
const dash = rest.indexOf('-');
|
|
135
|
+
if (dash < 1) return;
|
|
136
|
+
const protocol = rest.slice(0, dash);
|
|
137
|
+
const kind = rest.slice(dash + 1);
|
|
138
|
+
const { payload } = ev.data;
|
|
139
|
+
tile.dispatchEvent(Object.assign(new Event('protocol'), { protocol, kind, payload }));
|
|
140
|
+
if (protocol === 'data') {
|
|
141
|
+
tile.dispatchEvent(Object.assign(new Event(kind === 'payload' ? 'data' : `data-${kind}`), { payload }));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
97
144
|
});
|
|
98
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* The headers a tile document ships with: the resource's own, plus the
|
|
148
|
+
* policy from @dasl/tile-lexicon. A host that wants more on every response
|
|
149
|
+
* overrides this and calls super; nothing should ever return less.
|
|
150
|
+
*/
|
|
151
|
+
hardenResponse (headers?: MaslHeaders): MaslHeaders {
|
|
152
|
+
return tileResponseHeaders(headers);
|
|
153
|
+
}
|
|
154
|
+
tileForWindow (source: MessageEventSource | null): Tile | undefined {
|
|
155
|
+
if (!source) return;
|
|
156
|
+
for (const [id, ifr] of this.#id2shuttle) {
|
|
157
|
+
if (ifr.contentWindow === source) return this.#id2tile.get(id);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
99
160
|
sendToShuttle (id: string, action: string, payload: unknown) {
|
|
100
161
|
const ifr = this.#id2shuttle.get(id);
|
|
101
162
|
if (!ifr) return console.error(`No shuttle for ID ${id}`);
|
|
@@ -108,7 +169,7 @@ export class TileMothership {
|
|
|
108
169
|
return id;
|
|
109
170
|
}
|
|
110
171
|
startShuttle (id: string) {
|
|
111
|
-
this.sendToShuttle(id, SND_SHUTTLE_LOAD, { id });
|
|
172
|
+
this.sendToShuttle(id, SND_SHUTTLE_LOAD, { id, webrtcGuard: this.#conf.webrtcGuard ?? 'exhaust' });
|
|
112
173
|
}
|
|
113
174
|
// Adds a loader that will handle matching requests to load a tile.
|
|
114
175
|
// - `loader` is an object that knows how to load a tile for a specific scheme
|
|
@@ -121,7 +182,9 @@ export class TileMothership {
|
|
|
121
182
|
this.#loaders = this.#loaders.filter(ldr => ldr !== loader);
|
|
122
183
|
}
|
|
123
184
|
getLoadSource () {
|
|
124
|
-
|
|
185
|
+
const domain = this.#conf.loadDomain || 'load.webtil.es';
|
|
186
|
+
const base = /^https?:\/\//.test(domain) ? domain : `https://${domain}`;
|
|
187
|
+
return new URL('/.well-known/web-tiles/', base).href;
|
|
125
188
|
}
|
|
126
189
|
// Load a tile.
|
|
127
190
|
async loadTile (url: string): Promise<Tile | false> {
|
|
@@ -220,6 +283,19 @@ export class Tile extends EventTarget {
|
|
|
220
283
|
getLoadSource (): string {
|
|
221
284
|
return this.#mothership.getLoadSource();
|
|
222
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Sends a tiles-protocol message down to the rendered tile. Messages the
|
|
288
|
+
* tile sends up arrive as `protocol` events (and, for tp-data, as `data`
|
|
289
|
+
* and `data-ready` events) on this object.
|
|
290
|
+
*/
|
|
291
|
+
sendProtocol (protocol: string, kind: string, payload?: unknown) {
|
|
292
|
+
if (!this.#shuttleId) throw new Error('The tile is not rendered yet.');
|
|
293
|
+
this.#mothership.sendToShuttle(this.#shuttleId, `${PROTOCOL_DOWN}${protocol}-${kind}`, payload);
|
|
294
|
+
}
|
|
295
|
+
/** Sends a tp-data payload to the tile (https://dasl.ing/tp-data.html). */
|
|
296
|
+
sendData (payload: unknown) {
|
|
297
|
+
this.sendProtocol('data', 'payload', payload);
|
|
298
|
+
}
|
|
223
299
|
attachIframe (ifr: HTMLIFrameElement) {
|
|
224
300
|
this.#shuttleId = this.#mothership.registerShuttleFrame(ifr, this);
|
|
225
301
|
ifr.addEventListener('load', () => this.#mothership.startShuttle(this.#shuttleId!));
|
package/src/webxdc.ts
CHANGED
|
@@ -4,7 +4,7 @@ import mime from 'mime/lite';
|
|
|
4
4
|
import { parse } from 'smol-toml';
|
|
5
5
|
import { Tile } from "./index.js";
|
|
6
6
|
import type { TileMothership } from "./index.js";
|
|
7
|
-
import { ContentSchemeTileLoader } from "./content-scheme.js";
|
|
7
|
+
import { ContentSchemeTileLoader, type LoaderOptions } from "./content-scheme.js";
|
|
8
8
|
import { MemoryPathLoader } from './memory.js';
|
|
9
9
|
import type { InMemoryMasl } from "@dasl/tile-lexicon";
|
|
10
10
|
|
|
@@ -16,8 +16,8 @@ import type { InMemoryMasl } from "@dasl/tile-lexicon";
|
|
|
16
16
|
// - It may have a manifest.toml (seriously), that may have a name entry and
|
|
17
17
|
// one pointing to the source.
|
|
18
18
|
export class WebXDCTileLoader extends ContentSchemeTileLoader {
|
|
19
|
-
constructor (schemes?: string[]) {
|
|
20
|
-
super(schemes);
|
|
19
|
+
constructor (schemes?: string[], options?: LoaderOptions) {
|
|
20
|
+
super(schemes, options);
|
|
21
21
|
}
|
|
22
22
|
async processContent (zipData: ArrayBuffer, _: string, url: string, mothership: TileMothership): Promise<Tile | false> {
|
|
23
23
|
const zip = new JSZip();
|