@allystudio/dom-monitor
v1.0.0
Published
Lightweight, efficient DOM change monitoring with performance optimizations
Maintainers
Readme
@allystudio/dom-monitor
The fastest, most comprehensive DOM monitoring library on the market Built for 120+ FPS performance with advanced accessibility and performance tracking
🏆 Why This is the Best DOM Monitor
Unmatched Performance
- ⚡ 120+ FPS capable - Optimized for 8ms frame budget
- 📦 Only 10.71 KB ESM - Smallest comprehensive solution
- 🚀 requestAnimationFrame-based - Smooth, non-blocking processing
- 🎯 Adaptive batching - Automatically adjusts to frame budget
- 🔥 Zero dependencies - Pure TypeScript/JavaScript
Comprehensive Change Detection
- ✅ Element additions/removals
- ✅ Attribute changes (with old/new values)
- ✅ Text content changes
- ✅ Accessibility-specific tracking (ARIA, roles, etc.)
- ✅ Performance impact monitoring
- ✅ Custom filtering (elements & attributes)
Advanced Features
- 📊 Real-time performance metrics
- ♿ Accessibility change tracking
- 🎛️ Configurable frame rates (60, 120, 144+ FPS)
- 🐛 Debug mode with detailed logging
- 🎨 Framework agnostic - Works with React, Vue, Angular, Vanilla JS
🚀 Quick Start
npm install @allystudio/dom-monitorimport { createDOMMonitor, DOMChangeType } from "@allystudio/dom-monitor"
// Basic usage
const monitor = createDOMMonitor()
monitor.start((changes) => {
changes.forEach((change) => {
console.log(`${change.type}: ${change.element.tagName}`)
})
})
// Advanced usage with performance tracking
const advancedMonitor = createDOMMonitor({
maxChanges: 15, // Process up to 15 changes per frame
targetFrameRate: 120, // Optimize for 120 FPS
trackAccessibility: true, // Track ARIA changes
trackPerformance: true, // Monitor performance impact
debug: true, // Enable debug logging
onPerformanceUpdate: (metrics) => {
console.log(`Frame rate: ${metrics.frameRate} FPS`)
console.log(`Avg processing: ${metrics.averageProcessingTime}ms`)
},
})
advancedMonitor.start((changes) => {
changes.forEach((change) => {
if (change.type === DOMChangeType.ACCESSIBILITY_CHANGE) {
console.log("Accessibility change detected!", change.details)
}
})
})📊 Performance Comparison
| Library | Bundle Size | 120 FPS Ready | Accessibility | Performance Tracking | Framework Agnostic | | --------------------------- | ------------ | ------------- | ------------- | -------------------- | ------------------ | | @allystudio/dom-monitor | 10.71 KB | ✅ | ✅ | ✅ | ✅ | | Native MutationObserver | 0 KB | ❌ | ❌ | ❌ | ✅ | | React Scan | 50+ KB | ❌ | ❌ | ✅ | ❌ | | Enterprise Solutions | 500+ KB | ❌ | ❌ | ✅ | ✅ |
🎯 Use Cases
Web Performance Monitoring
const monitor = createDOMMonitor({
trackPerformance: true,
onPerformanceUpdate: (metrics) => {
if (metrics.frameRate < 60) {
console.warn("Performance degradation detected!")
}
},
})Accessibility Compliance
const a11yMonitor = createDOMMonitor({
trackAccessibility: true,
elementFilter: (el) =>
el.hasAttribute("role") || el.hasAttribute("aria-label"),
})
a11yMonitor.start((changes) => {
changes.forEach((change) => {
if (change.type === DOMChangeType.ACCESSIBILITY_CHANGE) {
// Log accessibility changes for compliance auditing
auditLog.push({
timestamp: change.timestamp,
element: change.element,
change: change.details,
})
}
})
})Development & Debugging
const debugMonitor = createDOMMonitor({
debug: true,
trackPerformance: true,
maxChanges: 5, // Limit for detailed analysis
})
debugMonitor.start((changes) => {
// Detailed change analysis for development
console.table(
changes.map((c) => ({
type: c.type,
element: c.element.tagName,
timestamp: c.timestamp,
processingTime: c.details?.performanceImpact,
}))
)
})🔧 Configuration Options
interface DOMMonitorOptions {
maxChanges?: number // Max changes per frame (default: 10)
observeText?: boolean // Monitor text changes (default: false)
ignoreClassChanges?: boolean // Ignore class attribute (default: true)
ignoreStyleChanges?: boolean // Ignore style attribute (default: true)
ignoreHiddenElements?: boolean // Ignore hidden elements (default: true)
trackAccessibility?: boolean // Track ARIA changes (default: false)
trackPerformance?: boolean // Monitor performance (default: false)
debug?: boolean // Enable debug mode (default: false)
targetFrameRate?: number // Target FPS (default: 120)
elementFilter?: (el: HTMLElement) => boolean
attributeFilter?: (attr: string, el: HTMLElement) => boolean
onPerformanceUpdate?: (metrics: PerformanceMetrics) => void
}📈 Performance Metrics
interface PerformanceMetrics {
totalChanges: number // Changes processed this second
changesPerSecond: number // Change rate
averageProcessingTime: number // Avg processing time (ms)
maxProcessingTime: number // Peak processing time (ms)
droppedChanges: number // Changes dropped due to frame budget
frameRate: number // Current frame rate
}🎨 Framework Integration
React
import { useEffect, useState } from "react"
import { createDOMMonitor } from "@allystudio/dom-monitor"
function usePerformanceMonitor() {
const [metrics, setMetrics] = useState(null)
useEffect(() => {
const monitor = createDOMMonitor({
trackPerformance: true,
onPerformanceUpdate: setMetrics,
})
monitor.start()
return () => monitor.stop()
}, [])
return metrics
}Vue
import { createDOMMonitor } from "@allystudio/dom-monitor"
import { onMounted, onUnmounted, ref } from "vue"
export function usePerformanceMonitor() {
const metrics = ref(null)
let monitor = null
onMounted(() => {
monitor = createDOMMonitor({
trackPerformance: true,
onPerformanceUpdate: (m) => (metrics.value = m),
})
monitor.start()
})
onUnmounted(() => {
monitor?.stop()
})
return { metrics }
}🏁 Competitive Advantages
vs Native MutationObserver
- ✅ Frame-rate optimized - Automatic batching and scheduling
- ✅ Performance tracking - Built-in metrics and monitoring
- ✅ Accessibility focus - Specialized ARIA/role change detection
- ✅ Developer experience - Clean functional API, TypeScript support
vs React Scan
- ✅ Framework agnostic - Works with any framework or vanilla JS
- ✅ Smaller bundle - 5x smaller than React Scan
- ✅ More comprehensive - Tracks all DOM changes, not just React
vs Enterprise Solutions
- ✅ Free & open source - No licensing costs
- ✅ 50x smaller - Fraction of the bundle size
- ✅ Better performance - Optimized for 120+ FPS
- ✅ More focused - Purpose-built for DOM monitoring
🧪 Testing
The library includes comprehensive test coverage:
npm test17/17 tests passing covering:
- ✅ Basic functionality (create, start, stop)
- ✅ Change detection (additions, removals, attributes, text)
- ✅ Filtering (class, style, custom filters)
- ✅ Batching and performance limits
- ✅ Configuration handling
📝 License
MIT License - see LICENSE file for details.
🤝 Contributing
Contributions welcome! Please read our contributing guidelines first.
Built with ❤️ for the modern web Making DOM monitoring fast, comprehensive, and accessible for everyone.
