Skip to content

Commit 89ad805

Browse files
authored
Merge pull request #16 from willwade/full-browser-migration
Full browser migration
2 parents 3805fda + f95dde3 commit 89ad805

31 files changed

Lines changed: 1219 additions & 416 deletions

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ const texts = await snap.extractTexts('board.sps');
3030
Browser-safe entry that avoids Node-only dependencies. It expects `Buffer`,
3131
`Uint8Array`, or `ArrayBuffer` inputs rather than file paths.
3232

33+
SQLite-backed formats (Snap `.sps/.spb` and TouchChat `.ce`) require a WASM
34+
SQLite engine. Configure `sql.js` in your bundler before loading those formats:
35+
36+
```ts
37+
import { configureSqlJs, SnapProcessor } from '@willwade/aac-processors/browser';
38+
39+
configureSqlJs({
40+
locateFile: (file) => new URL(`./${file}`, import.meta.url).toString(),
41+
});
42+
43+
const snap = new SnapProcessor();
44+
const tree = await snap.loadIntoTree(snapUint8Array);
45+
```
46+
3347
```ts
3448
import { GridsetProcessor } from '@willwade/aac-processors/browser';
3549

docs/BROWSER_USAGE.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -565,14 +565,7 @@ async function safeLoadFile(file) {
565565

566566
## Testing
567567

568-
See [Browser Test Page](../examples/browser-test.html) for interactive testing.
569-
570-
To run the test server:
571-
```bash
572-
node examples/browser-test-server.js
573-
```
574-
575-
Then open: http://localhost:8080/examples/browser-test.html
568+
Use the Vite demo in `examples/vitedemo` for interactive browser testing.
576569

577570
## Troubleshooting
578571

@@ -614,5 +607,4 @@ await processor.loadIntoTree(uint8Array);
614607

615608
- [API Documentation](./API.md)
616609
- [Examples](../examples/)
617-
- [Browser Test Page](../examples/browser-test.html)
618-
- [Test Server](../examples/browser-test-server.js)
610+
- [Vite Browser Demo](../examples/vitedemo)

examples/README.md

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -49,79 +49,7 @@ These pagesets are used by:
4949

5050
To run demo scripts that use these pagesets, see the [scripts/README.md](../scripts/README.md).
5151

52-
## Browser Testing
52+
## Browser Demo (Vite)
5353

54-
### ⚠️ Important Note
55-
56-
AACProcessors is built with TypeScript and outputs CommonJS modules. To use it in a browser, you **must use a bundler** (Vite, Webpack, Rollup, etc.). The browser test page below only validates the library structure - it cannot run actual processors without a bundler.
57-
58-
### Browser Test Page
59-
60-
A dedicated browser test page is available for validating the library structure:
61-
62-
**Start the test server:**
63-
```bash
64-
node examples/browser-test-server.js
65-
```
66-
67-
**Open in your browser:**
68-
```
69-
http://localhost:8080/examples/browser-test.html
70-
```
71-
72-
**What it tests:**
73-
- ✅ Browser build files exist and are accessible
74-
- ✅ Type definitions are present
75-
- ✅ Processor exports are available
76-
-**Does NOT run actual processors** (requires bundler)
77-
78-
### What Gets Tested
79-
80-
The browser test page (`browser-test.html`) verifies:
81-
82-
1. **Module Loading** - Can the browser load the ES modules?
83-
2. **Factory Functions** - Do `getProcessor()` and `getSupportedExtensions()` work?
84-
3. **Processor Instantiation** - Can processors be created?
85-
4. **File Loading** - Can files be loaded from `<input type="file">`?
86-
5. **Buffer Handling** - Do ArrayBuffers/Uint8Arrays work correctly?
87-
6. **Tree Structure** - Can AACTree be created from files?
88-
7. **Text Extraction** - Can texts be extracted from files?
89-
90-
### Supported File Types in Browser
91-
92-
The browser test page supports all browser-compatible processors:
93-
94-
- **DotProcessor** (.dot) - OpenSymbols Board files
95-
- **OpmlProcessor** (.opml) - OPML outline files
96-
- **ObfProcessor** (.obf/.obz) - Open Board Format files
97-
- **GridsetProcessor** (.gridset) - Grid 3 gridset files (not .gridsetx)
98-
- **ApplePanelsProcessor** (.plist) - Apple Panels files
99-
- **AstericsGridProcessor** (.grd) - Asterics Grid files
100-
101-
### Manual Testing
102-
103-
1. Open the browser console (F12 or Cmd+Option+I)
104-
2. Click "Select a file to test" to upload an AAC file
105-
3. Click "Test File" to process it
106-
4. Check the results panel for page count, button count, and extracted texts
107-
108-
### Automated Tests
109-
110-
Click "Run All Browser Tests" to run automated checks:
111-
- Factory function tests
112-
- Extension support tests
113-
- Processor instantiation tests
114-
- Buffer handling tests
115-
116-
### Node-Only Processors
117-
118-
The following processors are **not available** in the browser:
119-
- **SnapProcessor** (.spb/.sps) - Requires SQLite
120-
- **TouchChatProcessor** (.ce) - Requires SQLite
121-
- **ExcelProcessor** (.xlsx) - Uses fs at top level
122-
123-
### Notes
124-
125-
- Gridset `.gridsetx` files (encrypted) are not supported in browser
126-
- All processors work with Buffer, Uint8Array, and ArrayBuffer inputs
127-
- File paths are not supported in browser (use file inputs or fetch)
54+
For browser testing, use the Vite demo in `examples/vitedemo`. It bundles the
55+
library and exercises real processors in a browser environment.

examples/browser-test-server.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

examples/vitedemo/README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A real browser demo that uses Vite to bundle AACProcessors for browser use.
55
## Features
66

77
-**Real file processing** - Upload and process actual AAC files
8-
-**All browser-compatible processors** - Tests Dot, OPML, OBF/OBZ, Gridset, ApplePanels, AstericsGrid
8+
-**All browser-compatible processors** - Tests Dot, OPML, OBF/OBZ, Gridset, Snap, TouchChat, ApplePanels, AstericsGrid
99
-**Interactive UI** - Drag & drop files, view pages and buttons
1010
-**Text-to-speech** - Click SPEAK buttons to hear messages (browser speech API)
1111
-**Navigation** - Click NAVIGATE buttons to jump between pages
@@ -35,15 +35,14 @@ The demo will open automatically at: http://localhost:3000
3535
This demo is intended for `npm run dev` only. The production build currently fails because the
3636
demo source includes strict TypeScript issues, so it will not work "out of the box."
3737

38-
If you need a no-build browser check, use the browser test page served by:
39-
`node examples/browser-test-server.js`
38+
This demo is the recommended browser test environment.
4039

4140
## How to Use
4241

4342
1. **Upload a file**
4443
- Drag & drop an AAC file onto the upload area
4544
- Or click to open file picker
46-
- Supported formats: .dot, .opml, .obf, .obz, .gridset, .plist, .grd
45+
- Supported formats: .dot, .opml, .obf, .obz, .gridset, .sps, .spb, .ce, .plist, .grd
4746

4847
2. **Process the file**
4948
- Click "Process File" button
@@ -57,7 +56,7 @@ If you need a no-build browser check, use the browser test page served by:
5756
4. **Run compatibility tests**
5857
- Click "Run Compatibility Tests"
5958
- See test results in the left panel
60-
- Tests all 6 browser-compatible processors
59+
- Tests all browser-compatible processors
6160

6261
## Supported File Types
6362

@@ -67,6 +66,8 @@ If you need a no-build browser check, use the browser test page served by:
6766
| OPML | .opml | OpmlProcessor |
6867
| OBF/OBZ | .obf, .obz | ObfProcessor |
6968
| Gridset | .gridset | GridsetProcessor |
69+
| Snap | .sps, .spb | SnapProcessor |
70+
| TouchChat| .ce | TouchChatProcessor |
7071
| Apple | .plist | ApplePanelsProcessor |
7172
| Asterics | .grd | AstericsGridProcessor |
7273

@@ -102,10 +103,15 @@ export default defineConfig({
102103

103104
This allows direct TypeScript import without pre-building.
104105

105-
### Import Example
106+
### Import Example (with SQLite WASM)
106107

107108
```typescript
108-
import { getProcessor } from 'aac-processors';
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+
});
109115

