Skip to content

Commit 5960c1f

Browse files
committed
fix: update build tooling
BREAKING CHANGE: drops umd builds, and ships more modern syntax with ESM as baseline
1 parent ae9ebbd commit 5960c1f

16 files changed

+2008
-5249
lines changed

.gitignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,8 @@ typings/
6060
# next.js build output
6161
.next
6262

63-
# Typescript stuff
64-
typings
65-
src/*.js
66-
6763
lerna-debug.log
6864
dist
69-
es
70-
umd
7165
reports
7266
/index.js
7367
junit.xml

README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![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)
33
[![gzip size][gzip-badge]][unpkg-dist]
44
[![size][size-badge]][unpkg-dist]
5-
[![module formats: umd, cjs, and es][module-formats-badge]][unpkg-dist]
5+
[![module formats: cjs, esm][module-formats-badge]][unpkg-dist]
66
[![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)
77

88
![compute-scroll-into-view](https://user-images.githubusercontent.com/81981/43024153-a2cc212c-8c6d-11e8-913b-b4d62efcf105.png)
@@ -12,41 +12,49 @@ Use this if you want the smallest possible bundlesize and is ok with implementin
1212

1313
Scrolling 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).
1414

15+
- [Install](#install)
16+
- [Usage](#usage)
17+
- [API](#api)
18+
- [compute(target, options)](#computetarget-options)
19+
- [options](#options)
20+
- [block](#block)
21+
- [inline](#inline)
22+
- [scrollMode](#scrollmode)
23+
- [boundary](#boundary)
24+
- [skipOverflowHiddenElements](#skipoverflowhiddenelements)
25+
1526
## Install
1627

1728
```bash
1829
npm i compute-scroll-into-view
1930
```
2031

21-
The UMD build is also available on [unpkg](https://unpkg.com/compute-scroll-into-view/umd/):
32+
You can also use it from an CDN:
2233

23-
```html
24-
<script src="https://unpkg.com/compute-scroll-into-view/umd/compute-scroll-into-view.min.js"></script>
34+
```js
35+
const { default: compute } = await import(
36+
'https://esm.sh/compute-scroll-into-view'
37+
)
2538
```
2639

27-
You can find the library on `window.computeScrollIntoView`.
28-
2940
## Usage
3041

3142
```js
32-
// es6 import
33-
import computeScrollIntoView from 'compute-scroll-into-view'
34-
// or es5
35-
const computeScrollIntoView = require('compute-scroll-into-view')
43+
import compute from 'compute-scroll-into-view'
3644

3745
const node = document.getElementById('hero')
3846

3947
// same behavior as Element.scrollIntoView({block: "nearest", inline: "nearest"})
4048
// see: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
41-
const actions = computeScrollIntoView(node, {
49+
const actions = compute(node, {
4250
scrollMode: 'if-needed',
4351
block: 'nearest',
4452
inline: 'nearest',
4553
})
4654

4755
// same behavior as Element.scrollIntoViewIfNeeded(true)
4856
// see: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded
49-
const actions = computeScrollIntoView(node, {
57+
const actions = compute(node, {
5058
scrollMode: 'if-needed',
5159
block: 'center',
5260
inline: 'center',
@@ -61,7 +69,7 @@ actions.forEach(({ el, top, left }) => {
6169

6270
## API
6371

64-
### computeScrollIntoView(target, options)
72+
### compute(target, options)
6573

6674
### options
6775

@@ -102,7 +110,7 @@ By passing a boundary you can short-circuit this loop depending on your needs:
102110
You can also pass a function to do more dynamic checks to override the scroll scoping:
103111

104112
```js
105-
const actions = computeScrollIntoView(target, {
113+
const actions = compute(target, {
106114
boundary: (parent) => {
107115
// By default `overflow: hidden` elements are allowed, only `overflow: visible | clip` is skipped as
108116
// this is required by the CSSOM spec
@@ -123,11 +131,6 @@ By default the [spec](https://drafts.csswg.org/cssom-view/#scrolling-box) states
123131

124132
This 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.
125133

126-
# TypeScript support
127-
128-
This library ships with library definitions for TypeScript.
129-
130-
[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
131-
[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
132-
[unpkg-dist]: https://unpkg.com/compute-scroll-into-view/umd/
133-
[module-formats-badge]: https://img.shields.io/badge/module%20formats-umd%2C%20cjs%2C%20es-green.svg?style=flat-square
134+
[gzip-badge]: https://img.badgesize.io/https:/unpkg.com/compute-scroll-into-view/dist/index.js?label=gzip%20size&compression=gzip&style=flat-square
135+
[size-badge]: https://img.badgesize.io/https:/unpkg.com/compute-scroll-into-view/dist/index.js?label=size&style=flat-square
136+
[unpkg-dist]: https://unpkg.com/compute-scroll-into-view/dist/

integration/body.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
name="viewport"
55
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
66
/>
7-
<script src="../umd/compute-scroll-into-view.min.js"></script>
8-
<script src="./utils.js"></script>
7+
<script type="module" src="./utils.js"></script>
98
<style>
109
*,
1110
*:before,

integration/deeply_nested_overflow.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
name="viewport"
55
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
66
/>
7-
<script src="../umd/compute-scroll-into-view.min.js"></script>
8-
<script src="./utils.js"></script>
7+
<script type="module" src="./utils.js"></script>
98
<style>
109
html,
1110
body {

integration/iframe.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
name="viewport"
55
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
66
/>
7-
<script src="../umd/compute-scroll-into-view.min.js"></script>
8-
<script src="./utils.js"></script>
7+
<script type="module" src="./utils.js"></script>
98
<iframe
109
srcdoc="
1110
<div class='container' style='height: 100vh'></div>
File renamed without changes.

integration/nested_overflow.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
name="viewport"
55
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
66
/>
7-
<script src="../umd/compute-scroll-into-view.min.js"></script>
8-
<script src="./utils.js"></script>
7+
<script type="module" src="./utils.js"></script>
98
<style>
109
html,
1110
body {

integration/overflow_auto.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
name="viewport"
55
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
66
/>
7-
<script src="../umd/compute-scroll-into-view.min.js"></script>
8-
<script src="./utils.js"></script>
7+
<script type="module" src="./utils.js"></script>
98
<style>
109
html,
1110
body {

integration/target_same_height.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
name="viewport"
55
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
66
/>
7-
<script src="../umd/compute-scroll-into-view.min.js"></script>
8-
<script src="./utils.js"></script>
7+
<script type="module" src="./utils.js"></script>
98
<style>
109
html,
1110
body {

integration/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import compute from '../dist/index.js'
2+
window.computeScrollIntoView = compute
3+
14
window.mapActions = (item) => ({
25
el: (item.el.tagName.toLowerCase() + '.' + item.el.className).replace(
36
/\.$/,

0 commit comments

Comments
 (0)