UNPKG

@uifabric/utilities

Version:

Fluent UI React utilities for building components.

1 lines 1.26 kB
{"version":3,"file":"getRect.js","sourceRoot":"../src/","sources":["dom/getRect.ts"],"names":[],"mappings":"AACA;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,OAAoC;IAC1D,IAAI,IAA4B,CAAC;IACjC,IAAI,OAAO,EAAE;QACX,IAAI,OAAO,KAAK,MAAM,EAAE;YACtB,IAAI,GAAG;gBACL,IAAI,EAAE,CAAC;gBACP,GAAG,EAAE,CAAC;gBACN,KAAK,EAAE,MAAM,CAAC,UAAU;gBACxB,MAAM,EAAE,MAAM,CAAC,WAAW;gBAC1B,KAAK,EAAE,MAAM,CAAC,UAAU;gBACxB,MAAM,EAAE,MAAM,CAAC,WAAW;aAC3B,CAAC;SACH;aAAM,IAAK,OAAuB,CAAC,qBAAqB,EAAE;YACzD,IAAI,GAAI,OAAuB,CAAC,qBAAqB,EAAE,CAAC;SACzD;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { IRectangle } from '../IRectangle';\n/**\n * Helper to get bounding client rect. Passing in window will get the window size.\n *\n * @public\n */\nexport function getRect(element: HTMLElement | Window | null): IRectangle | undefined {\n let rect: IRectangle | undefined;\n if (element) {\n if (element === window) {\n rect = {\n left: 0,\n top: 0,\n width: window.innerWidth,\n height: window.innerHeight,\n right: window.innerWidth,\n bottom: window.innerHeight,\n };\n } else if ((element as HTMLElement).getBoundingClientRect) {\n rect = (element as HTMLElement).getBoundingClientRect();\n }\n }\n return rect;\n}\n"]}