Macaw.Frame.Hooks (macaw_frame v0.1.0)

Copy Markdown View Source

The Frame's client hooks (spec/10 §7, §7.11), copied from visualize's Visualize.Hooks (its file list, ratio/1 and resolution/1; install!/0 and js_code/0 are not carried over: hooks are static files declared through the component contract, imported by the host's JS that macaw_live generates from the registry).

hooks/0 is the map the Frame declares in hooks: (macaw_component 01 §1.8), each hook a static ES module in priv/static/macaw_frame/ whose default export is the hook object; shared/0 the sibling modules they import; files/0 both. Every hook imports only its siblings and /macaw_component/client.js (bus, announce, emit, request, onAnswer, reportSize), holds no eval or new Function, and styles its overlays by classes and the CSSOM, never a style attribute.

The pixel ratio (§7.11, visualize #1023, #1025, D-266): FrameResize reports it with each size; ratio/1 reads a reported value, a number in [1, 4] as it is, one outside clamped to it, anything else 1, never an atom; resolution/1 is a view's drawing resolution, the ratio a plain map holds, 1 where it holds none.

Summary

Functions

Every client file of the Frame: the hooks' and their siblings'.

The Frame's hooks by name, each the package path of its static module.

A reported pixel ratio as the server reads it: a number in [1, 4] as it is, one outside clamped to it, anything else 1.

A view's drawing resolution: the ratio a plain map holds, read by ratio/1, 1 where it holds none.

The sibling modules the hooks import.

Functions

files()

@spec files() :: [String.t()]

Every client file of the Frame: the hooks' and their siblings'.

hooks()

@spec hooks() :: %{required(String.t()) => String.t()}

The Frame's hooks by name, each the package path of its static module.

ratio(ratio)

@spec ratio(term()) :: number()

A reported pixel ratio as the server reads it: a number in [1, 4] as it is, one outside clamped to it, anything else 1.

iex> Enum.map([2, 9, 0.5, "2", nil], &Macaw.Frame.Hooks.ratio/1)
[2, 4, 1, 1, 1]

resolution(held)

@spec resolution(term()) :: number()

A view's drawing resolution: the ratio a plain map holds, read by ratio/1, 1 where it holds none.

iex> Macaw.Frame.Hooks.resolution(%{ratio: 2})
2
iex> Macaw.Frame.Hooks.resolution(%{})
1

shared()

@spec shared() :: [String.t()]

The sibling modules the hooks import.