Socket
Socket
Sign inDemoInstall

get-scroll-info

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-scroll-info - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

types/index.d.ts

67

build/cjs/src/index.js

@@ -5,8 +5,14 @@ "use strict";

exports.getScrollNode = exports["default"] = void 0;
var _winDoc = require("win-doc");
var _reshowConstant = require("reshow-constant");
// @ts-check
var lastScrollStore = Object.create(null);
var lastScrollStore = (0, _reshowConstant.NEW_OBJ)();
/**
* @typedef {object & Document} ThisDocument
* @propert {function} webkitIsFullScreen
*/
/**
* @type ThisDocument
*/
var oDoc;

@@ -17,3 +23,2 @@ var oWin;

var domCount = 0;
var initDoc = function initDoc() {

@@ -26,2 +31,6 @@ oDoc = (0, _winDoc.doc)();

/**
* @param {HTMLElement} el
* @returns {HTMLElement}
*/
var getScrollNode = function getScrollNode(el) {

@@ -31,3 +40,2 @@ if (!oDoc) {

}
if (!el && oDoc) {

@@ -42,3 +50,2 @@ if (oDoc.scrollingElement) {

}
if (!el.id) {

@@ -48,24 +55,46 @@ el.id = "scroll-info-" + domCount;

}
return el;
};
/**
* @typedef {object} InfoType
* @property {boolean} atTop
* @property {boolean} atRight
* @property {boolean} atBottom
* @property {boolean} atLeft
* @property {boolean} isScrollUp
* @property {boolean} isScrollRight
* @property {boolean} isScrollDown
* @property {boolean} isScrollLeft
* @property {number} scrollWidth
* @property {number} scrollHeight
* @property {number} scrollNodeWidth
* @property {number} scrollNodeHeight
* @property {number} top
* @property {number} right
* @property {number} bottom
* @property {number} left
*/
/**
* @returns {InfoType}
*/
exports.getScrollNode = getScrollNode;
var getScrollInfo = function getScrollInfo(el, margin) {
el = getScrollNode(el);
if (!margin) {
if (el === void 0) {
el = null;
}
if (margin === void 0) {
margin = 50;
}
el = getScrollNode(el);
var w;
var h;
var nodeName = (el.nodeName || "").toLowerCase();
var isRoot = "body" === nodeName || "html" === nodeName; // defined scrollWidth and scrollHeight first.
var isRoot = "body" === nodeName || "html" === nodeName;
// defined scrollWidth and scrollHeight first.
// to know if have vertical or horizontal bar.
var scrollWidth = el.scrollWidth;
var scrollHeight = el.scrollHeight;
if (isRoot) {

@@ -76,7 +105,5 @@ w = Math.max(el.clientWidth || 0, oWin.innerWidth || 0);

var hasVerticalBar = h < scrollHeight;
if (hasHorizontalBar) {
h = el.clientHeight;
}
if (hasVerticalBar) {

@@ -89,3 +116,2 @@ w = el.clientWidth;

}
var scrollLeft = el.scrollLeft;

@@ -102,6 +128,6 @@ var scrollTop = el.scrollTop;

atLeft: scrollLeft < margin,
isScrollUp: lastScroll && scrollTop < lastScroll.top,
isScrollRight: lastScroll && scrollLeft > lastScroll.left,
isScrollDown: lastScroll && scrollTop > lastScroll.top,
isScrollLeft: lastScroll && scrollLeft < lastScroll.left,
isScrollRight: lastScroll && scrollLeft > lastScroll.left,
isScrollUp: lastScroll && scrollTop < lastScroll.top,
scrollWidth: scrollWidth,

@@ -119,4 +145,3 @@ scrollHeight: scrollHeight,

};
var _default = getScrollInfo;
exports["default"] = _default;
{
"version": "0.3.2",
"version": "0.4.0",
"name": "get-scroll-info",

@@ -30,6 +30,7 @@ "repository": {

"scripts": {
"clean": "find ./build -name '*.*' | xargs rm -rf",
"clean": "find ./build ./types -name '*.*' | xargs rm -rf",
"build:cjs": "BABEL_ENV=cjs babel src -d build/cjs/src --ignore /**/__tests__ --root-mode upward",
"build:es": "BABEL_ENV=es babel src -d build/es/src --out-file-extension .mjs --root-mode upward",
"build": "npm run clean && npm run build:cjs && npm run build:es",
"build:type": "npx -p typescript tsc src/*.js --declaration --allowJs --emitDeclarationOnly --skipLibCheck --declarationDir types",
"build": "npm run clean && npm run build:cjs && npm run build:es && npm run build:type",
"mochaFor": "mocha -r global-jsdom/register",

@@ -40,3 +41,5 @@ "mocha": "npm run mochaFor -- 'build/es/**/__tests__/*.mjs'",

},
"types": "./types/index.d.ts",
"files": [
"types",
"build",

@@ -43,0 +46,0 @@ "package.json",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc