@oim-media/player-oim 1.29.1 → 1.30.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/dist/esm/index.js
CHANGED
|
@@ -179,12 +179,159 @@ function getDeviceProfile(nav, win) {
|
|
|
179
179
|
saveData: Boolean(n?.connection?.saveData)
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
|
+
// src/render/poster-head.ts
|
|
183
|
+
/**
|
|
184
|
+
* @license
|
|
185
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
186
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
187
|
+
*/
|
|
188
|
+
/**
|
|
189
|
+
* The start of a .oim, enough to show its poster. Since 15 Nov the backend
|
|
190
|
+
* writes the image, then a small OIM_Seal (the image hash signed on its own),
|
|
191
|
+
* then the metadata. Reading up to the seal is enough to verify and paint the
|
|
192
|
+
* poster; the metadata is fetched only if the work animates.
|
|
193
|
+
*/
|
|
194
|
+
var SEAL_KEY = "OIM_Seal";
|
|
195
|
+
var DATA_KEYS = ["OIM_Data", "OIM_JSON_DATA"];
|
|
196
|
+
var IEND = new Uint8Array([
|
|
197
|
+
0,
|
|
198
|
+
0,
|
|
199
|
+
0,
|
|
200
|
+
0,
|
|
201
|
+
73,
|
|
202
|
+
69,
|
|
203
|
+
78,
|
|
204
|
+
68,
|
|
205
|
+
174,
|
|
206
|
+
66,
|
|
207
|
+
96,
|
|
208
|
+
130
|
|
209
|
+
]);
|
|
210
|
+
function keyOf$1(data) {
|
|
211
|
+
const nul = data.indexOf(0);
|
|
212
|
+
return nul === -1 ? "" : new TextDecoder("latin1").decode(data.subarray(0, nul));
|
|
213
|
+
}
|
|
214
|
+
/** Scans complete chunks of `buf` (the file's first bytes) for the poster seal. */
|
|
215
|
+
function scanPosterHead(buf) {
|
|
216
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
217
|
+
const idat = [];
|
|
218
|
+
for (let at = 8; at + 8 <= buf.length;) {
|
|
219
|
+
const length = view.getUint32(at);
|
|
220
|
+
const end = at + 12 + length;
|
|
221
|
+
if (end > buf.length) return { done: false };
|
|
222
|
+
const type = new TextDecoder("latin1").decode(buf.subarray(at + 4, at + 8));
|
|
223
|
+
const data = buf.subarray(at + 8, at + 8 + length);
|
|
224
|
+
if (type === "IDAT") idat.push(data);
|
|
225
|
+
else if (type === "IEND") return {
|
|
226
|
+
done: true,
|
|
227
|
+
seal: null,
|
|
228
|
+
idat,
|
|
229
|
+
sealStart: at,
|
|
230
|
+
end
|
|
231
|
+
};
|
|
232
|
+
else if (type === "tEXt" || type === "zTXt" || type === "iTXt") {
|
|
233
|
+
const key = keyOf$1(data);
|
|
234
|
+
if (key === SEAL_KEY) {
|
|
235
|
+
let seal = null;
|
|
236
|
+
try {
|
|
237
|
+
seal = JSON.parse(new TextDecoder().decode(data.subarray(key.length + 1)));
|
|
238
|
+
} catch {
|
|
239
|
+
seal = null;
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
done: true,
|
|
243
|
+
seal: seal && typeof seal === "object" ? seal : null,
|
|
244
|
+
idat,
|
|
245
|
+
sealStart: at,
|
|
246
|
+
end
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if (DATA_KEYS.includes(key)) return {
|
|
250
|
+
done: true,
|
|
251
|
+
seal: null,
|
|
252
|
+
idat,
|
|
253
|
+
sealStart: at,
|
|
254
|
+
end
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
at = end;
|
|
258
|
+
}
|
|
259
|
+
return { done: false };
|
|
260
|
+
}
|
|
261
|
+
/** The poster as a standalone PNG: everything before the seal, then IEND. */
|
|
262
|
+
function posterPng(buf, sealStart) {
|
|
263
|
+
const out = new Uint8Array(sealStart + IEND.length);
|
|
264
|
+
out.set(buf.subarray(0, sealStart), 0);
|
|
265
|
+
out.set(IEND, sealStart);
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
182
268
|
// src/render/file-cache.ts
|
|
183
269
|
/**
|
|
184
270
|
* @license
|
|
185
271
|
* Copyright (c) 2026 Xue Studios LLC
|
|
186
272
|
* SPDX-License-Identifier: Apache-2.0
|
|
187
273
|
*/
|
|
274
|
+
function joined(parts, total) {
|
|
275
|
+
const out = new Uint8Array(total);
|
|
276
|
+
let at = 0;
|
|
277
|
+
for (const p of parts) {
|
|
278
|
+
out.set(p, at);
|
|
279
|
+
at += p.length;
|
|
280
|
+
}
|
|
281
|
+
return out;
|
|
282
|
+
}
|
|
283
|
+
async function sha256Hex(parts) {
|
|
284
|
+
const all = joined(parts, parts.reduce((n, p) => n + p.length, 0));
|
|
285
|
+
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", all));
|
|
286
|
+
return Array.from(digest, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
287
|
+
}
|
|
288
|
+
/** Reads the file until its poster seal. Without one, reads it all and caches it as the blob. */
|
|
289
|
+
async function readHead(src, e) {
|
|
290
|
+
const res = await fetch(src);
|
|
291
|
+
if (!res.ok) return null;
|
|
292
|
+
if (!res.body) {
|
|
293
|
+
const blob = await res.blob();
|
|
294
|
+
e.bytes = blob.size;
|
|
295
|
+
e.blob = Promise.resolve(blob);
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
const reader = res.body.getReader();
|
|
299
|
+
const parts = [];
|
|
300
|
+
let total = 0;
|
|
301
|
+
for (;;) {
|
|
302
|
+
const { value, done } = await reader.read();
|
|
303
|
+
if (value) {
|
|
304
|
+
parts.push(value);
|
|
305
|
+
total += value.length;
|
|
306
|
+
}
|
|
307
|
+
const buf = joined(parts, total);
|
|
308
|
+
const head = done ? {
|
|
309
|
+
done: true,
|
|
310
|
+
seal: null
|
|
311
|
+
} : scanPosterHead(buf);
|
|
312
|
+
if (head.done && head.seal && "idat" in head) {
|
|
313
|
+
await reader.cancel().catch(() => {});
|
|
314
|
+
e.head = buf;
|
|
315
|
+
return {
|
|
316
|
+
png: new Blob([posterPng(buf, head.sealStart)], { type: "image/png" }),
|
|
317
|
+
seal: head.seal,
|
|
318
|
+
imageHash: await sha256Hex(head.idat)
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
if (done || head.done) {
|
|
322
|
+
while (!done) {
|
|
323
|
+
const next = await reader.read();
|
|
324
|
+
if (next.done) break;
|
|
325
|
+
parts.push(next.value);
|
|
326
|
+
total += next.value.length;
|
|
327
|
+
}
|
|
328
|
+
const blob = new Blob([joined(parts, total)]);
|
|
329
|
+
e.bytes = blob.size;
|
|
330
|
+
e.blob = Promise.resolve(blob);
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
188
335
|
var MAX_ENTRIES = 20;
|
|
189
336
|
var MAX_BYTES = 52428800;
|
|
190
337
|
var byUrl = /* @__PURE__ */ new Map();
|
|
@@ -259,10 +406,15 @@ var fileCache = {
|
|
|
259
406
|
fetches++;
|
|
260
407
|
e.pending++;
|
|
261
408
|
evict();
|
|
262
|
-
|
|
409
|
+
const head = e.head;
|
|
410
|
+
e.head = void 0;
|
|
411
|
+
e.blob = (head ? fetch(src, { headers: { Range: "bytes=" + head.length + "-" } }).then(async (res) => {
|
|
412
|
+
if (!res.ok) throw new Error("HTTP " + res.status);
|
|
413
|
+
return res.status === 206 ? new Blob([head, await res.blob()]) : res.blob();
|
|
414
|
+
}) : fetch(src).then((res) => {
|
|
263
415
|
if (!res.ok) throw new Error("HTTP " + res.status);
|
|
264
416
|
return res.blob();
|
|
265
|
-
}).then((b) => {
|
|
417
|
+
})).then((b) => {
|
|
266
418
|
e.bytes = b.size;
|
|
267
419
|
e.lastUsed = ++tick;
|
|
268
420
|
evict();
|
|
@@ -290,8 +442,27 @@ var fileCache = {
|
|
|
290
442
|
}
|
|
291
443
|
return e.verified;
|
|
292
444
|
},
|
|
445
|
+
/** The verified-later poster from a partial read; null when the file has no seal or the read fails. */
|
|
446
|
+
readPoster(src) {
|
|
447
|
+
const e = entryFor(src);
|
|
448
|
+
if (!e.poster && e.blob) return Promise.resolve(null);
|
|
449
|
+
if (!e.poster) {
|
|
450
|
+
e.pending++;
|
|
451
|
+
e.poster = readHead(src, e).catch(() => null).finally(() => {
|
|
452
|
+
e.pending--;
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
return e.poster;
|
|
456
|
+
},
|
|
457
|
+
/** The first 16 bytes, from the partial read when there is one: never a second download. */
|
|
293
458
|
sniff(src) {
|
|
294
|
-
|
|
459
|
+
const fromBlob = (b) => b.then((x) => x.slice(0, 16).arrayBuffer()).then((buf) => new Uint8Array(buf));
|
|
460
|
+
if (typeof src !== "string") return fromBlob(Promise.resolve(src)).catch(() => null);
|
|
461
|
+
return fileCache.readPoster(src).then(() => {
|
|
462
|
+
const e = entryFor(src);
|
|
463
|
+
if (e.head) return e.head.slice(0, 16);
|
|
464
|
+
return fromBlob(fileCache.getBlob(src));
|
|
465
|
+
}).catch(() => null);
|
|
295
466
|
},
|
|
296
467
|
stats() {
|
|
297
468
|
return {
|
|
@@ -4449,6 +4620,47 @@ function validateOimMetadata(json) {
|
|
|
4449
4620
|
return errors;
|
|
4450
4621
|
}
|
|
4451
4622
|
/**
|
|
4623
|
+
* The poster seal (OIM_Seal, spec 15 Nov): the image hash signed on its own,
|
|
4624
|
+
* read before the metadata so the poster can be verified from a partial read.
|
|
4625
|
+
* Same rules as a full file: an altered image is refused, an expired key says so.
|
|
4626
|
+
*/
|
|
4627
|
+
async function verifyPosterSeal(seal, imageHash) {
|
|
4628
|
+
if (!seal || seal.v !== 1 || seal.alg !== "sha256-idat") return "invalid";
|
|
4629
|
+
if (typeof seal.image_hash !== "string" || typeof seal.signature !== "string" || typeof seal.key_version !== "string") return "invalid";
|
|
4630
|
+
if (!imageHash || seal.image_hash.toLowerCase() !== imageHash.toLowerCase()) return "invalid";
|
|
4631
|
+
const bytes = new TextEncoder().encode(JSON.stringify({
|
|
4632
|
+
alg: seal.alg,
|
|
4633
|
+
image_hash: seal.image_hash,
|
|
4634
|
+
key_version: seal.key_version,
|
|
4635
|
+
v: seal.v
|
|
4636
|
+
}));
|
|
4637
|
+
try {
|
|
4638
|
+
const raw = atob(seal.signature);
|
|
4639
|
+
const sig = new Uint8Array(raw.length);
|
|
4640
|
+
for (let i = 0; i < raw.length; i++) sig[i] = raw.charCodeAt(i);
|
|
4641
|
+
const check = async (jwk) => {
|
|
4642
|
+
const key = await crypto.subtle.importKey("jwk", jwk, {
|
|
4643
|
+
name: "ECDSA",
|
|
4644
|
+
namedCurve: "P-256"
|
|
4645
|
+
}, false, ["verify"]);
|
|
4646
|
+
return crypto.subtle.verify({
|
|
4647
|
+
name: "ECDSA",
|
|
4648
|
+
hash: { name: "SHA-256" }
|
|
4649
|
+
}, key, sig, bytes);
|
|
4650
|
+
};
|
|
4651
|
+
const jwk = await getPublicKey(seal.key_version);
|
|
4652
|
+
let valid = !!jwk && await check(jwk);
|
|
4653
|
+
if (!valid) {
|
|
4654
|
+
const serverJwk = await getServerPublicKey(seal.key_version).catch(() => null);
|
|
4655
|
+
if (serverJwk && (!jwk || serverJwk.x !== jwk.x || serverJwk.y !== jwk.y)) valid = await check(serverJwk);
|
|
4656
|
+
}
|
|
4657
|
+
if (!valid) return "invalid";
|
|
4658
|
+
} catch {
|
|
4659
|
+
return "invalid";
|
|
4660
|
+
}
|
|
4661
|
+
return await keyExpiredForFile({ key_version: seal.key_version }) ? "expired_key" : "ok";
|
|
4662
|
+
}
|
|
4663
|
+
/**
|
|
4452
4664
|
* @license
|
|
4453
4665
|
* Copyright (c) 2026 Xue Studios LLC
|
|
4454
4666
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -4511,7 +4723,7 @@ function nextWheelZoom(zoom, deltaY, deltaMode, pinch) {
|
|
|
4511
4723
|
* the format can change without the player being touched. Tying both numbers
|
|
4512
4724
|
* together would make an internal fix look like a format break.
|
|
4513
4725
|
*/
|
|
4514
|
-
var CONTRACT_VERSION = "1.
|
|
4726
|
+
var CONTRACT_VERSION = "1.30.0";
|
|
4515
4727
|
/**
|
|
4516
4728
|
* What the player implements TODAY, measured and not assumed.
|
|
4517
4729
|
*
|
|
@@ -11260,7 +11472,7 @@ var ImageEngine = class extends LegacyRenderer {
|
|
|
11260
11472
|
host.classList.add("oim-align-" + this.align);
|
|
11261
11473
|
host.classList.add("oim-tier-" + this._deviceProfile.tier);
|
|
11262
11474
|
if (this._deviceProfile.isMobile) host.classList.add("oim-mobile");
|
|
11263
|
-
shadow.innerHTML = "<div class=\"oim-player-viewport oim-fit-" + this.fit + "\" part=\"viewport\"><img class=\"oim-player-base\" crossorigin=\"anonymous\" src=\"" + this.imageUrl + "\" alt=\"\" aria-hidden=\"true\" part=\"base\" /><div class=\"oim-layer-overlay\" aria-hidden=\"true\" part=\"overlay\"></div></div>";
|
|
11475
|
+
shadow.innerHTML = "<div class=\"oim-player-viewport oim-fit-" + this.fit + "\" part=\"viewport\"><img class=\"oim-player-base\" crossorigin=\"anonymous\"" + (typeof src === "string" ? "" : " src=\"" + this.imageUrl + "\"") + " alt=\"\" aria-hidden=\"true\" part=\"base\" /><div class=\"oim-layer-overlay\" aria-hidden=\"true\" part=\"overlay\"></div></div>";
|
|
11264
11476
|
injectStyles(shadow);
|
|
11265
11477
|
this._viewport = shadow.querySelector(".oim-player-viewport");
|
|
11266
11478
|
this._baseImg = shadow.querySelector(".oim-player-base");
|
|
@@ -11305,6 +11517,35 @@ var ImageEngine = class extends LegacyRenderer {
|
|
|
11305
11517
|
this.updateViewportSize();
|
|
11306
11518
|
this.updateScale();
|
|
11307
11519
|
this._bindViewportEvents();
|
|
11520
|
+
if (typeof src === "string" && imgNode) {
|
|
11521
|
+
const poster = await fileCache.readPoster(src);
|
|
11522
|
+
if (poster) {
|
|
11523
|
+
const verdict = await verifyPosterSeal(poster.seal, poster.imageHash);
|
|
11524
|
+
if (verdict === "invalid") {
|
|
11525
|
+
shadow.innerHTML = "<div class=\"oim-player-error oim-player-refused\" part=\"error\"></div>";
|
|
11526
|
+
injectStyles(shadow);
|
|
11527
|
+
const box = shadow.querySelector(".oim-player-error");
|
|
11528
|
+
if (box) box.textContent = playerString("tampered", self.lang);
|
|
11529
|
+
host.dispatchEvent(new CustomEvent("error", { detail: new Error(ALTERED_FILE_ERROR) }));
|
|
11530
|
+
return false;
|
|
11531
|
+
}
|
|
11532
|
+
if (verdict === "expired_key") try {
|
|
11533
|
+
setFlag(host, "data-oim-key-retired", "data-oim-clave-retirada");
|
|
11534
|
+
} catch (e) {}
|
|
11535
|
+
this.imageUrl = URL.createObjectURL(poster.png);
|
|
11536
|
+
imgNode.src = this.imageUrl;
|
|
11537
|
+
if (this.poster === "only") {
|
|
11538
|
+
this.securityStatus = verdict === "ok" ? "verified" : "expired_key";
|
|
11539
|
+
viewportNode?.classList.add("oim-viewport--poster", "oim-viewport--ready");
|
|
11540
|
+
host.dispatchEvent(new CustomEvent("oim:loaded", { detail: {
|
|
11541
|
+
type: "image",
|
|
11542
|
+
metadata: null,
|
|
11543
|
+
security: this.securityStatus
|
|
11544
|
+
} }));
|
|
11545
|
+
return true;
|
|
11546
|
+
}
|
|
11547
|
+
} else imgNode.src = src;
|
|
11548
|
+
}
|
|
11308
11549
|
return fileCache.getBlob(src).then((blob) => {
|
|
11309
11550
|
return new Promise((resolve2, reject2) => {
|
|
11310
11551
|
OIMRegistry.requestRender(self, blob, src, resolve2, reject2);
|