Skip to content

Commit

Permalink
Improved typescript bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSom committed Dec 31, 2023
1 parent 77e8e35 commit 09f7eb6
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 312 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ https://github.com/ErikSom/Clipper2-WASM/tree/main/CPP/clipper2-wasm/examples/um

## Typescript example:
```javascript
import { MainModule } from 'clipper2-wasm';
import { Clipper2ZFactoryFunction, MainModule } from 'clipper2-wasm';
import * as _Clipper2ZFactory from 'clipper2-wasm/dist/umd/clipper2z';

const Clipper2ZFactory = _Clipper2ZFactory as any;
const Clipper2ZFactory: Clipper2ZFactoryFunction = _Clipper2ZFactory;

Clipper2ZFactory({
locateFile: () => {
return './clipper2z.wasm'
return 'path/to/your/clipper2z.wasm'
},
}).then((Clipper2Z: MainModule) => {
console.log('Clipper2Z', Clipper2Z);
});
})
```

## Benchmark vs Clipper1 WASM: (Apple M2 Pro)
Expand Down
8 changes: 4 additions & 4 deletions clipper2-wasm/compile-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ fi

# build ES6
echo "Building ES6"
em++ $FLAGS -s EXPORT_ES6=1 -s NO_FILESYSTEM=1 -s ENVIRONMENT='web' -s clipper2-wasm/clipper.bindings.cpp clipper2/CPP/build/libClipper2Z.a -o clipper2-wasm/dist/es/clipper2z.js -s EXPORT_NAME="Clipper2Z" --post-js clipper2-wasm/glue-stub-z.js --embind-emit-tsd clipper2z.d.ts
em++ $FLAGS -s EXPORT_ES6=1 -s NO_FILESYSTEM=1 -s ENVIRONMENT='web' -s clipper2-wasm/clipper.bindings.cpp clipper2/CPP/build/libClipper2Z.a -o clipper2-wasm/dist/es/clipper2z.js -s EXPORT_NAME="Clipper2Z" --post-js clipper2-wasm/glue-stub-z.js --embind-emit-tsd ../clipper2z-main.d.ts

# build Tools ES6
em++ $FLAGS -Iclipper2/CPP/Utils -s EXPORT_ES6=1 -s ENVIRONMENT='web' -s clipper2-wasm/clipper-tools.bindings.cpp clipper2/CPP/build/libClipper2Zutils.a clipper2/CPP/build/libClipper2Z.a -o clipper2-wasm/dist/es/clipper2z-utils.js -s EXPORT_NAME="Clipper2ZUtils" -s EXPORTED_FUNCTIONS=[FS] --post-js clipper2-wasm/glue-stub-tools-z.js --embind-emit-tsd clipper2z-utils.d.ts
em++ $FLAGS -Iclipper2/CPP/Utils -s EXPORT_ES6=1 -s ENVIRONMENT='web' -s clipper2-wasm/clipper-tools.bindings.cpp clipper2/CPP/build/libClipper2Zutils.a clipper2/CPP/build/libClipper2Z.a -o clipper2-wasm/dist/es/clipper2z-utils.js -s EXPORT_NAME="Clipper2ZUtils" -s EXPORTED_FUNCTIONS=[FS] --post-js clipper2-wasm/glue-stub-tools-z.js --embind-emit-tsd ../clipper2z-utils-main.d.ts

# build UMD
echo "Building UMD"
em++ $FLAGS -s NO_FILESYSTEM=1 clipper2-wasm/clipper.bindings.cpp clipper2/CPP/build/libClipper2Z.a -o clipper2-wasm/dist/umd/clipper2z.js -s ENVIRONMENT='web' -s EXPORT_NAME="Clipper2ZFactory" --post-js clipper2-wasm/glue-stub-z.js --embind-emit-tsd clipper2z.d.ts
em++ $FLAGS -s NO_FILESYSTEM=1 clipper2-wasm/clipper.bindings.cpp clipper2/CPP/build/libClipper2Z.a -o clipper2-wasm/dist/umd/clipper2z.js -s ENVIRONMENT='web' -s EXPORT_NAME="Clipper2ZFactory" --post-js clipper2-wasm/glue-stub-z.js

# build Tools UMD
em++ $FLAGS -Iclipper2/CPP/Utils clipper2-wasm/clipper-tools.bindings.cpp clipper2/CPP/build/libClipper2Zutils.a clipper2/CPP/build/libClipper2Z.a -o clipper2-wasm/dist/umd/clipper2z-utils.js -s ENVIRONMENT='web' -s EXPORT_NAME="Clipper2ZUtilsFactory" -s EXPORTED_FUNCTIONS=[FS] --post-js clipper2-wasm/glue-stub-tools-z.js --embind-emit-tsd clipper2z-utils.d.ts
em++ $FLAGS -Iclipper2/CPP/Utils clipper2-wasm/clipper-tools.bindings.cpp clipper2/CPP/build/libClipper2Zutils.a clipper2/CPP/build/libClipper2Z.a -o clipper2-wasm/dist/umd/clipper2z-utils.js -s ENVIRONMENT='web' -s EXPORT_NAME="Clipper2ZUtilsFactory" -s EXPORTED_FUNCTIONS=[FS] --post-js clipper2-wasm/glue-stub-tools-z.js
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions clipper2-wasm/dist/clipper2z-utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { MainModule } from './clipper2z-utils-main';

export interface Clipper2ZUtilsFactoryFunction {
(config: { locateFile: () => string }): Promise<MainModule>;
}
5 changes: 5 additions & 0 deletions clipper2-wasm/dist/clipper2z.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { MainModule } from './clipper2z-main';

export interface Clipper2ZFactoryFunction {
(config: { locateFile: () => string }): Promise<MainModule>;
}
61 changes: 0 additions & 61 deletions clipper2-wasm/dist/umd/clipper2z-utils.d.ts

This file was deleted.

242 changes: 0 additions & 242 deletions clipper2-wasm/dist/umd/clipper2z.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion clipper2-wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clipper2-wasm",
"version": "0.0.7",
"version": "0.0.8",
"description": "WebAssembly port of the Clipper2 library for polygon clipping and offsetting",
"module": "dist/es/clipper2z.js",
"main": "dist/umd/clipper2z.js",
Expand Down

0 comments on commit 09f7eb6

Please sign in to comment.