-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllms.txt
More file actions
297 lines (243 loc) · 9.8 KB
/
llms.txt
File metadata and controls
297 lines (243 loc) · 9.8 KB
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
# MicroUI - Pure Vanilla JavaScript Utility Library
> A lightweight, modern JavaScript utility library that makes DOM manipulation and event handling simple and efficient. Built with 100% vanilla JavaScript, zero dependencies.
## Project Overview
MicroUI is a production-ready vanilla JavaScript library that provides jQuery-like functionality with modern ES6+ features. It's designed to be the perfect middle ground between heavy frameworks and raw vanilla JavaScript.
### Key Statistics
- **Size**: 18KB minified, 5.2KB gzipped
- **Performance**: 5.8x smaller than jQuery, 2.5x smaller than React
- **Tests**: 72 comprehensive tests with 100% passing rate
- **Dependencies**: Zero - pure vanilla JavaScript
- **Browser Support**: All modern browsers (ES6+)
## Architecture
### Core Modules (`src/core/`)
- **`dom.js`** - DOM manipulation utilities (selection, classes, attributes, content)
- **`events.js`** - Event handling system with automatic delegation
- **`ajax.js`** - Promise-based HTTP requests (GET, POST, PUT, DELETE)
- **`utils.js`** - Helper functions (debounce, throttle, extend, type checking)
### Extended Modules (`src/modules/`)
- **`animation.js`** - Web Animations API wrapper (fade, slide, custom animations)
- **`storage.js`** - localStorage/sessionStorage utilities with JSON serialization
- **`component.js`** - Component system with lifecycle hooks and templating
- **`delegate.js`** - Advanced event delegation with namespacing and middleware
### Build System
- **Rollup** for bundling (UMD, ES modules, development builds)
- **Babel** for ES6+ compatibility
- **Terser** for minification
- **Jest** for testing
- **ESLint** for code quality
## API Design Philosophy
### 1. Familiar jQuery-like Syntax
```javascript
// jQuery style
$('.button').click(function() { $(this).addClass('active'); });
// MicroUI equivalent
MicroUI.on('click', '.button', function() { MicroUI.addClass(this, 'active'); });
```
### 2. Modern JavaScript Features
- Promise-based async operations
- ES6+ syntax (arrow functions, destructuring, modules)
- Web Animations API for smooth animations
- Native browser APIs (no polyfills needed)
### 3. Event Delegation by Default
All event handling uses delegation for better performance:
```javascript
MicroUI.on('click', '.dynamic-content', handler); // Works for future elements
```
### 4. Chainable and Functional
```javascript
MicroUI.addClass(element, 'loading')
.fadeIn(element, 300)
.then(() => MicroUI.removeClass(element, 'loading'));
```
## Key Components
### DOM Utilities
- **Selection**: `$()` with caching, `$$()` for multiple elements
- **Classes**: `addClass()`, `removeClass()`, `toggleClass()`, `hasClass()`
- **Content**: `html()`, `text()`, `append()`, `prepend()`, `remove()`
- **Attributes**: `attr()`, `data()`, `css()`
### Event System
- **Binding**: `on()`, `off()`, `once()`, `trigger()`
- **Delegation**: Automatic event delegation for performance
- **Custom Events**: Full support for custom event creation and handling
### AJAX Module
- **Methods**: `get()`, `post()`, `put()`, `delete()`, `ajax()`
- **Features**: Promise-based, automatic JSON parsing, error handling
- **Utilities**: `load()` for HTML content injection
### Animation Module
- **Presets**: `fadeIn()`, `fadeOut()`, `slideUp()`, `slideDown()`
- **Custom**: `animate()` using Web Animations API
- **Performance**: Hardware accelerated, smooth 60fps animations
### Component System
```javascript
MicroUI.component('counter', {
template: '<div>Count: {{count}}</div>',
state: { count: 0 },
methods: { increment() { this.state.count++; this.update(); } },
events: { 'click .btn': 'increment' },
lifecycle: { created() {}, mounted() {}, destroyed() {} }
});
```
### Storage Utilities
- **localStorage**: `MicroUI.store.set()`, `MicroUI.store.get()`
- **sessionStorage**: `MicroUI.session.set()`, `MicroUI.session.get()`
- **Features**: Automatic JSON serialization, error handling
## File Structure
```
microui/
├── src/
│ ├── core/
│ │ ├── dom.js # DOM manipulation utilities
│ │ ├── events.js # Event handling system
│ │ ├── ajax.js # HTTP request utilities
│ │ └── utils.js # Helper functions
│ ├── modules/
│ │ ├── animation.js # Animation utilities
│ │ ├── storage.js # Storage utilities
│ │ ├── component.js # Component system
│ │ └── delegate.js # Event delegation system
│ └── index.js # Main entry point and exports
├── dist/
│ ├── microui.js # Development build (UMD)
│ ├── microui.min.js # Production build (minified)
│ ├── microui.esm.js # ES module build
│ └── *.gz # Gzipped versions
├── tests/
│ ├── dom.test.js # DOM utilities tests
│ ├── events.test.js # Event system tests
│ ├── ajax.test.js # AJAX utilities tests
│ ├── utils.test.js # Helper functions tests
│ ├── component.test.js # Component system tests
│ └── delegate.test.js # Delegation system tests
├── examples/
│ ├── basic.html # Basic usage examples
│ ├── advanced.html # Advanced UI components
│ └── test.html # Manual testing page
├── scripts/
│ ├── build-sizes.js # Bundle size analysis
│ └── generate-badges.js # README badge generation
├── index.html # GitHub Pages demo site
├── package.json # NPM configuration
├── rollup.config.js # Build configuration
└── jest.config.js # Test configuration
```
## Build Process
### Development
```bash
npm run build:dev # Development build with source maps
npm run watch # Watch mode for development
npm run serve # Local development server
```
### Production
```bash
npm run build # Full production build with size analysis
npm run test # Run all tests
npm run lint # Code quality checks
```
### Generated Files
- **UMD Build**: `dist/microui.js` (48.6KB)
- **Minified**: `dist/microui.min.js` (18.2KB)
- **Gzipped**: `dist/microui.min.js.gz` (5.2KB)
- **ES Modules**: `dist/microui.esm.js` (45.2KB)
- **Build Report**: `dist/build-report.json` (size analysis)
## Testing Strategy
### Unit Tests (72 total)
- **DOM Tests**: Element selection, class manipulation, content updates
- **Event Tests**: Event binding, delegation, custom events
- **AJAX Tests**: HTTP requests, error handling, response parsing
- **Component Tests**: Lifecycle, state management, event binding
- **Delegate Tests**: Namespace management, middleware, scoping
### Test Environment
- **Jest** test runner with JSDOM for browser simulation
- **Coverage Reports** generated automatically
- **CI/CD Integration** with GitHub Actions
## Performance Optimizations
### Bundle Size
- **Tree Shaking**: Import only needed modules
- **Minification**: Terser for optimal compression
- **Gzip Compression**: 93% size reduction (75KB → 5.2KB)
### Runtime Performance
- **Event Delegation**: Automatic delegation for all events
- **DOM Caching**: Intelligent element caching in `$()`
- **Batched Operations**: Minimize DOM reflows
- **Native APIs**: Direct browser API usage
## Browser Compatibility
### Supported Browsers
- **Chrome/Edge**: 60+ (ES6+ support)
- **Firefox**: 55+ (ES6+ support)
- **Safari**: 10+ (ES6+ support)
- **Mobile**: iOS Safari 10+, Chrome Mobile 60+
### ES6+ Features Used
- Arrow functions, destructuring, template literals
- Promises, async/await
- Classes, modules (import/export)
- Web Animations API, Fetch API
## Deployment
### GitHub Pages
- **Demo Site**: Interactive examples and documentation
- **Automatic Deployment**: GitHub Actions on push to main
- **CDN Links**: Direct script tag usage
### NPM Package
- **Main**: `dist/microui.js` (UMD)
- **Module**: `dist/microui.esm.js` (ES modules)
- **Types**: TypeScript definitions included
## Usage Patterns
### Basic DOM Manipulation
```javascript
// Select and modify elements
const button = MicroUI.$('.my-button');
MicroUI.addClass(button, 'active');
MicroUI.html(button, 'Clicked!');
```
### Event Handling
```javascript
// Delegated events
MicroUI.on('click', '.button', function(e) {
MicroUI.toggleClass(this, 'selected');
});
```
### AJAX Requests
```javascript
// Promise-based HTTP
MicroUI.get('/api/users')
.then(users => MicroUI.html('.users', renderUsers(users)))
.catch(error => console.error(error));
```
### Components
```javascript
// Reusable components
MicroUI.component('todo-item', {
template: '<div class="todo">{{text}}</div>',
events: { 'click': 'toggleComplete' },
methods: { toggleComplete() { /* logic */ } }
});
```
## Comparison with Alternatives
| Feature | MicroUI | jQuery | React | Alpine.js |
|---------|---------|--------|-------|-----------|
| Bundle Size (gzipped) | 5.2KB | 30KB | 13KB | 15KB |
| Dependencies | 0 | 0 | Many | 0 |
| Learning Curve | Low | Low | High | Medium |
| Component System | Yes | No | Yes | Yes |
| Virtual DOM | No | No | Yes | No |
| Build Required | No | No | Yes | No |
## Contributing
### Development Setup
1. Clone repository
2. `npm install` - Install dependencies
3. `npm run watch` - Start development mode
4. `npm test` - Run tests
### Code Style
- ES6+ JavaScript
- ESLint configuration enforced
- JSDoc comments for public APIs
- Jest tests for all features
### Pull Request Process
- Fork repository
- Create feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit pull request
## License
MIT License - Use freely in commercial and open-source projects.
---
*This file helps LLMs understand the MicroUI codebase structure, design decisions, and usage patterns. For human developers, see README.md for getting started guides and examples.*