UNPKG

rphtml

Version:

A html parser written in rust, use wasm-pack for Nodejs package.

402 lines (345 loc) 10.6 kB
let imports = {}; imports['__wbindgen_placeholder__'] = module.exports; let wasm; const { TextEncoder, TextDecoder } = require(String.raw`util`); 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 isLikeNone(x) { return x === undefined || x === null; } /** * @param {string} content * @param {IJsParseOptions | undefined} options * @returns {IJsNode} */ module.exports.parse = function(content, options) { var ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len0 = WASM_VECTOR_LEN; var ret = wasm.parse(ptr0, len0, isLikeNone(options) ? 0 : addHeapObject(options)); return IJsNode.__wrap(ret); }; function handleError(f) { return function () { try { return f.apply(this, arguments); } catch (e) { wasm.__wbindgen_exn_store(addHeapObject(e)); } }; } function getArrayU8FromWasm0(ptr, len) { return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); } /** * @param {string} content * @param {number | undefined} entities * @param {number | undefined} encode_type * @returns {IString} */ module.exports.encode = function(content, entities, encode_type) { var ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len0 = WASM_VECTOR_LEN; var ret = wasm.encode(ptr0, len0, isLikeNone(entities) ? 5 : entities, isLikeNone(encode_type) ? 6 : encode_type); return takeObject(ret); }; /** * @param {string} content * @returns {IString} */ module.exports.decode = function(content) { var ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len0 = WASM_VECTOR_LEN; var ret = wasm.decode(ptr0, len0); return takeObject(ret); }; /** * @param {number} entity_set * @param {string} ch * @returns {boolean} */ module.exports.contains = function(entity_set, ch) { var ret = wasm.contains(entity_set, ch.codePointAt(0)); return ret !== 0; }; /** */ module.exports.NodeType = Object.freeze({ AbstractRoot:0,"0":"AbstractRoot",HTMLDOCTYPE:1,"1":"HTMLDOCTYPE",Comment:2,"2":"Comment",Text:3,"3":"Text",SpacesBetweenTag:4,"4":"SpacesBetweenTag",Tag:5,"5":"Tag",TagEnd:6,"6":"TagEnd",XMLCDATA:7,"7":"XMLCDATA", }); /** * The type of characters you need encoded, default: `SpecialCharsAndNoASCII` */ module.exports.EntitySet = Object.freeze({ Empty:0,"0":"Empty", /** * encode all */ All:1,"1":"All", /** * encode character not ascii */ NoASCII:2,"2":"NoASCII", /** * encode '<','>','&', main for entity in text node when call element's `innerHtml()` method */ Html:3,"3":"Html", /** * encode '<','>','&', '\'', '"' */ SpecialChars:4,"4":"SpecialChars", /** * this is default */ SpecialCharsAndNoASCII:6,"6":"SpecialCharsAndNoASCII", }); /** * EncodeType: the output format type, default: `NamedOrDecimal` */ module.exports.EncodeType = Object.freeze({ Ignore:0,"0":"Ignore",Named:1,"1":"Named",Hex:2,"2":"Hex",Decimal:4,"4":"Decimal",NamedOrHex:3,"3":"NamedOrHex",NamedOrDecimal:5,"5":"NamedOrDecimal", }); /** * * * the doc's position */ class CodePosAt { free() { const ptr = this.ptr; this.ptr = 0; wasm.__wbg_codeposat_free(ptr); } /** * @returns {number} */ get line_no() { var ret = wasm.__wbg_get_codeposat_line_no(this.ptr); return ret >>> 0; } /** * @param {number} arg0 */ set line_no(arg0) { wasm.__wbg_set_codeposat_line_no(this.ptr, arg0); } /** * @returns {number} */ get col_no() { var ret = wasm.__wbg_get_codeposat_col_no(this.ptr); return ret >>> 0; } /** * @param {number} arg0 */ set col_no(arg0) { wasm.__wbg_set_codeposat_col_no(this.ptr, arg0); } /** * @returns {number} */ get index() { var ret = wasm.__wbg_get_codeposat_index(this.ptr); return ret >>> 0; } /** * @param {number} arg0 */ set index(arg0) { wasm.__wbg_set_codeposat_index(this.ptr, arg0); } } module.exports.CodePosAt = CodePosAt; /** */ class IJsNode { static __wrap(ptr) { const obj = Object.create(IJsNode.prototype); obj.ptr = ptr; return obj; } free() { const ptr = this.ptr; this.ptr = 0; wasm.__wbg_ijsnode_free(ptr); } /** * @returns {IJsNodeTree} */ toJson() { var ret = wasm.ijsnode_toJson(this.ptr); return takeObject(ret); } /** * @returns {IJsString} */ toString() { var ret = wasm.ijsnode_toString(this.ptr); return takeObject(ret); } /** * @param {IJsRenderOptions | undefined} options * @returns {IJsString} */ render(options) { var ret = wasm.ijsnode_render(this.ptr, isLikeNone(options) ? 0 : addHeapObject(options)); return takeObject(ret); } /** * @param {string} uuid * @returns {IJsNode | undefined} */ getTagByUuid(uuid) { var ptr0 = passStringToWasm0(uuid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len0 = WASM_VECTOR_LEN; var ret = wasm.ijsnode_getTagByUuid(this.ptr, ptr0, len0); return ret === 0 ? undefined : IJsNode.__wrap(ret); } /** * @returns {boolean} */ isAloneTag() { var ret = wasm.ijsnode_isAloneTag(this.ptr); return ret !== 0; } } module.exports.IJsNode = IJsNode; module.exports.__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; }; module.exports.__wbindgen_object_drop_ref = function(arg0) { takeObject(arg0); }; module.exports.__wbindgen_json_parse = function(arg0, arg1) { var ret = JSON.parse(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); }; module.exports.__wbindgen_string_new = function(arg0, arg1) { var ret = getStringFromWasm0(arg0, arg1); return addHeapObject(ret); }; module.exports.__wbg_getRandomValues_3ac1b33c90b52596 = function(arg0, arg1, arg2) { getObject(arg0).getRandomValues(getArrayU8FromWasm0(arg1, arg2)); }; module.exports.__wbg_randomFillSync_6f956029658662ec = function(arg0, arg1, arg2) { getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2)); }; module.exports.__wbg_self_1c83eb4471d9eb9b = handleError(function() { var ret = self.self; return addHeapObject(ret); }); module.exports.__wbg_static_accessor_MODULE_abf5ae284bffdf45 = function() { var ret = module; return addHeapObject(ret); }; module.exports.__wbg_require_5b2b5b594d809d9f = function(arg0, arg1, arg2) { var ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2)); return addHeapObject(ret); }; module.exports.__wbg_crypto_c12f14e810edcaa2 = function(arg0) { var ret = getObject(arg0).crypto; return addHeapObject(ret); }; module.exports.__wbg_msCrypto_679be765111ba775 = function(arg0) { var ret = getObject(arg0).msCrypto; return addHeapObject(ret); }; module.exports.__wbindgen_is_undefined = function(arg0) { var ret = getObject(arg0) === undefined; return ret; }; module.exports.__wbg_getRandomValues_05a60bf171bfc2be = function(arg0) { var ret = getObject(arg0).getRandomValues; return addHeapObject(ret); }; module.exports.__wbindgen_throw = function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; module.exports.__wbindgen_rethrow = function(arg0) { throw takeObject(arg0); }; const path = require('path').join(__dirname, 'rphtml_bg.wasm'); const bytes = require('fs').readFileSync(path); const wasmModule = new WebAssembly.Module(bytes); const wasmInstance = new WebAssembly.Instance(wasmModule, imports); wasm = wasmInstance.exports; module.exports.__wasm = wasm;