@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.
Files changed (113) hide show
  1. package/dist/browser/core/baseProcessor.js +4 -0
  2. package/dist/browser/processors/applePanelsProcessor.js +33 -40
  3. package/dist/browser/processors/astericsGridProcessor.js +31 -26
  4. package/dist/browser/processors/dotProcessor.js +11 -12
  5. package/dist/browser/processors/gridset/colorUtils.js +354 -0
  6. package/dist/browser/processors/gridset/helpers.js +60 -53
  7. package/dist/browser/processors/gridset/index.js +61 -0
  8. package/dist/browser/processors/gridset/styleHelpers.js +205 -0
  9. package/dist/browser/processors/gridset/symbolExtractor.js +331 -0
  10. package/dist/browser/processors/gridset/symbolSearch.js +248 -0
  11. package/dist/browser/processors/gridset/symbols.js +39 -72
  12. package/dist/browser/processors/gridsetProcessor.js +39 -48
  13. package/dist/browser/processors/obfProcessor.js +39 -53
  14. package/dist/browser/processors/opmlProcessor.js +11 -12
  15. package/dist/browser/processors/snap/helpers.js +57 -49
  16. package/dist/browser/processors/snapProcessor.js +48 -51
  17. package/dist/browser/processors/touchchatProcessor.js +60 -52
  18. package/dist/browser/utilities/analytics/history.js +24 -18
  19. package/dist/browser/utilities/analytics/metrics/comparison.js +16 -16
  20. package/dist/browser/utilities/analytics/metrics/vocabulary.js +2 -2
  21. package/dist/browser/utilities/analytics/reference/browser.js +16 -16
  22. package/dist/browser/utilities/analytics/reference/index.js +44 -35
  23. package/dist/browser/utils/io.js +78 -21
  24. package/dist/browser/utils/sqlite.js +8 -10
  25. package/dist/browser/utils/zip.js +43 -43
  26. package/dist/browser/validation/baseValidator.js +5 -0
  27. package/dist/browser/validation/gridsetValidator.js +12 -20
  28. package/dist/browser/validation/obfValidator.js +6 -5
  29. package/dist/browser/validation/snapValidator.js +11 -7
  30. package/dist/browser/validation/touchChatValidator.js +23 -13
  31. package/dist/cli/index.js +22 -24
  32. package/dist/core/baseProcessor.d.ts +7 -7
  33. package/dist/core/baseProcessor.js +4 -0
  34. package/dist/processors/applePanelsProcessor.js +32 -39
  35. package/dist/processors/astericsGridProcessor.d.ts +4 -4
  36. package/dist/processors/astericsGridProcessor.js +30 -25
  37. package/dist/processors/dotProcessor.js +10 -11
  38. package/dist/processors/excelProcessor.d.ts +3 -3
  39. package/dist/processors/excelProcessor.js +14 -20
  40. package/dist/processors/gridset/helpers.d.ts +12 -14
  41. package/dist/processors/gridset/helpers.js +60 -79
  42. package/dist/processors/gridset/imageDebug.d.ts +3 -5
  43. package/dist/processors/gridset/imageDebug.js +4 -4
  44. package/dist/processors/gridset/password.d.ts +1 -1
  45. package/dist/processors/gridset/symbolExtractor.d.ts +5 -3
  46. package/dist/processors/gridset/symbolExtractor.js +15 -38
  47. package/dist/processors/gridset/symbolSearch.d.ts +11 -10
  48. package/dist/processors/gridset/symbolSearch.js +29 -51
  49. package/dist/processors/gridset/symbols.d.ts +8 -6
  50. package/dist/processors/gridset/symbols.js +38 -71
  51. package/dist/processors/gridset/wordlistHelpers.d.ts +4 -6
  52. package/dist/processors/gridset/wordlistHelpers.js +15 -74
  53. package/dist/processors/gridsetProcessor.d.ts +2 -2
  54. package/dist/processors/gridsetProcessor.js +38 -70
  55. package/dist/processors/obfProcessor.d.ts +2 -2
  56. package/dist/processors/obfProcessor.js +38 -75
  57. package/dist/processors/obfsetProcessor.js +2 -3
  58. package/dist/processors/opmlProcessor.js +10 -11
  59. package/dist/processors/snap/helpers.d.ts +9 -9
  60. package/dist/processors/snap/helpers.js +58 -76
  61. package/dist/processors/snapProcessor.d.ts +2 -2
  62. package/dist/processors/snapProcessor.js +47 -50
  63. package/dist/processors/touchchatProcessor.d.ts +2 -2
  64. package/dist/processors/touchchatProcessor.js +59 -51
  65. package/dist/types/aac.d.ts +2 -2
  66. package/dist/utilities/analytics/history.d.ts +8 -8
  67. package/dist/utilities/analytics/history.js +24 -18
  68. package/dist/utilities/analytics/index.d.ts +3 -2
  69. package/dist/utilities/analytics/index.js +9 -10
  70. package/dist/utilities/analytics/metrics/comparison.d.ts +1 -1
  71. package/dist/utilities/analytics/metrics/comparison.js +16 -16
  72. package/dist/utilities/analytics/metrics/vocabulary.d.ts +1 -1
  73. package/dist/utilities/analytics/metrics/vocabulary.js +2 -2
  74. package/dist/utilities/analytics/reference/browser.d.ts +9 -9
  75. package/dist/utilities/analytics/reference/browser.js +16 -16
  76. package/dist/utilities/analytics/reference/index.d.ts +25 -23
  77. package/dist/utilities/analytics/reference/index.js +43 -34
  78. package/dist/utilities/symbolTools.d.ts +8 -6
  79. package/dist/utilities/symbolTools.js +21 -18
  80. package/dist/utils/io.d.ts +24 -6
  81. package/dist/utils/io.js +79 -25
  82. package/dist/utils/sqlite.d.ts +3 -1
  83. package/dist/utils/sqlite.js +7 -9
  84. package/dist/utils/zip.d.ts +7 -3
  85. package/dist/utils/zip.js +43 -43
  86. package/dist/validation/applePanelsValidator.d.ts +2 -1
  87. package/dist/validation/applePanelsValidator.js +10 -11
  88. package/dist/validation/astericsValidator.d.ts +2 -1
  89. package/dist/validation/astericsValidator.js +5 -4
  90. package/dist/validation/baseValidator.d.ts +2 -2
  91. package/dist/validation/baseValidator.js +5 -0
  92. package/dist/validation/dotValidator.d.ts +2 -1
  93. package/dist/validation/dotValidator.js +5 -4
  94. package/dist/validation/excelValidator.d.ts +2 -1
  95. package/dist/validation/excelValidator.js +5 -4
  96. package/dist/validation/gridsetValidator.d.ts +2 -1
  97. package/dist/validation/gridsetValidator.js +11 -22
  98. package/dist/validation/index.d.ts +2 -2
  99. package/dist/validation/index.js +5 -4
  100. package/dist/validation/obfValidator.d.ts +2 -1
  101. package/dist/validation/obfValidator.js +5 -4
  102. package/dist/validation/obfsetValidator.d.ts +2 -1
  103. package/dist/validation/obfsetValidator.js +5 -4
  104. package/dist/validation/opmlValidator.d.ts +2 -1
  105. package/dist/validation/opmlValidator.js +5 -4
  106. package/dist/validation/snapValidator.d.ts +2 -1
  107. package/dist/validation/snapValidator.js +10 -6
  108. package/dist/validation/touchChatValidator.d.ts +4 -6
  109. package/dist/validation/touchChatValidator.js +22 -12
  110. package/dist/validation/validationTypes.d.ts +8 -1
  111. package/package.json +1 -1
  112. package/dist/core/fileProcessor.d.ts +0 -7
  113. package/dist/core/fileProcessor.js +0 -57
