Files
yoga/javascript/README.md

63 lines
1.6 KiB
Markdown
Raw Normal View History

2022-12-23 03:08:21 -08:00
# yoga-layout
2022-12-23 23:49:35 -08:00
This package provides prebuilt JavaScript bindings for the Yoga layout engine. Both WebAssembly and asm.js variants are packaged, with the optimal loaded based on platform.
2022-12-23 03:08:21 -08:00
## Usage
The default entrypoint provides an asynchronous loader function to return a Yoga instance.
```ts
import { loadYoga, ALIGN_CENTER } from "yoga-layout";
const Yoga = await loadYoga();
const node = Yoga.Node.create();
node.setAlignContent(ALIGN_CENTER);
```
An alternative synchronous API is provided for compatibility, but requires using asm.js in browsers instead of WebAssembly, leading to worse performance and larger assets.
```ts
import Yoga, { ALIGN_CENTER } from "yoga-layout/sync";
const node = Yoga.Node.create();
node.setAlignContent(ALIGN_CENTER);
```
2022-12-23 23:49:35 -08:00
## Selecting WebAssembly or asm.js
For better performance and smaller packages, WebAssembly is preferred to asm.js where available. `yoga-layout` tries to provide the right default using [export maps](https://webpack.js.org/guides/package-exports/#conditional-syntax) so that platforms which can take advantage of WebAssembly use it by default.
A specific entrypoint may be specified on platforms which do not understand export conditions.
```ts
import { loadYoga } from "yoga-layout/entrypoint/wasm-async";
```
## Contributing
2022-12-24 00:25:02 -08:00
### Requirements
1. CMake >= 3.13
1. (Optional) ninja, for faster builds
### Building
2022-12-23 23:49:35 -08:00
```bash
git clone https://github.com/facebook/yoga.git
cd yoga/javascript
yarn install
yarn build
```
2022-12-24 00:25:02 -08:00
### Testing
2022-12-23 23:49:35 -08:00
2022-12-24 00:25:02 -08:00
```bash
# Build and test all entrypoints
yarn test
# Build and test a specific entrypoint
yarn test:asmjs-sync
```