aac-board-viewer 0.1.5 → 0.1.7

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/dist/index.d.mts CHANGED
@@ -42,6 +42,8 @@ interface BoardViewerProps {
42
42
  onPageChange?: (pageId: string) => void;
43
43
  /** Custom CSS class name */
44
44
  className?: string;
45
+ /** Load ID for fetching images from server (for OBZ files) */
46
+ loadId?: string;
45
47
  }
46
48
  /**
47
49
  * Result from loading an AAC file
@@ -76,7 +78,7 @@ interface MetricsOptions {
76
78
  *
77
79
  * @param props - BoardViewerProps
78
80
  */
79
- declare function BoardViewer({ tree, buttonMetrics, showMessageBar, showEffortBadges, showLinkIndicators, initialPageId, onButtonClick, onPageChange, className, }: BoardViewerProps): react_jsx_runtime.JSX.Element;
81
+ declare function BoardViewer({ tree, buttonMetrics, showMessageBar, showEffortBadges, showLinkIndicators, initialPageId, onButtonClick, onPageChange, className, loadId, }: BoardViewerProps): react_jsx_runtime.JSX.Element;
80
82
 
81
83
  /**
82
84
  * React hooks for AAC Board Viewer
@@ -110,6 +112,38 @@ declare function useAACFile(url: string, options?: {
110
112
  error: Error | null;
111
113
  reload: () => Promise<void>;
112
114
  };
115
+ /**
116
+ * Hook to load an AAC file from a File object (Browser only)
117
+ *
118
+ * @param file - File object from file input
119
+ * @param options - Processor options
120
+ * @returns Object with tree, loading state, and error
121
+ *
122
+ * @example
123
+ * ```tsx
124
+ * function MyUploader() {
125
+ * const [file, setFile] = useState<File | null>(null);
126
+ * const { tree, loading, error } = useAACFileFromFile(file);
127
+ *
128
+ * return (
129
+ * <div>
130
+ * <input type="file" onChange={(e) => setFile(e.target.files?.[0])} />
131
+ * {loading && <div>Loading...</div>}
132
+ * {tree && <BoardViewer tree={tree} />}
133
+ * </div>
134
+ * );
135
+ * }
136
+ * ```
137
+ */
138
+ declare function useAACFileFromFile(file: File | Blob | null, options?: {
139
+ processorOptions?: Record<string, unknown>;
140
+ enabled?: boolean;
141
+ }): {
142
+ tree: AACTree | null;
143
+ loading: boolean;
144
+ error: Error | null;
145
+ reload: () => Promise<void>;
146
+ };
113
147
  /**
114
148
  * Hook to load an AAC file and calculate metrics
115
149
  *
@@ -142,6 +176,42 @@ declare function useAACFileWithMetrics(url: string, metricsOptions?: MetricsOpti
142
176
  error: Error | null;
143
177
  reload: () => Promise<void>;
144
178
  };
179
+ /**
180
+ * Hook to load an AAC file from a File object and calculate metrics
181
+ *
182
+ * @param file - File object from file input
183
+ * @param metricsOptions - Metrics calculation options
184
+ * @returns Object with tree, metrics, loading state, and error
185
+ *
186
+ * @example
187
+ * ```tsx
188
+ * function MyUploader() {
189
+ * const [file, setFile] = useState<File | null>(null);
190
+ * const { tree, metrics, loading, error } = useAACFileFromFileWithMetrics(
191
+ * file,
192
+ * { accessMethod: 'direct' }
193
+ * );
194
+ *
195
+ * return (
196
+ * <div>
197
+ * <input type="file" onChange={(e) => setFile(e.target.files?.[0])} />
198
+ * {loading && <div>Loading...</div>}
199
+ * {tree && <BoardViewer tree={tree} buttonMetrics={metrics} />}
200
+ * </div>
201
+ * );
202
+ * }
203
+ * ```
204
+ */
205
+ declare function useAACFileFromFileWithMetrics(file: File | Blob | null, metricsOptions?: MetricsOptions, fileOptions?: {
206
+ processorOptions?: Record<string, unknown>;
207
+ enabled?: boolean;
208
+ }): {
209
+ tree: AACTree | null;
210
+ metrics: ButtonMetric[] | null;
211
+ loading: boolean;
212
+ error: Error | null;
213
+ reload: () => Promise<void>;
214
+ };
145
215
  /**
146
216
  * Hook to calculate metrics for a tree
147
217
  *
@@ -199,12 +269,15 @@ declare function useSentenceBuilder(): {
199
269
  * AAC File Loading Utilities
200
270
  *
201
271
  * Provides utilities for loading AAC files from various sources
202
- * (URLs, File objects, file paths) in both client and server contexts.
272
+ * (File/Blob objects, file paths, URLs) in both browser and server contexts.
273
+ *
274
+ * Browser: Supports .obf, .obz, .gridset, .plist, .grd, .opml, .dot
275
+ * Node.js: Supports all formats including .sps, .spb, .ce (Node-only processors)
203
276
  */
