跳转至

节点与结果类型

Python 类型层定义了节点输入、测量结果和动画场景。

AnimationScene.duration_ms 和 RawAnimationFrame.duration_ms 必须为正。原始动画帧 还要求尺寸为正,并且恰好包含 width * height * 4 个 RGBA 字节。

RawRgbaImage 描述用作 ImageNode.src 的、已解码的按行优先 RGBA 像素。它的字节长度 遵循同样的 width * height * 4 约定。

takumi_py.types.TextNode

Bases: NodeBase

A text leaf node.

Attributes:

Name Type Description
text str

Text content to lay out and paint.

type instance-attribute

type: Literal['text']

text instance-attribute

text: str

takumi_py.types.ImageNode

Bases: NodeBase

An image leaf node.

Attributes:

Name Type Description
src str | bytes | RawRgbaImage

Image identifier, encoded image bytes, or raw RGBA pixels.

width NotRequired[float]

Rendered width in CSS pixels.

height NotRequired[float]

Rendered height in CSS pixels.

type instance-attribute

type: Literal['image']

src instance-attribute

src: str | bytes | RawRgbaImage

width instance-attribute

width: NotRequired[float]

height instance-attribute

height: NotRequired[float]

takumi_py.types.RawRgbaImage

Bases: TypedDict

Raw row-major RGBA pixels used directly as an image node source.

Attributes:

Name Type Description
width int

Image width in pixels.

height int

Image height in pixels.

data bytes

Exactly width * height * 4 bytes in RGBA channel order.

premultiplied NotRequired[bool]

Whether RGB channels already include alpha multiplication. Defaults to False.

width instance-attribute

width: int

height instance-attribute

height: int

data instance-attribute

data: bytes

premultiplied instance-attribute

premultiplied: NotRequired[bool]

takumi_py.types.ContainerNode

Bases: NodeBase

A container that lays out child nodes.

Attributes:

Name Type Description
children NotRequired[list[Node]]

Child nodes in document order.

type instance-attribute

type: Literal['container']

children instance-attribute

children: NotRequired[list[Node]]

takumi_py.types.MeasuredNode dataclass

An immutable node in a measured layout tree.

Attributes:

Name Type Description
width float

Box width in layout units.

height float

Box height in layout units.

transform tuple[float, float, float, float, float, float]

Six values for the node's 2D affine transform.

children tuple[MeasuredNode, ...]

Measured child nodes.

runs tuple[MeasuredTextRun, ...]

Text runs laid out directly on this node.

width instance-attribute

width: float

height instance-attribute

height: float

transform instance-attribute

transform: tuple[float, float, float, float, float, float]

children instance-attribute

children: tuple[MeasuredNode, ...]

runs instance-attribute

runs: tuple[MeasuredTextRun, ...]

__init__

__init__(
    width: float,
    height: float,
    transform: tuple[
        float, float, float, float, float, float
    ],
    children: tuple[MeasuredNode, ...],
    runs: tuple[MeasuredTextRun, ...],
) -> None

takumi_py.types.MeasuredTextRun dataclass

One shaped text run from a layout measurement.

Attributes:

Name Type Description
text str

Text covered by the run.

x float

Left edge in layout coordinates.

y float

Top edge in layout coordinates.

width float

Run width in layout units.

height float

Run height in layout units.

text instance-attribute

text: str

x instance-attribute

x: float

y instance-attribute

y: float

width instance-attribute

width: float

height instance-attribute

height: float

__init__

__init__(
    text: str,
    x: float,
    y: float,
    width: float,
    height: float,
) -> None

takumi_py.types.AnimationScene dataclass

One timed scene in a rendered animation sequence.

Attributes:

Name Type Description
node NodeInput | CompiledNode

A Python node mapping or an already compiled node.

duration_ms int

Positive scene duration in milliseconds.

node instance-attribute

node: NodeInput | CompiledNode

duration_ms instance-attribute

duration_ms: int

__init__

__init__(
    node: NodeInput | CompiledNode, duration_ms: int
) -> None

takumi_py.types.RawAnimationFrame dataclass

A pre-rendered RGBA frame for Renderer.encode_frames.

Attributes:

Name Type Description
data bytes

Exactly width * height * 4 row-major RGBA bytes.

width int

Frame width in pixels.

height int

Frame height in pixels.

duration_ms int

Positive frame duration in milliseconds.

data instance-attribute

data: bytes

width instance-attribute

width: int

height instance-attribute

height: int

duration_ms instance-attribute

duration_ms: int

__init__

__init__(
    data: bytes, width: int, height: int, duration_ms: int
) -> None

takumi_py.types.validate_node

validate_node(node: object) -> Node

Validate and normalize a node mapping in Python.

Parameters:

Name Type Description Default
node object

A mapping with a type of "text", "image", or "container".

required

Returns:

Type Description
Node

A typed node mapping normalized through msgspec.

Raises:

Type Description
NodeValidationError

If the mapping does not match a supported node shape.