View Source Idmlx.Components.Element behaviour (idmlx v0.2.1)

Behaviour and utilities for InDesign document elements.

This module provides common functionality shared across different InDesign elements (TextFrames, Rectangles, Polygons, etc.), including:

  • Attribute extraction
  • Geometric calculations
  • Style handling
  • Transformation processing
  • HTML/CSS conversion support

Element Properties

Common properties handled by this module:

  • Names and identifiers
  • Content types
  • Style references
  • Geometric properties
  • Transformations
  • Attributes and preferences

Coordinate System

Uses InDesign's coordinate system:

  • Origin at top-left
  • Positive X to the right
  • Positive Y downward
  • Units in points (1/72 inch)

Summary

Functions

Embeds object style in an element.

Embeds paragraph style in an element if applicable.

Formats rotation from a transformation matrix.

Gets all attributes from an XML element.

Gets a specific attribute value from a style.

Gets the bounding box for an element.

Gets the content type attribute from an XML element.

Gets dimensions from a bounding box.

Gets the transformation matrix from an XML element.

Gets Konva rotation properties for an element.

Gets the name attribute from an XML element.

Gets the object style name from an XML element.

Gets transformed points from an XML element.

Gets a specific preference value from an element.

Callbacks

parse(xml_fragment)

@callback parse(xml_fragment :: any()) :: any()

Functions

embed_object_style(element, styles)

@spec embed_object_style(map(), [map()]) :: map()

Embeds object style in an element.

Parameters

  • element: Element to update
  • styles: List of available styles

Returns

Updated element with embedded style

embed_paragraph_style(element, styles)

@spec embed_paragraph_style(map(), [map()]) :: map()

Embeds paragraph style in an element if applicable.

Parameters

  • element: Element to update
  • styles: List of available styles

Returns

Updated element with embedded style

format_rotation(item_transform)

@spec format_rotation([float()]) :: float()

Formats rotation from a transformation matrix.

Parameters

  • item_transform: Transformation matrix
  • _: Optional additional parameters

Returns

CSS rotation string or empty string

Examples

iex> Element.format_rotation([0.866, 0.5, -0.5, 0.866, 0, 0])
"transform: rotate(30deg);"

get_all_attributes(xml)

@spec get_all_attributes(SweetXml.t()) :: [map()]

Gets all attributes from an XML element.

Parameters

  • xml: XML fragment to extract attributes from

Returns

List of attribute maps with :key and :value pairs

Examples

iex> Element.get_all_attributes(xml_fragment)
[%{key: :Name, value: "rectangle_1"}, %{key: :ContentType, value: "GraphicType"}]

get_attribute_value(style, key)

@spec get_attribute_value(map(), atom() | String.t()) :: any()

Gets a specific attribute value from a style.

Parameters

  • style: Style struct containing attributes
  • key: Attribute key to look up

Returns

Normalized attribute value or nil

Examples

iex> Element.get_attribute_value(style, :PointSize)
12.0

get_bounding_box(xml)

@spec get_bounding_box(SweetXml.t()) :: %{required(String.t()) => float()}

Gets the bounding box for an element.

Parameters

  • xml: XML fragment containing geometry data

Returns

Map of bounding box coordinates

Examples

iex> Element.get_bounding_box(xml_fragment)
%{"x1" => 0.0, "y1" => 0.0, "x2" => 100.0, "y2" => 100.0}

get_content_type(xml)

@spec get_content_type(SweetXml.t()) :: String.t() | nil

Gets the content type attribute from an XML element.

Parameters

  • xml: XML fragment to extract content type from

Returns

Content type string or nil

Examples

iex> Element.get_content_type(xml_fragment)
"GraphicType"

get_dimensions(xml)

@spec get_dimensions(SweetXml.t()) :: %{required(String.t()) => float()}

Gets dimensions from a bounding box.

Parameters

  • xml: XML fragment containing geometry data

Returns

Map of width and height values

Examples

iex> Element.get_dimensions(xml_fragment)
%{"width" => 100.0, "height" => 100.0}

get_item_transform(xml)

@spec get_item_transform(SweetXml.t()) :: [float()]

Gets the transformation matrix from an XML element.

Parameters

  • xml: XML fragment to extract transform from

Returns

List of 6 float values [a, b, c, d, tx, ty] or default matrix

Examples

iex> Element.get_item_transform(xml_fragment)
[1.0, 0.0, 0.0, 1.0, 100.0, 200.0]

get_konva_rotation_props(element)

@spec get_konva_rotation_props(map()) :: map()

Gets Konva rotation properties for an element.

Parameters

  • element: Element to get properties for

Returns

Map of position properties or empty map

Examples

iex> Element.get_konva_rotation_props(element)
%{"x" => 100.0, "y" => 200.0}

get_name(xml)

@spec get_name(SweetXml.t()) :: String.t() | nil

Gets the name attribute from an XML element.

Parameters

  • xml: XML fragment to extract name from

Returns

Name string or nil

Examples

iex> Element.get_name(xml_fragment)
"rectangle_1"

get_object_style_name(xml)

@spec get_object_style_name(SweetXml.t()) :: String.t() | nil

Gets the object style name from an XML element.

Parameters

  • xml: XML fragment to extract style from

Returns

Object style name string or nil

Examples

iex> Element.get_object_style_name(xml_fragment)
"ObjectStyle/Basic"

get_points(xml)

@spec get_points(SweetXml.t()) :: [[float()]]

Gets transformed points from an XML element.

Parameters

  • xml: XML fragment containing point data

Returns

List of transformed point coordinates

Examples

iex> Element.get_points(xml_fragment)
[[0.0, 0.0], [100.0, 0.0], [100.0, 100.0], [0.0, 100.0]]

get_preference_value(element, key)

@spec get_preference_value(map(), atom() | String.t()) :: any()

Gets a specific preference value from an element.

Parameters

  • element: Element struct containing preferences
  • key: Preference key to look up

Returns

Normalized preference value or nil

Examples

iex> Element.get_preference_value(element, :VerticalJustification)
"CenterAlign"