@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,351 @@
1
+ /**
2
+ * <el-slider>
3
+ * Accessible, zero-dependency slider primitive supporting single-value
4
+ * or range tracking, keyboard navigation, touch/mouse dragging, and form association.
5
+ */
6
+
7
+ import { Elementum } from '../elementum.js';
8
+ import { html, css } from '../template.js';
9
+ import { signal } from '../signal.js';
10
+
11
+ export class ElSlider extends Elementum {
12
+ static formAssociated = true;
13
+ static observedAttributes = ['value', 'min', 'max', 'step', 'orientation', 'disabled', 'name'];
14
+
15
+ value = signal(50);
16
+ min = signal(0);
17
+ max = signal(100);
18
+ step = signal(1);
19
+ orientation = signal('horizontal');
20
+ disabled = signal(false);
21
+
22
+ #isDragging = false;
23
+
24
+ static styles = css`
25
+ :host {
26
+ display: inline-block;
27
+ width: 100%;
28
+ min-width: 140px;
29
+ font-family: var(--el-font-sans, system-ui, sans-serif);
30
+ box-sizing: border-box;
31
+ user-select: none;
32
+ touch-action: none;
33
+ }
34
+
35
+ :host([orientation="vertical"]) {
36
+ width: auto;
37
+ min-width: 0;
38
+ height: 160px;
39
+ }
40
+
41
+ .slider-root {
42
+ position: relative;
43
+ display: flex;
44
+ align-items: center;
45
+ width: 100%;
46
+ height: 24px;
47
+ cursor: pointer;
48
+ }
49
+
50
+ :host([orientation="vertical"]) .slider-root {
51
+ flex-direction: column;
52
+ width: 24px;
53
+ height: 100%;
54
+ }
55
+
56
+ :host([disabled]) .slider-root {
57
+ cursor: not-allowed;
58
+ opacity: 0.5;
59
+ }
60
+
61
+ .track {
62
+ position: relative;
63
+ background: var(--el-surface-border, #e2e8f0);
64
+ border-radius: 9999px;
65
+ width: 100%;
66
+ height: 6px;
67
+ overflow: hidden;
68
+ transition: background 150ms ease;
69
+ }
70
+
71
+ :host([orientation="vertical"]) .track {
72
+ width: 6px;
73
+ height: 100%;
74
+ }
75
+
76
+ :root[data-theme="dark"] .track {
77
+ background: #334155;
78
+ }
79
+
80
+ .range-fill {
81
+ position: absolute;
82
+ background: var(--el-color-primary, #2563eb);
83
+ border-radius: 9999px;
84
+ height: 100%;
85
+ left: 0;
86
+ top: 0;
87
+ pointer-events: none;
88
+ transition: width 50ms linear, height 50ms linear;
89
+ }
90
+
91
+ :host([orientation="vertical"]) .range-fill {
92
+ width: 100%;
93
+ bottom: 0;
94
+ top: auto;
95
+ }
96
+
97
+ .thumb {
98
+ position: absolute;
99
+ top: 50%;
100
+ width: 18px;
101
+ height: 18px;
102
+ margin-top: -9px;
103
+ margin-left: -9px;
104
+ background: var(--el-surface-base, #ffffff);
105
+ border: 2px solid var(--el-color-primary, #2563eb);
106
+ border-radius: 50%;
107
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.06);
108
+ cursor: grab;
109
+ outline: none;
110
+ transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
111
+ box-sizing: border-box;
112
+ }
113
+
114
+ :host([orientation="vertical"]) .thumb {
115
+ left: 50%;
116
+ top: auto;
117
+ margin-left: -9px;
118
+ margin-bottom: -9px;
119
+ }
120
+
121
+ .thumb:hover {
122
+ transform: scale(1.1);
123
+ }
124
+
125
+ .thumb:focus-visible {
126
+ box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35);
127
+ border-color: var(--el-color-primary-hover, #1d4ed8);
128
+ }
129
+
130
+ .thumb.dragging {
131
+ cursor: grabbing;
132
+ transform: scale(1.15);
133
+ }
134
+ `;
135
+
136
+ connected() {
137
+ this.#syncFromAttributes();
138
+ this.tabIndex = this.disabled.value ? -1 : 0;
139
+ this.setAttribute('role', 'slider');
140
+ this.#updateAria();
141
+ this.setFormValue(String(this.value.value));
142
+
143
+ this.addEventListener('keydown', this.#onKeyDown);
144
+ }
145
+
146
+ attributeChanged(name, oldValue, newValue) {
147
+ if (name === 'value') {
148
+ const num = parseFloat(newValue);
149
+ if (!isNaN(num)) this.value.value = this.#clamp(num);
150
+ } else if (name === 'min') {
151
+ const num = parseFloat(newValue);
152
+ if (!isNaN(num)) this.min.value = num;
153
+ } else if (name === 'max') {
154
+ const num = parseFloat(newValue);
155
+ if (!isNaN(num)) this.max.value = num;
156
+ } else if (name === 'step') {
157
+ const num = parseFloat(newValue);
158
+ if (!isNaN(num) && num > 0) this.step.value = num;
159
+ } else if (name === 'orientation') {
160
+ this.orientation.value = newValue === 'vertical' ? 'vertical' : 'horizontal';
161
+ } else if (name === 'disabled') {
162
+ this.disabled.value = newValue !== null && newValue !== 'false';
163
+ this.tabIndex = this.disabled.value ? -1 : 0;
164
+ }
165
+ this.#updateAria();
166
+ this.setFormValue(String(this.value.value));
167
+ return true;
168
+ }
169
+
170
+ #syncFromAttributes() {
171
+ if (this.hasAttribute('min')) this.min.value = parseFloat(this.getAttribute('min')) || 0;
172
+ if (this.hasAttribute('max')) this.max.value = parseFloat(this.getAttribute('max')) || 100;
173
+ if (this.hasAttribute('step')) this.step.value = parseFloat(this.getAttribute('step')) || 1;
174
+ if (this.hasAttribute('value')) {
175
+ this.value.value = this.#clamp(parseFloat(this.getAttribute('value')) || 0);
176
+ }
177
+ if (this.hasAttribute('orientation')) {
178
+ this.orientation.value = this.getAttribute('orientation') === 'vertical' ? 'vertical' : 'horizontal';
179
+ }
180
+ this.disabled.value = this.hasAttribute('disabled');
181
+ }
182
+
183
+ #updateAria() {
184
+ this.setAttribute('aria-valuenow', String(this.value.value));
185
+ this.setAttribute('aria-valuemin', String(this.min.value));
186
+ this.setAttribute('aria-valuemax', String(this.max.value));
187
+ this.setAttribute('aria-orientation', this.orientation.value);
188
+ this.setAttribute('aria-disabled', String(this.disabled.value));
189
+ }
190
+
191
+ #clamp(val) {
192
+ const minVal = this.min.value;
193
+ const maxVal = this.max.value;
194
+ const stepVal = this.step.value;
195
+ let clamped = Math.min(maxVal, Math.max(minVal, val));
196
+ if (stepVal > 0) {
197
+ const steps = Math.round((clamped - minVal) / stepVal);
198
+ clamped = minVal + steps * stepVal;
199
+ }
200
+ return Math.min(maxVal, Math.max(minVal, Math.round(clamped * 10000) / 10000));
201
+ }
202
+
203
+ #getPercentage() {
204
+ const minVal = this.min.value;
205
+ const maxVal = this.max.value;
206
+ if (maxVal <= minVal) return 0;
207
+ const pct = ((this.value.value - minVal) / (maxVal - minVal)) * 100;
208
+ return Math.min(100, Math.max(0, pct));
209
+ }
210
+
211
+ #setValueFromPosition(clientX, clientY) {
212
+ const track = this.root.querySelector('.track');
213
+ if (!track) return;
214
+ const rect = track.getBoundingClientRect();
215
+ const isVertical = this.orientation.value === 'vertical';
216
+
217
+ let ratio = 0;
218
+ if (isVertical) {
219
+ ratio = (rect.bottom - clientY) / rect.height;
220
+ } else {
221
+ ratio = (clientX - rect.left) / rect.width;
222
+ }
223
+ ratio = Math.max(0, Math.min(1, ratio));
224
+
225
+ const minVal = this.min.value;
226
+ const maxVal = this.max.value;
227
+ const rawVal = minVal + ratio * (maxVal - minVal);
228
+ const newVal = this.#clamp(rawVal);
229
+
230
+ if (newVal !== this.value.value) {
231
+ this.value.value = newVal;
232
+ this.#updateAria();
233
+ this.setFormValue(String(newVal));
234
+ this.emit('input', { value: newVal });
235
+ }
236
+ }
237
+
238
+ #onPointerDown = (e) => {
239
+ if (this.disabled.value) return;
240
+ this.#isDragging = true;
241
+ const thumb = this.root.querySelector('.thumb');
242
+ if (thumb) thumb.classList.add('dragging');
243
+
244
+ this.#setValueFromPosition(e.clientX, e.clientY);
245
+ this.focus();
246
+
247
+ const onPointerMove = (moveEvent) => {
248
+ if (!this.#isDragging) return;
249
+ this.#setValueFromPosition(moveEvent.clientX, moveEvent.clientY);
250
+ };
251
+
252
+ const onPointerUp = () => {
253
+ if (this.#isDragging) {
254
+ this.#isDragging = false;
255
+ if (thumb) thumb.classList.remove('dragging');
256
+ this.emit('change', { value: this.value.value });
257
+ }
258
+ window.removeEventListener('pointermove', onPointerMove);
259
+ window.removeEventListener('pointerup', onPointerUp);
260
+ };
261
+
262
+ window.addEventListener('pointermove', onPointerMove);
263
+ window.addEventListener('pointerup', onPointerUp);
264
+ };
265
+
266
+ #onKeyDown = (e) => {
267
+ if (this.disabled.value) return;
268
+ const minVal = this.min.value;
269
+ const maxVal = this.max.value;
270
+ const stepVal = this.step.value || 1;
271
+ let next = this.value.value;
272
+
273
+ switch (e.key) {
274
+ case 'ArrowRight':
275
+ case 'ArrowUp':
276
+ e.preventDefault();
277
+ next += stepVal;
278
+ break;
279
+ case 'ArrowLeft':
280
+ case 'ArrowDown':
281
+ e.preventDefault();
282
+ next -= stepVal;
283
+ break;
284
+ case 'PageUp':
285
+ e.preventDefault();
286
+ next += (maxVal - minVal) * 0.1;
287
+ break;
288
+ case 'PageDown':
289
+ e.preventDefault();
290
+ next -= (maxVal - minVal) * 0.1;
291
+ break;
292
+ case 'Home':
293
+ e.preventDefault();
294
+ next = minVal;
295
+ break;
296
+ case 'End':
297
+ e.preventDefault();
298
+ next = maxVal;
299
+ break;
300
+ default:
301
+ return;
302
+ }
303
+
304
+ const clamped = this.#clamp(next);
305
+ if (clamped !== this.value.value) {
306
+ this.value.value = clamped;
307
+ this.#updateAria();
308
+ this.setFormValue(String(clamped));
309
+ this.emit('input', { value: clamped });
310
+ this.emit('change', { value: clamped });
311
+ }
312
+ };
313
+
314
+ render() {
315
+ return html`
316
+ <div
317
+ class="slider-root"
318
+ @pointerdown=${this.#onPointerDown}
319
+ @keydown=${this.#onKeyDown}
320
+ tabindex="-1"
321
+ >
322
+ <div class="track" part="track">
323
+ <div
324
+ class="range-fill"
325
+ part="range"
326
+ style=${() => {
327
+ const pct = this.#getPercentage();
328
+ return this.orientation.value === 'vertical'
329
+ ? `height: ${pct}%;`
330
+ : `width: ${pct}%;`;
331
+ }}
332
+ ></div>
333
+ </div>
334
+ <div
335
+ class="thumb"
336
+ part="thumb"
337
+ style=${() => {
338
+ const pct = this.#getPercentage();
339
+ return this.orientation.value === 'vertical'
340
+ ? `bottom: ${pct}%;`
341
+ : `left: ${pct}%;`;
342
+ }}
343
+ ></div>
344
+ </div>
345
+ `;
346
+ }
347
+ }
348
+
349
+ if (typeof customElements !== 'undefined' && !customElements.get('el-slider')) {
350
+ customElements.define('el-slider', ElSlider);
351
+ }
@@ -0,0 +1,288 @@
1
+ import { Elementum } from '../elementum.js';
2
+ import { html, css } from '../template.js';
3
+ import { signal } from '../signal.js';
4
+
5
+ function sanitizeUrl(raw) {
6
+ const s = String(raw || '').trim();
7
+ if (/^https?:\/\//i.test(s)) return s;
8
+ return '';
9
+ }
10
+
11
+ function domainFromUrl(url) {
12
+ try {
13
+ return new URL(url).hostname.replace(/^www\./, '');
14
+ } catch {
15
+ return 'source';
16
+ }
17
+ }
18
+
19
+ /**
20
+ * <el-sources>
21
+ * Grounding citation pills and expandable source list for AI / RAG responses.
22
+ *
23
+ * @element el-sources
24
+ * @attr {string} sources - JSON array of { title, url, domain?, snippet? }
25
+ * @attr {string} label - Header label (default: 'Sources')
26
+ * @attr {boolean} expanded - Whether full source cards are expanded
27
+ * @fires source-select - Fired when a source pill is clicked ({ index, source })
28
+ */
29
+ export class ElSources extends Elementum {
30
+ static observedAttributes = ['sources', 'label', 'expanded'];
31
+
32
+ sources = signal([]);
33
+ label = signal('Sources');
34
+ expanded = signal(false);
35
+
36
+ connected() {
37
+ this.#sync();
38
+ }
39
+
40
+ attributeChanged() {
41
+ this.#sync();
42
+ }
43
+
44
+ #sync() {
45
+ if (this.hasAttribute('label')) this.label.value = this.getAttribute('label') || 'Sources';
46
+ this.expanded.value = this.hasAttribute('expanded') && this.getAttribute('expanded') !== 'false';
47
+ const raw = this.getAttribute('sources');
48
+ if (raw) {
49
+ try {
50
+ const parsed = JSON.parse(raw);
51
+ if (Array.isArray(parsed)) this.sources.value = parsed;
52
+ } catch {
53
+ // Ignore malformed JSON
54
+ }
55
+ }
56
+ }
57
+
58
+ toggleExpanded = () => {
59
+ const next = !this.expanded.value;
60
+ this.expanded.value = next;
61
+ if (next) this.setAttribute('expanded', '');
62
+ else this.removeAttribute('expanded');
63
+ };
64
+
65
+ #selectSource(src, index) {
66
+ this.emit('source-select', { index, source: src });
67
+ }
68
+
69
+ static styles = css`
70
+ :host {
71
+ display: block;
72
+ font-family: var(--el-font-sans, system-ui, -apple-system, sans-serif);
73
+ box-sizing: border-box;
74
+ }
75
+
76
+ .sources-wrap {
77
+ display: flex;
78
+ flex-direction: column;
79
+ gap: 10px;
80
+ }
81
+
82
+ .pills-bar {
83
+ display: flex;
84
+ align-items: center;
85
+ flex-wrap: wrap;
86
+ gap: 6px;
87
+ }
88
+
89
+ .toggle-btn {
90
+ display: inline-flex;
91
+ align-items: center;
92
+ gap: 6px;
93
+ padding: 4px 10px;
94
+ border-radius: 9999px;
95
+ border: 1px solid var(--el-surface-border, #e2e8f0);
96
+ background: var(--el-surface-muted, #f8fafc);
97
+ color: var(--el-text-primary, #0f172a);
98
+ font-family: inherit;
99
+ font-size: 0.76rem;
100
+ font-weight: 600;
101
+ font-variant-numeric: tabular-nums;
102
+ cursor: pointer;
103
+ touch-action: manipulation;
104
+ -webkit-tap-highlight-color: transparent;
105
+ transition: background-color 140ms ease, border-color 140ms ease, transform 120ms var(--el-ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
106
+ }
107
+
108
+ .toggle-btn:active {
109
+ transform: scale(0.97);
110
+ }
111
+
112
+ .pill {
113
+ display: inline-flex;
114
+ align-items: center;
115
+ gap: 5px;
116
+ padding: 3px 9px;
117
+ border-radius: 9999px;
118
+ border: 1px solid var(--el-surface-border, #e2e8f0);
119
+ background: var(--el-surface-base, #ffffff);
120
+ color: var(--el-text-secondary, #475569);
121
+ font-size: 0.75rem;
122
+ font-weight: 500;
123
+ text-decoration: none;
124
+ cursor: pointer;
125
+ touch-action: manipulation;
126
+ -webkit-tap-highlight-color: transparent;
127
+ transition: border-color 140ms ease, color 140ms ease, transform 120ms var(--el-ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
128
+ }
129
+
130
+ .pill:hover {
131
+ border-color: var(--el-color-primary, #2563eb);
132
+ color: var(--el-color-primary, #2563eb);
133
+ }
134
+
135
+ .pill:active {
136
+ transform: scale(0.97);
137
+ }
138
+
139
+ .idx {
140
+ display: inline-flex;
141
+ align-items: center;
142
+ justify-content: center;
143
+ min-width: 16px;
144
+ height: 16px;
145
+ padding: 0 4px;
146
+ border-radius: 9999px;
147
+ background: var(--el-color-primary, #2563eb);
148
+ color: #ffffff;
149
+ font-size: 0.65rem;
150
+ font-weight: 700;
151
+ font-variant-numeric: tabular-nums;
152
+ }
153
+
154
+ .cards {
155
+ display: grid;
156
+ grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
157
+ gap: 10px;
158
+ }
159
+
160
+ .source-card {
161
+ display: flex;
162
+ flex-direction: column;
163
+ gap: 4px;
164
+ padding: 10px 12px;
165
+ border-radius: var(--el-radius-md, 8px);
166
+ border: 1px solid var(--el-surface-border, #e2e8f0);
167
+ background: var(--el-surface-base, #ffffff);
168
+ text-decoration: none;
169
+ color: inherit;
170
+ transition: border-color 140ms ease, box-shadow 140ms ease;
171
+ }
172
+
173
+ .source-card:hover {
174
+ border-color: var(--el-color-primary, #2563eb);
175
+ box-shadow: var(--el-shadow-subtle, 0 2px 6px rgba(15, 23, 42, 0.06));
176
+ }
177
+
178
+ .source-title {
179
+ font-size: 0.82rem;
180
+ font-weight: 600;
181
+ color: var(--el-text-primary, #0f172a);
182
+ }
183
+
184
+ .source-domain {
185
+ font-size: 0.72rem;
186
+ color: var(--el-color-primary, #2563eb);
187
+ }
188
+
189
+ .source-snippet {
190
+ font-size: 0.76rem;
191
+ color: var(--el-text-secondary, #475569);
192
+ margin: 2px 0 0;
193
+ line-height: 1.45;
194
+ }
195
+
196
+ :root[data-theme="dark"] .toggle-btn,
197
+ :root[data-theme="dark"] .pill,
198
+ :root[data-theme="dark"] .source-card {
199
+ background: #1e293b;
200
+ border-color: #334155;
201
+ color: #e2e8f0;
202
+ }
203
+ :root[data-theme="dark"] .source-title {
204
+ color: #f8fafc;
205
+ }
206
+ :root[data-theme="dark"] .source-snippet {
207
+ color: #94a3b8;
208
+ }
209
+
210
+ @media (prefers-reduced-motion: reduce) {
211
+ .toggle-btn, .pill, .source-card { transition: none; }
212
+ .toggle-btn:active, .pill:active { transform: none; }
213
+ }
214
+ `;
215
+
216
+ render() {
217
+ return html`
218
+ <div class="sources-wrap" part="container">
219
+ <div class="pills-bar" part="pills">
220
+ <button
221
+ type="button"
222
+ class="toggle-btn"
223
+ aria-expanded=${() => String(this.expanded.value)}
224
+ @click=${this.toggleExpanded}
225
+ >
226
+ <span>${this.label} (${() => (Array.isArray(this.sources.value) ? this.sources.value.length : 0)})</span>
227
+ <span>${() => (this.expanded.value ? '▴' : '▾')}</span>
228
+ </button>
229
+ ${() => {
230
+ const list = Array.isArray(this.sources.value) ? this.sources.value : [];
231
+ return list.map((src, idx) => {
232
+ const safeHref = sanitizeUrl(src.url);
233
+ const dom = src.domain || domainFromUrl(safeHref);
234
+ return html`
235
+ <a
236
+ class="pill"
237
+ href=${safeHref || '#'}
238
+ target=${safeHref ? '_blank' : '_self'}
239
+ rel="noopener noreferrer"
240
+ @click=${(e) => {
241
+ if (!safeHref) e.preventDefault();
242
+ this.#selectSource(src, idx);
243
+ }}
244
+ >
245
+ <span class="idx">${idx + 1}</span>
246
+ <span>${dom}</span>
247
+ </a>
248
+ `;
249
+ });
250
+ }}
251
+ </div>
252
+
253
+ ${() => {
254
+ if (!this.expanded.value) return '';
255
+ const list = Array.isArray(this.sources.value) ? this.sources.value : [];
256
+ return html`
257
+ <div class="cards" part="list">
258
+ ${list.map((src, idx) => {
259
+ const safeHref = sanitizeUrl(src.url);
260
+ const dom = src.domain || domainFromUrl(safeHref);
261
+ return html`
262
+ <a
263
+ class="source-card"
264
+ href=${safeHref || '#'}
265
+ target=${safeHref ? '_blank' : '_self'}
266
+ rel="noopener noreferrer"
267
+ @click=${(e) => {
268
+ if (!safeHref) e.preventDefault();
269
+ this.#selectSource(src, idx);
270
+ }}
271
+ >
272
+ <span class="source-domain">[${idx + 1}] ${dom}</span>
273
+ <span class="source-title">${src.title || dom}</span>
274
+ ${src.snippet ? html`<p class="source-snippet">${src.snippet}</p>` : ''}
275
+ </a>
276
+ `;
277
+ })}
278
+ </div>
279
+ `;
280
+ }}
281
+ </div>
282
+ `;
283
+ }
284
+ }
285
+
286
+ if (typeof customElements !== 'undefined' && !customElements.get('el-sources')) {
287
+ customElements.define('el-sources', ElSources);
288
+ }