@wcomp/elementum 0.0.0-stage → 0.1.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 (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +266 -2
  3. package/custom-elements.json +3613 -0
  4. package/mcp/server.js +408 -0
  5. package/package.json +72 -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/components/el-accordion.js +201 -0
  16. package/src/components/el-alert-dialog.js +186 -0
  17. package/src/components/el-alert.js +254 -0
  18. package/src/components/el-aspect-ratio.js +73 -0
  19. package/src/components/el-autocomplete.js +775 -0
  20. package/src/components/el-avatar.js +271 -0
  21. package/src/components/el-badge.js +131 -0
  22. package/src/components/el-border-beam.js +135 -0
  23. package/src/components/el-breadcrumb.js +203 -0
  24. package/src/components/el-button.js +220 -0
  25. package/src/components/el-calendar.js +413 -0
  26. package/src/components/el-callout.js +158 -0
  27. package/src/components/el-card.js +298 -0
  28. package/src/components/el-carousel.js +308 -0
  29. package/src/components/el-chart.js +632 -0
  30. package/src/components/el-checkbox-card.js +221 -0
  31. package/src/components/el-checkbox.js +208 -0
  32. package/src/components/el-chip.js +276 -0
  33. package/src/components/el-code-block.js +228 -0
  34. package/src/components/el-collapsible.js +124 -0
  35. package/src/components/el-command.js +556 -0
  36. package/src/components/el-context-menu.js +328 -0
  37. package/src/components/el-data-list.js +210 -0
  38. package/src/components/el-datepicker.js +192 -0
  39. package/src/components/el-dialog.js +272 -0
  40. package/src/components/el-diff-viewer.js +441 -0
  41. package/src/components/el-drawer.js +782 -0
  42. package/src/components/el-dropdown.js +182 -0
  43. package/src/components/el-dropzone.js +242 -0
  44. package/src/components/el-empty-state.js +130 -0
  45. package/src/components/el-field.js +394 -0
  46. package/src/components/el-form.js +185 -0
  47. package/src/components/el-input.js +212 -0
  48. package/src/components/el-inset.js +90 -0
  49. package/src/components/el-insight-card.js +263 -0
  50. package/src/components/el-kbd.js +151 -0
  51. package/src/components/el-menubar.js +254 -0
  52. package/src/components/el-meter.js +182 -0
  53. package/src/components/el-navbar.js +294 -0
  54. package/src/components/el-navigation-menu.js +327 -0
  55. package/src/components/el-number-field.js +510 -0
  56. package/src/components/el-number-flow.js +153 -0
  57. package/src/components/el-otp-input.js +266 -0
  58. package/src/components/el-pagination.js +229 -0
  59. package/src/components/el-popover.js +288 -0
  60. package/src/components/el-preview-card.js +202 -0
  61. package/src/components/el-progress.js +179 -0
  62. package/src/components/el-prompt-input.js +383 -0
  63. package/src/components/el-radio-card.js +360 -0
  64. package/src/components/el-radio.js +257 -0
  65. package/src/components/el-rating.js +165 -0
  66. package/src/components/el-reasoning-card.js +293 -0
  67. package/src/components/el-resizable.js +324 -0
  68. package/src/components/el-router.js +305 -0
  69. package/src/components/el-scroll-area.js +150 -0
  70. package/src/components/el-segmented-control.js +282 -0
  71. package/src/components/el-select.js +219 -0
  72. package/src/components/el-separator.js +85 -0
  73. package/src/components/el-sidebar.js +386 -0
  74. package/src/components/el-skeleton.js +156 -0
  75. package/src/components/el-slider.js +351 -0
  76. package/src/components/el-sources.js +288 -0
  77. package/src/components/el-spinner.js +159 -0
  78. package/src/components/el-streaming-text.js +199 -0
  79. package/src/components/el-switch.js +221 -0
  80. package/src/components/el-table.js +397 -0
  81. package/src/components/el-tabs.js +235 -0
  82. package/src/components/el-task-list.js +230 -0
  83. package/src/components/el-textarea.js +175 -0
  84. package/src/components/el-theme-switch.js +120 -0
  85. package/src/components/el-timeline.js +254 -0
  86. package/src/components/el-toast.js +778 -0
  87. package/src/components/el-toggle.js +311 -0
  88. package/src/components/el-tool-call.js +386 -0
  89. package/src/components/el-toolbar.js +183 -0
  90. package/src/components/el-tooltip.js +172 -0
  91. package/src/components/el-tree-view.js +261 -0
  92. package/src/components/el-visually-hidden.js +32 -0
  93. package/src/elementum.js +485 -0
  94. package/src/index.d.ts +1007 -0
  95. package/src/index.js +99 -0
  96. package/src/signal.js +194 -0
  97. package/src/ssr.js +136 -0
  98. package/src/template.js +321 -0
  99. package/src/tokens.css +416 -0
  100. package/tokens/figma-tokens.json +69 -0
  101. package/tokens/penpot-tokens.json +98 -0
@@ -0,0 +1,632 @@
1
+ import { Elementum } from '../elementum.js';
2
+ import { html, css } from '../template.js';
3
+ import { signal } from '../signal.js';
4
+
5
+ /**
6
+ * <el-chart>
7
+ * Zero-dependency native SVG chart primitive.
8
+ * Supports area, line, and bar modes with reactive tooltips, keyboard navigation,
9
+ * and semantic CSS token theming (--el-chart-1 to --el-chart-5).
10
+ *
11
+ * @element el-chart
12
+ * @attr {'area' | 'line' | 'bar'} type - Chart type (default: 'area')
13
+ * @attr {string} x-key - Key for x-axis category/date (default: 'label')
14
+ * @attr {string} y-key - Key for primary y-axis metric (default: 'value')
15
+ * @attr {string} secondary-key - Optional key for secondary comparison series
16
+ * @attr {number} height - Height in pixels (default: 200)
17
+ * @attr {boolean} show-grid - Show subtle background gridlines
18
+ * @attr {boolean} show-dots - Show data point circles
19
+ */
20
+ export class ElChart extends Elementum {
21
+ static get observedAttributes() {
22
+ return ['type', 'x-key', 'y-key', 'secondary-key', 'height', 'show-grid', 'show-dots', 'data', 'curve'];
23
+ }
24
+
25
+ static styles = css`
26
+ :host {
27
+ display: block;
28
+ width: 100%;
29
+ position: relative;
30
+ font-family: var(--el-font-sans, system-ui, sans-serif);
31
+ color: var(--el-text-primary, #0f172a);
32
+ box-sizing: border-box;
33
+ user-select: none;
34
+ }
35
+
36
+ .chart-container {
37
+ position: relative;
38
+ width: 100%;
39
+ height: 100%;
40
+ display: flex;
41
+ flex-direction: column;
42
+ }
43
+
44
+ svg {
45
+ width: 100%;
46
+ height: 100%;
47
+ overflow: visible;
48
+ display: block;
49
+ }
50
+
51
+ .grid-line {
52
+ stroke: var(--el-surface-border, #e2e8f0);
53
+ stroke-width: 1;
54
+ stroke-dasharray: 3 3;
55
+ opacity: 0.7;
56
+ }
57
+
58
+ .axis-label {
59
+ font-size: 10px;
60
+ fill: var(--el-text-muted, #64748b);
61
+ text-anchor: middle;
62
+ font-variant-numeric: tabular-nums;
63
+ }
64
+
65
+ .axis-label.y-axis {
66
+ text-anchor: end;
67
+ dominant-baseline: central;
68
+ }
69
+
70
+ .series-primary-area {
71
+ fill: url(#area-grad-1);
72
+ opacity: 0.25;
73
+ transition: opacity 150ms ease;
74
+ }
75
+
76
+ .series-primary-stroke {
77
+ fill: none;
78
+ stroke: var(--el-chart-1, var(--el-color-primary, #2563eb));
79
+ stroke-width: 2.5;
80
+ stroke-linecap: round;
81
+ stroke-linejoin: round;
82
+ }
83
+
84
+ .series-secondary-stroke {
85
+ fill: none;
86
+ stroke: var(--el-chart-2, #10b981);
87
+ stroke-width: 2;
88
+ stroke-linecap: round;
89
+ stroke-linejoin: round;
90
+ stroke-dasharray: 4 4;
91
+ opacity: 0.85;
92
+ }
93
+
94
+ .bar-rect {
95
+ fill: var(--el-chart-1, var(--el-color-primary, #2563eb));
96
+ transition: opacity 150ms ease, fill 150ms ease;
97
+ rx: 3px;
98
+ }
99
+
100
+ .bar-rect.secondary {
101
+ fill: var(--el-chart-2, #10b981);
102
+ }
103
+
104
+ .bar-rect:hover, .bar-rect.active {
105
+ opacity: 0.85;
106
+ filter: brightness(1.1);
107
+ }
108
+
109
+ .point-dot {
110
+ fill: var(--el-surface-base, #ffffff);
111
+ stroke: var(--el-chart-1, var(--el-color-primary, #2563eb));
112
+ stroke-width: 2;
113
+ r: 3.5;
114
+ transition: r 150ms ease;
115
+ }
116
+
117
+ .point-dot.active {
118
+ r: 5.5;
119
+ stroke-width: 2.5;
120
+ }
121
+
122
+ .hit-column {
123
+ fill: transparent;
124
+ cursor: crosshair;
125
+ }
126
+
127
+ .cursor-line {
128
+ stroke: var(--el-surface-border, #94a3b8);
129
+ stroke-width: 1;
130
+ stroke-dasharray: 2 2;
131
+ pointer-events: none;
132
+ }
133
+
134
+ /* Floating Tooltip */
135
+ .chart-tooltip {
136
+ position: absolute;
137
+ pointer-events: none;
138
+ background: var(--el-tooltip-bg, #0f172a);
139
+ color: var(--el-tooltip-text, #f8fafc);
140
+ padding: 8px 12px;
141
+ border-radius: var(--el-radius-md, 8px);
142
+ font-size: 11px;
143
+ line-height: 1.4;
144
+ box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.25), 0 4px 6px -2px rgba(0, 0, 0, 0.15);
145
+ border: 1px solid var(--el-tooltip-border, #334155);
146
+ transform: translate(-50%, -100%);
147
+ margin-top: -10px;
148
+ white-space: nowrap;
149
+ z-index: 20;
150
+ transition: left 80ms ease, top 80ms ease, opacity 100ms ease;
151
+ }
152
+
153
+ .tooltip-header {
154
+ font-weight: 600;
155
+ color: #94a3b8;
156
+ margin-bottom: 4px;
157
+ font-size: 10px;
158
+ text-transform: uppercase;
159
+ letter-spacing: 0.05em;
160
+ }
161
+
162
+ .tooltip-row {
163
+ display: flex;
164
+ align-items: center;
165
+ gap: 6px;
166
+ color: #cbd5e1;
167
+ }
168
+
169
+ .tooltip-label {
170
+ color: #94a3b8;
171
+ font-size: 11px;
172
+ }
173
+
174
+ .tooltip-swatch {
175
+ width: 7px;
176
+ height: 7px;
177
+ border-radius: 50%;
178
+ background: var(--el-chart-1, #2563eb);
179
+ flex-shrink: 0;
180
+ }
181
+
182
+ .tooltip-swatch.secondary {
183
+ background: var(--el-chart-2, #10b981);
184
+ }
185
+
186
+ .tooltip-value {
187
+ font-weight: 700;
188
+ font-variant-numeric: tabular-nums;
189
+ color: #ffffff;
190
+ margin-left: auto;
191
+ }
192
+ `;
193
+
194
+ #activeIdx = signal(-1);
195
+ #dataItems = signal([]);
196
+ #resizeObserver = null;
197
+
198
+ constructor() {
199
+ super();
200
+ this._type = signal('area');
201
+ this._xKey = signal('label');
202
+ this._yKey = signal('value');
203
+ this._secondaryKey = signal('');
204
+ this._height = signal(200);
205
+ this._showGrid = signal(true);
206
+ this._showDots = signal(true);
207
+ this._curve = signal('smooth');
208
+ this._containerWidth = signal(800);
209
+ }
210
+
211
+ static DEFAULT_DATA = [
212
+ { label: 'Q1', value: 45, secondary: 25 },
213
+ { label: 'Q2', value: 85, secondary: 55 },
214
+ { label: 'Q3', value: 65, secondary: 40 },
215
+ { label: 'Q4', value: 110, secondary: 75 }
216
+ ];
217
+
218
+ connected() {
219
+ for (const attr of ElChart.observedAttributes) {
220
+ if (this.hasAttribute(attr)) {
221
+ this.attributeChangedCallback(attr, null, this.getAttribute(attr));
222
+ }
223
+ }
224
+ if (!this.hasAttribute('data') && this.#dataItems.value.length === 0) {
225
+ this.#dataItems.value = ElChart.DEFAULT_DATA;
226
+ }
227
+ if (typeof ResizeObserver !== 'undefined') {
228
+ this.#resizeObserver = new ResizeObserver((entries) => {
229
+ if (entries[0]?.contentRect?.width) {
230
+ const w = Math.round(entries[0].contentRect.width);
231
+ if (w > 50 && w !== this._containerWidth.value) {
232
+ this._containerWidth.value = w;
233
+ }
234
+ }
235
+ });
236
+ this.#resizeObserver.observe(this);
237
+ }
238
+ }
239
+
240
+ disconnected() {
241
+ this.#resizeObserver?.disconnect();
242
+ this.#resizeObserver = null;
243
+ }
244
+
245
+ get data() {
246
+ return this.#dataItems.value;
247
+ }
248
+
249
+ set data(val) {
250
+ if (Array.isArray(val)) {
251
+ this.#dataItems.value = val;
252
+ } else if (typeof val === 'string') {
253
+ try {
254
+ this.#dataItems.value = JSON.parse(val);
255
+ } catch {
256
+ this.#dataItems.value = [];
257
+ }
258
+ }
259
+ }
260
+
261
+ get type() { return this._type.value; }
262
+ set type(v) { this._type.value = v; }
263
+
264
+ get xKey() { return this._xKey.value; }
265
+ set xKey(v) { this._xKey.value = v; }
266
+
267
+ get yKey() { return this._yKey.value; }
268
+ set yKey(v) { this._yKey.value = v; }
269
+
270
+ get secondaryKey() { return this._secondaryKey.value; }
271
+ set secondaryKey(v) { this._secondaryKey.value = v; }
272
+
273
+ get height() { return this._height.value; }
274
+ set height(v) { this._height.value = Number(v) || 200; }
275
+
276
+ get curve() { return this._curve.value; }
277
+ set curve(v) { this._curve.value = v || 'smooth'; }
278
+
279
+ attributeChangedCallback(name, oldVal, newVal) {
280
+ if (oldVal === newVal) return;
281
+ if (name === 'type') this._type.value = newVal || 'area';
282
+ if (name === 'x-key') this._xKey.value = newVal || 'label';
283
+ if (name === 'y-key') this._yKey.value = newVal || 'value';
284
+ if (name === 'secondary-key') this._secondaryKey.value = newVal || '';
285
+ if (name === 'height') this._height.value = parseInt(newVal, 10) || 200;
286
+ if (name === 'show-grid') this._showGrid.value = newVal !== 'false';
287
+ if (name === 'show-dots') this._showDots.value = newVal !== 'false';
288
+ if (name === 'curve') this._curve.value = newVal || 'smooth';
289
+ if (name === 'data' && typeof newVal === 'string') {
290
+ try {
291
+ this.#dataItems.value = JSON.parse(newVal);
292
+ } catch {
293
+ this.#dataItems.value = [];
294
+ }
295
+ }
296
+ }
297
+
298
+ #onKeyDown = (e) => {
299
+ const items = this.#dataItems.value;
300
+ if (!items.length) return;
301
+
302
+ if (e.key === 'ArrowRight') {
303
+ e.preventDefault();
304
+ const next = this.#activeIdx.value < items.length - 1 ? this.#activeIdx.value + 1 : 0;
305
+ this.#activeIdx.value = next;
306
+ } else if (e.key === 'ArrowLeft') {
307
+ e.preventDefault();
308
+ const prev = this.#activeIdx.value > 0 ? this.#activeIdx.value - 1 : items.length - 1;
309
+ this.#activeIdx.value = prev;
310
+ } else if (e.key === 'Escape') {
311
+ this.#activeIdx.value = -1;
312
+ }
313
+ };
314
+
315
+ #onMouseLeave = () => {
316
+ this.#activeIdx.value = -1;
317
+ };
318
+
319
+ #onColumnHover = (idx) => {
320
+ this.#activeIdx.value = idx;
321
+ };
322
+
323
+ #getItemVal(item, key) {
324
+ if (!item) return 0;
325
+ if (key && item[key] !== undefined) return Number(item[key]);
326
+ if (item.value !== undefined) return Number(item.value);
327
+ if (item.y !== undefined) return Number(item.y);
328
+ return 0;
329
+ }
330
+
331
+ #getItemLabel(item, key) {
332
+ if (!item) return '';
333
+ if (key && item[key] !== undefined) return String(item[key]);
334
+ if (item.label !== undefined) return String(item.label);
335
+ if (item.x !== undefined) return String(item.x);
336
+ return '';
337
+ }
338
+
339
+ #buildSvgPath(points, isSmooth, bottomY) {
340
+ if (!points || points.length === 0) return { path: '', area: '' };
341
+ if (points.length === 1) {
342
+ const p = points[0];
343
+ const path = `M ${p.x} ${p.y} L ${p.x + 1} ${p.y}`;
344
+ const area = `${path} L ${p.x + 1} ${bottomY} L ${p.x} ${bottomY} Z`;
345
+ return { path, area };
346
+ }
347
+
348
+ if (!isSmooth || points.length === 2) {
349
+ const path = `M ${points[0].x} ${points[0].y} ` +
350
+ points.slice(1).map(p => `L ${p.x} ${p.y}`).join(' ');
351
+ const area = `${path} L ${points[points.length - 1].x} ${bottomY} L ${points[0].x} ${bottomY} Z`;
352
+ return { path, area };
353
+ }
354
+
355
+ const tension = 0.2;
356
+ let path = `M ${points[0].x.toFixed(1)} ${points[0].y.toFixed(1)}`;
357
+
358
+ for (let i = 0; i < points.length - 1; i++) {
359
+ const p0 = points[i > 0 ? i - 1 : i];
360
+ const p1 = points[i];
361
+ const p2 = points[i + 1];
362
+ const p3 = points[i + 2 < points.length ? i + 2 : i + 1];
363
+
364
+ const cp1x = p1.x + (p2.x - p0.x) * tension;
365
+ const cp1y = p1.y + (p2.y - p0.y) * tension;
366
+ const cp2x = p2.x - (p3.x - p1.x) * tension;
367
+ const cp2y = p2.y - (p3.y - p1.y) * tension;
368
+
369
+ path += ` C ${cp1x.toFixed(1)} ${cp1y.toFixed(1)}, ${cp2x.toFixed(1)} ${cp2y.toFixed(1)}, ${p2.x.toFixed(1)} ${p2.y.toFixed(1)}`;
370
+ }
371
+
372
+ const area = `${path} L ${points[points.length - 1].x.toFixed(1)} ${bottomY} L ${points[0].x.toFixed(1)} ${bottomY} Z`;
373
+ return { path, area };
374
+ }
375
+
376
+ render() {
377
+ const padding = { top: 16, right: 16, bottom: 26, left: 36 };
378
+
379
+ return html`
380
+ <div
381
+ class="chart-container"
382
+ style=${() => `height: ${this._height.value}px;`}
383
+ tabindex="0"
384
+ role="graphics-document"
385
+ aria-label="Data chart visualization"
386
+ @keydown=${this.#onKeyDown}
387
+ @mouseleave=${this.#onMouseLeave}
388
+ >
389
+ ${() => {
390
+ const width = Math.max(300, this._containerWidth.value || 800);
391
+ const items = this.#dataItems.value;
392
+ const chartH = this._height.value;
393
+ const innerW = width - padding.left - padding.right;
394
+ const innerH = chartH - padding.top - padding.bottom;
395
+
396
+ if (!items || items.length === 0) {
397
+ return html`
398
+ <div style="display:flex;align-items:center;justify-content:center;height:100%;color:var(--el-text-muted);font-size:12px;">
399
+ No chart data available
400
+ </div>
401
+ `;
402
+ }
403
+
404
+ const yKey = this._yKey.value;
405
+ const secKey = this._secondaryKey.value;
406
+ const xKey = this._xKey.value;
407
+ const chartType = this._type.value;
408
+ const isSmooth = this._curve.value !== 'linear';
409
+
410
+ // Compute max values
411
+ let maxVal = 0;
412
+ for (const item of items) {
413
+ const v1 = this.#getItemVal(item, yKey);
414
+ const v2 = secKey ? this.#getItemVal(item, secKey) : 0;
415
+ if (v1 > maxVal) maxVal = v1;
416
+ if (v2 > maxVal) maxVal = v2;
417
+ }
418
+ if (maxVal === 0) maxVal = 100;
419
+ // Add 10% head room
420
+ maxVal = Math.ceil(maxVal * 1.1);
421
+
422
+ // Point coordinates calculation
423
+ const stepX = items.length > 1 ? innerW / (items.length - 1) : innerW / 2;
424
+ const ptsPrimary = items.map((item, i) => {
425
+ const x = padding.left + (items.length > 1 ? i * stepX : innerW / 2);
426
+ const val = this.#getItemVal(item, yKey);
427
+ const y = padding.top + innerH - (val / maxVal) * innerH;
428
+ return { x, y, val, item, idx: i };
429
+ });
430
+
431
+ const ptsSec = secKey
432
+ ? items.map((item, i) => {
433
+ const x = padding.left + (items.length > 1 ? i * stepX : innerW / 2);
434
+ const val = this.#getItemVal(item, secKey);
435
+ const y = padding.top + innerH - (val / maxVal) * innerH;
436
+ return { x, y, val, item, idx: i };
437
+ })
438
+ : null;
439
+
440
+ const bottomY = padding.top + innerH;
441
+ const primaryResult = this.#buildSvgPath(ptsPrimary, isSmooth, bottomY);
442
+ const pathPrimary = primaryResult.path;
443
+ const areaPrimary = primaryResult.area;
444
+
445
+ const secResult = ptsSec ? this.#buildSvgPath(ptsSec, isSmooth, bottomY) : null;
446
+ const pathSec = secResult ? secResult.path : '';
447
+
448
+ // Gridlines
449
+ const gridSteps = 3;
450
+ const gridLines = [];
451
+ for (let g = 0; g <= gridSteps; g++) {
452
+ const y = padding.top + (innerH / gridSteps) * g;
453
+ const labelVal = Math.round(maxVal - (maxVal / gridSteps) * g);
454
+ gridLines.push({ y, label: labelVal });
455
+ }
456
+
457
+ // Bar chart calculations
458
+ const barSlotW = innerW / items.length;
459
+ const barW = Math.max(4, Math.min(28, barSlotW * 0.65));
460
+
461
+ const activeIndex = this.#activeIdx.value;
462
+ const activePt = activeIndex >= 0 && activeIndex < items.length ? ptsPrimary[activeIndex] : null;
463
+
464
+ return html`
465
+ <svg viewBox=${`0 0 ${width} ${chartH}`} style="width: 100%; height: 100%;">
466
+ <defs>
467
+ <linearGradient id="area-grad-1" x1="0" y1="0" x2="0" y2="1">
468
+ <stop offset="0%" stop-color="var(--el-chart-1, #2563eb)" stop-opacity="0.45" />
469
+ <stop offset="100%" stop-color="var(--el-chart-1, #2563eb)" stop-opacity="0.0" />
470
+ </linearGradient>
471
+ </defs>
472
+
473
+ <!-- Gridlines & Y-Axis Labels -->
474
+ ${this._showGrid.value ? gridLines.map(g => html`
475
+ <line x1=${padding.left} y1=${g.y} x2=${width - padding.right} y2=${g.y} class="grid-line" />
476
+ <text x=${padding.left - 6} y=${g.y} class="axis-label y-axis">${g.label}</text>
477
+ `) : null}
478
+
479
+ <!-- Chart Shapes -->
480
+ ${chartType === 'area' ? html`
481
+ <path d=${areaPrimary} class="series-primary-area" />
482
+ <path d=${pathPrimary} class="series-primary-stroke" />
483
+ ${pathSec ? html`<path d=${pathSec} class="series-secondary-stroke" />` : null}
484
+ ` : null}
485
+
486
+ ${chartType === 'line' ? html`
487
+ <path d=${pathPrimary} class="series-primary-stroke" />
488
+ ${pathSec ? html`<path d=${pathSec} class="series-secondary-stroke" />` : null}
489
+ ` : null}
490
+
491
+ ${chartType === 'bar' ? items.map((item, i) => {
492
+ const xCenter = padding.left + i * barSlotW + barSlotW / 2;
493
+ const v1 = this.#getItemVal(item, yKey);
494
+ const bH1 = Math.max(2, (v1 / maxVal) * innerH);
495
+ const y1 = padding.top + innerH - bH1;
496
+
497
+ if (secKey) {
498
+ const halfW = barW / 2;
499
+ const v2 = this.#getItemVal(item, secKey);
500
+ const bH2 = Math.max(2, (v2 / maxVal) * innerH);
501
+ const y2 = padding.top + innerH - bH2;
502
+ return html`
503
+ <g class="bar-group">
504
+ <rect
505
+ x=${xCenter - halfW}
506
+ y=${y1}
507
+ width=${halfW - 1}
508
+ height=${bH1}
509
+ class=${`bar-rect ${activeIndex === i ? 'active' : ''}`}
510
+ />
511
+ <rect
512
+ x=${xCenter + 1}
513
+ y=${y2}
514
+ width=${halfW - 1}
515
+ height=${bH2}
516
+ class=${`bar-rect secondary ${activeIndex === i ? 'active' : ''}`}
517
+ />
518
+ </g>
519
+ `;
520
+ }
521
+
522
+ return html`
523
+ <rect
524
+ x=${xCenter - barW / 2}
525
+ y=${y1}
526
+ width=${barW}
527
+ height=${bH1}
528
+ class=${`bar-rect ${activeIndex === i ? 'active' : ''}`}
529
+ />
530
+ `;
531
+ }) : null}
532
+
533
+ <!-- Data Dots for Line/Area -->
534
+ ${(chartType === 'line' || chartType === 'area') && this._showDots.value ? ptsPrimary.map(p => html`
535
+ <circle
536
+ cx=${p.x}
537
+ cy=${p.y}
538
+ class=${`point-dot ${activeIndex === p.idx ? 'active' : ''}`}
539
+ />
540
+ `) : null}
541
+
542
+ <!-- Active Cursor Vertical Line -->
543
+ ${activePt && (chartType === 'line' || chartType === 'area') ? html`
544
+ <line
545
+ x1=${activePt.x}
546
+ y1=${padding.top}
547
+ x2=${activePt.x}
548
+ y2=${padding.top + innerH}
549
+ class="cursor-line"
550
+ />
551
+ ` : null}
552
+
553
+ <!-- X-Axis Labels -->
554
+ ${items.map((item, i) => {
555
+ const x = chartType === 'bar'
556
+ ? padding.left + i * barSlotW + barSlotW / 2
557
+ : ptsPrimary[i].x;
558
+ return html`
559
+ <text x=${x} y=${chartH - 8} class="axis-label">
560
+ ${this.#getItemLabel(item, xKey)}
561
+ </text>
562
+ `;
563
+ })}
564
+
565
+ <!-- Interactive Hit Columns -->
566
+ ${items.map((item, i) => {
567
+ const hitX = padding.left + i * (innerW / items.length);
568
+ const hitW = innerW / items.length;
569
+ return html`
570
+ <rect
571
+ x=${hitX}
572
+ y=${padding.top}
573
+ width=${hitW}
574
+ height=${innerH}
575
+ class="hit-column"
576
+ @mouseenter=${() => this.#onColumnHover(i)}
577
+ @touchstart=${() => this.#onColumnHover(i)}
578
+ />
579
+ `;
580
+ })}
581
+ </svg>
582
+ `;
583
+ }}
584
+
585
+ <!-- Floating Tooltip -->
586
+ ${() => {
587
+ const idx = this.#activeIdx.value;
588
+ const items = this.#dataItems.value;
589
+ if (idx < 0 || idx >= items.length) return null;
590
+
591
+ const item = items[idx];
592
+ const xKey = this._xKey.value;
593
+ const yKey = this._yKey.value;
594
+ const secKey = this._secondaryKey.value;
595
+
596
+ const width = Math.max(300, this._containerWidth.value || 800);
597
+ const padding = { top: 16, right: 16, bottom: 26, left: 36 };
598
+ const innerW = width - padding.left - padding.right;
599
+ const stepX = items.length > 1 ? innerW / (items.length - 1) : innerW / 2;
600
+ const pctX = ((padding.left + (this._type.value === 'bar'
601
+ ? idx * (innerW / items.length) + (innerW / items.length) / 2
602
+ : idx * stepX)) / width) * 100;
603
+
604
+ return html`
605
+ <div
606
+ class="chart-tooltip"
607
+ style=${`left: ${pctX}%; top: 30%;`}
608
+ >
609
+ <div class="tooltip-header">${this.#getItemLabel(item, xKey)}</div>
610
+ <div class="tooltip-row">
611
+ <span class="tooltip-swatch"></span>
612
+ <span class="tooltip-label">${yKey || 'value'}:</span>
613
+ <span class="tooltip-value">${this.#getItemVal(item, yKey).toLocaleString()}</span>
614
+ </div>
615
+ ${secKey && (item[secKey] !== undefined || item.secondary !== undefined) ? html`
616
+ <div class="tooltip-row" style="margin-top: 3px;">
617
+ <span class="tooltip-swatch secondary"></span>
618
+ <span class="tooltip-label">${secKey}:</span>
619
+ <span class="tooltip-value">${this.#getItemVal(item, secKey).toLocaleString()}</span>
620
+ </div>
621
+ ` : null}
622
+ </div>
623
+ `;
624
+ }}
625
+ </div>
626
+ `;
627
+ }
628
+ }
629
+
630
+ if (typeof customElements !== 'undefined' && !customElements.get('el-chart')) {
631
+ customElements.define('el-chart', ElChart);
632
+ }