ovr 1.2.0 → 1.2.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/dist/jsx/elements.d.ts +1 -1
- package/dist/jsx/index.d.ts +3 -3
- package/dist/jsx/index.js +11 -11
- package/dist/jsx/merge-async-iterables.d.ts +9 -8
- package/dist/jsx/merge-async-iterables.js +23 -32
- package/dist/router/context.js +1 -1
- package/dist/trie/index.js +2 -8
- package/package.json +1 -1
package/dist/jsx/elements.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ type Attributes<P extends Props = Props, Children = JSX.Element> = Partial<{
|
|
|
26
26
|
lang: string;
|
|
27
27
|
nonce: string;
|
|
28
28
|
part: string;
|
|
29
|
-
popover:
|
|
29
|
+
popover: boolean | "auto" | "hint" | "manual";
|
|
30
30
|
role: "alert" | "alertdialog" | "application" | "article" | "banner" | "button" | "cell" | "checkbox" | "columnheader" | "combobox" | "complementary" | "contentinfo" | "definition" | "dialog" | "directory" | "document" | "feed" | "figure" | "form" | "grid" | "gridcell" | "group" | "heading" | "img" | "link" | "list" | "listbox" | "listitem" | "log" | "main" | "marquee" | "math" | "menu" | "menubar" | "menuitem" | "menuitemcheckbox" | "menuitemradio" | "navigation" | "none" | "note" | "option" | "presentation" | "progressbar" | "radio" | "radiogroup" | "region" | "row" | "rowgroup" | "rowheader" | "scrollbar" | "search" | "searchbox" | "separator" | "slider" | "spinbutton" | "status" | "switch" | "tab" | "table" | "tablist" | "tabpanel" | "term" | "textbox" | "timer" | "toolbar" | "tooltip" | "tree" | "treegrid" | "treeitem";
|
|
31
31
|
slot: string;
|
|
32
32
|
spellcheck: "true" | "false";
|
package/dist/jsx/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type FC<Props> = (props: Props) => JSX.Element;
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function jsx(tag: FC<Props> | string, props: Props): AsyncGenerator<string, void, unknown>;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* JSX requires a `Fragment` export to resolve <></>
|
|
21
21
|
*
|
|
22
22
|
* @param props containing `children` to render
|
|
23
23
|
* @returns async generator that yields concatenated children
|
|
@@ -27,11 +27,11 @@ export declare function Fragment(props?: {
|
|
|
27
27
|
}): AsyncGenerator<string, void, unknown>;
|
|
28
28
|
/**
|
|
29
29
|
* @param element
|
|
30
|
-
* @
|
|
30
|
+
* @yields Rendered strings of HTML as the `Element` resolves.
|
|
31
31
|
*/
|
|
32
32
|
export declare function toGenerator(element: JSX.Element): AsyncGenerator<string, void, unknown>;
|
|
33
33
|
/**
|
|
34
|
-
* Converts a `JSX.Element` into
|
|
34
|
+
* Converts a `JSX.Element` into a fully concatenated string of HTML.
|
|
35
35
|
*
|
|
36
36
|
* > [!WARNING]
|
|
37
37
|
* >
|
package/dist/jsx/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { merge } from "./merge-async-iterables.js";
|
|
2
2
|
// https://developer.mozilla.org/en-US/docs/Glossary/Void_element#self-closing_tags
|
|
3
3
|
const voidElements = new Set([
|
|
4
4
|
"area",
|
|
@@ -32,7 +32,7 @@ export async function* jsx(tag, props) {
|
|
|
32
32
|
const { children, ...attrs } = props;
|
|
33
33
|
let attrStr = "";
|
|
34
34
|
for (let key in attrs) {
|
|
35
|
-
const value = attrs[key];
|
|
35
|
+
const value = attrs[key]; // needs to come before reassigning keys
|
|
36
36
|
if (key === "className")
|
|
37
37
|
key = "class";
|
|
38
38
|
else if (key === "htmlFor")
|
|
@@ -57,7 +57,7 @@ export async function* jsx(tag, props) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
60
|
+
* JSX requires a `Fragment` export to resolve <></>
|
|
61
61
|
*
|
|
62
62
|
* @param props containing `children` to render
|
|
63
63
|
* @returns async generator that yields concatenated children
|
|
@@ -67,15 +67,15 @@ export async function* Fragment(props = {}) {
|
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* @param element
|
|
70
|
-
* @
|
|
70
|
+
* @yields Rendered strings of HTML as the `Element` resolves.
|
|
71
71
|
*/
|
|
72
72
|
export async function* toGenerator(element) {
|
|
73
73
|
if (typeof element === "function")
|
|
74
74
|
element = element();
|
|
75
75
|
if (element instanceof Promise)
|
|
76
76
|
element = await element;
|
|
77
|
-
// undefined, null, or
|
|
78
|
-
if (element == null || element ===
|
|
77
|
+
// undefined, null, or boolean should not render
|
|
78
|
+
if (element == null || typeof element === "boolean")
|
|
79
79
|
return;
|
|
80
80
|
if (typeof element === "object") {
|
|
81
81
|
if (Symbol.asyncIterator in element) {
|
|
@@ -89,8 +89,8 @@ export async function* toGenerator(element) {
|
|
|
89
89
|
const queue = new Array(generators.length).fill("");
|
|
90
90
|
const complete = new Set();
|
|
91
91
|
let current = 0;
|
|
92
|
-
for await (const { index,
|
|
93
|
-
if (done) {
|
|
92
|
+
for await (const { index, result } of merge(generators)) {
|
|
93
|
+
if (result.done) {
|
|
94
94
|
complete.add(index);
|
|
95
95
|
if (index === current) {
|
|
96
96
|
while (++current < generators.length) {
|
|
@@ -106,10 +106,10 @@ export async function* toGenerator(element) {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
else if (index === current) {
|
|
109
|
-
yield value; // stream the current value directly
|
|
109
|
+
yield result.value; // stream the current value directly
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
112
|
-
queue[index] += value; // queue the value for later
|
|
112
|
+
queue[index] += result.value; // queue the value for later
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
yield queue.join(""); // clear the queue
|
|
@@ -123,7 +123,7 @@ export async function* toGenerator(element) {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* Converts a `JSX.Element` into
|
|
126
|
+
* Converts a `JSX.Element` into a fully concatenated string of HTML.
|
|
127
127
|
*
|
|
128
128
|
* > [!WARNING]
|
|
129
129
|
* >
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Merges `AsyncIterable[]` into a single `AsyncGenerator`, resolving all in parallel.
|
|
3
|
+
* The return of each `AsyncIterable` is yielded from the generator with `done: true`.
|
|
4
|
+
*
|
|
5
|
+
* Adapted from [stack overflow answers](https://stackoverflow.com/questions/50585456).
|
|
6
|
+
*
|
|
7
|
+
* @param iterables Resolved in parallel.
|
|
8
|
+
* @yields `IteratorResult` and `index` of the resolved iterator.
|
|
3
9
|
*/
|
|
4
|
-
export declare function
|
|
10
|
+
export declare function merge<T, R>(iterables: AsyncIterable<T, R>[]): AsyncGenerator<{
|
|
5
11
|
index: number;
|
|
6
|
-
|
|
7
|
-
value?: undefined;
|
|
8
|
-
} | {
|
|
9
|
-
index: number;
|
|
10
|
-
value: T;
|
|
11
|
-
done: false;
|
|
12
|
+
result: IteratorResult<T, R>;
|
|
12
13
|
}, void, unknown>;
|
|
@@ -1,39 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.index = index;
|
|
7
|
-
this.iterator = iterable[Symbol.asyncIterator]();
|
|
8
|
-
this.promise = this.next();
|
|
9
|
-
}
|
|
10
|
-
next() {
|
|
11
|
-
return (this.promise = this.iterator.next().then((result) => ({
|
|
12
|
-
result,
|
|
13
|
-
handler: this,
|
|
14
|
-
})));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function* getPromises(handlers) {
|
|
18
|
-
for (const handler of handlers)
|
|
19
|
-
yield handler.promise;
|
|
20
|
-
}
|
|
1
|
+
const never = new Promise(() => { });
|
|
2
|
+
const next = async (iterator, index) => ({
|
|
3
|
+
index,
|
|
4
|
+
result: await iterator.next(),
|
|
5
|
+
});
|
|
21
6
|
/**
|
|
22
|
-
*
|
|
7
|
+
* Merges `AsyncIterable[]` into a single `AsyncGenerator`, resolving all in parallel.
|
|
8
|
+
* The return of each `AsyncIterable` is yielded from the generator with `done: true`.
|
|
9
|
+
*
|
|
10
|
+
* Adapted from [stack overflow answers](https://stackoverflow.com/questions/50585456).
|
|
11
|
+
*
|
|
12
|
+
* @param iterables Resolved in parallel.
|
|
13
|
+
* @yields `IteratorResult` and `index` of the resolved iterator.
|
|
23
14
|
*/
|
|
24
|
-
export async function*
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
export async function* merge(iterables) {
|
|
16
|
+
const iterators = iterables.map((iter) => iter[Symbol.asyncIterator]());
|
|
17
|
+
const promises = iterators.map(next);
|
|
18
|
+
let remaining = promises.length;
|
|
19
|
+
let current;
|
|
20
|
+
while (remaining) {
|
|
21
|
+
yield (current = await Promise.race(promises));
|
|
22
|
+
if (current.result.done) {
|
|
23
|
+
promises[current.index] = never;
|
|
24
|
+
remaining--;
|
|
33
25
|
}
|
|
34
26
|
else {
|
|
35
|
-
|
|
36
|
-
handler.next();
|
|
27
|
+
promises[current.index] = next(iterators[current.index], current.index);
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
30
|
}
|
package/dist/router/context.js
CHANGED
|
@@ -169,7 +169,7 @@ export class Context {
|
|
|
169
169
|
elements[3] = bodyParts[0];
|
|
170
170
|
elements.push(Page, bodyClose + bodyParts[1]);
|
|
171
171
|
this.html(new ReadableStream({
|
|
172
|
-
|
|
172
|
+
async start(c) {
|
|
173
173
|
for await (const value of toGenerator(elements))
|
|
174
174
|
c.enqueue(value);
|
|
175
175
|
c.close();
|
package/dist/trie/index.js
CHANGED
|
@@ -204,15 +204,9 @@ export class Trie {
|
|
|
204
204
|
if (pathname === this.segment) {
|
|
205
205
|
// reached the end of the path
|
|
206
206
|
if (this.route)
|
|
207
|
-
return {
|
|
208
|
-
route: this.route,
|
|
209
|
-
params: {},
|
|
210
|
-
};
|
|
207
|
+
return { route: this.route, params: {} };
|
|
211
208
|
if (this.wildcardRoute)
|
|
212
|
-
return {
|
|
213
|
-
route: this.wildcardRoute,
|
|
214
|
-
params: { "*": "" },
|
|
215
|
-
};
|
|
209
|
+
return { route: this.wildcardRoute, params: { "*": "" } };
|
|
216
210
|
return null;
|
|
217
211
|
}
|
|
218
212
|
if (this.staticMap) {
|