@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
package/src/index.js ADDED
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Elementum Public API
3
+ */
4
+
5
+ export { Elementum } from './elementum.js';
6
+ export { html, svg, css, render, CSSResult, TemplateResult } from './template.js';
7
+ export { signal, computed, effect, isSignal, Signal, Computed } from './signal.js';
8
+
9
+ // Component Exports
10
+ export { ElButton } from './components/el-button.js';
11
+ export { ElBadge } from './components/el-badge.js';
12
+ export { ElInput } from './components/el-input.js';
13
+ export { ElDropdown } from './components/el-dropdown.js';
14
+ export { ElCalendar } from './components/el-calendar.js';
15
+ export { ElDatepicker } from './components/el-datepicker.js';
16
+ export { ElDialog } from './components/el-dialog.js';
17
+ export { ElTabs, ElTab } from './components/el-tabs.js';
18
+ export { ElSelect } from './components/el-select.js';
19
+ export { ElToaster, toast } from './components/el-toast.js';
20
+ export { ElThemeSwitch } from './components/el-theme-switch.js';
21
+ export { ElSwitch } from './components/el-switch.js';
22
+ export { ElTooltip } from './components/el-tooltip.js';
23
+ export { ElAccordion, ElAccordionItem } from './components/el-accordion.js';
24
+ export { ElTable } from './components/el-table.js';
25
+ export { ElProgress } from './components/el-progress.js';
26
+ export { ElSpinner } from './components/el-spinner.js';
27
+ export { ElAvatar, ElAvatarGroup } from './components/el-avatar.js';
28
+ export { ElDrawer } from './components/el-drawer.js';
29
+ export { ElSegmentedControl } from './components/el-segmented-control.js';
30
+ export { ElPagination } from './components/el-pagination.js';
31
+ export { ElChip } from './components/el-chip.js';
32
+ export { ElAutocomplete } from './components/el-autocomplete.js';
33
+ export { ElNumberFlow } from './components/el-number-flow.js';
34
+ export { ElOtpInput } from './components/el-otp-input.js';
35
+ export { ElCommand, ElCommandGroup, ElCommandItem } from './components/el-command.js';
36
+ export { ElPromptInput } from './components/el-prompt-input.js';
37
+ export { ElReasoningCard } from './components/el-reasoning-card.js';
38
+ export { ElBorderBeam } from './components/el-border-beam.js';
39
+ export { ElStreamingText } from './components/el-streaming-text.js';
40
+ export { ElChart } from './components/el-chart.js';
41
+ export { ElField } from './components/el-field.js';
42
+ export { ElNumberField } from './components/el-number-field.js';
43
+
44
+ // Base UI Primitives
45
+ export { ElSlider } from './components/el-slider.js';
46
+ export { ElPopover } from './components/el-popover.js';
47
+ export { ElCollapsible } from './components/el-collapsible.js';
48
+ export { ElScrollArea } from './components/el-scroll-area.js';
49
+ export { ElToggle, ElToggleGroup } from './components/el-toggle.js';
50
+ export { ElCheckbox } from './components/el-checkbox.js';
51
+ export { ElRadio, ElRadioGroup } from './components/el-radio.js';
52
+ export { ElPreviewCard } from './components/el-preview-card.js';
53
+ export { ElAlertDialog } from './components/el-alert-dialog.js';
54
+ export { ElSeparator } from './components/el-separator.js';
55
+ export { ElMeter } from './components/el-meter.js';
56
+ export { ElToolbar } from './components/el-toolbar.js';
57
+ export { ElContextMenu } from './components/el-context-menu.js';
58
+ export { ElMenubar } from './components/el-menubar.js';
59
+
60
+ // Base UI & shadcn/ui Complete Suite
61
+ export { ElSkeleton } from './components/el-skeleton.js';
62
+ export { ElBreadcrumb, ElBreadcrumbItem } from './components/el-breadcrumb.js';
63
+ export { ElKbd } from './components/el-kbd.js';
64
+ export { ElAlert } from './components/el-alert.js';
65
+ export { ElCard, ElCardHeader, ElCardTitle, ElCardDescription, ElCardContent, ElCardFooter } from './components/el-card.js';
66
+ export { ElAspectRatio } from './components/el-aspect-ratio.js';
67
+ export { ElTextarea } from './components/el-textarea.js';
68
+ export { ElResizable, ElResizablePanel, ElResizableHandle } from './components/el-resizable.js';
69
+ export { ElCarousel, ElCarouselSlide } from './components/el-carousel.js';
70
+ export { ElTimeline, ElTimelineItem } from './components/el-timeline.js';
71
+ export { ElTreeView, ElTreeItem } from './components/el-tree-view.js';
72
+ export { ElEmptyState } from './components/el-empty-state.js';
73
+ export { ElRating } from './components/el-rating.js';
74
+ export { ElDropzone } from './components/el-dropzone.js';
75
+ export { ElSidebar, ElSidebarHeader, ElSidebarContent, ElSidebarFooter, ElSidebarTrigger } from './components/el-sidebar.js';
76
+ export { ElForm, ElFieldset } from './components/el-form.js';
77
+
78
+ // Radix Primitives & SPA Architecture Suite
79
+ export { ElRouter, ElRoute, ElRouteLink, currentRoute, navigate } from './components/el-router.js';
80
+ export { ElCallout } from './components/el-callout.js';
81
+ export { ElDataList, ElDataListItem } from './components/el-data-list.js';
82
+ export { ElRadioCard, ElRadioCardGroup } from './components/el-radio-card.js';
83
+ export { ElCheckboxCard } from './components/el-checkbox-card.js';
84
+ export { ElNavigationMenu, ElNavigationMenuItem, ElNavigationMenuTrigger, ElNavigationMenuContent } from './components/el-navigation-menu.js';
85
+ export { ElInset } from './components/el-inset.js';
86
+ export { ElVisuallyHidden } from './components/el-visually-hidden.js';
87
+ export { ElNavbar } from './components/el-navbar.js';
88
+ export { ElCodeBlock } from './components/el-code-block.js';
89
+ export { ElToolCall } from './components/el-tool-call.js';
90
+ export { ElDiffViewer, computeLineDiff } from './components/el-diff-viewer.js';
91
+ export { ElSources } from './components/el-sources.js';
92
+ export { ElTaskList } from './components/el-task-list.js';
93
+ export { ElInsightCard } from './components/el-insight-card.js';
94
+
95
+ // AG-UI Protocol Adapter (Streaming Events, State Deltas, & Signal Bindings)
96
+ export { createAgUiStore, applyJsonPatch, getByPointer } from './ag-ui.js';
97
+
98
+ // Server-Side Rendering (Declarative Shadow DOM)
99
+ export { renderTemplateToString, renderComponentToDSD } from './ssr.js';
100
+ export {
101
+ setHostState,
102
+ isRTL,
103
+ formatLocaleNumber,
104
+ formatLocaleDate,
105
+ announce,
106
+ clearAnnouncer,
107
+ createPressBehavior,
108
+ createRovingFocus,
109
+ createDismissableLayer,
110
+ createSelectionBehavior,
111
+ createReorderBehavior,
112
+ } from './behaviors/index.js';
package/src/signal.js ADDED
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Elementum Micro-Signals
3
+ * Fine-grained reactive primitives in ~80 lines.
4
+ */
5
+
6
+ let activeEffect = null;
7
+ const effectStack = [];
8
+
9
+ export class Signal {
10
+ constructor(initialValue) {
11
+ this._value = initialValue;
12
+ this.subscribers = new Set();
13
+ }
14
+
15
+ get value() {
16
+ if (activeEffect) {
17
+ this.subscribers.add(activeEffect);
18
+ activeEffect.dependencies.add(this);
19
+ }
20
+ return this._value;
21
+ }
22
+
23
+ set value(newValue) {
24
+ if (!Object.is(this._value, newValue)) {
25
+ this._value = newValue;
26
+ // Copy subscribers set before iterating in case effects modify subscriptions
27
+ const subs = Array.from(this.subscribers);
28
+ for (const sub of subs) {
29
+ sub.run();
30
+ }
31
+ }
32
+ }
33
+
34
+ peek() {
35
+ return this._value;
36
+ }
37
+
38
+ subscribe(callback) {
39
+ return effect(() => {
40
+ callback(this.value);
41
+ });
42
+ }
43
+
44
+ valueOf() {
45
+ return this.value;
46
+ }
47
+
48
+ toString() {
49
+ return String(this.value);
50
+ }
51
+
52
+ [Symbol.toPrimitive](hint) {
53
+ if (hint === 'number') {
54
+ return Number(this.value);
55
+ }
56
+ return String(this.value);
57
+ }
58
+
59
+ toUpperCase() {
60
+ return String(this.value).toUpperCase();
61
+ }
62
+
63
+ toLowerCase() {
64
+ return String(this.value).toLowerCase();
65
+ }
66
+
67
+ trim() {
68
+ return String(this.value).trim();
69
+ }
70
+
71
+ slice(...args) {
72
+ return String(this.value).slice(...args);
73
+ }
74
+
75
+ substring(...args) {
76
+ return String(this.value).substring(...args);
77
+ }
78
+
79
+ includes(...args) {
80
+ return String(this.value).includes(...args);
81
+ }
82
+
83
+ indexOf(...args) {
84
+ return String(this.value).indexOf(...args);
85
+ }
86
+
87
+ startsWith(...args) {
88
+ return String(this.value).startsWith(...args);
89
+ }
90
+
91
+ endsWith(...args) {
92
+ return String(this.value).endsWith(...args);
93
+ }
94
+
95
+ get length() {
96
+ return String(this.value).length;
97
+ }
98
+ }
99
+
100
+ export function signal(initialValue) {
101
+ return new Signal(initialValue);
102
+ }
103
+
104
+ export function isSignal(val) {
105
+ return val instanceof Signal;
106
+ }
107
+
108
+ export class Computed extends Signal {
109
+ constructor(getter) {
110
+ super(undefined);
111
+ this._getter = getter;
112
+ this._dirty = true;
113
+ this._computing = false;
114
+ this._computedEffect = new ReactiveEffect(() => {
115
+ if (this._dirty) return;
116
+ this._dirty = true;
117
+ // Notify downstreams
118
+ const subs = Array.from(this.subscribers);
119
+ for (const sub of subs) {
120
+ sub.run();
121
+ }
122
+ });
123
+ }
124
+
125
+ #evaluate() {
126
+ if (this._computing) {
127
+ throw new Error('Circular dependency detected in computed signal');
128
+ }
129
+ this._computing = true;
130
+ effectStack.push(activeEffect);
131
+ activeEffect = this._computedEffect;
132
+ this._computedEffect.cleanup();
133
+ try {
134
+ this._value = this._getter();
135
+ this._dirty = false;
136
+ } finally {
137
+ activeEffect = effectStack.pop();
138
+ this._computing = false;
139
+ }
140
+ }
141
+
142
+ get value() {
143
+ if (this._dirty) {
144
+ this.#evaluate();
145
+ }
146
+ if (activeEffect) {
147
+ this.subscribers.add(activeEffect);
148
+ activeEffect.dependencies.add(this);
149
+ }
150
+ return this._value;
151
+ }
152
+
153
+ peek() {
154
+ if (this._dirty) {
155
+ this.#evaluate();
156
+ }
157
+ return this._value;
158
+ }
159
+ }
160
+
161
+ export function computed(getter) {
162
+ return new Computed(getter);
163
+ }
164
+
165
+ class ReactiveEffect {
166
+ constructor(fn) {
167
+ this.fn = fn;
168
+ this.dependencies = new Set();
169
+ this.active = true;
170
+ this._running = false;
171
+ }
172
+
173
+ run() {
174
+ if (!this.active || this._running) return;
175
+ this._running = true;
176
+ this.cleanup();
177
+ effectStack.push(activeEffect);
178
+ activeEffect = this;
179
+ try {
180
+ this.fn();
181
+ } finally {
182
+ activeEffect = effectStack.pop();
183
+ this._running = false;
184
+ }
185
+ }
186
+
187
+ cleanup() {
188
+ for (const dep of this.dependencies) {
189
+ dep.subscribers.delete(this);
190
+ }
191
+ this.dependencies.clear();
192
+ }
193
+
194
+ stop() {
195
+ this.active = false;
196
+ this.cleanup();
197
+ }
198
+ }
199
+
200
+ export function effect(fn, options = {}) {
201
+ const reactiveEffect = new ReactiveEffect(fn);
202
+ reactiveEffect.run();
203
+
204
+ const dispose = () => reactiveEffect.stop();
205
+
206
+ if (options.signal) {
207
+ if (options.signal.aborted) {
208
+ dispose();
209
+ } else {
210
+ options.signal.addEventListener('abort', dispose, { once: true });
211
+ }
212
+ }
213
+
214
+ return dispose;
215
+ }
package/src/ssr.js ADDED
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Declarative Shadow DOM (DSD) Server-Side Renderer for Elementum
3
+ * Emits zero-runtime HTML with <template shadowrootmode="open">
4
+ * for instant hydration in Next.js, Nuxt, Astro, and Node.js.
5
+ */
6
+
7
+ import { CSSResult, TemplateResult } from './template.js';
8
+ import { isSignal } from './signal.js';
9
+
10
+ function escapeHtml(str) {
11
+ if (typeof str !== 'string') return String(str ?? '');
12
+ return str
13
+ .replace(/&/g, '&amp;')
14
+ .replace(/</g, '&lt;')
15
+ .replace(/>/g, '&gt;')
16
+ .replace(/"/g, '&quot;')
17
+ .replace(/'/g, '&#39;');
18
+ }
19
+
20
+ /**
21
+ * Evaluates dynamic template values safely for SSR
22
+ */
23
+ function resolveValue(val) {
24
+ if (val === null || val === undefined) return '';
25
+ if (typeof val === 'function') {
26
+ try {
27
+ return resolveValue(val());
28
+ } catch {
29
+ return '';
30
+ }
31
+ }
32
+ if (isSignal(val)) {
33
+ return resolveValue(val.value);
34
+ }
35
+ if (Array.isArray(val)) {
36
+ return val.map(resolveValue).join('');
37
+ }
38
+ if (val instanceof TemplateResult) {
39
+ return renderTemplateToString(val);
40
+ }
41
+ return escapeHtml(String(val));
42
+ }
43
+
44
+ /**
45
+ * Renders an Elementum TemplateResult to an HTML string
46
+ */
47
+ export function renderTemplateToString(templateResult) {
48
+ if (!(templateResult instanceof TemplateResult)) {
49
+ return resolveValue(templateResult);
50
+ }
51
+
52
+ const { strings, values } = templateResult;
53
+ let html = '';
54
+
55
+ for (let i = 0; i < strings.length; i++) {
56
+ html += strings[i];
57
+ if (i < values.length) {
58
+ const val = values[i];
59
+ // 1. Skip @event= and on<event>= listeners in SSR (never invoke event handlers!)
60
+ if (typeof val === 'function' && /(?:@[\w.-]+|on[a-z]+)=\s*$/i.test(strings[i])) {
61
+ html = html.replace(/(?:@[\w.-]+|on[a-z]+)=\s*$/i, '');
62
+ continue;
63
+ }
64
+ // 2. Boolean ?attr= bindings: emit bare attribute if truthy, omit if falsy
65
+ const boolMatch = strings[i].match(/\?([\w.-]+)=\s*$/);
66
+ if (boolMatch) {
67
+ const evaluated = resolveValue(val);
68
+ const truthy = evaluated !== '' && evaluated !== 'false' && evaluated !== 'null' && evaluated !== 'undefined' && evaluated !== '0';
69
+ html = html.replace(/\?[\w.-]+=\s*$/, truthy ? boolMatch[1] : '');
70
+ continue;
71
+ }
72
+ // 3. Property .prop= bindings: strip from HTML markup (hydrated on client)
73
+ if (/\.[\w.-]+=\s*$/.test(strings[i])) {
74
+ html = html.replace(/\.[\w.-]+=\s*$/, '');
75
+ continue;
76
+ }
77
+ html += resolveValue(val);
78
+ }
79
+ }
80
+
81
+ return html;
82
+ }
83
+
84
+ /**
85
+ * Wraps component shadow styles and template in Declarative Shadow DOM
86
+ * @param {string} tagName - Custom element tag name (e.g. 'el-button')
87
+ * @param {Function} ComponentClass - Elementum component class
88
+ * @param {Object} [attributes={}] - Attribute key-values
89
+ * @param {string} [lightDOMChildren=''] - Slotted children
90
+ * @returns {string} Declarative Shadow DOM HTML string
91
+ */
92
+ export function renderComponentToDSD(tagName, ComponentClass, attributes = {}, lightDOMChildren = '') {
93
+ let styleHtml = '';
94
+ if (ComponentClass.styles) {
95
+ const styles = Array.isArray(ComponentClass.styles)
96
+ ? ComponentClass.styles
97
+ : [ComponentClass.styles];
98
+ const cssText = styles
99
+ .map((s) => (s instanceof CSSResult ? s.cssText : String(s)))
100
+ .join('\n');
101
+ styleHtml = `<style>${cssText}</style>`;
102
+ }
103
+
104
+ // Instantiate component instance in memory to get its render template
105
+ let shadowBody = '';
106
+ try {
107
+ const instance = new ComponentClass();
108
+ for (const [k, v] of Object.entries(attributes)) {
109
+ const camel = k.replace(/-([a-z])/g, (_, ch) => ch.toUpperCase());
110
+ const targetKey = (camel in instance && isSignal(instance[camel])) ? camel : k;
111
+ if (instance[targetKey] && isSignal(instance[targetKey])) {
112
+ instance[targetKey].value = v;
113
+ }
114
+ if (typeof instance.setAttribute === 'function') {
115
+ instance.setAttribute(k, String(v));
116
+ }
117
+ }
118
+ const template = instance.render?.();
119
+ if (template) {
120
+ shadowBody = renderTemplateToString(template);
121
+ }
122
+ } catch {
123
+ // If DOM environment is unavailable, render minimal fallback
124
+ shadowBody = '<slot></slot>';
125
+ }
126
+
127
+ const attrStr = Object.entries(attributes)
128
+ .filter(([_, v]) => v !== false && v !== null && v !== undefined)
129
+ .map(([k, v]) => (v === true ? k : `${k}="${escapeHtml(String(v))}"`))
130
+ .join(' ');
131
+
132
+ const openTag = attrStr ? `<${tagName} ${attrStr}>` : `<${tagName}>`;
133
+ const dsdTemplate = `<template shadowrootmode="open">${styleHtml}${shadowBody}</template>`;
134
+
135
+ return `${openTag}${dsdTemplate}${lightDOMChildren}</${tagName}>`;
136
+ }