@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
package/src/template.js
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elementum Tagged Template Engine
|
|
3
|
+
* Ultra-lightweight template literal DOM binding and Constructable Stylesheets.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { isSignal, effect } from './signal.js';
|
|
7
|
+
|
|
8
|
+
// Cache for compiled CSSStyleSheets
|
|
9
|
+
const styleSheetCache = new Map();
|
|
10
|
+
|
|
11
|
+
export class CSSResult {
|
|
12
|
+
constructor(cssText) {
|
|
13
|
+
this.cssText = cssText;
|
|
14
|
+
if (typeof CSSStyleSheet !== 'undefined' && 'replaceSync' in CSSStyleSheet.prototype) {
|
|
15
|
+
let sheet = styleSheetCache.get(cssText);
|
|
16
|
+
if (!sheet) {
|
|
17
|
+
sheet = new CSSStyleSheet();
|
|
18
|
+
sheet.replaceSync(cssText);
|
|
19
|
+
styleSheetCache.set(cssText, sheet);
|
|
20
|
+
}
|
|
21
|
+
this.sheet = sheet;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toString() {
|
|
26
|
+
return this.cssText;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function css(strings, ...values) {
|
|
31
|
+
const cssText = strings.reduce((acc, str, i) => acc + str + (values[i] ?? ''), '');
|
|
32
|
+
return new CSSResult(cssText);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Marker token for template part tracking
|
|
36
|
+
const MARKER = '<!--elementum-part-->';
|
|
37
|
+
const ATTR_PREFIX = 'data-el-part-';
|
|
38
|
+
const SVG_TAG_REGEX = /^\s*(?:<!--[\s\S]*?-->\s*)*<(?:path|line|circle|rect|g|defs|text|polygon|polyline|clipPath|linearGradient|radialGradient|mask|pattern|stop|tspan|use|symbol)\b/i;
|
|
39
|
+
|
|
40
|
+
export class TemplateResult {
|
|
41
|
+
constructor(strings, values, isSvg = false) {
|
|
42
|
+
this.strings = strings;
|
|
43
|
+
this.values = values;
|
|
44
|
+
this.isSvg = isSvg;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function html(strings, ...values) {
|
|
49
|
+
return new TemplateResult(strings, values, false);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function svg(strings, ...values) {
|
|
53
|
+
return new TemplateResult(strings, values, true);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Template element cache by template string array reference
|
|
57
|
+
const templateCache = new WeakMap();
|
|
58
|
+
|
|
59
|
+
function getCachedTemplate(strings, isSvg = false) {
|
|
60
|
+
let cached = templateCache.get(strings);
|
|
61
|
+
if (cached) return cached;
|
|
62
|
+
|
|
63
|
+
let htmlString = '';
|
|
64
|
+
const partMeta = [];
|
|
65
|
+
let stripLeadingQuote = null;
|
|
66
|
+
|
|
67
|
+
for (let i = 0; i < strings.length - 1; i++) {
|
|
68
|
+
let str = strings[i];
|
|
69
|
+
if (stripLeadingQuote && str.startsWith(stripLeadingQuote)) {
|
|
70
|
+
str = str.slice(1);
|
|
71
|
+
stripLeadingQuote = null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Check if interpolation is inside an HTML tag attribute using accumulated HTML
|
|
75
|
+
const tempHtml = htmlString + str;
|
|
76
|
+
const lastOpenTag = tempHtml.lastIndexOf('<');
|
|
77
|
+
const lastCloseTag = tempHtml.lastIndexOf('>');
|
|
78
|
+
const isInsideTag = lastOpenTag > lastCloseTag;
|
|
79
|
+
|
|
80
|
+
if (isInsideTag) {
|
|
81
|
+
// Find attribute name preceding '='
|
|
82
|
+
const match = str.match(/([@.?a-zA-Z0-9_\-]+)\s*=\s*(["']?)$/);
|
|
83
|
+
if (match) {
|
|
84
|
+
const rawName = match[1];
|
|
85
|
+
stripLeadingQuote = match[2] || null;
|
|
86
|
+
|
|
87
|
+
let type = 'attr';
|
|
88
|
+
let name = rawName;
|
|
89
|
+
|
|
90
|
+
if (rawName.startsWith('@')) {
|
|
91
|
+
type = 'event';
|
|
92
|
+
name = rawName.slice(1);
|
|
93
|
+
} else if (rawName.startsWith('on') && rawName.length > 2 && /^[a-zA-Z]+$/.test(rawName.slice(2))) {
|
|
94
|
+
type = 'event';
|
|
95
|
+
name = rawName.slice(2).toLowerCase();
|
|
96
|
+
} else if (rawName.startsWith('.')) {
|
|
97
|
+
type = 'prop';
|
|
98
|
+
name = rawName.slice(1);
|
|
99
|
+
} else if (rawName.startsWith('?')) {
|
|
100
|
+
type = 'bool';
|
|
101
|
+
name = rawName.slice(1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const markerAttr = `${ATTR_PREFIX}${i}`;
|
|
105
|
+
// Cleanly substitute the attribute name and '=' with markerAttr=""
|
|
106
|
+
const cleanStr = str.slice(0, match.index) + `${markerAttr}=""`;
|
|
107
|
+
htmlString += cleanStr;
|
|
108
|
+
partMeta.push({ index: i, type, name, markerAttr });
|
|
109
|
+
} else {
|
|
110
|
+
const markerAttr = `${ATTR_PREFIX}${i}`;
|
|
111
|
+
htmlString += str + ` ${markerAttr}=""`;
|
|
112
|
+
partMeta.push({ index: i, type: 'attr', name: 'data-attr', markerAttr });
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
// Child node position
|
|
116
|
+
htmlString += str + MARKER;
|
|
117
|
+
partMeta.push({ index: i, type: 'node' });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let lastStr = strings[strings.length - 1];
|
|
122
|
+
if (stripLeadingQuote && lastStr.startsWith(stripLeadingQuote)) {
|
|
123
|
+
lastStr = lastStr.slice(1);
|
|
124
|
+
}
|
|
125
|
+
htmlString += lastStr;
|
|
126
|
+
|
|
127
|
+
const isSvgTemplate = Boolean(isSvg) || SVG_TAG_REGEX.test(htmlString);
|
|
128
|
+
const tpl = document.createElement('template');
|
|
129
|
+
if (isSvgTemplate && !htmlString.trim().toLowerCase().startsWith('<svg')) {
|
|
130
|
+
tpl.innerHTML = `<svg>${htmlString}</svg>`;
|
|
131
|
+
const svgEl = tpl.content.firstChild;
|
|
132
|
+
const frag = document.createDocumentFragment();
|
|
133
|
+
while (svgEl && svgEl.firstChild) {
|
|
134
|
+
frag.appendChild(svgEl.firstChild);
|
|
135
|
+
}
|
|
136
|
+
tpl.content.textContent = '';
|
|
137
|
+
tpl.content.appendChild(frag);
|
|
138
|
+
} else {
|
|
139
|
+
tpl.innerHTML = htmlString;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
cached = { template: tpl, partMeta };
|
|
143
|
+
templateCache.set(strings, cached);
|
|
144
|
+
return cached;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Resolves a dynamic value (signal, function getter, or literal)
|
|
149
|
+
*/
|
|
150
|
+
function resolveValue(val) {
|
|
151
|
+
if (isSignal(val)) {
|
|
152
|
+
return val.value;
|
|
153
|
+
}
|
|
154
|
+
if (typeof val === 'function' && !val._isEventHandler) {
|
|
155
|
+
return val();
|
|
156
|
+
}
|
|
157
|
+
return val;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function isReactive(val) {
|
|
161
|
+
return isSignal(val) || (typeof val === 'function' && !val._isEventHandler);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
class NodePart {
|
|
165
|
+
constructor(startNode, abortSignal) {
|
|
166
|
+
this.startNode = startNode;
|
|
167
|
+
this.endNode = document.createComment('/part');
|
|
168
|
+
startNode.parentNode.insertBefore(this.endNode, startNode.nextSibling);
|
|
169
|
+
this.abortSignal = abortSignal;
|
|
170
|
+
this.nodes = [];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
clear() {
|
|
174
|
+
for (const node of this.nodes) {
|
|
175
|
+
if (node.parentNode) {
|
|
176
|
+
node.parentNode.removeChild(node);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
this.nodes = [];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
commit(raw) {
|
|
183
|
+
const val = resolveValue(raw);
|
|
184
|
+
this.clear();
|
|
185
|
+
|
|
186
|
+
const parent = this.startNode.parentNode;
|
|
187
|
+
if (!parent) return;
|
|
188
|
+
|
|
189
|
+
if (val == null || val === false) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (val instanceof TemplateResult) {
|
|
194
|
+
const fragment = document.createDocumentFragment();
|
|
195
|
+
render(val, fragment, this.abortSignal);
|
|
196
|
+
this.nodes = Array.from(fragment.childNodes);
|
|
197
|
+
parent.insertBefore(fragment, this.endNode);
|
|
198
|
+
} else if (Array.isArray(val)) {
|
|
199
|
+
const fragment = document.createDocumentFragment();
|
|
200
|
+
for (const item of val) {
|
|
201
|
+
const resolvedItem = resolveValue(item);
|
|
202
|
+
if (resolvedItem instanceof TemplateResult) {
|
|
203
|
+
const subFrag = document.createDocumentFragment();
|
|
204
|
+
render(resolvedItem, subFrag, this.abortSignal);
|
|
205
|
+
fragment.appendChild(subFrag);
|
|
206
|
+
} else if (resolvedItem != null && resolvedItem !== false) {
|
|
207
|
+
fragment.appendChild(document.createTextNode(String(resolvedItem)));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
this.nodes = Array.from(fragment.childNodes);
|
|
211
|
+
parent.insertBefore(fragment, this.endNode);
|
|
212
|
+
} else {
|
|
213
|
+
const text = document.createTextNode(String(val));
|
|
214
|
+
this.nodes = [text];
|
|
215
|
+
parent.insertBefore(text, this.endNode);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function render(result, container, abortSignal) {
|
|
221
|
+
if (!result || !(result instanceof TemplateResult)) {
|
|
222
|
+
container.textContent = '';
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const { template, partMeta } = getCachedTemplate(result.strings, result.isSvg);
|
|
227
|
+
const fragment = template.content.cloneNode(true);
|
|
228
|
+
const values = result.values;
|
|
229
|
+
|
|
230
|
+
// Track and bind parts
|
|
231
|
+
partMeta.forEach((meta) => {
|
|
232
|
+
const val = values[meta.index];
|
|
233
|
+
|
|
234
|
+
if (meta.type === 'node') {
|
|
235
|
+
// Find next unattached comment marker
|
|
236
|
+
const iterator = document.createNodeIterator(fragment, NodeFilter.SHOW_COMMENT);
|
|
237
|
+
let commentNode;
|
|
238
|
+
while ((commentNode = iterator.nextNode())) {
|
|
239
|
+
if (commentNode.textContent === 'elementum-part') {
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (commentNode) {
|
|
245
|
+
commentNode.textContent = 'part';
|
|
246
|
+
const part = new NodePart(commentNode, abortSignal);
|
|
247
|
+
|
|
248
|
+
if (isReactive(val)) {
|
|
249
|
+
effect(() => part.commit(val), { signal: abortSignal });
|
|
250
|
+
} else {
|
|
251
|
+
part.commit(val);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
// Attribute / Prop / Event / Bool
|
|
256
|
+
const el = fragment.querySelector(`[${meta.markerAttr}]`);
|
|
257
|
+
if (el) {
|
|
258
|
+
el.removeAttribute(meta.markerAttr);
|
|
259
|
+
|
|
260
|
+
if (meta.type === 'event') {
|
|
261
|
+
if (typeof val === 'function') {
|
|
262
|
+
val._isEventHandler = true;
|
|
263
|
+
el.addEventListener(meta.name, val, { signal: abortSignal });
|
|
264
|
+
}
|
|
265
|
+
} else if (meta.type === 'prop') {
|
|
266
|
+
const updateProp = (v) => {
|
|
267
|
+
const resolved = resolveValue(v);
|
|
268
|
+
if (isSignal(el[meta.name])) {
|
|
269
|
+
el[meta.name].value = resolved;
|
|
270
|
+
} else {
|
|
271
|
+
el[meta.name] = resolved;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
if (isReactive(val)) {
|
|
275
|
+
effect(() => updateProp(val), { signal: abortSignal });
|
|
276
|
+
} else {
|
|
277
|
+
updateProp(val);
|
|
278
|
+
}
|
|
279
|
+
} else if (meta.type === 'bool') {
|
|
280
|
+
const updateBool = (v) => {
|
|
281
|
+
const resolved = Boolean(resolveValue(v));
|
|
282
|
+
if (resolved) {
|
|
283
|
+
el.setAttribute(meta.name, '');
|
|
284
|
+
} else {
|
|
285
|
+
el.removeAttribute(meta.name);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
if (isReactive(val)) {
|
|
289
|
+
effect(() => updateBool(val), { signal: abortSignal });
|
|
290
|
+
} else {
|
|
291
|
+
updateBool(val);
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
// Regular attribute
|
|
295
|
+
const updateAttr = (v) => {
|
|
296
|
+
const resolved = resolveValue(v);
|
|
297
|
+
if (resolved == null || resolved === false) {
|
|
298
|
+
el.removeAttribute(meta.name);
|
|
299
|
+
} else {
|
|
300
|
+
el.setAttribute(meta.name, String(resolved));
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
if (isReactive(val)) {
|
|
304
|
+
effect(() => updateAttr(val), { signal: abortSignal });
|
|
305
|
+
} else {
|
|
306
|
+
updateAttr(val);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
if ('replaceChildren' in container) {
|
|
314
|
+
container.replaceChildren(fragment);
|
|
315
|
+
} else {
|
|
316
|
+
while (container.firstChild) {
|
|
317
|
+
container.removeChild(container.firstChild);
|
|
318
|
+
}
|
|
319
|
+
container.appendChild(fragment);
|
|
320
|
+
}
|
|
321
|
+
}
|