Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"exports": {
"./package.json": "./package.json",
"./yoga.wasm": "./yoga.wasm",
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
Expand Down
16 changes: 10 additions & 6 deletions src/yoga.external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,29 @@ const yogaPromise: Promise<Yoga> = new Promise((resolve, reject) => {
})

export type InitInput =
| RequestInfo
| string
| Request
| URL
| Response
| BufferSource
| Buffer
| WebAssembly.Module
| Promise<Response | BufferSource | Buffer | WebAssembly.Module>

async function loadWasm(
input: InitInput,
imports: WebAssembly.Imports
): Promise<WebAssembly.WebAssemblyInstantiatedSource> {
let source: Response | BufferSource | Buffer | WebAssembly.Module = input
let source: Response | BufferSource | Buffer | WebAssembly.Module

if (
typeof source === 'string' ||
(typeof Request === 'function' && source instanceof Request) ||
(typeof URL === 'function' && source instanceof URL)
typeof input === 'string' ||
(typeof Request === 'function' && input instanceof Request) ||
(typeof URL === 'function' && input instanceof URL)
) {
source = await fetch(source)
source = await fetch(input)
} else {
source = await input
}

if (typeof Response === 'function' && source instanceof Response) {
Expand Down
2 changes: 1 addition & 1 deletion src/yoga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type Yoga } from 'yoga-layout/load'
import { type Node } from 'yoga-layout'
import { type InitInput } from './yoga.external.js'

export { Yoga as TYoga, Node as YogaNode }
export { Yoga as TYoga, Node as YogaNode, type InitInput }

export function init(input: InitInput) {
if (process.env.SATORI_STANDALONE === '1') {
Expand Down