@takumi-rs/helpers
v1.8.0
Published
Utility helpers for converting JSX/HTML to Takumi node trees and handling resources.
Maintainers
Readme
@takumi-rs/helpers
Utility functions and types for working with Takumi node trees.
This package provides the core logic for converting JSX and HTML into the layout-ready node trees that Takumi's Rust engine expects. It also handles resource fetching (fonts, images) and emoji processing.
Installation
npm install @takumi-rs/helpersFeatures
JSX to Node Tree
Convert React-like elements into a serializable node tree + stylesheets.
import { fromJsx } from "@takumi-rs/helpers/jsx";
const { node, stylesheets } = await fromJsx(<div style={{ display: "flex" }}>Hello</div>);HTML to Node Tree
Parse HTML strings into Takumi nodes.
import { fromHtml } from "@takumi-rs/helpers/html";
const { node, stylesheets } = await fromHtml("<div style='color: red'>Hello</div>");Resource Fetching
Extract and fetch external resources (images, fonts) mentioned in a node tree.
import { extractResourceUrls, fetchResources } from "@takumi-rs/helpers";
const urls = extractResourceUrls(node);
const resources = await fetchResources(urls);Emoji Processing
Find and replace emoji characters in text nodes with image nodes (Twemoji or custom).
import { extractEmojis } from "@takumi-rs/helpers/emoji";
const newNode = extractEmojis(oldNode, "twemoji");License
MIT or Apache-2.0
