@mathvoice/react 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.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # @mathvoice/react
2
+
3
+ Voice-driven LaTeX editing as a controlled React component.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mathvoice/react
9
+ ```
10
+
11
+ Also import the KaTeX stylesheet in your app entry point:
12
+
13
+ ```ts
14
+ import 'katex/dist/katex.min.css';
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```tsx
20
+ import { StudioEditor } from '@mathvoice/react';
21
+
22
+ export default function App() {
23
+ return (
24
+ <StudioEditor
25
+ initialLatex="\frac{-b \pm \sqrt{b^2-4ac}}{2a}"
26
+ apiEndpoint="/api/intent"
27
+ onMutation={(result) => console.log('updated:', result.after)}
28
+ />
29
+ );
30
+ }
31
+ ```
32
+
33
+ ## Controlled mode
34
+
35
+ ```tsx
36
+ const [latex, setLatex] = useState('\\frac{x}{2}');
37
+
38
+ <StudioEditor
39
+ latex={latex}
40
+ onMutation={(result) => setLatex(result.after)}
41
+ editMode="ALGEBRA"
42
+ />
43
+ ```
44
+
45
+ ## Props
46
+
47
+ | Prop | Type | Default | Description |
48
+ |------|------|---------|-------------|
49
+ | `initialLatex` | `string` | `\\frac{-b}{2a}` | Starting LaTeX (uncontrolled) |
50
+ | `latex` | `string` | — | Controlled LaTeX value |
51
+ | `onMutation` | `(result: MutationResult) => void` | — | Called after every successful edit |
52
+ | `editMode` | `'CORRECT' \| 'ALGEBRA' \| 'ASK'` | `'CORRECT'` | Enforced edit mode |
53
+ | `voiceEnabled` | `boolean` | `true` | Show mic button placeholder |
54
+ | `onModeChange` | `(mode: EditMode) => void` | — | Called when user switches mode |
55
+ | `apiEndpoint` | `string` | `'/api/intent'` | Override the intent API URL |
56
+ | `className` | `string` | — | CSS class on root element |
57
+ | `style` | `React.CSSProperties` | — | Inline styles on root element |
58
+
59
+ ## API endpoint
60
+
61
+ The component posts to `apiEndpoint` with:
62
+
63
+ ```json
64
+ {
65
+ "rawText": "change the numerator to x squared",
66
+ "normalizedText": "change numerator to x squared",
67
+ "formulaContext": { "latex": "\\frac{-b}{2a}" },
68
+ "editMode": "CORRECT"
69
+ }
70
+ ```
71
+
72
+ Expected response: an `Intent` object (see `@mathvoice/react` types).
73
+
74
+ ## License
75
+
76
+ MIT
@@ -0,0 +1,80 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface Intent {
4
+ type: IntentType;
5
+ target?: {
6
+ role: string;
7
+ };
8
+ source?: {
9
+ role: string;
10
+ };
11
+ value?: {
12
+ raw: string;
13
+ };
14
+ term?: {
15
+ raw: string;
16
+ };
17
+ wrapper?: 'SQRT' | 'FRACTION';
18
+ operation?: 'ADD' | 'SUBTRACT' | 'MULTIPLY' | 'DIVIDE';
19
+ reason?: string;
20
+ confidence?: number;
21
+ source_tier?: string;
22
+ source_origin?: string;
23
+ }
24
+ type IntentType = 'REPLACE_VALUE' | 'DELETE_NODE' | 'INSERT_NODE' | 'REPARENT_NODE' | 'NEGATE_NODE' | 'WRAP_NODE' | 'APPLY_INVERSE' | 'TRANSPOSE_TERM' | 'UNKNOWN';
25
+
26
+ type EditMode = 'CORRECT' | 'ALGEBRA' | 'ASK';
27
+ interface DiffEntry {
28
+ op: string;
29
+ role?: string;
30
+ before?: string;
31
+ after?: string;
32
+ srcRole?: string;
33
+ tgtRole?: string;
34
+ srcVal?: string;
35
+ tgtVal?: string;
36
+ wrapper?: string;
37
+ operation?: string;
38
+ value?: string;
39
+ lhsBefore?: string;
40
+ lhsAfter?: string;
41
+ rhsBefore?: string;
42
+ rhsAfter?: string;
43
+ term?: string;
44
+ from?: string;
45
+ to?: string;
46
+ note?: string;
47
+ }
48
+ interface MutationResult {
49
+ success: boolean;
50
+ before: string;
51
+ after: string;
52
+ diff: DiffEntry | null;
53
+ error?: string;
54
+ }
55
+
56
+ interface StudioEditorProps {
57
+ /** Starting LaTeX string (uncontrolled). Defaults to \\frac{-b}{2a}. */
58
+ initialLatex?: string;
59
+ /** Fully-controlled LaTeX. When provided, the component renders this value
60
+ * and calls onMutation on every successful edit but does not manage its
61
+ * own undo stack. */
62
+ latex?: string;
63
+ /** Called after every successful mutation. */
64
+ onMutation?: (result: MutationResult) => void;
65
+ /** Edit mode to enforce. Defaults to 'CORRECT'. */
66
+ editMode?: EditMode;
67
+ /** Show / hide the microphone button. Defaults to true. */
68
+ voiceEnabled?: boolean;
69
+ /** Called when the user changes modes (only when editMode is unset). */
70
+ onModeChange?: (mode: EditMode) => void;
71
+ /** Override the default /api/intent endpoint. */
72
+ apiEndpoint?: string;
73
+ /** Additional CSS class applied to the root wrapper. */
74
+ className?: string;
75
+ /** Inline styles applied to the root wrapper. */
76
+ style?: React.CSSProperties;
77
+ }
78
+ declare function StudioEditor({ initialLatex, latex: controlledLatex, onMutation, editMode, voiceEnabled, onModeChange, apiEndpoint, className, style, }: StudioEditorProps): react_jsx_runtime.JSX.Element;
79
+
80
+ export { type DiffEntry, type EditMode, type Intent, type IntentType, type MutationResult, StudioEditor, type StudioEditorProps };
@@ -0,0 +1,80 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface Intent {
4
+ type: IntentType;
5
+ target?: {
6
+ role: string;
7
+ };
8
+ source?: {
9
+ role: string;
10
+ };
11
+ value?: {
12
+ raw: string;
13
+ };
14
+ term?: {
15
+ raw: string;
16
+ };
17
+ wrapper?: 'SQRT' | 'FRACTION';
18
+ operation?: 'ADD' | 'SUBTRACT' | 'MULTIPLY' | 'DIVIDE';
19
+ reason?: string;
20
+ confidence?: number;
21
+ source_tier?: string;
22
+ source_origin?: string;
23
+ }
24
+ type IntentType = 'REPLACE_VALUE' | 'DELETE_NODE' | 'INSERT_NODE' | 'REPARENT_NODE' | 'NEGATE_NODE' | 'WRAP_NODE' | 'APPLY_INVERSE' | 'TRANSPOSE_TERM' | 'UNKNOWN';
25
+
26
+ type EditMode = 'CORRECT' | 'ALGEBRA' | 'ASK';
27
+ interface DiffEntry {
28
+ op: string;
29
+ role?: string;
30
+ before?: string;
31
+ after?: string;
32
+ srcRole?: string;
33
+ tgtRole?: string;
34
+ srcVal?: string;
35
+ tgtVal?: string;
36
+ wrapper?: string;
37
+ operation?: string;
38
+ value?: string;
39
+ lhsBefore?: string;
40
+ lhsAfter?: string;
41
+ rhsBefore?: string;
42
+ rhsAfter?: string;
43
+ term?: string;
44
+ from?: string;
45
+ to?: string;
46
+ note?: string;
47
+ }
48
+ interface MutationResult {
49
+ success: boolean;
50
+ before: string;
51
+ after: string;
52
+ diff: DiffEntry | null;
53
+ error?: string;
54
+ }
55
+
56
+ interface StudioEditorProps {
57
+ /** Starting LaTeX string (uncontrolled). Defaults to \\frac{-b}{2a}. */
58
+ initialLatex?: string;
59
+ /** Fully-controlled LaTeX. When provided, the component renders this value
60
+ * and calls onMutation on every successful edit but does not manage its
61
+ * own undo stack. */
62
+ latex?: string;
63
+ /** Called after every successful mutation. */
64
+ onMutation?: (result: MutationResult) => void;
65
+ /** Edit mode to enforce. Defaults to 'CORRECT'. */
66
+ editMode?: EditMode;
67
+ /** Show / hide the microphone button. Defaults to true. */
68
+ voiceEnabled?: boolean;
69
+ /** Called when the user changes modes (only when editMode is unset). */
70
+ onModeChange?: (mode: EditMode) => void;
71
+ /** Override the default /api/intent endpoint. */
72
+ apiEndpoint?: string;
73
+ /** Additional CSS class applied to the root wrapper. */
74
+ className?: string;
75
+ /** Inline styles applied to the root wrapper. */
76
+ style?: React.CSSProperties;
77
+ }
78
+ declare function StudioEditor({ initialLatex, latex: controlledLatex, onMutation, editMode, voiceEnabled, onModeChange, apiEndpoint, className, style, }: StudioEditorProps): react_jsx_runtime.JSX.Element;
79
+
80
+ export { type DiffEntry, type EditMode, type Intent, type IntentType, type MutationResult, StudioEditor, type StudioEditorProps };