{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createdDom } from \"@yamada-ui/utils\"\nimport { useEffect, useMemo, useRef, useState } from \"react\"\n\nexport interface ObserverRect extends Omit<DOMRectReadOnly, \"toJSON\"> {}\n\nconst defaultRect: ObserverRect = {\n  bottom: 0,\n  height: 0,\n  left: 0,\n  right: 0,\n  top: 0,\n  width: 0,\n  x: 0,\n  y: 0,\n}\n\n/**\n * `useResizeObserver` is a custom hook that tracks changes in the size and position of an element.\n *\n * @see Docs https://yamada-ui.com/hooks/use-resize-observer\n */\nexport const useResizeObserver = <T extends HTMLElement = any>() => {\n  const id = useRef(0)\n  const ref = useRef<T>(null)\n  const [rect, setRect] = useState<ObserverRect>(defaultRect)\n\n  const observer = useMemo(() => {\n    if (!createdDom()) return null\n\n    return new ResizeObserver(([entry]) => {\n      if (!entry) return\n\n      cancelAnimationFrame(id.current)\n\n      id.current = requestAnimationFrame(() => {\n        if (ref.current) setRect(entry.contentRect)\n      })\n    })\n  }, [])\n\n  useEffect(() => {\n    if (ref.current) observer?.observe(ref.current)\n\n    return () => {\n      observer?.disconnect()\n\n      if (id.current) cancelAnimationFrame(id.current)\n    }\n  }, [observer])\n\n  return [ref, rect] as const\n}\n\nexport const useElementSize = <T extends HTMLElement = any>() => {\n  const [ref, { height, width }] = useResizeObserver<T>()\n\n  return { ref, height, width }\n}\n"],"mappings":";;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,WAAW,SAAS,QAAQ,gBAAgB;AAIrD,IAAM,cAA4B;AAAA,EAChC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,EACL,OAAO;AAAA,EACP,GAAG;AAAA,EACH,GAAG;AACL;AAOO,IAAM,oBAAoB,MAAmC;AAClE,QAAM,KAAK,OAAO,CAAC;AACnB,QAAM,MAAM,OAAU,IAAI;AAC1B,QAAM,CAAC,MAAM,OAAO,IAAI,SAAuB,WAAW;AAE1D,QAAM,WAAW,QAAQ,MAAM;AAC7B,QAAI,CAAC,WAAW,EAAG,QAAO;AAE1B,WAAO,IAAI,eAAe,CAAC,CAAC,KAAK,MAAM;AACrC,UAAI,CAAC,MAAO;AAEZ,2BAAqB,GAAG,OAAO;AAE/B,SAAG,UAAU,sBAAsB,MAAM;AACvC,YAAI,IAAI,QAAS,SAAQ,MAAM,WAAW;AAAA,MAC5C,CAAC;AAAA,IACH,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,QAAI,IAAI,QAAS,sCAAU,QAAQ,IAAI;AAEvC,WAAO,MAAM;AACX,2CAAU;AAEV,UAAI,GAAG,QAAS,sBAAqB,GAAG,OAAO;AAAA,IACjD;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO,CAAC,KAAK,IAAI;AACnB;AAEO,IAAM,iBAAiB,MAAmC;AAC/D,QAAM,CAAC,KAAK,EAAE,QAAQ,MAAM,CAAC,IAAI,kBAAqB;AAEtD,SAAO,EAAE,KAAK,QAAQ,MAAM;AAC9B;","names":[]}