@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,151 @@
1
+ /**
2
+ * <el-kbd>
3
+ * Accessible keyboard shortcut badge inspired by shadcn/ui.
4
+ * Automatically parses modifier shortcuts (cmd, ctrl, shift, alt, opt, enter, esc, etc.)
5
+ * or renders custom slotted keycaps.
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 ElKbd extends Elementum {
13
+ static observedAttributes = ['keys', 'size'];
14
+
15
+ keys = signal('');
16
+ size = signal('md'); // 'sm' | 'md' | 'lg'
17
+
18
+ static styles = css`
19
+ :host {
20
+ display: inline-flex;
21
+ align-items: center;
22
+ gap: 3px;
23
+ vertical-align: middle;
24
+ font-family: var(--el-font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace);
25
+ box-sizing: border-box;
26
+ line-height: 1;
27
+ }
28
+
29
+ .keycap {
30
+ display: inline-flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ background: var(--el-surface-muted, #f1f5f9);
34
+ border: 1px solid var(--el-surface-border, #cbd5e1);
35
+ border-bottom-width: 2px;
36
+ border-radius: var(--el-radius-sm, 4px);
37
+ color: var(--el-text-secondary, #475569);
38
+ font-weight: 600;
39
+ box-sizing: border-box;
40
+ user-select: none;
41
+ box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
42
+ }
43
+
44
+ :root[data-theme="dark"] .keycap {
45
+ background: #1e293b;
46
+ border-color: #475569;
47
+ border-bottom-color: #64748b;
48
+ color: #cbd5e1;
49
+ box-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
50
+ }
51
+
52
+ /* Sizes */
53
+ :host([size="sm"]) .keycap {
54
+ min-width: 18px;
55
+ height: 18px;
56
+ padding: 0 4px;
57
+ font-size: 10px;
58
+ }
59
+
60
+ :host([size="md"]) .keycap,
61
+ :host(:not([size])) .keycap {
62
+ min-width: 22px;
63
+ height: 22px;
64
+ padding: 0 6px;
65
+ font-size: 11px;
66
+ }
67
+
68
+ :host([size="lg"]) .keycap {
69
+ min-width: 26px;
70
+ height: 26px;
71
+ padding: 0 8px;
72
+ font-size: 13px;
73
+ }
74
+ `;
75
+
76
+ connected() {
77
+ this.#syncAttrs();
78
+ }
79
+
80
+ attributeChanged(name, oldValue, newValue) {
81
+ this.#syncAttrs();
82
+ return true;
83
+ }
84
+
85
+ #syncAttrs() {
86
+ this.keys.value = this.getAttribute('keys') || '';
87
+ this.size.value = this.getAttribute('size') || 'md';
88
+ if (!this.hasAttribute('size')) this.setAttribute('size', 'md');
89
+ }
90
+
91
+ #formatKey(key) {
92
+ const k = key.trim().toLowerCase();
93
+ switch (k) {
94
+ case 'cmd':
95
+ case 'command':
96
+ return '⌘';
97
+ case 'ctrl':
98
+ case 'control':
99
+ return '⌃';
100
+ case 'shift':
101
+ return '⇧';
102
+ case 'alt':
103
+ case 'opt':
104
+ case 'option':
105
+ return '⌥';
106
+ case 'enter':
107
+ case 'return':
108
+ return '↵';
109
+ case 'esc':
110
+ case 'escape':
111
+ return '⎋';
112
+ case 'tab':
113
+ return '⇥';
114
+ case 'backspace':
115
+ case 'delete':
116
+ return '⌫';
117
+ case 'up':
118
+ return '↑';
119
+ case 'down':
120
+ return '↓';
121
+ case 'left':
122
+ return '←';
123
+ case 'right':
124
+ return '→';
125
+ default:
126
+ return key.trim().toUpperCase();
127
+ }
128
+ }
129
+
130
+ render() {
131
+ const keyList = () => {
132
+ const raw = this.keys.value;
133
+ if (!raw) return [];
134
+ return raw.split('+').map(k => this.#formatKey(k));
135
+ };
136
+
137
+ return html`
138
+ ${() => {
139
+ const list = keyList();
140
+ if (list.length === 0) {
141
+ return html`<kbd class="keycap" part="key"><slot></slot></kbd>`;
142
+ }
143
+ return list.map(k => html`<kbd class="keycap" part="key">${k}</kbd>`);
144
+ }}
145
+ `;
146
+ }
147
+ }
148
+
149
+ if (typeof customElements !== 'undefined' && !customElements.get('el-kbd')) {
150
+ customElements.define('el-kbd', ElKbd);
151
+ }
@@ -0,0 +1,254 @@
1
+ /**
2
+ * <el-menubar>
3
+ * Desktop-grade application menubar primitive inspired by Base UI.
4
+ * Features WAI-ARIA role="menubar", horizontal keyboard navigation (ArrowLeft/ArrowRight),
5
+ * automatic hover-switching between menus when open, and light-dismiss.
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 ElMenubar extends Elementum {
13
+ static observedAttributes = ['disabled'];
14
+
15
+ activeMenu = signal(null); // id or trigger element currently open
16
+ disabled = signal(false);
17
+
18
+ static styles = css`
19
+ :host {
20
+ display: flex;
21
+ width: 100%;
22
+ font-family: var(--el-font-sans, system-ui, sans-serif);
23
+ box-sizing: border-box;
24
+ }
25
+
26
+ .menubar {
27
+ display: flex;
28
+ align-items: center;
29
+ gap: 2px;
30
+ padding: 3px 6px;
31
+ width: 100%;
32
+ overflow-x: auto;
33
+ -webkit-overflow-scrolling: touch;
34
+ background: var(--el-surface-base, #ffffff);
35
+ border: 1px solid var(--el-surface-border, #e2e8f0);
36
+ border-radius: var(--el-radius-md, 8px);
37
+ box-sizing: border-box;
38
+ }
39
+
40
+ :root[data-theme="dark"] .menubar {
41
+ background: #1e293b;
42
+ border-color: #334155;
43
+ }
44
+
45
+ :host([disabled]) {
46
+ opacity: 0.6;
47
+ pointer-events: none;
48
+ }
49
+
50
+ ::slotted([role="menuitem"]),
51
+ ::slotted(.menubar-item),
52
+ ::slotted(button) {
53
+ display: inline-flex;
54
+ align-items: center;
55
+ padding: 4px 10px;
56
+ font-size: 13px;
57
+ font-weight: 500;
58
+ color: var(--el-text-base, #111827);
59
+ background: transparent;
60
+ border: none;
61
+ border-radius: var(--el-radius-sm, 4px);
62
+ cursor: pointer;
63
+ font-family: inherit;
64
+ outline: none;
65
+ transition: background-color 0.12s ease, color 0.12s ease;
66
+ box-sizing: border-box;
67
+ }
68
+
69
+ ::slotted([role="menuitem"]:hover),
70
+ ::slotted(.menubar-item:hover),
71
+ ::slotted(button:hover),
72
+ ::slotted([role="menuitem"]:focus-visible),
73
+ ::slotted(button:focus-visible) {
74
+ background: var(--el-surface-muted, #f1f5f9);
75
+ color: var(--el-color-primary, #2563eb);
76
+ }
77
+
78
+ :root[data-theme="dark"] ::slotted([role="menuitem"]:hover),
79
+ :root[data-theme="dark"] ::slotted(.menubar-item:hover),
80
+ :root[data-theme="dark"] ::slotted(button:hover) {
81
+ background: #334155;
82
+ color: #93c5fd;
83
+ }
84
+
85
+ ::slotted([data-state="open"]) {
86
+ background: var(--el-surface-muted, #f1f5f9) !important;
87
+ color: var(--el-color-primary, #2563eb) !important;
88
+ }
89
+ `;
90
+
91
+ #focusedIndex = 0;
92
+
93
+ connected() {
94
+ if (this.hasAttribute('disabled')) this.disabled.value = true;
95
+ this.addEventListener('keydown', this.#onKeyDown);
96
+ this.addEventListener('pointerenter', this.#onPointerEnterItem, true);
97
+ this.addEventListener('click', this.#onClickItem, true);
98
+
99
+ const raf = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : (cb) => setTimeout(cb, 0);
100
+ raf(() => this.#initItems());
101
+ }
102
+
103
+ disconnected() {
104
+ this.removeEventListener('keydown', this.#onKeyDown);
105
+ this.removeEventListener('pointerenter', this.#onPointerEnterItem, true);
106
+ this.removeEventListener('click', this.#onClickItem, true);
107
+ this.#removeGlobalListeners();
108
+ }
109
+
110
+ attributeChanged(name, oldValue, newValue) {
111
+ if (name === 'disabled') this.disabled.value = newValue !== null;
112
+ return true;
113
+ }
114
+
115
+ #getItems() {
116
+ return Array.from(this.querySelectorAll('*')).filter((el) => {
117
+ if (el.parentElement !== this) return false;
118
+ const tag = el.tagName.toLowerCase();
119
+ if (['el-separator', 'hr'].includes(tag)) return false;
120
+ return true;
121
+ });
122
+ }
123
+
124
+ #initItems() {
125
+ const items = this.#getItems();
126
+ items.forEach((item, idx) => {
127
+ item.setAttribute('role', 'menuitem');
128
+ item.setAttribute('tabindex', idx === 0 ? '0' : '-1');
129
+ });
130
+ }
131
+
132
+ #onClickItem = (e) => {
133
+ const items = this.#getItems();
134
+ const item = items.find((i) => i === e.target || i.contains(e.target));
135
+ if (!item) return;
136
+
137
+ if (this.activeMenu.value === item) {
138
+ this.closeMenu();
139
+ } else {
140
+ this.openMenu(item);
141
+ }
142
+ };
143
+
144
+ #onPointerEnterItem = (e) => {
145
+ // If ANY menu is already open, hovering an adjacent item switches to it!
146
+ if (!this.activeMenu.value) return;
147
+ const items = this.#getItems();
148
+ const item = items.find((i) => i === e.target || i.contains(e.target));
149
+ if (item && item !== this.activeMenu.value) {
150
+ this.openMenu(item);
151
+ }
152
+ };
153
+
154
+ openMenu(item) {
155
+ if (this.activeMenu.value) {
156
+ this.activeMenu.value.removeAttribute('data-state');
157
+ this.activeMenu.value.setAttribute('aria-expanded', 'false');
158
+ }
159
+ this.activeMenu.value = item;
160
+ item.setAttribute('data-state', 'open');
161
+ item.setAttribute('aria-expanded', 'true');
162
+ this.#addGlobalListeners();
163
+ this.emit('open', { item });
164
+ }
165
+
166
+ closeMenu() {
167
+ if (!this.activeMenu.value) return;
168
+ this.activeMenu.value.removeAttribute('data-state');
169
+ this.activeMenu.value.setAttribute('aria-expanded', 'false');
170
+ this.activeMenu.value = null;
171
+ this.#removeGlobalListeners();
172
+ this.emit('close');
173
+ }
174
+
175
+ #addGlobalListeners() {
176
+ this.#removeGlobalListeners();
177
+ document.addEventListener('pointerdown', this.#onPointerDownOutside, true);
178
+ window.addEventListener('keydown', this.#onWindowKeyDown, true);
179
+ }
180
+
181
+ #removeGlobalListeners() {
182
+ document.removeEventListener('pointerdown', this.#onPointerDownOutside, true);
183
+ window.removeEventListener('keydown', this.#onWindowKeyDown, true);
184
+ }
185
+
186
+ #onPointerDownOutside = (e) => {
187
+ if (!this.activeMenu.value) return;
188
+ const path = e.composedPath ? e.composedPath() : [];
189
+ if (!path.includes(this)) {
190
+ this.closeMenu();
191
+ }
192
+ };
193
+
194
+ #onWindowKeyDown = (e) => {
195
+ if (!this.activeMenu.value) return;
196
+ if (e.key === 'Escape') {
197
+ e.preventDefault();
198
+ this.closeMenu();
199
+ }
200
+ };
201
+
202
+ #onKeyDown = (e) => {
203
+ const items = this.#getItems();
204
+ if (items.length === 0) return;
205
+
206
+ if (e.key === 'ArrowRight') {
207
+ e.preventDefault();
208
+ this.#focusedIndex = (this.#focusedIndex + 1) % items.length;
209
+ this.#focusItem(items[this.#focusedIndex]);
210
+ if (this.activeMenu.value) this.openMenu(items[this.#focusedIndex]);
211
+ } else if (e.key === 'ArrowLeft') {
212
+ e.preventDefault();
213
+ this.#focusedIndex = (this.#focusedIndex - 1 + items.length) % items.length;
214
+ this.#focusItem(items[this.#focusedIndex]);
215
+ if (this.activeMenu.value) this.openMenu(items[this.#focusedIndex]);
216
+ } else if (e.key === 'Home') {
217
+ e.preventDefault();
218
+ this.#focusedIndex = 0;
219
+ this.#focusItem(items[0]);
220
+ } else if (e.key === 'End') {
221
+ e.preventDefault();
222
+ this.#focusedIndex = items.length - 1;
223
+ this.#focusItem(items[items.length - 1]);
224
+ } else if (e.key === 'ArrowDown' || e.key === 'Enter' || e.key === ' ') {
225
+ e.preventDefault();
226
+ const current = items[this.#focusedIndex];
227
+ if (current) this.openMenu(current);
228
+ }
229
+ };
230
+
231
+ #focusItem(item) {
232
+ const items = this.#getItems();
233
+ items.forEach((it) => it.setAttribute('tabindex', it === item ? '0' : '-1'));
234
+ item?.focus();
235
+ }
236
+
237
+ render() {
238
+ return html`
239
+ <div
240
+ class="menubar"
241
+ part="menubar"
242
+ role="menubar"
243
+ aria-orientation="horizontal"
244
+ aria-disabled=${() => (this.disabled.value ? 'true' : 'false')}
245
+ >
246
+ <slot></slot>
247
+ </div>
248
+ `;
249
+ }
250
+ }
251
+
252
+ if (typeof customElements !== 'undefined' && !customElements.get('el-menubar')) {
253
+ customElements.define('el-menubar', ElMenubar);
254
+ }
@@ -0,0 +1,183 @@
1
+ /**
2
+ * <el-meter>
3
+ * Accessible scalar measurement gauge primitive inspired by Base UI.
4
+ * Displays a known scalar value or fractional measurement within a bounded range
5
+ * (e.g. disk storage, password strength, battery, quota limits) with semantic threshold statuses.
6
+ */
7
+
8
+ import { Elementum } from '../elementum.js';
9
+ import { html, css } from '../template.js';
10
+ import { signal, computed, effect } from '../signal.js';
11
+
12
+ export class ElMeter extends Elementum {
13
+ static observedAttributes = ['value', 'min', 'max', 'low', 'high', 'optimum', 'size'];
14
+
15
+ value = signal(0);
16
+ min = signal(0);
17
+ max = signal(100);
18
+ low = signal(null);
19
+ high = signal(null);
20
+ optimum = signal(null);
21
+ size = signal('md'); // 'sm' | 'md' | 'lg'
22
+
23
+ percentage = computed(() => {
24
+ const val = Number(this.value.value) || 0;
25
+ const minVal = Number(this.min.value) || 0;
26
+ const maxVal = Number(this.max.value) || 100;
27
+ if (maxVal <= minVal) return 0;
28
+ const pct = ((val - minVal) / (maxVal - minVal)) * 100;
29
+ return Math.min(100, Math.max(0, pct));
30
+ });
31
+
32
+ status = computed(() => {
33
+ const val = Number(this.value.value) || 0;
34
+ const lowVal = this.low.value !== null ? Number(this.low.value) : null;
35
+ const highVal = this.high.value !== null ? Number(this.high.value) : null;
36
+ const optVal = this.optimum.value !== null ? Number(this.optimum.value) : null;
37
+
38
+ if (lowVal === null || highVal === null) {
39
+ return 'default';
40
+ }
41
+
42
+ const optimum = optVal !== null ? optVal : (lowVal + highVal) / 2;
43
+
44
+ // Higher is better (e.g., battery, storage remaining)
45
+ if (optimum >= highVal) {
46
+ if (val >= highVal) return 'safe';
47
+ if (val >= lowVal) return 'warning';
48
+ return 'critical';
49
+ }
50
+
51
+ // Lower is better (e.g., CPU load, disk usage)
52
+ if (optimum <= lowVal) {
53
+ if (val <= lowVal) return 'safe';
54
+ if (val <= highVal) return 'warning';
55
+ return 'critical';
56
+ }
57
+
58
+ // Medium is optimum
59
+ if (val >= lowVal && val <= highVal) return 'safe';
60
+ return 'warning';
61
+ });
62
+
63
+ static styles = css`
64
+ :host {
65
+ display: block;
66
+ width: 100%;
67
+ font-family: var(--el-font-sans, system-ui, sans-serif);
68
+ font-variant-numeric: tabular-nums;
69
+ box-sizing: border-box;
70
+ }
71
+
72
+ .meter-container {
73
+ width: 100%;
74
+ display: flex;
75
+ flex-direction: column;
76
+ gap: 4px;
77
+ }
78
+
79
+ .track {
80
+ width: 100%;
81
+ background: var(--el-surface-muted, #e2e8f0);
82
+ border-radius: 9999px;
83
+ overflow: hidden;
84
+ position: relative;
85
+ }
86
+
87
+ :host([size="sm"]) .track {
88
+ height: 4px;
89
+ }
90
+
91
+ :host([size="md"]) .track,
92
+ :host(:not([size])) .track {
93
+ height: 8px;
94
+ }
95
+
96
+ :host([size="lg"]) .track {
97
+ height: 12px;
98
+ }
99
+
100
+ :root[data-theme="dark"] .track {
101
+ background: #334155;
102
+ }
103
+
104
+ .fill {
105
+ height: 100%;
106
+ border-radius: inherit;
107
+ transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s ease;
108
+ background: var(--el-color-primary, #2563eb);
109
+ }
110
+
111
+ :host([data-status="safe"]) .fill {
112
+ background: var(--el-color-success, #16a34a);
113
+ }
114
+
115
+ :host([data-status="warning"]) .fill {
116
+ background: var(--el-color-warning, #eab308);
117
+ }
118
+
119
+ :host([data-status="critical"]) .fill {
120
+ background: var(--el-color-danger, #dc2626);
121
+ }
122
+ `;
123
+
124
+ #stopEffect = null;
125
+
126
+ connected() {
127
+ this.#syncAttributes();
128
+ this.#stopEffect = effect(() => {
129
+ this.setAttribute('data-status', this.status.value);
130
+ });
131
+ }
132
+
133
+ disconnected() {
134
+ this.#stopEffect?.();
135
+ }
136
+
137
+ attributeChanged(name, oldValue, newValue) {
138
+ if (name === 'value') this.value.value = Number(newValue) || 0;
139
+ else if (name === 'min') this.min.value = Number(newValue) || 0;
140
+ else if (name === 'max') this.max.value = Number(newValue) || 100;
141
+ else if (name === 'low') this.low.value = newValue !== null ? Number(newValue) : null;
142
+ else if (name === 'high') this.high.value = newValue !== null ? Number(newValue) : null;
143
+ else if (name === 'optimum') this.optimum.value = newValue !== null ? Number(newValue) : null;
144
+ else if (name === 'size') this.size.value = newValue || 'md';
145
+ return true;
146
+ }
147
+
148
+ #syncAttributes() {
149
+ if (this.hasAttribute('value')) this.value.value = Number(this.getAttribute('value')) || 0;
150
+ if (this.hasAttribute('min')) this.min.value = Number(this.getAttribute('min')) || 0;
151
+ if (this.hasAttribute('max')) this.max.value = Number(this.getAttribute('max')) || 100;
152
+ if (this.hasAttribute('low')) this.low.value = Number(this.getAttribute('low'));
153
+ if (this.hasAttribute('high')) this.high.value = Number(this.getAttribute('high'));
154
+ if (this.hasAttribute('optimum')) this.optimum.value = Number(this.getAttribute('optimum'));
155
+ if (this.hasAttribute('size')) this.size.value = this.getAttribute('size');
156
+ }
157
+
158
+ render() {
159
+ return html`
160
+ <div
161
+ class="meter-container"
162
+ role="meter"
163
+ aria-label=${() => this.getAttribute?.('aria-label') || 'Meter'}
164
+ aria-valuenow=${() => this.value.value}
165
+ aria-valuemin=${() => this.min.value}
166
+ aria-valuemax=${() => this.max.value}
167
+ aria-valuetext=${() => `${Math.round(this.percentage.value)}%`}
168
+ >
169
+ <div class="track" part="track">
170
+ <div
171
+ class="fill"
172
+ part="fill"
173
+ style=${() => `width: ${this.percentage.value}%;`}
174
+ ></div>
175
+ </div>
176
+ </div>
177
+ `;
178
+ }
179
+ }
180
+
181
+ if (typeof customElements !== 'undefined' && !customElements.get('el-meter')) {
182
+ customElements.define('el-meter', ElMeter);
183
+ }