UNPKG

@dotcms/analytics

Version:

Official JavaScript library for Content Analytics with DotCMS.

28 lines (27 loc) 867 B
function s(e) { const t = e.getBoundingClientRect(), i = window.innerHeight || document.documentElement.clientHeight, n = window.innerWidth || document.documentElement.clientWidth, o = Math.min(t.bottom, i) - Math.max(t.top, 0), c = Math.min(t.right, n) - Math.max(t.left, 0); if (o <= 0 || c <= 0) return 0; const l = o * c, r = t.height * t.width; return r > 0 ? l / r : 0; } function h(e) { const t = e.getBoundingClientRect(), i = window.innerHeight || document.documentElement.clientHeight, n = t.top / i * 100; return Math.round(n * 100) / 100; } function a(e, t) { return s(e) >= t; } function u(e) { const t = s(e); return { offsetPercentage: h(e), visibilityRatio: t }; } export { s as calculateElementVisibilityRatio, h as calculateViewportOffset, u as getViewportMetrics, a as isElementMeetingVisibilityThreshold };