/**
HTML asset reference extraction.
Parses an HTML document with rehype-parse and walks the resulting hast tree
to collect every local asset URL the page would cause a browser to fetch.
*/
import type {
Element,
Node,
Parent,
Root,
Text,
} from 'hast';
import rehypeParse from 'rehype-parse';
import { unified, } from 'unified';
import type { DeepReadonly, } from './types.ts';
import { startsWithUriScheme, } from './url-detect.ts';
/**
Sentinel for "this element exposes no candidate asset URL". Shared by the
one cohesive flow that produces a fetchable URL or nothing: {@link attr}
(missing/non-string/empty attribute), `firstSrcsetUrl` (empty srcset), and
{@link ownAssetUrl} (tag carries no own asset). A `unique symbol`; callers
narrow with `=== NO_ASSET_URL`.
*/
const NO_ASSET_URL: unique symbol = Symbol('page-weight/no-asset-url',);
/**
Sentinel returned by {@link localUrlOrAbsent} when a candidate URL is not a
local reference: absent, external scheme, protocol-relative, data URI, or
fragment-only. A `unique symbol`; callers narrow with `=== NON_LOCAL_REF`.
*/
const NON_LOCAL_REF: unique symbol = Symbol('page-weight reference is not local',);
/**
Sentinel returned by {@link inlineStyleText} when a `