openmaic-custom/lib/export/inline-assets-shared.ts
杨慎 4ac70cceeb
feat(video-export): capture self-contained static interactive HTML (#1086)
* feat(video-export): capture static interactive HTML

* fix(video-export): harden interactive HTML capture diagnostics

* fix(video-export): initialize runtime diagnostics in manifest

* fix(video-export): close interactive capture review findings

* fix(video-export): preserve packaged interactive resources

* fix(video-export): address packaging review feedback

* fix(video-export): harden interactive HTML packaging

* fix(video-export): unify interactive asset packaging

* fix(video-export): close remaining interactive packaging gaps
2026-08-11 22:16:58 +08:00

28 lines
900 B
TypeScript

export interface InlineReport {
inlined: string[];
failed: { url: string; reason: string }[];
}
export interface InlineOptions {
fetchImpl?: typeof fetch;
maxAssetBytes?: number;
fetcher?: FetchAsset;
/** Keep original remote import-map entries as an online fallback. Default true. */
keepImportmapFallbacks?: boolean;
}
export type FetchAsset = (
url: string,
) => Promise<{ bytes: Uint8Array; contentType: string } | null>;
/** Encode bytes as a data: URI. */
export function toDataUri(bytes: Uint8Array, contentType: string): string {
let binary = '';
const CHUNK = 0x8000;
for (let i = 0; i < bytes.length; i += CHUNK) {
binary += String.fromCharCode.apply(null, bytes.subarray(i, i + CHUNK) as unknown as number[]);
}
const b64 = typeof btoa !== 'undefined' ? btoa(binary) : Buffer.from(bytes).toString('base64');
return `data:${contentType};base64,${b64}`;
}