create-volt 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ All notable changes to `create-volt` are documented here. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/), and this project adheres to
5
5
  [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.18.0] - 2026-06-29
8
+
9
+ ### Added
10
+ - **Volt SSR** — `volt-ssr.js`, a tiny server-side renderer: render the same
11
+ `html` / `h()` markup and signal values to an HTML string in Node (`${values}`
12
+ escaped by default, `raw()` for trusted HTML) via `renderToString`. Ships in
13
+ every template, so a scaffolded app can be server-rendered for SEO + fast first
14
+ paint and hydrate with `volt.js` on the client. The Volt site itself is now
15
+ built with it — marketing pages as Volt components, docs as markdown rendered
16
+ with `raw()`, the whole page composed by `renderToString`.
17
+
7
18
  ## [0.17.0] - 2026-06-29
8
19
 
9
20
  ### Added
@@ -256,6 +267,7 @@ All notable changes to `create-volt` are documented here. The format follows
256
267
  watching and full-page hot reload. Supports `--skip-install` and `--force`,
257
268
  and auto-detects npm / pnpm / yarn / bun for the install step.
258
269
 
270
+ [0.18.0]: https://github.com/MIR-2025/volt/releases/tag/v0.18.0
259
271
  [0.17.0]: https://github.com/MIR-2025/volt/releases/tag/v0.17.0
260
272
  [0.16.0]: https://github.com/MIR-2025/volt/releases/tag/v0.16.0
261
273
  [0.15.1]: https://github.com/MIR-2025/volt/releases/tag/v0.15.1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-volt",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Scaffold a new Volt app — no-build, signals-based UI with Socket.io hot reload.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,63 @@
