NativeElixirPdfUtilities.Validators.PrintMediaValidator (native_elixir_pdf_utilities v1.1.0)

View Source

Media predicates share one bounded grammar. Lengths are CSS pixels. Stylesheet media dimensions describe the requested page box before CSS @page size. The legacy responsive source-size context uses the effective printable area. Embedded media dimensions include gutters; client layout is separate.

Summary

Functions

Returns the environment part of a stylesheet cache key, omitting invariant media types.

Builds media context from a nonnegative child viewport in points, including scrollbar gutters.

Returns a validated print context from effective renderer options.

Evaluates a media query list against a validated print context. Unknown features do not match.

Checks stylesheet applicability and diagnoses viewport-qualified page defaults during page preparation.

Returns stylesheet media context from the requested page box before CSS @page size.

Selects bounded nested media blocks without changing their source order. Nil retains the legacy media-type-only API.

Resolves a nonnegative CSS source-size length to CSS pixels, or returns :error.

Validates explicit print viewport and deterministic image density options.

Types

context()

@type context() :: %{
  :width => float(),
  :height => float(),
  :density => float(),
  :type => :print,
  optional(:source_font_options) => keyword(),
  optional(:source_metrics) => map()
}

Functions

cache_context(css, context)

@spec cache_context(String.t(), context() | nil | :unpositioned) ::
  context() | nil | :unpositioned | :print

Returns the environment part of a stylesheet cache key, omitting invariant media types.

client_context(opts, arg)

@spec client_context(keyword(), {number(), number()}) ::
  {:ok, context()} | {:error, {atom(), map()}}

Builds media context from a nonnegative child viewport in points, including scrollbar gutters.

context(opts)

@spec context(keyword()) :: {:ok, context()} | {:error, {atom(), map()}}

Returns a validated print context from effective renderer options.

matches?(query, context)

@spec matches?(String.t(), context() | nil | :unpositioned) :: boolean()

Evaluates a media query list against a validated print context. Unknown features do not match.

matches_stylesheet?(query, css, context)

@spec matches_stylesheet?(
  String.t(),
  String.t(),
  context() | nil | :unpositioned
) :: boolean()

Checks stylesheet applicability and diagnoses viewport-qualified page defaults during page preparation.

renderer_context(opts)

@spec renderer_context(keyword()) :: {:ok, context()} | {:error, {atom(), map()}}

Returns stylesheet media context from the requested page box before CSS @page size.

select_rules(css, context)

@spec select_rules(String.t(), context() | nil | :unpositioned) ::
  {:ok, String.t()} | {:error, :invalid_css}

Selects bounded nested media blocks without changing their source order. Nil retains the legacy media-type-only API.

source_length(value, context)

@spec source_length(String.t(), context()) ::
  {:ok, float()} | :error | {:error, {atom(), map()}}

Resolves a nonnegative CSS source-size length to CSS pixels, or returns :error.

validate_options(opts)

@spec validate_options(keyword()) :: :ok | {:error, {atom(), map()}}

Validates explicit print viewport and deterministic image density options.