@oim-media/player-oim 1.32.5 → 1.33.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 +7 -252
- package/dist/oim-player.js +12 -12
- package/package.json +2 -2
- /package/dist/vendor/{oim-generative-db0a99d62daf.js → oim-generative-fde035d434a6.js} +0 -0
- /package/dist/vendor/{oim-patterns-db0a99d62daf.js → oim-patterns-fde035d434a6.js} +0 -0
- /package/dist/vendor/{oim-upgrade-db0a99d62daf.js → oim-upgrade-fde035d434a6.js} +0 -0
package/dist/esm/index.js
CHANGED
|
@@ -180,160 +180,12 @@ function getDeviceProfile(nav, win) {
|
|
|
180
180
|
saveData: Boolean(n?.connection?.saveData)
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
|
-
// src/render/poster-head.ts
|
|
184
|
-
/**
|
|
185
|
-
* @license
|
|
186
|
-
* Copyright (c) 2026 Xue Studios LLC
|
|
187
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
188
|
-
*/
|
|
189
|
-
/**
|
|
190
|
-
* The start of a .oim, enough to show its poster. Since 15 Nov the backend
|
|
191
|
-
* writes the image, then a small OIM_Seal (the image hash signed on its own),
|
|
192
|
-
* then the metadata. Reading up to the seal is enough to verify and paint the
|
|
193
|
-
* poster; the metadata is fetched only if the work animates.
|
|
194
|
-
*/
|
|
195
|
-
var SEAL_KEY = "OIM_Seal";
|
|
196
|
-
var DATA_KEYS = ["OIM_Data", "OIM_JSON_DATA"];
|
|
197
|
-
var IEND = new Uint8Array([
|
|
198
|
-
0,
|
|
199
|
-
0,
|
|
200
|
-
0,
|
|
201
|
-
0,
|
|
202
|
-
73,
|
|
203
|
-
69,
|
|
204
|
-
78,
|
|
205
|
-
68,
|
|
206
|
-
174,
|
|
207
|
-
66,
|
|
208
|
-
96,
|
|
209
|
-
130
|
|
210
|
-
]);
|
|
211
|
-
function keyOf$1(data) {
|
|
212
|
-
const nul = data.indexOf(0);
|
|
213
|
-
return nul === -1 ? "" : new TextDecoder("latin1").decode(data.subarray(0, nul));
|
|
214
|
-
}
|
|
215
|
-
/** Scans complete chunks of `buf` (the file's first bytes) for the poster seal. */
|
|
216
|
-
function scanPosterHead(buf) {
|
|
217
|
-
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
218
|
-
const idat = [];
|
|
219
|
-
for (let at = 8; at + 8 <= buf.length;) {
|
|
220
|
-
const length = view.getUint32(at);
|
|
221
|
-
const end = at + 12 + length;
|
|
222
|
-
if (end > buf.length) return { done: false };
|
|
223
|
-
const type = new TextDecoder("latin1").decode(buf.subarray(at + 4, at + 8));
|
|
224
|
-
const data = buf.subarray(at + 8, at + 8 + length);
|
|
225
|
-
if (type === "IDAT") idat.push(data);
|
|
226
|
-
else if (type === "IEND") return {
|
|
227
|
-
done: true,
|
|
228
|
-
seal: null,
|
|
229
|
-
idat,
|
|
230
|
-
sealStart: at,
|
|
231
|
-
end
|
|
232
|
-
};
|
|
233
|
-
else if (type === "tEXt" || type === "zTXt" || type === "iTXt") {
|
|
234
|
-
const key = keyOf$1(data);
|
|
235
|
-
if (key === SEAL_KEY) {
|
|
236
|
-
let seal = null;
|
|
237
|
-
try {
|
|
238
|
-
seal = JSON.parse(new TextDecoder().decode(data.subarray(key.length + 1)));
|
|
239
|
-
} catch {
|
|
240
|
-
seal = null;
|
|
241
|
-
}
|
|
242
|
-
return {
|
|
243
|
-
done: true,
|
|
244
|
-
seal: seal && typeof seal === "object" ? seal : null,
|
|
245
|
-
idat,
|
|
246
|
-
sealStart: at,
|
|
247
|
-
end
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
if (DATA_KEYS.includes(key)) return {
|
|
251
|
-
done: true,
|
|
252
|
-
seal: null,
|
|
253
|
-
idat,
|
|
254
|
-
sealStart: at,
|
|
255
|
-
end
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
at = end;
|
|
259
|
-
}
|
|
260
|
-
return { done: false };
|
|
261
|
-
}
|
|
262
|
-
/** The poster as a standalone PNG: everything before the seal, then IEND. */
|
|
263
|
-
function posterPng(buf, sealStart) {
|
|
264
|
-
const out = new Uint8Array(sealStart + IEND.length);
|
|
265
|
-
out.set(buf.subarray(0, sealStart), 0);
|
|
266
|
-
out.set(IEND, sealStart);
|
|
267
|
-
return out;
|
|
268
|
-
}
|
|
269
183
|
// src/render/file-cache.ts
|
|
270
184
|
/**
|
|
271
185
|
* @license
|
|
272
186
|
* Copyright (c) 2026 Xue Studios LLC
|
|
273
187
|
* SPDX-License-Identifier: Apache-2.0
|
|
274
188
|
*/
|
|
275
|
-
function joined(parts, total) {
|
|
276
|
-
const out = new Uint8Array(total);
|
|
277
|
-
let at = 0;
|
|
278
|
-
for (const p of parts) {
|
|
279
|
-
out.set(p, at);
|
|
280
|
-
at += p.length;
|
|
281
|
-
}
|
|
282
|
-
return out;
|
|
283
|
-
}
|
|
284
|
-
async function sha256Hex(parts) {
|
|
285
|
-
const all = joined(parts, parts.reduce((n, p) => n + p.length, 0));
|
|
286
|
-
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", all));
|
|
287
|
-
return Array.from(digest, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
288
|
-
}
|
|
289
|
-
/** Reads the file until its poster seal. Without one, reads it all and caches it as the blob. */
|
|
290
|
-
async function readHead(src, e) {
|
|
291
|
-
const res = await fetch(src);
|
|
292
|
-
if (!res.ok) return null;
|
|
293
|
-
if (!res.body) {
|
|
294
|
-
const blob = await res.blob();
|
|
295
|
-
e.bytes = blob.size;
|
|
296
|
-
e.blob = Promise.resolve(blob);
|
|
297
|
-
return null;
|
|
298
|
-
}
|
|
299
|
-
const reader = res.body.getReader();
|
|
300
|
-
const parts = [];
|
|
301
|
-
let total = 0;
|
|
302
|
-
for (;;) {
|
|
303
|
-
const { value, done } = await reader.read();
|
|
304
|
-
if (value) {
|
|
305
|
-
parts.push(value);
|
|
306
|
-
total += value.length;
|
|
307
|
-
}
|
|
308
|
-
const buf = joined(parts, total);
|
|
309
|
-
const head = done ? {
|
|
310
|
-
done: true,
|
|
311
|
-
seal: null
|
|
312
|
-
} : scanPosterHead(buf);
|
|
313
|
-
if (head.done && head.seal && "idat" in head) {
|
|
314
|
-
await reader.cancel().catch(() => {});
|
|
315
|
-
e.head = buf;
|
|
316
|
-
e.validator = res.headers.get("ETag") ?? res.headers.get("Last-Modified") ?? void 0;
|
|
317
|
-
return {
|
|
318
|
-
png: new Blob([posterPng(buf, head.sealStart)], { type: "image/png" }),
|
|
319
|
-
seal: head.seal,
|
|
320
|
-
imageHash: await sha256Hex(head.idat)
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
if (done || head.done) {
|
|
324
|
-
while (!done) {
|
|
325
|
-
const next = await reader.read();
|
|
326
|
-
if (next.done) break;
|
|
327
|
-
parts.push(next.value);
|
|
328
|
-
total += next.value.length;
|
|
329
|
-
}
|
|
330
|
-
const blob = new Blob([joined(parts, total)]);
|
|
331
|
-
e.bytes = blob.size;
|
|
332
|
-
e.blob = Promise.resolve(blob);
|
|
333
|
-
return null;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
189
|
var MAX_ENTRIES = 20;
|
|
338
190
|
var MAX_BYTES = 52428800;
|
|
339
191
|
var byUrl = /* @__PURE__ */ new Map();
|
|
@@ -408,20 +260,10 @@ var fileCache = {
|
|
|
408
260
|
fetches++;
|
|
409
261
|
e.pending++;
|
|
410
262
|
evict();
|
|
411
|
-
|
|
412
|
-
const validator = e.validator;
|
|
413
|
-
e.head = void 0;
|
|
414
|
-
e.validator = void 0;
|
|
415
|
-
const rangeHeaders = { Range: "bytes=" + (head?.length ?? 0) + "-" };
|
|
416
|
-
if (validator) rangeHeaders["If-Range"] = validator;
|
|
417
|
-
e.blob = (head ? fetch(src, { headers: rangeHeaders }).then(async (res) => {
|
|
418
|
-
if (res.status === 416) return new Blob([head]);
|
|
419
|
-
if (!res.ok) throw new Error("HTTP " + res.status);
|
|
420
|
-
return res.status === 206 ? new Blob([head, await res.blob()]) : res.blob();
|
|
421
|
-
}) : fetch(src).then((res) => {
|
|
263
|
+
e.blob = fetch(src).then((res) => {
|
|
422
264
|
if (!res.ok) throw new Error("HTTP " + res.status);
|
|
423
265
|
return res.blob();
|
|
424
|
-
})
|
|
266
|
+
}).then((b) => {
|
|
425
267
|
e.bytes = b.size;
|
|
426
268
|
e.lastUsed = ++tick;
|
|
427
269
|
evict();
|
|
@@ -449,27 +291,9 @@ var fileCache = {
|
|
|
449
291
|
}
|
|
450
292
|
return e.verified;
|
|
451
293
|
},
|
|
452
|
-
/** The
|
|
453
|
-
readPoster(src) {
|
|
454
|
-
const e = entryFor(src);
|
|
455
|
-
if (!e.poster && e.blob) return Promise.resolve(null);
|
|
456
|
-
if (!e.poster) {
|
|
457
|
-
e.pending++;
|
|
458
|
-
e.poster = readHead(src, e).catch(() => null).finally(() => {
|
|
459
|
-
e.pending--;
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
return e.poster;
|
|
463
|
-
},
|
|
464
|
-
/** The first 16 bytes, from the partial read when there is one: never a second download. */
|
|
294
|
+
/** The first 16 bytes, from the one download. */
|
|
465
295
|
sniff(src) {
|
|
466
|
-
|
|
467
|
-
if (typeof src !== "string") return fromBlob(Promise.resolve(src)).catch(() => null);
|
|
468
|
-
return fileCache.readPoster(src).then(() => {
|
|
469
|
-
const e = entryFor(src);
|
|
470
|
-
if (e.head) return e.head.slice(0, 16);
|
|
471
|
-
return fromBlob(fileCache.getBlob(src));
|
|
472
|
-
}).catch(() => null);
|
|
296
|
+
return fileCache.getBlob(src).then((b) => b.slice(0, 16).arrayBuffer()).then((buf) => new Uint8Array(buf)).catch(() => null);
|
|
473
297
|
},
|
|
474
298
|
stats() {
|
|
475
299
|
return {
|
|
@@ -7220,47 +7044,6 @@ function validateOimMetadata(json) {
|
|
|
7220
7044
|
return errors;
|
|
7221
7045
|
}
|
|
7222
7046
|
/**
|
|
7223
|
-
* The poster seal (OIM_Seal, spec 15 Nov): the image hash signed on its own,
|
|
7224
|
-
* read before the metadata so the poster can be verified from a partial read.
|
|
7225
|
-
* Same rules as a full file: an altered image is refused, an expired key says so.
|
|
7226
|
-
*/
|
|
7227
|
-
async function verifyPosterSeal(seal, imageHash) {
|
|
7228
|
-
if (!seal || seal.v !== 1 || seal.alg !== "sha256-idat") return "invalid";
|
|
7229
|
-
if (typeof seal.image_hash !== "string" || typeof seal.signature !== "string" || typeof seal.key_version !== "string") return "invalid";
|
|
7230
|
-
if (!imageHash || seal.image_hash.toLowerCase() !== imageHash.toLowerCase()) return "invalid";
|
|
7231
|
-
const bytes = new TextEncoder().encode(JSON.stringify({
|
|
7232
|
-
alg: seal.alg,
|
|
7233
|
-
image_hash: seal.image_hash,
|
|
7234
|
-
key_version: seal.key_version,
|
|
7235
|
-
v: seal.v
|
|
7236
|
-
}));
|
|
7237
|
-
try {
|
|
7238
|
-
const raw = atob(seal.signature);
|
|
7239
|
-
const sig = new Uint8Array(raw.length);
|
|
7240
|
-
for (let i = 0; i < raw.length; i++) sig[i] = raw.charCodeAt(i);
|
|
7241
|
-
const check = async (jwk) => {
|
|
7242
|
-
const key = await crypto.subtle.importKey("jwk", jwk, {
|
|
7243
|
-
name: "ECDSA",
|
|
7244
|
-
namedCurve: "P-256"
|
|
7245
|
-
}, false, ["verify"]);
|
|
7246
|
-
return crypto.subtle.verify({
|
|
7247
|
-
name: "ECDSA",
|
|
7248
|
-
hash: { name: "SHA-256" }
|
|
7249
|
-
}, key, sig, bytes);
|
|
7250
|
-
};
|
|
7251
|
-
const jwk = await getPublicKey(seal.key_version);
|
|
7252
|
-
let valid = !!jwk && await check(jwk);
|
|
7253
|
-
if (!valid) {
|
|
7254
|
-
const serverJwk = await getServerPublicKey(seal.key_version).catch(() => null);
|
|
7255
|
-
if (serverJwk && (!jwk || serverJwk.x !== jwk.x || serverJwk.y !== jwk.y)) valid = await check(serverJwk);
|
|
7256
|
-
}
|
|
7257
|
-
if (!valid) return "invalid";
|
|
7258
|
-
} catch {
|
|
7259
|
-
return "invalid";
|
|
7260
|
-
}
|
|
7261
|
-
return await keyExpiredForFile({ key_version: seal.key_version }) ? "expired_key" : "ok";
|
|
7262
|
-
}
|
|
7263
|
-
/**
|
|
7264
7047
|
* @license
|
|
7265
7048
|
* Copyright (c) 2026 Xue Studios LLC
|
|
7266
7049
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -7323,7 +7106,7 @@ function nextWheelZoom(zoom, deltaY, deltaMode, pinch) {
|
|
|
7323
7106
|
* the format can change without the player being touched. Tying both numbers
|
|
7324
7107
|
* together would make an internal fix look like a format break.
|
|
7325
7108
|
*/
|
|
7326
|
-
var CONTRACT_VERSION = "1.
|
|
7109
|
+
var CONTRACT_VERSION = "1.33.0";
|
|
7327
7110
|
/**
|
|
7328
7111
|
* What the player implements TODAY, measured and not assumed.
|
|
7329
7112
|
*
|
|
@@ -12152,7 +11935,7 @@ var ImageEngine = class extends LegacyRenderer {
|
|
|
12152
11935
|
host.classList.add("oim-align-" + this.align);
|
|
12153
11936
|
host.classList.add("oim-tier-" + this._deviceProfile.tier);
|
|
12154
11937
|
if (this._deviceProfile.isMobile) host.classList.add("oim-mobile");
|
|
12155
|
-
shadow.innerHTML = "<div class=\"oim-player-viewport oim-fit-" + this.fit + "\" part=\"viewport\"><img class=\"oim-player-base\" crossorigin=\"anonymous\"
|
|
11938
|
+
shadow.innerHTML = "<div class=\"oim-player-viewport oim-fit-" + this.fit + "\" part=\"viewport\"><img class=\"oim-player-base\" crossorigin=\"anonymous\" alt=\"\" aria-hidden=\"true\" part=\"base\" /><div class=\"oim-layer-overlay\" aria-hidden=\"true\" part=\"overlay\"></div></div>";
|
|
12156
11939
|
injectStyles(shadow);
|
|
12157
11940
|
this._viewport = shadow.querySelector(".oim-player-viewport");
|
|
12158
11941
|
this._baseImg = shadow.querySelector(".oim-player-base");
|
|
@@ -12197,35 +11980,7 @@ var ImageEngine = class extends LegacyRenderer {
|
|
|
12197
11980
|
this.updateViewportSize();
|
|
12198
11981
|
this.updateScale();
|
|
12199
11982
|
this._bindViewportEvents();
|
|
12200
|
-
if (
|
|
12201
|
-
const poster = await fileCache.readPoster(src);
|
|
12202
|
-
if (poster) {
|
|
12203
|
-
const verdict = await verifyPosterSeal(poster.seal, poster.imageHash);
|
|
12204
|
-
if (verdict === "invalid") {
|
|
12205
|
-
shadow.innerHTML = "<div class=\"oim-player-error oim-player-refused\" part=\"error\"></div>";
|
|
12206
|
-
injectStyles(shadow);
|
|
12207
|
-
const box = shadow.querySelector(".oim-player-error");
|
|
12208
|
-
if (box) box.textContent = playerString("tampered", self.lang);
|
|
12209
|
-
host.dispatchEvent(new CustomEvent("error", { detail: new Error(ALTERED_FILE_ERROR) }));
|
|
12210
|
-
return false;
|
|
12211
|
-
}
|
|
12212
|
-
if (verdict === "expired_key") try {
|
|
12213
|
-
setFlag(host, "data-oim-key-retired", "data-oim-clave-retirada");
|
|
12214
|
-
} catch (e) {}
|
|
12215
|
-
this.imageUrl = URL.createObjectURL(poster.png);
|
|
12216
|
-
imgNode.src = this.imageUrl;
|
|
12217
|
-
if (this.poster === "only") {
|
|
12218
|
-
this.securityStatus = verdict === "ok" ? "verified" : "expired_key";
|
|
12219
|
-
viewportNode?.classList.add("oim-viewport--poster", "oim-viewport--ready");
|
|
12220
|
-
host.dispatchEvent(new CustomEvent("oim:loaded", { detail: {
|
|
12221
|
-
type: "image",
|
|
12222
|
-
metadata: null,
|
|
12223
|
-
security: this.securityStatus
|
|
12224
|
-
} }));
|
|
12225
|
-
return true;
|
|
12226
|
-
}
|
|
12227
|
-
} else imgNode.src = src;
|
|
12228
|
-
}
|
|
11983
|
+
if (imgNode) imgNode.src = this.imageUrl ?? "";
|
|
12229
11984
|
return fileCache.getBlob(src).then((blob) => {
|
|
12230
11985
|
return new Promise((resolve2, reject2) => {
|
|
12231
11986
|
OIMRegistry.requestRender(self, blob, src, resolve2, reject2);
|