ovr 0.1.1 → 1.1.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/README.md +1 -316
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +3 -0
- package/dist/components/suspense.d.ts +33 -0
- package/dist/components/suspense.js +31 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/jsx/elements.d.ts +27 -28
- package/dist/jsx/index.d.ts +3 -7
- package/dist/jsx/index.js +6 -6
- package/dist/router/context.js +5 -1
- package/package.json +9 -18
- package/LICENSE.md +0 -21
package/README.md
CHANGED
|
@@ -1,318 +1,3 @@
|
|
|
1
1
|
# ovr
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
npm i ovr
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
**ovr** is a [lightweight](https://bundlephobia.com/package/ovr) toolkit for building fast, streaming web applications using asynchronous JSX and a modern Fetch API-based router.
|
|
8
|
-
|
|
9
|
-
```tsx
|
|
10
|
-
async function* Component() {
|
|
11
|
-
yield <p>start</p>; // streamed immediately
|
|
12
|
-
await promise;
|
|
13
|
-
yield <p>after</p>;
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
It's designed for server-side rendering (SSR) where performance and Time-To-First-Byte (TTFB) matter. ovr evaluates components concurrently but streams the resulting HTML **in order**, allowing browsers to render content progressively as it arrives.
|
|
18
|
-
|
|
19
|
-
## Features
|
|
20
|
-
|
|
21
|
-
- **Asynchronous Streaming JSX**: Write components that perform async operations (like data fetching) directly. ovr handles concurrent evaluation and ordered streaming output.
|
|
22
|
-
- **Performance Focused**: Deliver HTML faster to the client by streaming content as it becomes ready, improving performance and TTFB.
|
|
23
|
-
- **Fetch API Router**: A modern, flexible router built on the standard Fetch API `Request` and `Response` objects.
|
|
24
|
-
- **Minimal & Platform Agnostic**: Uses standard JavaScript/Web APIs, allowing it to run in Node.js, Deno, Bun, Cloudflare Workers, browsers, and other environments.
|
|
25
|
-
- **[Trie](https://en.wikipedia.org/wiki/Radix_tree)-Based Routing**: Efficient and fast route matching, supporting static paths, parameters, and wildcards with clear prioritization. Performance does not degrade as you add more routes.
|
|
26
|
-
|
|
27
|
-
## Table of Contents
|
|
28
|
-
|
|
29
|
-
- [JSX](#jsx)
|
|
30
|
-
- [Router](#router)
|
|
31
|
-
- [Trie](#trie)
|
|
32
|
-
|
|
33
|
-
## JSX
|
|
34
|
-
|
|
35
|
-
ovr provides an asynchronous JSX runtime designed for server-side rendering. Instead of building the entire HTML string in memory, it produces an `AsyncGenerator` that yields HTML chunks.
|
|
36
|
-
|
|
37
|
-
When you render multiple asynchronous components (e.g., components fetching data), ovr initiates their evaluation concurrently. As each component resolves, its corresponding HTML is generated.
|
|
38
|
-
|
|
39
|
-
Crucially, ovr ensures that these HTML chunks are yielded in the original source order, even if components finish evaluating out of order. This allows the browser to start parsing and rendering the initial parts of your page while waiting for slower data fetches further down, significantly improving perceived load times.
|
|
40
|
-
|
|
41
|
-
For example, ovr will immediately send the `<head>` of your document for the browser to start requesting the linked assets. Then the rest of the page streams in as it becomes available.
|
|
42
|
-
|
|
43
|
-
### Configuration
|
|
44
|
-
|
|
45
|
-
Add the following to your `tsconfig.json` to enable the JSX transform,
|
|
46
|
-
|
|
47
|
-
```json
|
|
48
|
-
{
|
|
49
|
-
"jsx": "react-jsx",
|
|
50
|
-
"jsxImportSource": "ovr"
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
or use JSDoc comments within a module.
|
|
55
|
-
|
|
56
|
-
```ts
|
|
57
|
-
/** @jsx jsx */
|
|
58
|
-
/** @jsxImportSource ovr */
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Usage
|
|
62
|
-
|
|
63
|
-
JSX evaluates to an `AsyncGenerator`, with this, the `Router` creates an in-order stream of components.
|
|
64
|
-
|
|
65
|
-
```tsx
|
|
66
|
-
// Basic component with props
|
|
67
|
-
const Component = (props: { foo: string }) => <div>{props.foo}</div>;
|
|
68
|
-
|
|
69
|
-
// Components can be asynchronous, for example you can fetch directly in a component
|
|
70
|
-
const Data = async () => {
|
|
71
|
-
const res = await fetch("...");
|
|
72
|
-
const data = await res.json();
|
|
73
|
-
|
|
74
|
-
return <div>{JSON.stringify(data)}</div>;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// Components can also be generators, `yield` values instead of `return`
|
|
78
|
-
async function* Generator() {
|
|
79
|
-
yield <p>start</p>; // streamed immediately
|
|
80
|
-
await promise;
|
|
81
|
-
yield <p>after</p>;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const Page = () => {
|
|
85
|
-
return (
|
|
86
|
-
<div>
|
|
87
|
-
<Component foo="bar" />
|
|
88
|
-
|
|
89
|
-
{/* These three components await in parallel when this component is called. */}
|
|
90
|
-
{/* Then they will stream in order as soon as they are ready. */}
|
|
91
|
-
<Generator />
|
|
92
|
-
<Data />
|
|
93
|
-
<Data />
|
|
94
|
-
</div>
|
|
95
|
-
);
|
|
96
|
-
};
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
You can `return` or `yield` most data types from a component, they will be rendered as you might expect.
|
|
100
|
-
|
|
101
|
-
```tsx
|
|
102
|
-
function* DataTypes() {
|
|
103
|
-
yield null; // ""
|
|
104
|
-
yield undefined; // ""
|
|
105
|
-
yield false; // ""
|
|
106
|
-
yield "string"; // "string"
|
|
107
|
-
yield 0; // "0";
|
|
108
|
-
yield BigInt(9007199254740991); // "9007199254740991"
|
|
109
|
-
yield true; // "true"
|
|
110
|
-
yield { foo: "bar" }; // '{ "foo": "bar" }'
|
|
111
|
-
yield <p>jsx</p>; // "<p>jsx</p>"
|
|
112
|
-
yield ["any-", "iterable", 1, null]; // "any-iterable1"
|
|
113
|
-
yield () => "function"; // "function"
|
|
114
|
-
yield async () => "async"; // "async"
|
|
115
|
-
}
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
> [!WARNING]
|
|
119
|
-
>
|
|
120
|
-
> ovr does not escape HTML automatically, use the `escape` function provided.
|
|
121
|
-
|
|
122
|
-
## Router
|
|
123
|
-
|
|
124
|
-
```ts
|
|
125
|
-
import { Router } from "ovr";
|
|
126
|
-
|
|
127
|
-
const router = new Router();
|
|
128
|
-
|
|
129
|
-
router.get("/", (c) => c.text("Hello world"));
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Configuration
|
|
133
|
-
|
|
134
|
-
Optional configuration when creating the router.
|
|
135
|
-
|
|
136
|
-
```ts
|
|
137
|
-
const router = new Router({
|
|
138
|
-
// redirect trailing slash preference
|
|
139
|
-
trailingSlash: "always",
|
|
140
|
-
|
|
141
|
-
// runs at the start of each request
|
|
142
|
-
start(c) {
|
|
143
|
-
// customize the not found response
|
|
144
|
-
c.notFound = (c) => c.res("custom", { status: 404 });
|
|
145
|
-
|
|
146
|
-
// add a global error handler
|
|
147
|
-
c.error = (c, error) => c.res(error.message, { status: 500 });
|
|
148
|
-
|
|
149
|
-
// base HTML to inject head and body elements into, this is the default
|
|
150
|
-
c.base =
|
|
151
|
-
'<!doctype html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"></head><body></body></html>';
|
|
152
|
-
// (these can be set in middleware as well)
|
|
153
|
-
|
|
154
|
-
// return state to use in middleware
|
|
155
|
-
return { foo: "bar" };
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### Context
|
|
161
|
-
|
|
162
|
-
`Context` contains context for the current request.
|
|
163
|
-
|
|
164
|
-
```tsx
|
|
165
|
-
router.get("/api/:id", (c) => {
|
|
166
|
-
// Request Info
|
|
167
|
-
c.req; // The original Request object
|
|
168
|
-
c.url; // The parsed URL object
|
|
169
|
-
c.params; // Type-safe route parameters (e.g., { id: "123" })
|
|
170
|
-
c.route; // The matched Route object (contains pattern, store)
|
|
171
|
-
c.state; // State returned from `config.start` (e.g., { dbClient, user })
|
|
172
|
-
|
|
173
|
-
// Response Building Methods
|
|
174
|
-
c.res(body, init); // Generic response (like `new Response()`)
|
|
175
|
-
c.html(body, status); // Set HTML response
|
|
176
|
-
c.text(body, status); // Set plain text response
|
|
177
|
-
c.json(data, status); // Set JSON response
|
|
178
|
-
c.redirect(location, status); // Set redirect response
|
|
179
|
-
|
|
180
|
-
// JSX Page Building Methods (Leverages Streaming JSX)
|
|
181
|
-
c.head(<meta name="description" content="..." />); // Add elements to <head>
|
|
182
|
-
c.layout(MainLayout); // Wrap page content with layout components
|
|
183
|
-
c.page(<UserProfilePage userId={c.params.id} />); // Render JSX page, streaming enabled!
|
|
184
|
-
|
|
185
|
-
// Other Utilities
|
|
186
|
-
c.etag("content-to-hash"); // Generate and check ETag for caching
|
|
187
|
-
c.build(); // (Internal) Builds the final Response object
|
|
188
|
-
});
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### Examples
|
|
192
|
-
|
|
193
|
-
#### Overview
|
|
194
|
-
|
|
195
|
-
```ts
|
|
196
|
-
// Basic
|
|
197
|
-
router.get("/", (c) => c.text("Hello world"));
|
|
198
|
-
|
|
199
|
-
// Params
|
|
200
|
-
router.post("/api/:id", (c) => {
|
|
201
|
-
// matches "/api/123"
|
|
202
|
-
c.params; // { id: "123" }
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
// Wildcard - add an asterisk `*` to match all remaining segments in the route
|
|
206
|
-
router.get("/files/*", (c) => {
|
|
207
|
-
// c.params["*"] contains the matched wildcard path (e.g., "images/logo.png")
|
|
208
|
-
return c.text(`Serving file: ${c.params["*"]}`);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// Other or custom methods
|
|
212
|
-
router.on("METHOD", "/pattern", () => {
|
|
213
|
-
// ...
|
|
214
|
-
});
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
#### Middleware
|
|
218
|
-
|
|
219
|
-
Add middleware to a route, the first middleware added to the route will be called, and the `next` middleware can be called within the first by using `await next()`. Middleware is based on [koa-compose](https://github.com/koajs/compose).
|
|
220
|
-
|
|
221
|
-
```ts
|
|
222
|
-
router.get(
|
|
223
|
-
"/multi",
|
|
224
|
-
async (c, next) => {
|
|
225
|
-
// middleware
|
|
226
|
-
console.log("pre"); // 1
|
|
227
|
-
await next(); // calls the next middleware below
|
|
228
|
-
console.log("post"); // 3
|
|
229
|
-
},
|
|
230
|
-
() => console.log("final"); // 2
|
|
231
|
-
);
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
`Context` is passed between between each middleware that is stored in the matched `Route`. After all the handlers have been run, the `Context` will `build` and return the final response.
|
|
235
|
-
|
|
236
|
-
#### Multiple patterns
|
|
237
|
-
|
|
238
|
-
Apply handlers to multiple patterns at once with type safe parameters.
|
|
239
|
-
|
|
240
|
-
```ts
|
|
241
|
-
router.get(["/multi/:param", "/pattern/:another"], (c) => {
|
|
242
|
-
c.param; // { param: string } | { another: string }
|
|
243
|
-
});
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### fetch
|
|
247
|
-
|
|
248
|
-
Use the `fetch` method to create a response,
|
|
249
|
-
|
|
250
|
-
```ts
|
|
251
|
-
const res = await router.fetch(new Request("https://example.com/"));
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
or use in a framework.
|
|
255
|
-
|
|
256
|
-
```ts
|
|
257
|
-
// next, sveltekit, astro...
|
|
258
|
-
export const GET = router.fetch;
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
```ts
|
|
262
|
-
// bun, deno, cloudflare...
|
|
263
|
-
export default router;
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
### mount
|
|
267
|
-
|
|
268
|
-
Mount routers onto another with a base pattern.
|
|
269
|
-
|
|
270
|
-
```ts
|
|
271
|
-
const app = new Router();
|
|
272
|
-
|
|
273
|
-
const hello = new Router();
|
|
274
|
-
|
|
275
|
-
hello.get("/world", (c) => c.text("hello world"));
|
|
276
|
-
|
|
277
|
-
app.mount("/hello", hello); // creates route at "/hello/world"
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
## Trie
|
|
281
|
-
|
|
282
|
-
[Router](#router) is built using the `Trie` and `Route` classes. You can build your own trie based router by importing them.
|
|
283
|
-
|
|
284
|
-
The trie is forked and adapted from [memoirist](https://github.com/SaltyAom/memoirist) and [@medley/router](https://github.com/medleyjs/router).
|
|
285
|
-
|
|
286
|
-
```ts
|
|
287
|
-
import { Trie, Route } from "ovr";
|
|
288
|
-
|
|
289
|
-
// specify the type of the store in the generic
|
|
290
|
-
const trie = new Trie<string>();
|
|
291
|
-
const route = new Route("/hello/:name", "store");
|
|
292
|
-
|
|
293
|
-
trie.add(route);
|
|
294
|
-
|
|
295
|
-
const match = trie.find("/hello/world"); // { route, params: { name: "world" } }
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### Prioritization
|
|
299
|
-
|
|
300
|
-
The trie prioritizes matches in this order: **Static > Parametric > Wildcard**.
|
|
301
|
-
|
|
302
|
-
Given three routes are added in any order,
|
|
303
|
-
|
|
304
|
-
```ts
|
|
305
|
-
trie.add(new Route("/hello/world", "store"));
|
|
306
|
-
trie.add(new Route("/hello/:name", "store"));
|
|
307
|
-
trie.add(new Route("/hello/*", "store"));
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
The following pathnames would match the corresponding patterns.
|
|
311
|
-
|
|
312
|
-
| pathname | Route.pattern |
|
|
313
|
-
| --------------------- | ---------------- |
|
|
314
|
-
| `"/hello/world"` | `"/hello/world"` |
|
|
315
|
-
| `"/hello/john"` | `"/hello/:name"` |
|
|
316
|
-
| `"/hello/john/smith"` | `"/hello/*"` |
|
|
317
|
-
|
|
318
|
-
More specific matches are prioritized. First, the static match is found, then the parametric, and finally the wildcard.
|
|
3
|
+
Repository for the core `ovr` package.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { JSX } from "../jsx/index.js";
|
|
2
|
+
export declare const style = "l-f,l-c{display:contents}l-f:has(+*>l-c:not(:empty)){display:none}l-a{display:flex;flex-direction:column-reverse}";
|
|
3
|
+
/**
|
|
4
|
+
* Wrap an async component with `Suspense` to provide a loading `fallback`
|
|
5
|
+
* to display before it resolves. The `Suspense` component works without
|
|
6
|
+
* client-side JavaScript using CSS to hide the `fallback` once the `children`
|
|
7
|
+
* are streamed in and to reverse the order of the `children` and `after` elements.
|
|
8
|
+
*
|
|
9
|
+
* `fallback`, `after`, and `children` are resolved in parallel but streamed sequentially.
|
|
10
|
+
*
|
|
11
|
+
* @param props
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <Suspense fallback={<p>Loading...</p>} after={<footer>After</footer>}>
|
|
17
|
+
* <AsyncComponent />
|
|
18
|
+
* </Suspense>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function Suspense(props: {
|
|
22
|
+
/** Fallback to display while `children` are loading. */
|
|
23
|
+
fallback?: JSX.Element;
|
|
24
|
+
/**
|
|
25
|
+
* Element(s) to display _visually after_ the `children`, but stream/resolve before.
|
|
26
|
+
*
|
|
27
|
+
* Ensure `after` does take less time to resolve than `children`, otherwise
|
|
28
|
+
* `children` will be blocked until `after` resolves.
|
|
29
|
+
*/
|
|
30
|
+
after?: JSX.Element;
|
|
31
|
+
/** Asynchronous element(s) to provide a fallback for. */
|
|
32
|
+
children?: JSX.Element;
|
|
33
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const style = /* css */ `l-f,l-c{display:contents}l-f:has(+*>l-c:not(:empty)){display:none}l-a{display:flex;flex-direction:column-reverse}`;
|
|
2
|
+
/**
|
|
3
|
+
* Wrap an async component with `Suspense` to provide a loading `fallback`
|
|
4
|
+
* to display before it resolves. The `Suspense` component works without
|
|
5
|
+
* client-side JavaScript using CSS to hide the `fallback` once the `children`
|
|
6
|
+
* are streamed in and to reverse the order of the `children` and `after` elements.
|
|
7
|
+
*
|
|
8
|
+
* `fallback`, `after`, and `children` are resolved in parallel but streamed sequentially.
|
|
9
|
+
*
|
|
10
|
+
* @param props
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <Suspense fallback={<p>Loading...</p>} after={<footer>After</footer>}>
|
|
16
|
+
* <AsyncComponent />
|
|
17
|
+
* </Suspense>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function Suspense(props) {
|
|
21
|
+
const wrap = props.after != null ? "a" : "w";
|
|
22
|
+
return [
|
|
23
|
+
"<l-f>",
|
|
24
|
+
props.fallback,
|
|
25
|
+
"</l-f><l-" + wrap + "><div>",
|
|
26
|
+
props.after,
|
|
27
|
+
"</div><l-c>",
|
|
28
|
+
props.children,
|
|
29
|
+
"</l-c></l-" + wrap + ">",
|
|
30
|
+
];
|
|
31
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export { Suspense } from "./components/suspense.js";
|
|
2
|
+
export { escape } from "./escape/index.js";
|
|
3
|
+
export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment, toGenerator, toString, type FC, type JSX, } from "./jsx/index.js";
|
|
1
4
|
export { Context } from "./router/context.js";
|
|
2
5
|
export { Router, type Middleware, type Params } from "./router/index.js";
|
|
3
6
|
export { Trie, Route } from "./trie/index.js";
|
|
4
|
-
export { escape } from "./escape/index.js";
|
|
5
|
-
export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment, toGenerator, toString, type FC, type JSX, } from "./jsx/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export { Suspense } from "./components/suspense.js";
|
|
2
|
+
export { escape } from "./escape/index.js";
|
|
3
|
+
export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment, toGenerator, toString, } from "./jsx/index.js";
|
|
1
4
|
export { Context } from "./router/context.js";
|
|
2
5
|
export { Router } from "./router/index.js";
|
|
3
6
|
export { Trie, Route } from "./trie/index.js";
|
|
4
|
-
export { escape } from "./escape/index.js";
|
|
5
|
-
export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment, toGenerator, toString, } from "./jsx/index.js";
|
package/dist/jsx/elements.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { JSX,
|
|
2
|
-
type Attributes<
|
|
3
|
-
children:
|
|
1
|
+
import type { JSX, Props } from "./index.js";
|
|
2
|
+
type Attributes<P extends Props = Props, Children = JSX.Element> = Partial<{
|
|
3
|
+
children: Children;
|
|
4
4
|
accesskey: string;
|
|
5
5
|
anchor: string;
|
|
6
6
|
autocapitalize: "on" | "off" | "characters" | "words" | "sentences";
|
|
@@ -58,8 +58,7 @@ type Attributes<T extends ElementProps = ElementProps> = Partial<{
|
|
|
58
58
|
"aria-owns": string;
|
|
59
59
|
"aria-relevant": "additions" | "all" | "removals" | "text" | "additions text";
|
|
60
60
|
"aria-roledescription": string;
|
|
61
|
-
}> &
|
|
62
|
-
type VoidAttributes<T extends ElementProps = ElementProps> = Omit<Attributes<T>, "children">;
|
|
61
|
+
}> & Props & Partial<P>;
|
|
63
62
|
type SharedAttributes = {
|
|
64
63
|
autocomplete: "on" | "off" | (string & {});
|
|
65
64
|
blocking: "render";
|
|
@@ -84,7 +83,7 @@ type AAttributes = Attributes<{
|
|
|
84
83
|
target: SharedAttributes["target"];
|
|
85
84
|
type: string;
|
|
86
85
|
}>;
|
|
87
|
-
type AreaAttributes =
|
|
86
|
+
type AreaAttributes = Attributes<{
|
|
88
87
|
alt: string;
|
|
89
88
|
coords: "rect" | "circle" | "poly";
|
|
90
89
|
download: string | boolean;
|
|
@@ -94,7 +93,7 @@ type AreaAttributes = VoidAttributes<{
|
|
|
94
93
|
rel: AAttributes["rel"];
|
|
95
94
|
shape: "rect" | "circle" | "poly" | "default";
|
|
96
95
|
target: SharedAttributes["target"];
|
|
97
|
-
}>;
|
|
96
|
+
}, never>;
|
|
98
97
|
type AudioAttributes = Attributes<{
|
|
99
98
|
autoplay: boolean;
|
|
100
99
|
controls: boolean;
|
|
@@ -106,10 +105,10 @@ type AudioAttributes = Attributes<{
|
|
|
106
105
|
preload: SharedAttributes["preload"];
|
|
107
106
|
src: string;
|
|
108
107
|
}>;
|
|
109
|
-
type BaseAttributes =
|
|
108
|
+
type BaseAttributes = Attributes<{
|
|
110
109
|
href: string;
|
|
111
110
|
target: SharedAttributes["target"];
|
|
112
|
-
}>;
|
|
111
|
+
}, undefined>;
|
|
113
112
|
type BlockquoteAttributes = Attributes<{
|
|
114
113
|
cite: string;
|
|
115
114
|
}>;
|
|
@@ -159,9 +158,9 @@ type CanvasAttributes = Attributes<{
|
|
|
159
158
|
["moz-opaque"]: boolean;
|
|
160
159
|
width: string;
|
|
161
160
|
}>;
|
|
162
|
-
type ColAttributes =
|
|
161
|
+
type ColAttributes = Attributes<{
|
|
163
162
|
span: string;
|
|
164
|
-
}>;
|
|
163
|
+
}, undefined>;
|
|
165
164
|
type ColgroupAttributes = Attributes<{
|
|
166
165
|
span: string;
|
|
167
166
|
}>;
|
|
@@ -179,12 +178,12 @@ type DetailsAttributes = Attributes<{
|
|
|
179
178
|
type DialogAttributes = Attributes<{
|
|
180
179
|
open: boolean;
|
|
181
180
|
}>;
|
|
182
|
-
type EmbedAttributes =
|
|
181
|
+
type EmbedAttributes = Attributes<{
|
|
183
182
|
height: string;
|
|
184
183
|
src: string;
|
|
185
184
|
type: string;
|
|
186
185
|
width: string;
|
|
187
|
-
}>;
|
|
186
|
+
}, undefined>;
|
|
188
187
|
type FieldsetAttributes = Attributes<{
|
|
189
188
|
disabled: boolean;
|
|
190
189
|
form: string;
|
|
@@ -216,7 +215,7 @@ type IframeAttributes = Attributes<{
|
|
|
216
215
|
srcdoc: string;
|
|
217
216
|
width: string;
|
|
218
217
|
}>;
|
|
219
|
-
type ImgAttributes =
|
|
218
|
+
type ImgAttributes = Attributes<{
|
|
220
219
|
alt: string;
|
|
221
220
|
crossorigin: SharedAttributes["crossorigin"];
|
|
222
221
|
decoding: "sync" | "async" | "auto";
|
|
@@ -231,8 +230,8 @@ type ImgAttributes = VoidAttributes<{
|
|
|
231
230
|
srcset: string;
|
|
232
231
|
width: string;
|
|
233
232
|
usemap: string;
|
|
234
|
-
}>;
|
|
235
|
-
type InputAttributes =
|
|
233
|
+
}, undefined>;
|
|
234
|
+
type InputAttributes = Attributes<{
|
|
236
235
|
accept: string;
|
|
237
236
|
alt: string;
|
|
238
237
|
autocomplete: SharedAttributes["autocomplete"];
|
|
@@ -266,7 +265,7 @@ type InputAttributes = VoidAttributes<{
|
|
|
266
265
|
type: "button" | "checkbox" | "color" | "date" | "datetime-local" | "email" | "file" | "hidden" | "image" | "month" | "number" | "password" | "radio" | "range" | "reset" | "search" | "submit" | "tel" | "text" | "time" | "url" | "week";
|
|
267
266
|
value: string;
|
|
268
267
|
width: string;
|
|
269
|
-
}>;
|
|
268
|
+
}, never>;
|
|
270
269
|
type InsAttributes = Attributes<{
|
|
271
270
|
cite: string;
|
|
272
271
|
datetime: string;
|
|
@@ -278,7 +277,7 @@ type LabelAttributes = Attributes<{
|
|
|
278
277
|
type LiAttributes = Attributes<{
|
|
279
278
|
value: string;
|
|
280
279
|
}>;
|
|
281
|
-
type LinkAttributes =
|
|
280
|
+
type LinkAttributes = Attributes<{
|
|
282
281
|
as: "audio" | "document" | "embed" | "fetch" | "font" | "image" | "object" | "script" | "style" | "track" | "video" | "worker";
|
|
283
282
|
blocking: SharedAttributes["blocking"];
|
|
284
283
|
crossorigin: SharedAttributes["crossorigin"];
|
|
@@ -294,17 +293,17 @@ type LinkAttributes = VoidAttributes<{
|
|
|
294
293
|
rel: "alternate" | "author" | "canonical" | "dns-prefetch" | "expect" | "help" | "icon" | "license" | "manifest" | "me" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "prev" | "privacy-policy" | "search" | "stylesheet" | "terms-of-service" | (string & {});
|
|
295
294
|
sizes: string;
|
|
296
295
|
type: string;
|
|
297
|
-
}>;
|
|
296
|
+
}, undefined>;
|
|
298
297
|
type MapAttributes = Attributes<{
|
|
299
298
|
name: string;
|
|
300
299
|
}>;
|
|
301
|
-
type MetaAttributes =
|
|
300
|
+
type MetaAttributes = Attributes<{
|
|
302
301
|
charset: "utf-8";
|
|
303
302
|
content: string;
|
|
304
303
|
"http-equiv": "content-security-policy" | "content-type" | "default-style" | "x-ua-compatible" | "refresh";
|
|
305
304
|
media: string;
|
|
306
305
|
name: "application-name" | "author" | "description" | "generator" | "keywords" | "theme-color" | "viewport" | (string & {});
|
|
307
|
-
}>;
|
|
306
|
+
}, undefined>;
|
|
308
307
|
type MeterAttributes = Attributes<{
|
|
309
308
|
value: string;
|
|
310
309
|
min: string;
|
|
@@ -374,7 +373,7 @@ type SelectAttributes = Attributes<{
|
|
|
374
373
|
type SlotAttributes = Attributes<{
|
|
375
374
|
name: string;
|
|
376
375
|
}>;
|
|
377
|
-
type SourceAttributes =
|
|
376
|
+
type SourceAttributes = Attributes<{
|
|
378
377
|
type: string;
|
|
379
378
|
src: string;
|
|
380
379
|
srcset: string;
|
|
@@ -382,7 +381,7 @@ type SourceAttributes = VoidAttributes<{
|
|
|
382
381
|
media: string;
|
|
383
382
|
height: string;
|
|
384
383
|
width: string;
|
|
385
|
-
}>;
|
|
384
|
+
}, undefined>;
|
|
386
385
|
type StyleAttributes = Attributes<{
|
|
387
386
|
blocking: SharedAttributes["blocking"];
|
|
388
387
|
media: string;
|
|
@@ -423,13 +422,13 @@ type ThAttributes = Attributes<{
|
|
|
423
422
|
type TimeAttributes = Attributes<{
|
|
424
423
|
datetime: string;
|
|
425
424
|
}>;
|
|
426
|
-
type TrackAttributes =
|
|
425
|
+
type TrackAttributes = Attributes<{
|
|
427
426
|
default: boolean;
|
|
428
427
|
kind: "subtitles" | "captions" | "chapters" | "metadata";
|
|
429
428
|
label: string;
|
|
430
429
|
src: string;
|
|
431
430
|
srclang: string;
|
|
432
|
-
}>;
|
|
431
|
+
}, undefined>;
|
|
433
432
|
type VideoAttributes = Attributes<{
|
|
434
433
|
autoplay: boolean;
|
|
435
434
|
controls: boolean;
|
|
@@ -459,7 +458,7 @@ export type Elements = Record<string, Attributes> & {
|
|
|
459
458
|
bdo: Attributes;
|
|
460
459
|
blockquote: BlockquoteAttributes;
|
|
461
460
|
body: BodyAttributes;
|
|
462
|
-
br:
|
|
461
|
+
br: Attributes<Props, undefined>;
|
|
463
462
|
button: ButtonAttributes;
|
|
464
463
|
canvas: CanvasAttributes;
|
|
465
464
|
caption: Attributes;
|
|
@@ -493,7 +492,7 @@ export type Elements = Record<string, Attributes> & {
|
|
|
493
492
|
head: Attributes;
|
|
494
493
|
header: Attributes;
|
|
495
494
|
hgroup: Attributes;
|
|
496
|
-
hr:
|
|
495
|
+
hr: Attributes<Props, undefined>;
|
|
497
496
|
html: HtmlAttributes;
|
|
498
497
|
iframe: IframeAttributes;
|
|
499
498
|
i: Attributes;
|
|
@@ -557,6 +556,6 @@ export type Elements = Record<string, Attributes> & {
|
|
|
557
556
|
ul: Attributes;
|
|
558
557
|
var: Attributes;
|
|
559
558
|
video: VideoAttributes;
|
|
560
|
-
wbr:
|
|
559
|
+
wbr: Attributes<Props, undefined>;
|
|
561
560
|
};
|
|
562
561
|
export {};
|
package/dist/jsx/index.d.ts
CHANGED
|
@@ -5,21 +5,17 @@ export declare namespace JSX {
|
|
|
5
5
|
type IntrinsicElements = Elements;
|
|
6
6
|
type Element = MaybeFunction<MaybePromise<string | number | bigint | boolean | object | null | undefined | Symbol | Iterable<Element> | AsyncIterable<Element>>>;
|
|
7
7
|
}
|
|
8
|
-
export type ElementProps = Record<string, JSX.Element>;
|
|
9
8
|
export type Props = Record<string, unknown>;
|
|
10
|
-
export type FC<
|
|
9
|
+
export type FC<Props> = (props: Props) => JSX.Element;
|
|
11
10
|
/**
|
|
12
|
-
* The main function of the
|
|
11
|
+
* The main function of the JSX transform cycle, each time JSX is encountered
|
|
13
12
|
* it is passed into this function to be resolved.
|
|
14
13
|
*
|
|
15
14
|
* @param tag string or function that refers to the component or element type
|
|
16
15
|
* @param props object containing all the properties and attributes passed to the element or component
|
|
17
16
|
* @returns an async generator that yields parts of HTML
|
|
18
17
|
*/
|
|
19
|
-
export declare
|
|
20
|
-
(tag: FC, props: Props): Awaited<JSX.Element>;
|
|
21
|
-
(tag: string, props: ElementProps): Awaited<JSX.Element>;
|
|
22
|
-
};
|
|
18
|
+
export declare function jsx(tag: FC<Props> | string, props: Props): AsyncGenerator<string, void, unknown>;
|
|
23
19
|
/**
|
|
24
20
|
* jsx requires a `Fragment` export to resolve <></>
|
|
25
21
|
*
|
package/dist/jsx/index.js
CHANGED
|
@@ -16,14 +16,14 @@ const voidElements = new Set([
|
|
|
16
16
|
"wbr",
|
|
17
17
|
]);
|
|
18
18
|
/**
|
|
19
|
-
* The main function of the
|
|
19
|
+
* The main function of the JSX transform cycle, each time JSX is encountered
|
|
20
20
|
* it is passed into this function to be resolved.
|
|
21
21
|
*
|
|
22
22
|
* @param tag string or function that refers to the component or element type
|
|
23
23
|
* @param props object containing all the properties and attributes passed to the element or component
|
|
24
24
|
* @returns an async generator that yields parts of HTML
|
|
25
25
|
*/
|
|
26
|
-
export
|
|
26
|
+
export async function* jsx(tag, props) {
|
|
27
27
|
if (typeof tag === "function") {
|
|
28
28
|
yield* toGenerator(tag(props));
|
|
29
29
|
}
|
|
@@ -55,7 +55,7 @@ export const jsx = async function* (tag, props) {
|
|
|
55
55
|
yield* toGenerator(children);
|
|
56
56
|
yield `</${tag}>`;
|
|
57
57
|
}
|
|
58
|
-
}
|
|
58
|
+
}
|
|
59
59
|
/**
|
|
60
60
|
* jsx requires a `Fragment` export to resolve <></>
|
|
61
61
|
*
|
|
@@ -87,11 +87,11 @@ export async function* toGenerator(element) {
|
|
|
87
87
|
for (const children of element)
|
|
88
88
|
generators.push(toGenerator(children));
|
|
89
89
|
const queue = new Array(generators.length).fill("");
|
|
90
|
-
const
|
|
90
|
+
const complete = new Set();
|
|
91
91
|
let current = 0;
|
|
92
92
|
for await (const { index, value, done } of mergeAsyncIterables(generators)) {
|
|
93
93
|
if (done) {
|
|
94
|
-
|
|
94
|
+
complete.add(index);
|
|
95
95
|
if (index === current) {
|
|
96
96
|
while (++current < generators.length) {
|
|
97
97
|
if (queue[current]) {
|
|
@@ -100,7 +100,7 @@ export async function* toGenerator(element) {
|
|
|
100
100
|
queue[current] = "";
|
|
101
101
|
}
|
|
102
102
|
// if it hasn't completed, stop iterating to the next
|
|
103
|
-
if (!
|
|
103
|
+
if (!complete.has(current))
|
|
104
104
|
break;
|
|
105
105
|
}
|
|
106
106
|
}
|
package/dist/router/context.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { head } from "../components/index.js";
|
|
1
2
|
import { toGenerator } from "../jsx/index.js";
|
|
2
3
|
class TagNotFound extends Error {
|
|
3
4
|
constructor(tag) {
|
|
@@ -158,10 +159,13 @@ export class Context {
|
|
|
158
159
|
const elements = this.base.split(headClose);
|
|
159
160
|
if (!elements[1])
|
|
160
161
|
throw new TagNotFound(headClose);
|
|
161
|
-
elements.splice(1, 0, this.#headElements, headClose);
|
|
162
|
+
elements.splice(1, 0, this.#headElements, head + headClose);
|
|
162
163
|
const bodyParts = elements[3].split(bodyClose);
|
|
163
164
|
if (!bodyParts[1])
|
|
164
165
|
throw new TagNotFound(bodyClose);
|
|
166
|
+
// https://bugs.webkit.org/show_bug.cgi?id=252413
|
|
167
|
+
// https://github.com/sveltejs/kit/issues/10315
|
|
168
|
+
bodyParts[0] += `<div aria-hidden=true style=position:absolute;width:0;height:0;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0>${"/".repeat(200)}</div>`;
|
|
165
169
|
elements[3] = bodyParts[0];
|
|
166
170
|
elements.push(Page, bodyClose + bodyParts[1]);
|
|
167
171
|
this.html(new ReadableStream({
|
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ovr",
|
|
3
|
-
"
|
|
3
|
+
"description": "Asynchronous streaming server framework",
|
|
4
|
+
"version": "1.1.0",
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "git+https://github.com/rossrobino/ovr.git"
|
|
8
9
|
},
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Ross Robino",
|
|
12
|
+
"url": "https://robino.dev"
|
|
13
|
+
},
|
|
9
14
|
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
10
16
|
"types": "./dist/index.d.ts",
|
|
11
17
|
"main": "./dist/index.js",
|
|
12
18
|
"exports": {
|
|
@@ -27,23 +33,8 @@
|
|
|
27
33
|
"dist"
|
|
28
34
|
],
|
|
29
35
|
"scripts": {
|
|
30
|
-
"test": "vitest run",
|
|
31
|
-
"test:dev": "vitest",
|
|
32
36
|
"check": "tsc --noEmit",
|
|
33
37
|
"dev": "tsc --watch",
|
|
34
|
-
"build": "tsc"
|
|
35
|
-
|
|
36
|
-
"changeset": "changeset",
|
|
37
|
-
"version": "changeset version",
|
|
38
|
-
"release": "npm run build && changeset publish"
|
|
39
|
-
},
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@changesets/cli": "^2.28.1",
|
|
42
|
-
"@robino/prettier": "^1.0.2",
|
|
43
|
-
"@robino/tsconfig": "^1.0.2",
|
|
44
|
-
"prettier": "^3.5.3",
|
|
45
|
-
"typescript": "^5.8.2",
|
|
46
|
-
"vitest": "^3.0.9"
|
|
47
|
-
},
|
|
48
|
-
"prettier": "@robino/prettier"
|
|
38
|
+
"build": "tsc"
|
|
39
|
+
}
|
|
49
40
|
}
|
package/LICENSE.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Ross Robino
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|