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
Functions
Embeds object style in an element.
Parameters
- element: Element to update
- styles: List of available styles
Returns
Updated element with embedded style
Embeds paragraph style in an element if applicable.
Parameters
- element: Element to update
- styles: List of available styles
Returns
Updated element with embedded style
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);"
@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"}]
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
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}
@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"
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}
@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]
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}
@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"
@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"
@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]]
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"