@kehto/paja 0.25.0 → 0.25.1
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/browser-host.js +114 -4
- package/dist/browser-host.js.map +1 -1
- package/package.json +3 -3
package/dist/browser-host.js
CHANGED
|
@@ -2361,7 +2361,7 @@ var getPublicKey = i.getPublicKey;
|
|
|
2361
2361
|
var finalizeEvent = i.finalizeEvent;
|
|
2362
2362
|
var verifyEvent = i.verifyEvent;
|
|
2363
2363
|
|
|
2364
|
-
// ../nip/dist/chunk-
|
|
2364
|
+
// ../nip/dist/chunk-RW3L2FAS.js
|
|
2365
2365
|
var NappletResolutionError = class extends Error {
|
|
2366
2366
|
code;
|
|
2367
2367
|
constructor(code, message2) {
|
|
@@ -2492,6 +2492,113 @@ function warnLegacyManifest() {
|
|
|
2492
2492
|
console.warn("[KEHTO_COMPAT_LEGACY_MANIFEST] Legacy aggregate manifest resolved. Republish with @napplet/vite-plugin >=0.15 using the current single-artifact schema. See docs/compatibility.md.");
|
|
2493
2493
|
}
|
|
2494
2494
|
var HASH = /^[a-f0-9]{64}$/;
|
|
2495
|
+
var MIME_TYPE = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/i;
|
|
2496
|
+
var DIMENSIONS = /^([1-9][0-9]*)x([1-9][0-9]*)$/;
|
|
2497
|
+
var INTEGER = /^(?:0|[1-9][0-9]*)$/;
|
|
2498
|
+
var SECONDS = /^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/;
|
|
2499
|
+
var SCREENSHOT_FORMATS = ["image/png", "image/jpeg", "image/webp"];
|
|
2500
|
+
function fieldsOf(tag) {
|
|
2501
|
+
const fields = /* @__PURE__ */ new Map();
|
|
2502
|
+
for (const field of tag.slice(1)) {
|
|
2503
|
+
if (typeof field !== "string") continue;
|
|
2504
|
+
const space = field.indexOf(" ");
|
|
2505
|
+
const key = space < 0 ? field : field.slice(0, space);
|
|
2506
|
+
const values = fields.get(key) ?? [];
|
|
2507
|
+
values.push(space < 0 ? "" : field.slice(space + 1));
|
|
2508
|
+
fields.set(key, values);
|
|
2509
|
+
}
|
|
2510
|
+
return fields;
|
|
2511
|
+
}
|
|
2512
|
+
function parseMediaTag(tag, kind) {
|
|
2513
|
+
const fields = fieldsOf(tag);
|
|
2514
|
+
const hashes = fields.get("x");
|
|
2515
|
+
if (!hashes || hashes.length !== 1 || !HASH.test(hashes[0])) return void 0;
|
|
2516
|
+
const media = { sha256: hashes[0] };
|
|
2517
|
+
const optional = (key, accept) => {
|
|
2518
|
+
const values = fields.get(key);
|
|
2519
|
+
return values?.length === 1 && accept(values[0]) ? values[0] : void 0;
|
|
2520
|
+
};
|
|
2521
|
+
const mimeType = optional("m", (value) => MIME_TYPE.test(value));
|
|
2522
|
+
if (mimeType !== void 0) {
|
|
2523
|
+
const lower = mimeType.toLowerCase();
|
|
2524
|
+
const decodable = kind === "preview" ? lower.startsWith("video/") : SCREENSHOT_FORMATS.includes(lower);
|
|
2525
|
+
if (!decodable) return void 0;
|
|
2526
|
+
media.mimeType = mimeType;
|
|
2527
|
+
}
|
|
2528
|
+
const dim = optional("dim", (value) => DIMENSIONS.test(value));
|
|
2529
|
+
if (dim !== void 0) {
|
|
2530
|
+
const [, width, height] = DIMENSIONS.exec(dim);
|
|
2531
|
+
media.dim = { width: Number(width), height: Number(height) };
|
|
2532
|
+
}
|
|
2533
|
+
const size = optional("size", (value) => INTEGER.test(value));
|
|
2534
|
+
if (size !== void 0) media.size = Number(size);
|
|
2535
|
+
if (kind === "preview") {
|
|
2536
|
+
const duration = optional("duration", (value) => SECONDS.test(value));
|
|
2537
|
+
if (duration !== void 0) media.duration = Number(duration);
|
|
2538
|
+
}
|
|
2539
|
+
const alt = optional("alt", (value) => value.trim().length > 0);
|
|
2540
|
+
if (alt !== void 0) media.alt = alt;
|
|
2541
|
+
return media;
|
|
2542
|
+
}
|
|
2543
|
+
function parsePresentationMedia(tags) {
|
|
2544
|
+
const screenshots = [];
|
|
2545
|
+
for (const tag of tags) {
|
|
2546
|
+
if (tag[0] !== "screenshot") continue;
|
|
2547
|
+
const media = parseMediaTag(tag, "screenshot");
|
|
2548
|
+
if (media) screenshots.push(media);
|
|
2549
|
+
}
|
|
2550
|
+
const previews = tags.filter((tag) => tag[0] === "preview");
|
|
2551
|
+
const preview = previews.length === 1 ? parseMediaTag(previews[0], "preview") : void 0;
|
|
2552
|
+
return preview ? { screenshots, preview } : { screenshots };
|
|
2553
|
+
}
|
|
2554
|
+
var HASH2 = /^[a-f0-9]{64}$/;
|
|
2555
|
+
var GIT_COMMIT = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
|
|
2556
|
+
var SCP_LOCATION = /^(?:[^@\s/:]+@)?[^:\s/]+:[^\s]+$/;
|
|
2557
|
+
var WINDOWS_DRIVE = /^[a-z]:[\\/]/i;
|
|
2558
|
+
var MIME_TYPE2 = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/i;
|
|
2559
|
+
function isSourceLocation(value) {
|
|
2560
|
+
if (!value || /\s/.test(value) || WINDOWS_DRIVE.test(value)) return false;
|
|
2561
|
+
try {
|
|
2562
|
+
const { protocol } = new URL(value);
|
|
2563
|
+
if (["http:", "https:", "ssh:", "git:"].includes(protocol)) return true;
|
|
2564
|
+
if (protocol === "nostr:") return value.startsWith("nostr://") && value.length > "nostr://".length;
|
|
2565
|
+
} catch {
|
|
2566
|
+
}
|
|
2567
|
+
return !value.includes("://") && SCP_LOCATION.test(value);
|
|
2568
|
+
}
|
|
2569
|
+
function isArchiveUrl(value) {
|
|
2570
|
+
if (!value || value.includes("#")) return false;
|
|
2571
|
+
try {
|
|
2572
|
+
const url = new URL(value);
|
|
2573
|
+
return url.protocol === "https:" && !url.username && !url.password;
|
|
2574
|
+
} catch {
|
|
2575
|
+
return false;
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
function sourceArchiveFromTags(tags) {
|
|
2579
|
+
const archives = tags.filter((tag) => tag[0] === "source-archive");
|
|
2580
|
+
if (archives.length !== 1) return void 0;
|
|
2581
|
+
const [, url, sha2563, mimeType] = archives[0];
|
|
2582
|
+
if (archives[0].length !== 4 || !isArchiveUrl(url) || !HASH2.test(sha2563) || !MIME_TYPE2.test(mimeType)) {
|
|
2583
|
+
return void 0;
|
|
2584
|
+
}
|
|
2585
|
+
return { url, sha256: sha2563, mimeType };
|
|
2586
|
+
}
|
|
2587
|
+
function parseSourceMetadata(tags) {
|
|
2588
|
+
const metadata = {};
|
|
2589
|
+
const sources2 = tags.filter((tag) => tag[0] === "source");
|
|
2590
|
+
if (sources2.length === 1 && sources2[0].length === 2 && isSourceLocation(sources2[0][1])) {
|
|
2591
|
+
metadata.source = sources2[0][1];
|
|
2592
|
+
}
|
|
2593
|
+
const commits = tags.filter((tag) => tag[0] === "source-commit");
|
|
2594
|
+
if (metadata.source !== void 0 && commits.length === 1 && commits[0].length === 2 && GIT_COMMIT.test(commits[0][1])) {
|
|
2595
|
+
metadata.sourceCommit = commits[0][1];
|
|
2596
|
+
}
|
|
2597
|
+
const sourceArchive = sourceArchiveFromTags(tags);
|
|
2598
|
+
if (sourceArchive) metadata.sourceArchive = sourceArchive;
|
|
2599
|
+
return metadata;
|
|
2600
|
+
}
|
|
2601
|
+
var HASH3 = /^[a-f0-9]{64}$/;
|
|
2495
2602
|
var DOMAIN = /^[a-z][a-z0-9-]*$/;
|
|
2496
2603
|
var SLUG = /^[a-z0-9][a-z0-9-]*$/;
|
|
2497
2604
|
function invalid(message2) {
|
|
@@ -2527,7 +2634,7 @@ function iconFromTags(tags) {
|
|
|
2527
2634
|
const icons = tags.filter((tag) => tag[0] === "icon");
|
|
2528
2635
|
if (icons.length !== 1) return void 0;
|
|
2529
2636
|
const [, hash, mimeType] = icons[0];
|
|
2530
|
-
if (icons[0].length !== 3 || !
|
|
2637
|
+
if (icons[0].length !== 3 || !HASH3.test(hash)) return void 0;
|
|
2531
2638
|
if (mimeType !== "image/png" && mimeType !== "image/jpeg" && mimeType !== "image/webp") {
|
|
2532
2639
|
return void 0;
|
|
2533
2640
|
}
|
|
@@ -2536,7 +2643,7 @@ function iconFromTags(tags) {
|
|
|
2536
2643
|
function parseCurrentManifest(event) {
|
|
2537
2644
|
const tags = event.tags;
|
|
2538
2645
|
const artifactHash = single(tags, "x");
|
|
2539
|
-
if (!artifactHash || !
|
|
2646
|
+
if (!artifactHash || !HASH3.test(artifactHash)) invalid("invalid artifact x hash");
|
|
2540
2647
|
if (typeof event.content !== "string" || !event.content.trim()) {
|
|
2541
2648
|
invalid("manifest content must be a non-empty plain-text description");
|
|
2542
2649
|
}
|
|
@@ -2572,7 +2679,10 @@ function parseCurrentManifest(event) {
|
|
|
2572
2679
|
archetypes,
|
|
2573
2680
|
title: single(tags, "title"),
|
|
2574
2681
|
description: event.content,
|
|
2575
|
-
|
|
2682
|
+
// Source and presentation media are informational: malformed or repeated
|
|
2683
|
+
// tags are ignored and never prevent playback (NIP-5D §Source, §Presentation media).
|
|
2684
|
+
...parseSourceMetadata(tags),
|
|
2685
|
+
...parsePresentationMedia(tags),
|
|
2576
2686
|
icon: iconFromTags(tags),
|
|
2577
2687
|
parent,
|
|
2578
2688
|
root
|