Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions docs/src/app/[lang]/docs/core/en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,43 @@ The main class that orchestrates section detection and scrolling.
const manager = new ScrollManager({
offset: -80,
behavior: 'smooth',
hash: false,
keyboard: false,
debug: false,
rootMargin: '-20% 0px -60% 0px',
focusActiveSection: false,
stickyElements: [],
easing: undefined,
});
```

### Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `offset` | `number` | `0` | Fixed header offset (px) |
| `behavior` | `'smooth' \| 'auto' \| 'instant'` | `'smooth'` | Scroll behavior |
| `hash` | `boolean` | `false` | Sync URL hash with active section |
| `keyboard` | `boolean` | `false` | Alt+Arrow keyboard navigation |
| `debug` | `boolean` | `false` | Debug mode |
| `rootMargin` | `string` | `'-20% 0px -60% 0px'` | IntersectionObserver rootMargin |
| `focusActiveSection` | `boolean` | `false` | Focus section after scroll |
| `stickyElements` | `string[] \| HTMLElement[]` | `[]` | Sticky header/footer elements |
| `easing` | `(t: number) => number` | `undefined` | Custom easing function |

### Methods

- `registerSection(id: string, element: HTMLElement)`: Register a new section to be tracked.
- `registerSection(id: string, element: HTMLElement)`: Register a new section to be tracked. Automatically applies `role="region"` and `aria-labelledby`.
- `unregisterSection(id: string)`: Stop tracking a section.
- `scrollTo(id: string)`: Programmatically scroll to a registered section.
- `onActiveChange(callback: (id: string | null) => void)`: Subscribe to active section changes.
- `scrollToNext()`: Scroll to the next section.
- `scrollToPrev()`: Scroll to the previous section.
- `onActiveChange(callback: (id: string | null, meta: { previous: string | null, direction: 'up' | 'down' | null }) => void)`: Subscribe to active section changes.
- `onProgressChange(sectionId: string, callback: (progress: number) => void)`: Subscribe to scroll progress (0~1).
- `getSections()`: Get registered section IDs.
- `getActiveId()`: Get current active section ID.
- `disableSection(id: string)`: Disable a section from active detection.
- `enableSection(id: string)`: Re-enable a disabled section.
- `destroy()`: Clean up observers and listeners.

### Basic Usage
Expand All @@ -39,3 +67,24 @@ manager.onActiveChange((id) => {

manager.scrollTo('home');
```

### Advanced Usage

```ts
// With sticky header
const manager = new ScrollManager({
offset: -60,
stickyElements: ['sticky-header'],
});

// Custom easing
const customEasing = (t: number) => t * t * (3 - 2 * t); // smoothstep
const manager = new ScrollManager({
easing: customEasing,
});

// Focus management
const manager = new ScrollManager({
focusActiveSection: true,
});
```
53 changes: 51 additions & 2 deletions docs/src/app/[lang]/docs/core/ko.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,43 @@ The main class that orchestrates section detection and scrolling.
const manager = new ScrollManager({
offset: -80,
behavior: 'smooth',
hash: false,
keyboard: false,
debug: false,
rootMargin: '-20% 0px -60% 0px',
focusActiveSection: false,
stickyElements: [],
easing: undefined,
});
```

### Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `offset` | `number` | `0` | Fixed header용 오프셋 (px) |
| `behavior` | `'smooth' \| 'auto' \| 'instant'` | `'smooth'` | 스크롤 동작 |
| `hash` | `boolean` | `false` | URL hash와 활성 섹션 동기화 |
| `keyboard` | `boolean` | `false` | Alt+Arrow 키보드 네비게이션 |
| `debug` | `boolean` | `false` | 디버그 모드 |
| `rootMargin` | `string` | `'-20% 0px -60% 0px'` | IntersectionObserver rootMargin |
| `focusActiveSection` | `boolean` | `false` | 스크롤 후 섹션으로 포커스 이동 |
| `stickyElements` | `string[] \| HTMLElement[]` | `[]` | sticky 헤더/푸터 요소 |
| `easing` | `(t: number) => number` | `undefined` | 커스텀 easing 함수 |

### Methods

- `registerSection(id: string, element: HTMLElement)`: Register a new section to be tracked.
- `registerSection(id: string, element: HTMLElement)`: Register a new section to be tracked. Automatically applies `role="region"` and `aria-labelledby`.
- `unregisterSection(id: string)`: Stop tracking a section.
- `scrollTo(id: string)`: Programmatically scroll to a registered section.
- `onActiveChange(callback: (id: string | null) => void)`: Subscribe to active section changes.
- `scrollToNext()`: Scroll to the next section.
- `scrollToPrev()`: Scroll to the previous section.
- `onActiveChange(callback: (id: string | null, meta: { previous: string | null, direction: 'up' | 'down' | null }) => void)`: Subscribe to active section changes.
- `onProgressChange(sectionId: string, callback: (progress: number) => void)`: Subscribe to scroll progress (0~1).
- `getSections()`: Get registered section IDs.
- `getActiveId()`: Get current active section ID.
- `disableSection(id: string)`: Disable a section from active detection.
- `enableSection(id: string)`: Re-enable a disabled section.
- `destroy()`: Clean up observers and listeners.

### Basic Usage
Expand All @@ -39,3 +67,24 @@ manager.onActiveChange((id) => {

manager.scrollTo('home');
```

### Advanced Usage

```ts
// Sticky header가 있는 경우
const manager = new ScrollManager({
offset: -60,
stickyElements: ['sticky-header'],
});

// 커스텀 easing 사용
const customEasing = (t: number) => t * t * (3 - 2 * t); // smoothstep
const manager = new ScrollManager({
easing: customEasing,
});

// 포커스 관리
const manager = new ScrollManager({
focusActiveSection: true,
});
```
Loading
Loading