@newkrok/nape-js 3.38.1 → 3.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- 'use strict';var i=3,a=3;function p(d){return `
1
+ 'use strict';var l=1,i=3,a=3;function p(d){return `
2
2
  /* nape-js physics worker \u2014 auto-generated, do not edit */
3
3
  const FLOATS_PER_BODY = 3;
4
4
  const HEADER_FLOATS = 3;
@@ -234,6 +234,6 @@ self.onmessage = async (e) => {
234
234
  }
235
235
  }
236
236
  };
237
- `}var l="https://cdn.jsdelivr.net/npm/@newkrok/nape-js/dist/index.js",y=class{constructor(e={}){this.worker=null;this.buffer=null;this.transforms=null;this.useShared=false;this.nextId=0;this.bodySlots=new Map;this.readyPromise=null;this.onFrame=null;this.destroyed=false;this.napeUrl=l;this.maxBodies=e.maxBodies??512,this.timestep=e.timestep??1/60,this.velocityIterations=e.velocityIterations??10,this.positionIterations=e.positionIterations??10,this.gravityX=e.gravityX??0,this.gravityY=e.gravityY??600,this.workerUrl=e.workerUrl,this.autoStep=e.autoStep??true;}init(){return this.readyPromise?this.readyPromise:(this.readyPromise=this.doInit(),this.readyPromise)}async doInit(){if(this.workerUrl)this.worker=new Worker(this.workerUrl,{type:"module"});else {let s=p(this.napeUrl),t=new Blob([s],{type:"application/javascript"}),r=URL.createObjectURL(t);this.worker=new Worker(r,{type:"module"}),URL.revokeObjectURL(r);}let e=(3+this.maxBodies*3)*Float32Array.BYTES_PER_ELEMENT;return typeof SharedArrayBuffer<"u"?(this.buffer=new SharedArrayBuffer(e),this.transforms=new Float32Array(this.buffer),this.useShared=true):(this.buffer=null,this.transforms=new Float32Array(3+this.maxBodies*3),this.useShared=false),this.worker.onmessage=s=>{let t=s.data;t.type==="frame"&&!this.useShared&&t.buffer?(this.transforms=t.buffer,this.onFrame?.(t.buffer)):t.type==="frame"&&this.useShared&&this.onFrame?.(this.transforms);},new Promise((s,t)=>{let r=o=>{o.data.type==="ready"?(this.worker.removeEventListener("message",r),s()):o.data.type==="error"&&(this.worker.removeEventListener("message",r),t(new Error(o.data.message)));};this.worker.addEventListener("message",r),this.worker.postMessage({type:"init",maxBodies:this.maxBodies,timestep:this.timestep,velocityIterations:this.velocityIterations,positionIterations:this.positionIterations,gravityX:this.gravityX,gravityY:this.gravityY,buffer:this.useShared?this.buffer:null});})}start(){this.post({type:"start"});}stop(){this.post({type:"stop"});}step(){this.post({type:"step"});}destroy(){this.destroyed||(this.destroyed=true,this.post({type:"destroy"}),this.worker?.terminate(),this.worker=null,this.transforms=null,this.buffer=null,this.bodySlots.clear());}addBody(e,s,t,r,o){let n=this.nextId++;return this.bodySlots.set(n,this.bodySlots.size),this.post({type:"addBody",id:n,bodyType:e,x:s,y:t,shapes:r,options:o}),n}removeBody(e){this.bodySlots.delete(e),this.post({type:"removeBody",id:e});}applyForce(e,s,t){this.post({type:"applyForce",id:e,fx:s,fy:t});}applyImpulse(e,s,t){this.post({type:"applyImpulse",id:e,ix:s,iy:t});}setVelocity(e,s,t){this.post({type:"setVelocity",id:e,vx:s,vy:t});}setPosition(e,s,t){this.post({type:"setPosition",id:e,x:s,y:t});}setGravity(e,s){this.post({type:"setGravity",gravityX:e,gravityY:s});}getTransform(e){let s=this.bodySlots.get(e);if(s===void 0||!this.transforms)return null;let t=3+s*3;return {x:this.transforms[t],y:this.transforms[t+1],rotation:this.transforms[t+2]}}readAllTransforms(e){if(this.transforms)for(let[s,t]of this.bodySlots){let r=3+t*3,o=e.get(s);o?(o.x=this.transforms[r],o.y=this.transforms[r+1],o.rotation=this.transforms[r+2]):e.set(s,{x:this.transforms[r],y:this.transforms[r+1],rotation:this.transforms[r+2]});}}get rawTransforms(){return this.transforms}get bodyCount(){return this.transforms?this.transforms[0]:0}get timestamp(){return this.transforms?this.transforms[1]:0}get stepTimeMs(){return this.transforms?this.transforms[2]:0}get isSharedBuffer(){return this.useShared}set onFrameCallback(e){this.onFrame=e;}post(e){this.worker?.postMessage(e);}};
238
- exports.FLOATS_PER_BODY=i;exports.HEADER_FLOATS=a;exports.PhysicsWorkerManager=y;exports.buildWorkerScript=p;//# sourceMappingURL=index.cjs.map
237
+ `}var m="https://cdn.jsdelivr.net/npm/@newkrok/nape-js/dist/index.js",y=class{constructor(e={}){this.worker=null;this.buffer=null;this.transforms=null;this.useShared=false;this.nextId=0;this.bodySlots=new Map;this.readyPromise=null;this.onFrame=null;this.destroyed=false;this.napeUrl=m;this.maxBodies=e.maxBodies??512,this.timestep=e.timestep??1/60,this.velocityIterations=e.velocityIterations??10,this.positionIterations=e.positionIterations??10,this.gravityX=e.gravityX??0,this.gravityY=e.gravityY??600,this.workerUrl=e.workerUrl,this.autoStep=e.autoStep??true;}init(){return this.readyPromise?this.readyPromise:(this.readyPromise=this.doInit(),this.readyPromise)}async doInit(){if(this.workerUrl)this.worker=new Worker(this.workerUrl,{type:"module"});else {let s=p(this.napeUrl),t=new Blob([s],{type:"application/javascript"}),r=URL.createObjectURL(t);this.worker=new Worker(r,{type:"module"}),URL.revokeObjectURL(r);}let e=(3+this.maxBodies*3)*Float32Array.BYTES_PER_ELEMENT;return typeof SharedArrayBuffer<"u"?(this.buffer=new SharedArrayBuffer(e),this.transforms=new Float32Array(this.buffer),this.useShared=true):(this.buffer=null,this.transforms=new Float32Array(3+this.maxBodies*3),this.useShared=false),this.worker.onmessage=s=>{let t=s.data;t.type==="frame"&&!this.useShared&&t.buffer?(this.transforms=t.buffer,this.onFrame?.(t.buffer)):t.type==="frame"&&this.useShared&&this.onFrame?.(this.transforms);},new Promise((s,t)=>{let r=o=>{o.data.type==="ready"?(this.worker.removeEventListener("message",r),s()):o.data.type==="error"&&(this.worker.removeEventListener("message",r),t(new Error(o.data.message)));};this.worker.addEventListener("message",r),this.worker.postMessage({type:"init",maxBodies:this.maxBodies,timestep:this.timestep,velocityIterations:this.velocityIterations,positionIterations:this.positionIterations,gravityX:this.gravityX,gravityY:this.gravityY,buffer:this.useShared?this.buffer:null});})}start(){this.post({type:"start"});}stop(){this.post({type:"stop"});}step(){this.post({type:"step"});}destroy(){this.destroyed||(this.destroyed=true,this.post({type:"destroy"}),this.worker?.terminate(),this.worker=null,this.transforms=null,this.buffer=null,this.bodySlots.clear());}addBody(e,s,t,r,o){let n=this.nextId++;return this.bodySlots.set(n,this.bodySlots.size),this.post({type:"addBody",id:n,bodyType:e,x:s,y:t,shapes:r,options:o}),n}removeBody(e){this.bodySlots.delete(e),this.post({type:"removeBody",id:e});}applyForce(e,s,t){this.post({type:"applyForce",id:e,fx:s,fy:t});}applyImpulse(e,s,t){this.post({type:"applyImpulse",id:e,ix:s,iy:t});}setVelocity(e,s,t){this.post({type:"setVelocity",id:e,vx:s,vy:t});}setPosition(e,s,t){this.post({type:"setPosition",id:e,x:s,y:t});}setGravity(e,s){this.post({type:"setGravity",gravityX:e,gravityY:s});}getTransform(e){let s=this.bodySlots.get(e);if(s===void 0||!this.transforms)return null;let t=3+s*3;return {x:this.transforms[t],y:this.transforms[t+1],rotation:this.transforms[t+2]}}readAllTransforms(e){if(this.transforms)for(let[s,t]of this.bodySlots){let r=3+t*3,o=e.get(s);o?(o.x=this.transforms[r],o.y=this.transforms[r+1],o.rotation=this.transforms[r+2]):e.set(s,{x:this.transforms[r],y:this.transforms[r+1],rotation:this.transforms[r+2]});}}get rawTransforms(){return this.transforms}get bodyCount(){return this.transforms?this.transforms[0]:0}get timestamp(){return this.transforms?this.transforms[1]:0}get stepTimeMs(){return this.transforms?this.transforms[2]:0}get isSharedBuffer(){return this.useShared}set onFrameCallback(e){this.onFrame=e;}post(e){this.worker?.postMessage(e);}};
238
+ exports.FLOATS_PER_BODY=i;exports.HEADER_FLOATS=a;exports.PROTOCOL_VERSION=l;exports.PhysicsWorkerManager=y;exports.buildWorkerScript=p;//# sourceMappingURL=index.cjs.map
239
239
  //# sourceMappingURL=index.cjs.map
