@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,324 @@
1
+ /**
2
+ * <el-resizable> family
3
+ * Accessible resizable panel splitter inspired by shadcn/ui.
4
+ * Includes <el-resizable-panel> and <el-resizable-handle> with smooth pointer dragging,
5
+ * keyboard arrow sizing, touch support, and min/max boundaries.
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 ElResizableHandle extends Elementum {
13
+ static observedAttributes = ['disabled'];
14
+ disabled = signal(false);
15
+
16
+ static styles = css`
17
+ :host {
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ position: relative;
22
+ touch-action: none;
23
+ user-select: none;
24
+ -webkit-user-select: none;
25
+ z-index: 10;
26
+ box-sizing: border-box;
27
+ flex-shrink: 0;
28
+ width: 8px;
29
+ cursor: col-resize;
30
+ background: var(--el-surface-border, #cbd5e1);
31
+ transition: background-color 0.15s ease;
32
+ }
33
+
34
+ :host([direction="vertical"]) {
35
+ width: 100%;
36
+ height: 8px;
37
+ cursor: row-resize;
38
+ }
39
+
40
+ :host(:hover),
41
+ :host([dragging]),
42
+ :host(:focus-visible) {
43
+ background: var(--el-color-primary, #3b82f6) !important;
44
+ outline: none;
45
+ }
46
+
47
+ .handle-bar {
48
+ width: 100%;
49
+ height: 100%;
50
+ display: flex;
51
+ align-items: center;
52
+ justify-content: center;
53
+ }
54
+
55
+ .grip {
56
+ width: 4px;
57
+ height: 24px;
58
+ border-radius: 999px;
59
+ background: rgba(255, 255, 255, 0.7);
60
+ }
61
+ `;
62
+
63
+ connected() {
64
+ this.disabled.value = this.hasAttribute('disabled');
65
+ this.setAttribute('role', 'separator');
66
+ this.setAttribute('tabindex', '0');
67
+ }
68
+
69
+ attributeChanged(name, oldValue, newValue) {
70
+ if (name === 'disabled') this.disabled.value = newValue !== null;
71
+ return true;
72
+ }
73
+
74
+ render() {
75
+ return html`
76
+ <div class="handle-bar" part="handle">
77
+ <slot><div class="grip"></div></slot>
78
+ </div>
79
+ `;
80
+ }
81
+ }
82
+
83
+ export class ElResizablePanel extends Elementum {
84
+ static observedAttributes = ['default-size', 'min-size', 'max-size'];
85
+
86
+ size = signal(50); // percentage
87
+ minSize = signal(10);
88
+ maxSize = signal(90);
89
+
90
+ static styles = css`
91
+ :host {
92
+ display: flex;
93
+ flex-direction: column;
94
+ box-sizing: border-box;
95
+ overflow: auto;
96
+ position: relative;
97
+ min-width: 0;
98
+ min-height: 0;
99
+ }
100
+ `;
101
+
102
+ connected() {
103
+ const def = parseFloat(this.getAttribute('default-size') || '50');
104
+ this.size.value = def;
105
+ this.minSize.value = parseFloat(this.getAttribute('min-size') || '10');
106
+ this.maxSize.value = parseFloat(this.getAttribute('max-size') || '90');
107
+ this.#applySize();
108
+ }
109
+
110
+ attributeChanged(name, oldValue, newValue) {
111
+ if (name === 'default-size') this.size.value = parseFloat(newValue || '50');
112
+ if (name === 'min-size') this.minSize.value = parseFloat(newValue || '10');
113
+ if (name === 'max-size') this.maxSize.value = parseFloat(newValue || '90');
114
+ this.#applySize();
115
+ return true;
116
+ }
117
+
118
+ setSize(pct) {
119
+ const clamped = Math.min(Math.max(pct, this.minSize.value), this.maxSize.value);
120
+ this.size.value = clamped;
121
+ this.#applySize();
122
+ }
123
+
124
+ #applySize() {
125
+ this.style.flex = `0 0 ${this.size.value}%`;
126
+ }
127
+
128
+ render() {
129
+ return html`<slot></slot>`;
130
+ }
131
+ }
132
+
133
+ export class ElResizable extends Elementum {
134
+ static observedAttributes = ['direction'];
135
+
136
+ direction = signal('horizontal'); // 'horizontal' | 'vertical'
137
+ #isDragging = false;
138
+ #activeHandle = null;
139
+ #startPos = 0;
140
+ #prevPanel = null;
141
+ #nextPanel = null;
142
+ #startPrevSize = 0;
143
+ #startNextSize = 0;
144
+
145
+ static styles = css`
146
+ :host {
147
+ display: flex;
148
+ width: 100%;
149
+ height: 100%;
150
+ min-height: 120px;
151
+ box-sizing: border-box;
152
+ overflow: hidden;
153
+ border: 1px solid var(--el-surface-border, #e2e8f0);
154
+ border-radius: var(--el-radius-md, 8px);
155
+ background: var(--el-surface-card, #ffffff);
156
+ }
157
+
158
+ :host([direction="horizontal"]) {
159
+ flex-direction: row;
160
+ }
161
+
162
+ :host([direction="vertical"]) {
163
+ flex-direction: column;
164
+ }
165
+
166
+ ::slotted(el-resizable-handle) {
167
+ width: 8px;
168
+ cursor: col-resize;
169
+ }
170
+
171
+ :host([direction="vertical"]) ::slotted(el-resizable-handle) {
172
+ width: 100%;
173
+ height: 8px;
174
+ cursor: row-resize;
175
+ }
176
+ `;
177
+
178
+ connected() {
179
+ this.direction.value = this.getAttribute('direction') || 'horizontal';
180
+ if (!this.hasAttribute('direction')) this.setAttribute('direction', 'horizontal');
181
+
182
+ this.#ensurePanelsAndHandles();
183
+
184
+ this.addEventListener('pointerdown', this.#onPointerDown);
185
+ this.addEventListener('keydown', this.#onKeyDown);
186
+ }
187
+
188
+ #ensurePanelsAndHandles() {
189
+ const children = Array.from(this.children);
190
+ if (children.length >= 2 && !this.querySelector('el-resizable-handle')) {
191
+ const handle = document.createElement('el-resizable-handle');
192
+ children[0].after(handle);
193
+ }
194
+ Array.from(this.children).forEach((child) => {
195
+ if (child.tagName.toLowerCase() !== 'el-resizable-handle') {
196
+ if (!child.style.flex) {
197
+ child.style.flex = '1 1 0%';
198
+ child.style.overflow = 'auto';
199
+ child.style.boxSizing = 'border-box';
200
+ }
201
+ }
202
+ });
203
+ }
204
+
205
+ disconnected() {
206
+ this.removeEventListener('pointerdown', this.#onPointerDown);
207
+ this.removeEventListener('keydown', this.#onKeyDown);
208
+ this.#stopDragging();
209
+ }
210
+
211
+ attributeChanged(name, oldValue, newValue) {
212
+ if (name === 'direction') this.direction.value = newValue || 'horizontal';
213
+ return true;
214
+ }
215
+
216
+ #onPointerDown = (e) => {
217
+ const handle = e.target.closest('el-resizable-handle');
218
+ if (!handle || handle.disabled?.value) return;
219
+
220
+ this.#activeHandle = handle;
221
+ this.#prevPanel = handle.previousElementSibling;
222
+ this.#nextPanel = handle.nextElementSibling;
223
+
224
+ if (!this.#prevPanel || !this.#nextPanel) return;
225
+
226
+ this.#isDragging = true;
227
+ handle.setAttribute('dragging', '');
228
+ this.#startPos = this.direction.value === 'horizontal' ? e.clientX : e.clientY;
229
+
230
+ const totalDim = (this.direction.value === 'horizontal' ? this.offsetWidth : this.offsetHeight) || 1;
231
+ const prevRect = this.#prevPanel.getBoundingClientRect();
232
+ const nextRect = this.#nextPanel.getBoundingClientRect();
233
+
234
+ this.#startPrevSize = this.#prevPanel.size?.value ?? (((this.direction.value === 'horizontal' ? prevRect.width : prevRect.height) / totalDim) * 100);
235
+ this.#startNextSize = this.#nextPanel.size?.value ?? (((this.direction.value === 'horizontal' ? nextRect.width : nextRect.height) / totalDim) * 100);
236
+
237
+ window.addEventListener('pointermove', this.#onPointerMove);
238
+ window.addEventListener('pointerup', this.#onPointerUp);
239
+ window.addEventListener('pointercancel', this.#onPointerUp);
240
+ e.preventDefault();
241
+ };
242
+
243
+ #onPointerMove = (e) => {
244
+ if (!this.#isDragging || !this.#prevPanel || !this.#nextPanel) return;
245
+
246
+ const currentPos = this.direction.value === 'horizontal' ? e.clientX : e.clientY;
247
+ const delta = currentPos - this.#startPos;
248
+ const totalPixels = this.direction.value === 'horizontal' ? this.offsetWidth : this.offsetHeight;
249
+
250
+ if (totalPixels <= 0) return;
251
+
252
+ const deltaPct = (delta / totalPixels) * 100;
253
+ const newPrev = this.#startPrevSize + deltaPct;
254
+ const newNext = this.#startNextSize - deltaPct;
255
+
256
+ const minPrev = this.#prevPanel.minSize?.value ?? 10;
257
+ const maxPrev = this.#prevPanel.maxSize?.value ?? 90;
258
+ const minNext = this.#nextPanel.minSize?.value ?? 10;
259
+ const maxNext = this.#nextPanel.maxSize?.value ?? 90;
260
+
261
+ if (newPrev >= minPrev && newPrev <= maxPrev && newNext >= minNext && newNext <= maxNext) {
262
+ if (typeof this.#prevPanel.setSize === 'function') {
263
+ this.#prevPanel.setSize(newPrev);
264
+ } else {
265
+ this.#prevPanel.style.flex = `0 0 ${newPrev}%`;
266
+ }
267
+ if (typeof this.#nextPanel.setSize === 'function') {
268
+ this.#nextPanel.setSize(newNext);
269
+ } else {
270
+ this.#nextPanel.style.flex = `0 0 ${newNext}%`;
271
+ }
272
+ this.emit('resize', { prevSize: newPrev, nextSize: newNext });
273
+ }
274
+ };
275
+
276
+ #onPointerUp = () => {
277
+ this.#stopDragging();
278
+ };
279
+
280
+ #stopDragging() {
281
+ if (!this.#isDragging) return;
282
+ this.#isDragging = false;
283
+ this.#activeHandle?.removeAttribute('dragging');
284
+ this.#activeHandle = null;
285
+ window.removeEventListener('pointermove', this.#onPointerMove);
286
+ window.removeEventListener('pointerup', this.#onPointerUp);
287
+ window.removeEventListener('pointercancel', this.#onPointerUp);
288
+ }
289
+
290
+ #onKeyDown = (e) => {
291
+ const handle = document.activeElement?.closest('el-resizable-handle');
292
+ if (!handle) return;
293
+
294
+ const prev = handle.previousElementSibling;
295
+ const next = handle.nextElementSibling;
296
+ if (!prev || !next) return;
297
+
298
+ let step = 0;
299
+ if (this.direction.value === 'horizontal') {
300
+ if (e.key === 'ArrowLeft') step = -4;
301
+ if (e.key === 'ArrowRight') step = 4;
302
+ } else {
303
+ if (e.key === 'ArrowUp') step = -4;
304
+ if (e.key === 'ArrowDown') step = 4;
305
+ }
306
+
307
+ if (step !== 0) {
308
+ e.preventDefault();
309
+ prev.setSize(prev.size.value + step);
310
+ next.setSize(next.size.value - step);
311
+ this.emit('resize', { prevSize: prev.size.value, nextSize: next.size.value });
312
+ }
313
+ };
314
+
315
+ render() {
316
+ return html`<slot></slot>`;
317
+ }
318
+ }
319
+
320
+ if (typeof customElements !== 'undefined') {
321
+ if (!customElements.get('el-resizable-handle')) customElements.define('el-resizable-handle', ElResizableHandle);
322
+ if (!customElements.get('el-resizable-panel')) customElements.define('el-resizable-panel', ElResizablePanel);
323
+ if (!customElements.get('el-resizable')) customElements.define('el-resizable', ElResizable);
324
+ }
@@ -0,0 +1,305 @@
1
+ import { Elementum } from '../elementum.js';
2
+ import { html, css } from '../template.js';
3
+ import { signal } from '../signal.js';
4
+
5
+ // Global router state
6
+ export const currentRoute = signal(
7
+ typeof window !== 'undefined' ? (window.location.hash.slice(1) || '/') : '/'
8
+ );
9
+
10
+ function normalizePath(path) {
11
+ if (!path) return '/';
12
+ try {
13
+ path = decodeURIComponent(path);
14
+ } catch {}
15
+ path = path.trim();
16
+ while (path.startsWith('#') || path.startsWith(' ')) {
17
+ path = path.slice(1);
18
+ }
19
+ if (!path.startsWith('/')) path = '/' + path;
20
+ if (path.length > 1 && path.endsWith('/')) path = path.slice(0, -1);
21
+ return path;
22
+ }
23
+
24
+ export function navigate(path) {
25
+ const normalized = normalizePath(path);
26
+ currentRoute.value = normalized;
27
+ if (window.location.hash.slice(1) !== normalized) {
28
+ window.location.hash = normalized;
29
+ }
30
+ }
31
+
32
+ // Listen to hash changes globally
33
+ if (typeof window !== 'undefined') {
34
+ window.addEventListener('hashchange', () => {
35
+ const raw = window.location.hash.slice(1) || '/';
36
+ currentRoute.value = normalizePath(raw);
37
+ });
38
+ }
39
+
40
+ /**
41
+ * <el-router>
42
+ * Client-side declarative SPA router powered by micro-signals.
43
+ * Controls which <el-route> child is active based on the URL hash.
44
+ */
45
+ export class ElRouter extends Elementum {
46
+ static observedAttributes = ['default'];
47
+
48
+ defaultPath = signal('/');
49
+
50
+ static styles = css`
51
+ :host {
52
+ display: block;
53
+ width: 100%;
54
+ }
55
+
56
+ @media (prefers-reduced-motion: reduce) {
57
+ *, *::before, *::after {
58
+ animation: none !important;
59
+ transition: none !important;
60
+ }
61
+ }
62
+ `;
63
+
64
+ connected() {
65
+ const def = this.getAttribute('default') || '/';
66
+ this.defaultPath.value = normalizePath(def);
67
+
68
+ const rawHash = typeof window !== 'undefined' ? window.location.hash.slice(1) : '';
69
+ const normalizedHash = rawHash ? normalizePath(rawHash) : '';
70
+ const routes = Array.from(this.querySelectorAll('el-route'));
71
+ const hashMatchesChild =
72
+ normalizedHash &&
73
+ routes.some((r) => {
74
+ const rp = normalizePath(r.getAttribute('path'));
75
+ if (rp === '/*' || rp === '*') return false;
76
+ return normalizedHash === rp || normalizedHash.startsWith(rp + '/');
77
+ });
78
+
79
+ if (hashMatchesChild) {
80
+ currentRoute.value = normalizedHash;
81
+ } else {
82
+ currentRoute.value = this.defaultPath.value;
83
+ if ((!window.location.hash || window.location.hash === '#') && typeof window !== 'undefined') {
84
+ window.location.hash = this.defaultPath.value;
85
+ }
86
+ }
87
+
88
+ this.#updateActiveRoutes();
89
+ this.disposeRouteSubscription = currentRoute.subscribe(() => {
90
+ this.#updateActiveRoutes();
91
+ });
92
+ }
93
+
94
+ attributeChanged(name, oldValue, newValue) {
95
+ if (name === 'default') {
96
+ this.defaultPath.value = normalizePath(newValue || '/');
97
+ currentRoute.value = this.defaultPath.value;
98
+ this.#updateActiveRoutes();
99
+ }
100
+ }
101
+
102
+ disconnected() {
103
+ if (this.disposeRouteSubscription) {
104
+ this.disposeRouteSubscription();
105
+ }
106
+ }
107
+
108
+ #updateActiveRoutes() {
109
+ const activePath = currentRoute.value;
110
+ const routes = this.querySelectorAll('el-route');
111
+ let hasMatch = false;
112
+
113
+ routes.forEach((route) => {
114
+ const routePath = normalizePath(route.getAttribute('path'));
115
+ const isExact = route.hasAttribute('exact');
116
+ const isWildcard = routePath === '/*' || routePath === '*';
117
+
118
+ let isMatch = false;
119
+ if (isWildcard) {
120
+ isMatch = true;
121
+ } else if (isExact) {
122
+ isMatch = activePath === routePath;
123
+ } else {
124
+ isMatch = activePath === routePath || activePath.startsWith(routePath + '/');
125
+ }
126
+
127
+ if (isMatch && !hasMatch) {
128
+ route.setAttribute('active', '');
129
+ route.removeAttribute('hidden');
130
+ hasMatch = true;
131
+ } else {
132
+ route.removeAttribute('active');
133
+ route.setAttribute('hidden', '');
134
+ }
135
+ });
136
+
137
+ if (!hasMatch && routes.length > 0) {
138
+ const defTarget = this.defaultPath.value;
139
+ const fallbackRoute =
140
+ Array.from(routes).find((r) => normalizePath(r.getAttribute('path')) === defTarget) ||
141
+ routes[0];
142
+ if (fallbackRoute) {
143
+ fallbackRoute.setAttribute('active', '');
144
+ fallbackRoute.removeAttribute('hidden');
145
+ }
146
+ }
147
+
148
+ // Update route links if upgraded
149
+ document.querySelectorAll('el-route-link').forEach((link) => {
150
+ if (typeof link.checkActive === 'function') {
151
+ link.checkActive(activePath);
152
+ }
153
+ });
154
+ }
155
+
156
+ render() {
157
+ return html`<slot></slot>`;
158
+ }
159
+ }
160
+
161
+ /**
162
+ * <el-route>
163
+ * Represents an individual view/subpage within <el-router>.
164
+ */
165
+ export class ElRoute extends Elementum {
166
+ static observedAttributes = ['path', 'exact'];
167
+
168
+ path = signal('/');
169
+ exact = signal(false);
170
+
171
+ static styles = css`
172
+ :host {
173
+ display: block;
174
+ width: 100%;
175
+ animation: el-route-fade-in 220ms cubic-bezier(0.16, 1, 0.3, 1);
176
+ }
177
+
178
+ :host([hidden]) {
179
+ display: none !important;
180
+ }
181
+
182
+ @keyframes el-route-fade-in {
183
+ from {
184
+ opacity: 0;
185
+ transform: translateY(4px);
186
+ }
187
+ to {
188
+ opacity: 1;
189
+ transform: translateY(0);
190
+ }
191
+ }
192
+ `;
193
+
194
+ connected() {
195
+ this.path.value = normalizePath(this.getAttribute('path') || '/');
196
+ this.exact.value = this.hasAttribute('exact');
197
+ }
198
+
199
+ attributeChanged(name, oldValue, newValue) {
200
+ if (name === 'path') this.path.value = normalizePath(newValue || '/');
201
+ if (name === 'exact') this.exact.value = newValue !== null;
202
+ }
203
+
204
+ render() {
205
+ return html`<slot></slot>`;
206
+ }
207
+ }
208
+
209
+ /**
210
+ * <el-route-link>
211
+ * SPA navigation link that prevents full page reloads and toggles active state.
212
+ */
213
+ export class ElRouteLink extends Elementum {
214
+ static observedAttributes = ['to', 'exact'];
215
+
216
+ to = signal('/');
217
+ exact = signal(false);
218
+ active = signal(false);
219
+
220
+ static styles = css`
221
+ :host {
222
+ display: inline-flex;
223
+ cursor: pointer;
224
+ }
225
+
226
+ a {
227
+ display: inline-flex;
228
+ align-items: center;
229
+ gap: inherit;
230
+ width: 100%;
231
+ height: 100%;
232
+ color: inherit;
233
+ text-decoration: none;
234
+ font-size: inherit;
235
+ font-weight: inherit;
236
+ border-radius: inherit;
237
+ box-sizing: border-box;
238
+ outline: none;
239
+ }
240
+
241
+ :host([active]) a {
242
+ color: var(--el-primary, #2563eb);
243
+ }
244
+ `;
245
+
246
+ connected() {
247
+ this.to.value = normalizePath(this.getAttribute('to') || '/');
248
+ this.exact.value = this.hasAttribute('exact');
249
+
250
+ this.addEventListener('click', this.#onHostClick);
251
+
252
+ this.checkActive(currentRoute.value);
253
+ this.disposeRouteSub = currentRoute.subscribe((path) => {
254
+ this.checkActive(path);
255
+ });
256
+ }
257
+
258
+ disconnected() {
259
+ this.removeEventListener('click', this.#onHostClick);
260
+ if (this.disposeRouteSub) {
261
+ this.disposeRouteSub();
262
+ }
263
+ }
264
+
265
+ #onHostClick = (e) => {
266
+ e.preventDefault();
267
+ navigate(this.to.value);
268
+ };
269
+
270
+ attributeChanged(name, oldValue, newValue) {
271
+ if (name === 'to') {
272
+ this.to.value = normalizePath(newValue || '/');
273
+ this.checkActive(currentRoute.value);
274
+ }
275
+ if (name === 'exact') {
276
+ this.exact.value = newValue !== null;
277
+ this.checkActive(currentRoute.value);
278
+ }
279
+ }
280
+
281
+ checkActive(currentPath) {
282
+ const target = this.to.value;
283
+ const isMatch = this.exact.value
284
+ ? currentPath === target
285
+ : currentPath === target || (target !== '/' && currentPath.startsWith(target + '/'));
286
+
287
+ if (isMatch) {
288
+ this.setAttribute('active', '');
289
+ this.active.value = true;
290
+ } else {
291
+ this.removeAttribute('active');
292
+ this.active.value = false;
293
+ }
294
+ }
295
+
296
+ render() {
297
+ return html`<a href="${() => '#' + this.to.value}"><slot></slot></a>`;
298
+ }
299
+ }
300
+
301
+ if (typeof customElements !== 'undefined') {
302
+ if (!customElements.get('el-route')) customElements.define('el-route', ElRoute);
303
+ if (!customElements.get('el-route-link')) customElements.define('el-route-link', ElRouteLink);
304
+ if (!customElements.get('el-router')) customElements.define('el-router', ElRouter);
305
+ }