math-core 0.1.1

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.
@@ -0,0 +1,26 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ interface MathCoreOptions {
5
+ prettyPrint?: "never" | "always" | "auto";
6
+ macros?: Map<string, string>;
7
+ xmlNamespace?: boolean;
8
+ continueOnError?: boolean;
9
+ }
10
+
11
+
12
+ export class LatexError {
13
+ private constructor();
14
+ free(): void;
15
+ [Symbol.dispose](): void;
16
+ message: any;
17
+ location: number;
18
+ }
19
+ export class LatexToMathML {
20
+ free(): void;
21
+ [Symbol.dispose](): void;
22
+ reset_global_counter(): void;
23
+ convert_with_local_counter(content: string, displaystyle: boolean): string;
24
+ convert_with_global_counter(content: string, displaystyle: boolean): string;
25
+ constructor(js_config: MathCoreOptions);
26
+ }
@@ -0,0 +1,17 @@
1
+
2
+ let imports = {};
3
+ import * as import0 from './math_core_bg.js';
4
+ imports['./math_core_bg.js'] = import0;
5
+
6
+ import { readFileSync } from 'node:fs';
7
+
8
+ const wasmUrl = new URL('math_core_bg.wasm', import.meta.url);
9
+ const wasmBytes = readFileSync(wasmUrl);
10
+ const wasmModule = new WebAssembly.Module(wasmBytes);
11
+ const wasm = new WebAssembly.Instance(wasmModule, imports).exports;
12
+ export { wasm as __wasm };
13
+
14
+ imports["./math_core_bg.js"].__wbg_set_wasm(wasm, wasmModule);
15
+ wasm.__wbindgen_start();
16
+
17
+ export * from "./math_core_bg.js";
@@ -0,0 +1,328 @@
1
+ let wasm;
2
+ let wasmModule;
3
+ export function __wbg_set_wasm(exports, module) {
4
+ wasm = exports;
5
+ wasmModule = module;
6
+ }
7
+
8
+
9
+ let WASM_VECTOR_LEN = 0;
10
+
11
+ let cachedUint8ArrayMemory0 = null;
12
+
13
+ function getUint8ArrayMemory0() {
14
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
15
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
16
+ }
17
+ return cachedUint8ArrayMemory0;
18
+ }
19
+
20
+ const cachedTextEncoder = new TextEncoder();
21
+
22
+ if (!('encodeInto' in cachedTextEncoder)) {
23
+ cachedTextEncoder.encodeInto = function (arg, view) {
24
+ const buf = cachedTextEncoder.encode(arg);
25
+ view.set(buf);
26
+ return {
27
+ read: arg.length,
28
+ written: buf.length
29
+ };
30
+ }
31
+ }
32
+
33
+ function passStringToWasm0(arg, malloc, realloc) {
34
+
35
+ if (realloc === undefined) {
36
+ const buf = cachedTextEncoder.encode(arg);
37
+ const ptr = malloc(buf.length, 1) >>> 0;
38
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
39
+ WASM_VECTOR_LEN = buf.length;
40
+ return ptr;
41
+ }
42
+
43
+ let len = arg.length;
44
+ let ptr = malloc(len, 1) >>> 0;
45
+
46
+ const mem = getUint8ArrayMemory0();
47
+
48
+ let offset = 0;
49
+
50
+ for (; offset < len; offset++) {
51
+ const code = arg.charCodeAt(offset);
52
+ if (code > 0x7F) break;
53
+ mem[ptr + offset] = code;
54
+ }
55
+
56
+ if (offset !== len) {
57
+ if (offset !== 0) {
58
+ arg = arg.slice(offset);
59
+ }
60
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
61
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
62
+ const ret = cachedTextEncoder.encodeInto(arg, view);
63
+
64
+ offset += ret.written;
65
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
66
+ }
67
+
68
+ WASM_VECTOR_LEN = offset;
69
+ return ptr;
70
+ }
71
+
72
+ function isLikeNone(x) {
73
+ return x === undefined || x === null;
74
+ }
75
+
76
+ let cachedDataViewMemory0 = null;
77
+
78
+ function getDataViewMemory0() {
79
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
80
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
81
+ }
82
+ return cachedDataViewMemory0;
83
+ }
84
+
85
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
86
+
87
+ cachedTextDecoder.decode();
88
+
89
+ function decodeText(ptr, len) {
90
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
91
+ }
92
+
93
+ function getStringFromWasm0(ptr, len) {
94
+ ptr = ptr >>> 0;
95
+ return decodeText(ptr, len);
96
+ }
97
+
98
+ function addToExternrefTable0(obj) {
99
+ const idx = wasm.__externref_table_alloc();
100
+ wasm.__wbindgen_externrefs.set(idx, obj);
101
+ return idx;
102
+ }
103
+
104
+ function handleError(f, args) {
105
+ try {
106
+ return f.apply(this, args);
107
+ } catch (e) {
108
+ const idx = addToExternrefTable0(e);
109
+ wasm.__wbindgen_exn_store(idx);
110
+ }
111
+ }
112
+
113
+ function takeFromExternrefTable0(idx) {
114
+ const value = wasm.__wbindgen_externrefs.get(idx);
115
+ wasm.__externref_table_dealloc(idx);
116
+ return value;
117
+ }
118
+
119
+ const LatexErrorFinalization = (typeof FinalizationRegistry === 'undefined')
120
+ ? { register: () => {}, unregister: () => {} }
121
+ : new FinalizationRegistry(ptr => wasm.__wbg_latexerror_free(ptr >>> 0, 1));
122
+
123
+ export class LatexError {
124
+
125
+ static __wrap(ptr) {
126
+ ptr = ptr >>> 0;
127
+ const obj = Object.create(LatexError.prototype);
128
+ obj.__wbg_ptr = ptr;
129
+ LatexErrorFinalization.register(obj, obj.__wbg_ptr, obj);
130
+ return obj;
131
+ }
132
+
133
+ __destroy_into_raw() {
134
+ const ptr = this.__wbg_ptr;
135
+ this.__wbg_ptr = 0;
136
+ LatexErrorFinalization.unregister(this);
137
+ return ptr;
138
+ }
139
+
140
+ free() {
141
+ const ptr = this.__destroy_into_raw();
142
+ wasm.__wbg_latexerror_free(ptr, 0);
143
+ }
144
+ /**
145
+ * @returns {any}
146
+ */
147
+ get message() {
148
+ const ret = wasm.__wbg_get_latexerror_message(this.__wbg_ptr);
149
+ return ret;
150
+ }
151
+ /**
152
+ * @param {any} arg0
153
+ */
154
+ set message(arg0) {
155
+ wasm.__wbg_set_latexerror_message(this.__wbg_ptr, arg0);
156
+ }
157
+ /**
158
+ * @returns {number}
159
+ */
160
+ get location() {
161
+ const ret = wasm.__wbg_get_latexerror_location(this.__wbg_ptr);
162
+ return ret >>> 0;
163
+ }
164
+ /**
165
+ * @param {number} arg0
166
+ */
167
+ set location(arg0) {
168
+ wasm.__wbg_set_latexerror_location(this.__wbg_ptr, arg0);
169
+ }
170
+ }
171
+ if (Symbol.dispose) LatexError.prototype[Symbol.dispose] = LatexError.prototype.free;
172
+
173
+ const LatexToMathMLFinalization = (typeof FinalizationRegistry === 'undefined')
174
+ ? { register: () => {}, unregister: () => {} }
175
+ : new FinalizationRegistry(ptr => wasm.__wbg_latextomathml_free(ptr >>> 0, 1));
176
+
177
+ export class LatexToMathML {
178
+
179
+ __destroy_into_raw() {
180
+ const ptr = this.__wbg_ptr;
181
+ this.__wbg_ptr = 0;
182
+ LatexToMathMLFinalization.unregister(this);
183
+ return ptr;
184
+ }
185
+
186
+ free() {
187
+ const ptr = this.__destroy_into_raw();
188
+ wasm.__wbg_latextomathml_free(ptr, 0);
189
+ }
190
+ reset_global_counter() {
191
+ wasm.latextomathml_reset_global_counter(this.__wbg_ptr);
192
+ }
193
+ /**
194
+ * @param {string} content
195
+ * @param {boolean} displaystyle
196
+ * @returns {string}
197
+ */
198
+ convert_with_local_counter(content, displaystyle) {
199
+ const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
200
+ const len0 = WASM_VECTOR_LEN;
201
+ const ret = wasm.latextomathml_convert_with_local_counter(this.__wbg_ptr, ptr0, len0, displaystyle);
202
+ if (ret[2]) {
203
+ throw takeFromExternrefTable0(ret[1]);
204
+ }
205
+ return takeFromExternrefTable0(ret[0]);
206
+ }
207
+ /**
208
+ * @param {string} content
209
+ * @param {boolean} displaystyle
210
+ * @returns {string}
211
+ */
212
+ convert_with_global_counter(content, displaystyle) {
213
+ const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
214
+ const len0 = WASM_VECTOR_LEN;
215
+ const ret = wasm.latextomathml_convert_with_global_counter(this.__wbg_ptr, ptr0, len0, displaystyle);
216
+ if (ret[2]) {
217
+ throw takeFromExternrefTable0(ret[1]);
218
+ }
219
+ return takeFromExternrefTable0(ret[0]);
220
+ }
221
+ /**
222
+ * @param {MathCoreOptions} js_config
223
+ */
224
+ constructor(js_config) {
225
+ const ret = wasm.latextomathml_new(js_config);
226
+ if (ret[2]) {
227
+ throw takeFromExternrefTable0(ret[1]);
228
+ }
229
+ this.__wbg_ptr = ret[0] >>> 0;
230
+ LatexToMathMLFinalization.register(this, this.__wbg_ptr, this);
231
+ return this;
232
+ }
233
+ }
234
+ if (Symbol.dispose) LatexToMathML.prototype[Symbol.dispose] = LatexToMathML.prototype.free;
235
+
236
+ export function __wbg___wbindgen_string_get_e4f06c90489ad01b(arg0, arg1) {
237
+ const obj = arg1;
238
+ const ret = typeof(obj) === 'string' ? obj : undefined;
239
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
240
+ var len1 = WASM_VECTOR_LEN;
241
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
242
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
243
+ };
244
+
245
+ export function __wbg___wbindgen_throw_b855445ff6a94295(arg0, arg1) {
246
+ throw new Error(getStringFromWasm0(arg0, arg1));
247
+ };
248
+
249
+ export function __wbg_continueOnError_b8dff4404d45b65e(arg0) {
250
+ const ret = arg0.continueOnError;
251
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
252
+ };
253
+
254
+ export function __wbg_done_2042aa2670fb1db1(arg0) {
255
+ const ret = arg0.done;
256
+ return ret;
257
+ };
258
+
259
+ export function __wbg_entries_eb145c4da5c811f7(arg0) {
260
+ const ret = arg0.entries();
261
+ return ret;
262
+ };
263
+
264
+ export function __wbg_get_7bed016f185add81(arg0, arg1) {
265
+ const ret = arg0[arg1 >>> 0];
266
+ return ret;
267
+ };
268
+
269
+ export function __wbg_isArray_96e0af9891d0945d(arg0) {
270
+ const ret = Array.isArray(arg0);
271
+ return ret;
272
+ };
273
+
274
+ export function __wbg_latexerror_new(arg0) {
275
+ const ret = LatexError.__wrap(arg0);
276
+ return ret;
277
+ };
278
+
279
+ export function __wbg_macros_4f3a3cb8196fd9f6(arg0) {
280
+ const ret = arg0.macros;
281
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
282
+ };
283
+
284
+ export function __wbg_next_020810e0ae8ebcb0() { return handleError(function (arg0) {
285
+ const ret = arg0.next();
286
+ return ret;
287
+ }, arguments) };
288
+
289
+ export function __wbg_prettyPrint_69e2e31a28db25ad(arg0, arg1) {
290
+ const ret = arg1.prettyPrint;
291
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
292
+ var len1 = WASM_VECTOR_LEN;
293
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
294
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
295
+ };
296
+
297
+ export function __wbg_size_252e34f77ca59a74(arg0) {
298
+ const ret = arg0.size;
299
+ return ret;
300
+ };
301
+
302
+ export function __wbg_value_692627309814bb8c(arg0) {
303
+ const ret = arg0.value;
304
+ return ret;
305
+ };
306
+
307
+ export function __wbg_xmlNamespace_19354e2aa7a61d14(arg0) {
308
+ const ret = arg0.xmlNamespace;
309
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
310
+ };
311
+
312
+ export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) {
313
+ // Cast intrinsic for `Ref(String) -> Externref`.
314
+ const ret = getStringFromWasm0(arg0, arg1);
315
+ return ret;
316
+ };
317
+
318
+ export function __wbindgen_init_externref_table() {
319
+ const table = wasm.__wbindgen_externrefs;
320
+ const offset = table.grow(4);
321
+ table.set(0, undefined);
322
+ table.set(offset + 0, undefined);
323
+ table.set(offset + 1, null);
324
+ table.set(offset + 2, true);
325
+ table.set(offset + 3, false);
326
+ ;
327
+ };
328
+
Binary file
@@ -0,0 +1,20 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_get_latexerror_location: (a: number) => number;
5
+ export const __wbg_get_latexerror_message: (a: number) => any;
6
+ export const __wbg_latexerror_free: (a: number, b: number) => void;
7
+ export const __wbg_latextomathml_free: (a: number, b: number) => void;
8
+ export const __wbg_set_latexerror_location: (a: number, b: number) => void;
9
+ export const __wbg_set_latexerror_message: (a: number, b: any) => void;
10
+ export const latextomathml_convert_with_global_counter: (a: number, b: number, c: number, d: number) => [number, number, number];
11
+ export const latextomathml_convert_with_local_counter: (a: number, b: number, c: number, d: number) => [number, number, number];
12
+ export const latextomathml_new: (a: any) => [number, number, number];
13
+ export const latextomathml_reset_global_counter: (a: number) => void;
14
+ export const __wbindgen_malloc: (a: number, b: number) => number;
15
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
16
+ export const __externref_table_alloc: () => number;
17
+ export const __wbindgen_externrefs: WebAssembly.Table;
18
+ export const __wbindgen_exn_store: (a: number) => void;
19
+ export const __externref_table_dealloc: (a: number) => void;
20
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "module",
3
+ "dependencies": {}
4
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "math-core",
3
+ "version": "0.1.1",
4
+ "description": "Convert LaTeX to MathML Core",
5
+ "homepage": "https://github.com/tmke8/math-core#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/tmke8/math-core/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/tmke8/math-core.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Thomas M Kehrenberg",
15
+ "type": "module",
16
+ "main": "dist/math_core.js",
17
+ "types": "dist/math_core.d.ts",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "test": "mocha",
23
+ "build": "npm run build:cargo && npm run build:wasm-bindgen",
24
+ "build:cargo": "cargo build --release --target wasm32-unknown-unknown --package math-core-wasm",
25
+ "build:wasm-bindgen": "wasm-bindgen ../target/wasm32-unknown-unknown/release/math_core_wasm.wasm --out-dir ./dist --out-name math_core --target experimental-nodejs-module"
26
+ },
27
+ "devDependencies": {
28
+ "@types/chai": "^5.2.2",
29
+ "@types/mocha": "^10.0.10",
30
+ "chai": "^6.2.0",
31
+ "mocha": "^11.7.4"
32
+ }
33
+ }