aac-board-viewer 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,305 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as _willwade_aac_processors from '@willwade/aac-processors';
3
+ import { AACTree } from '@willwade/aac-processors';
4
+ export { AACButton, AACPage, AACSemanticAction, AACSemanticCategory, AACSemanticIntent, AACTree } from '@willwade/aac-processors';
5
+
6
+ /**
7
+ * Button metric information for effort scoring
8
+ */
9
+ interface ButtonMetric {
10
+ /** Button ID */
11
+ id: string;
12
+ /** Button label text */
13
+ label: string;
14
+ /** Cognitive effort score (lower is easier) */
15
+ effort: number;
16
+ /** Usage count */
17
+ count?: number;
18
+ /** Whether the button represents a word */
19
+ is_word?: boolean;
20
+ /** Depth level in navigation tree */
21
+ level?: number;
22
+ }
23
+ /**
24
+ * Props for BoardViewer component
25
+ */
26
+ interface BoardViewerProps {
27
+ /** The AAC tree containing pages and navigation structure */
28
+ tree: _willwade_aac_processors.AACTree;
29
+ /** Optional button metrics to display effort scores */
30
+ buttonMetrics?: ButtonMetric[] | null;
31
+ /** Show the message bar at the top (default: true) */
32
+ showMessageBar?: boolean;
33
+ /** Show effort badges on buttons (default: true if metrics provided) */
34
+ showEffortBadges?: boolean;
35
+ /** Show indicators for buttons that link to other pages (default: true) */
36
+ showLinkIndicators?: boolean;
37
+ /** Start the viewer on this page id (overrides tree.rootId) */
38
+ initialPageId?: string;
39
+ /** Callback when a button is clicked */
40
+ onButtonClick?: (button: _willwade_aac_processors.AACButton) => void;
41
+ /** Callback when page changes */
42
+ onPageChange?: (pageId: string) => void;
43
+ /** Custom CSS class name */
44
+ className?: string;
45
+ }
46
+ /**
47
+ * Result from loading an AAC file
48
+ */
49
+ interface LoadAACFileResult {
50
+ tree: _willwade_aac_processors.AACTree;
51
+ format: string;
52
+ metadata?: {
53
+ [key: string]: unknown;
54
+ };
55
+ }
56
+
57
+ interface MetricsOptions {
58
+ /** Access method: 'direct' or 'scanning' */
59
+ accessMethod?: 'direct' | 'scanning';
60
+ /** Scanning configuration */
61
+ scanningConfig?: {
62
+ /** Scanning pattern: 'linear', 'row-column', or 'block' */
63
+ pattern?: 'linear' | 'row-column' | 'block';
64
+ /** Selection method for scanning */
65
+ selectionMethod?: string;
66
+ /** Enable error correction */
67
+ errorCorrection?: boolean;
68
+ };
69
+ }
70
+
71
+ /**
72
+ * AAC Board Viewer Component
73
+ *
74
+ * Displays AAC boards with interactive navigation, sentence building,
75
+ * and optional effort metrics.
76
+ *
77
+ * @param props - BoardViewerProps
78
+ */
79
+ declare function BoardViewer({ tree, buttonMetrics, showMessageBar, showEffortBadges, showLinkIndicators, initialPageId, onButtonClick, onPageChange, className, }: BoardViewerProps): react_jsx_runtime.JSX.Element;
80
+
81
+ /**
82
+ * React hooks for AAC Board Viewer
83
+ */
84
+
85
+ /**
86
+ * Hook to load an AAC file from a URL
87
+ *
88
+ * @param url - URL to the AAC file
89
+ * @param options - Processor options (e.g., pageLayoutPreference for SNAP)
90
+ * @returns Object with tree, loading state, and error
91
+ *
92
+ * @example
93
+ * ```tsx
94
+ * function MyViewer() {
95
+ * const { tree, loading, error, reload } = useAACFile('/files/board.sps');
96
+ *
97
+ * if (loading) return <div>Loading...</div>;
98
+ * if (error) return <div>Error: {error.message}</div>;
99
+ *
100
+ * return <BoardViewer tree={tree} />;
101
+ * }
102
+ * ```
103
+ */
104
+ declare function useAACFile(url: string, options?: {
105
+ processorOptions?: Record<string, unknown>;
106
+ enabled?: boolean;
107
+ }): {
108
+ tree: AACTree | null;
109
+ loading: boolean;
110
+ error: Error | null;
111
+ reload: () => Promise<void>;
112
+ };
113
+ /**
114
+ * Hook to load an AAC file and calculate metrics
115
+ *
116
+ * @param url - URL to the AAC file
117
+ * @param metricsOptions - Metrics calculation options
118
+ * @returns Object with tree, metrics, loading state, and error
119
+ *
120
+ * @example
121
+ * ```tsx
122
+ * function MyViewer() {
123
+ * const { tree, metrics, loading, error } = useAACFileWithMetrics(
124
+ * '/files/board.sps',
125
+ * { accessMethod: 'direct' }
126
+ * );
127
+ *
128
+ * if (loading) return <div>Loading...</div>;
129
+ * if (error) return <div>Error: {error.message}</div>;
130
+ *
131
+ * return <BoardViewer tree={tree} buttonMetrics={metrics} />;
132
+ * }
133
+ * ```
134
+ */
135
+ declare function useAACFileWithMetrics(url: string, metricsOptions?: MetricsOptions, fileOptions?: {
136
+ processorOptions?: Record<string, unknown>;
137
+ enabled?: boolean;
138
+ }): {
139
+ tree: AACTree | null;
140
+ metrics: ButtonMetric[] | null;
141
+ loading: boolean;
142
+ error: Error | null;
143
+ reload: () => Promise<void>;
144
+ };
145
+ /**
146
+ * Hook to calculate metrics for a tree
147
+ *
148
+ * @param tree - The AAC tree
149
+ * @param options - Metrics calculation options
150
+ * @returns Object with metrics, loading state, and error
151
+ *
152
+ * @example
153
+ * ```tsx
154
+ * function MyViewer({ tree }) {
155
+ * const { metrics, loading } = useMetrics(tree, {
156
+ * accessMethod: 'scanning',
157
+ * scanningConfig: { pattern: 'row-column' }
158
+ * });
159
+ *
160
+ * return <BoardViewer tree={tree} buttonMetrics={metrics} />;
161
+ * }
162
+ * ```
163
+ */
164
+ declare function useMetrics(tree: AACTree | null, options?: MetricsOptions): {
165
+ metrics: ButtonMetric[] | null;
166
+ loading: boolean;
167
+ error: Error | null;
168
+ recalculate: () => Promise<void>;
169
+ };
170
+ /**
171
+ * Hook for sentence building state
172
+ *
173
+ * @returns Object with message state and handlers
174
+ *
175
+ * @example
176
+ * ```tsx
177
+ * function MyComponent() {
178
+ * const { message, wordCount, effort, addWord, clear } = useSentenceBuilder();
179
+ *
180
+ * return (
181
+ * <div>
182
+ * <p>{message || 'Start building...'}</p>
183
+ * <p>{wordCount} words, {effort.toFixed(2)} effort</p>
184
+ * <button onClick={clear}>Clear</button>
185
+ * </div>
186
+ * );
187
+ * }
188
+ * ```
189
+ */
190
+ declare function useSentenceBuilder(): {
191
+ message: string;
192
+ wordCount: number;
193
+ effort: number;
194
+ addWord: (word: string, wordEffort?: number) => void;
195
+ clear: () => void;
196
+ };
197
+
198
+ /**
199
+ * AAC File Loading Utilities
200
+ *
201
+ * Provides utilities for loading AAC files from various sources
202
+ * (URLs, File objects, file paths) in both client and server contexts.
203
+ */
204
+
205
+ type ProcessorOptions = Record<string, unknown> | undefined;
206
+ /**
207
+ * Load an AAC file from a file path (server-side only)
208
+ *
209
+ * @param filepath - Path to the AAC file
210
+ * @param options - Processor options (e.g., pageLayoutPreference for SNAP)
211
+ * @returns Promise resolving to AACTree
212
+ *
213
+ * @example
214
+ * ```ts
215
+ * const tree = await loadAACFile('/path/to/file.sps');
216
+ * ```
217
+ */
218
+ declare function loadAACFile(filepath: string, options?: ProcessorOptions): Promise<AACTree>;
219
+ /**
220
+ * Load an AAC file and return extended result with format info
221
+ *
222
+ * @param filepath - Path to the AAC file
223
+ * @param options - Processor options
224
+ * @returns Promise resolving to LoadAACFileResult
225
+ */
226
+ declare function loadAACFileWithMetadata(filepath: string, options?: ProcessorOptions): Promise<LoadAACFileResult>;
227
+ /**
228
+ * Load an AAC file from a URL (client-side)
229
+ *
230
+ * Note: This requires the server to provide the file with appropriate CORS headers.
231
+ * For better performance, consider server-side loading instead.
232
+ *
233
+ * @param url - URL to the AAC file
234
+ * @param options - Processor options
235
+ * @returns Promise resolving to AACTree
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * const tree = await loadAACFileFromURL('https://example.com/file.sps');
240
+ * ```
241
+ */
242
+ declare function loadAACFileFromURL(url: string, options?: ProcessorOptions): Promise<AACTree>;
243
+ /**
244
+ * Load an AAC file from a File object (client-side file input)
245
+ *
246
+ * @param file - File object from file input
247
+ * @param options - Processor options
248
+ * @returns Promise resolving to AACTree
249
+ *
250
+ * @example
251
+ * ```ts
252
+ * const input = document.querySelector('input[type="file"]');
253
+ * input.onchange = async (e) => {
254
+ * const file = e.target.files[0];
255
+ * const tree = await loadAACFileFromFile(file);
256
+ * // Use tree...
257
+ * };
258
+ * ```
259
+ */
260
+ declare function loadAACFileFromFile(_file: File | Blob, _filename?: string, _options?: unknown): Promise<AACTree>;
261
+ /**
262
+ * Calculate cognitive effort metrics for an AAC tree
263
+ *
264
+ * @param tree - The AAC tree
265
+ * @param options - Metrics calculation options
266
+ * @returns Promise resolving to array of ButtonMetrics
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * import { calculateMetrics } from 'aac-board-viewer';
271
+ *
272
+ * const metrics = await calculateMetrics(tree, {
273
+ * accessMethod: 'direct',
274
+ * });
275
+ * ```
276
+ */
277
+ declare function calculateMetrics(tree: AACTree, options?: {
278
+ accessMethod?: 'direct' | 'scanning';
279
+ scanningConfig?: {
280
+ pattern?: 'linear' | 'row-column' | 'block';
281
+ selectionMethod?: string;
282
+ errorCorrection?: boolean;
283
+ };
284
+ }): Promise<{
285
+ id: string;
286
+ label: string;
287
+ effort: number;
288
+ count: number;
289
+ is_word: boolean;
290
+ level: number | undefined;
291
+ semantic_id: string | undefined;
292
+ clone_id: string | undefined;
293
+ }[]>;
294
+ /**
295
+ * Get a list of supported file formats
296
+ *
297
+ * @returns Array of format information
298
+ */
299
+ declare function getSupportedFormats(): Array<{
300
+ name: string;
301
+ extensions: string[];
302
+ description: string;
303
+ }>;
304
+
305
+ export { BoardViewer, type BoardViewerProps, type ButtonMetric, type LoadAACFileResult, type MetricsOptions, calculateMetrics, getSupportedFormats, loadAACFile, loadAACFileFromFile, loadAACFileFromURL, loadAACFileWithMetadata, useAACFile, useAACFileWithMetrics, useMetrics, useSentenceBuilder };