Figler.Scene (figler v0.1.0-beta.1)

Copy Markdown View Source

Fast queries and navigation for Figma scenes.

These functions accept .fig files directly, as well as already-extracted Figma Kiwi binaries. Build an index once to run repeated name, text, type, structural, and hierarchy queries over the same design.

Successful calls return their documented value directly. Malformed inputs, selectors, GUIDs, and options raise Figler.Error; valid lookups with no match return nil or []. See the errors-and-options guide for the stable contract.

Summary

Functions

Returns ancestors for a node GUID, ordered from root to parent.

Returns projected field values from nodes, similar to Floki.attribute/2.

Returns nodes of a given projected node type without constructing XPath.

Returns direct children for a parent GUID in scene order.

Returns nodes with component keys.

Returns all descendants for a node GUID in scene order.

Finds nodes by common projected fields without interpolating XPath.

Builds an effective scene graph handle.

Builds a reusable native scene index resource.

Returns nodes whose projected name contains needle without constructing XPath.

Returns nodes with an exact projected name without constructing XPath.

Looks up a projected scene node by GUID.

Returns canvas/page nodes.

Returns the parent node for a node GUID.

Extracts the raw Figma Kiwi Message binary from any supported scene input.

Queries a binary scene, reusable scene index, or graph source projection with XPath. For an effective graph, XPath runs against its reusable raw index; helper APIs such as by_type/3, named/2, and find/2 inspect effective graph nodes, including resolved clones.

Returns root nodes in scene order.

Returns sibling nodes for a node GUID in scene order.

Returns a projected scene summary.

Returns projected text from nodes, similar to Floki.text/2.

Returns text nodes whose projected text contains needle without constructing XPath.

Returns text nodes.

Builds a lightweight nested scene tree.

Returns nodes with one or more fill paints.

Returns nodes with one or more stroke paints.

Types

scene_graph()

@type scene_graph() :: Figler.Scene.Graph.t()

scene_index()

@type scene_index() :: Figler.Scene.Index.t()

scene_node()

@type scene_node() :: Figler.Scene.Node.t()

summary()

@type summary() :: Figler.Scene.Summary.t()

Functions

ancestors(graph, guid)

@spec ancestors(
  binary() | Figler.Scene.Index.t() | Figler.Scene.Graph.t() | reference(),
  String.t()
) ::
  [scene_node()]

Returns ancestors for a node GUID, ordered from root to parent.

attribute(nodes, field)

@spec attribute([scene_node()], atom() | String.t()) :: [term()]

Returns projected field values from nodes, similar to Floki.attribute/2.

by_type(scene_or_nodes, type, opts \\ [])

@spec by_type(
  binary()
  | Figler.Scene.Index.t()
  | Figler.Scene.Graph.t()
  | reference()
  | [scene_node()],
  atom() | String.t(),
  keyword()
) :: [scene_node()]

Returns nodes of a given projected node type without constructing XPath.

children(graph, parent_guid)

@spec children(
  binary() | Figler.Scene.Index.t() | Figler.Scene.Graph.t() | reference(),
  String.t()
) ::
  [scene_node()]

Returns direct children for a parent GUID in scene order.

components(nodes)

@spec components(
  binary()
  | Figler.Scene.Index.t()
  | Figler.Scene.Graph.t()
  | reference()
  | [scene_node()]
) :: [scene_node()]

Returns nodes with component keys.

descendants(graph, guid)

@spec descendants(
  binary() | Figler.Scene.Index.t() | Figler.Scene.Graph.t() | reference(),
  String.t()
) ::
  [scene_node()]

Returns all descendants for a node GUID in scene order.

find(graph, opts)

Finds nodes by common projected fields without interpolating XPath.

graph(scene, opts \\ [])

Builds an effective scene graph handle.

Scene.index/1 is the fast raw projection. Scene.graph/2 is the separate surface for resolved Figma semantics such as populated instances, symbol overrides, component props, derived symbol data, and variable/style resolution.

index(binary)

@spec index(binary()) :: Figler.Scene.Index.t()

Builds a reusable native scene index resource.

Use this when running multiple XPath queries over the same scene.

name_contains(scene_or_nodes, needle, opts \\ [])

@spec name_contains(
  binary()
  | Figler.Scene.Index.t()
  | Figler.Scene.Graph.t()
  | reference()
  | [scene_node()],
  String.t(),
  keyword()
) :: [scene_node()]

Returns nodes whose projected name contains needle without constructing XPath.

named(nodes, name)

Returns nodes with an exact projected name without constructing XPath.

node(graph, guid)

@spec node(
  binary() | Figler.Scene.Index.t() | Figler.Scene.Graph.t() | reference(),
  String.t()
) ::
  scene_node() | nil

Looks up a projected scene node by GUID.

pages(scene)

Returns canvas/page nodes.

parent(graph, guid)

@spec parent(
  binary() | Figler.Scene.Index.t() | Figler.Scene.Graph.t() | reference(),
  String.t()
) ::
  scene_node() | nil

Returns the parent node for a node GUID.

payload!(binary)

@spec payload!(binary()) :: binary()

Extracts the raw Figma Kiwi Message binary from any supported scene input.

query(scene, xpath, opts \\ [])

Queries a binary scene, reusable scene index, or graph source projection with XPath. For an effective graph, XPath runs against its reusable raw index; helper APIs such as by_type/3, named/2, and find/2 inspect effective graph nodes, including resolved clones.

Options:

  • :fields - list of projected fields to keep in returned nodes. :guid and :node_type are always kept. Defaults to all fields.

Scene nodes are exposed as elements named by their Figma node type, for example //canvas or //text.

roots(graph)

Returns root nodes in scene order.

siblings(graph, guid)

@spec siblings(
  binary() | Figler.Scene.Index.t() | Figler.Scene.Graph.t() | reference(),
  String.t()
) ::
  [scene_node()]

Returns sibling nodes for a node GUID in scene order.

summary(binary)

@spec summary(binary()) :: Figler.Scene.Summary.t()

Returns a projected scene summary.

text(nodes, opts \\ [])

@spec text(
  [scene_node()],
  keyword()
) :: String.t()

Returns projected text from nodes, similar to Floki.text/2.

text_contains(scene_or_nodes, needle, opts \\ [])

@spec text_contains(
  binary()
  | Figler.Scene.Index.t()
  | Figler.Scene.Graph.t()
  | reference()
  | [scene_node()],
  String.t(),
  keyword()
) :: [scene_node()]

Returns text nodes whose projected text contains needle without constructing XPath.

text_nodes(scene_or_nodes)

@spec text_nodes(
  binary()
  | Figler.Scene.Index.t()
  | Figler.Scene.Graph.t()
  | reference()
  | [scene_node()]
) :: [scene_node()]

Returns text nodes.

tree(scene, opts \\ [])

Builds a lightweight nested scene tree.

with_fills(nodes)

@spec with_fills(
  binary()
  | Figler.Scene.Index.t()
  | Figler.Scene.Graph.t()
  | reference()
  | [scene_node()]
) :: [scene_node()]

Returns nodes with one or more fill paints.

with_strokes(nodes)

@spec with_strokes(
  binary()
  | Figler.Scene.Index.t()
  | Figler.Scene.Graph.t()
  | reference()
  | [scene_node()]
) :: [scene_node()]

Returns nodes with one or more stroke paints.