-
-
Notifications
You must be signed in to change notification settings - Fork 391
/
llms.old.txt
341 lines (290 loc) · 7.99 KB
/
llms.old.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# Lenis Codebase Overview
## Core Purpose
- Smooth scrolling library optimized for modern browsers
- Originally designed for WebGL-DOM synchronization
- Handles complex scroll animations and parallax effects
## Key Features
- Smooth scroll interpolation (lerp)
- Touch device support
- Nested scroll handling
- GSAP ScrollTrigger integration
- Infinite scroll support
- Horizontal/vertical scrolling
- Event system (scroll, virtual-scroll)
## Technical Implementation
- Uses requestAnimationFrame for smooth animations
- Supports both native and smooth scrolling modes
- Handles wheel, touch, and scroll events
- Provides virtual scroll capabilities
- Manages scroll prevention and locking
- Supports custom easing functions
## Core Instance Options
```typescript
{
wrapper?: Window | HTMLElement // Scroll container (default: window)
content?: HTMLElement // Content element (default: document.documentElement)
lerp?: number // Linear interpolation value (default: 0.1)
duration?: number // Scroll animation duration in seconds
orientation?: 'vertical' | 'horizontal' // Scroll direction (default: 'vertical')
gestureOrientation?: 'vertical' | 'horizontal' | 'both'
smoothWheel?: boolean // Smooth wheel events (default: true)
smoothTouch?: boolean // Smooth touch events (default: false)
wheelMultiplier?: number // Wheel multiplication factor (default: 1)
touchMultiplier?: number // Touch multiplication factor (default: 2)
infinite?: boolean // Enable infinite scrolling (default: false)
autoResize?: boolean // Auto resize on content changes (default: true)
}
```
## Key Methods
```typescript
scrollTo(target: number | string | HTMLElement, options?: {
offset?: number
lerp?: number
duration?: number
immediate?: boolean
lock?: boolean
force?: boolean
onComplete?: () => void
})
stop() // Pause scrolling
start() // Resume scrolling
destroy() // Cleanup instance
resize() // Recalculate dimensions
setScroll(value) // Set scroll position
isLocked() // Check if scrolling is locked
isStopped() // Check if scrolling is stopped
```
## Events
```typescript
lenis.on('scroll', ({ scroll, limit, velocity, direction, progress }) => {})
lenis.on('virtual-scroll', ({ deltaX, deltaY, event }) => {})
```
## Architecture
- Core Lenis class
- Animate system
- Dimensions handling
- Event emitter
- Virtual scroll implementation
- TypeScript support
## Integration Methods
- NPM package: `npm i lenis`
- CDN: `<script src="https://unpkg.com/lenis"></script>`
- CSS stylesheet: `import 'lenis/dist/lenis.css'`
- Framework integrations (React, Vue)
## Common Usage Patterns
```typescript
// Basic setup
const lenis = new Lenis()
function raf(time) {
lenis.raf(time)
requestAnimationFrame(raf)
}
requestAnimationFrame(raf)
// GSAP integration
lenis.on('scroll', ScrollTrigger.update)
gsap.ticker.add((time) => lenis.raf(time * 1000))
gsap.ticker.lagSmoothing(0)
// Nested scroll prevention
const lenis = new Lenis({
prevent: (node) => node.classList.contains('scrollable')
})
```
## Limitations
- No native CSS scroll-snap support (use lenis/snap package)
- Safari FPS caps: 60fps, 30fps in low power mode
- iframe scroll limitations (no wheel event forwarding)
- Safari pre-M1 fixed position lag
- iOS < 16 touch event quirks with smoothTouch
- Nested scroll requires proper configuration
## File Structure
- /packages/core - Main implementation
- /packages/react - React integration
- /packages/vue - Vue integration
- /packages/snap - Scroll snap support
- lenis.css - Core styles
- types.ts - TypeScript definitions
## Performance Considerations
- RAF optimization
- Touch event handling
- Scroll synchronization
- Browser compatibility
- Device-specific behaviors
## Extension Points
- Virtual scroll customization
- Event system
- Scroll prevention logic
- Animation configuration
- Framework integrations
## Packages
### Core Package (lenis)
```typescript
// Basic usage
import Lenis from 'lenis'
const lenis = new Lenis({
duration: 1.2,
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
orientation: 'vertical',
gestureOrientation: 'vertical',
smoothWheel: true,
wheelMultiplier: 1,
smoothTouch: false,
touchMultiplier: 2
})
// Required CSS
html.lenis {
height: auto;
}
.lenis.lenis-smooth {
scroll-behavior: auto !important;
}
.lenis.lenis-smooth [data-lenis-prevent] {
overscroll-behavior: contain;
}
.lenis.lenis-stopped {
overflow: clip;
}
```
### React Package (lenis/react)
```typescript
import { ReactLenis, useLenis } from 'lenis/react'
// Component wrapper
function App() {
return (
<ReactLenis root options={{ duration: 1.2, orientation: 'vertical' }}>
{/* content */}
</ReactLenis>
)
}
// Hook usage
function Component() {
const lenis = useLenis(({ scroll }) => {
// Called every scroll
})
return <button onClick={() => lenis.scrollTo(0)}>Top</button>
}
// Custom RAF
function CustomRaf() {
const lenisRef = useRef()
useEffect(() => {
function raf(time) {
lenisRef.current?.lenis?.raf(time)
}
requestAnimationFrame(raf)
}, [])
return (
<ReactLenis ref={lenisRef} autoRaf={false}>
{/* content */}
</ReactLenis>
)
}
```
### Vue Package (lenis/vue)
```typescript
import { VueLenis, useLenis } from 'lenis/vue'
// Component usage
<template>
<vue-lenis :options="{ duration: 1.2 }" root>
<!-- content -->
</vue-lenis>
</template>
// Composition API usage
const lenis = useLenis(({ scroll }) => {
// Called every scroll
})
// Props
interface LenisProps {
root?: boolean // Setup global instance
options?: LenisOptions // Lenis options
autoRaf?: boolean // Auto RAF setup
className?: string // Wrapper class
}
```
### Snap Package (lenis/snap)
```typescript
import Lenis from 'lenis'
import Snap from 'lenis/snap'
const lenis = new Lenis()
const snap = new Snap(lenis, {
type: 'mandatory', // 'mandatory' | 'proximity'
velocityThreshold: 1, // Snap velocity threshold
snapToChildren: true, // Snap to direct children
snapChildren: '.snap-target', // CSS selector for snap targets
duration: 1, // Snap animation duration
easing: (t) => t, // Snap easing function
onSnapStart: (snap) => {}, // Snap start callback
onSnapComplete: (snap) => {} // Snap complete callback
})
// Manual snap points
snap.add(500) // Snap at 500px
snap.add(1000) // Snap at 1000px
// Element-based snapping
snap.addElement(element, {
align: ['start', 'center', 'end']
})
```
## Package-specific Features
### Core
- Base scrolling functionality
- Virtual scroll system
- Event handling
- Dimension management
- Animation system
### React
- React component wrapper
- useLenis hook
- Automatic cleanup
- Context system
- Ref forwarding
- TypeScript support
### Vue
- Vue component wrapper
- useLenis composable
- Auto RAF management
- Props validation
- Template integration
- TypeScript support
### Snap
- CSS scroll-snap alternative
- Element-based snapping
- Manual snap points
- Velocity-based snapping
- Animation customization
## Package Integration Patterns
### Core + GSAP
```typescript
lenis.on('scroll', ScrollTrigger.update)
gsap.ticker.add((time) => lenis.raf(time * 1000))
gsap.ticker.lagSmoothing(0)
```
### React + Snap
```typescript
function App() {
const lenisRef = useRef()
useEffect(() => {
const snap = new Snap(lenisRef.current.lenis, {
type: 'mandatory'
})
return () => snap.destroy()
}, [])
return <ReactLenis ref={lenisRef}>{/* content */}</ReactLenis>
}
```
### Vue + Custom RAF
```typescript
<script setup>
const lenisRef = ref()
const autoRaf = ref(false)
onMounted(() => {
function raf(time) {
lenisRef.value?.lenis?.raf(time)
requestAnimationFrame(raf)
}
requestAnimationFrame(raf)
})
</script>
<template>
<vue-lenis ref="lenisRef" :auto-raf="autoRaf">
<!-- content -->
</vue-lenis>
</template>
```