@jump-section/core 1.0.0 → 1.0.1
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 +86 -0
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @jump-section/core
|
|
2
|
+
|
|
3
|
+
Core scroll management library for jump-section. Framework-agnostic scroll navigation with intersection observer.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @jump-section/core
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @jump-section/core
|
|
11
|
+
# or
|
|
12
|
+
yarn add @jump-section/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { ScrollManager } from '@jump-section/core';
|
|
19
|
+
|
|
20
|
+
// Create a scroll manager instance
|
|
21
|
+
const manager = new ScrollManager({
|
|
22
|
+
offset: -80, // Offset for fixed headers (optional)
|
|
23
|
+
behavior: 'smooth', // Scroll behavior (optional)
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Register sections
|
|
27
|
+
const section1 = document.getElementById('section-1');
|
|
28
|
+
const section2 = document.getElementById('section-2');
|
|
29
|
+
|
|
30
|
+
manager.registerSection('section-1', section1);
|
|
31
|
+
manager.registerSection('section-2', section2);
|
|
32
|
+
|
|
33
|
+
// Scroll to a section
|
|
34
|
+
manager.scrollTo('section-1');
|
|
35
|
+
|
|
36
|
+
// Listen to active section changes
|
|
37
|
+
const unsubscribe = manager.onActiveChange((activeId) => {
|
|
38
|
+
console.log('Active section:', activeId);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Cleanup
|
|
42
|
+
manager.unregisterSection('section-1');
|
|
43
|
+
manager.destroy();
|
|
44
|
+
unsubscribe();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API
|
|
48
|
+
|
|
49
|
+
### `ScrollManager`
|
|
50
|
+
|
|
51
|
+
#### Constructor
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
new ScrollManager(options?: ScrollOptions)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Options:**
|
|
58
|
+
|
|
59
|
+
- `offset?: number` - Vertical offset in pixels (useful for fixed headers)
|
|
60
|
+
- `behavior?: ScrollBehavior` - Scroll behavior: `'smooth'` | `'instant'` | `'auto'`
|
|
61
|
+
|
|
62
|
+
#### Methods
|
|
63
|
+
|
|
64
|
+
##### `registerSection(id: string, element: HTMLElement): void`
|
|
65
|
+
|
|
66
|
+
Registers a section element to be tracked by the scroll manager.
|
|
67
|
+
|
|
68
|
+
##### `unregisterSection(id: string): void`
|
|
69
|
+
|
|
70
|
+
Unregisters a section from tracking.
|
|
71
|
+
|
|
72
|
+
##### `scrollTo(id: string): void`
|
|
73
|
+
|
|
74
|
+
Scrolls to the specified section.
|
|
75
|
+
|
|
76
|
+
##### `onActiveChange(callback: (id: string | null) => void): () => void`
|
|
77
|
+
|
|
78
|
+
Subscribes to active section changes. Returns an unsubscribe function.
|
|
79
|
+
|
|
80
|
+
##### `destroy(): void`
|
|
81
|
+
|
|
82
|
+
Cleans up the scroll manager and removes all observers.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
ISC
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jump-section/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Core scroll management library for jump-section",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"scroll",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"types": "dist/index.d.ts",
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"files": [
|
|
23
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md"
|
|
24
25
|
],
|
|
25
26
|
"scripts": {
|
|
26
27
|
"build": "tsup",
|