planning
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s

This commit is contained in:
2024-10-14 09:15:30 +02:00
parent bcba00a730
commit 6e64e138e2
21059 changed files with 2317811 additions and 1 deletions

21
node_modules/scroll-into-view-if-needed/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Cody Olsen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

415
node_modules/scroll-into-view-if-needed/README.md generated vendored Normal file
View File

@@ -0,0 +1,415 @@
[![npm stat](https://img.shields.io/npm/dm/scroll-into-view-if-needed.svg?style=flat-square)](https://npm-stat.com/charts.html?package=scroll-into-view-if-needed)
[![npm version](https://img.shields.io/npm/v/scroll-into-view-if-needed.svg?style=flat-square)](https://www.npmjs.com/package/scroll-into-view-if-needed)
[![gzip size][gzip-badge]][unpkg-dist]
[![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)
[![BrowserStack Status](https://www.browserstack.com/automate/badge.svg?style=flat-square&badge_key=ejZ6OUtTaS9rZFFOYzlkeHlwTzMwSWxpR0FzWFcwOW5TS3ROTmlSdXMrVT0tLVhrVk9La2lCb1o4Y05mcmNXVnAvdkE9PQ==--d17668b8aba5091e4ef3a58927b8209e50b0a788)](https://www.browserstack.com/automate/public-build/ejZ6OUtTaS9rZFFOYzlkeHlwTzMwSWxpR0FzWFcwOW5TS3ROTmlSdXMrVT0tLVhrVk9La2lCb1o4Y05mcmNXVnAvdkE9PQ==--d17668b8aba5091e4ef3a58927b8209e50b0a788)
![scroll-into-view-if-needed](https://user-images.githubusercontent.com/81981/39476436-34a4f3ae-4d5c-11e8-9d1c-7fa2fa6288a0.png)
This used to be a [ponyfill](https://ponyfill.com) for
`Element.scrollIntoViewIfNeeded`. Since then the CSS working group have decided to implement its features in `Element.scrollIntoView` as the option `scrollMode: "if-needed"`. Thus this library got rewritten to implement that spec instead of the soon to be deprecated one.
## [Demo](https://scroll-into-view.dev)
## Install
```bash
npm i scroll-into-view-if-needed
```
The UMD build is also available on [unpkg](https://unpkg.com/scroll-into-view-if-needed/umd/):
```html
<script src="https://unpkg.com/scroll-into-view-if-needed/umd/scroll-into-view-if-needed.min.js"></script>
```
You can find the library on `window.scrollIntoView`.
## Usage
```js
// es6 import
import scrollIntoView from 'scroll-into-view-if-needed'
// or es5
const scrollIntoView = require('scroll-into-view-if-needed')
const node = document.getElementById('hero')
// similar behavior as Element.scrollIntoView({block: "nearest", inline: "nearest"})
// only that it is a no-op if `node` is already visible
// see: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
// same behavior as Element.scrollIntoViewIfNeeded()
// see: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded
scrollIntoView(node, {
scrollMode: 'if-needed',
block: 'nearest',
inline: 'nearest',
})
// same behavior as Element.scrollIntoViewIfNeeded(true) without the "IfNeeded" behavior
// see: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded
scrollIntoView(node, { block: 'center', inline: 'center' })
// scrollMode is "always" by default
// smooth scroll if the browser supports it and if the element isn't visible
scrollIntoView(node, { behavior: 'smooth', scrollMode: 'if-needed' })
```
### Ponyfill smooth scrolling
What does ponyfilling smooth scrolling mean, and why is it implemented in [`smooth-scroll-into-view-if-needed`](https://github.com/scroll-into-view/smooth-scroll-into-view-if-needed) instead?
The answer is bundlesize. If this package adds smooth scrolling to browsers that's missing it then the overall bundlesize increases regardless of wether you use this feature or not.
Put it this way:
```js
import scrollIntoView from 'scroll-into-view-if-needed'
// Even if all you do is this
scrollIntoView(node, { scrollMode: 'if-needed' })
// You would end up with the same bundlesize as people who need
// smooth scrolling to work in browsers that don't support it natively
scrollIntoView(node, { behavior: 'smooth', scrollMode: 'if-needed' })
```
That's why only native smooth scrolling is supported out of the box. There are two common ways you can smooth scroll browsers that don't support it natively. Below is all three, which one is best for you depends on what is the most important to your use case:: load time, consistency or quality.
##### Load time
In many scenarios smooth scrolling can be used as a progressive enhancement. If the user is on a browser that don't implement smooth scrolling it'll simply scroll instantly and your bundlesize is only as large as it has to be.
```js
import scrollIntoView from 'scroll-into-view-if-needed'
scrollIntoView(node, { behavior: 'smooth' })
```
##### Consistency
If a consistent smooth scrolling experience is a priority and you really don't want any surprises between different browsers and enviroments. In other words don't want to be affected by how a vendor might implement native smooth scrolling, then [`smooth-scroll-into-view-if-needed`](https://github.com/scroll-into-view/smooth-scroll-into-view-if-needed) is your best option. It ensures the same smooth scrolling experience for every browser.
```js
import smoothScrollIntoView from 'smooth-scroll-into-view-if-needed'
smoothScrollIntoView(node, { behavior: 'smooth' })
```
##### Quality
If you want to use native smooth scrolling when it's available, and fallback to the smooth scrolling ponyfill:
```js
import scrollIntoView from 'scroll-into-view-if-needed'
import smoothScrollIntoView from 'smooth-scroll-into-view-if-needed'
const scrollIntoViewSmoothly =
'scrollBehavior' in document.documentElement.style
? scrollIntoView
: smoothScrollIntoView
scrollIntoViewSmoothly(node, { behavior: 'smooth' })
```
## API
### scrollIntoView(target, [options])
> New API introduced in `v1.3.0`
### options
Type: `Object`
#### behavior
Type: `'auto' | 'smooth' | Function`<br> Default: `'auto'`
> Introduced in `v2.1.0`
##### `'auto'`
The auto option unlocks a few interesting opportunities.
The browser will decide based on user preferences wether it should smooth scroll or not.
On top of that you can control/override scrolling behavior through the [`scroll-behavior`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior) CSS property.
Some people get [motion sick from animations](https://css-tricks.com/smooth-scrolling-accessibility/#article-header-id-5). You can use CSS to turn off smooth scrolling in those cases to avoid making them dizzy:
```css
html,
.scroll-container {
overflow: scroll;
}
html,
.scroll-container {
scroll-behavior: smooth;
}
@media (prefers-reduced-motion) {
html,
.scroll-container {
scroll-behavior: auto;
}
}
```
##### `'smooth'`
Using `behavior: 'smooth'` is the easiest way to smooth scroll an element as it does not require any CSS, just a browser that implements it. [More information.](#ponyfill-smooth-scrolling)
##### `Function`
When given a function then this library will only calculate what should be scrolled and leave it up to you to perform the actual scrolling.
The callback is given an array over actions. Each action contain a reference to an element that should be scrolled, with its top and left scrolling coordinates.
What you return is passed through, allowing you to implement a Promise interface if you want to (check [`smooth-scroll-into-view-if-needed`](https://github.com/scroll-into-view/smooth-scroll-into-view-if-needed) to see an example of that).
```js
import scrollIntoView from 'scroll-into-view-if-needed'
const node = document.getElementById('hero')
scrollIntoView(node, {
// Your scroll actions will always be an array, even if there is nothing to scroll
behavior: (actions) =>
// list is sorted from innermost (closest parent to your target) to outermost (often the document.body or viewport)
actions.forEach(({ el, top, left }) => {
// implement the scroll anyway you want
el.scrollTop = top
el.scrollLeft = left
// If you need the relative scroll coordinates, for things like window.scrollBy style logic or whatever, just do the math
const offsetTop = el.scrollTop - top
const offsetLeft = el.scrollLeft - left
}),
// all the other options (scrollMode, block, inline) still work, so you don't need to reimplement them (unless you really really want to)
})
```
Check the demo to see an [example with popmotion and a spring transition](https://scroll-into-view.dev/#custom-transition).
> If you only need the custom behavior you might be better off by using the compute library directly: https://github.com/scroll-into-view/compute-scroll-into-view
#### [block](https://scroll-into-view.dev/#scroll-alignment)
Type: `'start' | 'center' | 'end' | 'nearest'`<br> Default: `'center'`
> Introduced in `v2.1.0`
[More info.](https://github.com/scroll-into-view/compute-scroll-into-view#block)
#### [inline](https://scroll-into-view.dev/#scroll-alignment)
Type: `'start' | 'center' | 'end' | 'nearest'`<br> Default: `'nearest'`
> Introduced in `v2.1.0`
[More info.](https://github.com/scroll-into-view/compute-scroll-into-view#inline)
#### [scrollMode](https://scroll-into-view.dev/#scrolling-if-needed)
Type: `'always' | 'if-needed'`<br> Default: `'always'`
> Introduced in `v2.1.0`
[More info.](https://github.com/scroll-into-view/compute-scroll-into-view#scrollmode)
#### [boundary](https://scroll-into-view.dev/#limit-propagation)
Type: `Element | Function`
> `Function` introduced in `v2.1.0`, `Element` introduced in `v1.1.0`
[More info.](https://github.com/scroll-into-view/compute-scroll-into-view#boundary)
#### skipOverflowHiddenElements
Type: `Boolean`<br> Default: `false`
> Introduced in `v2.2.0`
[More info.](https://github.com/scroll-into-view/compute-scroll-into-view#skipoverflowhiddenelements)
# TypeScript support
When the library itself is built on TypeScript there's no excuse for not publishing great library definitions!
This goes beyond just checking if you misspelled `behavior: 'smoooth'` to the return type of a custom behavior:
```typescript
const scrolling = scrollIntoView(document.body, {
behavior: actions => {
return new Promise(
...
)
},
})
// TypeScript understands that scrolling is a Promise, you can safely await on it
scrolling.then(() => console.log('done scrolling'))
```
You can optionally use a generic to ensure that `options.behavior` is the expected type.
It can be useful if the custom behavior is implemented in another module:
```typescript
const customBehavior = actions => {
return new Promise(
...
)
}
const scrolling = scrollIntoView<Promise<any>>(document.body, {
behavior: customBehavior
})
// throws if customBehavior does not return a promise
```
The options are available for you if you are wrapping this libary in another abstraction (like a React component):
```typescript
import scrollIntoView, { Options } from 'scroll-into-view-if-needed'
interface CustomOptions extends Options {
useBoundary?: boolean
}
function scrollToTarget(selector, options: Options = {}) {
const { useBoundary = false, ...scrollOptions } = options
return scrollIntoView(document.querySelector(selector), scrollOptions)
}
```
# Breaking API changes from v1
Since v1 ponyfilled Element.scrollIntoViewIfNeeded, while v2 ponyfills Element.scrollIntoView, there are breaking changes from the differences in their APIs.
The biggest difference is that the new behavior follows the spec, so the "if-needed" behavior is **not enabled by default:**
##### v1
```js
import scrollIntoViewIfNeeded from 'scroll-into-view-if-needed'
// Only scrolls into view if needed, and to the nearest edge
scrollIntoViewIfNeeded(target)
```
##### v2
```js
import scrollIntoView from 'scroll-into-view-if-needed'
// Must provide these options to behave the same way as v1 default
scrollIntoView(target, { block: 'nearest', scrollMode: 'if-needed' })
```
#### centerIfNeeded
The old `Element.scrollIntoView` api only had two settings, align to top or bottom. [`Element.scrollIntoViewIfNeeded`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded) had two more, align to the center or nearest edge.
The `Element.scrollIntoView` spec now supports these two modes as `block: 'center'` and `block: 'nearest'`.
Breaking changes sucks, but on the plus side your code is now more portable and will make this library easier to delete from your codebase on the glorious day browser support is good enough.
##### v1
```js
import scrollIntoViewIfNeeded from 'scroll-into-view-if-needed'
// v1.3.x and later
scrollIntoViewIfNeeded(target, { centerIfNeeded: true })
scrollIntoViewIfNeeded(target, { centerIfNeeded: false })
// v1.2.x and earlier
scrollIntoViewIfNeeded(target, true)
scrollIntoViewIfNeeded(target, false)
```
##### v2
```js
import scrollIntoView from 'scroll-into-view-if-needed'
scrollIntoView(target, { block: 'center' })
scrollIntoView(target, { block: 'nearest' })
```
#### duration
[More information.](#ponyfill-smooth-scrolling)
##### v1
```js
import scrollIntoViewIfNeeded from 'scroll-into-view-if-needed'
scrollIntoViewIfNeeded(target, { duration: 300 })
```
##### v2
```js
import scrollIntoView from 'scroll-into-view-if-needed'
// or
import scrollIntoView from 'smooth-scroll-into-view-if-needed'
scrollIntoView(target, { behavior: 'smooth' })
```
#### easing
This feature is removed, but you can achieve the same thing by implementing [`behavior: Function`](#function).
#### handleScroll
This is replaced with [`behavior: Function`](#function) with one key difference. Instead of firing once per element that should be scrolled, the new API only fire once and instead give you an array so you can much easier batch and scroll multiple elements at the same time. Or sync scrolling with another element if that's the kind of stuff you're into, I don't judge.
```diff
-import scrollIntoViewIfNeeded from 'scroll-into-view-if-needed'
+import scrollIntoView from 'scroll-into-view-if-needed'
-scrollIntoViewIfNeeded(node, {handleScroll: (el, {scrollTop, scrollLeft}) => {
- el.scrollTop = scrollTop
- el.scrollLeft = scrollLeft
-}})
+scrollIntoView(node, {behavior: actions.forEach(({el, top, left}) => {
+ el.scrollTop = top
+ el.scrollLeft = left
+})})
```
#### offset
This was always a buggy feature and warned against using in v1 as it might get dropped.
It's much safer to use CSS wrapper elements for this kind of thing.
### scrollIntoViewIfNeeded(target, [centerIfNeeded], [animateOptions], [finalElement], [offsetOptions])
This API signature were warned to be dropped in `v2.0.0`, and it was.
# Related packages
- [compute-scroll-into-view](https://www.npmjs.com/package/compute-scroll-into-view) - the engine used by this library.
- [smooth-scroll-into-view-if-needed](https://www.npmjs.com/package/smooth-scroll-into-view-if-needed) ponyfills smooth scrolling.
- [react-scroll-into-view-if-needed](https://www.npmjs.com/package/react-scroll-into-view-if-needed) A thin wrapper to scroll your component into view.
- [scroll-polyfill](https://www.npmjs.com/package/scroll-polyfill) polyfills smooth scrolling.
- [Don't be shy, add yours!](https://github.com/scroll-into-view/scroll-into-view-if-needed/edit/main/README.md)
# Who's using this
- [zeit.co/docs](https://github.com/zeit/docs) Documentation of ZEIT Now and other services.
- [Selenium IDE](https://github.com/SeleniumHQ/selenium-ide) An integrated development environment for Selenium scripts.
- [Box UI Elements](https://github.com/box/box-ui-elements) Box UI Elements are pre-built UI components that allow developers to add elements of the main Box web application into their own applications.
- [react-responsive-ui](https://github.com/catamphetamine/react-responsive-ui) Responsive React UI components.
- [Mineral UI](https://github.com/mineral-ui/mineral-ui)
A design system and React component library for the web that lets you quickly build high-quality, accessible apps.
- [Covalent](https://github.com/Teradata/covalent) Teradata UI Platform built on Angular Material.
- [docs.expo.io](https://github.com/expo/expo-docs) Documentation for Expo, its SDK, client and services.
- [Add yourself to the list 😉](https://github.com/scroll-into-view/scroll-into-view-if-needed/edit/main/README.md)
[gzip-badge]: http://img.badgesize.io/https://unpkg.com/scroll-into-view-if-needed/umd/scroll-into-view-if-needed.min.js?compression=gzip&label=gzip%20size&style=flat-square
[size-badge]: http://img.badgesize.io/https://unpkg.com/scroll-into-view-if-needed/umd/scroll-into-view-if-needed.min.js?label=size&style=flat-square
[unpkg-dist]: https://unpkg.com/scroll-into-view-if-needed/umd/
[module-formats-badge]: https://img.shields.io/badge/module%20formats-umd%2C%20cjs%2C%20es-green.svg?style=flat-square
## Sponsors
Thanks to [BrowserStack](https://www.browserstack.com) for sponsoring cross browser and device testing 😄
<a href="https://www.browserstack.com" target="_blank"><img src="https://www.browserstack.com/images/layout/logo.svg"></a>

52
node_modules/scroll-into-view-if-needed/es/index.js generated vendored Normal file
View File

@@ -0,0 +1,52 @@
import compute from 'compute-scroll-into-view';
function isOptionsObject(options) {
return options === Object(options) && Object.keys(options).length !== 0;
}
function defaultBehavior(actions, behavior) {
if (behavior === void 0) {
behavior = 'auto';
}
var canSmoothScroll = ('scrollBehavior' in document.body.style);
actions.forEach(function (_ref) {
var el = _ref.el,
top = _ref.top,
left = _ref.left;
if (el.scroll && canSmoothScroll) {
el.scroll({
top: top,
left: left,
behavior: behavior
});
} else {
el.scrollTop = top;
el.scrollLeft = left;
}
});
}
function getOptions(options) {
if (options === false) {
return {
block: 'end',
inline: 'nearest'
};
}
if (isOptionsObject(options)) {
return options;
}
return {
block: 'start',
inline: 'nearest'
};
}
function scrollIntoView(target, options) {
var isTargetAttached = target.isConnected || target.ownerDocument.documentElement.contains(target);
if (isOptionsObject(options) && typeof options.behavior === 'function') {
return options.behavior(isTargetAttached ? compute(target, options) : []);
}
if (!isTargetAttached) {
return;
}
var computeOptions = getOptions(options);
return defaultBehavior(compute(target, computeOptions), computeOptions.behavior);
}
export default scrollIntoView;

1
node_modules/scroll-into-view-if-needed/es/types.js generated vendored Normal file
View File

@@ -0,0 +1 @@
export {};

59
node_modules/scroll-into-view-if-needed/index.js generated vendored Normal file
View File

@@ -0,0 +1,59 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _computeScrollIntoView = _interopRequireDefault(require("compute-scroll-into-view"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function isOptionsObject(options) {
return options === Object(options) && Object.keys(options).length !== 0;
}
function defaultBehavior(actions, behavior) {
if (behavior === void 0) {
behavior = 'auto';
}
var canSmoothScroll = ('scrollBehavior' in document.body.style);
actions.forEach(function (_ref) {
var el = _ref.el,
top = _ref.top,
left = _ref.left;
if (el.scroll && canSmoothScroll) {
el.scroll({
top: top,
left: left,
behavior: behavior
});
} else {
el.scrollTop = top;
el.scrollLeft = left;
}
});
}
function getOptions(options) {
if (options === false) {
return {
block: 'end',
inline: 'nearest'
};
}
if (isOptionsObject(options)) {
return options;
}
return {
block: 'start',
inline: 'nearest'
};
}
function scrollIntoView(target, options) {
var isTargetAttached = target.isConnected || target.ownerDocument.documentElement.contains(target);
if (isOptionsObject(options) && typeof options.behavior === 'function') {
return options.behavior(isTargetAttached ? (0, _computeScrollIntoView["default"])(target, options) : []);
}
if (!isTargetAttached) {
return;
}
var computeOptions = getOptions(options);
return defaultBehavior((0, _computeScrollIntoView["default"])(target, computeOptions), computeOptions.behavior);
}
var _default = scrollIntoView;
exports["default"] = _default;
module.exports = exports.default;

119
node_modules/scroll-into-view-if-needed/package.json generated vendored Normal file
View File

@@ -0,0 +1,119 @@
{
"name": "scroll-into-view-if-needed",
"version": "2.2.31",
"description": "Ponyfill for upcoming Element.scrollIntoView() APIs like scrollMode: if-needed, behavior: smooth and block: center",
"keywords": [
"behavior-smooth",
"if-needed",
"polyfill",
"ponyfill",
"scroll",
"scroll-into-view",
"scrollIntoView",
"scrollIntoViewIfNeeded",
"scrollMode",
"smooth",
"smoothscroll",
"typescript"
],
"homepage": "https://scroll-into-view.dev",
"repository": {
"type": "git",
"url": "git+https://github.com/scroll-into-view/scroll-into-view-if-needed.git"
},
"license": "MIT",
"author": "Cody Olsen",
"sideEffects": false,
"exports": {
".": {
"types": "./typings/index.d.ts",
"source": "./src/index.ts",
"import": "./es/index.js",
"require": "./index.js",
"default": "./es/index.js"
},
"./package.json": "./package.json"
},
"main": "index.js",
"module": "es/index.js",
"typings": "typings/index.d.ts",
"files": [
"es",
"typings",
"umd"
],
"scripts": {
"prebuild": "npm run clean",
"build": "npm run build:d.ts && npm run build:cjs && npm run build:es && npm run build:umd && npm run build:umd.min",
"build:cjs": "cross-env BABEL_ENV=cjs babel src -d . --extensions '.ts'",
"build:d.ts": "tsc --emitDeclarationOnly",
"build:es": "cross-env BABEL_ENV=es babel src -d es --extensions '.ts'",
"build:umd": "cross-env BABEL_ENV=umd NODE_ENV=development rollup -c -f umd -o umd/scroll-into-view-if-needed.js",
"build:umd.min": "cross-env BABEL_ENV=umd NODE_ENV=production rollup -c -f umd -o umd/scroll-into-view-if-needed.min.js",
"clean": "rimraf 'umd' 'es' 'typings'",
"dev": "concurrently 'tsc --noEmit --watch' 'tsc --noEmit -p tests/typescript --watch' 'npm run build:cjs --watch' 'npm run build:es --watch' 'npm run build:umd --watch' 'npm run build:umd.min --watch'",
"lint": "eslint ./integration-examples",
"precommit": "lint-staged",
"prepublishOnly": "npm run build",
"typecheck": "tsc --noEmit && tsc --noEmit -p tests/typescript"
},
"browserify": {
"transform": [
"loose-envify"
]
},
"prettier": {
"semi": false,
"singleQuote": true,
"overrides": [
{
"files": ".babelrc",
"options": {
"parser": "json"
}
}
]
},
"dependencies": {
"compute-scroll-into-view": "^1.0.20"
},
"devDependencies": {
"@babel/cli": "^7.19.3",
"@babel/core": "^7.20.5",
"@babel/plugin-external-helpers": "^7.18.6",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@sanity/semantic-release-preset": "^2.0.2",
"babel-eslint": "^10.1.0",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-dev-expression": "^0.2.3",
"concurrently": "^7.6.0",
"cross-env": "^7.0.3",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-react": "^7.31.11",
"flowgen": "^1.20.1",
"husky": "^7.0.4",
"lint-staged": "^12.5.0",
"prettier": "^2.8.0",
"prettier-plugin-packagejson": "^2.3.0",
"rimraf": "^3.0.2",
"rollup": "^2.79.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^7.0.2",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.9.3"
},
"bundlesize": [
{
"path": "./umd/scroll-into-view-if-needed.min.js",
"maxSize": "3.3 kB",
"compression": "none"
}
]
}

View File

@@ -0,0 +1,13 @@
import { CustomScrollBehaviorCallback, Options as BaseOptions, ScrollBehavior } from './types';
export interface StandardBehaviorOptions extends BaseOptions {
behavior?: ScrollBehavior;
}
export interface CustomBehaviorOptions<T> extends BaseOptions {
behavior: CustomScrollBehaviorCallback<T>;
}
export interface Options<T = any> extends BaseOptions {
behavior?: ScrollBehavior | CustomScrollBehaviorCallback<T>;
}
declare function scrollIntoView<T>(target: Element, options: CustomBehaviorOptions<T>): T;
declare function scrollIntoView(target: Element, options?: Options | boolean): void;
export default scrollIntoView;

View File

@@ -0,0 +1,19 @@
export type ScrollBehavior = 'auto' | 'smooth';
export type ScrollLogicalPosition = 'start' | 'center' | 'end' | 'nearest';
export type ScrollMode = 'always' | 'if-needed';
export type SkipOverflowHiddenElements = boolean;
export interface Options {
block?: ScrollLogicalPosition;
inline?: ScrollLogicalPosition;
scrollMode?: ScrollMode;
boundary?: CustomScrollBoundary;
skipOverflowHiddenElements?: SkipOverflowHiddenElements;
}
export type CustomScrollBoundaryCallback = (parent: Element) => boolean;
export type CustomScrollBoundary = Element | CustomScrollBoundaryCallback | null;
export interface CustomScrollAction {
el: Element;
top: number;
left: number;
}
export type CustomScrollBehaviorCallback<T> = (actions: CustomScrollAction[]) => T;

View File

@@ -0,0 +1,62 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.scrollIntoView = factory());
})(this, (function () { 'use strict';
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 r=getComputedStyle(t,null);return e(r.overflowY,n)||e(r.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 r(t,e,n,r,i,o,l,d){return o<t&&l>e||o>t&&l<e?0:o<=t&&d<=n||l>=e&&d>=n?o-t-r:l>e&&d<n||o<t&&d>n?l-e+i:0}var i=function(e,i){var o=window,l=i.scrollMode,d=i.block,f=i.inline,h=i.boundary,u=i.skipOverflowHiddenElements,s="function"==typeof h?h:function(t){return t!==h};if(!t(e))throw new TypeError("Invalid target");for(var a,c,g=document.scrollingElement||document.documentElement,p=[],m=e;t(m)&&s(m);){if((m=null==(c=(a=m).parentElement)?a.getRootNode().host||null:c)===g){p.push(m);break}null!=m&&m===document.body&&n(m)&&!n(document.documentElement)||null!=m&&n(m,u)&&p.push(m);}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<p.length;k++){var B=p[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?r(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:r(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?r(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:r(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 isOptionsObject(options) {
return options === Object(options) && Object.keys(options).length !== 0;
}
function defaultBehavior(actions, behavior) {
if (behavior === void 0) {
behavior = 'auto';
}
var canSmoothScroll = ('scrollBehavior' in document.body.style);
actions.forEach(function (_ref) {
var el = _ref.el,
top = _ref.top,
left = _ref.left;
if (el.scroll && canSmoothScroll) {
el.scroll({
top: top,
left: left,
behavior: behavior
});
} else {
el.scrollTop = top;
el.scrollLeft = left;
}
});
}
function getOptions(options) {
if (options === false) {
return {
block: 'end',
inline: 'nearest'
};
}
if (isOptionsObject(options)) {
return options;
}
return {
block: 'start',
inline: 'nearest'
};
}
function scrollIntoView(target, options) {
var isTargetAttached = target.isConnected || target.ownerDocument.documentElement.contains(target);
if (isOptionsObject(options) && typeof options.behavior === 'function') {
return options.behavior(isTargetAttached ? i(target, options) : []);
}
if (!isTargetAttached) {
return;
}
var computeOptions = getOptions(options);
return defaultBehavior(i(target, computeOptions), computeOptions.behavior);
}
return scrollIntoView;
}));

View File

@@ -0,0 +1 @@
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).scrollIntoView=t()}(this,(function(){"use strict";function e(e){return"object"==typeof e&&null!=e&&1===e.nodeType}function t(e,t){return(!t||"hidden"!==e)&&"visible"!==e&&"clip"!==e}function n(e,n){if(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth){var o=getComputedStyle(e,null);return t(o.overflowY,n)||t(o.overflowX,n)||function(e){var t=function(e){if(!e.ownerDocument||!e.ownerDocument.defaultView)return null;try{return e.ownerDocument.defaultView.frameElement}catch(e){return null}}(e);return!!t&&(t.clientHeight<e.scrollHeight||t.clientWidth<e.scrollWidth)}(e)}return!1}function o(e,t,n,o,i,r,l,f){return r<e&&l>t||r>e&&l<t?0:r<=e&&f<=n||l>=t&&f>=n?r-e-o:l>t&&f<n||r<e&&f>n?l-t+i:0}var i=function(t,i){var r=window,l=i.scrollMode,f=i.block,u=i.inline,c=i.boundary,d=i.skipOverflowHiddenElements,s="function"==typeof c?c:function(e){return e!==c};if(!e(t))throw new TypeError("Invalid target");for(var a,h,p=document.scrollingElement||document.documentElement,m=[],g=t;e(g)&&s(g);){if((g=null==(h=(a=g).parentElement)?a.getRootNode().host||null:h)===p){m.push(g);break}null!=g&&g===document.body&&n(g)&&!n(document.documentElement)||null!=g&&n(g,d)&&m.push(g)}for(var v=r.visualViewport?r.visualViewport.width:innerWidth,w=r.visualViewport?r.visualViewport.height:innerHeight,b=window.scrollX||pageXOffset,y=window.scrollY||pageYOffset,W=t.getBoundingClientRect(),H=W.height,E=W.width,M=W.top,T=W.right,V=W.bottom,k=W.left,x="start"===f||"nearest"===f?M:"end"===f?V:M+H/2,I="center"===u?k+E/2:"end"===u?T:k,C=[],O=0;O<m.length;O++){var j=m[O],B=j.getBoundingClientRect(),D=B.height,R=B.width,L=B.top,X=B.right,Y=B.bottom,S=B.left;if("if-needed"===l&&M>=0&&k>=0&&V<=w&&T<=v&&M>=L&&V<=Y&&k>=S&&T<=X)return C;var N=getComputedStyle(j),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 j?j.offsetWidth-j.clientWidth-q-A:0,P="offsetHeight"in j?j.offsetHeight-j.clientHeight-z-F:0,Q="offsetWidth"in j?0===j.offsetWidth?0:R/j.offsetWidth:0,U="offsetHeight"in j?0===j.offsetHeight?0:D/j.offsetHeight:0;if(p===j)G="start"===f?x:"end"===f?x-w:"nearest"===f?o(y,y+w,w,z,F,y+x,y+x+H,H):x-w/2,J="start"===u?I:"center"===u?I-v/2:"end"===u?I-v:o(b,b+v,v,q,A,b+I,b+I+E,E),G=Math.max(0,G+y),J=Math.max(0,J+b);else{G="start"===f?x-L-z:"end"===f?x-Y+F+P:"nearest"===f?o(L,Y,D,z,F+P,x,x+H,H):x-(L+D/2)+P/2,J="start"===u?I-S-q:"center"===u?I-(S+R/2)+K/2:"end"===u?I-X+A+K:o(S,X,R,q,A+K,I,I+E,E);var Z=j.scrollLeft,$=j.scrollTop;x+=$-(G=Math.max(0,Math.min($+G/U,j.scrollHeight-D/U+P))),I+=Z-(J=Math.max(0,Math.min(Z+J/Q,j.scrollWidth-R/Q+K)))}C.push({el:j,top:G,left:J})}return C};function r(e){return e===Object(e)&&0!==Object.keys(e).length}return function(e,t){var n=e.isConnected||e.ownerDocument.documentElement.contains(e);if(r(t)&&"function"==typeof t.behavior)return t.behavior(n?i(e,t):[]);if(n){var o=function(e){return!1===e?{block:"end",inline:"nearest"}:r(e)?e:{block:"start",inline:"nearest"}}(t);return function(e,t){void 0===t&&(t="auto");var n="scrollBehavior"in document.body.style;e.forEach((function(e){var o=e.el,i=e.top,r=e.left;o.scroll&&n?o.scroll({top:i,left:r,behavior:t}):(o.scrollTop=i,o.scrollLeft=r)}))}(i(e,o),o.behavior)}}}));