diff --git a/javascript/README.md b/javascript/README.md index 73a95462..da4fe27f 100644 --- a/javascript/README.md +++ b/javascript/README.md @@ -29,3 +29,12 @@ node.free(); ## Requirements `yoga-layout` requires a toolchain that supports ES Modules and top-level await. + +If top-level-await is not supported, use the `yoga-layout/load` entry point instead. This requires to load yoga manually: + +```ts +import {loadYoga, Align} from 'yoga-layout/load'; + +const node = (await loadYoga).Node.create(); +node.setAlignContent(Align.Center); +``` diff --git a/javascript/package.json b/javascript/package.json index c06b6a20..42aab81e 100644 --- a/javascript/package.json +++ b/javascript/package.json @@ -11,6 +11,10 @@ }, "type": "module", "main": "./src/index.ts", + "exports": { + ".": "./src/index.ts", + "./load": "./src/load.ts" + }, "files": [ "binaries/**", "src/**" diff --git a/javascript/src/load.ts b/javascript/src/load.ts new file mode 100644 index 00000000..a415a0dd --- /dev/null +++ b/javascript/src/load.ts @@ -0,0 +1,25 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +// @ts-ignore untyped from Emscripten +import loadYogaImpl from '../binaries/yoga-wasm-base64-esm.js'; +import wrapAssembly from './wrapAssembly.ts'; + +export type { + Config, + DirtiedFunction, + MeasureFunction, + Node, + Yoga, +} from './wrapAssembly.ts'; + +export async function loadYoga() { + return wrapAssembly(await loadYogaImpl()); +} +export * from './generated/YGEnums.ts';