@willwade/aac-processors 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -31,7 +31,9 @@ Browser-safe entry that avoids Node-only dependencies. It expects `Buffer`,
|
|
|
31
31
|
`Uint8Array`, or `ArrayBuffer` inputs rather than file paths.
|
|
32
32
|
|
|
33
33
|
SQLite-backed formats (Snap `.sps/.spb` and TouchChat `.ce`) require a WASM
|
|
34
|
-
SQLite engine.
|
|
34
|
+
SQLite engine. To support these, configure `sql.js` in your bundler
|
|
35
|
+
and either include `<script src="sql-wasm.js"></script>` in your HTML, or
|
|
36
|
+
`window.initSqlJs = require('sql.js');` in your app.
|
|
35
37
|
|
|
36
38
|
```ts
|
|
37
39
|
import { configureSqlJs, SnapProcessor } from '@willwade/aac-processors/browser';
|
|
@@ -587,15 +587,29 @@ class ObfProcessor extends BaseProcessor {
|
|
|
587
587
|
await writeTextToPath(outputPath, JSON.stringify(obfBoard, null, 2));
|
|
588
588
|
}
|
|
589
589
|
else {
|
|
590
|
+
const getPageFilename = (id) => (id.endsWith('.obf') ? id : `${id}.obf`);
|
|
590
591
|
const files = Object.values(tree.pages).map((page) => {
|
|
591
592
|
const obfBoard = this.createObfBoardFromPage(page, 'Board', tree.metadata);
|
|
592
593
|
const obfContent = JSON.stringify(obfBoard, null, 2);
|
|
593
|
-
const name = page.id
|
|
594
|
+
const name = getPageFilename(page.id);
|
|
594
595
|
return {
|
|
595
596
|
name,
|
|
596
597
|
data: new TextEncoder().encode(obfContent),
|
|
597
598
|
};
|
|
598
599
|
});
|
|
600
|
+
const manifest = {
|
|
601
|
+
format: OBF_FORMAT_VERSION,
|
|
602
|
+
root: tree.metadata.defaultHomePageId,
|
|
603
|
+
paths: {
|
|
604
|
+
boards: Object.fromEntries(Object.entries(tree.pages).map(([id, page]) => [id, getPageFilename(page.id)])),
|
|
605
|
+
images: {}, //TODO Add support for saving images as files
|
|
606
|
+
sounds: {}, //TODO Add support for saving sounds as files
|
|
607
|
+
},
|
|
608
|
+
};
|
|
609
|
+
files.push({
|
|
610
|
+
name: 'manifest.json',
|
|
611
|
+
data: new TextEncoder().encode(JSON.stringify(manifest)),
|
|
612
|
+
});
|
|
599
613
|
const fileExists = await pathExists(outputPath);
|
|
600
614
|
this.zipFile = await this.options.zipAdapter(fileExists ? outputPath : undefined, this.options.fileAdapter);
|
|
601
615
|
const zipData = await this.zipFile.writeFiles(files);
|
|
@@ -4,12 +4,16 @@ let sqlJsPromise = null;
|
|
|
4
4
|
export function configureSqlJs(config) {
|
|
5
5
|
sqlJsConfig = { ...(sqlJsConfig ?? {}), ...config };
|
|
6
6
|
}
|
|
7
|
-
async function
|
|
7
|
+
async function getSqlJsBrowser() {
|
|
8
8
|
if (!sqlJsPromise) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const isBrowser = typeof globalThis !== 'undefined' && globalThis.window !== undefined;
|
|
10
|
+
if (!isBrowser)
|
|
11
|
+
throw new Error('Must be run in a browser');
|
|
12
|
+
const window = globalThis.window;
|
|
13
|
+
if (!('initSqlJs' in window))
|
|
14
|
+
throw new Error('Need to add sql-wasm.js script element to DOM');
|
|
15
|
+
const initSqlJs = window.initSqlJs;
|
|
16
|
+
sqlJsPromise = initSqlJs(sqlJsConfig ?? {});
|
|
13
17
|
}
|
|
14
18
|
return sqlJsPromise;
|
|
15
19
|
}
|
|
@@ -81,7 +85,7 @@ export async function openSqliteDatabase(input, options = {}) {
|
|
|
81
85
|
}
|
|
82
86
|
const data = await readBinaryFromInput(input);
|
|
83
87
|
if (!isNodeRuntime()) {
|
|
84
|
-
const SQL = await
|
|
88
|
+
const SQL = await getSqlJsBrowser();
|
|
85
89
|
const db = new SQL.Database(data);
|
|
86
90
|
return { db: createSqlJsAdapter(db) };
|
|
87
91
|
}
|
|
@@ -590,15 +590,29 @@ class ObfProcessor extends baseProcessor_1.BaseProcessor {
|
|
|
590
590
|
await writeTextToPath(outputPath, JSON.stringify(obfBoard, null, 2));
|
|
591
591
|
}
|
|
592
592
|
else {
|
|
593
|
+
const getPageFilename = (id) => (id.endsWith('.obf') ? id : `${id}.obf`);
|
|
593
594
|
const files = Object.values(tree.pages).map((page) => {
|
|
594
595
|
const obfBoard = this.createObfBoardFromPage(page, 'Board', tree.metadata);
|
|
595
596
|
const obfContent = JSON.stringify(obfBoard, null, 2);
|
|
596
|
-
const name = page.id
|
|
597
|
+
const name = getPageFilename(page.id);
|
|
597
598
|
return {
|
|
598
599
|
name,
|
|
599
600
|
data: new TextEncoder().encode(obfContent),
|
|
600
601
|
};
|
|
601
602
|
});
|
|
603
|
+
const manifest = {
|
|
604
|
+
format: OBF_FORMAT_VERSION,
|
|
605
|
+
root: tree.metadata.defaultHomePageId,
|
|
606
|
+
paths: {
|
|
607
|
+
boards: Object.fromEntries(Object.entries(tree.pages).map(([id, page]) => [id, getPageFilename(page.id)])),
|
|
608
|
+
images: {}, //TODO Add support for saving images as files
|
|
609
|
+
sounds: {}, //TODO Add support for saving sounds as files
|
|
610
|
+
},
|
|
611
|
+
};
|
|
612
|
+
files.push({
|
|
613
|
+
name: 'manifest.json',
|
|
614
|
+
data: new TextEncoder().encode(JSON.stringify(manifest)),
|
|
615
|
+
});
|
|
602
616
|
const fileExists = await pathExists(outputPath);
|
|
603
617
|
this.zipFile = await this.options.zipAdapter(fileExists ? outputPath : undefined, this.options.fileAdapter);
|
|
604
618
|
const zipData = await this.zipFile.writeFiles(files);
|
package/dist/utils/sqlite.js
CHANGED
|
@@ -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.configureSqlJs = configureSqlJs;
|
|
27
4
|
exports.requireBetterSqlite3 = requireBetterSqlite3;
|
|
@@ -32,12 +9,16 @@ let sqlJsPromise = null;
|
|
|
32
9
|
function configureSqlJs(config) {
|
|
33
10
|
sqlJsConfig = { ...(sqlJsConfig ?? {}), ...config };
|
|
34
11
|
}
|
|
35
|
-
async function
|
|
12
|
+
async function getSqlJsBrowser() {
|
|
36
13
|
if (!sqlJsPromise) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
14
|
+
const isBrowser = typeof globalThis !== 'undefined' && globalThis.window !== undefined;
|
|
15
|
+
if (!isBrowser)
|
|
16
|
+
throw new Error('Must be run in a browser');
|
|
17
|
+
const window = globalThis.window;
|
|
18
|
+
if (!('initSqlJs' in window))
|
|
19
|
+
throw new Error('Need to add sql-wasm.js script element to DOM');
|
|
20
|
+
const initSqlJs = window.initSqlJs;
|
|
21
|
+
sqlJsPromise = initSqlJs(sqlJsConfig ?? {});
|
|
41
22
|
}
|
|
42
23
|
return sqlJsPromise;
|
|
43
24
|
}
|
|
@@ -109,7 +90,7 @@ async function openSqliteDatabase(input, options = {}) {
|
|
|
109
90
|
}
|
|
110
91
|
const data = await readBinaryFromInput(input);
|
|
111
92
|
if (!(0, io_1.isNodeRuntime)()) {
|
|
112
|
-
const SQL = await
|
|
93
|
+
const SQL = await getSqlJsBrowser();
|
|
113
94
|
const db = new SQL.Database(data);
|
|
114
95
|
return { db: createSqlJsAdapter(db) };
|
|
115
96
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willwade/aac-processors",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "A comprehensive TypeScript library for processing AAC (Augmentative and Alternative Communication) file formats with translation support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"browser": "dist/browser/index.browser.js",
|
|
@@ -181,7 +181,7 @@
|
|
|
181
181
|
"fast-xml-parser": "^5.2.0",
|
|
182
182
|
"jszip": "^3.10.1",
|
|
183
183
|
"plist": "^3.1.0",
|
|
184
|
-
"sql.js": "^1.
|
|
184
|
+
"sql.js": "^1.14.1",
|
|
185
185
|
"xml2js": "^0.6.2",
|
|
186
186
|
"yauzl": "^3.2.0"
|
|
187
187
|
},
|