JavaScript bindings and compatibility facade for crater
Dependencies
npm install @mizchi/craterimport {
renderHtml,
renderHtmlToJson,
renderHtmlToPaintTree,
Crater
} from '@mizchi/crater';
const html = '<div style="width: 200px; display: flex">...</div>';
// Get layout tree as JSON string
const layoutJson = renderHtmlToJson(html, 800, 600);
const layout = Crater.parseLayout(layoutJson);
// Get paint tree with colors
const paintJson = renderHtmlToPaintTree(html, 800, 600);
const paintTree = Crater.parsePaintTree(paintJson);# Via npx
npx @mizchi/crater input.html
npx @mizchi/crater --json input.html
npx @mizchi/crater --styles input.html
# Or install globally
npm install -g @mizchi/crater
crater input.htmlimport loadCrater from '@mizchi/crater/wasm';
const crater = await loadCrater();
const layoutJson = crater.renderHtmlToJson(html, 800, 600);import type { LayoutNode, PaintNode, BoxEdges } from '@mizchi/crater';
import type { CraterWasm } from '@mizchi/crater/wasm';# Build from MoonBit source
cd js && npm run build
# Run playground
cd js/playground && npm run devpub(all) struct FlatLayoutNode {
id : String
parent_id : String
index : Int
x : Double
y : Double
width : Double
height : Double
content_x : Double
content_y : Double
content_width : Double
content_height : Double
text : String
}fn addChild(parent_id : String, child_id : String) -> Boolfn calculateLayout(width : Double, height : Double) -> Stringfn computeFull() -> Stringfn computeIncremental() -> Stringfn computeLayoutJson(html : String, width : Int, height : Int) -> Stringfn createNode(id : String) -> Intfn createTree(html : String, width : Int, height : Int) -> Intfn extractMainContent(html : String) -> Stringfn extractMainContentWithLayout(html : String, width : Int, height : Int) -> Stringfn getAccessibilityTree(html : String) -> Stringfn getAriaSnapshot(html : String) -> Stringfn getAriaSnapshotJson(html : String) -> Stringfn insertChild(parent_id : String, child_id : String, index : Int) -> Boolfn markDirty(node_id : String) -> Boolfn renderHtml(html : String, width : Int, height : Int) -> Stringfn renderHtmlToJson(html : String, width : Int, height : Int) -> Stringfn renderHtmlToPaintTree(html : String, width : Int, height : Int) -> Stringfn renderHtmlToSixel(html : String, width : Int, height : Int) -> Stringfn renderHtmlToSixelWithStyles(html : String, width : Int, height : Int) -> Stringfn setAlignItems(node_id : String, value : Int) -> Boolfn setDisplay(node_id : String, value : Int) -> Boolfn setFlexBasis(node_id : String, value : Double) -> Boolfn setFlexDirection(node_id : String, value : Int) -> Boolfn setFlexWrap(node_id : String, value : Int) -> Boolfn setHeightPercent(node_id : String, value : Double) -> Boolfn setJustifyContent(node_id : String, value : Int) -> Boolfn setWidthPercent(node_id : String, value : Double) -> Boolfn updateStyle(node_id : String, css : String) -> BoolJavaScript bindings and compatibility facade for crater
Dependencies