resizeObserver.mjs.map 2.8 KB

1
  1. {"version":3,"file":"resizeObserver.mjs","names":["onBeforeUnmount","readonly","ref","watch","refElement","IN_BROWSER","useResizeObserver","callback","box","arguments","length","undefined","resizeRef","contentRect","observer","ResizeObserver","entries","value","target","getBoundingClientRect","disconnect","newValue","oldValue","unobserve","observe","flush"],"sources":["../../src/composables/resizeObserver.ts"],"sourcesContent":["// Utilities\nimport { onBeforeUnmount, readonly, ref, watch } from 'vue'\nimport { refElement } from '@/util'\nimport { IN_BROWSER } from '@/util/globals'\n\n// Types\nimport type { DeepReadonly, Ref } from 'vue'\n\ninterface ResizeState {\n resizeRef: Ref<HTMLElement | undefined>\n contentRect: DeepReadonly<Ref<DOMRectReadOnly | undefined>>\n}\n\nexport function useResizeObserver (callback?: ResizeObserverCallback, box: 'content' | 'border' = 'content'): ResizeState {\n const resizeRef = ref<HTMLElement>()\n const contentRect = ref<DOMRectReadOnly>()\n\n if (IN_BROWSER) {\n const observer = new ResizeObserver((entries: ResizeObserverEntry[]) => {\n callback?.(entries, observer)\n\n if (!entries.length) return\n\n if (box === 'content') {\n contentRect.value = entries[0].contentRect\n } else {\n contentRect.value = entries[0].target.getBoundingClientRect()\n }\n })\n\n onBeforeUnmount(() => {\n observer.disconnect()\n })\n\n watch(resizeRef, (newValue, oldValue) => {\n if (oldValue) {\n observer.unobserve(refElement(oldValue))\n contentRect.value = undefined\n }\n\n if (newValue) observer.observe(refElement(newValue))\n }, {\n flush: 'post',\n })\n }\n\n return {\n resizeRef,\n contentRect: readonly(contentRect),\n }\n}\n"],"mappings":"AAAA;AACA,SAASA,eAAe,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,QAAQ,KAAK;AAAA,SAClDC,UAAU;AAAA,SACVC,UAAU,+BAEnB;AAQA,OAAO,SAASC,iBAAiBA,CAAEC,QAAiC,EAAsD;EAAA,IAApDC,GAAyB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,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