{"version":3,"file":"useKeyboardLock-CW9BhNeE.js","sources":["../../../app/javascript/composables/useKeyboardLock.js"],"sourcesContent":["import { createGlobalState, tryOnScopeDispose } from \"@vueuse/core\"\nimport { computed, reactive } from \"vue\"\n\nconst useKeyboardLockState = createGlobalState(() => {\n // Use reactive for the Map to ensure reactivity\n const state = reactive({\n // Map of key -> number of components requesting lock\n lockedKeys: new Map(),\n // Currently active locks in the browser\n activeLocks: new Set(),\n })\n\n return {\n state,\n }\n})\n\nexport { useKeyboardLockState }\n\nexport function useKeyboardLock() {\n const { state } = useKeyboardLockState()\n\n /**\n * Request a lock for specific keys\n * @param {string[]} keys - Array of keys to lock\n * @returns {Promise}\n */\n const lockKeys = async (keys) => {\n // Update lock count for each key\n keys.forEach(key => {\n const count = state.lockedKeys.get(key) || 0\n state.lockedKeys.set(key, count + 1)\n })\n\n // Get all keys that have at least one lock request\n const keysToLock = Array.from(state.lockedKeys.entries())\n .filter(([_, count]) => count > 0) //eslint-disable-line no-unused-vars\n .map(([key]) => key)\n\n if (keysToLock.length > 0 && navigator.keyboard?.lock) {\n try {\n await navigator.keyboard.lock(keysToLock)\n state.activeLocks = new Set(keysToLock)\n } catch (error) {\n console.warn(\"Could not lock keyboard:\", error)\n }\n }\n }\n\n /**\n * Release lock for specific keys\n * @param {string[]} keys - Array of keys to unlock\n */\n const unlockKeys = (keys) => {\n // Update lock count for each key\n keys.forEach(key => {\n const count = state.lockedKeys.get(key) || 0\n if (count <= 1) {\n state.lockedKeys.delete(key)\n } else {\n state.lockedKeys.set(key, count - 1)\n }\n })\n\n // If no more locks are requested, unlock keyboard\n if (state.lockedKeys.size === 0 && navigator.keyboard?.unlock) {\n navigator.keyboard.unlock()\n state.activeLocks.clear()\n } else if (navigator.keyboard?.lock) {\n // Update locks with remaining locked keys\n const remainingKeys = Array.from(state.lockedKeys.keys())\n navigator.keyboard.lock(remainingKeys)\n .then(() => {\n state.activeLocks = new Set(remainingKeys)\n })\n .catch(error => console.warn(\"Could not update keyboard lock:\", error))\n }\n }\n\n // Computed properties for checking lock status\n const isLocked = computed(() => state.activeLocks.size > 0)\n const getKeyLockCount = (key) => state.lockedKeys.get(key) || 0\n const isKeyLocked = (key) => state.activeLocks.has(key)\n\n // Cleanup on component unmount\n tryOnScopeDispose(() => {\n // Only unlock keys that this component locked\n if (state.lockedKeys.size > 0) {\n unlockKeys(Array.from(state.lockedKeys.keys()))\n }\n })\n\n return {\n lockKeys,\n unlockKeys,\n isLocked,\n getKeyLockCount,\n isKeyLocked,\n state,\n }\n}\n"],"names":["useKeyboardLockState","createGlobalState","reactive","useKeyboardLock","state","lockKeys","keys","__async","key","count","keysToLock","_","_a","error","unlockKeys","_b","remainingKeys","isLocked","computed","getKeyLockCount","isKeyLocked","tryOnScopeDispose"],"mappings":"qrBAGK,MAACA,EAAuBC,EAAkB,KAStC,CACL,MARYC,EAAS,CAErB,WAAY,IAAI,IAEhB,YAAa,IAAI,GAClB,CAAA,CAIH,EACC,EAIM,SAASC,GAAkB,CAChC,KAAM,CAAE,MAAAC,CAAK,EAAKJ,EAAoB,EAOhCK,EAAkBC,GAASC,EAAA,4BAE/BD,EAAK,QAAQE,GAAO,CAClB,MAAMC,EAAQL,EAAM,WAAW,IAAII,CAAG,GAAK,EAC3CJ,EAAM,WAAW,IAAII,EAAKC,EAAQ,CAAC,CACpC,CAAA,EAGD,MAAMC,EAAa,MAAM,KAAKN,EAAM,WAAW,QAAS,CAAA,EACrD,OAAO,CAAC,CAACO,EAAGF,CAAK,IAAMA,EAAQ,CAAC,EAChC,IAAI,CAAC,CAACD,CAAG,IAAMA,CAAG,EAErB,GAAIE,EAAW,OAAS,KAAKE,EAAA,UAAU,WAAV,MAAAA,EAAoB,MAC/C,GAAI,CACF,MAAM,UAAU,SAAS,KAAKF,CAAU,EACxCN,EAAM,YAAc,IAAI,IAAIM,CAAU,CACvC,OAAQG,EAAO,CACd,QAAQ,KAAK,2BAA4BA,CAAK,CACtD,CAEA,GAMQC,EAAcR,GAAS,S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