@takazudo/zfb-md-wasm 2.7.0 → 2.8.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 +153 -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,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.8.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": [
|