Zero-dependency, auto-generated TypeScript definitions for ARToolKit5 constants.
This package provides a strict "Single Source of Truth" for the ARToolKit ecosystem. Instead of manually maintaining magic numbers in JavaScript, we extract values directly from the C++ source code using a WebAssembly extractor.
npm install @ar-js-org/artoolkit5-constantsThis library exports constants individually to support tree-shaking. You have two ways to use them depending on your preference.
Import only what you need. This allows bundlers (Webpack, Rollup, Vite) to remove unused code, keeping your application lightweight.
import {
AR_PIXEL_FORMAT_RGBA,
AR_MATRIX_CODE_DETECTION
} from '@ar-js-org/artoolkit5-constants';
// Example: Configuring ARController
const config = {
pixelFormat: AR_PIXEL_FORMAT_RGBA,
detectionMode: AR_MATRIX_CODE_DETECTION
};
if (config.pixelFormat === AR_PIXEL_FORMAT_RGBA) {
console.log("Using RGBA format");
}If you prefer accessing constants via a global object (similar to how Enums work or legacy ARToolKit structure), use the import * as syntax:
import * as AR from '@ar-js-org//artoolkit5-constants';
// Now you can access everything under 'AR'
console.log(AR.AR_LOG_LEVEL_ERROR); // Output: 3
console.log(AR.AR_TEMPLATE_MATCHING_MONO); // Output: 1
function setLogLevel(level: number) {
if (level === AR.AR_LOG_LEVEL_DEBUG) {
// enable debug tools
}
}This project uses a unique build pipeline to ensure accuracy:
- C++ Source: It links against the
WebARKitLibsubmodule. - Embind Extraction: A minimal C++ program exposes macros and enums via WebAssembly.
- Generation: A Node.js script loads the WASM, reads the values, and generates a static
.tsfile.
The generated constants are committed, and CI regenerates them and fails if the result differs from what is in the repository. A build therefore has to use the same toolchain CI does, or it produces a pull request that cannot pass.
npm run build:docker guarantees that. It builds inside the pinned Emscripten
image — the same one CI runs in — so nothing depends on what happens to be
installed locally:
git submodule update --init --recursive
npm install
npm run build:dockerDocker is the only requirement; the image supplies Emscripten, CMake and Node.
The Emscripten version lives in .emscripten-version and
is used in two places:
| Where | How |
|---|---|
npm run build:docker |
reads the file and uses it as the image tag |
.github/workflows/ci.yml |
container: tag, asserted against the file on every run |
CI cannot read the file to choose its container — container: is resolved
before the repository is checked out — so the tag is written out there as well.
The first CI step compares emcc --version against the file and fails if they
have drifted, which means the two must be changed together.
Possible, but you are responsible for matching the pinned version. You will need
Emscripten (exactly the version in
.emscripten-version), CMake, optionally
Ninja — the build falls back to Makefiles without it
— and Node.js 18+.
git submodule update --init --recursive
npm install
npm run build # configure -> extractor -> generate -> TypeScriptThe generated source file is written to src/generated/artoolkit_constants.ts.
This project is licensed under the GPLv3 License - see the LICENSE file for details.