@snackbit/opendil 0.0.0 → 0.2.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/LICENSE +201 -0
- package/README.md +137 -2
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/bin/opendil.mjs +75 -0
- package/bin/publish-directory.d.mts +18 -0
- package/bin/publish-directory.mjs +188 -0
- package/dist/agent-spec.js +9 -0
- package/dist/chunk-RPZW4WVX.js +2 -0
- package/dist/chunk-ZSTXLIS6.js +2 -0
- package/dist/index.js +2 -0
- package/dist/mermaid-diagram-GFWD4Y2X.js +2 -0
- package/dist/runtime/frame.html +2435 -0
- package/dist/runtime/frame.js +4621 -0
- package/dist/spec/genui.agent.full.md +1927 -0
- package/dist/spec/genui.agent.md +479 -0
- package/dist/spec/genui.examples.md +836 -0
- package/dist/styled-renderer-PHI4MNPF.js +2441 -0
- package/dist/styles.css +2434 -0
- package/dist/types/agent-spec.d.ts +12 -0
- package/dist/types/components/ui/controls/button.d.ts +10 -0
- package/dist/types/components/ui/controls/checkbox.d.ts +4 -0
- package/dist/types/components/ui/controls/input.d.ts +3 -0
- package/dist/types/components/ui/controls/radio-group.d.ts +5 -0
- package/dist/types/components/ui/controls/select.d.ts +14 -0
- package/dist/types/components/ui/controls/slider.d.ts +4 -0
- package/dist/types/components/ui/controls/tabs.d.ts +7 -0
- package/dist/types/components/ui/controls/textarea.d.ts +3 -0
- package/dist/types/components/ui/controls/toggle-group.d.ts +10 -0
- package/dist/types/components/ui/controls/toggle.d.ts +9 -0
- package/dist/types/components/ui/display/badge.d.ts +9 -0
- package/dist/types/components/ui/display/card.d.ts +9 -0
- package/dist/types/components/ui/display/chart.d.ts +39 -0
- package/dist/types/components/ui/display/separator.d.ts +4 -0
- package/dist/types/components/ui/display/skeleton.d.ts +2 -0
- package/dist/types/components/ui/display/table.d.ts +10 -0
- package/dist/types/components/ui/media/carousel.d.ts +19 -0
- package/dist/types/components/ui/overlays/collapsible.d.ts +6 -0
- package/dist/types/components/ui/overlays/popover.d.ts +11 -0
- package/dist/types/components/ui/overlays/tooltip.d.ts +8 -0
- package/dist/types/components/ui/overlays/ui-scope.d.ts +27 -0
- package/dist/types/dil/custom-component.d.ts +14 -0
- package/dist/types/dil/customization.d.ts +21 -0
- package/dist/types/dil/dil-renderer.d.ts +90 -0
- package/dist/types/dil/isolation/frame-startup.d.ts +18 -0
- package/dist/types/dil/isolation/frame-theme.d.ts +14 -0
- package/dist/types/dil/isolation/frame-viewport.d.ts +30 -0
- package/dist/types/dil/isolation/frame.d.ts +1 -0
- package/dist/types/dil/isolation/isolated-renderer.d.ts +28 -0
- package/dist/types/dil/isolation/overlay-room.d.ts +29 -0
- package/dist/types/dil/isolation/shadow-renderer.d.ts +7 -0
- package/dist/types/dil/isolation/shadow-styles.d.ts +2 -0
- package/dist/types/dil/isolation/viewport-scroll.d.ts +7 -0
- package/dist/types/dil/isolation/vm-worker.d.ts +1 -0
- package/dist/types/dil/message-renderer.d.ts +17 -0
- package/dist/types/dil/parser/dil-parser.d.ts +74 -0
- package/dist/types/dil/parser/lexical.d.ts +27 -0
- package/dist/types/dil/parser/literal-tag.d.ts +16 -0
- package/dist/types/dil/parser/markdown-lexing.d.ts +41 -0
- package/dist/types/dil/parser/stream-worker.d.ts +1 -0
- package/dist/types/dil/parser/types.d.ts +53 -0
- package/dist/types/dil/parser/unfinished.d.ts +22 -0
- package/dist/types/dil/parser/vocabulary.d.ts +12 -0
- package/dist/types/dil/render-error.d.ts +47 -0
- package/dist/types/dil/renderer-environment.d.ts +33 -0
- package/dist/types/dil/renderer-handle.d.ts +4 -0
- package/dist/types/dil/runtime/action-receipt.d.ts +5 -0
- package/dist/types/dil/runtime/child-list.d.ts +8 -0
- package/dist/types/dil/runtime/document.d.ts +54 -0
- package/dist/types/dil/runtime/evaluation-cache.d.ts +24 -0
- package/dist/types/dil/runtime/execution-queue.d.ts +56 -0
- package/dist/types/dil/runtime/expressions.d.ts +62 -0
- package/dist/types/dil/runtime/inline-worker.d.ts +33 -0
- package/dist/types/dil/runtime/markdown-stream.d.ts +17 -0
- package/dist/types/dil/runtime/presentation-history.d.ts +14 -0
- package/dist/types/dil/runtime/presentation-scheduler.d.ts +16 -0
- package/dist/types/dil/runtime/render-budget.d.ts +10 -0
- package/dist/types/dil/runtime/view-cost.d.ts +10 -0
- package/dist/types/dil/styled-renderer.d.ts +39 -0
- package/dist/types/dil/view/conditional-view.d.ts +12 -0
- package/dist/types/dil/view/loading-block.d.ts +7 -0
- package/dist/types/dil/view/markdown-node.d.ts +12 -0
- package/dist/types/dil/view/node-children.d.ts +13 -0
- package/dist/types/dil/view/node-view.d.ts +11 -0
- package/dist/types/dil/view/progressive-reveal.d.ts +7 -0
- package/dist/types/dil/view/render-boundary.d.ts +35 -0
- package/dist/types/dil/view/render-limit.d.ts +14 -0
- package/dist/types/dil/view/repeated-nodes.d.ts +15 -0
- package/dist/types/dil/view/reveal/controller.d.ts +32 -0
- package/dist/types/dil/view/reveal/presentation.d.ts +13 -0
- package/dist/types/dil/view/reveal-options.d.ts +11 -0
- package/dist/types/dil/view/scroll/controller.d.ts +42 -0
- package/dist/types/dil/view/scroll/host-viewport.d.ts +24 -0
- package/dist/types/dil/view/scroll/root-tracker.d.ts +17 -0
- package/dist/types/dil/view/scroll/scroll-root.d.ts +36 -0
- package/dist/types/dil/view/scroll-options.d.ts +25 -0
- package/dist/types/dil/view/stream-follow.d.ts +15 -0
- package/dist/types/dil/view/table-context.d.ts +15 -0
- package/dist/types/dil/view/virtual-flow.d.ts +15 -0
- package/dist/types/dil/widgets/action-feedback.d.ts +11 -0
- package/dist/types/dil/widgets/async-image.d.ts +6 -0
- package/dist/types/dil/widgets/charts/chart-hover.d.ts +17 -0
- package/dist/types/dil/widgets/charts/chart-legend.d.ts +10 -0
- package/dist/types/dil/widgets/charts/chart-pie.d.ts +16 -0
- package/dist/types/dil/widgets/charts/chart-selection.d.ts +8 -0
- package/dist/types/dil/widgets/charts/chart-series.d.ts +19 -0
- package/dist/types/dil/widgets/charts/chart-snapping.d.ts +13 -0
- package/dist/types/dil/widgets/charts/dil-chart.d.ts +5 -0
- package/dist/types/dil/widgets/charts/snap-cursor.d.ts +12 -0
- package/dist/types/dil/widgets/charts/snap-tooltip.d.ts +12 -0
- package/dist/types/dil/widgets/code/code-editor.d.ts +9 -0
- package/dist/types/dil/widgets/code/highlighted-code.d.ts +25 -0
- package/dist/types/dil/widgets/code-block.d.ts +11 -0
- package/dist/types/dil/widgets/control-revision.d.ts +1 -0
- package/dist/types/dil/widgets/control-state.d.ts +8 -0
- package/dist/types/dil/widgets/controls.d.ts +25 -0
- package/dist/types/dil/widgets/graphs/graph-model.d.ts +13 -0
- package/dist/types/dil/widgets/graphs/node-graph.d.ts +6 -0
- package/dist/types/dil/widgets/graphs/service-node.d.ts +3 -0
- package/dist/types/dil/widgets/mermaid-diagram.d.ts +5 -0
- package/dist/types/dil/widgets/primitives/attribute-values.d.ts +12 -0
- package/dist/types/dil/widgets/primitives/primitive.d.ts +17 -0
- package/dist/types/dil/widgets/primitives/vocabulary.d.ts +5 -0
- package/dist/types/dil/widgets/use-control-value.d.ts +2 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/lib/cn.d.ts +2 -0
- package/dist/types/ui.d.ts +11 -0
- package/dist/ui.js +2 -0
- package/package.json +85 -4
- package/styles/tailwind.css +443 -0
- package/styles/tokens.css +32 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { DilNode, TreeBatch } from "./types.js";
|
|
2
|
+
export interface DilParserOptions {
|
|
3
|
+
/** Host-registered component names; lowercase ones become DIL tags. */
|
|
4
|
+
components?: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Append-only parser. Closed tokens are never scanned again. Text inside an
|
|
8
|
+
* unclosed code span is held back until its closing backticks arrive; if its
|
|
9
|
+
* block ends first, only the text since the opener is scanned again as prose.
|
|
10
|
+
*/
|
|
11
|
+
export declare class DilParser {
|
|
12
|
+
private source;
|
|
13
|
+
private cursor;
|
|
14
|
+
private textStart;
|
|
15
|
+
private tokenStart;
|
|
16
|
+
private mode;
|
|
17
|
+
private lexical;
|
|
18
|
+
private fence;
|
|
19
|
+
/** The open code span; lineBreak is set while only blanks follow a line feed. */
|
|
20
|
+
private span;
|
|
21
|
+
/** Code span opener lengths that have no closer before `until`. */
|
|
22
|
+
private unmatched;
|
|
23
|
+
/** Where the current Markdown block began, after the latest tag or block directive. */
|
|
24
|
+
private blockStart;
|
|
25
|
+
private readonly vocabulary;
|
|
26
|
+
private readonly isComponent;
|
|
27
|
+
private literalTag;
|
|
28
|
+
private readonly memo;
|
|
29
|
+
private tokenNode;
|
|
30
|
+
private nodes;
|
|
31
|
+
private children;
|
|
32
|
+
private stack;
|
|
33
|
+
private dirty;
|
|
34
|
+
private links;
|
|
35
|
+
private declarations;
|
|
36
|
+
private issues;
|
|
37
|
+
private revision;
|
|
38
|
+
constructor(options?: DilParserOptions);
|
|
39
|
+
/** Registers component names for tags that start after this call. */
|
|
40
|
+
allow(components: unknown): void;
|
|
41
|
+
private get parent();
|
|
42
|
+
private closeFrame;
|
|
43
|
+
private create;
|
|
44
|
+
private touch;
|
|
45
|
+
private markdown;
|
|
46
|
+
private flushText;
|
|
47
|
+
private finishMarkdown;
|
|
48
|
+
/** Moves scanned code into the open CodeBlock. */
|
|
49
|
+
private codeText;
|
|
50
|
+
/** At the end of input, drops a cut-off tag; completion reports it. */
|
|
51
|
+
private cutToken;
|
|
52
|
+
private finish;
|
|
53
|
+
private fail;
|
|
54
|
+
/** Open constructs keep what they completed; an unfinished token is dropped. */
|
|
55
|
+
private finishIncomplete;
|
|
56
|
+
/** Returns whether the directive ends the current Markdown block. */
|
|
57
|
+
private directive;
|
|
58
|
+
private tag;
|
|
59
|
+
append(suffix: string, complete?: boolean): TreeBatch;
|
|
60
|
+
private scan;
|
|
61
|
+
/** Advances through a tag or brace token with JavaScript lexical rules. */
|
|
62
|
+
private token;
|
|
63
|
+
private text;
|
|
64
|
+
private openTag;
|
|
65
|
+
private startLiteral;
|
|
66
|
+
/** A literal tag stays text up to its ">", its line end, or a prose brace. */
|
|
67
|
+
private literal;
|
|
68
|
+
private fenced;
|
|
69
|
+
private openSpan;
|
|
70
|
+
private spanned;
|
|
71
|
+
/** The span has no closer in its block: its opener is literal text. */
|
|
72
|
+
private abandonSpan;
|
|
73
|
+
snapshot(): DilNode[];
|
|
74
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Attribute } from "./types.js";
|
|
2
|
+
export declare class LexicalState {
|
|
3
|
+
depth: number;
|
|
4
|
+
quote: string;
|
|
5
|
+
escaped: boolean;
|
|
6
|
+
comment: string;
|
|
7
|
+
regex: boolean;
|
|
8
|
+
characterClass: boolean;
|
|
9
|
+
previous: string;
|
|
10
|
+
templates: number[];
|
|
11
|
+
consume(char: string, next: string): number;
|
|
12
|
+
get neutral(): boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface TagStart {
|
|
15
|
+
name: string;
|
|
16
|
+
closing: boolean;
|
|
17
|
+
/** Offset just past the name. */
|
|
18
|
+
end: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reads the tag name after "<" or "</" at cursor. Returns undefined while a
|
|
22
|
+
* streamed name may still grow, and null when the source is not tag-shaped,
|
|
23
|
+
* such as an autolink, an email address, or a comparison.
|
|
24
|
+
*/
|
|
25
|
+
export declare function tagStart(source: string, cursor: number, complete: boolean): TagStart | null | undefined;
|
|
26
|
+
export declare function braceEnd(source: string, start: number): number;
|
|
27
|
+
export declare function parseAttributes(source: string): Record<string, Attribute>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** An autolink scheme such as "<https:"; tagStart has already rejected it as a tag. */
|
|
2
|
+
export declare const AUTOLINK: RegExp;
|
|
3
|
+
export declare class LiteralTag {
|
|
4
|
+
private readonly autolink;
|
|
5
|
+
/** Whether the run ended with its own ">". */
|
|
6
|
+
closed: boolean;
|
|
7
|
+
private equals;
|
|
8
|
+
private quote;
|
|
9
|
+
private braces;
|
|
10
|
+
constructor(autolink?: boolean);
|
|
11
|
+
/**
|
|
12
|
+
* Returns how many characters at char belong to the literal run, or 0 when
|
|
13
|
+
* the run ends before char. A run never continues past its line.
|
|
14
|
+
*/
|
|
15
|
+
step(char: string, next: string): number;
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const WAIT = -1;
|
|
2
|
+
export interface Fence {
|
|
3
|
+
char: string;
|
|
4
|
+
length: number;
|
|
5
|
+
}
|
|
6
|
+
/** How far a scan starting at `from` has already looked. */
|
|
7
|
+
export interface Reach {
|
|
8
|
+
from: number;
|
|
9
|
+
to: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Unresolved run and line scans. The source only grows, so a scan that waited
|
|
13
|
+
* for more input resumes where it stopped instead of rescanning a long run.
|
|
14
|
+
*/
|
|
15
|
+
export interface ScanMemo {
|
|
16
|
+
run: Reach;
|
|
17
|
+
line: Reach;
|
|
18
|
+
}
|
|
19
|
+
export declare const scanMemo: () => ScanMemo;
|
|
20
|
+
type IsComponent = (name: string) => boolean;
|
|
21
|
+
/** Length of the run of identical characters at cursor. */
|
|
22
|
+
export declare function runLength(source: string, cursor: number, complete: boolean, memo?: ScanMemo): number;
|
|
23
|
+
/**
|
|
24
|
+
* Whether only indentation, list markers, or blockquote markers precede cursor
|
|
25
|
+
* on its line. The current Markdown block may also begin at floor, after a tag.
|
|
26
|
+
*/
|
|
27
|
+
export declare function atBlockStart(source: string, cursor: number, floor: number): boolean;
|
|
28
|
+
/** An opening fence at cursor, null when there is none (CommonMark rules). */
|
|
29
|
+
export declare function openingFence(source: string, cursor: number, floor: number, complete: boolean, memo?: ScanMemo): Fence | null | typeof WAIT;
|
|
30
|
+
/**
|
|
31
|
+
* Length of the closing fence at cursor, or 0 when the line does not close
|
|
32
|
+
* fence. Besides spaces, only a DIL closing tag or block directive may follow it.
|
|
33
|
+
*/
|
|
34
|
+
export declare function closingFence(source: string, cursor: number, fence: Fence, complete: boolean, memo?: ScanMemo, isComponent?: IsComponent): number;
|
|
35
|
+
/**
|
|
36
|
+
* Whether the line whose first non-blank character is at cursor starts a block
|
|
37
|
+
* that a code span cannot continue into: a fence, blockquote, heading, list
|
|
38
|
+
* item, thematic break, DIL block directive, or DIL component tag.
|
|
39
|
+
*/
|
|
40
|
+
export declare function blockLine(source: string, cursor: number, complete: boolean, isComponent: IsComponent): boolean | typeof WAIT;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type NodeKind = "root" | "element" | "markdown" | "if" | "branch" | "each" | "pending";
|
|
2
|
+
/**
|
|
3
|
+
* `incomplete` marks a construct that was still open when the document was
|
|
4
|
+
* finalized: elements keep their completed children, while unfinished opening
|
|
5
|
+
* tags and repeat templates render nothing.
|
|
6
|
+
*/
|
|
7
|
+
export type NodeStatus = "streaming" | "ready" | "incomplete" | "error";
|
|
8
|
+
export interface Attribute {
|
|
9
|
+
expression?: string;
|
|
10
|
+
literal?: string | boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface DilNode {
|
|
13
|
+
id: number;
|
|
14
|
+
kind: NodeKind;
|
|
15
|
+
name: string;
|
|
16
|
+
attributes: Record<string, Attribute>;
|
|
17
|
+
text: string;
|
|
18
|
+
expressions: string[];
|
|
19
|
+
status: NodeStatus;
|
|
20
|
+
offset: number;
|
|
21
|
+
/** Developer-facing reason for an `error` node; readers see generic wording. */
|
|
22
|
+
error: string;
|
|
23
|
+
}
|
|
24
|
+
/** A parse problem reported to the host once, with its source offset. */
|
|
25
|
+
export interface ParseIssue {
|
|
26
|
+
kind: "syntax" | "incomplete";
|
|
27
|
+
message: string;
|
|
28
|
+
offset: number;
|
|
29
|
+
}
|
|
30
|
+
export interface TreeBatch {
|
|
31
|
+
revision: number;
|
|
32
|
+
nodes: DilNode[];
|
|
33
|
+
links: {
|
|
34
|
+
parent: number;
|
|
35
|
+
child: number;
|
|
36
|
+
}[];
|
|
37
|
+
declarations: string[];
|
|
38
|
+
issues: ParseIssue[];
|
|
39
|
+
complete: boolean;
|
|
40
|
+
scanned: number;
|
|
41
|
+
}
|
|
42
|
+
/** The parser's last reply when a message exceeds its node limit. */
|
|
43
|
+
export interface ParserStop {
|
|
44
|
+
stopped: "limit";
|
|
45
|
+
message: string;
|
|
46
|
+
}
|
|
47
|
+
export type ParserReply = TreeBatch | ParserStop;
|
|
48
|
+
export interface StreamInput {
|
|
49
|
+
suffix: string;
|
|
50
|
+
complete: boolean;
|
|
51
|
+
/** Host-registered component names, sent when they change. */
|
|
52
|
+
components?: readonly string[];
|
|
53
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DilNode, ParseIssue } from "./types.js";
|
|
2
|
+
import type { TagVocabulary } from "./vocabulary.js";
|
|
3
|
+
/** A tag or brace token that the end of the document cut off. */
|
|
4
|
+
export interface CutToken {
|
|
5
|
+
source: string;
|
|
6
|
+
mode: "brace" | "tag";
|
|
7
|
+
offset: number;
|
|
8
|
+
/** The node an unfinished opening tag of a known component created. */
|
|
9
|
+
pending: DilNode | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Marks the open constructs (outermost first) and the cut token's pending node
|
|
13
|
+
* incomplete, so they keep what they completed, and returns one
|
|
14
|
+
* developer-facing report that lists them.
|
|
15
|
+
*/
|
|
16
|
+
export declare function finishOpen(open: readonly DilNode[], token: CutToken | undefined): ParseIssue | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the rest of a finalized source is a cut-off tag: a strict prefix of
|
|
19
|
+
* the open element's closing tag, a lone "<", or "<" and the start of a
|
|
20
|
+
* component name that is not a name by itself.
|
|
21
|
+
*/
|
|
22
|
+
export declare function cutTag(rest: string, open: string | undefined, vocabulary: TagVocabulary): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const TAG_NAME: RegExp;
|
|
2
|
+
export declare class TagVocabulary {
|
|
3
|
+
private readonly names;
|
|
4
|
+
private custom;
|
|
5
|
+
static stock(): readonly string[];
|
|
6
|
+
/** Adds host-registered component names; malformed entries are ignored. */
|
|
7
|
+
allow(names: unknown): void;
|
|
8
|
+
/** Capitalized names are components; lowercase names must be registered. */
|
|
9
|
+
isComponent(name: string): boolean;
|
|
10
|
+
/** Whether some component name starts with this lowercase prefix. */
|
|
11
|
+
startsName(prefix: string): boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What went wrong:
|
|
3
|
+
* - `incomplete`: the document was finalized with unfinished structure, for
|
|
4
|
+
* example because the reader stopped the response, the model reached its
|
|
5
|
+
* output limit, or the stream failed.
|
|
6
|
+
* - `syntax`: the source contains malformed DIL or names a component that is
|
|
7
|
+
* neither a stock component nor one passed in `components`.
|
|
8
|
+
* - `runtime`: the parser, the expression runtime, or the iframe runtime
|
|
9
|
+
* failed, was blocked by the page's security policy, or a declaration failed;
|
|
10
|
+
* or, once the message is final, an expression could not be evaluated or a
|
|
11
|
+
* component failed to render.
|
|
12
|
+
* - `limit`: a size, display, or execution limit stopped the message.
|
|
13
|
+
* - `source`: `text` changed in an unsupported way, such as being replaced or
|
|
14
|
+
* growing after the message was finalized.
|
|
15
|
+
*/
|
|
16
|
+
export type DilRenderErrorKind = "incomplete" | "syntax" | "runtime" | "limit" | "source";
|
|
17
|
+
export interface DilRenderError {
|
|
18
|
+
kind: DilRenderErrorKind;
|
|
19
|
+
/** Developer-facing description. Readers see shorter wording. */
|
|
20
|
+
message: string;
|
|
21
|
+
/** Position in `text`, in UTF-16 code units, when the error has one. */
|
|
22
|
+
offset?: number;
|
|
23
|
+
}
|
|
24
|
+
/** Reader-facing wording for a part of the message that cannot be shown. */
|
|
25
|
+
export declare const UNSHOWN_PART_MESSAGE = "This part of the response couldn't be shown.";
|
|
26
|
+
/** Problems reported for one message before the rest are summarized. */
|
|
27
|
+
export declare const MAX_REPORTED_PROBLEMS = 20;
|
|
28
|
+
export declare const UNREPORTED_PROBLEMS = "This message has more than 20 problems; later ones are not reported.";
|
|
29
|
+
/**
|
|
30
|
+
* Decides what reaches `onError` for one message: each distinct problem once,
|
|
31
|
+
* at most MAX_REPORTED_PROBLEMS of them followed by one `limit` notice, and
|
|
32
|
+
* the end-of-document report once. Messages are bounded in every mode.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ProblemReports {
|
|
35
|
+
private readonly seen;
|
|
36
|
+
private count;
|
|
37
|
+
private ended;
|
|
38
|
+
/** Returns the error to report for this problem, or undefined to drop it. */
|
|
39
|
+
take(problem: DilRenderError): DilRenderError | undefined;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Calls the host's handler. An exception it throws must not interrupt
|
|
43
|
+
* rendering, so it is rethrown asynchronously, like an event handler's.
|
|
44
|
+
*/
|
|
45
|
+
export declare function deliverError(onError: ((error: DilRenderError) => void) | undefined, error: DilRenderError): void;
|
|
46
|
+
/** Validates an error received from the iframe runtime. */
|
|
47
|
+
export declare function readRenderError(value: unknown): DilRenderError | undefined;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DilRenderError } from "./render-error.js";
|
|
2
|
+
/**
|
|
3
|
+
* The visible part of a renderer's scroller. Offsets are measured from the
|
|
4
|
+
* renderer's top, so layout around the renderer does not move its content.
|
|
5
|
+
*/
|
|
6
|
+
export interface RendererViewport {
|
|
7
|
+
/** Distance from the renderer's top to the top of the visible area. */
|
|
8
|
+
readonly offset: number;
|
|
9
|
+
readonly height: number;
|
|
10
|
+
readonly width: number;
|
|
11
|
+
/** The renderer's top in client coordinates, the origin of `offset`. */
|
|
12
|
+
origin(): number;
|
|
13
|
+
subscribe(listener: () => void): () => void;
|
|
14
|
+
/** Scrolls until `offset` is at the top of the visible area. */
|
|
15
|
+
scrollTo(offset: number): void;
|
|
16
|
+
}
|
|
17
|
+
export interface RendererMetrics {
|
|
18
|
+
scanned: number;
|
|
19
|
+
complete: boolean;
|
|
20
|
+
/** The document was finalized while some of its structure was still open. */
|
|
21
|
+
incomplete: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface RendererEnvironment {
|
|
24
|
+
viewport?: RendererViewport;
|
|
25
|
+
copy?: (text: string) => Promise<boolean>;
|
|
26
|
+
onInput?: (detail: {
|
|
27
|
+
length: number;
|
|
28
|
+
}) => void;
|
|
29
|
+
onCommit?: (detail: RendererMetrics) => void;
|
|
30
|
+
onError?: (error: DilRenderError) => void;
|
|
31
|
+
}
|
|
32
|
+
export declare const RendererEnvironmentContext: import("react").Context<RendererEnvironment>;
|
|
33
|
+
export declare function useRendererEnvironment(): RendererEnvironment;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type StoreApi } from "zustand/vanilla";
|
|
2
|
+
import type { DilNode, TreeBatch } from "../parser/types.js";
|
|
3
|
+
import { ChildList } from "./child-list.js";
|
|
4
|
+
import { ExpressionEngine, type Scope } from "./expressions.js";
|
|
5
|
+
import { RenderBudget } from "./render-budget.js";
|
|
6
|
+
import { PresentationHistory } from "./presentation-history.js";
|
|
7
|
+
import { PresentationScheduler } from "./presentation-scheduler.js";
|
|
8
|
+
import { type DilRenderError } from "../render-error.js";
|
|
9
|
+
export interface NodeState {
|
|
10
|
+
node: DilNode;
|
|
11
|
+
children: ChildList;
|
|
12
|
+
}
|
|
13
|
+
export interface DocumentStatus {
|
|
14
|
+
complete: boolean;
|
|
15
|
+
/** The document was finalized while some of its structure was still open. */
|
|
16
|
+
incomplete: boolean;
|
|
17
|
+
revision: number;
|
|
18
|
+
scanned: number;
|
|
19
|
+
error: string;
|
|
20
|
+
/** Latest clipboard outcome, keyed by the intent of the action that requested it. */
|
|
21
|
+
clipboard: {
|
|
22
|
+
intent: number;
|
|
23
|
+
ok: boolean;
|
|
24
|
+
} | null;
|
|
25
|
+
}
|
|
26
|
+
export declare class DilDocument {
|
|
27
|
+
readonly updates: PresentationScheduler;
|
|
28
|
+
readonly presentation: PresentationHistory;
|
|
29
|
+
readonly renderBudget: RenderBudget;
|
|
30
|
+
renderLimited: boolean;
|
|
31
|
+
reportRenderLimit(): void;
|
|
32
|
+
readonly nodes: Map<number, NodeState>;
|
|
33
|
+
private readonly stores;
|
|
34
|
+
private readonly parents;
|
|
35
|
+
private readonly flows;
|
|
36
|
+
readonly status: StoreApi<DocumentStatus>;
|
|
37
|
+
readonly engine: ExpressionEngine;
|
|
38
|
+
readonly drafts: Map<string, string>;
|
|
39
|
+
private readonly reports;
|
|
40
|
+
/**
|
|
41
|
+
* Receives each distinct problem once, within the ProblemReports budget.
|
|
42
|
+
* Problems readers see only generic wording for are also logged.
|
|
43
|
+
*/
|
|
44
|
+
onError: ((error: DilRenderError) => void) | undefined;
|
|
45
|
+
report(problem: DilRenderError): void;
|
|
46
|
+
/** Shows a document-level alert and reports it. */
|
|
47
|
+
fail(error: DilRenderError): void;
|
|
48
|
+
constructor();
|
|
49
|
+
apply(batch: TreeBatch): void;
|
|
50
|
+
private presentedChildren;
|
|
51
|
+
flowChildren(id: number): StoreApi<ChildList>;
|
|
52
|
+
node(id: number): StoreApi<NodeState>;
|
|
53
|
+
attributes(node: DilNode, scope: Scope): Record<string, unknown>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type Scope = Readonly<Record<string, unknown>>;
|
|
2
|
+
export interface EvaluationEntry {
|
|
3
|
+
source: string;
|
|
4
|
+
scope: Scope;
|
|
5
|
+
owners: number;
|
|
6
|
+
oneShot: boolean;
|
|
7
|
+
ready: boolean;
|
|
8
|
+
dirty: boolean;
|
|
9
|
+
value: unknown;
|
|
10
|
+
dependencies?: readonly string[];
|
|
11
|
+
revision: number;
|
|
12
|
+
invalidated: number;
|
|
13
|
+
handles: readonly number[];
|
|
14
|
+
}
|
|
15
|
+
export declare class EvaluationCache {
|
|
16
|
+
readonly entries: Map<string, EvaluationEntry>;
|
|
17
|
+
key(source: string, scope: Scope): string;
|
|
18
|
+
ensure(source: string, scope: Scope): {
|
|
19
|
+
key: string;
|
|
20
|
+
entry: EvaluationEntry;
|
|
21
|
+
};
|
|
22
|
+
touch(key: string): void;
|
|
23
|
+
prune(busy: (key: string) => boolean, evict: (key: string, entry: EvaluationEntry) => void): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface ExecutionReply {
|
|
2
|
+
id: number;
|
|
3
|
+
value?: unknown;
|
|
4
|
+
error?: string;
|
|
5
|
+
changed?: boolean;
|
|
6
|
+
revision?: number;
|
|
7
|
+
dependencies?: string[];
|
|
8
|
+
bindings?: string[];
|
|
9
|
+
handles?: number[];
|
|
10
|
+
copy?: string;
|
|
11
|
+
/** The VM can no longer be trusted; the document must stop. */
|
|
12
|
+
fatal?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Worker replies cross the VM boundary; keep only well-formed fields. */
|
|
15
|
+
export declare function readReply(data: unknown): ExecutionReply | undefined;
|
|
16
|
+
export interface ExecutionJob {
|
|
17
|
+
type: string;
|
|
18
|
+
payload: Record<string, unknown>;
|
|
19
|
+
key?: string;
|
|
20
|
+
setter?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Bounded transport window; waiting evaluations never consume execution deadlines. */
|
|
23
|
+
export declare class ExecutionQueue {
|
|
24
|
+
private readonly post;
|
|
25
|
+
private readonly receive;
|
|
26
|
+
private readonly failure;
|
|
27
|
+
private next;
|
|
28
|
+
private answered;
|
|
29
|
+
private pending;
|
|
30
|
+
private evaluations;
|
|
31
|
+
private activeKeys;
|
|
32
|
+
private mutations;
|
|
33
|
+
private setters;
|
|
34
|
+
private draining;
|
|
35
|
+
private stopped;
|
|
36
|
+
constructor(post: (message: Record<string, unknown>) => void, receive: (job: ExecutionJob, reply: ExecutionReply) => void, failure: (message: string, kind: "runtime" | "limit") => void);
|
|
37
|
+
get stats(): {
|
|
38
|
+
inFlight: number;
|
|
39
|
+
evaluations: number;
|
|
40
|
+
queued: number;
|
|
41
|
+
mutations: number;
|
|
42
|
+
};
|
|
43
|
+
has(key: string): boolean;
|
|
44
|
+
evaluate(key: string, payload: Record<string, unknown>): boolean;
|
|
45
|
+
cancel(key: string): void;
|
|
46
|
+
mutate(job: ExecutionJob): {
|
|
47
|
+
payload: Record<string, unknown>;
|
|
48
|
+
type: string;
|
|
49
|
+
key?: string;
|
|
50
|
+
setter?: string;
|
|
51
|
+
} | undefined;
|
|
52
|
+
reply(data: unknown): void;
|
|
53
|
+
private dispatch;
|
|
54
|
+
private drain;
|
|
55
|
+
stop(): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PresentationScheduler } from "./presentation-scheduler.js";
|
|
2
|
+
import { type Scope } from "./evaluation-cache.js";
|
|
3
|
+
export type { Scope } from "./evaluation-cache.js";
|
|
4
|
+
export interface BindingState {
|
|
5
|
+
values: Record<string, unknown>;
|
|
6
|
+
versions: Record<string, number>;
|
|
7
|
+
catalog: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class EvaluationPending extends Error {
|
|
10
|
+
constructor();
|
|
11
|
+
}
|
|
12
|
+
export declare class ExpressionEngine {
|
|
13
|
+
readonly events: EventTarget;
|
|
14
|
+
private readonly updates;
|
|
15
|
+
readonly store: import("zustand").StoreApi<BindingState>;
|
|
16
|
+
/** Started by the first job, so documents without expressions or state never load QuickJS. */
|
|
17
|
+
private runtime;
|
|
18
|
+
private readonly cache;
|
|
19
|
+
private readonly queue;
|
|
20
|
+
private intent;
|
|
21
|
+
private failed;
|
|
22
|
+
private gestureUntil;
|
|
23
|
+
private handleRefs;
|
|
24
|
+
private released;
|
|
25
|
+
private pendingChanges;
|
|
26
|
+
private urgentKeys;
|
|
27
|
+
compilations: number;
|
|
28
|
+
get stopped(): boolean;
|
|
29
|
+
get stats(): {
|
|
30
|
+
cached: number;
|
|
31
|
+
handles: number;
|
|
32
|
+
inFlight: number;
|
|
33
|
+
evaluations: number;
|
|
34
|
+
queued: number;
|
|
35
|
+
mutations: number;
|
|
36
|
+
};
|
|
37
|
+
markGesture(): void;
|
|
38
|
+
constructor(events?: EventTarget, updates?: PresentationScheduler);
|
|
39
|
+
private start;
|
|
40
|
+
private reference;
|
|
41
|
+
private replaceHandles;
|
|
42
|
+
private retire;
|
|
43
|
+
private notify;
|
|
44
|
+
private fill;
|
|
45
|
+
private receive;
|
|
46
|
+
/** Stops the runtime; a reported halt reaches the document as a dil:error event. */
|
|
47
|
+
halt(reason: string, kind?: "runtime" | "limit", report?: boolean): void;
|
|
48
|
+
dispose(): void;
|
|
49
|
+
/** Committed views own demand; cancelled renders never enqueue worker work. */
|
|
50
|
+
retain(expressions: readonly string[], scope?: Scope): () => void;
|
|
51
|
+
read(source: string, scope?: Scope): unknown;
|
|
52
|
+
hasValue(source: string, scope?: Scope): boolean;
|
|
53
|
+
isFresh(source: string, scope?: Scope): boolean;
|
|
54
|
+
evaluate(source: string, scope?: Scope): unknown;
|
|
55
|
+
private check;
|
|
56
|
+
evaluationRevision(source: string | undefined, scope?: Scope): number;
|
|
57
|
+
signature(expressions: readonly string[], scope: Scope, state: BindingState): string;
|
|
58
|
+
declare(source: string): void;
|
|
59
|
+
private call;
|
|
60
|
+
private decode;
|
|
61
|
+
private revive;
|
|
62
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host and Shadow DOM renderers run the parser and the QuickJS runtime in blob:
|
|
3
|
+
* workers, which inherit the page's Content Security Policy. When that policy
|
|
4
|
+
* blocks them, readers get a plain explanation and developers get the directives
|
|
5
|
+
* to add, instead of a generic crash message.
|
|
6
|
+
*/
|
|
7
|
+
export declare const POLICY_BLOCKED_MESSAGE = "This content can't be displayed because this page's security policy blocks it.";
|
|
8
|
+
export declare const WASM_BLOCKED_MESSAGE = "Interactive parts of this content can't run because this page's security policy blocks them.";
|
|
9
|
+
/** Name of the Trusted Types policy that turns OpenDIL's own blob: URLs into script URLs. */
|
|
10
|
+
export declare const TRUSTED_TYPES_POLICY = "opendil";
|
|
11
|
+
export interface InlineWorkerOptions<Message> {
|
|
12
|
+
/** Names the worker in developer diagnostics. */
|
|
13
|
+
role: string;
|
|
14
|
+
/** Reader-safe message for failures the page policy does not explain. */
|
|
15
|
+
crashMessage: string;
|
|
16
|
+
onMessage: (data: Message) => void;
|
|
17
|
+
/** Receives one reader-safe message when the worker cannot start or stops. */
|
|
18
|
+
onStop: (message: string) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface InlineWorker {
|
|
21
|
+
/** Null when the browser refused to construct the worker. */
|
|
22
|
+
readonly worker: Worker | null;
|
|
23
|
+
/** Terminates the worker without reporting a failure. */
|
|
24
|
+
dispose(): void;
|
|
25
|
+
}
|
|
26
|
+
export declare function startInlineWorker<Message>(source: string, { role, crashMessage, onMessage, onStop }: InlineWorkerOptions<Message>): InlineWorker;
|
|
27
|
+
/** quickjs-emscripten could not instantiate its WebAssembly module (see vm-worker.ts). */
|
|
28
|
+
export declare const RUNTIME_START_FAILURE = "QuickJS failed to start";
|
|
29
|
+
/**
|
|
30
|
+
* Returns a reader-safe message when the page policy forbids WebAssembly
|
|
31
|
+
* compilation, which blob: workers inherit; otherwise undefined.
|
|
32
|
+
*/
|
|
33
|
+
export declare function explainRuntimeStartFailure(): string | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface MarkdownBlock {
|
|
2
|
+
offset: number;
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
export interface MarkdownSnapshot {
|
|
6
|
+
source: string;
|
|
7
|
+
offset: number;
|
|
8
|
+
blocks: readonly MarkdownBlock[];
|
|
9
|
+
complete: boolean;
|
|
10
|
+
trailing?: MarkdownBlock;
|
|
11
|
+
}
|
|
12
|
+
export declare const EMPTY_MARKDOWN: MarkdownSnapshot;
|
|
13
|
+
/** Only the trailing block is reparsed; completed blocks keep their values and keys. */
|
|
14
|
+
export declare function advanceMarkdown(previous: MarkdownSnapshot, source: string, complete: boolean): MarkdownSnapshot;
|
|
15
|
+
export declare function currentMarkdown(snapshot: MarkdownSnapshot): readonly MarkdownBlock[];
|
|
16
|
+
export declare function markdownIndent(source: string): number | undefined;
|
|
17
|
+
export declare function normalizeMarkdown(source: string, indentation: number): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type PresentationPhase = "ready" | "revealing" | "visible";
|
|
2
|
+
/** Logical message state survives view replacement and virtualization. */
|
|
3
|
+
export declare class PresentationHistory {
|
|
4
|
+
private phases;
|
|
5
|
+
private attributes;
|
|
6
|
+
private virtual;
|
|
7
|
+
phase(key: string): PresentationPhase | undefined;
|
|
8
|
+
set(key: string, phase: PresentationPhase): void;
|
|
9
|
+
last(key: string): Record<string, unknown> | undefined;
|
|
10
|
+
remember(key: string, value: Record<string, unknown>): void;
|
|
11
|
+
visited(key: string): boolean;
|
|
12
|
+
visit(key: string): void;
|
|
13
|
+
forget(prefix: string): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type UpdateInterval = "instant" | number;
|
|
2
|
+
export declare function parseUpdateInterval(value: unknown): UpdateInterval;
|
|
3
|
+
/** Latest work per owner, bounded by cadence rather than waiting for a quiet stream. */
|
|
4
|
+
export declare class PresentationScheduler {
|
|
5
|
+
private pending;
|
|
6
|
+
private timer;
|
|
7
|
+
private last;
|
|
8
|
+
private interval;
|
|
9
|
+
private disposed;
|
|
10
|
+
configure(value: UpdateInterval): void;
|
|
11
|
+
enqueue(key: string, task: () => void, urgent?: boolean): void;
|
|
12
|
+
cancel(key: string): void;
|
|
13
|
+
private schedule;
|
|
14
|
+
private flush;
|
|
15
|
+
dispose(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Bounds mounted presentation work, including multiplicative repeated templates. */
|
|
2
|
+
export declare class RenderBudget {
|
|
3
|
+
readonly limit: number;
|
|
4
|
+
private leases;
|
|
5
|
+
private total;
|
|
6
|
+
constructor(limit?: number);
|
|
7
|
+
get used(): number;
|
|
8
|
+
reserve(id: string, cost: number): boolean;
|
|
9
|
+
release(id: string): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DilDocument } from "./document.js";
|
|
2
|
+
import type { Scope } from "./expressions.js";
|
|
3
|
+
export interface CostDocument {
|
|
4
|
+
nodes: DilDocument["nodes"];
|
|
5
|
+
engine: Pick<DilDocument["engine"], "read">;
|
|
6
|
+
attributes: DilDocument["attributes"];
|
|
7
|
+
}
|
|
8
|
+
/** Pure, short-circuiting preflight; unresolved expressions cost a local placeholder. */
|
|
9
|
+
export declare function nodeCost(document: CostDocument, id: number, scope: Scope, svg: boolean, limit: number): number;
|
|
10
|
+
export declare function childrenCost(document: CostDocument, ids: readonly number[], scope: Scope, svg: boolean, limit: number): number;
|