import { FrameElement, UrlString, SubresourceType } from '../../types'; import { Resource, DomResource } from '..'; /** * A representation of a link between web resources. * * Links are obtained via {@link Resource.links | `Resource.links`}, and provide a live view on the * links defined in the resource. Changing the target of a link will change the resource content. * * A Link contains (see {@link Link_base}): * - `from`: an {@link Anchor} representing the place this link ‘points from’. * - `target`: the link target, possibly relative URL. Can be modified. * - `absoluteTarget`: the link target, expanded to an absolute URL if needed. * - `isSubresource`: whether the link’s target is considered a subresource. * - `subresourceType`: what type of subresource it links to (if applicable). * - `resource`: if available, the `Resource` that this link targets. * * @category Links */ export declare type Link = NonSubresourceLink | SubresourceLink; /** * A representation of a link between web resources. * * This interface is not for direct use, but is extended by all subtypes of {@link Link}. * * @category Links */ export interface Link_base { /** * The link’s target URL. * * This is the exact value as it appears in the document, and may thus be * a relative URL. For most use cases `absoluteTarget` is more useful than `target`. * * This property can be written to, which will modify the resource containing the link. */ target: string; /** * The link’s target URL as an absolute URL. * * This takes into account factors like the `` element. * * If the target is not a valid (relative) URL, absoluteTarget equals undefined. */ readonly absoluteTarget?: UrlString; /** * A boolean indicating whether the resource being linked to is normally considered a * subresource of the document. For example, the `src` of an `` element specifies a * subresource because the image is considered *part of* the document, while the `href` of an * `` or the `action` of a `
` merely *point to* another resource. */ readonly isSubresource: boolean; /** * Information about where the link points ‘from’ (the place where it is defined) in the DOM or * stylesheet. */ readonly from: Anchor; } /** * A {@link Link} that refers to resources without making them ‘part of’ the document. * * Note the [WHATWG HTML spec](https://html.spec.whatwg.org/multipage/links.html#hyperlink) * calls such (and *only* such) links ‘hyperlinks’. * * @category Links */ export interface NonSubresourceLink extends Link_base { readonly isSubresource: false; readonly subresourceType?: undefined; } /** * A {@link Link} that makes its target ‘part of’ the document. * * @category Links */ export interface SubresourceLink extends Link_base { readonly isSubresource: true; /** * Indicates the type of resource (`image`, `style`, ...). This corresponds to what is now * called the ‘destination’ in the [WHATWG fetch spec](https://fetch.spec.whatwg.org/#concept-request-destination). */ readonly subresourceType?: SubresourceType; /** * If the subresource is available, it can be assigned to this attribute. */ resource?: Resource; } /** * The place a {@link Link} points ‘from’. For links in HTML or CSS, this is the place where the * link is defined (only an HTTP `Link` header can specify the anchor of a link). * * @category Links */ export interface Anchor { resource?: Resource; } /** * An {@link Anchor} that points from the attribute of an HTML element. * * @category Links */ export interface AttributeAnchor extends Anchor { element: E; attribute: A; /** * The character position of the URL inside the attribute. * * Relevant for attributes that contain more than a single URL; e.g. the `srcset` of an ``. * * It is not yet implemented for the `style` attribute (it depends on {@link CssAnchor.range | * `CssAnchor.range`}). */ rangeWithinAttribute?: [number, number]; } /** * An {@link Anchor} that points from the text content of an HTML (`