110116
// Get processor for file type
111117
const processor = getProcessor('.obf');

examples/vitedemo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,11 @@ <h1>🎯 AAC Processors Browser Demo</h1>
423423
<div class="upload-icon">📤</div>
424424
<p><strong>Drop file here</strong> or click to upload</p>
425425
<p style="font-size: 12px; color: #999; margin-top: 5px;">
426-
Supports: .dot, .opml, .obf, .obz, .gridset, .plist, .grd
426+
Supports: .dot, .opml, .obf, .obz, .gridset, .sps, .spb, .ce, .plist, .grd
427427
</p>
428428
</div>
429429

430-
<input type="file" id="fileInput" accept=".dot,.opml,.obf,.obz,.gridset,.plist,.grd">
430+
<input type="file" id="fileInput" accept=".dot,.opml,.obf,.obz,.gridset,.sps,.spb,.ce,.plist,.grd">
431431

432432
<div id="fileInfo" style="display: none;">
433433
<div class="processor-info">

examples/vitedemo/package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/vitedemo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@willwade/aac-processors": "file:../..",
1717
"events": "^3.3.0",
1818
"jszip": "^3.10.1",
19+
"sql.js": "^1.13.0",
1920
"stream-browserify": "^3.0.0",
2021
"timers-browserify": "^2.0.12",
2122
"util": "^0.12.5"

0 commit comments

Comments
 (0)