@sharadox/scroll-web-library 0.4.2 → 0.5.0-development.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -8
- package/distribution/glide-into-view/index.d.ts +11 -0
- package/distribution/glide-into-view/index.d.ts.map +1 -0
- package/distribution/glide-into-view/index.js +16 -0
- package/distribution/glide-into-view/index.js.map +1 -0
- package/distribution/glide-into-view/type.d.ts +7 -0
- package/distribution/glide-into-view/type.d.ts.map +1 -0
- package/distribution/glide-into-view/type.js +2 -0
- package/distribution/glide-into-view/type.js.map +1 -0
- package/llms.txt +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Scrolling for React websites:
|
|
4
4
|
|
|
5
5
|
- **Smooth scrolling:** inertial scrolling with Lenis, including in-page anchor links that stop above a fixed header. A link to the page already open (the logo on the home page) glides back to the top instead of reloading. Smoothing turns off for visitors who prefer reduced motion; same-page links still skip the reload.
|
|
6
|
-
- **Glide:** `glideTo(top)` moves the page through the smooth scrolling, so code-driven moves ease like the visitor's own.
|
|
6
|
+
- **Glide:** `glideTo(top)` moves the page through the smooth scrolling, so code-driven moves ease like the visitor's own. `glideIntoView(element)` brings an element into view, clear of the top bar, when it isn't wholly in view (a form's thank-you after sending on a phone).
|
|
7
7
|
- **Scroll steps:** `useScrollSteps(section, count)` gives a tall pinned section that shows steps one after another (a timelapse, a story) one step per scroll gesture: one wheel turn, trackpad swipe or finger swipe. It doesn't take many to get from one step to the next.
|
|
8
8
|
- **Active section:** which section holds the middle of the screen, how far through it you are, and how far down the page. That's what section indicators and progress bars need.
|
|
9
9
|
|
|
@@ -15,13 +15,14 @@ pnpm add @sharadox/scroll-web-library
|
|
|
15
15
|
|
|
16
16
|
## API
|
|
17
17
|
|
|
18
|
-
| Import
|
|
19
|
-
|
|
|
20
|
-
| `…/smooth-scroll`
|
|
21
|
-
| `…/section-link`
|
|
22
|
-
| `…/active-section`
|
|
23
|
-
| `…/glide`
|
|
24
|
-
| `…/
|
|
18
|
+
| Import | Export |
|
|
19
|
+
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
20
|
+
| `…/smooth-scroll` | `<SmoothScroll duration? anchorOffset?>` (renders nothing; default 1.15 s and -60 px; `#top` glides to the top of any page; in a page or a layout, and a glide from one page never carries over to the next) |
|
|
21
|
+
| `…/section-link` | `<SectionLink href>`: Next.js `Link` for a section: on this page (`#id`) scrolling is left to `SmoothScroll` (`scroll={false}`); on another page (`/en#id`) Next.js scrolls there |
|
|
22
|
+
| `…/active-section` | `useActiveSection(ids)` → `{ active, within, page }` (keep `ids` stable, for example a module constant) |
|
|
23
|
+
| `…/glide` | `glideTo(top, { duration? })` |
|
|
24
|
+
| `…/glide-into-view` | `glideIntoView(element, { offset? = 96, duration? })`: glides the element's top to `offset` below the window's top when it isn't wholly in view |
|
|
25
|
+
| `…/scroll-steps` | `useScrollSteps(sectionRef, count, { duration? })` (0.9 s by default) |
|
|
25
26
|
|
|
26
27
|
## Develop
|
|
27
28
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GlideIntoViewOptions } from "@sharadox/scroll-web-library/glide-into-view/type";
|
|
2
|
+
/**
|
|
3
|
+
* Brings an element into view when it isn't wholly in view already: the page glides (through the smooth scrolling,
|
|
4
|
+
* like every other move) until the element's top sits `offset` pixels below the top of the window, clear of a fixed
|
|
5
|
+
* bar. For something that appears in place of something taller, such as a form's thank-you after sending on a phone.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* <div ref={(element) => element && glideIntoView(element)}>Thank you</div>
|
|
9
|
+
*/
|
|
10
|
+
export declare function glideIntoView(element: Element, { offset, duration }?: GlideIntoViewOptions): void;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/glide-into-view/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mDAAmD,CAAC;AAE9F;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,MAAW,EAAE,QAAQ,EAAE,GAAE,oBAAyB,QAInG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { glideTo } from "@sharadox/scroll-web-library/glide";
|
|
2
|
+
/**
|
|
3
|
+
* Brings an element into view when it isn't wholly in view already: the page glides (through the smooth scrolling,
|
|
4
|
+
* like every other move) until the element's top sits `offset` pixels below the top of the window, clear of a fixed
|
|
5
|
+
* bar. For something that appears in place of something taller, such as a form's thank-you after sending on a phone.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* <div ref={(element) => element && glideIntoView(element)}>Thank you</div>
|
|
9
|
+
*/
|
|
10
|
+
export function glideIntoView(element, { offset = 96, duration } = {}) {
|
|
11
|
+
const box = element.getBoundingClientRect();
|
|
12
|
+
if (box.top >= offset && box.bottom <= innerHeight)
|
|
13
|
+
return;
|
|
14
|
+
glideTo(Math.max(0, box.top + scrollY - offset), duration === undefined ? {} : { duration });
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/glide-into-view/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAG7D;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgB,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE,QAAQ,KAA2B,EAAE;IAClG,MAAM,GAAG,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAC5C,IAAI,GAAG,CAAC,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,WAAW;QAAE,OAAO;IAC3D,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,OAAO,GAAG,MAAM,CAAC,EAAE,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC/F,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface GlideIntoViewOptions {
|
|
2
|
+
/** The room kept above the element, for a fixed bar at the top: 96 pixels by default. */
|
|
3
|
+
offset?: number;
|
|
4
|
+
/** How long the glide takes, in seconds (with smooth scrolling). */
|
|
5
|
+
duration?: number;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/glide-into-view/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/glide-into-view/type.ts"],"names":[],"mappings":""}
|
package/llms.txt
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
- SmoothScroll works in a page or a layout (it starts afresh for every pathname). Each page's smoothing stops the moment the address is another page's (link, back or forward) and a new page stops the previous one's, so a glide or trackpad momentum from the old page never moves the new one; for 300 ms after a page opens, wheel and touch are left to the browser while Next.js places it (0.4.2).
|
|
9
9
|
- SmoothScroll also turns plain clicks on links to the current page (same path, no hash or query, no target, no modifier keys) into a scroll to the top, without reloading — with or without reduced motion.
|
|
10
10
|
- /glide: glideTo(top, { duration? }) — through the running SmoothScroll (Lenis) or window.scrollTo (smooth, or auto with reduced motion); registerGlider is internal to SmoothScroll
|
|
11
|
+
- /glide-into-view: glideIntoView(element, { offset? = 96, duration? }) — glides the element's top to offset below the window's top, only when it isn't wholly in view (0.5.0)
|
|
11
12
|
- /scroll-steps: useScrollSteps(sectionRef, count, { duration? = 0.9 }) — while the section is pinned, each wheel gesture (a pause of 180 ms starts a new one) or finger swipe (30 px+) glides exactly one step; step i sits at top + (i + 0.5) / count × (height − innerHeight); past the ends the page scrolls on
|
|
12
13
|
- 0.3.0: glide, scroll-steps
|
|
13
14
|
- 0.3.1: a finger swipe's step glide starts after the touch event, so smooth scrolling (Lenis) no longer stops it on phones
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/scroll-web-library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-development.11",
|
|
4
4
|
"description": "Scrolling for React websites: smooth inertial scrolling with anchor jumps (Lenis) and the active section with page progress.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENCA.md",
|