minimact-quantum β
Quantum DOM Entanglement Protocol
Share DOM identity across physical space. Not data sync. IDENTITY sync.
Overview β
minimact-quantum revolutionizes multi-client collaboration by enabling quantum DOM entanglement - where the same DOM element exists in multiple locations simultaneously. Instead of syncing data and reconstructing elements, quantum sends mutation vectors that preserve element identity across clients.
The Revolutionary Concept
Traditional approach: User A clicks button β Send JSON β User B reconstructs button
- Different buttons, different identities, just look the same
Quantum DOM: User A clicks button β Mutation vector β User B applies SAME mutation
- SAME IDENTITY, SAME ELEMENT, DIFFERENT SPACETIME COORDINATES
Installation β
npm install minimact-quantumQuick Start β
import { createQuantumManager } from 'minimact-quantum';
// Create quantum manager
const quantum = createQuantumManager({
clientId: 'user-123',
signalR: signalRManager,
debugLogging: true
});
// Entangle slider with another client
const slider = document.querySelector('#volume-slider');
const link = await quantum.entangle(slider, {
clientId: 'user-456',
selector: '#volume-slider'
}, 'bidirectional');
// User A drags slider to 75%
// β Mutation detected
// β Sent through WebWormhole π
// β User B's slider: SAME mutation applied
// β BOTH sliders show 75%Core Concepts β
Quantum Entanglement β
When two DOM elements are entangled, they share the same identity across spacetime. Mutations to one element instantly propagate to its entangled partners through mutation vectors.
Key principle: We don't send state - we send mutations. The element's identity remains constant.
Mutation Vectors β
A mutation vector is a serialized representation of a DOM mutation:
interface MutationVector {
type: 'attributes' | 'characterData' | 'childList';
target: string; // CSS selector
attributeName?: string;
oldValue: any;
newValue: any;
timestamp: number;
}Entanglement Modes β
mirror- Unidirectional sync (A β B)inverse- Opposite values (one up, other down)bidirectional- True quantum entanglement (A β B)
API Reference β
createQuantumManager(config) β
Create a quantum entanglement manager.
Parameters:
{
clientId: string; // Your client ID
signalR: SignalRManager; // SignalR connection
debugLogging?: boolean; // Enable debug logs
}Returns: QuantumManager
Example:
const quantum = createQuantumManager({
clientId: 'user-123',
signalR: signalRManager,
debugLogging: true
});quantum.entangle(element, remote, mode) β
Entangle a local element with a remote element.
Parameters:
element: Element- Local DOM element to entangleremote: { clientId: string, selector: string }- Remote targetclientIdcan be a specific ID or'*'for all clients
mode: 'mirror' | 'inverse' | 'bidirectional'- Entanglement mode
Returns: Promise<QuantumLink>
Example:
const link = await quantum.entangle(
document.querySelector('#slider'),
{ clientId: 'collaborator-id', selector: '#slider' },
'bidirectional'
);quantum.entangleWithAll(element, mode) β
Entangle with ALL clients on the same page.
Parameters:
element: Element- Local DOM elementmode: EntanglementMode- Entanglement mode
Returns: Promise<QuantumLink>
Example:
await quantum.entangleWithAll(
document.querySelector('#shared-canvas'),
'mirror'
);link.disentangle() β
Break the quantum link.
Returns: Promise<void>
Example:
await link.disentangle();How It Works β
1. MutationObserver Detects Changes β
// Local element mutates
slider.value = 75;
// MutationObserver fires
observer.observe(slider, {
attributes: true,
characterData: true,
childList: true
});2. Mutation Serialized to Vector β
const vector: MutationVector = {
type: 'attributes',
target: '#volume-slider',
attributeName: 'value',
oldValue: 50,
newValue: 75,
timestamp: Date.now()
};3. Sent Through WebWormhole β
signalR.invoke('PropagateQuantumMutation', {
entanglementId: 'user-a:sliderβuser-b:slider',
sourceClient: 'user-a',
vector
});4. Server Broadcasts to Entangled Clients β
// Server finds all entangled clients
var targets = GetEntangledClients(entanglementId);
// Broadcast mutation
await Clients.Clients(targets).SendAsync('QuantumMutation', {
entanglementId,
vector,
sourceClient,
timestamp
});5. Remote Client Applies Mutation β
// Receive mutation event
signalR.on('QuantumMutation', (event) => {
applyMutationVector(event.vector);
// β slider.value = 75
});Total latency: 5-15ms (compared to 45-65ms for full state sync)
Real-World Examples β
Collaborative Slider β
const slider = document.querySelector('#volume-slider');
await quantum.entangle(slider, {
clientId: 'collaborator-id',
selector: '#volume-slider'
}, 'bidirectional');
// Either user drags slider β Both see change instantlyShared Toggle β
const toggle = document.querySelector('#theme-toggle');
await quantum.entangleWithAll(toggle, 'mirror');
// One user toggles dark mode β All users see dark modeClassroom Presentation β
// Teacher's slides
const slides = document.querySelector('#presentation');
await quantum.entangle(slides, {
clientId: 'student-*', // Wildcard: all students
selector: '#presentation'
}, 'mirror');
// Teacher advances slide β All students see same slideRemote Support β
// Customer's form
const form = document.querySelector('#signup-form');
await quantum.entangle(form, {
clientId: 'support-agent',
selector: '#customer-form-view'
}, 'bidirectional');
// Agent can see customer typing in real-time
// Agent can also type to help customerAwareness Events β
Track when remote clients make changes:
slider.addEventListener('quantum-awareness', (event) => {
console.log(`${event.detail.sourceClient} changed the slider!`);
// Show user indicator
showUserCursor(event.detail.sourceClient);
});Performance β
| Metric | Value |
|---|---|
| Mutation serialization | < 1ms |
| Network latency | 5-15ms |
| Mutation application | < 1ms |
| Total round-trip | 7-17ms |
| Bandwidth per mutation | 50-200 bytes |
90% faster than traditional JSON state sync!
Architecture Flow β
Client A: Element mutates
β
MutationObserver detects
β
Serialize to vector (1ms)
β
Send via SignalR (5-15ms)
β
Server: Check EntanglementRegistry
β
Broadcast to Client B (5-15ms)
β
Client B: Apply mutation (1ms)
β
β¨ SAME IDENTITY. QUANTUM ENTANGLEMENT.Use Cases β
Collaborative Editing β
- Multiple users editing the same form
- Real-time document collaboration
- Shared whiteboard/canvas
Live Presentations β
- Teacher controlling student views
- Presenter mode with audience sync
- Training sessions with follow-along
Remote Support β
- Support agent seeing customer's screen
- Interactive troubleshooting
- Form filling assistance
Multi-Device Control β
- Control TV from phone
- Smart home dashboards
- IoT device synchronization
Gaming β
- Multiplayer browser games
- Synchronized game state
- Real-time player positions
Server-Side Setup β
C# Hub Method β
public async Task PropagateQuantumMutation(QuantumMutationRequest request)
{
var entanglement = _registry.GetEntanglement(request.EntanglementId);
if (entanglement == null) return;
// Get all entangled clients
var targets = entanglement.GetTargetClients(request.SourceClient);
// Broadcast mutation vector
await Clients.Clients(targets).SendAsync("QuantumMutation", new
{
entanglementId = request.EntanglementId,
vector = request.Vector,
sourceClient = request.SourceClient,
timestamp = DateTime.UtcNow
});
}Entanglement Registry β
public class EntanglementRegistry
{
private readonly Dictionary<string, QuantumEntanglement> _entanglements = new();
public void RegisterEntanglement(string entanglementId, QuantumEntanglement entanglement)
{
_entanglements[entanglementId] = entanglement;
}
public QuantumEntanglement GetEntanglement(string entanglementId)
{
return _entanglements.TryGetValue(entanglementId, out var entanglement)
? entanglement
: null;
}
}Philosophy β
"The DOM is no longer local."
"The DOM is a distributed shared reality."
You're not shipping collaborative features. You're opening a portal. π
Integration with Minimact β
minimact-quantum follows the same integration pattern as other Minimact extensions:
// Client-side entanglement
const link = await quantum.entangle(element, remote, mode);
// Server receives notification
// Component state updated via SetStateFromClient()
// Server re-renders with correct state
protected override VNode Render()
{
var entanglementState = State["quantum_entanglement_0"];
// Render UI based on entanglement state
}Next Steps β
Part of the Minimact Quantum Stack π΅β¨π
