@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,485 @@
1
+ /**
2
+ * Elementum Base Class
3
+ * Ultra-lightweight custom element with shadow root, signal lifecycle, and styles adoption.
4
+ */
5
+
6
+ import { render, CSSResult, html, css } from './template.js';
7
+ import { signal, isSignal, effect } from './signal.js';
8
+
9
+ export { html, css };
10
+
11
+ const BaseElement = typeof HTMLElement !== 'undefined' ? HTMLElement : class {};
12
+
13
+ function toCamelCase(attr) {
14
+ return attr.replace(/-([a-z])/g, (_, ch) => ch.toUpperCase());
15
+ }
16
+
17
+ function toKebabCase(prop) {
18
+ return prop.replace(/[A-Z]/g, (ch) => `-${ch.toLowerCase()}`);
19
+ }
20
+
21
+ function hasCustomSubclassAccessor(instance, prop) {
22
+ let proto = Object.getPrototypeOf(instance);
23
+ while (proto && proto !== Elementum.prototype && proto !== BaseElement.prototype && proto !== Object.prototype) {
24
+ const desc = Object.getOwnPropertyDescriptor(proto, prop);
25
+ if (desc && (typeof desc.get === 'function' || typeof desc.set === 'function')) {
26
+ return true;
27
+ }
28
+ proto = Object.getPrototypeOf(proto);
29
+ }
30
+ return false;
31
+ }
32
+
33
+ export class Elementum extends BaseElement {
34
+ /**
35
+ * Set to false to disable Shadow DOM and render into Light DOM
36
+ */
37
+ static shadowRoot = true;
38
+
39
+ /**
40
+ * Set to true to participate in native HTML <form> submission & validation
41
+ */
42
+ static formAssociated = false;
43
+
44
+ /**
45
+ * CSSResult or array of CSSResults (created via css`...`)
46
+ */
47
+ static styles = null;
48
+
49
+ #abortController = null;
50
+ #mounted = false;
51
+ #syncingAttr = false;
52
+ #upgradedProps = new Set();
53
+ #reflectedSignals = new Set();
54
+ #boolAttrs = new Set();
55
+ #syntheticProps = new Set();
56
+ #signalEntries = [];
57
+ internals = null;
58
+ #validity = {
59
+ valid: true,
60
+ valueMissing: false,
61
+ typeMismatch: false,
62
+ patternMismatch: false,
63
+ tooLong: false,
64
+ tooShort: false,
65
+ rangeUnderflow: false,
66
+ rangeOverflow: false,
67
+ stepMismatch: false,
68
+ badInput: false,
69
+ customError: false,
70
+ };
71
+ #validationMessage = '';
72
+
73
+ constructor() {
74
+ super();
75
+ if (this.constructor.formAssociated && typeof this.attachInternals === 'function') {
76
+ this.internals = this.attachInternals();
77
+ }
78
+ queueMicrotask(() => this.#setupReactiveProperties());
79
+ }
80
+
81
+ setFormValue(value) {
82
+ if (this.internals && typeof this.internals.setFormValue === 'function') {
83
+ this.internals.setFormValue(value);
84
+ }
85
+ }
86
+
87
+ get validity() {
88
+ return this.internals?.validity || this.#validity;
89
+ }
90
+
91
+ get validationMessage() {
92
+ return this.internals?.validationMessage || this.#validationMessage;
93
+ }
94
+
95
+ get willValidate() {
96
+ return this.internals?.willValidate ?? true;
97
+ }
98
+
99
+ checkValidity() {
100
+ if (this.internals && typeof this.internals.checkValidity === 'function') {
101
+ return this.internals.checkValidity();
102
+ }
103
+ return this.validity.valid;
104
+ }
105
+
106
+ reportValidity() {
107
+ if (this.internals && typeof this.internals.reportValidity === 'function') {
108
+ return this.internals.reportValidity();
109
+ }
110
+ const isValid = this.checkValidity();
111
+ if (!isValid) {
112
+ this.dispatchEvent(new Event('invalid', { bubbles: false, cancelable: true }));
113
+ }
114
+ return isValid;
115
+ }
116
+
117
+ setValidity(flags = {}, message = '', anchor) {
118
+ const isInvalid = Object.values(flags).some(Boolean);
119
+ this.#validity = {
120
+ valid: !isInvalid,
121
+ valueMissing: !!flags.valueMissing,
122
+ typeMismatch: !!flags.typeMismatch,
123
+ patternMismatch: !!flags.patternMismatch,
124
+ tooLong: !!flags.tooLong,
125
+ tooShort: !!flags.tooShort,
126
+ rangeUnderflow: !!flags.rangeUnderflow,
127
+ rangeOverflow: !!flags.rangeOverflow,
128
+ stepMismatch: !!flags.stepMismatch,
129
+ badInput: !!flags.badInput,
130
+ customError: !!flags.customError,
131
+ };
132
+ this.#validationMessage = message || '';
133
+
134
+ if (this.internals && typeof this.internals.setValidity === 'function') {
135
+ if (anchor && typeof HTMLElement !== 'undefined' && anchor instanceof HTMLElement) {
136
+ this.internals.setValidity(flags, message, anchor);
137
+ } else {
138
+ this.internals.setValidity(flags, message);
139
+ }
140
+ }
141
+ }
142
+
143
+ setCustomValidity(message = '') {
144
+ if (message) {
145
+ this.setValidity({ customError: true }, message);
146
+ } else {
147
+ this.setValidity({});
148
+ }
149
+ }
150
+
151
+ formResetCallback() {
152
+ if (typeof this.formReset === 'function') {
153
+ this.formReset();
154
+ }
155
+ }
156
+
157
+ formDisabledCallback(disabled) {
158
+ if (typeof this.formDisabled === 'function') {
159
+ this.formDisabled(disabled);
160
+ }
161
+ }
162
+
163
+ get signal() {
164
+ return this.#abortController?.signal;
165
+ }
166
+
167
+ #reflectToAttribute(attrName, val, initialBoolDefault = false) {
168
+ if (this.#syncingAttr || !attrName) return;
169
+ if (typeof val === 'object' && val !== null) return;
170
+ if (this.constructor.formAssociated && (attrName === 'value' || attrName === 'checked')) return;
171
+
172
+ if (typeof val === 'boolean' || initialBoolDefault) {
173
+ const boolVal = typeof val === 'boolean' ? val : (val === 'false' ? false : Boolean(val));
174
+ if (boolVal) {
175
+ if (!this.hasAttribute(attrName) || this.getAttribute(attrName) === 'false') {
176
+ this.setAttribute(attrName, '');
177
+ }
178
+ } else if (this.hasAttribute(attrName)) {
179
+ this.removeAttribute(attrName);
180
+ }
181
+ return;
182
+ }
183
+
184
+ if (val === null || val === undefined) {
185
+ if (this.hasAttribute(attrName)) {
186
+ this.removeAttribute(attrName);
187
+ }
188
+ return;
189
+ }
190
+
191
+ const strVal = String(val);
192
+ if (this.getAttribute(attrName) !== strVal) {
193
+ this.setAttribute(attrName, strVal);
194
+ }
195
+ }
196
+
197
+ #getMappedAttrValue(attr) {
198
+ if (!this.hasAttribute(attr)) {
199
+ return this.#boolAttrs.has(attr) ? false : null;
200
+ }
201
+ const val = this.getAttribute(attr);
202
+ if (this.#boolAttrs.has(attr)) {
203
+ return val !== 'false';
204
+ }
205
+ return val;
206
+ }
207
+
208
+ #syncAttributeToProperty(attr, rawVal) {
209
+ const camel = toCamelCase(attr);
210
+ const propKey = (camel !== attr && camel in this) ? camel : attr;
211
+ if (!(propKey in this)) return;
212
+ if (typeof this[propKey] === 'function' || this.#syntheticProps.has(propKey)) return;
213
+
214
+ const current = this[propKey];
215
+ const isBool = this.#boolAttrs.has(attr) ||
216
+ (isSignal(current) ? typeof current.peek() === 'boolean' : typeof current === 'boolean');
217
+ const mappedVal = isBool ? (rawVal !== null && rawVal !== 'false') : rawVal;
218
+
219
+ if (isSignal(current)) {
220
+ current.value = mappedVal;
221
+ } else {
222
+ this[propKey] = mappedVal;
223
+ }
224
+ }
225
+
226
+ #defineSignalProperty(propKey, attrName, sig, isBool, initialVal) {
227
+ if (isBool && attrName) {
228
+ this.#boolAttrs.add(attrName);
229
+ }
230
+
231
+ this.#upgradedProps.add(propKey);
232
+ if (attrName) {
233
+ this.#signalEntries.push({ attrName, sig, isBool, initialVal });
234
+ }
235
+
236
+ Object.defineProperty(this, propKey, {
237
+ configurable: true,
238
+ enumerable: true,
239
+ get: () => sig,
240
+ set: (val) => {
241
+ if (isSignal(val)) return;
242
+ sig.value = val;
243
+ if (attrName) {
244
+ this.#reflectToAttribute(attrName, val, isBool);
245
+ }
246
+ },
247
+ });
248
+ }
249
+
250
+ #setupReactiveProperties() {
251
+ const observed = this.constructor.observedAttributes;
252
+ const observedSet = Array.isArray(observed) ? new Set(observed) : null;
253
+
254
+ // 1. Upgrade own Signal properties into two-way reactive accessors
255
+ for (const propKey of Object.keys(this)) {
256
+ if (propKey.startsWith('_') || this.#upgradedProps.has(propKey)) continue;
257
+ if (hasCustomSubclassAccessor(this, propKey)) continue;
258
+
259
+ const desc = Object.getOwnPropertyDescriptor(this, propKey);
260
+ if (!desc || !desc.configurable || !('value' in desc) || !isSignal(desc.value)) {
261
+ continue;
262
+ }
263
+
264
+ const sig = desc.value;
265
+ const initialVal = sig.peek();
266
+ const isBool = typeof initialVal === 'boolean';
267
+ const kebab = toKebabCase(propKey);
268
+ const attrName = observedSet
269
+ ? (observedSet.has(propKey) ? propKey : (observedSet.has(kebab) ? kebab : null))
270
+ : null;
271
+
272
+ this.#defineSignalProperty(propKey, attrName, sig, isBool, initialVal);
273
+ }
274
+
275
+ // 2. Ensure remaining observedAttributes have reactive property accessors
276
+ if (!observedSet) return;
277
+ for (const attr of observedSet) {
278
+ const camel = toCamelCase(attr);
279
+ const propKey = (attr in this && !(camel in this)) ? attr : camel;
280
+
281
+ if (this.#upgradedProps.has(propKey) || this.#upgradedProps.has(attr)) continue;
282
+ if (hasCustomSubclassAccessor(this, propKey) || (propKey !== attr && hasCustomSubclassAccessor(this, attr))) {
283
+ continue;
284
+ }
285
+
286
+ const ownDesc = Object.getOwnPropertyDescriptor(this, propKey);
287
+ if (!ownDesc && propKey in BaseElement.prototype) {
288
+ continue;
289
+ }
290
+
291
+ if (ownDesc && !ownDesc.configurable) continue;
292
+ if (ownDesc && !('value' in ownDesc)) continue;
293
+
294
+ if (typeof this[propKey] === 'function') {
295
+ const origMethod = this[propKey];
296
+ this.#upgradedProps.add(propKey);
297
+ this.#boolAttrs.add(attr);
298
+ Object.defineProperty(this, propKey, {
299
+ configurable: true,
300
+ enumerable: true,
301
+ get: () => origMethod,
302
+ set: (val) => {
303
+ const boolVal = typeof val === 'boolean' ? val : (val === 'false' ? false : Boolean(val));
304
+ this.#reflectToAttribute(attr, boolVal, true);
305
+ },
306
+ });
307
+ continue;
308
+ }
309
+
310
+ // Reconstruct Signal when a pre-mount synchronous assignment overwrote a field before microtask setup
311
+ const hasInitialOwnValue = Boolean(ownDesc && 'value' in ownDesc);
312
+ if (hasInitialOwnValue) {
313
+ const initialVal = ownDesc.value;
314
+ const sig = signal(initialVal);
315
+ const isBool = typeof initialVal === 'boolean';
316
+ this.#defineSignalProperty(propKey, attr, sig, isBool, initialVal);
317
+ if (initialVal !== undefined && !this.hasAttribute(attr)) {
318
+ this.#reflectToAttribute(attr, initialVal, isBool);
319
+ }
320
+ continue;
321
+ }
322
+
323
+ this.#upgradedProps.add(propKey);
324
+ this.#syntheticProps.add(propKey);
325
+
326
+ Object.defineProperty(this, propKey, {
327
+ configurable: true,
328
+ enumerable: true,
329
+ get: () => this.#getMappedAttrValue(attr),
330
+ set: (val) => {
331
+ if (typeof val === 'boolean') {
332
+ this.#boolAttrs.add(attr);
333
+ }
334
+ this.#reflectToAttribute(attr, val, this.#boolAttrs.has(attr));
335
+ },
336
+ });
337
+ }
338
+ }
339
+
340
+ #setupAttributeReflection() {
341
+ if (!this.#abortController) return;
342
+ for (const { attrName, sig, isBool, initialVal } of this.#signalEntries) {
343
+ if (!attrName || this.#reflectedSignals.has(sig)) continue;
344
+ this.#reflectedSignals.add(sig);
345
+
346
+ let initialized = false;
347
+ effect(() => {
348
+ const val = sig.value;
349
+ if (!initialized) {
350
+ initialized = true;
351
+ if (val !== initialVal && !this.hasAttribute(attrName)) {
352
+ this.#reflectToAttribute(attrName, val, isBool);
353
+ }
354
+ return;
355
+ }
356
+ this.#reflectToAttribute(attrName, val, isBool);
357
+ }, { signal: this.#abortController.signal });
358
+ }
359
+ }
360
+
361
+ connectedCallback() {
362
+ this.#abortController = new AbortController();
363
+
364
+ // 1. Shadow Root initialization
365
+ if (this.constructor.shadowRoot !== false) {
366
+ if (!this.shadowRoot) {
367
+ this.attachShadow({ mode: 'open' });
368
+ }
369
+ this.root = this.shadowRoot;
370
+
371
+ // 2. Adopt Constructable Stylesheets
372
+ if (this.constructor.styles) {
373
+ const rawStyles = Array.isArray(this.constructor.styles)
374
+ ? this.constructor.styles
375
+ : [this.constructor.styles];
376
+
377
+ const sheets = [];
378
+ const fallbackStyles = [];
379
+
380
+ for (const s of rawStyles) {
381
+ if (s instanceof CSSResult && s.sheet) {
382
+ sheets.push(s.sheet);
383
+ } else {
384
+ fallbackStyles.push(String(s));
385
+ }
386
+ }
387
+
388
+ if (sheets.length > 0 && typeof Document !== 'undefined' && 'adoptedStyleSheets' in Document.prototype) {
389
+ this.shadowRoot.adoptedStyleSheets = sheets;
390
+ }
391
+
392
+ if (fallbackStyles.length > 0) {
393
+ const styleEl = document.createElement('style');
394
+ styleEl.textContent = fallbackStyles.join('\n');
395
+ this.shadowRoot.appendChild(styleEl);
396
+ }
397
+ }
398
+ } else {
399
+ this.root = this;
400
+ }
401
+
402
+ // 3. Ensure reactive properties are initialized before syncing attributes or rendering
403
+ this.#setupReactiveProperties();
404
+
405
+ // Sync initial HTML attributes into signals or properties
406
+ const observed = this.constructor.observedAttributes;
407
+ if (Array.isArray(observed)) {
408
+ this.#syncingAttr = true;
409
+ try {
410
+ for (const attr of observed) {
411
+ if (this.hasAttribute(attr)) {
412
+ this.#syncAttributeToProperty(attr, this.getAttribute(attr));
413
+ }
414
+ }
415
+ } finally {
416
+ this.#syncingAttr = false;
417
+ }
418
+ }
419
+
420
+ // 4. User lifecycle hook
421
+ if (typeof this.connected === 'function') {
422
+ this.connected();
423
+ }
424
+
425
+ // Reflect signal updates back to host HTML attributes while connected
426
+ this.#setupAttributeReflection();
427
+
428
+ // 5. Initial Render
429
+ if (typeof this.render === 'function') {
430
+ const templateResult = this.render();
431
+ if (templateResult) {
432
+ render(templateResult, this.root, this.#abortController.signal);
433
+ }
434
+ }
435
+
436
+ this.#mounted = true;
437
+
438
+ if (typeof this.rendered === 'function') {
439
+ this.rendered();
440
+ }
441
+ }
442
+
443
+ disconnectedCallback() {
444
+ if (this.#abortController) {
445
+ this.#abortController.abort();
446
+ }
447
+ this.#reflectedSignals.clear();
448
+ this.#mounted = false;
449
+
450
+ if (typeof this.disconnected === 'function') {
451
+ this.disconnected();
452
+ }
453
+ }
454
+
455
+ attributeChangedCallback(name, oldValue, newValue) {
456
+ if (oldValue === newValue) return;
457
+
458
+ this.#syncingAttr = true;
459
+ try {
460
+ if (typeof this.attributeChanged === 'function') {
461
+ this.attributeChanged(name, oldValue, newValue);
462
+ return;
463
+ }
464
+
465
+ // Sync attribute changes directly into matching signals or properties
466
+ this.#syncAttributeToProperty(name, newValue);
467
+ } finally {
468
+ this.#syncingAttr = false;
469
+ }
470
+ }
471
+
472
+ /**
473
+ * Helper to dispatch standard bubbling, composed CustomEvents
474
+ */
475
+ emit(eventName, detail = null, options = {}) {
476
+ return this.dispatchEvent(
477
+ new CustomEvent(eventName, {
478
+ bubbles: true,
479
+ composed: true,
480
+ detail,
481
+ ...options,
482
+ })
483
+ );
484
+ }
485
+ }