# JFVR module interfaces (contract) Everything lives under a single global namespace `window.__JFVR`, created by `src/00-core.js` before any other module runs. Modules are plain `(function(){ ... })()` IIFEs that attach themselves to `__JFVR`. Load order (build script concatenates in this order): ``` 00-core.js -> __JFVR core: state, helpers, layer/frame-hook registry 10-subtitles.js -> __JFVR.Subtitles 20-controls.js -> __JFVR.Controls 90-main.js -> boot, DOM scan, XR session lifecycle, settings panel, wiring ``` Nothing may read `document` / `navigator.xr` at load time except `00-core.js` and `90-main.js`. The two module files must only *define* functions and are called later with a session/frame. --- ## 00-core.js — always available as `window.__JFVR` ```js __JFVR.state // shared mutable state object (see below) __JFVR.log(...args) // console.log with [JFVR] prefix + colour __JFVR.version // string // --- helpers --- __JFVR.makeEl(tag, className?, text?) // document.createElement wrapper __JFVR.compileShader(gl, type, source) // throws with the info log on failure __JFVR.invert4(mat4ArrayLike) // -> Float32Array(16) __JFVR.QUAD_VS // vertex shader source: fullscreen triangle, // `in vec2 aPos; out vec2 vUv;` // vUv = vec2(aPos.x*.5+.5, .5 - aPos.y*.5) __JFVR.bindFullscreenTriangle(gl, program) // creates the VBO, enables aPos, returns attribLoc // --- XR layer registry (owned by 90-main.js) --- __JFVR.addLayer(layer) // register + push updateRenderState if a session is live __JFVR.removeLayer(layer) // unregister + push __JFVR.addFrameHook(fn) // fn(frame, time, session) every XR frame __JFVR.removeFrameHook(fn) // --- capabilities (filled by 00-core.js at boot) --- __JFVR.caps = { secureContext, hasXR, immersiveVR, hasXRMediaBinding, hasEquirectLayer, hasXRWebGLBinding, hasXRHand, hasXRJointSpace, maxTextureSize, hevc: { ... }, ua } // --- live handles --- __JFVR.session // current XRSession or null __JFVR.video // current