@kehto/paja 0.22.0 → 0.24.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 +14 -0
- package/dist/browser-host.js +337 -214
- package/dist/browser-host.js.map +1 -1
- package/dist/{chunk-RMYEHOOR.js → chunk-ZRAED35O.js} +31 -5
- package/dist/chunk-ZRAED35O.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-RMYEHOOR.js.map +0 -1
package/README.md
CHANGED
|
@@ -198,6 +198,8 @@ runtime tabs in local storage so returning to `/web/paja/` restores the previous
|
|
|
198
198
|
pointer set. An explicit pointer in the URL still takes precedence over restored
|
|
199
199
|
tabs.
|
|
200
200
|
|
|
201
|
+
The browser page title follows the active napplet tab name, including when switching or closing tabs. With no active napplet, the title is `@kehto/paja`.
|
|
202
|
+
|
|
201
203
|
The static artifact defaults to Paja's standard live relays and memory uploads.
|
|
202
204
|
To point it at specific live relays or Blossom upload servers, pass
|
|
203
205
|
comma-separated host lists when generating the artifact:
|
|
@@ -252,6 +254,14 @@ catalog. Entries preserve exact conventions and ordered parameter names under
|
|
|
252
254
|
publisher/kind-safe opaque IDs, including nameless root and snapshot artifacts.
|
|
253
255
|
The target's resolved `intent` domain must be available; INC is not required.
|
|
254
256
|
|
|
257
|
+
Catalog installs, replacements, removals, and user default-handler updates emit
|
|
258
|
+
`intent.changed` to eligible open napplets (`napplet.intent.onChanged(...)`).
|
|
259
|
+
Replacements notify both removed and added archetypes, once per slug, using the
|
|
260
|
+
current filtered catalog. A `no handler` rejection remains terminal: callers must
|
|
261
|
+
retry explicitly; installing a handler does not replay the failed invocation.
|
|
262
|
+
This follows `napplet/naps` NAP-INTENT on master (last changed at `e5308ac`), whose
|
|
263
|
+
runtime behavior recommends notifications on catalog/default changes.
|
|
264
|
+
|
|
255
265
|
Selection uses exact contracts and user-owned default, chooser, recommendation,
|
|
256
266
|
and explicit-authorization policy. Explicit handler IDs require sender-aware
|
|
257
267
|
authorization and cannot address an arbitrary running frame.
|
|
@@ -548,3 +558,7 @@ remain a documented upstream spec gap; no host sender identity is invented.
|
|
|
548
558
|
## GAMEPAD integration
|
|
549
559
|
|
|
550
560
|
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).
|
|
561
|
+
|
|
562
|
+
## Controller diagnostics
|
|
563
|
+
|
|
564
|
+
Paja shows a numbered controller icon directly beside the console arrow for each controller the browser detects. Each slot has its own color and input animation; hover for the controller model and activity state. Buttons and stick movement light up only that controller (stick movement below 0.12 is ignored). Quick taps retain the highlight briefly so they are easy to spot. Reduced-motion settings keep the activity highlight without animation. Disconnecting removes the icon. Browsers may require a button press before exposing a newly connected controller. These host diagnostics work without a napplet gamepad subscription and do not change focus-scoped input delivery.
|
package/dist/browser-host.js
CHANGED
|
@@ -16355,6 +16355,93 @@ function installPajaSidebarSections() {
|
|
|
16355
16355
|
return () => disposers.forEach((dispose) => dispose());
|
|
16356
16356
|
}
|
|
16357
16357
|
|
|
16358
|
+
// src/browser-gamepad-indicators.ts
|
|
16359
|
+
var ICON = '<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><path d="M7 6h10c3 0 5 10 3 12-2 2-5-3-6-3h-4c-1 0-4 5-6 3C2 16 4 6 7 6Z"/><path d="M7 9v6m-3-3h6"/><circle cx="16" cy="10" r="1" fill="currentColor"/><circle cx="19" cy="13" r="1" fill="currentColor"/></svg>';
|
|
16360
|
+
function installPajaGamepadIndicators() {
|
|
16361
|
+
const container = document.getElementById("paja-gamepads");
|
|
16362
|
+
if (!container || typeof navigator.getGamepads !== "function") return () => {
|
|
16363
|
+
};
|
|
16364
|
+
const icons = /* @__PURE__ */ new Map();
|
|
16365
|
+
const activeUntil = /* @__PURE__ */ new Map();
|
|
16366
|
+
let frame;
|
|
16367
|
+
let disposed = false;
|
|
16368
|
+
const makeIcon = (pad3) => {
|
|
16369
|
+
const icon = document.createElement("span");
|
|
16370
|
+
icon.className = "gamepad-indicator";
|
|
16371
|
+
icon.dataset.gamepadIndex = String(pad3.index);
|
|
16372
|
+
icon.setAttribute("role", "img");
|
|
16373
|
+
icon.style.setProperty("--pad-color", `hsl(${(pad3.index * 137.508 + 155) % 360} 75% 70%)`);
|
|
16374
|
+
icon.style.setProperty("--pad-turn", `${(pad3.index % 2 ? -1 : 1) * (6 + pad3.index * 2)}deg`);
|
|
16375
|
+
icon.style.setProperty("--pad-lift", `${-2 - pad3.index % 4}px`);
|
|
16376
|
+
icon.style.setProperty("--pad-duration", `${480 + pad3.index * 85}ms`);
|
|
16377
|
+
icon.style.setProperty("--pad-animation", ["gamepad-bounce", "gamepad-rock", "gamepad-pulse", "gamepad-nudge"][pad3.index % 4]);
|
|
16378
|
+
icon.innerHTML = ICON;
|
|
16379
|
+
const number = document.createElement("small");
|
|
16380
|
+
number.textContent = String(pad3.index + 1);
|
|
16381
|
+
icon.append(number);
|
|
16382
|
+
container.append(icon);
|
|
16383
|
+
icons.set(pad3.index, icon);
|
|
16384
|
+
return icon;
|
|
16385
|
+
};
|
|
16386
|
+
const sample = () => {
|
|
16387
|
+
let pads;
|
|
16388
|
+
try {
|
|
16389
|
+
pads = Array.from(navigator.getGamepads());
|
|
16390
|
+
} catch {
|
|
16391
|
+
pads = [];
|
|
16392
|
+
}
|
|
16393
|
+
const connected = /* @__PURE__ */ new Set();
|
|
16394
|
+
const focused = document.visibilityState !== "hidden" && document.hasFocus();
|
|
16395
|
+
const now2 = performance.now();
|
|
16396
|
+
for (const pad3 of pads) {
|
|
16397
|
+
if (!pad3?.connected) continue;
|
|
16398
|
+
connected.add(pad3.index);
|
|
16399
|
+
const icon = icons.get(pad3.index) ?? makeIcon(pad3);
|
|
16400
|
+
const input = focused && (pad3.axes.some((axis) => Math.abs(axis) > 0.12) || pad3.buttons.some((button2) => button2.pressed || button2.value > 0.05));
|
|
16401
|
+
if (input) activeUntil.set(pad3.index, now2 + 420);
|
|
16402
|
+
if (!focused) activeUntil.delete(pad3.index);
|
|
16403
|
+
const active = now2 < (activeUntil.get(pad3.index) ?? 0);
|
|
16404
|
+
const activity = active ? "active" : "idle";
|
|
16405
|
+
if (icon.dataset.activity !== activity || icon.dataset.model !== pad3.id) {
|
|
16406
|
+
icon.dataset.activity = activity;
|
|
16407
|
+
icon.dataset.model = pad3.id;
|
|
16408
|
+
const label = `Controller ${pad3.index + 1}: ${pad3.id} \u2014 ${activity}`;
|
|
16409
|
+
icon.setAttribute("aria-label", label);
|
|
16410
|
+
icon.title = label;
|
|
16411
|
+
}
|
|
16412
|
+
}
|
|
16413
|
+
for (const [index, icon] of icons) {
|
|
16414
|
+
if (connected.has(index)) continue;
|
|
16415
|
+
icon.remove();
|
|
16416
|
+
icons.delete(index);
|
|
16417
|
+
activeUntil.delete(index);
|
|
16418
|
+
}
|
|
16419
|
+
};
|
|
16420
|
+
const tick = () => {
|
|
16421
|
+
frame = void 0;
|
|
16422
|
+
if (disposed) return;
|
|
16423
|
+
sample();
|
|
16424
|
+
if (document.visibilityState !== "hidden") frame = requestAnimationFrame(tick);
|
|
16425
|
+
};
|
|
16426
|
+
const refresh = () => {
|
|
16427
|
+
if (frame !== void 0) cancelAnimationFrame(frame);
|
|
16428
|
+
tick();
|
|
16429
|
+
};
|
|
16430
|
+
const events = ["gamepadconnected", "gamepaddisconnected", "focus", "blur"];
|
|
16431
|
+
for (const event of events) window.addEventListener(event, refresh);
|
|
16432
|
+
document.addEventListener("visibilitychange", refresh);
|
|
16433
|
+
tick();
|
|
16434
|
+
return () => {
|
|
16435
|
+
disposed = true;
|
|
16436
|
+
if (frame !== void 0) cancelAnimationFrame(frame);
|
|
16437
|
+
for (const event of events) window.removeEventListener(event, refresh);
|
|
16438
|
+
document.removeEventListener("visibilitychange", refresh);
|
|
16439
|
+
container.replaceChildren();
|
|
16440
|
+
icons.clear();
|
|
16441
|
+
activeUntil.clear();
|
|
16442
|
+
};
|
|
16443
|
+
}
|
|
16444
|
+
|
|
16358
16445
|
// ../../node_modules/.pnpm/nostr-tools@2.23.3_typescript@5.9.3/node_modules/nostr-tools/lib/esm/pool.js
|
|
16359
16446
|
var verifiedSymbol3 = /* @__PURE__ */ Symbol("verified");
|
|
16360
16447
|
var isRecord4 = (obj) => obj instanceof Object;
|
|
@@ -18331,208 +18418,39 @@ function createBrowserBleController(activation, api = browserBluetoothApi()) {
|
|
|
18331
18418
|
};
|
|
18332
18419
|
}
|
|
18333
18420
|
|
|
18334
|
-
// src/browser-intent-
|
|
18335
|
-
|
|
18336
|
-
|
|
18337
|
-
|
|
18338
|
-
|
|
18339
|
-
|
|
18340
|
-
|
|
18341
|
-
|
|
18342
|
-
|
|
18343
|
-
|
|
18344
|
-
|
|
18345
|
-
const acceptance = Object.freeze({ completion: this.dispatch(params) });
|
|
18346
|
-
this.options.onAccepted?.(params, acceptance);
|
|
18347
|
-
return acceptance;
|
|
18348
|
-
}
|
|
18349
|
-
/** Complete an already accepted delivery. Kept public for host diagnostics and tests. */
|
|
18350
|
-
async dispatch(params) {
|
|
18351
|
-
const dispatch2 = freezeDispatch(params);
|
|
18352
|
-
let reason = "no-current-target";
|
|
18353
|
-
for (let attempt = 1; attempt <= this.maxAttempts; attempt += 1) {
|
|
18354
|
-
let generation;
|
|
18355
|
-
try {
|
|
18356
|
-
generation = await this.options.openOrReuse(dispatch2, attempt);
|
|
18357
|
-
} catch {
|
|
18358
|
-
reason = "open-failed";
|
|
18359
|
-
continue;
|
|
18360
|
-
}
|
|
18361
|
-
if (!generation) {
|
|
18362
|
-
reason = "open-failed";
|
|
18363
|
-
continue;
|
|
18364
|
-
}
|
|
18365
|
-
try {
|
|
18366
|
-
await this.options.waitForReady(generation);
|
|
18367
|
-
} catch {
|
|
18368
|
-
reason = "ready-failed";
|
|
18369
|
-
continue;
|
|
18370
|
-
}
|
|
18371
|
-
if (!await this.options.isCurrent(generation)) {
|
|
18372
|
-
reason = "no-current-target";
|
|
18373
|
-
continue;
|
|
18374
|
-
}
|
|
18375
|
-
try {
|
|
18376
|
-
await this.options.send(generation, dispatch2);
|
|
18377
|
-
this.options.onDelivered?.(dispatch2);
|
|
18378
|
-
return;
|
|
18379
|
-
} catch {
|
|
18380
|
-
this.options.onTerminal?.(dispatch2, "send-failed");
|
|
18381
|
-
throw new Error("intent target send failed");
|
|
18382
|
-
}
|
|
18383
|
-
}
|
|
18384
|
-
this.options.onTerminal?.(dispatch2, reason);
|
|
18385
|
-
throw new Error(`intent target ${reason}`);
|
|
18386
|
-
}
|
|
18387
|
-
};
|
|
18388
|
-
function normalizeAttempts(value) {
|
|
18389
|
-
if (value === void 0) return 2;
|
|
18390
|
-
if (!Number.isFinite(value)) throw new TypeError("maxAttempts must be finite");
|
|
18391
|
-
return Math.min(MAX_INTENT_DELIVERY_ATTEMPTS, Math.max(1, Math.floor(value)));
|
|
18392
|
-
}
|
|
18393
|
-
function freezeDispatch(params) {
|
|
18394
|
-
if (!params || typeof params.handler !== "string" || params.handler.length === 0) {
|
|
18395
|
-
throw new TypeError("Intent dispatch requires a handler");
|
|
18396
|
-
}
|
|
18397
|
-
if (typeof params.sender !== "string" || params.sender.length === 0 || typeof params.archetype !== "string" || params.archetype.length === 0 || typeof params.action !== "string" || params.action.length === 0 || typeof params.convention !== "string" || params.convention.length === 0) {
|
|
18398
|
-
throw new TypeError("Intent dispatch requires canonical routing fields");
|
|
18399
|
-
}
|
|
18400
|
-
const payload = freezeValue(params.payload);
|
|
18401
|
-
const behavior = params.behavior === void 0 ? void 0 : freezeValue({ ...params.behavior });
|
|
18402
|
-
return Object.freeze({
|
|
18403
|
-
handler: params.handler,
|
|
18404
|
-
sender: params.sender,
|
|
18405
|
-
archetype: params.archetype,
|
|
18406
|
-
action: params.action,
|
|
18407
|
-
convention: params.convention,
|
|
18408
|
-
...params.payload === void 0 ? {} : { payload },
|
|
18409
|
-
...behavior === void 0 ? {} : { behavior },
|
|
18410
|
-
...params.sourceWindowId === void 0 ? {} : { sourceWindowId: params.sourceWindowId }
|
|
18411
|
-
});
|
|
18412
|
-
}
|
|
18413
|
-
function freezeValue(value, seen = /* @__PURE__ */ new WeakMap()) {
|
|
18414
|
-
if (typeof value !== "object" || value === null) return value;
|
|
18415
|
-
const existing = seen.get(value);
|
|
18416
|
-
if (existing !== void 0) return existing;
|
|
18417
|
-
if (Array.isArray(value)) {
|
|
18418
|
-
const copy2 = [];
|
|
18419
|
-
seen.set(value, copy2);
|
|
18420
|
-
for (const item of value) copy2.push(freezeValue(item, seen));
|
|
18421
|
-
return Object.freeze(copy2);
|
|
18422
|
-
}
|
|
18423
|
-
const copy = {};
|
|
18424
|
-
seen.set(value, copy);
|
|
18425
|
-
for (const [key, item] of Object.entries(value)) copy[key] = freezeValue(item, seen);
|
|
18426
|
-
return Object.freeze(copy);
|
|
18427
|
-
}
|
|
18428
|
-
|
|
18429
|
-
// src/installed-napplet-catalog.ts
|
|
18430
|
-
function matchesInstalledNappletRecord(record2, target) {
|
|
18431
|
-
return target.id === record2.id && target.aggregateHash === record2.aggregateHash;
|
|
18432
|
-
}
|
|
18433
|
-
var InstalledNappletCatalog = class {
|
|
18434
|
-
records = /* @__PURE__ */ new Map();
|
|
18435
|
-
listeners = /* @__PURE__ */ new Set();
|
|
18436
|
-
/** Insert or replace a record from an already resolver-verified pointer. */
|
|
18437
|
-
install(resolved) {
|
|
18438
|
-
const record2 = freezeRecord({
|
|
18439
|
-
id: resolved.manifest.catalogId,
|
|
18440
|
-
dTag: resolved.dTag,
|
|
18441
|
-
aggregateHash: resolved.aggregateHash,
|
|
18442
|
-
pointer: copyPointer(resolved.pointer),
|
|
18443
|
-
...resolved.manifest.title === void 0 ? {} : { title: resolved.manifest.title },
|
|
18444
|
-
requires: [...resolved.manifest.requires],
|
|
18445
|
-
optional: [...resolved.manifest.optional ?? []],
|
|
18446
|
-
archetypes: resolved.manifest.archetypes.map((archetype) => ({
|
|
18447
|
-
slug: archetype.slug,
|
|
18448
|
-
convention: archetype.convention,
|
|
18449
|
-
params: [...archetype.params]
|
|
18450
|
-
}))
|
|
18451
|
-
});
|
|
18452
|
-
this.records.set(record2.id, record2);
|
|
18453
|
-
this.notify(record2.id);
|
|
18454
|
-
return record2;
|
|
18455
|
-
}
|
|
18456
|
-
/** Remove an artifact explicitly; frame teardown never calls this method. */
|
|
18457
|
-
remove(id) {
|
|
18458
|
-
const removed = this.records.delete(id);
|
|
18459
|
-
if (removed) this.notify(id);
|
|
18460
|
-
return removed;
|
|
18461
|
-
}
|
|
18462
|
-
/** Return whether a verified installation exists for a catalog ID. */
|
|
18463
|
-
has(id) {
|
|
18464
|
-
return this.records.has(id);
|
|
18465
|
-
}
|
|
18466
|
-
/** Return immutable serializable installed-artifact facts. */
|
|
18467
|
-
installed() {
|
|
18468
|
-
return [...this.records.values()];
|
|
18469
|
-
}
|
|
18470
|
-
/** Return a verified record by catalog ID. */
|
|
18471
|
-
get(id) {
|
|
18472
|
-
return this.records.get(id);
|
|
18473
|
-
}
|
|
18474
|
-
/**
|
|
18475
|
-
* Atomically confirm that a resolved target still belongs to the exact record
|
|
18476
|
-
* selected before an async operation. The record object is the catalog version
|
|
18477
|
-
* token, so even a same-identity replacement cannot pass this check.
|
|
18478
|
-
*/
|
|
18479
|
-
validateCurrent(selected, target) {
|
|
18480
|
-
if (this.records.get(selected.id) !== selected) return null;
|
|
18481
|
-
return matchesInstalledNappletRecord(selected, target) ? selected : null;
|
|
18482
|
-
}
|
|
18483
|
-
/**
|
|
18484
|
-
* Return declared handlers whose host environment can receive intent delivery.
|
|
18485
|
-
* @param canReceiveIntent - Resolve intent availability for each verified identity;
|
|
18486
|
-
* without host policy, return declared candidates for the host to filter.
|
|
18487
|
-
* @returns Named intent candidates usable under the supplied host policy.
|
|
18488
|
-
*/
|
|
18489
|
-
intentCatalog(canReceiveIntent = () => true) {
|
|
18490
|
-
return this.installed().filter(canReceiveIntent).map((record2) => manifestToIntentCatalogEntry({
|
|
18491
|
-
catalogId: record2.id,
|
|
18492
|
-
...record2.title === void 0 ? {} : { title: record2.title },
|
|
18493
|
-
archetypes: record2.archetypes.map((archetype) => ({
|
|
18494
|
-
slug: archetype.slug,
|
|
18495
|
-
convention: archetype.convention,
|
|
18496
|
-
params: [...archetype.params]
|
|
18497
|
-
}))
|
|
18498
|
-
}));
|
|
18499
|
-
}
|
|
18500
|
-
/** Subscribe to explicit install and artifact-removal changes. */
|
|
18501
|
-
onChanged(listener) {
|
|
18502
|
-
this.listeners.add(listener);
|
|
18503
|
-
return () => this.listeners.delete(listener);
|
|
18504
|
-
}
|
|
18505
|
-
notify(id) {
|
|
18506
|
-
for (const listener of this.listeners) listener(id);
|
|
18507
|
-
}
|
|
18508
|
-
};
|
|
18509
|
-
function copyPointer(pointer) {
|
|
18510
|
-
if (pointer.type === "naddr") {
|
|
18511
|
-
return Object.freeze({
|
|
18512
|
-
type: "naddr",
|
|
18513
|
-
value: pointer.value,
|
|
18514
|
-
identifier: pointer.identifier,
|
|
18515
|
-
pubkey: pointer.pubkey,
|
|
18516
|
-
kind: pointer.kind,
|
|
18517
|
-
relays: Object.freeze([...pointer.relays])
|
|
18518
|
-
});
|
|
18519
|
-
}
|
|
18520
|
-
return Object.freeze({
|
|
18521
|
-
type: "nevent",
|
|
18522
|
-
value: pointer.value,
|
|
18523
|
-
id: pointer.id,
|
|
18524
|
-
...pointer.author === void 0 ? {} : { author: pointer.author },
|
|
18525
|
-
...pointer.kind === void 0 ? {} : { kind: pointer.kind },
|
|
18526
|
-
relays: Object.freeze([...pointer.relays])
|
|
18421
|
+
// src/browser-catalog-intent-service.ts
|
|
18422
|
+
function createPajaCatalogIntentService(adapter, host) {
|
|
18423
|
+
const resolver = createCatalogIntentResolver({
|
|
18424
|
+
loadCatalog: () => host.catalog.intentCatalog(
|
|
18425
|
+
(record2) => resolveShellEnvironment(adapter, record2).capabilities.domains.includes("intent")
|
|
18426
|
+
),
|
|
18427
|
+
targets: host.controller,
|
|
18428
|
+
getDefaultHandler: host.getDefaultHandler,
|
|
18429
|
+
chooseHandler: host.chooseHandler,
|
|
18430
|
+
authorizeExplicitHandler: host.authorizeExplicitHandler,
|
|
18431
|
+
resolveHandlerHint: host.resolveHandlerHint
|
|
18527
18432
|
});
|
|
18528
|
-
|
|
18529
|
-
|
|
18530
|
-
|
|
18531
|
-
...record2,
|
|
18532
|
-
requires: Object.freeze([...record2.requires]),
|
|
18533
|
-
optional: Object.freeze([...record2.optional ?? []]),
|
|
18534
|
-
archetypes: Object.freeze(record2.archetypes.map((archetype) => Object.freeze({ ...archetype, params: Object.freeze([...archetype.params]) })))
|
|
18433
|
+
const intentService = createIntentService({
|
|
18434
|
+
resolver,
|
|
18435
|
+
resolveSender: host.resolveSender
|
|
18535
18436
|
});
|
|
18437
|
+
let stopCatalogChanges;
|
|
18438
|
+
const service = {
|
|
18439
|
+
...intentService,
|
|
18440
|
+
onRegistered(context) {
|
|
18441
|
+
stopCatalogChanges?.();
|
|
18442
|
+
intentService.onRegistered?.(context);
|
|
18443
|
+
stopCatalogChanges = host.catalog.onChanged((_id, archetypes) => {
|
|
18444
|
+
for (const archetype of archetypes) resolver.notifyChanged(archetype);
|
|
18445
|
+
});
|
|
18446
|
+
},
|
|
18447
|
+
onUnregistered() {
|
|
18448
|
+
stopCatalogChanges?.();
|
|
18449
|
+
stopCatalogChanges = void 0;
|
|
18450
|
+
intentService.onUnregistered?.();
|
|
18451
|
+
}
|
|
18452
|
+
};
|
|
18453
|
+
return { service, notifyChanged: (archetype) => resolver.notifyChanged(archetype) };
|
|
18536
18454
|
}
|
|
18537
18455
|
|
|
18538
18456
|
// src/browser-upload.ts
|
|
@@ -21944,6 +21862,8 @@ function createPajaAdapter(config, getSimulation, onThemeService, onThemeBroadca
|
|
|
21944
21862
|
});
|
|
21945
21863
|
const adapter = {
|
|
21946
21864
|
ready,
|
|
21865
|
+
notifyIntentChanged: () => {
|
|
21866
|
+
},
|
|
21947
21867
|
setWindowBlossomServers: serviceBundle.setWindowBlossomServers,
|
|
21948
21868
|
relayPool: createPajaRelayHooks(relayBackend, getSimulation, relayConfig),
|
|
21949
21869
|
relayConfig,
|
|
@@ -21983,20 +21903,9 @@ function createPajaAdapter(config, getSimulation, onThemeService, onThemeBroadca
|
|
|
21983
21903
|
}
|
|
21984
21904
|
};
|
|
21985
21905
|
if (getSimulation().intent.enabled && intentHost) {
|
|
21986
|
-
const
|
|
21987
|
-
|
|
21988
|
-
|
|
21989
|
-
),
|
|
21990
|
-
targets: intentHost.controller,
|
|
21991
|
-
getDefaultHandler: intentHost.getDefaultHandler,
|
|
21992
|
-
chooseHandler: intentHost.chooseHandler,
|
|
21993
|
-
authorizeExplicitHandler: intentHost.authorizeExplicitHandler,
|
|
21994
|
-
resolveHandlerHint: intentHost.resolveHandlerHint
|
|
21995
|
-
});
|
|
21996
|
-
services.intent = createIntentService({
|
|
21997
|
-
resolver,
|
|
21998
|
-
resolveSender: intentHost.resolveSender
|
|
21999
|
-
});
|
|
21906
|
+
const intent = createPajaCatalogIntentService(adapter, intentHost);
|
|
21907
|
+
services.intent = intent.service;
|
|
21908
|
+
adapter.notifyIntentChanged = intent.notifyChanged;
|
|
22000
21909
|
}
|
|
22001
21910
|
return adapter;
|
|
22002
21911
|
}
|
|
@@ -23667,6 +23576,7 @@ function parseRuntimeTabsSnapshot(value) {
|
|
|
23667
23576
|
};
|
|
23668
23577
|
}
|
|
23669
23578
|
function renderRuntimeTabs(state) {
|
|
23579
|
+
document.title = getActiveTab(state)?.title || "@kehto/paja";
|
|
23670
23580
|
const tabsEl = document.getElementById("napplet-tabs");
|
|
23671
23581
|
if (!(tabsEl instanceof HTMLElement)) return;
|
|
23672
23582
|
tabsEl.replaceChildren(...state.tabs.map((tab) => renderTab(state, tab)));
|
|
@@ -24111,6 +24021,216 @@ function installLocalFileControls(load) {
|
|
|
24111
24021
|
function disposeNothing() {
|
|
24112
24022
|
}
|
|
24113
24023
|
|
|
24024
|
+
// src/browser-intent-controller.ts
|
|
24025
|
+
var MAX_INTENT_DELIVERY_ATTEMPTS = 10;
|
|
24026
|
+
var BrowserIntentController = class {
|
|
24027
|
+
constructor(options) {
|
|
24028
|
+
this.options = options;
|
|
24029
|
+
this.maxAttempts = normalizeAttempts(options.maxAttempts);
|
|
24030
|
+
}
|
|
24031
|
+
options;
|
|
24032
|
+
maxAttempts;
|
|
24033
|
+
/** Retain delivery work immediately; completion remains host-observable only. */
|
|
24034
|
+
accept(params) {
|
|
24035
|
+
const acceptance = Object.freeze({ completion: this.dispatch(params) });
|
|
24036
|
+
this.options.onAccepted?.(params, acceptance);
|
|
24037
|
+
return acceptance;
|
|
24038
|
+
}
|
|
24039
|
+
/** Complete an already accepted delivery. Kept public for host diagnostics and tests. */
|
|
24040
|
+
async dispatch(params) {
|
|
24041
|
+
const dispatch2 = freezeDispatch(params);
|
|
24042
|
+
let reason = "no-current-target";
|
|
24043
|
+
for (let attempt = 1; attempt <= this.maxAttempts; attempt += 1) {
|
|
24044
|
+
let generation;
|
|
24045
|
+
try {
|
|
24046
|
+
generation = await this.options.openOrReuse(dispatch2, attempt);
|
|
24047
|
+
} catch {
|
|
24048
|
+
reason = "open-failed";
|
|
24049
|
+
continue;
|
|
24050
|
+
}
|
|
24051
|
+
if (!generation) {
|
|
24052
|
+
reason = "open-failed";
|
|
24053
|
+
continue;
|
|
24054
|
+
}
|
|
24055
|
+
try {
|
|
24056
|
+
await this.options.waitForReady(generation);
|
|
24057
|
+
} catch {
|
|
24058
|
+
reason = "ready-failed";
|
|
24059
|
+
continue;
|
|
24060
|
+
}
|
|
24061
|
+
if (!await this.options.isCurrent(generation)) {
|
|
24062
|
+
reason = "no-current-target";
|
|
24063
|
+
continue;
|
|
24064
|
+
}
|
|
24065
|
+
try {
|
|
24066
|
+
await this.options.send(generation, dispatch2);
|
|
24067
|
+
this.options.onDelivered?.(dispatch2);
|
|
24068
|
+
return;
|
|
24069
|
+
} catch {
|
|
24070
|
+
this.options.onTerminal?.(dispatch2, "send-failed");
|
|
24071
|
+
throw new Error("intent target send failed");
|
|
24072
|
+
}
|
|
24073
|
+
}
|
|
24074
|
+
this.options.onTerminal?.(dispatch2, reason);
|
|
24075
|
+
throw new Error(`intent target ${reason}`);
|
|
24076
|
+
}
|
|
24077
|
+
};
|
|
24078
|
+
function normalizeAttempts(value) {
|
|
24079
|
+
if (value === void 0) return 2;
|
|
24080
|
+
if (!Number.isFinite(value)) throw new TypeError("maxAttempts must be finite");
|
|
24081
|
+
return Math.min(MAX_INTENT_DELIVERY_ATTEMPTS, Math.max(1, Math.floor(value)));
|
|
24082
|
+
}
|
|
24083
|
+
function freezeDispatch(params) {
|
|
24084
|
+
if (!params || typeof params.handler !== "string" || params.handler.length === 0) {
|
|
24085
|
+
throw new TypeError("Intent dispatch requires a handler");
|
|
24086
|
+
}
|
|
24087
|
+
if (typeof params.sender !== "string" || params.sender.length === 0 || typeof params.archetype !== "string" || params.archetype.length === 0 || typeof params.action !== "string" || params.action.length === 0 || typeof params.convention !== "string" || params.convention.length === 0) {
|
|
24088
|
+
throw new TypeError("Intent dispatch requires canonical routing fields");
|
|
24089
|
+
}
|
|
24090
|
+
const payload = freezeValue(params.payload);
|
|
24091
|
+
const behavior = params.behavior === void 0 ? void 0 : freezeValue({ ...params.behavior });
|
|
24092
|
+
return Object.freeze({
|
|
24093
|
+
handler: params.handler,
|
|
24094
|
+
sender: params.sender,
|
|
24095
|
+
archetype: params.archetype,
|
|
24096
|
+
action: params.action,
|
|
24097
|
+
convention: params.convention,
|
|
24098
|
+
...params.payload === void 0 ? {} : { payload },
|
|
24099
|
+
...behavior === void 0 ? {} : { behavior },
|
|
24100
|
+
...params.sourceWindowId === void 0 ? {} : { sourceWindowId: params.sourceWindowId }
|
|
24101
|
+
});
|
|
24102
|
+
}
|
|
24103
|
+
function freezeValue(value, seen = /* @__PURE__ */ new WeakMap()) {
|
|
24104
|
+
if (typeof value !== "object" || value === null) return value;
|
|
24105
|
+
const existing = seen.get(value);
|
|
24106
|
+
if (existing !== void 0) return existing;
|
|
24107
|
+
if (Array.isArray(value)) {
|
|
24108
|
+
const copy2 = [];
|
|
24109
|
+
seen.set(value, copy2);
|
|
24110
|
+
for (const item of value) copy2.push(freezeValue(item, seen));
|
|
24111
|
+
return Object.freeze(copy2);
|
|
24112
|
+
}
|
|
24113
|
+
const copy = {};
|
|
24114
|
+
seen.set(value, copy);
|
|
24115
|
+
for (const [key, item] of Object.entries(value)) copy[key] = freezeValue(item, seen);
|
|
24116
|
+
return Object.freeze(copy);
|
|
24117
|
+
}
|
|
24118
|
+
|
|
24119
|
+
// src/installed-napplet-catalog.ts
|
|
24120
|
+
function matchesInstalledNappletRecord(record2, target) {
|
|
24121
|
+
return target.id === record2.id && target.aggregateHash === record2.aggregateHash;
|
|
24122
|
+
}
|
|
24123
|
+
var InstalledNappletCatalog = class {
|
|
24124
|
+
records = /* @__PURE__ */ new Map();
|
|
24125
|
+
listeners = /* @__PURE__ */ new Set();
|
|
24126
|
+
/** Insert or replace a record from an already resolver-verified pointer. */
|
|
24127
|
+
install(resolved) {
|
|
24128
|
+
const record2 = freezeRecord({
|
|
24129
|
+
id: resolved.manifest.catalogId,
|
|
24130
|
+
dTag: resolved.dTag,
|
|
24131
|
+
aggregateHash: resolved.aggregateHash,
|
|
24132
|
+
pointer: copyPointer(resolved.pointer),
|
|
24133
|
+
...resolved.manifest.title === void 0 ? {} : { title: resolved.manifest.title },
|
|
24134
|
+
requires: [...resolved.manifest.requires],
|
|
24135
|
+
optional: [...resolved.manifest.optional ?? []],
|
|
24136
|
+
archetypes: resolved.manifest.archetypes.map((archetype) => ({
|
|
24137
|
+
slug: archetype.slug,
|
|
24138
|
+
convention: archetype.convention,
|
|
24139
|
+
params: [...archetype.params]
|
|
24140
|
+
}))
|
|
24141
|
+
});
|
|
24142
|
+
const previous = this.records.get(record2.id);
|
|
24143
|
+
this.records.set(record2.id, record2);
|
|
24144
|
+
this.notify(record2.id, previous, record2);
|
|
24145
|
+
return record2;
|
|
24146
|
+
}
|
|
24147
|
+
/** Remove an artifact explicitly; frame teardown never calls this method. */
|
|
24148
|
+
remove(id) {
|
|
24149
|
+
const previous = this.records.get(id);
|
|
24150
|
+
const removed = this.records.delete(id);
|
|
24151
|
+
if (removed) this.notify(id, previous);
|
|
24152
|
+
return removed;
|
|
24153
|
+
}
|
|
24154
|
+
/** Return whether a verified installation exists for a catalog ID. */
|
|
24155
|
+
has(id) {
|
|
24156
|
+
return this.records.has(id);
|
|
24157
|
+
}
|
|
24158
|
+
/** Return immutable serializable installed-artifact facts. */
|
|
24159
|
+
installed() {
|
|
24160
|
+
return [...this.records.values()];
|
|
24161
|
+
}
|
|
24162
|
+
/** Return a verified record by catalog ID. */
|
|
24163
|
+
get(id) {
|
|
24164
|
+
return this.records.get(id);
|
|
24165
|
+
}
|
|
24166
|
+
/**
|
|
24167
|
+
* Atomically confirm that a resolved target still belongs to the exact record
|
|
24168
|
+
* selected before an async operation. The record object is the catalog version
|
|
24169
|
+
* token, so even a same-identity replacement cannot pass this check.
|
|
24170
|
+
*/
|
|
24171
|
+
validateCurrent(selected, target) {
|
|
24172
|
+
if (this.records.get(selected.id) !== selected) return null;
|
|
24173
|
+
return matchesInstalledNappletRecord(selected, target) ? selected : null;
|
|
24174
|
+
}
|
|
24175
|
+
/**
|
|
24176
|
+
* Return declared handlers whose host environment can receive intent delivery.
|
|
24177
|
+
* @param canReceiveIntent - Resolve intent availability for each verified identity;
|
|
24178
|
+
* without host policy, return declared candidates for the host to filter.
|
|
24179
|
+
* @returns Named intent candidates usable under the supplied host policy.
|
|
24180
|
+
*/
|
|
24181
|
+
intentCatalog(canReceiveIntent = () => true) {
|
|
24182
|
+
return this.installed().filter(canReceiveIntent).map((record2) => manifestToIntentCatalogEntry({
|
|
24183
|
+
catalogId: record2.id,
|
|
24184
|
+
...record2.title === void 0 ? {} : { title: record2.title },
|
|
24185
|
+
archetypes: record2.archetypes.map((archetype) => ({
|
|
24186
|
+
slug: archetype.slug,
|
|
24187
|
+
convention: archetype.convention,
|
|
24188
|
+
params: [...archetype.params]
|
|
24189
|
+
}))
|
|
24190
|
+
}));
|
|
24191
|
+
}
|
|
24192
|
+
/** Subscribe to explicit install and artifact-removal changes. */
|
|
24193
|
+
onChanged(listener) {
|
|
24194
|
+
this.listeners.add(listener);
|
|
24195
|
+
return () => this.listeners.delete(listener);
|
|
24196
|
+
}
|
|
24197
|
+
notify(id, previous, current) {
|
|
24198
|
+
const archetypes = Object.freeze([.../* @__PURE__ */ new Set([
|
|
24199
|
+
...(previous?.archetypes ?? []).map(({ slug }) => slug),
|
|
24200
|
+
...(current?.archetypes ?? []).map(({ slug }) => slug)
|
|
24201
|
+
])]);
|
|
24202
|
+
for (const listener of this.listeners) listener(id, archetypes);
|
|
24203
|
+
}
|
|
24204
|
+
};
|
|
24205
|
+
function copyPointer(pointer) {
|
|
24206
|
+
if (pointer.type === "naddr") {
|
|
24207
|
+
return Object.freeze({
|
|
24208
|
+
type: "naddr",
|
|
24209
|
+
value: pointer.value,
|
|
24210
|
+
identifier: pointer.identifier,
|
|
24211
|
+
pubkey: pointer.pubkey,
|
|
24212
|
+
kind: pointer.kind,
|
|
24213
|
+
relays: Object.freeze([...pointer.relays])
|
|
24214
|
+
});
|
|
24215
|
+
}
|
|
24216
|
+
return Object.freeze({
|
|
24217
|
+
type: "nevent",
|
|
24218
|
+
value: pointer.value,
|
|
24219
|
+
id: pointer.id,
|
|
24220
|
+
...pointer.author === void 0 ? {} : { author: pointer.author },
|
|
24221
|
+
...pointer.kind === void 0 ? {} : { kind: pointer.kind },
|
|
24222
|
+
relays: Object.freeze([...pointer.relays])
|
|
24223
|
+
});
|
|
24224
|
+
}
|
|
24225
|
+
function freezeRecord(record2) {
|
|
24226
|
+
return Object.freeze({
|
|
24227
|
+
...record2,
|
|
24228
|
+
requires: Object.freeze([...record2.requires]),
|
|
24229
|
+
optional: Object.freeze([...record2.optional ?? []]),
|
|
24230
|
+
archetypes: Object.freeze(record2.archetypes.map((archetype) => Object.freeze({ ...archetype, params: Object.freeze([...archetype.params]) })))
|
|
24231
|
+
});
|
|
24232
|
+
}
|
|
24233
|
+
|
|
24114
24234
|
// src/runtime-resolver.ts
|
|
24115
24235
|
var PAJA_NAPPLET_MANIFEST_KINDS = NAPPLET_KINDS;
|
|
24116
24236
|
function decodePajaPointer(value) {
|
|
@@ -26291,6 +26411,8 @@ function createPajaBrowserState(context, relayEventCounts, relayInventory) {
|
|
|
26291
26411
|
};
|
|
26292
26412
|
}
|
|
26293
26413
|
async function installPajaHost() {
|
|
26414
|
+
const disposeGamepadIndicators = installPajaGamepadIndicators();
|
|
26415
|
+
window.addEventListener("pagehide", disposeGamepadIndicators, { once: true });
|
|
26294
26416
|
const disposeConsolePanel = installPajaConsolePanel();
|
|
26295
26417
|
const disposeSidebarSections = installPajaSidebarSections();
|
|
26296
26418
|
window.addEventListener("pagehide", disposeSidebarSections, { once: true });
|
|
@@ -26504,6 +26626,7 @@ async function installPajaHost() {
|
|
|
26504
26626
|
setDefault(archetype, id) {
|
|
26505
26627
|
runtime.intentDefaults.set(archetype, id);
|
|
26506
26628
|
writePajaIntentDefaults(runtime.intentDefaults);
|
|
26629
|
+
adapter.notifyIntentChanged(archetype);
|
|
26507
26630
|
},
|
|
26508
26631
|
onAccepted() {
|
|
26509
26632
|
const url = new URL(window.location.href);
|