@zvndev/darkmown 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/AGENTS.md +8 -6
  2. package/CHANGELOG.md +23 -0
  3. package/README.md +37 -3
  4. package/SECURITY.md +1 -0
  5. package/docs/cli.md +20 -1
  6. package/docs/errors.md +255 -0
  7. package/docs/spec-alignment.md +14 -1
  8. package/package.json +3 -2
  9. package/site/pages/benchmarks/index.wd +1 -1
  10. package/site/pages/docs/index.wd +6 -1
  11. package/site/pages/index.wd +1 -0
  12. package/site/pages/playground/index.js +59 -54
  13. package/src/api-runner.js +80 -8
  14. package/src/builder.js +122 -13
  15. package/src/catalog.js +6 -0
  16. package/src/cli.js +48 -5
  17. package/src/compiler/page.js +16 -4
  18. package/src/compiler/state.js +75 -0
  19. package/src/compiler.js +1 -1
  20. package/src/errors.js +50 -3
  21. package/src/font-subset.js +25 -7
  22. package/src/image-variant-resize.js +4 -1
  23. package/src/image-variants.js +9 -4
  24. package/src/mcp-tools.js +354 -0
  25. package/src/mcp.js +287 -0
  26. package/src/router.js +16 -0
  27. package/src/skin.js +111 -45
  28. package/src/statics.js +1 -0
  29. package/src/templates/dashboard/README.md +3 -1
  30. package/src/templates/landing/site/pages/index.skin +7 -0
  31. package/src/templates/landing/site/pages/index.wd +10 -3
  32. package/src/templates/store/README.md +5 -2
  33. package/src/templates/store/site/_/card.wd +19 -0
  34. package/src/templates/store/site/_/products.json +6 -6
  35. package/src/templates/store/site/pages/index.skin +17 -2
  36. package/src/templates/store/site/pages/index.wd +3 -12
  37. package/types/api-runner.d.ts +20 -4
  38. package/types/builder.d.ts +5 -0
  39. package/types/compiler/page.d.ts +12 -3
  40. package/types/compiler.d.ts +4 -1
  41. package/types/errors.d.ts +6 -4
  42. package/types/font-subset.d.ts +7 -3
  43. package/types/image-variants.d.ts +7 -3
  44. package/types/router.d.ts +5 -0
  45. package/types/skin.d.ts +9 -4