@@ -9,6 +9,16 @@
9
9
  * (missing COOP/COEP headers) the worker posts a copy of the buffer each
10
10
  * tick via `postMessage`.
11
11
  */
12
+ /**
13
+ * Version of the transform-buffer wire layout.
14
+ *
15
+ * Bump this whenever the float layout changes ({@link FLOATS_PER_BODY},
16
+ * {@link HEADER_FLOATS}, or the meaning of any slot) so that a mismatch
17
+ * between a cached worker bundle and the main thread is caught loudly
18
+ * instead of decoding garbage transforms. Must be kept in lockstep with
19
+ * `TRANSFORM_PROTOCOL_VERSION` in `@newkrok/nape-pixi`'s `workerProtocol.ts`.
20
+ */
21
+ declare const PROTOCOL_VERSION = 1;
12
22
  /** Floats per body in the transform buffer: x, y, rotation. */
13
23
  declare const FLOATS_PER_BODY = 3;
14
24
  /**
@@ -218,4 +228,4 @@ declare class PhysicsWorkerManager {
218
228
  */
219
229
  declare function buildWorkerScript(napeUrl: string): string;
220
230
 
221
- export { type BodyOptions, type BodyTransform, type BoxDesc, type CircleDesc, FLOATS_PER_BODY, HEADER_FLOATS, PhysicsWorkerManager, type PhysicsWorkerOptions, type PolygonDesc, type ShapeDesc, buildWorkerScript };
231
+ export { type BodyOptions, type BodyTransform, type BoxDesc, type CircleDesc, FLOATS_PER_BODY, HEADER_FLOATS, PROTOCOL_VERSION, PhysicsWorkerManager, type PhysicsWorkerOptions, type PolygonDesc, type ShapeDesc, buildWorkerScript };
@@ -9,6 +9,16 @@
9
9
  * (missing COOP/COEP headers) the worker posts a copy of the buffer each
