@ewe-studios/foundation-wasm-ui 0.0.0-stage → 0.1.13
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/LICENSE +201 -0
- package/README.md +11 -2
- package/bundle.js +15565 -0
- package/bundle.min.js +2 -0
- package/foundation_wasm/runtime/foundation-wasm.js +2449 -0
- package/index.js +3 -0
- package/package.json +12 -4
- package/ui/runtimes/foundation-ui-actions.js +698 -0
- package/ui/runtimes/foundation-ui-behaviours.js +792 -0
- package/ui/runtimes/foundation-ui-bootstrap.js +13 -0
- package/ui/runtimes/foundation-ui-connections.js +99 -0
- package/ui/runtimes/foundation-ui-frames.js +1023 -0
- package/ui/runtimes/foundation-ui-live.js +186 -0
- package/ui/runtimes/foundation-ui-recovery.js +66 -0
- package/ui/runtimes/foundation-ui-vocab.js +262 -0
- package/ui/runtimes/foundation-ui-wire.js +1 -0
- package/ui/runtimes/foundation-wasm-ui.js +2164 -0
- package/ui/runtimes/platform-scheme-interceptor.js +124 -0
- package/ui/runtimes/runtime-entry.js +4 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Connect an instantiated WebAssembly app to the browser frame reader.
|
|
2
|
+
import { createApp } from "./foundation-ui-actions.js";
|
|
3
|
+
export { createApp };
|
|
4
|
+
import * as ui from "./foundation-wasm-ui.js";
|
|
5
|
+
import { installFrameRuntime } from "./foundation-ui-frames.js";
|
|
6
|
+
|
|
7
|
+
export function registerFrameApp(runtime, options = {}) {
|
|
8
|
+
const frames = installFrameRuntime(ui, options);
|
|
9
|
+
ui.registerWasmApp(runtime, options);
|
|
10
|
+
ui.registerWebComponents();
|
|
11
|
+
return frames;
|
|
12
|
+
}
|
|
13
|
+
globalThis.FoundationUiBootstrap = { createApp, registerFrameApp };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// One manager belongs to one authenticated application context.
|
|
2
|
+
export class ConnectionManager {
|
|
3
|
+
#adapters = new Map();
|
|
4
|
+
#connections = new Set();
|
|
5
|
+
#closed = false;
|
|
6
|
+
#tag = 0n;
|
|
7
|
+
nextTag() {
|
|
8
|
+
if (this.#tag === 0xffffffffffffffffn) throw new Error("Connection identifiers exhausted");
|
|
9
|
+
return ++this.#tag;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
supports(transport) { return this.#adapters.has(transport); }
|
|
14
|
+
|
|
15
|
+
register(transport, open) {
|
|
16
|
+
if (this.#closed || this.#adapters.has(transport)) throw new Error("Connection adapter is unavailable");
|
|
17
|
+
this.#adapters.set(transport, open);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
acquire(options, listener = {}) {
|
|
22
|
+
if (this.#closed) throw new Error("Connection manager is closed");
|
|
23
|
+
const { transport, endpoint, shared = transport === "websocket", keepAlive = false,
|
|
24
|
+
settings = null, authority = null, protocol = "frame" } = options;
|
|
25
|
+
const url = new URL(endpoint, options.base ?? globalThis.location?.href);
|
|
26
|
+
if (url.username || url.password) throw new Error("Use the connection authentication context");
|
|
27
|
+
url.hash = "";
|
|
28
|
+
if (transport === "websocket") {
|
|
29
|
+
if (url.protocol === "https:") url.protocol = "wss:";
|
|
30
|
+
if (url.protocol === "http:") url.protocol = "ws:";
|
|
31
|
+
}
|
|
32
|
+
let entry = shared && Array.from(this.#connections).find(c =>
|
|
33
|
+
c.shared && c.transport === transport && c.address === url.href && c.settings === settings &&
|
|
34
|
+
c.authority === authority && c.protocol === protocol);
|
|
35
|
+
const handle = { ...listener };
|
|
36
|
+
if (!entry) {
|
|
37
|
+
const open = this.#adapters.get(transport);
|
|
38
|
+
if (!open) throw new Error("Unknown connection transport: " + transport);
|
|
39
|
+
entry = { shared, address: url.href, settings, authority, transport, protocol, retainers: new Set(), handles: new Set([handle]) };
|
|
40
|
+
this.#connections.add(entry);
|
|
41
|
+
try {
|
|
42
|
+
entry.connection = open({ ...options, endpoint: url.href }, {
|
|
43
|
+
listening: () => [...entry.handles].some(h => h.receive),
|
|
44
|
+
deliver: bytes => {
|
|
45
|
+
if (!this.#connections.has(entry)) return;
|
|
46
|
+
if (options.isContext?.(bytes)) {
|
|
47
|
+
entry.context = new Uint8Array(bytes).slice();
|
|
48
|
+
for (const h of [...entry.handles]) h.onContext?.(entry.context.slice());
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const delivered = new Set();
|
|
52
|
+
for (const h of [...entry.handles]) {
|
|
53
|
+
if (!entry.handles.has(h) || !h.receive || (h.owner && delivered.has(h.owner))) continue;
|
|
54
|
+
try {
|
|
55
|
+
const copy = new Uint8Array(bytes).slice();
|
|
56
|
+
if (h.accept && !h.accept(copy)) continue;
|
|
57
|
+
h.receive(copy);
|
|
58
|
+
if (h.owner) delivered.add(h.owner);
|
|
59
|
+
} catch (cause) { h.onError?.(cause); }
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
opened: () => { entry.opened = true; for (const h of [...entry.handles]) h.onOpen?.(); },
|
|
63
|
+
disconnected: cause => { entry.opened = false; entry.context = null; for (const h of [...entry.handles]) h.onError?.(cause); },
|
|
64
|
+
});
|
|
65
|
+
} catch (cause) { this.#connections.delete(entry); throw cause; }
|
|
66
|
+
} else {
|
|
67
|
+
entry.handles.add(handle);
|
|
68
|
+
if (entry.opened || entry.context) queueMicrotask(() => {
|
|
69
|
+
if (!entry.handles.has(handle)) return;
|
|
70
|
+
if (entry.opened) handle.onOpen?.();
|
|
71
|
+
if (entry.context) handle.onContext?.(entry.context.slice());
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const retention = {};
|
|
75
|
+
if (keepAlive) entry.retainers.add(retention);
|
|
76
|
+
const releaseUnused = () => {
|
|
77
|
+
if (!entry.handles.size && !entry.retainers.size) this.#close(entry);
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
send: async bytes => {
|
|
81
|
+
if (!entry.handles.has(handle) || !entry.connection?.send) throw new Error("Connection cannot send");
|
|
82
|
+
await entry.connection.send(bytes);
|
|
83
|
+
},
|
|
84
|
+
close: () => { entry.handles.delete(handle); releaseUnused(); },
|
|
85
|
+
releaseRetention: () => { entry.retainers.delete(retention); releaseUnused(); },
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#close(entry) {
|
|
90
|
+
if (!this.#connections.delete(entry)) return;
|
|
91
|
+
entry.handles.clear();
|
|
92
|
+
entry.connection?.close();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
close() {
|
|
96
|
+
this.#closed = true;
|
|
97
|
+
for (const entry of [...this.#connections]) this.#close(entry);
|
|
98
|
+
}
|
|
99
|
+
}
|