package/src/mcp.js ADDED
@@ -0,0 +1,287 @@
1
+ // ---------------------------------------------------------------------------
2
+ // MCP (Model Context Protocol) server, stdio transport, hand-rolled.
3
+ //
4
+ // MCP over stdio is newline-delimited JSON-RPC 2.0: the client (Claude Code,
5
+ // Codex, Cursor, …) writes one JSON message per line on the server's stdin and
6
+ // reads one JSON response per line from its stdout. Everything else a server
7
+ // wants to say (startup banners, logs) goes to stderr — a single stray byte on
8
+ // stdout corrupts the frame stream, so `serveMcp` only ever writes responses
9
+ // there.
10
+ //
11
+ // This is a focused implementation of the subset a doc/validation server
12
+ // needs, protocol revision 2024-11-05:
13
+ //
14
+ // initialize handshake: protocolVersion, capabilities, serverInfo
15
+ // notifications/initialized client ack — no response (as for every notification)
16
+ // ping liveness — answers {}
17
+ // tools/list the five Darkmown tools, with inputSchema
18
+ // tools/call run one tool, answer MCP text content
19
+ // resources/list the darkmown://docs/* resources
20
+ // resources/read one resource's markdown text
21
+ //
22
+ // Deliberately NOT implemented (noted in the handshake's capabilities by their
23
+ // absence): prompts, logging, completion, sampling, subscriptions, and
24
+ // BATCHED requests — a JSON array on one line is answered with a single
25
+ // -32600 Invalid Request, which the spec permits a server to do. Tool/resource
26
+ // definitions are static for the life of the process, so the optional
27
+ // list-change notifications never fire.
28
+ //
29
+ // The module is dependency-free (Node built-ins only) and side-effect-free on
30
+ // import: `serveMcp` is called explicitly by the CLI's `mcp` command, and the
31
+ // dispatcher is a pure function tests drive in-process.
32
+ // ---------------------------------------------------------------------------
33
+
34
+ /** The one MCP protocol revision this server speaks. */
35
+ export const PROTOCOL_VERSION = "2024-11-05";
36
+
37
+ // Standard JSON-RPC 2.0 error codes.
38
+ const PARSE_ERROR = -32700;
39
+ const INVALID_REQUEST = -32600;
40
+ const METHOD_NOT_FOUND = -32601;
41
+ const INVALID_PARAMS = -32602;
42
+
43
+ /**
44
+ * One tool the server exposes over `tools/list` / `tools/call`.
45
+ * @typedef {object} McpTool
46
+ * @property {string} name
47
+ * @property {string} description
48
+ * @property {object} inputSchema A JSON Schema object describing the arguments.
49
+ * @property {(args: Record<string, unknown>) => McpToolOutcome} run
50
+ */
51
+
52
+ /**
53
+ * What a tool run returns. `text` becomes the first MCP text content item; a
54
+ * defined `data` is appended as a second text item carrying pretty-printed
55
+ * JSON, so an agent gets both the human-readable answer and the structured
56
+ * one. `isError` marks the result as a tool-level failure (a bad argument),
57
+ * never a protocol error — those are JSON-RPC errors on the envelope.
58
+ * @typedef {object} McpToolOutcome
59
+ * @property {string} text
60
+ * @property {object} [data]
61
+ * @property {boolean} [isError]
62
+ */
63
+
64
+ /**
65
+ * One resource the server exposes over `resources/list` / `resources/read`.
66
+ * @typedef {object} McpResource
67
+ * @property {string} uri
68
+ * @property {string} name
69
+ * @property {string} description
70
+ * @property {string} mimeType
71
+ * @property {() => string} read
72
+ */
73
+
74
+ /**
75
+ * Everything the dispatcher needs to answer. Constructed by
76
+ * `mcpConfig()` in src/mcp-tools.js; injected here so this module stays a
77
+ * transport + envelope layer with no knowledge of Darkmown's docs.
78
+ * @typedef {object} McpConfig
79
+ * @property {{ name: string, version: string }} serverInfo
80
+ * @property {McpTool[]} tools
81
+ * @property {McpResource[]} resources
82
+ */
83
+
84
+ /**
85
+ * A JSON-RPC 2.0 message as it arrives on the wire. The server is liberal in
86
+ * what it accepts: `id` may be a string, a number, or absent (a notification).
87
+ * @typedef {{ jsonrpc?: string, id?: string | number | null, method?: unknown, params?: unknown }} McpMessage
88
+ */
89
+
90
+ /**
91
+ * Create the request dispatcher: one JSON-RPC message in, one response (or
92
+ * `null` for a notification, which must never be answered) out.
93
+ *
94
+ * @param {McpConfig} config
95
+ * @returns {(message: unknown) => object | null}
96
+ */
97
+ export function createDispatcher({ serverInfo, tools, resources }) {
98
+ const toolsByName = new Map(tools.map((tool) => [tool.name, tool]));
99
+ const resourcesByUri = new Map(resources.map((resource) => [resource.uri, resource]));
100
+
101
+ /**
102
+ * @param {string | number | null} id
103
+ * @param {unknown} value
104
+ */
105
+ const ok = (id, value) => ({ jsonrpc: "2.0", id, result: value });
106
+ /**
107
+ * @param {string | number | null} id
108
+ * @param {number} code
109
+ * @param {string} message
110
+ */
111
+ const fail = (id, code, message) => ({ jsonrpc: "2.0", id, error: { code, message } });
112
+
113
+ /**
114
+ * `tools/call`: find the tool, run it, shape the MCP result. A tool that
115
+ * throws is a tool-level error result (the spec's `isError` channel), not a
116
+ * protocol error — the client asked a fair question and the tool failed.
117
+ * @param {string | number | null} id
118
+ * @param {unknown} params
119
+ */
120
+ function callTool(id, params) {
121
+ const args = /** @type {{ name?: unknown, arguments?: unknown }} */ (
122
+ params && typeof params === "object" ? params : {}
123
+ );
124
+ const tool = typeof args.name === "string" ? toolsByName.get(args.name) : undefined;
125
+ if (!tool) {
126
+ const known = tools.map((t) => t.name).join(", ");
127
+ return fail(id, INVALID_PARAMS, `Unknown tool: ${String(args.name)}. Available: ${known}`);
128
+ }
129
+ /** @type {McpToolOutcome} */
130
+ let outcome;
131
+ try {
132
+ outcome = tool.run(
133
+ /** @type {Record<string, unknown>} */ (
134
+ args.arguments && typeof args.arguments === "object" ? args.arguments : {}
135
+ )
136
+ );
137
+ } catch (err) {
138
+ const message = err instanceof Error ? err.message : String(err);
139
+ return ok(id, {
140
+ content: [{ type: "text", text: `Tool "${tool.name}" failed: ${message}` }],
141
+ isError: true
142
+ });
143
+ }
144
+ const content = [{ type: "text", text: outcome.text }];
145
+ if (outcome.data !== undefined) {
146
+ content.push({ type: "text", text: JSON.stringify(outcome.data, null, 2) });
147
+ }
148
+ return ok(id, { content, ...(outcome.isError ? { isError: true } : {}) });
149
+ }
150
+
151
+ /**
152
+ * `resources/read`: one resource's full text. An unknown URI is an invalid
153
+ * params error naming what the server actually has.
154
+ * @param {string | number | null} id
155
+ * @param {unknown} params
156
+ */
157
+ function readResource(id, params) {
158
+ const args = /** @type {{ uri?: unknown }} */ (
159
+ params && typeof params === "object" ? params : {}
160
+ );
161
+ const resource = typeof args.uri === "string" ? resourcesByUri.get(args.uri) : undefined;
162
+ if (!resource) {
163
+ const known = resources.map((r) => r.uri).join(", ");
164
+ return fail(id, INVALID_PARAMS, `Unknown resource: ${String(args.uri)}. Available: ${known}`);
165
+ }
166
+ return ok(id, {
167
+ contents: [{ uri: resource.uri, mimeType: resource.mimeType, text: resource.read() }]
168
+ });
169
+ }
170
+
171
+ /**
172
+ * Dispatch one decoded message. Returns the response to write back, or
173
+ * `null` when the message is a notification (answered with silence, per
174
+ * JSON-RPC) or otherwise needs no reply.
175
+ * @param {unknown} message
176
+ * @returns {object | null}
177
+ */
178
+ function handle(message) {
179
+ if (!message || typeof message !== "object") {
180
+ // A bare scalar, or a JSON array (a batch — not supported): one error.
181
+ return fail(null, INVALID_REQUEST, "Invalid Request: expected a JSON-RPC object");
182
+ }
183
+ const { id, method, params } = /** @type {McpMessage} */ (message);
184
+ if (typeof method !== "string") {
185
+ return fail(id ?? null, INVALID_REQUEST, "Invalid Request: missing method");
186
+ }
187
+ // No id means notification: `notifications/initialized` and anything else
188
+ // the client fires one-way. Notifications are never answered, even when
189
+ // the method is unknown.
190
+ if (id === undefined || id === null) return null;
191
+
192
+ switch (method) {
193
+ case "initialize":
194
+ return ok(id, {
195
+ protocolVersion: PROTOCOL_VERSION,
196
+ capabilities: {
197
+ tools: { listChanged: false },
198
+ resources: { listChanged: false }
199
+ },
200
+ serverInfo
201
+ });
202
+ case "ping":
203
+ return ok(id, {});
204
+ case "tools/list":
205
+ return ok(id, {
206
+ tools: tools.map(({ name, description, inputSchema }) => ({
207
+ name,
208
+ description,
209
+ inputSchema
210
+ }))
211
+ });
212
+ case "tools/call":
213
+ return callTool(id, params);
214
+ case "resources/list":
215
+ return ok(id, {
216
+ resources: resources.map(({ uri, name, description, mimeType }) => ({
217
+ uri,
218
+ name,
219
+ description,
220
+ mimeType
221
+ }))
222
+ });
223
+ case "resources/read":
224
+ return readResource(id, params);
225
+ default:
226
+ return fail(id, METHOD_NOT_FOUND, `Method not found: ${method}`);
227
+ }
228
+ }
229
+
230
+ return handle;
231
+ }
232
+
233
+ /**
234
+ * Run the stdio loop: read newline-delimited JSON-RPC from `input`, write one
235
+ * JSON response per line to `output`. Resolves when `input` ends, which is
236
+ * how an MCP host stops a stdio server.
237
+ *
238
+ * A line that is not valid JSON answers with a -32700 Parse error and the loop
239
+ * carries on — one garbage line from a misbehaving client must not kill the
240
+ * server. A trailing partial line at end-of-input is answered too: MCP clients
241
+ * always terminate frames, but a hand-rolled `echo '{…}' | darkmown mcp` smoke
242
+ * test may not.
243
+ *
244
+ * @param {{ input: NodeJS.ReadableStream, output: NodeJS.WritableStream,
245
+ * dispatcher: (message: unknown) => object | null }} io
246
+ * @returns {Promise<{ command: "mcp" }>}
247
+ */
248
+ export function serveMcp({ input, output, dispatcher }) {
249
+ const send = (/** @type {object} */ message) => {
250
+ output.write(`${JSON.stringify(message)}\n`);
251
+ };
252
+ const answer = (/** @type {string} */ line) => {
253
+ const trimmed = line.trim();
254
+ if (!trimmed) return;
255
+ /** @type {unknown} */
256
+ let message;
257
+ try {
258
+ message = JSON.parse(trimmed);
259
+ } catch {
260
+ send({
261
+ jsonrpc: "2.0",
262
+ id: null,
263
+ error: { code: PARSE_ERROR, message: "Parse error: line is not valid JSON" }
264
+ });
265
+ return;
266
+ }
267
+ const response = dispatcher(message);
268
+ if (response) send(response);
269
+ };
270
+
271
+ let buffer = "";
272
+ return new Promise((resolve) => {
273
+ input.on("data", (chunk) => {
274
+ buffer += chunk;
275
+ let index = buffer.indexOf("\n");
276
+ while (index !== -1) {
277
+ answer(buffer.slice(0, index));
278
+ buffer = buffer.slice(index + 1);
279
+ index = buffer.indexOf("\n");
280
+ }
281
+ });
282
+ input.on("end", () => {
283
+ if (buffer) answer(buffer);
284
+ resolve({ command: "mcp" });
285
+ });
286
+ });
287
+ }
package/src/router.js CHANGED
@@ -88,6 +88,11 @@ export function isDraft(meta) {
88
88
 
89
89
  /**
90
90
  * Derive a public route path from a source file path.
91
+ *
92
+ * Fail-closed on control/whitespace characters: the route string flows RAW
93
+ * into generated config (`dist/_headers` blocks, llms.txt lines), where a
94
+ * newline in a filename would inject whole config lines. Rejecting here, at
95
+ * the one route-derivation chokepoint, protects every downstream sink at once.
91
96
  * @param {string} routesRoot Absolute path to `site/pages`.
92
97
  * @param {string} file Absolute path to the source file.
93
98
  * @returns {string}
@@ -98,9 +103,20 @@ export function routeFromFile(routesRoot, file) {
98
103
  const parts = rel.split(path.sep);
99
104
  if (parts.at(-1) === "index") parts.pop();
100
105
  const route = `/${parts.join("/")}`;
106
+ if (ROUTE_UNSAFE_CHARS.test(route)) {
107
+ throw wdError(
108
+ `Refusing to route ${file} — a page filename must not contain whitespace or ` +
109
+ "control characters: the route is written verbatim into generated config " +
110
+ "(dist/_headers, llms.txt), where such a character would corrupt the file.",
111
+ { code: "WD908", file }
112
+ );
113
+ }
101
114
  return route === "/" ? "/" : `${route}/`;
102
115
  }
103
116
 
117
+ /** Whitespace (`\s`) and control characters (`\p{Cc}`: C0, DEL, C1) a route string must never carry. */
118
+ const ROUTE_UNSAFE_CHARS = /[\s\p{Cc}]/u;
119
+
104
120
  /**
105
121
  * Map a public route to the `index.html` output path under `distRoot`.
106
122
  *
package/src/skin.js CHANGED
@@ -1,6 +1,12 @@
1
1
  import crypto from "node:crypto";
2
2
  import { wdError } from "./compiler/context.js";
3
3
 
4
+ // Concrete, compilable skins for the at-rule error hints + the error registry
5
+ // (src/errors.js). Multi-line because both at-rules are block constructs; a
6
+ // test in tests/skin-atrules.test.js compiles each verbatim.
7
+ export const FONT_FACE_EXAMPLE = '@font-face\n font-family "Newsreader"';
8
+ export const KEYFRAMES_EXAMPLE = "@keyframes fade-in\n to\n opacity 1";
9
+
4
10
  const aliases = new Map([
5
11
  ["radius", "border-radius"],
6
12
  ["shadow", "box-shadow"],
@@ -70,28 +76,37 @@ const PAGE_LEVEL_SELECTORS = new Set(["page", "*", "html", "body", "::selection"
70
76
  * selectors), they are ALWAYS global (never scope-stamped, same contract as
71
77
  * `tokens`), and their declaration values use the same alias/`$token` pipeline.
72
78
  * @param {string} source
73
- * @param {{ scope?: string, subjects?: Set<string> }} [opts] `scope`: the scope
74
- * id enabling scoped mode. `subjects`: an optional set the compiler fills with
75
- * every scoped subject token (`.card`, `h2`, `#id`) for the unused-selector
76
- * warning, so the caller need not re-parse the source.
79
+ * @param {{ scope?: string, subjects?: Set<string>, file?: string }} [opts]
80
+ * `scope`: the scope id enabling scoped mode. `subjects`: an optional set the
81
+ * compiler fills with every scoped subject token (`.card`, `h2`, `#id`) for
82
+ * the unused-selector warning, so the caller need not re-parse the source.
83
+ * `file`: the skin's path, threaded into author-facing errors so they report
84
+ * `file:line` (the builder always passes it; a bare call reports `on line N`).
77
85
  * @returns {string}
78
86
  */
79
87
  export function compileSkin(source, opts = {}) {
80
88
  const scope = opts.scope;
81
89
  const subjects = opts.subjects;
90
+ const file = opts.file;
82
91
  const lines = source
83
92
  .replace(/\r\n?/g, "\n")
84
- .replace(/\/\*[\s\S]*?\*\//g, "") // strip /* … */ block comments (any span)
93
+ // Strip /* … */ block comments (any span), KEEPING their newlines so the
94
+ // `line` recorded below stays the true file line even past a multi-line
95
+ // comment.
96
+ .replace(/\/\*[\s\S]*?\*\//g, (comment) => comment.replace(/[^\n]/g, ""))
85
97
  .split("\n")
86
- .filter((raw) => {
87
- const t = raw.trim();
88
- if (!t || t.startsWith("//")) return false;
98
+ .map((raw, index) => ({
99
+ indent: (raw.match(/^\s*/)?.[0] ?? "").length,
100
+ text: raw.trim(),
101
+ line: index + 1
102
+ }))
103
+ .filter(({ text }) => {
104
+ if (!text || text.startsWith("//")) return false;
89
105
  // Decorative divider lines (----, ====, * * *, ~~~) carry no rule and would
90
106
  // otherwise parse as a bogus selector/declaration. Anything with a letter or
91
107
  // digit is real content; punctuation-only lines are skipped.
92
- return /[A-Za-z0-9]/.test(t);
93
- })
94
- .map((raw) => ({ indent: (raw.match(/^\s*/)?.[0] ?? "").length, text: raw.trim() }));
108
+ return /[A-Za-z0-9]/.test(text);
109
+ });
95
110
 
96
111
  // The opt-in marker: `scoped` must be the FIRST meaningful line (the filter
97
112
  // above has already dropped comments, blanks, and dividers). Anywhere else it
@@ -181,7 +196,7 @@ export function compileSkin(source, opts = {}) {
181
196
  const atRule = /^@(font-face|keyframes)(?:\s+(.+))?$/.exec(text);
182
197
  if (atRule) {
183
198
  const media = stack.find((frame) => frame.media)?.media;
184
- const block = collectAtRule(atRule[1], atRule[2], lines, i);
199
+ const block = collectAtRule(atRule[1], atRule[2], lines, i, file);
185
200
  css.push(media ? `${media} {\n${block.css}\n}` : block.css);
186
201
  i = block.end;
187
202
  continue;
@@ -367,17 +382,19 @@ function normalizeSelector(text, parent) {
367
382
  const KEYFRAME_SELECTOR = /^(?:from|to|\d+(?:\.\d+)?%)(?:\s*,\s*(?:from|to|\d+(?:\.\d+)?%))*$/;
368
383
 
369
384
  /**
370
- * A plain Error, no WD code: the code registry (`src/errors.js`) and its drift
371
- * guard (`tests/error-codes.test.js`) are owned by a parallel change, so a
372
- * `code: "WD8xx"` here would fail the "every code thrown is registered" gate
373
- * and an inline throw would fail the "no author-facing throw bypasses wdError"
374
- * scan. Messages still lead with the construct and end with a corrective
375
- * example, registry-style.
376
- * @param {string} message
377
- * @returns {Error}
385
+ * An author-facing at-rule error, routed through `wdError` like every other
386
+ * compile error: it carries a registered WD8xx code (src/errors.js), the true
387
+ * source line, and a corrective `Use:` hint. The file is named when the caller
388
+ * threaded one (the builder always does); a bare `compileSkin` call has no
389
+ * path, so the location falls back to `on line N`.
390
+ * @param {string} summary What is wrong, naming the offending text.
391
+ * @param {import("./compiler/context.js").WdErrorInfo} wd The structured mirror;
392
+ * `code` is required (every at-rule error is registered in src/errors.js).
393
+ * @returns {Error & { wd: import("./compiler/context.js").WdErrorInfo }}
378
394
  */
379
- function skinError(message) {
380
- return new Error(message);
395
+ function skinError(summary, wd) {
396
+ const where = wd.file ? ` in ${wd.file}:${wd.line}` : ` on line ${wd.line}`;
397
+ return wdError(`${summary}${where}. Use: ${wd.hint}`, wd);
381
398
  }
382
399
 
383
400
  /**
@@ -403,21 +420,28 @@ function declaration(text) {
403
420
  * `50%, 75%`), each with its own indented declarations; a keyframe selector is
404
421
  * validated against KEYFRAME_SELECTOR so it can never be misread as a
405
422
  * declaration or an element selector, and declarations cannot nest further.
423
+ * Every rejection is a coded WD8xx error pointing at the offending line.
406
424
  * @param {string} kind `font-face` or `keyframes`.
407
425
  * @param {string | undefined} rest Text after the at-rule keyword (the
408
426
  * keyframes name; invalid on `@font-face`).
409
- * @param {{ indent: number, text: string }[]} lines Preprocessed skin lines.
427
+ * @param {{ indent: number, text: string, line: number }[]} lines Preprocessed
428
+ * skin lines, each carrying its true 1-based file line.
410
429
  * @param {number} start Index of the at-rule line.
430
+ * @param {string | undefined} file The skin's path, when the caller knows it.
411
431
  * @returns {{ css: string, end: number }} `end` = last consumed line index.
412
432
  */
413
- function collectAtRule(kind, rest, lines, start) {
433
+ function collectAtRule(kind, rest, lines, start, file) {
414
434
  const indent = lines[start].indent;
415
435
 
416
436
  if (kind === "font-face") {
417
437
  if (rest)
418
- throw skinError(
419
- `@font-face takes no name, got "${rest}" — write the descriptors indented beneath a bare @font-face line, e.g. font-family "Newsreader"`
420
- );
438
+ throw skinError(`@font-face takes no name, got "${rest}"`, {
439
+ code: "WD804",
440
+ file,
441
+ line: lines[start].line,
442
+ hint: `write the descriptors indented beneath a bare @font-face line — e.g. font-family "Newsreader"`,
443
+ example: FONT_FACE_EXAMPLE
444
+ });
421
445
  /** @type {string[]} */
422
446
  const decls = [];
423
447
  let i = start;
@@ -425,52 +449,94 @@ function collectAtRule(kind, rest, lines, start) {
425
449
  i++;
426
450
  if (i + 1 < lines.length && lines[i + 1].indent > lines[i].indent)
427
451
  throw skinError(
428
- `@font-face only takes declarations — "${lines[i].text}" opens a nested block, which is not valid inside @font-face`
452
+ `@font-face only takes declarations — "${lines[i].text}" opens a nested block, which is not valid inside @font-face`,
453
+ {
454
+ code: "WD804",
455
+ file,
456
+ line: lines[i].line,
457
+ hint: `keep every @font-face child a flat prop value declaration — e.g. font-family "Newsreader"`,
458
+ example: FONT_FACE_EXAMPLE
459
+ }
429
460
  );
430
461
  decls.push(` ${declaration(lines[i].text)}`);
431
462
  }
432
463
  if (!decls.length)
433
- throw skinError(
434
- '@font-face has no declarations — indent its descriptors beneath it, e.g. font-family "Newsreader"'
435
- );
464
+ throw skinError("@font-face has no declarations", {
465
+ code: "WD804",
466
+ file,
467
+ line: lines[start].line,
468
+ hint: `indent its descriptors beneath it — e.g. font-family "Newsreader"`,
469
+ example: FONT_FACE_EXAMPLE
470
+ });
436
471
  return { css: `@font-face {\n${decls.join("\n")}\n}`, end: i };
437
472
  }
438
473
 
439
- if (!rest) throw skinError("@keyframes needs a name — e.g. @keyframes fade-in");
474
+ if (!rest)
475
+ throw skinError("@keyframes needs a name", {
476
+ code: "WD805",
477
+ file,
478
+ line: lines[start].line,
479
+ hint: "@keyframes <name> — e.g. @keyframes fade-in",
480
+ example: KEYFRAMES_EXAMPLE
481
+ });
440
482
  if (!/^-?[A-Za-z_][\w-]*$/.test(rest))
441
- throw skinError(
442
- `invalid @keyframes name "${rest}" — use a plain CSS identifier, e.g. @keyframes fade-in`
443
- );
483
+ throw skinError(`invalid @keyframes name "${rest}"`, {
484
+ code: "WD805",
485
+ file,
486
+ line: lines[start].line,
487
+ hint: "name it with a plain CSS identifier — e.g. @keyframes fade-in",
488
+ example: KEYFRAMES_EXAMPLE
489
+ });
444
490
  /** @type {string[]} */
445
491
  const stops = [];
446
492
  let i = start;
447
493
  while (i + 1 < lines.length && lines[i + 1].indent > indent) {
448
494
  i++;
449
495
  const selector = lines[i].text;
496
+ const selectorLine = lines[i].line;
450
497
  const selectorIndent = lines[i].indent;
451
498
  if (!KEYFRAME_SELECTOR.test(selector))
452
- throw skinError(
453
- `"${selector}" is not a keyframe selector in @keyframes ${rest} — use from, to, or a percentage (50%, or a list like 50%, 75%)`
454
- );
499
+ throw skinError(`"${selector}" is not a keyframe selector in @keyframes ${rest}`, {
500
+ code: "WD806",
501
+ file,
502
+ line: selectorLine,
503
+ hint: "use from, to, or a percentage (50%, or a list like 50%, 75%)",
504
+ example: KEYFRAMES_EXAMPLE
505
+ });
455
506
  /** @type {string[]} */
456
507
  const decls = [];
457
508
  while (i + 1 < lines.length && lines[i + 1].indent > selectorIndent) {
458
509
  i++;
459
510
  if (i + 1 < lines.length && lines[i + 1].indent > lines[i].indent)
460
511
  throw skinError(
461
- `@keyframes declarations cannot nest — "${lines[i].text}" opens a block inside keyframe "${selector}"`
512
+ `@keyframes declarations cannot nest — "${lines[i].text}" opens a block inside keyframe "${selector}"`,
513
+ {
514
+ code: "WD807",
515
+ file,
516
+ line: lines[i].line,
517
+ hint: "keep each keyframe's declarations flat, one level beneath its selector — e.g. opacity 1",
518
+ example: KEYFRAMES_EXAMPLE
519
+ }
462
520
  );
463
521
  decls.push(` ${declaration(lines[i].text)}`);
464
522
  }
465
523
  if (!decls.length)
466
- throw skinError(
467
- `keyframe "${selector}" in @keyframes ${rest} has no declarations — indent them beneath it`
468
- );
524
+ throw skinError(`keyframe "${selector}" in @keyframes ${rest} has no declarations`, {
525
+ code: "WD807",
526
+ file,
527
+ line: selectorLine,
528
+ hint: "indent the declarations beneath the keyframe selector — e.g. opacity 1",
529
+ example: KEYFRAMES_EXAMPLE
530
+ });
469
531
  stops.push(` ${selector} {\n${decls.join("\n")}\n }`);
470
532
  }
471
533
  if (!stops.length)
472
- throw skinError(
473
- `@keyframes ${rest} has no keyframe selectors — indent from/to/percentage blocks beneath it`
474
- );
534
+ throw skinError(`@keyframes ${rest} has no keyframe selectors`, {
535
+ code: "WD807",
536
+ file,
537
+ line: lines[start].line,
538
+ hint: "indent from/to/percentage blocks beneath it — e.g. from",
539
+ example: KEYFRAMES_EXAMPLE
540
+ });
475
541
  return { css: `@keyframes ${rest} {\n${stops.join("\n")}\n}`, end: i };
476
542
  }
package/src/statics.js CHANGED
@@ -292,6 +292,7 @@ const contentTypes = {
292
292
  ".js": "text/javascript; charset=utf-8",
293
293
  ".json": "application/json",
294
294
  ".map": "application/json",
295
+ ".md": "text/markdown; charset=utf-8",
295
296
  ".svg": "image/svg+xml",
296
297
  ".png": "image/png",
297
298
  ".jpg": "image/jpeg",
@@ -12,7 +12,9 @@ in `darkmown dev` and on every host. Loading and error states are handled inline
12
12
 
13
13
  - `npm run dev` — live compiler + local `/api/*` runner on http://localhost:5173.
14
14
  - `npm run build` — compile to `dist/`.
15
- - `npm run preview` — serve the built `dist/` locally (static only; use `dev` for `/api`).
15
+ - `npm run preview`: serve the built `dist/` locally. Since Darkmown 2.8.0 this
16
+ runs your `api/` functions too, so the dashboard fetches live data in preview
17
+ exactly like in `dev`.
16
18
 
17
19
  ## Deploy
18
20
 
@@ -164,6 +164,13 @@ input:focus-visible, textarea:focus-visible, select:focus-visible
164
164
  radius 12px
165
165
  padding 1.25rem
166
166
 
167
+ .icon
168
+ color $accent
169
+ margin-bottom .35rem
170
+
171
+ .icon svg
172
+ display block
173
+
167
174
  .feature h3
168
175
  margin .25rem 0 .5rem
169
176
 
@@ -2,6 +2,7 @@
2
2
  title: Acme — ship faster
3
3
  description: A marketing one-pager built with Darkmown. Zero framework JS on the static parts, with a testimonials carousel.
4
4
  transitions: true
5
+ html: true
5
6
  ---
6
7
 
7
8
  @include /nav.wd
@@ -20,15 +21,21 @@ The all-in-one toolkit your team actually enjoys using.
20
21
 
21
22
  ::: features
22
23
  ::: feature
23
- ### ⚡ Fast
24
+ <div class="icon"><svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13 2 4 14h6l-1 8 9-12h-6l1-8z"/></svg></div>
25
+
26
+ ### Fast
24
27
  Static pages, zero framework JavaScript. Instant loads, perfect Lighthouse.
25
28
  :::
26
29
  ::: feature
27
- ### 🧩 Simple
30
+ <div class="icon"><svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="4" width="7" height="7" rx="1.5"/><rect x="13" y="4" width="7" height="7" rx="1.5"/><rect x="4" y="13" width="7" height="7" rx="1.5"/><rect x="13" y="13" width="7" height="7" rx="1.5"/></svg></div>
31
+
32
+ ### Simple
28
33
  Write Markdown. Add a directive only on the pages that need interactivity.
29
34
  :::
30
35
  ::: feature
31
- ### 🚀 Deploy anywhere
36
+ <div class="icon"><svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 15V3"/><path d="m6 9 6-6 6 6"/><path d="M4 21h16"/></svg></div>
37
+
38
+ ### Deploy anywhere
32
39
  One command to Vercel or Cloudflare — your API comes along for free.
33
40
  :::
34
41
  :::
@@ -3,7 +3,9 @@
3
3
  A storefront in Markdown: a product grid with live search, a shared `:store` cart,
4
4
  and a checkout that POSTs to a serverless function.
5
5
 
6
- - **Static catalog** — `site/pages/index.wd` loops `site/_/products.json`.
6
+ - **Static catalog**: `site/pages/index.wd` loops `site/_/products.json`, rendering
7
+ each product through the `site/_/card.wd` include (a `defaults:` fallback plus a
8
+ `{ children }` slot for the add-to-cart button).
7
9
  - **Cart** — a `:store` shared across the page; add/remove with `:button`.
8
10
  - **Checkout** — `:form action="/api/checkout"` posts to `api/checkout.js`, a plain
9
11
  Web-standard `(request) => Response` function that runs in `darkmown dev` and on
@@ -13,7 +15,8 @@ and a checkout that POSTs to a serverless function.
13
15
 
14
16
  - `npm run dev` — live compiler + the local `/api/*` runner on http://localhost:5173.
15
17
  - `npm run build` — compile to `dist/`.
16
- - `npm run preview` — serve the built `dist/` locally (static only; use `dev` for `/api`).
18
+ - `npm run preview`: serve the built `dist/` locally. Since Darkmown 2.8.0 this
19
+ runs your `api/` functions too, so checkout works in preview exactly like in `dev`.
17
20
 
18
21
  ## Deploy
19
22