204
277
 
205
278
  type ProcessorOptions = Record<string, unknown> | undefined;
206
279
  /**
207
- * Load an AAC file from a file path (server-side only)
280
+ * Load an AAC file from a file path (Node.js only)
208
281
  *
209
282
  * @param filepath - Path to the AAC file
210
283
  * @param options - Processor options (e.g., pageLayoutPreference for SNAP)
@@ -217,47 +290,59 @@ type ProcessorOptions = Record<string, unknown> | undefined;
217
290
  */
218
291
  declare function loadAACFile(filepath: string, options?: ProcessorOptions): Promise<AACTree>;
219
292
  /**
220
- * Load an AAC file and return extended result with format info
293
+ * Load an AAC file from a File or Blob object (Browser only)
221
294
  *
222
- * @param filepath - Path to the AAC file
295
+ * @param file - File or Blob object
223
296
  * @param options - Processor options
224
- * @returns Promise resolving to LoadAACFileResult
297
+ * @returns Promise resolving to AACTree
298
+ *
299
+ * @example
300
+ * ```ts
301
+ * const input = document.querySelector('input[type="file"]');
302
+ * const file = input.files[0];
303
+ * const tree = await loadAACFile(file);
304
+ * ```
225
305
  */
226
- declare function loadAACFileWithMetadata(filepath: string, options?: ProcessorOptions): Promise<LoadAACFileResult>;
306
+ declare function loadAACFile(file: File | Blob, options?: ProcessorOptions): Promise<AACTree>;
227
307
  /**
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.
308
+ * Load an AAC file from an ArrayBuffer (Browser only)
232
309
  *
233
- * @param url - URL to the AAC file
310
+ * @param buffer - ArrayBuffer containing file data
311
+ * @param filename - Filename with extension to detect processor
234
312
  * @param options - Processor options
235
313
  * @returns Promise resolving to AACTree
236
314
  *
237
315
  * @example
238
316
  * ```ts
239
- * const tree = await loadAACFileFromURL('https://example.com/file.sps');
317
+ * const arrayBuffer = await file.arrayBuffer();
318
+ * const tree = await loadAACFile(arrayBuffer, 'board.obf');
240
319
  * ```
241
320
  */
242
- declare function loadAACFileFromURL(url: string, options?: ProcessorOptions): Promise<AACTree>;
321
+ declare function loadAACFile(buffer: ArrayBuffer, filename: string, options?: ProcessorOptions): Promise<AACTree>;
243
322
  /**
244
- * Load an AAC file from a File object (client-side file input)
323
+ * Load an AAC file from a URL (Browser only)
245
324
  *
246
- * @param file - File object from file input
325
+ * Note: This requires the server to provide the file with appropriate CORS headers.
326
+ * For better performance, consider using loadAACFileFromFile() with direct file upload instead.
327
+ *
328
+ * @param url - URL to the AAC file
247
329
  * @param options - Processor options
248
330
  * @returns Promise resolving to AACTree
249
331
  *
250
332
  * @example
251
333
  * ```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
- * };
334
+ * const tree = await loadAACFileFromURL('https://example.com/file.obf');
258
335
  * ```
259
336
  */
