@wcomp/elementum 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +282 -2
  3. package/custom-elements.json +3613 -0
  4. package/mcp/server.js +593 -0
  5. package/package.json +77 -4
  6. package/skills/elementum-break-ui/CATALOG.md +11 -0
  7. package/skills/elementum-break-ui/SKILL.md +16 -0
  8. package/skills/elementum-mobile/SKILL.md +18 -0
  9. package/skills/elementum-motion/SKILL.md +18 -0
  10. package/skills/elementum-motion/STANDARDS.md +15 -0
  11. package/skills/elementum-penpot/SKILL.md +45 -0
  12. package/skills/elementum-ui/CATALOG.md +14 -0
  13. package/skills/elementum-ui/SKILL.md +21 -0
  14. package/src/ag-ui.js +474 -0
  15. package/src/behaviors/index.js +760 -0
  16. package/src/components/el-accordion.js +201 -0
  17. package/src/components/el-alert-dialog.js +186 -0
  18. package/src/components/el-alert.js +254 -0
  19. package/src/components/el-aspect-ratio.js +73 -0
  20. package/src/components/el-autocomplete.js +775 -0
  21. package/src/components/el-avatar.js +271 -0
  22. package/src/components/el-badge.js +131 -0
  23. package/src/components/el-border-beam.js +135 -0
  24. package/src/components/el-breadcrumb.js +203 -0
  25. package/src/components/el-button.js +231 -0
  26. package/src/components/el-calendar.js +436 -0
  27. package/src/components/el-callout.js +158 -0
  28. package/src/components/el-card.js +298 -0
  29. package/src/components/el-carousel.js +308 -0
  30. package/src/components/el-chart.js +632 -0
  31. package/src/components/el-checkbox-card.js +221 -0
  32. package/src/components/el-checkbox.js +208 -0
  33. package/src/components/el-chip.js +276 -0
  34. package/src/components/el-code-block.js +230 -0
  35. package/src/components/el-collapsible.js +124 -0
  36. package/src/components/el-command.js +556 -0
  37. package/src/components/el-context-menu.js +328 -0
  38. package/src/components/el-data-list.js +210 -0
  39. package/src/components/el-datepicker.js +192 -0
  40. package/src/components/el-dialog.js +272 -0
  41. package/src/components/el-diff-viewer.js +441 -0
  42. package/src/components/el-drawer.js +782 -0
  43. package/src/components/el-dropdown.js +182 -0
  44. package/src/components/el-dropzone.js +242 -0
  45. package/src/components/el-empty-state.js +130 -0
  46. package/src/components/el-field.js +394 -0
  47. package/src/components/el-form.js +185 -0
  48. package/src/components/el-input.js +229 -0
  49. package/src/components/el-inset.js +90 -0
  50. package/src/components/el-insight-card.js +263 -0
  51. package/src/components/el-kbd.js +151 -0
  52. package/src/components/el-menubar.js +254 -0
  53. package/src/components/el-meter.js +183 -0
  54. package/src/components/el-navbar.js +294 -0
  55. package/src/components/el-navigation-menu.js +327 -0
  56. package/src/components/el-number-field.js +510 -0
  57. package/src/components/el-number-flow.js +164 -0
  58. package/src/components/el-otp-input.js +266 -0
  59. package/src/components/el-pagination.js +231 -0
  60. package/src/components/el-popover.js +288 -0
  61. package/src/components/el-preview-card.js +202 -0
  62. package/src/components/el-progress.js +179 -0
  63. package/src/components/el-prompt-input.js +383 -0
  64. package/src/components/el-radio-card.js +360 -0
  65. package/src/components/el-radio.js +257 -0
  66. package/src/components/el-rating.js +165 -0
  67. package/src/components/el-reasoning-card.js +293 -0
  68. package/src/components/el-resizable.js +324 -0
  69. package/src/components/el-router.js +305 -0
  70. package/src/components/el-scroll-area.js +150 -0
  71. package/src/components/el-segmented-control.js +282 -0
  72. package/src/components/el-select.js +220 -0
  73. package/src/components/el-separator.js +85 -0
  74. package/src/components/el-sidebar.js +386 -0
  75. package/src/components/el-skeleton.js +156 -0
  76. package/src/components/el-slider.js +351 -0
  77. package/src/components/el-sources.js +288 -0
  78. package/src/components/el-spinner.js +159 -0
  79. package/src/components/el-streaming-text.js +199 -0
  80. package/src/components/el-switch.js +221 -0
  81. package/src/components/el-table.js +397 -0
  82. package/src/components/el-tabs.js +235 -0
  83. package/src/components/el-task-list.js +230 -0
  84. package/src/components/el-textarea.js +175 -0
  85. package/src/components/el-theme-switch.js +120 -0
  86. package/src/components/el-timeline.js +254 -0
  87. package/src/components/el-toast.js +778 -0
  88. package/src/components/el-toggle.js +311 -0
  89. package/src/components/el-tool-call.js +386 -0
  90. package/src/components/el-toolbar.js +183 -0
  91. package/src/components/el-tooltip.js +172 -0
  92. package/src/components/el-tree-view.js +261 -0
  93. package/src/components/el-visually-hidden.js +32 -0
  94. package/src/elementum.js +504 -0
  95. package/src/index.d.ts +1093 -0
  96. package/src/index.js +112 -0
  97. package/src/signal.js +215 -0
  98. package/src/ssr.js +136 -0
  99. package/src/template.js +321 -0
  100. package/src/tokens.css +416 -0
  101. package/tokens/figma-tokens.json +69 -0
  102. package/tokens/penpot-tokens.json +98 -0
