ovr 7.0.0-next.36 → 7.0.0-next.38
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 +12 -0
- package/dist/context/index.d.ts +2 -2
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +4 -7
- package/dist/markdown/index.d.ts +38 -52
- package/dist/markdown/index.d.ts.map +1 -1
- package/dist/markdown/index.js +6 -73
- package/dist/markup/index.d.ts +8 -52
- package/dist/markup/index.d.ts.map +1 -1
- package/dist/markup/index.js +24 -96
- package/dist/render/index.d.ts +56 -43
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/index.js +87 -37
- package/package.json +1 -1
- package/src/context/index.ts +14 -11
- package/src/markdown/index.ts +41 -120
- package/src/markup/index.ts +27 -114
- package/src/render/index.ts +133 -58
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# ovr
|
|
2
2
|
|
|
3
|
+
## 7.0.0-next.38
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0e9715a: The option types of a render are `Render.Options.Markup` and `Render.Options.Markdown`, where they were `Render.Markup.Options` and `Render.Markdown.Options`. Inside, `Render` drives the renderers itself, without a class of each between.
|
|
8
|
+
|
|
9
|
+
## 7.0.0-next.37
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- c15a886: A render is made with `new Render`, which takes the element by what to render it to, as `Render.raw` and `Render.escape` take theirs: `new Render({ markup: element }, options)` and `new Render({ markdown: element }, options)`, where they were `Render.markup(element, options)` and `Render.markdown(element, options)`.
|
|
14
|
+
|
|
3
15
|
## 7.0.0-next.36
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { App } from "../app/index.js";
|
|
2
2
|
import { Cookie } from "../cookie/index.js";
|
|
3
3
|
import { type Field } from "../form/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { type Options, tools } from "../markdown/index.js";
|
|
5
5
|
import type { Middleware } from "../middleware/index.js";
|
|
6
6
|
import { Multipart } from "../multipart/index.js";
|
|
7
7
|
import { Route } from "../route/index.js";
|
|
@@ -20,7 +20,7 @@ export declare const agent: WeakMap<Request, {
|
|
|
20
20
|
readonly message: string;
|
|
21
21
|
}[];
|
|
22
22
|
/** The tool a form submits to and its arguments, so a page points to it */
|
|
23
|
-
readonly tool?:
|
|
23
|
+
readonly tool?: Options[typeof tools];
|
|
24
24
|
}>;
|
|
25
25
|
/** Properties to build the final `Response` with once middleware has run. */
|
|
26
26
|
declare class PreparedResponse {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,KAAK,KAAK,EAA6B,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,KAAK,KAAK,EAA6B,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAkC,KAAK,IAAI,EAA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,QAE1C;IAED;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,WAM9C;IAaD;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,GAAG,KAAK,EAEtC,QAAQ,EAAE,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAC/B,CAAC,SAAS,GAAG,MAAM,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,EAAE,GACzC,KAAK,GACL,CAAC,GACF,CAAC,EACJ,MAAM,GAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAS,QAQzC;IAED;;;;;;;;OAQG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,WAalB;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,aAEpC;IAED;;;;;;;;;;;OAWG;IACH,OAAO,oCAIN;IAED;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAgEtE;IAwGD;;;;;;OAMG;IACH,OAAa,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,qBAoBxD;CACD"}
|
package/dist/context/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Cookie } from "../cookie/index.js";
|
|
2
2
|
import { Form as FormSchema, forms } from "../form/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import { Markup } from "../markup/index.js";
|
|
3
|
+
import { tools } from "../markdown/index.js";
|
|
5
4
|
import { Multipart } from "../multipart/index.js";
|
|
5
|
+
import { Render } from "../render/index.js";
|
|
6
6
|
import { Route } from "../route/index.js";
|
|
7
7
|
import { Checksum, Header, Method, Mime } from "../util/index.js";
|
|
8
8
|
/**
|
|
@@ -328,15 +328,12 @@ export class Context {
|
|
|
328
328
|
// for both
|
|
329
329
|
if (!/^\s*attachment/i.test(res.headers.get("content-disposition") ?? "") &&
|
|
330
330
|
this.#markdown()) {
|
|
331
|
-
res.body = new
|
|
332
|
-
base: this.url,
|
|
333
|
-
[tools]: agent.get(this.req)?.tool,
|
|
334
|
-
}).stream();
|
|
331
|
+
res.body = new Render({ markdown: r }, { base: this.url, [tools]: agent.get(this.req)?.tool }).stream();
|
|
335
332
|
res.headers.set(Header.name.type, Header.utf8(Mime.type.md));
|
|
336
333
|
return;
|
|
337
334
|
}
|
|
338
335
|
}
|
|
339
|
-
res.body = new
|
|
336
|
+
res.body = new Render({ markup: r }, {
|
|
340
337
|
// other defined types are not markup, so they are not escaped
|
|
341
338
|
raw: Boolean(mime && !Mime.markup(mime)),
|
|
342
339
|
}).stream();
|
package/dist/markdown/index.d.ts
CHANGED
|
@@ -1,66 +1,52 @@
|
|
|
1
1
|
import type { JSX } from "../jsx/index.js";
|
|
2
2
|
/** Internal protocol for the MCP endpoint, to write a form as its tool's call. */
|
|
3
3
|
export declare const tools: unique symbol;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
}
|
|
4
|
+
/** Markdown conversion options */
|
|
5
|
+
export type Options = {
|
|
6
|
+
/** Resolves relative links and form actions, usually the request URL */
|
|
7
|
+
readonly base?: string | URL | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Finds the tool that submits a form, if there is one, set by
|
|
10
|
+
* an MCP endpoint. A form is then written as the call to its tool, with
|
|
11
|
+
* the arguments its address holds, its values, and its messages. A form
|
|
12
|
+
* without a tool is left out: the agent has no way to submit it.
|
|
13
|
+
*
|
|
14
|
+
* @param method Form method
|
|
15
|
+
* @param action Resolved form action
|
|
16
|
+
* @returns The tool's name, the arguments from the address's parameters,
|
|
17
|
+
* the fields whose choices are given as the form renders, which its
|
|
18
|
+
* input schema can't list, and the fields it takes as an array, which
|
|
19
|
+
* the form shows as rows or lines
|
|
20
|
+
*/
|
|
21
|
+
readonly [tools]?: ((method: string, action: URL) => {
|
|
22
|
+
name: string;
|
|
23
|
+
args: Record<string, string>;
|
|
24
|
+
choices: ReadonlySet<string>;
|
|
25
|
+
lists: ReadonlySet<string>;
|
|
26
|
+
} | undefined) | undefined;
|
|
27
|
+
};
|
|
30
28
|
/**
|
|
31
|
-
* Renders an element to Markdown
|
|
32
|
-
*
|
|
33
|
-
* `Render.markdown`. Each top level block is
|
|
34
|
-
* written as soon as it closes, and when the page has a `<main>` element, only
|
|
35
|
-
* its contents are kept. Raw HTML is written as it is.
|
|
36
|
-
*
|
|
37
|
-
* ```tsx
|
|
38
|
-
* const markdown = await Render.markdown(<Post post={post} />, { base: url }).string();
|
|
39
|
-
* ```
|
|
29
|
+
* Renders an element to Markdown a step at a time, as a render of markup
|
|
30
|
+
* steps through its chunks, so neither waits unless the element does.
|
|
40
31
|
*/
|
|
41
|
-
export declare class
|
|
32
|
+
export declare class Blocks {
|
|
42
33
|
#private;
|
|
43
34
|
/**
|
|
44
|
-
* @param text Plain text
|
|
45
|
-
* @returns The text escaped, to write in Markdown as it is
|
|
46
|
-
*/
|
|
47
|
-
static escape(text: string): string;
|
|
48
|
-
/**
|
|
49
|
-
* Creates an `AsyncIterable` that renders the element to Markdown.
|
|
50
|
-
*
|
|
51
35
|
* @param element Element to render
|
|
52
36
|
* @param options Markdown options
|
|
53
37
|
*/
|
|
54
|
-
constructor(element: JSX.Element, options?:
|
|
55
|
-
/** @yields Markdown as each block completes */
|
|
56
|
-
[Symbol.asyncIterator](): AsyncGenerator<string, void, unknown>;
|
|
57
|
-
/** @returns `ReadableStream` of Markdown */
|
|
58
|
-
stream(): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
38
|
+
constructor(element: JSX.Element, options?: Options);
|
|
59
39
|
/**
|
|
60
|
-
* The
|
|
61
|
-
*
|
|
62
|
-
* @returns Concatenated Markdown
|
|
40
|
+
* @returns The Markdown of the next complete block or blocks, a promise to
|
|
41
|
+
* wait for before the next step, or `undefined` once all of it is written
|
|
63
42
|
*/
|
|
64
|
-
|
|
43
|
+
step(): string | Promise<unknown> | undefined;
|
|
44
|
+
/** Ends the render if it is not read to its end. */
|
|
45
|
+
close(): Promise<void>;
|
|
65
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* @param text Plain text
|
|
49
|
+
* @returns The text escaped, to write in Markdown as it is
|
|
50
|
+
*/
|
|
51
|
+
export declare function escape(text: string): string;
|
|
66
52
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AA0C3C,kFAAkF;AAClF,eAAO,MAAM,KAAK,eAAkB,CAAC;AAErC,kCAAkC;AAClC,MAAM,MAAM,OAAO,GAAG;IACrB,wEAAwE;IACxE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAAC;IAEzC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EACd,CAAC,CACD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,GAAG,KAET;QACA,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7B,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QAC7B,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;KAC1B,GACD,SAAS,CAAC,GACZ,SAAS,CAAC;CACb,CAAC;AAg0CF;;;GAGG;AACH,qBAAa,MAAM;;IAUlB;;;OAGG;IACH,YAAY,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,EAGlD;IAED;;;OAGG;IACH,IAAI,0CAaH;IAED,oDAAoD;IACpD,KAAK,kBAEJ;CACD;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,UAElC"}
|
package/dist/markdown/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Group, Renderer, Source, Tag
|
|
1
|
+
import { Group, Renderer, Source, Tag } from "../markup/index.js";
|
|
2
2
|
/** Internal protocol for the MCP endpoint, to write a form as its tool's call. */
|
|
3
3
|
export const tools = Symbol("tools");
|
|
4
4
|
/** Writes Markdown from rendered chunks, one block at a time */
|
|
@@ -1246,7 +1246,7 @@ class Writer {
|
|
|
1246
1246
|
* Renders an element to Markdown a step at a time, as a render of markup
|
|
1247
1247
|
* steps through its chunks, so neither waits unless the element does.
|
|
1248
1248
|
*/
|
|
1249
|
-
class Blocks {
|
|
1249
|
+
export class Blocks {
|
|
1250
1250
|
/** Render of the element's chunks */
|
|
1251
1251
|
#render;
|
|
1252
1252
|
/** Writes Markdown from the chunks */
|
|
@@ -1285,76 +1285,9 @@ class Blocks {
|
|
|
1285
1285
|
}
|
|
1286
1286
|
}
|
|
1287
1287
|
/**
|
|
1288
|
-
*
|
|
1289
|
-
*
|
|
1290
|
-
* `Render.markdown`. Each top level block is
|
|
1291
|
-
* written as soon as it closes, and when the page has a `<main>` element, only
|
|
1292
|
-
* its contents are kept. Raw HTML is written as it is.
|
|
1293
|
-
*
|
|
1294
|
-
* ```tsx
|
|
1295
|
-
* const markdown = await Render.markdown(<Post post={post} />, { base: url }).string();
|
|
1296
|
-
* ```
|
|
1288
|
+
* @param text Plain text
|
|
1289
|
+
* @returns The text escaped, to write in Markdown as it is
|
|
1297
1290
|
*/
|
|
1298
|
-
export
|
|
1299
|
-
|
|
1300
|
-
* @param text Plain text
|
|
1301
|
-
* @returns The text escaped, to write in Markdown as it is
|
|
1302
|
-
*/
|
|
1303
|
-
static escape(text) {
|
|
1304
|
-
return Writer.escape(text);
|
|
1305
|
-
}
|
|
1306
|
-
/** Element to render */
|
|
1307
|
-
#element;
|
|
1308
|
-
/** Markdown options */
|
|
1309
|
-
#options;
|
|
1310
|
-
/**
|
|
1311
|
-
* Creates an `AsyncIterable` that renders the element to Markdown.
|
|
1312
|
-
*
|
|
1313
|
-
* @param element Element to render
|
|
1314
|
-
* @param options Markdown options
|
|
1315
|
-
*/
|
|
1316
|
-
constructor(element, options) {
|
|
1317
|
-
this.#element = element;
|
|
1318
|
-
this.#options = options;
|
|
1319
|
-
}
|
|
1320
|
-
/** @yields Markdown as each block completes */
|
|
1321
|
-
async *[Symbol.asyncIterator]() {
|
|
1322
|
-
const blocks = new Blocks(this.#element, this.#options);
|
|
1323
|
-
try {
|
|
1324
|
-
for (let result; (result = blocks.step());) {
|
|
1325
|
-
if (typeof result === "string")
|
|
1326
|
-
yield result;
|
|
1327
|
-
else
|
|
1328
|
-
await result;
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
finally {
|
|
1332
|
-
await blocks.close();
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
/** @returns `ReadableStream` of Markdown */
|
|
1336
|
-
stream() {
|
|
1337
|
-
return readable(new Blocks(this.#element, this.#options));
|
|
1338
|
-
}
|
|
1339
|
-
/**
|
|
1340
|
-
* The whole render as one string.
|
|
1341
|
-
*
|
|
1342
|
-
* @returns Concatenated Markdown
|
|
1343
|
-
*/
|
|
1344
|
-
async string() {
|
|
1345
|
-
const blocks = new Blocks(this.#element, this.#options);
|
|
1346
|
-
let markdown = "";
|
|
1347
|
-
try {
|
|
1348
|
-
for (let result; (result = blocks.step());) {
|
|
1349
|
-
if (typeof result === "string")
|
|
1350
|
-
markdown += result;
|
|
1351
|
-
else
|
|
1352
|
-
await result;
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
finally {
|
|
1356
|
-
await blocks.close();
|
|
1357
|
-
}
|
|
1358
|
-
return markdown;
|
|
1359
|
-
}
|
|
1291
|
+
export function escape(text) {
|
|
1292
|
+
return Writer.escape(text);
|
|
1360
1293
|
}
|
package/dist/markup/index.d.ts
CHANGED
|
@@ -86,8 +86,8 @@ export declare class Element implements AsyncGenerator<Chunk, void, unknown> {
|
|
|
86
86
|
[Symbol.asyncIterator](): this;
|
|
87
87
|
[Symbol.asyncDispose](): Promise<void>;
|
|
88
88
|
}
|
|
89
|
-
/** Internal protocol for a render, to read the element
|
|
90
|
-
declare const source: unique symbol;
|
|
89
|
+
/** Internal protocol for a render, to read the element it renders. */
|
|
90
|
+
export declare const source: unique symbol;
|
|
91
91
|
/** One step of a render: a chunk, a wait before the next step, or nothing once it is done */
|
|
92
92
|
export type Step = Chunk | Promise<unknown> | undefined;
|
|
93
93
|
/**
|
|
@@ -129,56 +129,12 @@ export declare const readable: (render: {
|
|
|
129
129
|
step(): Chunk | string | Promise<unknown> | undefined;
|
|
130
130
|
close(): Promise<unknown>;
|
|
131
131
|
}) => ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
132
|
-
export declare namespace Markup {
|
|
133
|
-
/** Markup options */
|
|
134
|
-
type Options = {
|
|
135
|
-
/** Set to `true` to disable escaping, for content that is not markup */
|
|
136
|
-
raw?: boolean;
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
132
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
133
|
+
* Escapes text for markup.
|
|
134
|
+
*
|
|
135
|
+
* @param text Text to escape
|
|
136
|
+
* @param attr Set to `true` if the value is an attribute, otherwise it is content
|
|
137
|
+
* @returns Escaped text
|
|
143
138
|
*/
|
|
144
|
-
export declare
|
|
145
|
-
#private;
|
|
146
|
-
/**
|
|
147
|
-
* Creates an `AsyncIterable` that renders the `Element`.
|
|
148
|
-
*
|
|
149
|
-
* @param element Element to render
|
|
150
|
-
* @param options Markup options
|
|
151
|
-
*/
|
|
152
|
-
constructor(element: JSX.Element, options?: Markup.Options);
|
|
153
|
-
/** @returns The element, rendered in place where a `Markup` is a child */
|
|
154
|
-
get [source](): JSX.Element;
|
|
155
|
-
/** @yields Markup as the `Element` resolves */
|
|
156
|
-
[Symbol.asyncIterator](): AsyncGenerator<string, void, unknown>;
|
|
157
|
-
/**
|
|
158
|
-
* The render piped into a `ReadableStream`. Iterate it when possible, to
|
|
159
|
-
* avoid the overhead of the stream.
|
|
160
|
-
*
|
|
161
|
-
* @returns `ReadableStream` of markup
|
|
162
|
-
*/
|
|
163
|
-
stream(): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
164
|
-
/**
|
|
165
|
-
* The whole render as one string.
|
|
166
|
-
*
|
|
167
|
-
* ### WARNING
|
|
168
|
-
*
|
|
169
|
-
* This negates streaming benefits and buffers the result into a string.
|
|
170
|
-
*
|
|
171
|
-
* @returns Concatenated markup
|
|
172
|
-
*/
|
|
173
|
-
string(): Promise<string>;
|
|
174
|
-
/**
|
|
175
|
-
* Escapes text for markup.
|
|
176
|
-
*
|
|
177
|
-
* @param html String to escape
|
|
178
|
-
* @param attr Set to `true` if the value is an attribute, otherwise it is content
|
|
179
|
-
* @returns Escaped text
|
|
180
|
-
*/
|
|
181
|
-
static escape(html: string, attr?: boolean): string;
|
|
182
|
-
}
|
|
183
|
-
export {};
|
|
139
|
+
export declare function escape(text: string, attr?: boolean): string;
|
|
184
140
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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AAC,wCAErC;IAED,KAAK,CAAC,KAAK,EAAE,OAAO,wCAEnB;IAED,CAAC,MAAM,CAAC,aAAa,CAAC,SAErB;IAEK,CAAC,MAAM,CAAC,YAAY,CAAC,kBAE1B;CACD;AAED,sEAAsE;AACtE,eAAO,MAAM,MAAM,eAAmB,CAAC;AAEvC,6FAA6F;AAC7F,MAAM,MAAM,IAAI,GAAG,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;AAQxD;;;;GAIG;AACH,qBAAa,QAAQ;;IACpB,uEAAuE;IACvE,KAAK,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC;IAE3B,4CAA4C;IAC5C,OAAO,UAAS;IAEhB,2DAA2D;IAC3D,IAAI,UAAS;IAiBb;;;OAGG;IACH,YAAY,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,SAAS,EAGrD;IAED;;;OAGG;IACH,IAAI,IAAI,IAAI,CAgJX;IAED;;;OAGG;IACG,KAAK,kBAqBV;CACD;AA0MD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,WAAY;IAChC,IAAI,IAAI,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IACtD,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B,gDA0EA,CAAC;AAeF;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,UAElD"}
|
package/dist/markup/index.js
CHANGED
|
@@ -19,7 +19,7 @@ export class Chunk {
|
|
|
19
19
|
* @returns Safe markup to render
|
|
20
20
|
*/
|
|
21
21
|
toString() {
|
|
22
|
-
return this.raw ? this.value :
|
|
22
|
+
return this.raw ? this.value : escape(this.value);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
@@ -61,7 +61,7 @@ export class Tag extends Chunk {
|
|
|
61
61
|
opening += ` ${key}`;
|
|
62
62
|
}
|
|
63
63
|
else if (typeof value === "string") {
|
|
64
|
-
opening += ` ${key}="${
|
|
64
|
+
opening += ` ${key}="${escape(value, true)}"`;
|
|
65
65
|
}
|
|
66
66
|
else if (typeof value === "number" || typeof value === "bigint") {
|
|
67
67
|
opening += ` ${key}="${value}"`;
|
|
@@ -197,8 +197,8 @@ export class Element {
|
|
|
197
197
|
await this.return();
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
-
/** Internal protocol for a render, to read the element
|
|
201
|
-
const source = Symbol("source");
|
|
200
|
+
/** Internal protocol for a render, to read the element it renders. */
|
|
201
|
+
export const source = Symbol("source");
|
|
202
202
|
/**
|
|
203
203
|
* Renders an element one chunk at a time, internal to ovr. A step is
|
|
204
204
|
* synchronous unless the element has to be waited for, so nested elements cost
|
|
@@ -286,8 +286,9 @@ export class Renderer {
|
|
|
286
286
|
}
|
|
287
287
|
return new Tag(tag, props, closed);
|
|
288
288
|
}
|
|
289
|
-
if (
|
|
290
|
-
// its element, which its strings would
|
|
289
|
+
if (source in element) {
|
|
290
|
+
// a render as a child: its element, which its strings would
|
|
291
|
+
// be escaped as text
|
|
291
292
|
this.#element = element[source];
|
|
292
293
|
this.#next = 1;
|
|
293
294
|
continue;
|
|
@@ -625,96 +626,23 @@ export const readable = (render) => {
|
|
|
625
626
|
},
|
|
626
627
|
}, { highWaterMark });
|
|
627
628
|
};
|
|
629
|
+
/** Regex to find escape character for attributes */
|
|
630
|
+
const attribute = /[&"<]/g;
|
|
631
|
+
/** Regex to find escape character for content */
|
|
632
|
+
const content = /[&<]/g;
|
|
633
|
+
/** Escape character map */
|
|
634
|
+
const entities = {
|
|
635
|
+
"&": "&",
|
|
636
|
+
'"': """,
|
|
637
|
+
"<": "<",
|
|
638
|
+
};
|
|
628
639
|
/**
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
640
|
+
* Escapes text for markup.
|
|
641
|
+
*
|
|
642
|
+
* @param text Text to escape
|
|
643
|
+
* @param attr Set to `true` if the value is an attribute, otherwise it is content
|
|
644
|
+
* @returns Escaped text
|
|
632
645
|
*/
|
|
633
|
-
export
|
|
634
|
-
|
|
635
|
-
static #attr = /[&"<]/g;
|
|
636
|
-
/** Regex to find escape character for content */
|
|
637
|
-
static #content = /[&<]/g;
|
|
638
|
-
/** Escape character map */
|
|
639
|
-
static #map = { "&": "&", '"': """, "<": "<" };
|
|
640
|
-
/** Element to render */
|
|
641
|
-
#element;
|
|
642
|
-
/** Markup options */
|
|
643
|
-
#options;
|
|
644
|
-
/**
|
|
645
|
-
* Creates an `AsyncIterable` that renders the `Element`.
|
|
646
|
-
*
|
|
647
|
-
* @param element Element to render
|
|
648
|
-
* @param options Markup options
|
|
649
|
-
*/
|
|
650
|
-
constructor(element, options) {
|
|
651
|
-
this.#element = element;
|
|
652
|
-
this.#options = options;
|
|
653
|
-
}
|
|
654
|
-
/** @returns The element, rendered in place where a `Markup` is a child */
|
|
655
|
-
get [source]() {
|
|
656
|
-
return this.#element;
|
|
657
|
-
}
|
|
658
|
-
/** @yields Markup as the `Element` resolves */
|
|
659
|
-
async *[Symbol.asyncIterator]() {
|
|
660
|
-
const render = new Renderer(this.#element, this.#options?.raw);
|
|
661
|
-
try {
|
|
662
|
-
for (let result; (result = render.step());) {
|
|
663
|
-
if (result instanceof Chunk)
|
|
664
|
-
yield result.toString();
|
|
665
|
-
else
|
|
666
|
-
await result;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
finally {
|
|
670
|
-
await render.close();
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* The render piped into a `ReadableStream`. Iterate it when possible, to
|
|
675
|
-
* avoid the overhead of the stream.
|
|
676
|
-
*
|
|
677
|
-
* @returns `ReadableStream` of markup
|
|
678
|
-
*/
|
|
679
|
-
stream() {
|
|
680
|
-
return readable(new Renderer(this.#element, this.#options?.raw));
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* The whole render as one string.
|
|
684
|
-
*
|
|
685
|
-
* ### WARNING
|
|
686
|
-
*
|
|
687
|
-
* This negates streaming benefits and buffers the result into a string.
|
|
688
|
-
*
|
|
689
|
-
* @returns Concatenated markup
|
|
690
|
-
*/
|
|
691
|
-
async string() {
|
|
692
|
-
const render = new Renderer(this.#element, this.#options?.raw);
|
|
693
|
-
const chunks = [];
|
|
694
|
-
try {
|
|
695
|
-
for (let result; (result = render.step());) {
|
|
696
|
-
if (result instanceof Chunk)
|
|
697
|
-
chunks.push(result);
|
|
698
|
-
else
|
|
699
|
-
await result;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
finally {
|
|
703
|
-
await render.close();
|
|
704
|
-
}
|
|
705
|
-
// written once every chunk is rendered, as a group of them is
|
|
706
|
-
return new Group(chunks).toString();
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* Escapes text for markup.
|
|
710
|
-
*
|
|
711
|
-
* @param html String to escape
|
|
712
|
-
* @param attr Set to `true` if the value is an attribute, otherwise it is content
|
|
713
|
-
* @returns Escaped text
|
|
714
|
-
*/
|
|
715
|
-
static escape(html, attr) {
|
|
716
|
-
return html.replace(attr ? Markup.#attr : Markup.#content, (c) =>
|
|
717
|
-
// @ts-expect-error - private method type error
|
|
718
|
-
Markup.#map[c]);
|
|
719
|
-
}
|
|
646
|
+
export function escape(text, attr) {
|
|
647
|
+
return text.replace(attr ? attribute : content, (c) => entities[c]);
|
|
720
648
|
}
|