@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.
- package/LICENSE +21 -0
- package/README.md +266 -2
- package/custom-elements.json +3613 -0
- package/mcp/server.js +408 -0
- package/package.json +72 -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/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 +220 -0
- package/src/components/el-calendar.js +413 -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 +228 -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 +212 -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 +182 -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 +153 -0
- package/src/components/el-otp-input.js +266 -0
- package/src/components/el-pagination.js +229 -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 +219 -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 +485 -0
- package/src/index.d.ts +1007 -0
- package/src/index.js +99 -0
- package/src/signal.js +194 -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
package/src/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
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';
|
package/src/signal.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
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._computedEffect = new ReactiveEffect(() => {
|
|
114
|
+
this._dirty = true;
|
|
115
|
+
// Notify downstreams
|
|
116
|
+
const subs = Array.from(this.subscribers);
|
|
117
|
+
for (const sub of subs) {
|
|
118
|
+
sub.run();
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
get value() {
|
|
124
|
+
if (this._dirty) {
|
|
125
|
+
effectStack.push(activeEffect);
|
|
126
|
+
activeEffect = this._computedEffect;
|
|
127
|
+
this._computedEffect.cleanup();
|
|
128
|
+
try {
|
|
129
|
+
this._value = this._getter();
|
|
130
|
+
this._dirty = false;
|
|
131
|
+
} finally {
|
|
132
|
+
activeEffect = effectStack.pop();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (activeEffect) {
|
|
136
|
+
this.subscribers.add(activeEffect);
|
|
137
|
+
activeEffect.dependencies.add(this);
|
|
138
|
+
}
|
|
139
|
+
return this._value;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function computed(getter) {
|
|
144
|
+
return new Computed(getter);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
class ReactiveEffect {
|
|
148
|
+
constructor(fn) {
|
|
149
|
+
this.fn = fn;
|
|
150
|
+
this.dependencies = new Set();
|
|
151
|
+
this.active = true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
run() {
|
|
155
|
+
if (!this.active) return;
|
|
156
|
+
this.cleanup();
|
|
157
|
+
effectStack.push(activeEffect);
|
|
158
|
+
activeEffect = this;
|
|
159
|
+
try {
|
|
160
|
+
this.fn();
|
|
161
|
+
} finally {
|
|
162
|
+
activeEffect = effectStack.pop();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
cleanup() {
|
|
167
|
+
for (const dep of this.dependencies) {
|
|
168
|
+
dep.subscribers.delete(this);
|
|
169
|
+
}
|
|
170
|
+
this.dependencies.clear();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
stop() {
|
|
174
|
+
this.active = false;
|
|
175
|
+
this.cleanup();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function effect(fn, options = {}) {
|
|
180
|
+
const reactiveEffect = new ReactiveEffect(fn);
|
|
181
|
+
reactiveEffect.run();
|
|
182
|
+
|
|
183
|
+
const dispose = () => reactiveEffect.stop();
|
|
184
|
+
|
|
185
|
+
if (options.signal) {
|
|
186
|
+
if (options.signal.aborted) {
|
|
187
|
+
dispose();
|
|
188
|
+
} else {
|
|
189
|
+
options.signal.addEventListener('abort', dispose, { once: true });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return dispose;
|
|
194
|
+
}
|
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, '&')
|
|
14
|
+
.replace(/</g, '<')
|
|
15
|
+
.replace(/>/g, '>')
|
|
16
|
+
.replace(/"/g, '"')
|
|
17
|
+
.replace(/'/g, ''');
|
|
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 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
|
+
}
|