1 |
- {"ast":null,"code":"import htmlTrie from \"./generated/encode-html.js\";\nimport { xmlReplacer, getCodePoint } from \"./escape.js\";\nconst htmlReplacer = /[\\t\\n!-,./:-@[-`\\f{-}$\\x80-\\uFFFF]/g;\n/**\n * Encodes all characters in the input using HTML entities. This includes\n * characters that are valid ASCII characters in HTML documents, such as `#`.\n *\n * To get a more compact output, consider using the `encodeNonAsciiHTML`\n * function, which will only encode characters that are not valid in HTML\n * documents, as well as non-ASCII characters.\n *\n * If a character has no equivalent entity, a numeric hexadecimal reference\n * (eg. `ü`) will be used.\n */\nexport function encodeHTML(data) {\n return encodeHTMLTrieRe(htmlReplacer, data);\n}\n/**\n * Encodes all non-ASCII characters, as well as characters not valid in HTML\n * documents using HTML entities. This function will not encode characters that\n * are valid in HTML documents, such as `#`.\n *\n * If a character has no equivalent entity, a numeric hexadecimal reference\n * (eg. `ü`) will be used.\n */\nexport function encodeNonAsciiHTML(data) {\n return encodeHTMLTrieRe(xmlReplacer, data);\n}\nfunction encodeHTMLTrieRe(regExp, str) {\n let ret = \"\";\n let lastIdx = 0;\n let match;\n while ((match = regExp.exec(str)) !== null) {\n const i = match.index;\n ret += str.substring(lastIdx, i);\n const char = str.charCodeAt(i);\n let next = htmlTrie.get(char);\n if (typeof next === \"object\") {\n // We are in a branch. Try to match the next char.\n if (i + 1 < str.length) {\n const nextChar = str.charCodeAt(i + 1);\n const value = typeof next.n === \"number\" ? next.n === nextChar ? next.o : undefined : next.n.get(nextChar);\n if (value !== undefined) {\n ret += value;\n lastIdx = regExp.lastIndex += 1;\n continue;\n }\n }\n next = next.v;\n }\n // We might have a tree node without a value; skip and use a numeric entity.\n if (next !== undefined) {\n ret += next;\n lastIdx = i + 1;\n } else {\n const cp = getCodePoint(str, i);\n ret += `&#x${cp.toString(16)};`;\n // Increase by 1 if we have a surrogate pair\n lastIdx = regExp.lastIndex += Number(cp !== char);\n }\n }\n return ret + str.substr(lastIdx);\n}","map":{"version":3,"names":["htmlTrie","xmlReplacer","getCodePoint","htmlReplacer","encodeHTML","data","encodeHTMLTrieRe","encodeNonAsciiHTML","regExp","str","ret","lastIdx","match","exec","i","index","substring","char","charCodeAt","next","get","length","nextChar","value","n","o","undefined","lastIndex","v","cp","toString","Number","substr"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/entities/lib/esm/encode.js"],"sourcesContent":["import htmlTrie from \"./generated/encode-html.js\";\nimport { xmlReplacer, getCodePoint } from \"./escape.js\";\nconst htmlReplacer = /[\\t\\n!-,./:-@[-`\\f{-}$\\x80-\\uFFFF]/g;\n/**\n * Encodes all characters in the input using HTML entities. This includes\n * characters that are valid ASCII characters in HTML documents, such as `#`.\n *\n * To get a more compact output, consider using the `encodeNonAsciiHTML`\n * function, which will only encode characters that are not valid in HTML\n * documents, as well as non-ASCII characters.\n *\n * If a character has no equivalent entity, a numeric hexadecimal reference\n * (eg. `ü`) will be used.\n */\nexport function encodeHTML(data) {\n return encodeHTMLTrieRe(htmlReplacer, data);\n}\n/**\n * Encodes all non-ASCII characters, as well as characters not valid in HTML\n * documents using HTML entities. This function will not encode characters that\n * are valid in HTML documents, such as `#`.\n *\n * If a character has no equivalent entity, a numeric hexadecimal reference\n * (eg. `ü`) will be used.\n */\nexport function encodeNonAsciiHTML(data) {\n return encodeHTMLTrieRe(xmlReplacer, data);\n}\nfunction encodeHTMLTrieRe(regExp, str) {\n let ret = \"\";\n let lastIdx = 0;\n let match;\n while ((match = regExp.exec(str)) !== null) {\n const i = match.index;\n ret += str.substring(lastIdx, i);\n const char = str.charCodeAt(i);\n let next = htmlTrie.get(char);\n if (typeof next === \"object\") {\n // We are in a branch. Try to match the next char.\n if (i + 1 < str.length) {\n const nextChar = str.charCodeAt(i + 1);\n const value = typeof next.n === \"number\"\n ? next.n === nextChar\n ? next.o\n : undefined\n : next.n.get(nextChar);\n if (value !== undefined) {\n ret += value;\n lastIdx = regExp.lastIndex += 1;\n continue;\n }\n }\n next = next.v;\n }\n // We might have a tree node without a value; skip and use a numeric entity.\n if (next !== undefined) {\n ret += next;\n lastIdx = i + 1;\n }\n else {\n const cp = getCodePoint(str, i);\n ret += `&#x${cp.toString(16)};`;\n // Increase by 1 if we have a surrogate pair\n lastIdx = regExp.lastIndex += Number(cp !== char);\n }\n }\n return ret + str.substr(lastIdx);\n}\n"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,4BAA4B;AACjD,SAASC,WAAW,EAAEC,YAAY,QAAQ,aAAa;AACvD,MAAMC,YAAY,GAAG,qCAAqC;AAC1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,IAAI,EAAE;EAC7B,OAAOC,gBAAgB,CAACH,YAAY,EAAEE,IAAI,CAAC;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,kBAAkBA,CAACF,IAAI,EAAE;EACrC,OAAOC,gBAAgB,CAACL,WAAW,EAAEI,IAAI,CAAC;AAC9C;AACA,SAASC,gBAAgBA,CAACE,MAAM,EAAEC,GAAG,EAAE;EACnC,IAAIC,GAAG,GAAG,EAAE;EACZ,IAAIC,OAAO,GAAG,CAAC;EACf,IAAIC,KAAK;EACT,OAAO,CAACA,KAAK,GAAGJ,MAAM,CAACK,IAAI,CAACJ,GAAG,CAAC,MAAM,IAAI,EAAE;IACxC,MAAMK,CAAC,GAAGF,KAAK,CAACG,KAAK;IACrBL,GAAG,IAAID,GAAG,CAACO,SAAS,CAACL,OAAO,EAAEG,CAAC,CAAC;IAChC,MAAMG,IAAI,GAAGR,GAAG,CAACS,UAAU,CAACJ,CAAC,CAAC;IAC9B,IAAIK,IAAI,GAAGnB,QAAQ,CAACoB,GAAG,CAACH,IAAI,CAAC;IAC7B,IAAI,OAAOE,IAAI,KAAK,QAAQ,EAAE;MAC1B;MACA,IAAIL,CAAC,GAAG,CAAC,GAAGL,GAAG,CAACY,MAAM,EAAE;QACpB,MAAMC,QAAQ,GAAGb,GAAG,CAACS,UAAU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