/** * Font fetching: the shared retry policy (`../retry.js`) plus the two things * that are genuinely font-specific — a magic-byte check that rejects a throttle * page served as HTTP 200, and an injectable byte cache. * * Pure and platform-neutral, so the exact same code runs in the browser * (website converters) and in Node (cloud render). Anything platform-specific — * notably a disk cache — is injected via {@link ByteCache}. * * The retry/classification loop used to live here and was the only one in the * repo that got it right; it now lives in `@polotno/core/retry` so images and * every other fetcher share it. Read that module's header for the policy. */ import { type RetryPolicy } from '../retry.js'; /** The rejection `discover.ts` uses for a font load its caller cancelled. */ export declare function abortError(): Error; /** Optional byte cache (e.g. Node disk cache) injected by the consumer. */ export interface ByteCache { get(url: string): Uint8Array | undefined; set(url: string, bytes: Uint8Array): void; } export interface FetchFontOptions extends RetryPolicy { /** Reject fetched bytes that fail this check (retried as a throttle blip). */ validate?: (bytes: Uint8Array) => boolean; /** Injected byte cache; consulted before the network and written on success. */ cache?: ByteCache; /** Per-attempt timeout in ms. Default 15000 (tuned for browser export UX). */ timeout?: number; } /** Container mime from the font's magic bytes (same table looksLikeFont checks). */ export declare function sniffFontMime(bytes: Uint8Array): string; export declare function looksLikeFont(bytes: Uint8Array): boolean; /** * Fetch font bytes with retry + classification. On terminal failure throws a * `FETCH_FAILED` `PolotnoError` whose `details` carry `{ url, status?, attempts, * reason }` — the caller's font-domain layer maps a 4xx `status` to * `FONT_FAILED/'not-found'` and everything else to `'fetch-failed'`/`'timeout'`. */ export declare function fetchFontResource(url: string, opts?: FetchFontOptions): Promise; export interface SettledResult { ok: boolean; value?: R; error?: unknown; } /** * Run `fn` over `items` with at most `limit` in flight. Unlike a bare * `Promise.all`, every task settles — a rejection is returned in place, so a * batch never leaves sibling rejections unhandled (the psd-import bug). Order * of results matches `items`. */ export declare function mapWithConcurrency(items: readonly T[], fn: (item: T, index: number) => Promise, limit?: number): Promise>>;