klods-js 1.0.2
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/README.md +24 -0
- package/dist/index.cjs +361 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +117 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +304 -0
- package/dist/index.js.map +1 -0
- package/dist/klods.umd.js +2 -0
- package/dist/klods.umd.js.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# klods
|
|
2
|
+
|
|
3
|
+
Tiny, typed, lego-like builder API. Pairs with [`klods-css`](../klods-css).
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install klods-js klods-css
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { content, footer, header, nav, navLink, navList, page, sidebar } from "klods-js";
|
|
11
|
+
import "klods-css";
|
|
12
|
+
|
|
13
|
+
page({ sidebar: true }, [
|
|
14
|
+
header(
|
|
15
|
+
{},
|
|
16
|
+
nav({}, navList({}, [navLink({ href: "/", active: true }, "Home"), navLink({ href: "/about" }, "About")]))
|
|
17
|
+
),
|
|
18
|
+
sidebar({}, "filters here"),
|
|
19
|
+
content({ narrow: true }, "Hello world"),
|
|
20
|
+
footer({}, "© 2026"),
|
|
21
|
+
]).render(document.body);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Every builder accepts arbitrary `class`, `id`, `data-*`, `aria-*`, event handlers and any other HTML attribute. See the [docs site](../../apps/docs) for the full reference.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
KlodsNode: () => KlodsNode,
|
|
24
|
+
alert: () => alert,
|
|
25
|
+
badge: () => badge,
|
|
26
|
+
builder: () => builder,
|
|
27
|
+
button: () => button,
|
|
28
|
+
card: () => card,
|
|
29
|
+
cardBody: () => cardBody,
|
|
30
|
+
cardFooter: () => cardFooter,
|
|
31
|
+
cardTitle: () => cardTitle,
|
|
32
|
+
center: () => center,
|
|
33
|
+
classNames: () => classNames,
|
|
34
|
+
cluster: () => cluster,
|
|
35
|
+
content: () => content,
|
|
36
|
+
el: () => el,
|
|
37
|
+
footer: () => footer,
|
|
38
|
+
grid: () => grid,
|
|
39
|
+
header: () => header,
|
|
40
|
+
lead: () => lead,
|
|
41
|
+
mergeClasses: () => mergeClasses,
|
|
42
|
+
muted: () => muted,
|
|
43
|
+
nav: () => nav,
|
|
44
|
+
navLink: () => navLink,
|
|
45
|
+
navList: () => navList,
|
|
46
|
+
page: () => page,
|
|
47
|
+
prose: () => prose,
|
|
48
|
+
raw: () => raw,
|
|
49
|
+
row: () => row,
|
|
50
|
+
sidebar: () => sidebar,
|
|
51
|
+
spread: () => spread,
|
|
52
|
+
stack: () => stack,
|
|
53
|
+
text: () => text
|
|
54
|
+
});
|
|
55
|
+
module.exports = __toCommonJS(index_exports);
|
|
56
|
+
|
|
57
|
+
// src/core.ts
|
|
58
|
+
var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
59
|
+
"area",
|
|
60
|
+
"base",
|
|
61
|
+
"br",
|
|
62
|
+
"col",
|
|
63
|
+
"embed",
|
|
64
|
+
"hr",
|
|
65
|
+
"img",
|
|
66
|
+
"input",
|
|
67
|
+
"link",
|
|
68
|
+
"meta",
|
|
69
|
+
"source",
|
|
70
|
+
"track",
|
|
71
|
+
"wbr"
|
|
72
|
+
]);
|
|
73
|
+
var RAW = /* @__PURE__ */ Symbol("klods.raw");
|
|
74
|
+
function raw(html) {
|
|
75
|
+
return { [RAW]: true, html };
|
|
76
|
+
}
|
|
77
|
+
function isRaw(value) {
|
|
78
|
+
return typeof value === "object" && value !== null && value[RAW] === true;
|
|
79
|
+
}
|
|
80
|
+
function escapeHtml(str) {
|
|
81
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
82
|
+
}
|
|
83
|
+
function escapeAttr(str) {
|
|
84
|
+
return str.replace(/&/g, "&").replace(/"/g, """);
|
|
85
|
+
}
|
|
86
|
+
function classNames(input) {
|
|
87
|
+
if (!input) return "";
|
|
88
|
+
if (typeof input === "string") return input.trim();
|
|
89
|
+
if (Array.isArray(input)) return input.filter(Boolean).join(" ").trim();
|
|
90
|
+
return Object.entries(input).filter(([, v]) => Boolean(v)).map(([k]) => k).join(" ").trim();
|
|
91
|
+
}
|
|
92
|
+
function mergeClasses(...inputs) {
|
|
93
|
+
return inputs.map((c) => classNames(c)).filter(Boolean).join(" ");
|
|
94
|
+
}
|
|
95
|
+
function styleToString(style) {
|
|
96
|
+
if (typeof style === "string") return style;
|
|
97
|
+
return Object.entries(style).filter(([, v]) => v !== void 0 && v !== null && v !== "").map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}:${String(v)}`).join(";");
|
|
98
|
+
}
|
|
99
|
+
function flattenChildren(children) {
|
|
100
|
+
const out = [];
|
|
101
|
+
const stack2 = Array.isArray(children) ? [...children] : [children];
|
|
102
|
+
while (stack2.length) {
|
|
103
|
+
const next = stack2.shift();
|
|
104
|
+
if (Array.isArray(next)) stack2.unshift(...next);
|
|
105
|
+
else if (next !== null && next !== void 0 && next !== false && next !== true) out.push(next);
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
var KlodsNode = class _KlodsNode {
|
|
110
|
+
tag;
|
|
111
|
+
attrs;
|
|
112
|
+
children;
|
|
113
|
+
constructor(tag, attrs = {}, children = []) {
|
|
114
|
+
this.tag = tag;
|
|
115
|
+
this.attrs = attrs;
|
|
116
|
+
this.children = Array.isArray(children) ? children : [children];
|
|
117
|
+
}
|
|
118
|
+
/** Render to a real DOM element. If `target` is given, append to it. */
|
|
119
|
+
render(target) {
|
|
120
|
+
const el2 = document.createElement(this.tag);
|
|
121
|
+
for (const [name, value] of Object.entries(this.attrs)) {
|
|
122
|
+
if (value === void 0 || value === null || value === false) continue;
|
|
123
|
+
if (name === "children") continue;
|
|
124
|
+
if (name === "class") {
|
|
125
|
+
const cls = classNames(value);
|
|
126
|
+
if (cls) el2.setAttribute("class", cls);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (name === "style") {
|
|
130
|
+
el2.setAttribute("style", styleToString(value));
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (name.startsWith("on") && typeof value === "function") {
|
|
134
|
+
el2.addEventListener(name.slice(2).toLowerCase(), value);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (value === true) {
|
|
138
|
+
el2.setAttribute(name, "");
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
el2.setAttribute(name, String(value));
|
|
142
|
+
}
|
|
143
|
+
for (const child of flattenChildren(this.children)) {
|
|
144
|
+
if (child instanceof _KlodsNode) el2.appendChild(child.render());
|
|
145
|
+
else if (typeof child === "object" && child !== null && "nodeType" in child) {
|
|
146
|
+
el2.appendChild(child);
|
|
147
|
+
} else if (isRaw(child)) {
|
|
148
|
+
const tpl = document.createElement("template");
|
|
149
|
+
tpl.innerHTML = child.html;
|
|
150
|
+
el2.appendChild(tpl.content);
|
|
151
|
+
} else {
|
|
152
|
+
el2.appendChild(document.createTextNode(String(child)));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (target) target.appendChild(el2);
|
|
156
|
+
return el2;
|
|
157
|
+
}
|
|
158
|
+
/** Render to a string of HTML. */
|
|
159
|
+
toString() {
|
|
160
|
+
const parts = [`<${this.tag}`];
|
|
161
|
+
for (const [name, value] of Object.entries(this.attrs)) {
|
|
162
|
+
if (value === void 0 || value === null || value === false) continue;
|
|
163
|
+
if (name === "children") continue;
|
|
164
|
+
if (name.startsWith("on") && typeof value === "function") continue;
|
|
165
|
+
if (name === "class") {
|
|
166
|
+
const cls = classNames(value);
|
|
167
|
+
if (cls) parts.push(` class="${escapeAttr(cls)}"`);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (name === "style") {
|
|
171
|
+
parts.push(` style="${escapeAttr(styleToString(value))}"`);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (value === true) {
|
|
175
|
+
parts.push(` ${name}`);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
parts.push(` ${name}="${escapeAttr(String(value))}"`);
|
|
179
|
+
}
|
|
180
|
+
if (VOID_TAGS.has(this.tag)) {
|
|
181
|
+
parts.push(" />");
|
|
182
|
+
return parts.join("");
|
|
183
|
+
}
|
|
184
|
+
parts.push(">");
|
|
185
|
+
for (const child of flattenChildren(this.children)) {
|
|
186
|
+
if (child instanceof _KlodsNode) parts.push(child.toString());
|
|
187
|
+
else if (isRaw(child)) parts.push(child.html);
|
|
188
|
+
else if (typeof child === "object" && child !== null && "outerHTML" in child) {
|
|
189
|
+
parts.push(child.outerHTML);
|
|
190
|
+
} else {
|
|
191
|
+
parts.push(escapeHtml(String(child)));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
parts.push(`</${this.tag}>`);
|
|
195
|
+
return parts.join("");
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
function el(tag, attrs = {}, children = []) {
|
|
199
|
+
return new KlodsNode(tag, attrs, children);
|
|
200
|
+
}
|
|
201
|
+
function builder(options) {
|
|
202
|
+
const { tag, base, modifiers = {} } = options;
|
|
203
|
+
const modifierMap = modifiers;
|
|
204
|
+
return (props, children) => {
|
|
205
|
+
const userProps = props ?? {};
|
|
206
|
+
const modClasses = [];
|
|
207
|
+
const passthrough = {};
|
|
208
|
+
for (const [key, value] of Object.entries(userProps)) {
|
|
209
|
+
const m = modifierMap[key];
|
|
210
|
+
if (m !== void 0) {
|
|
211
|
+
if (typeof m === "function") {
|
|
212
|
+
const c = m(value);
|
|
213
|
+
if (c) modClasses.push(c);
|
|
214
|
+
} else if (value) {
|
|
215
|
+
modClasses.push(m);
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
passthrough[key] = value;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const finalClass = mergeClasses(base, ...modClasses, userProps.class);
|
|
222
|
+
const resolvedChildren = children !== void 0 ? children : userProps.children ?? [];
|
|
223
|
+
delete passthrough.children;
|
|
224
|
+
return new KlodsNode(tag, { ...passthrough, class: finalClass || void 0 }, resolvedChildren);
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// src/components.ts
|
|
229
|
+
var nav = builder({ tag: "nav", base: "klods-nav" });
|
|
230
|
+
var navList = builder({ tag: "ul", base: "klods-nav__list" });
|
|
231
|
+
var navLinkBuilder = builder({
|
|
232
|
+
tag: "a",
|
|
233
|
+
base: "klods-nav__link",
|
|
234
|
+
modifiers: { active: "klods-nav__link--active" }
|
|
235
|
+
});
|
|
236
|
+
function navLink(props, children) {
|
|
237
|
+
return el("li", {}, [navLinkBuilder(props ?? null, children)]);
|
|
238
|
+
}
|
|
239
|
+
var card = builder({
|
|
240
|
+
tag: "div",
|
|
241
|
+
base: "klods-card",
|
|
242
|
+
modifiers: { elevated: "klods-card--elevated" }
|
|
243
|
+
});
|
|
244
|
+
var cardTitle = builder({ tag: "h3", base: "klods-card__title" });
|
|
245
|
+
var cardBody = builder({ tag: "div", base: "klods-card__body" });
|
|
246
|
+
var cardFooter = builder({ tag: "div", base: "klods-card__footer" });
|
|
247
|
+
var buttonBase = builder({
|
|
248
|
+
tag: "button",
|
|
249
|
+
base: "klods-button",
|
|
250
|
+
modifiers: {
|
|
251
|
+
variant: (v) => v && v !== "default" ? `klods-button--${v}` : void 0
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
function button(props, children) {
|
|
255
|
+
const merged = { type: "button", ...props ?? {} };
|
|
256
|
+
return buttonBase(merged, children);
|
|
257
|
+
}
|
|
258
|
+
var badge = builder({
|
|
259
|
+
tag: "span",
|
|
260
|
+
base: "klods-badge",
|
|
261
|
+
modifiers: {
|
|
262
|
+
variant: (v) => v && v !== "default" ? `klods-badge--${v}` : void 0
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
var alertBase = builder({
|
|
266
|
+
tag: "div",
|
|
267
|
+
base: "klods-alert",
|
|
268
|
+
modifiers: {
|
|
269
|
+
variant: (v) => v && v !== "default" ? `klods-alert--${v}` : void 0
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
function alert(props, children) {
|
|
273
|
+
const merged = { role: "alert", ...props ?? {} };
|
|
274
|
+
return alertBase(merged, children);
|
|
275
|
+
}
|
|
276
|
+
var prose = builder({ tag: "div", base: "klods-prose" });
|
|
277
|
+
var muted = builder({ tag: "span", base: "klods-muted" });
|
|
278
|
+
var lead = builder({ tag: "p", base: "klods-lead" });
|
|
279
|
+
|
|
280
|
+
// src/layout.ts
|
|
281
|
+
var page = builder({
|
|
282
|
+
tag: "div",
|
|
283
|
+
base: "klods-page",
|
|
284
|
+
modifiers: {
|
|
285
|
+
sidebar: "klods-page--with-sidebar",
|
|
286
|
+
sidebarRight: "klods-page--sidebar-right"
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
var header = builder({ tag: "header", base: "klods-header" });
|
|
290
|
+
var sidebar = builder({ tag: "aside", base: "klods-sidebar" });
|
|
291
|
+
var content = builder({
|
|
292
|
+
tag: "main",
|
|
293
|
+
base: "klods-content",
|
|
294
|
+
modifiers: { narrow: "klods-content--narrow" }
|
|
295
|
+
});
|
|
296
|
+
var footer = builder({ tag: "footer", base: "klods-footer" });
|
|
297
|
+
var gapModifier = (prefix) => (v) => v === void 0 ? void 0 : `${prefix}--gap-${v}`;
|
|
298
|
+
var stack = builder({
|
|
299
|
+
tag: "div",
|
|
300
|
+
base: "klods-stack",
|
|
301
|
+
modifiers: { gap: gapModifier("klods-stack") }
|
|
302
|
+
});
|
|
303
|
+
var cluster = builder({
|
|
304
|
+
tag: "div",
|
|
305
|
+
base: "klods-cluster",
|
|
306
|
+
modifiers: { gap: gapModifier("klods-cluster") }
|
|
307
|
+
});
|
|
308
|
+
var row = builder({
|
|
309
|
+
tag: "div",
|
|
310
|
+
base: "klods-row",
|
|
311
|
+
modifiers: { gap: gapModifier("klods-row") }
|
|
312
|
+
});
|
|
313
|
+
var grid = builder({
|
|
314
|
+
tag: "div",
|
|
315
|
+
base: "klods-grid",
|
|
316
|
+
modifiers: {
|
|
317
|
+
gap: gapModifier("klods-grid"),
|
|
318
|
+
cols: (v) => v === void 0 ? void 0 : `klods-grid--cols-${v}`,
|
|
319
|
+
fit: "klods-grid--fit"
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
var center = builder({ tag: "div", base: "klods-center" });
|
|
323
|
+
var spread = builder({ tag: "div", base: "klods-spread" });
|
|
324
|
+
function text(value) {
|
|
325
|
+
return new KlodsNode("span", {}, [String(value)]);
|
|
326
|
+
}
|
|
327
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
328
|
+
0 && (module.exports = {
|
|
329
|
+
KlodsNode,
|
|
330
|
+
alert,
|
|
331
|
+
badge,
|
|
332
|
+
builder,
|
|
333
|
+
button,
|
|
334
|
+
card,
|
|
335
|
+
cardBody,
|
|
336
|
+
cardFooter,
|
|
337
|
+
cardTitle,
|
|
338
|
+
center,
|
|
339
|
+
classNames,
|
|
340
|
+
cluster,
|
|
341
|
+
content,
|
|
342
|
+
el,
|
|
343
|
+
footer,
|
|
344
|
+
grid,
|
|
345
|
+
header,
|
|
346
|
+
lead,
|
|
347
|
+
mergeClasses,
|
|
348
|
+
muted,
|
|
349
|
+
nav,
|
|
350
|
+
navLink,
|
|
351
|
+
navList,
|
|
352
|
+
page,
|
|
353
|
+
prose,
|
|
354
|
+
raw,
|
|
355
|
+
row,
|
|
356
|
+
sidebar,
|
|
357
|
+
spread,
|
|
358
|
+
stack,
|
|
359
|
+
text
|
|
360
|
+
});
|
|
361
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/core.ts","../src/components.ts","../src/layout.ts"],"sourcesContent":["// Public API surface for the `klods` package.\n\nexport * from \"./components.js\";\nexport * from \"./core.js\";\nexport * from \"./layout.js\";\n","// Core — a tiny VDOM-ish node with two faces:\n// - .render(target?) → HTMLElement (uses real DOM)\n// - .toString() → HTML string (works in Node / Rails / SSR)\n//\n// Both are produced from the same KlodsNode tree, so the docs site can show the\n// TS source, the rendered HTML and the live preview from one source of truth.\n\nexport type KlodsChild = string | number | bigint | boolean | null | undefined | KlodsNode | Node | KlodsChild[];\n\nexport type KlodsAttrs = {\n class?: string | string[] | Record<string, boolean | undefined> | undefined;\n id?: string | undefined;\n style?: string | Partial<CSSStyleDeclaration> | undefined;\n [key: `data-${string}`]: string | number | boolean | undefined;\n [key: `aria-${string}`]: string | number | boolean | undefined;\n // Allow any other HTML attribute or DOM event handler (onClick, onInput, …).\n [key: string]: unknown;\n};\n\nconst VOID_TAGS = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"link\",\n \"meta\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\nconst RAW = Symbol(\"klods.raw\");\n\ntype RawHtml = { [RAW]: true; html: string };\n\n/** Mark a string as already-escaped HTML; pass it as a child to inject as-is. */\nexport function raw(html: string): RawHtml {\n return { [RAW]: true, html };\n}\n\nfunction isRaw(value: unknown): value is RawHtml {\n return typeof value === \"object\" && value !== null && (value as { [RAW]?: unknown })[RAW] === true;\n}\n\nfunction escapeHtml(str: string): string {\n return str\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n}\n\nfunction escapeAttr(str: string): string {\n return str.replace(/&/g, \"&\").replace(/\"/g, \""\");\n}\n\n/** Normalise a `class` value (string | array | record) into a clean string. */\nexport function classNames(input: KlodsAttrs[\"class\"]): string {\n if (!input) return \"\";\n if (typeof input === \"string\") return input.trim();\n if (Array.isArray(input)) return input.filter(Boolean).join(\" \").trim();\n return Object.entries(input)\n .filter(([, v]) => Boolean(v))\n .map(([k]) => k)\n .join(\" \")\n .trim();\n}\n\n/** Merge two class values (used internally to combine builder defaults + user-supplied). */\nexport function mergeClasses(...inputs: Array<KlodsAttrs[\"class\"]>): string {\n return inputs\n .map((c) => classNames(c))\n .filter(Boolean)\n .join(\" \");\n}\n\nfunction styleToString(style: string | Partial<CSSStyleDeclaration>): string {\n if (typeof style === \"string\") return style;\n return Object.entries(style)\n .filter(([, v]) => v !== undefined && v !== null && v !== \"\")\n .map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}:${String(v)}`)\n .join(\";\");\n}\n\nfunction flattenChildren(children: KlodsChild | KlodsChild[]): Array<Exclude<KlodsChild, KlodsChild[]>> {\n const out: Array<Exclude<KlodsChild, KlodsChild[]>> = [];\n const stack: KlodsChild[] = Array.isArray(children) ? [...children] : [children];\n while (stack.length) {\n const next = stack.shift();\n if (Array.isArray(next)) stack.unshift(...next);\n else if (next !== null && next !== undefined && next !== false && next !== true) out.push(next);\n }\n return out;\n}\n\nexport class KlodsNode {\n readonly tag: string;\n readonly attrs: KlodsAttrs;\n readonly children: KlodsChild[];\n\n constructor(tag: string, attrs: KlodsAttrs = {}, children: KlodsChild | KlodsChild[] = []) {\n this.tag = tag;\n this.attrs = attrs;\n this.children = Array.isArray(children) ? children : [children];\n }\n\n /** Render to a real DOM element. If `target` is given, append to it. */\n render(target?: Element | null): HTMLElement {\n const el = document.createElement(this.tag);\n for (const [name, value] of Object.entries(this.attrs)) {\n if (value === undefined || value === null || value === false) continue;\n if (name === \"children\") continue;\n if (name === \"class\") {\n const cls = classNames(value as KlodsAttrs[\"class\"]);\n if (cls) el.setAttribute(\"class\", cls);\n continue;\n }\n if (name === \"style\") {\n el.setAttribute(\"style\", styleToString(value as string | Partial<CSSStyleDeclaration>));\n continue;\n }\n if (name.startsWith(\"on\") && typeof value === \"function\") {\n el.addEventListener(name.slice(2).toLowerCase(), value as EventListener);\n continue;\n }\n if (value === true) {\n el.setAttribute(name, \"\");\n continue;\n }\n el.setAttribute(name, String(value));\n }\n for (const child of flattenChildren(this.children)) {\n if (child instanceof KlodsNode) el.appendChild(child.render());\n else if (typeof child === \"object\" && child !== null && \"nodeType\" in child) {\n el.appendChild(child as Node);\n } else if (isRaw(child)) {\n const tpl = document.createElement(\"template\");\n tpl.innerHTML = child.html;\n el.appendChild(tpl.content);\n } else {\n el.appendChild(document.createTextNode(String(child)));\n }\n }\n if (target) target.appendChild(el);\n return el;\n }\n\n /** Render to a string of HTML. */\n toString(): string {\n const parts: string[] = [`<${this.tag}`];\n for (const [name, value] of Object.entries(this.attrs)) {\n if (value === undefined || value === null || value === false) continue;\n if (name === \"children\") continue;\n if (name.startsWith(\"on\") && typeof value === \"function\") continue;\n if (name === \"class\") {\n const cls = classNames(value as KlodsAttrs[\"class\"]);\n if (cls) parts.push(` class=\"${escapeAttr(cls)}\"`);\n continue;\n }\n if (name === \"style\") {\n parts.push(` style=\"${escapeAttr(styleToString(value as string | Partial<CSSStyleDeclaration>))}\"`);\n continue;\n }\n if (value === true) {\n parts.push(` ${name}`);\n continue;\n }\n parts.push(` ${name}=\"${escapeAttr(String(value))}\"`);\n }\n if (VOID_TAGS.has(this.tag)) {\n parts.push(\" />\");\n return parts.join(\"\");\n }\n parts.push(\">\");\n for (const child of flattenChildren(this.children)) {\n if (child instanceof KlodsNode) parts.push(child.toString());\n else if (isRaw(child)) parts.push(child.html);\n else if (typeof child === \"object\" && child !== null && \"outerHTML\" in child) {\n parts.push((child as Element).outerHTML);\n } else {\n parts.push(escapeHtml(String(child)));\n }\n }\n parts.push(`</${this.tag}>`);\n return parts.join(\"\");\n }\n}\n\n/**\n * Generic element builder. Most consumers use the named builders (page, header, …)\n * rather than calling `el` directly, but it's exported as an escape hatch.\n */\nexport function el(tag: string, attrs: KlodsAttrs = {}, children: KlodsChild | KlodsChild[] = []): KlodsNode {\n return new KlodsNode(tag, attrs, children);\n}\n\n/**\n * Factory that produces a typed builder for a tag with a base class. Modifier\n * props are converted into `--modifier` BEM classes and stripped from the output\n * attributes; everything else passes through untouched, so consumers can attach\n * arbitrary `id`, `data-*`, `aria-*`, event handlers, `style`, etc.\n */\nexport function builder<P extends Record<string, unknown> = Record<string, never>>(options: {\n tag: string;\n base: string;\n /** Map of prop name → class (or function returning a class) when the prop is truthy. */\n modifiers?: { [K in keyof P]?: string | ((value: P[K]) => string | undefined) };\n}): (props?: (P & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]) => KlodsNode {\n const { tag, base, modifiers = {} } = options;\n const modifierMap = modifiers as Record<string, string | ((value: unknown) => string | undefined) | undefined>;\n return (props, children) => {\n const userProps = (props ?? {}) as P & KlodsAttrs;\n const modClasses: string[] = [];\n const passthrough: KlodsAttrs = {};\n for (const [key, value] of Object.entries(userProps)) {\n const m = modifierMap[key];\n if (m !== undefined) {\n if (typeof m === \"function\") {\n const c = m(value);\n if (c) modClasses.push(c);\n } else if (value) {\n modClasses.push(m);\n }\n } else {\n passthrough[key] = value;\n }\n }\n const finalClass = mergeClasses(base, ...modClasses, userProps.class);\n const resolvedChildren =\n children !== undefined ? children : ((userProps.children as KlodsChild | KlodsChild[] | undefined) ?? []);\n delete passthrough.children;\n return new KlodsNode(tag, { ...passthrough, class: finalClass || undefined }, resolvedChildren);\n };\n}\n","// First wave of components: nav, card, button, badge, alert, prose helpers.\n// All match the BEM classes shipped by klods-css.\n\nimport type { KlodsAttrs, KlodsChild } from \"./core.js\";\nimport { builder, el, KlodsNode } from \"./core.js\";\n\n// ── Nav ──────────────────────────────────────────────────────────────────\nexport const nav = builder({ tag: \"nav\", base: \"klods-nav\" });\nexport const navList = builder({ tag: \"ul\", base: \"klods-nav__list\" });\n\nexport type NavLinkProps = {\n href?: string;\n active?: boolean;\n};\nconst navLinkBuilder = builder<NavLinkProps>({\n tag: \"a\",\n base: \"klods-nav__link\",\n modifiers: { active: \"klods-nav__link--active\" },\n});\nexport function navLink(props?: (NavLinkProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode {\n // Wrap each link in <li> so it's idiomatic inside <ul class=\"klods-nav__list\">.\n return el(\"li\", {}, [navLinkBuilder(props ?? null, children)]);\n}\n\n// ── Card ─────────────────────────────────────────────────────────────────\nexport type CardProps = {\n elevated?: boolean;\n};\nexport const card = builder<CardProps>({\n tag: \"div\",\n base: \"klods-card\",\n modifiers: { elevated: \"klods-card--elevated\" },\n});\nexport const cardTitle = builder({ tag: \"h3\", base: \"klods-card__title\" });\nexport const cardBody = builder({ tag: \"div\", base: \"klods-card__body\" });\nexport const cardFooter = builder({ tag: \"div\", base: \"klods-card__footer\" });\n\n// ── Button ───────────────────────────────────────────────────────────────\nexport type ButtonProps = {\n variant?: \"default\" | \"primary\" | \"danger\" | \"ghost\";\n type?: \"button\" | \"submit\" | \"reset\";\n};\nconst buttonBase = builder<ButtonProps>({\n tag: \"button\",\n base: \"klods-button\",\n modifiers: {\n variant: (v) => (v && v !== \"default\" ? `klods-button--${v}` : undefined),\n },\n});\nexport function button(props?: (ButtonProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode {\n // Default `type=\"button\"` so it never accidentally submits a form.\n const merged = { type: \"button\", ...(props ?? {}) } as ButtonProps & KlodsAttrs;\n return buttonBase(merged, children);\n}\n\n// ── Badge ────────────────────────────────────────────────────────────────\nexport type BadgeProps = {\n variant?: \"default\" | \"accent\" | \"success\" | \"danger\";\n};\nexport const badge = builder<BadgeProps>({\n tag: \"span\",\n base: \"klods-badge\",\n modifiers: {\n variant: (v) => (v && v !== \"default\" ? `klods-badge--${v}` : undefined),\n },\n});\n\n// ── Alert ────────────────────────────────────────────────────────────────\nexport type AlertProps = {\n variant?: \"default\" | \"info\" | \"success\" | \"warning\" | \"danger\";\n};\nconst alertBase = builder<AlertProps>({\n tag: \"div\",\n base: \"klods-alert\",\n modifiers: {\n variant: (v) => (v && v !== \"default\" ? `klods-alert--${v}` : undefined),\n },\n});\nexport function alert(props?: (AlertProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode {\n // role=alert by default for assistive tech, overridable.\n const merged = { role: \"alert\", ...(props ?? {}) } as AlertProps & KlodsAttrs;\n return alertBase(merged, children);\n}\n\n// ── Prose helpers ────────────────────────────────────────────────────────\nexport const prose = builder({ tag: \"div\", base: \"klods-prose\" });\nexport const muted = builder({ tag: \"span\", base: \"klods-muted\" });\nexport const lead = builder({ tag: \"p\", base: \"klods-lead\" });\n","// Layout builders — the four corners and the \"I-always-forget\" utilities.\n// Each builder is a thin wrapper around `builder()` from core.ts.\n\nimport type { KlodsAttrs, KlodsChild } from \"./core.js\";\nimport { builder, KlodsNode } from \"./core.js\";\n\n// ── Page ─────────────────────────────────────────────────────────────────\nexport type PageProps = {\n /** Render with a sidebar column. */\n sidebar?: boolean;\n /** Place the sidebar on the right (only meaningful with `sidebar: true`). */\n sidebarRight?: boolean;\n};\n\nexport const page = builder<PageProps>({\n tag: \"div\",\n base: \"klods-page\",\n modifiers: {\n sidebar: \"klods-page--with-sidebar\",\n sidebarRight: \"klods-page--sidebar-right\",\n },\n});\n\n// ── Page slots ───────────────────────────────────────────────────────────\nexport const header = builder({ tag: \"header\", base: \"klods-header\" });\nexport const sidebar = builder({ tag: \"aside\", base: \"klods-sidebar\" });\n\nexport type ContentProps = {\n /** Cap content width to --klods-content-max and centre it. */\n narrow?: boolean;\n};\nexport const content = builder<ContentProps>({\n tag: \"main\",\n base: \"klods-content\",\n modifiers: { narrow: \"klods-content--narrow\" },\n});\n\nexport const footer = builder({ tag: \"footer\", base: \"klods-footer\" });\n\n// ── Layout utilities ─────────────────────────────────────────────────────\ntype GapProp = { gap?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 };\n\nconst gapModifier = (prefix: string) => (v: number | undefined) =>\n v === undefined ? undefined : `${prefix}--gap-${v}`;\n\nexport const stack = builder<GapProp>({\n tag: \"div\",\n base: \"klods-stack\",\n modifiers: { gap: gapModifier(\"klods-stack\") },\n});\n\nexport const cluster = builder<GapProp>({\n tag: \"div\",\n base: \"klods-cluster\",\n modifiers: { gap: gapModifier(\"klods-cluster\") },\n});\n\nexport const row = builder<GapProp>({\n tag: \"div\",\n base: \"klods-row\",\n modifiers: { gap: gapModifier(\"klods-row\") },\n});\n\nexport type GridProps = GapProp & {\n cols?: 1 | 2 | 3 | 4 | 5 | 6;\n /** Auto-fit responsive columns; pair with `--klods-grid-min` if you want a custom minimum. */\n fit?: boolean;\n};\nexport const grid = builder<GridProps>({\n tag: \"div\",\n base: \"klods-grid\",\n modifiers: {\n gap: gapModifier(\"klods-grid\"),\n cols: (v) => (v === undefined ? undefined : `klods-grid--cols-${v}`),\n fit: \"klods-grid--fit\",\n },\n});\n\nexport const center = builder({ tag: \"div\", base: \"klods-center\" });\nexport const spread = builder({ tag: \"div\", base: \"klods-spread\" });\n\n// ── Convenience: empty fragment-ish wrapper for quick text + nodes ──────\nexport function text(value: string | number): KlodsNode {\n // Wrap loose text in a span so it composes anywhere a KlodsNode is expected.\n return new KlodsNode(\"span\", {}, [String(value)]);\n}\n\n// Re-export attribute / child types so consumers can extend a builder neatly.\nexport type { KlodsAttrs, KlodsChild };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBA,IAAM,YAAY,oBAAI,IAAI;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,MAAM,uBAAO,WAAW;AAKvB,SAAS,IAAI,MAAuB;AACzC,SAAO,EAAE,CAAC,GAAG,GAAG,MAAM,KAAK;AAC7B;AAEA,SAAS,MAAM,OAAkC;AAC/C,SAAO,OAAO,UAAU,YAAY,UAAU,QAAS,MAA8B,GAAG,MAAM;AAChG;AAEA,SAAS,WAAW,KAAqB;AACvC,SAAO,IACJ,QAAQ,MAAM,OAAO,EACrB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,QAAQ,EACtB,QAAQ,MAAM,OAAO;AAC1B;AAEA,SAAS,WAAW,KAAqB;AACvC,SAAO,IAAI,QAAQ,MAAM,OAAO,EAAE,QAAQ,MAAM,QAAQ;AAC1D;AAGO,SAAS,WAAW,OAAoC;AAC7D,MAAI,CAAC,MAAO,QAAO;AACnB,MAAI,OAAO,UAAU,SAAU,QAAO,MA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AAQ,EAAE,KAAK,OAAO,MAAM,eAAe,CAAC;AAC3D,IAAM,SAAS,QAAQ,EAAE,KAAK,OAAO,MAAM,eAAe,CAAC;AAG3D,SAAS,KAAK,OAAmC;AAEtD,SAAO,IAAI,UAAU,QAAQ,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC;AAClD;","names":["stack","el"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
type KlodsChild = string | number | bigint | boolean | null | undefined | KlodsNode | Node | KlodsChild[];
|
|
2
|
+
type KlodsAttrs = {
|
|
3
|
+
class?: string | string[] | Record<string, boolean | undefined> | undefined;
|
|
4
|
+
id?: string | undefined;
|
|
5
|
+
style?: string | Partial<CSSStyleDeclaration> | undefined;
|
|
6
|
+
[key: `data-${string}`]: string | number | boolean | undefined;
|
|
7
|
+
[key: `aria-${string}`]: string | number | boolean | undefined;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
declare const RAW: unique symbol;
|
|
11
|
+
type RawHtml = {
|
|
12
|
+
[RAW]: true;
|
|
13
|
+
html: string;
|
|
14
|
+
};
|
|
15
|
+
/** Mark a string as already-escaped HTML; pass it as a child to inject as-is. */
|
|
16
|
+
declare function raw(html: string): RawHtml;
|
|
17
|
+
/** Normalise a `class` value (string | array | record) into a clean string. */
|
|
18
|
+
declare function classNames(input: KlodsAttrs["class"]): string;
|
|
19
|
+
/** Merge two class values (used internally to combine builder defaults + user-supplied). */
|
|
20
|
+
declare function mergeClasses(...inputs: Array<KlodsAttrs["class"]>): string;
|
|
21
|
+
declare class KlodsNode {
|
|
22
|
+
readonly tag: string;
|
|
23
|
+
readonly attrs: KlodsAttrs;
|
|
24
|
+
readonly children: KlodsChild[];
|
|
25
|
+
constructor(tag: string, attrs?: KlodsAttrs, children?: KlodsChild | KlodsChild[]);
|
|
26
|
+
/** Render to a real DOM element. If `target` is given, append to it. */
|
|
27
|
+
render(target?: Element | null): HTMLElement;
|
|
28
|
+
/** Render to a string of HTML. */
|
|
29
|
+
toString(): string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generic element builder. Most consumers use the named builders (page, header, …)
|
|
33
|
+
* rather than calling `el` directly, but it's exported as an escape hatch.
|
|
34
|
+
*/
|
|
35
|
+
declare function el(tag: string, attrs?: KlodsAttrs, children?: KlodsChild | KlodsChild[]): KlodsNode;
|
|
36
|
+
/**
|
|
37
|
+
* Factory that produces a typed builder for a tag with a base class. Modifier
|
|
38
|
+
* props are converted into `--modifier` BEM classes and stripped from the output
|
|
39
|
+
* attributes; everything else passes through untouched, so consumers can attach
|
|
40
|
+
* arbitrary `id`, `data-*`, `aria-*`, event handlers, `style`, etc.
|
|
41
|
+
*/
|
|
42
|
+
declare function builder<P extends Record<string, unknown> = Record<string, never>>(options: {
|
|
43
|
+
tag: string;
|
|
44
|
+
base: string;
|
|
45
|
+
/** Map of prop name → class (or function returning a class) when the prop is truthy. */
|
|
46
|
+
modifiers?: {
|
|
47
|
+
[K in keyof P]?: string | ((value: P[K]) => string | undefined);
|
|
48
|
+
};
|
|
49
|
+
}): (props?: (P & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
50
|
+
|
|
51
|
+
declare const nav: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
52
|
+
declare const navList: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
53
|
+
type NavLinkProps = {
|
|
54
|
+
href?: string;
|
|
55
|
+
active?: boolean;
|
|
56
|
+
};
|
|
57
|
+
declare function navLink(props?: (NavLinkProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode;
|
|
58
|
+
type CardProps = {
|
|
59
|
+
elevated?: boolean;
|
|
60
|
+
};
|
|
61
|
+
declare const card: (props?: (CardProps & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
62
|
+
declare const cardTitle: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
63
|
+
declare const cardBody: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
64
|
+
declare const cardFooter: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
65
|
+
type ButtonProps = {
|
|
66
|
+
variant?: "default" | "primary" | "danger" | "ghost";
|
|
67
|
+
type?: "button" | "submit" | "reset";
|
|
68
|
+
};
|
|
69
|
+
declare function button(props?: (ButtonProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode;
|
|
70
|
+
type BadgeProps = {
|
|
71
|
+
variant?: "default" | "accent" | "success" | "danger";
|
|
72
|
+
};
|
|
73
|
+
declare const badge: (props?: (BadgeProps & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
74
|
+
type AlertProps = {
|
|
75
|
+
variant?: "default" | "info" | "success" | "warning" | "danger";
|
|
76
|
+
};
|
|
77
|
+
declare function alert(props?: (AlertProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode;
|
|
78
|
+
declare const prose: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
79
|
+
declare const muted: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
80
|
+
declare const lead: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
81
|
+
|
|
82
|
+
type PageProps = {
|
|
83
|
+
/** Render with a sidebar column. */
|
|
84
|
+
sidebar?: boolean;
|
|
85
|
+
/** Place the sidebar on the right (only meaningful with `sidebar: true`). */
|
|
86
|
+
sidebarRight?: boolean;
|
|
87
|
+
};
|
|
88
|
+
declare const page: (props?: (PageProps & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
89
|
+
declare const header: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
90
|
+
declare const sidebar: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
91
|
+
type ContentProps = {
|
|
92
|
+
/** Cap content width to --klods-content-max and centre it. */
|
|
93
|
+
narrow?: boolean;
|
|
94
|
+
};
|
|
95
|
+
declare const content: (props?: (ContentProps & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
96
|
+
declare const footer: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
97
|
+
type GapProp = {
|
|
98
|
+
gap?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
99
|
+
};
|
|
100
|
+
declare const stack: (props?: (GapProp & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
101
|
+
declare const cluster: (props?: (GapProp & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
102
|
+
declare const row: (props?: (GapProp & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
103
|
+
type GridProps = GapProp & {
|
|
104
|
+
cols?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
105
|
+
/** Auto-fit responsive columns; pair with `--klods-grid-min` if you want a custom minimum. */
|
|
106
|
+
fit?: boolean;
|
|
107
|
+
};
|
|
108
|
+
declare const grid: (props?: (GapProp & {
|
|
109
|
+
cols?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
110
|
+
/** Auto-fit responsive columns; pair with `--klods-grid-min` if you want a custom minimum. */
|
|
111
|
+
fit?: boolean;
|
|
112
|
+
} & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
113
|
+
declare const center: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
114
|
+
declare const spread: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
115
|
+
declare function text(value: string | number): KlodsNode;
|
|
116
|
+
|
|
117
|
+
export { type AlertProps, type BadgeProps, type ButtonProps, type CardProps, type ContentProps, type GridProps, type KlodsAttrs, type KlodsChild, KlodsNode, type NavLinkProps, type PageProps, alert, badge, builder, button, card, cardBody, cardFooter, cardTitle, center, classNames, cluster, content, el, footer, grid, header, lead, mergeClasses, muted, nav, navLink, navList, page, prose, raw, row, sidebar, spread, stack, text };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
type KlodsChild = string | number | bigint | boolean | null | undefined | KlodsNode | Node | KlodsChild[];
|
|
2
|
+
type KlodsAttrs = {
|
|
3
|
+
class?: string | string[] | Record<string, boolean | undefined> | undefined;
|
|
4
|
+
id?: string | undefined;
|
|
5
|
+
style?: string | Partial<CSSStyleDeclaration> | undefined;
|
|
6
|
+
[key: `data-${string}`]: string | number | boolean | undefined;
|
|
7
|
+
[key: `aria-${string}`]: string | number | boolean | undefined;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
declare const RAW: unique symbol;
|
|
11
|
+
type RawHtml = {
|
|
12
|
+
[RAW]: true;
|
|
13
|
+
html: string;
|
|
14
|
+
};
|
|
15
|
+
/** Mark a string as already-escaped HTML; pass it as a child to inject as-is. */
|
|
16
|
+
declare function raw(html: string): RawHtml;
|
|
17
|
+
/** Normalise a `class` value (string | array | record) into a clean string. */
|
|
18
|
+
declare function classNames(input: KlodsAttrs["class"]): string;
|
|
19
|
+
/** Merge two class values (used internally to combine builder defaults + user-supplied). */
|
|
20
|
+
declare function mergeClasses(...inputs: Array<KlodsAttrs["class"]>): string;
|
|
21
|
+
declare class KlodsNode {
|
|
22
|
+
readonly tag: string;
|
|
23
|
+
readonly attrs: KlodsAttrs;
|
|
24
|
+
readonly children: KlodsChild[];
|
|
25
|
+
constructor(tag: string, attrs?: KlodsAttrs, children?: KlodsChild | KlodsChild[]);
|
|
26
|
+
/** Render to a real DOM element. If `target` is given, append to it. */
|
|
27
|
+
render(target?: Element | null): HTMLElement;
|
|
28
|
+
/** Render to a string of HTML. */
|
|
29
|
+
toString(): string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generic element builder. Most consumers use the named builders (page, header, …)
|
|
33
|
+
* rather than calling `el` directly, but it's exported as an escape hatch.
|
|
34
|
+
*/
|
|
35
|
+
declare function el(tag: string, attrs?: KlodsAttrs, children?: KlodsChild | KlodsChild[]): KlodsNode;
|
|
36
|
+
/**
|
|
37
|
+
* Factory that produces a typed builder for a tag with a base class. Modifier
|
|
38
|
+
* props are converted into `--modifier` BEM classes and stripped from the output
|
|
39
|
+
* attributes; everything else passes through untouched, so consumers can attach
|
|
40
|
+
* arbitrary `id`, `data-*`, `aria-*`, event handlers, `style`, etc.
|
|
41
|
+
*/
|
|
42
|
+
declare function builder<P extends Record<string, unknown> = Record<string, never>>(options: {
|
|
43
|
+
tag: string;
|
|
44
|
+
base: string;
|
|
45
|
+
/** Map of prop name → class (or function returning a class) when the prop is truthy. */
|
|
46
|
+
modifiers?: {
|
|
47
|
+
[K in keyof P]?: string | ((value: P[K]) => string | undefined);
|
|
48
|
+
};
|
|
49
|
+
}): (props?: (P & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
50
|
+
|
|
51
|
+
declare const nav: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
52
|
+
declare const navList: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
53
|
+
type NavLinkProps = {
|
|
54
|
+
href?: string;
|
|
55
|
+
active?: boolean;
|
|
56
|
+
};
|
|
57
|
+
declare function navLink(props?: (NavLinkProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode;
|
|
58
|
+
type CardProps = {
|
|
59
|
+
elevated?: boolean;
|
|
60
|
+
};
|
|
61
|
+
declare const card: (props?: (CardProps & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
62
|
+
declare const cardTitle: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
63
|
+
declare const cardBody: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
64
|
+
declare const cardFooter: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
65
|
+
type ButtonProps = {
|
|
66
|
+
variant?: "default" | "primary" | "danger" | "ghost";
|
|
67
|
+
type?: "button" | "submit" | "reset";
|
|
68
|
+
};
|
|
69
|
+
declare function button(props?: (ButtonProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode;
|
|
70
|
+
type BadgeProps = {
|
|
71
|
+
variant?: "default" | "accent" | "success" | "danger";
|
|
72
|
+
};
|
|
73
|
+
declare const badge: (props?: (BadgeProps & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
74
|
+
type AlertProps = {
|
|
75
|
+
variant?: "default" | "info" | "success" | "warning" | "danger";
|
|
76
|
+
};
|
|
77
|
+
declare function alert(props?: (AlertProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode;
|
|
78
|
+
declare const prose: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
79
|
+
declare const muted: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
80
|
+
declare const lead: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
81
|
+
|
|
82
|
+
type PageProps = {
|
|
83
|
+
/** Render with a sidebar column. */
|
|
84
|
+
sidebar?: boolean;
|
|
85
|
+
/** Place the sidebar on the right (only meaningful with `sidebar: true`). */
|
|
86
|
+
sidebarRight?: boolean;
|
|
87
|
+
};
|
|
88
|
+
declare const page: (props?: (PageProps & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
89
|
+
declare const header: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
90
|
+
declare const sidebar: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
91
|
+
type ContentProps = {
|
|
92
|
+
/** Cap content width to --klods-content-max and centre it. */
|
|
93
|
+
narrow?: boolean;
|
|
94
|
+
};
|
|
95
|
+
declare const content: (props?: (ContentProps & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
96
|
+
declare const footer: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
97
|
+
type GapProp = {
|
|
98
|
+
gap?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
99
|
+
};
|
|
100
|
+
declare const stack: (props?: (GapProp & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
101
|
+
declare const cluster: (props?: (GapProp & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
102
|
+
declare const row: (props?: (GapProp & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
103
|
+
type GridProps = GapProp & {
|
|
104
|
+
cols?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
105
|
+
/** Auto-fit responsive columns; pair with `--klods-grid-min` if you want a custom minimum. */
|
|
106
|
+
fit?: boolean;
|
|
107
|
+
};
|
|
108
|
+
declare const grid: (props?: (GapProp & {
|
|
109
|
+
cols?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
110
|
+
/** Auto-fit responsive columns; pair with `--klods-grid-min` if you want a custom minimum. */
|
|
111
|
+
fit?: boolean;
|
|
112
|
+
} & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
113
|
+
declare const center: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
114
|
+
declare const spread: (props?: (Record<string, never> & KlodsAttrs) | null | undefined, children?: KlodsChild | KlodsChild[]) => KlodsNode;
|
|
115
|
+
declare function text(value: string | number): KlodsNode;
|
|
116
|
+
|
|
117
|
+
export { type AlertProps, type BadgeProps, type ButtonProps, type CardProps, type ContentProps, type GridProps, type KlodsAttrs, type KlodsChild, KlodsNode, type NavLinkProps, type PageProps, alert, badge, builder, button, card, cardBody, cardFooter, cardTitle, center, classNames, cluster, content, el, footer, grid, header, lead, mergeClasses, muted, nav, navLink, navList, page, prose, raw, row, sidebar, spread, stack, text };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
// src/core.ts
|
|
2
|
+
var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
3
|
+
"area",
|
|
4
|
+
"base",
|
|
5
|
+
"br",
|
|
6
|
+
"col",
|
|
7
|
+
"embed",
|
|
8
|
+
"hr",
|
|
9
|
+
"img",
|
|
10
|
+
"input",
|
|
11
|
+
"link",
|
|
12
|
+
"meta",
|
|
13
|
+
"source",
|
|
14
|
+
"track",
|
|
15
|
+
"wbr"
|
|
16
|
+
]);
|
|
17
|
+
var RAW = /* @__PURE__ */ Symbol("klods.raw");
|
|
18
|
+
function raw(html) {
|
|
19
|
+
return { [RAW]: true, html };
|
|
20
|
+
}
|
|
21
|
+
function isRaw(value) {
|
|
22
|
+
return typeof value === "object" && value !== null && value[RAW] === true;
|
|
23
|
+
}
|
|
24
|
+
function escapeHtml(str) {
|
|
25
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
26
|
+
}
|
|
27
|
+
function escapeAttr(str) {
|
|
28
|
+
return str.replace(/&/g, "&").replace(/"/g, """);
|
|
29
|
+
}
|
|
30
|
+
function classNames(input) {
|
|
31
|
+
if (!input) return "";
|
|
32
|
+
if (typeof input === "string") return input.trim();
|
|
33
|
+
if (Array.isArray(input)) return input.filter(Boolean).join(" ").trim();
|
|
34
|
+
return Object.entries(input).filter(([, v]) => Boolean(v)).map(([k]) => k).join(" ").trim();
|
|
35
|
+
}
|
|
36
|
+
function mergeClasses(...inputs) {
|
|
37
|
+
return inputs.map((c) => classNames(c)).filter(Boolean).join(" ");
|
|
38
|
+
}
|
|
39
|
+
function styleToString(style) {
|
|
40
|
+
if (typeof style === "string") return style;
|
|
41
|
+
return Object.entries(style).filter(([, v]) => v !== void 0 && v !== null && v !== "").map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}:${String(v)}`).join(";");
|
|
42
|
+
}
|
|
43
|
+
function flattenChildren(children) {
|
|
44
|
+
const out = [];
|
|
45
|
+
const stack2 = Array.isArray(children) ? [...children] : [children];
|
|
46
|
+
while (stack2.length) {
|
|
47
|
+
const next = stack2.shift();
|
|
48
|
+
if (Array.isArray(next)) stack2.unshift(...next);
|
|
49
|
+
else if (next !== null && next !== void 0 && next !== false && next !== true) out.push(next);
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
var KlodsNode = class _KlodsNode {
|
|
54
|
+
tag;
|
|
55
|
+
attrs;
|
|
56
|
+
children;
|
|
57
|
+
constructor(tag, attrs = {}, children = []) {
|
|
58
|
+
this.tag = tag;
|
|
59
|
+
this.attrs = attrs;
|
|
60
|
+
this.children = Array.isArray(children) ? children : [children];
|
|
61
|
+
}
|
|
62
|
+
/** Render to a real DOM element. If `target` is given, append to it. */
|
|
63
|
+
render(target) {
|
|
64
|
+
const el2 = document.createElement(this.tag);
|
|
65
|
+
for (const [name, value] of Object.entries(this.attrs)) {
|
|
66
|
+
if (value === void 0 || value === null || value === false) continue;
|
|
67
|
+
if (name === "children") continue;
|
|
68
|
+
if (name === "class") {
|
|
69
|
+
const cls = classNames(value);
|
|
70
|
+
if (cls) el2.setAttribute("class", cls);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (name === "style") {
|
|
74
|
+
el2.setAttribute("style", styleToString(value));
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (name.startsWith("on") && typeof value === "function") {
|
|
78
|
+
el2.addEventListener(name.slice(2).toLowerCase(), value);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (value === true) {
|
|
82
|
+
el2.setAttribute(name, "");
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
el2.setAttribute(name, String(value));
|
|
86
|
+
}
|
|
87
|
+
for (const child of flattenChildren(this.children)) {
|
|
88
|
+
if (child instanceof _KlodsNode) el2.appendChild(child.render());
|
|
89
|
+
else if (typeof child === "object" && child !== null && "nodeType" in child) {
|
|
90
|
+
el2.appendChild(child);
|
|
91
|
+
} else if (isRaw(child)) {
|
|
92
|
+
const tpl = document.createElement("template");
|
|
93
|
+
tpl.innerHTML = child.html;
|
|
94
|
+
el2.appendChild(tpl.content);
|
|
95
|
+
} else {
|
|
96
|
+
el2.appendChild(document.createTextNode(String(child)));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (target) target.appendChild(el2);
|
|
100
|
+
return el2;
|
|
101
|
+
}
|
|
102
|
+
/** Render to a string of HTML. */
|
|
103
|
+
toString() {
|
|
104
|
+
const parts = [`<${this.tag}`];
|
|
105
|
+
for (const [name, value] of Object.entries(this.attrs)) {
|
|
106
|
+
if (value === void 0 || value === null || value === false) continue;
|
|
107
|
+
if (name === "children") continue;
|
|
108
|
+
if (name.startsWith("on") && typeof value === "function") continue;
|
|
109
|
+
if (name === "class") {
|
|
110
|
+
const cls = classNames(value);
|
|
111
|
+
if (cls) parts.push(` class="${escapeAttr(cls)}"`);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (name === "style") {
|
|
115
|
+
parts.push(` style="${escapeAttr(styleToString(value))}"`);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (value === true) {
|
|
119
|
+
parts.push(` ${name}`);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
parts.push(` ${name}="${escapeAttr(String(value))}"`);
|
|
123
|
+
}
|
|
124
|
+
if (VOID_TAGS.has(this.tag)) {
|
|
125
|
+
parts.push(" />");
|
|
126
|
+
return parts.join("");
|
|
127
|
+
}
|
|
128
|
+
parts.push(">");
|
|
129
|
+
for (const child of flattenChildren(this.children)) {
|
|
130
|
+
if (child instanceof _KlodsNode) parts.push(child.toString());
|
|
131
|
+
else if (isRaw(child)) parts.push(child.html);
|
|
132
|
+
else if (typeof child === "object" && child !== null && "outerHTML" in child) {
|
|
133
|
+
parts.push(child.outerHTML);
|
|
134
|
+
} else {
|
|
135
|
+
parts.push(escapeHtml(String(child)));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
parts.push(`</${this.tag}>`);
|
|
139
|
+
return parts.join("");
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
function el(tag, attrs = {}, children = []) {
|
|
143
|
+
return new KlodsNode(tag, attrs, children);
|
|
144
|
+
}
|
|
145
|
+
function builder(options) {
|
|
146
|
+
const { tag, base, modifiers = {} } = options;
|
|
147
|
+
const modifierMap = modifiers;
|
|
148
|
+
return (props, children) => {
|
|
149
|
+
const userProps = props ?? {};
|
|
150
|
+
const modClasses = [];
|
|
151
|
+
const passthrough = {};
|
|
152
|
+
for (const [key, value] of Object.entries(userProps)) {
|
|
153
|
+
const m = modifierMap[key];
|
|
154
|
+
if (m !== void 0) {
|
|
155
|
+
if (typeof m === "function") {
|
|
156
|
+
const c = m(value);
|
|
157
|
+
if (c) modClasses.push(c);
|
|
158
|
+
} else if (value) {
|
|
159
|
+
modClasses.push(m);
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
passthrough[key] = value;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const finalClass = mergeClasses(base, ...modClasses, userProps.class);
|
|
166
|
+
const resolvedChildren = children !== void 0 ? children : userProps.children ?? [];
|
|
167
|
+
delete passthrough.children;
|
|
168
|
+
return new KlodsNode(tag, { ...passthrough, class: finalClass || void 0 }, resolvedChildren);
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/components.ts
|
|
173
|
+
var nav = builder({ tag: "nav", base: "klods-nav" });
|
|
174
|
+
var navList = builder({ tag: "ul", base: "klods-nav__list" });
|
|
175
|
+
var navLinkBuilder = builder({
|
|
176
|
+
tag: "a",
|
|
177
|
+
base: "klods-nav__link",
|
|
178
|
+
modifiers: { active: "klods-nav__link--active" }
|
|
179
|
+
});
|
|
180
|
+
function navLink(props, children) {
|
|
181
|
+
return el("li", {}, [navLinkBuilder(props ?? null, children)]);
|
|
182
|
+
}
|
|
183
|
+
var card = builder({
|
|
184
|
+
tag: "div",
|
|
185
|
+
base: "klods-card",
|
|
186
|
+
modifiers: { elevated: "klods-card--elevated" }
|
|
187
|
+
});
|
|
188
|
+
var cardTitle = builder({ tag: "h3", base: "klods-card__title" });
|
|
189
|
+
var cardBody = builder({ tag: "div", base: "klods-card__body" });
|
|
190
|
+
var cardFooter = builder({ tag: "div", base: "klods-card__footer" });
|
|
191
|
+
var buttonBase = builder({
|
|
192
|
+
tag: "button",
|
|
193
|
+
base: "klods-button",
|
|
194
|
+
modifiers: {
|
|
195
|
+
variant: (v) => v && v !== "default" ? `klods-button--${v}` : void 0
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
function button(props, children) {
|
|
199
|
+
const merged = { type: "button", ...props ?? {} };
|
|
200
|
+
return buttonBase(merged, children);
|
|
201
|
+
}
|
|
202
|
+
var badge = builder({
|
|
203
|
+
tag: "span",
|
|
204
|
+
base: "klods-badge",
|
|
205
|
+
modifiers: {
|
|
206
|
+
variant: (v) => v && v !== "default" ? `klods-badge--${v}` : void 0
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
var alertBase = builder({
|
|
210
|
+
tag: "div",
|
|
211
|
+
base: "klods-alert",
|
|
212
|
+
modifiers: {
|
|
213
|
+
variant: (v) => v && v !== "default" ? `klods-alert--${v}` : void 0
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
function alert(props, children) {
|
|
217
|
+
const merged = { role: "alert", ...props ?? {} };
|
|
218
|
+
return alertBase(merged, children);
|
|
219
|
+
}
|
|
220
|
+
var prose = builder({ tag: "div", base: "klods-prose" });
|
|
221
|
+
var muted = builder({ tag: "span", base: "klods-muted" });
|
|
222
|
+
var lead = builder({ tag: "p", base: "klods-lead" });
|
|
223
|
+
|
|
224
|
+
// src/layout.ts
|
|
225
|
+
var page = builder({
|
|
226
|
+
tag: "div",
|
|
227
|
+
base: "klods-page",
|
|
228
|
+
modifiers: {
|
|
229
|
+
sidebar: "klods-page--with-sidebar",
|
|
230
|
+
sidebarRight: "klods-page--sidebar-right"
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
var header = builder({ tag: "header", base: "klods-header" });
|
|
234
|
+
var sidebar = builder({ tag: "aside", base: "klods-sidebar" });
|
|
235
|
+
var content = builder({
|
|
236
|
+
tag: "main",
|
|
237
|
+
base: "klods-content",
|
|
238
|
+
modifiers: { narrow: "klods-content--narrow" }
|
|
239
|
+
});
|
|
240
|
+
var footer = builder({ tag: "footer", base: "klods-footer" });
|
|
241
|
+
var gapModifier = (prefix) => (v) => v === void 0 ? void 0 : `${prefix}--gap-${v}`;
|
|
242
|
+
var stack = builder({
|
|
243
|
+
tag: "div",
|
|
244
|
+
base: "klods-stack",
|
|
245
|
+
modifiers: { gap: gapModifier("klods-stack") }
|
|
246
|
+
});
|
|
247
|
+
var cluster = builder({
|
|
248
|
+
tag: "div",
|
|
249
|
+
base: "klods-cluster",
|
|
250
|
+
modifiers: { gap: gapModifier("klods-cluster") }
|
|
251
|
+
});
|
|
252
|
+
var row = builder({
|
|
253
|
+
tag: "div",
|
|
254
|
+
base: "klods-row",
|
|
255
|
+
modifiers: { gap: gapModifier("klods-row") }
|
|
256
|
+
});
|
|
257
|
+
var grid = builder({
|
|
258
|
+
tag: "div",
|
|
259
|
+
base: "klods-grid",
|
|
260
|
+
modifiers: {
|
|
261
|
+
gap: gapModifier("klods-grid"),
|
|
262
|
+
cols: (v) => v === void 0 ? void 0 : `klods-grid--cols-${v}`,
|
|
263
|
+
fit: "klods-grid--fit"
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
var center = builder({ tag: "div", base: "klods-center" });
|
|
267
|
+
var spread = builder({ tag: "div", base: "klods-spread" });
|
|
268
|
+
function text(value) {
|
|
269
|
+
return new KlodsNode("span", {}, [String(value)]);
|
|
270
|
+
}
|
|
271
|
+
export {
|
|
272
|
+
KlodsNode,
|
|
273
|
+
alert,
|
|
274
|
+
badge,
|
|
275
|
+
builder,
|
|
276
|
+
button,
|
|
277
|
+
card,
|
|
278
|
+
cardBody,
|
|
279
|
+
cardFooter,
|
|
280
|
+
cardTitle,
|
|
281
|
+
center,
|
|
282
|
+
classNames,
|
|
283
|
+
cluster,
|
|
284
|
+
content,
|
|
285
|
+
el,
|
|
286
|
+
footer,
|
|
287
|
+
grid,
|
|
288
|
+
header,
|
|
289
|
+
lead,
|
|
290
|
+
mergeClasses,
|
|
291
|
+
muted,
|
|
292
|
+
nav,
|
|
293
|
+
navLink,
|
|
294
|
+
navList,
|
|
295
|
+
page,
|
|
296
|
+
prose,
|
|
297
|
+
raw,
|
|
298
|
+
row,
|
|
299
|
+
sidebar,
|
|
300
|
+
spread,
|
|
301
|
+
stack,
|
|
302
|
+
text
|
|
303
|
+
};
|
|
304
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core.ts","../src/components.ts","../src/layout.ts"],"sourcesContent":["// Core — a tiny VDOM-ish node with two faces:\n// - .render(target?) → HTMLElement (uses real DOM)\n// - .toString() → HTML string (works in Node / Rails / SSR)\n//\n// Both are produced from the same KlodsNode tree, so the docs site can show the\n// TS source, the rendered HTML and the live preview from one source of truth.\n\nexport type KlodsChild = string | number | bigint | boolean | null | undefined | KlodsNode | Node | KlodsChild[];\n\nexport type KlodsAttrs = {\n class?: string | string[] | Record<string, boolean | undefined> | undefined;\n id?: string | undefined;\n style?: string | Partial<CSSStyleDeclaration> | undefined;\n [key: `data-${string}`]: string | number | boolean | undefined;\n [key: `aria-${string}`]: string | number | boolean | undefined;\n // Allow any other HTML attribute or DOM event handler (onClick, onInput, …).\n [key: string]: unknown;\n};\n\nconst VOID_TAGS = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"link\",\n \"meta\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\nconst RAW = Symbol(\"klods.raw\");\n\ntype RawHtml = { [RAW]: true; html: string };\n\n/** Mark a string as already-escaped HTML; pass it as a child to inject as-is. */\nexport function raw(html: string): RawHtml {\n return { [RAW]: true, html };\n}\n\nfunction isRaw(value: unknown): value is RawHtml {\n return typeof value === \"object\" && value !== null && (value as { [RAW]?: unknown })[RAW] === true;\n}\n\nfunction escapeHtml(str: string): string {\n return str\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n}\n\nfunction escapeAttr(str: string): string {\n return str.replace(/&/g, \"&\").replace(/\"/g, \""\");\n}\n\n/** Normalise a `class` value (string | array | record) into a clean string. */\nexport function classNames(input: KlodsAttrs[\"class\"]): string {\n if (!input) return \"\";\n if (typeof input === \"string\") return input.trim();\n if (Array.isArray(input)) return input.filter(Boolean).join(\" \").trim();\n return Object.entries(input)\n .filter(([, v]) => Boolean(v))\n .map(([k]) => k)\n .join(\" \")\n .trim();\n}\n\n/** Merge two class values (used internally to combine builder defaults + user-supplied). */\nexport function mergeClasses(...inputs: Array<KlodsAttrs[\"class\"]>): string {\n return inputs\n .map((c) => classNames(c))\n .filter(Boolean)\n .join(\" \");\n}\n\nfunction styleToString(style: string | Partial<CSSStyleDeclaration>): string {\n if (typeof style === \"string\") return style;\n return Object.entries(style)\n .filter(([, v]) => v !== undefined && v !== null && v !== \"\")\n .map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}:${String(v)}`)\n .join(\";\");\n}\n\nfunction flattenChildren(children: KlodsChild | KlodsChild[]): Array<Exclude<KlodsChild, KlodsChild[]>> {\n const out: Array<Exclude<KlodsChild, KlodsChild[]>> = [];\n const stack: KlodsChild[] = Array.isArray(children) ? [...children] : [children];\n while (stack.length) {\n const next = stack.shift();\n if (Array.isArray(next)) stack.unshift(...next);\n else if (next !== null && next !== undefined && next !== false && next !== true) out.push(next);\n }\n return out;\n}\n\nexport class KlodsNode {\n readonly tag: string;\n readonly attrs: KlodsAttrs;\n readonly children: KlodsChild[];\n\n constructor(tag: string, attrs: KlodsAttrs = {}, children: KlodsChild | KlodsChild[] = []) {\n this.tag = tag;\n this.attrs = attrs;\n this.children = Array.isArray(children) ? children : [children];\n }\n\n /** Render to a real DOM element. If `target` is given, append to it. */\n render(target?: Element | null): HTMLElement {\n const el = document.createElement(this.tag);\n for (const [name, value] of Object.entries(this.attrs)) {\n if (value === undefined || value === null || value === false) continue;\n if (name === \"children\") continue;\n if (name === \"class\") {\n const cls = classNames(value as KlodsAttrs[\"class\"]);\n if (cls) el.setAttribute(\"class\", cls);\n continue;\n }\n if (name === \"style\") {\n el.setAttribute(\"style\", styleToString(value as string | Partial<CSSStyleDeclaration>));\n continue;\n }\n if (name.startsWith(\"on\") && typeof value === \"function\") {\n el.addEventListener(name.slice(2).toLowerCase(), value as EventListener);\n continue;\n }\n if (value === true) {\n el.setAttribute(name, \"\");\n continue;\n }\n el.setAttribute(name, String(value));\n }\n for (const child of flattenChildren(this.children)) {\n if (child instanceof KlodsNode) el.appendChild(child.render());\n else if (typeof child === \"object\" && child !== null && \"nodeType\" in child) {\n el.appendChild(child as Node);\n } else if (isRaw(child)) {\n const tpl = document.createElement(\"template\");\n tpl.innerHTML = child.html;\n el.appendChild(tpl.content);\n } else {\n el.appendChild(document.createTextNode(String(child)));\n }\n }\n if (target) target.appendChild(el);\n return el;\n }\n\n /** Render to a string of HTML. */\n toString(): string {\n const parts: string[] = [`<${this.tag}`];\n for (const [name, value] of Object.entries(this.attrs)) {\n if (value === undefined || value === null || value === false) continue;\n if (name === \"children\") continue;\n if (name.startsWith(\"on\") && typeof value === \"function\") continue;\n if (name === \"class\") {\n const cls = classNames(value as KlodsAttrs[\"class\"]);\n if (cls) parts.push(` class=\"${escapeAttr(cls)}\"`);\n continue;\n }\n if (name === \"style\") {\n parts.push(` style=\"${escapeAttr(styleToString(value as string | Partial<CSSStyleDeclaration>))}\"`);\n continue;\n }\n if (value === true) {\n parts.push(` ${name}`);\n continue;\n }\n parts.push(` ${name}=\"${escapeAttr(String(value))}\"`);\n }\n if (VOID_TAGS.has(this.tag)) {\n parts.push(\" />\");\n return parts.join(\"\");\n }\n parts.push(\">\");\n for (const child of flattenChildren(this.children)) {\n if (child instanceof KlodsNode) parts.push(child.toString());\n else if (isRaw(child)) parts.push(child.html);\n else if (typeof child === \"object\" && child !== null && \"outerHTML\" in child) {\n parts.push((child as Element).outerHTML);\n } else {\n parts.push(escapeHtml(String(child)));\n }\n }\n parts.push(`</${this.tag}>`);\n return parts.join(\"\");\n }\n}\n\n/**\n * Generic element builder. Most consumers use the named builders (page, header, …)\n * rather than calling `el` directly, but it's exported as an escape hatch.\n */\nexport function el(tag: string, attrs: KlodsAttrs = {}, children: KlodsChild | KlodsChild[] = []): KlodsNode {\n return new KlodsNode(tag, attrs, children);\n}\n\n/**\n * Factory that produces a typed builder for a tag with a base class. Modifier\n * props are converted into `--modifier` BEM classes and stripped from the output\n * attributes; everything else passes through untouched, so consumers can attach\n * arbitrary `id`, `data-*`, `aria-*`, event handlers, `style`, etc.\n */\nexport function builder<P extends Record<string, unknown> = Record<string, never>>(options: {\n tag: string;\n base: string;\n /** Map of prop name → class (or function returning a class) when the prop is truthy. */\n modifiers?: { [K in keyof P]?: string | ((value: P[K]) => string | undefined) };\n}): (props?: (P & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]) => KlodsNode {\n const { tag, base, modifiers = {} } = options;\n const modifierMap = modifiers as Record<string, string | ((value: unknown) => string | undefined) | undefined>;\n return (props, children) => {\n const userProps = (props ?? {}) as P & KlodsAttrs;\n const modClasses: string[] = [];\n const passthrough: KlodsAttrs = {};\n for (const [key, value] of Object.entries(userProps)) {\n const m = modifierMap[key];\n if (m !== undefined) {\n if (typeof m === \"function\") {\n const c = m(value);\n if (c) modClasses.push(c);\n } else if (value) {\n modClasses.push(m);\n }\n } else {\n passthrough[key] = value;\n }\n }\n const finalClass = mergeClasses(base, ...modClasses, userProps.class);\n const resolvedChildren =\n children !== undefined ? children : ((userProps.children as KlodsChild | KlodsChild[] | undefined) ?? []);\n delete passthrough.children;\n return new KlodsNode(tag, { ...passthrough, class: finalClass || undefined }, resolvedChildren);\n };\n}\n","// First wave of components: nav, card, button, badge, alert, prose helpers.\n// All match the BEM classes shipped by klods-css.\n\nimport type { KlodsAttrs, KlodsChild } from \"./core.js\";\nimport { builder, el, KlodsNode } from \"./core.js\";\n\n// ── Nav ──────────────────────────────────────────────────────────────────\nexport const nav = builder({ tag: \"nav\", base: \"klods-nav\" });\nexport const navList = builder({ tag: \"ul\", base: \"klods-nav__list\" });\n\nexport type NavLinkProps = {\n href?: string;\n active?: boolean;\n};\nconst navLinkBuilder = builder<NavLinkProps>({\n tag: \"a\",\n base: \"klods-nav__link\",\n modifiers: { active: \"klods-nav__link--active\" },\n});\nexport function navLink(props?: (NavLinkProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode {\n // Wrap each link in <li> so it's idiomatic inside <ul class=\"klods-nav__list\">.\n return el(\"li\", {}, [navLinkBuilder(props ?? null, children)]);\n}\n\n// ── Card ─────────────────────────────────────────────────────────────────\nexport type CardProps = {\n elevated?: boolean;\n};\nexport const card = builder<CardProps>({\n tag: \"div\",\n base: \"klods-card\",\n modifiers: { elevated: \"klods-card--elevated\" },\n});\nexport const cardTitle = builder({ tag: \"h3\", base: \"klods-card__title\" });\nexport const cardBody = builder({ tag: \"div\", base: \"klods-card__body\" });\nexport const cardFooter = builder({ tag: \"div\", base: \"klods-card__footer\" });\n\n// ── Button ───────────────────────────────────────────────────────────────\nexport type ButtonProps = {\n variant?: \"default\" | \"primary\" | \"danger\" | \"ghost\";\n type?: \"button\" | \"submit\" | \"reset\";\n};\nconst buttonBase = builder<ButtonProps>({\n tag: \"button\",\n base: \"klods-button\",\n modifiers: {\n variant: (v) => (v && v !== \"default\" ? `klods-button--${v}` : undefined),\n },\n});\nexport function button(props?: (ButtonProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode {\n // Default `type=\"button\"` so it never accidentally submits a form.\n const merged = { type: \"button\", ...(props ?? {}) } as ButtonProps & KlodsAttrs;\n return buttonBase(merged, children);\n}\n\n// ── Badge ────────────────────────────────────────────────────────────────\nexport type BadgeProps = {\n variant?: \"default\" | \"accent\" | \"success\" | \"danger\";\n};\nexport const badge = builder<BadgeProps>({\n tag: \"span\",\n base: \"klods-badge\",\n modifiers: {\n variant: (v) => (v && v !== \"default\" ? `klods-badge--${v}` : undefined),\n },\n});\n\n// ── Alert ────────────────────────────────────────────────────────────────\nexport type AlertProps = {\n variant?: \"default\" | \"info\" | \"success\" | \"warning\" | \"danger\";\n};\nconst alertBase = builder<AlertProps>({\n tag: \"div\",\n base: \"klods-alert\",\n modifiers: {\n variant: (v) => (v && v !== \"default\" ? `klods-alert--${v}` : undefined),\n },\n});\nexport function alert(props?: (AlertProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode {\n // role=alert by default for assistive tech, overridable.\n const merged = { role: \"alert\", ...(props ?? {}) } as AlertProps & KlodsAttrs;\n return alertBase(merged, children);\n}\n\n// ── Prose helpers ────────────────────────────────────────────────────────\nexport const prose = builder({ tag: \"div\", base: \"klods-prose\" });\nexport const muted = builder({ tag: \"span\", base: \"klods-muted\" });\nexport const lead = builder({ tag: \"p\", base: \"klods-lead\" });\n","// Layout builders — the four corners and the \"I-always-forget\" utilities.\n// Each builder is a thin wrapper around `builder()` from core.ts.\n\nimport type { KlodsAttrs, KlodsChild } from \"./core.js\";\nimport { builder, KlodsNode } from \"./core.js\";\n\n// ── Page ─────────────────────────────────────────────────────────────────\nexport type PageProps = {\n /** Render with a sidebar column. */\n sidebar?: boolean;\n /** Place the sidebar on the right (only meaningful with `sidebar: true`). */\n sidebarRight?: boolean;\n};\n\nexport const page = builder<PageProps>({\n tag: \"div\",\n base: \"klods-page\",\n modifiers: {\n sidebar: \"klods-page--with-sidebar\",\n sidebarRight: \"klods-page--sidebar-right\",\n },\n});\n\n// ── Page slots ───────────────────────────────────────────────────────────\nexport const header = builder({ tag: \"header\", base: \"klods-header\" });\nexport const sidebar = builder({ tag: \"aside\", base: \"klods-sidebar\" });\n\nexport type ContentProps = {\n /** Cap content width to --klods-content-max and centre it. */\n narrow?: boolean;\n};\nexport const content = builder<ContentProps>({\n tag: \"main\",\n base: \"klods-content\",\n modifiers: { narrow: \"klods-content--narrow\" },\n});\n\nexport const footer = builder({ tag: \"footer\", base: \"klods-footer\" });\n\n// ── Layout utilities ─────────────────────────────────────────────────────\ntype GapProp = { gap?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 };\n\nconst gapModifier = (prefix: string) => (v: number | undefined) =>\n v === undefined ? undefined : `${prefix}--gap-${v}`;\n\nexport const stack = builder<GapProp>({\n tag: \"div\",\n base: \"klods-stack\",\n modifiers: { gap: gapModifier(\"klods-stack\") },\n});\n\nexport const cluster = builder<GapProp>({\n tag: \"div\",\n base: \"klods-cluster\",\n modifiers: { gap: gapModifier(\"klods-cluster\") },\n});\n\nexport const row = builder<GapProp>({\n tag: \"div\",\n base: \"klods-row\",\n modifiers: { gap: gapModifier(\"klods-row\") },\n});\n\nexport type GridProps = GapProp & {\n cols?: 1 | 2 | 3 | 4 | 5 | 6;\n /** Auto-fit responsive columns; pair with `--klods-grid-min` if you want a custom minimum. */\n fit?: boolean;\n};\nexport const grid = builder<GridProps>({\n tag: \"div\",\n base: \"klods-grid\",\n modifiers: {\n gap: gapModifier(\"klods-grid\"),\n cols: (v) => (v === undefined ? undefined : `klods-grid--cols-${v}`),\n fit: \"klods-grid--fit\",\n },\n});\n\nexport const center = builder({ tag: \"div\", base: \"klods-center\" });\nexport const spread = builder({ tag: \"div\", base: \"klods-spread\" });\n\n// ── Convenience: empty fragment-ish wrapper for quick text + nodes ──────\nexport function text(value: string | number): KlodsNode {\n // Wrap loose text in a span so it composes anywhere a KlodsNode is expected.\n return new KlodsNode(\"span\", {}, [String(value)]);\n}\n\n// Re-export attribute / child types so consumers can extend a builder neatly.\nexport type { KlodsAttrs, KlodsChild };\n"],"mappings":";AAmBA,IAAM,YAAY,oBAAI,IAAI;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,MAAM,uBAAO,WAAW;AAKvB,SAAS,IAAI,MAAuB;AACzC,SAAO,EAAE,CAAC,GAAG,GAAG,MAAM,KAAK;AAC7B;AAEA,SAAS,MAAM,OAAkC;AAC/C,SAAO,OAAO,UAAU,YAAY,UAAU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AAW,EAAE,KAAK,YAAY,eAAe,EAAE;AACjD,CAAC;AAEM,IAAM,MAAM,QAAiB;AAAA,EAClC,KAAK;AAAA,EACL,MAAM;AAAA,EACN,WAAW,EAAE,KAAK,YAAY,WAAW,EAAE;AAC7C,CAAC;AAOM,IAAM,OAAO,QAAmB;AAAA,EACrC,KAAK;AAAA,EACL,MAAM;AAAA,EACN,WAAW;AAAA,IACT,KAAK,YAAY,YAAY;AAAA,IAC7B,MAAM,CAAC,MAAO,MAAM,SAAY,SAAY,oBAAoB,CAAC;AAAA,IACjE,KAAK;AAAA,EACP;AACF,CAAC;AAEM,IAAM,SAAS,QAAQ,EAAE,KAAK,OAAO,MAAM,eAAe,CAAC;AAC3D,IAAM,SAAS,QAAQ,EAAE,KAAK,OAAO,MAAM,eAAe,CAAC;AAG3D,SAAS,KAAK,OAAmC;AAEtD,SAAO,IAAI,UAAU,QAAQ,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC;AAClD;","names":["stack","el"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var Klods=(()=>{var a=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var B=(t,e,s)=>e in t?a(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var R=(t,e)=>{for(var s in e)a(t,s,{get:e[s],enumerable:!0})},_=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of N(e))!L.call(t,n)&&n!==s&&a(t,n,{get:()=>e[n],enumerable:!(o=j(e,n))||o.enumerable});return t};var E=t=>_(a({},"__esModule",{value:!0}),t);var c=(t,e,s)=>B(t,typeof e!="symbol"?e+"":e,s);var ft={};R(ft,{KlodsNode:()=>i,alert:()=>U,badge:()=>J,builder:()=>r,button:()=>z,card:()=>q,cardBody:()=>I,cardFooter:()=>V,cardTitle:()=>F,center:()=>ct,classNames:()=>u,cluster:()=>dt,content:()=>rt,el:()=>k,footer:()=>nt,grid:()=>at,header:()=>st,lead:()=>tt,mergeClasses:()=>w,muted:()=>Y,nav:()=>M,navLink:()=>W,navList:()=>O,page:()=>et,prose:()=>X,raw:()=>G,row:()=>lt,sidebar:()=>ot,spread:()=>ut,stack:()=>it,text:()=>pt});var T=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),v=Symbol("klods.raw");function G(t){return{[v]:!0,html:t}}function C(t){return typeof t=="object"&&t!==null&&t[v]===!0}function H(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function m(t){return t.replace(/&/g,"&").replace(/"/g,""")}function u(t){return t?typeof t=="string"?t.trim():Array.isArray(t)?t.filter(Boolean).join(" ").trim():Object.entries(t).filter(([,e])=>!!e).map(([e])=>e).join(" ").trim():""}function w(...t){return t.map(e=>u(e)).filter(Boolean).join(" ")}function A(t){return typeof t=="string"?t:Object.entries(t).filter(([,e])=>e!=null&&e!=="").map(([e,s])=>`${e.replace(/[A-Z]/g,o=>`-${o.toLowerCase()}`)}:${String(s)}`).join(";")}function P(t){let e=[],s=Array.isArray(t)?[...t]:[t];for(;s.length;){let o=s.shift();Array.isArray(o)?s.unshift(...o):o!=null&&o!==!1&&o!==!0&&e.push(o)}return e}var i=class t{constructor(e,s={},o=[]){c(this,"tag");c(this,"attrs");c(this,"children");this.tag=e,this.attrs=s,this.children=Array.isArray(o)?o:[o]}render(e){let s=document.createElement(this.tag);for(let[o,n]of Object.entries(this.attrs))if(!(n==null||n===!1)&&o!=="children"){if(o==="class"){let d=u(n);d&&s.setAttribute("class",d);continue}if(o==="style"){s.setAttribute("style",A(n));continue}if(o.startsWith("on")&&typeof n=="function"){s.addEventListener(o.slice(2).toLowerCase(),n);continue}if(n===!0){s.setAttribute(o,"");continue}s.setAttribute(o,String(n))}for(let o of P(this.children))if(o instanceof t)s.appendChild(o.render());else if(typeof o=="object"&&o!==null&&"nodeType"in o)s.appendChild(o);else if(C(o)){let n=document.createElement("template");n.innerHTML=o.html,s.appendChild(n.content)}else s.appendChild(document.createTextNode(String(o)));return e&&e.appendChild(s),s}toString(){let e=[`<${this.tag}`];for(let[s,o]of Object.entries(this.attrs))if(!(o==null||o===!1)&&s!=="children"&&!(s.startsWith("on")&&typeof o=="function")){if(s==="class"){let n=u(o);n&&e.push(` class="${m(n)}"`);continue}if(s==="style"){e.push(` style="${m(A(o))}"`);continue}if(o===!0){e.push(` ${s}`);continue}e.push(` ${s}="${m(String(o))}"`)}if(T.has(this.tag))return e.push(" />"),e.join("");e.push(">");for(let s of P(this.children))s instanceof t?e.push(s.toString()):C(s)?e.push(s.html):typeof s=="object"&&s!==null&&"outerHTML"in s?e.push(s.outerHTML):e.push(H(String(s)));return e.push(`</${this.tag}>`),e.join("")}};function k(t,e={},s=[]){return new i(t,e,s)}function r(t){let{tag:e,base:s,modifiers:o={}}=t,n=o;return(d,y)=>{let f=d??{},g=[],h={};for(let[K,b]of Object.entries(f)){let l=n[K];if(l!==void 0)if(typeof l=="function"){let x=l(b);x&&g.push(x)}else b&&g.push(l);else h[K]=b}let S=w(s,...g,f.class),$=y!==void 0?y:f.children??[];return delete h.children,new i(e,{...h,class:S||void 0},$)}}var M=r({tag:"nav",base:"klods-nav"}),O=r({tag:"ul",base:"klods-nav__list"}),D=r({tag:"a",base:"klods-nav__link",modifiers:{active:"klods-nav__link--active"}});function W(t,e){return k("li",{},[D(t??null,e)])}var q=r({tag:"div",base:"klods-card",modifiers:{elevated:"klods-card--elevated"}}),F=r({tag:"h3",base:"klods-card__title"}),I=r({tag:"div",base:"klods-card__body"}),V=r({tag:"div",base:"klods-card__footer"}),Z=r({tag:"button",base:"klods-button",modifiers:{variant:t=>t&&t!=="default"?`klods-button--${t}`:void 0}});function z(t,e){let s={type:"button",...t??{}};return Z(s,e)}var J=r({tag:"span",base:"klods-badge",modifiers:{variant:t=>t&&t!=="default"?`klods-badge--${t}`:void 0}}),Q=r({tag:"div",base:"klods-alert",modifiers:{variant:t=>t&&t!=="default"?`klods-alert--${t}`:void 0}});function U(t,e){let s={role:"alert",...t??{}};return Q(s,e)}var X=r({tag:"div",base:"klods-prose"}),Y=r({tag:"span",base:"klods-muted"}),tt=r({tag:"p",base:"klods-lead"});var et=r({tag:"div",base:"klods-page",modifiers:{sidebar:"klods-page--with-sidebar",sidebarRight:"klods-page--sidebar-right"}}),st=r({tag:"header",base:"klods-header"}),ot=r({tag:"aside",base:"klods-sidebar"}),rt=r({tag:"main",base:"klods-content",modifiers:{narrow:"klods-content--narrow"}}),nt=r({tag:"footer",base:"klods-footer"}),p=t=>e=>e===void 0?void 0:`${t}--gap-${e}`,it=r({tag:"div",base:"klods-stack",modifiers:{gap:p("klods-stack")}}),dt=r({tag:"div",base:"klods-cluster",modifiers:{gap:p("klods-cluster")}}),lt=r({tag:"div",base:"klods-row",modifiers:{gap:p("klods-row")}}),at=r({tag:"div",base:"klods-grid",modifiers:{gap:p("klods-grid"),cols:t=>t===void 0?void 0:`klods-grid--cols-${t}`,fit:"klods-grid--fit"}}),ct=r({tag:"div",base:"klods-center"}),ut=r({tag:"div",base:"klods-spread"});function pt(t){return new i("span",{},[String(t)])}return E(ft);})();
|
|
2
|
+
//# sourceMappingURL=klods.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/core.ts","../src/components.ts","../src/layout.ts"],"sourcesContent":["// Public API surface for the `klods` package.\n\nexport * from \"./components.js\";\nexport * from \"./core.js\";\nexport * from \"./layout.js\";\n","// Core — a tiny VDOM-ish node with two faces:\n// - .render(target?) → HTMLElement (uses real DOM)\n// - .toString() → HTML string (works in Node / Rails / SSR)\n//\n// Both are produced from the same KlodsNode tree, so the docs site can show the\n// TS source, the rendered HTML and the live preview from one source of truth.\n\nexport type KlodsChild = string | number | bigint | boolean | null | undefined | KlodsNode | Node | KlodsChild[];\n\nexport type KlodsAttrs = {\n class?: string | string[] | Record<string, boolean | undefined> | undefined;\n id?: string | undefined;\n style?: string | Partial<CSSStyleDeclaration> | undefined;\n [key: `data-${string}`]: string | number | boolean | undefined;\n [key: `aria-${string}`]: string | number | boolean | undefined;\n // Allow any other HTML attribute or DOM event handler (onClick, onInput, …).\n [key: string]: unknown;\n};\n\nconst VOID_TAGS = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"link\",\n \"meta\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\nconst RAW = Symbol(\"klods.raw\");\n\ntype RawHtml = { [RAW]: true; html: string };\n\n/** Mark a string as already-escaped HTML; pass it as a child to inject as-is. */\nexport function raw(html: string): RawHtml {\n return { [RAW]: true, html };\n}\n\nfunction isRaw(value: unknown): value is RawHtml {\n return typeof value === \"object\" && value !== null && (value as { [RAW]?: unknown })[RAW] === true;\n}\n\nfunction escapeHtml(str: string): string {\n return str\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n}\n\nfunction escapeAttr(str: string): string {\n return str.replace(/&/g, \"&\").replace(/\"/g, \""\");\n}\n\n/** Normalise a `class` value (string | array | record) into a clean string. */\nexport function classNames(input: KlodsAttrs[\"class\"]): string {\n if (!input) return \"\";\n if (typeof input === \"string\") return input.trim();\n if (Array.isArray(input)) return input.filter(Boolean).join(\" \").trim();\n return Object.entries(input)\n .filter(([, v]) => Boolean(v))\n .map(([k]) => k)\n .join(\" \")\n .trim();\n}\n\n/** Merge two class values (used internally to combine builder defaults + user-supplied). */\nexport function mergeClasses(...inputs: Array<KlodsAttrs[\"class\"]>): string {\n return inputs\n .map((c) => classNames(c))\n .filter(Boolean)\n .join(\" \");\n}\n\nfunction styleToString(style: string | Partial<CSSStyleDeclaration>): string {\n if (typeof style === \"string\") return style;\n return Object.entries(style)\n .filter(([, v]) => v !== undefined && v !== null && v !== \"\")\n .map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}:${String(v)}`)\n .join(\";\");\n}\n\nfunction flattenChildren(children: KlodsChild | KlodsChild[]): Array<Exclude<KlodsChild, KlodsChild[]>> {\n const out: Array<Exclude<KlodsChild, KlodsChild[]>> = [];\n const stack: KlodsChild[] = Array.isArray(children) ? [...children] : [children];\n while (stack.length) {\n const next = stack.shift();\n if (Array.isArray(next)) stack.unshift(...next);\n else if (next !== null && next !== undefined && next !== false && next !== true) out.push(next);\n }\n return out;\n}\n\nexport class KlodsNode {\n readonly tag: string;\n readonly attrs: KlodsAttrs;\n readonly children: KlodsChild[];\n\n constructor(tag: string, attrs: KlodsAttrs = {}, children: KlodsChild | KlodsChild[] = []) {\n this.tag = tag;\n this.attrs = attrs;\n this.children = Array.isArray(children) ? children : [children];\n }\n\n /** Render to a real DOM element. If `target` is given, append to it. */\n render(target?: Element | null): HTMLElement {\n const el = document.createElement(this.tag);\n for (const [name, value] of Object.entries(this.attrs)) {\n if (value === undefined || value === null || value === false) continue;\n if (name === \"children\") continue;\n if (name === \"class\") {\n const cls = classNames(value as KlodsAttrs[\"class\"]);\n if (cls) el.setAttribute(\"class\", cls);\n continue;\n }\n if (name === \"style\") {\n el.setAttribute(\"style\", styleToString(value as string | Partial<CSSStyleDeclaration>));\n continue;\n }\n if (name.startsWith(\"on\") && typeof value === \"function\") {\n el.addEventListener(name.slice(2).toLowerCase(), value as EventListener);\n continue;\n }\n if (value === true) {\n el.setAttribute(name, \"\");\n continue;\n }\n el.setAttribute(name, String(value));\n }\n for (const child of flattenChildren(this.children)) {\n if (child instanceof KlodsNode) el.appendChild(child.render());\n else if (typeof child === \"object\" && child !== null && \"nodeType\" in child) {\n el.appendChild(child as Node);\n } else if (isRaw(child)) {\n const tpl = document.createElement(\"template\");\n tpl.innerHTML = child.html;\n el.appendChild(tpl.content);\n } else {\n el.appendChild(document.createTextNode(String(child)));\n }\n }\n if (target) target.appendChild(el);\n return el;\n }\n\n /** Render to a string of HTML. */\n toString(): string {\n const parts: string[] = [`<${this.tag}`];\n for (const [name, value] of Object.entries(this.attrs)) {\n if (value === undefined || value === null || value === false) continue;\n if (name === \"children\") continue;\n if (name.startsWith(\"on\") && typeof value === \"function\") continue;\n if (name === \"class\") {\n const cls = classNames(value as KlodsAttrs[\"class\"]);\n if (cls) parts.push(` class=\"${escapeAttr(cls)}\"`);\n continue;\n }\n if (name === \"style\") {\n parts.push(` style=\"${escapeAttr(styleToString(value as string | Partial<CSSStyleDeclaration>))}\"`);\n continue;\n }\n if (value === true) {\n parts.push(` ${name}`);\n continue;\n }\n parts.push(` ${name}=\"${escapeAttr(String(value))}\"`);\n }\n if (VOID_TAGS.has(this.tag)) {\n parts.push(\" />\");\n return parts.join(\"\");\n }\n parts.push(\">\");\n for (const child of flattenChildren(this.children)) {\n if (child instanceof KlodsNode) parts.push(child.toString());\n else if (isRaw(child)) parts.push(child.html);\n else if (typeof child === \"object\" && child !== null && \"outerHTML\" in child) {\n parts.push((child as Element).outerHTML);\n } else {\n parts.push(escapeHtml(String(child)));\n }\n }\n parts.push(`</${this.tag}>`);\n return parts.join(\"\");\n }\n}\n\n/**\n * Generic element builder. Most consumers use the named builders (page, header, …)\n * rather than calling `el` directly, but it's exported as an escape hatch.\n */\nexport function el(tag: string, attrs: KlodsAttrs = {}, children: KlodsChild | KlodsChild[] = []): KlodsNode {\n return new KlodsNode(tag, attrs, children);\n}\n\n/**\n * Factory that produces a typed builder for a tag with a base class. Modifier\n * props are converted into `--modifier` BEM classes and stripped from the output\n * attributes; everything else passes through untouched, so consumers can attach\n * arbitrary `id`, `data-*`, `aria-*`, event handlers, `style`, etc.\n */\nexport function builder<P extends Record<string, unknown> = Record<string, never>>(options: {\n tag: string;\n base: string;\n /** Map of prop name → class (or function returning a class) when the prop is truthy. */\n modifiers?: { [K in keyof P]?: string | ((value: P[K]) => string | undefined) };\n}): (props?: (P & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]) => KlodsNode {\n const { tag, base, modifiers = {} } = options;\n const modifierMap = modifiers as Record<string, string | ((value: unknown) => string | undefined) | undefined>;\n return (props, children) => {\n const userProps = (props ?? {}) as P & KlodsAttrs;\n const modClasses: string[] = [];\n const passthrough: KlodsAttrs = {};\n for (const [key, value] of Object.entries(userProps)) {\n const m = modifierMap[key];\n if (m !== undefined) {\n if (typeof m === \"function\") {\n const c = m(value);\n if (c) modClasses.push(c);\n } else if (value) {\n modClasses.push(m);\n }\n } else {\n passthrough[key] = value;\n }\n }\n const finalClass = mergeClasses(base, ...modClasses, userProps.class);\n const resolvedChildren =\n children !== undefined ? children : ((userProps.children as KlodsChild | KlodsChild[] | undefined) ?? []);\n delete passthrough.children;\n return new KlodsNode(tag, { ...passthrough, class: finalClass || undefined }, resolvedChildren);\n };\n}\n","// First wave of components: nav, card, button, badge, alert, prose helpers.\n// All match the BEM classes shipped by klods-css.\n\nimport type { KlodsAttrs, KlodsChild } from \"./core.js\";\nimport { builder, el, KlodsNode } from \"./core.js\";\n\n// ── Nav ──────────────────────────────────────────────────────────────────\nexport const nav = builder({ tag: \"nav\", base: \"klods-nav\" });\nexport const navList = builder({ tag: \"ul\", base: \"klods-nav__list\" });\n\nexport type NavLinkProps = {\n href?: string;\n active?: boolean;\n};\nconst navLinkBuilder = builder<NavLinkProps>({\n tag: \"a\",\n base: \"klods-nav__link\",\n modifiers: { active: \"klods-nav__link--active\" },\n});\nexport function navLink(props?: (NavLinkProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode {\n // Wrap each link in <li> so it's idiomatic inside <ul class=\"klods-nav__list\">.\n return el(\"li\", {}, [navLinkBuilder(props ?? null, children)]);\n}\n\n// ── Card ─────────────────────────────────────────────────────────────────\nexport type CardProps = {\n elevated?: boolean;\n};\nexport const card = builder<CardProps>({\n tag: \"div\",\n base: \"klods-card\",\n modifiers: { elevated: \"klods-card--elevated\" },\n});\nexport const cardTitle = builder({ tag: \"h3\", base: \"klods-card__title\" });\nexport const cardBody = builder({ tag: \"div\", base: \"klods-card__body\" });\nexport const cardFooter = builder({ tag: \"div\", base: \"klods-card__footer\" });\n\n// ── Button ───────────────────────────────────────────────────────────────\nexport type ButtonProps = {\n variant?: \"default\" | \"primary\" | \"danger\" | \"ghost\";\n type?: \"button\" | \"submit\" | \"reset\";\n};\nconst buttonBase = builder<ButtonProps>({\n tag: \"button\",\n base: \"klods-button\",\n modifiers: {\n variant: (v) => (v && v !== \"default\" ? `klods-button--${v}` : undefined),\n },\n});\nexport function button(props?: (ButtonProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode {\n // Default `type=\"button\"` so it never accidentally submits a form.\n const merged = { type: \"button\", ...(props ?? {}) } as ButtonProps & KlodsAttrs;\n return buttonBase(merged, children);\n}\n\n// ── Badge ────────────────────────────────────────────────────────────────\nexport type BadgeProps = {\n variant?: \"default\" | \"accent\" | \"success\" | \"danger\";\n};\nexport const badge = builder<BadgeProps>({\n tag: \"span\",\n base: \"klods-badge\",\n modifiers: {\n variant: (v) => (v && v !== \"default\" ? `klods-badge--${v}` : undefined),\n },\n});\n\n// ── Alert ────────────────────────────────────────────────────────────────\nexport type AlertProps = {\n variant?: \"default\" | \"info\" | \"success\" | \"warning\" | \"danger\";\n};\nconst alertBase = builder<AlertProps>({\n tag: \"div\",\n base: \"klods-alert\",\n modifiers: {\n variant: (v) => (v && v !== \"default\" ? `klods-alert--${v}` : undefined),\n },\n});\nexport function alert(props?: (AlertProps & KlodsAttrs) | null, children?: KlodsChild | KlodsChild[]): KlodsNode {\n // role=alert by default for assistive tech, overridable.\n const merged = { role: \"alert\", ...(props ?? {}) } as AlertProps & KlodsAttrs;\n return alertBase(merged, children);\n}\n\n// ── Prose helpers ────────────────────────────────────────────────────────\nexport const prose = builder({ tag: \"div\", base: \"klods-prose\" });\nexport const muted = builder({ tag: \"span\", base: \"klods-muted\" });\nexport const lead = builder({ tag: \"p\", base: \"klods-lead\" });\n","// Layout builders — the four corners and the \"I-always-forget\" utilities.\n// Each builder is a thin wrapper around `builder()` from core.ts.\n\nimport type { KlodsAttrs, KlodsChild } from \"./core.js\";\nimport { builder, KlodsNode } from \"./core.js\";\n\n// ── Page ─────────────────────────────────────────────────────────────────\nexport type PageProps = {\n /** Render with a sidebar column. */\n sidebar?: boolean;\n /** Place the sidebar on the right (only meaningful with `sidebar: true`). */\n sidebarRight?: boolean;\n};\n\nexport const page = builder<PageProps>({\n tag: \"div\",\n base: \"klods-page\",\n modifiers: {\n sidebar: \"klods-page--with-sidebar\",\n sidebarRight: \"klods-page--sidebar-right\",\n },\n});\n\n// ── Page slots ───────────────────────────────────────────────────────────\nexport const header = builder({ tag: \"header\", base: \"klods-header\" });\nexport const sidebar = builder({ tag: \"aside\", base: \"klods-sidebar\" });\n\nexport type ContentProps = {\n /** Cap content width to --klods-content-max and centre it. */\n narrow?: boolean;\n};\nexport const content = builder<ContentProps>({\n tag: \"main\",\n base: \"klods-content\",\n modifiers: { narrow: \"klods-content--narrow\" },\n});\n\nexport const footer = builder({ tag: \"footer\", base: \"klods-footer\" });\n\n// ── Layout utilities ─────────────────────────────────────────────────────\ntype GapProp = { gap?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 };\n\nconst gapModifier = (prefix: string) => (v: number | undefined) =>\n v === undefined ? undefined : `${prefix}--gap-${v}`;\n\nexport const stack = builder<GapProp>({\n tag: \"div\",\n base: \"klods-stack\",\n modifiers: { gap: gapModifier(\"klods-stack\") },\n});\n\nexport const cluster = builder<GapProp>({\n tag: \"div\",\n base: \"klods-cluster\",\n modifiers: { gap: gapModifier(\"klods-cluster\") },\n});\n\nexport const row = builder<GapProp>({\n tag: \"div\",\n base: \"klods-row\",\n modifiers: { gap: gapModifier(\"klods-row\") },\n});\n\nexport type GridProps = GapProp & {\n cols?: 1 | 2 | 3 | 4 | 5 | 6;\n /** Auto-fit responsive columns; pair with `--klods-grid-min` if you want a custom minimum. */\n fit?: boolean;\n};\nexport const grid = builder<GridProps>({\n tag: \"div\",\n base: \"klods-grid\",\n modifiers: {\n gap: gapModifier(\"klods-grid\"),\n cols: (v) => (v === undefined ? undefined : `klods-grid--cols-${v}`),\n fit: \"klods-grid--fit\",\n },\n});\n\nexport const center = builder({ tag: \"div\", base: \"klods-center\" });\nexport const spread = builder({ tag: \"div\", base: \"klods-spread\" });\n\n// ── Convenience: empty fragment-ish wrapper for quick text + nodes ──────\nexport function text(value: string | number): KlodsNode {\n // Wrap loose text in a span so it composes anywhere a KlodsNode is expected.\n return new KlodsNode(\"span\", {}, [String(value)]);\n}\n\n// Re-export attribute / child types so consumers can extend a builder neatly.\nexport type { KlodsAttrs, KlodsChild };\n"],"mappings":"ikBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,eAAAE,EAAA,UAAAC,EAAA,UAAAC,EAAA,YAAAC,EAAA,WAAAC,EAAA,SAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,cAAAC,EAAA,WAAAC,GAAA,eAAAC,EAAA,YAAAC,GAAA,YAAAC,GAAA,OAAAC,EAAA,WAAAC,GAAA,SAAAC,GAAA,WAAAC,GAAA,SAAAC,GAAA,iBAAAC,EAAA,UAAAC,EAAA,QAAAC,EAAA,YAAAC,EAAA,YAAAC,EAAA,SAAAC,GAAA,UAAAC,EAAA,QAAAC,EAAA,QAAAC,GAAA,YAAAC,GAAA,WAAAC,GAAA,UAAAC,GAAA,SAAAC,KCmBA,IAAMC,EAAY,IAAI,IAAI,CACxB,OACA,OACA,KACA,MACA,QACA,KACA,MACA,QACA,OACA,OACA,SACA,QACA,KACF,CAAC,EAEKC,EAAM,OAAO,WAAW,EAKvB,SAASC,EAAIC,EAAuB,CACzC,MAAO,CAAE,CAACF,CAAG,EAAG,GAAM,KAAAE,CAAK,CAC7B,CAEA,SAASC,EAAMC,EAAkC,CAC/C,OAAO,OAAOA,GAAU,UAAYA,IAAU,MAASA,EAA8BJ,CAAG,IAAM,EAChG,CAEA,SAASK,EAAWC,EAAqB,CACvC,OAAOA,EACJ,QAAQ,KAAM,OAAO,EACrB,QAAQ,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AAK,MACL,KAAM,aACN,UAAW,CACT,QAAS,2BACT,aAAc,2BAChB,CACF,CAAC,EAGYC,GAASD,EAAQ,CAAE,IAAK,SAAU,KAAM,cAAe,CAAC,EACxDE,GAAUF,EAAQ,CAAE,IAAK,QAAS,KAAM,eAAgB,CAAC,EAMzDG,GAAUH,EAAsB,CAC3C,IAAK,OACL,KAAM,gBACN,UAAW,CAAE,OAAQ,uBAAwB,CAC/C,CAAC,EAEYI,GAASJ,EAAQ,CAAE,IAAK,SAAU,KAAM,cAAe,CAAC,EAK/DK,EAAeC,GAAoBC,GACvCA,IAAM,OAAY,OAAY,GAAGD,CAAM,SAASC,CAAC,GAEtCC,GAAQR,EAAiB,CACpC,IAAK,MACL,KAAM,cACN,UAAW,CAAE,IAAKK,EAAY,aAAa,CAAE,CAC/C,CAAC,EAEYI,GAAUT,EAAiB,CACtC,IAAK,MACL,KAAM,gBACN,UAAW,CAAE,IAAKK,EAAY,eAAe,CAAE,CACjD,CAAC,EAEYK,GAAMV,EAAiB,CAClC,IAAK,MACL,KAAM,YACN,UAAW,CAAE,IAAKK,EAAY,WAAW,CAAE,CAC7C,CAAC,EAOYM,GAAOX,EAAmB,CACrC,IAAK,MACL,KAAM,aACN,UAAW,CACT,IAAKK,EAAY,YAAY,EAC7B,KAAOE,GAAOA,IAAM,OAAY,OAAY,oBAAoBA,CAAC,GACjE,IAAK,iBACP,CACF,CAAC,EAEYK,GAASZ,EAAQ,CAAE,IAAK,MAAO,KAAM,cAAe,CAAC,EACrDa,GAASb,EAAQ,CAAE,IAAK,MAAO,KAAM,cAAe,CAAC,EAG3D,SAASc,GAAKC,EAAmC,CAEtD,OAAO,IAAIC,EAAU,OAAQ,CAAC,EAAG,CAAC,OAAOD,CAAK,CAAC,CAAC,CAClD","names":["src_exports","__export","KlodsNode","alert","badge","builder","button","card","cardBody","cardFooter","cardTitle","center","classNames","cluster","content","el","footer","grid","header","lead","mergeClasses","muted","nav","navLink","navList","page","prose","raw","row","sidebar","spread","stack","text","VOID_TAGS","RAW","raw","html","isRaw","value","escapeHtml","str","escapeAttr","classNames","input","v","k","mergeClasses","inputs","c","styleToString","style","m","flattenChildren","children","out","stack","next","KlodsNode","_KlodsNode","tag","attrs","__publicField","target","el","name","cls","child","tpl","parts","builder","options","base","modifiers","modifierMap","props","userProps","modClasses","passthrough","key","finalClass","resolvedChildren","nav","builder","navList","navLinkBuilder","navLink","props","children","el","card","cardTitle","cardBody","cardFooter","buttonBase","v","button","merged","badge","alertBase","alert","prose","muted","lead","page","builder","header","sidebar","content","footer","gapModifier","prefix","v","stack","cluster","row","grid","center","spread","text","value","KlodsNode"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "klods-js",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Tiny, typed, lego-like builder API for klods components.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Drue Wilding",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/druewilding/klods",
|
|
10
|
+
"directory": "packages/klods-js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"klods",
|
|
14
|
+
"klods-js",
|
|
15
|
+
"component",
|
|
16
|
+
"builder"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "./dist/index.cjs",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"source": "./src/index.ts",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"require": "./dist/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"dev": "tsup --watch",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:watch": "vitest"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^22.9.0",
|
|
42
|
+
"happy-dom": "^20.9.0",
|
|
43
|
+
"tsup": "^8.3.5",
|
|
44
|
+
"typescript": "^5.6.3",
|
|
45
|
+
"vitest": "^4.1.7"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"vite": "8.0.14"
|
|
49
|
+
}
|
|
50
|
+
}
|