{"name":"compute-scroll-into-view","version":"3.1.1","description":"The engine that powers scroll-into-view-if-needed","keywords":["if-needed","scroll","scroll-into-view","scroll-into-view-if-needed","scrollIntoView","scrollIntoViewIfNeeded","scrollMode","typescript"],"homepage":"https://scroll-into-view.dev","repository":{"type":"git","url":"git+https://github.com/scroll-into-view/compute-scroll-into-view.git"},"license":"MIT","author":{"name":"Cody Olsen"},"sideEffects":false,"type":"module","exports":{".":{"types":"./dist/index.d.ts","source":"./src/index.ts","require":"./dist/index.cjs","import":"./dist/index.js","default":"./dist/index.js"},"./package.json":"./package.json"},"main":"./dist/index.cjs","module":"./dist/index.js","source":"./src/index.ts","typings":"./dist/index.d.ts","scripts":{"prebuild":"npx rimraf 'dist'","build":"pkg build --strict","prepublishOnly":"npm run build","test":"npx cross-env JEST_PUPPETEER_CONFIG='jest-puppeteer.config.cjs' jest -c integration/jest.config.cjs","typecheck":"tsc"},"browserslist":["> 0.2% and supports es6-module and supports es6-module-dynamic-import and not dead","maintained node versions"],"prettier":{"semi":false,"singleQuote":true},"devDependencies":{"@sanity/pkg-utils":"^2.2.5","@sanity/semantic-release-preset":"^4.0.0","@types/expect-puppeteer":"^5.0.2","@types/jest":"^29.4.0","@types/jest-environment-puppeteer":"^5.0.3","@types/puppeteer":"^7.0.4","cross-env":"^7.0.3","jest":"^29.5.0","jest-junit":"^15.0.0","jest-puppeteer":"^8.0.0","prettier":"^2.8.4","prettier-plugin-packagejson":"^2.4.3","puppeteer":"^19.7.0","rimraf":"^4.1.2","serve":"^14.2.0","typescript":"^5.0.0"},"bundlesize":[{"path":"./dist/index.js","maxSize":"3 kB","compression":"none"}],"gitHead":"16d90f8ac94c585add15d0b7f6d86864c9f0980a","bugs":{"url":"https://github.com/scroll-into-view/compute-scroll-into-view/issues"},"_id":"compute-scroll-into-view@3.1.1","_nodeVersion":"22.12.0","_npmVersion":"9.6.4","dist":{"integrity":"sha512-VRhuHOLoKYOy4UbilLbUzbYg93XLjv2PncJC50EuTWPA3gaja1UjBsUP/D/9/juV3vQFr6XBEzn9KCAHdUvOHw==","shasum":"02c3386ec531fb6a9881967388e53e8564f3e9aa","tarball":"http://registry-npm.ywwl.com/compute-scroll-into-view/download/compute-scroll-into-view-3.1.1.tgz","fileCount":9,"unpackedSize":95312,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF+t1YKN0ViFlGf6qf6YGha34BrJBHCMRhib+kOL0a+8AiBOJUkVJRLypdvNqIau7OG9eq+lhV4EYSLTlNZX6UC4qQ=="}],"size":17806,"noattachment":false,"key":"/compute-scroll-into-view/-/compute-scroll-into-view-3.1.1.tgz"},"_npmUser":{"name":"stipsan","email":"stipsan@gmail.com"},"directories":{},"maintainers":[{"name":"stipsan","email":"stipsan@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/compute-scroll-into-view_3.1.1_1736536235203_0.8286713288395877"},"_hasShrinkwrap":false,"readme":"[![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)\n[![npm version](https://img.shields.io/npm/v/compute-scroll-into-view.svg?style=flat-square)](https://www.npmjs.com/package/compute-scroll-into-view)\n[![gzip size][gzip-badge]][unpkg-dist]\n[![size][size-badge]][unpkg-dist]\n[![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)\n\n![compute-scroll-into-view](https://user-images.githubusercontent.com/81981/43024153-a2cc212c-8c6d-11e8-913b-b4d62efcf105.png)\n\nLower level API that is used by the [ponyfill](https://ponyfill.com) [scroll-into-view-if-needed](https://github.com/scroll-into-view/scroll-into-view-if-needed) to compute where (if needed) elements should scroll based on [options defined in the spec](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) and the [`scrollMode: \"if-needed\"` draft spec proposal](https://github.com/w3c/csswg-drafts/pull/1805).\nUse this if you want the smallest possible bundlesize and is ok with implementing the actual scrolling yourself.\n\nScrolling SVG elements are supported, as well as Shadow DOM elements. The [VisualViewport](https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport) API is also supported, ensuring scrolling works properly on modern devices. Quirksmode is also supported as long as you polyfill [`document.scrollingElement`](https://developer.mozilla.org/en-US/docs/Web/API/document/scrollingElement).\n\n- [Install](#install)\n- [Usage](#usage)\n- [API](#api)\n  - [compute(target, options)](#computetarget-options)\n  - [options](#options)\n    - [block](#block)\n    - [inline](#inline)\n    - [scrollMode](#scrollmode)\n    - [boundary](#boundary)\n    - [skipOverflowHiddenElements](#skipoverflowhiddenelements)\n\n# Install\n\n```bash\nnpm i compute-scroll-into-view\n```\n\nYou can also use it from a CDN:\n\n```js\nconst { compute } = await import('https://esm.sh/compute-scroll-into-view')\n```\n\n# Usage\n\n```js\nimport { compute } from 'compute-scroll-into-view'\n\nconst node = document.getElementById('hero')\n\n// same behavior as Element.scrollIntoView({block: \"nearest\", inline: \"nearest\"})\n// see: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView\nconst actions = compute(node, {\n  scrollMode: 'if-needed',\n  block: 'nearest',\n  inline: 'nearest',\n})\n\n// same behavior as Element.scrollIntoViewIfNeeded(true)\n// see: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded\nconst actions = compute(node, {\n  scrollMode: 'if-needed',\n  block: 'center',\n  inline: 'center',\n})\n\n// Then perform the scrolling, use scroll-into-view-if-needed if you don't want to implement this part\nactions.forEach(({ el, top, left }) => {\n  el.scrollTop = top\n  el.scrollLeft = left\n})\n```\n\n# API\n\n## compute(target, options)\n\n## options\n\nType: `Object`\n\n### [block](https://scroll-into-view.dev/#scroll-alignment)\n\nType: `'start' | 'center' | 'end' | 'nearest'`<br> Default: `'center'`\n\nControl the logical scroll position on the y-axis. The spec states that the `block` direction is related to the [writing-mode](https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode), but this is not implemented yet in this library.\nThis means that `block: 'start'` aligns to the top edge and `block: 'end'` to the bottom.\n\n### [inline](https://scroll-into-view.dev/#scroll-alignment)\n\nType: `'start' | 'center' | 'end' | 'nearest'`<br> Default: `'nearest'`\n\nLike `block` this is affected by the [writing-mode](https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode). In left-to-right pages `inline: 'start'` will align to the left edge. In right-to-left it should be flipped. This will be supported in a future release.\n\n### [scrollMode](https://scroll-into-view.dev/#scrolling-if-needed)\n\nType: `'always' | 'if-needed'`<br> Default: `'always'`\n\nThis is a proposed addition to the spec that you can track here: https://github.com/w3c/csswg-drafts/pull/5677\n\nThis library will be updated to reflect any changes to the spec and will provide a migration path.\nTo be backwards compatible with `Element.scrollIntoViewIfNeeded` if something is not 100% visible it will count as \"needs scrolling\". If you need a different visibility ratio your best option would be to implement an [Intersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).\n\n### [boundary](https://scroll-into-view.dev/#limit-propagation)\n\nType: `Element | Function`\n\nBy default there is no boundary. All the parent elements of your target is checked until it reaches the viewport ([`document.scrollingElement`](https://developer.mozilla.org/en-US/docs/Web/API/document/scrollingElement)) when calculating layout and what to scroll.\nBy passing a boundary you can short-circuit this loop depending on your needs:\n\n- Prevent the browser window from scrolling.\n- Scroll elements into view in a list, without scrolling container elements.\n\nYou can also pass a function to do more dynamic checks to override the scroll scoping:\n\n```js\nconst actions = compute(target, {\n  boundary: (parent) => {\n    // By default `overflow: hidden` elements are allowed, only `overflow: visible | clip` is skipped as\n    // this is required by the CSSOM spec\n    if (getComputedStyle(parent)['overflow'] === 'hidden') {\n      return false\n    }\n\n    return true\n  },\n})\n```\n\n### skipOverflowHiddenElements\n\nType: `Boolean`<br> Default: `false`\n\nBy default the [spec](https://drafts.csswg.org/cssom-view/#scrolling-box) states that `overflow: hidden` elements should be scrollable because it has [been used to allow programatic scrolling](https://drafts.csswg.org/css-overflow-3/#valdef-overflow-hidden). This behavior can sometimes lead to [scrolling issues](https://github.com/scroll-into-view/scroll-into-view-if-needed/pull/225#issue-186419520) when you have a node that is a child of an `overflow: hidden` node.\n\nThis package follows the convention [adopted by Firefox](https://hg.mozilla.org/integration/fx-team/rev/c48c3ec05012#l7.18) of setting a boolean option to _not_ scroll all nodes with `overflow: hidden` set.\n\n[gzip-badge]: https://img.shields.io/bundlephobia/minzip/compute-scroll-into-view?label=gzip%20size&style=flat-square\n[size-badge]: https://img.shields.io/bundlephobia/min/compute-scroll-into-view?label=size&style=flat-square\n[unpkg-dist]: https://unpkg.com/compute-scroll-into-view/dist/\n","publish_time":1736536235418,"_cnpm_publish_time":1736536235418,"dist-tags":{"latest":"3.1.1"}}