@oxog/scrollex 1.0.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,68 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.0.0] - 2025-12-27
11
+
12
+ ### Added
13
+
14
+ #### Core Components
15
+ - `VirtualList` - High-performance virtualized list component with fixed and variable heights
16
+ - `VirtualGrid` - Multi-column grid virtualization with gap support
17
+ - `VirtualMasonry` - Pinterest-style masonry layout with dynamic columns
18
+
19
+ #### React Hooks
20
+ - `useVirtualList` - Hook for custom list virtualization
21
+ - `useVirtualGrid` - Hook for custom grid virtualization
22
+ - `useVirtualMasonry` - Hook for custom masonry layouts
23
+ - `useMeasure` - Hook for measuring element dimensions
24
+ - `useMeasureMany` - Hook for batch element measurement
25
+ - `useScrollex` - Context hook for accessing kernel instance
26
+
27
+ #### Micro-Kernel Architecture
28
+ - Event-driven kernel with typed event system
29
+ - Plugin registry with dependency resolution
30
+ - Binary search for O(log n) visible range calculation
31
+ - RAF-throttled scroll handling for smooth 60fps rendering
32
+ - Configurable viewport management
33
+
34
+ #### Core Plugins
35
+ - `listRendererPlugin` - Core list rendering with positioning
36
+ - `gridRendererPlugin` - Grid layout calculations and rendering
37
+ - `autoMeasurerPlugin` - Automatic height measurement with ResizeObserver
38
+ - `infiniteLoaderPlugin` - Bidirectional infinite scroll with debouncing
39
+ - `scrollControllerPlugin` - Programmatic scroll control with easing functions
40
+
41
+ #### Optional Plugins
42
+ - `debugPanelPlugin` - Visual debugging panel with FPS, render count, and memory stats
43
+
44
+ #### Performance Features
45
+ - Zero runtime dependencies (React is peer dependency only)
46
+ - Tree-shakeable exports for minimal bundle size (~3KB core)
47
+ - Measurement caching for variable heights
48
+ - Object pooling to minimize garbage collection
49
+ - CSS containment support for rendering optimization
50
+ - Overscan configuration for smooth scrolling
51
+
52
+ #### Developer Experience
53
+ - Full TypeScript support with strict mode
54
+ - Comprehensive type definitions for all APIs
55
+ - ESM and CJS dual package exports
56
+ - Source maps included for debugging
57
+ - 71%+ test coverage with Vitest
58
+
59
+ ### Technical Details
60
+ - Tested with 100,000+ items at consistent 60fps
61
+ - Supports React 17.0.0 and above
62
+ - Node.js 18.0.0+ required for development
63
+ - Modern browser support (Chrome 80+, Firefox 75+, Safari 13+, Edge 80+)
64
+
65
+ ---
66
+
67
+ [Unreleased]: https://github.com/ersinkoc/Scrollex/compare/v1.0.0...HEAD
68
+ [1.0.0]: https://github.com/ersinkoc/Scrollex/releases/tag/v1.0.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ersinkoc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,328 @@
1
+ # Scrollex
2
+
3
+ <div align="center">
4
+
5
+ **Zero-dependency React virtualization library with micro-kernel plugin architecture**
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@oxog/scrollex.svg)](https://www.npmjs.com/package/@oxog/scrollex)
8
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/@oxog/scrollex)](https://bundlephobia.com/package/@oxog/scrollex)
9
+ [![license](https://img.shields.io/npm/l/@oxog/scrollex.svg)](https://github.com/ersinkoc/Scrollex/blob/main/LICENSE)
10
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
11
+
12
+ [Documentation](https://scrollex.oxog.dev) | [Examples](https://scrollex.oxog.dev/examples) | [GitHub](https://github.com/ersinkoc/Scrollex)
13
+
14
+ </div>
15
+
16
+ ---
17
+
18
+ ## Features
19
+
20
+ - **Zero Dependencies** - No runtime dependencies, React is a peer dependency
21
+ - **High Performance** - 100k+ items at 60fps with RAF-based rendering
22
+ - **Micro-Kernel Architecture** - Small core (~3KB) with tree-shakeable plugins
23
+ - **Variable Heights** - Auto-measurement for dynamic content
24
+ - **Infinite Scroll** - Built-in bidirectional infinite loading
25
+ - **Multiple Layouts** - List, Grid, and Masonry components
26
+ - **TypeScript First** - Full type safety with strict mode
27
+ - **Accessible** - Keyboard navigation and ARIA support
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ npm install @oxog/scrollex
33
+ ```
34
+
35
+ ```bash
36
+ yarn add @oxog/scrollex
37
+ ```
38
+
39
+ ```bash
40
+ pnpm add @oxog/scrollex
41
+ ```
42
+
43
+ ## Quick Start
44
+
45
+ ```tsx
46
+ import { VirtualList } from '@oxog/scrollex'
47
+
48
+ function App() {
49
+ const items = Array.from({ length: 10000 }, (_, i) => ({
50
+ id: i,
51
+ name: `Item ${i + 1}`,
52
+ }))
53
+
54
+ return (
55
+ <VirtualList
56
+ data={items}
57
+ itemHeight={50}
58
+ height={400}
59
+ renderItem={({ item, style }) => (
60
+ <div style={style}>{item.name}</div>
61
+ )}
62
+ />
63
+ )
64
+ }
65
+ ```
66
+
67
+ ## Components
68
+
69
+ ### VirtualList
70
+
71
+ Efficiently render large lists with fixed or variable heights.
72
+
73
+ ```tsx
74
+ import { VirtualList } from '@oxog/scrollex'
75
+
76
+ <VirtualList
77
+ data={items}
78
+ itemHeight={50}
79
+ height={400}
80
+ overscan={5}
81
+ renderItem={({ item, index, style }) => (
82
+ <div style={style}>
83
+ {item.name}
84
+ </div>
85
+ )}
86
+ />
87
+ ```
88
+
89
+ **Variable Heights:**
90
+
91
+ ```tsx
92
+ <VirtualList
93
+ data={items}
94
+ itemHeight="auto"
95
+ estimatedItemHeight={60}
96
+ renderItem={({ item, style, measureRef }) => (
97
+ <div ref={measureRef} style={style}>
98
+ {item.content}
99
+ </div>
100
+ )}
101
+ />
102
+ ```
103
+
104
+ ### VirtualGrid
105
+
106
+ Multi-column grid virtualization.
107
+
108
+ ```tsx
109
+ import { VirtualGrid } from '@oxog/scrollex'
110
+
111
+ <VirtualGrid
112
+ data={products}
113
+ columns={4}
114
+ itemHeight={200}
115
+ gap={16}
116
+ height={600}
117
+ renderItem={({ item, style }) => (
118
+ <div style={style}>
119
+ <ProductCard product={item} />
120
+ </div>
121
+ )}
122
+ />
123
+ ```
124
+
125
+ ### VirtualMasonry
126
+
127
+ Pinterest-style masonry layout.
128
+
129
+ ```tsx
130
+ import { VirtualMasonry } from '@oxog/scrollex'
131
+
132
+ <VirtualMasonry
133
+ data={images}
134
+ columns={3}
135
+ gap={8}
136
+ height={800}
137
+ getItemHeight={(item, columnWidth) =>
138
+ (item.height / item.width) * columnWidth
139
+ }
140
+ renderItem={({ item, style, width }) => (
141
+ <div style={style}>
142
+ <img src={item.url} width={width} alt={item.alt} />
143
+ </div>
144
+ )}
145
+ />
146
+ ```
147
+
148
+ ## Hooks
149
+
150
+ For more control, use the hooks directly:
151
+
152
+ ```tsx
153
+ import { useRef } from 'react'
154
+ import { useVirtualList } from '@oxog/scrollex'
155
+
156
+ function MyList({ items }) {
157
+ const containerRef = useRef<HTMLDivElement>(null)
158
+
159
+ const { virtualItems, totalSize, scrollToIndex } = useVirtualList({
160
+ count: items.length,
161
+ estimatedItemHeight: 50,
162
+ containerRef,
163
+ overscan: 5,
164
+ })
165
+
166
+ return (
167
+ <div ref={containerRef} style={{ height: 400, overflow: 'auto' }}>
168
+ <div style={{ height: totalSize, position: 'relative' }}>
169
+ {virtualItems.map((virtualItem) => (
170
+ <div
171
+ key={virtualItem.key}
172
+ style={{
173
+ position: 'absolute',
174
+ top: virtualItem.start,
175
+ height: virtualItem.size,
176
+ width: '100%',
177
+ }}
178
+ >
179
+ {items[virtualItem.index].name}
180
+ </div>
181
+ ))}
182
+ </div>
183
+ </div>
184
+ )
185
+ }
186
+ ```
187
+
188
+ ## Plugins
189
+
190
+ Extend functionality with optional plugins:
191
+
192
+ ```tsx
193
+ import { VirtualList } from '@oxog/scrollex'
194
+ import { infiniteLoaderPlugin, debugPanelPlugin } from '@oxog/scrollex/plugins'
195
+
196
+ <VirtualList
197
+ data={items}
198
+ itemHeight={50}
199
+ plugins={[
200
+ infiniteLoaderPlugin({
201
+ threshold: 200,
202
+ onLoadMore: async (direction) => {
203
+ const newItems = await fetchMore(direction)
204
+ setItems(prev => [...prev, ...newItems])
205
+ }
206
+ }),
207
+ debugPanelPlugin({ position: 'bottom-right' }),
208
+ ]}
209
+ renderItem={({ item, style }) => (
210
+ <div style={style}>{item.name}</div>
211
+ )}
212
+ />
213
+ ```
214
+
215
+ ### Available Plugins
216
+
217
+ | Plugin | Description |
218
+ |--------|-------------|
219
+ | `listRendererPlugin` | Core list rendering |
220
+ | `gridRendererPlugin` | Grid layout rendering |
221
+ | `autoMeasurerPlugin` | Automatic height measurement |
222
+ | `infiniteLoaderPlugin` | Infinite scroll loading |
223
+ | `scrollControllerPlugin` | Programmatic scroll control |
224
+ | `debugPanelPlugin` | Visual debugging tools |
225
+
226
+ ## Infinite Scroll
227
+
228
+ ```tsx
229
+ import { useState } from 'react'
230
+ import { VirtualList } from '@oxog/scrollex'
231
+ import { infiniteLoaderPlugin } from '@oxog/scrollex/plugins'
232
+
233
+ function InfiniteList() {
234
+ const [items, setItems] = useState(initialItems)
235
+ const [loading, setLoading] = useState(false)
236
+
237
+ const handleLoadMore = async (direction: 'forward' | 'backward') => {
238
+ if (loading) return
239
+ setLoading(true)
240
+
241
+ const newItems = await fetchMoreItems(direction)
242
+ setItems(prev =>
243
+ direction === 'forward'
244
+ ? [...prev, ...newItems]
245
+ : [...newItems, ...prev]
246
+ )
247
+
248
+ setLoading(false)
249
+ }
250
+
251
+ return (
252
+ <VirtualList
253
+ data={items}
254
+ itemHeight={50}
255
+ height={400}
256
+ plugins={[
257
+ infiniteLoaderPlugin({
258
+ threshold: 200,
259
+ onLoadMore: handleLoadMore,
260
+ })
261
+ ]}
262
+ renderItem={({ item, style }) => (
263
+ <div style={style}>{item.name}</div>
264
+ )}
265
+ />
266
+ )
267
+ }
268
+ ```
269
+
270
+ ## Performance
271
+
272
+ Scrollex is designed for maximum performance:
273
+
274
+ - **Binary Search** - O(log n) visible range calculation
275
+ - **Measurement Caching** - Efficient variable height handling
276
+ - **RAF Batching** - Smooth 60fps rendering
277
+ - **CSS Containment** - Optimized paint and layout
278
+ - **Tree Shaking** - Import only what you need
279
+
280
+ Tested with **100,000+ items** at consistent 60fps.
281
+
282
+ ## Browser Support
283
+
284
+ - Chrome 80+
285
+ - Firefox 75+
286
+ - Safari 13+
287
+ - Edge 80+
288
+
289
+ ## Documentation
290
+
291
+ Full documentation available at **[scrollex.oxog.dev](https://scrollex.oxog.dev)**
292
+
293
+ - [Getting Started](https://scrollex.oxog.dev/getting-started)
294
+ - [API Reference](https://scrollex.oxog.dev/api)
295
+ - [Examples](https://scrollex.oxog.dev/examples)
296
+ - [Plugins](https://scrollex.oxog.dev/plugins)
297
+
298
+ ## Contributing
299
+
300
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
301
+
302
+ ```bash
303
+ # Clone the repository
304
+ git clone https://github.com/ersinkoc/Scrollex.git
305
+
306
+ # Install dependencies
307
+ npm install
308
+
309
+ # Run tests
310
+ npm test
311
+
312
+ # Start development
313
+ npm run dev
314
+ ```
315
+
316
+ ## Author
317
+
318
+ **Ersin KOC** - [@ersinkoc](https://github.com/ersinkoc)
319
+
320
+ ## License
321
+
322
+ MIT License - see the [LICENSE](LICENSE) file for details.
323
+
324
+ ---
325
+
326
+ <div align="center">
327
+ <sub>Built with care by Ersin KOC</sub>
328
+ </div>