100+ copy-paste UI components in plain HTML and CSS: no dependencies, no build step.

0 downloads

dbbasic-web-native/context-aware-demo.html
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-web-native.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-web-native.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-web-native.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add canonical.html v1.0 - The single source of truth for usability standards fb6e650 1 year ago History
context-aware-demo.html · 34.0 KB · 965 lines
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>Context-Aware Semantic Interface</title>
7 <style>
8 * {
9 margin: 0;
10 padding: 0;
11 box-sizing: border-box;
12 }
13
14 :root {
15 --critical: #ff3b30;
16 --high: #ff9500;
17 --medium: #007aff;
18 --low: #8e8e93;
19 --success: #34c759;
20
21 --bg: #000000;
22 --surface: #1c1c1e;
23 --surface-elevated: #2c2c2e;
24 --surface-modal: #3a3a3c;
25 --text: #ffffff;
26 --text-secondary: #98989d;
27 --border: #38383a;
28
29 --spacing: 16px;
30 }
31
32 body {
33 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
34 background: var(--bg);
35 color: var(--text);
36 line-height: 1.6;
37 font-size: 16px;
38 overflow-x: hidden;
39 }
40
41 /* Layout */
42 .dashboard {
43 display: grid;
44 grid-template-columns: 300px 1fr 350px;
45 height: 100vh;
46 gap: 0;
47 }
48
49 /* Left Panel - Context Controls */
50 .context-panel {
51 background: var(--surface);
52 border-right: 1px solid var(--border);
53 padding: calc(var(--spacing) * 1.5);
54 overflow-y: auto;
55 }
56
57 .context-section {
58 margin-bottom: calc(var(--spacing) * 2);
59 }
60
61 .context-section h3 {
62 font-size: 12px;
63 text-transform: uppercase;
64 letter-spacing: 1px;
65 color: var(--text-secondary);
66 margin-bottom: var(--spacing);
67 font-weight: 600;
68 }
69
70 .context-option {
71 display: flex;
72 align-items: center;
73 gap: calc(var(--spacing) / 2);
74 padding: calc(var(--spacing) / 2) 0;
75 }
76
77 .context-option label {
78 flex: 1;
79 font-size: 14px;
80 }
81
82 .toggle {
83 width: 44px;
84 height: 26px;
85 background: var(--border);
86 border-radius: 13px;
87 position: relative;
88 cursor: pointer;
89 transition: background 0.3s;
90 }
91
92 .toggle.active {
93 background: var(--success);
94 }
95
96 .toggle::after {
97 content: '';
98 position: absolute;
99 width: 22px;
100 height: 22px;
101 border-radius: 11px;
102 background: white;
103 top: 2px;
104 left: 2px;
105 transition: transform 0.3s;
106 }
107
108 .toggle.active::after {
109 transform: translateX(18px);
110 }
111
112 .slider-control {
113 width: 100%;
114 }
115
116 .slider-control input {
117 width: 100%;
118 margin-top: calc(var(--spacing) / 2);
119 }
120
121 .slider-value {
122 display: flex;
123 justify-content: space-between;
124 font-size: 12px;
125 color: var(--text-secondary);
126 margin-top: 4px;
127 }
128
129 .mode-select {
130 display: flex;
131 flex-direction: column;
132 gap: calc(var(--spacing) / 2);
133 }
134
135 .mode-btn {
136 padding: calc(var(--spacing) / 2) var(--spacing);
137 background: var(--surface-elevated);
138 border: 1px solid var(--border);
139 border-radius: 8px;
140 color: var(--text);
141 cursor: pointer;
142 font-size: 14px;
143 transition: all 0.2s;
144 text-align: left;
145 }
146
147 .mode-btn.active {
148 background: var(--medium);
149 border-color: var(--medium);
150 font-weight: 600;
151 }
152
153 /* Center Panel - Main Interface */
154 .main-interface {
155 background: var(--bg);
156 padding: calc(var(--spacing) * 2);
157 overflow-y: auto;
158 position: relative;
159 }
160
161 /* Multi-viewer overlay */
162 .viewer-overlay {
163 position: fixed;
164 top: 0;
165 left: 300px;
166 right: 350px;
167 bottom: 0;
168 background: rgba(0,0,0,0.95);
169 display: none;
170 align-items: center;
171 justify-content: center;
172 z-index: 100;
173 flex-direction: column;
174 gap: calc(var(--spacing) * 2);
175 }
176
177 .viewer-overlay.active {
178 display: flex;
179 }
180
181 .viewer-icons {
182 display: flex;
183 gap: calc(var(--spacing) * 2);
184 font-size: 64px;
185 opacity: 0.5;
186 }
187
188 .viewer-message {
189 font-size: 32px;
190 text-align: center;
191 max-width: 600px;
192 }
193
194 /* Voice mode overlay */
195 .voice-overlay {
196 position: fixed;
197 bottom: calc(var(--spacing) * 2);
198 left: 50%;
199 transform: translateX(-50%);
200 background: var(--surface-modal);
201 border: 2px solid var(--medium);
202 border-radius: 16px;
203 padding: calc(var(--spacing) * 1.5);
204 min-width: 500px;
205 display: none;
206 box-shadow: 0 8px 32px rgba(0,0,0,0.8);
207 z-index: 50;
208 }
209
210 .voice-overlay.active {
211 display: block;
212 }
213
214 .voice-output {
215 font-size: 18px;
216 line-height: 1.8;
217 margin-bottom: var(--spacing);
218 }
219
220 .voice-hints {
221 font-size: 12px;
222 color: var(--text-secondary);
223 border-top: 1px solid var(--border);
224 padding-top: var(--spacing);
225 }
226
227 /* Component Cards */
228 .component-grid {
229 display: grid;
230 grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
231 gap: calc(var(--spacing) * 1.5);
232 margin-bottom: calc(var(--spacing) * 2);
233 }
234
235 .component {
236 background: var(--surface);
237 border: 2px solid var(--border);
238 border-radius: 12px;
239 padding: calc(var(--spacing) * 1.5);
240 position: relative;
241 opacity: 1;
242 transition: all 0.3s;
243 }
244
245 .component.deferred {
246 opacity: 0.3;
247 transform: scale(0.95);
248 }
249
250 .component.hidden {
251 display: none;
252 }
253
254 .urgency-badge {
255 position: absolute;
256 top: calc(var(--spacing) / 2);
257 right: calc(var(--spacing) / 2);
258 padding: 4px 8px;
259 border-radius: 4px;
260 font-size: 10px;
261 font-weight: 700;
262 text-transform: uppercase;
263 letter-spacing: 0.5px;
264 }
265
266 .urgency-critical { background: var(--critical); color: white; }
267 .urgency-high { background: var(--high); color: white; }
268 .urgency-medium { background: var(--medium); color: white; }
269 .urgency-low { background: var(--low); color: white; }
270
271 .component-title {
272 font-size: 18px;
273 font-weight: 600;
274 margin-bottom: calc(var(--spacing) / 2);
275 padding-right: 60px;
276 }
277
278 .component-description {
279 font-size: 14px;
280 color: var(--text-secondary);
281 margin-bottom: var(--spacing);
282 }
283
284 .component-context {
285 font-size: 12px;
286 font-family: 'Monaco', monospace;
287 color: var(--success);
288 background: rgba(52, 199, 89, 0.1);
289 padding: calc(var(--spacing) / 2);
290 border-radius: 4px;
291 margin-top: var(--spacing);
292 white-space: pre-wrap;
293 }
294
295 .attention-score {
296 display: flex;
297 justify-content: space-between;
298 align-items: center;
299 margin-top: var(--spacing);
300 padding-top: var(--spacing);
301 border-top: 1px solid var(--border);
302 font-size: 12px;
303 }
304
305 .score-value {
306 font-weight: 700;
307 font-size: 16px;
308 }
309
310 .component-status {
311 margin-top: var(--spacing);
312 padding: calc(var(--spacing) / 2);
313 background: var(--surface-elevated);
314 border-radius: 6px;
315 font-size: 11px;
316 text-align: center;
317 }
318
319 .status-allocated { color: var(--success); }
320 .status-deferred { color: var(--orange); }
321 .status-hidden { color: var(--text-secondary); }
322
323 /* Right Panel - Priority Queue */
324 .priority-panel {
325 background: var(--surface);
326 border-left: 1px solid var(--border);
327 padding: calc(var(--spacing) * 1.5);
328 overflow-y: auto;
329 }
330
331 .priority-panel h2 {
332 font-size: 16px;
333 margin-bottom: var(--spacing);
334 text-transform: uppercase;
335 letter-spacing: 1px;
336 }
337
338 .resource-meters {
339 margin-bottom: calc(var(--spacing) * 2);
340 }
341
342 .meter {
343 margin-bottom: var(--spacing);
344 }
345
346 .meter-label {
347 font-size: 12px;
348 color: var(--text-secondary);
349 margin-bottom: 4px;
350 display: flex;
351 justify-content: space-between;
352 }
353
354 .meter-bar {
355 height: 8px;
356 background: var(--border);
357 border-radius: 4px;
358 overflow: hidden;
359 }
360
361 .meter-fill {
362 height: 100%;
363 background: linear-gradient(90deg, var(--success), var(--medium));
364 transition: width 0.3s;
365 }
366
367 .priority-queue {
368 display: flex;
369 flex-direction: column;
370 gap: calc(var(--spacing) / 2);
371 }
372
373 .queue-item {
374 background: var(--surface-elevated);
375 border-left: 4px solid;
376 padding: calc(var(--spacing) / 2) var(--spacing);
377 border-radius: 4px;
378 font-size: 13px;
379 animation: slideIn 0.3s;
380 }
381
382 @keyframes slideIn {
383 from {
384 transform: translateX(20px);
385 opacity: 0;
386 }
387 }
388
389 .queue-item.critical { border-color: var(--critical); }
390 .queue-item.high { border-color: var(--high); }
391 .queue-item.medium { border-color: var(--medium); }
392 .queue-item.low { border-color: var(--low); }
393
394 .queue-item-title {
395 font-weight: 600;
396 margin-bottom: 2px;
397 }
398
399 .queue-item-meta {
400 font-size: 11px;
401 color: var(--text-secondary);
402 }
403
404 .section-title {
405 font-size: 24px;
406 font-weight: 700;
407 margin-bottom: calc(var(--spacing) * 1.5);
408 padding-bottom: var(--spacing);
409 border-bottom: 1px solid var(--border);
410 }
411
412 /* Environmental indicators */
413 .env-indicators {
414 display: flex;
415 gap: var(--spacing);
416 margin-bottom: calc(var(--spacing) * 2);
417 flex-wrap: wrap;
418 }
419
420 .env-indicator {
421 display: flex;
422 align-items: center;
423 gap: calc(var(--spacing) / 2);
424 padding: calc(var(--spacing) / 2) var(--spacing);
425 background: var(--surface);
426 border: 1px solid var(--border);
427 border-radius: 8px;
428 font-size: 14px;
429 }
430
431 .env-indicator.active {
432 border-color: var(--medium);
433 background: rgba(0, 122, 255, 0.1);
434 }
435 </style>
436</head>
437<body>
438 <div class="dashboard">
439 <!-- Left Panel: Context Controls -->
440 <div class="context-panel">
441 <div class="context-section">
442 <h3>Input Modality</h3>
443 <div class="mode-select">
444 <button class="mode-btn active" data-mode="screen">🖥️ Screen Only</button>
445 <button class="mode-btn" data-mode="voice-screen">🎤📱 Voice + Screen</button>
446 <button class="mode-btn" data-mode="voice-only">🎤 Voice Only</button>
447 <button class="mode-btn" data-mode="touch">👆 Touch</button>
448 </div>
449 </div>
450
451 <div class="context-section">
452 <h3>Environment</h3>
453 <div class="context-option">
454 <label>Multi-Viewer Mode</label>
455 <div class="toggle" data-context="multi-viewer"></div>
456 </div>
457 <div class="context-option">
458 <label>Public Display</label>
459 <div class="toggle" data-context="public"></div>
460 </div>
461 </div>
462
463 <div class="context-section">
464 <h3>Ambient Noise</h3>
465 <div class="slider-control">
466 <input type="range" min="0" max="100" value="20" id="noise-level">
467 <div class="slider-value">
468 <span>Quiet</span>
469 <span id="noise-value">20%</span>
470 <span>Loud</span>
471 </div>
472 </div>
473 </div>
474
475 <div class="context-section">
476 <h3>Number of Viewers</h3>
477 <div class="slider-control">
478 <input type="range" min="1" max="10" value="1" id="viewer-count">
479 <div class="slider-value">
480 <span>1</span>
481 <span id="viewer-value">1 viewer</span>
482 <span>10</span>
483 </div>
484 </div>
485 </div>
486
487 <div class="context-section">
488 <h3>User State</h3>
489 <div class="context-option">
490 <label>User Busy</label>
491 <div class="toggle" data-context="busy"></div>
492 </div>
493 <div class="context-option">
494 <label>Focus Mode</label>
495 <div class="toggle" data-context="focus"></div>
496 </div>
497 </div>
498
499 <div class="context-section">
500 <h3>Time Context</h3>
501 <div class="context-option">
502 <label>After Hours</label>
503 <div class="toggle" data-context="after-hours"></div>
504 </div>
505 </div>
506 </div>
507
508 <!-- Center Panel: Main Interface -->
509 <div class="main-interface">
510 <div class="viewer-overlay">
511 <div class="viewer-icons">
512 <span>👤</span>
513 <span>👤</span>
514 <span>👤</span>
515 </div>
516 <div class="viewer-message">
517 Multi-viewer mode active<br>
518 <span style="font-size: 18px; opacity: 0.7;">Sensitive content hidden • Privacy protected</span>
519 </div>
520 </div>
521
522 <div class="voice-overlay">
523 <div class="voice-output" id="voice-output">
524 Listening...
525 </div>
526 <div class="voice-hints" id="voice-hints">
527 Available commands will appear here
528 </div>
529 </div>
530
531 <h1 class="section-title">Active Components</h1>
532
533 <div class="env-indicators">
534 <div class="env-indicator" data-indicator="modality">🖥️ Screen</div>
535 <div class="env-indicator" data-indicator="noise">🔇 Quiet</div>
536 <div class="env-indicator" data-indicator="viewers">👤 Single User</div>
537 <div class="env-indicator" data-indicator="state">✓ Available</div>
538 </div>
539
540 <div class="component-grid" id="components"></div>
541 </div>
542
543 <!-- Right Panel: Priority Queue -->
544 <div class="priority-panel">
545 <h2>Attention Budget</h2>
546
547 <div class="resource-meters">
548 <div class="meter">
549 <div class="meter-label">
550 <span>Screen Space</span>
551 <span id="screen-usage">0%</span>
552 </div>
553 <div class="meter-bar">
554 <div class="meter-fill" id="screen-meter" style="width: 0%"></div>
555 </div>
556 </div>
557
558 <div class="meter">
559 <div class="meter-label">
560 <span>Audio Time</span>
561 <span id="audio-usage">0s</span>
562 </div>
563 <div class="meter-bar">
564 <div class="meter-fill" id="audio-meter" style="width: 0%"></div>
565 </div>
566 </div>
567
568 <div class="meter">
569 <div class="meter-label">
570 <span>Cognitive Load</span>
571 <span id="cognitive-usage">0/3</span>
572 </div>
573 <div class="meter-bar">
574 <div class="meter-fill" id="cognitive-meter" style="width: 0%"></div>
575 </div>
576 </div>
577 </div>
578
579 <h2>Priority Queue</h2>
580 <div class="priority-queue" id="priority-queue"></div>
581 </div>
582 </div>
583
584 <script>
585 // Component definitions with context-aware behavior
586 const components = [
587 {
588 id: 'unsaved-changes',
589 title: 'Unsaved Changes',
590 description: 'Document has unsaved changes',
591 urgency: 'critical',
592 priority: 'user-initiated',
593 attentionWeight: 100,
594 canDefer: false,
595 screenSpace: 20,
596 audioTime: 3,
597 cognitiveLoad: 1,
598 contexts: {
599 'screen': 'Modal dialog with Save/Discard buttons',
600 'voice-screen': 'Say "save" or "discard"',
601 'voice-only': 'Your document has unsaved changes in 3 sections. Would you like to save, continue editing, or discard changes?',
602 'noisy': 'Visual emphasis + haptic confirmation required',
603 'multi-viewer': 'Hide document preview, show generic warning'
604 }
605 },
606 {
607 id: 'meeting-reminder',
608 title: 'Meeting Starting',
609 description: 'Team sync in 5 minutes',
610 urgency: 'high',
611 priority: 'time-sensitive',
612 attentionWeight: 80,
613 canDefer: false,
614 screenSpace: 15,
615 audioTime: 4,
616 cognitiveLoad: 1,
617 contexts: {
618 'screen': 'Notification banner with Join button',
619 'voice-screen': 'Meeting in 5 minutes. Say "join" when ready.',
620 'voice-only': 'Your team sync meeting starts in 5 minutes. The meeting link has been sent to your calendar. Would you like to join now?',
621 'busy': 'Defer until 2 minutes before',
622 'multi-viewer': 'Show meeting title only, hide attendees'
623 }
624 },
625 {
626 id: 'messages',
627 title: 'New Messages',
628 description: '3 unread from team channel',
629 urgency: 'medium',
630 priority: 'passive-info',
631 attentionWeight: 60,
632 canDefer: true,
633 screenSpace: 10,
634 audioTime: 5,
635 cognitiveLoad: 1,
636 contexts: {
637 'screen': 'Badge with count + preview',
638 'voice-screen': '3 new messages. Say "read messages" for details.',
639 'voice-only': 'You have 3 unread messages in the team channel. The most recent is from Sarah, sent 5 minutes ago: "Meeting has been moved to 3pm today." Would you like to hear the other messages?',
640 'busy': 'Defer until idle',
641 'focus': 'Collapse to badge only',
642 'multi-viewer': 'Hide content, show count only',
643 'public': 'Hide completely'
644 }
645 },
646 {
647 id: 'security-alert',
648 title: 'Security Alert',
649 description: 'Unusual login detected',
650 urgency: 'critical',
651 priority: 'system-critical',
652 attentionWeight: 95,
653 canDefer: false,
654 screenSpace: 25,
655 audioTime: 4,
656 cognitiveLoad: 1,
657 contexts: {
658 'screen': 'Full-screen modal with Verify/Block options',
659 'voice-screen': 'Security alert. Say "verify" if this was you, or "block" to secure account.',
660 'voice-only': 'Security alert: We detected an unusual login to your account from San Francisco, California. If this was you, say "verify". If not, say "block" to secure your account immediately.',
661 'multi-viewer': 'Generic security alert, require authentication to view details',
662 'public': 'Audio only, no screen display'
663 }
664 },
665 {
666 id: 'task-complete',
667 title: 'Task Completed',
668 description: 'Build finished successfully',
669 urgency: 'medium',
670 priority: 'user-requested',
671 attentionWeight: 50,
672 canDefer: true,
673 screenSpace: 10,
674 audioTime: 2,
675 cognitiveLoad: 0.5,
676 contexts: {
677 'screen': 'Success toast notification',
678 'voice-screen': 'Build complete.',
679 'voice-only': 'Your build has finished successfully. All tests passed.',
680 'busy': 'Defer until current task complete',
681 'focus': 'Silent notification'
682 }
683 },
684 {
685 id: 'update-available',
686 title: 'Update Available',
687 description: 'Version 2.1.0 ready to install',
688 urgency: 'low',
689 priority: 'promotional',
690 attentionWeight: 20,
691 canDefer: true,
692 screenSpace: 8,
693 audioTime: 3,
694 cognitiveLoad: 0.5,
695 contexts: {
696 'screen': 'Small banner at bottom',
697 'voice-screen': 'Update available.',
698 'voice-only': 'A software update is available. Version 2.1.0 includes performance improvements and bug fixes. Would you like to install now?',
699 'busy': 'Defer until idle',
700 'focus': 'Hide completely',
701 'after-hours': 'Auto-schedule for off-hours'
702 }
703 },
704 {
705 id: 'calendar-event',
706 title: 'Calendar Event',
707 description: 'Lunch with Alex at 12:30',
708 urgency: 'medium',
709 priority: 'time-sensitive',
710 attentionWeight: 65,
711 canDefer: true,
712 screenSpace: 12,
713 audioTime: 3,
714 cognitiveLoad: 0.5,
715 contexts: {
716 'screen': 'Calendar notification with location',
717 'voice-screen': 'Lunch with Alex at 12:30.',
718 'voice-only': 'You have lunch scheduled with Alex at 12:30pm at The Bistro on Main Street.',
719 'multi-viewer': 'Hide personal calendar events',
720 'public': 'Hide completely'
721 }
722 },
723 {
724 id: 'system-resources',
725 title: 'Resource Warning',
726 description: 'Memory usage at 85%',
727 urgency: 'medium',
728 priority: 'system-critical',
729 attentionWeight: 55,
730 canDefer: true,
731 screenSpace: 10,
732 audioTime: 2,
733 cognitiveLoad: 0.5,
734 contexts: {
735 'screen': 'System indicator with details',
736 'voice-screen': 'Memory usage high.',
737 'voice-only': 'System resources warning: Memory usage is at 85 percent. Consider closing unused applications.',
738 'busy': 'Defer unless critical',
739 'focus': 'Collapse to icon'
740 }
741 }
742 ];
743
744 // State
745 let context = {
746 mode: 'screen',
747 'multi-viewer': false,
748 'public': false,
749 'busy': false,
750 'focus': false,
751 'after-hours': false,
752 noiseLevel: 20,
753 viewerCount: 1
754 };
755
756 const MAX_SCREEN_SPACE = 100;
757 const MAX_AUDIO_TIME = 10; // seconds
758 const MAX_COGNITIVE = 3;
759
760 // Calculate attention score
761 function calculateScore(component) {
762 let score = component.attentionWeight;
763
764 // Urgency multipliers
765 const urgencyMultiplier = {
766 'critical': 2.0,
767 'high': 1.5,
768 'medium': 1.0,
769 'low': 0.5
770 };
771 score *= urgencyMultiplier[component.urgency];
772
773 // Context penalties
774 if (context.busy && component.canDefer) score *= 0.3;
775 if (context.focus && component.urgency !== 'critical') score *= 0.5;
776 if (context['after-hours'] && component.priority === 'promotional') score *= 0.1;
777 if (context.noiseLevel > 70 && context.mode.includes('voice')) score *= 0.7;
778
779 return Math.round(score);
780 }
781
782 // Render components
783 function render() {
784 const sorted = [...components]
785 .map(c => ({ ...c, score: calculateScore(c) }))
786 .sort((a, b) => b.score - a.score);
787
788 let screenUsed = 0;
789 let audioUsed = 0;
790 let cognitiveUsed = 0;
791
792 const allocated = [];
793 const deferred = [];
794
795 for (const component of sorted) {
796 const wouldUseScreen = screenUsed + component.screenSpace;
797 const wouldUseAudio = audioUsed + component.audioTime;
798 const wouldUseCognitive = cognitiveUsed + component.cognitiveLoad;
799
800 const canAllocate =
801 wouldUseScreen <= MAX_SCREEN_SPACE &&
802 wouldUseAudio <= MAX_AUDIO_TIME &&
803 wouldUseCognitive <= MAX_COGNITIVE;
804
805 if (canAllocate && component.score > 10) {
806 allocated.push({ ...component, status: 'allocated' });
807 screenUsed = wouldUseScreen;
808 audioUsed = wouldUseAudio;
809 cognitiveUsed = wouldUseCognitive;
810 } else {
811 deferred.push({ ...component, status: 'deferred' });
812 }
813 }
814
815 // Check for hiding conditions
816 const shouldHide = (component) => {
817 if (context['multi-viewer'] && component.contexts['multi-viewer']?.includes('Hide')) return true;
818 if (context['public'] && component.contexts['public']?.includes('Hide')) return true;
819 if (context.focus && component.contexts['focus']?.includes('Hide')) return true;
820 return false;
821 };
822
823 // Render components
824 const grid = document.getElementById('components');
825 grid.innerHTML = [...allocated, ...deferred].map(c => {
826 const hidden = shouldHide(c);
827 const contextKey = Object.keys(c.contexts).find(k => {
828 if (k === context.mode) return true;
829 if (k === 'noisy' && context.noiseLevel > 60) return true;
830 if (k === 'multi-viewer' && context['multi-viewer']) return true;
831 if (k === 'busy' && context.busy) return true;
832 if (k === 'focus' && context.focus) return true;
833 if (k === 'public' && context.public) return true;
834 if (k === 'after-hours' && context['after-hours']) return true;
835 return false;
836 }) || context.mode;
837
838 const contextOutput = c.contexts[contextKey] || c.contexts['screen'];
839
840 return `
841 <div class="component ${c.status === 'deferred' ? 'deferred' : ''} ${hidden ? 'hidden' : ''}">
842 <div class="urgency-badge urgency-${c.urgency}">${c.urgency}</div>
843 <div class="component-title">${c.title}</div>
844 <div class="component-description">${c.description}</div>
845 <div class="component-context">${contextOutput}</div>
846 <div class="attention-score">
847 <span>Attention Score:</span>
848 <span class="score-value">${c.score}</span>
849 </div>
850 <div class="component-status status-${c.status}">
851 ${c.status === 'allocated' ? '✓ ALLOCATED' : '⏸ DEFERRED'}
852 ${hidden ? '(HIDDEN)' : ''}
853 </div>
854 </div>
855 `;
856 }).join('');
857
858 // Update meters
859 document.getElementById('screen-meter').style.width = (screenUsed / MAX_SCREEN_SPACE * 100) + '%';
860 document.getElementById('screen-usage').textContent = Math.round(screenUsed) + '%';
861
862 document.getElementById('audio-meter').style.width = (audioUsed / MAX_AUDIO_TIME * 100) + '%';
863 document.getElementById('audio-usage').textContent = audioUsed + 's';
864
865 document.getElementById('cognitive-meter').style.width = (cognitiveUsed / MAX_COGNITIVE * 100) + '%';
866 document.getElementById('cognitive-usage').textContent = cognitiveUsed.toFixed(1) + '/3';
867
868 // Update priority queue
869 const queue = document.getElementById('priority-queue');
870 queue.innerHTML = [...allocated, ...deferred].map((c, i) => `
871 <div class="queue-item ${c.urgency}">
872 <div class="queue-item-title">${i + 1}. ${c.title}</div>
873 <div class="queue-item-meta">
874 Score: ${c.score} | ${c.status.toUpperCase()} | ${c.priority}
875 </div>
876 </div>
877 `).join('');
878
879 // Update voice overlay
880 if (context.mode.includes('voice')) {
881 const voiceOverlay = document.querySelector('.voice-overlay');
882 voiceOverlay.classList.add('active');
883
884 const topComponents = allocated.slice(0, 3);
885 const output = topComponents.map(c => {
886 const contextKey = context.mode === 'voice-only' ? 'voice-only' : 'voice-screen';
887 return c.contexts[contextKey] || c.contexts['voice-screen'];
888 }).join('\n\n');
889
890 document.getElementById('voice-output').textContent = output || 'No urgent items.';
891 document.getElementById('voice-hints').textContent =
892 context.mode === 'voice-only'
893 ? 'Commands: save, discard, join, read messages, verify, block'
894 : 'Available on screen ↑ or say command';
895 } else {
896 document.querySelector('.voice-overlay').classList.remove('active');
897 }
898
899 // Update multi-viewer overlay
900 if (context['multi-viewer'] || context.viewerCount > 1) {
901 document.querySelector('.viewer-overlay').classList.add('active');
902 } else {
903 document.querySelector('.viewer-overlay').classList.remove('active');
904 }
905
906 // Update env indicators
907 const indicators = {
908 modality: {
909 'screen': '🖥️ Screen',
910 'voice-screen': '🎤📱 Voice + Screen',
911 'voice-only': '🎤 Voice Only',
912 'touch': '👆 Touch'
913 }[context.mode],
914 noise: context.noiseLevel < 30 ? '🔇 Quiet' : context.noiseLevel < 70 ? '🔉 Moderate' : '🔊 Loud',
915 viewers: context.viewerCount === 1 ? '👤 Single User' : `👥 ${context.viewerCount} Viewers`,
916 state: context.busy ? '⏳ Busy' : context.focus ? '🎯 Focus' : '✓ Available'
917 };
918
919 document.querySelectorAll('.env-indicator').forEach(el => {
920 const type = el.dataset.indicator;
921 el.textContent = indicators[type];
922 el.classList.toggle('active',
923 type === 'noise' && context.noiseLevel > 60 ||
924 type === 'viewers' && context.viewerCount > 1 ||
925 type === 'state' && (context.busy || context.focus)
926 );
927 });
928 }
929
930 // Event listeners
931 document.querySelectorAll('.mode-btn').forEach(btn => {
932 btn.addEventListener('click', () => {
933 document.querySelectorAll('.mode-btn').forEach(b => b.classList.remove('active'));
934 btn.classList.add('active');
935 context.mode = btn.dataset.mode;
936 render();
937 });
938 });
939
940 document.querySelectorAll('.toggle').forEach(toggle => {
941 toggle.addEventListener('click', () => {
942 toggle.classList.toggle('active');
943 context[toggle.dataset.context] = toggle.classList.contains('active');
944 render();
945 });
946 });
947
948 document.getElementById('noise-level').addEventListener('input', (e) => {
949 context.noiseLevel = parseInt(e.target.value);
950 document.getElementById('noise-value').textContent = context.noiseLevel + '%';
951 render();
952 });
953
954 document.getElementById('viewer-count').addEventListener('input', (e) => {
955 context.viewerCount = parseInt(e.target.value);
956 document.getElementById('viewer-value').textContent =
957 context.viewerCount === 1 ? '1 viewer' : context.viewerCount + ' viewers';
958 render();
959 });
960
961 // Initial render
962 render();
963 </script>
964</body>
965</html>