@willwade/aac-processors 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/core/baseProcessor.js +4 -0
- package/dist/browser/processors/applePanelsProcessor.js +24 -31
- package/dist/browser/processors/astericsGridProcessor.js +10 -3
- package/dist/browser/processors/dotProcessor.js +5 -2
- package/dist/browser/processors/gridset/colorUtils.js +354 -0
- package/dist/browser/processors/gridset/helpers.js +49 -45
- package/dist/browser/processors/gridset/index.js +61 -0
- package/dist/browser/processors/gridset/styleHelpers.js +205 -0
- package/dist/browser/processors/gridset/symbolExtractor.js +331 -0
- package/dist/browser/processors/gridset/symbolSearch.js +248 -0
- package/dist/browser/processors/gridset/symbols.js +35 -68
- package/dist/browser/processors/gridsetProcessor.js +32 -41
- package/dist/browser/processors/obfProcessor.js +20 -33
- package/dist/browser/processors/opmlProcessor.js +5 -2
- package/dist/browser/processors/snap/helpers.js +49 -45
- package/dist/browser/processors/snapProcessor.js +39 -42
- package/dist/browser/processors/touchchatProcessor.js +54 -45
- package/dist/browser/utilities/analytics/reference/index.js +27 -19
- package/dist/browser/utils/io.js +67 -14
- package/dist/browser/utils/sqlite.js +6 -8
- package/dist/browser/utils/zip.js +45 -43
- package/dist/browser/validation/baseValidator.js +5 -0
- package/dist/browser/validation/gridsetValidator.js +12 -20
- package/dist/browser/validation/obfValidator.js +5 -4
- package/dist/browser/validation/snapValidator.js +9 -5
- package/dist/browser/validation/touchChatValidator.js +21 -11
- package/dist/cli/index.js +10 -15
- package/dist/core/baseProcessor.d.ts +7 -7
- package/dist/core/baseProcessor.js +4 -0
- package/dist/processors/applePanelsProcessor.js +29 -36
- package/dist/processors/astericsGridProcessor.js +20 -13
- package/dist/processors/dotProcessor.js +10 -7
- package/dist/processors/excelProcessor.js +9 -12
- package/dist/processors/gridset/helpers.d.ts +9 -11
- package/dist/processors/gridset/helpers.js +49 -71
- package/dist/processors/gridset/imageDebug.d.ts +3 -5
- package/dist/processors/gridset/imageDebug.js +4 -4
- package/dist/processors/gridset/password.d.ts +1 -1
- package/dist/processors/gridset/symbolExtractor.d.ts +5 -3
- package/dist/processors/gridset/symbolExtractor.js +15 -38
- package/dist/processors/gridset/symbolSearch.d.ts +3 -2
- package/dist/processors/gridset/symbolSearch.js +12 -34
- package/dist/processors/gridset/symbols.d.ts +8 -6
- package/dist/processors/gridset/symbols.js +34 -67
- package/dist/processors/gridset/wordlistHelpers.d.ts +4 -6
- package/dist/processors/gridset/wordlistHelpers.js +15 -74
- package/dist/processors/gridsetProcessor.js +36 -68
- package/dist/processors/obfProcessor.js +26 -62
- package/dist/processors/obfsetProcessor.js +2 -2
- package/dist/processors/opmlProcessor.js +10 -7
- package/dist/processors/snap/helpers.d.ts +8 -8
- package/dist/processors/snap/helpers.js +50 -72
- package/dist/processors/snapProcessor.js +38 -41
- package/dist/processors/touchchatProcessor.js +54 -45
- package/dist/utilities/analytics/index.d.ts +3 -2
- package/dist/utilities/analytics/index.js +8 -10
- package/dist/utilities/analytics/reference/index.d.ts +5 -3
- package/dist/utilities/analytics/reference/index.js +26 -18
- package/dist/utilities/symbolTools.d.ts +4 -2
- package/dist/utilities/symbolTools.js +16 -15
- package/dist/utils/io.d.ts +24 -6
- package/dist/utils/io.js +64 -14
- package/dist/utils/sqlite.d.ts +2 -0
- package/dist/utils/sqlite.js +6 -8
- package/dist/utils/zip.d.ts +7 -3
- package/dist/utils/zip.js +45 -43
- package/dist/validation/applePanelsValidator.d.ts +2 -1
- package/dist/validation/applePanelsValidator.js +9 -11
- package/dist/validation/astericsValidator.d.ts +2 -1
- package/dist/validation/astericsValidator.js +5 -4
- package/dist/validation/baseValidator.d.ts +2 -2
- package/dist/validation/baseValidator.js +5 -0
- package/dist/validation/dotValidator.d.ts +2 -1
- package/dist/validation/dotValidator.js +5 -4
- package/dist/validation/excelValidator.d.ts +2 -1
- package/dist/validation/excelValidator.js +5 -4
- package/dist/validation/gridsetValidator.d.ts +2 -1
- package/dist/validation/gridsetValidator.js +11 -22
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +5 -4
- package/dist/validation/obfValidator.d.ts +2 -1
- package/dist/validation/obfValidator.js +5 -4
- package/dist/validation/obfsetValidator.d.ts +2 -1
- package/dist/validation/obfsetValidator.js +5 -4
- package/dist/validation/opmlValidator.d.ts +2 -1
- package/dist/validation/opmlValidator.js +5 -4
- package/dist/validation/snapValidator.d.ts +2 -1
- package/dist/validation/snapValidator.js +9 -5
- package/dist/validation/touchChatValidator.d.ts +4 -6
- package/dist/validation/touchChatValidator.js +21 -11
- package/dist/validation/validationTypes.d.ts +8 -1
- package/package.json +1 -1
- package/dist/core/fileProcessor.d.ts +0 -7
- package/dist/core/fileProcessor.js +0 -57
|
@@ -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
|
+
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
|
-
|
|
153
|
-
if (defaultPath && fs.existsSync(defaultPath)) {
|
|
122
|
+
if (defaultPath && 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 (
|
|
134
|
+
if (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
|
|
183
|
-
return
|
|
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
|
|
194
|
-
return
|
|
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 = {}) {
|
|
170
|
+
function getAvailableSymbolLibraries(options = {}, fileAdapter) {
|
|
171
|
+
const { pathExists, getFileSize, listDir, join, basename } = fileAdapter ?? io_1.defaultFileAdapter;
|
|
202
172
|
const grid3Path = options.grid3Path || options.symbolDir || getDefaultGrid3Path();
|
|
203
173
|
if (!grid3Path) {
|
|
204
174
|
return [];
|
|
205
175
|
}
|
|
206
|
-
const symbolsDir = getSymbolLibrariesDir(grid3Path);
|
|
207
|
-
|
|
208
|
-
if (!fs.existsSync(symbolsDir)) {
|
|
176
|
+
const symbolsDir = getSymbolLibrariesDir(grid3Path, fileAdapter);
|
|
177
|
+
if (!pathExists(symbolsDir)) {
|
|
209
178
|
return [];
|
|
210
179
|
}
|
|
211
180
|
const libraries = [];
|
|
212
|
-
const files =
|
|
181
|
+
const files = listDir(symbolsDir);
|
|
213
182
|
for (const file of files) {
|
|
214
183
|
if (file.endsWith('.symbols')) {
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
const libraryName = path.basename(file, '.symbols');
|
|
184
|
+
const fullPath = join(symbolsDir, file);
|
|
185
|
+
const size = 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
|
|
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 = {}) {
|
|
204
|
+
function getSymbolLibraryInfo(libraryName, options = {}, fileAdapter) {
|
|
205
|
+
const { pathExists, getFileSize, join } = fileAdapter ?? io_1.defaultFileAdapter;
|
|
237
206
|
const grid3Path = options.grid3Path || options.symbolDir || 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
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (fs.existsSync(fullPath)) {
|
|
254
|
-
const stats = fs.statSync(fullPath);
|
|
219
|
+
const fullPath = join(symbolsDir, file);
|
|
220
|
+
if (pathExists(fullPath)) {
|
|
221
|
+
const size = getFileSize(fullPath);
|
|
255
222
|
return {
|
|
256
223
|
name: libraryName,
|
|
257
224
|
pixFile: fullPath,
|
|
258
225
|
exists: true,
|
|
259
|
-
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 {
|
|
@@ -296,16 +263,16 @@ function resolveSymbolReference(reference, options = {}) {
|
|
|
296
263
|
}
|
|
297
264
|
try {
|
|
298
265
|
// .symbols files are ZIP archives
|
|
299
|
-
const
|
|
300
|
-
const zip =
|
|
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.
|
|
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.
|
|
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 =
|
|
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 =
|
|
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
|
|
12
|
-
import {
|
|
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
|
|
111
|
+
const zip = zipAdapter
|
|
135
112
|
? await zipAdapter(gridsetBuffer)
|
|
136
|
-
: await (0, zip_1.
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
279
|
-
|
|
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
|
-
|
|
294
|
-
throw new Error('Failed to serialize updated gridset.');
|
|
295
|
-
}
|
|
296
|
-
return await saveZip();
|
|
237
|
+
return await zip.writeFiles(updatedEntries);
|
|
297
238
|
}
|
|
@@ -1,27 +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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.GridsetProcessor = void 0;
|
|
27
4
|
const baseProcessor_1 = require("../core/baseProcessor");
|
|
@@ -40,7 +17,6 @@ const resolver_2 = require("./gridset/resolver");
|
|
|
40
17
|
const idGenerator_1 = require("../utilities/analytics/utils/idGenerator");
|
|
41
18
|
const symbolAlignment_1 = require("./gridset/symbolAlignment");
|
|
42
19
|
const io_1 = require("../utils/io");
|
|
43
|
-
const zip_1 = require("../utils/zip");
|
|
44
20
|
class GridsetProcessor extends baseProcessor_1.BaseProcessor {
|
|
45
21
|
constructor(options) {
|
|
46
22
|
super(options);
|
|
@@ -421,19 +397,18 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
|
|
|
421
397
|
return texts;
|
|
422
398
|
}
|
|
423
399
|
async loadIntoTree(filePathOrBuffer) {
|
|
400
|
+
const { readBinaryFromInput } = this.options.fileAdapter;
|
|
424
401
|
const tree = new treeStructure_1.AACTree();
|
|
425
402
|
let zipResult;
|
|
426
403
|
try {
|
|
427
|
-
const zipInput =
|
|
428
|
-
zipResult = this.options.zipAdapter
|
|
429
|
-
? await this.options.zipAdapter(zipInput)
|
|
430
|
-
: await (0, zip_1.openZipFromInput)(zipInput);
|
|
404
|
+
const zipInput = readBinaryFromInput(filePathOrBuffer);
|
|
405
|
+
zipResult = await this.options.zipAdapter(zipInput);
|
|
431
406
|
}
|
|
432
407
|
catch (error) {
|
|
433
408
|
throw new Error(`Invalid ZIP file format: ${error.message}`);
|
|
434
409
|
}
|
|
435
410
|
const password = this.getGridsetPassword(filePathOrBuffer);
|
|
436
|
-
const entries = (0, password_1.getZipEntriesFromAdapter)(zipResult
|
|
411
|
+
const entries = (0, password_1.getZipEntriesFromAdapter)(zipResult, password);
|
|
437
412
|
const options = {
|
|
438
413
|
ignoreAttributes: false,
|
|
439
414
|
ignoreDeclaration: true,
|
|
@@ -1709,6 +1684,7 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
|
|
|
1709
1684
|
return tree;
|
|
1710
1685
|
}
|
|
1711
1686
|
async processTexts(filePathOrBuffer, translations, outputPath) {
|
|
1687
|
+
const { readBinaryFromInput } = this.options.fileAdapter;
|
|
1712
1688
|
// Load the tree, apply translations, and save to new file
|
|
1713
1689
|
const tree = await this.loadIntoTree(filePathOrBuffer);
|
|
1714
1690
|
// Apply translations to all text content
|
|
@@ -1769,7 +1745,7 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
|
|
|
1769
1745
|
});
|
|
1770
1746
|
// Save the translated tree and return its content
|
|
1771
1747
|
await this.saveFromTree(tree, outputPath);
|
|
1772
|
-
return
|
|
1748
|
+
return readBinaryFromInput(outputPath);
|
|
1773
1749
|
}
|
|
1774
1750
|
/**
|
|
1775
1751
|
* Extract symbol information from a gridset for LLM-based translation.
|
|
@@ -1811,6 +1787,7 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
|
|
|
1811
1787
|
* @returns Buffer of the translated gridset
|
|
1812
1788
|
*/
|
|
1813
1789
|
async processLLMTranslations(filePathOrBuffer, llmTranslations, outputPath, options) {
|
|
1790
|
+
const { readBinaryFromInput } = this.options.fileAdapter;
|
|
1814
1791
|
const tree = await this.loadIntoTree(filePathOrBuffer);
|
|
1815
1792
|
// Validate translations using shared utility
|
|
1816
1793
|
const buttonIds = Object.values(tree.pages).flatMap((page) => page.buttons.map((b) => b.id));
|
|
@@ -1849,40 +1826,16 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
|
|
|
1849
1826
|
});
|
|
1850
1827
|
// Save and return
|
|
1851
1828
|
await this.saveFromTree(tree, outputPath);
|
|
1852
|
-
return
|
|
1829
|
+
return readBinaryFromInput(outputPath);
|
|
1853
1830
|
}
|
|
1854
1831
|
async saveFromTree(tree, outputPath) {
|
|
1855
|
-
const
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
let finalizeZip;
|
|
1859
|
-
if (useNodeZip) {
|
|
1860
|
-
const AdmZip = (0, io_1.getNodeRequire)()('adm-zip');
|
|
1861
|
-
const zip = new AdmZip();
|
|
1862
|
-
addText = (entryPath, content) => {
|
|
1863
|
-
zip.addFile(entryPath, Buffer.from(content, 'utf8'));
|
|
1864
|
-
};
|
|
1865
|
-
addBinary = (entryPath, content) => {
|
|
1866
|
-
zip.addFile(entryPath, Buffer.from(content));
|
|
1867
|
-
};
|
|
1868
|
-
finalizeZip = () => Promise.resolve(zip.toBuffer());
|
|
1869
|
-
}
|
|
1870
|
-
else {
|
|
1871
|
-
const module = await Promise.resolve().then(() => __importStar(require('jszip')));
|
|
1872
|
-
const JSZip = module.default || module;
|
|
1873
|
-
const zip = new JSZip();
|
|
1874
|
-
addText = (entryPath, content) => {
|
|
1875
|
-
zip.file(entryPath, content, { binary: false });
|
|
1876
|
-
};
|
|
1877
|
-
addBinary = (entryPath, content) => {
|
|
1878
|
-
zip.file(entryPath, content);
|
|
1879
|
-
};
|
|
1880
|
-
finalizeZip = async () => zip.generateAsync({ type: 'uint8array' });
|
|
1881
|
-
}
|
|
1832
|
+
const files = [];
|
|
1833
|
+
const { writeBinaryToPath } = this.options.fileAdapter;
|
|
1834
|
+
const zip = await this.options.zipAdapter();
|
|
1882
1835
|
if (Object.keys(tree.pages).length === 0) {
|
|
1883
1836
|
// Create empty zip for empty tree
|
|
1884
|
-
const zipBuffer = await
|
|
1885
|
-
|
|
1837
|
+
const zipBuffer = await zip.writeFiles([]);
|
|
1838
|
+
writeBinaryToPath(outputPath, zipBuffer);
|
|
1886
1839
|
return;
|
|
1887
1840
|
}
|
|
1888
1841
|
// Collect all unique styles from pages and buttons
|
|
@@ -1954,7 +1907,10 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
|
|
|
1954
1907
|
suppressEmptyNode: true,
|
|
1955
1908
|
});
|
|
1956
1909
|
const settingsXmlContent = settingsBuilder.build(settingsData);
|
|
1957
|
-
|
|
1910
|
+
files.push({
|
|
1911
|
+
name: 'Settings0/settings.xml',
|
|
1912
|
+
data: settingsXmlContent,
|
|
1913
|
+
});
|
|
1958
1914
|
// Create Settings0/Styles/style.xml if there are styles
|
|
1959
1915
|
if (uniqueStyles.size > 0) {
|
|
1960
1916
|
const stylesArray = Array.from(uniqueStyles.values()).map(({ id, style }) => {
|
|
@@ -1987,7 +1943,10 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
|
|
|
1987
1943
|
indentBy: ' ',
|
|
1988
1944
|
});
|
|
1989
1945
|
const styleXmlContent = styleBuilder.build(styleData);
|
|
1990
|
-
|
|
1946
|
+
files.push({
|
|
1947
|
+
name: 'Settings0/Styles/styles.xml',
|
|
1948
|
+
data: styleXmlContent,
|
|
1949
|
+
});
|
|
1991
1950
|
}
|
|
1992
1951
|
// Collect grid file paths for FileMap.xml
|
|
1993
1952
|
const gridFilePaths = [];
|
|
@@ -2128,14 +2087,20 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
|
|
|
2128
2087
|
// Add to zip in Grids folder with proper Grid3 naming
|
|
2129
2088
|
const gridPath = `Grids/${page.name || page.id}/grid.xml`;
|
|
2130
2089
|
gridFilePaths.push(gridPath);
|
|
2131
|
-
|
|
2090
|
+
files.push({
|
|
2091
|
+
name: gridPath,
|
|
2092
|
+
data: xmlContent,
|
|
2093
|
+
});
|
|
2132
2094
|
});
|
|
2133
2095
|
// Write image files to ZIP
|
|
2134
2096
|
buttonImages.forEach((imgData) => {
|
|
2135
2097
|
if (imgData.imageData && imgData.imageData.length > 0) {
|
|
2136
2098
|
// Create image path in the grid's directory
|
|
2137
2099
|
const imagePath = `Grids/${imgData.pageName}/${imgData.x}-${imgData.y}-0-text-0.${imgData.ext}`;
|
|
2138
|
-
|
|
2100
|
+
files.push({
|
|
2101
|
+
name: imagePath,
|
|
2102
|
+
data: imgData.imageData,
|
|
2103
|
+
});
|
|
2139
2104
|
}
|
|
2140
2105
|
});
|
|
2141
2106
|
// Create FileMap.xml to map all grid files with their dynamic image files
|
|
@@ -2174,10 +2139,13 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
|
|
|
2174
2139
|
indentBy: ' ',
|
|
2175
2140
|
});
|
|
2176
2141
|
const fileMapXmlContent = fileMapBuilder.build(fileMapData);
|
|
2177
|
-
|
|
2142
|
+
files.push({
|
|
2143
|
+
name: 'FileMap.xml',
|
|
2144
|
+
data: fileMapXmlContent,
|
|
2145
|
+
});
|
|
2178
2146
|
// Write the zip file
|
|
2179
|
-
const zipBuffer = await
|
|
2180
|
-
|
|
2147
|
+
const zipBuffer = await zip.writeFiles(files);
|
|
2148
|
+
writeBinaryToPath(outputPath, zipBuffer);
|
|
2181
2149
|
}
|
|
2182
2150
|
// Helper method to calculate column definitions based on page layout
|
|
2183
2151
|
calculateColumnDefinitions(page) {
|
|
@@ -2274,7 +2242,7 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
|
|
|
2274
2242
|
* @returns Promise with validation result
|
|
2275
2243
|
*/
|
|
2276
2244
|
async validate(filePath) {
|
|
2277
|
-
return gridsetValidator_1.GridsetValidator.validateFile(filePath);
|
|
2245
|
+
return gridsetValidator_1.GridsetValidator.validateFile(filePath, this.options.fileAdapter);
|
|
2278
2246
|
}
|
|
2279
2247
|
}
|
|
2280
2248
|
exports.GridsetProcessor = GridsetProcessor;
|