260
- declare function loadAACFileFromFile(_file: File | Blob, _filename?: string, _options?: unknown): Promise<AACTree>;
337
+ declare function loadAACFileFromURL(url: string, options?: ProcessorOptions): Promise<AACTree>;
338
+ /**
339
+ * Load an AAC file and return extended result with format info
340
+ *
341
+ * @param input - File path (Node.js), File/Blob (Browser), or URL string
342
+ * @param options - Processor options
343
+ * @returns Promise resolving to LoadAACFileResult
344
+ */
345
+ declare function loadAACFileWithMetadata(input: string | File | Blob, options?: ProcessorOptions): Promise<LoadAACFileResult>;
261
346
  /**
262
347
  * Calculate cognitive effort metrics for an AAC tree
263
348
  *
@@ -300,6 +385,22 @@ declare function getSupportedFormats(): Array<{
300
385
  name: string;
301
386
  extensions: string[];
302
387
  description: string;
388
+ browserCompatible: boolean;
303
389
  }>;
390
+ /**
391
+ * Check if a file format is compatible with browser processing
392
+ *
393
+ * @param extension - File extension (e.g., '.obf', 'obf')
394
+ * @returns true if browser-compatible, false if server-only
395
+ */
396
+ declare function isBrowserCompatible(extension: string): boolean;
397
+ /**
398
+ * Get list of browser-compatible file extensions
399
+ */
400
+ declare function getBrowserExtensions(): string[];
401
+ /**
402
+ * Get list of Node-only file extensions
403
+ */
404
+ declare function getNodeOnlyExtensions(): string[];
304
405
 
305
- export { BoardViewer, type BoardViewerProps, type ButtonMetric, type LoadAACFileResult, type MetricsOptions, calculateMetrics, getSupportedFormats, loadAACFile, loadAACFileFromFile, loadAACFileFromURL, loadAACFileWithMetadata, useAACFile, useAACFileWithMetrics, useMetrics, useSentenceBuilder };
406
+ export { BoardViewer, type BoardViewerProps, type ButtonMetric, type LoadAACFileResult, type MetricsOptions, calculateMetrics, getBrowserExtensions, getNodeOnlyExtensions, getSupportedFormats, isBrowserCompatible, loadAACFile, loadAACFileFromURL, loadAACFileWithMetadata, useAACFile, useAACFileFromFile, useAACFileFromFileWithMetrics, useAACFileWithMetrics, useMetrics, useSentenceBuilder };
package/dist/index.d.ts CHANGED
@@ -42,6 +42,8 @@ interface BoardViewerProps {
42
42
  onPageChange?: (pageId: string) => void;
43
43
  /** Custom CSS class name */
44
44
  className?: string;
45
+ /** Load ID for fetching images from server (for OBZ files) */
46
+ loadId?: string;
45
47
  }
46
48
  /**
47
49
  * Result from loading an AAC file
@@ -76,7 +78,7 @@ interface MetricsOptions {
76
78
  *
77
79
  * @param props - BoardViewerProps
78
80
  */
79
- declare function BoardViewer({ tree, buttonMetrics, showMessageBar, showEffortBadges, showLinkIndicators, initialPageId, onButtonClick, onPageChange, className, }: BoardViewerProps): react_jsx_runtime.JSX.Element;
81
+ declare function BoardViewer({ tree, buttonMetrics, showMessageBar, showEffortBadges, showLinkIndicators, initialPageId, onButtonClick, onPageChange, className, loadId, }: BoardViewerProps): react_jsx_runtime.JSX.Element;
80
82
 
