@pragma-sh/scratchpad-viewer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,105 @@
1
+ import { ScratchpadBlock, ScratchpadComment } from "@pragma-sh/scratchpad-contract";
2
+ /** Messages the viewer document posts to its native host. */
3
+ type ScratchpadViewerMessage = {
4
+ type: "ready";
5
+ height: number;
6
+ } | {
7
+ type: "height";
8
+ height: number;
9
+ } | {
10
+ type: "error";
11
+ message: string;
12
+ } | {
13
+ type: "preview";
14
+ block: ScratchpadBlock | null;
15
+ } | {
16
+ type: "select";
17
+ block: ScratchpadBlock;
18
+ } | {
19
+ type: "promptAgent";
20
+ requestId: string;
21
+ text: string;
22
+ } | {
23
+ type: "requestAgentAttachment";
24
+ requestId: string;
25
+ } | {
26
+ type: "getWhiteboardSnapshot";
27
+ requestId: string;
28
+ whiteboardId: string;
29
+ knownVersion?: number;
30
+ dark?: boolean;
31
+ } | {
32
+ type: "subscribeAgentProgress";
33
+ requestId: string;
34
+ tabIds: string[];
35
+ } | {
36
+ type: "unsubscribeAgentProgress";
37
+ requestId: string;
38
+ };
39
+ /** Commands the native host sends into the viewer document. */
40
+ type ScratchpadViewerCommand = {
41
+ type: "comments";
42
+ comments: ScratchpadComment[];
43
+ } | {
44
+ type: "commentMode";
45
+ active: boolean;
46
+ } | {
47
+ type: "clearSelection";
48
+ } | {
49
+ type: "theme";
50
+ css: string;
51
+ mode: "light" | "dark";
52
+ } | {
53
+ type: "response";
54
+ requestId: string;
55
+ value?: unknown;
56
+ error?: string;
57
+ } | {
58
+ type: "progress";
59
+ requestId: string;
60
+ entries: unknown[];
61
+ };
62
+ /** Options for {@link buildScratchpadViewerHtml}. */
63
+ interface ScratchpadViewerHtmlOptions {
64
+ /** The scratchpad's MDX source, frontmatter included. */
65
+ source: string;
66
+ /** Comments to highlight on first paint. */
67
+ comments?: readonly ScratchpadComment[];
68
+ /** Which color scheme the host is rendering in. */
69
+ mode?: "light" | "dark";
70
+ /**
71
+ * Host theme overrides as CSS declarations (`--card: oklch(...);`).
72
+ *
73
+ * Only overrides belong here. Every `@pragma-sh/scratchpad` rule already carries
74
+ * a literal fallback after its `var()`, which is what a scratchpad rendered
75
+ * outside the desktop uses — restating those defaults here would fork the
76
+ * palette. Build this with {@link scratchpadThemeCss}.
77
+ */
78
+ themeCss?: string;
79
+ }
80
+ /** Turns host theme overrides into the CSS custom-property block the document takes. */
81
+ declare function scratchpadThemeCss(overrides: Readonly<Record<string, string | undefined>>): string;
82
+ /**
83
+ * Builds the whole viewer document: one self-contained HTML string with the
84
+ * runtime, the document source, and the comment layer inlined.
85
+ *
86
+ * Self-contained is the requirement, not a preference — a web view loading this
87
+ * from a string has no origin to resolve relative URLs against, and a phone
88
+ * viewing a scratchpad over a tunnel should not need a second round trip to
89
+ * paint. Nothing here is fetched.
90
+ */
91
+ declare function buildScratchpadViewerHtml(options: ScratchpadViewerHtmlOptions): string;
92
+ /**
93
+ * Removes frontmatter and import statements from scratchpad MDX before it is
94
+ * evaluated in a web view.
95
+ *
96
+ * Frontmatter is host metadata the MDX compiler would reject without a plugin.
97
+ * Imports are dropped because the document runs with no module resolver: the
98
+ * components they name are supplied to MDX as run-time components instead, so a
99
+ * document that imports from `@pragma-sh/scratchpad/ui` renders exactly as it does
100
+ * on the desktop, and one that imports a worktree file reports the missing
101
+ * component in place rather than failing to render at all.
102
+ */
103
+ declare function prepareMdxSource(source: string): string;
104
+ import { attachScratchpadAgent, createScratchpadComment, markAllResolved, parseScratchpadComments, parseScratchpadDocument, replaceScratchpadBody, scratchpadCommentsPath, serializeScratchpadComments, unresolvedComments, unresolvedCommentsPrompt, ScratchpadDocument, ScratchpadMetadata } from "@pragma-sh/scratchpad-contract";
105
+ export { unresolvedCommentsPrompt, unresolvedComments, serializeScratchpadComments, scratchpadThemeCss, scratchpadCommentsPath, replaceScratchpadBody, prepareMdxSource, parseScratchpadDocument, parseScratchpadComments, markAllResolved, createScratchpadComment, buildScratchpadViewerHtml, attachScratchpadAgent, ScratchpadViewerMessage, ScratchpadViewerHtmlOptions, ScratchpadViewerCommand, ScratchpadMetadata, ScratchpadDocument, ScratchpadComment, ScratchpadBlock };
@@ -0,0 +1,105 @@
1
+ import { ScratchpadBlock, ScratchpadComment } from "@pragma-sh/scratchpad-contract";
2
+ /** Messages the viewer document posts to its native host. */
3
+ type ScratchpadViewerMessage = {
4
+ type: "ready";
5
+ height: number;
6
+ } | {
7
+ type: "height";
8
+ height: number;
9
+ } | {
10
+ type: "error";
11
+ message: string;
12
+ } | {
13
+ type: "preview";
14
+ block: ScratchpadBlock | null;
15
+ } | {
16
+ type: "select";
17
+ block: ScratchpadBlock;
18
+ } | {
19
+ type: "promptAgent";
20
+ requestId: string;
21
+ text: string;
22
+ } | {
23
+ type: "requestAgentAttachment";
24
+ requestId: string;
25
+ } | {
26
+ type: "getWhiteboardSnapshot";
27
+ requestId: string;
28
+ whiteboardId: string;
29
+ knownVersion?: number;
30
+ dark?: boolean;
31
+ } | {
32
+ type: "subscribeAgentProgress";
33
+ requestId: string;
34
+ tabIds: string[];
35
+ } | {
36
+ type: "unsubscribeAgentProgress";
37
+ requestId: string;
38
+ };
39
+ /** Commands the native host sends into the viewer document. */
40
+ type ScratchpadViewerCommand = {
41
+ type: "comments";
42
+ comments: ScratchpadComment[];
43
+ } | {
44
+ type: "commentMode";
45
+ active: boolean;
46
+ } | {
47
+ type: "clearSelection";
48
+ } | {
49
+ type: "theme";
50
+ css: string;
51
+ mode: "light" | "dark";
52
+ } | {
53
+ type: "response";
54
+ requestId: string;
55
+ value?: unknown;
56
+ error?: string;
57
+ } | {
58
+ type: "progress";
59
+ requestId: string;
60
+ entries: unknown[];
61
+ };
62
+ /** Options for {@link buildScratchpadViewerHtml}. */
63
+ interface ScratchpadViewerHtmlOptions {
64
+ /** The scratchpad's MDX source, frontmatter included. */
65
+ source: string;
66
+ /** Comments to highlight on first paint. */
67
+ comments?: readonly ScratchpadComment[];
68
+ /** Which color scheme the host is rendering in. */
69
+ mode?: "light" | "dark";
70
+ /**
71
+ * Host theme overrides as CSS declarations (`--card: oklch(...);`).
72
+ *
73
+ * Only overrides belong here. Every `@pragma-sh/scratchpad` rule already carries
74
+ * a literal fallback after its `var()`, which is what a scratchpad rendered
75
+ * outside the desktop uses — restating those defaults here would fork the
76
+ * palette. Build this with {@link scratchpadThemeCss}.
77
+ */
78
+ themeCss?: string;
79
+ }
80
+ /** Turns host theme overrides into the CSS custom-property block the document takes. */
81
+ declare function scratchpadThemeCss(overrides: Readonly<Record<string, string | undefined>>): string;
82
+ /**
83
+ * Builds the whole viewer document: one self-contained HTML string with the
84
+ * runtime, the document source, and the comment layer inlined.
85
+ *
86
+ * Self-contained is the requirement, not a preference — a web view loading this
87
+ * from a string has no origin to resolve relative URLs against, and a phone
88
+ * viewing a scratchpad over a tunnel should not need a second round trip to
89
+ * paint. Nothing here is fetched.
90
+ */
91
+ declare function buildScratchpadViewerHtml(options: ScratchpadViewerHtmlOptions): string;
92
+ /**
93
+ * Removes frontmatter and import statements from scratchpad MDX before it is
94
+ * evaluated in a web view.
95
+ *
96
+ * Frontmatter is host metadata the MDX compiler would reject without a plugin.
97
+ * Imports are dropped because the document runs with no module resolver: the
98
+ * components they name are supplied to MDX as run-time components instead, so a
99
+ * document that imports from `@pragma-sh/scratchpad/ui` renders exactly as it does
100
+ * on the desktop, and one that imports a worktree file reports the missing
101
+ * component in place rather than failing to render at all.
102
+ */
103
+ declare function prepareMdxSource(source: string): string;
104
+ import { attachScratchpadAgent, createScratchpadComment, markAllResolved, parseScratchpadComments, parseScratchpadDocument, replaceScratchpadBody, scratchpadCommentsPath, serializeScratchpadComments, unresolvedComments, unresolvedCommentsPrompt, ScratchpadDocument, ScratchpadMetadata } from "@pragma-sh/scratchpad-contract";
105
+ export { unresolvedCommentsPrompt, unresolvedComments, serializeScratchpadComments, scratchpadThemeCss, scratchpadCommentsPath, replaceScratchpadBody, prepareMdxSource, parseScratchpadDocument, parseScratchpadComments, markAllResolved, createScratchpadComment, buildScratchpadViewerHtml, attachScratchpadAgent, ScratchpadViewerMessage, ScratchpadViewerHtmlOptions, ScratchpadViewerCommand, ScratchpadMetadata, ScratchpadDocument, ScratchpadComment, ScratchpadBlock };