10
10
  * tick via `postMessage`.
11
11
  */
12
+ /**
13
+ * Version of the transform-buffer wire layout.
14
+ *
15
+ * Bump this whenever the float layout changes ({@link FLOATS_PER_BODY},
16
+ * {@link HEADER_FLOATS}, or the meaning of any slot) so that a mismatch
17
+ * between a cached worker bundle and the main thread is caught loudly
18
+ * instead of decoding garbage transforms. Must be kept in lockstep with
19
+ * `TRANSFORM_PROTOCOL_VERSION` in `@newkrok/nape-pixi`'s `workerProtocol.ts`.
20
+ */
21
+ declare const PROTOCOL_VERSION = 1;
12
22
  /** Floats per body in the transform buffer: x, y, rotation. */
13
23
  declare const FLOATS_PER_BODY = 3;
14
24
  /**
@@ -218,4 +228,4 @@ declare class PhysicsWorkerManager {
218
228
  */
219
229
  declare function buildWorkerScript(napeUrl: string): string;
220
230
 
221
- export { type BodyOptions, type BodyTransform, type BoxDesc, type CircleDesc, FLOATS_PER_BODY, HEADER_FLOATS, PhysicsWorkerManager, type PhysicsWorkerOptions, type PolygonDesc, type ShapeDesc, buildWorkerScript };
231
+ export { type BodyOptions, type BodyTransform, type BoxDesc, type CircleDesc, FLOATS_PER_BODY, HEADER_FLOATS, PROTOCOL_VERSION, PhysicsWorkerManager, type PhysicsWorkerOptions, type PolygonDesc, type ShapeDesc, buildWorkerScript };
@@ -1,4 +1,4 @@
1
- var i=3,a=3;function p(d){return `
1
+ var l=1,i=3,a=3;function p(d){return `
2
2
  /* nape-js physics worker \u2014 auto-generated, do not edit */
3
3
  const FLOATS_PER_BODY = 3;
4
4
  const HEADER_FLOATS = 3;
@@ -234,6 +234,6 @@ self.onmessage = async (e) => {
234
234
  }
235
235
  }
