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

0 downloads

dbbasic-web-native/semantic-components.js
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
semantic-components.js · 115.5 KB · 3749 lines
1/**
2 * Semantic Web Components Library
3 * Version: 1.0.0
4 *
5 * Intent-based, context-aware, modality-agnostic UI components
6 * for building applications that work across any interaction method.
7 */
8
9// ============================================================================
10// CONTEXT MANAGER
11// ============================================================================
12
13class ContextManager {
14 constructor() {
15 this.context = {
16 modality: 'screen',
17 environment: {
18 noiseLevel: 0,
19 viewerCount: 1,
20 isPublic: false,
21 lighting: 'normal'
22 },
23 user: {
24 isBusy: false,
25 inFocusMode: false,
26 prefersReducedMotion: false
27 },
28 attention: {
29 maxScreenSpace: 100,
30 maxAudioTime: 10,
31 maxCognitiveLoad: 3,
32 usedScreenSpace: 0,
33 usedAudioTime: 0,
34 usedCognitiveLoad: 0
35 }
36 };
37
38 this.components = new Set();
39 this.listeners = new Set();
40 }
41
42 register(component) {
43 this.components.add(component);
44 this.notifyChange();
45 }
46
47 unregister(component) {
48 this.components.delete(component);
49 this.notifyChange();
50 }
51
52 updateContext(updates) {
53 this.context = { ...this.context, ...updates };
54 this.notifyChange();
55 }
56
57 setModality(modality) {
58 this.context.modality = modality;
59 this.notifyChange();
60 }
61
62 notifyChange() {
63 this.allocateAttention();
64 this.listeners.forEach(listener => listener(this.context));
65 }
66
67 allocateAttention() {
68 // Get all components that need attention
69 const needsAttention = Array.from(this.components)
70 .filter(c => c.computeAttentionScore)
71 .map(c => ({
72 component: c,
73 score: c.computeAttentionScore(this.context)
74 }))
75 .sort((a, b) => b.score - a.score);
76
77 // Reset attention budget
78 let screenUsed = 0;
79 let audioUsed = 0;
80 let cognitiveUsed = 0;
81
82 // Allocate resources in priority order
83 needsAttention.forEach(({ component, score }) => {
84 const needs = component.getAttentionNeeds();
85
86 const canAllocate =
87 screenUsed + needs.screen <= this.context.attention.maxScreenSpace &&
88 audioUsed + needs.audio <= this.context.attention.maxAudioTime &&
89 cognitiveUsed + needs.cognitive <= this.context.attention.maxCognitiveLoad;
90
91 if (canAllocate && score > 10) {
92 component.setAttribute('attention-state', 'allocated');
93 screenUsed += needs.screen;
94 audioUsed += needs.audio;
95 cognitiveUsed += needs.cognitive;
96 } else {
97 component.setAttribute('attention-state', 'deferred');
98 }
99 });
100
101 this.context.attention.usedScreenSpace = screenUsed;
102 this.context.attention.usedAudioTime = audioUsed;
103 this.context.attention.usedCognitiveLoad = cognitiveUsed;
104 }
105
106 onChange(callback) {
107 this.listeners.add(callback);
108 return () => this.listeners.delete(callback);
109 }
110}
111
112// Global context manager
113window.semanticContext = window.semanticContext || new ContextManager();
114
115// ============================================================================
116// BASE SEMANTIC COMPONENT
117// ============================================================================
118
119class SemanticComponent extends HTMLElement {
120 constructor() {
121 super();
122 this.attachShadow({ mode: 'open' });
123 }
124
125 connectedCallback() {
126 window.semanticContext.register(this);
127 this.render();
128 this.setupEventListeners();
129 }
130
131 disconnectedCallback() {
132 window.semanticContext.unregister(this);
133 }
134
135 computeAttentionScore(context) {
136 const urgency = this.getAttribute('urgency') || 'medium';
137 const priority = this.getAttribute('priority') || 'passive-info';
138 const weight = parseInt(this.getAttribute('attention-weight') || '50');
139
140 const urgencyMultiplier = {
141 'critical': 2.0,
142 'high': 1.5,
143 'medium': 1.0,
144 'low': 0.5
145 };
146
147 let score = weight * urgencyMultiplier[urgency];
148
149 // Context penalties
150 if (context.user.isBusy && this.canDefer()) score *= 0.3;
151 if (context.user.inFocusMode && urgency !== 'critical') score *= 0.5;
152 if (context.environment.noiseLevel > 70 && context.modality.includes('voice')) score *= 0.7;
153
154 return Math.round(score);
155 }
156
157 getAttentionNeeds() {
158 return {
159 screen: parseInt(this.getAttribute('screen-space') || '10'),
160 audio: parseInt(this.getAttribute('audio-time') || '2'),
161 cognitive: parseFloat(this.getAttribute('cognitive-load') || '0.5')
162 };
163 }
164
165 canDefer() {
166 return this.getAttribute('can-defer') !== 'false';
167 }
168
169 shouldHideInContext(context) {
170 const sensitivity = this.getAttribute('sensitivity');
171 if (sensitivity === 'private' && context.environment.viewerCount > 1) return true;
172 if (sensitivity === 'private' && context.environment.isPublic) return true;
173 if (this.getAttribute('urgency') === 'low' && context.user.inFocusMode) return true;
174 return false;
175 }
176
177 emitIntent(intentType, detail = {}) {
178 this.dispatchEvent(new CustomEvent('intent', {
179 bubbles: true,
180 composed: true,
181 detail: { type: intentType, ...detail }
182 }));
183 }
184
185 getStyles() {
186 return `
187 :host {
188 display: block;
189 box-sizing: border-box;
190 max-width: 100%;
191 }
192 * {
193 box-sizing: border-box;
194 }
195
196 /* Mobile responsive - removed font-size reduction to maintain touch target sizes */
197 `;
198 }
199
200 getIntentColors() {
201 const intent = this.getAttribute('intent') || 'secondary';
202 const sentiment = this.getAttribute('sentiment') || 'neutral';
203
204 // Base colors
205 const colors = {
206 bg: '#2c2c2e',
207 border: '#38383a',
208 borderHover: '#4d9fff',
209 text: '#fff'
210 };
211
212 // Intent overrides
213 if (intent === 'primary') {
214 colors.bg = '#1c1c1e';
215 colors.border = '#409cff';
216 colors.borderHover = '#64b5ff';
217 }
218
219 // Sentiment overrides
220 if (sentiment === 'positive') {
221 colors.border = '#34c759';
222 colors.borderHover = '#48d368';
223 } else if (sentiment === 'negative') {
224 colors.border = '#ff3b30';
225 colors.borderHover = '#ff453a';
226 } else if (sentiment === 'warning') {
227 colors.border = '#ff9500';
228 colors.borderHover = '#ffa624';
229 }
230
231 return colors;
232 }
233}
234
235// ============================================================================
236// ACTION COMPONENT
237// ============================================================================
238
239class SemanticAction extends SemanticComponent {
240 static get observedAttributes() {
241 return ['intent', 'sentiment', 'disabled'];
242 }
243
244 render() {
245 const intent = this.getAttribute('intent') || 'secondary';
246 const sentiment = this.getAttribute('sentiment') || 'neutral';
247 const disabled = this.hasAttribute('disabled');
248
249 this.shadowRoot.innerHTML = `
250 <style>
251 ${this.getStyles()}
252
253 button {
254 min-height: 44px;
255 min-width: 88px;
256 padding: 12px 24px;
257 border: none;
258 border-radius: 8px;
259 font-size: 16px;
260 font-weight: 600;
261 font-family: inherit;
262 cursor: pointer;
263 transition: all 0.2s;
264 position: relative;
265 display: inline-flex;
266 align-items: center;
267 justify-content: center;
268 gap: 8px;
269 /* Support CSS custom properties for forced demo states (only when set) */
270 transform: var(--demo-transform);
271 box-shadow: var(--demo-box-shadow);
272 filter: var(--demo-filter);
273 outline: var(--demo-outline);
274 outline-offset: var(--demo-outline-offset);
275 }
276
277 button:focus-visible {
278 outline: 3px solid #4d9fff;
279 outline-offset: 2px;
280 }
281
282 /* Intent styles */
283 button[data-intent="primary"] {
284 background: #0066cc; /* Darker blue for WCAG AA with white text (5.9:1) */
285 color: white;
286 }
287
288 button[data-intent="secondary"] {
289 background: #8e8e93;
290 color: white;
291 }
292
293 button[data-intent="tertiary"] {
294 background: transparent;
295 color: #409cff;
296 border: 2px solid #409cff;
297 }
298
299 /* Sentiment overrides */
300 button[data-sentiment="constructive"] {
301 background: #34c759;
302 }
303
304 button[data-sentiment="destructive"] {
305 background: #ff3b30;
306 }
307
308 /* States */
309 button:hover:not(:disabled) {
310 transform: translateY(-2px);
311 box-shadow: 0 3px 8px rgba(64, 156, 255, 0.6);
312 filter: brightness(1.2);
313 }
314
315 button:active:not(:disabled) {
316 transform: scale(0.96) translateY(1px);
317 box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
318 filter: brightness(0.85);
319 }
320
321 button:disabled {
322 background: #3a3a3a !important;
323 color: #8f8f8f !important;
324 opacity: 1;
325 cursor: not-allowed;
326 border-color: #3a3a3a !important;
327 }
328
329 /* Long-press indicator */
330 button.inspecting::after {
331 content: '';
332 position: absolute;
333 inset: -4px;
334 border: 3px solid #4d9fff;
335 border-radius: 10px;
336 animation: pulse 1s infinite;
337 }
338
339 @keyframes pulse {
340 0%, 100% { opacity: 1; }
341 50% { opacity: 0.5; }
342 }
343
344
345 @media (prefers-reduced-motion: reduce) {
346 button {
347 transition: none;
348 }
349 button:hover:not(:disabled) {
350 transform: none;
351 }
352 button:active:not(:disabled) {
353 transform: none;
354 }
355 }
356 </style>
357 <button
358 data-intent="${intent}"
359 data-sentiment="${sentiment}"
360 ?disabled="${disabled}"
361 part="button"
362 >
363 <slot></slot>
364 </button>
365 `;
366 }
367
368 setupEventListeners() {
369 const button = this.shadowRoot.querySelector('button');
370 let longPressTimer = null;
371
372 // ACTIVATE intent
373 button.addEventListener('click', (e) => {
374 if (!this.hasAttribute('disabled')) {
375 this.emitIntent('activate');
376 }
377 });
378
379 // INSPECT intent (long-press)
380 button.addEventListener('mousedown', () => {
381 longPressTimer = setTimeout(() => {
382 button.classList.add('inspecting');
383 this.emitIntent('inspect');
384 }, 500);
385 });
386
387 button.addEventListener('mouseup', () => {
388 clearTimeout(longPressTimer);
389 button.classList.remove('inspecting');
390 });
391
392 button.addEventListener('mouseleave', () => {
393 clearTimeout(longPressTimer);
394 button.classList.remove('inspecting');
395 });
396
397 // Keyboard support
398 button.addEventListener('keydown', (e) => {
399 if (e.key === 'Enter' || e.key === ' ') {
400 e.preventDefault();
401 if (!this.hasAttribute('disabled')) {
402 this.emitIntent('activate');
403 }
404 }
405 });
406 }
407
408 attributeChangedCallback() {
409 if (this.shadowRoot.innerHTML) {
410 this.render();
411 this.setupEventListeners();
412 }
413 }
414}
415
416// ============================================================================
417// CARD COMPONENT
418// ============================================================================
419
420class SemanticCard extends SemanticComponent {
421 static get observedAttributes() {
422 return ['intent', 'sentiment', 'media-url', 'media-alt'];
423 }
424
425 render() {
426 const mediaUrl = this.getAttribute('media-url') || '';
427 const mediaAlt = this.getAttribute('media-alt') || '';
428 const colors = this.getIntentColors();
429
430 this.shadowRoot.innerHTML = `
431 <style>
432 ${this.getStyles()}
433
434 .card {
435 background: ${colors.bg};
436 border: 2px solid ${colors.border};
437 border-radius: 12px;
438 cursor: pointer;
439 transition: all 0.3s;
440 position: relative;
441 color: ${colors.text};
442 }
443
444 .card:hover {
445 border-color: ${colors.borderHover};
446 transform: translateY(-4px);
447 box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
448 }
449
450 .card.inspecting {
451 border-color: #4d9fff;
452 box-shadow: 0 0 0 4px rgba(77, 159, 255, 0.2);
453 }
454
455 .preview {
456 position: absolute;
457 bottom: 100%;
458 left: 0;
459 right: 0;
460 background: #2c2c2e;
461 border: 2px solid #0066cc;
462 border-radius: 12px;
463 padding: 16px;
464 margin-bottom: 8px;
465 opacity: 0;
466 transform: translateY(20px);
467 transition: all 0.3s;
468 pointer-events: none;
469 z-index: 10;
470 }
471
472 .card:hover .preview,
473 .card.inspecting .preview {
474 opacity: 1;
475 transform: translateY(0);
476 }
477
478 .media {
479 width: 100%;
480 height: 200px;
481 object-fit: cover;
482 display: block;
483 }
484
485 .media-placeholder {
486 width: 100%;
487 height: 200px;
488 background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
489 display: flex;
490 align-items: center;
491 justify-content: center;
492 font-size: 48px;
493 }
494
495 .content {
496 padding: 16px;
497 }
498
499 .actions {
500 padding: 12px 16px;
501 background: #2c2c2e;
502 border-top: 1px solid #38383a;
503 display: flex;
504 gap: 8px;
505 }
506
507 ::slotted([slot="title"]) {
508 font-size: 18px;
509 font-weight: 600;
510 margin: 0 0 8px 0;
511 }
512
513 ::slotted([slot="description"]) {
514 color: #8a8a8a;
515 font-size: 14px;
516 margin: 0;
517 }
518
519 @media (prefers-reduced-motion: reduce) {
520 .card, .preview {
521 transition: none;
522 }
523 .card:hover {
524 transform: none;
525 }
526 }
527 </style>
528 <div class="card" part="card" role="article" tabindex="0">
529 <div class="preview" part="preview">
530 <slot name="preview">Preview content appears here</slot>
531 </div>
532 ${mediaUrl ?
533 `<img class="media" src="${mediaUrl}" alt="${mediaAlt}" part="media">` :
534 `<div class="media-placeholder" part="media-placeholder">
535 <slot name="media-icon">📄</slot>
536 </div>`
537 }
538 <div class="content" part="content">
539 <slot name="title"></slot>
540 <slot name="description"></slot>
541 <slot></slot>
542 </div>
543 <div class="actions" part="actions">
544 <slot name="actions"></slot>
545 </div>
546 </div>
547 `;
548 }
549
550 setupEventListeners() {
551 const card = this.shadowRoot.querySelector('.card');
552 let longPressTimer = null;
553
554 // ACTIVATE intent (navigate)
555 card.addEventListener('click', (e) => {
556 if (!e.target.closest('[slot="actions"]')) {
557 this.emitIntent('activate', { action: 'navigate' });
558 }
559 });
560
561 // INSPECT intent (preview)
562 card.addEventListener('mouseenter', () => {
563 this.emitIntent('inspect', { action: 'preview' });
564 });
565
566 // Long-press for touch
567 card.addEventListener('mousedown', (e) => {
568 if (!e.target.closest('[slot="actions"]')) {
569 longPressTimer = setTimeout(() => {
570 card.classList.add('inspecting');
571 this.emitIntent('inspect', { action: 'preview', method: 'long-press' });
572 }, 500);
573 }
574 });
575
576 card.addEventListener('mouseup', () => {
577 clearTimeout(longPressTimer);
578 setTimeout(() => card.classList.remove('inspecting'), 2000);
579 });
580
581 card.addEventListener('mouseleave', () => {
582 clearTimeout(longPressTimer);
583 card.classList.remove('inspecting');
584 });
585
586 // Keyboard
587 card.addEventListener('keydown', (e) => {
588 if (e.key === 'Enter') {
589 this.emitIntent('activate', { action: 'navigate' });
590 }
591 });
592 }
593
594 attributeChangedCallback() {
595 if (this.shadowRoot.innerHTML) {
596 this.render();
597 this.setupEventListeners();
598 }
599 }
600}
601
602// ============================================================================
603// FEEDBACK COMPONENT (Notifications)
604// ============================================================================
605
606class SemanticFeedback extends SemanticComponent {
607 static get observedAttributes() {
608 return ['urgency', 'type', 'auto-dismiss'];
609 }
610
611 render() {
612 const urgency = this.getAttribute('urgency') || 'medium';
613 const type = this.getAttribute('type') || 'notification';
614 const autoDismiss = this.hasAttribute('auto-dismiss');
615
616 this.shadowRoot.innerHTML = `
617 <style>
618 ${this.getStyles()}
619
620 .feedback {
621 padding: 16px;
622 border-radius: 8px;
623 border-left: 4px solid;
624 background: #2c2c2e;
625 display: flex;
626 align-items: flex-start;
627 gap: 12px;
628 animation: slideIn 0.3s;
629 }
630
631 @keyframes slideIn {
632 from {
633 transform: translateX(100%);
634 opacity: 0;
635 }
636 }
637
638 .feedback[data-urgency="critical"] {
639 border-color: #ff3b30;
640 background: rgba(255, 59, 48, 0.1);
641 }
642
643 .feedback[data-urgency="high"] {
644 border-color: #ff9500;
645 background: rgba(255, 149, 0, 0.1);
646 }
647
648 .feedback[data-urgency="medium"] {
649 border-color: #0066cc;
650 background: rgba(0, 122, 255, 0.1);
651 }
652
653 .feedback[data-urgency="low"] {
654 border-color: #8e8e93;
655 }
656
657 .icon {
658 font-size: 24px;
659 flex-shrink: 0;
660 }
661
662 .content {
663 flex: 1;
664 }
665
666 .dismiss {
667 background: none;
668 border: none;
669 color: #8a8a8a;
670 cursor: pointer;
671 font-size: 20px;
672 padding: 0;
673 width: 44px;
674 height: 44px;
675 flex-shrink: 0;
676 display: flex;
677 align-items: center;
678 justify-content: center;
679 }
680
681 .dismiss:hover {
682 color: #fff;
683 }
684
685 :host([attention-state="deferred"]) {
686 opacity: 0.5;
687 /* Removed scale to maintain 44px minimum touch targets */
688 filter: grayscale(0.5);
689 }
690
691 :host([hidden]) {
692 display: none;
693 }
694
695 @media (prefers-reduced-motion: reduce) {
696 .feedback {
697 animation: none;
698 }
699 }
700 </style>
701 <div class="feedback" data-urgency="${urgency}" data-type="${type}" role="alert" part="feedback">
702 <div class="icon" part="icon">
703 <slot name="icon">${this.getIcon(urgency)}</slot>
704 </div>
705 <div class="content" part="content">
706 <slot></slot>
707 </div>
708 <button class="dismiss" aria-label="Dismiss" part="dismiss">×</button>
709 </div>
710 `;
711
712 if (autoDismiss) {
713 setTimeout(() => this.dismiss(), 5000);
714 }
715 }
716
717 getIcon(urgency) {
718 const icons = {
719 'critical': '⚠️',
720 'high': '❗',
721 'medium': 'ℹ️',
722 'low': '💡'
723 };
724 return icons[urgency] || icons.medium;
725 }
726
727 setupEventListeners() {
728 const dismissBtn = this.shadowRoot.querySelector('.dismiss');
729 dismissBtn.addEventListener('click', () => this.dismiss());
730 }
731
732 dismiss() {
733 this.emitIntent('dismiss');
734 this.remove();
735 }
736
737 attributeChangedCallback() {
738 if (this.shadowRoot.innerHTML) {
739 this.render();
740 this.setupEventListeners();
741 }
742 }
743}
744
745// ============================================================================
746// INPUT ADJUSTER COMPONENT
747// ============================================================================
748
749class SemanticAdjuster extends SemanticComponent {
750 static get observedAttributes() {
751 return ['intent', 'sentiment', 'value', 'min', 'max', 'step', 'label'];
752 }
753
754 constructor() {
755 super();
756 this._value = 50;
757 }
758
759 get value() {
760 return this._value;
761 }
762
763 set value(val) {
764 const min = parseFloat(this.getAttribute('min') || '0');
765 const max = parseFloat(this.getAttribute('max') || '100');
766 this._value = Math.max(min, Math.min(max, parseFloat(val)));
767 this.render();
768 this.emitIntent('adjust', { value: this._value });
769 }
770
771 render() {
772 const label = this.getAttribute('label') || 'Value';
773 const min = this.getAttribute('min') || '0';
774 const max = this.getAttribute('max') || '100';
775 const step = this.getAttribute('step') || '1';
776 const colors = this.getIntentColors();
777
778 this.shadowRoot.innerHTML = `
779 <style>
780 ${this.getStyles()}
781
782 .adjuster {
783 display: flex;
784 flex-direction: column;
785 gap: 12px;
786 }
787
788 .label {
789 font-size: 16px;
790 font-weight: 600;
791 color: ${colors.text};
792 }
793
794 .controls {
795 display: flex;
796 align-items: center;
797 gap: 16px;
798 }
799
800 .value {
801 font-size: 32px;
802 font-weight: 700;
803 color: #409cff;
804 min-width: 80px;
805 text-align: center;
806 }
807
808 button {
809 width: 48px;
810 height: 48px;
811 border-radius: 50%;
812 background: ${colors.bg};
813 border: 2px solid ${colors.border};
814 color: ${colors.text};
815 font-size: 24px;
816 cursor: pointer;
817 transition: all 0.2s;
818 display: flex;
819 align-items: center;
820 justify-content: center;
821 }
822
823 button:hover {
824 background: ${colors.bgHover};
825 border-color: ${colors.borderHover};
826 transform: scale(1.1);
827 }
828
829 button:active {
830 transform: scale(0.95);
831 }
832
833 .slider {
834 flex: 1;
835 height: 8px;
836 background: #38383a;
837 border-radius: 4px;
838 position: relative;
839 cursor: pointer;
840 }
841
842 .slider-fill {
843 height: 100%;
844 background: #0066cc;
845 border-radius: 4px;
846 transition: width 0.2s;
847 }
848
849 .slider-thumb {
850 position: absolute;
851 top: 50%;
852 transform: translate(-50%, -50%);
853 width: 24px;
854 height: 24px;
855 background: white;
856 border: 3px solid #0066cc;
857 border-radius: 50%;
858 cursor: grab;
859 transition: all 0.2s;
860 }
861
862 .slider-thumb:active {
863 cursor: grabbing;
864 transform: translate(-50%, -50%) scale(1.2);
865 }
866
867 @media (prefers-reduced-motion: reduce) {
868 button, .slider-fill, .slider-thumb {
869 transition: none;
870 }
871 button:hover {
872 transform: none;
873 }
874 }
875 </style>
876 <div class="adjuster" part="adjuster">
877 <label class="label" part="label">${label}</label>
878 <div class="controls">
879 <button class="decrease" aria-label="Decrease" part="decrease">−</button>
880 <div class="value" part="value">${this._value}</div>
881 <button class="increase" aria-label="Increase" part="increase">+</button>
882 </div>
883 <div class="slider" part="slider">
884 <div class="slider-fill" style="width: ${this.getPercentage()}%"></div>
885 <div class="slider-thumb" style="left: ${this.getPercentage()}%"></div>
886 </div>
887 </div>
888 `;
889 }
890
891 getPercentage() {
892 const min = parseFloat(this.getAttribute('min') || '0');
893 const max = parseFloat(this.getAttribute('max') || '100');
894 return ((this._value - min) / (max - min)) * 100;
895 }
896
897 setupEventListeners() {
898 const decreaseBtn = this.shadowRoot.querySelector('.decrease');
899 const increaseBtn = this.shadowRoot.querySelector('.increase');
900 const slider = this.shadowRoot.querySelector('.slider');
901 const step = parseFloat(this.getAttribute('step') || '5');
902
903 decreaseBtn.addEventListener('click', () => {
904 this.value = this._value - step;
905 });
906
907 increaseBtn.addEventListener('click', () => {
908 this.value = this._value + step;
909 });
910
911 let isDragging = false;
912
913 const updateFromPosition = (clientX) => {
914 const rect = slider.getBoundingClientRect();
915 const percent = Math.max(0, Math.min(100, ((clientX - rect.left) / rect.width) * 100));
916 const min = parseFloat(this.getAttribute('min') || '0');
917 const max = parseFloat(this.getAttribute('max') || '100');
918 this.value = min + (percent / 100) * (max - min);
919 };
920
921 slider.addEventListener('mousedown', (e) => {
922 isDragging = true;
923 updateFromPosition(e.clientX);
924 });
925
926 document.addEventListener('mousemove', (e) => {
927 if (isDragging) updateFromPosition(e.clientX);
928 });
929
930 document.addEventListener('mouseup', () => {
931 isDragging = false;
932 });
933
934 // Touch support
935 slider.addEventListener('touchstart', (e) => {
936 isDragging = true;
937 updateFromPosition(e.touches[0].clientX);
938 });
939
940 document.addEventListener('touchmove', (e) => {
941 if (isDragging) updateFromPosition(e.touches[0].clientX);
942 });
943
944 document.addEventListener('touchend', () => {
945 isDragging = false;
946 });
947 }
948
949 attributeChangedCallback(name, oldValue, newValue) {
950 if (name === 'value' && newValue !== oldValue) {
951 this._value = parseFloat(newValue);
952 }
953 if (this.shadowRoot.innerHTML) {
954 this.render();
955 this.setupEventListeners();
956 }
957 }
958}
959
960// ============================================================================
961// INPUT COMPONENT
962// ============================================================================
963
964class SemanticInput extends SemanticComponent {
965 static get observedAttributes() {
966 return ['intent', 'sentiment', 'type', 'label', 'placeholder', 'value', 'required', 'disabled', 'valid', 'error'];
967 }
968
969 constructor() {
970 super();
971 this._value = '';
972 }
973
974 get value() {
975 return this._value;
976 }
977
978 set value(val) {
979 this._value = val;
980 const input = this.shadowRoot.querySelector('input, textarea');
981 if (input) input.value = val;
982 this.emitIntent('input', { value: val });
983 }
984
985 render() {
986 const type = this.getAttribute('type') || 'text';
987 const label = this.getAttribute('label') || '';
988 const placeholder = this.getAttribute('placeholder') || '';
989 const required = this.hasAttribute('required');
990 const disabled = this.hasAttribute('disabled');
991 const valid = this.hasAttribute('valid');
992 const error = this.getAttribute('error') || '';
993 const colors = this.getIntentColors();
994
995 const inputTypes = {
996 'text': 'text',
997 'email': 'email',
998 'password': 'password',
999 'number': 'number',
1000 'tel': 'tel',
1001 'url': 'url',
1002 'search': 'search'
1003 };
1004
1005 const isTextarea = type === 'textarea';
1006 const inputType = inputTypes[type] || 'text';
1007
1008 this.shadowRoot.innerHTML = `
1009 <style>
1010 ${this.getStyles()}
1011
1012 .input-wrapper {
1013 display: flex;
1014 flex-direction: column;
1015 gap: 8px;
1016 }
1017
1018 label {
1019 font-size: 14px;
1020 font-weight: 600;
1021 color: ${colors.text};
1022 }
1023
1024 input, textarea {
1025 min-height: 44px;
1026 padding: 12px 16px;
1027 background: ${colors.bg};
1028 border: 2px solid ${colors.border};
1029 border-radius: 8px;
1030 color: ${colors.text};
1031 font-size: 16px;
1032 font-family: inherit;
1033 transition: all 0.2s;
1034 }
1035
1036 textarea {
1037 min-height: 120px;
1038 resize: vertical;
1039 }
1040
1041 input:focus, textarea:focus {
1042 outline: 3px solid #4d9fff;
1043 outline-offset: 2px;
1044 border-color: #0066cc;
1045 box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15);
1046 }
1047
1048 input::placeholder, textarea::placeholder {
1049 color: #8a8a8a;
1050 }
1051
1052 input:disabled, textarea:disabled {
1053 background: #1a1a1a !important;
1054 border-color: #2a2a2a !important;
1055 color: #8a8a8a !important;
1056 cursor: not-allowed;
1057 opacity: 1;
1058 }
1059
1060 :host([valid]) input, :host([valid]) textarea {
1061 border-color: #34c759;
1062 }
1063
1064 :host([error]) input, :host([error]) textarea {
1065 border-color: #ff3b30;
1066 }
1067
1068 .error-message {
1069 font-size: 13px;
1070 color: #ff3b30;
1071 margin-top: -4px;
1072 }
1073
1074 .voice-hint {
1075 font-size: 12px;
1076 color: #8a8a8a;
1077 display: none;
1078 }
1079
1080 :host([data-modality="voice-screen"]) .voice-hint,
1081 :host([data-modality="voice-only"]) .voice-hint {
1082 display: block;
1083 }
1084 </style>
1085 <div class="input-wrapper" part="wrapper">
1086 ${label ? `<label part="label">${label}${required ? ' *' : ''}</label>` : ''}
1087 ${isTextarea ?
1088 `<textarea
1089 part="input"
1090 placeholder="${placeholder}"
1091 ?required="${required}"
1092 ?disabled="${disabled}"
1093 ></textarea>` :
1094 `<input
1095 part="input"
1096 type="${inputType}"
1097 placeholder="${placeholder}"
1098 ?required="${required}"
1099 ?disabled="${disabled}"
1100 />`
1101 }
1102 <div class="voice-hint" part="voice-hint">
1103 Say "Type ${label || 'input'}" to dictate
1104 </div>
1105 ${error ? `<div class="error-message">${error}</div>` : ''}
1106 </div>
1107 `;
1108 }
1109
1110 setupEventListeners() {
1111 const input = this.shadowRoot.querySelector('input, textarea');
1112
1113 input.addEventListener('input', (e) => {
1114 this._value = e.target.value;
1115 this.emitIntent('input', { value: this._value });
1116 });
1117
1118 input.addEventListener('change', (e) => {
1119 this.emitIntent('change', { value: this._value });
1120 });
1121
1122 input.addEventListener('focus', () => {
1123 this.emitIntent('focus');
1124 });
1125
1126 input.addEventListener('blur', () => {
1127 this.emitIntent('blur', { value: this._value });
1128 });
1129 }
1130
1131 attributeChangedCallback() {
1132 if (this.shadowRoot.innerHTML) {
1133 this.render();
1134 this.setupEventListeners();
1135 }
1136 }
1137}
1138
1139// ============================================================================
1140// MODAL COMPONENT
1141// ============================================================================
1142
1143class SemanticModal extends SemanticComponent {
1144 static get observedAttributes() {
1145 return ['open', 'urgency', 'dismissible'];
1146 }
1147
1148 render() {
1149 const urgency = this.getAttribute('urgency') || 'medium';
1150 const dismissible = this.getAttribute('dismissible') !== 'false';
1151
1152 this.shadowRoot.innerHTML = `
1153 <style>
1154 ${this.getStyles()}
1155
1156 :host {
1157 display: none;
1158 position: fixed;
1159 top: 0;
1160 left: 0;
1161 right: 0;
1162 bottom: 0;
1163 z-index: 9999;
1164 align-items: center;
1165 justify-content: center;
1166 }
1167
1168 :host([open]) {
1169 display: flex;
1170 }
1171
1172 .backdrop {
1173 position: absolute;
1174 top: 0;
1175 left: 0;
1176 right: 0;
1177 bottom: 0;
1178 background: rgba(0, 0, 0, 0.8);
1179 animation: fadeIn 0.2s;
1180 }
1181
1182 @keyframes fadeIn {
1183 from { opacity: 0; }
1184 }
1185
1186 .modal {
1187 position: relative;
1188 background: #1c1c1e;
1189 border-radius: 16px;
1190 max-width: 90vw;
1191 max-height: 90vh;
1192 overflow: auto;
1193 animation: slideUp 0.3s;
1194 box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
1195 }
1196
1197 @keyframes slideUp {
1198 from {
1199 transform: translateY(50px);
1200 opacity: 0;
1201 }
1202 }
1203
1204 .modal[data-urgency="critical"] {
1205 border: 3px solid #ff3b30;
1206 }
1207
1208 .header {
1209 padding: 24px;
1210 border-bottom: 1px solid #38383a;
1211 display: flex;
1212 align-items: center;
1213 justify-content: space-between;
1214 }
1215
1216 .close-btn {
1217 background: none;
1218 border: none;
1219 color: #8a8a8a;
1220 font-size: 32px;
1221 cursor: pointer;
1222 padding: 0;
1223 min-width: 44px;
1224 min-height: 44px;
1225 display: flex;
1226 align-items: center;
1227 justify-content: center;
1228 border-radius: 50%;
1229 transition: all 0.2s;
1230 }
1231
1232 .close-btn:hover {
1233 background: #38383a;
1234 color: #fff;
1235 }
1236
1237 .close-btn:focus-visible {
1238 outline: 3px solid #4d9fff;
1239 outline-offset: 2px;
1240 }
1241
1242 .content {
1243 padding: 24px;
1244 }
1245
1246 .actions {
1247 padding: 24px;
1248 border-top: 1px solid #38383a;
1249 display: flex;
1250 gap: 12px;
1251 justify-content: flex-end;
1252 }
1253
1254 /* Mobile responsive - fullscreen on small screens */
1255 @media (max-width: 640px) {
1256 .modal {
1257 max-width: 100vw;
1258 max-height: 100vh;
1259 border-radius: 0;
1260 width: 100%;
1261 height: 100%;
1262 }
1263
1264 .header, .content, .actions {
1265 padding: 20px;
1266 }
1267 }
1268
1269 @media (prefers-reduced-motion: reduce) {
1270 .backdrop, .modal {
1271 animation: none;
1272 }
1273 }
1274 </style>
1275 <div class="backdrop" part="backdrop"></div>
1276 <div class="modal" data-urgency="${urgency}" part="modal" role="dialog" aria-modal="true">
1277 <div class="header" part="header">
1278 <slot name="header"></slot>
1279 ${dismissible ? '<button class="close-btn" aria-label="Close" part="close">×</button>' : ''}
1280 </div>
1281 <div class="content" part="content">
1282 <slot></slot>
1283 </div>
1284 <div class="actions" part="actions">
1285 <slot name="actions"></slot>
1286 </div>
1287 </div>
1288 `;
1289 }
1290
1291 setupEventListeners() {
1292 const backdrop = this.shadowRoot.querySelector('.backdrop');
1293 const closeBtn = this.shadowRoot.querySelector('.close-btn');
1294 const dismissible = this.getAttribute('dismissible') !== 'false';
1295
1296 if (dismissible) {
1297 backdrop?.addEventListener('click', () => this.close());
1298 closeBtn?.addEventListener('click', () => this.close());
1299
1300 // ESC key
1301 document.addEventListener('keydown', (e) => {
1302 if (e.key === 'Escape' && this.hasAttribute('open')) {
1303 this.close();
1304 }
1305 });
1306 }
1307 }
1308
1309 open() {
1310 this.setAttribute('open', '');
1311 this.emitIntent('open');
1312 // Trap focus
1313 const firstFocusable = this.shadowRoot.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
1314 firstFocusable?.focus();
1315 }
1316
1317 close() {
1318 this.removeAttribute('open');
1319 this.emitIntent('close');
1320 }
1321
1322 attributeChangedCallback(name) {
1323 if (name === 'open' && this.shadowRoot.innerHTML) {
1324 if (this.hasAttribute('open')) {
1325 document.body.style.overflow = 'hidden';
1326 } else {
1327 document.body.style.overflow = '';
1328 }
1329 }
1330 if (this.shadowRoot.innerHTML) {
1331 this.render();
1332 this.setupEventListeners();
1333 }
1334 }
1335}
1336
1337// ============================================================================
1338// NAVIGATOR COMPONENT
1339// ============================================================================
1340
1341class SemanticNavigator extends SemanticComponent {
1342 static get observedAttributes() {
1343 return ['type', 'current'];
1344 }
1345
1346 render() {
1347 const type = this.getAttribute('type') || 'tabs';
1348 const current = this.getAttribute('current') || '';
1349
1350 this.shadowRoot.innerHTML = `
1351 <style>
1352 ${this.getStyles()}
1353
1354 .navigator {
1355 display: flex;
1356 gap: 4px;
1357 }
1358
1359 .navigator[data-type="tabs"] {
1360 flex-direction: row;
1361 border-bottom: 2px solid #38383a;
1362 }
1363
1364 .navigator[data-type="menu"] {
1365 flex-direction: column;
1366 }
1367
1368 ::slotted(*) {
1369 display: flex;
1370 align-items: center;
1371 padding: 12px 20px;
1372 border-radius: 8px;
1373 cursor: pointer;
1374 transition: all 0.2s;
1375 color: #8a8a8a;
1376 text-decoration: none;
1377 user-select: none;
1378 }
1379
1380 ::slotted(:hover) {
1381 background: #2c2c2e;
1382 color: #fff;
1383 }
1384
1385 ::slotted([aria-current="page"]),
1386 ::slotted(.current) {
1387 background: #0066cc;
1388 color: #fff;
1389 font-weight: 600;
1390 }
1391
1392 ::slotted(:focus-visible) {
1393 outline: 3px solid #4d9fff;
1394 outline-offset: 2px;
1395 }
1396 </style>
1397 <nav class="navigator" data-type="${type}" part="navigator" role="navigation">
1398 <slot></slot>
1399 </nav>
1400 `;
1401 }
1402
1403 setupEventListeners() {
1404 this.addEventListener('click', (e) => {
1405 const target = e.target;
1406 if (target.hasAttribute('data-nav-id')) {
1407 this.emitIntent('navigate', {
1408 id: target.getAttribute('data-nav-id'),
1409 href: target.getAttribute('href')
1410 });
1411 }
1412 });
1413 }
1414
1415 attributeChangedCallback() {
1416 if (this.shadowRoot.innerHTML) {
1417 this.render();
1418 this.setupEventListeners();
1419 }
1420 }
1421}
1422
1423// ============================================================================
1424// LIST COMPONENT
1425// ============================================================================
1426
1427class SemanticList extends SemanticComponent {
1428 static get observedAttributes() {
1429 return ['type', 'selectable'];
1430 }
1431
1432 render() {
1433 const type = this.getAttribute('type') || 'default';
1434 const selectable = this.hasAttribute('selectable');
1435
1436 this.shadowRoot.innerHTML = `
1437 <style>
1438 ${this.getStyles()}
1439
1440 .list {
1441 display: flex;
1442 flex-direction: column;
1443 gap: 2px;
1444 }
1445
1446 ::slotted(*) {
1447 padding: 18px 16px;
1448 min-height: 44px;
1449 display: flex;
1450 align-items: center;
1451 background: #1c1c1e;
1452 border: 1px solid #38383a;
1453 border-radius: 8px;
1454 transition: all 0.2s;
1455 }
1456
1457 :host([selectable]) ::slotted(*) {
1458 cursor: pointer;
1459 user-select: none;
1460 }
1461
1462 :host([selectable]) ::slotted(:hover) {
1463 background: #2c2c2e;
1464 border-color: #0066cc;
1465 transform: translateX(4px);
1466 }
1467
1468 :host([selectable]) ::slotted([aria-selected="true"]),
1469 :host([selectable]) ::slotted(.selected) {
1470 background: rgba(0, 122, 255, 0.1);
1471 border-color: #0066cc;
1472 }
1473
1474 ::slotted(:focus-visible) {
1475 outline: 3px solid #4d9fff;
1476 outline-offset: 2px;
1477 }
1478
1479 .list[data-type="compact"] ::slotted(*) {
1480 padding: 12px;
1481 }
1482
1483 .list[data-type="dense"] ::slotted(*) {
1484 padding: 8px 12px;
1485 border-radius: 4px;
1486 }
1487 </style>
1488 <div class="list" data-type="${type}" part="list" role="list">
1489 <slot></slot>
1490 </div>
1491 `;
1492 }
1493
1494 setupEventListeners() {
1495 if (this.hasAttribute('selectable')) {
1496 this.addEventListener('click', (e) => {
1497 const item = e.target.closest('[data-item-id]');
1498 if (item) {
1499 // Toggle selection
1500 const isSelected = item.getAttribute('aria-selected') === 'true';
1501 item.setAttribute('aria-selected', !isSelected);
1502
1503 this.emitIntent('select', {
1504 id: item.getAttribute('data-item-id'),
1505 selected: !isSelected
1506 });
1507 }
1508 });
1509
1510 // Keyboard navigation
1511 this.addEventListener('keydown', (e) => {
1512 const items = Array.from(this.querySelectorAll('[data-item-id]'));
1513 const current = this.querySelector('[aria-selected="true"]');
1514 const currentIndex = items.indexOf(current);
1515
1516 if (e.key === 'ArrowDown' && currentIndex < items.length - 1) {
1517 e.preventDefault();
1518 items[currentIndex + 1].focus();
1519 } else if (e.key === 'ArrowUp' && currentIndex > 0) {
1520 e.preventDefault();
1521 items[currentIndex - 1].focus();
1522 } else if (e.key === 'Enter' || e.key === ' ') {
1523 e.preventDefault();
1524 e.target.click();
1525 }
1526 });
1527 }
1528 }
1529
1530 attributeChangedCallback() {
1531 if (this.shadowRoot.innerHTML) {
1532 this.render();
1533 this.setupEventListeners();
1534 }
1535 }
1536}
1537
1538// ============================================================================
1539// MENU COMPONENT
1540// ============================================================================
1541
1542class SemanticMenu extends SemanticComponent {
1543 static get observedAttributes() {
1544 return ['open', 'anchor'];
1545 }
1546
1547 render() {
1548 this.shadowRoot.innerHTML = `
1549 <style>
1550 ${this.getStyles()}
1551
1552 :host {
1553 position: absolute;
1554 display: none;
1555 z-index: 10000;
1556 }
1557
1558 :host([open]) {
1559 display: block;
1560 }
1561
1562 .menu {
1563 background: #2c2c2e;
1564 border: 1px solid #38383a;
1565 border-radius: 12px;
1566 padding: 8px;
1567 min-width: 200px;
1568 box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
1569 animation: scaleIn 0.15s;
1570 }
1571
1572 @keyframes scaleIn {
1573 from {
1574 transform: scale(0.95);
1575 opacity: 0;
1576 }
1577 }
1578
1579 ::slotted(*) {
1580 display: flex;
1581 align-items: center;
1582 gap: 12px;
1583 padding: 12px;
1584 min-height: 44px;
1585 border-radius: 6px;
1586 cursor: pointer;
1587 transition: all 0.15s;
1588 color: #fff;
1589 text-decoration: none;
1590 user-select: none;
1591 }
1592
1593 ::slotted(:hover) {
1594 background: #0066cc;
1595 transform: translateX(2px);
1596 }
1597
1598 ::slotted(:focus-visible) {
1599 outline: 2px solid #4d9fff;
1600 outline-offset: 2px;
1601 }
1602
1603 ::slotted([disabled]) {
1604 opacity: 0.4;
1605 cursor: not-allowed;
1606 }
1607
1608 ::slotted([disabled]):hover {
1609 background: transparent;
1610 }
1611
1612 .divider {
1613 height: 1px;
1614 background: #38383a;
1615 margin: 4px 0;
1616 }
1617
1618 @media (prefers-reduced-motion: reduce) {
1619 .menu {
1620 animation: none;
1621 }
1622 }
1623 </style>
1624 <div class="menu" part="menu" role="menu">
1625 <slot></slot>
1626 </div>
1627 `;
1628 }
1629
1630 setupEventListeners() {
1631 this.addEventListener('click', (e) => {
1632 const item = e.target.closest('[data-menu-id]');
1633 if (item && !item.hasAttribute('disabled')) {
1634 this.emitIntent('select', {
1635 id: item.getAttribute('data-menu-id')
1636 });
1637 this.close();
1638 }
1639 });
1640
1641 // Close on outside click
1642 document.addEventListener('click', (e) => {
1643 if (this.hasAttribute('open') && !this.contains(e.target)) {
1644 this.close();
1645 }
1646 });
1647
1648 // Close on ESC
1649 document.addEventListener('keydown', (e) => {
1650 if (e.key === 'Escape' && this.hasAttribute('open')) {
1651 this.close();
1652 }
1653 });
1654 }
1655
1656 open(x, y) {
1657 this.style.left = x + 'px';
1658 this.style.top = y + 'px';
1659 this.setAttribute('open', '');
1660 this.emitIntent('open');
1661
1662 // Focus first item
1663 const firstItem = this.querySelector('[data-menu-id]:not([disabled])');
1664 firstItem?.focus();
1665 }
1666
1667 close() {
1668 this.removeAttribute('open');
1669 this.emitIntent('close');
1670 }
1671
1672 attributeChangedCallback() {
1673 if (this.shadowRoot.innerHTML) {
1674 this.render();
1675 this.setupEventListeners();
1676 }
1677 }
1678}
1679
1680// ============================================================================
1681// TABS COMPONENT
1682// ============================================================================
1683
1684class SemanticTabs extends SemanticComponent {
1685 static get observedAttributes() {
1686 return ['selected'];
1687 }
1688
1689 constructor() {
1690 super();
1691 this.tabs = [];
1692 this.panels = [];
1693 }
1694
1695 render() {
1696 const selected = parseInt(this.getAttribute('selected') || '0');
1697
1698 this.shadowRoot.innerHTML = `
1699 <style>
1700 ${this.getStyles()}
1701
1702 :host {
1703 display: block;
1704 }
1705
1706 .tabs-container {
1707 display: flex;
1708 flex-direction: column;
1709 gap: 0;
1710 }
1711
1712 .tab-list {
1713 display: flex;
1714 gap: 0;
1715 border-bottom: 2px solid #38383a;
1716 background: #1c1c1e;
1717 }
1718
1719 .tab {
1720 min-height: 44px;
1721 min-width: 88px;
1722 padding: 12px 24px;
1723 border: none;
1724 background: transparent;
1725 color: #8e8e93;
1726 font-size: 15px;
1727 font-weight: 600;
1728 font-family: inherit;
1729 cursor: pointer;
1730 border-bottom: 3px solid transparent;
1731 transition: all 0.2s;
1732 position: relative;
1733 /* Support CSS custom properties for forced demo states */
1734 transform: var(--demo-transform);
1735 box-shadow: var(--demo-box-shadow);
1736 filter: var(--demo-filter);
1737 outline: var(--demo-outline);
1738 outline-offset: var(--demo-outline-offset);
1739 }
1740
1741 .tab:hover:not(:disabled):not([aria-selected="true"]) {
1742 color: #ffffff;
1743 background: rgba(255, 255, 255, 0.05);
1744 }
1745
1746 .tab[aria-selected="true"] {
1747 color: #409cff;
1748 border-bottom-color: #409cff;
1749 background: rgba(64, 156, 255, 0.1);
1750 }
1751
1752 .tab:focus-visible {
1753 outline: 3px solid #4d9fff;
1754 outline-offset: -3px;
1755 }
1756
1757 .tab:disabled {
1758 color: #48484a;
1759 cursor: not-allowed;
1760 opacity: 0.5;
1761 }
1762
1763 .tab-panels {
1764 padding: 20px 0;
1765 }
1766
1767 .tab-panel {
1768 display: none;
1769 }
1770
1771 .tab-panel[aria-hidden="false"] {
1772 display: block;
1773 }
1774
1775 @media (prefers-reduced-motion: reduce) {
1776 .tab {
1777 transition: none;
1778 }
1779 }
1780 </style>
1781 <div class="tabs-container" role="tablist">
1782 <div class="tab-list"></div>
1783 <div class="tab-panels"></div>
1784 </div>
1785 `;
1786 }
1787
1788 setupEventListeners() {
1789 // Use setTimeout to ensure child elements are fully initialized
1790 setTimeout(() => {
1791 this.collectTabsAndPanels();
1792 this.renderTabs();
1793 this.selectTab(parseInt(this.getAttribute('selected') || '0'));
1794 }, 0);
1795 }
1796
1797 collectTabsAndPanels() {
1798 // Collect tab-item and tab-panel elements from light DOM
1799 this.tabs = Array.from(this.querySelectorAll('tab-item'));
1800 this.panels = Array.from(this.querySelectorAll('tab-panel'));
1801 }
1802
1803 renderTabs() {
1804 const tabList = this.shadowRoot.querySelector('.tab-list');
1805 const panelsContainer = this.shadowRoot.querySelector('.tab-panels');
1806
1807 tabList.innerHTML = '';
1808 panelsContainer.innerHTML = '';
1809
1810 this.tabs.forEach((tabItem, index) => {
1811 const button = document.createElement('button');
1812 button.className = 'tab';
1813 button.setAttribute('role', 'tab');
1814 button.setAttribute('aria-controls', `panel-${index}`);
1815 button.setAttribute('aria-selected', 'false');
1816 button.setAttribute('tabindex', '-1');
1817 button.setAttribute('id', `tab-${index}`);
1818 button.textContent = tabItem.getAttribute('label') || `Tab ${index + 1}`;
1819
1820 if (tabItem.hasAttribute('disabled')) {
1821 button.disabled = true;
1822 }
1823
1824 if (tabItem.hasAttribute('badge')) {
1825 const badge = document.createElement('span');
1826 badge.textContent = tabItem.getAttribute('badge');
1827 badge.style.cssText = 'background: #ff3b30; color: white; padding: 2px 6px; border-radius: 10px; font-size: 11px; margin-left: 8px;';
1828 button.appendChild(badge);
1829 }
1830
1831 button.addEventListener('click', () => {
1832 if (!button.disabled) {
1833 this.selectTab(index);
1834 }
1835 });
1836
1837 tabList.appendChild(button);
1838 });
1839
1840 this.panels.forEach((panel, index) => {
1841 panel.setAttribute('role', 'tabpanel');
1842 panel.setAttribute('aria-labelledby', `tab-${index}`);
1843 panel.setAttribute('id', `panel-${index}`);
1844 panel.setAttribute('aria-hidden', 'true');
1845 panel.className = 'tab-panel';
1846 panelsContainer.appendChild(panel);
1847 });
1848
1849 // Keyboard navigation
1850 tabList.addEventListener('keydown', (e) => {
1851 const tabs = Array.from(tabList.querySelectorAll('.tab:not(:disabled)'));
1852 const currentIndex = tabs.findIndex(tab => tab.getAttribute('aria-selected') === 'true');
1853
1854 let nextIndex = currentIndex;
1855
1856 switch (e.key) {
1857 case 'ArrowRight':
1858 case 'ArrowDown':
1859 e.preventDefault();
1860 nextIndex = (currentIndex + 1) % tabs.length;
1861 break;
1862 case 'ArrowLeft':
1863 case 'ArrowUp':
1864 e.preventDefault();
1865 nextIndex = (currentIndex - 1 + tabs.length) % tabs.length;
1866 break;
1867 case 'Home':
1868 e.preventDefault();
1869 nextIndex = 0;
1870 break;
1871 case 'End':
1872 e.preventDefault();
1873 nextIndex = tabs.length - 1;
1874 break;
1875 }
1876
1877 if (nextIndex !== currentIndex) {
1878 const allTabs = Array.from(tabList.querySelectorAll('.tab'));
1879 const targetIndex = allTabs.indexOf(tabs[nextIndex]);
1880 this.selectTab(targetIndex);
1881 tabs[nextIndex].focus();
1882 }
1883 });
1884 }
1885
1886 selectTab(index) {
1887 const tabList = this.shadowRoot.querySelector('.tab-list');
1888 const tabs = Array.from(tabList.querySelectorAll('.tab'));
1889 const panels = Array.from(this.shadowRoot.querySelectorAll('.tab-panel'));
1890
1891 tabs.forEach((tab, i) => {
1892 const isSelected = i === index;
1893 tab.setAttribute('aria-selected', isSelected ? 'true' : 'false');
1894 tab.setAttribute('tabindex', isSelected ? '0' : '-1');
1895 });
1896
1897 panels.forEach((panel, i) => {
1898 panel.setAttribute('aria-hidden', i === index ? 'false' : 'true');
1899 });
1900
1901 this.setAttribute('selected', index.toString());
1902 this.emitIntent('tab-change', { index, tab: this.tabs[index] });
1903 }
1904
1905 attributeChangedCallback(name, oldValue, newValue) {
1906 if (name === 'selected' && this.shadowRoot.innerHTML && oldValue !== newValue) {
1907 this.selectTab(parseInt(newValue || '0'));
1908 }
1909 }
1910}
1911
1912// ============================================================================
1913// DISCLOSURE COMPONENT (Accordion/Collapsible)
1914// ============================================================================
1915
1916class SemanticDisclosure extends SemanticComponent {
1917 static get observedAttributes() {
1918 return ['open', 'mode'];
1919 }
1920
1921 constructor() {
1922 super();
1923 this.items = [];
1924 }
1925
1926 getCSS() {
1927 return `
1928 .disclosure-container {
1929 display: flex;
1930 flex-direction: column;
1931 gap: 0;
1932 background: #1c1c1e;
1933 border-radius: 12px;
1934 overflow: hidden;
1935 }
1936
1937 .disclosure-item {
1938 border-bottom: 1px solid #38383a;
1939 }
1940
1941 .disclosure-item:last-child {
1942 border-bottom: none;
1943 }
1944
1945 .disclosure-header {
1946 all: unset;
1947 display: flex;
1948 align-items: center;
1949 justify-content: space-between;
1950 width: 100%;
1951 padding: 16px;
1952 background: transparent;
1953 color: #fff;
1954 font-size: 16px;
1955 font-weight: 500;
1956 cursor: pointer;
1957 transition: background 0.15s ease;
1958 box-sizing: border-box;
1959 min-height: 44px;
1960 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
1961 }
1962
1963 .disclosure-header:hover {
1964 background: rgba(255, 255, 255, 0.05);
1965 }
1966
1967 .disclosure-header:active {
1968 background: rgba(255, 255, 255, 0.08);
1969 }
1970
1971 .disclosure-header:focus-visible {
1972 outline: 3px solid #4d9fff;
1973 outline-offset: -3px;
1974 }
1975
1976 .disclosure-icon {
1977 font-size: 14px;
1978 color: #8e8e93;
1979 transition: transform 0.2s ease;
1980 user-select: none;
1981 }
1982
1983 .disclosure-icon.open {
1984 transform: rotate(90deg);
1985 }
1986
1987 .disclosure-content {
1988 max-height: 0;
1989 overflow: hidden;
1990 transition: max-height 0.3s ease, padding 0.3s ease;
1991 padding: 0 16px;
1992 box-sizing: border-box;
1993 }
1994
1995 .disclosure-content.open {
1996 max-height: 2000px;
1997 padding: 0 16px 16px 16px;
1998 }
1999
2000 .disclosure-content-inner {
2001 color: #ababab;
2002 font-size: 14px;
2003 line-height: 1.6;
2004 }
2005 `;
2006 }
2007
2008 getHTML() {
2009 return `<div class="disclosure-container" role="region"></div>`;
2010 }
2011
2012 render() {
2013 this.shadowRoot.innerHTML = `
2014 <style>
2015 ${this.getCSS()}
2016 </style>
2017 ${this.getHTML()}
2018 `;
2019 }
2020
2021 setupEventListeners() {
2022 setTimeout(() => {
2023 this.collectItems();
2024 this.renderItems();
2025 this.setupMode();
2026 }, 0);
2027 }
2028
2029 collectItems() {
2030 this.items = Array.from(this.querySelectorAll('disclosure-item'));
2031 }
2032
2033 renderItems() {
2034 const container = this.shadowRoot.querySelector('.disclosure-container');
2035
2036 this.items.forEach((item, index) => {
2037 const header = item.getAttribute('header') || `Item ${index + 1}`;
2038 const open = item.hasAttribute('open');
2039 const disabled = item.hasAttribute('disabled');
2040
2041 const itemEl = document.createElement('div');
2042 itemEl.className = 'disclosure-item';
2043 itemEl.setAttribute('data-index', index);
2044
2045 const headerButton = document.createElement('button');
2046 headerButton.className = 'disclosure-header';
2047 headerButton.setAttribute('role', 'button');
2048 headerButton.setAttribute('aria-expanded', open ? 'true' : 'false');
2049 headerButton.setAttribute('aria-controls', `disclosure-content-${index}`);
2050
2051 if (disabled) {
2052 headerButton.disabled = true;
2053 headerButton.style.opacity = '0.4';
2054 headerButton.style.cursor = 'not-allowed';
2055 }
2056
2057 const headerText = document.createElement('span');
2058 headerText.textContent = header;
2059
2060 const icon = document.createElement('span');
2061 icon.className = `disclosure-icon ${open ? 'open' : ''}`;
2062 icon.textContent = '▶';
2063 icon.setAttribute('aria-hidden', 'true');
2064
2065 headerButton.appendChild(headerText);
2066 headerButton.appendChild(icon);
2067
2068 const content = document.createElement('div');
2069 content.className = `disclosure-content ${open ? 'open' : ''}`;
2070 content.id = `disclosure-content-${index}`;
2071 content.setAttribute('role', 'region');
2072 content.setAttribute('aria-labelledby', `disclosure-header-${index}`);
2073
2074 const contentInner = document.createElement('div');
2075 contentInner.className = 'disclosure-content-inner';
2076 contentInner.innerHTML = item.innerHTML;
2077
2078 content.appendChild(contentInner);
2079
2080 itemEl.appendChild(headerButton);
2081 itemEl.appendChild(content);
2082
2083 container.appendChild(itemEl);
2084
2085 if (!disabled) {
2086 headerButton.addEventListener('click', () => {
2087 this.toggleItem(index);
2088 });
2089 }
2090 });
2091 }
2092
2093 setupMode() {
2094 const mode = this.getAttribute('mode') || 'multiple';
2095 this.mode = mode;
2096 }
2097
2098 toggleItem(index) {
2099 const container = this.shadowRoot.querySelector('.disclosure-container');
2100 const items = container.querySelectorAll('.disclosure-item');
2101 const item = items[index];
2102 const content = item.querySelector('.disclosure-content');
2103 const icon = item.querySelector('.disclosure-icon');
2104 const button = item.querySelector('.disclosure-header');
2105 const isOpen = content.classList.contains('open');
2106
2107 if (this.mode === 'single' && !isOpen) {
2108 // Close all other items
2109 items.forEach((otherItem, otherIndex) => {
2110 if (otherIndex !== index) {
2111 const otherContent = otherItem.querySelector('.disclosure-content');
2112 const otherIcon = otherItem.querySelector('.disclosure-icon');
2113 const otherButton = otherItem.querySelector('.disclosure-header');
2114 otherContent.classList.remove('open');
2115 otherIcon.classList.remove('open');
2116 otherButton.setAttribute('aria-expanded', 'false');
2117 }
2118 });
2119 }
2120
2121 // Toggle current item
2122 if (isOpen) {
2123 content.classList.remove('open');
2124 icon.classList.remove('open');
2125 button.setAttribute('aria-expanded', 'false');
2126 this.items[index].removeAttribute('open');
2127 } else {
2128 content.classList.add('open');
2129 icon.classList.add('open');
2130 button.setAttribute('aria-expanded', 'true');
2131 this.items[index].setAttribute('open', '');
2132 }
2133
2134 // Emit event
2135 this.dispatchEvent(new CustomEvent('disclosure-change', {
2136 detail: {
2137 index,
2138 open: !isOpen,
2139 item: this.items[index]
2140 }
2141 }));
2142 }
2143
2144 attributeChangedCallback(name, oldValue, newValue) {
2145 if (name === 'mode' && this.shadowRoot.innerHTML && oldValue !== newValue) {
2146 this.setupMode();
2147 }
2148 }
2149}
2150
2151// ============================================================================
2152// PROGRESS COMPONENT (Spinner & Progress Bar)
2153// ============================================================================
2154
2155class SemanticProgress extends SemanticComponent {
2156 static get observedAttributes() {
2157 return ['value', 'max', 'type', 'size'];
2158 }
2159
2160 getCSS() {
2161 return `
2162 .progress-container {
2163 display: inline-flex;
2164 align-items: center;
2165 gap: 12px;
2166 }
2167
2168 /* Spinner styles */
2169 .spinner {
2170 display: inline-block;
2171 border-radius: 50%;
2172 border-style: solid;
2173 animation: spin 1s linear infinite;
2174 }
2175
2176 .spinner.small {
2177 width: 16px;
2178 height: 16px;
2179 border-width: 2px;
2180 }
2181
2182 .spinner.medium {
2183 width: 24px;
2184 height: 24px;
2185 border-width: 3px;
2186 }
2187
2188 .spinner.large {
2189 width: 48px;
2190 height: 48px;
2191 border-width: 4px;
2192 }
2193
2194 @keyframes spin {
2195 0% { transform: rotate(0deg); }
2196 100% { transform: rotate(360deg); }
2197 }
2198
2199 /* Progress bar styles */
2200 .progress-bar-container {
2201 width: 200px;
2202 height: 8px;
2203 background: #38383a;
2204 border-radius: 8px;
2205 overflow: hidden;
2206 position: relative;
2207 }
2208
2209 .progress-bar-container.small {
2210 height: 4px;
2211 width: 100px;
2212 }
2213
2214 .progress-bar-container.medium {
2215 height: 8px;
2216 width: 200px;
2217 }
2218
2219 .progress-bar-container.large {
2220 height: 12px;
2221 width: 300px;
2222 }
2223
2224 .progress-bar-fill {
2225 height: 100%;
2226 background: var(--progress-color, #409cff);
2227 border-radius: 8px;
2228 transition: width 0.3s ease;
2229 position: relative;
2230 overflow: hidden;
2231 }
2232
2233 .progress-bar-fill.indeterminate {
2234 width: 30% !important;
2235 animation: indeterminate 1.5s ease-in-out infinite;
2236 }
2237
2238 @keyframes indeterminate {
2239 0% { transform: translateX(-100%); }
2240 50% { transform: translateX(250%); }
2241 100% { transform: translateX(-100%); }
2242 }
2243
2244 .progress-label {
2245 font-size: 14px;
2246 color: #ababab;
2247 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
2248 }
2249
2250 /* Intent colors */
2251 .intent-primary { --progress-color: #409cff; }
2252 .intent-success { --progress-color: #30d158; }
2253 .intent-warning { --progress-color: #ff9f0a; }
2254 .intent-danger { --progress-color: #ff3b30; }
2255 `;
2256 }
2257
2258 getHTML() {
2259 const type = this.getAttribute('type') || 'spinner';
2260 const size = this.getAttribute('size') || 'medium';
2261 const label = this.getAttribute('label') || '';
2262 const intent = this.getAttribute('intent') || 'primary';
2263 const value = parseFloat(this.getAttribute('value') || '0');
2264 const max = parseFloat(this.getAttribute('max') || '100');
2265 const isIndeterminate = !this.hasAttribute('value');
2266
2267 if (type === 'spinner') {
2268 const borderColor = this.getIntentColor(intent);
2269 return `
2270 <div class="progress-container">
2271 <div class="spinner ${size}" style="border-color: ${borderColor} transparent transparent transparent;"></div>
2272 ${label ? `<span class="progress-label">${label}</span>` : ''}
2273 </div>
2274 `;
2275 } else {
2276 // Progress bar
2277 const percentage = isIndeterminate ? 0 : Math.min(100, (value / max) * 100);
2278 return `
2279 <div class="progress-container">
2280 <div class="progress-bar-container ${size}">
2281 <div class="progress-bar-fill intent-${intent} ${isIndeterminate ? 'indeterminate' : ''}"
2282 style="width: ${percentage}%"
2283 role="progressbar"
2284 aria-valuenow="${value}"
2285 aria-valuemin="0"
2286 aria-valuemax="${max}">
2287 </div>
2288 </div>
2289 ${label ? `<span class="progress-label">${label}</span>` : ''}
2290 </div>
2291 `;
2292 }
2293 }
2294
2295 getIntentColor(intent) {
2296 const colors = {
2297 primary: '#409cff',
2298 success: '#30d158',
2299 warning: '#ff9f0a',
2300 danger: '#ff3b30'
2301 };
2302 return colors[intent] || colors.primary;
2303 }
2304
2305 render() {
2306 this.shadowRoot.innerHTML = `
2307 <style>
2308 ${this.getCSS()}
2309 </style>
2310 ${this.getHTML()}
2311 `;
2312 }
2313
2314 setupEventListeners() {
2315 // No event listeners needed for progress component
2316 }
2317
2318 attributeChangedCallback(name, oldValue, newValue) {
2319 if (this.shadowRoot.innerHTML && oldValue !== newValue) {
2320 this.render();
2321 }
2322 }
2323}
2324
2325// ============================================================================
2326// BADGE COMPONENT (Notification indicators, status badges, counts)
2327// ============================================================================
2328
2329class SemanticBadge extends SemanticComponent {
2330 static get observedAttributes() {
2331 return ['intent', 'variant', 'size', 'pulse'];
2332 }
2333
2334 getCSS() {
2335 return `
2336 .badge {
2337 display: inline-flex;
2338 align-items: center;
2339 justify-content: center;
2340 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
2341 font-weight: 600;
2342 border-radius: 12px;
2343 white-space: nowrap;
2344 box-sizing: border-box;
2345 position: relative;
2346 }
2347
2348 /* Sizes */
2349 .badge.small {
2350 height: 16px;
2351 padding: 0 6px;
2352 font-size: 11px;
2353 min-width: 16px;
2354 }
2355
2356 .badge.medium {
2357 height: 20px;
2358 padding: 0 8px;
2359 font-size: 12px;
2360 min-width: 20px;
2361 }
2362
2363 .badge.large {
2364 height: 24px;
2365 padding: 0 10px;
2366 font-size: 14px;
2367 min-width: 24px;
2368 }
2369
2370 /* Dot variant (for notification indicators) */
2371 .badge.dot {
2372 width: 8px;
2373 height: 8px;
2374 min-width: 8px;
2375 padding: 0;
2376 border-radius: 50%;
2377 }
2378
2379 .badge.dot.medium {
2380 width: 10px;
2381 height: 10px;
2382 min-width: 10px;
2383 }
2384
2385 .badge.dot.large {
2386 width: 12px;
2387 height: 12px;
2388 min-width: 12px;
2389 }
2390
2391 /* Intent colors - filled variant */
2392 .badge.filled.intent-primary {
2393 background: #409cff;
2394 color: #fff;
2395 }
2396
2397 .badge.filled.intent-success {
2398 background: #30d158;
2399 color: #fff;
2400 }
2401
2402 .badge.filled.intent-warning {
2403 background: #ff9f0a;
2404 color: #000;
2405 }
2406
2407 .badge.filled.intent-danger {
2408 background: #ff3b30;
2409 color: #fff;
2410 }
2411
2412 .badge.filled.intent-neutral {
2413 background: #8e8e93;
2414 color: #fff;
2415 }
2416
2417 /* Intent colors - outline variant */
2418 .badge.outline.intent-primary {
2419 background: transparent;
2420 color: #409cff;
2421 border: 1px solid #409cff;
2422 }
2423
2424 .badge.outline.intent-success {
2425 background: transparent;
2426 color: #30d158;
2427 border: 1px solid #30d158;
2428 }
2429
2430 .badge.outline.intent-warning {
2431 background: transparent;
2432 color: #ff9f0a;
2433 border: 1px solid #ff9f0a;
2434 }
2435
2436 .badge.outline.intent-danger {
2437 background: transparent;
2438 color: #ff3b30;
2439 border: 1px solid #ff3b30;
2440 }
2441
2442 .badge.outline.intent-neutral {
2443 background: transparent;
2444 color: #8e8e93;
2445 border: 1px solid #8e8e93;
2446 }
2447
2448 /* Intent colors - subtle variant */
2449 .badge.subtle.intent-primary {
2450 background: rgba(64, 156, 255, 0.15);
2451 color: #409cff;
2452 }
2453
2454 .badge.subtle.intent-success {
2455 background: rgba(48, 209, 88, 0.15);
2456 color: #30d158;
2457 }
2458
2459 .badge.subtle.intent-warning {
2460 background: rgba(255, 159, 10, 0.15);
2461 color: #ff9f0a;
2462 }
2463
2464 .badge.subtle.intent-danger {
2465 background: rgba(255, 59, 48, 0.15);
2466 color: #ff3b30;
2467 }
2468
2469 .badge.subtle.intent-neutral {
2470 background: rgba(142, 142, 147, 0.15);
2471 color: #8e8e93;
2472 }
2473
2474 /* Pulse animation */
2475 .badge.pulse::before {
2476 content: '';
2477 position: absolute;
2478 top: 0;
2479 left: 0;
2480 right: 0;
2481 bottom: 0;
2482 border-radius: inherit;
2483 background: inherit;
2484 animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
2485 z-index: -1;
2486 }
2487
2488 @keyframes pulse {
2489 0%, 100% {
2490 opacity: 1;
2491 transform: scale(1);
2492 }
2493 50% {
2494 opacity: 0.5;
2495 transform: scale(1.1);
2496 }
2497 }
2498 `;
2499 }
2500
2501 getHTML() {
2502 const intent = this.getAttribute('intent') || 'primary';
2503 const variant = this.getAttribute('variant') || 'filled';
2504 const size = this.getAttribute('size') || 'medium';
2505 const pulse = this.hasAttribute('pulse');
2506 const content = this.textContent.trim();
2507
2508 // If variant is dot, don't show content
2509 const displayContent = variant === 'dot' ? '' : content;
2510
2511 return `
2512 <span class="badge ${variant} ${size} intent-${intent} ${pulse ? 'pulse' : ''}" role="status" aria-label="${content || 'notification'}">
2513 ${displayContent}
2514 </span>
2515 `;
2516 }
2517
2518 render() {
2519 this.shadowRoot.innerHTML = `
2520 <style>
2521 ${this.getCSS()}
2522 </style>
2523 ${this.getHTML()}
2524 `;
2525 }
2526
2527 setupEventListeners() {
2528 // No event listeners needed for badge component
2529 }
2530
2531 attributeChangedCallback(name, oldValue, newValue) {
2532 if (this.shadowRoot.innerHTML && oldValue !== newValue) {
2533 this.render();
2534 }
2535 }
2536}
2537
2538// ============================================================================
2539// POPOVER COMPONENT (Tooltips, popovers, contextual overlays)
2540// ============================================================================
2541
2542class SemanticPopover extends SemanticComponent {
2543 static get observedAttributes() {
2544 return ['open', 'position', 'trigger'];
2545 }
2546
2547 constructor() {
2548 super();
2549 this.isOpen = false;
2550 this.triggerElement = null;
2551 }
2552
2553 getCSS() {
2554 return `
2555 :host {
2556 position: relative;
2557 display: inline-block;
2558 }
2559
2560 .popover-trigger {
2561 display: inline-block;
2562 cursor: pointer;
2563 }
2564
2565 .popover-content {
2566 position: absolute;
2567 background: #2c2c2e;
2568 border: 1px solid #48484a;
2569 border-radius: 8px;
2570 padding: 12px;
2571 box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
2572 z-index: 1000;
2573 opacity: 0;
2574 pointer-events: none;
2575 transition: opacity 0.2s ease, transform 0.2s ease;
2576 min-width: 150px;
2577 max-width: 300px;
2578 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
2579 font-size: 14px;
2580 color: #fff;
2581 line-height: 1.5;
2582 }
2583
2584 .popover-content.open {
2585 opacity: 1;
2586 pointer-events: auto;
2587 }
2588
2589 /* Positions */
2590 .popover-content.top {
2591 bottom: calc(100% + 8px);
2592 left: 50%;
2593 transform: translateX(-50%) translateY(4px);
2594 }
2595
2596 .popover-content.top.open {
2597 transform: translateX(-50%) translateY(0);
2598 }
2599
2600 .popover-content.bottom {
2601 top: calc(100% + 8px);
2602 left: 50%;
2603 transform: translateX(-50%) translateY(-4px);
2604 }
2605
2606 .popover-content.bottom.open {
2607 transform: translateX(-50%) translateY(0);
2608 }
2609
2610 .popover-content.left {
2611 right: calc(100% + 8px);
2612 top: 50%;
2613 transform: translateY(-50%) translateX(4px);
2614 }
2615
2616 .popover-content.left.open {
2617 transform: translateY(-50%) translateX(0);
2618 }
2619
2620 .popover-content.right {
2621 left: calc(100% + 8px);
2622 top: 50%;
2623 transform: translateY(-50%) translateX(-4px);
2624 }
2625
2626 .popover-content.right.open {
2627 transform: translateY(-50%) translateX(0);
2628 }
2629
2630 /* Arrow */
2631 .popover-arrow {
2632 position: absolute;
2633 width: 8px;
2634 height: 8px;
2635 background: #2c2c2e;
2636 border: 1px solid #48484a;
2637 transform: rotate(45deg);
2638 }
2639
2640 .popover-content.top .popover-arrow {
2641 bottom: -5px;
2642 left: 50%;
2643 margin-left: -4px;
2644 border-top: none;
2645 border-left: none;
2646 }
2647
2648 .popover-content.bottom .popover-arrow {
2649 top: -5px;
2650 left: 50%;
2651 margin-left: -4px;
2652 border-bottom: none;
2653 border-right: none;
2654 }
2655
2656 .popover-content.left .popover-arrow {
2657 right: -5px;
2658 top: 50%;
2659 margin-top: -4px;
2660 border-left: none;
2661 border-bottom: none;
2662 }
2663
2664 .popover-content.right .popover-arrow {
2665 left: -5px;
2666 top: 50%;
2667 margin-top: -4px;
2668 border-right: none;
2669 border-top: none;
2670 }
2671
2672 .popover-title {
2673 font-weight: 600;
2674 margin-bottom: 4px;
2675 color: #fff;
2676 }
2677
2678 .popover-body {
2679 color: #ababab;
2680 }
2681
2682 /* Mobile responsive */
2683 @media (max-width: 640px) {
2684 .popover-content {
2685 max-width: calc(100vw - 32px);
2686 font-size: 13px;
2687 }
2688 }
2689
2690 @media (prefers-reduced-motion: reduce) {
2691 .popover-content {
2692 transition: none;
2693 }
2694 }
2695 `;
2696 }
2697
2698 getHTML() {
2699 const position = this.getAttribute('position') || 'top';
2700 const title = this.getAttribute('title') || '';
2701 const content = this.getAttribute('content') || '';
2702
2703 return `
2704 <div class="popover-trigger">
2705 <slot name="trigger"></slot>
2706 </div>
2707 <div class="popover-content ${position} ${this.isOpen ? 'open' : ''}" role="tooltip">
2708 <div class="popover-arrow"></div>
2709 ${title ? `<div class="popover-title">${title}</div>` : ''}
2710 <div class="popover-body">
2711 ${content}
2712 <slot name="content"></slot>
2713 </div>
2714 </div>
2715 `;
2716 }
2717
2718 render() {
2719 this.shadowRoot.innerHTML = `
2720 <style>
2721 ${this.getCSS()}
2722 </style>
2723 ${this.getHTML()}
2724 `;
2725 }
2726
2727 setupEventListeners() {
2728 const trigger = this.getAttribute('trigger') || 'hover';
2729 const triggerEl = this.shadowRoot.querySelector('.popover-trigger');
2730 const contentEl = this.shadowRoot.querySelector('.popover-content');
2731
2732 if (!triggerEl || !contentEl) return;
2733
2734 if (trigger === 'hover') {
2735 triggerEl.addEventListener('mouseenter', () => this.show());
2736 triggerEl.addEventListener('mouseleave', () => this.hide());
2737 contentEl.addEventListener('mouseenter', () => this.show());
2738 contentEl.addEventListener('mouseleave', () => this.hide());
2739 } else if (trigger === 'click') {
2740 triggerEl.addEventListener('click', () => this.toggle());
2741 // Close when clicking outside
2742 document.addEventListener('click', (e) => {
2743 if (!this.contains(e.target)) {
2744 this.hide();
2745 }
2746 });
2747 } else if (trigger === 'focus') {
2748 triggerEl.addEventListener('focusin', () => this.show());
2749 triggerEl.addEventListener('focusout', () => this.hide());
2750 }
2751 }
2752
2753 show() {
2754 this.isOpen = true;
2755 const contentEl = this.shadowRoot.querySelector('.popover-content');
2756 if (contentEl) {
2757 contentEl.classList.add('open');
2758 }
2759 this.dispatchEvent(new CustomEvent('popover-show'));
2760 }
2761
2762 hide() {
2763 this.isOpen = false;
2764 const contentEl = this.shadowRoot.querySelector('.popover-content');
2765 if (contentEl) {
2766 contentEl.classList.remove('open');
2767 }
2768 this.dispatchEvent(new CustomEvent('popover-hide'));
2769 }
2770
2771 toggle() {
2772 if (this.isOpen) {
2773 this.hide();
2774 } else {
2775 this.show();
2776 }
2777 }
2778
2779 attributeChangedCallback(name, oldValue, newValue) {
2780 if (name === 'open' && this.shadowRoot.innerHTML) {
2781 if (newValue !== null) {
2782 this.show();
2783 } else {
2784 this.hide();
2785 }
2786 } else if (this.shadowRoot.innerHTML && oldValue !== newValue) {
2787 this.render();
2788 this.setupEventListeners();
2789 }
2790 }
2791}
2792
2793// ============================================================================
2794// BREADCRUMB COMPONENT (Navigation hierarchy)
2795// ============================================================================
2796
2797class SemanticBreadcrumb extends SemanticComponent {
2798 static get observedAttributes() {
2799 return ['separator'];
2800 }
2801
2802 getCSS() {
2803 return `
2804 .breadcrumb-container {
2805 display: flex;
2806 align-items: center;
2807 flex-wrap: wrap;
2808 gap: 8px;
2809 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
2810 font-size: 14px;
2811 padding: 12px 0;
2812 }
2813
2814 .breadcrumb-item {
2815 display: flex;
2816 align-items: center;
2817 gap: 8px;
2818 color: #8e8e93;
2819 text-decoration: none;
2820 transition: color 0.15s ease;
2821 min-height: 44px;
2822 padding: 8px 12px;
2823 border-radius: 6px;
2824 }
2825
2826 .breadcrumb-item:hover {
2827 color: #409cff;
2828 background: rgba(64, 156, 255, 0.1);
2829 }
2830
2831 .breadcrumb-item.active {
2832 color: #fff;
2833 font-weight: 500;
2834 pointer-events: none;
2835 background: transparent;
2836 }
2837
2838 .breadcrumb-separator {
2839 color: #48484a;
2840 user-select: none;
2841 font-size: 12px;
2842 padding: 0 4px;
2843 }
2844
2845 /* Link styles */
2846 a.breadcrumb-item {
2847 cursor: pointer;
2848 }
2849
2850 a.breadcrumb-item:focus-visible {
2851 outline: 2px solid #409cff;
2852 outline-offset: 2px;
2853 border-radius: 6px;
2854 }
2855
2856 /* Mobile responsive */
2857 @media (max-width: 640px) {
2858 .breadcrumb-container {
2859 font-size: 13px;
2860 }
2861
2862 .breadcrumb-item {
2863 padding: 10px 14px;
2864 }
2865 }
2866
2867 @media (prefers-reduced-motion: reduce) {
2868 .breadcrumb-item {
2869 transition: none;
2870 }
2871 }
2872 `;
2873 }
2874
2875 getHTML() {
2876 return `
2877 <nav class="breadcrumb-container" aria-label="Breadcrumb">
2878 <slot></slot>
2879 </nav>
2880 `;
2881 }
2882
2883 render() {
2884 this.shadowRoot.innerHTML = `
2885 <style>
2886 ${this.getCSS()}
2887 </style>
2888 ${this.getHTML()}
2889 `;
2890 }
2891
2892 setupEventListeners() {
2893 setTimeout(() => {
2894 this.renderBreadcrumbs();
2895 }, 0);
2896 }
2897
2898 renderBreadcrumbs() {
2899 const separator = this.getAttribute('separator') || '/';
2900 const items = Array.from(this.querySelectorAll('breadcrumb-item'));
2901 const container = this.shadowRoot.querySelector('.breadcrumb-container');
2902
2903 // Clear existing content
2904 container.innerHTML = '';
2905
2906 items.forEach((item, index) => {
2907 const isLast = index === items.length - 1;
2908 const href = item.getAttribute('href');
2909 const active = item.hasAttribute('active') || isLast;
2910
2911 // Create breadcrumb element
2912 let breadcrumbEl;
2913 if (href && !active) {
2914 breadcrumbEl = document.createElement('a');
2915 breadcrumbEl.href = href;
2916 breadcrumbEl.addEventListener('click', (e) => {
2917 // Allow custom handling
2918 const event = new CustomEvent('breadcrumb-click', {
2919 detail: { href, index, item },
2920 cancelable: true
2921 });
2922 if (!this.dispatchEvent(event)) {
2923 e.preventDefault();
2924 }
2925 });
2926 } else {
2927 breadcrumbEl = document.createElement('span');
2928 }
2929
2930 breadcrumbEl.className = `breadcrumb-item ${active ? 'active' : ''}`;
2931 breadcrumbEl.textContent = item.textContent.trim();
2932
2933 if (active) {
2934 breadcrumbEl.setAttribute('aria-current', 'page');
2935 }
2936
2937 container.appendChild(breadcrumbEl);
2938
2939 // Add separator if not last item
2940 if (!isLast) {
2941 const sep = document.createElement('span');
2942 sep.className = 'breadcrumb-separator';
2943 sep.textContent = separator;
2944 sep.setAttribute('aria-hidden', 'true');
2945 container.appendChild(sep);
2946 }
2947 });
2948 }
2949
2950 attributeChangedCallback(name, oldValue, newValue) {
2951 if (this.shadowRoot.innerHTML && oldValue !== newValue) {
2952 this.renderBreadcrumbs();
2953 }
2954 }
2955}
2956
2957// ============================================================================
2958// CHILD ELEMENTS (for use within parent components)
2959// ============================================================================
2960
2961class NavItem extends HTMLElement {
2962 connectedCallback() {
2963 const icon = this.getAttribute('icon') || '';
2964 const active = this.hasAttribute('active');
2965 const href = this.getAttribute('href') || '#';
2966
2967 this.style.display = 'flex';
2968 this.style.alignItems = 'center';
2969 this.style.gap = '8px';
2970 this.setAttribute('role', 'link');
2971 this.setAttribute('tabindex', '0');
2972
2973 if (active) {
2974 this.setAttribute('aria-current', 'page');
2975 this.classList.add('current');
2976 }
2977
2978 if (icon) {
2979 const iconSpan = document.createElement('span');
2980 iconSpan.textContent = icon;
2981 iconSpan.style.fontSize = '18px';
2982 this.insertBefore(iconSpan, this.firstChild);
2983 }
2984 }
2985}
2986
2987class ListItem extends HTMLElement {
2988 connectedCallback() {
2989 const selected = this.hasAttribute('selected');
2990 const value = this.getAttribute('value') || '';
2991
2992 this.style.display = 'block';
2993 this.setAttribute('role', 'option');
2994 this.setAttribute('tabindex', '0');
2995 this.setAttribute('data-value', value);
2996
2997 if (selected) {
2998 this.setAttribute('aria-selected', 'true');
2999 this.classList.add('selected');
3000 }
3001 }
3002}
3003
3004class MenuItem extends HTMLElement {
3005 connectedCallback() {
3006 const icon = this.getAttribute('icon') || '';
3007 const shortcut = this.getAttribute('shortcut') || '';
3008 const intent = this.getAttribute('intent') || '';
3009
3010 this.style.display = 'flex';
3011 this.style.alignItems = 'center';
3012 this.style.justifyContent = 'space-between';
3013 this.style.gap = '12px';
3014 this.setAttribute('role', 'menuitem');
3015 this.setAttribute('tabindex', '0');
3016
3017 if (intent === 'destructive') {
3018 this.style.color = '#ff3b30';
3019 }
3020
3021 const content = this.innerHTML;
3022 this.innerHTML = `
3023 ${icon ? `<span style="font-size: 16px;">${icon}</span>` : ''}
3024 <span style="flex: 1;">${content}</span>
3025 ${shortcut ? `<span style="font-size: 12px; color: #8a8a8a;">${shortcut}</span>` : ''}
3026 `;
3027 }
3028}
3029
3030class MenuDivider extends HTMLElement {
3031 connectedCallback() {
3032 this.style.height = '1px';
3033 this.style.background = '#38383a';
3034 this.style.margin = '4px 0';
3035 this.setAttribute('role', 'separator');
3036 }
3037}
3038
3039class CardTitle extends HTMLElement {
3040 connectedCallback() {
3041 this.style.display = 'block';
3042 this.style.fontSize = '18px';
3043 this.style.fontWeight = '600';
3044 this.style.color = '#fff';
3045 }
3046}
3047
3048class CardDescription extends HTMLElement {
3049 connectedCallback() {
3050 this.style.display = 'block';
3051 this.style.fontSize = '14px';
3052 this.style.color = '#ababab';
3053 }
3054}
3055
3056class TabItem extends HTMLElement {
3057 connectedCallback() {
3058 // Tab item is just a marker element, actual rendering happens in SemanticTabs
3059 this.style.display = 'none';
3060 }
3061}
3062
3063class TabPanel extends HTMLElement {
3064 connectedCallback() {
3065 // Tab panel will be moved into shadow DOM by SemanticTabs
3066 // No styling needed here
3067 }
3068}
3069
3070class DisclosureItem extends HTMLElement {
3071 connectedCallback() {
3072 // Disclosure item is just a marker element, actual rendering happens in SemanticDisclosure
3073 this.style.display = 'none';
3074 }
3075}
3076
3077class BreadcrumbItem extends HTMLElement {
3078 connectedCallback() {
3079 // Breadcrumb item is just a marker element, actual rendering happens in SemanticBreadcrumb
3080 this.style.display = 'none';
3081 }
3082}
3083
3084// ============================================================================
3085// LAYOUT COMPONENTS (Phase 2)
3086// ============================================================================
3087
3088/**
3089 * SemanticStack - Vertical or horizontal stacking with consistent spacing
3090 *
3091 * Attributes:
3092 * - direction: "vertical" | "horizontal" (default: "vertical")
3093 * - spacing: "1" | "2" | "3" | "4" | "6" | "8" (default: "4")
3094 * - align: "start" | "center" | "end" | "stretch" (default: "stretch")
3095 * - justify: "start" | "center" | "end" | "between" | "around" (default: "start")
3096 * - wrap: boolean (default: false)
3097 */
3098class SemanticStack extends HTMLElement {
3099 constructor() {
3100 super();
3101 this.attachShadow({ mode: 'open' });
3102 }
3103
3104 static get observedAttributes() {
3105 return ['direction', 'spacing', 'align', 'justify', 'wrap'];
3106 }
3107
3108 connectedCallback() {
3109 this.render();
3110 }
3111
3112 attributeChangedCallback() {
3113 if (this.shadowRoot.innerHTML) {
3114 this.render();
3115 }
3116 }
3117
3118 render() {
3119 const direction = this.getAttribute('direction') || 'vertical';
3120 const spacing = this.getAttribute('spacing') || '4';
3121 const align = this.getAttribute('align') || 'stretch';
3122 const justify = this.getAttribute('justify') || 'start';
3123 const wrap = this.hasAttribute('wrap');
3124
3125 const spacingMap = {
3126 '1': '4px',
3127 '2': '8px',
3128 '3': '12px',
3129 '4': '16px',
3130 '6': '24px',
3131 '8': '32px'
3132 };
3133
3134 const alignMap = {
3135 'start': 'flex-start',
3136 'center': 'center',
3137 'end': 'flex-end',
3138 'stretch': 'stretch'
3139 };
3140
3141 const justifyMap = {
3142 'start': 'flex-start',
3143 'center': 'center',
3144 'end': 'flex-end',
3145 'between': 'space-between',
3146 'around': 'space-around'
3147 };
3148
3149 this.shadowRoot.innerHTML = `
3150 <style>
3151 :host {
3152 display: flex;
3153 flex-direction: ${direction === 'horizontal' ? 'row' : 'column'};
3154 gap: ${spacingMap[spacing] || '16px'};
3155 align-items: ${alignMap[align] || 'stretch'};
3156 justify-content: ${justifyMap[justify] || 'flex-start'};
3157 ${wrap ? 'flex-wrap: wrap;' : ''}
3158 width: 100%;
3159 }
3160
3161 /* Accessibility: make stack keyboard navigable if it contains focusable items */
3162 :host(:focus-within) {
3163 outline: 2px solid transparent;
3164 }
3165
3166 /* Reduced motion support */
3167 @media (prefers-reduced-motion: reduce) {
3168 :host {
3169 transition: none;
3170 }
3171 }
3172 </style>
3173 <slot></slot>
3174 `;
3175 }
3176}
3177
3178/**
3179 * SemanticGrid - Responsive grid layouts with automatic columns
3180 *
3181 * Attributes:
3182 * - cols: "1" | "2" | "3" | "4" | "auto-fit" | "auto-fill" (default: "auto-fit")
3183 * - gap: "1" | "2" | "3" | "4" | "6" | "8" (default: "4")
3184 * - min-width: minimum column width for auto layouts (default: "250px")
3185 * - responsive: boolean - automatically adjust columns on mobile (default: true)
3186 */
3187class SemanticGrid extends HTMLElement {
3188 constructor() {
3189 super();
3190 this.attachShadow({ mode: 'open' });
3191 }
3192
3193 static get observedAttributes() {
3194 return ['cols', 'gap', 'min-width', 'responsive'];
3195 }
3196
3197 connectedCallback() {
3198 this.render();
3199 }
3200
3201 attributeChangedCallback() {
3202 if (this.shadowRoot.innerHTML) {
3203 this.render();
3204 }
3205 }
3206
3207 render() {
3208 const cols = this.getAttribute('cols') || 'auto-fit';
3209 const gap = this.getAttribute('gap') || '4';
3210 const minWidth = this.getAttribute('min-width') || '250px';
3211 const responsive = this.hasAttribute('responsive') !== false;
3212
3213 const spacingMap = {
3214 '1': '4px',
3215 '2': '8px',
3216 '3': '12px',
3217 '4': '16px',
3218 '6': '24px',
3219 '8': '32px'
3220 };
3221
3222 let gridTemplate;
3223 if (cols === 'auto-fit' || cols === 'auto-fill') {
3224 gridTemplate = `repeat(${cols}, minmax(${minWidth}, 1fr))`;
3225 } else {
3226 gridTemplate = `repeat(${cols}, minmax(0, 1fr))`;
3227 }
3228
3229 this.shadowRoot.innerHTML = `
3230 <style>
3231 :host {
3232 display: block;
3233 width: 100%;
3234 }
3235
3236 .grid-container {
3237 display: grid;
3238 grid-template-columns: ${gridTemplate};
3239 gap: ${spacingMap[gap] || '16px'};
3240 width: 100%;
3241 }
3242
3243 ${responsive ? `
3244 /* Mobile responsive - stack on small screens */
3245 @media (max-width: 640px) {
3246 .grid-container {
3247 grid-template-columns: 1fr;
3248 }
3249 }
3250 ` : ''}
3251
3252 /* Accessibility */
3253 :host(:focus-within) {
3254 outline: 2px solid transparent;
3255 }
3256
3257 /* Reduced motion support */
3258 @media (prefers-reduced-motion: reduce) {
3259 :host {
3260 transition: none;
3261 }
3262 }
3263
3264 /* Ensure grid items can grow to fill available space */
3265 .grid-container ::slotted(*) {
3266 min-width: 0;
3267 }
3268 </style>
3269 <div class="grid-container">
3270 <slot></slot>
3271 </div>
3272 `;
3273 }
3274}
3275
3276/**
3277 * SemanticContainer - Max-width containers with responsive padding
3278 *
3279 * Attributes:
3280 * - size: "small" | "medium" | "large" | "xlarge" | "full" (default: "large")
3281 * - padding: boolean - add responsive padding (default: true)
3282 */
3283class SemanticContainer extends HTMLElement {
3284 constructor() {
3285 super();
3286 this.attachShadow({ mode: 'open' });
3287 }
3288
3289 static get observedAttributes() {
3290 return ['size', 'padding'];
3291 }
3292
3293 connectedCallback() {
3294 this.render();
3295 }
3296
3297 attributeChangedCallback() {
3298 if (this.shadowRoot.innerHTML) {
3299 this.render();
3300 }
3301 }
3302
3303 render() {
3304 const size = this.getAttribute('size') || 'large';
3305 const padding = this.hasAttribute('padding') !== false;
3306
3307 const sizeMap = {
3308 'small': '640px',
3309 'medium': '768px',
3310 'large': '1024px',
3311 'xlarge': '1280px',
3312 'full': '100%'
3313 };
3314
3315 this.shadowRoot.innerHTML = `
3316 <style>
3317 :host {
3318 display: block;
3319 width: 100%;
3320 max-width: ${sizeMap[size] || '1024px'};
3321 margin: 0 auto;
3322 ${padding ? 'padding: 0 20px;' : ''}
3323 }
3324
3325 .container-inner {
3326 display: grid;
3327 grid-template-columns: minmax(0, 1fr);
3328 }
3329
3330 .container-inner ::slotted(*) {
3331 min-width: 0;
3332 }
3333
3334 ${padding ? `
3335 /* Responsive padding */
3336 @media (min-width: 640px) {
3337 :host {
3338 padding: 0 24px;
3339 }
3340 }
3341
3342 @media (min-width: 1024px) {
3343 :host {
3344 padding: 0 32px;
3345 }
3346 }
3347 ` : ''}
3348
3349 /* Accessibility: container as landmark */
3350 :host {
3351 role: region;
3352 }
3353 </style>
3354 <div class="container-inner">
3355 <slot></slot>
3356 </div>
3357 `;
3358 }
3359}
3360
3361customElements.define('semantic-action', SemanticAction);
3362customElements.define('semantic-card', SemanticCard);
3363customElements.define('semantic-feedback', SemanticFeedback);
3364customElements.define('semantic-adjuster', SemanticAdjuster);
3365customElements.define('semantic-input', SemanticInput);
3366customElements.define('semantic-modal', SemanticModal);
3367customElements.define('semantic-navigator', SemanticNavigator);
3368customElements.define('semantic-list', SemanticList);
3369customElements.define('semantic-menu', SemanticMenu);
3370customElements.define('semantic-tabs', SemanticTabs);
3371customElements.define('semantic-disclosure', SemanticDisclosure);
3372customElements.define('semantic-progress', SemanticProgress);
3373customElements.define('semantic-badge', SemanticBadge);
3374customElements.define('semantic-popover', SemanticPopover);
3375customElements.define('semantic-breadcrumb', SemanticBreadcrumb);
3376customElements.define('semantic-stack', SemanticStack);
3377customElements.define('semantic-grid', SemanticGrid);
3378customElements.define('semantic-container', SemanticContainer);
3379customElements.define('semantic-hero', SemanticHero);
3380
3381/**
3382 * Semantic Hero - Premium marketing hero sections
3383 *
3384 * Variants:
3385 * - centered: Classic centered hero (default)
3386 * - split: Content left, image right
3387 * - minimal: Clean single CTA
3388 * - background: Full background image/video
3389 *
3390 * Usage:
3391 * <semantic-hero variant="centered" height="large">
3392 * <h1 slot="heading">Your Amazing Product</h1>
3393 * <p slot="subheading">The best solution for your needs</p>
3394 * <div slot="actions">
3395 * <semantic-action intent="primary" size="large">Get Started</semantic-action>
3396 * </div>
3397 * <img slot="image" src="hero.jpg" alt="Product">
3398 * </semantic-hero>
3399 */
3400class SemanticHero extends HTMLElement {
3401 constructor() {
3402 super();
3403 this.attachShadow({ mode: 'open' });
3404 }
3405
3406 static get observedAttributes() {
3407 return ['variant', 'height', 'background', 'background-video', 'align'];
3408 }
3409
3410 connectedCallback() {
3411 this.render();
3412 }
3413
3414 attributeChangedCallback() {
3415 if (this.shadowRoot.innerHTML) {
3416 this.render();
3417 }
3418 }
3419
3420 render() {
3421 const variant = this.getAttribute('variant') || 'centered';
3422 const height = this.getAttribute('height') || 'medium';
3423 const background = this.getAttribute('background') || '';
3424 const backgroundVideo = this.getAttribute('background-video') || '';
3425 const align = this.getAttribute('align') || 'center';
3426
3427 const heightMap = {
3428 'small': '400px',
3429 'medium': '600px',
3430 'large': '100vh',
3431 'auto': 'auto'
3432 };
3433
3434 const alignMap = {
3435 'left': 'flex-start',
3436 'center': 'center',
3437 'right': 'flex-end'
3438 };
3439
3440 this.shadowRoot.innerHTML = `
3441 <style>
3442 :host {
3443 display: block;
3444 position: relative;
3445 width: 100%;
3446 min-height: ${heightMap[height] || '600px'};
3447 overflow: hidden;
3448 }
3449
3450 .hero-container {
3451 position: relative;
3452 width: 100%;
3453 height: 100%;
3454 min-height: inherit;
3455 display: flex;
3456 align-items: center;
3457 justify-content: ${alignMap[align] || 'center'};
3458 padding: 80px 32px;
3459 box-sizing: border-box;
3460 }
3461
3462 /* Background styling */
3463 .hero-background {
3464 position: absolute;
3465 top: 0;
3466 left: 0;
3467 width: 100%;
3468 height: 100%;
3469 z-index: 0;
3470 }
3471
3472 .hero-background.image {
3473 background-image: url('${background}');
3474 background-size: cover;
3475 background-position: center;
3476 }
3477
3478 .hero-background.video video {
3479 width: 100%;
3480 height: 100%;
3481 object-fit: cover;
3482 }
3483
3484 .hero-background-overlay {
3485 position: absolute;
3486 top: 0;
3487 left: 0;
3488 width: 100%;
3489 height: 100%;
3490 background: ${background || backgroundVideo ? 'rgba(0, 0, 0, 0.4)' : 'transparent'};
3491 z-index: 1;
3492 }
3493
3494 .hero-content {
3495 position: relative;
3496 z-index: 2;
3497 max-width: 1280px;
3498 width: 100%;
3499 margin: 0 auto;
3500 }
3501
3502 /* Centered variant (default) */
3503 .hero-content.centered {
3504 text-align: center;
3505 display: flex;
3506 flex-direction: column;
3507 align-items: center;
3508 gap: 24px;
3509 }
3510
3511 .centered ::slotted([slot="heading"]) {
3512 font-size: 56px;
3513 font-weight: 800;
3514 line-height: 1.2;
3515 margin: 0;
3516 max-width: 800px;
3517 }
3518
3519 .centered ::slotted([slot="subheading"]) {
3520 font-size: 20px;
3521 line-height: 1.6;
3522 margin: 0;
3523 max-width: 600px;
3524 opacity: 0.9;
3525 }
3526
3527 .centered ::slotted([slot="actions"]) {
3528 display: flex;
3529 gap: 16px;
3530 flex-wrap: wrap;
3531 justify-content: center;
3532 }
3533
3534 .centered ::slotted([slot="badge"]) {
3535 margin-bottom: 16px;
3536 }
3537
3538 /* Split variant */
3539 .hero-content.split {
3540 display: grid;
3541 grid-template-columns: 1fr 1fr;
3542 gap: 64px;
3543 align-items: center;
3544 }
3545
3546 .split .content-col {
3547 display: flex;
3548 flex-direction: column;
3549 gap: 24px;
3550 }
3551
3552 .split ::slotted([slot="heading"]) {
3553 font-size: 48px;
3554 font-weight: 800;
3555 line-height: 1.2;
3556 margin: 0;
3557 }
3558
3559 .split ::slotted([slot="subheading"]) {
3560 font-size: 18px;
3561 line-height: 1.6;
3562 margin: 0;
3563 opacity: 0.9;
3564 }
3565
3566 .split ::slotted([slot="actions"]) {
3567 display: flex;
3568 gap: 16px;
3569 flex-wrap: wrap;
3570 }
3571
3572 .split ::slotted([slot="image"]) {
3573 width: 100%;
3574 height: auto;
3575 border-radius: 12px;
3576 box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
3577 }
3578
3579 /* Minimal variant */
3580 .hero-content.minimal {
3581 text-align: center;
3582 display: flex;
3583 flex-direction: column;
3584 align-items: center;
3585 gap: 32px;
3586 max-width: 600px;
3587 }
3588
3589 .minimal ::slotted([slot="heading"]) {
3590 font-size: 64px;
3591 font-weight: 800;
3592 line-height: 1.1;
3593 margin: 0;
3594 }
3595
3596 .minimal ::slotted([slot="subheading"]) {
3597 font-size: 18px;
3598 line-height: 1.6;
3599 margin: 0;
3600 opacity: 0.7;
3601 }
3602
3603 .minimal ::slotted([slot="actions"]) {
3604 display: flex;
3605 justify-content: center;
3606 }
3607
3608 /* Background variant */
3609 .hero-content.background {
3610 text-align: center;
3611 display: flex;
3612 flex-direction: column;
3613 align-items: center;
3614 gap: 24px;
3615 color: white;
3616 }
3617
3618 .background ::slotted([slot="heading"]) {
3619 font-size: 56px;
3620 font-weight: 800;
3621 line-height: 1.2;
3622 margin: 0;
3623 max-width: 800px;
3624 color: white;
3625 text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
3626 }
3627
3628 .background ::slotted([slot="subheading"]) {
3629 font-size: 20px;
3630 line-height: 1.6;
3631 margin: 0;
3632 max-width: 600px;
3633 color: white;
3634 text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
3635 }
3636
3637 .background ::slotted([slot="actions"]) {
3638 display: flex;
3639 gap: 16px;
3640 flex-wrap: wrap;
3641 justify-content: center;
3642 }
3643
3644 /* Responsive */
3645 @media (max-width: 768px) {
3646 .hero-container {
3647 padding: 60px 24px;
3648 }
3649
3650 .hero-content.split {
3651 grid-template-columns: 1fr;
3652 gap: 40px;
3653 }
3654
3655 .centered ::slotted([slot="heading"]),
3656 .background ::slotted([slot="heading"]) {
3657 font-size: 40px;
3658 }
3659
3660 .split ::slotted([slot="heading"]) {
3661 font-size: 36px;
3662 }
3663
3664 .minimal ::slotted([slot="heading"]) {
3665 font-size: 48px;
3666 }
3667
3668 .centered ::slotted([slot="subheading"]),
3669 .split ::slotted([slot="subheading"]),
3670 .background ::slotted([slot="subheading"]) {
3671 font-size: 18px;
3672 }
3673
3674 .minimal ::slotted([slot="subheading"]) {
3675 font-size: 16px;
3676 }
3677 }
3678
3679 /* Accessibility */
3680 @media (prefers-reduced-motion: reduce) {
3681 * {
3682 animation: none !important;
3683 transition: none !important;
3684 }
3685 }
3686 </style>
3687
3688 ${background ? `<div class="hero-background image"></div>` : ''}
3689 ${backgroundVideo ? `
3690 <div class="hero-background video">
3691 <video autoplay muted loop playsinline>
3692 <source src="${backgroundVideo}" type="video/mp4">
3693 </video>
3694 </div>
3695 ` : ''}
3696 ${background || backgroundVideo ? '<div class="hero-background-overlay"></div>' : ''}
3697
3698 <div class="hero-container">
3699 <div class="hero-content ${variant}">
3700 ${variant === 'split' ? `
3701 <div class="content-col">
3702 <slot name="badge"></slot>
3703 <slot name="heading"></slot>
3704 <slot name="subheading"></slot>
3705 <slot name="actions"></slot>
3706 </div>
3707 <div class="image-col">
3708 <slot name="image"></slot>
3709 </div>
3710 ` : `
3711 <slot name="badge"></slot>
3712 <slot name="heading"></slot>
3713 <slot name="subheading"></slot>
3714 <slot name="actions"></slot>
3715 <slot name="image"></slot>
3716 `}
3717 </div>
3718 </div>
3719 `;
3720 }
3721}
3722
3723// Child elements
3724customElements.define('nav-item', NavItem);
3725customElements.define('list-item', ListItem);
3726customElements.define('menu-item', MenuItem);
3727customElements.define('menu-divider', MenuDivider);
3728customElements.define('card-title', CardTitle);
3729customElements.define('card-description', CardDescription);
3730customElements.define('tab-item', TabItem);
3731customElements.define('tab-panel', TabPanel);
3732customElements.define('disclosure-item', DisclosureItem);
3733customElements.define('breadcrumb-item', BreadcrumbItem);
3734
3735// Export for module usage
3736if (typeof module !== 'undefined' && module.exports) {
3737 module.exports = {
3738 SemanticAction,
3739 SemanticCard,
3740 SemanticFeedback,
3741 SemanticAdjuster,
3742 SemanticInput,
3743 SemanticModal,
3744 SemanticNavigator,
3745 SemanticList,
3746 SemanticMenu,
3747 ContextManager
3748 };
3749}