@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.
- package/LICENSE +21 -0
- package/README.md +282 -2
- package/custom-elements.json +3613 -0
- package/mcp/server.js +593 -0
- package/package.json +77 -4
- package/skills/elementum-break-ui/CATALOG.md +11 -0
- package/skills/elementum-break-ui/SKILL.md +16 -0
- package/skills/elementum-mobile/SKILL.md +18 -0
- package/skills/elementum-motion/SKILL.md +18 -0
- package/skills/elementum-motion/STANDARDS.md +15 -0
- package/skills/elementum-penpot/SKILL.md +45 -0
- package/skills/elementum-ui/CATALOG.md +14 -0
- package/skills/elementum-ui/SKILL.md +21 -0
- package/src/ag-ui.js +474 -0
- package/src/behaviors/index.js +760 -0
- package/src/components/el-accordion.js +201 -0
- package/src/components/el-alert-dialog.js +186 -0
- package/src/components/el-alert.js +254 -0
- package/src/components/el-aspect-ratio.js +73 -0
- package/src/components/el-autocomplete.js +775 -0
- package/src/components/el-avatar.js +271 -0
- package/src/components/el-badge.js +131 -0
- package/src/components/el-border-beam.js +135 -0
- package/src/components/el-breadcrumb.js +203 -0
- package/src/components/el-button.js +231 -0
- package/src/components/el-calendar.js +436 -0
- package/src/components/el-callout.js +158 -0
- package/src/components/el-card.js +298 -0
- package/src/components/el-carousel.js +308 -0
- package/src/components/el-chart.js +632 -0
- package/src/components/el-checkbox-card.js +221 -0
- package/src/components/el-checkbox.js +208 -0
- package/src/components/el-chip.js +276 -0
- package/src/components/el-code-block.js +230 -0
- package/src/components/el-collapsible.js +124 -0
- package/src/components/el-command.js +556 -0
- package/src/components/el-context-menu.js +328 -0
- package/src/components/el-data-list.js +210 -0
- package/src/components/el-datepicker.js +192 -0
- package/src/components/el-dialog.js +272 -0
- package/src/components/el-diff-viewer.js +441 -0
- package/src/components/el-drawer.js +782 -0
- package/src/components/el-dropdown.js +182 -0
- package/src/components/el-dropzone.js +242 -0
- package/src/components/el-empty-state.js +130 -0
- package/src/components/el-field.js +394 -0
- package/src/components/el-form.js +185 -0
- package/src/components/el-input.js +229 -0
- package/src/components/el-inset.js +90 -0
- package/src/components/el-insight-card.js +263 -0
- package/src/components/el-kbd.js +151 -0
- package/src/components/el-menubar.js +254 -0
- package/src/components/el-meter.js +183 -0
- package/src/components/el-navbar.js +294 -0
- package/src/components/el-navigation-menu.js +327 -0
- package/src/components/el-number-field.js +510 -0
- package/src/components/el-number-flow.js +164 -0
- package/src/components/el-otp-input.js +266 -0
- package/src/components/el-pagination.js +231 -0
- package/src/components/el-popover.js +288 -0
- package/src/components/el-preview-card.js +202 -0
- package/src/components/el-progress.js +179 -0
- package/src/components/el-prompt-input.js +383 -0
- package/src/components/el-radio-card.js +360 -0
- package/src/components/el-radio.js +257 -0
- package/src/components/el-rating.js +165 -0
- package/src/components/el-reasoning-card.js +293 -0
- package/src/components/el-resizable.js +324 -0
- package/src/components/el-router.js +305 -0
- package/src/components/el-scroll-area.js +150 -0
- package/src/components/el-segmented-control.js +282 -0
- package/src/components/el-select.js +220 -0
- package/src/components/el-separator.js +85 -0
- package/src/components/el-sidebar.js +386 -0
- package/src/components/el-skeleton.js +156 -0
- package/src/components/el-slider.js +351 -0
- package/src/components/el-sources.js +288 -0
- package/src/components/el-spinner.js +159 -0
- package/src/components/el-streaming-text.js +199 -0
- package/src/components/el-switch.js +221 -0
- package/src/components/el-table.js +397 -0
- package/src/components/el-tabs.js +235 -0
- package/src/components/el-task-list.js +230 -0
- package/src/components/el-textarea.js +175 -0
- package/src/components/el-theme-switch.js +120 -0
- package/src/components/el-timeline.js +254 -0
- package/src/components/el-toast.js +778 -0
- package/src/components/el-toggle.js +311 -0
- package/src/components/el-tool-call.js +386 -0
- package/src/components/el-toolbar.js +183 -0
- package/src/components/el-tooltip.js +172 -0
- package/src/components/el-tree-view.js +261 -0
- package/src/components/el-visually-hidden.js +32 -0
- package/src/elementum.js +504 -0
- package/src/index.d.ts +1093 -0
- package/src/index.js +112 -0
- package/src/signal.js +215 -0
- package/src/ssr.js +136 -0
- package/src/template.js +321 -0
- package/src/tokens.css +416 -0
- package/tokens/figma-tokens.json +69 -0
- package/tokens/penpot-tokens.json +98 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { Elementum } from '../elementum.js';
|
|
2
|
+
import { html, css } from '../template.js';
|
|
3
|
+
import { signal } from '../signal.js';
|
|
4
|
+
|
|
5
|
+
function getInitials(name = '') {
|
|
6
|
+
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
7
|
+
if (!parts.length) return '';
|
|
8
|
+
if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
|
|
9
|
+
return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class ElAvatar extends Elementum {
|
|
13
|
+
static observedAttributes = ['src', 'alt', 'name', 'size', 'shape', 'status'];
|
|
14
|
+
|
|
15
|
+
src = signal('');
|
|
16
|
+
alt = signal('');
|
|
17
|
+
name = signal('');
|
|
18
|
+
size = signal('md'); // 'sm' | 'md' | 'lg'
|
|
19
|
+
shape = signal('circle'); // 'circle' | 'square'
|
|
20
|
+
status = signal(''); // 'online' | 'offline' | 'busy' | 'away'
|
|
21
|
+
#imageError = signal(false);
|
|
22
|
+
|
|
23
|
+
connected() {
|
|
24
|
+
this.#sync();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
attributeChanged(name, oldValue, newValue) {
|
|
28
|
+
if (name === 'src') {
|
|
29
|
+
this.#imageError.value = false;
|
|
30
|
+
}
|
|
31
|
+
this.#sync();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#sync() {
|
|
35
|
+
this.src.value = this.getAttribute('src') || '';
|
|
36
|
+
this.alt.value = this.getAttribute('alt') || '';
|
|
37
|
+
this.name.value = this.getAttribute('name') || '';
|
|
38
|
+
this.size.value = this.getAttribute('size') || 'md';
|
|
39
|
+
this.shape.value = this.getAttribute('shape') || 'circle';
|
|
40
|
+
this.status.value = this.getAttribute('status') || '';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static styles = css`
|
|
44
|
+
:host {
|
|
45
|
+
display: inline-flex;
|
|
46
|
+
flex-shrink: 0;
|
|
47
|
+
position: relative;
|
|
48
|
+
vertical-align: middle;
|
|
49
|
+
box-sizing: border-box;
|
|
50
|
+
user-select: none;
|
|
51
|
+
border-radius: var(--el-radius-full, 9999px);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
:host([shape="square"]) {
|
|
55
|
+
border-radius: var(--el-radius-md, 8px);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.avatar {
|
|
59
|
+
display: flex;
|
|
60
|
+
align-items: center;
|
|
61
|
+
justify-content: center;
|
|
62
|
+
position: relative;
|
|
63
|
+
overflow: hidden;
|
|
64
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
65
|
+
color: var(--el-text-primary, #0f172a);
|
|
66
|
+
font-weight: 600;
|
|
67
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
68
|
+
border: 1px solid var(--el-surface-border, #e2e8f0);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.shape-circle {
|
|
72
|
+
border-radius: var(--el-radius-full, 9999px);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.shape-square {
|
|
76
|
+
border-radius: var(--el-radius-md, 8px);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Sizes */
|
|
80
|
+
.size-sm {
|
|
81
|
+
width: 28px;
|
|
82
|
+
height: 28px;
|
|
83
|
+
font-size: 11px;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.size-md {
|
|
87
|
+
width: 38px;
|
|
88
|
+
height: 38px;
|
|
89
|
+
font-size: 14px;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.size-lg {
|
|
93
|
+
width: 48px;
|
|
94
|
+
height: 48px;
|
|
95
|
+
font-size: 18px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.size-xl {
|
|
99
|
+
width: 56px;
|
|
100
|
+
height: 56px;
|
|
101
|
+
font-size: 20px;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
img {
|
|
105
|
+
width: 100%;
|
|
106
|
+
height: 100%;
|
|
107
|
+
object-fit: cover;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* Status dot */
|
|
111
|
+
.status-dot {
|
|
112
|
+
position: absolute;
|
|
113
|
+
bottom: 0;
|
|
114
|
+
right: 0;
|
|
115
|
+
width: 10px;
|
|
116
|
+
height: 10px;
|
|
117
|
+
border-radius: var(--el-radius-full, 9999px);
|
|
118
|
+
border: 2px solid var(--el-surface-card, #ffffff);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.size-lg .status-dot,
|
|
122
|
+
.size-xl .status-dot {
|
|
123
|
+
width: 12px;
|
|
124
|
+
height: 12px;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.status-online {
|
|
128
|
+
background: var(--el-color-success, #10b981);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.status-busy {
|
|
132
|
+
background: var(--el-color-danger, #ef4444);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.status-away {
|
|
136
|
+
background: #f59e0b;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.status-offline {
|
|
140
|
+
background: var(--el-text-muted, #94a3b8);
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
|
|
144
|
+
#onImageError = () => {
|
|
145
|
+
this.#imageError.value = true;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
render() {
|
|
149
|
+
const showImage = () => Boolean(this.src.value) && !this.#imageError.value;
|
|
150
|
+
const initials = () => getInitials(this.name.value);
|
|
151
|
+
|
|
152
|
+
return html`
|
|
153
|
+
<div
|
|
154
|
+
class=${() => `avatar size-${this.size.value} shape-${this.shape.value}`}
|
|
155
|
+
part="avatar"
|
|
156
|
+
role="img"
|
|
157
|
+
aria-label=${() => this.alt.value || this.name.value || 'User avatar'}
|
|
158
|
+
>
|
|
159
|
+
${() =>
|
|
160
|
+
showImage()
|
|
161
|
+
? html`<img
|
|
162
|
+
src=${() => this.src.value}
|
|
163
|
+
alt=${() => this.alt.value || this.name.value}
|
|
164
|
+
@error=${this.#onImageError}
|
|
165
|
+
/>`
|
|
166
|
+
: html`<span part="initials">${initials() || '👤'}</span>`}
|
|
167
|
+
|
|
168
|
+
${() =>
|
|
169
|
+
this.status.value
|
|
170
|
+
? html`<span class=${() => `status-dot status-${this.status.value}`} part="status"></span>`
|
|
171
|
+
: null}
|
|
172
|
+
</div>
|
|
173
|
+
`;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export class ElAvatarGroup extends Elementum {
|
|
178
|
+
static observedAttributes = ['max'];
|
|
179
|
+
|
|
180
|
+
max = signal(0);
|
|
181
|
+
overflowCount = signal(0);
|
|
182
|
+
|
|
183
|
+
static styles = css`
|
|
184
|
+
:host {
|
|
185
|
+
display: inline-flex;
|
|
186
|
+
align-items: center;
|
|
187
|
+
box-sizing: border-box;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
::slotted(el-avatar) {
|
|
191
|
+
border-radius: var(--el-radius-full, 9999px);
|
|
192
|
+
position: relative;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
::slotted(el-avatar[shape="square"]) {
|
|
196
|
+
border-radius: var(--el-radius-md, 8px);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
::slotted(el-avatar:not(:first-child)) {
|
|
200
|
+
margin-left: var(--el-avatar-overlap, -10px);
|
|
201
|
+
box-shadow: 0 0 0 2px var(--el-surface-card, #ffffff);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
::slotted(el-avatar:hover) {
|
|
205
|
+
z-index: 10;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.overflow-badge {
|
|
209
|
+
display: inline-flex;
|
|
210
|
+
align-items: center;
|
|
211
|
+
justify-content: center;
|
|
212
|
+
width: 38px;
|
|
213
|
+
height: 38px;
|
|
214
|
+
margin-left: var(--el-avatar-overlap, -10px);
|
|
215
|
+
border-radius: var(--el-radius-full, 9999px);
|
|
216
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
217
|
+
color: var(--el-text-primary, #0f172a);
|
|
218
|
+
border: 1px solid var(--el-surface-border, #e2e8f0);
|
|
219
|
+
box-shadow: 0 0 0 2px var(--el-surface-card, #ffffff);
|
|
220
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
221
|
+
font-size: 12px;
|
|
222
|
+
font-weight: 600;
|
|
223
|
+
position: relative;
|
|
224
|
+
z-index: 5;
|
|
225
|
+
}
|
|
226
|
+
`;
|
|
227
|
+
|
|
228
|
+
connected() {
|
|
229
|
+
this.#syncMax();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
attributeChanged(name, oldValue, newValue) {
|
|
233
|
+
if (name === 'max') {
|
|
234
|
+
this.#syncMax();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
#syncMax() {
|
|
239
|
+
const raw = parseInt(this.getAttribute('max') || '0', 10);
|
|
240
|
+
const maxVal = Number.isFinite(raw) && raw > 0 ? raw : 0;
|
|
241
|
+
this.max.value = maxVal;
|
|
242
|
+
|
|
243
|
+
const avatars = Array.from(this.querySelectorAll('el-avatar'));
|
|
244
|
+
if (maxVal > 0 && avatars.length > maxVal) {
|
|
245
|
+
avatars.forEach((av, idx) => {
|
|
246
|
+
av.style.display = idx < maxVal ? '' : 'none';
|
|
247
|
+
});
|
|
248
|
+
this.overflowCount.value = avatars.length - maxVal;
|
|
249
|
+
} else {
|
|
250
|
+
avatars.forEach((av) => {
|
|
251
|
+
av.style.display = '';
|
|
252
|
+
});
|
|
253
|
+
this.overflowCount.value = 0;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
render() {
|
|
258
|
+
return html`
|
|
259
|
+
<slot @slotchange=${() => this.#syncMax()}></slot>
|
|
260
|
+
${() =>
|
|
261
|
+
this.overflowCount.value > 0
|
|
262
|
+
? html`<span class="overflow-badge" part="overflow">+${() => this.overflowCount.value}</span>`
|
|
263
|
+
: null}
|
|
264
|
+
`;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (typeof customElements !== 'undefined') {
|
|
269
|
+
if (!customElements.get('el-avatar')) customElements.define('el-avatar', ElAvatar);
|
|
270
|
+
if (!customElements.get('el-avatar-group')) customElements.define('el-avatar-group', ElAvatarGroup);
|
|
271
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-badge>
|
|
3
|
+
* Minimal status indicator and notification badge.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Elementum } from '../elementum.js';
|
|
7
|
+
import { html, css } from '../template.js';
|
|
8
|
+
import { signal } from '../signal.js';
|
|
9
|
+
|
|
10
|
+
export class ElBadge extends Elementum {
|
|
11
|
+
static observedAttributes = ['variant', 'count', 'label', 'size'];
|
|
12
|
+
|
|
13
|
+
variant = signal('default'); // 'default' | 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'outline'
|
|
14
|
+
count = signal('');
|
|
15
|
+
label = signal('');
|
|
16
|
+
size = signal('md');
|
|
17
|
+
|
|
18
|
+
connected() {
|
|
19
|
+
if (this.hasAttribute('label')) this.label.value = this.getAttribute('label');
|
|
20
|
+
if (this.hasAttribute('count')) this.count.value = this.getAttribute('count');
|
|
21
|
+
if (this.hasAttribute('variant')) this.variant.value = this.getAttribute('variant');
|
|
22
|
+
if (this.hasAttribute('size')) this.size.value = this.getAttribute('size');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
attributeChanged(name, oldValue, newValue) {
|
|
26
|
+
if (name === 'label') {
|
|
27
|
+
this.label.value = newValue || '';
|
|
28
|
+
} else if (name === 'count') {
|
|
29
|
+
this.count.value = newValue || '';
|
|
30
|
+
} else if (name === 'variant') {
|
|
31
|
+
this.variant.value = newValue || 'default';
|
|
32
|
+
} else if (name === 'size') {
|
|
33
|
+
this.size.value = newValue || 'md';
|
|
34
|
+
} else if (name in this) {
|
|
35
|
+
this[name].value = newValue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static styles = css`
|
|
40
|
+
:host {
|
|
41
|
+
display: inline-flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
vertical-align: middle;
|
|
44
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
span {
|
|
48
|
+
display: inline-flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
justify-content: center;
|
|
51
|
+
padding: 2px 8px;
|
|
52
|
+
font-size: 0.75rem;
|
|
53
|
+
font-weight: 600;
|
|
54
|
+
border-radius: var(--el-radius-full, 9999px);
|
|
55
|
+
line-height: 1.2;
|
|
56
|
+
box-sizing: border-box;
|
|
57
|
+
transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease, transform 120ms ease;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
:host([variant="default"]) span,
|
|
61
|
+
:host(:not([variant])) span {
|
|
62
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
63
|
+
color: var(--el-text-primary, #0f172a);
|
|
64
|
+
border: 1px solid var(--el-surface-border, #e2e8f0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:host([variant="primary"]) span {
|
|
68
|
+
background: var(--el-color-primary, #2563eb);
|
|
69
|
+
color: #ffffff;
|
|
70
|
+
border: 1px solid transparent;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
:host([variant="secondary"]) span {
|
|
74
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
75
|
+
color: var(--el-text-muted, #475569);
|
|
76
|
+
border: 1px solid var(--el-surface-border, #cbd5e1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
:host([variant="success"]) span {
|
|
80
|
+
background: #dcfce7;
|
|
81
|
+
color: #15803d;
|
|
82
|
+
border: 1px solid rgba(21, 128, 61, 0.25);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
:host([variant="danger"]) span {
|
|
86
|
+
background: #fee2e2;
|
|
87
|
+
color: #b91c1c;
|
|
88
|
+
border: 1px solid rgba(185, 28, 28, 0.25);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
:host([variant="warning"]) span {
|
|
92
|
+
background: #fef3c7;
|
|
93
|
+
color: #92400e;
|
|
94
|
+
border: 1px solid rgba(146, 64, 14, 0.25);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
:host([variant="info"]) span {
|
|
98
|
+
background: #e0f2fe;
|
|
99
|
+
color: #0369a1;
|
|
100
|
+
border: 1px solid rgba(3, 105, 161, 0.25);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
:host([variant="outline"]) span {
|
|
104
|
+
background: transparent;
|
|
105
|
+
color: var(--el-text-primary, #0f172a);
|
|
106
|
+
border: 1px solid var(--el-surface-border, #cbd5e1);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
:host([size="sm"]) span {
|
|
110
|
+
padding: 1px 6px;
|
|
111
|
+
font-size: 0.6875rem;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
:host([size="lg"]) span {
|
|
115
|
+
padding: 4px 12px;
|
|
116
|
+
font-size: 0.875rem;
|
|
117
|
+
}
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
render() {
|
|
121
|
+
return html`
|
|
122
|
+
<span part="badge">
|
|
123
|
+
<slot>${() => this.label.value || this.count.value || 'Badge'}</slot>
|
|
124
|
+
</span>
|
|
125
|
+
`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-badge')) {
|
|
130
|
+
customElements.define('el-badge', ElBadge);
|
|
131
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Elementum } from '../elementum.js';
|
|
2
|
+
import { html, css } from '../template.js';
|
|
3
|
+
import { signal } from '../signal.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* <el-border-beam>
|
|
7
|
+
* Magic UI & Aceternity-inspired luminous border highlight that travels around the perimeter of any parent container.
|
|
8
|
+
* Uses hardware-accelerated CSS conic rotation with mask clipping. Zero JS runtime loops.
|
|
9
|
+
*
|
|
10
|
+
* @element el-border-beam
|
|
11
|
+
* @attr {number} size - Length/spread of the beam in degrees or pixels (default: 60)
|
|
12
|
+
* @attr {number} duration - Full rotation loop duration in seconds (default: 8)
|
|
13
|
+
* @attr {string} color-from - Starting gradient color (default: var(--el-color-primary, #2563eb))
|
|
14
|
+
* @attr {string} color-to - Ending gradient color (default: var(--el-color-accent, #a855f7))
|
|
15
|
+
* @attr {number} border-width - Thickness of the border beam line in px (default: 1.5)
|
|
16
|
+
* @attr {boolean} reverse - Reverse clockwise direction
|
|
17
|
+
*/
|
|
18
|
+
export class ElBorderBeam extends Elementum {
|
|
19
|
+
static observedAttributes = ['size', 'duration', 'color-from', 'color-to', 'border-width', 'reverse'];
|
|
20
|
+
|
|
21
|
+
size = signal(60);
|
|
22
|
+
duration = signal(8);
|
|
23
|
+
colorFrom = signal('var(--el-color-primary, #2563eb)');
|
|
24
|
+
colorTo = signal('var(--el-color-accent, #a855f7)');
|
|
25
|
+
borderWidth = signal(1.5);
|
|
26
|
+
reverse = signal(false);
|
|
27
|
+
|
|
28
|
+
connected() {
|
|
29
|
+
this.#syncAttributes();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
attributeChangedCallback() {
|
|
33
|
+
this.#syncAttributes();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#syncAttributes() {
|
|
37
|
+
if (this.hasAttribute('size')) {
|
|
38
|
+
this.size.value = parseFloat(this.getAttribute('size')) || 60;
|
|
39
|
+
}
|
|
40
|
+
if (this.hasAttribute('duration')) {
|
|
41
|
+
this.duration.value = parseFloat(this.getAttribute('duration')) || 8;
|
|
42
|
+
}
|
|
43
|
+
if (this.hasAttribute('color-from')) {
|
|
44
|
+
this.colorFrom.value = this.getAttribute('color-from');
|
|
45
|
+
}
|
|
46
|
+
if (this.hasAttribute('color-to')) {
|
|
47
|
+
this.colorTo.value = this.getAttribute('color-to');
|
|
48
|
+
}
|
|
49
|
+
if (this.hasAttribute('border-width')) {
|
|
50
|
+
this.borderWidth.value = parseFloat(this.getAttribute('border-width')) || 1.5;
|
|
51
|
+
}
|
|
52
|
+
this.reverse.value = this.hasAttribute('reverse');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static styles = css`
|
|
56
|
+
:host {
|
|
57
|
+
position: absolute;
|
|
58
|
+
inset: 0;
|
|
59
|
+
border-radius: inherit;
|
|
60
|
+
pointer-events: none;
|
|
61
|
+
overflow: hidden;
|
|
62
|
+
display: block;
|
|
63
|
+
box-sizing: border-box;
|
|
64
|
+
z-index: 1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.beam-track {
|
|
68
|
+
position: absolute;
|
|
69
|
+
inset: 0;
|
|
70
|
+
border-radius: inherit;
|
|
71
|
+
padding: var(--beam-border-width, 1.5px);
|
|
72
|
+
box-sizing: border-box;
|
|
73
|
+
-webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
|
|
74
|
+
-webkit-mask-composite: xor;
|
|
75
|
+
mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
|
|
76
|
+
mask-composite: exclude;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.beam-spinner {
|
|
80
|
+
position: absolute;
|
|
81
|
+
top: 50%;
|
|
82
|
+
left: 50%;
|
|
83
|
+
width: 200%;
|
|
84
|
+
height: 200%;
|
|
85
|
+
transform: translate(-50%, -50%);
|
|
86
|
+
background: conic-gradient(
|
|
87
|
+
from 0deg,
|
|
88
|
+
transparent 0deg,
|
|
89
|
+
transparent calc(180deg - var(--beam-size, 60deg)),
|
|
90
|
+
var(--beam-color-from, #2563eb) calc(180deg - var(--beam-size, 60deg) / 2),
|
|
91
|
+
var(--beam-color-to, #a855f7) 180deg,
|
|
92
|
+
transparent calc(180deg + 15deg),
|
|
93
|
+
transparent 360deg
|
|
94
|
+
);
|
|
95
|
+
animation: beam-spin var(--beam-duration, 8s) linear infinite;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
:host([reverse]) .beam-spinner {
|
|
99
|
+
animation-direction: reverse;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@keyframes beam-spin {
|
|
103
|
+
from { transform: translate(-50%, -50%) rotate(0deg); }
|
|
104
|
+
to { transform: translate(-50%, -50%) rotate(360deg); }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@media (prefers-reduced-motion: reduce) {
|
|
108
|
+
.beam-spinner {
|
|
109
|
+
animation: none;
|
|
110
|
+
opacity: 0.4;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
render() {
|
|
116
|
+
return html`
|
|
117
|
+
<div
|
|
118
|
+
class="beam-track"
|
|
119
|
+
style=${() => `
|
|
120
|
+
--beam-size: ${this.size.value}deg;
|
|
121
|
+
--beam-duration: ${this.duration.value}s;
|
|
122
|
+
--beam-color-from: ${this.colorFrom.value};
|
|
123
|
+
--beam-color-to: ${this.colorTo.value};
|
|
124
|
+
--beam-border-width: ${this.borderWidth.value}px;
|
|
125
|
+
`}
|
|
126
|
+
>
|
|
127
|
+
<div class="beam-spinner"></div>
|
|
128
|
+
</div>
|
|
129
|
+
`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-border-beam')) {
|
|
134
|
+
customElements.define('el-border-beam', ElBorderBeam);
|
|
135
|
+
}
|