@willwade/aac-processors 0.1.10 → 0.1.12

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.
Files changed (52) hide show
  1. package/dist/browser/processors/gridset/resolver.js +10 -0
  2. package/dist/browser/processors/gridsetProcessor.js +128 -6
  3. package/dist/processors/gridset/resolver.js +10 -0
  4. package/dist/processors/gridsetProcessor.js +128 -6
  5. package/package.json +1 -3
  6. package/examples/.coverage +0 -0
  7. package/examples/.keep +0 -1
  8. package/examples/README.md +0 -55
  9. package/examples/browser-test.html +0 -331
  10. package/examples/communikate.dot +0 -2637
  11. package/examples/demo.js +0 -143
  12. package/examples/example-images.gridset +0 -0
  13. package/examples/example.ce +0 -0
  14. package/examples/example.dot +0 -14
  15. package/examples/example.grd +0 -1
  16. package/examples/example.gridset +0 -0
  17. package/examples/example.obf +0 -27
  18. package/examples/example.obz +0 -0
  19. package/examples/example.opml +0 -18
  20. package/examples/example.spb +0 -0
  21. package/examples/example.sps +0 -0
  22. package/examples/example2.grd +0 -1
  23. package/examples/obf/aboutme.json +0 -376
  24. package/examples/obf/array.json +0 -6
  25. package/examples/obf/hash.json +0 -4
  26. package/examples/obf/links.obz +0 -0
  27. package/examples/obf/simple.obf +0 -53
  28. package/examples/package-lock.json +0 -1326
  29. package/examples/package.json +0 -10
  30. package/examples/styled-output/converted-snap-to-touchchat.ce +0 -0
  31. package/examples/styled-output/styled-example.ce +0 -0
  32. package/examples/styled-output/styled-example.gridset +0 -0
  33. package/examples/styled-output/styled-example.obf +0 -37
  34. package/examples/styled-output/styled-example.spb +0 -0
  35. package/examples/styling-example.ts +0 -316
  36. package/examples/translate.js +0 -39
  37. package/examples/translate_demo.js +0 -254
  38. package/examples/typescript-demo.ts +0 -251
  39. package/examples/vitedemo/README.md +0 -164
  40. package/examples/vitedemo/index.html +0 -580
  41. package/examples/vitedemo/package-lock.json +0 -1751
  42. package/examples/vitedemo/package.json +0 -24
  43. package/examples/vitedemo/src/main.ts +0 -1001
  44. package/examples/vitedemo/src/vite-env.d.ts +0 -1
  45. package/examples/vitedemo/test-files/example.dot +0 -14
  46. package/examples/vitedemo/test-files/example.grd +0 -1
  47. package/examples/vitedemo/test-files/example.gridset +0 -0
  48. package/examples/vitedemo/test-files/example.obz +0 -0
  49. package/examples/vitedemo/test-files/example.opml +0 -18
  50. package/examples/vitedemo/test-files/simple.obf +0 -53
  51. package/examples/vitedemo/tsconfig.json +0 -24
  52. package/examples/vitedemo/vite.config.ts +0 -57