81
83
  /**
82
84
  * React hooks for AAC Board Viewer
@@ -110,6 +112,38 @@ declare function useAACFile(url: string, options?: {
110
112
  error: Error | null;
111
113
  reload: () => Promise<void>;
112
114
  };
115
+ /**
116
+ * Hook to load an AAC file from a File object (Browser only)
117
+ *
118
+ * @param file - File object from file input
119
+ * @param options - Processor options
120
+ * @returns Object with tree, loading state, and error
121
+ *
122
+ * @example
123
+ * ```tsx
124
+ * function MyUploader() {
125
+ * const [file, setFile] = useState<File | null>(null);
126
+ * const { tree, loading, error } = useAACFileFromFile(file);
127
+ *
128
+ * return (
129
+ * <div>
130
+ * <input type="file" onChange={(e) => setFile(e.target.files?.[0])} />
131
+ * {loading && <div>Loading...</div>}
132
+ * {tree && <BoardViewer tree={tree} />}
133
+ * </div>
134
+ * );
135
+ * }
136
+ * ```
137
+ */
138
+ declare function useAACFileFromFile(file: File | Blob | null, options?: {
139
+ processorOptions?: Record<string, unknown>;
140
+ enabled?: boolean;
141
+ }): {
142
+ tree: AACTree | null;
143
+ loading: boolean;
144
+ error: Error | null;
145
+ reload: () => Promise<void>;
146
+ };
113
147
  /**
114
148
  * Hook to load an AAC file and calculate metrics
115
149
  *
@@ -142,6 +176,42 @@ declare function useAACFileWithMetrics(url: string, metricsOptions?: MetricsOpti
142
176
  error: Error | null;
143
177
  reload: () => Promise<void>;
144
178
  };
179
+ /**
180
+ * Hook to load an AAC file from a File object and calculate metrics
181
+ *
182
+ * @param file - File object from file input
183
+ * @param metricsOptions - Metrics calculation options
184
+ * @returns Object with tree, metrics, loading state, and error
185
+ *
186
+ * @example
187
+ * ```tsx
188
+ * function MyUploader() {
189
+ * const [file, setFile] = useState<File | null>(null);
190
+ * const { tree, metrics, loading, error } = useAACFileFromFileWithMetrics(
191
+ * file,
192
+ * { accessMethod: 'direct' }
193
+ * );
194
+ *
195
+ * return (
196
+ * <div>
197
+ * <input type="file" onChange={(e) => setFile(e.target.files?.[0])} />
198
+ * {loading && <div>Loading...</div>}
199
+ * {tree && <BoardViewer tree={tree} buttonMetrics={metrics} />}
200
+ * </div>
201
+ * );
202
+ * }
203
+ * ```
204
+ */
205
+ declare function useAACFileFromFileWithMetrics(file: File | Blob | null, metricsOptions?: MetricsOptions, fileOptions?: {
206
+ processorOptions?: Record<string, unknown>;
207
+ enabled?: boolean;
208
+ }): {
209
+ tree: AACTree | null;
210
+ metrics: ButtonMetric[] | null;
211
+ loading: boolean;
212
+ error: Error | null;
213
+ reload: () => Promise<void>;
214
+ };
145
215
  /**
146
216
  * Hook to calculate metrics for a tree
147
217
  *
@@ -199,12 +269,15 @@ declare function useSentenceBuilder(): {
199
269
  * AAC File Loading Utilities
200
270
  *
201
271
  * Provides utilities for loading AAC files from various sources
202
- * (URLs, File objects, file paths) in both client and server contexts.
272
+ * (File/Blob objects, file paths, URLs) in both browser and server contexts.
273
+ *
274
+ * Browser: Supports .obf, .obz, .gridset, .plist, .grd, .opml, .dot
275
+ * Node.js: Supports all formats including .sps, .spb, .ce (Node-only processors)
203
276
  */
204
277
 
205
278
  type ProcessorOptions = Record<string, unknown> | undefined;
206
279
  /**
207
- * Load an AAC file from a file path (server-side only)
280
+ * Load an AAC file from a file path (Node.js only)
208
281
  *
209
282
  * @param filepath - Path to the AAC file
210
283
  * @param options - Processor options (e.g., pageLayoutPreference for SNAP)
@@ -217,47 +290,59 @@ type ProcessorOptions = Record<string, unknown> | undefined;
217
290
  */
218
291
  declare function loadAACFile(filepath: string, options?: ProcessorOptions): Promise<AACTree>;
219
292
  /**
220
- * Load an AAC file and return extended result with format info
293
+ * Load an AAC file from a File or Blob object (Browser only)
221
294
  *
222
- * @param filepath - Path to the AAC file
295
+ * @param file - File or Blob object
223
296
  * @param options - Processor options
224
- * @returns Promise resolving to LoadAACFileResult
297
+ * @returns Promise resolving to AACTree
298
+ *
299
+ * @example
300
+ * ```ts
301
+ * const input = document.querySelector('input[type="file"]');
302
+ * const file = input.files[0];
303
+ * const tree = await loadAACFile(file);
304
+ * ```
225
305
  */
