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AM,IAAI,GAAG,YAAY,CAAC,IAAI,GAAG,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC;YAC/D,CAAC,YAAY,CAAC,IAAI;YAClB,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC;QAE7B,MAAM,CAAC,EAAC,QAAG,EAAE,UAAI,EAAC,CAAC;IACrB,CAAC;IApDH;QAAC,UAAU,EAAE;;qBAAA;IAqDb,oBAAC;AAAD,CApDA,AAoDC,IAAA","file":"core/overlay/position/viewport-ruler.js","sourcesContent":["import {Injectable} from '@angular/core';\n\n\n\n/**\n * Simple utility for getting the bounds of the browser viewport.\n * TODO: internal\n */\n@Injectable()\nexport class ViewportRuler {\n // TODO(jelbourn): cache the document's bounding rect and only update it when the window\n // is resized (debounced).\n\n\n /** Gets a ClientRect for the viewport's bounds. */\n getViewportRect(): ClientRect {\n // Use the document element's bounding rect rather than the window scroll properties\n // (e.g. pageYOffset, scrollY) due to in issue in Chrome and IE where window scroll\n // properties and client coordinates (boundingClientRect, clientX/Y, etc.) are in different\n // conceptual viewports. Under most circumstances these viewports are equivalent, but they\n // can disagree when the page is pinch-zoomed (on devices that support touch).\n // See https://bugs.chromium.org/p/chromium/issues/detail?id=489206#c4\n // We use the documentElement instead of the body because, by default (without a css reset)\n // browsers typically give the document body an 8px margin, which is not included in\n // getBoundingClientRect().\n const documentRect = document.documentElement.getBoundingClientRect();\n const scrollPosition = this.getViewportScrollPosition(documentRect);\n const height = window.innerHeight;\n const width = window.innerWidth;\n\n return {\n top: scrollPosition.top,\n left: scrollPosition.left,\n bottom: scrollPosition.top + height,\n right: scrollPosition.left + width,\n height,\n width,\n };\n }\n\n\n /**\n * Gets the (top, left) scroll position of the viewport.\n * @param documentRect\n */\n getViewportScrollPosition(documentRect = document.documentElement.getBoundingClientRect()) {\n // The top-left-corner of the viewport is determined by the scroll position of the document\n // body, normally just (scrollLeft, scrollTop). However, Chrome and Firefox disagree about\n // whether `document.body` or `document.documentElement` is the scrolled element, so reading\n // `scrollTop` and `scrollLeft` is inconsistent. However, using the bounding rect of\n // `document.documentElement` works consistently, where the `top` and `left` values will\n // equal negative the scroll position.\n const top = documentRect.top < 0 && document.body.scrollTop == 0 ?\n -documentRect.top :\n document.body.scrollTop;\n const left = documentRect.left < 0 && document.body.scrollLeft == 0 ?\n -documentRect.left :\n document.body.scrollLeft;\n\n return {top, left};\n }\n}\n"],"sourceRoot":"/source/"}
\No newline at end of file