跳转至

选项与资源

这些类型把渲染、动画、HTML 解析、字体和图片输入组织在一起。

通用的校验约定:

  • 设置 RenderOptions.lang 时,它必须是合法的 BCP-47 语言标签。
  • 设置 FontResource.weight 时,它必须是 1 到 1000 的有限数。
  • FontResource.unicode_range 的每一项都是满足 0 <= start <= end <= 0x10FFFF 的 (start, end) 闭区间。
  • AnimationEncodeOptions.quality 接受 0 到 100,webp_speed 接受 0 到 6。

违反这些数值或语言标签约定时抛出 ValueError。

takumi_py.options.RenderOptions dataclass

Reusable render settings shared by raster, SVG, and measurement APIs.

Explicit keyword arguments on a render method override matching fields.

Attributes:

Name Type Description
width int | None

Viewport width in CSS pixels, or None to infer it from layout. The default is 1200.

height int | None

Viewport height in CSS pixels, or None to infer it from layout. The default is 630.

format ImageOutputFormat

Static output format. "raw" returns row-major RGBA bytes.

quality int | None

Lossy encoder quality from 0 through 100 where supported.

lossless bool | None

Whether to use lossless WebP encoding.

font_size float

Root font size in CSS pixels.

device_pixel_ratio float

Scale factor for raster output and layout.

draw_debug_border bool

Draw Takumi's layout debug borders.

time_ms int

Animation sampling time in milliseconds.

dithering DitheringAlgorithm

Color-dithering algorithm for supported formats.

images Sequence[ImageResourceInput] | None

Per-render image resources addressable by their src values.

keyframes KeyframesInput | None

Structured animation rules appended to the stylesheets.

font_families Sequence[str] | None

Preferred fallback font-family order.

lang str | None

BCP-47 language tag used for text shaping and font selection.

width class-attribute instance-attribute

width: int | None = 1200

height class-attribute instance-attribute

height: int | None = 630

format class-attribute instance-attribute

format: ImageOutputFormat = 'png'

quality class-attribute instance-attribute

quality: int | None = None

lossless class-attribute instance-attribute

lossless: bool | None = None

font_size class-attribute instance-attribute

font_size: float = 16.0

device_pixel_ratio class-attribute instance-attribute

device_pixel_ratio: float = 1.0

draw_debug_border class-attribute instance-attribute

draw_debug_border: bool = False

time_ms class-attribute instance-attribute

time_ms: int = 0

dithering class-attribute instance-attribute

dithering: DitheringAlgorithm = 'none'

images class-attribute instance-attribute

images: Sequence[ImageResourceInput] | None = None

keyframes class-attribute instance-attribute

keyframes: KeyframesInput | None = None

font_families class-attribute instance-attribute

font_families: Sequence[str] | None = None

lang class-attribute instance-attribute

lang: str | None = None

__init__

__init__(
    width: int | None = 1200,
    height: int | None = 630,
    format: ImageOutputFormat = "png",
    quality: int | None = None,
    lossless: bool | None = None,
    font_size: float = 16.0,
    device_pixel_ratio: float = 1.0,
    draw_debug_border: bool = False,
    time_ms: int = 0,
    dithering: DitheringAlgorithm = "none",
    images: Sequence[ImageResourceInput] | None = None,
    keyframes: KeyframesInput | None = None,
    font_families: Sequence[str] | None = None,
    lang: str | None = None,
) -> None

takumi_py.options.AnimationEncodeOptions dataclass

Reusable encoder settings for animated output.

Explicit keyword arguments on render_animation or encode_frames override matching fields.

Attributes:

Name Type Description
format AnimationOutputFormat

Animation container format.

quality int | None

Lossy encoder quality from 0 through 100 where supported.

lossless bool | None

Whether to use lossless WebP encoding.

loop_count int | None

Number of animation repetitions, or None for the format-specific default.

webp_blend bool

Blend each WebP frame with the previous canvas.

webp_dispose bool

Dispose each WebP frame before drawing the next one.

webp_speed int | None

WebP encoder speed/effort setting from 0 through 6.

format class-attribute instance-attribute

format: AnimationOutputFormat = 'webp'

quality class-attribute instance-attribute

quality: int | None = None

lossless class-attribute instance-attribute

lossless: bool | None = None

loop_count class-attribute instance-attribute

loop_count: int | None = None

webp_blend class-attribute instance-attribute

webp_blend: bool = True

