import type { FontFaceDescriptor } from "../transport/protocol"; /** * Walk every accessible `@font-face` rule in the document and collect a * descriptor list ready for forwarding to a Web Worker, where each * entry is reconstituted via `new FontFace(family, src, descriptors)` * and registered in the worker's own `self.fonts` set. * * Background: a `Worker` has its own `FontFaceSet` distinct from the * document's. Fonts loaded into `document.fonts` (by ``, * `@font-face`, or programmatic `FontFace`) are *not* visible to the * worker — Canvas2D `ctx.font` lookups inside the worker fall back to * the platform default if the family isn't in `self.fonts`. This * helper bridges that gap for the in-CSS case. * * # CORS / security caveats * * 1. **Cross-origin stylesheets without permissive CORS** throw * `SecurityError` on `cssRules` access, and we silently skip them. * Their `@font-face` rules are unreachable to JS regardless of * where the worker would re-load them, so this is the same * fundamental limitation the document itself has. * * 2. **Font URLs are absolutized against the parent stylesheet's * `href`** before forwarding. The worker's own script URL is a * Blob URL produced by `WorkerPlugin`, so relative URLs in the raw * `src:` declaration would resolve against the Blob origin (i.e. * fail). Callers should treat the absolute URLs as the canonical * source. * * 3. **The actual font fetch issued by `face.load()` in the worker * is a fresh cross-origin request from the worker scope.** The * font server must respond with `Access-Control-Allow-Origin` * (e.g. `*` or the page origin) and an appropriate * `Access-Control-Allow-Headers` policy if any non-simple headers * are involved. A "no-cors" / opaque response is *not* usable * here: `FontFace.load()` rejects on opaque responses, and even * if it didn't, painted glyphs would taint the canvas and break * `getImageData`. Same-origin fonts (including `data:` URIs) * sidestep this entirely. * * 4. **Programmatic fonts** (e.g. `document.fonts.add(new * FontFace(name, source))`) are *not* captured by this walker — * they don't appear in any stylesheet's `cssRules`. Iterating * `document.fonts` directly would catch them, but `FontFace` * instances don't expose their source URL or buffer post- * construction, so there's no public path to forward them. If a * test or app needs that, it must register the same fonts in the * worker explicitly. */ export declare function snapshotFontFaces(): FontFaceDescriptor[];