@barefootjs/hono 0.5.2 → 0.6.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/dist/render.d.ts +40 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +13 -0
- package/package.json +6 -2
- package/src/render.ts +48 -0
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic SSR render entry for the hono/jsx runtime.
|
|
3
|
+
*
|
|
4
|
+
* BarefootJS components compiled with the Hono adapter are plain
|
|
5
|
+
* `hono/jsx` components: they render to an HTML string without needing a
|
|
6
|
+
* Hono `app`, a router, or `hono/jsx-renderer`'s request context. This
|
|
7
|
+
* module exposes that capability directly so any HTTP framework (h3,
|
|
8
|
+
* Elysia, Express, …) can host BarefootJS by importing this package as a
|
|
9
|
+
* render runtime — the same way the Go `Echo` integration imports the
|
|
10
|
+
* framework-agnostic `bf` runtime shipped by the go-template adapter.
|
|
11
|
+
*
|
|
12
|
+
* Two entry points:
|
|
13
|
+
* - `renderToHtml` — buffered: resolves the whole tree to one string.
|
|
14
|
+
* - `renderToStream` — streaming: returns a `ReadableStream` so
|
|
15
|
+
* `<Suspense>` boundaries flush out-of-order.
|
|
16
|
+
*
|
|
17
|
+
* Both accept a `hono/jsx` node (typically a full page including the
|
|
18
|
+
* layout shell, `<BfImportMap>`, and `<BfScripts>`).
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Render a hono/jsx node to a complete HTML string.
|
|
22
|
+
*
|
|
23
|
+
* A `hono/jsx` node stringifies via `.toString()`, which returns either
|
|
24
|
+
* a string (fully synchronous tree) or a `Promise<string>` (the tree
|
|
25
|
+
* contains an `async` component). We normalise both to `Promise<string>`
|
|
26
|
+
* so callers always `await` once. Streaming `<Suspense>` boundaries are
|
|
27
|
+
* NOT resolved here — use `renderToStream` when the page streams.
|
|
28
|
+
*/
|
|
29
|
+
export declare function renderToHtml(node: unknown): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Render a hono/jsx node to a `ReadableStream` of UTF-8 HTML chunks.
|
|
32
|
+
*
|
|
33
|
+
* Use this when the page contains `<Suspense>` boundaries (e.g. async
|
|
34
|
+
* data / streaming SSR): the shell flushes immediately and each boundary
|
|
35
|
+
* streams in as it resolves. The returned stream is a Web-standard
|
|
36
|
+
* `ReadableStream`, directly returnable from any WinterCG-compatible
|
|
37
|
+
* handler (h3, Elysia, Hono, Workers, …).
|
|
38
|
+
*/
|
|
39
|
+
export declare function renderToStream(node: unknown): ReadableStream;
|
|
40
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAGjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,CAE5D"}
|
package/dist/render.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/render.ts
|
|
2
|
+
import { renderToReadableStream } from "hono/jsx/streaming";
|
|
3
|
+
async function renderToHtml(node) {
|
|
4
|
+
const out = node.toString();
|
|
5
|
+
return out instanceof Promise ? await out : out;
|
|
6
|
+
}
|
|
7
|
+
function renderToStream(node) {
|
|
8
|
+
return renderToReadableStream(node);
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
renderToStream,
|
|
12
|
+
renderToHtml
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/hono",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Hono integration for BarefootJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -72,6 +72,10 @@
|
|
|
72
72
|
"./app": {
|
|
73
73
|
"types": "./dist/app.d.ts",
|
|
74
74
|
"import": "./dist/app.js"
|
|
75
|
+
},
|
|
76
|
+
"./render": {
|
|
77
|
+
"types": "./dist/render.d.ts",
|
|
78
|
+
"import": "./dist/render.js"
|
|
75
79
|
}
|
|
76
80
|
},
|
|
77
81
|
"files": [
|
|
@@ -80,7 +84,7 @@
|
|
|
80
84
|
],
|
|
81
85
|
"scripts": {
|
|
82
86
|
"build": "bun run build:js && bun run build:types",
|
|
83
|
-
"build:js": "bun build ./src/index.ts ./src/adapter/index.ts ./src/scripts.tsx ./src/portals.tsx ./src/portal-ssr.tsx ./src/dialog-context.tsx ./src/client-shim.ts ./src/preload.tsx ./src/dev.tsx ./src/dev-worker.ts ./src/jsx/jsx-runtime/index.ts ./src/jsx/jsx-dev-runtime/index.ts ./src/async.tsx ./src/utils.ts ./src/build.ts ./src/app.ts --root ./src --outdir ./dist --format esm --external hono --external @barefootjs/client --external @barefootjs/jsx --external @barefootjs/shared",
|
|
87
|
+
"build:js": "bun build ./src/index.ts ./src/adapter/index.ts ./src/scripts.tsx ./src/portals.tsx ./src/portal-ssr.tsx ./src/dialog-context.tsx ./src/client-shim.ts ./src/preload.tsx ./src/dev.tsx ./src/dev-worker.ts ./src/jsx/jsx-runtime/index.ts ./src/jsx/jsx-dev-runtime/index.ts ./src/async.tsx ./src/utils.ts ./src/build.ts ./src/app.ts ./src/render.ts --root ./src --outdir ./dist --format esm --external hono --external @barefootjs/client --external @barefootjs/jsx --external @barefootjs/shared",
|
|
84
88
|
"build:types": "tsgo --emitDeclarationOnly --outDir ./dist",
|
|
85
89
|
"test": "bun test",
|
|
86
90
|
"clean": "rm -rf dist",
|
package/src/render.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic SSR render entry for the hono/jsx runtime.
|
|
3
|
+
*
|
|
4
|
+
* BarefootJS components compiled with the Hono adapter are plain
|
|
5
|
+
* `hono/jsx` components: they render to an HTML string without needing a
|
|
6
|
+
* Hono `app`, a router, or `hono/jsx-renderer`'s request context. This
|
|
7
|
+
* module exposes that capability directly so any HTTP framework (h3,
|
|
8
|
+
* Elysia, Express, …) can host BarefootJS by importing this package as a
|
|
9
|
+
* render runtime — the same way the Go `Echo` integration imports the
|
|
10
|
+
* framework-agnostic `bf` runtime shipped by the go-template adapter.
|
|
11
|
+
*
|
|
12
|
+
* Two entry points:
|
|
13
|
+
* - `renderToHtml` — buffered: resolves the whole tree to one string.
|
|
14
|
+
* - `renderToStream` — streaming: returns a `ReadableStream` so
|
|
15
|
+
* `<Suspense>` boundaries flush out-of-order.
|
|
16
|
+
*
|
|
17
|
+
* Both accept a `hono/jsx` node (typically a full page including the
|
|
18
|
+
* layout shell, `<BfImportMap>`, and `<BfScripts>`).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { renderToReadableStream } from 'hono/jsx/streaming'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Render a hono/jsx node to a complete HTML string.
|
|
25
|
+
*
|
|
26
|
+
* A `hono/jsx` node stringifies via `.toString()`, which returns either
|
|
27
|
+
* a string (fully synchronous tree) or a `Promise<string>` (the tree
|
|
28
|
+
* contains an `async` component). We normalise both to `Promise<string>`
|
|
29
|
+
* so callers always `await` once. Streaming `<Suspense>` boundaries are
|
|
30
|
+
* NOT resolved here — use `renderToStream` when the page streams.
|
|
31
|
+
*/
|
|
32
|
+
export async function renderToHtml(node: unknown): Promise<string> {
|
|
33
|
+
const out = (node as { toString(): string | Promise<string> }).toString()
|
|
34
|
+
return out instanceof Promise ? await out : out
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Render a hono/jsx node to a `ReadableStream` of UTF-8 HTML chunks.
|
|
39
|
+
*
|
|
40
|
+
* Use this when the page contains `<Suspense>` boundaries (e.g. async
|
|
41
|
+
* data / streaming SSR): the shell flushes immediately and each boundary
|
|
42
|
+
* streams in as it resolves. The returned stream is a Web-standard
|
|
43
|
+
* `ReadableStream`, directly returnable from any WinterCG-compatible
|
|
44
|
+
* handler (h3, Elysia, Hono, Workers, …).
|
|
45
|
+
*/
|
|
46
|
+
export function renderToStream(node: unknown): ReadableStream {
|
|
47
|
+
return renderToReadableStream(node as Parameters<typeof renderToReadableStream>[0])
|
|
48
|
+
}
|