Files
wehub-resource-sync c48612c494
CI / E2E Tests (push) Has been cancelled
CI / Lint, Typecheck & Unit Tests (push) Has been cancelled
Docs Build / Build docs site (push) Has been cancelled
Publish @openmaic packages / Build, validate & publish (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:23 +08:00

26 lines
778 B
TypeScript

export interface InlineReport {
inlined: string[];
failed: { url: string; reason: string }[];
}
export interface InlineOptions {
fetchImpl?: typeof fetch;
maxAssetBytes?: number;
fetcher?: FetchAsset;
}
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}`;
}