Figler.Scene.Graph.OpenPencilOracle (figler v0.1.0-beta.3)

Copy Markdown View Source

Compares effective scene graphs against OpenPencil's occurrence interpreter.

scripts/openpencil_oracle.ts runs OpenPencil's reader on a .fig file and prints each page's interpreted tree. This module builds the same projection from a Figler graph and reports field-level differences, aligning children by their saved order.

With scene: true, OpenPencil materializes the document into its scene graph, which also resolves variables, modes, and styles, and the comparison covers resolved paints, text, and layout values (see project_scene/2).

Summary

Functions

Compares every page in expected against graph.

Compares every page in expected against trees already in the oracle's shape, which actual returns for a page GUID string.

Compares every page of OpenPencil's materialized scene against graph.

Runs OpenPencil's reader on fig_path through bun and decodes its output.

Projects a graph node and its descendants into the oracle's shape.

Projects a graph node's resolved values into the scene oracle's shape.

Types

diff()

@type diff() :: %{
  path: String.t(),
  field: String.t(),
  openpencil: term(),
  figler: term()
}

Functions

compare(graph, expected)

@spec compare(Figler.Scene.Graph.t(), map()) :: %{
  pages: [map()],
  diffs: [diff()],
  by_field: map()
}

Compares every page in expected against graph.

compare_projected(map, actual)

@spec compare_projected(map(), (String.t() -> map() | nil)) :: %{
  pages: [map()],
  diffs: [diff()],
  by_field: map()
}

Compares every page in expected against trees already in the oracle's shape, which actual returns for a page GUID string.

compare_scene(graph, expected)

@spec compare_scene(Figler.Scene.Graph.t(), map()) :: %{
  pages: [map()],
  diffs: [diff()],
  by_field: map()
}

Compares every page of OpenPencil's materialized scene against graph.

expected!(fig_path, opts \\ [])

@spec expected!(
  Path.t(),
  keyword()
) :: map()

Runs OpenPencil's reader on fig_path through bun and decodes its output.

Options:

  • :openpencil - OpenPencil checkout with installed dependencies. Defaults to FIGLER_OPENPENCIL_DIR or ../open-pencil-app.
  • :pages - page GUID strings to read. Defaults to every visible page.
  • :scene - dump OpenPencil's materialized scene graph instead of its interpreted occurrence trees.

project(graph, node)

@spec project(Figler.Scene.Graph.t(), Figler.Scene.Node.t() | nil) :: map() | nil

Projects a graph node and its descendants into the oracle's shape.

project_scene(graph, node, expanded? \\ false)

Projects a graph node's resolved values into the scene oracle's shape.

OpenPencil's scene graph keeps source identity on layers built from source records but not on components, instances, or anything inside them, which pair by position. Defaults follow OpenPencil's record conversion.