@ox-content/wasm 2.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.
- package/LICENSE +21 -0
- package/README.md +66 -0
- package/ox_content_wasm.d.ts +74 -0
- package/ox_content_wasm.js +411 -0
- package/ox_content_wasm_bg.wasm +0 -0
- package/ox_content_wasm_bg.wasm.d.ts +19 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ubugeeei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @ox-content/wasm
|
|
2
|
+
|
|
3
|
+
WebAssembly bindings for Ox Content's Rust Markdown engine.
|
|
4
|
+
|
|
5
|
+
Use this package when you want to run Ox Content in the browser, a Web Worker, or another JavaScript environment that can load `.wasm` from ESM.
|
|
6
|
+
|
|
7
|
+
If you are building for Node.js, prefer [`@ox-content/napi`](https://www.npmjs.com/package/@ox-content/napi).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @ox-content/wasm
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import init, { parseAndRender, WasmParserOptions } from "@ox-content/wasm";
|
|
19
|
+
|
|
20
|
+
await init();
|
|
21
|
+
|
|
22
|
+
const options = new WasmParserOptions();
|
|
23
|
+
options.gfm = true;
|
|
24
|
+
options.tables = true;
|
|
25
|
+
options.taskLists = true;
|
|
26
|
+
|
|
27
|
+
const result = parseAndRender("# Hello from WASM", options);
|
|
28
|
+
console.log(result.html);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## API
|
|
32
|
+
|
|
33
|
+
The current WebAssembly surface exposes:
|
|
34
|
+
|
|
35
|
+
- `parseAndRender(source, options?)`
|
|
36
|
+
- `transform(source, options?)`
|
|
37
|
+
- `version()`
|
|
38
|
+
- `WasmParserOptions`
|
|
39
|
+
|
|
40
|
+
## Notes
|
|
41
|
+
|
|
42
|
+
- The generated module is ESM-only.
|
|
43
|
+
- The default `init()` call loads `ox_content_wasm_bg.wasm` relative to the package entry.
|
|
44
|
+
- For server-side Node.js usage, use `@ox-content/napi` instead.
|
|
45
|
+
|
|
46
|
+
## Local Build
|
|
47
|
+
|
|
48
|
+
From the repository root:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
vp run build:wasm
|
|
52
|
+
pnpm --filter @ox-content/wasm pack --dry-run
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This generates a publish-ready package in `crates/ox_content_wasm/pkg/`.
|
|
56
|
+
|
|
57
|
+
## First Local Publish
|
|
58
|
+
|
|
59
|
+
Use `pnpm --filter` from the workspace root so you do not accidentally target the wrong package:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm whoami || pnpm login
|
|
63
|
+
pnpm --filter @ox-content/wasm publish --access public --no-git-checks
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Avoid `pnpm -r publish` here, because that would try to publish every publishable package in the workspace.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class WasmParserOptions {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
constructor();
|
|
8
|
+
set tables(value: boolean);
|
|
9
|
+
set autolinks(value: boolean);
|
|
10
|
+
set footnotes(value: boolean);
|
|
11
|
+
set taskLists(value: boolean);
|
|
12
|
+
set strikethrough(value: boolean);
|
|
13
|
+
set tocMaxDepth(value: number);
|
|
14
|
+
set gfm(value: boolean);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Parses Markdown and renders to HTML.
|
|
19
|
+
*/
|
|
20
|
+
export function parseAndRender(source: string, options?: WasmParserOptions | null): any;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Transforms Markdown source into HTML, frontmatter, and TOC.
|
|
24
|
+
*/
|
|
25
|
+
export function transform(source: string, options?: WasmParserOptions | null): any;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns the version of ox_content_wasm.
|
|
29
|
+
*/
|
|
30
|
+
export function version(): string;
|
|
31
|
+
|
|
32
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
33
|
+
|
|
34
|
+
export interface InitOutput {
|
|
35
|
+
readonly memory: WebAssembly.Memory;
|
|
36
|
+
readonly __wbg_wasmparseroptions_free: (a: number, b: number) => void;
|
|
37
|
+
readonly parseAndRender: (a: number, b: number, c: number) => number;
|
|
38
|
+
readonly transform: (a: number, b: number, c: number) => number;
|
|
39
|
+
readonly version: (a: number) => void;
|
|
40
|
+
readonly wasmparseroptions_new: () => number;
|
|
41
|
+
readonly wasmparseroptions_set_autolinks: (a: number, b: number) => void;
|
|
42
|
+
readonly wasmparseroptions_set_footnotes: (a: number, b: number) => void;
|
|
43
|
+
readonly wasmparseroptions_set_gfm: (a: number, b: number) => void;
|
|
44
|
+
readonly wasmparseroptions_set_strikethrough: (a: number, b: number) => void;
|
|
45
|
+
readonly wasmparseroptions_set_tables: (a: number, b: number) => void;
|
|
46
|
+
readonly wasmparseroptions_set_task_lists: (a: number, b: number) => void;
|
|
47
|
+
readonly wasmparseroptions_set_toc_max_depth: (a: number, b: number) => void;
|
|
48
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
49
|
+
readonly __wbindgen_export: (a: number, b: number, c: number) => void;
|
|
50
|
+
readonly __wbindgen_export2: (a: number, b: number) => number;
|
|
51
|
+
readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
58
|
+
* a precompiled `WebAssembly.Module`.
|
|
59
|
+
*
|
|
60
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
61
|
+
*
|
|
62
|
+
* @returns {InitOutput}
|
|
63
|
+
*/
|
|
64
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
68
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
69
|
+
*
|
|
70
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
71
|
+
*
|
|
72
|
+
* @returns {Promise<InitOutput>}
|
|
73
|
+
*/
|
|
74
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
function addHeapObject(obj) {
|
|
4
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
5
|
+
const idx = heap_next;
|
|
6
|
+
heap_next = heap[idx];
|
|
7
|
+
|
|
8
|
+
heap[idx] = obj;
|
|
9
|
+
return idx;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function _assertClass(instance, klass) {
|
|
13
|
+
if (!(instance instanceof klass)) {
|
|
14
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function dropObject(idx) {
|
|
19
|
+
if (idx < 132) return;
|
|
20
|
+
heap[idx] = heap_next;
|
|
21
|
+
heap_next = idx;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let cachedDataViewMemory0 = null;
|
|
25
|
+
function getDataViewMemory0() {
|
|
26
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
27
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
28
|
+
}
|
|
29
|
+
return cachedDataViewMemory0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getStringFromWasm0(ptr, len) {
|
|
33
|
+
ptr = ptr >>> 0;
|
|
34
|
+
return decodeText(ptr, len);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let cachedUint8ArrayMemory0 = null;
|
|
38
|
+
function getUint8ArrayMemory0() {
|
|
39
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
40
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
41
|
+
}
|
|
42
|
+
return cachedUint8ArrayMemory0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getObject(idx) { return heap[idx]; }
|
|
46
|
+
|
|
47
|
+
let heap = new Array(128).fill(undefined);
|
|
48
|
+
heap.push(undefined, null, true, false);
|
|
49
|
+
|
|
50
|
+
let heap_next = heap.length;
|
|
51
|
+
|
|
52
|
+
function isLikeNone(x) {
|
|
53
|
+
return x === undefined || x === null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
57
|
+
if (realloc === undefined) {
|
|
58
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
59
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
60
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
61
|
+
WASM_VECTOR_LEN = buf.length;
|
|
62
|
+
return ptr;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let len = arg.length;
|
|
66
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
67
|
+
|
|
68
|
+
const mem = getUint8ArrayMemory0();
|
|
69
|
+
|
|
70
|
+
let offset = 0;
|
|
71
|
+
|
|
72
|
+
for (; offset < len; offset++) {
|
|
73
|
+
const code = arg.charCodeAt(offset);
|
|
74
|
+
if (code > 0x7F) break;
|
|
75
|
+
mem[ptr + offset] = code;
|
|
76
|
+
}
|
|
77
|
+
if (offset !== len) {
|
|
78
|
+
if (offset !== 0) {
|
|
79
|
+
arg = arg.slice(offset);
|
|
80
|
+
}
|
|
81
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
82
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
83
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
84
|
+
|
|
85
|
+
offset += ret.written;
|
|
86
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
WASM_VECTOR_LEN = offset;
|
|
90
|
+
return ptr;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function takeObject(idx) {
|
|
94
|
+
const ret = getObject(idx);
|
|
95
|
+
dropObject(idx);
|
|
96
|
+
return ret;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
100
|
+
cachedTextDecoder.decode();
|
|
101
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
102
|
+
let numBytesDecoded = 0;
|
|
103
|
+
function decodeText(ptr, len) {
|
|
104
|
+
numBytesDecoded += len;
|
|
105
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
106
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
107
|
+
cachedTextDecoder.decode();
|
|
108
|
+
numBytesDecoded = len;
|
|
109
|
+
}
|
|
110
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const cachedTextEncoder = new TextEncoder();
|
|
114
|
+
|
|
115
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
116
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
117
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
118
|
+
view.set(buf);
|
|
119
|
+
return {
|
|
120
|
+
read: arg.length,
|
|
121
|
+
written: buf.length
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let WASM_VECTOR_LEN = 0;
|
|
127
|
+
|
|
128
|
+
const WasmParserOptionsFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
129
|
+
? { register: () => {}, unregister: () => {} }
|
|
130
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmparseroptions_free(ptr >>> 0, 1));
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Parser options.
|
|
134
|
+
*/
|
|
135
|
+
export class WasmParserOptions {
|
|
136
|
+
__destroy_into_raw() {
|
|
137
|
+
const ptr = this.__wbg_ptr;
|
|
138
|
+
this.__wbg_ptr = 0;
|
|
139
|
+
WasmParserOptionsFinalization.unregister(this);
|
|
140
|
+
return ptr;
|
|
141
|
+
}
|
|
142
|
+
free() {
|
|
143
|
+
const ptr = this.__destroy_into_raw();
|
|
144
|
+
wasm.__wbg_wasmparseroptions_free(ptr, 0);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @param {boolean} value
|
|
148
|
+
*/
|
|
149
|
+
set tables(value) {
|
|
150
|
+
wasm.wasmparseroptions_set_tables(this.__wbg_ptr, value);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @param {boolean} value
|
|
154
|
+
*/
|
|
155
|
+
set autolinks(value) {
|
|
156
|
+
wasm.wasmparseroptions_set_autolinks(this.__wbg_ptr, value);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* @param {boolean} value
|
|
160
|
+
*/
|
|
161
|
+
set footnotes(value) {
|
|
162
|
+
wasm.wasmparseroptions_set_footnotes(this.__wbg_ptr, value);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @param {boolean} value
|
|
166
|
+
*/
|
|
167
|
+
set taskLists(value) {
|
|
168
|
+
wasm.wasmparseroptions_set_task_lists(this.__wbg_ptr, value);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* @param {boolean} value
|
|
172
|
+
*/
|
|
173
|
+
set strikethrough(value) {
|
|
174
|
+
wasm.wasmparseroptions_set_strikethrough(this.__wbg_ptr, value);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* @param {number} value
|
|
178
|
+
*/
|
|
179
|
+
set tocMaxDepth(value) {
|
|
180
|
+
wasm.wasmparseroptions_set_toc_max_depth(this.__wbg_ptr, value);
|
|
181
|
+
}
|
|
182
|
+
constructor() {
|
|
183
|
+
const ret = wasm.wasmparseroptions_new();
|
|
184
|
+
this.__wbg_ptr = ret >>> 0;
|
|
185
|
+
WasmParserOptionsFinalization.register(this, this.__wbg_ptr, this);
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* @param {boolean} value
|
|
190
|
+
*/
|
|
191
|
+
set gfm(value) {
|
|
192
|
+
wasm.wasmparseroptions_set_gfm(this.__wbg_ptr, value);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (Symbol.dispose) WasmParserOptions.prototype[Symbol.dispose] = WasmParserOptions.prototype.free;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Parses Markdown and renders to HTML.
|
|
199
|
+
* @param {string} source
|
|
200
|
+
* @param {WasmParserOptions | null} [options]
|
|
201
|
+
* @returns {any}
|
|
202
|
+
*/
|
|
203
|
+
export function parseAndRender(source, options) {
|
|
204
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
205
|
+
const len0 = WASM_VECTOR_LEN;
|
|
206
|
+
let ptr1 = 0;
|
|
207
|
+
if (!isLikeNone(options)) {
|
|
208
|
+
_assertClass(options, WasmParserOptions);
|
|
209
|
+
ptr1 = options.__destroy_into_raw();
|
|
210
|
+
}
|
|
211
|
+
const ret = wasm.parseAndRender(ptr0, len0, ptr1);
|
|
212
|
+
return takeObject(ret);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Transforms Markdown source into HTML, frontmatter, and TOC.
|
|
217
|
+
* @param {string} source
|
|
218
|
+
* @param {WasmParserOptions | null} [options]
|
|
219
|
+
* @returns {any}
|
|
220
|
+
*/
|
|
221
|
+
export function transform(source, options) {
|
|
222
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
223
|
+
const len0 = WASM_VECTOR_LEN;
|
|
224
|
+
let ptr1 = 0;
|
|
225
|
+
if (!isLikeNone(options)) {
|
|
226
|
+
_assertClass(options, WasmParserOptions);
|
|
227
|
+
ptr1 = options.__destroy_into_raw();
|
|
228
|
+
}
|
|
229
|
+
const ret = wasm.transform(ptr0, len0, ptr1);
|
|
230
|
+
return takeObject(ret);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Returns the version of ox_content_wasm.
|
|
235
|
+
* @returns {string}
|
|
236
|
+
*/
|
|
237
|
+
export function version() {
|
|
238
|
+
let deferred1_0;
|
|
239
|
+
let deferred1_1;
|
|
240
|
+
try {
|
|
241
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
242
|
+
wasm.version(retptr);
|
|
243
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
244
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
245
|
+
deferred1_0 = r0;
|
|
246
|
+
deferred1_1 = r1;
|
|
247
|
+
return getStringFromWasm0(r0, r1);
|
|
248
|
+
} finally {
|
|
249
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
250
|
+
wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
255
|
+
|
|
256
|
+
async function __wbg_load(module, imports) {
|
|
257
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
258
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
259
|
+
try {
|
|
260
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
261
|
+
} catch (e) {
|
|
262
|
+
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
263
|
+
|
|
264
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
265
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
266
|
+
|
|
267
|
+
} else {
|
|
268
|
+
throw e;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const bytes = await module.arrayBuffer();
|
|
274
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
275
|
+
} else {
|
|
276
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
277
|
+
|
|
278
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
279
|
+
return { instance, module };
|
|
280
|
+
} else {
|
|
281
|
+
return instance;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function __wbg_get_imports() {
|
|
287
|
+
const imports = {};
|
|
288
|
+
imports.wbg = {};
|
|
289
|
+
imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
|
|
290
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
291
|
+
return addHeapObject(ret);
|
|
292
|
+
};
|
|
293
|
+
imports.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030 = function(arg0) {
|
|
294
|
+
const ret = typeof(getObject(arg0)) === 'string';
|
|
295
|
+
return ret;
|
|
296
|
+
};
|
|
297
|
+
imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
|
|
298
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
299
|
+
};
|
|
300
|
+
imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
|
|
301
|
+
const ret = new Object();
|
|
302
|
+
return addHeapObject(ret);
|
|
303
|
+
};
|
|
304
|
+
imports.wbg.__wbg_new_25f239778d6112b9 = function() {
|
|
305
|
+
const ret = new Array();
|
|
306
|
+
return addHeapObject(ret);
|
|
307
|
+
};
|
|
308
|
+
imports.wbg.__wbg_new_b546ae120718850e = function() {
|
|
309
|
+
const ret = new Map();
|
|
310
|
+
return addHeapObject(ret);
|
|
311
|
+
};
|
|
312
|
+
imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
|
|
313
|
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
314
|
+
};
|
|
315
|
+
imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
|
|
316
|
+
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
317
|
+
};
|
|
318
|
+
imports.wbg.__wbg_set_efaaf145b9377369 = function(arg0, arg1, arg2) {
|
|
319
|
+
const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
|
|
320
|
+
return addHeapObject(ret);
|
|
321
|
+
};
|
|
322
|
+
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
323
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
324
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
325
|
+
return addHeapObject(ret);
|
|
326
|
+
};
|
|
327
|
+
imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
|
|
328
|
+
// Cast intrinsic for `U64 -> Externref`.
|
|
329
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
330
|
+
return addHeapObject(ret);
|
|
331
|
+
};
|
|
332
|
+
imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
|
|
333
|
+
// Cast intrinsic for `I64 -> Externref`.
|
|
334
|
+
const ret = arg0;
|
|
335
|
+
return addHeapObject(ret);
|
|
336
|
+
};
|
|
337
|
+
imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
|
|
338
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
339
|
+
const ret = arg0;
|
|
340
|
+
return addHeapObject(ret);
|
|
341
|
+
};
|
|
342
|
+
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
|
343
|
+
const ret = getObject(arg0);
|
|
344
|
+
return addHeapObject(ret);
|
|
345
|
+
};
|
|
346
|
+
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
347
|
+
takeObject(arg0);
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
return imports;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function __wbg_finalize_init(instance, module) {
|
|
354
|
+
wasm = instance.exports;
|
|
355
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
356
|
+
cachedDataViewMemory0 = null;
|
|
357
|
+
cachedUint8ArrayMemory0 = null;
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
return wasm;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function initSync(module) {
|
|
365
|
+
if (wasm !== undefined) return wasm;
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
if (typeof module !== 'undefined') {
|
|
369
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
370
|
+
({module} = module)
|
|
371
|
+
} else {
|
|
372
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const imports = __wbg_get_imports();
|
|
377
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
378
|
+
module = new WebAssembly.Module(module);
|
|
379
|
+
}
|
|
380
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
381
|
+
return __wbg_finalize_init(instance, module);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
async function __wbg_init(module_or_path) {
|
|
385
|
+
if (wasm !== undefined) return wasm;
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
if (typeof module_or_path !== 'undefined') {
|
|
389
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
390
|
+
({module_or_path} = module_or_path)
|
|
391
|
+
} else {
|
|
392
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (typeof module_or_path === 'undefined') {
|
|
397
|
+
module_or_path = new URL('ox_content_wasm_bg.wasm', import.meta.url);
|
|
398
|
+
}
|
|
399
|
+
const imports = __wbg_get_imports();
|
|
400
|
+
|
|
401
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
402
|
+
module_or_path = fetch(module_or_path);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
406
|
+
|
|
407
|
+
return __wbg_finalize_init(instance, module);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export { initSync };
|
|
411
|
+
export default __wbg_init;
|
|
Binary file
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_wasmparseroptions_free: (a: number, b: number) => void;
|
|
5
|
+
export const parseAndRender: (a: number, b: number, c: number) => number;
|
|
6
|
+
export const transform: (a: number, b: number, c: number) => number;
|
|
7
|
+
export const version: (a: number) => void;
|
|
8
|
+
export const wasmparseroptions_new: () => number;
|
|
9
|
+
export const wasmparseroptions_set_autolinks: (a: number, b: number) => void;
|
|
10
|
+
export const wasmparseroptions_set_footnotes: (a: number, b: number) => void;
|
|
11
|
+
export const wasmparseroptions_set_gfm: (a: number, b: number) => void;
|
|
12
|
+
export const wasmparseroptions_set_strikethrough: (a: number, b: number) => void;
|
|
13
|
+
export const wasmparseroptions_set_tables: (a: number, b: number) => void;
|
|
14
|
+
export const wasmparseroptions_set_task_lists: (a: number, b: number) => void;
|
|
15
|
+
export const wasmparseroptions_set_toc_max_depth: (a: number, b: number) => void;
|
|
16
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
17
|
+
export const __wbindgen_export: (a: number, b: number, c: number) => void;
|
|
18
|
+
export const __wbindgen_export2: (a: number, b: number) => number;
|
|
19
|
+
export const __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ox-content/wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "WebAssembly bindings for Ox Content - Browser-ready Markdown parser",
|
|
5
|
+
"version": "2.2.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/ubugeeei/ox-content.git",
|
|
10
|
+
"directory": "crates/ox_content_wasm"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"ox_content_wasm.js",
|
|
14
|
+
"ox_content_wasm.d.ts",
|
|
15
|
+
"ox_content_wasm_bg.wasm",
|
|
16
|
+
"ox_content_wasm_bg.wasm.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"main": "ox_content_wasm.js",
|
|
19
|
+
"homepage": "https://ubugeeei.github.io/ox-content/packages/wasm",
|
|
20
|
+
"types": "ox_content_wasm.d.ts",
|
|
21
|
+
"sideEffects": [
|
|
22
|
+
"./snippets/*"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"markdown",
|
|
26
|
+
"documentation",
|
|
27
|
+
"parser",
|
|
28
|
+
"vite",
|
|
29
|
+
"browser",
|
|
30
|
+
"wasm",
|
|
31
|
+
"webassembly"
|
|
32
|
+
],
|
|
33
|
+
"author": "ubugeeei",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/ubugeeei/ox-content/issues"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|