@mdocui/core 0.1.1

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,140 @@
1
+ import { z } from 'zod';
2
+
3
+ declare enum TokenizerState {
4
+ IN_PROSE = "IN_PROSE",
5
+ IN_TAG = "IN_TAG",
6
+ IN_STRING = "IN_STRING"
7
+ }
8
+ declare enum TokenType {
9
+ PROSE = "PROSE",
10
+ TAG_OPEN = "TAG_OPEN",
11
+ TAG_SELF_CLOSE = "TAG_SELF_CLOSE",
12
+ TAG_CLOSE = "TAG_CLOSE"
13
+ }
14
+ interface Token {
15
+ type: TokenType;
16
+ raw: string;
17
+ name?: string;
18
+ attrs?: string;
19
+ selfClosing?: boolean;
20
+ }
21
+ declare class Tokenizer {
22
+ private state;
23
+ private buffer;
24
+ private proseBuffer;
25
+ private stringChar;
26
+ private escaped;
27
+ private tokens;
28
+ getState(): TokenizerState;
29
+ getBuffer(): string;
30
+ write(chunk: string): Token[];
31
+ flush(): Token[];
32
+ reset(): void;
33
+ private flushProse;
34
+ private emitTag;
35
+ }
36
+
37
+ interface ComponentDefinition {
38
+ name: string;
39
+ description: string;
40
+ props: z.ZodObject<z.ZodRawShape>;
41
+ children?: 'none' | 'any' | string[];
42
+ streaming?: Record<string, boolean>;
43
+ }
44
+ interface ProseNode {
45
+ type: 'prose';
46
+ content: string;
47
+ }
48
+ interface ComponentNode {
49
+ type: 'component';
50
+ name: string;
51
+ props: Record<string, unknown>;
52
+ children: ASTNode[];
53
+ selfClosing: boolean;
54
+ }
55
+ type ASTNode = ProseNode | ComponentNode;
56
+ interface ActionEvent {
57
+ type: 'button_click' | 'form_submit' | 'select_change' | 'link_click';
58
+ action: string;
59
+ label?: string;
60
+ formName?: string;
61
+ formState?: Record<string, unknown>;
62
+ tagName: string;
63
+ params?: Record<string, unknown>;
64
+ }
65
+ interface ComponentGroup {
66
+ name: string;
67
+ components: string[];
68
+ notes?: string[];
69
+ }
70
+ interface PromptOptions {
71
+ preamble?: string;
72
+ additionalRules?: string[];
73
+ examples?: string[];
74
+ groups?: ComponentGroup[];
75
+ }
76
+ interface ParseError {
77
+ code: 'unknown_tag' | 'validation' | 'malformed' | 'unclosed';
78
+ tagName: string;
79
+ message: string;
80
+ raw?: string;
81
+ }
82
+ interface ParseMeta {
83
+ errors: ParseError[];
84
+ nodeCount: number;
85
+ isComplete: boolean;
86
+ }
87
+ interface ValidationResult {
88
+ valid: boolean;
89
+ errors: string[];
90
+ props?: Record<string, unknown>;
91
+ }
92
+
93
+ interface ParserOptions {
94
+ dropUnknown?: boolean;
95
+ knownTags?: Set<string>;
96
+ }
97
+ declare class StreamingParser {
98
+ private tokenizer;
99
+ private completedNodes;
100
+ private bodyStack;
101
+ private errors;
102
+ private options;
103
+ constructor(options?: ParserOptions);
104
+ write(chunk: string): ASTNode[];
105
+ /** Flush remaining buffers. Open body tags are force-closed. */
106
+ flush(): ASTNode[];
107
+ getNodes(): ASTNode[];
108
+ getMeta(): ParseMeta;
109
+ reset(): void;
110
+ private processToken;
111
+ private handleProse;
112
+ private handleSelfClose;
113
+ private handleOpen;
114
+ private handleClose;
115
+ private buildComponentNode;
116
+ private popFrame;
117
+ private isInBody;
118
+ private currentFrame;
119
+ private isKnown;
120
+ }
121
+
122
+ declare function parseAttributes(input: string): Record<string, unknown>;
123
+
124
+ /** Type helper — returns the definition unchanged. */
125
+ declare function defineComponent(definition: ComponentDefinition): ComponentDefinition;
126
+ declare class ComponentRegistry {
127
+ private components;
128
+ register(definition: ComponentDefinition): this;
129
+ registerAll(definitions: ComponentDefinition[]): this;
130
+ get(name: string): ComponentDefinition | undefined;
131
+ has(name: string): boolean;
132
+ names(): string[];
133
+ all(): ComponentDefinition[];
134
+ knownTags(): Set<string>;
135
+ validate(tagName: string, props: Record<string, unknown>): ValidationResult;
136
+ }
137
+
138
+ declare function generatePrompt(registry: ComponentRegistry, options?: PromptOptions): string;
139
+
140
+ export { type ASTNode, type ActionEvent, type ComponentDefinition, type ComponentGroup, type ComponentNode, ComponentRegistry, type ParseError, type ParseMeta, type ParserOptions, type PromptOptions, type ProseNode, StreamingParser, type Token, TokenType, Tokenizer, TokenizerState, type ValidationResult, defineComponent, generatePrompt, parseAttributes };
@@ -0,0 +1,140 @@
1
+ import { z } from 'zod';
2
+
3
+ declare enum TokenizerState {
4
+ IN_PROSE = "IN_PROSE",
5
+ IN_TAG = "IN_TAG",
6
+ IN_STRING = "IN_STRING"
7
+ }
8
+ declare enum TokenType {
9
+ PROSE = "PROSE",
10
+ TAG_OPEN = "TAG_OPEN",
11
+ TAG_SELF_CLOSE = "TAG_SELF_CLOSE",
12
+ TAG_CLOSE = "TAG_CLOSE"
13
+ }
14
+ interface Token {
15
+ type: TokenType;
16
+ raw: string;
17
+ name?: string;
18
+ attrs?: string;
19
+ selfClosing?: boolean;
20
+ }
21
+ declare class Tokenizer {
22
+ private state;
23
+ private buffer;
24
+ private proseBuffer;
25
+ private stringChar;
26
+ private escaped;
27
+ private tokens;
28
+ getState(): TokenizerState;
29
+ getBuffer(): string;
30
+ write(chunk: string): Token[];
31
+ flush(): Token[];
32
+ reset(): void;
33
+ private flushProse;
34
+ private emitTag;
35
+ }
36
+
37
+ interface ComponentDefinition {
38
+ name: string;
39
+ description: string;
40
+ props: z.ZodObject<z.ZodRawShape>;
41
+ children?: 'none' | 'any' | string[];
42
+ streaming?: Record<string, boolean>;
43
+ }
44
+ interface ProseNode {
45
+ type: 'prose';
46
+ content: string;
47
+ }
48
+ interface ComponentNode {
49
+ type: 'component';
50
+ name: string;
51
+ props: Record<string, unknown>;
52
+ children: ASTNode[];
53
+ selfClosing: boolean;
54
+ }
55
+ type ASTNode = ProseNode | ComponentNode;
56
+ interface ActionEvent {
57
+ type: 'button_click' | 'form_submit' | 'select_change' | 'link_click';
58
+ action: string;
59
+ label?: string;
60
+ formName?: string;
61
+ formState?: Record<string, unknown>;
62
+ tagName: string;
63
+ params?: Record<string, unknown>;
64
+ }
65
+ interface ComponentGroup {
66
+ name: string;
67
+ components: string[];
68
+ notes?: string[];
69
+ }
70
+ interface PromptOptions {
71
+ preamble?: string;
72
+ additionalRules?: string[];
73
+ examples?: string[];
74
+ groups?: ComponentGroup[];
75
+ }
76
+ interface ParseError {
77
+ code: 'unknown_tag' | 'validation' | 'malformed' | 'unclosed';
78
+ tagName: string;
79
+ message: string;
80
+ raw?: string;
81
+ }
82
+ interface ParseMeta {
83
+ errors: ParseError[];
84
+ nodeCount: number;
85
+ isComplete: boolean;
86
+ }
87
+ interface ValidationResult {
88
+ valid: boolean;
89
+ errors: string[];
90
+ props?: Record<string, unknown>;
91
+ }
92
+
93
+ interface ParserOptions {
94
+ dropUnknown?: boolean;
95
+ knownTags?: Set<string>;
96
+ }
97
+ declare class StreamingParser {
98
+ private tokenizer;
99
+ private completedNodes;
100
+ private bodyStack;
101
+ private errors;
102
+ private options;
103
+ constructor(options?: ParserOptions);
104
+ write(chunk: string): ASTNode[];
105
+ /** Flush remaining buffers. Open body tags are force-closed. */
106
+ flush(): ASTNode[];
107
+ getNodes(): ASTNode[];
108
+ getMeta(): ParseMeta;
109
+ reset(): void;
110
+ private processToken;
111
+ private handleProse;
112
+ private handleSelfClose;
113
+ private handleOpen;
114
+ private handleClose;
115
+ private buildComponentNode;
116
+ private popFrame;
117
+ private isInBody;
118
+ private currentFrame;
119
+ private isKnown;
120
+ }
121
+
122
+ declare function parseAttributes(input: string): Record<string, unknown>;
123
+
124
+ /** Type helper — returns the definition unchanged. */
125
+ declare function defineComponent(definition: ComponentDefinition): ComponentDefinition;
126
+ declare class ComponentRegistry {
127
+ private components;
128
+ register(definition: ComponentDefinition): this;
129
+ registerAll(definitions: ComponentDefinition[]): this;
130
+ get(name: string): ComponentDefinition | undefined;
131
+ has(name: string): boolean;
132
+ names(): string[];
133
+ all(): ComponentDefinition[];
134
+ knownTags(): Set<string>;
135
+ validate(tagName: string, props: Record<string, unknown>): ValidationResult;
136
+ }
137
+
138
+ declare function generatePrompt(registry: ComponentRegistry, options?: PromptOptions): string;
139
+
140
+ export { type ASTNode, type ActionEvent, type ComponentDefinition, type ComponentGroup, type ComponentNode, ComponentRegistry, type ParseError, type ParseMeta, type ParserOptions, type PromptOptions, type ProseNode, StreamingParser, type Token, TokenType, Tokenizer, TokenizerState, type ValidationResult, defineComponent, generatePrompt, parseAttributes };