@@ -0,0 +1,150 @@
1
+ /**
2
+ * <el-scroll-area>
3
+ * Accessible, zero-dependency custom scrollbar primitive inspired by Base UI.
4
+ * Provides sleek, unobtrusive cross-browser scrollbars with custom track/thumb styling
5
+ * and zero layout shifts.
6
+ */
7
+
8
+ import { Elementum } from '../elementum.js';
9
+ import { html, css } from '../template.js';
10
+ import { signal } from '../signal.js';
11
+
12
+ export class ElScrollArea extends Elementum {
13
+ static observedAttributes = ['type', 'max-height', 'max-width', 'height'];
14
+
15
+ type = signal('hover');
16
+ maxHeight = signal('');
17
+ maxWidth = signal('');
18
+ height = signal('');
19
+
20
+ static styles = css`
21
+ :host {
22
+ display: block;
23
+ position: relative;
24
+ overflow: hidden;
25
+ font-family: var(--el-font-sans, system-ui, sans-serif);
26
+ box-sizing: border-box;
27
+ }
28
+
29
+ .viewport {
30
+ width: 100%;
31
+ height: 100%;
32
+ overflow: auto;
33
+ box-sizing: border-box;
34
+ scrollbar-width: thin;
35
+ scrollbar-color: var(--el-surface-border, #cbd5e1) transparent;
36
+ -webkit-overflow-scrolling: touch;
37
+ }
38
+
39
+ :root[data-theme="dark"] .viewport {
40
+ scrollbar-color: #475569 transparent;
41
+ }
42
+
43
+ /* WebKit sleek custom scrollbar */
44
+ .viewport::-webkit-scrollbar {
45
+ width: 6px;
46
+ height: 6px;
47
+ }
48
+
49
+ .viewport::-webkit-scrollbar-track {
50
+ background: transparent;
51
+ }
52
+
53
+ .viewport::-webkit-scrollbar-thumb {
54
+ background: var(--el-surface-border, #cbd5e1);
55
+ border-radius: 9999px;
56
+ transition: background 150ms ease;
57
+ }
58
+
59
+ .viewport::-webkit-scrollbar-thumb:hover {
60
+ background: var(--el-text-muted, #94a3b8);
61
+ }
62
+
63
+ :root[data-theme="dark"] .viewport::-webkit-scrollbar-thumb {
64
+ background: #475569;
65
+ }
66
+
67
+ :root[data-theme="dark"] .viewport::-webkit-scrollbar-thumb:hover {
68
+ background: #64748b;
69
+ }
70
+
71
+ /* Hover-only scrollbar mode */
72
+ :host([type="hover"]) .viewport {
73
+ scrollbar-color: transparent transparent;
74
+ }
75
+
76
+ :host([type="hover"]:hover) .viewport {
77
+ scrollbar-color: var(--el-surface-border, #cbd5e1) transparent;
78
+ }
79
+
80
+ :host([type="hover"]) .viewport::-webkit-scrollbar-thumb {
81
+ background: transparent;
82
+ }
83
+
84
+ :host([type="hover"]:hover) .viewport::-webkit-scrollbar-thumb {
85
+ background: var(--el-surface-border, #cbd5e1);
86
+ }
87
+
88
+ :host([type="always"]) .viewport {
89
+ overflow: scroll;
90
+ scrollbar-color: var(--el-surface-border, #cbd5e1) transparent;
91
+ }
92
+ :host([type="always"]) .viewport::-webkit-scrollbar-thumb {
93
+ background: var(--el-surface-border, #cbd5e1);
94
+ }
95
+
96
+ :host([type="scroll"]) .viewport {
97
+ overflow: auto;
98
+ scrollbar-color: var(--el-text-muted, #94a3b8) transparent;
99
+ }
100
+
101
+ :host([type="auto"]) .viewport {
102
+ overflow: auto;
103
+ }
104
+ `;
105
+
106
+ #normalizeSize(val) {
107
+ if (!val) return '';
108
+ return /^\d+(\.\d+)?$/.test(val.trim()) ? `${val.trim()}px` : val;
109
+ }
110
+
111
+ connected() {
112
+ if (this.hasAttribute('type')) this.type.value = this.getAttribute('type');
113
+ if (this.hasAttribute('max-height')) this.maxHeight.value = this.#normalizeSize(this.getAttribute('max-height'));
114
+ if (this.hasAttribute('max-width')) this.maxWidth.value = this.#normalizeSize(this.getAttribute('max-width'));
115
+ if (this.hasAttribute('height')) this.height.value = this.#normalizeSize(this.getAttribute('height'));
116
+ }
117
+
118
+ attributeChanged(name, oldValue, newValue) {
119
+ if (name === 'type') this.type.value = newValue || 'hover';
120
+ else if (name === 'max-height') this.maxHeight.value = this.#normalizeSize(newValue || '');
121
+ else if (name === 'max-width') this.maxWidth.value = this.#normalizeSize(newValue || '');
122
+ else if (name === 'height') this.height.value = this.#normalizeSize(newValue || '');
123
+ return true;
124
+ }
125
+
126
+ render() {
127
+ return html`
128
+ <div
129
+ class="viewport"
130
+ part="viewport"
131
+ tabindex="0"
132
+ role="region"
133
+ aria-label="Scrollable container"
134
+ style=${() => {
135
+ let s = '';
136
+ if (this.height.value) s += `height: ${this.height.value};`;
137
+ if (this.maxHeight.value) s += `max-height: ${this.maxHeight.value};`;
138
+ if (this.maxWidth.value) s += `max-width: ${this.maxWidth.value};`;
139
+ return s;
140
+ }}
141
+ >
142
+ <slot></slot>
143
+ </div>
144
+ `;
145
+ }
146
+ }
147
+
148
+ if (typeof customElements !== 'undefined' && !customElements.get('el-scroll-area')) {
149
+ customElements.define('el-scroll-area', ElScrollArea);
150
+ }
@@ -0,0 +1,282 @@
1
+ import { Elementum } from '../elementum.js';
2
+ import { html, css } from '../template.js';
3
+ import { signal } from '../signal.js';
4
+
5
+ export class ElSegmentedControl extends Elementum {
6
+ static formAssociated = true;
7
+ static observedAttributes = ['value', 'disabled', 'size', 'name', 'options'];
8
+
9
+ value = signal('');
10
+ disabled = signal(false);
11
+ size = signal('md'); // 'sm' | 'md' | 'lg'
12
+ name = signal('');
13
+ #options = signal([]);
14
+
15
+ connected() {
16
+ this.disabled.value = this.hasAttribute('disabled');
17
+ this.size.value = this.getAttribute('size') || 'md';
18
+ this.name.value = this.getAttribute('name') || '';
19
+
20
+ this.#scanOptions();
21
+
22
+ const observer = new MutationObserver(() => this.#scanOptions());
23
+ observer.observe(this, { childList: true, subtree: true, characterData: true });
24
+ this.signal?.addEventListener('abort', () => observer.disconnect());
25
+
26
+ const initial = this.getAttribute('value') || this.#options.value[0]?.value || '';
27
+ this.value.value = initial;
28
+ this.setFormValue(initial);
29
+
30
+ this.addEventListener('keydown', this.#onKeyDown);
31
+ }
32
+
33
+ disconnected() {
34
+ this.removeEventListener('keydown', this.#onKeyDown);
35
+ }
36
+
37
+ attributeChanged(name, oldValue, newValue) {
38
+ if (name === 'value') {
39
+ this.value.value = newValue || '';
40
+ this.setFormValue(this.value.value);
41
+ } else if (name === 'disabled') {
42
+ this.disabled.value = newValue !== null && newValue !== 'false';
43
+ } else if (name === 'size') {
44
+ this.size.value = newValue || 'md';
45
+ } else if (name === 'options') {
46
+ this.#scanOptions();
47
+ if (!this.value.value && this.#options.value[0]) {
48
+ this.value.value = this.#options.value[0].value;
49
+ this.setFormValue(this.value.value);
50
+ }
51
+ }
52
+ }
53
+
54
+ formReset() {
55
+ const initial = this.getAttribute('value') || this.#options.value[0]?.value || '';
56
+ this.value.value = initial;
57
+ this.setFormValue(initial);
58
+ }
59
+
60
+ #scanOptions() {
61
+ const raw = Array.from(this.querySelectorAll('option')).map((opt) => ({
62
+ label: opt.textContent.trim(),
63
+ value: opt.value || opt.textContent.trim(),
64
+ disabled: opt.hasAttribute('disabled'),
65
+ }));
66
+
67
+ if (raw.length > 0) {
68
+ this.#options.value = raw;
69
+ if (!this.value.value && raw[0]) {
70
+ this.value.value = raw[0].value;
71
+ this.setFormValue(raw[0].value);
72
+ }
73
+ return;
74
+ }
75
+
76
+ const optAttr = this.getAttribute('options');
77
+ if (optAttr) {
78
+ try {
79
+ const parsed = JSON.parse(optAttr);
80
+ if (Array.isArray(parsed)) {
81
+ this.#options.value = parsed.map((o) =>
82
+ typeof o === 'string'
83
+ ? { label: o, value: o, disabled: false }
84
+ : { label: o.label || o.value, value: o.value || o.label, disabled: !!o.disabled }
85
+ );
86
+ if (!this.value.value && this.#options.value[0]) {
87
+ this.value.value = this.#options.value[0].value;
88
+ this.setFormValue(this.value.value);
89
+ }
90
+ return;
91
+ }
92
+ } catch (e) {
93
+ this.#options.value = optAttr
94
+ .split(',')
95
+ .map((s) => s.trim())
96
+ .filter(Boolean)
97
+ .map((s) => ({ label: s, value: s, disabled: false }));
98
+ if (!this.value.value && this.#options.value[0]) {
99
+ this.value.value = this.#options.value[0].value;
100
+ this.setFormValue(this.value.value);
101
+ }
102
+ return;
103
+ }
104
+ }
105
+
106
+ this.#options.value = [];
107
+ }
108
+
109
+ selectOption(val) {
110
+ if (this.disabled.value) return;
111
+ const opt = this.#options.value.find((o) => o.value === val);
112
+ if (opt && !opt.disabled && this.value.value !== val) {
113
+ this.value.value = val;
114
+ this.setFormValue(val);
115
+ this.emit('change', { value: val });
116
+ }
117
+ }
118
+
119
+ #onKeyDown = (e) => {
120
+ if (this.disabled.value) return;
121
+ const opts = this.#options.value.filter((o) => !o.disabled);
122
+ if (!opts.length) return;
123
+
124
+ const currentIndex = opts.findIndex((o) => o.value === this.value.value);
125
+ let nextIndex = -1;
126
+
127
+ if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
128
+ e.preventDefault();
129
+ nextIndex = (currentIndex + 1) % opts.length;
130
+ } else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
131
+ e.preventDefault();
132
+ nextIndex = (currentIndex - 1 + opts.length) % opts.length;
133
+ }
134
+
135
+ if (nextIndex >= 0) {
136
+ this.selectOption(opts[nextIndex].value);
137
+ // Focus newly selected segment button
138
+ const buttons = this.root.querySelectorAll('button[role="radio"]');
139
+ buttons[nextIndex]?.focus();
140
+ }
141
+ };
142
+
143
+ static styles = css`
144
+ :host {
145
+ display: inline-flex;
146
+ max-width: 100%;
147
+ vertical-align: middle;
148
+ box-sizing: border-box;
149
+ user-select: none;
150
+ }
151
+
152
+ .segmented-group {
153
+ display: inline-flex;
154
+ max-width: 100%;
155
+ overflow-x: auto;
156
+ -webkit-overflow-scrolling: touch;
157
+ align-items: center;
158
+ background: var(--el-surface-muted, #f1f5f9);
159
+ border: 1px solid var(--el-surface-border, #e2e8f0);
160
+ border-radius: var(--el-radius-md, 8px);
161
+ padding: 3px;
162
+ gap: 2px;
163
+ font-family: var(--el-font-sans, system-ui, sans-serif);
164
+ }
165
+
166
+ .segment-btn {
167
+ display: inline-flex;
168
+ align-items: center;
169
+ justify-content: center;
170
+ border: none;
171
+ background: transparent;
172
+ color: var(--el-text-muted, #64748b);
173
+ font-weight: 500;
174
+ cursor: pointer;
175
+ touch-action: manipulation;
176
+ -webkit-tap-highlight-color: transparent;
177
+ border-radius: calc(var(--el-radius-md, 8px) - 2px);
178
+ transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.12s var(--el-ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
179
+ font-family: inherit;
180
+ }
181
+
182
+ .segment-btn:active:not([disabled]) {
183
+ transform: scale(0.97);
184
+ }
185
+
186
+ @media (prefers-reduced-motion: reduce) {
187
+ .segment-btn {
188
+ transition: none;
189
+ }
190
+ .segment-btn:active:not([disabled]) {
191
+ transform: none;
192
+ }
193
+ }
194
+
195
+ /* Sizes */
196
+ :host([size='sm']) .segment-btn,
197
+ .segment-btn.size-sm {
198
+ padding: 4px 10px;
199
+ font-size: 0.75rem;
200
+ min-height: 26px;
201
+ }
202
+
203
+ :host([size='md']) .segment-btn,
204
+ .segment-btn,
205
+ .segment-btn.size-md {
206
+ padding: 6px 14px;
207
+ font-size: 0.875rem;
208
+ min-height: 32px;
209
+ }
210
+
211
+ :host([size='lg']) .segment-btn,
212
+ .segment-btn.size-lg {
213
+ padding: 8px 18px;
214
+ font-size: 1rem;
215
+ min-height: 40px;
216
+ }
217
+
218
+ .segment-btn:hover:not([disabled]):not(.active) {
219
+ color: var(--el-text-primary, #0f172a);
220
+ }
221
+
222
+ .segment-btn.active {
223
+ background: var(--el-surface-card, #ffffff);
224
+ color: var(--el-color-primary, #2563eb);
225
+ font-weight: 600;
226
+ box-shadow: var(--el-shadow-sm, 0 1px 2px 0 rgb(0 0 0 / 0.05));
227
+ }
228
+
229
+ .segment-btn:focus-visible {
230
+ outline: 2px solid var(--el-color-primary, #2563eb);
231
+ outline-offset: -1px;
232
+ }
233
+
234
+ .segment-btn[disabled] {
235
+ opacity: 0.5;
236
+ cursor: not-allowed;
237
+ }
238
+
239
+ .sr-only-slot {
240
+ display: none;
241
+ }
242
+ `;
243
+
244
+ render() {
245
+ return html`
246
+ <div class="sr-only-slot">
247
+ <slot></slot>
248
+ </div>
249
+
250
+ <div
251
+ class="segmented-group"
252
+ part="group"
253
+ role="radiogroup"
254
+ aria-label=${() => this.getAttribute('aria-label') || 'Options'}
255
+ >
256
+ ${() =>
257
+ this.#options.value.map((opt) => {
258
+ const isChecked = this.value.value === opt.value;
259
+ return html`
260
+ <button
261
+ type="button"
262
+ role="radio"
263
+ part="segment"
264
+ class=${() =>
265
+ `segment-btn size-${this.size.value} ${isChecked ? 'active' : ''}`}
266
+ aria-checked=${String(isChecked)}
267
+ tabindex=${isChecked ? '0' : '-1'}
268
+ disabled=${opt.disabled || this.disabled.value}
269
+ @click=${() => this.selectOption(opt.value)}
270
+ >
271
+ ${opt.label}
272
+ </button>
273
+ `;
274
+ })}
275
+ </div>
276
+ `;
277
+ }
278
+ }
279
+
280
+ if (typeof customElements !== 'undefined' && !customElements.get('el-segmented-control')) {
281
+ customElements.define('el-segmented-control', ElSegmentedControl);
282
+ }
@@ -0,0 +1,220 @@
1
+ /**
2
+ * <el-select>
3
+ * Form-associated select component with custom styling and design tokens.
4
+ */
5
+
6
+ import { Elementum } from '../elementum.js';
7
+ import { html, css } from '../template.js';
8
+ import { signal } from '../signal.js';
9
+
10
+ export class ElSelect extends Elementum {
11
+ static formAssociated = true;
12
+ static observedAttributes = ['value', 'placeholder', 'disabled', 'name', 'required', 'options'];
13
+
14
+ value = signal('');
15
+ placeholder = signal('');
16
+ disabled = signal(false);
17
+ name = signal('');
18
+ required = signal(false);
19
+ options = signal([]); // [{ label, value }]
20
+
21
+ static styles = css`
22
+ :host {
23
+ display: inline-block;
24
+ width: 100%;
25
+ font-family: inherit;
26
+ }
27
+
28
+ .wrapper {
29
+ position: relative;
30
+ display: flex;
31
+ align-items: center;
32
+ background: var(--el-surface-base, #ffffff);
33
+ border: 1px solid var(--el-surface-border, #e5e7eb);
34
+ border-radius: var(--el-radius-md, 8px);
35
+ transition: border-color 0.15s ease, box-shadow 0.15s ease;
36
+ height: 40px;
37
+ box-sizing: border-box;
38
+ }
39
+
40
+ .wrapper:focus-within {
41
+ border-color: var(--el-color-primary, #2563eb);
42
+ box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
43
+ }
44
+
45
+ select {
46
+ flex: 1;
47
+ width: 100%;
48
+ height: 100%;
49
+ border: none;
50
+ outline: none;
51
+ background: transparent;
52
+ padding: 0 var(--el-spacing-md, 16px);
53
+ padding-right: 32px;
54
+ font-family: inherit;
55
+ font-size: 0.9375rem;
56
+ color: var(--el-text-base, #111827);
57
+ cursor: pointer;
58
+ appearance: none;
59
+ }
60
+
61
+ select:disabled {
62
+ cursor: not-allowed;
63
+ opacity: 0.6;
64
+ }
65
+
66
+ @media (hover: none) and (pointer: coarse), (max-width: 640px) {
67
+ select {
68
+ font-size: 16px !important;
69
+ }
70
+ }
71
+
72
+ .arrow {
73
+ position: absolute;
74
+ right: 12px;
75
+ pointer-events: none;
76
+ font-size: 0.75rem;
77
+ color: var(--el-text-muted, #6b7280);
78
+ }
79
+
80
+ @media (pointer: coarse) {
81
+ select {
82
+ font-size: max(16px, 1em);
83
+ }
84
+ }
85
+ `;
86
+
87
+ connected() {
88
+ this.required.value = this.hasAttribute('required');
89
+ this.#scanOptions();
90
+ if (!this.value.value && !this.hasAttribute('placeholder') && this.options.value.length > 0) {
91
+ this.value.value = this.options.value[0].value;
92
+ }
93
+ this.setFormValue(this.value.value);
94
+ this.validate();
95
+
96
+ const observer = new MutationObserver(() => {
97
+ this.#scanOptions();
98
+ if (!this.value.value && !this.hasAttribute('placeholder') && this.options.value.length > 0) {
99
+ this.value.value = this.options.value[0].value;
100
+ this.setFormValue(this.value.value);
101
+ }
102
+ this.validate();
103
+ });
104
+ observer.observe(this, { childList: true, subtree: true });
105
+ this.signal.addEventListener('abort', () => observer.disconnect());
106
+ }
107
+
108
+ formReset() {
109
+ const initial = this.getAttribute('value') || '';
110
+ this.value.value = initial;
111
+ this.setFormValue(initial);
112
+ this.validate();
113
+ }
114
+
115
+ attributeChanged(name, oldValue, newValue) {
116
+ if (name === 'value') {
117
+ this.setFormValue(newValue);
118
+ this.validate();
119
+ } else if (name === 'required') {
120
+ this.required.value = newValue !== null && newValue !== 'false';
121
+ this.validate();
122
+ } else if (name === 'options') {
123
+ this.#scanOptions();
124
+ if (!this.value.value && !this.hasAttribute('placeholder') && this.options.value.length > 0) {
125
+ this.value.value = this.options.value[0].value;
126
+ this.setFormValue(this.value.value);
127
+ }
128
+ this.validate();
129
+ }
130
+ }
131
+
132
+ validate() {
133
+ const val = String(this.value.value || '');
134
+ const selectEl = this.root?.querySelector?.('select');
135
+
136
+ if (this.required.value && !val.trim()) {
137
+ this.setValidity({ valueMissing: true }, 'Please select an item in the list.', selectEl);
138
+ this.setAttribute('aria-invalid', 'true');
139
+ return false;
140
+ }
141
+
142
+ this.setValidity({});
143
+ this.removeAttribute('aria-invalid');
144
+ return true;
145
+ }
146
+
147
+ #scanOptions() {
148
+ const rawOptions = Array.from(this.querySelectorAll('option')).map((opt) => ({
149
+ label: opt.textContent.trim(),
150
+ value: opt.value || opt.textContent.trim(),
151
+ }));
152
+
153
+ if (rawOptions.length > 0) {
154
+ this.options.value = rawOptions;
155
+ return;
156
+ }
157
+
158
+ const optAttr = this.getAttribute('options');
159
+ if (optAttr) {
160
+ try {
161
+ const parsed = JSON.parse(optAttr);
162
+ if (Array.isArray(parsed)) {
163
+ this.options.value = parsed.map(o => typeof o === 'string' ? { label: o, value: o } : { label: o.label || o.value, value: o.value || o.label });
164
+ return;
165
+ }
166
+ } catch (e) {
167
+ this.options.value = optAttr.split(',').map(s => s.trim()).filter(Boolean).map(s => ({ label: s, value: s }));
168
+ return;
169
+ }
170
+ }
171
+
172
+ this.options.value = [];
173
+ }
174
+
175
+ #onChange = (e) => {
176
+ const val = e.target.value;
177
+ this.value.value = val;
178
+ this.setFormValue(val);
179
+ this.validate();
180
+ this.emit('change', { value: val });
181
+ };
182
+
183
+ render() {
184
+ return html`
185
+ <div class="wrapper" part="wrapper">
186
+ <select
187
+ part="select"
188
+ aria-label=${() => this.getAttribute('aria-label') || this.placeholder.value || this.getAttribute('name') || 'Select option'}
189
+ ?disabled=${this.disabled}
190
+ @change=${this.#onChange}
191
+ >
192
+ ${() =>
193
+ this.placeholder.value
194
+ ? html`
195
+ <option value="" disabled ?selected=${() => !this.value.value}>
196
+ ${this.placeholder}
197
+ </option>
198
+ `
199
+ : ''}
200
+ ${() =>
201
+ this.options.value.map(
202
+ (opt) => html`
203
+ <option
204
+ value=${opt.value}
205
+ ?selected=${() => this.value.value === opt.value}
206
+ >
207
+ ${opt.label}
208
+ </option>
209
+ `
210
+ )}
211
+ </select>
212
+ <span class="arrow">▼</span>
213
+ </div>
214
+ `;
215
+ }
216
+ }
217
+
218
+ if (typeof customElements !== 'undefined' && !customElements.get('el-select')) {
219
+ customElements.define('el-select', ElSelect);
220
+ }