This package provides prebuilt WebAssembly bindings for the Yoga layout engine.
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();
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.
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.
- Emscripten SDK
- CMake >= 3.13
- (Optional) ninja, for faster builds
git clone https://github.com/facebook/yoga.git
cd yoga/javascript
yarn install
yarn build
# Build and test all entrypoints
yarn test
# Build and test a specific entrypoint
yarn test:asmjs-sync