@@ -9,29 +9,6 @@
9
9
  * above bw=above bw.png=above bw
10
10
  * active family=active family.png=active family
11
11
  */
12
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- var desc = Object.getOwnPropertyDescriptor(m, k);
15
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
- desc = { enumerable: true, get: function() { return m[k]; } };
17
- }
18
- Object.defineProperty(o, k2, desc);
19
- }) : (function(o, m, k, k2) {
20
- if (k2 === undefined) k2 = k;
21
- o[k2] = m[k];
22
- }));
23
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
- Object.defineProperty(o, "default", { enumerable: true, value: v });
25
- }) : function(o, v) {
26
- o["default"] = v;
27
- });
28
- var __importStar = (this && this.__importStar) || function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
12
  Object.defineProperty(exports, "__esModule", { value: true });
36
13
  exports.parsePixFile = parsePixFile;
37
14
  exports.loadSearchIndexes = loadSearchIndexes;
@@ -43,16 +20,16 @@ exports.getSearchSuggestions = getSearchSuggestions;
43
20
  exports.searchSymbolsWithReferences = searchSymbolsWithReferences;
44
21
  exports.countLibrarySymbols = countLibrarySymbols;
45
22
  exports.getSymbolSearchStats = getSymbolSearchStats;
46
- const fs = __importStar(require("fs"));
47
- const path = __importStar(require("path"));
23
+ const io_1 = require("../../utils/io");
48
24
  /**
49
25
  * Parse a .pix file into search index
50
26
  * @param pixFilePath - Path to .pix file
51
27
  * @returns Search index
52
28
  */
