Skip to content

Commit e54ec82

Browse files
authored
Configure Vite for ESM-only build, vitest and update dependencies (#6)
* feat(build): configure Vite for ESM-only build and update dependencies * fix(worker): correct ARController export extraction logic * feat(plugin): improve worker readiness handling and fallback logic * feat(build): set relative asset URLs and simplify asset file naming in Vite config * feat(tests): add unit tests for ArtoolkitPlugin and configure coverage reporting * feat(tests): add extra coverage tests for ArtoolkitPlugin and update coverage configuration * feat(ci): add CI configuration and coverage tests for ArtoolkitPlugin * feat(docs): update README and index.html for ESM module usage and paths * chore: include dist build output * feat(plugin): normalize detection updates and emit markerFound/Updated events
1 parent 75527aa commit e54ec82

21 files changed

+6140
-244
lines changed

.github/workflows/build.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
build-and-test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version-file: .nvmrc
22+
cache: npm
23+
24+
- name: Install
25+
run: npm ci
26+
27+
- name: Build
28+
run: npm run build
29+
30+
- name: Test with coverage
31+
run: npm run coverage

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ out
8080

8181
# Nuxt.js build / generate output
8282
.nuxt
83-
dist
83+
84+
# Generic dist directories (ignored everywhere)…
85+
**/dist
86+
# …but keep the repository root /dist tracked (for built ESM + worker assets)
87+
!/dist
88+
!/dist/**
8489

8590
# Gatsby files
8691
.cache/
@@ -139,4 +144,4 @@ vite.config.js.timestamp-*
139144
vite.config.ts.timestamp-*
140145

141146
# jetbrains IDEs files
142-
.idea/
147+
.idea/

README.md

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ ARToolKit marker detection plugin for AR.js core with WebAssembly support.
44

55
## Features
66

7-
- Web Worker-based detection — marker detection runs off the main thread
7+
- Web Worker-based detection — marker detection runs off the main thread (Browser Module Worker)
88
- ImageBitmap support — zero-copy frame transfer (browser)
9-
- Cross-platform — browser Workers and Node.js worker_threads (stub path)
109
- ARToolKit integration — square pattern markers
1110
- Event-driven API — marker found/updated/lost + raw getMarker forwarding
1211
- Filtering — only forwards PATTERN_MARKER events above a minimum confidence
@@ -17,26 +16,53 @@ ARToolKit marker detection plugin for AR.js core with WebAssembly support.
1716
npm install @ar-js-org/arjs-plugin-artoolkit
1817
```
1918

20-
## Configuration (module + assets)
19+
## Using the ESM build (recommended)
2120

22-
To ensure the Worker can import ARToolKit in the browser, pass an explicit ESM URL (recommended):
21+
When you import the built ESM bundle from `dist/`, the worker and ARToolKit are already bundled and referenced correctly. You do NOT need to pass `artoolkitModuleUrl`.
22+
23+
Example:
24+
25+
```html
26+
<script type="module">
27+
import { ArtoolkitPlugin } from '/dist/arjs-plugin-artoolkit.esm.js';
28+
29+
const engine = { eventBus: /* your event bus */ };
30+
31+
const plugin = new ArtoolkitPlugin({
32+
worker: true,
33+
cameraParametersUrl: '/path/to/camera_para.dat',
34+
minConfidence: 0.6
35+
});
36+
37+
await plugin.init(engine);
38+
await plugin.enable();
39+
</script>
40+
```
41+
42+
Serving notes:
43+
- Serve from a web server so `/dist` assets resolve. The build is configured with `base: './'`, so the worker asset is referenced relative to the ESM file (e.g., `/dist/assets/worker-*.js`).
44+
- In your own apps, place `dist/` where you serve static assets and import the ESM with the appropriate path (absolute or relative).
45+
46+
## Using source (development mode)
47+
48+
If you develop against `src/` (not the built `dist/`), the worker will attempt to dynamically import ARToolKit. In that case you should provide `artoolkitModuleUrl` or ensure your dev server can resolve `@ar-js-org/artoolkit5-js`.
2349

2450
```js
2551
const plugin = new ArtoolkitPlugin({
2652
worker: true,
27-
artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js', // explicit ESM
28-
cameraParametersUrl: '/path/to/camera_para.dat', // optional override
29-
wasmBaseUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/', // optional; if your build needs it
30-
minConfidence: 0.6 // forward only confident detections
53+
artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js', // provide when using src/
54+
cameraParametersUrl: '/path/to/camera_para.dat',
55+
wasmBaseUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/', // optional; if your build requires it
56+
minConfidence: 0.6
3157
});
3258
```
3359

34-
CDN fallback (if you don’t serve node_modules):
35-
- Set `artoolkitModuleUrl` to a CDN ESM endpoint, e.g. a jsDelivr/UNPKG URL for the package’s ESM bundle.
60+
CDN fallback (for source/dev):
61+
- Set `artoolkitModuleUrl` to a CDN ESM endpoint (e.g., jsDelivr/UNPKG) for `@ar-js-org/artoolkit5-js`.
3662

3763
Notes:
3864
- The previous “loader.js” and manual WASM placement flow is no longer used.
39-
- If your ARToolKit build fetches auxiliary assets (WASM, data), set `wasmBaseUrl` accordingly.
65+
- In the `dist/` build, ARToolKit is bundled and `artoolkitModuleUrl` is NOT needed.
4066

4167
## Usage
4268

@@ -49,7 +75,7 @@ const plugin = new ArtoolkitPlugin({
4975
worker: true,
5076
lostThreshold: 5, // frames before a marker is considered lost
5177
frameDurationMs: 100, // expected ms per frame (affects lost timing)
52-
artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js',
78+
// artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js', // Only for src/dev
5379
cameraParametersUrl: '/data/camera_para.dat',
5480
minConfidence: 0.6
5581
});
@@ -114,7 +140,7 @@ const { markerId, size } = await plugin.loadMarker('/examples/simple-marker/data
114140

115141
A complete webcam-based example is available under `examples/simple-marker/`.
116142

117-
Serve from the repository root so that ES modules and node_modules paths resolve:
143+
Serve from the repository root so that `dist/` and example paths resolve:
118144

119145
```bash
120146
# From repository root
@@ -142,9 +168,9 @@ The example demonstrates:
142168
lostThreshold?: number; // Frames before 'lost' (default: 5)
143169
frameDurationMs?: number; // ms per frame (default: 200)
144170
sweepIntervalMs?: number; // Lost-sweep interval (default: 100)
145-
artoolkitModuleUrl?: string; // ESM URL for ARToolKit (recommended)
171+
artoolkitModuleUrl?: string; // Only needed when using source/dev; NOT needed for dist build
146172
cameraParametersUrl?: string;// Camera params file URL
147-
wasmBaseUrl?: string; // Base URL for ARToolKit assets (if required)
173+
wasmBaseUrl?: string; // Base URL for ARToolKit assets (if required by your build)
148174
minConfidence?: number; // Minimum confidence to forward getMarker (default: 0.6)
149175
}
150176
```
@@ -160,7 +186,10 @@ The example demonstrates:
160186

161187
## Troubleshooting
162188

163-
- “Failed to resolve module specifier” in the Worker:
189+
- Worker asset 404:
190+
- Ensure you import the ESM from `/dist/arjs-plugin-artoolkit.esm.js` and that `/dist/assets/worker-*.js` is served.
191+
- The build uses `base: './'`, so worker URLs are relative to the ESM file location.
192+
- “Failed to resolve module specifier” in the Worker (source/dev only):
164193
- Provide `artoolkitModuleUrl` or serve `/node_modules` from your dev server
165194
- Worker not starting:
166195
- Serve via HTTP/HTTPS; ensure ES modules and Workers are supported

dist/arjs-plugin-artoolkit.esm.js

Lines changed: 187 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/arjs-plugin-artoolkit.esm.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)