226
- declare function loadAACFileWithMetadata(filepath: string, options?: ProcessorOptions): Promise<LoadAACFileResult>;
306
+ declare function loadAACFile(file: File | Blob, options?: ProcessorOptions): Promise<AACTree>;
227
307
  /**
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.
308
+ * Load an AAC file from an ArrayBuffer (Browser only)
232
309
  *
233
- * @param url - URL to the AAC file
310
+ * @param buffer - ArrayBuffer containing file data
311
+ * @param filename - Filename with extension to detect processor
234
312
  * @param options - Processor options
235
313
  * @returns Promise resolving to AACTree
236
314
  *
237
315
  * @example
238
316
  * ```ts
239
- * const tree = await loadAACFileFromURL('https://example.com/file.sps');
317
+ * const arrayBuffer = await file.arrayBuffer();
318
+ * const tree = await loadAACFile(arrayBuffer, 'board.obf');
240
319
  * ```
241
320
  */
242
- declare function loadAACFileFromURL(url: string, options?: ProcessorOptions): Promise<AACTree>;
321
+ declare function loadAACFile(buffer: ArrayBuffer, filename: string, options?: ProcessorOptions): Promise<AACTree>;
243
322
  /**
244
- * Load an AAC file from a File object (client-side file input)
323
+ * Load an AAC file from a URL (Browser only)
245
324
  *
246
- * @param file - File object from file input
325
+ * Note: This requires the server to provide the file with appropriate CORS headers.
326
+ * For better performance, consider using loadAACFileFromFile() with direct file upload instead.
327
+ *
328
+ * @param url - URL to the AAC file
247
329
  * @param options - Processor options
248
330
  * @returns Promise resolving to AACTree
249
331
  *
250
332
  * @example
251
333
  * ```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
- * };
334
+ * const tree = await loadAACFileFromURL('https://example.com/file.obf');
258
335
  * ```
259
336
  */
260
- declare function loadAACFileFromFile(_file: File | Blob, _filename?: string, _options?: unknown): Promise<AACTree>;
337
+ declare function loadAACFileFromURL(url: string, options?: ProcessorOptions): Promise<AACTree>;
338
+ /**
339
+ * Load an AAC file and return extended result with format info
340
+ *
341
+ * @param input - File path (Node.js), File/Blob (Browser), or URL string
342
+ * @param options - Processor options
343
+ * @returns Promise resolving to LoadAACFileResult
344
+ */
345
+ declare function loadAACFileWithMetadata(input: string | File | Blob, options?: ProcessorOptions): Promise<LoadAACFileResult>;
261
346
  /**
262
347
  * Calculate cognitive effort metrics for an AAC tree
263
348
  *
@@ -300,6 +385,22 @@ declare function getSupportedFormats(): Array<{
300
385
  name: string;
301
386
  extensions: string[];
302
387
  description: string;
388
+ browserCompatible: boolean;
303
389
  }>;
390
+ /**
391
+ * Check if a file format is compatible with browser processing
392
+ *
393
+ * @param extension - File extension (e.g., '.obf', 'obf')
394
+ * @returns true if browser-compatible, false if server-only
395
+ */
396
+ declare function isBrowserCompatible(extension: string): boolean;
397
+ /**
398
+ * Get list of browser-compatible file extensions
399
+ */
400
+ declare function getBrowserExtensions(): string[];
401
+ /**
402
+ * Get list of Node-only file extensions
403
+ */
404
+ declare function getNodeOnlyExtensions(): string[];
304
405
 
305
- export { BoardViewer, type BoardViewerProps, type ButtonMetric, type LoadAACFileResult, type MetricsOptions, calculateMetrics, getSupportedFormats, loadAACFile, loadAACFileFromFile, loadAACFileFromURL, loadAACFileWithMetadata, useAACFile, useAACFileWithMetrics, useMetrics, useSentenceBuilder };
406
+ export { BoardViewer, type BoardViewerProps, type ButtonMetric, type LoadAACFileResult, type MetricsOptions, calculateMetrics, getBrowserExtensions, getNodeOnlyExtensions, getSupportedFormats, isBrowserCompatible, loadAACFile, loadAACFileFromURL, loadAACFileWithMetadata, useAACFile, useAACFileFromFile, useAACFileFromFileWithMetrics, useAACFileWithMetrics, useMetrics, useSentenceBuilder };