StylesheetResource represents a CSS stylesheet.

It parses the stylesheet and exposes its links. Links in CSS are the images and fonts that the stylesheet refers to, as well as any @imported stylesheets.

To dry a stylesheet means expanding any relative URLs in links to absolute URLs.

Hierarchy

Accessors

  • An array of Links (a subset of links), containing only subresource links, and for whose subresourceType a Resource subclass exists. That is, those links that fromLink accepts.

    Returns SubresourceLink[]

  • get url(): `${string}:${string}`
  • URL of the resource.

    Returns `${string}:${string}`

  • get blob(): Blob
  • The stylesheet’s current content, as a Blob of CSS.

    Any modifications that were made to the stylesheet’s links are included.

    Returns Blob

  • get string(): string
  • The stylesheet’s current content, as a string of CSS.

    Any modifications that were made to the stylesheet’s links are included.

    Returns string

  • Get the links defined in the stylesheet.

    Links in CSS are the images and fonts that the stylesheet refers to, as well as any @imported stylesheets.

    The target of a Link can be modified, which updates the resource content accordingly.

    Note that currently, all links we find in a stylesheet are subresource links.

    Returns CssSubresourceLink[]

Methods

  • ‘Dry’ the resource, i.e. make it static and context-free.

    Returns void

  • Make ‘outward’ links absolute, and ‘within-document’ links relative (e.g. href="#top").

    Returns void

  • Fetch the resource a given link points to, and return it as a Resource.

    This method does not modify the given link; the caller can store the created Resource in link.resource, to grow a tree of links and resources.

    Example

    link.resource = await Resource.fromLink(link)
    

    Returns

    The newly created Resource.

    Parameters

    • link: SubresourceLink

      The link pointing to the resource.

    • config: GlobalConfig & { fetchResource?: Fetchy; signal?: AbortSignal } = {}

      Optional environment configuration.

    Returns Promise<Resource>

  • Determine the Resource subclass to use for the given subresource type.

    Returns

    The appropriate Resource subclass, or undefined if the type is not supported.

    Parameters

    • subresourceType: undefined | SubresourceType

      The type of subresource expected by the parent resource, e.g. 'image' or 'style'. Note this is not the same as its MIME type.

    Returns undefined | ResourceFactory

Constructors

  • Parameters

    • stylesheetContent: string

      The stylesheet’s content, a string of CSS.

    • url: `${string}:${string}`

      The stylesheets URL. Relevant for expanding any relative URLs it may contain.

    • config: GlobalConfig = {}

      Optional environment configuration.

    Returns StylesheetResource