@snackbit/opendil 0.1.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/README.md +74 -137
- package/bin/opendil.mjs +66 -11
- package/bin/publish-directory.d.mts +18 -0
- package/bin/publish-directory.mjs +173 -17
- 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 +1 -10
- package/dist/runtime/frame.html +117 -44
- package/dist/runtime/frame.js +501 -505
- 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 +115 -42
- package/dist/types/agent-spec.d.ts +12 -0
- package/dist/types/components/ui/controls/select.d.ts +14 -0
- package/dist/types/components/ui/controls/tabs.d.ts +7 -0
- package/dist/types/components/ui/controls/toggle-group.d.ts +3 -2
- package/dist/types/components/ui/display/chart.d.ts +6 -12
- package/dist/types/components/ui/media/carousel.d.ts +1 -1
- package/dist/types/components/ui/overlays/collapsible.d.ts +6 -0
- package/dist/types/components/ui/overlays/popover.d.ts +2 -1
- package/dist/types/components/ui/overlays/ui-scope.d.ts +16 -0
- package/dist/types/dil/custom-component.d.ts +1 -1
- package/dist/types/dil/dil-renderer.d.ts +58 -23
- 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/isolated-renderer.d.ts +13 -7
- package/dist/types/dil/isolation/overlay-room.d.ts +29 -0
- package/dist/types/dil/isolation/viewport-scroll.d.ts +3 -2
- package/dist/types/dil/message-renderer.d.ts +6 -5
- package/dist/types/dil/parser/dil-parser.d.ts +44 -3
- package/dist/types/dil/parser/lexical.d.ts +13 -2
- 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/types.d.ts +22 -1
- 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 +19 -8
- package/dist/types/dil/runtime/document.d.ts +18 -6
- package/dist/types/dil/runtime/execution-queue.d.ts +2 -1
- package/dist/types/dil/runtime/expressions.d.ts +8 -5
- package/dist/types/dil/runtime/inline-worker.d.ts +33 -0
- package/dist/types/dil/runtime/view-cost.d.ts +2 -2
- package/dist/types/dil/styled-renderer.d.ts +39 -0
- package/dist/types/dil/view/conditional-view.d.ts +3 -3
- package/dist/types/dil/view/markdown-node.d.ts +3 -3
- package/dist/types/dil/view/node-children.d.ts +3 -3
- package/dist/types/dil/view/node-view.d.ts +2 -2
- package/dist/types/dil/view/progressive-reveal.d.ts +5 -4
- package/dist/types/dil/view/render-boundary.d.ts +13 -0
- package/dist/types/dil/view/render-limit.d.ts +1 -1
- package/dist/types/dil/view/repeated-nodes.d.ts +4 -4
- package/dist/types/dil/view/reveal/controller.d.ts +9 -2
- package/dist/types/dil/view/reveal/presentation.d.ts +1 -1
- package/dist/types/dil/view/scroll/controller.d.ts +16 -2
- 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 +15 -0
- package/dist/types/dil/view/stream-follow.d.ts +10 -3
- package/dist/types/dil/view/table-context.d.ts +1 -1
- package/dist/types/dil/view/virtual-flow.d.ts +3 -3
- package/dist/types/dil/widgets/action-feedback.d.ts +1 -1
- package/dist/types/dil/widgets/charts/chart-hover.d.ts +17 -0
- package/dist/types/dil/widgets/charts/chart-legend.d.ts +1 -1
- package/dist/types/dil/widgets/charts/chart-pie.d.ts +16 -0
- package/dist/types/dil/widgets/charts/chart-series.d.ts +10 -2
- package/dist/types/dil/widgets/charts/chart-snapping.d.ts +3 -5
- package/dist/types/dil/widgets/charts/snap-cursor.d.ts +3 -7
- package/dist/types/dil/widgets/charts/snap-tooltip.d.ts +6 -4
- package/dist/types/dil/widgets/code-block.d.ts +1 -1
- package/dist/types/dil/widgets/controls.d.ts +2 -2
- package/dist/types/dil/widgets/graphs/node-graph.d.ts +1 -1
- package/dist/types/dil/widgets/graphs/service-node.d.ts +1 -1
- package/dist/types/dil/widgets/primitives/primitive.d.ts +4 -4
- package/dist/types/index.d.ts +9 -8
- package/dist/types/ui.d.ts +11 -8
- package/dist/ui.js +1 -1
- package/package.json +13 -2
- package/styles/tailwind.css +53 -1
- package/styles/tokens.css +3 -0
- package/dist/chunk-ZWAN2JCV.js +0 -2
- package/dist/runtime/vm.js +0 -6
- package/dist/shadow-renderer-F25KL3C4.js +0 -2363
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type Ref } from "react";
|
|
2
|
-
import type { DilRendererHandle } from "../renderer-handle";
|
|
3
|
-
import type { RendererMetrics } from "../renderer-environment";
|
|
4
|
-
import type
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
2
|
+
import type { DilRendererHandle } from "../renderer-handle.js";
|
|
3
|
+
import type { RendererMetrics } from "../renderer-environment.js";
|
|
4
|
+
import { type DilRenderError } from "../render-error.js";
|
|
5
|
+
import type { ProgressiveReveal } from "../view/reveal-options.js";
|
|
6
|
+
import type { AutoScroll, ScrollContainer } from "../view/scroll-options.js";
|
|
7
|
+
import type { UpdateInterval } from "../runtime/presentation-scheduler.js";
|
|
8
|
+
import { type Appearance, type ThemeTokens } from "./frame-theme.js";
|
|
7
9
|
export interface IsolatedRendererProps {
|
|
8
10
|
ref?: Ref<DilRendererHandle> | undefined;
|
|
9
11
|
text: string;
|
|
@@ -11,12 +13,16 @@ export interface IsolatedRendererProps {
|
|
|
11
13
|
showStatus?: boolean;
|
|
12
14
|
progressiveReveal?: ProgressiveReveal;
|
|
13
15
|
autoScroll?: AutoScroll;
|
|
16
|
+
scrollContainer?: ScrollContainer | undefined;
|
|
14
17
|
updateInterval?: UpdateInterval;
|
|
15
18
|
onFollowChange?: (following: boolean) => void;
|
|
16
|
-
runtimeBaseUrl?: string;
|
|
19
|
+
runtimeBaseUrl?: string | undefined;
|
|
20
|
+
appearance?: Appearance | undefined;
|
|
21
|
+
tokens?: ThemeTokens | undefined;
|
|
17
22
|
onInput?: (detail: {
|
|
18
23
|
length: number;
|
|
19
24
|
}) => void;
|
|
20
25
|
onCommit?: (detail: RendererMetrics) => void;
|
|
26
|
+
onError?: ((error: DilRenderError) => void) | undefined;
|
|
21
27
|
}
|
|
22
|
-
export declare function IsolatedRenderer({ ref, text, isStreaming, showStatus, progressiveReveal, autoScroll, updateInterval, onFollowChange, runtimeBaseUrl, onInput, onCommit, }: IsolatedRendererProps): import("react").JSX.Element;
|
|
28
|
+
export declare function IsolatedRenderer({ ref, text, isStreaming, showStatus, progressiveReveal, autoScroll, scrollContainer, updateInterval, onFollowChange, runtimeBaseUrl, appearance, tokens, onInput, onCommit, onError, }: IsolatedRendererProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { OverlayRoom } from "../../components/ui/overlays/ui-scope.js";
|
|
2
|
+
/**
|
|
3
|
+
* Decides how far overlays may extend below the frame's bottom. The host grows
|
|
4
|
+
* the content-sized frame to show an overlay that extends past it, but cannot
|
|
5
|
+
* grow it upward, so an overlay that flips above a trigger is clipped at the
|
|
6
|
+
* frame's top.
|
|
7
|
+
*
|
|
8
|
+
* Overlays may use the part of the host's scroller that is visible below the
|
|
9
|
+
* frame, as they would in host mode. When one is clipped at the top anyway, for
|
|
10
|
+
* example in a short frame at the bottom of the scroller, overlays may extend
|
|
11
|
+
* any distance below until all of them close, and the reader can scroll to them.
|
|
12
|
+
*/
|
|
13
|
+
export declare class FrameOverlayRoom implements OverlayRoom {
|
|
14
|
+
private readonly visibleBottom;
|
|
15
|
+
private readonly frameHeight;
|
|
16
|
+
private readonly listeners;
|
|
17
|
+
private room;
|
|
18
|
+
private unbounded;
|
|
19
|
+
/** `visibleBottom` is the bottom of the host's visible area, in frame coordinates. */
|
|
20
|
+
constructor(visibleBottom: () => number, frameHeight: () => number);
|
|
21
|
+
below: () => number;
|
|
22
|
+
subscribe: (listener: () => void) => () => void;
|
|
23
|
+
/** Recomputes the room after the visible area or the frame's height changed. */
|
|
24
|
+
update: () => void;
|
|
25
|
+
/** Receives the boxes of the placed, open overlays, in frame coordinates. */
|
|
26
|
+
track(overlays: readonly {
|
|
27
|
+
top: number;
|
|
28
|
+
}[]): void;
|
|
29
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { FrameViewport } from "../renderer-environment";
|
|
2
1
|
/** Coalesce measurement corrections after layout; discard them if the reader moved meanwhile. */
|
|
3
|
-
export declare function viewportScroller(viewport:
|
|
2
|
+
export declare function viewportScroller(viewport: {
|
|
3
|
+
readonly revision: number;
|
|
4
|
+
}, send: (offset: number, revision: number) => void): {
|
|
4
5
|
scroll(offset: number): void;
|
|
5
6
|
dispose(): void;
|
|
6
7
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Ref } from "react";
|
|
2
|
-
import type { DilRendererHandle } from "./renderer-handle";
|
|
3
|
-
import type { ProgressiveReveal } from "./view/reveal-options";
|
|
4
|
-
import type { AutoScroll } from "./view/scroll-options";
|
|
5
|
-
import type { UpdateInterval } from "./runtime/presentation-scheduler";
|
|
2
|
+
import type { DilRendererHandle } from "./renderer-handle.js";
|
|
3
|
+
import type { ProgressiveReveal } from "./view/reveal-options.js";
|
|
4
|
+
import type { AutoScroll, ScrollContainer } from "./view/scroll-options.js";
|
|
5
|
+
import type { UpdateInterval } from "./runtime/presentation-scheduler.js";
|
|
6
6
|
export interface MessageRendererProps {
|
|
7
7
|
rendererRef?: Ref<DilRendererHandle> | undefined;
|
|
8
8
|
text: string;
|
|
@@ -10,7 +10,8 @@ export interface MessageRendererProps {
|
|
|
10
10
|
showStatus?: boolean;
|
|
11
11
|
progressiveReveal?: ProgressiveReveal;
|
|
12
12
|
autoScroll?: AutoScroll;
|
|
13
|
+
scrollContainer?: ScrollContainer | undefined;
|
|
13
14
|
updateInterval?: UpdateInterval;
|
|
14
15
|
onFollowChange?: ((following: boolean) => void) | undefined;
|
|
15
16
|
}
|
|
16
|
-
export declare function MessageRenderer({ rendererRef, text, isStreaming, showStatus, progressiveReveal, autoScroll, updateInterval, onFollowChange, }: MessageRendererProps): import("react").JSX.Element;
|
|
17
|
+
export declare function MessageRenderer({ rendererRef, text, isStreaming, showStatus, progressiveReveal, autoScroll, scrollContainer, updateInterval, onFollowChange, }: MessageRendererProps): import("react").JSX.Element;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import type { DilNode, TreeBatch } from "./types";
|
|
2
|
-
|
|
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
|
+
*/
|
|
3
11
|
export declare class DilParser {
|
|
4
12
|
private source;
|
|
5
13
|
private cursor;
|
|
@@ -8,6 +16,16 @@ export declare class DilParser {
|
|
|
8
16
|
private mode;
|
|
9
17
|
private lexical;
|
|
10
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;
|
|
11
29
|
private tokenNode;
|
|
12
30
|
private nodes;
|
|
13
31
|
private children;
|
|
@@ -15,8 +33,11 @@ export declare class DilParser {
|
|
|
15
33
|
private dirty;
|
|
16
34
|
private links;
|
|
17
35
|
private declarations;
|
|
36
|
+
private issues;
|
|
18
37
|
private revision;
|
|
19
|
-
constructor();
|
|
38
|
+
constructor(options?: DilParserOptions);
|
|
39
|
+
/** Registers component names for tags that start after this call. */
|
|
40
|
+
allow(components: unknown): void;
|
|
20
41
|
private get parent();
|
|
21
42
|
private closeFrame;
|
|
22
43
|
private create;
|
|
@@ -24,10 +45,30 @@ export declare class DilParser {
|
|
|
24
45
|
private markdown;
|
|
25
46
|
private flushText;
|
|
26
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;
|
|
27
52
|
private finish;
|
|
28
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. */
|
|
29
57
|
private directive;
|
|
30
58
|
private tag;
|
|
31
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;
|
|
32
73
|
snapshot(): DilNode[];
|
|
33
74
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Attribute } from "./types";
|
|
1
|
+
import type { Attribute } from "./types.js";
|
|
2
2
|
export declare class LexicalState {
|
|
3
3
|
depth: number;
|
|
4
4
|
quote: string;
|
|
@@ -11,6 +11,17 @@ export declare class LexicalState {
|
|
|
11
11
|
consume(char: string, next: string): number;
|
|
12
12
|
get neutral(): boolean;
|
|
13
13
|
}
|
|
14
|
-
export
|
|
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;
|
|
15
26
|
export declare function braceEnd(source: string, start: number): number;
|
|
16
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 {};
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export type NodeKind = "root" | "element" | "markdown" | "if" | "branch" | "each" | "pending";
|
|
2
|
-
|
|
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";
|
|
3
8
|
export interface Attribute {
|
|
4
9
|
expression?: string;
|
|
5
10
|
literal?: string | boolean;
|
|
@@ -13,8 +18,15 @@ export interface DilNode {
|
|
|
13
18
|
expressions: string[];
|
|
14
19
|
status: NodeStatus;
|
|
15
20
|
offset: number;
|
|
21
|
+
/** Developer-facing reason for an `error` node; readers see generic wording. */
|
|
16
22
|
error: string;
|
|
17
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
|
+
}
|
|
18
30
|
export interface TreeBatch {
|
|
19
31
|
revision: number;
|
|
20
32
|
nodes: DilNode[];
|
|
@@ -23,10 +35,19 @@ export interface TreeBatch {
|
|
|
23
35
|
child: number;
|
|
24
36
|
}[];
|
|
25
37
|
declarations: string[];
|
|
38
|
+
issues: ParseIssue[];
|
|
26
39
|
complete: boolean;
|
|
27
40
|
scanned: number;
|
|
28
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;
|
|
29
48
|
export interface StreamInput {
|
|
30
49
|
suffix: string;
|
|
31
50
|
complete: boolean;
|
|
51
|
+
/** Host-registered component names, sent when they change. */
|
|
52
|
+
components?: readonly string[];
|
|
32
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;
|
|
@@ -1,22 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
7
16
|
}
|
|
8
17
|
export interface RendererMetrics {
|
|
9
18
|
scanned: number;
|
|
10
19
|
complete: boolean;
|
|
20
|
+
/** The document was finalized while some of its structure was still open. */
|
|
21
|
+
incomplete: boolean;
|
|
11
22
|
}
|
|
12
23
|
export interface RendererEnvironment {
|
|
13
|
-
viewport?:
|
|
14
|
-
scrollTo?: (offset: number) => void;
|
|
24
|
+
viewport?: RendererViewport;
|
|
15
25
|
copy?: (text: string) => Promise<boolean>;
|
|
16
26
|
onInput?: (detail: {
|
|
17
27
|
length: number;
|
|
18
28
|
}) => void;
|
|
19
29
|
onCommit?: (detail: RendererMetrics) => void;
|
|
30
|
+
onError?: (error: DilRenderError) => void;
|
|
20
31
|
}
|
|
21
32
|
export declare const RendererEnvironmentContext: import("react").Context<RendererEnvironment>;
|
|
22
33
|
export declare function useRendererEnvironment(): RendererEnvironment;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { type StoreApi } from "zustand/vanilla";
|
|
2
|
-
import type { DilNode, TreeBatch } from "../parser/types";
|
|
3
|
-
import { ChildList } from "./child-list";
|
|
4
|
-
import { ExpressionEngine, type Scope } from "./expressions";
|
|
5
|
-
import { RenderBudget } from "./render-budget";
|
|
6
|
-
import { PresentationHistory } from "./presentation-history";
|
|
7
|
-
import { PresentationScheduler } from "./presentation-scheduler";
|
|
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";
|
|
8
9
|
export interface NodeState {
|
|
9
10
|
node: DilNode;
|
|
10
11
|
children: ChildList;
|
|
11
12
|
}
|
|
12
13
|
export interface DocumentStatus {
|
|
13
14
|
complete: boolean;
|
|
15
|
+
/** The document was finalized while some of its structure was still open. */
|
|
16
|
+
incomplete: boolean;
|
|
14
17
|
revision: number;
|
|
15
18
|
scanned: number;
|
|
16
19
|
error: string;
|
|
@@ -33,6 +36,15 @@ export declare class DilDocument {
|
|
|
33
36
|
readonly status: StoreApi<DocumentStatus>;
|
|
34
37
|
readonly engine: ExpressionEngine;
|
|
35
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;
|
|
36
48
|
constructor();
|
|
37
49
|
apply(batch: TreeBatch): void;
|
|
38
50
|
private presentedChildren;
|
|
@@ -25,6 +25,7 @@ export declare class ExecutionQueue {
|
|
|
25
25
|
private readonly receive;
|
|
26
26
|
private readonly failure;
|
|
27
27
|
private next;
|
|
28
|
+
private answered;
|
|
28
29
|
private pending;
|
|
29
30
|
private evaluations;
|
|
30
31
|
private activeKeys;
|
|
@@ -32,7 +33,7 @@ export declare class ExecutionQueue {
|
|
|
32
33
|
private setters;
|
|
33
34
|
private draining;
|
|
34
35
|
private stopped;
|
|
35
|
-
constructor(post: (message: Record<string, unknown>) => void, receive: (job: ExecutionJob, reply: ExecutionReply) => void, failure: (message: string) => void);
|
|
36
|
+
constructor(post: (message: Record<string, unknown>) => void, receive: (job: ExecutionJob, reply: ExecutionReply) => void, failure: (message: string, kind: "runtime" | "limit") => void);
|
|
36
37
|
get stats(): {
|
|
37
38
|
inFlight: number;
|
|
38
39
|
evaluations: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PresentationScheduler } from "./presentation-scheduler";
|
|
2
|
-
import { type Scope } from "./evaluation-cache";
|
|
3
|
-
export type { Scope } from "./evaluation-cache";
|
|
1
|
+
import { PresentationScheduler } from "./presentation-scheduler.js";
|
|
2
|
+
import { type Scope } from "./evaluation-cache.js";
|
|
3
|
+
export type { Scope } from "./evaluation-cache.js";
|
|
4
4
|
export interface BindingState {
|
|
5
5
|
values: Record<string, unknown>;
|
|
6
6
|
versions: Record<string, number>;
|
|
@@ -13,7 +13,8 @@ export declare class ExpressionEngine {
|
|
|
13
13
|
readonly events: EventTarget;
|
|
14
14
|
private readonly updates;
|
|
15
15
|
readonly store: import("zustand").StoreApi<BindingState>;
|
|
16
|
-
|
|
16
|
+
/** Started by the first job, so documents without expressions or state never load QuickJS. */
|
|
17
|
+
private runtime;
|
|
17
18
|
private readonly cache;
|
|
18
19
|
private readonly queue;
|
|
19
20
|
private intent;
|
|
@@ -35,13 +36,15 @@ export declare class ExpressionEngine {
|
|
|
35
36
|
};
|
|
36
37
|
markGesture(): void;
|
|
37
38
|
constructor(events?: EventTarget, updates?: PresentationScheduler);
|
|
39
|
+
private start;
|
|
38
40
|
private reference;
|
|
39
41
|
private replaceHandles;
|
|
40
42
|
private retire;
|
|
41
43
|
private notify;
|
|
42
44
|
private fill;
|
|
43
45
|
private receive;
|
|
44
|
-
halt
|
|
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;
|
|
45
48
|
dispose(): void;
|
|
46
49
|
/** Committed views own demand; cancelled renders never enqueue worker work. */
|
|
47
50
|
retain(expressions: readonly string[], scope?: Scope): () => void;
|
|
@@ -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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DilDocument } from "./document";
|
|
2
|
-
import type { Scope } from "./expressions";
|
|
1
|
+
import type { DilDocument } from "./document.js";
|
|
2
|
+
import type { Scope } from "./expressions.js";
|
|
3
3
|
export interface CostDocument {
|
|
4
4
|
nodes: DilDocument["nodes"];
|
|
5
5
|
engine: Pick<DilDocument["engine"], "read">;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Ref } from "react";
|
|
2
|
+
import type { DilRendererHandle } from "./renderer-handle.js";
|
|
3
|
+
import { type DilCustomization } from "./customization.js";
|
|
4
|
+
import { type RendererMetrics } from "./renderer-environment.js";
|
|
5
|
+
import type { DilRenderError } from "./render-error.js";
|
|
6
|
+
import type { ProgressiveReveal } from "./view/reveal-options.js";
|
|
7
|
+
import type { AutoScroll, ScrollContainer } from "./view/scroll-options.js";
|
|
8
|
+
import type { UpdateInterval } from "./runtime/presentation-scheduler.js";
|
|
9
|
+
import type { Appearance, ThemeTokens } from "./isolation/frame-theme.js";
|
|
10
|
+
type Optional<T> = {
|
|
11
|
+
[Key in keyof T]?: T[Key] | undefined;
|
|
12
|
+
};
|
|
13
|
+
export interface StyledRendererProps extends Optional<DilCustomization> {
|
|
14
|
+
mode: "host" | "shadow";
|
|
15
|
+
rendererRef?: Ref<DilRendererHandle> | undefined;
|
|
16
|
+
text: string;
|
|
17
|
+
isStreaming: boolean;
|
|
18
|
+
showStatus: boolean;
|
|
19
|
+
progressiveReveal: ProgressiveReveal;
|
|
20
|
+
autoScroll: AutoScroll;
|
|
21
|
+
scrollContainer?: ScrollContainer | undefined;
|
|
22
|
+
updateInterval: UpdateInterval;
|
|
23
|
+
onFollowChange?: ((following: boolean) => void) | undefined;
|
|
24
|
+
onInput?: ((detail: {
|
|
25
|
+
length: number;
|
|
26
|
+
}) => void) | undefined;
|
|
27
|
+
onCommit?: ((detail: RendererMetrics) => void) | undefined;
|
|
28
|
+
onError?: ((error: DilRenderError) => void) | undefined;
|
|
29
|
+
className?: string | undefined;
|
|
30
|
+
appearance: Appearance;
|
|
31
|
+
tokens?: ThemeTokens | undefined;
|
|
32
|
+
shadowStyles?: string | undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Host and Shadow DOM rendering run the parser and QuickJS workers in the page,
|
|
36
|
+
* so this module and its embedded workers load only when a page uses those modes.
|
|
37
|
+
*/
|
|
38
|
+
export declare function StyledRenderer(props: StyledRendererProps): import("react").JSX.Element;
|
|
39
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ChildList } from "../runtime/child-list";
|
|
2
|
-
import type { DilDocument } from "../runtime/document";
|
|
3
|
-
import type { Scope } from "../runtime/expressions";
|
|
1
|
+
import type { ChildList } from "../runtime/child-list.js";
|
|
2
|
+
import type { DilDocument } from "../runtime/document.js";
|
|
3
|
+
import type { Scope } from "../runtime/expressions.js";
|
|
4
4
|
export interface ConditionalViewProps {
|
|
5
5
|
childrenIds: ChildList;
|
|
6
6
|
document: DilDocument;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type Scope } from "../runtime/expressions";
|
|
2
|
-
import type { DilNode } from "../parser/types";
|
|
3
|
-
import type { DilDocument } from "../runtime/document";
|
|
1
|
+
import { type Scope } from "../runtime/expressions.js";
|
|
2
|
+
import type { DilNode } from "../parser/types.js";
|
|
3
|
+
import type { DilDocument } from "../runtime/document.js";
|
|
4
4
|
export interface MarkdownNodeProps {
|
|
5
5
|
node: DilNode;
|
|
6
6
|
document: DilDocument;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { DilDocument } from "../runtime/document";
|
|
2
|
-
import type { Scope } from "../runtime/expressions";
|
|
3
|
-
import type { ChildList } from "../runtime/child-list";
|
|
1
|
+
import type { DilDocument } from "../runtime/document.js";
|
|
2
|
+
import type { Scope } from "../runtime/expressions.js";
|
|
3
|
+
import type { ChildList } from "../runtime/child-list.js";
|
|
4
4
|
export interface NodeChildrenProps {
|
|
5
5
|
childrenIds: ChildList;
|
|
6
6
|
document: DilDocument;
|