/* ────────────────────────────────────────────────────────────────
   EPIC E2 — AR/VR Support
   
   WebXR integration, VR templates, AR placement, hand tracking,
   spatial UI, 360° video
──────────────────────────────────────────────────────────────── */
const VR_SESSION_DEFAULT = {
    mode: 'immersive-vr',
    referenceSpace: 'local-floor',
    requiredFeatures: ['local-floor'],
    optionalFeatures: ['hand-tracking', 'bounded-floor'],
    frameRate: 72,
    handTracking: true,
};
const AR_SESSION_DEFAULT = {
    mode: 'immersive-ar',
    referenceSpace: 'local-floor',
    requiredFeatures: ['local-floor', 'hit-test'],
    optionalFeatures: ['anchors', 'light-estimation', 'depth-sensing', 'hand-tracking'],
    depthSensing: true,
    hitTest: true,
    anchors: true,
    lightEstimation: true,
};
async function detectXRCapabilities() {
    const nav = typeof navigator !== 'undefined' ? navigator : null;
    const xr = nav && 'xr' in nav ? nav.xr : null;
    if (!xr) {
        return { vrSupported: false, arSupported: false, handTrackingSupported: false, depthSensingSupported: false, hitTestSupported: false };
    }
    const [vr, ar] = await Promise.all([
        xr.isSessionSupported('immersive-vr').catch(() => false),
        xr.isSessionSupported('immersive-ar').catch(() => false),
    ]);
    return {
        vrSupported: vr,
        arSupported: ar,
        handTrackingSupported: false, // Checked during session
        depthSensingSupported: false,
        hitTestSupported: ar, // Hit-test generally available with AR
    };
}
const STANDARD_CONTROLLER_MAPPING = {
    trigger: 0,
    grip: 1,
    thumbstick: 2,
    trackpad: 2,
    buttonA: 4,
    buttonB: 5,
    thumbstickPress: 3,
};
function createPinchGesture(threshold = 0.02) {
    return {
        name: 'pinch',
        detect(joints) {
            const thumb = joints.get('thumb-tip');
            const index = joints.get('index-finger-tip');
            if (!thumb || !index)
                return false;
            const dx = thumb.position.x - index.position.x;
            const dy = thumb.position.y - index.position.y;
            const dz = thumb.position.z - index.position.z;
            return Math.sqrt(dx * dx + dy * dy + dz * dz) < threshold;
        },
    };
}
function createGrabGesture(curlThreshold = 0.04) {
    const tips = ['index-finger-tip', 'middle-finger-tip', 'ring-finger-tip', 'pinky-finger-tip'];
    const metas = ['index-finger-metacarpal', 'middle-finger-metacarpal', 'ring-finger-metacarpal', 'pinky-finger-metacarpal'];
    return {
        name: 'grab',
        detect(joints) {
            const wrist = joints.get('wrist');
            if (!wrist)
                return false;
            for (let i = 0; i < tips.length; i++) {
                const tip = joints.get(tips[i]);
                const meta = joints.get(metas[i]);
                if (!tip || !meta)
                    return false;
                const dx = tip.position.x - meta.position.x;
                const dy = tip.position.y - meta.position.y;
                const dz = tip.position.z - meta.position.z;
                if (Math.sqrt(dx * dx + dy * dy + dz * dz) > curlThreshold)
                    return false;
            }
            return true;
        },
    };
}
const DEFAULT_AR_PLACEMENT = {
    snapToSurface: true,
    alignToNormal: true,
    gridSnap: 0,
    minScale: 0.1,
    maxScale: 10,
    defaultScale: 1,
    allowRotation: true,
    rotationSnapDeg: 0,
    allowVertical: false,
    shadowEnabled: true,
};
function snapPlacement(hit, config, currentRotationY) {
    let { x, y, z } = hit.position;
    if (config.gridSnap > 0) {
        x = Math.round(x / config.gridSnap) * config.gridSnap;
        z = Math.round(z / config.gridSnap) * config.gridSnap;
    }
    let rotY = currentRotationY;
    if (config.rotationSnapDeg > 0) {
        const snap = (config.rotationSnapDeg * Math.PI) / 180;
        rotY = Math.round(rotY / snap) * snap;
    }
    return { position: { x, y, z }, rotationY: rotY };
}
function createSpatialPanel(id, partial) {
    return {
        id,
        width: 0.4,
        height: 0.3,
        pixelsPerMeter: 1000,
        position: { x: 0, y: 1.5, z: -1 },
        orientation: { x: 0, y: 0, z: 0, w: 1 },
        followGaze: false,
        curved: false,
        opacity: 1,
        interactable: true,
        grabbable: true,
        ...partial,
    };
}
/** Billboard: rotate panel to face camera. */
function billboardToward(panelPos, cameraPos) {
    const dx = cameraPos.x - panelPos.x;
    const dz = cameraPos.z - panelPos.z;
    const angle = Math.atan2(dx, dz);
    const halfAngle = angle / 2;
    return { x: 0, y: Math.sin(halfAngle), z: 0, w: Math.cos(halfAngle) };
}
const DEFAULT_PANO_CONFIG = {
    projection: 'equirectangular',
    stereo: 'mono',
    loop: true,
    autoplay: false,
    muted: false,
    fov: 100,
    initialYaw: 0,
    initialPitch: 0,
    dragSensitivity: 0.3,
    gyroscope: true,
};
const DEFAULT_VR_COMFORT = {
    vignette: true,
    vignetteIntensity: 0.5,
    snapTurning: true,
    snapAngleDeg: 45,
    smoothTurnSpeed: 90,
    heightAdjustment: true,
    motionSicknessLevel: 'medium',
};
const DEFAULT_VR_TELEPORT = {
    maxDistance: 10,
    arcResolution: 30,
    validColor: '#00ff88',
    invalidColor: '#ff4444',
    hapticOnTeleport: true,
    fadeTransition: true,
    fadeDurationMs: 150,
};
const DEFAULT_VR_INTERACTION = {
    grabDistance: 0.12,
    throwMultiplier: 1.5,
    hapticIntensity: 0.5,
    hapticDurationMs: 50,
    highlightColor: '#ffffff',
    laserPointer: true,
    laserColor: '#4488ff',
    laserWidth: 0.003,
};

export { AR_SESSION_DEFAULT, DEFAULT_AR_PLACEMENT, DEFAULT_PANO_CONFIG, DEFAULT_VR_COMFORT, DEFAULT_VR_INTERACTION, DEFAULT_VR_TELEPORT, STANDARD_CONTROLLER_MAPPING, VR_SESSION_DEFAULT, billboardToward, createGrabGesture, createPinchGesture, createSpatialPanel, detectXRCapabilities, snapPlacement };
//# sourceMappingURL=ARVR.js.map
