Skip to content

Latest commit

 

History

History
 
 

javascript

yoga-layout

This package provides prebuilt WebAssembly bindings for the Yoga layout engine.

Usage

import {Yoga, Align} from 'yoga-layout';

const node = Yoga.Node.create();
node.setAlignContent(Align.Center);

Objects created by Yoga.<>.create() are not automatically garbage collected and should be freed once they are no longer in use.

// Free a config
config.free();

// Free a tree of Nodes
node.freeRecursive();

// Free a single Node
node.free();

Using TypeScript

This package provides out-of-the-box TypeScript typings so long as tsc is configured to support ESM resolution. It is recommended to set moduleResolution: 'bundler' or moduleResolution: node16 in your tsconfig.json according to your environment.

ES Modules

yoga-layout is only provided as an ES Module, relying on top-level await. This allows providing a synchronous API, while still allowing async WebAssembly compilation in browsers, and will allow eventual usage of ESM/WASM interop.

Contributing

Requirements

  1. Emscripten SDK
  2. CMake >= 3.13
  3. (Optional) ninja, for faster builds

Building

git clone https://github.com/facebook/yoga.git
cd yoga/javascript
yarn install
yarn build

Testing

# Build and test all entrypoints
yarn test

# Build and test a specific entrypoint
yarn test:asmjs-sync