@willwade/aac-processors 0.2.2 → 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. Configure `sql.js` in your bundler before loading those formats:
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';
@@ -4,12 +4,16 @@ let sqlJsPromise = null;
4
4
  export function configureSqlJs(config) {
5
5
  sqlJsConfig = { ...(sqlJsConfig ?? {}), ...config };
6
6
  }
7
- async function getSqlJs() {
7
+ async function getSqlJsBrowser() {
8
8
  if (!sqlJsPromise) {
9
- sqlJsPromise = import('sql.js').then((module) => {
10
- const initSqlJs = module.default || module;
11
- return initSqlJs(sqlJsConfig ?? {});
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 getSqlJs();
88
+ const SQL = await getSqlJsBrowser();
85
89
  const db = new SQL.Database(data);
86
90
  return { db: createSqlJsAdapter(db) };
87
91
  }
@@ -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 getSqlJs() {
12
+ async function getSqlJsBrowser() {
36
13
  if (!sqlJsPromise) {
37
- sqlJsPromise = Promise.resolve().then(() => __importStar(require('sql.js'))).then((module) => {
38
- const initSqlJs = module.default || module;
39
- return initSqlJs(sqlJsConfig ?? {});
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 getSqlJs();
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.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.13.0",
184
+ "sql.js": "^1.14.1",
185
185
  "xml2js": "^0.6.2",
186
186
  "yauzl": "^3.2.0"
187
187
  },