@kehto/paja 0.20.1 → 0.21.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 +6 -7
- package/dist/browser-host.js +277 -16
- package/dist/browser-host.js.map +1 -1
- package/dist/{chunk-FUBJAN4W.js → chunk-LGPTNOM7.js} +9 -2
- package/dist/chunk-LGPTNOM7.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +1 -1
- package/dist/{server-5j5uoy2Z.d.ts → server-Cd34l9ts.d.ts} +1 -1
- package/package.json +9 -9
- package/dist/chunk-FUBJAN4W.js.map +0 -1
package/README.md
CHANGED
|
@@ -219,7 +219,7 @@ The file opens in a new runtime tab named after the file.
|
|
|
219
219
|
- **Same loading path as verified pointers.** Paja registers the identity before
|
|
220
220
|
the frame runs. It injects the Class-1 CSP (with `connect-src 'none'`, since a
|
|
221
221
|
local file has no relay or Blossom hints) and then the runtime-owned
|
|
222
|
-
`window.napplet` prelude, including
|
|
222
|
+
`window.napplet` prelude, including enabled optional domains. The bytes go in through
|
|
223
223
|
`srcdoc` under the same `allow-scripts` sandbox.
|
|
224
224
|
- **Development only and unverified.** A local file has no signed manifest. It
|
|
225
225
|
never enters the installed napplet catalog, never becomes an intent delivery
|
|
@@ -254,12 +254,7 @@ Paja activates delivered handler tabs because its stage shows one tab at a time.
|
|
|
254
254
|
`behavior.focus` is advisory; `reuse: false` creates a new surface. Existing caller
|
|
255
255
|
tabs remain open. Installed contracts and domains appear in pointer diagnostics.
|
|
256
256
|
|
|
257
|
-
|
|
258
|
-
its host-owned mandatory `window.napplet.shell` prelude: it installs the live
|
|
259
|
-
receiver before the one bare `shell.ready`, caches the first `shell.init`, and
|
|
260
|
-
provides local `ready()`, `supports()`, read-only `services`, and one-shot
|
|
261
|
-
`onReady()`. This is the documented upstream-package-drift exception, not a
|
|
262
|
-
shim capability.
|
|
257
|
+
Kehto provides the optional `window.napplet.shell` interface for environment information. Other domains route through trusted iframe creation identity independently of readiness. `supports(domain)` queries namespace presence locally. See the living [NAP-SHELL](https://github.com/napplet/naps/blob/master/naps/NAP-SHELL.md).
|
|
263
258
|
|
|
264
259
|
Before Paja assigns a verified runtime-pointer document to `srcdoc`, it calls
|
|
265
260
|
`@kehto/shell`'s `prepareNappletSrcdoc`. The shell inserts validated CSP first,
|
|
@@ -521,3 +516,7 @@ URL cannot supply one. The hidden launcher is removed after acceptance and is
|
|
|
521
516
|
never persisted or restored. Verification precedes `srcdoc`, and host bootstrap
|
|
522
517
|
injection stays outside signed bytes. Native external-origin sender semantics
|
|
523
518
|
remain a documented upstream spec gap; no host sender identity is invented.
|
|
519
|
+
|
|
520
|
+
## GAMEPAD integration
|
|
521
|
+
|
|
522
|
+
This non-normative guidance defers to the living [NAP-GAMEPAD](https://github.com/napplet/naps/pull/108). Services export `createGamepadService` and `browserGamepadOptions`; shell exports `denyNappletControllerAccess`. Paja and the playground register one host reader and deny native gamepad/HID/USB paths before frame execution. Source-bound subscriptions receive immediate full snapshots; only the visible host's input owner gets live controls. Focus loss supplies neutral controls and timestamp zero; unsubscribe, window destruction, and service removal release polling. Non-browser or denied native readers report the proposal's unavailable reasons. See [Controller input](https://github.com/kehto/web/blob/main/docs/gamepad.md).
|
package/dist/browser-host.js
CHANGED
|
@@ -5262,6 +5262,7 @@ function handleStorageNap(windowId, msg, sendToNapplet, sessionRegistry2, aclSta
|
|
|
5262
5262
|
}
|
|
5263
5263
|
function createRuntimeDomainHandlers(context) {
|
|
5264
5264
|
return {
|
|
5265
|
+
gamepad: (windowId, msg) => handleServiceOnlyMessage(context, "gamepad", windowId, msg),
|
|
5265
5266
|
storage: (windowId, msg) => handleStorageMessage(context, windowId, msg),
|
|
5266
5267
|
media: (windowId, msg) => handleMediaMessage(context, windowId, msg),
|
|
5267
5268
|
keys: (windowId, msg) => handleKeysMessage(context, windowId, msg),
|
|
@@ -5410,6 +5411,7 @@ function createNapEnvelopeDispatcher(handlers) {
|
|
|
5410
5411
|
const adapt = (handler) => (msg) => {
|
|
5411
5412
|
if (currentWindowId !== null) handler(currentWindowId, msg);
|
|
5412
5413
|
};
|
|
5414
|
+
napDispatch.registerNap("gamepad", adapt(handlers.gamepad));
|
|
5413
5415
|
napDispatch.registerNap("relay", adapt(handlers.relay));
|
|
5414
5416
|
napDispatch.registerNap("identity", adapt(handlers.identity));
|
|
5415
5417
|
napDispatch.registerNap("count", adapt(handlers.count));
|
|
@@ -5551,7 +5553,7 @@ function createDenialResponse(envelope, error) {
|
|
|
5551
5553
|
}
|
|
5552
5554
|
function createMessageHandler(hooks, sessionRegistry2, enforceNap, dispatchNapEnvelope, firewallGate) {
|
|
5553
5555
|
return (windowId, msg) => {
|
|
5554
|
-
if (typeof msg !== "object" || msg === null || !("type" in msg)) return;
|
|
5556
|
+
if (typeof msg !== "object" || msg === null || Array.isArray(msg) || !("type" in msg) || typeof msg.type !== "string") return;
|
|
5555
5557
|
const envelope = msg;
|
|
5556
5558
|
const dotIdx = envelope.type.indexOf(".");
|
|
5557
5559
|
if (dotIdx === -1) return;
|
|
@@ -5637,8 +5639,8 @@ function createRuntimeInstance(context) {
|
|
|
5637
5639
|
try {
|
|
5638
5640
|
if (isDomainAllowed && !isDomainAllowed(windowId, domain)) return false;
|
|
5639
5641
|
const { recipientCap } = resolveCapabilitiesNap(message2);
|
|
5640
|
-
if (!recipientCap) return false;
|
|
5641
|
-
if (!aclState.check("", entry.dTag, entry.aggregateHash, recipientCap)) {
|
|
5642
|
+
if (!recipientCap && message2.type !== "gamepad.state") return false;
|
|
5643
|
+
if (recipientCap && !aclState.check("", entry.dTag, entry.aggregateHash, recipientCap)) {
|
|
5642
5644
|
return false;
|
|
5643
5645
|
}
|
|
5644
5646
|
sendToNapplet(windowId, message2);
|
|
@@ -12328,6 +12330,169 @@ function createFsService(options) {
|
|
|
12328
12330
|
}
|
|
12329
12331
|
};
|
|
12330
12332
|
}
|
|
12333
|
+
var SUBSCRIBE_WINDOW_MS = 1e3;
|
|
12334
|
+
var MAX_SUBSCRIPTIONS_PER_WINDOW = 32;
|
|
12335
|
+
function clamp(value, minimum, maximum) {
|
|
12336
|
+
return Number.isFinite(value) ? Math.max(minimum, Math.min(maximum, value)) : 0;
|
|
12337
|
+
}
|
|
12338
|
+
function readSample(read) {
|
|
12339
|
+
if (!read) return { available: false, reason: "unavailable", pads: [] };
|
|
12340
|
+
try {
|
|
12341
|
+
return {
|
|
12342
|
+
available: true,
|
|
12343
|
+
pads: Array.from(read(), (pad3) => !pad3?.connected ? null : {
|
|
12344
|
+
index: pad3.index,
|
|
12345
|
+
id: pad3.id,
|
|
12346
|
+
mapping: pad3.mapping,
|
|
12347
|
+
connected: true,
|
|
12348
|
+
timestamp: Number.isFinite(pad3.timestamp) ? pad3.timestamp : 0,
|
|
12349
|
+
axes: Array.from(pad3.axes, (axis) => clamp(axis, -1, 1)),
|
|
12350
|
+
buttons: Array.from(pad3.buttons, (button2) => ({
|
|
12351
|
+
value: clamp(button2.value, 0, 1),
|
|
12352
|
+
pressed: button2.pressed,
|
|
12353
|
+
touched: button2.touched ?? button2.pressed
|
|
12354
|
+
}))
|
|
12355
|
+
})
|
|
12356
|
+
};
|
|
12357
|
+
} catch (error) {
|
|
12358
|
+
const blocked = typeof error === "object" && error !== null && "name" in error && error.name === "SecurityError";
|
|
12359
|
+
if (!blocked) throw error;
|
|
12360
|
+
return { available: false, reason: "blocked", pads: [] };
|
|
12361
|
+
}
|
|
12362
|
+
}
|
|
12363
|
+
function padsFor(sample, focused) {
|
|
12364
|
+
return sample.pads.map((pad3) => pad3 === null ? null : {
|
|
12365
|
+
index: pad3.index,
|
|
12366
|
+
id: pad3.id,
|
|
12367
|
+
mapping: pad3.mapping,
|
|
12368
|
+
connected: true,
|
|
12369
|
+
timestamp: focused ? pad3.timestamp : 0,
|
|
12370
|
+
axes: pad3.axes.map((axis) => focused ? axis : 0),
|
|
12371
|
+
buttons: pad3.buttons.map((button2) => focused ? { ...button2 } : { value: 0, pressed: false, touched: false })
|
|
12372
|
+
});
|
|
12373
|
+
}
|
|
12374
|
+
function createGamepadService(options = {}) {
|
|
12375
|
+
const recipients = /* @__PURE__ */ new Map();
|
|
12376
|
+
const changes = /* @__PURE__ */ new Map();
|
|
12377
|
+
const now2 = options.now ?? Date.now;
|
|
12378
|
+
let context;
|
|
12379
|
+
let frame;
|
|
12380
|
+
let generation = 0;
|
|
12381
|
+
let detach;
|
|
12382
|
+
let closed = false;
|
|
12383
|
+
let sample = { available: false, reason: "unavailable", pads: [] };
|
|
12384
|
+
function cancel() {
|
|
12385
|
+
generation += 1;
|
|
12386
|
+
if (frame !== void 0) options.cancelFrame?.(frame);
|
|
12387
|
+
frame = void 0;
|
|
12388
|
+
}
|
|
12389
|
+
function schedule() {
|
|
12390
|
+
if (closed || recipients.size === 0 || !sample.available || frame !== void 0 || !options.requestFrame) return;
|
|
12391
|
+
const scheduled = ++generation;
|
|
12392
|
+
frame = options.requestFrame(() => {
|
|
12393
|
+
if (scheduled !== generation) return;
|
|
12394
|
+
frame = void 0;
|
|
12395
|
+
refresh();
|
|
12396
|
+
});
|
|
12397
|
+
}
|
|
12398
|
+
function deliver(windowId, recipient, force = false) {
|
|
12399
|
+
const focused = sample.available && (options.isHostActive?.() ?? true) && options.getFocusedWindow?.() === windowId;
|
|
12400
|
+
const message2 = { type: "gamepad.state", ...sample, focused, pads: padsFor(sample, focused) };
|
|
12401
|
+
const signature = JSON.stringify(message2);
|
|
12402
|
+
if (!force && signature === recipient.previous) return;
|
|
12403
|
+
recipient.previous = signature;
|
|
12404
|
+
if (context) {
|
|
12405
|
+
if (!context.sendToEligibleNapplet(windowId, message2)) recipients.delete(windowId);
|
|
12406
|
+
} else recipient.send(message2);
|
|
12407
|
+
}
|
|
12408
|
+
function refresh() {
|
|
12409
|
+
if (closed || recipients.size === 0) return;
|
|
12410
|
+
sample = readSample(options.readGamepads);
|
|
12411
|
+
const current = [...recipients];
|
|
12412
|
+
for (const [windowId, recipient] of current) {
|
|
12413
|
+
if (recipients.get(windowId) === recipient) deliver(windowId, recipient);
|
|
12414
|
+
}
|
|
12415
|
+
if (recipients.size === 0 || !sample.available) cancel();
|
|
12416
|
+
schedule();
|
|
12417
|
+
}
|
|
12418
|
+
function unsubscribe(windowId) {
|
|
12419
|
+
recipients.delete(windowId);
|
|
12420
|
+
if (recipients.size === 0) cancel();
|
|
12421
|
+
}
|
|
12422
|
+
function allowSubscribe(windowId) {
|
|
12423
|
+
const time = now2();
|
|
12424
|
+
let bucket = changes.get(windowId);
|
|
12425
|
+
if (!bucket || time < bucket.start || time - bucket.start >= SUBSCRIBE_WINDOW_MS) {
|
|
12426
|
+
bucket = { start: time, count: 0 };
|
|
12427
|
+
changes.set(windowId, bucket);
|
|
12428
|
+
}
|
|
12429
|
+
bucket.count += 1;
|
|
12430
|
+
return bucket.count <= MAX_SUBSCRIPTIONS_PER_WINDOW;
|
|
12431
|
+
}
|
|
12432
|
+
return {
|
|
12433
|
+
descriptor: { name: "gamepad", version: "1.0.0", description: "NAP-GAMEPAD focus-scoped controller snapshots" },
|
|
12434
|
+
refresh,
|
|
12435
|
+
onRegistered(runtime) {
|
|
12436
|
+
context = runtime;
|
|
12437
|
+
closed = false;
|
|
12438
|
+
detach?.();
|
|
12439
|
+
detach = options.subscribeChanges?.(refresh);
|
|
12440
|
+
},
|
|
12441
|
+
onUnregistered() {
|
|
12442
|
+
closed = true;
|
|
12443
|
+
cancel();
|
|
12444
|
+
detach?.();
|
|
12445
|
+
detach = void 0;
|
|
12446
|
+
recipients.clear();
|
|
12447
|
+
changes.clear();
|
|
12448
|
+
context = void 0;
|
|
12449
|
+
},
|
|
12450
|
+
handleMessage(windowId, message2, send) {
|
|
12451
|
+
if (closed || !message2 || typeof message2 !== "object" || Array.isArray(message2) || "id" in message2) return;
|
|
12452
|
+
if (message2.type === "gamepad.unsubscribe") {
|
|
12453
|
+
unsubscribe(windowId);
|
|
12454
|
+
return;
|
|
12455
|
+
}
|
|
12456
|
+
if (message2.type !== "gamepad.subscribe" || !allowSubscribe(windowId)) return;
|
|
12457
|
+
const recipient = recipients.get(windowId) ?? { send };
|
|
12458
|
+
recipients.set(windowId, recipient);
|
|
12459
|
+
sample = readSample(options.readGamepads);
|
|
12460
|
+
deliver(windowId, recipient, true);
|
|
12461
|
+
schedule();
|
|
12462
|
+
},
|
|
12463
|
+
onWindowDestroyed(windowId) {
|
|
12464
|
+
unsubscribe(windowId);
|
|
12465
|
+
changes.delete(windowId);
|
|
12466
|
+
}
|
|
12467
|
+
};
|
|
12468
|
+
}
|
|
12469
|
+
function browserGamepadOptions(host, resolveWindow = () => void 0) {
|
|
12470
|
+
if (!host) return {};
|
|
12471
|
+
const doc = host.document;
|
|
12472
|
+
const nav = host.navigator;
|
|
12473
|
+
return {
|
|
12474
|
+
readGamepads: typeof nav.getGamepads === "function" ? () => nav.getGamepads() : void 0,
|
|
12475
|
+
getFocusedWindow: () => {
|
|
12476
|
+
const active = doc.activeElement;
|
|
12477
|
+
if (!active || active.tagName !== "IFRAME") return null;
|
|
12478
|
+
const target = active.contentWindow;
|
|
12479
|
+
return target ? resolveWindow(target) ?? null : null;
|
|
12480
|
+
},
|
|
12481
|
+
isHostActive: () => doc.visibilityState !== "hidden" && doc.hasFocus(),
|
|
12482
|
+
requestFrame: typeof host.requestAnimationFrame === "function" ? (callback) => host.requestAnimationFrame(callback) : void 0,
|
|
12483
|
+
cancelFrame: (frame) => host.cancelAnimationFrame(frame),
|
|
12484
|
+
subscribeChanges(refresh) {
|
|
12485
|
+
const windowEvents = ["focus", "blur", "gamepadconnected", "gamepaddisconnected"];
|
|
12486
|
+
const documentEvents = ["focusin", "focusout", "visibilitychange"];
|
|
12487
|
+
for (const type of windowEvents) host.addEventListener(type, refresh);
|
|
12488
|
+
for (const type of documentEvents) doc.addEventListener(type, refresh);
|
|
12489
|
+
return () => {
|
|
12490
|
+
for (const type of windowEvents) host.removeEventListener(type, refresh);
|
|
12491
|
+
for (const type of documentEvents) doc.removeEventListener(type, refresh);
|
|
12492
|
+
};
|
|
12493
|
+
}
|
|
12494
|
+
};
|
|
12495
|
+
}
|
|
12331
12496
|
|
|
12332
12497
|
// src/simulation.ts
|
|
12333
12498
|
var PajaSimulationError = class extends Error {
|
|
@@ -12337,6 +12502,8 @@ var PajaSimulationError = class extends Error {
|
|
|
12337
12502
|
}
|
|
12338
12503
|
};
|
|
12339
12504
|
var PAJA_SIMULATION_DOMAINS = [
|
|
12505
|
+
"shell",
|
|
12506
|
+
"gamepad",
|
|
12340
12507
|
"relay",
|
|
12341
12508
|
"outbox",
|
|
12342
12509
|
"storage",
|
|
@@ -13854,6 +14021,7 @@ var audioManager = {
|
|
|
13854
14021
|
}
|
|
13855
14022
|
};
|
|
13856
14023
|
var RUNTIME_NATIVE_DOMAINS = [
|
|
14024
|
+
"shell",
|
|
13857
14025
|
"relay",
|
|
13858
14026
|
"identity",
|
|
13859
14027
|
"storage",
|
|
@@ -13878,7 +14046,8 @@ var SERVICE_ONLY_DOMAINS = [
|
|
|
13878
14046
|
"webrtc",
|
|
13879
14047
|
"dm",
|
|
13880
14048
|
"count",
|
|
13881
|
-
"fs"
|
|
14049
|
+
"fs",
|
|
14050
|
+
"gamepad"
|
|
13882
14051
|
];
|
|
13883
14052
|
function buildShellCapabilities(hooks) {
|
|
13884
14053
|
const disabled = new Set(hooks.capabilities?.disabledDomains ?? []);
|
|
@@ -13972,14 +14141,21 @@ function handleShellReady({
|
|
|
13972
14141
|
if (state.initSent.get(sourceWindow) === sourceRegistrationId) {
|
|
13973
14142
|
return;
|
|
13974
14143
|
}
|
|
13975
|
-
const
|
|
13976
|
-
if (!
|
|
13977
|
-
registerNip5dSessionIfNeeded({ origin, runtime, state, sourceRegistrationId, windowId, identity });
|
|
13978
|
-
const environment = originRegistry.getEnvironment(sourceWindow) ?? resolveShellEnvironment(hooks, identity);
|
|
13979
|
-
state.environments.set(windowId, environment);
|
|
14144
|
+
const environment = registerSourceSession({ hooks, origin, runtime, state, sourceRegistrationId, sourceWindow, windowId });
|
|
14145
|
+
if (!environment?.capabilities.domains.includes("shell")) return;
|
|
13980
14146
|
postShellInit(sourceWindow, environment);
|
|
13981
14147
|
state.initSent.set(sourceWindow, sourceRegistrationId);
|
|
13982
14148
|
}
|
|
14149
|
+
function registerSourceSession(options) {
|
|
14150
|
+
const { hooks, origin, runtime, state, sourceRegistrationId, sourceWindow, windowId } = options;
|
|
14151
|
+
const identity = resolveNip5dIdentity(hooks, windowId, sourceWindow, runtime.sessionRegistry.getEntryByWindowId(windowId));
|
|
14152
|
+
if (!identity) return null;
|
|
14153
|
+
registerNip5dSessionIfNeeded({ origin, runtime, state, sourceRegistrationId, windowId, identity });
|
|
14154
|
+
const existing = state.environments.get(windowId);
|
|
14155
|
+
const environment = originRegistry.getEnvironment(sourceWindow) ?? existing ?? resolveShellEnvironment(hooks, identity);
|
|
14156
|
+
state.environments.set(windowId, environment);
|
|
14157
|
+
return environment;
|
|
14158
|
+
}
|
|
13983
14159
|
function registerNip5dSessionIfNeeded({
|
|
13984
14160
|
origin,
|
|
13985
14161
|
runtime,
|
|
@@ -13994,9 +14170,14 @@ function registerNip5dSessionIfNeeded({
|
|
|
13994
14170
|
return;
|
|
13995
14171
|
}
|
|
13996
14172
|
if (existing && previousRegistration !== void 0) {
|
|
14173
|
+
runtime.destroyWindow(windowId);
|
|
13997
14174
|
runtime.sessionRegistry.unregister(windowId);
|
|
14175
|
+
state.environments.delete(windowId);
|
|
14176
|
+
}
|
|
14177
|
+
if (existing && previousRegistration === void 0) {
|
|
14178
|
+
state.sessionRegistration.set(windowId, sourceRegistrationId);
|
|
14179
|
+
return;
|
|
13998
14180
|
}
|
|
13999
|
-
if (existing && previousRegistration === void 0) return;
|
|
14000
14181
|
const entry = {
|
|
14001
14182
|
pubkey: "",
|
|
14002
14183
|
windowId,
|
|
@@ -14011,7 +14192,7 @@ function registerNip5dSessionIfNeeded({
|
|
|
14011
14192
|
runtime.sessionRegistry.register(windowId, entry);
|
|
14012
14193
|
state.sessionRegistration.set(windowId, sourceRegistrationId);
|
|
14013
14194
|
}
|
|
14014
|
-
function resolveNip5dIdentity(hooks, windowId, sourceWindow) {
|
|
14195
|
+
function resolveNip5dIdentity(hooks, windowId, sourceWindow, existingSession) {
|
|
14015
14196
|
const hookIdentity = hooks.onNip5dIframeCreate?.(windowId);
|
|
14016
14197
|
if (hookIdentity !== null && hookIdentity !== void 0) {
|
|
14017
14198
|
return Object.freeze({
|
|
@@ -14021,7 +14202,8 @@ function resolveNip5dIdentity(hooks, windowId, sourceWindow) {
|
|
|
14021
14202
|
}
|
|
14022
14203
|
const originIdentity = originRegistry.getIdentity(sourceWindow);
|
|
14023
14204
|
if (!originIdentity) {
|
|
14024
|
-
return null;
|
|
14205
|
+
if (existingSession?.provenance !== "nip-5d" || typeof existingSession.dTag !== "string" || typeof existingSession.aggregateHash !== "string") return null;
|
|
14206
|
+
return Object.freeze({ dTag: existingSession.dTag, aggregateHash: existingSession.aggregateHash });
|
|
14025
14207
|
}
|
|
14026
14208
|
return Object.freeze({
|
|
14027
14209
|
dTag: originIdentity.dTag,
|
|
@@ -14082,6 +14264,15 @@ function createShellBridge(hooks) {
|
|
|
14082
14264
|
}
|
|
14083
14265
|
const msg = event.data;
|
|
14084
14266
|
if (typeof msg !== "object" || msg === null || typeof msg.type !== "string") return;
|
|
14267
|
+
if (!registerSourceSession({
|
|
14268
|
+
hooks,
|
|
14269
|
+
origin: event.origin,
|
|
14270
|
+
runtime,
|
|
14271
|
+
state: shellReadyState,
|
|
14272
|
+
sourceRegistrationId: originRegistry.getRegistrationId(sourceWindow) ?? 0,
|
|
14273
|
+
sourceWindow,
|
|
14274
|
+
windowId
|
|
14275
|
+
})) return;
|
|
14085
14276
|
if (msg.type === "shell.ready") {
|
|
14086
14277
|
handleShellReady({
|
|
14087
14278
|
hooks,
|
|
@@ -14119,6 +14310,11 @@ function createShellBridge(hooks) {
|
|
|
14119
14310
|
}
|
|
14120
14311
|
};
|
|
14121
14312
|
}
|
|
14313
|
+
var CONTROLLER_FEATURES = ["gamepad", "hid", "usb"];
|
|
14314
|
+
function denyNappletControllerAccess(frame) {
|
|
14315
|
+
const remaining = (frame.getAttribute("allow") ?? "").split(";").map((entry) => entry.trim()).filter((entry) => entry && !CONTROLLER_FEATURES.some((feature) => entry === feature || entry.startsWith(`${feature} `)));
|
|
14316
|
+
frame.setAttribute("allow", [...remaining, ...CONTROLLER_FEATURES.map((feature) => `${feature} 'none'`)].join("; "));
|
|
14317
|
+
}
|
|
14122
14318
|
function createIntentUriNormalizer() {
|
|
14123
14319
|
const hasOwn2 = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
14124
14320
|
const fail2 = (message2) => {
|
|
@@ -14309,7 +14505,7 @@ function scriptJson(value) {
|
|
|
14309
14505
|
return JSON.stringify(value).replace(/</g, "\\u003c");
|
|
14310
14506
|
}
|
|
14311
14507
|
function renderNappletNamespacePrelude(options) {
|
|
14312
|
-
const domains = uniqueBareDomains(
|
|
14508
|
+
const domains = uniqueBareDomains(options.domains);
|
|
14313
14509
|
return `<script data-kehto-nip5d-injection>(${nappletNamespacePrelude.toString()})(${scriptJson(domains)}, (${createIntentUriNormalizer.toString()})());<\/script>`;
|
|
14314
14510
|
}
|
|
14315
14511
|
function injectNappletNamespacePrelude(html, options) {
|
|
@@ -14498,7 +14694,7 @@ function nappletNamespacePrelude(domains, normalizeIntentUri2) {
|
|
|
14498
14694
|
return Object.freeze(strings);
|
|
14499
14695
|
}
|
|
14500
14696
|
function supports2(domain) {
|
|
14501
|
-
return typeof domain === "string" &&
|
|
14697
|
+
return typeof domain === "string" && !!target.napplet && Object.prototype.hasOwnProperty.call(target.napplet, domain);
|
|
14502
14698
|
}
|
|
14503
14699
|
const shell2 = {
|
|
14504
14700
|
ready: () => ready,
|
|
@@ -15579,6 +15775,63 @@ function nappletNamespacePrelude(domains, normalizeIntentUri2) {
|
|
|
15579
15775
|
})
|
|
15580
15776
|
};
|
|
15581
15777
|
}
|
|
15778
|
+
function makeGamepad() {
|
|
15779
|
+
let state = { available: true, focused: false, pads: [] };
|
|
15780
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
15781
|
+
const copy = (value) => ({
|
|
15782
|
+
available: value.available,
|
|
15783
|
+
focused: value.focused,
|
|
15784
|
+
...value.reason === void 0 ? {} : { reason: value.reason },
|
|
15785
|
+
pads: value.pads.map((pad3) => pad3 === null ? null : {
|
|
15786
|
+
index: pad3.index,
|
|
15787
|
+
id: pad3.id,
|
|
15788
|
+
mapping: pad3.mapping,
|
|
15789
|
+
connected: true,
|
|
15790
|
+
timestamp: pad3.timestamp,
|
|
15791
|
+
axes: [...pad3.axes],
|
|
15792
|
+
buttons: pad3.buttons.map(({ value: value2, pressed, touched }) => ({ value: value2, pressed, touched }))
|
|
15793
|
+
})
|
|
15794
|
+
});
|
|
15795
|
+
const numberIn = (value, min, max) => typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
|
|
15796
|
+
const valid = (value) => {
|
|
15797
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
15798
|
+
const candidate = value;
|
|
15799
|
+
if (typeof candidate.available !== "boolean" || typeof candidate.focused !== "boolean" || !Array.isArray(candidate.pads)) return false;
|
|
15800
|
+
if (candidate.available ? candidate.reason !== void 0 : candidate.focused || !["blocked", "unavailable"].includes(candidate.reason ?? "")) return false;
|
|
15801
|
+
return Array.from(candidate.pads).every((pad3) => {
|
|
15802
|
+
if (pad3 === null) return true;
|
|
15803
|
+
if (!pad3 || typeof pad3 !== "object" || !Number.isInteger(pad3.index) || pad3.index < 0 || typeof pad3.id !== "string" || typeof pad3.mapping !== "string" || pad3.connected !== true || !Number.isFinite(pad3.timestamp) || !Array.isArray(pad3.axes) || !Array.isArray(pad3.buttons)) return false;
|
|
15804
|
+
if (!candidate.focused && pad3.timestamp !== 0) return false;
|
|
15805
|
+
if (!Array.from(pad3.axes).every((axis) => numberIn(axis, -1, 1) && (candidate.focused || axis === 0))) return false;
|
|
15806
|
+
return Array.from(pad3.buttons).every((button2) => button2 && numberIn(button2.value, 0, 1) && typeof button2.pressed === "boolean" && typeof button2.touched === "boolean" && (candidate.focused || button2.value === 0 && !button2.pressed && !button2.touched));
|
|
15807
|
+
});
|
|
15808
|
+
};
|
|
15809
|
+
listen((event) => {
|
|
15810
|
+
if (!isParentMessage(event)) return;
|
|
15811
|
+
const incoming = event.data;
|
|
15812
|
+
if (!incoming || incoming.type !== "gamepad.state" || "id" in incoming || !valid(incoming)) return;
|
|
15813
|
+
state = copy(incoming);
|
|
15814
|
+
const snapshot = copy(state);
|
|
15815
|
+
const recipients = Array.from(handlers);
|
|
15816
|
+
for (const entry of recipients) if (handlers.has(entry)) entry.handler(copy(snapshot));
|
|
15817
|
+
});
|
|
15818
|
+
const api = {
|
|
15819
|
+
get available() {
|
|
15820
|
+
return state.available;
|
|
15821
|
+
},
|
|
15822
|
+
get focused() {
|
|
15823
|
+
return state.focused;
|
|
15824
|
+
},
|
|
15825
|
+
getGamepads: () => copy(state).pads,
|
|
15826
|
+
onChange(handler) {
|
|
15827
|
+
const entry = { handler };
|
|
15828
|
+
handlers.add(entry);
|
|
15829
|
+
return subscriptionHandle(() => handlers.delete(entry));
|
|
15830
|
+
}
|
|
15831
|
+
};
|
|
15832
|
+
post({ type: "gamepad.subscribe" });
|
|
15833
|
+
return api;
|
|
15834
|
+
}
|
|
15582
15835
|
function makeDm() {
|
|
15583
15836
|
const req = (type, payload) => request({ type, ...payload }, `${type}.result`, withoutEnvelope, { rejectOnError: false });
|
|
15584
15837
|
return {
|
|
@@ -15625,7 +15878,8 @@ function nappletNamespacePrelude(domains, normalizeIntentUri2) {
|
|
|
15625
15878
|
};
|
|
15626
15879
|
}
|
|
15627
15880
|
const intentDelivery = allowed2.has("intent") ? makeIntentDelivery() : void 0;
|
|
15628
|
-
const shell = makeShell();
|
|
15881
|
+
const shell = allowed2.has("shell") ? makeShell() : void 0;
|
|
15882
|
+
let gamepad;
|
|
15629
15883
|
let inc;
|
|
15630
15884
|
let identity;
|
|
15631
15885
|
let theme;
|
|
@@ -15648,9 +15902,10 @@ function nappletNamespacePrelude(domains, normalizeIntentUri2) {
|
|
|
15648
15902
|
return intent;
|
|
15649
15903
|
}
|
|
15650
15904
|
function isProtectedDomain(domain) {
|
|
15651
|
-
return domain === "shell" || domain === "inc" || domain === "identity" || domain === "theme" || domain === "intent";
|
|
15905
|
+
return domain === "gamepad" || domain === "shell" || domain === "inc" || domain === "identity" || domain === "theme" || domain === "intent";
|
|
15652
15906
|
}
|
|
15653
15907
|
function makeDomain(domain, existing) {
|
|
15908
|
+
if (domain === "gamepad") return gamepad ??= makeGamepad();
|
|
15654
15909
|
if (domain === "shell") return shell;
|
|
15655
15910
|
if (domain === "inc") return makeProtectedInc(existing);
|
|
15656
15911
|
if (domain === "identity") return makeProtectedIdentity();
|
|
@@ -21172,6 +21427,9 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
|
|
|
21172
21427
|
}
|
|
21173
21428
|
}
|
|
21174
21429
|
};
|
|
21430
|
+
if (getSimulation().capabilities.domains.gamepad) {
|
|
21431
|
+
services.gamepad = createGamepadService(browserGamepadOptions(typeof window === "undefined" ? void 0 : window, (target) => originRegistry.getWindowId(target)));
|
|
21432
|
+
}
|
|
21175
21433
|
if (getSimulation().capabilities.domains.keys && typeof document !== "undefined") {
|
|
21176
21434
|
services.keys = createKeysService({ listenerTarget: document });
|
|
21177
21435
|
}
|
|
@@ -21580,6 +21838,7 @@ function registerFrameForGeneration(frame, config, generation, identity, environ
|
|
|
21580
21838
|
return windowId;
|
|
21581
21839
|
}
|
|
21582
21840
|
async function navigateFrame(frame, config, generation, adapter, resolvedTarget, windowId, isCurrent, onRegistered) {
|
|
21841
|
+
denyNappletControllerAccess(frame);
|
|
21583
21842
|
const identity = getTargetOriginIdentity(config, resolvedTarget);
|
|
21584
21843
|
const environment = resolvePajaFrameEnvironment(adapter, identity);
|
|
21585
21844
|
const domains = environment.capabilities.domains;
|
|
@@ -23142,6 +23401,7 @@ function createRuntimeTabFrame(tab, state, context) {
|
|
|
23142
23401
|
frame.id = `napplet-frame-${tab.id}`;
|
|
23143
23402
|
frame.className = "tab-panel";
|
|
23144
23403
|
frame.title = `Napplet runtime target: ${tab.title}`;
|
|
23404
|
+
denyNappletControllerAccess(frame);
|
|
23145
23405
|
frame.sandbox.add("allow-scripts");
|
|
23146
23406
|
frame.sandbox.remove("allow-same-origin");
|
|
23147
23407
|
frame.dataset.tabId = tab.id;
|
|
@@ -24611,6 +24871,7 @@ async function launchPajaSharedIntent(state, context, intent, progress, setPoint
|
|
|
24611
24871
|
if (!progress.isActive()) return;
|
|
24612
24872
|
const frame = document.createElement("iframe");
|
|
24613
24873
|
frame.hidden = true;
|
|
24874
|
+
denyNappletControllerAccess(frame);
|
|
24614
24875
|
frame.sandbox.add("allow-scripts");
|
|
24615
24876
|
frame.setAttribute("aria-hidden", "true");
|
|
24616
24877
|
context.stage.append(frame);
|