# yoga-layout-wasm

> yoga-layout webassembly module

Latest version **1.9.3-alpha.7** (published 2020-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install yoga-layout-wasm
pnpm add yoga-layout-wasm
yarn add yoga-layout-wasm
bun add yoga-layout-wasm
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.9.3-alpha.7 |
| Published | 2020-05-30 |
| First published | 2020-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 581.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 32 |
| Author | Huang Qi |
| Maintainers | pinqy520 |
| Keywords | webassembly, wasm, yoga-layout, yoga |

## Links

- npm: https://www.npmjs.com/package/yoga-layout-wasm
- Repository: https://github.com/pinqy520/yoga-layout-wasm
- Homepage: https://github.com/pinqy520/yoga-layout-wasm#readme
- Issues: https://github.com/pinqy520/yoga-layout-wasm/issues
- npm.io page: https://npm.io/package/yoga-layout-wasm

## Dependencies (1)

- [@types/yoga-layout](https://npm.io/package/@types/yoga-layout.md) ^1.9.2

## Recent versions

- 1.9.3-alpha.7 (latest) — 2020-05-30
- 1.9.3-alpha.6 — 2020-05-30
- 1.9.3-alpha.5 — 2020-05-30
- 1.9.3-alpha.4 — 2020-05-30
- 1.9.3-alpha.3 — 2020-05-30
- 1.9.3-alpha.2 — 2020-05-30
- 1.9.3-alpha.1 — 2020-05-30
- 1.9.3-alpha.0 — 2020-05-30
- 1.9.3-alpha — 2020-05-29

## README

# yoga-layout-wasm
> yoga-layout webassembly module, for browser and node. fallback to asm.js in non-webassembly environment

## Get Start

```
$ npm i yoga-layout-wasm --save
```

``` javascript
import Yoga from 'yoga-layout-wasm'

function test () {
  const Node = Yoga.Node
  const root = Node.create();
  root.setWidth(500);
  root.setHeight(300);
  root.setJustifyContent(Yoga.JUSTIFY_CENTER);
  
  const node1 = Node.create();
  node1.setWidth(100);
  node1.setHeight(100);
  
  const node2 = Node.create();
  node2.setWidth(100);
  node2.setHeight(100);
  
  root.insertChild(node1, 0);
  root.insertChild(node2, 1);
  
  root.calculateLayout(500, 300, yoga.DIRECTION_LTR);
  console.log(root.getComputedLayout());
  // {left: 0, top: 0, width: 500, height: 300}
  console.log(node1.getComputedLayout());
  // {left: 150, top: 0, width: 100, height: 100}
  console.log(node2.getComputedLayout());
  // {left: 250, top: 0, width: 100, height: 100}
}

const wasmFilePath = 'node_modules/yoga-layout-wasm/dist/yoga.wasm'

Yoga.init(wasmFilePath).then(test)
```

### Single `asm.js` module

``` javascript
// *.js
import Yoga from 'yoga-layout-wasm/asm'

Yoga.init().then(yoga => {
  // ... test()
})
```

### Webpack and Auto Fallback

``` javascript
// ... webpack.config.js
  {
    test: /\.(wasm)$/,
    type: 'javascript/auto',
    use: [
      {
        loader: 'file-loader',
        options: {
          name: '[path][name].[md5:hash:base64:6].[ext]',
        },
      },
    ],
  }
// ...
```

``` javascript
// *.js
  typeof WebAssembly === 'undefined' ?
    import('yoga-layout-wasm/asm')
      .then(mod => mod.default.init())
      .then(test) :
    import('yoga-layout-wasm')
      .then(mod => mod.default.init(require('yoga-layout-wasm/dist/yoga.wasm')))
      .then(test);
```

## Examples

```
$ npm run example:node
$ npm run example:html
$ npm run example:node:asm
```

---
_Source: https://npm.io/package/yoga-layout-wasm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
