{"version":3,"file":"device.cjs","names":[],"sources":["../../src/perf/device.ts"],"sourcesContent":["import type { DeviceProfile } from \"./types\";\n\n/**\n * What the browser will tell us about the machine it is running on.\n */\n\nconst BYTES_PER_MIB = 1024 * 1024;\n\n/** `navigator.deviceMemory` is Chromium-only and absent from the DOM lib. */\ninterface DeviceMemoryNavigator extends Navigator {\n    deviceMemory?: number;\n}\n\n/** `performance.memory` is a non-standard Chromium extension. */\ninterface HeapPerformance extends Performance {\n    memory?: { usedJSHeapSize: number };\n}\n\n/**\n * Used JS heap in MiB, rounded to one decimal.\n *\n * @returns The heap usage, or `null` outside Chromium.\n */\nfunction readHeapUsedMb(): number | null {\n    if (typeof performance === \"undefined\") return null;\n    const memory = (performance as HeapPerformance).memory;\n    if (!memory) return null;\n    return Math.round((memory.usedJSHeapSize / BYTES_PER_MIB) * 10) / 10;\n}\n\n/**\n * Sample the device capabilities the browser reports.\n *\n * Safe to call during SSR: without a `navigator` every field is `null`.\n *\n * @returns The profile, with `null` for anything this platform withholds.\n *\n * @example\n * ```typescript\n * const device = readDeviceProfile();\n * console.log(device.hardwareConcurrency); // 8\n * console.log(device.deviceMemoryGb);      // 8 on Chromium, null on Safari\n * ```\n */\nexport function readDeviceProfile(): DeviceProfile {\n    if (typeof navigator === \"undefined\") {\n        return { hardwareConcurrency: null, deviceMemoryGb: null, jsHeapUsedMb: null };\n    }\n    const nav = navigator as DeviceMemoryNavigator;\n    return {\n        hardwareConcurrency: nav.hardwareConcurrency ?? null,\n        deviceMemoryGb: nav.deviceMemory ?? null,\n        jsHeapUsedMb: readHeapUsedMb(),\n    };\n}\n"],"mappings":"AAuBA,SAAS,GAAgC,CACrC,GAAI,OAAO,YAAgB,IAAa,OAAO,KAC/C,IAAM,EAAU,YAAgC,OAEhD,OADK,EACE,KAAK,MAAO,EAAO,eAAiB,QAAiB,EAAE,EAAI,GAD9C,IAExB,CAgBA,SAAgB,GAAmC,CAC/C,GAAI,OAAO,UAAc,IACrB,MAAO,CAAE,oBAAqB,KAAM,eAAgB,KAAM,aAAc,IAAK,EAEjF,IAAM,EAAM,UACZ,MAAO,CACH,oBAAqB,EAAI,qBAAuB,KAChD,eAAgB,EAAI,cAAgB,KACpC,aAAc,EAAe,CACjC,CACJ"}