1
+ // volt-ssr.js — server-side rendering for Volt. Renders the same html`` markup,
2
+ // h() elements, and signal values to an HTML string in Node (no DOM), so a Volt
3
+ // app can be fully server-rendered for SEO and hydrate interactive islands with
4
+ // volt.js on the client.
5
+ //
6
+ // import { html, h, raw, renderToString } from "./volt-ssr.js";
7
+ // renderToString(html`<p>${name}</p>`) // → "<p>Ada</p>" (name is escaped)
8
+ //
9
+ // Authoring matches the client: html`` interpolations render as escaped text;
10
+ // nest html``/h() nodes for structure; use raw() for trusted pre-built HTML.
11
+
12
+ const VOID = new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
13
+ const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
14
+
15
+ // trusted, pre-rendered HTML — emitted verbatim. Use only for content you control.
16
+ export const raw = (s) => ({ __raw: String(s) });
17
+
18
+ // tagged-template markup; the literal chunks are trusted, ${values} are escaped.
19
+ export const html = (strings, ...values) => ({ __tpl: true, strings, values });
20
+
21
+ const isNode = (x) => x && typeof x === "object" && (x.__tpl || x.__raw || x.__el);
22
+
23
+ // hyperscript element: h(tag, props?, ...children)
24
+ export function h(tag, props, ...children) {
25
+ if (props === undefined || props === null || isNode(props) || Array.isArray(props) || typeof props !== "object") {
26
+ if (props !== undefined && props !== null) children.unshift(props);
27
+ props = {};
28
+ }
29
+ return { __el: true, tag, props, children };
30
+ }
31
+
32
+ const read = (v) => (typeof v === "function" ? v() : v); // resolve signals/thunks (once)
33
+
34
+ function attrs(props) {
35
+ let out = "";
36
+ for (const [k, rawVal] of Object.entries(props)) {
37
+ if (k === "children" || k.startsWith("on")) continue; // event handlers don't SSR
38
+ const v = read(rawVal);
39
+ if (v == null || v === false) continue;
40
+ const name = k === "className" ? "class" : k;
41
+ out += v === true ? ` ${name}` : ` ${name}="${esc(v)}"`;
42
+ }
43
+ return out;
44
+ }
45
+
46
+ export function renderToString(node) {
47
+ const v = read(node);
48
+ if (v == null || v === false || v === true) return "";
49
+ if (typeof v === "string" || typeof v === "number") return esc(v);
50
+ if (v.__raw != null) return v.__raw;
51
+ if (Array.isArray(v)) return v.map(renderToString).join("");
52
+ if (v.__tpl) {
53
+ let out = v.strings[0];
54
+ for (let i = 0; i < v.values.length; i++) out += renderToString(v.values[i]) + v.strings[i + 1];
55
+ return out;
56
+ }
57
+ if (v.__el) {
58
+ if (typeof v.tag === "function") return renderToString(v.tag({ ...v.props, children: v.children }));
59
+ const open = `<${v.tag}${attrs(v.props)}>`;
60
+ return VOID.has(v.tag) ? open : `${open}${v.children.map(renderToString).join("")}</${v.tag}>`;
61
+ }
62
+ return esc(String(v));
63
+ }
@@ -0,0 +1,63 @@
1
+ // volt-ssr.js — server-side rendering for Volt. Renders the same html`` markup,
2
+ // h() elements, and signal values to an HTML string in Node (no DOM), so a Volt
3
+ // app can be fully server-rendered for SEO and hydrate interactive islands with
4
+ // volt.js on the client.
5
+ //
6
+ // import { html, h, raw, renderToString } from "./volt-ssr.js";
7
+ // renderToString(html`<p>${name}</p>`) // → "<p>Ada</p>" (name is escaped)
8
+ //
9
+ // Authoring matches the client: html`` interpolations render as escaped text;
10
+ // nest html``/h() nodes for structure; use raw() for trusted pre-built HTML.
11
+
12
+ const VOID = new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
13
+ const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
14
+
15
+ // trusted, pre-rendered HTML — emitted verbatim. Use only for content you control.
16
+ export const raw = (s) => ({ __raw: String(s) });
17
+
18
+ // tagged-template markup; the literal chunks are trusted, ${values} are escaped.
19
+ export const html = (strings, ...values) => ({ __tpl: true, strings, values });
20
+
21
+ const isNode = (x) => x && typeof x === "object" && (x.__tpl || x.__raw || x.__el);
22
+
23
+ // hyperscript element: h(tag, props?, ...children)
24
+ export function h(tag, props, ...children) {
25
+ if (props === undefined || props === null || isNode(props) || Array.isArray(props) || typeof props !== "object") {
26
+ if (props !== undefined && props !== null) children.unshift(props);
27
+ props = {};
28
+ }
29
+ return { __el: true, tag, props, children };
30
+ }
31
+
32
+ const read = (v) => (typeof v === "function" ? v() : v); // resolve signals/thunks (once)
33
+
34
+ function attrs(props) {
35
+ let out = "";
36
+ for (const [k, rawVal] of Object.entries(props)) {
37
+ if (k === "children" || k.startsWith("on")) continue; // event handlers don't SSR
38
+ const v = read(rawVal);
39
+ if (v == null || v === false) continue;
40
+ const name = k === "className" ? "class" : k;
41
+ out += v === true ? ` ${name}` : ` ${name}="${esc(v)}"`;
42
+ }
43
+ return out;
44
+ }
45
+
46
+ export function renderToString(node) {
47
+ const v = read(node);
48
+ if (v == null || v === false || v === true) return "";
49
+ if (typeof v === "string" || typeof v === "number") return esc(v);
50
+ if (v.__raw != null) return v.__raw;
51
+ if (Array.isArray(v)) return v.map(renderToString).join("");
52
+ if (v.__tpl) {
53
+ let out = v.strings[0];
54
+ for (let i = 0; i < v.values.length; i++) out += renderToString(v.values[i]) + v.strings[i + 1];
55
+ return out;
56
+ }
57
+ if (v.__el) {
58
+ if (typeof v.tag === "function") return renderToString(v.tag({ ...v.props, children: v.children }));
59
+ const open = `<${v.tag}${attrs(v.props)}>`;
60
+ return VOID.has(v.tag) ? open : `${open}${v.children.map(renderToString).join("")}</${v.tag}>`;
61
+ }
62
+ return esc(String(v));
63
+ }
@@ -0,0 +1,63 @@
1
+ // volt-ssr.js — server-side rendering for Volt. Renders the same html`` markup,
2
+ // h() elements, and signal values to an HTML string in Node (no DOM), so a Volt
3
+ // app can be fully server-rendered for SEO and hydrate interactive islands with
4
+ // volt.js on the client.
5
+ //
6
+ // import { html, h, raw, renderToString } from "./volt-ssr.js";
7
+ // renderToString(html`<p>${name}</p>`) // → "<p>Ada</p>" (name is escaped)
8
+ //
9
+ // Authoring matches the client: html`` interpolations render as escaped text;
10
+ // nest html``/h() nodes for structure; use raw() for trusted pre-built HTML.
11
+
12
+ const VOID = new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
13
+ const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
14
+
15
+ // trusted, pre-rendered HTML — emitted verbatim. Use only for content you control.
16
+ export const raw = (s) => ({ __raw: String(s) });
17
+
18
+ // tagged-template markup; the literal chunks are trusted, ${values} are escaped.
19
+ export const html = (strings, ...values) => ({ __tpl: true, strings, values });
20
+
21
+ const isNode = (x) => x && typeof x === "object" && (x.__tpl || x.__raw || x.__el);
22
+
23
+ // hyperscript element: h(tag, props?, ...children)
24
+ export function h(tag, props, ...children) {
25
+ if (props === undefined || props === null || isNode(props) || Array.isArray(props) || typeof props !== "object") {
26
+ if (props !== undefined && props !== null) children.unshift(props);
27
+ props = {};
28
+ }
29
+ return { __el: true, tag, props, children };
30
+ }
31
+
32
+ const read = (v) => (typeof v === "function" ? v() : v); // resolve signals/thunks (once)
33
+
34
+ function attrs(props) {
35
+ let out = "";
36
+ for (const [k, rawVal] of Object.entries(props)) {
37
+ if (k === "children" || k.startsWith("on")) continue; // event handlers don't SSR
38
+ const v = read(rawVal);
39
+ if (v == null || v === false) continue;
40
+ const name = k === "className" ? "class" : k;
41
+ out += v === true ? ` ${name}` : ` ${name}="${esc(v)}"`;
42
+ }
43
+ return out;
44
+ }
45
+
46
+ export function renderToString(node) {
47
+ const v = read(node);
48
+ if (v == null || v === false || v === true) return "";
49
+ if (typeof v === "string" || typeof v === "number") return esc(v);
50
+ if (v.__raw != null) return v.__raw;
51
+ if (Array.isArray(v)) return v.map(renderToString).join("");
52
+ if (v.__tpl) {
53
+ let out = v.strings[0];
54
+ for (let i = 0; i < v.values.length; i++) out += renderToString(v.values[i]) + v.strings[i + 1];
55
+ return out;
56
+ }
57
+ if (v.__el) {
58
+ if (typeof v.tag === "function") return renderToString(v.tag({ ...v.props, children: v.children }));
59
+ const open = `<${v.tag}${attrs(v.props)}>`;
60
+ return VOID.has(v.tag) ? open : `${open}${v.children.map(renderToString).join("")}</${v.tag}>`;
61
+ }
62
+ return esc(String(v));
63
+ }