'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports[Symbol.toStringTag] = 'Module'; let wasm; const heap = new Array(32).fill(undefined); heap.push(undefined, null, true, false); function getObject(idx) { return heap[idx]; } let WASM_VECTOR_LEN = 0; let cachegetUint8Memory0 = null; function getUint8Memory0() { if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) { cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer); } return cachegetUint8Memory0; } let cachedTextEncoder = new TextEncoder('utf-8'); const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' ? function (arg, view) { return cachedTextEncoder.encodeInto(arg, view); } : function (arg, view) { const buf = cachedTextEncoder.encode(arg); view.set(buf); return { read: arg.length, written: buf.length }; }); function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length); getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; } let len = arg.length; let ptr = malloc(len); const mem = getUint8Memory0(); let offset = 0; for (; offset < len; offset++) { const code = arg.charCodeAt(offset); if (code > 0x7F) break; mem[ptr + offset] = code; } if (offset !== len) { if (offset !== 0) { arg = arg.slice(offset); } ptr = realloc(ptr, len, len = offset + arg.length * 3); const view = getUint8Memory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); offset += ret.written; } WASM_VECTOR_LEN = offset; return ptr; } let cachegetInt32Memory0 = null; function getInt32Memory0() { if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); } return cachegetInt32Memory0; } let heap_next = heap.length; function dropObject(idx) { if (idx < 36) return; heap[idx] = heap_next; heap_next = idx; } function takeObject(idx) { const ret = getObject(idx); dropObject(idx); return ret; } let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); function getStringFromWasm0(ptr, len) { return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; heap_next = heap[idx]; heap[idx] = obj; return idx; } function _assertClass(instance, klass) { if (!(instance instanceof klass)) { throw new Error(`expected instance of ${klass.name}`); } return instance.ptr; } /** * @param {PageInfo} page_info * @param {SyntaxTree} syntax_tree * @returns {HtmlOutput} */ function render_html(page_info, syntax_tree) { _assertClass(page_info, PageInfo); var ptr0 = page_info.ptr; page_info.ptr = 0; _assertClass(syntax_tree, SyntaxTree); var ptr1 = syntax_tree.ptr; syntax_tree.ptr = 0; var ret = wasm.render_html(ptr0, ptr1); return HtmlOutput.__wrap(ret); } /** * @param {PageInfo} page_info * @param {SyntaxTree} syntax_tree * @returns {string} */ function render_text(page_info, syntax_tree) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(page_info, PageInfo); var ptr0 = page_info.ptr; page_info.ptr = 0; _assertClass(syntax_tree, SyntaxTree); var ptr1 = syntax_tree.ptr; syntax_tree.ptr = 0; wasm.render_text(retptr, ptr0, ptr1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_free(r0, r1); } } /** * @returns {string} */ function version$1() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.version(retptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_free(r0, r1); } } /** * @param {string} text * @returns {Tokenization} */ function tokenize$1(text) { var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len0 = WASM_VECTOR_LEN; var ret = wasm.tokenize(ptr0, len0); return Tokenization.__wrap(ret); } /** * @param {PageInfo} page_info * @param {Tokenization} tokens * @returns {ParseOutcome} */ function parse$1(page_info, tokens) { _assertClass(page_info, PageInfo); var ptr0 = page_info.ptr; page_info.ptr = 0; _assertClass(tokens, Tokenization); var ptr1 = tokens.ptr; tokens.ptr = 0; var ret = wasm.parse(ptr0, ptr1); return ParseOutcome.__wrap(ret); } /** * @param {string} text * @returns {string} */ function preprocess$1(text) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len0 = WASM_VECTOR_LEN; wasm.preprocess(retptr, ptr0, len0); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_free(r0, r1); } } /** */ class HtmlOutput { static __wrap(ptr) { const obj = Object.create(HtmlOutput.prototype); obj.ptr = ptr; return obj; } __destroy_into_raw() { const ptr = this.ptr; this.ptr = 0; return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_htmloutput_free(ptr); } /** * @returns {HtmlOutput} */ copy() { var ret = wasm.htmloutput_copy(this.ptr); return HtmlOutput.__wrap(ret); } /** * @returns {string} */ body() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.htmloutput_body(retptr, this.ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_free(r0, r1); } } /** * @returns {string[]} */ styles() { var ret = wasm.htmloutput_styles(this.ptr); return takeObject(ret); } /** * @returns {IHtmlMeta[]} */ html_meta() { var ret = wasm.htmloutput_html_meta(this.ptr); return takeObject(ret); } /** * @returns {IBacklinks} */ backlinks() { var ret = wasm.htmloutput_backlinks(this.ptr); return takeObject(ret); } } /** */ class PageInfo { static __wrap(ptr) { const obj = Object.create(PageInfo.prototype); obj.ptr = ptr; return obj; } __destroy_into_raw() { const ptr = this.ptr; this.ptr = 0; return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_pageinfo_free(ptr); } /** * @returns {PageInfo} */ copy() { var ret = wasm.pageinfo_copy(this.ptr); return PageInfo.__wrap(ret); } /** * @param {IPageInfo} object */ constructor(object) { var ret = wasm.pageinfo_new(addHeapObject(object)); return PageInfo.__wrap(ret); } /** * @returns {string} */ get page() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.pageinfo_page(retptr, this.ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_free(r0, r1); } } /** * @returns {string | undefined} */ get category() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.pageinfo_category(retptr, this.ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; let v0; if (r0 !== 0) { v0 = getStringFromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1); } return v0; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * @returns {string} */ get site() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.pageinfo_site(retptr, this.ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_free(r0, r1); } } /** * @returns {string} */ get title() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.pageinfo_title(retptr, this.ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_free(r0, r1); } } /** * @returns {string | undefined} */ get alt_title() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.pageinfo_alt_title(retptr, this.ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; let v0; if (r0 !== 0) { v0 = getStringFromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1); } return v0; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * @returns {number} */ get rating() { var ret = wasm.pageinfo_rating(this.ptr); return ret; } /** * @returns {string[]} */ get tags() { var ret = wasm.pageinfo_tags(this.ptr); return takeObject(ret); } /** * @returns {string} */ get language() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.pageinfo_language(retptr, this.ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_free(r0, r1); } } } /** */ class ParseOutcome { static __wrap(ptr) { const obj = Object.create(ParseOutcome.prototype); obj.ptr = ptr; return obj; } __destroy_into_raw() { const ptr = this.ptr; this.ptr = 0; return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_parseoutcome_free(ptr); } /** * @returns {ParseOutcome} */ copy() { var ret = wasm.parseoutcome_copy(this.ptr); return ParseOutcome.__wrap(ret); } /** * @returns {SyntaxTree} */ syntax_tree() { var ret = wasm.parseoutcome_syntax_tree(this.ptr); return SyntaxTree.__wrap(ret); } /** * @returns {IParseWarning[]} */ warnings() { var ret = wasm.parseoutcome_warnings(this.ptr); return takeObject(ret); } } /** */ class SyntaxTree { static __wrap(ptr) { const obj = Object.create(SyntaxTree.prototype); obj.ptr = ptr; return obj; } __destroy_into_raw() { const ptr = this.ptr; this.ptr = 0; return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_syntaxtree_free(ptr); } /** * @returns {SyntaxTree} */ copy() { var ret = wasm.parseoutcome_copy(this.ptr); return SyntaxTree.__wrap(ret); } /** * @returns {ISyntaxTree} */ data() { var ret = wasm.syntaxtree_data(this.ptr); return takeObject(ret); } } /** */ class Tokenization { static __wrap(ptr) { const obj = Object.create(Tokenization.prototype); obj.ptr = ptr; return obj; } __destroy_into_raw() { const ptr = this.ptr; this.ptr = 0; return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_tokenization_free(ptr); } /** * @returns {Tokenization} */ copy() { var ret = wasm.tokenization_copy(this.ptr); return Tokenization.__wrap(ret); } /** * @returns {string} */ text() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.tokenization_text(retptr, this.ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_free(r0, r1); } } /** * @returns {IToken[]} */ tokens() { var ret = wasm.tokenization_tokens(this.ptr); return takeObject(ret); } } /** */ class Utf16IndexMap { static __wrap(ptr) { const obj = Object.create(Utf16IndexMap.prototype); obj.ptr = ptr; return obj; } __destroy_into_raw() { const ptr = this.ptr; this.ptr = 0; return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_utf16indexmap_free(ptr); } /** * @param {string} text */ constructor(text) { var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len0 = WASM_VECTOR_LEN; var ret = wasm.utf16indexmap_new(ptr0, len0); return Utf16IndexMap.__wrap(ret); } /** * @returns {Utf16IndexMap} */ copy() { var ret = wasm.utf16indexmap_copy(this.ptr); return Utf16IndexMap.__wrap(ret); } /** * @param {number} index * @returns {number} */ get_index(index) { var ret = wasm.utf16indexmap_get_index(this.ptr, index); return ret >>> 0; } } async function load(module, imports) { if (typeof Response === 'function' && module instanceof Response) { if (typeof WebAssembly.instantiateStreaming === 'function') { try { return await WebAssembly.instantiateStreaming(module, imports); } catch (e) { if (module.headers.get('Content-Type') != 'application/wasm') { 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); } else { throw e; } } } const bytes = await module.arrayBuffer(); return await WebAssembly.instantiate(bytes, imports); } else { const instance = await WebAssembly.instantiate(module, imports); if (instance instanceof WebAssembly.Instance) { return { instance, module }; } else { return instance; } } } async function init$1(input) { const imports = {}; imports.wbg = {}; imports.wbg.__wbindgen_json_serialize = function(arg0, arg1) { const obj = getObject(arg1); var ret = JSON.stringify(obj === undefined ? null : obj); var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len0 = WASM_VECTOR_LEN; getInt32Memory0()[arg0 / 4 + 1] = len0; getInt32Memory0()[arg0 / 4 + 0] = ptr0; }; imports.wbg.__wbindgen_object_drop_ref = function(arg0) { takeObject(arg0); }; imports.wbg.__wbindgen_string_new = function(arg0, arg1) { var ret = getStringFromWasm0(arg0, arg1); return addHeapObject(ret); }; imports.wbg.__wbindgen_json_parse = function(arg0, arg1) { var ret = JSON.parse(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); }; imports.wbg.__wbindgen_throw = function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; imports.wbg.__wbindgen_rethrow = function(arg0) { throw takeObject(arg0); }; if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) { input = fetch(input); } const { instance, module } = await load(await input, imports); wasm = instance.exports; init$1.__wbindgen_wasm_module = module; return wasm; } exports.ready = false; let resolveLoading; const loading = new Promise((resolve) => { resolveLoading = resolve; }); async function init(path) { if (!path) path = (await Promise.resolve().then(function () { return require('./ftml_bg.js'); })).default; await init$1(path); exports.ready = true; resolveLoading(); } function free(objs) { for (const obj of objs) { if (typeof obj !== "object" || !("ptr" in obj)) continue; if (obj.ptr !== 0) obj.free(); } } const tracked = new Set(); function trk(obj) { tracked.add(obj); return obj; } function freeTracked() { setTimeout(() => { free(tracked); tracked.clear(); }); } function makeInfo(partial) { return { alt_title: null, category: null, language: "default", rating: 0, page: "unknown", site: "www", tags: [], title: "", ...partial }; } function version() { if (!exports.ready) throw new Error("FTML wasn't ready yet!"); return version$1(); } function preprocess(str) { if (!exports.ready) throw new Error("FTML wasn't ready yet!"); return preprocess$1(str); } function tokenize(str) { if (!exports.ready) throw new Error("FTML wasn't ready yet!"); try { const tokenized = trk(tokenize$1(str)); const tokens = tokenized.tokens(); freeTracked(); return tokens; } catch (err) { freeTracked(); throw err; } } function parse(str, info) { if (!exports.ready) throw new Error("FTML wasn't ready yet!"); try { const tokenized = trk(tokenize$1(str)); const pageInfo = trk(new PageInfo(makeInfo(info))); const parsed = trk(parse$1(pageInfo, tokenized)); const tree = trk(parsed.syntax_tree()); const ast = tree.data(); const warnings2 = parsed.warnings(); freeTracked(); return { ast, warnings: warnings2 }; } catch (err) { freeTracked(); throw err; } } function warnings(str, info) { if (!exports.ready) throw new Error("FTML wasn't ready yet!"); try { const pageInfo = trk(new PageInfo(makeInfo(info))); const tokenized = trk(tokenize$1(str)); const parsed = trk(parse$1(pageInfo, tokenized)); const warnings2 = parsed.warnings(); freeTracked(); return warnings2; } catch (err) { freeTracked(); throw err; } } function renderHTML(str, info) { if (!exports.ready) throw new Error("FTML wasn't ready yet!"); try { const pageInfo = trk(new PageInfo(makeInfo(info))); const tokenized = trk(tokenize$1(str)); const parsed = trk(parse$1(trk(pageInfo.copy()), tokenized)); const tree = trk(parsed.syntax_tree()); const rendered = trk(render_html(pageInfo, tree)); const html = rendered.body(); const meta = rendered.html_meta(); const styles = rendered.styles(); const backlinks = rendered.backlinks(); freeTracked(); return { html, meta, styles, backlinks }; } catch (err) { freeTracked(); throw err; } } function detailRenderHTML(str, info) { if (!exports.ready) throw new Error("FTML wasn't ready yet!"); try { const pageInfo = trk(new PageInfo(makeInfo(info))); const tokenized = trk(tokenize$1(str)); const tokens = tokenized.tokens(); const parsed = trk(parse$1(trk(pageInfo.copy()), tokenized)); const tree = trk(parsed.syntax_tree()); const ast = tree.data(); const warnings2 = parsed.warnings(); const rendered = trk(render_html(pageInfo, tree)); const html = rendered.body(); const meta = rendered.html_meta(); const styles = rendered.styles(); const backlinks = rendered.backlinks(); freeTracked(); return { tokens, ast, warnings: warnings2, html, meta, styles, backlinks }; } catch (err) { freeTracked(); throw err; } } function renderText(str, info) { if (!exports.ready) throw new Error("FTML wasn't ready yet!"); try { const pageInfo = trk(new PageInfo(makeInfo(info))); const tokenized = trk(tokenize$1(str)); const parsed = trk(parse$1(trk(pageInfo.copy()), tokenized)); const tree = trk(parsed.syntax_tree()); const text = render_text(pageInfo, tree); freeTracked(); return text; } catch (err) { freeTracked(); throw err; } } function detailRenderText(str, info) { if (!exports.ready) throw new Error("FTML wasn't ready yet!"); try { const pageInfo = trk(new PageInfo(makeInfo(info))); const tokenized = trk(tokenize$1(str)); const tokens = tokenized.tokens(); const parsed = trk(parse$1(trk(pageInfo.copy()), tokenized)); const tree = trk(parsed.syntax_tree()); const ast = tree.data(); const warnings2 = parsed.warnings(); const text = render_text(pageInfo, tree); freeTracked(); return { tokens, ast, warnings: warnings2, text }; } catch (err) { freeTracked(); throw err; } } function getUTF16IndexMap(str) { if (!exports.ready) throw new Error("FTML wasn't ready yet!"); const map = new Utf16IndexMap(str); const mapFunction = (pos) => map.get_index(pos); mapFunction.free = () => map.free(); return mapFunction; } class Page { constructor(source, info, preprocessSource = true) { this.source = preprocessSource ? preprocess(source) : source; this.info = makeInfo(info); } ensureRendered(detailed) { if (!this.rendered || detailed && !("tokens" in this.rendered)) { this.rendered = detailed ? detailRenderHTML(this.source, this.info) : renderHTML(this.source, this.info); } return this.rendered; } updateSource(source, preprocessSource = true) { this.source = preprocessSource ? preprocess(source) : source; this.rendered = void 0; } updateInfo(info) { this.info = makeInfo({ ...this.info, ...info }); this.rendered = void 0; } get html() { return this.ensureRendered(false).html; } get meta() { return this.ensureRendered(false).meta; } get styles() { return this.ensureRendered(false).styles; } get backlinks() { return this.ensureRendered(false).backlinks; } get tokens() { return this.ensureRendered(true).tokens; } get ast() { return this.ensureRendered(true).ast; } get warnings() { return this.ensureRendered(true).warnings; } get text() { return renderText(this.source, this.info); } } function inspectTokens(str, preprocess = true) { if (!exports.ready) throw new Error("FTML wasn't ready yet!"); try { str = preprocess ? preprocess$1(str) : str; const tokenized = trk(tokenize$1(str)); const tokens = tokenized.tokens(); freeTracked(); let out = ""; for (const { slice, span: { start, end }, token } of tokens) { const tokenStr = String(token.padEnd(16)); const startStr = String(start).padStart(4, "0"); const endStr = String(end).padStart(4, "0"); const sliceStr = slice.slice(0, 40).replaceAll("\n", "\\n"); out += `[${startStr} <-> ${endStr}]: ${tokenStr} => '${sliceStr}' `; } return out; } catch (err) { freeTracked(); throw err; } } exports.Page = Page; exports.detailRenderHTML = detailRenderHTML; exports.detailRenderText = detailRenderText; exports.getUTF16IndexMap = getUTF16IndexMap; exports.init = init; exports.inspectTokens = inspectTokens; exports.loading = loading; exports.makeInfo = makeInfo; exports.parse = parse; exports.preprocess = preprocess; exports.renderHTML = renderHTML; exports.renderText = renderText; exports.tokenize = tokenize; exports.version = version; exports.warnings = warnings; //# sourceMappingURL=wj-ftml-wasm.cjs.map