{"version":3,"sources":["../src/react.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react'\nimport device from './index'\nimport type { DeviceOrientation, DeviceOs, DeviceType } from './index'\n\nexport type { DeviceOrientation, DeviceOs, DeviceType }\n\nexport interface DeviceState {\n  type: DeviceType\n  os: DeviceOs\n  orientation: DeviceOrientation\n}\n\n// What the hooks return on the server and while hydrating: the server can't\n// see the device, and the first client render has to match the server's HTML.\nconst serverState: DeviceState = {\n  type: 'unknown',\n  os: 'unknown',\n  orientation: 'unknown',\n}\n\nlet state: DeviceState | undefined\n\nfunction subscribe(onChange: () => void): () => void {\n  return device.onChangeOrientation(onChange)\n}\n\n// useSyncExternalStore needs the same object back until something changed.\n// Only the orientation can change after the page has loaded.\nfunction getState(): DeviceState {\n  if (!state || state.orientation !== device.orientation) {\n    state = { type: device.type, os: device.os, orientation: device.orientation }\n  }\n  return state\n}\n\nfunction getServerState(): DeviceState {\n  return serverState\n}\n\nfunction getOrientation(): DeviceOrientation {\n  return device.orientation\n}\n\nfunction getServerOrientation(): DeviceOrientation {\n  return serverState.orientation\n}\n\n// The device's type, OS and orientation. Re-renders the component when the\n// orientation changes.\nexport function useDevice(): DeviceState {\n  return useSyncExternalStore(subscribe, getState, getServerState)\n}\n\n// The device's orientation. Re-renders the component when it changes.\nexport function useOrientation(): DeviceOrientation {\n  return useSyncExternalStore(subscribe, getOrientation, getServerOrientation)\n}\n"],"mappings":";;;AAAA,SAAS,4BAA4B;AACrC,OAAO,YAAY;AAanB,IAAM,cAA2B;AAAA,EAC/B,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,aAAa;AACf;AAEA,IAAI;AAEJ,SAAS,UAAU,UAAkC;AACnD,SAAO,OAAO,oBAAoB,QAAQ;AAC5C;AAIA,SAAS,WAAwB;AAC/B,MAAI,CAAC,SAAS,MAAM,gBAAgB,OAAO,aAAa;AACtD,YAAQ,EAAE,MAAM,OAAO,MAAM,IAAI,OAAO,IAAI,aAAa,OAAO,YAAY;AAAA,EAC9E;AACA,SAAO;AACT;AAEA,SAAS,iBAA8B;AACrC,SAAO;AACT;AAEA,SAAS,iBAAoC;AAC3C,SAAO,OAAO;AAChB;AAEA,SAAS,uBAA0C;AACjD,SAAO,YAAY;AACrB;AAIO,SAAS,YAAyB;AACvC,SAAO,qBAAqB,WAAW,UAAU,cAAc;AACjE;AAGO,SAAS,iBAAoC;AAClD,SAAO,qBAAqB,WAAW,gBAAgB,oBAAoB;AAC7E;","names":[]}