@@ -1,251 +0,0 @@
1
- #!/usr/bin/env ts-node
2
-
3
- /**
4
- * TypeScript Demo - AACProcessors 2.0
5
- *
6
- * This example demonstrates the new TypeScript API and features
7
- * including translation workflows and cross-format conversion.
8
- */
9
-
10
- import {
11
- getProcessor,
12
- DotProcessor,
13
- ObfProcessor,
14
- AACTree,
15
- AACPage,
16
- AACButton
17
- } from '../src/index';
18
- import fs from 'fs';
19
- import path from 'path';
20
-
21
- async function main() {
22
- console.log('🚀 AACProcessors 2.0 TypeScript Demo\n');
23
-
24
- // Example 1: Auto-detect processor by file extension
25
- console.log('📁 Example 1: Auto-detection');
26
- try {
27
- const dotFile = path.join(__dirname, 'example.dot');
28
- if (fs.existsSync(dotFile)) {
29
- const processor = getProcessor(dotFile);
30
- console.log(`✅ Detected processor: ${processor.constructor.name}`);
31
-
32
- const tree = processor.loadIntoTree(dotFile);
33
- console.log(`📊 Loaded ${Object.keys(tree.pages).length} pages`);
34
-
35
- const texts = processor.extractTexts(dotFile);
36
- console.log(`📝 Found ${texts.length} text elements`);
37
- } else {
38
- console.log('⚠️ example.dot not found, skipping auto-detection demo');
39
- }
40
- } catch (error) {
41
- console.error('❌ Auto-detection error:', error);
42
- }
43
-
44
- console.log('\n' + '='.repeat(50) + '\n');
45
-
46
- // Example 2: Create a communication board programmatically
47
- console.log('🏗️ Example 2: Programmatic Board Creation');
48
-
49
- const tree = new AACTree();
50
-
51
- // Create home page
52
- const homePage = new AACPage({
53
- id: 'home',
54
- name: 'Home Page',
55
- buttons: []
56
- });
57
-
58
- // Add buttons
59
- const greetingButton = new AACButton({
60
- id: 'btn_hello',
61
- label: 'Hello',
62
- message: 'Hello, how are you today?',
63
- type: 'SPEAK'
64
- });
65
-
66
- const foodButton = new AACButton({
67
- id: 'btn_food',
68
- label: 'Food',
69
- message: 'I want something to eat',
70
- type: 'NAVIGATE',
71
- targetPageId: 'food_page'
72
- });
73
-
74
- const drinkButton = new AACButton({
75
- id: 'btn_drink',
76
- label: 'Drink',
77
- message: 'I want something to drink',
78
- type: 'SPEAK'
79
- });
80
-
81
- homePage.addButton(greetingButton);
82
- homePage.addButton(foodButton);
83
- homePage.addButton(drinkButton);
84
- tree.addPage(homePage);
85
-
86
- // Create food page
87
- const foodPage = new AACPage({
88
- id: 'food_page',
89
- name: 'Food Options',
90
- buttons: []
91
- });
92
-
93
- const appleButton = new AACButton({
94
- id: 'btn_apple',
95
- label: 'Apple',
96
- message: 'I want an apple',
97
- type: 'SPEAK'
98
- });
99
-
100
- const backButton = new AACButton({
101
- id: 'btn_back',
102
- label: 'Back',
103
- message: 'Go back to home',
104
- type: 'NAVIGATE',
105
- targetPageId: 'home'
106
- });
107
-
108
- foodPage.addButton(appleButton);
109
- foodPage.addButton(backButton);
110
- tree.addPage(foodPage);
111
-
112
- tree.rootId = 'home';
113
-
114
- console.log(`✅ Created communication board with ${Object.keys(tree.pages).length} pages`);
115
-
116
- console.log('\n' + '='.repeat(50) + '\n');
117
-
118
- // Example 3: Save to multiple formats
119
- console.log('💾 Example 3: Cross-Format Conversion');
120
-
121
- const tempDir = path.join(__dirname, 'temp');
122
- if (!fs.existsSync(tempDir)) {
123
- fs.mkdirSync(tempDir);
124
- }
125
-
126
- try {
127
- // Save as DOT
128
- const dotProcessor = new DotProcessor();
129
- const dotPath = path.join(tempDir, 'demo-board.dot');
130
- dotProcessor.saveFromTree(tree, dotPath);
131
- console.log(`✅ Saved as DOT: ${dotPath}`);
132
-
133
- // Save as OBF
134
- const obfProcessor = new ObfProcessor();
135
- const obfPath = path.join(tempDir, 'demo-board.obf');
136
- obfProcessor.saveFromTree(tree, obfPath);
137
- console.log(`✅ Saved as OBF: ${obfPath}`);
138
-
139
- // Verify round-trip integrity
140
- const reloadedDotTree = dotProcessor.loadIntoTree(dotPath);
141
- const reloadedObfTree = obfProcessor.loadIntoTree(obfPath);
142
-
143
- console.log(`🔄 DOT round-trip: ${Object.keys(reloadedDotTree.pages).length} pages`);
144
- console.log(`🔄 OBF round-trip: ${Object.keys(reloadedObfTree.pages).length} pages`);
145
-
146
- } catch (error) {
147
- console.error('❌ Conversion error:', error);
148
- }
149
-
150
- console.log('\n' + '='.repeat(50) + '\n');
151
-
152
- // Example 4: Translation workflow
153
- console.log('🌍 Example 4: Translation Workflow');
154
-
155
- try {
156
- const dotPath = path.join(tempDir, 'demo-board.dot');
157
- if (fs.existsSync(dotPath)) {
158
- const processor = new DotProcessor();
159
-
160
- // Extract all text
161
- const originalTexts = processor.extractTexts(dotPath);
162
- console.log(`📝 Found ${originalTexts.length} translatable texts:`, originalTexts);
163
-
164
- // Create Spanish translations
165
- const translations = new Map([
166
- ['Hello', 'Hola'],
167
- ['Food', 'Comida'],
168
- ['Drink', 'Bebida'],
169
- ['Apple', 'Manzana'],
170
- ['Back', 'Atrás'],
171
- ['Home Page', 'Página Principal'],
172
- ['Food Options', 'Opciones de Comida'],
173
- ['Hello, how are you today?', 'Hola, ¿cómo estás hoy?'],
174
- ['I want something to eat', 'Quiero algo de comer'],
175
- ['I want something to drink', 'Quiero algo de beber'],
176
- ['I want an apple', 'Quiero una manzana'],
177
- ['Go back to home', 'Volver a casa']
178
- ]);
179
-
180
- // Apply translations
181
- const spanishPath = path.join(tempDir, 'demo-board-spanish.dot');
182
- const translatedBuffer = processor.processTexts(dotPath, translations, spanishPath);
183
-
184
- console.log(`✅ Applied ${translations.size} translations`);
185
- console.log(`💾 Saved Spanish version: ${spanishPath}`);
186
-
187
- // Verify translations
188
- const spanishTexts = processor.extractTexts(spanishPath);
189
- console.log(`🔍 Spanish texts:`, spanishTexts.slice(0, 5), '...');
190
-
191
- } else {
192
- console.log('⚠️ DOT file not found for translation demo');
193
- }
194
- } catch (error) {
195
- console.error('❌ Translation error:', error);
196
- }
197
-
198
- console.log('\n' + '='.repeat(50) + '\n');
199
-
200
- // Example 5: Error handling
201
- console.log('🛡️ Example 5: Error Handling');
202
-
203
- try {
204
- const processor = new DotProcessor();
205
-
206
- // Try to load a non-existent file
207
- try {
208
- processor.loadIntoTree('non-existent-file.dot');
209
- } catch (error) {
210
- console.log(`✅ Caught expected error: ${error instanceof Error ? error.message : error}`);
211
- }
212
-
213
- // Try to load invalid content
214
- try {
215
- const invalidContent = Buffer.from('This is not a valid DOT file');
216
- const tree = processor.loadIntoTree(invalidContent);
217
- console.log(`✅ Gracefully handled invalid content: ${Object.keys(tree.pages).length} pages`);
218
- } catch (error) {
219
- console.log(`✅ Handled invalid content error: ${error instanceof Error ? error.message : error}`);
220
- }
221
-
222
- } catch (error) {
223
- console.error('❌ Error handling demo failed:', error);
224
- }
225
-
226
- console.log('\n🎉 Demo completed successfully!');
227
- console.log('\n📚 For more examples, see:');
228
- console.log(' - README.md for API documentation');
229
- console.log(' - test/ directory for comprehensive usage examples');
230
- console.log(' - examples/ directory for more demos');
231
-
232
- // Cleanup
233
- try {
234
- if (fs.existsSync(tempDir)) {
235
- fs.rmSync(tempDir, { recursive: true, force: true });
236
- console.log('\n🧹 Cleaned up temporary files');
237
- }
238
- } catch (error) {
239
- console.warn('⚠️ Failed to clean up temporary files:', error);
240
- }
241
- }
242
-
243
- // Run the demo
244
- if (require.main === module) {
245
- main().catch(error => {
246
- console.error('❌ Demo failed:', error);
247
- process.exit(1);
248
- });
249
- }
250
-
251
- export { main as runDemo };
@@ -1,164 +0,0 @@
1
- # AAC Processors Browser Demo
2
-
3
- A real browser demo that uses Vite to bundle AACProcessors for browser use.
4
-
5
- ## Features
6
-
7
- - ✅ **Real file processing** - Upload and process actual AAC files
8
- - ✅ **All browser-compatible processors** - Tests Dot, OPML, OBF/OBZ, Gridset, Snap, TouchChat, ApplePanels, AstericsGrid
9
- - ✅ **Interactive UI** - Drag & drop files, view pages and buttons
10
- - ✅ **Text-to-speech** - Click SPEAK buttons to hear messages (browser speech API)
11
- - ✅ **Navigation** - Click NAVIGATE buttons to jump between pages
12
- - ✅ **Compatibility tests** - Automated tests for all processors
13
- - ✅ **Performance metrics** - Load time, page/button/text counts
14
- - ✅ **TypeScript** - Full type safety and IntelliSense
15
-
16
- ## Quick Start
17
-
18
- ### 1. Install Dependencies
19
-
20
- ```bash
21
- cd examples/vitedemo
22
- npm install
23
- ```
24
-
25
- ### 2. Run Dev Server
26
-
27
- ```bash
28
- npm run dev
29
- ```
30
-
31
- The demo will open automatically at: http://localhost:3000
32
-
33
- ### 3. Build for Production (Not Supported Yet)
34
-
35
- This demo is intended for `npm run dev` only. The production build currently fails because the
36
- demo source includes strict TypeScript issues, so it will not work "out of the box."
37
-
38
- This demo is the recommended browser test environment.
39
-
40
- ## How to Use
41
-
42
- 1. **Upload a file**
43
- - Drag & drop an AAC file onto the upload area
44
- - Or click to open file picker
45
- - Supported formats: .dot, .opml, .obf, .obz, .gridset, .sps, .spb, .ce, .plist, .grd
46
-
47
- 2. **Process the file**
48
- - Click "Process File" button
49
- - View pages and buttons in the right panel
50
- - Check stats: pages, buttons, texts, load time
51
-
52
- 3. **Interact with buttons**
53
- - Click SPEAK buttons to hear text (uses browser speech API)
54
- - Click NAVIGATE buttons to jump to target pages
55
-
56
- 4. **Run compatibility tests**
57
- - Click "Run Compatibility Tests"
58
- - See test results in the left panel
59
- - Tests all browser-compatible processors
60
-
61
- ## Supported File Types
62
-
63
- | Format | Extensions | Processor |
64
- |----------|-----------------|-------------------------|
65
- | DOT | .dot | DotProcessor |
66
- | OPML | .opml | OpmlProcessor |
67
- | OBF/OBZ | .obf, .obz | ObfProcessor |
68
- | Gridset | .gridset | GridsetProcessor |
69
- | Snap | .sps, .spb | SnapProcessor |
70
- | TouchChat| .ce | TouchChatProcessor |
71
- | Apple | .plist | ApplePanelsProcessor |
72
- | Asterics | .grd | AstericsGridProcessor |
73
-
74
- ## Test Files
75
-
76
- You can use test files from the parent directory:
77
-
78
- ```bash
79
- # From vitedemo directory
80
- ../../test/assets/dot/example.dot
81
- ../../test/assets/opml/example.opml
82
- ../../test/assets/obf/simple.obf
83
- ../../test/assets/gridset/example.gridset
84
- ../../test/assets/asterics/example.grd
85
- ```
86
-
87
- ## Technical Details
88
-
89
- ### Vite Configuration
90
-
91
- The demo uses a custom Vite config to import from the source TypeScript:
92
-
93
- ```typescript
94
- // vite.config.ts
95
- export default defineConfig({
96
- resolve: {
97
- alias: {
98
- 'aac-processors': path.resolve(__dirname, '../../src/index.browser.ts')
99
- }
100
- }
101
- });
102
- ```
103
-
104
- This allows direct TypeScript import without pre-building.
105
-
106
- ### Import Example (with SQLite WASM)
107
-
108
- ```typescript
109
- import { configureSqlJs, getProcessor } from 'aac-processors';
110
- import sqlWasmUrl from 'sql.js/dist/sql-wasm.wasm?url';
111
-
112
- configureSqlJs({
113
- locateFile: () => sqlWasmUrl
114
- });
115
-
116
- // Get processor for file type
117
- const processor = getProcessor('.obf');
118
-
119
- // Load file from input
120
- const arrayBuffer = await file.arrayBuffer();
121
- const tree = await processor.loadIntoTree(arrayBuffer);
122
-
123
- // Extract texts
124
- const texts = await processor.extractTexts(arrayBuffer);
125
- ```
126
-
127
- ## Troubleshooting
128
-
129
- ### Module not found errors
130
-
131
- Make sure you're in the `examples/vitedemo` directory and have run `npm install`.
132
-
133
- ### TypeScript errors
134
-
135
- Clear the Vite cache:
136
- ```bash
137
- rm -rf node_modules/.vite
138
- npm run dev
139
- ```
140
-
141
- ### File processing errors
142
-
143
- Check the browser console (F12) for detailed error messages. Common issues:
144
- - Invalid file format
145
- - Corrupted file
146
- - Unsupported file type (check extensions)
147
-
148
- ## Browser Compatibility
149
-
150
- - ✅ Chrome/Edge (recommended)
151
- - ✅ Firefox
152
- - ✅ Safari
153
- - ⚠️ Speech API works best in Chrome/Edge
154
-
155
- ## Next Steps
156
-
157
- This demonstrates that AACProcessors works in browsers with a bundler. To use in your own project:
158
-
159
- 1. Install AACProcessors: `npm install @willwade/aac-processors`
160
- 2. Set up Vite/Webpack/Rollup
161
- 3. Import from `'aac-processors'`
162
- 4. Use `getProcessor()` factory function
163
-
164
- See `docs/BROWSER_USAGE.md` for complete setup guides.