@takazudo/zfb-md-wasm 2.7.1 → 2.9.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/README.md +179 -49
- package/dist/parse-browser.d.ts +12 -0
- package/dist/parse-browser.js +17 -0
- package/dist/parse-browser.js.map +1 -0
- package/dist/parse.d.ts +12 -0
- package/dist/parse.js +23 -0
- package/dist/parse.js.map +1 -0
- package/dist/render-browser.d.ts +11 -0
- package/dist/render-browser.js +16 -0
- package/dist/render-browser.js.map +1 -0
- package/dist/render.d.ts +11 -0
- package/dist/render.js +22 -0
- package/dist/render.js.map +1 -0
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +9 -12
- package/dist/runtime.js.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.js.map +1 -1
- package/dist/wasm/zfb_md_wasm_bg.wasm +0 -0
- package/dist/wasm/zfb_md_wasm_glue.zfb-resource.d.mts +3 -1
- package/dist/wasm/zfb_md_wasm_glue.zfb-resource.mjs +3 -1
- package/dist/wasm-highlight/zfb_md_wasm_highlight_bg.wasm +0 -0
- package/dist/wasm-parse/zfb_md_wasm_parse_bg.wasm +0 -0
- package/dist/wasm-parse/zfb_md_wasm_parse_bg.wasm.d.ts +10 -0
- package/dist/wasm-parse/zfb_md_wasm_parse_glue.zfb-resource.d.mts +108 -0
- package/dist/wasm-parse/zfb_md_wasm_parse_glue.zfb-resource.mjs +300 -0
- package/dist/wasm-render/zfb_md_wasm_render_bg.wasm +0 -0
- package/dist/wasm-render/zfb_md_wasm_render_bg.wasm.d.ts +10 -0
- package/dist/wasm-render/zfb_md_wasm_render_glue.zfb-resource.d.mts +68 -0
- package/dist/wasm-render/zfb_md_wasm_render_glue.zfb-resource.mjs +260 -0
- package/package.json +11 -1
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/* @ts-self-types="./zfb_md_wasm_parse.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Deliberately trap the current WebAssembly instance for wrapper recovery
|
|
5
|
+
* tests. This is not part of the typed package API; the JavaScript wrapper
|
|
6
|
+
* exposes it only through its internal test hook.
|
|
7
|
+
*
|
|
8
|
+
* A Rust panic is the reliable cross-engine representation of the real
|
|
9
|
+
* failure this hook needs to exercise. Calling a generated raw C-ABI export
|
|
10
|
+
* with fabricated pointers could instead enter undefined Rust-level work and
|
|
11
|
+
* hang Chromium before reaching the wasm trap boundary.
|
|
12
|
+
*/
|
|
13
|
+
export function __forceTrapForTests() {
|
|
14
|
+
wasm.__forceTrapForTests();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Parse markdown/MDX source into a serialized RAW mdast tree — a
|
|
19
|
+
* supported API tier (zfb#1857, decided GO by epic zfb#1854 / zfb#1828).
|
|
20
|
+
* Exported to JS as `parseToAst`.
|
|
21
|
+
*
|
|
22
|
+
* Returns a JSON string: `{ "ast": mdast|null, "frontmatter": json,
|
|
23
|
+
* "diagnostics": Diagnostic[] }`. The tree is raw markdown-rs parser output
|
|
24
|
+
* converted through its serde shape into an open carrier, optionally
|
|
25
|
+
* composed with generic directives (post-frontmatter-strip,
|
|
26
|
+
* PRE-zfb-visitors — mdast, not hast, and
|
|
27
|
+
* unrecognized/custom constructs such as MDX JSX elements survive as typed
|
|
28
|
+
* nodes rather than being dropped), serialized in the unist shape via
|
|
29
|
+
* markdown-rs's `serde` feature, with every `position` shifted back into
|
|
30
|
+
* original-source coordinates (see [`shift_interop_positions`]). Its
|
|
31
|
+
* distinct closed options document accepts only `filename`, `dialect`,
|
|
32
|
+
* `directives`, and `pipeline.gfm`; compile/visitor/serializer knobs are
|
|
33
|
+
* rejected rather than silently ignored. A missing filename defaults to
|
|
34
|
+
* `<anonymous>.mdx`.
|
|
35
|
+
* Otherwise `.md` infers Markdown and `.mdx` infers MDX; an explicit dialect
|
|
36
|
+
* overrides either valid extension without waiving the extension gate.
|
|
37
|
+
*
|
|
38
|
+
* ## Position contract: UTF-16 code units (decided zfb#1856)
|
|
39
|
+
*
|
|
40
|
+
* `position.offset` and `position.column` are UTF-16 code-unit indices —
|
|
41
|
+
* remark/unist convention, and what `String.prototype.slice`,
|
|
42
|
+
* `mdast-util-to-hast`, and consumer mdast plugins already index by.
|
|
43
|
+
* `position.line` is unit-agnostic and needs no conversion. This matters on
|
|
44
|
+
* non-ASCII sources: a scalar value outside the Basic Multilingual Plane
|
|
45
|
+
* (most emoji) is 1 UTF-16 code unit different from its UTF-8 byte width
|
|
46
|
+
* (2 UTF-16 units vs. usually 4 bytes) — see [`Utf16Positions`] for the
|
|
47
|
+
* conversion and `tests/parse_to_ast.rs`'s
|
|
48
|
+
* `utf16_code_unit_semantics_are_pinned_on_non_ascii` for the pin. Pure-
|
|
49
|
+
* ASCII sources take a fast path that skips the conversion entirely (byte
|
|
50
|
+
* units already equal UTF-16 units there).
|
|
51
|
+
*
|
|
52
|
+
* ## Documented divergences from remark-parse / remark-mdx
|
|
53
|
+
*
|
|
54
|
+
* - `mdxJsxAttribute` records carry no `position` — markdown-rs does not
|
|
55
|
+
* model attribute positions.
|
|
56
|
+
* - Top-level `import`/`export` degrade to paragraphs (no `mdxjsEsm` nodes
|
|
57
|
+
* — markdown-rs's `mdx_esm_parse` needs a JS ESM parser the wasm boundary
|
|
58
|
+
* cannot host), and MDX expressions carry no estree data (the default
|
|
59
|
+
* aggressive mode validates braces only, unlike remark-mdx's acorn pass).
|
|
60
|
+
* Consumers needing remark-mdx-equivalent ESM/estree keep remark for
|
|
61
|
+
* those documents.
|
|
62
|
+
* - `_markdownRsStops` (on MDX expression/ESM nodes) is markdown-rs-
|
|
63
|
+
* internal re-parse bookkeeping: internal, unstable, and BYTE-based (NOT
|
|
64
|
+
* UTF-16 like `position`) — never slice a string with it.
|
|
65
|
+
* @param {string} source
|
|
66
|
+
* @param {string} options_json
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
export function parseToAst(source, options_json) {
|
|
70
|
+
let deferred3_0;
|
|
71
|
+
let deferred3_1;
|
|
72
|
+
try {
|
|
73
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
74
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
75
|
+
const len0 = WASM_VECTOR_LEN;
|
|
76
|
+
const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
77
|
+
const len1 = WASM_VECTOR_LEN;
|
|
78
|
+
wasm.parseToAst(retptr, ptr0, len0, ptr1, len1);
|
|
79
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
80
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
81
|
+
deferred3_0 = r0;
|
|
82
|
+
deferred3_1 = r1;
|
|
83
|
+
return getStringFromWasm0(r0, r1);
|
|
84
|
+
} finally {
|
|
85
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
86
|
+
wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* This package's release version, stamped by CI at compile time.
|
|
92
|
+
*
|
|
93
|
+
* Development builds without `ZFB_RELEASE_VERSION` fall back to this crate's
|
|
94
|
+
* manifest version (`CARGO_PKG_VERSION`).
|
|
95
|
+
* @returns {string}
|
|
96
|
+
*/
|
|
97
|
+
export function version() {
|
|
98
|
+
let deferred1_0;
|
|
99
|
+
let deferred1_1;
|
|
100
|
+
try {
|
|
101
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
102
|
+
wasm.version(retptr);
|
|
103
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
104
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
105
|
+
deferred1_0 = r0;
|
|
106
|
+
deferred1_1 = r1;
|
|
107
|
+
return getStringFromWasm0(r0, r1);
|
|
108
|
+
} finally {
|
|
109
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
110
|
+
wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function __wbg_get_imports() {
|
|
114
|
+
const import0 = {
|
|
115
|
+
__proto__: null,
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
__proto__: null,
|
|
119
|
+
"./zfb_md_wasm_parse_bg.js": import0,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let cachedDataViewMemory0 = null;
|
|
124
|
+
function getDataViewMemory0() {
|
|
125
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
126
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
127
|
+
}
|
|
128
|
+
return cachedDataViewMemory0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function getStringFromWasm0(ptr, len) {
|
|
132
|
+
return decodeText(ptr >>> 0, len);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let cachedUint8ArrayMemory0 = null;
|
|
136
|
+
function getUint8ArrayMemory0() {
|
|
137
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
138
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
139
|
+
}
|
|
140
|
+
return cachedUint8ArrayMemory0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
144
|
+
if (realloc === undefined) {
|
|
145
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
146
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
147
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
148
|
+
WASM_VECTOR_LEN = buf.length;
|
|
149
|
+
return ptr;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let len = arg.length;
|
|
153
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
154
|
+
|
|
155
|
+
const mem = getUint8ArrayMemory0();
|
|
156
|
+
|
|
157
|
+
let offset = 0;
|
|
158
|
+
|
|
159
|
+
for (; offset < len; offset++) {
|
|
160
|
+
const code = arg.charCodeAt(offset);
|
|
161
|
+
if (code > 0x7F) break;
|
|
162
|
+
mem[ptr + offset] = code;
|
|
163
|
+
}
|
|
164
|
+
if (offset !== len) {
|
|
165
|
+
if (offset !== 0) {
|
|
166
|
+
arg = arg.slice(offset);
|
|
167
|
+
}
|
|
168
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
169
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
170
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
171
|
+
|
|
172
|
+
offset += ret.written;
|
|
173
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
WASM_VECTOR_LEN = offset;
|
|
177
|
+
return ptr;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
181
|
+
cachedTextDecoder.decode();
|
|
182
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
183
|
+
let numBytesDecoded = 0;
|
|
184
|
+
function decodeText(ptr, len) {
|
|
185
|
+
numBytesDecoded += len;
|
|
186
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
187
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
188
|
+
cachedTextDecoder.decode();
|
|
189
|
+
numBytesDecoded = len;
|
|
190
|
+
}
|
|
191
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const cachedTextEncoder = new TextEncoder();
|
|
195
|
+
|
|
196
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
197
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
198
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
199
|
+
view.set(buf);
|
|
200
|
+
return {
|
|
201
|
+
read: arg.length,
|
|
202
|
+
written: buf.length
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
let WASM_VECTOR_LEN = 0;
|
|
208
|
+
|
|
209
|
+
let wasmModule, wasmInstance, wasm;
|
|
210
|
+
function __wbg_finalize_init(instance, module) {
|
|
211
|
+
wasmInstance = instance;
|
|
212
|
+
wasm = instance.exports;
|
|
213
|
+
wasmModule = module;
|
|
214
|
+
cachedDataViewMemory0 = null;
|
|
215
|
+
cachedUint8ArrayMemory0 = null;
|
|
216
|
+
return wasm;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function __wbg_load(module, imports) {
|
|
220
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
221
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
222
|
+
try {
|
|
223
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
224
|
+
} catch (e) {
|
|
225
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
226
|
+
|
|
227
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
228
|
+
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);
|
|
229
|
+
|
|
230
|
+
} else { throw e; }
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const bytes = await module.arrayBuffer();
|
|
235
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
236
|
+
} else {
|
|
237
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
238
|
+
|
|
239
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
240
|
+
return { instance, module };
|
|
241
|
+
} else {
|
|
242
|
+
return instance;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function expectedResponseType(type) {
|
|
247
|
+
switch (type) {
|
|
248
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
249
|
+
}
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function initSync(module) {
|
|
255
|
+
if (wasm !== undefined) return wasm;
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
if (module !== undefined) {
|
|
259
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
260
|
+
({module} = module)
|
|
261
|
+
} else {
|
|
262
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const imports = __wbg_get_imports();
|
|
267
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
268
|
+
module = new WebAssembly.Module(module);
|
|
269
|
+
}
|
|
270
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
271
|
+
return __wbg_finalize_init(instance, module);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async function __wbg_init(module_or_path) {
|
|
275
|
+
if (wasm !== undefined) return wasm;
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
if (module_or_path !== undefined) {
|
|
279
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
280
|
+
({module_or_path} = module_or_path)
|
|
281
|
+
} else {
|
|
282
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (module_or_path === undefined) {
|
|
287
|
+
module_or_path = new URL('zfb_md_wasm_parse_bg.wasm', import.meta.url);
|
|
288
|
+
}
|
|
289
|
+
const imports = __wbg_get_imports();
|
|
290
|
+
|
|
291
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
292
|
+
module_or_path = fetch(module_or_path);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
296
|
+
|
|
297
|
+
return __wbg_finalize_init(instance, module);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __forceTrapForTests: () => void;
|
|
5
|
+
export const renderHtml: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
6
|
+
export const version: (a: number) => void;
|
|
7
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
8
|
+
export const __wbindgen_export: (a: number, b: number) => number;
|
|
9
|
+
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
10
|
+
export const __wbindgen_export3: (a: number, b: number, c: number) => void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Deliberately trap the current WebAssembly instance for wrapper recovery
|
|
6
|
+
* tests. This is not part of the typed package API; the JavaScript wrapper
|
|
7
|
+
* exposes it only through its internal test hook.
|
|
8
|
+
*
|
|
9
|
+
* A Rust panic is the reliable cross-engine representation of the real
|
|
10
|
+
* failure this hook needs to exercise. Calling a generated raw C-ABI export
|
|
11
|
+
* with fabricated pointers could instead enter undefined Rust-level work and
|
|
12
|
+
* hang Chromium before reaching the wasm trap boundary.
|
|
13
|
+
*/
|
|
14
|
+
export function __forceTrapForTests(): void;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Render markdown source to an HTML fragment (no SWC at runtime).
|
|
18
|
+
*
|
|
19
|
+
* Returns a JSON string: `{ "html": string|null, "frontmatter": json,
|
|
20
|
+
* "diagnostics": Diagnostic[] }` — see the crate docs for the options
|
|
21
|
+
* and diagnostics shapes. A `.md` filename selects CommonMark and `.mdx`
|
|
22
|
+
* selects MDX unless the top-level `dialect` option overrides it. Exported
|
|
23
|
+
* to JS as `renderHtml`.
|
|
24
|
+
*/
|
|
25
|
+
export function renderHtml(source: string, options_json: string): string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This package's release version, stamped by CI at compile time.
|
|
29
|
+
*
|
|
30
|
+
* Development builds without `ZFB_RELEASE_VERSION` fall back to this crate's
|
|
31
|
+
* manifest version (`CARGO_PKG_VERSION`).
|
|
32
|
+
*/
|
|
33
|
+
export function version(): string;
|
|
34
|
+
|
|
35
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
36
|
+
|
|
37
|
+
export interface InitOutput {
|
|
38
|
+
readonly memory: WebAssembly.Memory;
|
|
39
|
+
readonly __forceTrapForTests: () => void;
|
|
40
|
+
readonly renderHtml: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
41
|
+
readonly version: (a: number) => void;
|
|
42
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
43
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
44
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
45
|
+
readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
52
|
+
* a precompiled `WebAssembly.Module`.
|
|
53
|
+
*
|
|
54
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
55
|
+
*
|
|
56
|
+
* @returns {InitOutput}
|
|
57
|
+
*/
|
|
58
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
62
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
63
|
+
*
|
|
64
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
65
|
+
*
|
|
66
|
+
* @returns {Promise<InitOutput>}
|
|
67
|
+
*/
|
|
68
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/* @ts-self-types="./zfb_md_wasm_render.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Deliberately trap the current WebAssembly instance for wrapper recovery
|
|
5
|
+
* tests. This is not part of the typed package API; the JavaScript wrapper
|
|
6
|
+
* exposes it only through its internal test hook.
|
|
7
|
+
*
|
|
8
|
+
* A Rust panic is the reliable cross-engine representation of the real
|
|
9
|
+
* failure this hook needs to exercise. Calling a generated raw C-ABI export
|
|
10
|
+
* with fabricated pointers could instead enter undefined Rust-level work and
|
|
11
|
+
* hang Chromium before reaching the wasm trap boundary.
|
|
12
|
+
*/
|
|
13
|
+
export function __forceTrapForTests() {
|
|
14
|
+
wasm.__forceTrapForTests();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Render markdown source to an HTML fragment (no SWC at runtime).
|
|
19
|
+
*
|
|
20
|
+
* Returns a JSON string: `{ "html": string|null, "frontmatter": json,
|
|
21
|
+
* "diagnostics": Diagnostic[] }` — see the crate docs for the options
|
|
22
|
+
* and diagnostics shapes. A `.md` filename selects CommonMark and `.mdx`
|
|
23
|
+
* selects MDX unless the top-level `dialect` option overrides it. Exported
|
|
24
|
+
* to JS as `renderHtml`.
|
|
25
|
+
* @param {string} source
|
|
26
|
+
* @param {string} options_json
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
export function renderHtml(source, options_json) {
|
|
30
|
+
let deferred3_0;
|
|
31
|
+
let deferred3_1;
|
|
32
|
+
try {
|
|
33
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
34
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
35
|
+
const len0 = WASM_VECTOR_LEN;
|
|
36
|
+
const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
37
|
+
const len1 = WASM_VECTOR_LEN;
|
|
38
|
+
wasm.renderHtml(retptr, ptr0, len0, ptr1, len1);
|
|
39
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
40
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
41
|
+
deferred3_0 = r0;
|
|
42
|
+
deferred3_1 = r1;
|
|
43
|
+
return getStringFromWasm0(r0, r1);
|
|
44
|
+
} finally {
|
|
45
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
46
|
+
wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* This package's release version, stamped by CI at compile time.
|
|
52
|
+
*
|
|
53
|
+
* Development builds without `ZFB_RELEASE_VERSION` fall back to this crate's
|
|
54
|
+
* manifest version (`CARGO_PKG_VERSION`).
|
|
55
|
+
* @returns {string}
|
|
56
|
+
*/
|
|
57
|
+
export function version() {
|
|
58
|
+
let deferred1_0;
|
|
59
|
+
let deferred1_1;
|
|
60
|
+
try {
|
|
61
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
62
|
+
wasm.version(retptr);
|
|
63
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
64
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
65
|
+
deferred1_0 = r0;
|
|
66
|
+
deferred1_1 = r1;
|
|
67
|
+
return getStringFromWasm0(r0, r1);
|
|
68
|
+
} finally {
|
|
69
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
70
|
+
wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function __wbg_get_imports() {
|
|
74
|
+
const import0 = {
|
|
75
|
+
__proto__: null,
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
__proto__: null,
|
|
79
|
+
"./zfb_md_wasm_render_bg.js": import0,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let cachedDataViewMemory0 = null;
|
|
84
|
+
function getDataViewMemory0() {
|
|
85
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
86
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
87
|
+
}
|
|
88
|
+
return cachedDataViewMemory0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getStringFromWasm0(ptr, len) {
|
|
92
|
+
return decodeText(ptr >>> 0, len);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let cachedUint8ArrayMemory0 = null;
|
|
96
|
+
function getUint8ArrayMemory0() {
|
|
97
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
98
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
99
|
+
}
|
|
100
|
+
return cachedUint8ArrayMemory0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
104
|
+
if (realloc === undefined) {
|
|
105
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
106
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
107
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
108
|
+
WASM_VECTOR_LEN = buf.length;
|
|
109
|
+
return ptr;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let len = arg.length;
|
|
113
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
114
|
+
|
|
115
|
+
const mem = getUint8ArrayMemory0();
|
|
116
|
+
|
|
117
|
+
let offset = 0;
|
|
118
|
+
|
|
119
|
+
for (; offset < len; offset++) {
|
|
120
|
+
const code = arg.charCodeAt(offset);
|
|
121
|
+
if (code > 0x7F) break;
|
|
122
|
+
mem[ptr + offset] = code;
|
|
123
|
+
}
|
|
124
|
+
if (offset !== len) {
|
|
125
|
+
if (offset !== 0) {
|
|
126
|
+
arg = arg.slice(offset);
|
|
127
|
+
}
|
|
128
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
129
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
130
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
131
|
+
|
|
132
|
+
offset += ret.written;
|
|
133
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
WASM_VECTOR_LEN = offset;
|
|
137
|
+
return ptr;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
141
|
+
cachedTextDecoder.decode();
|
|
142
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
143
|
+
let numBytesDecoded = 0;
|
|
144
|
+
function decodeText(ptr, len) {
|
|
145
|
+
numBytesDecoded += len;
|
|
146
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
147
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
148
|
+
cachedTextDecoder.decode();
|
|
149
|
+
numBytesDecoded = len;
|
|
150
|
+
}
|
|
151
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const cachedTextEncoder = new TextEncoder();
|
|
155
|
+
|
|
156
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
157
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
158
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
159
|
+
view.set(buf);
|
|
160
|
+
return {
|
|
161
|
+
read: arg.length,
|
|
162
|
+
written: buf.length
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let WASM_VECTOR_LEN = 0;
|
|
168
|
+
|
|
169
|
+
let wasmModule, wasmInstance, wasm;
|
|
170
|
+
function __wbg_finalize_init(instance, module) {
|
|
171
|
+
wasmInstance = instance;
|
|
172
|
+
wasm = instance.exports;
|
|
173
|
+
wasmModule = module;
|
|
174
|
+
cachedDataViewMemory0 = null;
|
|
175
|
+
cachedUint8ArrayMemory0 = null;
|
|
176
|
+
return wasm;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function __wbg_load(module, imports) {
|
|
180
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
181
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
182
|
+
try {
|
|
183
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
184
|
+
} catch (e) {
|
|
185
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
186
|
+
|
|
187
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
188
|
+
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);
|
|
189
|
+
|
|
190
|
+
} else { throw e; }
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const bytes = await module.arrayBuffer();
|
|
195
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
196
|
+
} else {
|
|
197
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
198
|
+
|
|
199
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
200
|
+
return { instance, module };
|
|
201
|
+
} else {
|
|
202
|
+
return instance;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function expectedResponseType(type) {
|
|
207
|
+
switch (type) {
|
|
208
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function initSync(module) {
|
|
215
|
+
if (wasm !== undefined) return wasm;
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
if (module !== undefined) {
|
|
219
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
220
|
+
({module} = module)
|
|
221
|
+
} else {
|
|
222
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const imports = __wbg_get_imports();
|
|
227
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
228
|
+
module = new WebAssembly.Module(module);
|
|
229
|
+
}
|
|
230
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
231
|
+
return __wbg_finalize_init(instance, module);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function __wbg_init(module_or_path) {
|
|
235
|
+
if (wasm !== undefined) return wasm;
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
if (module_or_path !== undefined) {
|
|
239
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
240
|
+
({module_or_path} = module_or_path)
|
|
241
|
+
} else {
|
|
242
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (module_or_path === undefined) {
|
|
247
|
+
module_or_path = new URL('zfb_md_wasm_render_bg.wasm', import.meta.url);
|
|
248
|
+
}
|
|
249
|
+
const imports = __wbg_get_imports();
|
|
250
|
+
|
|
251
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
252
|
+
module_or_path = fetch(module_or_path);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
256
|
+
|
|
257
|
+
return __wbg_finalize_init(instance, module);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export { initSync, __wbg_init as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takazudo/zfb-md-wasm",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "zfb's md/mdx -> JS/HTML conversion pipeline compiled to WebAssembly, for browser-side dynamic conversion (CMS live preview with parity to zfb's production output).",
|
|
@@ -37,6 +37,16 @@
|
|
|
37
37
|
"types": "./dist/highlight.d.ts",
|
|
38
38
|
"browser": "./dist/highlight-browser.js",
|
|
39
39
|
"default": "./dist/highlight.js"
|
|
40
|
+
},
|
|
41
|
+
"./render": {
|
|
42
|
+
"types": "./dist/render.d.ts",
|
|
43
|
+
"browser": "./dist/render-browser.js",
|
|
44
|
+
"default": "./dist/render.js"
|
|
45
|
+
},
|
|
46
|
+
"./parse": {
|
|
47
|
+
"types": "./dist/parse.d.ts",
|
|
48
|
+
"browser": "./dist/parse-browser.js",
|
|
49
|
+
"default": "./dist/parse.js"
|
|
40
50
|
}
|
|
41
51
|
},
|
|
42
52
|
"files": [
|