{"version":3,"sources":["../../src/use-window-size/index.ts"],"sourcesContent":["import { useEventListener } from '../use-event-listener'\nimport { useLayoutMount } from '../use-layout-mount'\nimport { useMediaQuery } from '../use-media-query'\nimport { useSafeState } from '../use-safe-state'\nimport { useStableFn } from '../use-stable-fn'\nimport { useUpdateEffect } from '../use-update-effect'\n\nimport type { Size } from '../utils/basic'\n\nexport interface UseWindowSizeOptions {\n  /**\n   * The initial width of the window.\n   *\n   * @defaultValue Number.POSITIVE_INFINITY\n   */\n  initialWidth?: number\n  /**\n   * The initial height of the window.\n   *\n   * @defaultValue Number.POSITIVE_INFINITY\n   */\n  initialHeight?: number\n  /**\n   * Whether to listen to orientation changes.\n   *\n   * @defaultValue true\n   */\n  listenOrientation?: boolean\n  /**\n   * Whether to include the scrollbar width.\n   *\n   * @defaultValue true\n   */\n  includeScrollbar?: boolean\n}\n\nexport interface UseWindowSizeReturns extends Size {\n  /**\n   * Update the window size.\n   */\n  update(): void\n}\n\n/**\n * A React Hook that helps to track window height and innerWidth, and optionnally listen orientation media query.\n */\nexport function useWindowSize(options: UseWindowSizeOptions = {}): UseWindowSizeReturns {\n  const {\n    initialWidth = Number.POSITIVE_INFINITY,\n    initialHeight = Number.POSITIVE_INFINITY,\n    listenOrientation = true,\n    includeScrollbar = true,\n  } = options\n\n  const [size, setSize] = useSafeState<Size>({ width: initialWidth, height: initialHeight }, { deep: true })\n  const update = useStableFn(() => setSize(getWindowSize(includeScrollbar)))\n\n  useLayoutMount(update)\n\n  useEventListener(() => window, 'resize', update, { passive: true })\n\n  const isPortrait = useMediaQuery(listenOrientation ? '(orientation: portrait)' : '')\n\n  // biome-ignore lint/correctness/useExhaustiveDependencies: effect need to re-run when orientation changes\n  useUpdateEffect(() => update(), [isPortrait])\n\n  return { ...size, update }\n}\n\nfunction getWindowSize(includeScrollbar = true) {\n  const width = includeScrollbar ? window.innerWidth : document.documentElement.clientWidth\n  const height = includeScrollbar ? window.innerHeight : document.documentElement.clientHeight\n  return { width, height }\n}\n"],"names":["useWindowSize","options","initialWidth","Number","POSITIVE_INFINITY","initialHeight","listenOrientation","includeScrollbar","useSafeState","width","height","deep","size","setSize","update","useStableFn","getWindowSize","useLayoutMount","useEventListener","window","passive","isPortrait","useMediaQuery","useUpdateEffect","innerWidth","document","documentElement","clientWidth","innerHeight","clientHeight"],"mappings":";;;;+BA8CgBA;;;eAAAA;;;gCA9CiB;8BACF;6BACD;4BACD;2BACD;+BACI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCzB,SAASA;QAAcC,UAAAA,iEAAgC,CAAC;IAC7D,4BAKIA,QAJFC,cAAAA,kDAAeC,OAAOC,iBAAiB,mDAIrCH,QAHFI,eAAAA,oDAAgBF,OAAOC,iBAAiB,wDAGtCH,QAFFK,mBAAAA,4DAAoB,+DAElBL,QADFM,kBAAAA,0DAAmB;IAGrB,IAAwBC,iCAAAA,IAAAA,0BAAY,EAAO;QAAEC,OAAOP;QAAcQ,QAAQL;IAAc,GAAG;QAAEM,MAAM;IAAK,QAAjGC,OAAiBJ,kBAAXK,UAAWL;IACxB,IAAMM,SAASC,IAAAA,wBAAW,EAAC;eAAMF,QAAQG,cAAcT;;IAEvDU,IAAAA,8BAAc,EAACH;IAEfI,IAAAA,kCAAgB,EAAC;eAAMC;OAAQ,UAAUL,QAAQ;QAAEM,SAAS;IAAK;IAEjE,IAAMC,aAAaC,IAAAA,4BAAa,EAAChB,oBAAoB,4BAA4B;IAEjF,0GAA0G;IAC1GiB,IAAAA,gCAAe,EAAC;eAAMT;OAAU;QAACO;KAAW;IAE5C,OAAO,wCAAKT;QAAME,QAAAA;;AACpB;AAEA,SAASE;QAAcT,mBAAAA,iEAAmB;IACxC,IAAME,QAAQF,mBAAmBY,OAAOK,UAAU,GAAGC,SAASC,eAAe,CAACC,WAAW;IACzF,IAAMjB,SAASH,mBAAmBY,OAAOS,WAAW,GAAGH,SAASC,eAAe,CAACG,YAAY;IAC5F,OAAO;QAAEpB,OAAAA;QAAOC,QAAAA;IAAO;AACzB"}