53
- function parsePixFile(pixFilePath) {
54
- const content = fs.readFileSync(pixFilePath, 'utf-8');
55
- const library = path.basename(pixFilePath, '.pix');
29
+ async function parsePixFile(pixFilePath, fileAdapter = io_1.defaultFileAdapter) {
30
+ const { readTextFromInput, basename } = fileAdapter;
31
+ const content = await readTextFromInput(pixFilePath);
32
+ const library = basename(pixFilePath, '.pix');
56
33
  const searchTerms = new Map();
57
34
  const filenames = new Map();
58
35
  const lines = content.split('\n');
@@ -78,22 +55,23 @@ function parsePixFile(pixFilePath) {
78
55
  * @param options - Search options
79
56
  * @returns Map of library name to search index
80
57
  */
81
- function loadSearchIndexes(options = {}) {
58
+ async function loadSearchIndexes(options = {}, fileAdapter = io_1.defaultFileAdapter) {
59
+ const { listDir, pathExists, join, basename } = fileAdapter;
82
60
  const { grid3Path, locale = 'en-GB', libraries: specifiedLibs } = options;
83
61
  if (!grid3Path) {
84
62
  throw new Error('grid3Path is required for symbol search');
85
63
  }
86
- const searchIndexesDir = path.join(grid3Path, 'Locale', locale, 'symbolsearch');
87
- if (!fs.existsSync(searchIndexesDir)) {
64
+ const searchIndexesDir = join(grid3Path, 'Locale', locale, 'symbolsearch');
65
+ if (!(await pathExists(searchIndexesDir))) {
88
66
  throw new Error(`Symbol search directory not found: ${searchIndexesDir}`);
89
67
  }
90
68
  const indexes = new Map();
91
- const files = fs.readdirSync(searchIndexesDir);
69
+ const files = await listDir(searchIndexesDir);
92
70
  for (const file of files) {
93
71
  if (!file.endsWith('.pix')) {
94
72
  continue;
95
73
  }
96
- const libraryName = path.basename(file, '.pix');
74
+ const libraryName = basename(file, '.pix');
97
75
  // Filter libraries if specified
98
76
  if (specifiedLibs && specifiedLibs.length > 0) {
99
77
  if (!specifiedLibs.some((lib) => lib.toLowerCase() === libraryName.toLowerCase())) {
@@ -101,8 +79,8 @@ function loadSearchIndexes(options = {}) {
101
79
  }
102
80
  }
103
81
  try {
104
- const pixFilePath = path.join(searchIndexesDir, file);
105
- const index = parsePixFile(pixFilePath);
82
+ const pixFilePath = join(searchIndexesDir, file);
83
+ const index = await parsePixFile(pixFilePath);
106
84
  indexes.set(libraryName, index);
107
85
  }
108
86
  catch (error) {
@@ -117,8 +95,8 @@ function loadSearchIndexes(options = {}) {
117
95
  * @param options - Search options
118
96
  * @returns Array of search results
119
97
  */
120
- function searchSymbols(searchTerm, options = {}) {
121
- const indexes = loadSearchIndexes(options);
98
+ async function searchSymbols(searchTerm, options = {}) {
99
+ const indexes = await loadSearchIndexes(options);
122
100
  const results = [];
123
101
  const lowerSearchTerm = searchTerm.toLowerCase().trim();
124
102
  const limit = options.limit || 100;
@@ -171,8 +149,8 @@ function searchSymbols(searchTerm, options = {}) {
171
149
  * @param options - Search options
172
150
  * @returns Symbol filename or undefined
173
151
  */
174
- function getSymbolFilename(searchTerm, library, options = {}) {
175
- const indexes = loadSearchIndexes({
152
+ async function getSymbolFilename(searchTerm, library, options = {}) {
153
+ const indexes = await loadSearchIndexes({
176
154
  ...options,
177
155
  libraries: [library],
178
156
  });
@@ -189,8 +167,8 @@ function getSymbolFilename(searchTerm, library, options = {}) {
189
167
  * @param options - Search options
190
168
  * @returns Display name or undefined
191
169
  */
192
- function getSymbolDisplayName(symbolFilename, library, options = {}) {
193
- const indexes = loadSearchIndexes({
170
+ async function getSymbolDisplayName(symbolFilename, library, options = {}) {
171
+ const indexes = await loadSearchIndexes({
194
172
  ...options,
195
173
  libraries: [library],
196
174
  });
@@ -206,8 +184,8 @@ function getSymbolDisplayName(symbolFilename, library, options = {}) {
206
184
  * @param options - Search options
207
185
  * @returns Array of search terms
208
186
  */
209
- function getAllSearchTerms(library, options = {}) {
210
- const indexes = loadSearchIndexes({
187
+ async function getAllSearchTerms(library, options = {}) {
188
+ const indexes = await loadSearchIndexes({
211
189
  ...options,
212
190
  libraries: [library],
213
191
  });
@@ -223,8 +201,8 @@ function getAllSearchTerms(library, options = {}) {
223
201
  * @param options - Search options
224
202
  * @returns Array of suggested terms
225
203
  */
226
- function getSearchSuggestions(partialTerm, options = {}) {
227
- const indexes = loadSearchIndexes(options);
204
+ async function getSearchSuggestions(partialTerm, options = {}) {
205
+ const indexes = await loadSearchIndexes(options);
228
206
  const suggestions = new Set();
229
207
  const lowerPartial = partialTerm.toLowerCase().trim();
230
208
  for (const index of indexes.values()) {
@@ -242,8 +220,8 @@ function getSearchSuggestions(partialTerm, options = {}) {
242
220
  * @param options - Search options
243
221
  * @returns Array of full symbol references
244
222
  */
245
- function searchSymbolsWithReferences(searchTerm, options = {}) {
246
- const results = searchSymbols(searchTerm, options);
223
+ async function searchSymbolsWithReferences(searchTerm, options = {}) {
224
+ const results = await searchSymbols(searchTerm, options);
247
225
  return results.map((r) => `[${r.library}]${r.symbolFilename}`);
248
226
  }
249
227
  /**
@@ -251,8 +229,8 @@ function searchSymbolsWithReferences(searchTerm, options = {}) {
251
229
  * @param options - Search options
252
230
  * @returns Map of library name to symbol count
253
231
  */
254
- function countLibrarySymbols(options = {}) {
255
- const indexes = loadSearchIndexes(options);
232
+ async function countLibrarySymbols(options = {}) {
233
+ const indexes = await loadSearchIndexes(options);
256
234
  const counts = new Map();
257
235
  for (const [libraryName, index] of indexes.entries()) {
258
236
  counts.set(libraryName, index.searchTerms.size);
@@ -264,8 +242,8 @@ function countLibrarySymbols(options = {}) {
264
242
  * @param options - Search options
265
243
  * @returns Statistics about available symbols
266
244
  */
267
- function getSymbolSearchStats(options = {}) {
268
- const indexes = loadSearchIndexes(options);
245
+ async function getSymbolSearchStats(options = {}) {
246
+ const indexes = await loadSearchIndexes(options);
269
247
  const stats = {
270
248
  totalLibraries: indexes.size,
271
249
  totalSymbols: 0,
@@ -12,6 +12,8 @@
12
12
  *
13
13
  * This module provides symbol resolution and metadata extraction.
14
14
  */
15
+ import { FileAdapter, ProcessorInput } from '../../utils/io';
16
+ import { ZipAdapter } from '../../utils/zip';
15
17
  /**
16
18
  * Known symbol libraries in Grid 3
17
19
  */
@@ -92,14 +94,14 @@ export declare function isSymbolReference(reference: string): boolean;
92
94
  * Get the default Grid 3 installation path for the current platform
93
95
  * @returns Default Grid 3 path or empty string if not found
94
96
  */
95
- export declare function getDefaultGrid3Path(): string;
97
+ export declare function getDefaultGrid3Path(fileAdapter?: FileAdapter): Promise<string>;
96
98
  /**
97
99
  * Get the Symbol Libraries directory path
98
100
  * Contains .symbols ZIP archives with actual image files
99
101
  * @param grid3Path - Grid 3 installation path
100
102
  * @returns Path to Symbol Libraries directory (e.g., "C:\...\Grid 3\Resources\Symbols")
101
103
  */
102
- export declare function getSymbolLibrariesDir(grid3Path: string): string;
104
+ export declare function getSymbolLibrariesDir(grid3Path: string, fileAdapter?: FileAdapter): string;
103
105
  /**
104
106
  * Get the symbol search indexes directory path for a given locale
105
107
  * Contains .pix index files for searching symbols
@@ -107,27 +109,27 @@ export declare function getSymbolLibrariesDir(grid3Path: string): string;
107
109
  * @param locale - Locale code (e.g., 'en-GB')
108
110
  * @returns Path to symbol search indexes directory (e.g., "C:\...\Grid 3\Locale\en-GB\symbolsearch")
109
111
  */
110
- export declare function getSymbolSearchIndexesDir(grid3Path: string, locale?: string): string;
112
+ export declare function getSymbolSearchIndexesDir(grid3Path: string, locale?: string, fileAdapter?: FileAdapter): string;
111
113
  /**
112
114
  * Get all available symbol libraries in the Grid 3 installation
113
115
  * @param options - Resolution options
114
116
  * @returns Array of symbol library information
115
117
  */
116
- export declare function getAvailableSymbolLibraries(options?: SymbolResolutionOptions): SymbolLibraryInfo[];
118
+ export declare function getAvailableSymbolLibraries(options?: SymbolResolutionOptions, fileAdapter?: FileAdapter): Promise<SymbolLibraryInfo[]>;
117
119
  /**
118
120
  * Check if a symbol library exists
119
121
  * @param libraryName - Name of the library (e.g., 'widgit', 'tawasl')
120
122
  * @param options - Resolution options
121
123
  * @returns Symbol library info or undefined if not found
122
124
  */
123
- export declare function getSymbolLibraryInfo(libraryName: string, options?: SymbolResolutionOptions): SymbolLibraryInfo | undefined;
125
+ export declare function getSymbolLibraryInfo(libraryName: string, options?: SymbolResolutionOptions, fileAdapter?: FileAdapter): Promise<SymbolLibraryInfo | undefined>;
124
126
  /**
125
127
  * Resolve a symbol reference to extract the actual image data
126
128
  * @param reference - Symbol reference like "[tawasl]/above bw.png"
127
129
  * @param options - Resolution options
128
130
  * @returns Resolution result with image data if found
129
131
  */
130
- export declare function resolveSymbolReference(reference: string, options?: SymbolResolutionOptions): SymbolResolutionResult;
132
+ export declare function resolveSymbolReference(reference: string, options?: SymbolResolutionOptions, fileAdapter?: FileAdapter, zipAdapter?: (input: ProcessorInput) => Promise<ZipAdapter>): Promise<SymbolResolutionResult>;
131
133
  /**
132
134
  * Get all symbol references from a gridset
133
135
  * This scans button images for symbol references
@@ -34,6 +34,7 @@ exports.symbolReferenceToFilename = symbolReferenceToFilename;
34
34
  exports.getSymbolsDir = getSymbolsDir;
35
35
  exports.getSymbolSearchDir = getSymbolSearchDir;
36
36
  const io_1 = require("../../utils/io");
37
+ const zip_1 = require("../../utils/zip");
37
38
  /**
38
39
  * Default Grid 3 installation paths by platform
39
40
  */
@@ -76,38 +77,6 @@ exports.SYMBOL_LIBRARIES = {
76
77
  * Default locale to use
77
78
  */
78
79
  exports.DEFAULT_LOCALE = 'en-GB';
79
- function getNodeFs() {
80
- try {
81
- return (0, io_1.getFs)();
82
- }
83
- catch {
84
- throw new Error('Symbol library access is not available in this environment.');
85
- }
86
- }
87
- function getNodePath() {
88
- try {
89
- return (0, io_1.getPath)();
90
- }
91
- catch {
92
- throw new Error('Path utilities are not available in this environment.');
93
- }
94
- }
95
- let cachedAdmZip = null;
96
- function getAdmZip() {
97
- if (cachedAdmZip)
98
- return cachedAdmZip;
99
- try {
100
- const nodeRequire = (0, io_1.getNodeRequire)();
101
- // eslint-disable-next-line @typescript-eslint/no-var-requires
102
- const module = nodeRequire('adm-zip');
103
- const resolved = module.default || module;
104
- cachedAdmZip = resolved;
105
- return resolved;
106
- }
107
- catch {
108
- throw new Error('Symbol library access requires AdmZip in this environment.');
109
- }
110
- }
111
80
  /**
112
81
  * Parse a symbol reference string
113
82
  * @param reference - Symbol reference like "[widgit]/food/apple.png"
@@ -145,12 +114,12 @@ function isSymbolReference(reference) {
145
114
  * Get the default Grid 3 installation path for the current platform
146
115
  * @returns Default Grid 3 path or empty string if not found
147
116
  */
148
- function getDefaultGrid3Path() {
117
+ async function getDefaultGrid3Path(fileAdapter) {
118
+ const { pathExists } = fileAdapter ?? io_1.defaultFileAdapter;
149
119
  const platform = (typeof process !== 'undefined' && process.platform ? process.platform : 'unknown');
150
120
  const defaultPath = DEFAULT_GRID3_PATHS[platform] || '';
151
121
  try {
152
- const fs = getNodeFs();
153
- if (defaultPath && fs.existsSync(defaultPath)) {
122
+ if (defaultPath && (await pathExists(defaultPath))) {
154
123
  return defaultPath;
155
124
  }
156
125
  // Try to find Grid 3 in common locations
@@ -162,7 +131,7 @@ function getDefaultGrid3Path() {
162
131
  '/opt/smartbox/grid3',
163
132
  ];
164
133
  for (const testPath of commonPaths) {
165
- if (fs.existsSync(testPath)) {
134
+ if (await pathExists(testPath)) {
166
135
  return testPath;
167
136
  }
168
137
  }
@@ -178,9 +147,9 @@ function getDefaultGrid3Path() {
178
147
  * @param grid3Path - Grid 3 installation path
179
148
  * @returns Path to Symbol Libraries directory (e.g., "C:\...\Grid 3\Resources\Symbols")
180
149
  */
181
- function getSymbolLibrariesDir(grid3Path) {
182
- const path = getNodePath();
183
- return path.join(grid3Path, SYMBOLS_SUBDIR);
150
+ function getSymbolLibrariesDir(grid3Path, fileAdapter = io_1.defaultFileAdapter) {
151
+ const { join } = fileAdapter;
152
+ return join(grid3Path, SYMBOLS_SUBDIR);
184
153
  }
185
154
  /**
186
155
  * Get the symbol search indexes directory path for a given locale
@@ -189,38 +158,37 @@ function getSymbolLibrariesDir(grid3Path) {
189
158
  * @param locale - Locale code (e.g., 'en-GB')
190
159
  * @returns Path to symbol search indexes directory (e.g., "C:\...\Grid 3\Locale\en-GB\symbolsearch")
191
160
  */
192
- function getSymbolSearchIndexesDir(grid3Path, locale = exports.DEFAULT_LOCALE) {
193
- const path = getNodePath();
194
- return path.join(grid3Path, SYMBOLSEARCH_SUBDIR, locale, 'symbolsearch');
161
+ function getSymbolSearchIndexesDir(grid3Path, locale = exports.DEFAULT_LOCALE, fileAdapter = io_1.defaultFileAdapter) {
162
+ const { join } = fileAdapter;
163
+ return join(grid3Path, SYMBOLSEARCH_SUBDIR, locale, 'symbolsearch');
195
164
  }
196
165
  /**
197
166
  * Get all available symbol libraries in the Grid 3 installation
198
167
  * @param options - Resolution options
199
168
  * @returns Array of symbol library information
200
169
  */
201
- function getAvailableSymbolLibraries(options = {}) {
202
- const grid3Path = options.grid3Path || options.symbolDir || getDefaultGrid3Path();
170
+ async function getAvailableSymbolLibraries(options = {}, fileAdapter) {
171
+ const { pathExists, getFileSize, listDir, join, basename } = fileAdapter ?? io_1.defaultFileAdapter;
172
+ const grid3Path = options.grid3Path || options.symbolDir || (await getDefaultGrid3Path());
203
173
  if (!grid3Path) {
204
174
  return [];
205
175
  }
206
- const symbolsDir = getSymbolLibrariesDir(grid3Path);
207
- const fs = getNodeFs();
208
- if (!fs.existsSync(symbolsDir)) {
176
+ const symbolsDir = getSymbolLibrariesDir(grid3Path, fileAdapter);
177
+ if (!(await pathExists(symbolsDir))) {
209
178
  return [];
210
179
  }
211
180
  const libraries = [];
212
- const files = fs.readdirSync(symbolsDir);
181
+ const files = await listDir(symbolsDir);
213
182
  for (const file of files) {
214
183
  if (file.endsWith('.symbols')) {
215
- const path = getNodePath();
216
- const fullPath = path.join(symbolsDir, file);
217
- const stats = fs.statSync(fullPath);
218
- const libraryName = path.basename(file, '.symbols');
184
+ const fullPath = join(symbolsDir, file);
185
+ const size = await getFileSize(fullPath);
186
+ const libraryName = basename(file, '.symbols');
219
187
  libraries.push({
220
188
  name: libraryName,
221
189
  pixFile: fullPath, // Reuse this field for the .symbols file path
222
190
  exists: true,
223
- size: stats.size,
191
+ size,
224
192
  locale: 'global', // .symbols files are not locale-specific
225
193
  });
226
194
  }
@@ -233,12 +201,13 @@ function getAvailableSymbolLibraries(options = {}) {
233
201
  * @param options - Resolution options
234
202
  * @returns Symbol library info or undefined if not found
235
203
  */
236
- function getSymbolLibraryInfo(libraryName, options = {}) {
237
- const grid3Path = options.grid3Path || options.symbolDir || getDefaultGrid3Path();
204
+ async function getSymbolLibraryInfo(libraryName, options = {}, fileAdapter) {
205
+ const { pathExists, getFileSize, join } = fileAdapter ?? io_1.defaultFileAdapter;
206
+ const grid3Path = options.grid3Path || options.symbolDir || (await getDefaultGrid3Path());
238
207
  if (!grid3Path) {
239
208
  return undefined;
240
209
  }
241
- const symbolsDir = getSymbolLibrariesDir(grid3Path);
210
+ const symbolsDir = getSymbolLibrariesDir(grid3Path, fileAdapter);
242
211
  const normalizedLibName = libraryName.toLowerCase();
243
212
  // Try different case variations
244
213
  const variations = [
@@ -247,16 +216,14 @@ function getSymbolLibraryInfo(libraryName, options = {}) {
247
216
  libraryName + '.symbols',
248
217
  ];
249
218
  for (const file of variations) {
250
- const path = getNodePath();
251
- const fullPath = path.join(symbolsDir, file);
252
- const fs = getNodeFs();
253
- if (fs.existsSync(fullPath)) {
254
- const stats = fs.statSync(fullPath);
219
+ const fullPath = join(symbolsDir, file);
220
+ if (await pathExists(fullPath)) {
221
+ const size = await getFileSize(fullPath);
255
222
  return {
256
223
  name: libraryName,
257
224
  pixFile: fullPath,
258
225
  exists: true,
259
- size: stats.size,
226
+ size,
260
227
  locale: 'global',
261
228
  };
262
229
  }
@@ -269,7 +236,7 @@ function getSymbolLibraryInfo(libraryName, options = {}) {
269
236
  * @param options - Resolution options
270
237
  * @returns Resolution result with image data if found
271
238
  */
272
- function resolveSymbolReference(reference, options = {}) {
239
+ async function resolveSymbolReference(reference, options = {}, fileAdapter = io_1.defaultFileAdapter, zipAdapter) {
273
240
  const parsed = parseSymbolReference(reference);
274
241
  if (!parsed.isValid) {
275
242
  return {
@@ -278,7 +245,7 @@ function resolveSymbolReference(reference, options = {}) {
278
245
  error: 'Invalid symbol reference format',
279
246
  };
280
247
  }
281
- const grid3Path = options.grid3Path || getDefaultGrid3Path();
248
+ const grid3Path = options.grid3Path || (await getDefaultGrid3Path());
282
249
  if (!grid3Path) {
283
250
  return {
284
251
  reference: parsed,
@@ -286,7 +253,7 @@ function resolveSymbolReference(reference, options = {}) {
286
253
  error: 'Grid 3 installation not found. Please specify grid3Path.',
287
254
  };
288
255
  }
289
- const libraryInfo = getSymbolLibraryInfo(parsed.library, { grid3Path });
256
+ const libraryInfo = await getSymbolLibraryInfo(parsed.library, { grid3Path });
290
257
  if (!libraryInfo || !libraryInfo.exists) {
291
258
  return {
292
259
  reference: parsed,
@@ -296,16 +263,16 @@ function resolveSymbolReference(reference, options = {}) {
296
263
  }
297
264
  try {
298
265
  // .symbols files are ZIP archives
299
- const AdmZip = getAdmZip();
300
- const zip = new AdmZip(libraryInfo.pixFile);
266
+ const zipFile = libraryInfo.pixFile;
267
+ const zip = zipAdapter ? await zipAdapter(zipFile) : await (0, zip_1.getZipAdapter)(zipFile, fileAdapter);
301
268
  // The path in the symbol reference becomes the path within the symbols/ folder
302
269
  // e.g., [tawasl]/above bw.png becomes symbols/above bw.png
303
270
  const symbolPath = `symbols/${parsed.path}`;
304
- const entry = zip.getEntry(symbolPath);
271
+ const entry = await zip.readFile(symbolPath);
305
272
  if (!entry) {
306
273
  // Try without the symbols/ prefix (in case reference already includes it)
307
274
  const altPath = parsed.path.startsWith('symbols/') ? parsed.path : `symbols/${parsed.path}`;
308
- const altEntry = zip.getEntry(altPath);
275
+ const altEntry = await zip.readFile(altPath);
309
276
  if (!altEntry) {
310
277
  return {
311
278
  reference: parsed,
@@ -316,7 +283,7 @@ function resolveSymbolReference(reference, options = {}) {
316
283
  };
317
284
  }
318
285
  // Found with alternate path
319
- const data = altEntry.getData();
286
+ const data = Buffer.from(altEntry);
320
287
  return {
321
288
  reference: parsed,
322
289
  found: true,
@@ -326,7 +293,7 @@ function resolveSymbolReference(reference, options = {}) {
326
293
  };
327
294
  }
328
295
  // Found the symbol!
329
- const data = entry.getData();
296
+ const data = Buffer.from(entry);
330
297
  return {
331
298
  reference: parsed,
332
299
  found: true,
@@ -8,8 +8,8 @@
8
8
  * Note: Wordlists are only supported in Grid3 format. Other AAC formats
9
9
  * do not have equivalent wordlist functionality.
10
10
  */
11
- import { type ZipAdapter } from '../../utils/zip';
12
- import { type ProcessorInput } from '../../utils/io';
11
+ import { FileAdapter, type ProcessorInput } from '../../utils/io';
12
+ import { ZipAdapter } from '../../utils/zip';
13
13
  /**
14
14
  * Represents a single item in a wordlist
15
15
  */
@@ -66,9 +66,7 @@ export declare function wordlistToXml(wordlist: WordList): string;
66
66
  * console.log(`Grid "${gridName}" has ${wordlist.items.length} items`);
67
67
  * });
68
68
  */
69
- export declare function extractWordlists(gridsetBuffer: Uint8Array, password?: string | undefined, zipAdapter?: (input: ProcessorInput) => Promise<{
70
- zip: ZipAdapter;
71
- }>): Promise<Map<string, WordList>>;
69
+ export declare function extractWordlists(gridsetBuffer: Uint8Array, password?: string | undefined, fileAdapter?: FileAdapter, zipAdapter?: (input: ProcessorInput) => Promise<ZipAdapter>): Promise<Map<string, WordList>>;
72
70
  /**
73
71
  * Updates or adds a wordlist to a specific grid in a gridset
74
72
  *
@@ -83,4 +81,4 @@ export declare function extractWordlists(gridsetBuffer: Uint8Array, password?: s
83
81
  * const updatedGridset = updateWordlist(gridsetBuffer, 'Greetings', newWordlist);
84
82
  * fs.writeFileSync('updated-gridset.gridset', updatedGridset);
85
83
  */
86
- export declare function updateWordlist(gridsetBuffer: Uint8Array, gridName: string, wordlist: WordList, password?: string | undefined): Promise<Uint8Array>;
84
+ export declare function updateWordlist(gridsetBuffer: Uint8Array, gridName: string, wordlist: WordList, password?: string | undefined, fileAdapter?: FileAdapter, zipAdapter?: (input: ProcessorInput) => Promise<ZipAdapter>): Promise<Uint8Array>;
@@ -9,29 +9,6 @@
9
9
  * Note: Wordlists are only supported in Grid3 format. Other AAC formats
10
10
  * do not have equivalent wordlist functionality.
11
11
  */
12
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- var desc = Object.getOwnPropertyDescriptor(m, k);
15
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
- desc = { enumerable: true, get: function() { return m[k]; } };
17
- }
18
- Object.defineProperty(o, k2, desc);
19
- }) : (function(o, m, k, k2) {
20
- if (k2 === undefined) k2 = k;
21
- o[k2] = m[k];
22
- }));
23
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
- Object.defineProperty(o, "default", { enumerable: true, value: v });
25
- }) : function(o, v) {
26
- o["default"] = v;
27
- });
28
- var __importStar = (this && this.__importStar) || function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
12
  Object.defineProperty(exports, "__esModule", { value: true });
36
13
  exports.createWordlist = createWordlist;
37
14
  exports.wordlistToXml = wordlistToXml;
@@ -39,9 +16,9 @@ exports.extractWordlists = extractWordlists;
39
16
  exports.updateWordlist = updateWordlist;
40
17
  const fast_xml_parser_1 = require("fast-xml-parser");
41
18
  const password_1 = require("./password");
42
- const zip_1 = require("../../utils/zip");
43
19
  const io_1 = require("../../utils/io");
44
20
  const io_2 = require("../../utils/io");
21
+ const zip_1 = require("../../utils/zip");
45
22
  /**
46
23
  * Creates a WordList object from an array of words/phrases or a dictionary
47
24
  *
@@ -127,13 +104,13 @@ function wordlistToXml(wordlist) {
127
104
  * console.log(`Grid "${gridName}" has ${wordlist.items.length} items`);
128
105
  * });
129
106
  */
130
- async function extractWordlists(gridsetBuffer, password = (0, password_1.resolveGridsetPasswordFromEnv)(), zipAdapter) {
107
+ async function extractWordlists(gridsetBuffer, password = (0, password_1.resolveGridsetPasswordFromEnv)(), fileAdapter = io_1.defaultFileAdapter, zipAdapter) {
131
108
  const wordlists = new Map();
132
109
  const parser = new fast_xml_parser_1.XMLParser();
133
110
  try {
134
- const { zip } = zipAdapter
111
+ const zip = zipAdapter
135
112
  ? await zipAdapter(gridsetBuffer)
136
- : await (0, zip_1.openZipFromInput)(gridsetBuffer);
113
+ : await (0, zip_1.getZipAdapter)(gridsetBuffer, fileAdapter);
137
114
  const entries = (0, password_1.getZipEntriesFromAdapter)(zip, password);
138
115
  // Process each grid file
139
116
  for (const entry of entries) {
@@ -194,7 +171,7 @@ async function extractWordlists(gridsetBuffer, password = (0, password_1.resolve
194
171
  * const updatedGridset = updateWordlist(gridsetBuffer, 'Greetings', newWordlist);
195
172
  * fs.writeFileSync('updated-gridset.gridset', updatedGridset);
196
173
  */
197
- async function updateWordlist(gridsetBuffer, gridName, wordlist, password = (0, password_1.resolveGridsetPasswordFromEnv)()) {
174
+ async function updateWordlist(gridsetBuffer, gridName, wordlist, password = (0, password_1.resolveGridsetPasswordFromEnv)(), fileAdapter = io_1.defaultFileAdapter, zipAdapter) {
198
175
  const parser = new fast_xml_parser_1.XMLParser();
199
176
  const builder = new fast_xml_parser_1.XMLBuilder({
200
177
  ignoreAttributes: false,
@@ -202,45 +179,11 @@ async function updateWordlist(gridsetBuffer, gridName, wordlist, password = (0,
202
179
  indentBy: ' ',
203
180
  suppressEmptyNode: false,
204
181
  });
205
- let entries;
206
- let saveZip = null;
207
- let updateEntry = null;
208
- try {
209
- if ((0, io_1.isNodeRuntime)()) {
210
- const AdmZip = (0, io_1.getNodeRequire)()('adm-zip');
211
- const zip = new AdmZip(Buffer.from(gridsetBuffer));
212
- entries = zip.getEntries().map((entry) => ({
213
- entryName: entry.entryName,
214
- getData: () => Promise.resolve(entry.getData()),
215
- }));
216
- updateEntry = (entryName, xml) => {
217
- zip.addFile(entryName, Buffer.from(xml, 'utf8'));
218
- };
219
- saveZip = () => Promise.resolve(zip.toBuffer());
220
- }
221
- else {
222
- const module = await Promise.resolve().then(() => __importStar(require('jszip')));
223
- const JSZip = module.default || module;
224
- const zip = await JSZip.loadAsync(gridsetBuffer);
225
- entries = (0, password_1.getZipEntriesFromAdapter)({
226
- listFiles: () => Object.keys(zip.files),
227
- readFile: async (name) => {
228
- const file = zip.file(name);
229
- if (!file) {
230
- throw new Error(`Zip entry not found: ${name}`);
231
- }
232
- return file.async('uint8array');
233
- },
234
- }, password);
235
- updateEntry = (entryName, xml) => {
236
- zip.file(entryName, xml, { binary: false });
237
- };
238
- saveZip = async () => zip.generateAsync({ type: 'uint8array' });
239
- }
240
- }
241
- catch (error) {
242
- throw new Error(`Invalid gridset buffer: ${error.message}`);
243
- }
182
+ const updatedEntries = [];
183
+ const zip = zipAdapter
184
+ ? await zipAdapter(gridsetBuffer)
185
+ : await (0, zip_1.getZipAdapter)(gridsetBuffer, fileAdapter);
186
+ const entries = (0, password_1.getZipEntriesFromAdapter)(zip, password);
244
187
  let found = false;
245
188
  // Find and update the grid
246
189
  for (const entry of entries) {
@@ -275,9 +218,10 @@ async function updateWordlist(gridsetBuffer, gridName, wordlist, password = (0,
275
218
  };
276
219
  // Rebuild the XML
277
220
  const updatedXml = builder.build(data);
278
- if (updateEntry) {
279
- updateEntry(entry.entryName, updatedXml);
280
- }
221
+ updatedEntries.push({
222
+ name: entry.entryName,
223
+ data: updatedXml,
224
+ });
281
225
  found = true;
282
226
  }
283
227
  catch (error) {
@@ -290,8 +234,5 @@ async function updateWordlist(gridsetBuffer, gridName, wordlist, password = (0,
290
234
  if (!found) {
291
235
  throw new Error(`Grid "${gridName}" not found in gridset`);
292
236
  }
293
- if (!saveZip) {
294
- throw new Error('Failed to serialize updated gridset.');
295
- }
296
- return await saveZip();
237
+ return await zip.writeFiles(updatedEntries);
297
238
  }
@@ -30,7 +30,7 @@ declare class GridsetProcessor extends BaseProcessor {
30
30
  * This method uses shared translation utilities that work across all AAC formats.
31
31
  *
32
32
  * @param filePathOrBuffer - Path to gridset file or buffer
33
- * @returns Array of symbol information for LLM processing
33
+ * @returns Promise resolving to symbol information for LLM processing
34
34
  */
35
35
  extractSymbolsForLLM(filePathOrBuffer: string | Buffer): Promise<ButtonForTranslation[]>;
36
36
  /**
@@ -43,7 +43,7 @@ declare class GridsetProcessor extends BaseProcessor {
43
43
  * @param llmTranslations - Array of LLM translations with symbol info
44
44
  * @param outputPath - Where to save the translated gridset
45
45
  * @param options - Translation options (e.g., allowPartial for testing)
46
- * @returns Buffer of the translated gridset
46
+ * @returns Promise resolving to a buffer of the translated gridset
47
47
  */
48
48
  processLLMTranslations(filePathOrBuffer: string | Buffer, llmTranslations: LLMLTranslationResult[], outputPath: string, options?: {
49
49
  allowPartial?: boolean;