diff --git a/CHANGELOG.md b/CHANGELOG.md
index b652718..bc720bb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,54 @@
See https://github.com/Birch-san/box2d-wasm/releases
+# v6.0.1
+
+Added a mechanism to the 'browser global' loader in the UMD entrypoint that enables you to specify the directory from which you serve Box2D.js, via the `data-box2d-dir` attribute on its `
+```
+
+This tells `entry.js` that `Box2D.js` can be found at `Box2D/Box2D.js`.
+
+# v6.0.0
+
+Simplified (i.e. flattened) directory structure introduced in v5.0.0, to make it easier to import the library and serve deferred assets.
+
+Inlined SIMD feature detection, eliminating dependency on `wasm-feature-detect`. This simplifies the entrypoints (fewer files to locate and load in).
+
+Eliminated "ES explicit" entrypoint (now that we are zero-dependency again, we no longer need to cater for differences in ES module resolution).
+
+Simplified UMD entrypoint by writing bespoke loaders for each of CommonJS, AMD and Browser globals.
+
+Tested AMD entrypoint and confirmed working. Can be used by serving a folder with the following assets:
+
+```
+entry.js
+Box2D.js
+Box2D.wasm
+Box2D.simd.js
+Box2D.simd.wasm
+index.html
+main.js
+require.js
+```
+
+```html
+
+
+```
+
+```js
+// main.js
+// import Box2D's umd/entry.js
+requirejs(['./entry.js'], function (Box2DFactory) {
+ (async () => {
+ const box2D = await Box2DFactory();
+ console.log(box2D);
+ })();
+});
+```
+
# v5.0.3
Updated from Emscripten `2.0.17`->`2.0.26`.
diff --git a/box2d-wasm/dist/umd/entry.js b/box2d-wasm/dist/umd/entry.js
index 03844b1..5154f9e 100644
--- a/box2d-wasm/dist/umd/entry.js
+++ b/box2d-wasm/dist/umd/entry.js
@@ -23,6 +23,7 @@
define([asset], module => module);
} else if (typeof module === 'object' && module.exports) {
// NodeJS
+ /** @type {import('box2d-wasm')} */
module.exports = require(asset);
} else {
// Browser globals (root is window)
@@ -30,20 +31,25 @@
const dirAttr = 'data-box2d-dir';
const hasDirAttribute = Array.from(scripts).find(script => script.hasAttribute(dirAttr));
const box2DDir = hasDirAttribute?.getAttribute(dirAttr) ?? '.';
- const loadModule = (path) => new Promise((resolve, reject) => {
+ const loadModule = (path, moduleName) => new Promise((resolve, reject) => {
const tag = root.document.createElement("script");
tag.onload = () => {
- resolve(root.Box2D);
+ resolve(root[moduleName]);
return false;
};
tag.onerror = ({ target: { src } }) => {
- reject(new Error(`Failed to load '${src}'`));
+ reject(new Error(`Failed to load '${src}'. Check your browser console for network errors.`));
return false;
};
tag.src = path;
root.document.getElementsByTagName("head")[0].appendChild(tag);
});
- const modulePromise = loadModule(`${box2DDir}/${asset}`);
+ /** @type {Promise} */
+ const modulePromise = loadModule(`${box2DDir}/${asset}`, 'Box2D');
+ /**
+ * @param {Parameters} args
+ * @return {ReturnType}
+ */
root.Box2D = async (...args) => {
const Box2DFactory = await modulePromise;
// awaiting gives us a better stack trace (at the cost of an extra microtask)
diff --git a/box2d-wasm/package.json b/box2d-wasm/package.json
index c4ba1d2..a1e1c74 100644
--- a/box2d-wasm/package.json
+++ b/box2d-wasm/package.json
@@ -1,6 +1,6 @@
{
"name": "box2d-wasm",
- "version": "6.0.0",
+ "version": "6.0.1",
"description": "Box2D compiled to WebAssembly",
"module": "dist/es/entry.js",
"main": "dist/umd/entry.js",