webp_dispose class-attribute instance-attribute

webp_dispose: bool = False

webp_speed class-attribute instance-attribute

webp_speed: int | None = None

__init__

__init__(
    format: AnimationOutputFormat = "webp",
    quality: int | None = None,
    lossless: bool | None = None,
    loop_count: int | None = None,
    webp_blend: bool = True,
    webp_dispose: bool = False,
    webp_speed: int | None = None,
) -> None

takumi_py.options.HtmlOptions dataclass

Inputs that control how the Rust HTML parser builds a node tree.

Attributes:

Name Type Description
presets HtmlStylePresets

Default element styles to apply. "chromium" matches browser defaults; "none" applies no preset.

tailwind_property str | None

HTML attribute that contains Tailwind classes. None reads the tw attribute.

max_depth int | None

Maximum element nesting depth, or None for Takumi's default limit.

presets class-attribute instance-attribute

presets: HtmlStylePresets = 'chromium'

tailwind_property class-attribute instance-attribute

tailwind_property: str | None = None

max_depth class-attribute instance-attribute

max_depth: int | None = None

__init__

__init__(
    presets: HtmlStylePresets = "chromium",
    tailwind_property: str | None = None,
    max_depth: int | None = None,
) -> None

takumi_py.options.ImageResource dataclass

Image bytes addressable by an image node's src.

Attributes:

Name Type Description
src str

Identifier matched against the image node's src.

data bytes

Encoded image bytes, such as PNG, JPEG, WebP, or SVG data.

cache ImageCacheMode

Whether the renderer may retain the decoded image in its renderer-local resource cache.

src instance-attribute

src: str

data instance-attribute

data: bytes

cache class-attribute instance-attribute

cache: ImageCacheMode = 'auto'

__init__

__init__(
    src: str, data: bytes, cache: ImageCacheMode = "auto"
) -> None

takumi_py.options.FontResource dataclass

Font bytes plus the @font-face descriptors used to register them.

Register each subset of a family under the same name with the unicode_range its @font-face declares; a subset only serves the codepoints in its ranges.

Attributes:

Name Type Description
data bytes

TrueType, OpenType, WOFF, or WOFF2 font bytes.

name str | None

Family name to register the font under. Defaults to the name stored in the font file.

weight float | None

Weight override from 1 through 1000.

style str | None

CSS font-style override such as "italic".

subset_of str | None

Deprecated. Takumi now treats it as the family name and it takes precedence over name; use name with unicode_range instead.

generic_family GenericFontFamily | None

CSS generic family keyword this font resolves.

unicode_range Sequence[UnicodeRange] | None

Inclusive (start, end) codepoint ranges the font serves, as in @font-face unicode-range. None serves every codepoint the font covers.

data instance-attribute

data: bytes

name class-attribute instance-attribute

name: str | None = None

weight class-attribute instance-attribute

weight: float | None = None

style class-attribute instance-attribute

style: str | None = None

subset_of class-attribute instance-attribute

subset_of: str | None = None

generic_family class-attribute instance-attribute

generic_family: GenericFontFamily | None = None

unicode_range class-attribute instance-attribute

unicode_range: Sequence[UnicodeRange] | None = None

__init__

__init__(
    data: bytes,
    name: str | None = None,
    weight: float | None = None,
    style: str | None = None,
    subset_of: str | None = None,
    generic_family: GenericFontFamily | None = None,
    unicode_range: Sequence[UnicodeRange] | None = None,
) -> None

__post_init__

__post_init__() -> None

结构化关键帧

可以把结构化关键帧传给渲染方法,或存入 RenderOptions.keyframes。映射形式使用动画名称 作为键。

takumi_py.options.Keyframe

Bases: TypedDict

One structured keyframe and the declarations it applies.

Attributes:

Name Type Description
offsets Sequence[float]

Normalized timeline positions from 0 through 1.

declarations StyleInput

CSS declarations applied at those positions.

offsets instance-attribute

offsets: Sequence[float]

declarations instance-attribute

declarations: StyleInput

takumi_py.options.KeyframesRule

Bases: TypedDict

A structured keyframe rule with a CSS animation name.

Attributes:

Name Type Description
name str

Animation name referenced by the CSS animation property.

keyframes Sequence[Keyframe]

Ordered keyframes that make up the rule.

name instance-attribute

name: str

keyframes instance-attribute

keyframes: Sequence[Keyframe]