@willwade/aac-processors 0.1.20 → 0.2.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/dist/browser/core/baseProcessor.js +4 -0
- package/dist/browser/processors/applePanelsProcessor.js +33 -40
- package/dist/browser/processors/astericsGridProcessor.js +31 -26
- package/dist/browser/processors/dotProcessor.js +11 -12
- package/dist/browser/processors/gridset/colorUtils.js +354 -0
- package/dist/browser/processors/gridset/helpers.js +60 -53
- package/dist/browser/processors/gridset/index.js +61 -0
- package/dist/browser/processors/gridset/styleHelpers.js +205 -0
- package/dist/browser/processors/gridset/symbolExtractor.js +331 -0
- package/dist/browser/processors/gridset/symbolSearch.js +248 -0
- package/dist/browser/processors/gridset/symbols.js +39 -72
- package/dist/browser/processors/gridsetProcessor.js +39 -48
- package/dist/browser/processors/obfProcessor.js +39 -53
- package/dist/browser/processors/opmlProcessor.js +11 -12
- package/dist/browser/processors/snap/helpers.js +57 -49
- package/dist/browser/processors/snapProcessor.js +48 -51
- package/dist/browser/processors/touchchatProcessor.js +60 -52
- package/dist/browser/utilities/analytics/history.js +24 -18
- package/dist/browser/utilities/analytics/metrics/comparison.js +16 -16
- package/dist/browser/utilities/analytics/metrics/vocabulary.js +2 -2
- package/dist/browser/utilities/analytics/reference/browser.js +16 -16
- package/dist/browser/utilities/analytics/reference/index.js +44 -35
- package/dist/browser/utils/io.js +78 -21
- package/dist/browser/utils/sqlite.js +8 -10
- package/dist/browser/utils/zip.js +43 -43
- package/dist/browser/validation/baseValidator.js +5 -0
- package/dist/browser/validation/gridsetValidator.js +12 -20
- package/dist/browser/validation/obfValidator.js +6 -5
- package/dist/browser/validation/snapValidator.js +11 -7
- package/dist/browser/validation/touchChatValidator.js +23 -13
- package/dist/cli/index.js +22 -24
- package/dist/core/baseProcessor.d.ts +7 -7
- package/dist/core/baseProcessor.js +4 -0
- package/dist/processors/applePanelsProcessor.js +32 -39
- package/dist/processors/astericsGridProcessor.d.ts +4 -4
- package/dist/processors/astericsGridProcessor.js +30 -25
- package/dist/processors/dotProcessor.js +10 -11
- package/dist/processors/excelProcessor.d.ts +3 -3
- package/dist/processors/excelProcessor.js +14 -20
- package/dist/processors/gridset/helpers.d.ts +12 -14
- package/dist/processors/gridset/helpers.js +60 -79
- package/dist/processors/gridset/imageDebug.d.ts +3 -5
- package/dist/processors/gridset/imageDebug.js +4 -4
- package/dist/processors/gridset/password.d.ts +1 -1
- package/dist/processors/gridset/symbolExtractor.d.ts +5 -3
- package/dist/processors/gridset/symbolExtractor.js +15 -38
- package/dist/processors/gridset/symbolSearch.d.ts +11 -10
- package/dist/processors/gridset/symbolSearch.js +29 -51
- package/dist/processors/gridset/symbols.d.ts +8 -6
- package/dist/processors/gridset/symbols.js +38 -71
- package/dist/processors/gridset/wordlistHelpers.d.ts +4 -6
- package/dist/processors/gridset/wordlistHelpers.js +15 -74
- package/dist/processors/gridsetProcessor.d.ts +2 -2
- package/dist/processors/gridsetProcessor.js +38 -70
- package/dist/processors/obfProcessor.d.ts +2 -2
- package/dist/processors/obfProcessor.js +38 -75
- package/dist/processors/obfsetProcessor.js +2 -3
- package/dist/processors/opmlProcessor.js +10 -11
- package/dist/processors/snap/helpers.d.ts +9 -9
- package/dist/processors/snap/helpers.js +58 -76
- package/dist/processors/snapProcessor.d.ts +2 -2
- package/dist/processors/snapProcessor.js +47 -50
- package/dist/processors/touchchatProcessor.d.ts +2 -2
- package/dist/processors/touchchatProcessor.js +59 -51
- package/dist/types/aac.d.ts +2 -2
- package/dist/utilities/analytics/history.d.ts +8 -8
- package/dist/utilities/analytics/history.js +24 -18
- package/dist/utilities/analytics/index.d.ts +3 -2
- package/dist/utilities/analytics/index.js +9 -10
- package/dist/utilities/analytics/metrics/comparison.d.ts +1 -1
- package/dist/utilities/analytics/metrics/comparison.js +16 -16
- package/dist/utilities/analytics/metrics/vocabulary.d.ts +1 -1
- package/dist/utilities/analytics/metrics/vocabulary.js +2 -2
- package/dist/utilities/analytics/reference/browser.d.ts +9 -9
- package/dist/utilities/analytics/reference/browser.js +16 -16
- package/dist/utilities/analytics/reference/index.d.ts +25 -23
- package/dist/utilities/analytics/reference/index.js +43 -34
- package/dist/utilities/symbolTools.d.ts +8 -6
- package/dist/utilities/symbolTools.js +21 -18
- package/dist/utils/io.d.ts +24 -6
- package/dist/utils/io.js +79 -25
- package/dist/utils/sqlite.d.ts +3 -1
- package/dist/utils/sqlite.js +7 -9
- package/dist/utils/zip.d.ts +7 -3
- package/dist/utils/zip.js +43 -43
- package/dist/validation/applePanelsValidator.d.ts +2 -1
- package/dist/validation/applePanelsValidator.js +10 -11
- package/dist/validation/astericsValidator.d.ts +2 -1
- package/dist/validation/astericsValidator.js +5 -4
- package/dist/validation/baseValidator.d.ts +2 -2
- package/dist/validation/baseValidator.js +5 -0
- package/dist/validation/dotValidator.d.ts +2 -1
- package/dist/validation/dotValidator.js +5 -4
- package/dist/validation/excelValidator.d.ts +2 -1
- package/dist/validation/excelValidator.js +5 -4
- package/dist/validation/gridsetValidator.d.ts +2 -1
- package/dist/validation/gridsetValidator.js +11 -22
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +5 -4
- package/dist/validation/obfValidator.d.ts +2 -1
- package/dist/validation/obfValidator.js +5 -4
- package/dist/validation/obfsetValidator.d.ts +2 -1
- package/dist/validation/obfsetValidator.js +5 -4
- package/dist/validation/opmlValidator.d.ts +2 -1
- package/dist/validation/opmlValidator.js +5 -4
- package/dist/validation/snapValidator.d.ts +2 -1
- package/dist/validation/snapValidator.js +10 -6
- package/dist/validation/touchChatValidator.d.ts +4 -6
- package/dist/validation/touchChatValidator.js +22 -12
- package/dist/validation/validationTypes.d.ts +8 -1
- package/package.json +1 -1
- package/dist/core/fileProcessor.d.ts +0 -7
- package/dist/core/fileProcessor.js +0 -57
|
@@ -30,8 +30,8 @@ exports.TouchChatValidator = void 0;
|
|
|
30
30
|
const xml2js = __importStar(require("xml2js"));
|
|
31
31
|
const baseValidator_1 = require("./baseValidator");
|
|
32
32
|
const io_1 = require("../utils/io");
|
|
33
|
-
const zip_1 = require("../utils/zip");
|
|
34
33
|
const sqlite_1 = require("../utils/sqlite");
|
|
34
|
+
const zip_1 = require("../utils/zip");
|
|
35
35
|
/**
|
|
36
36
|
* Validator for TouchChat files (.ce)
|
|
37
37
|
* TouchChat files are ZIP archives that contain a .c4v SQLite database.
|
|
@@ -44,23 +44,26 @@ class TouchChatValidator extends baseValidator_1.BaseValidator {
|
|
|
44
44
|
/**
|
|
45
45
|
* Validate a TouchChat file from disk
|
|
46
46
|
*/
|
|
47
|
-
static async validateFile(filePath) {
|
|
47
|
+
static async validateFile(filePath, fileAdapter) {
|
|
48
|
+
const { readBinaryFromInput, getFileSize } = fileAdapter ?? io_1.defaultFileAdapter;
|
|
48
49
|
const validator = new TouchChatValidator();
|
|
49
|
-
const content =
|
|
50
|
-
const
|
|
51
|
-
return validator.validate(content, (0, io_1.getBasename)(filePath),
|
|
50
|
+
const content = await readBinaryFromInput(filePath);
|
|
51
|
+
const size = await getFileSize(filePath);
|
|
52
|
+
return validator.validate(content, (0, io_1.getBasename)(filePath), size);
|
|
52
53
|
}
|
|
53
54
|
/**
|
|
54
55
|
* Check if content is TouchChat format
|
|
55
56
|
*/
|
|
56
|
-
static async identifyFormat(content, filename, zipAdapter) {
|
|
57
|
+
static async identifyFormat(content, filename, fileAdapter = io_1.defaultFileAdapter, zipAdapter) {
|
|
57
58
|
const name = filename.toLowerCase();
|
|
58
59
|
if (name.endsWith('.ce')) {
|
|
59
60
|
return true;
|
|
60
61
|
}
|
|
61
62
|
// Try to parse as ZIP and check for .c4v database
|
|
62
63
|
try {
|
|
63
|
-
const
|
|
64
|
+
const zip = zipAdapter
|
|
65
|
+
? await zipAdapter(content)
|
|
66
|
+
: await (0, zip_1.getZipAdapter)(content, fileAdapter);
|
|
64
67
|
const entries = zip.listFiles();
|
|
65
68
|
if (entries.some((entry) => entry.toLowerCase().endsWith('.c4v'))) {
|
|
66
69
|
return true;
|
|
@@ -92,7 +95,9 @@ class TouchChatValidator extends baseValidator_1.BaseValidator {
|
|
|
92
95
|
}
|
|
93
96
|
});
|
|
94
97
|
const looksLikeXml = this.isXmlBuffer(content);
|
|
95
|
-
const zipped = looksLikeXml
|
|
98
|
+
const zipped = looksLikeXml
|
|
99
|
+
? false
|
|
100
|
+
: await this.tryValidateZipSqlite(content, this._options.fileAdapter, this._options.zipAdapter);
|
|
96
101
|
if (!zipped) {
|
|
97
102
|
let xmlObj = null;
|
|
98
103
|
await this.add_check('xml_parse', 'valid XML', async () => {
|
|
@@ -272,11 +277,13 @@ class TouchChatValidator extends baseValidator_1.BaseValidator {
|
|
|
272
277
|
}
|
|
273
278
|
return bytes[start] === 0x3c; // '<'
|
|
274
279
|
}
|
|
275
|
-
async tryValidateZipSqlite(content) {
|
|
280
|
+
async tryValidateZipSqlite(content, fileAdapter = io_1.defaultFileAdapter, zipAdapter) {
|
|
276
281
|
let usedZip = false;
|
|
277
282
|
await this.add_check('zip', 'TouchChat ZIP package', async () => {
|
|
278
283
|
try {
|
|
279
|
-
const
|
|
284
|
+
const zip = zipAdapter
|
|
285
|
+
? await zipAdapter(content)
|
|
286
|
+
: await (0, zip_1.getZipAdapter)(content, fileAdapter);
|
|
280
287
|
const entries = zip.listFiles();
|
|
281
288
|
const vocabEntry = entries.find((name) => name.toLowerCase().endsWith('.c4v'));
|
|
282
289
|
if (!vocabEntry) {
|
|
@@ -301,7 +308,10 @@ class TouchChatValidator extends baseValidator_1.BaseValidator {
|
|
|
301
308
|
await this.add_check('sqlite', 'valid TouchChat SQLite database', async () => {
|
|
302
309
|
let cleanup;
|
|
303
310
|
try {
|
|
304
|
-
const result = await (0, sqlite_1.openSqliteDatabase)(content, {
|
|
311
|
+
const result = await (0, sqlite_1.openSqliteDatabase)(content, {
|
|
312
|
+
readonly: true,
|
|
313
|
+
fileAdapter: this._options.fileAdapter,
|
|
314
|
+
});
|
|
305
315
|
const db = result.db;
|
|
306
316
|
cleanup = result.cleanup;
|
|
307
317
|
const tableRows = db
|
|
@@ -351,7 +361,7 @@ class TouchChatValidator extends baseValidator_1.BaseValidator {
|
|
|
351
361
|
}
|
|
352
362
|
finally {
|
|
353
363
|
if (cleanup) {
|
|
354
|
-
cleanup();
|
|
364
|
+
await cleanup();
|
|
355
365
|
}
|
|
356
366
|
}
|
|
357
367
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { FileAdapter, ProcessorInput } from '../utils/io';
|
|
2
|
+
import { ZipAdapter } from '../utils/zip';
|
|
1
3
|
/**
|
|
2
4
|
* Custom error class for validation errors
|
|
3
5
|
* Can be marked as a blocker to stop validation immediately
|
|
@@ -45,14 +47,19 @@ export interface ValidationResult {
|
|
|
45
47
|
/**
|
|
46
48
|
* Options for validation behavior
|
|
47
49
|
*/
|
|
48
|
-
export interface
|
|
50
|
+
export interface ValidationConfig {
|
|
49
51
|
/** Whether to include warnings in validation (default: true) */
|
|
50
52
|
includeWarnings?: boolean;
|
|
51
53
|
/** Whether to stop on first blocker error (default: true) */
|
|
52
54
|
stopOnBlocker?: boolean;
|
|
53
55
|
/** Custom validation rules to apply */
|
|
54
56
|
customRules?: ValidationRule[];
|
|
57
|
+
/** Adapter for handling file IO (optional) */
|
|
58
|
+
fileAdapter: FileAdapter;
|
|
59
|
+
/** Adapter for handling ZIP files (optional) */
|
|
60
|
+
zipAdapter: (input: ProcessorInput) => Promise<ZipAdapter>;
|
|
55
61
|
}
|
|
62
|
+
export type ValidationOptions = Partial<ValidationConfig>;
|
|
56
63
|
/**
|
|
57
64
|
* Custom validation rule that can be added
|
|
58
65
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willwade/aac-processors",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A comprehensive TypeScript library for processing AAC (Augmentative and Alternative Communication) file formats with translation support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"browser": "dist/browser/index.browser.js",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type FileFormat = 'gridset' | 'coughdrop' | 'touchchat' | 'snap' | 'dot' | 'opml' | 'excel' | 'unknown';
|
|
2
|
-
declare class FileProcessor {
|
|
3
|
-
static readFile(filePath: string): Buffer;
|
|
4
|
-
static writeFile(filePath: string, data: Buffer | string): void;
|
|
5
|
-
static detectFormat(filePathOrBuffer: string | Buffer): FileFormat;
|
|
6
|
-
}
|
|
7
|
-
export default FileProcessor;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
class FileProcessor {
|
|
9
|
-
// Read a file and return its contents as a Buffer
|
|
10
|
-
static readFile(filePath) {
|
|
11
|
-
return fs_1.default.readFileSync(filePath);
|
|
12
|
-
}
|
|
13
|
-
// Write data (Buffer or string) to a file
|
|
14
|
-
static writeFile(filePath, data) {
|
|
15
|
-
fs_1.default.writeFileSync(filePath, data);
|
|
16
|
-
}
|
|
17
|
-
// Detect file format based on extension or magic bytes
|
|
18
|
-
static detectFormat(filePathOrBuffer) {
|
|
19
|
-
if (typeof filePathOrBuffer === 'string') {
|
|
20
|
-
const ext = path_1.default.extname(filePathOrBuffer).toLowerCase();
|
|
21
|
-
const fileName = path_1.default.basename(filePathOrBuffer).toLowerCase();
|
|
22
|
-
// Handle double extensions like .sub.zip
|
|
23
|
-
if (fileName.endsWith('.sub.zip') || ext === '.sub') {
|
|
24
|
-
return 'snap';
|
|
25
|
-
}
|
|
26
|
-
switch (ext) {
|
|
27
|
-
case '.gridset':
|
|
28
|
-
case '.gridsetx':
|
|
29
|
-
return 'gridset';
|
|
30
|
-
case '.obf':
|
|
31
|
-
case '.obz':
|
|
32
|
-
return 'coughdrop';
|
|
33
|
-
case '.ce':
|
|
34
|
-
case '.wfl':
|
|
35
|
-
case '.touchchat':
|
|
36
|
-
return 'touchchat';
|
|
37
|
-
case '.sps':
|
|
38
|
-
case '.spb':
|
|
39
|
-
return 'snap';
|
|
40
|
-
case '.dot':
|
|
41
|
-
return 'dot';
|
|
42
|
-
case '.opml':
|
|
43
|
-
return 'opml';
|
|
44
|
-
case '.xlsx':
|
|
45
|
-
return 'excel';
|
|
46
|
-
default:
|
|
47
|
-
return 'unknown';
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else if (Buffer.isBuffer(filePathOrBuffer)) {
|
|
51
|
-
// Optionally: inspect magic bytes here
|
|
52
|
-
return 'unknown';
|
|
53
|
-
}
|
|
54
|
-
return 'unknown';
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.default = FileProcessor;
|