@wikimedia/codex
Version:
Codex Design System for Wikimedia
2 lines (1 loc) • 654 B
JavaScript
;const t=require("vue");function u(r){const i=t.ref({width:void 0,height:void 0});if(typeof window!="object"||!("ResizeObserver"in window)||!("ResizeObserverEntry"in window))return i;const o=new window.ResizeObserver(e=>{var c;const n=e==null?void 0:e[0];if(n){const d=(c=n.borderBoxSize)==null?void 0:c[0];d?i.value={width:d.inlineSize,height:d.blockSize}:i.value={width:n.contentRect.width,height:n.contentRect.height}}});let s=!1;return t.onMounted(()=>{s=!0,r.value&&o.observe(r.value)}),t.onUnmounted(()=>{s=!1,o.disconnect()}),t.watch(r,e=>{s&&(o.disconnect(),i.value={width:void 0,height:void 0},e&&o.observe(e))}),i}module.exports=u;