236
236
  };
237
- `}var l="https://cdn.jsdelivr.net/npm/@newkrok/nape-js/dist/index.js",y=class{constructor(e={}){this.worker=null;this.buffer=null;this.transforms=null;this.useShared=false;this.nextId=0;this.bodySlots=new Map;this.readyPromise=null;this.onFrame=null;this.destroyed=false;this.napeUrl=l;this.maxBodies=e.maxBodies??512,this.timestep=e.timestep??1/60,this.velocityIterations=e.velocityIterations??10,this.positionIterations=e.positionIterations??10,this.gravityX=e.gravityX??0,this.gravityY=e.gravityY??600,this.workerUrl=e.workerUrl,this.autoStep=e.autoStep??true;}init(){return this.readyPromise?this.readyPromise:(this.readyPromise=this.doInit(),this.readyPromise)}async doInit(){if(this.workerUrl)this.worker=new Worker(this.workerUrl,{type:"module"});else {let s=p(this.napeUrl),t=new Blob([s],{type:"application/javascript"}),r=URL.createObjectURL(t);this.worker=new Worker(r,{type:"module"}),URL.revokeObjectURL(r);}let e=(3+this.maxBodies*3)*Float32Array.BYTES_PER_ELEMENT;return typeof SharedArrayBuffer<"u"?(this.buffer=new SharedArrayBuffer(e),this.transforms=new Float32Array(this.buffer),this.useShared=true):(this.buffer=null,this.transforms=new Float32Array(3+this.maxBodies*3),this.useShared=false),this.worker.onmessage=s=>{let t=s.data;t.type==="frame"&&!this.useShared&&t.buffer?(this.transforms=t.buffer,this.onFrame?.(t.buffer)):t.type==="frame"&&this.useShared&&this.onFrame?.(this.transforms);},new Promise((s,t)=>{let r=o=>{o.data.type==="ready"?(this.worker.removeEventListener("message",r),s()):o.data.type==="error"&&(this.worker.removeEventListener("message",r),t(new Error(o.data.message)));};this.worker.addEventListener("message",r),this.worker.postMessage({type:"init",maxBodies:this.maxBodies,timestep:this.timestep,velocityIterations:this.velocityIterations,positionIterations:this.positionIterations,gravityX:this.gravityX,gravityY:this.gravityY,buffer:this.useShared?this.buffer:null});})}start(){this.post({type:"start"});}stop(){this.post({type:"stop"});}step(){this.post({type:"step"});}destroy(){this.destroyed||(this.destroyed=true,this.post({type:"destroy"}),this.worker?.terminate(),this.worker=null,this.transforms=null,this.buffer=null,this.bodySlots.clear());}addBody(e,s,t,r,o){let n=this.nextId++;return this.bodySlots.set(n,this.bodySlots.size),this.post({type:"addBody",id:n,bodyType:e,x:s,y:t,shapes:r,options:o}),n}removeBody(e){this.bodySlots.delete(e),this.post({type:"removeBody",id:e});}applyForce(e,s,t){this.post({type:"applyForce",id:e,fx:s,fy:t});}applyImpulse(e,s,t){this.post({type:"applyImpulse",id:e,ix:s,iy:t});}setVelocity(e,s,t){this.post({type:"setVelocity",id:e,vx:s,vy:t});}setPosition(e,s,t){this.post({type:"setPosition",id:e,x:s,y:t});}setGravity(e,s){this.post({type:"setGravity",gravityX:e,gravityY:s});}getTransform(e){let s=this.bodySlots.get(e);if(s===void 0||!this.transforms)return null;let t=3+s*3;return {x:this.transforms[t],y:this.transforms[t+1],rotation:this.transforms[t+2]}}readAllTransforms(e){if(this.transforms)for(let[s,t]of this.bodySlots){let r=3+t*3,o=e.get(s);o?(o.x=this.transforms[r],o.y=this.transforms[r+1],o.rotation=this.transforms[r+2]):e.set(s,{x:this.transforms[r],y:this.transforms[r+1],rotation:this.transforms[r+2]});}}get rawTransforms(){return this.transforms}get bodyCount(){return this.transforms?this.transforms[0]:0}get timestamp(){return this.transforms?this.transforms[1]:0}get stepTimeMs(){return this.transforms?this.transforms[2]:0}get isSharedBuffer(){return this.useShared}set onFrameCallback(e){this.onFrame=e;}post(e){this.worker?.postMessage(e);}};
238
- export{i as FLOATS_PER_BODY,a as HEADER_FLOATS,y as PhysicsWorkerManager,p as buildWorkerScript};//# sourceMappingURL=index.js.map
237
+ `}var m="https://cdn.jsdelivr.net/npm/@newkrok/nape-js/dist/index.js",y=class{constructor(e={}){this.worker=null;this.buffer=null;this.transforms=null;this.useShared=false;this.nextId=0;this.bodySlots=new Map;this.readyPromise=null;this.onFrame=null;this.destroyed=false;this.napeUrl=m;this.maxBodies=e.maxBodies??512,this.timestep=e.timestep??1/60,this.velocityIterations=e.velocityIterations??10,this.positionIterations=e.positionIterations??10,this.gravityX=e.gravityX??0,this.gravityY=e.gravityY??600,this.workerUrl=e.workerUrl,this.autoStep=e.autoStep??true;}init(){return this.readyPromise?this.readyPromise:(this.readyPromise=this.doInit(),this.readyPromise)}async doInit(){if(this.workerUrl)this.worker=new Worker(this.workerUrl,{type:"module"});else {let s=p(this.napeUrl),t=new Blob([s],{type:"application/javascript"}),r=URL.createObjectURL(t);this.worker=new Worker(r,{type:"module"}),URL.revokeObjectURL(r);}let e=(3+this.maxBodies*3)*Float32Array.BYTES_PER_ELEMENT;return typeof SharedArrayBuffer<"u"?(this.buffer=new SharedArrayBuffer(e),this.transforms=new Float32Array(this.buffer),this.useShared=true):(this.buffer=null,this.transforms=new Float32Array(3+this.maxBodies*3),this.useShared=false),this.worker.onmessage=s=>{let t=s.data;t.type==="frame"&&!this.useShared&&t.buffer?(this.transforms=t.buffer,this.onFrame?.(t.buffer)):t.type==="frame"&&this.useShared&&this.onFrame?.(this.transforms);},new Promise((s,t)=>{let r=o=>{o.data.type==="ready"?(this.worker.removeEventListener("message",r),s()):o.data.type==="error"&&(this.worker.removeEventListener("message",r),t(new Error(o.data.message)));};this.worker.addEventListener("message",r),this.worker.postMessage({type:"init",maxBodies:this.maxBodies,timestep:this.timestep,velocityIterations:this.velocityIterations,positionIterations:this.positionIterations,gravityX:this.gravityX,gravityY:this.gravityY,buffer:this.useShared?this.buffer:null});})}start(){this.post({type:"start"});}stop(){this.post({type:"stop"});}step(){this.post({type:"step"});}destroy(){this.destroyed||(this.destroyed=true,this.post({type:"destroy"}),this.worker?.terminate(),this.worker=null,this.transforms=null,this.buffer=null,this.bodySlots.clear());}addBody(e,s,t,r,o){let n=this.nextId++;return this.bodySlots.set(n,this.bodySlots.size),this.post({type:"addBody",id:n,bodyType:e,x:s,y:t,shapes:r,options:o}),n}removeBody(e){this.bodySlots.delete(e),this.post({type:"removeBody",id:e});}applyForce(e,s,t){this.post({type:"applyForce",id:e,fx:s,fy:t});}applyImpulse(e,s,t){this.post({type:"applyImpulse",id:e,ix:s,iy:t});}setVelocity(e,s,t){this.post({type:"setVelocity",id:e,vx:s,vy:t});}setPosition(e,s,t){this.post({type:"setPosition",id:e,x:s,y:t});}setGravity(e,s){this.post({type:"setGravity",gravityX:e,gravityY:s});}getTransform(e){let s=this.bodySlots.get(e);if(s===void 0||!this.transforms)return null;let t=3+s*3;return {x:this.transforms[t],y:this.transforms[t+1],rotation:this.transforms[t+2]}}readAllTransforms(e){if(this.transforms)for(let[s,t]of this.bodySlots){let r=3+t*3,o=e.get(s);o?(o.x=this.transforms[r],o.y=this.transforms[r+1],o.rotation=this.transforms[r+2]):e.set(s,{x:this.transforms[r],y:this.transforms[r+1],rotation:this.transforms[r+2]});}}get rawTransforms(){return this.transforms}get bodyCount(){return this.transforms?this.transforms[0]:0}get timestamp(){return this.transforms?this.transforms[1]:0}get stepTimeMs(){return this.transforms?this.transforms[2]:0}get isSharedBuffer(){return this.useShared}set onFrameCallback(e){this.onFrame=e;}post(e){this.worker?.postMessage(e);}};
238
+ export{i as FLOATS_PER_BODY,a as HEADER_FLOATS,l as PROTOCOL_VERSION,y as PhysicsWorkerManager,p as buildWorkerScript};//# sourceMappingURL=index.js.map
239
239
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newkrok/nape-js",
3
- "version": "3.38.1",
3
+ "version": "3.39.1",
4
4
  "description": "High-performance 2D physics engine for TypeScript & JavaScript — rigid bodies, constraints, fluid simulation, raycasting, and deterministic multiplayer. Tree-shakeable, zero dependencies.",
5
5
  "type": "module",
6
6
  "sideEffects": [