CSS Layout Engine - Box/Flex/Grid layout computation
npm install @mizchi/craterCSS Layout Engine - Box/Flex/Grid layout computation, compiled from MoonBit.
Taffy-compatible test pass rate: 83% (212/256 Grid tests)
``bash`
npm install @mizchi/crater
`typescript
import {
renderHtml,
renderHtmlToJson,
renderHtmlToPaintTree,
Crater
} from '@mizchi/crater';
const html = '
// 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);
`
`bashVia npx
npx @mizchi/crater input.html
npx @mizchi/crater --json input.html
npx @mizchi/crater --styles input.html
WASM-GC (Experimental)
For browsers with WASM-GC support (Chrome 119+, Firefox 120+):
`typescript
import loadCrater from '@mizchi/crater/wasm';const crater = await loadCrater();
const layoutJson = crater.renderHtmlToJson(html, 800, 600);
`Benefits:
- Smaller bundle size (326KB vs 1.4MB)
- Potentially faster execution
- Requires WASM-GC support
TypeScript
Full TypeScript support with type definitions:
`typescript
import type { LayoutNode, PaintNode, BoxEdges } from '@mizchi/crater';
import type { CraterWasm } from '@mizchi/crater/wasm';
`Development
`bash
Build from MoonBit source
cd js && npm run buildRun playground
cd js/playground && npm run dev
``Apache-2.0