@kehto/shell 0.16.7 → 0.17.2

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/dist/index.js CHANGED
@@ -961,36 +961,6 @@ var audioManager = {
961
961
  }
962
962
  };
963
963
 
964
- // src/keys-forwarder.ts
965
- function createKeysForwarder(deps) {
966
- const target = deps.target ?? (typeof window !== "undefined" ? window : new EventTarget());
967
- const listener = (ev) => {
968
- const ke = ev;
969
- const entries = deps.sessionRegistry.getAllEntries();
970
- for (const entry of entries) {
971
- if (!deps.hasKeysForwardCap(entry.pubkey)) continue;
972
- const iframe = deps.originRegistry.getIframeWindow(entry.windowId);
973
- if (!iframe) continue;
974
- const envelope = {
975
- type: "keys.forward",
976
- key: ke.key ?? "",
977
- code: ke.code ?? "",
978
- ctrl: ke.ctrlKey ?? false,
979
- alt: ke.altKey ?? false,
980
- shift: ke.shiftKey ?? false,
981
- meta: ke.metaKey ?? false
982
- };
983
- iframe.postMessage(envelope, "*");
984
- }
985
- };
986
- target.addEventListener("keydown", listener);
987
- return {
988
- destroy() {
989
- target.removeEventListener("keydown", listener);
990
- }
991
- };
992
- }
993
-
994
964
  // src/shell-init.ts
995
965
  var NAP_DOMAINS = [
996
966
  "identity",
@@ -1169,23 +1139,6 @@ function createShellBridge(hooks) {
1169
1139
  win.postMessage(envelope, "*");
1170
1140
  }
1171
1141
  }
1172
- let keysForwarder = null;
1173
- if (typeof window !== "undefined") {
1174
- try {
1175
- keysForwarder = createKeysForwarder({
1176
- originRegistry,
1177
- sessionRegistry,
1178
- hasKeysForwardCap: (pubkey) => {
1179
- const entry = sessionRegistry.getEntry(pubkey);
1180
- if (!entry) return false;
1181
- const acl = aclStore.getEntry(entry.pubkey, entry.dTag, entry.aggregateHash);
1182
- return acl?.capabilities.includes("keys:forward") ?? false;
1183
- }
1184
- });
1185
- } catch {
1186
- keysForwarder = null;
1187
- }
1188
- }
1189
1142
  return {
1190
1143
  handleMessage(event) {
1191
1144
  const sourceWindow = event.source;
@@ -1217,7 +1170,6 @@ function createShellBridge(hooks) {
1217
1170
  runtime.injectEvent(topic, payload);
1218
1171
  },
1219
1172
  destroy() {
1220
- keysForwarder?.destroy();
1221
1173
  runtime.destroy();
1222
1174
  },
1223
1175
  registerConsentHandler(handler) {
@@ -1255,7 +1207,7 @@ function scriptJson(value) {
1255
1207
  return JSON.stringify(value).replace(/</g, "\\u003c");
1256
1208
  }
1257
1209
  function renderNappletNamespacePrelude(options) {
1258
- const domains = uniqueBareDomains(options.domains);
1210
+ const domains = uniqueBareDomains(["shell", ...options.domains]);
1259
1211
  return `<script data-kehto-nip5d-injection>(${nappletNamespacePrelude.toString()})(${scriptJson(domains)});</script>`;
1260
1212
  }
1261
1213
  function injectNappletNamespacePrelude(html, options) {
@@ -1349,6 +1301,67 @@ function nappletNamespacePrelude(domains) {
1349
1301
  }
1350
1302
  };
1351
1303
  }
1304
+ function makeShell() {
1305
+ const emptyServices = Object.freeze([]);
1306
+ const readyHandlers = /* @__PURE__ */ new Set();
1307
+ let environment;
1308
+ let resolveReady = () => void 0;
1309
+ const ready = new Promise((resolve) => {
1310
+ resolveReady = resolve;
1311
+ });
1312
+ const off = listen((event) => {
1313
+ if (!isParentMessage(event) || environment) return;
1314
+ const incoming = event.data;
1315
+ if (typeof incoming !== "object" || incoming === null) return;
1316
+ const message = incoming;
1317
+ if (message.type !== "shell.init") return;
1318
+ const services = Object.freeze(
1319
+ Array.isArray(message.services) ? message.services.filter((service) => typeof service === "string") : []
1320
+ );
1321
+ environment = Object.freeze({
1322
+ capabilities: message.capabilities ?? {},
1323
+ services
1324
+ });
1325
+ off();
1326
+ resolveReady(environment);
1327
+ for (const handler of readyHandlers) handler(environment);
1328
+ readyHandlers.clear();
1329
+ });
1330
+ function supports(domain, protocol) {
1331
+ if (!environment || typeof environment.capabilities !== "object" || environment.capabilities === null) {
1332
+ return false;
1333
+ }
1334
+ const capabilities = environment.capabilities;
1335
+ if (protocol !== void 0) {
1336
+ const protocols = capabilities.protocols;
1337
+ if (typeof protocols === "object" && protocols !== null) {
1338
+ const supported = protocols[domain];
1339
+ if (Array.isArray(supported) && supported.includes(protocol)) return true;
1340
+ }
1341
+ return Array.isArray(capabilities.naps) && capabilities.naps.includes(`${domain}:${protocol}`);
1342
+ }
1343
+ return Array.isArray(capabilities.domains) && capabilities.domains.includes(domain) || Array.isArray(capabilities.naps) && capabilities.naps.includes(domain);
1344
+ }
1345
+ const shell2 = {
1346
+ ready: () => ready,
1347
+ supports,
1348
+ get services() {
1349
+ return environment?.services ?? emptyServices;
1350
+ },
1351
+ set services(_services) {
1352
+ },
1353
+ onReady(handler) {
1354
+ if (environment) {
1355
+ handler(environment);
1356
+ return subscriptionHandle(() => void 0);
1357
+ }
1358
+ readyHandlers.add(handler);
1359
+ return subscriptionHandle(() => readyHandlers.delete(handler));
1360
+ }
1361
+ };
1362
+ post({ type: "shell.ready" });
1363
+ return shell2;
1364
+ }
1352
1365
  function domainEventHandle(eventType, callback, select = (message) => message.event) {
1353
1366
  const off = listen((event) => {
1354
1367
  if (!isParentMessage(event)) return;
@@ -2109,7 +2122,9 @@ function nappletNamespacePrelude(domains) {
2109
2122
  }
2110
2123
  };
2111
2124
  }
2125
+ const shell = makeShell();
2112
2126
  function makeDomain(domain, existing) {
2127
+ if (domain === "shell") return shell;
2113
2128
  if (existing && typeof existing === "object" && Object.keys(existing).length > 0) return existing;
2114
2129
  switch (domain) {
2115
2130
  case "relay":
@@ -2285,7 +2300,6 @@ export {
2285
2300
  buildShellCapabilities,
2286
2301
  createEnforceGate,
2287
2302
  createIdentityProxy,
2288
- createKeysForwarder,
2289
2303
  createKeysProxy,
2290
2304
  createMediaProxy,
2291
2305
  createNapEnforceGate,