@willwade/aac-processors 0.0.3
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/LICENSE +674 -0
- package/README.md +787 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +189 -0
- package/dist/cli/prettyPrint.d.ts +2 -0
- package/dist/cli/prettyPrint.js +28 -0
- package/dist/core/analyze.d.ts +6 -0
- package/dist/core/analyze.js +49 -0
- package/dist/core/baseProcessor.d.ts +94 -0
- package/dist/core/baseProcessor.js +208 -0
- package/dist/core/fileProcessor.d.ts +7 -0
- package/dist/core/fileProcessor.js +51 -0
- package/dist/core/stringCasing.d.ts +37 -0
- package/dist/core/stringCasing.js +174 -0
- package/dist/core/treeStructure.d.ts +190 -0
- package/dist/core/treeStructure.js +223 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +96 -0
- package/dist/optional/symbolTools.d.ts +28 -0
- package/dist/optional/symbolTools.js +126 -0
- package/dist/processors/applePanelsProcessor.d.ts +23 -0
- package/dist/processors/applePanelsProcessor.js +521 -0
- package/dist/processors/astericsGridProcessor.d.ts +49 -0
- package/dist/processors/astericsGridProcessor.js +1427 -0
- package/dist/processors/dotProcessor.d.ts +21 -0
- package/dist/processors/dotProcessor.js +191 -0
- package/dist/processors/excelProcessor.d.ts +145 -0
- package/dist/processors/excelProcessor.js +556 -0
- package/dist/processors/gridset/helpers.d.ts +4 -0
- package/dist/processors/gridset/helpers.js +48 -0
- package/dist/processors/gridset/resolver.d.ts +8 -0
- package/dist/processors/gridset/resolver.js +100 -0
- package/dist/processors/gridsetProcessor.d.ts +28 -0
- package/dist/processors/gridsetProcessor.js +1339 -0
- package/dist/processors/index.d.ts +14 -0
- package/dist/processors/index.js +42 -0
- package/dist/processors/obfProcessor.d.ts +21 -0
- package/dist/processors/obfProcessor.js +278 -0
- package/dist/processors/opmlProcessor.d.ts +21 -0
- package/dist/processors/opmlProcessor.js +235 -0
- package/dist/processors/snap/helpers.d.ts +4 -0
- package/dist/processors/snap/helpers.js +27 -0
- package/dist/processors/snapProcessor.d.ts +44 -0
- package/dist/processors/snapProcessor.js +586 -0
- package/dist/processors/touchchat/helpers.d.ts +4 -0
- package/dist/processors/touchchat/helpers.js +27 -0
- package/dist/processors/touchchatProcessor.d.ts +27 -0
- package/dist/processors/touchchatProcessor.js +768 -0
- package/dist/types/aac.d.ts +47 -0
- package/dist/types/aac.js +2 -0
- package/docs/.keep +1 -0
- package/docs/ApplePanels.md +309 -0
- package/docs/Grid3-XML-Format.md +1788 -0
- package/docs/TobiiDynavox-Snap-Details.md +394 -0
- package/docs/asterics-Grid-fileformat-details.md +443 -0
- package/docs/obf_.obz Open Board File Formats.md +432 -0
- package/docs/touchchat.md +520 -0
- package/examples/.coverage +0 -0
- package/examples/.keep +1 -0
- package/examples/README.md +31 -0
- package/examples/communikate.dot +2637 -0
- package/examples/demo.js +143 -0
- package/examples/example-images.gridset +0 -0
- package/examples/example.ce +0 -0
- package/examples/example.dot +14 -0
- package/examples/example.grd +1 -0
- package/examples/example.gridset +0 -0
- package/examples/example.obf +27 -0
- package/examples/example.obz +0 -0
- package/examples/example.opml +18 -0
- package/examples/example.spb +0 -0
- package/examples/example.sps +0 -0
- package/examples/example2.grd +1 -0
- package/examples/gemini_response.txt +845 -0
- package/examples/image-map.js +45 -0
- package/examples/package-lock.json +1326 -0
- package/examples/package.json +10 -0
- package/examples/styled-output/converted-snap-to-touchchat.ce +0 -0
- package/examples/styled-output/styled-example.ce +0 -0
- package/examples/styled-output/styled-example.gridset +0 -0
- package/examples/styled-output/styled-example.obf +37 -0
- package/examples/styled-output/styled-example.spb +0 -0
- package/examples/styling-example.ts +316 -0
- package/examples/translate.js +39 -0
- package/examples/translate_demo.js +254 -0
- package/examples/translation_cache.json +44894 -0
- package/examples/typescript-demo.ts +251 -0
- package/examples/unified-interface-demo.ts +183 -0
- package/package.json +106 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.getProcessor = getProcessor;
|
|
18
|
+
exports.getSupportedExtensions = getSupportedExtensions;
|
|
19
|
+
exports.isExtensionSupported = isExtensionSupported;
|
|
20
|
+
// Main entry point for AACProcessors library
|
|
21
|
+
__exportStar(require("./core/treeStructure"), exports);
|
|
22
|
+
__exportStar(require("./core/baseProcessor"), exports);
|
|
23
|
+
__exportStar(require("./core/stringCasing"), exports);
|
|
24
|
+
__exportStar(require("./processors"), exports);
|
|
25
|
+
const dotProcessor_1 = require("./processors/dotProcessor");
|
|
26
|
+
const excelProcessor_1 = require("./processors/excelProcessor");
|
|
27
|
+
const opmlProcessor_1 = require("./processors/opmlProcessor");
|
|
28
|
+
const obfProcessor_1 = require("./processors/obfProcessor");
|
|
29
|
+
const gridsetProcessor_1 = require("./processors/gridsetProcessor");
|
|
30
|
+
const snapProcessor_1 = require("./processors/snapProcessor");
|
|
31
|
+
const touchchatProcessor_1 = require("./processors/touchchatProcessor");
|
|
32
|
+
const applePanelsProcessor_1 = require("./processors/applePanelsProcessor");
|
|
33
|
+
const astericsGridProcessor_1 = require("./processors/astericsGridProcessor");
|
|
34
|
+
/**
|
|
35
|
+
* Factory function to get the appropriate processor for a file extension
|
|
36
|
+
* @param filePathOrExtension - File path or extension (e.g., '.dot', '/path/to/file.obf')
|
|
37
|
+
* @returns The appropriate processor instance
|
|
38
|
+
* @throws Error if the file extension is not supported
|
|
39
|
+
*/
|
|
40
|
+
function getProcessor(filePathOrExtension) {
|
|
41
|
+
// Extract extension from file path
|
|
42
|
+
const extension = filePathOrExtension.includes('.')
|
|
43
|
+
? filePathOrExtension.substring(filePathOrExtension.lastIndexOf('.'))
|
|
44
|
+
: filePathOrExtension;
|
|
45
|
+
switch (extension.toLowerCase()) {
|
|
46
|
+
case '.dot':
|
|
47
|
+
return new dotProcessor_1.DotProcessor();
|
|
48
|
+
case '.xlsx':
|
|
49
|
+
return new excelProcessor_1.ExcelProcessor();
|
|
50
|
+
case '.opml':
|
|
51
|
+
return new opmlProcessor_1.OpmlProcessor();
|
|
52
|
+
case '.obf':
|
|
53
|
+
case '.obz':
|
|
54
|
+
return new obfProcessor_1.ObfProcessor();
|
|
55
|
+
case '.gridset':
|
|
56
|
+
return new gridsetProcessor_1.GridsetProcessor();
|
|
57
|
+
case '.spb':
|
|
58
|
+
case '.sps':
|
|
59
|
+
return new snapProcessor_1.SnapProcessor();
|
|
60
|
+
case '.ce':
|
|
61
|
+
return new touchchatProcessor_1.TouchChatProcessor();
|
|
62
|
+
case '.plist':
|
|
63
|
+
return new applePanelsProcessor_1.ApplePanelsProcessor();
|
|
64
|
+
case '.grd':
|
|
65
|
+
return new astericsGridProcessor_1.AstericsGridProcessor();
|
|
66
|
+
default:
|
|
67
|
+
throw new Error(`Unsupported file extension: ${extension}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get all supported file extensions
|
|
72
|
+
* @returns Array of supported file extensions
|
|
73
|
+
*/
|
|
74
|
+
function getSupportedExtensions() {
|
|
75
|
+
return [
|
|
76
|
+
'.dot',
|
|
77
|
+
'.xlsx',
|
|
78
|
+
'.opml',
|
|
79
|
+
'.obf',
|
|
80
|
+
'.obz',
|
|
81
|
+
'.gridset',
|
|
82
|
+
'.spb',
|
|
83
|
+
'.sps',
|
|
84
|
+
'.ce',
|
|
85
|
+
'.plist',
|
|
86
|
+
'.grd',
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check if a file extension is supported
|
|
91
|
+
* @param extension - File extension to check
|
|
92
|
+
* @returns True if the extension is supported
|
|
93
|
+
*/
|
|
94
|
+
function isExtensionSupported(extension) {
|
|
95
|
+
return getSupportedExtensions().includes(extension.toLowerCase());
|
|
96
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare abstract class SymbolExtractor {
|
|
2
|
+
abstract getSymbolReferences(filePath: string): string[];
|
|
3
|
+
}
|
|
4
|
+
export declare abstract class SymbolResolver {
|
|
5
|
+
protected symbolPath: string;
|
|
6
|
+
protected dbPath: string;
|
|
7
|
+
constructor(symbolPath: string, dbPath: string);
|
|
8
|
+
abstract resolveSymbol(symbolRef: string): string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare class SnapSymbolExtractor extends SymbolExtractor {
|
|
11
|
+
getSymbolReferences(filePath: string): string[];
|
|
12
|
+
}
|
|
13
|
+
export declare class SnapSymbolResolver extends SymbolResolver {
|
|
14
|
+
resolveSymbol(symbolRef: string): string | null;
|
|
15
|
+
}
|
|
16
|
+
export declare class Grid3SymbolExtractor extends SymbolExtractor {
|
|
17
|
+
getSymbolReferences(filePath: string): string[];
|
|
18
|
+
}
|
|
19
|
+
export declare class Grid3SymbolResolver extends SymbolResolver {
|
|
20
|
+
resolveSymbol(symbolRef: string): string | null;
|
|
21
|
+
}
|
|
22
|
+
export declare class TouchChatSymbolExtractor extends SymbolExtractor {
|
|
23
|
+
getSymbolReferences(_filePath: string): string[];
|
|
24
|
+
}
|
|
25
|
+
export declare class TouchChatSymbolResolver extends SymbolResolver {
|
|
26
|
+
resolveSymbol(symbolRef: string): string | null;
|
|
27
|
+
}
|
|
28
|
+
export declare function resolveSymbol(label: string, symbolDir: string): string | null;
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
exports.TouchChatSymbolResolver = exports.TouchChatSymbolExtractor = exports.Grid3SymbolResolver = exports.Grid3SymbolExtractor = exports.SnapSymbolResolver = exports.SnapSymbolExtractor = exports.SymbolResolver = exports.SymbolExtractor = void 0;
|
|
7
|
+
exports.resolveSymbol = resolveSymbol;
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
// --- Base Classes ---
|
|
11
|
+
class SymbolExtractor {
|
|
12
|
+
}
|
|
13
|
+
exports.SymbolExtractor = SymbolExtractor;
|
|
14
|
+
class SymbolResolver {
|
|
15
|
+
constructor(symbolPath, dbPath) {
|
|
16
|
+
this.symbolPath = symbolPath;
|
|
17
|
+
this.dbPath = dbPath;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.SymbolResolver = SymbolResolver;
|
|
21
|
+
// --- Snap (Tobii Dynavox) ---
|
|
22
|
+
let Database = null;
|
|
23
|
+
try {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
25
|
+
Database = require('better-sqlite3');
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
Database = null;
|
|
29
|
+
}
|
|
30
|
+
class SnapSymbolExtractor extends SymbolExtractor {
|
|
31
|
+
getSymbolReferences(filePath) {
|
|
32
|
+
if (!Database)
|
|
33
|
+
throw new Error('better-sqlite3 not installed');
|
|
34
|
+
const db = new Database(filePath, { readonly: true });
|
|
35
|
+
const rows = db
|
|
36
|
+
.prepare('SELECT DISTINCT LibrarySymbolId FROM Button WHERE LibrarySymbolId IS NOT NULL')
|
|
37
|
+
.all();
|
|
38
|
+
db.close();
|
|
39
|
+
return rows.map((row) => String(row.LibrarySymbolId));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.SnapSymbolExtractor = SnapSymbolExtractor;
|
|
43
|
+
class SnapSymbolResolver extends SymbolResolver {
|
|
44
|
+
resolveSymbol(symbolRef) {
|
|
45
|
+
if (!Database)
|
|
46
|
+
throw new Error('better-sqlite3 not installed');
|
|
47
|
+
const db = new Database(this.dbPath, { readonly: true });
|
|
48
|
+
const query = 'SELECT ImageData FROM Symbol WHERE Id = ?';
|
|
49
|
+
const row = db.prepare(query).get(symbolRef);
|
|
50
|
+
db.close();
|
|
51
|
+
if (!row)
|
|
52
|
+
return null;
|
|
53
|
+
const outPath = path_1.default.join(this.symbolPath, `${symbolRef}.png`);
|
|
54
|
+
fs_1.default.writeFileSync(outPath, row.ImageData);
|
|
55
|
+
return outPath;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.SnapSymbolResolver = SnapSymbolResolver;
|
|
59
|
+
// --- Grid 3 ---
|
|
60
|
+
let AdmZip = null;
|
|
61
|
+
let XMLParser = null;
|
|
62
|
+
try {
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
64
|
+
AdmZip = require('adm-zip');
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
66
|
+
XMLParser = require('fast-xml-parser').XMLParser;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
AdmZip = null;
|
|
70
|
+
XMLParser = null;
|
|
71
|
+
}
|
|
72
|
+
class Grid3SymbolExtractor extends SymbolExtractor {
|
|
73
|
+
getSymbolReferences(filePath) {
|
|
74
|
+
if (!AdmZip || !XMLParser)
|
|
75
|
+
throw new Error('adm-zip or fast-xml-parser not installed');
|
|
76
|
+
const zip = new AdmZip(filePath);
|
|
77
|
+
const parser = new XMLParser();
|
|
78
|
+
const refs = new Set();
|
|
79
|
+
zip.getEntries().forEach((entry) => {
|
|
80
|
+
if (entry.entryName.endsWith('.gridset')) {
|
|
81
|
+
const xmlBuffer = entry.getData();
|
|
82
|
+
// Parse to validate XML structure (future: extract refs)
|
|
83
|
+
parser.parse(xmlBuffer.toString('utf8'));
|
|
84
|
+
// TODO: Extract symbol references from Grid 3 XML structure when needed
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return Array.from(refs);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.Grid3SymbolExtractor = Grid3SymbolExtractor;
|
|
91
|
+
class Grid3SymbolResolver extends SymbolResolver {
|
|
92
|
+
resolveSymbol(symbolRef) {
|
|
93
|
+
// Implementation depends on Grid 3 symbol storage format
|
|
94
|
+
const symbolPath = path_1.default.join(this.symbolPath, symbolRef);
|
|
95
|
+
return fs_1.default.existsSync(symbolPath) ? symbolPath : null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.Grid3SymbolResolver = Grid3SymbolResolver;
|
|
99
|
+
// --- TouchChat ---
|
|
100
|
+
class TouchChatSymbolExtractor extends SymbolExtractor {
|
|
101
|
+
getSymbolReferences(_filePath) {
|
|
102
|
+
// Implementation depends on TouchChat file format
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.TouchChatSymbolExtractor = TouchChatSymbolExtractor;
|
|
107
|
+
class TouchChatSymbolResolver extends SymbolResolver {
|
|
108
|
+
resolveSymbol(symbolRef) {
|
|
109
|
+
// Implementation depends on TouchChat symbol storage format
|
|
110
|
+
const symbolPath = path_1.default.join(this.symbolPath, symbolRef);
|
|
111
|
+
return fs_1.default.existsSync(symbolPath) ? symbolPath : null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.TouchChatSymbolResolver = TouchChatSymbolResolver;
|
|
115
|
+
// --- Simple fallback function for PCS-style lookup ---
|
|
116
|
+
function resolveSymbol(label, symbolDir) {
|
|
117
|
+
const cleanLabel = label.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
118
|
+
const exts = ['.png', '.jpg', '.svg'];
|
|
119
|
+
for (const ext of exts) {
|
|
120
|
+
const symbolPath = path_1.default.join(symbolDir, cleanLabel + ext);
|
|
121
|
+
if (fs_1.default.existsSync(symbolPath)) {
|
|
122
|
+
return symbolPath;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseProcessor, ProcessorOptions, ExtractStringsResult, TranslatedString, SourceString } from '../core/baseProcessor';
|
|
2
|
+
import { AACTree } from '../core/treeStructure';
|
|
3
|
+
declare class ApplePanelsProcessor extends BaseProcessor {
|
|
4
|
+
constructor(options?: ProcessorOptions);
|
|
5
|
+
private parseRect;
|
|
6
|
+
private pixelToGrid;
|
|
7
|
+
extractTexts(filePathOrBuffer: string | Buffer): string[];
|
|
8
|
+
loadIntoTree(filePathOrBuffer: string | Buffer): AACTree;
|
|
9
|
+
processTexts(filePathOrBuffer: string | Buffer, translations: Map<string, string>, outputPath: string): Buffer;
|
|
10
|
+
saveFromTree(tree: AACTree, outputPath: string): void;
|
|
11
|
+
private createApplePanelsAction;
|
|
12
|
+
/**
|
|
13
|
+
* Extract strings with metadata for aac-tools-platform compatibility
|
|
14
|
+
* Uses the generic implementation from BaseProcessor
|
|
15
|
+
*/
|
|
16
|
+
extractStringsWithMetadata(filePath: string): Promise<ExtractStringsResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Generate translated download for aac-tools-platform compatibility
|
|
19
|
+
* Uses the generic implementation from BaseProcessor
|
|
20
|
+
*/
|
|
21
|
+
generateTranslatedDownload(filePath: string, translatedStrings: TranslatedString[], sourceStrings: SourceString[]): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
export { ApplePanelsProcessor };
|