Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

compute-scroll-into-view

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

compute-scroll-into-view - npm Package Compare versions

Comparing version 1.0.20 to 2.0.0

dist/index.cjs

2

dist/index.js

@@ -1,2 +0,2 @@

function t(t){return"object"==typeof t&&null!=t&&1===t.nodeType}function e(t,e){return(!e||"hidden"!==t)&&"visible"!==t&&"clip"!==t}function n(t,n){if(t.clientHeight<t.scrollHeight||t.clientWidth<t.scrollWidth){var i=getComputedStyle(t,null);return e(i.overflowY,n)||e(i.overflowX,n)||function(t){var e=function(t){if(!t.ownerDocument||!t.ownerDocument.defaultView)return null;try{return t.ownerDocument.defaultView.frameElement}catch(t){return null}}(t);return!!e&&(e.clientHeight<t.scrollHeight||e.clientWidth<t.scrollWidth)}(t)}return!1}function i(t,e,n,i,r,o,l,d){return o<t&&l>e||o>t&&l<e?0:o<=t&&d<=n||l>=e&&d>=n?o-t-i:l>e&&d<n||o<t&&d>n?l-e+r:0}module.exports=function(e,r){var o=window,l=r.scrollMode,d=r.block,f=r.inline,h=r.boundary,u=r.skipOverflowHiddenElements,s="function"==typeof h?h:function(t){return t!==h};if(!t(e))throw new TypeError("Invalid target");for(var c,a,g=document.scrollingElement||document.documentElement,m=[],p=e;t(p)&&s(p);){if((p=null==(a=(c=p).parentElement)?c.getRootNode().host||null:a)===g){m.push(p);break}null!=p&&p===document.body&&n(p)&&!n(document.documentElement)||null!=p&&n(p,u)&&m.push(p)}for(var w=o.visualViewport?o.visualViewport.width:innerWidth,v=o.visualViewport?o.visualViewport.height:innerHeight,W=window.scrollX||pageXOffset,H=window.scrollY||pageYOffset,b=e.getBoundingClientRect(),y=b.height,E=b.width,M=b.top,V=b.right,x=b.bottom,I=b.left,C="start"===d||"nearest"===d?M:"end"===d?x:M+y/2,R="center"===f?I+E/2:"end"===f?V:I,T=[],k=0;k<m.length;k++){var B=m[k],D=B.getBoundingClientRect(),O=D.height,X=D.width,Y=D.top,L=D.right,S=D.bottom,j=D.left;if("if-needed"===l&&M>=0&&I>=0&&x<=v&&V<=w&&M>=Y&&x<=S&&I>=j&&V<=L)return T;var N=getComputedStyle(B),q=parseInt(N.borderLeftWidth,10),z=parseInt(N.borderTopWidth,10),A=parseInt(N.borderRightWidth,10),F=parseInt(N.borderBottomWidth,10),G=0,J=0,K="offsetWidth"in B?B.offsetWidth-B.clientWidth-q-A:0,P="offsetHeight"in B?B.offsetHeight-B.clientHeight-z-F:0,Q="offsetWidth"in B?0===B.offsetWidth?0:X/B.offsetWidth:0,U="offsetHeight"in B?0===B.offsetHeight?0:O/B.offsetHeight:0;if(g===B)G="start"===d?C:"end"===d?C-v:"nearest"===d?i(H,H+v,v,z,F,H+C,H+C+y,y):C-v/2,J="start"===f?R:"center"===f?R-w/2:"end"===f?R-w:i(W,W+w,w,q,A,W+R,W+R+E,E),G=Math.max(0,G+H),J=Math.max(0,J+W);else{G="start"===d?C-Y-z:"end"===d?C-S+F+P:"nearest"===d?i(Y,S,O,z,F+P,C,C+y,y):C-(Y+O/2)+P/2,J="start"===f?R-j-q:"center"===f?R-(j+X/2)+K/2:"end"===f?R-L+A+K:i(j,L,X,q,A+K,R,R+E,E);var Z=B.scrollLeft,$=B.scrollTop;C+=$-(G=Math.max(0,Math.min($+G/U,B.scrollHeight-O/U+P))),R+=Z-(J=Math.max(0,Math.min(Z+J/Q,B.scrollWidth-X/Q+K)))}T.push({el:B,top:G,left:J})}return T};
function t(t){return"object"==typeof t&&null!=t&&1===t.nodeType}function e(t,e){return(!e||"hidden"!==t)&&("visible"!==t&&"clip"!==t)}function n(t,n){if(t.clientHeight<t.scrollHeight||t.clientWidth<t.scrollWidth){const o=getComputedStyle(t,null);return e(o.overflowY,n)||e(o.overflowX,n)||function(t){const e=function(t){if(!t.ownerDocument||!t.ownerDocument.defaultView)return null;try{return t.ownerDocument.defaultView.frameElement}catch(t){return null}}(t);return!!e&&(e.clientHeight<t.scrollHeight||e.clientWidth<t.scrollWidth)}(t)}return!1}function o(t,e,n,o,i,l,r,d){return l<t&&r>e||l>t&&r<e?0:l<=t&&d<=n||r>=e&&d>=n?l-t-o:r>e&&d<n||l<t&&d>n?r-e+i:0}function i(t){const e=t.parentElement;return null==e?t.getRootNode().host||null:e}var l=(e,l)=>{var r,d,u,f,s,c;if("undefined"==typeof document)return[];const{scrollMode:h,block:a,inline:g,boundary:m,skipOverflowHiddenElements:p}=l,w="function"==typeof m?m:t=>t!==m;if(!t(e))throw new TypeError("Invalid target");const W=document.scrollingElement||document.documentElement,H=[];let b=e;for(;t(b)&&w(b);){if(b=i(b),b===W){H.push(b);break}null!=b&&b===document.body&&n(b)&&!n(document.documentElement)||null!=b&&n(b,p)&&H.push(b)}const v=null!=(d=null==(r=window.visualViewport)?void 0:r.width)?d:innerWidth,y=null!=(f=null==(u=window.visualViewport)?void 0:u.height)?f:innerHeight,E=null!=(s=window.scrollX)?s:pageXOffset,M=null!=(c=window.scrollY)?c:pageYOffset,{height:x,width:I,top:C,right:R,bottom:T,left:V}=e.getBoundingClientRect();let k="start"===a||"nearest"===a?C:"end"===a?T:C+x/2,B="center"===g?V+I/2:"end"===g?R:V;const D=[];for(let t=0;t<H.length;t++){const e=H[t],{height:n,width:i,top:l,right:r,bottom:d,left:u}=e.getBoundingClientRect();if("if-needed"===h&&C>=0&&V>=0&&T<=y&&R<=v&&C>=l&&T<=d&&V>=u&&R<=r)return D;const f=getComputedStyle(e),s=parseInt(f.borderLeftWidth,10),c=parseInt(f.borderTopWidth,10),m=parseInt(f.borderRightWidth,10),p=parseInt(f.borderBottomWidth,10);let w=0,b=0;const O="offsetWidth"in e?e.offsetWidth-e.clientWidth-s-m:0,X="offsetHeight"in e?e.offsetHeight-e.clientHeight-c-p:0,Y="offsetWidth"in e?0===e.offsetWidth?0:i/e.offsetWidth:0,L="offsetHeight"in e?0===e.offsetHeight?0:n/e.offsetHeight:0;if(W===e)w="start"===a?k:"end"===a?k-y:"nearest"===a?o(M,M+y,y,c,p,M+k,M+k+x,x):k-y/2,b="start"===g?B:"center"===g?B-v/2:"end"===g?B-v:o(E,E+v,v,s,m,E+B,E+B+I,I),w=Math.max(0,w+M),b=Math.max(0,b+E);else{w="start"===a?k-l-c:"end"===a?k-d+p+X:"nearest"===a?o(l,d,n,c,p+X,k,k+x,x):k-(l+n/2)+X/2,b="start"===g?B-u-s:"center"===g?B-(u+i/2)+O/2:"end"===g?B-r+m+O:o(u,r,i,s,m+O,B,B+I,I);const{scrollLeft:t,scrollTop:f}=e;w=Math.max(0,Math.min(f+w/L,e.scrollHeight-n/L+X)),b=Math.max(0,Math.min(t+b/Y,e.scrollWidth-i/Y+O)),k+=f-w,B+=t-b}D.push({el:e,top:w,left:b})}return D};export{l as default};
//# sourceMappingURL=index.js.map
{
"name": "compute-scroll-into-view",
"version": "1.0.20",
"version": "2.0.0",
"description": "The engine that powers scroll-into-view-if-needed",

@@ -23,45 +23,32 @@ "keywords": [

"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./typings/index.d.ts",
"types": "./dist/index.d.ts",
"source": "./src/index.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"default": "./dist/index.mjs"
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"main": "dist/index.js",
"umd:main": "umd/compute-scroll-into-view.min.js",
"module": "dist/index.mjs",
"source": "src/index.ts",
"typings": "typings/index.d.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"source": "./src/index.ts",
"typings": "./dist/index.d.ts",
"files": [
"dist",
"typings",
"umd/compute-scroll-into-view.min.js",
"umd/compute-scroll-into-view.min.js.map"
"src"
],
"scripts": {
"prebuild": "rimraf 'dist' 'umd'",
"build": "npm run build:dist && npm run build:umd",
"build:dist": "microbundle -f cjs,es",
"build:umd": "microbundle -f umd -o umd",
"prebuild": "npx rimraf 'dist'",
"build": "pkg build --strict",
"prepublishOnly": "npm run build",
"test": "jest -c integration/jest.config.js",
"typecheck": "tsc --noEmit"
"test": "npx cross-env JEST_PUPPETEER_CONFIG='jest-puppeteer.config.cjs' jest -c integration/jest.config.cjs",
"typecheck": "tsc"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,ts,tsx,json,md}": "prettier --write"
},
"browserify": {
"transform": [
"loose-envify"
]
},
"browserslist": [
"> 0.2% and supports es6-module and supports es6-module-dynamic-import and not dead and not IE 11",
"maintained node versions"
],
"prettier": {

@@ -72,9 +59,12 @@ "semi": false,

"devDependencies": {
"@sanity/pkg-utils": "^1.20.1",
"@sanity/semantic-release-preset": "^2.0.2",
"husky": "^8.0.2",
"@types/expect-puppeteer": "^5.0.2",
"@types/jest": "^29.2.3",
"@types/jest-environment-puppeteer": "^5.0.3",
"@types/puppeteer": "^7.0.4",
"cross-env": "^7.0.3",
"jest": "^29.3.1",
"jest-junit": "^15.0.0",
"jest-puppeteer": "^6.1.1",
"lint-staged": "^13.0.4",
"microbundle": "^0.15.1",
"prettier": "^2.8.0",

@@ -89,3 +79,3 @@ "prettier-plugin-packagejson": "^2.3.0",

{
"path": "./umd/compute-scroll-into-view.min.js",
"path": "./dist/index.js",
"maxSize": "3 kB",

@@ -92,0 +82,0 @@ "compression": "none"

@@ -5,3 +5,2 @@ [![npm stat](https://img.shields.io/npm/dm/compute-scroll-into-view.svg?style=flat-square)](https://npm-stat.com/charts.html?package=compute-scroll-into-view)

[![size][size-badge]][unpkg-dist]
[![module formats: umd, cjs, and es][module-formats-badge]][unpkg-dist]
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)

@@ -16,2 +15,13 @@

- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [compute(target, options)](#computetarget-options)
- [options](#options)
- [block](#block)
- [inline](#inline)
- [scrollMode](#scrollmode)
- [boundary](#boundary)
- [skipOverflowHiddenElements](#skipoverflowhiddenelements)
## Install

@@ -23,17 +33,14 @@

The UMD build is also available on [unpkg](https://unpkg.com/compute-scroll-into-view/umd/):
You can also use it from an CDN:
```html
<script src="https://unpkg.com/compute-scroll-into-view/umd/compute-scroll-into-view.min.js"></script>
```js
const { default: compute } = await import(
'https://esm.sh/compute-scroll-into-view'
)
```
You can find the library on `window.computeScrollIntoView`.
## Usage
```js
// es6 import
import computeScrollIntoView from 'compute-scroll-into-view'
// or es5
const computeScrollIntoView = require('compute-scroll-into-view')
import compute from 'compute-scroll-into-view'

@@ -44,3 +51,3 @@ const node = document.getElementById('hero')

// see: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
const actions = computeScrollIntoView(node, {
const actions = compute(node, {
scrollMode: 'if-needed',

@@ -53,3 +60,3 @@ block: 'nearest',

// see: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded
const actions = computeScrollIntoView(node, {
const actions = compute(node, {
scrollMode: 'if-needed',

@@ -69,3 +76,3 @@ block: 'center',

### computeScrollIntoView(target, options)
### compute(target, options)

@@ -111,3 +118,3 @@ ### options

```js
const actions = computeScrollIntoView(target, {
const actions = compute(target, {
boundary: (parent) => {

@@ -133,9 +140,4 @@ // By default `overflow: hidden` elements are allowed, only `overflow: visible | clip` is skipped as

# TypeScript support
This library ships with library definitions for TypeScript.
[gzip-badge]: http://img.badgesize.io/https://unpkg.com/compute-scroll-into-view/umd/compute-scroll-into-view.min.js?compression=gzip&label=gzip%20size&style=flat-square
[size-badge]: http://img.badgesize.io/https://unpkg.com/compute-scroll-into-view/umd/compute-scroll-into-view.min.js?label=size&style=flat-square
[unpkg-dist]: https://unpkg.com/compute-scroll-into-view/umd/
[module-formats-badge]: https://img.shields.io/badge/module%20formats-umd%2C%20cjs%2C%20es-green.svg?style=flat-square
[gzip-badge]: https://img.badgesize.io/https:/unpkg.com/compute-scroll-into-view/dist/index.js?label=gzip%20size&compression=gzip&style=flat-square
[size-badge]: https://img.badgesize.io/https:/unpkg.com/compute-scroll-into-view/dist/index.js?label=size&style=flat-square
[unpkg-dist]: https://unpkg.com/compute-scroll-into-view/dist/

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