NativeElixirPdfUtilities.Validators.ResponsiveImageValidator (native_elixir_pdf_utilities v1.1.0)

View Source

Canonical static image selection from the pinned HTML Standard of 2026-10-05, sections 4.8.4.3.5 through 4.8.4.3.12. Invalid candidate descriptors are discarded by the standard's parser. Duplicate normalized densities retain the first URL. The standard leaves candidate choice implementation-defined. This renderer chooses the smallest density at least the print density, or the largest available. Selection never reads resources, retries failed candidates, or changes authorization.

Summary

Functions

Whether an authored img permits automatic source sizing under the HTML lazy-loading rule.

Validates density-corrected natural dimensions against the shared numeric limit.

Parses srcset with the HTML URL/descriptor tokenizer, preserving data URL commas.

Resolves an issued lazy request at its final used CSS-pixel width in its original document scope.

Selects the img resource using its direct picture parent, without loading unselected URLs.

Resolves sizes in a validated print environment. Invalid entries and eager auto are skipped.

Checks the canonical picture content model, including script-supporting elements.

Types

candidate()

@type candidate() :: %{
  url: String.t(),
  width: number() | nil,
  density: number() | nil
}

selection()

@type selection() :: %{
  url: String.t(),
  density: number() | :infinity,
  dimensions: map(),
  source: String.t()
}

Functions

allows_auto?(node)

@spec allows_auto?(map()) :: boolean()

Whether an authored img permits automatic source sizing under the HTML lazy-loading rule.

correct_natural_dimensions(image, selected)

@spec correct_natural_dimensions(map(), selection()) ::
  {:ok, map()} | {:error, {atom(), map()}}

Validates density-corrected natural dimensions against the shared numeric limit.

parse_srcset(value)

@spec parse_srcset(String.t()) :: [candidate()]

Parses srcset with the HTML URL/descriptor tokenizer, preserving data URL commas.

resolve_request(request, width, fun)

@spec resolve_request(term(), number(), (selection(), keyword() -> term())) :: term()

Resolves an issued lazy request at its final used CSS-pixel width in its original document scope.

select(node, ancestors, opts, auto_width \\ nil)

@spec select(map(), [map()], keyword(), number() | nil) ::
  {:ok, selection()} | {:error, {atom(), map()}}

Selects the img resource using its direct picture parent, without loading unselected URLs.

source_size(sizes, context, auto_width \\ nil)

@spec source_size(
  String.t(),
  NativeElixirPdfUtilities.Validators.PrintMediaValidator.context(),
  number() | nil
) :: number() | {:error, {atom(), map()}}

Resolves sizes in a validated print environment. Invalid entries and eager auto are skipped.

valid_picture_children?(children)

@spec valid_picture_children?([map()]) :: boolean()

Checks the canonical picture content model, including script-supporting elements.