@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
@@ -1,30 +1,4 @@
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
2
  Object.defineProperty(exports, "__esModule", { value: true });
29
3
  exports.getPageTokenImageMap = getPageTokenImageMap;
30
4
  exports.getAllowedImageEntries = getAllowedImageEntries;
@@ -44,13 +18,11 @@ exports.readGrid3HistoryForUser = readGrid3HistoryForUser;
44
18
  exports.readAllGrid3History = readAllGrid3History;
45
19
  const fast_xml_parser_1 = require("fast-xml-parser");
46
20
  const treeStructure_1 = require("../../core/treeStructure");
47
- const fs = __importStar(require("fs"));
48
- const path = __importStar(require("path"));
49
- const child_process_1 = require("child_process");
50
- const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
51
21
  const dotnetTicks_1 = require("../../utils/dotnetTicks");
52
22
  const password_1 = require("./password");
23
+ const io_1 = require("../../utils/io");
53
24
  const zip_1 = require("../../utils/zip");
25
+ const sqlite_1 = require("../../utils/sqlite");
54
26
  function normalizeZipPath(p) {
55
27
  const unified = p.replace(/\\/g, '/');
56
28
  try {
@@ -96,11 +68,11 @@ function getAllowedImageEntries(tree) {
96
68
  * @param entryPath Entry name inside the zip
97
69
  * @returns Image data buffer or null if not found
98
70
  */
99
- async function openImage(gridsetBuffer, entryPath, password = (0, password_1.resolveGridsetPasswordFromEnv)(), zipAdapter) {
71
+ async function openImage(gridsetBuffer, entryPath, password = (0, password_1.resolveGridsetPasswordFromEnv)(), fileAdapter = io_1.defaultFileAdapter, zipAdapter) {
100
72
  try {
101
- const { zip } = zipAdapter
73
+ const zip = zipAdapter
102
74
  ? await zipAdapter(gridsetBuffer)
103
- : await (0, zip_1.openZipFromInput)(gridsetBuffer);
75
+ : await (0, zip_1.getZipAdapter)(gridsetBuffer, fileAdapter);
104
76
  const entries = (0, password_1.getZipEntriesFromAdapter)(zip, password);
105
77
  const want = normalizeZipPath(entryPath);
106
78
  const entry = entries.find((e) => normalizeZipPath(e.entryName) === want);
@@ -193,8 +165,9 @@ function getCommonDocumentsPath() {
193
165
  }
194
166
  try {
195
167
  // Query registry for Common Documents path
168
+ const child_process = (0, io_1.getNodeRequire)()('child_process');
196
169
  const command = 'REG.EXE QUERY "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" /V "Common Documents"';
197
- const output = (0, child_process_1.execSync)(command, { encoding: 'utf-8', windowsHide: true });
170
+ const output = child_process.execSync(command, { encoding: 'utf-8', windowsHide: true });
198
171
  // Parse the output to extract the path
199
172
  const match = output.match(/Common Documents\s+REG_SZ\s+(.+)/);
200
173
  if (match && match[1]) {
@@ -215,7 +188,8 @@ function getCommonDocumentsPath() {
215
188
  * C:\Users\Public\Documents\Smartbox\Grid 3\Users\{UserName}\Grid Sets\
216
189
  * @returns Array of Grid3 user path information
217
190
  */
218
- function findGrid3UserPaths() {
191
+ async function findGrid3UserPaths(fileAdapter = io_1.defaultFileAdapter) {
192
+ const { pathExists, listDir, isDirectory } = fileAdapter;
219
193
  const results = [];
220
194
  // Only works on Windows
221
195
  if (process.platform !== 'win32') {
@@ -224,28 +198,28 @@ function findGrid3UserPaths() {
224
198
  try {
225
199
  const commonDocs = getCommonDocumentsPath();
226
200
  // Use Windows path joining so tests that mock a Windows platform stay consistent even on POSIX runners
227
- const grid3BasePath = path.win32.join(commonDocs, 'Smartbox', 'Grid 3', 'Users');
201
+ const grid3BasePath = (0, io_1.joinWin32)(commonDocs, 'Smartbox', 'Grid 3', 'Users');
228
202
  // Check if Grid3 Users directory exists
229
- if (!fs.existsSync(grid3BasePath)) {
203
+ if (!(await pathExists(grid3BasePath))) {
230
204
  return results;
231
205
  }
232
206
  // Enumerate users
233
- const users = fs.readdirSync(grid3BasePath, { withFileTypes: true });
207
+ const users = await listDir(grid3BasePath);
234
208
  for (const userDir of users) {
235
- if (!userDir.isDirectory())
209
+ if (!(await isDirectory(userDir)))
236
210
  continue;
237
- const userName = userDir.name;
238
- const userPath = path.win32.join(grid3BasePath, userName);
211
+ const userName = userDir;
212
+ const userPath = (0, io_1.joinWin32)(grid3BasePath, userName);
239
213
  // Enumerate language codes
240
- const langDirs = fs.readdirSync(userPath, { withFileTypes: true });
214
+ const langDirs = await listDir(userPath);
241
215
  for (const langDir of langDirs) {
242
- if (!langDir.isDirectory())
216
+ if (!(await isDirectory(langDir)))
243
217
  continue;
244
- const langCode = langDir.name;
245
- const basePath = path.win32.join(userPath, langCode);
246
- const historyDbPath = path.win32.join(basePath, 'Phrases', 'history.sqlite');
218
+ const langCode = langDir;
219
+ const basePath = (0, io_1.joinWin32)(userPath, langCode);
220
+ const historyDbPath = (0, io_1.joinWin32)(basePath, 'Phrases', 'history.sqlite');
247
221
  // Only include if history database exists
248
- if (fs.existsSync(historyDbPath)) {
222
+ if (await pathExists(historyDbPath)) {
249
223
  results.push({
250
224
  userName,
251
225
  langCode,
@@ -266,50 +240,52 @@ function findGrid3UserPaths() {
266
240
  * Convenience method that returns just the database file paths
267
241
  * @returns Array of paths to history.sqlite files
268
242
  */
269
- function findGrid3HistoryDatabases() {
270
- return findGrid3UserPaths().map((userPath) => userPath.historyDbPath);
243
+ async function findGrid3HistoryDatabases(fileAdapter) {
244
+ const userPaths = await findGrid3UserPaths(fileAdapter);
245
+ return userPaths.map((userPath) => userPath.historyDbPath);
271
246
  }
272
247
  /**
273
248
  * Get Grid 3 users (alias of findGrid3UserPaths for clarity)
274
249
  */
275
- function findGrid3Users() {
276
- return findGrid3UserPaths();
250
+ async function findGrid3Users() {
251
+ return await findGrid3UserPaths();
277
252
  }
278
253
  /**
279
254
  * Find Grid 3 gridset/vocabulary files for each user
280
255
  * @param userName Optional user filter; matches case-insensitively
281
256
  * @returns Array of user/gridset path pairs
282
257
  */
283
- function findGrid3Vocabularies(userName) {
258
+ async function findGrid3Vocabularies(userName, fileAdapter = io_1.defaultFileAdapter) {
259
+ const { pathExists, listDir, isDirectory } = fileAdapter;
284
260
  const results = [];
285
261
  if (process.platform !== 'win32') {
286
262
  return results;
287
263
  }
288
264
  const commonDocs = getCommonDocumentsPath();
289
- const grid3BasePath = path.win32.join(commonDocs, 'Smartbox', 'Grid 3', 'Users');
290
- if (!fs.existsSync(grid3BasePath)) {
265
+ const grid3BasePath = (0, io_1.joinWin32)(commonDocs, 'Smartbox', 'Grid 3', 'Users');
266
+ if (!(await pathExists(grid3BasePath))) {
291
267
  return results;
292
268
  }
293
269
  const normalizedUser = userName?.toLowerCase();
294
- const users = fs.readdirSync(grid3BasePath, { withFileTypes: true });
270
+ const users = await listDir(grid3BasePath);
295
271
  for (const userDir of users) {
296
- if (!userDir.isDirectory())
272
+ if (!(await isDirectory(userDir)))
297
273
  continue;
298
- if (normalizedUser && userDir.name.toLowerCase() !== normalizedUser)
274
+ if (normalizedUser && userDir.toLowerCase() !== normalizedUser)
299
275
  continue;
300
- const userRoot = path.win32.join(grid3BasePath, userDir.name);
301
- const gridSetsDir = path.win32.join(userRoot, 'Grid Sets');
302
- if (!fs.existsSync(gridSetsDir))
276
+ const userRoot = (0, io_1.joinWin32)(grid3BasePath, userDir);
277
+ const gridSetsDir = (0, io_1.joinWin32)(userRoot, 'Grid Sets');
278
+ if (!(await pathExists(gridSetsDir)))
303
279
  continue;
304
- const entries = fs.readdirSync(gridSetsDir, { withFileTypes: true });
280
+ const entries = await listDir(gridSetsDir);
305
281
  for (const entry of entries) {
306
- if (!entry.isFile())
282
+ if (!(await pathExists(entry)) || (await isDirectory(entry)))
307
283
  continue;
308
- const ext = path.extname(entry.name).toLowerCase();
284
+ const ext = (0, io_1.extname)(entry).toLowerCase();
309
285
  if (ext === '.gridset' || ext === '.gridsetx' || ext === '.grd' || ext === '.grdl') {
310
286
  results.push({
311
- userName: userDir.name,
312
- gridsetPath: path.win32.join(gridSetsDir, entry.name),
287
+ userName: userDir,
288
+ gridsetPath: (0, io_1.joinWin32)(gridSetsDir, entry),
313
289
  });
314
290
  }
315
291
  }
@@ -322,26 +298,28 @@ function findGrid3Vocabularies(userName) {
322
298
  * @param langCode Optional language code filter (case-insensitive)
323
299
  * @returns Path to history.sqlite or null if not found
324
300
  */
325
- function findGrid3UserHistory(userName, langCode) {
301
+ async function findGrid3UserHistory(userName, langCode, fileAdapter) {
326
302
  if (!userName)
327
303
  return null;
328
304
  const normalizedUser = userName.toLowerCase();
329
305
  const normalizedLang = langCode?.toLowerCase();
330
- const match = findGrid3UserPaths().find((u) => u.userName.toLowerCase() === normalizedUser &&
306
+ const userPaths = await findGrid3UserPaths(fileAdapter);
307
+ const match = userPaths.find((u) => u.userName.toLowerCase() === normalizedUser &&
331
308
  (!normalizedLang || u.langCode.toLowerCase() === normalizedLang));
332
309
  return match?.historyDbPath ?? null;
333
310
  }
334
311
  /**
335
312
  * Check whether Grid 3 appears to be installed (Windows only)
336
313
  */
337
- function isGrid3Installed() {
314
+ async function isGrid3Installed(fileAdapter = io_1.defaultFileAdapter) {
315
+ const { pathExists } = fileAdapter;
338
316
  if (process.platform !== 'win32')
339
317
  return false;
340
318
  const commonDocs = getCommonDocumentsPath();
341
319
  if (!commonDocs)
342
320
  return false;
343
- const grid3BasePath = path.win32.join(commonDocs, 'Smartbox', 'Grid 3', 'Users');
344
- return fs.existsSync(grid3BasePath);
321
+ const grid3BasePath = (0, io_1.joinWin32)(commonDocs, 'Smartbox', 'Grid 3', 'Users');
322
+ return await pathExists(grid3BasePath);
345
323
  }
346
324
  function parseGrid3ContentXml(xmlContent) {
347
325
  const regex = /<r>(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?<\/r>/gis;
@@ -360,10 +338,12 @@ function parseGrid3ContentXml(xmlContent) {
360
338
  * @param historyDbPath Absolute path to the history database
361
339
  * @returns Parsed history entries grouped by phrase
362
340
  */
363
- function readGrid3History(historyDbPath) {
364
- if (!fs.existsSync(historyDbPath))
341
+ async function readGrid3History(historyDbPath, fileAdapter = io_1.defaultFileAdapter) {
342
+ const { pathExists } = fileAdapter;
343
+ if (!(await pathExists(historyDbPath)))
365
344
  return [];
366
- const db = new better_sqlite3_1.default(historyDbPath, { readonly: true });
345
+ const Database = (0, sqlite_1.requireBetterSqlite3)();
346
+ const db = new Database(historyDbPath, { readonly: true });
367
347
  const rows = db
368
348
  .prepare(`
369
349
  SELECT p.Id as PhraseId,
@@ -420,17 +400,18 @@ function readGrid3History(historyDbPath) {
420
400
  * @param langCode Optional language code to narrow selection (case-insensitive)
421
401
  * @returns History entries for that user/language, or empty array if none
422
402
  */
423
- function readGrid3HistoryForUser(userName, langCode) {
424
- const dbPath = findGrid3UserHistory(userName, langCode);
403
+ async function readGrid3HistoryForUser(userName, langCode) {
404
+ const dbPath = await findGrid3UserHistory(userName, langCode);
425
405
  if (!dbPath)
426
406
  return [];
427
- return readGrid3History(dbPath);
407
+ return await readGrid3History(dbPath);
428
408
  }
429
409
  /**
430
410
  * Load all available Grid 3 histories on the machine.
431
411
  * @returns Combined history entries from every discovered history.sqlite
432
412
  */
433
- function readAllGrid3History() {
434
- const paths = findGrid3HistoryDatabases();
435
- return paths.flatMap((p) => readGrid3History(p));
413
+ async function readAllGrid3History() {
414
+ const paths = await findGrid3HistoryDatabases();
415
+ const history = await Promise.all(paths.map(async (p) => await readGrid3History(p)));
416
+ return history.flat();
436
417
  }
@@ -4,8 +4,8 @@
4
4
  * These utilities help developers understand why images might not be resolving
5
5
  * correctly in Grid3 gridsets.
6
6
  */
7
- import { type ZipAdapter } from '../../utils/zip';
8
- import { type ProcessorInput } from '../../utils/io';
7
+ import { FileAdapter, type ProcessorInput } from '../../utils/io';
8
+ import { ZipAdapter } from '../../utils/zip';
9
9
  export interface ImageIssue {
10
10
  gridName: string;
11
11
  cellX: number;
@@ -36,9 +36,7 @@ export interface ImageAuditResult {
36
36
  * console.log(`Cell (${issue.cellX}, ${issue.cellY}): ${issue.suggestion}`);
37
37
  * });
38
38
  */
39
- export declare function auditGridsetImages(gridsetBuffer: Uint8Array, password?: string | undefined, zipAdapter?: (input: ProcessorInput) => Promise<{
40
- zip: ZipAdapter;
41
- }>): Promise<ImageAuditResult>;
39
+ export declare function auditGridsetImages(gridsetBuffer: Uint8Array, password?: string | undefined, fileAdapter?: FileAdapter, zipAdapter?: (input: ProcessorInput) => Promise<ZipAdapter>): Promise<ImageAuditResult>;
42
40
  /**
43
41
  * Get a human-readable summary of image audit results
44
42
  */
@@ -8,11 +8,11 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.auditGridsetImages = auditGridsetImages;
10
10
  exports.formatImageAuditSummary = formatImageAuditSummary;
11
- const zip_1 = require("../../utils/zip");
12
11
  const password_1 = require("./password");
13
12
  const password_2 = require("./password");
14
13
  const fast_xml_parser_1 = require("fast-xml-parser");
15
14
  const io_1 = require("../../utils/io");
15
+ const zip_1 = require("../../utils/zip");
16
16
  /**
17
17
  * Audit a gridset file to find image resolution issues
18
18
  *
@@ -26,7 +26,7 @@ const io_1 = require("../../utils/io");
26
26
  * console.log(`Cell (${issue.cellX}, ${issue.cellY}): ${issue.suggestion}`);
27
27
  * });
28
28
  */
29
- async function auditGridsetImages(gridsetBuffer, password = (0, password_2.resolveGridsetPasswordFromEnv)(), zipAdapter) {
29
+ async function auditGridsetImages(gridsetBuffer, password = (0, password_2.resolveGridsetPasswordFromEnv)(), fileAdapter = io_1.defaultFileAdapter, zipAdapter) {
30
30
  const issues = [];
31
31
  const availableImages = new Set();
32
32
  let totalCells = 0;
@@ -34,9 +34,9 @@ async function auditGridsetImages(gridsetBuffer, password = (0, password_2.resol
34
34
  let resolvedImages = 0;
35
35
  let unresolvedImages = 0;
36
36
  try {
37
- const { zip } = zipAdapter
37
+ const zip = zipAdapter
38
38
  ? await zipAdapter(gridsetBuffer)
39
- : await (0, zip_1.openZipFromInput)(gridsetBuffer);
39
+ : await (0, zip_1.getZipAdapter)(gridsetBuffer, fileAdapter);
40
40
  const entries = (0, password_1.getZipEntriesFromAdapter)(zip, password);
41
41
  const parser = new fast_xml_parser_1.XMLParser();
42
42
  // Collect all image files in the gridset
@@ -1,7 +1,7 @@
1
1
  import type JSZip from 'jszip';
2
2
  import { ProcessorOptions } from '../../core/baseProcessor';
3
3
  import { ProcessorInput } from '../../utils/io';
4
- import { type ZipAdapter } from '../../utils/zip';
4
+ import { ZipAdapter } from '../../utils/zip';
5
5
  /**
6
6
  * Resolve the password to use for Grid3 archives.
7
7
  * Preference order:
@@ -12,6 +12,8 @@
12
12
  * c. For Tawasol: provide alternative sources
13
13
  */
14
14
  import { type SymbolReference } from './symbols';
15
+ import { FileAdapter, ProcessorInput } from '../../utils/io';
16
+ import { ZipAdapter } from '../../utils/zip';
15
17
  /**
16
18
  * Image extraction result
17
19
  */
@@ -50,14 +52,14 @@ export interface SymbolExtractionOptions {
50
52
  * @param options - Extraction options
51
53
  * @returns Extracted image data
52
54
  */
53
- export declare function extractButtonImage(gridsetBuffer: Buffer, resolvedImageEntry: string | undefined, symbolReference: string | undefined, options?: SymbolExtractionOptions): ExtractedImage;
55
+ export declare function extractButtonImage(gridsetBuffer: Buffer, resolvedImageEntry: string | undefined, symbolReference: string | undefined, options?: SymbolExtractionOptions, fileAdapter?: FileAdapter, zipAdapter?: (input: ProcessorInput) => Promise<ZipAdapter>): Promise<ExtractedImage>;
54
56
  /**
55
57
  * Extract image from symbol library
56
58
  * @param reference - Symbol reference like "[tawasl]/food/apple.png"
57
59
  * @param options - Extraction options
58
60
  * @returns Extracted image or reference info
59
61
  */
60
- export declare function extractSymbolLibraryImage(reference: string, options?: SymbolExtractionOptions): ExtractedImage;
62
+ export declare function extractSymbolLibraryImage(reference: string, options?: SymbolExtractionOptions): Promise<ExtractedImage>;
61
63
  /**
62
64
  * Convert extracted image to Asterics Grid format
63
65
  * @param extracted - Extracted image
@@ -95,7 +97,7 @@ export declare function suggestExtractionStrategy(report: SymbolReport): string;
95
97
  /**
96
98
  * Export symbol references to CSV for manual extraction
97
99
  */
98
- export declare function exportSymbolReferencesToCsv(report: SymbolReport, outputPath: string): void;
100
+ export declare function exportSymbolReferencesToCsv(report: SymbolReport, outputPath: string, fileAdapter?: FileAdapter): Promise<void>;
99
101
  /**
100
102
  * Create a manifest file for missing symbols
101
103
  */
@@ -12,32 +12,6 @@
12
12
  * b. Provide reference/URL for manual resolution
13
13
  * c. For Tawasol: provide alternative sources
14
14
  */
15
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- var desc = Object.getOwnPropertyDescriptor(m, k);
18
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
- desc = { enumerable: true, get: function() { return m[k]; } };
20
- }
21
- Object.defineProperty(o, k2, desc);
22
- }) : (function(o, m, k, k2) {
23
- if (k2 === undefined) k2 = k;
24
- o[k2] = m[k];
25
- }));
26
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
27
- Object.defineProperty(o, "default", { enumerable: true, value: v });
28
- }) : function(o, v) {
29
- o["default"] = v;
30
- });
31
- var __importStar = (this && this.__importStar) || function (mod) {
32
- if (mod && mod.__esModule) return mod;
33
- var result = {};
34
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
35
- __setModuleDefault(result, mod);
36
- return result;
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
15
  Object.defineProperty(exports, "__esModule", { value: true });
42
16
  exports.extractButtonImage = extractButtonImage;
43
17
  exports.extractSymbolLibraryImage = extractSymbolLibraryImage;
@@ -46,9 +20,9 @@ exports.analyzeSymbolExtraction = analyzeSymbolExtraction;
46
20
  exports.suggestExtractionStrategy = suggestExtractionStrategy;
47
21
  exports.exportSymbolReferencesToCsv = exportSymbolReferencesToCsv;
48
22
  exports.createSymbolManifest = createSymbolManifest;
49
- const fs = __importStar(require("fs"));
50
- const adm_zip_1 = __importDefault(require("adm-zip"));
51
23
  const symbols_1 = require("./symbols");
24
+ const io_1 = require("../../utils/io");
25
+ const zip_1 = require("../../utils/zip");
52
26
  /**
53
27
  * Known open-license symbol sources
54
28
  */
@@ -80,15 +54,17 @@ const OPEN_LICENSE_SYMBOLS = {
80
54
  * @param options - Extraction options
81
55
  * @returns Extracted image data
82
56
  */
83
- function extractButtonImage(gridsetBuffer, resolvedImageEntry, symbolReference, options = {}) {
57
+ async function extractButtonImage(gridsetBuffer, resolvedImageEntry, symbolReference, options = {}, fileAdapter = io_1.defaultFileAdapter, zipAdapter) {
84
58
  // Priority 1: Use embedded image if available
85
59
  if (resolvedImageEntry && options.preferEmbedded !== false) {
86
60
  try {
87
- const zip = new adm_zip_1.default(gridsetBuffer);
88
- const entries = zip.getEntries();
89
- const entry = entries.find((e) => e.entryName === resolvedImageEntry);
61
+ const zip = zipAdapter
62
+ ? await zipAdapter(gridsetBuffer)
63
+ : await (0, zip_1.getZipAdapter)(gridsetBuffer, fileAdapter);
64
+ const entries = zip.listFiles();
65
+ const entry = entries.find((e) => e === resolvedImageEntry);
90
66
  if (entry) {
91
- const data = entry.getData();
67
+ const data = Buffer.from(await zip.readFile(entry));
92
68
  const format = detectImageFormat(data);
93
69
  return {
94
70
  found: true,
@@ -105,7 +81,7 @@ function extractButtonImage(gridsetBuffer, resolvedImageEntry, symbolReference,
105
81
  }
106
82
  // Priority 2: Check symbol library reference
107
83
  if (symbolReference) {
108
- return extractSymbolLibraryImage(symbolReference, options);
84
+ return await extractSymbolLibraryImage(symbolReference, options);
109
85
  }
110
86
  // Not found
111
87
  return {
@@ -119,7 +95,7 @@ function extractButtonImage(gridsetBuffer, resolvedImageEntry, symbolReference,
119
95
  * @param options - Extraction options
120
96
  * @returns Extracted image or reference info
121
97
  */
122
- function extractSymbolLibraryImage(reference, options = {}) {
98
+ async function extractSymbolLibraryImage(reference, options = {}) {
123
99
  const ref = parseSymbolReferenceSafe(reference);
124
100
  if (!ref || !ref.isValid) {
125
101
  return {
@@ -131,7 +107,7 @@ function extractSymbolLibraryImage(reference, options = {}) {
131
107
  // Get library metadata
132
108
  const libInfo = OPEN_LICENSE_SYMBOLS[ref.library];
133
109
  // Resolve symbol reference and extract from .symbols file
134
- const resolved = (0, symbols_1.resolveSymbolReference)(reference, {
110
+ const resolved = await (0, symbols_1.resolveSymbolReference)(reference, {
135
111
  grid3Path: options.grid3Path,
136
112
  });
137
113
  const metadata = {
@@ -310,12 +286,13 @@ function parseSymbolReferenceSafe(reference) {
310
286
  /**
311
287
  * Export symbol references to CSV for manual extraction
312
288
  */
313
- function exportSymbolReferencesToCsv(report, outputPath) {
289
+ async function exportSymbolReferencesToCsv(report, outputPath, fileAdapter = io_1.defaultFileAdapter) {
290
+ const { writeTextToPath } = fileAdapter;
314
291
  const lines = ['Reference,Library,Path,Attribution,License'];
315
292
  for (const symbol of report.missingSymbols) {
316
293
  lines.push(`"${symbol.reference}","${symbol.library}","${symbol.path}","${symbol.attribution || ''}","${symbol.license || ''}"`);
317
294
  }
318
- fs.writeFileSync(outputPath, lines.join('\n'));
295
+ await writeTextToPath(outputPath, lines.join('\n'));
319
296
  }
320
297
  function createSymbolManifest(tree, gridsetName) {
321
298
  const manifest = {
@@ -8,6 +8,7 @@
8
8
  * above bw=above bw.png=above bw
9
9
  * active family=active family.png=active family
10
10
  */
11
+ import { FileAdapter } from '../../utils/io';
11
12
  /**
12
13
  * Symbol search result
13
14
  */
@@ -41,20 +42,20 @@ export interface LibrarySearchIndex {
41
42
  * @param pixFilePath - Path to .pix file
42
43
  * @returns Search index
43
44
  */
44
- export declare function parsePixFile(pixFilePath: string): LibrarySearchIndex;
45
+ export declare function parsePixFile(pixFilePath: string, fileAdapter?: FileAdapter): Promise<LibrarySearchIndex>;
45
46
  /**
46
47
  * Load search indexes for all available libraries
47
48
  * @param options - Search options
48
49
  * @returns Map of library name to search index
49
50
  */
50
- export declare function loadSearchIndexes(options?: SymbolSearchOptions): Map<string, LibrarySearchIndex>;
51
+ export declare function loadSearchIndexes(options?: SymbolSearchOptions, fileAdapter?: FileAdapter): Promise<Map<string, LibrarySearchIndex>>;
51
52
  /**
52
53
  * Search for symbols by term
53
54
  * @param searchTerm - Term to search for
54
55
  * @param options - Search options
55
56
  * @returns Array of search results
56
57
  */
57
- export declare function searchSymbols(searchTerm: string, options?: SymbolSearchOptions): SymbolSearchResult[];
58
+ export declare function searchSymbols(searchTerm: string, options?: SymbolSearchOptions): Promise<SymbolSearchResult[]>;
58
59
  /**
59
60
  * Get symbol filename for a specific search term
60
61
  * @param searchTerm - Search term to look up
@@ -62,7 +63,7 @@ export declare function searchSymbols(searchTerm: string, options?: SymbolSearch
62
63
  * @param options - Search options
63
64
  * @returns Symbol filename or undefined
64
65
  */
65
- export declare function getSymbolFilename(searchTerm: string, library: string, options?: SymbolSearchOptions): string | undefined;
66
+ export declare function getSymbolFilename(searchTerm: string, library: string, options?: SymbolSearchOptions): Promise<string | undefined>;
66
67
  /**
67
68
  * Get display name for a symbol filename
68
69
  * @param symbolFilename - Symbol filename (e.g., "above bw.png")
@@ -70,34 +71,34 @@ export declare function getSymbolFilename(searchTerm: string, library: string, o
70
71
  * @param options - Search options
71
72
  * @returns Display name or undefined
72
73
  */
73
- export declare function getSymbolDisplayName(symbolFilename: string, library: string, options?: SymbolSearchOptions): string | undefined;
74
+ export declare function getSymbolDisplayName(symbolFilename: string, library: string, options?: SymbolSearchOptions): Promise<string | undefined>;
74
75
  /**
75
76
  * Get all search terms for a library
76
77
  * @param library - Library name
77
78
  * @param options - Search options
78
79
  * @returns Array of search terms
79
80
  */
80
- export declare function getAllSearchTerms(library: string, options?: SymbolSearchOptions): string[];
81
+ export declare function getAllSearchTerms(library: string, options?: SymbolSearchOptions): Promise<string[]>;
81
82
  /**
82
83
  * Search suggestions (autocomplete)
83
84
  * @param partialTerm - Partial search term
84
85
  * @param options - Search options
85
86
  * @returns Array of suggested terms
86
87
  */
87
- export declare function getSearchSuggestions(partialTerm: string, options?: SymbolSearchOptions): string[];
88
+ export declare function getSearchSuggestions(partialTerm: string, options?: SymbolSearchOptions): Promise<string[]>;
88
89
  /**
89
90
  * Search for symbols and return results with library references
90
91
  * @param searchTerm - Term to search for
91
92
  * @param options - Search options
92
93
  * @returns Array of full symbol references
93
94
  */
94
- export declare function searchSymbolsWithReferences(searchTerm: string, options?: SymbolSearchOptions): string[];
95
+ export declare function searchSymbolsWithReferences(searchTerm: string, options?: SymbolSearchOptions): Promise<string[]>;
95
96
  /**
96
97
  * Count symbols in each library
97
98
  * @param options - Search options
98
99
  * @returns Map of library name to symbol count
99
100
  */
100
- export declare function countLibrarySymbols(options?: SymbolSearchOptions): Map<string, number>;
101
+ export declare function countLibrarySymbols(options?: SymbolSearchOptions): Promise<Map<string, number>>;
101
102
  /**
102
103
  * Get statistics about symbol libraries
103
104
  */
@@ -114,4 +115,4 @@ export interface SymbolSearchStats {
114
115
  * @param options - Search options
115
116
  * @returns Statistics about available symbols
116
117
  */
117
- export declare function getSymbolSearchStats(options?: SymbolSearchOptions): SymbolSearchStats;
118
+ export declare function getSymbolSearchStats(options?: SymbolSearchOptions): Promise<SymbolSearchStats>;