"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("../../../../character-entities-legacy@3.0.0/node_modules/character-entities-legacy/index.cjs.js"),I=require("../../../../character-reference-invalid@2.0.1/node_modules/character-reference-invalid/index.cjs.js"),H=require("../../../../is-decimal@2.0.1/node_modules/is-decimal/index.cjs.js"),L=require("../../../../is-hexadecimal@2.0.1/node_modules/is-hexadecimal/index.cjs.js"),j=require("../../../../is-alphanumerical@2.0.1/node_modules/is-alphanumerical/index.cjs.js"),k=require("../../../../decode-named-character-reference@1.2.0/node_modules/decode-named-character-reference/index.dom.cjs.js"),M=["","Named character references must be terminated by a semicolon","Numeric character references must be terminated by a semicolon","Named character references cannot be empty","Numeric character references cannot be empty","Named character references must be known","Numeric character references cannot be disallowed","Numeric character references cannot be outside the permissible Unicode range"];function O(t,_){const n={},q=typeof n.additional=="string"?n.additional.charCodeAt(0):n.additional,A=[];let d=0,R=-1,h="",m,S;n.position&&("start"in n.position||"indent"in n.position?(S=n.position.indent,m=n.position.start):m=n.position);let $=(m?m.line:0)||1,u=(m?m.column:0)||1,y=b(),x;for(d--;++d<=t.length;)if(x===10&&(u=(S?S[R]:0)||1),x=t.charCodeAt(d),x===38){const r=t.charCodeAt(d+1);if(r===9||r===10||r===12||r===32||r===38||r===60||Number.isNaN(r)||q&&r===q){h+=String.fromCharCode(x),u++;continue}const s=d+1;let o=s,i=s,a;if(r===35){i=++o;const e=t.charCodeAt(i);e===88||e===120?(a="hexadecimal",i=++o):a="decimal"}else a="named";let N="",C="",f="";const T=a==="named"?j.isAlphanumerical:a==="decimal"?H.isDecimal:L.isHexadecimal;for(i--;++i<=t.length;){const e=t.charCodeAt(i);if(!T(e))break;f+=String.fromCharCode(e),a==="named"&&D.characterEntitiesLegacy.includes(f)&&(N=f,C=k.decodeNamedCharacterReference(f))}let p=t.charCodeAt(i)===59;if(p){i++;const e=a==="named"?k.decodeNamedCharacterReference(f):!1;e&&(N=f,C=e)}let l=1+i-s,g="";if(!(!p&&n.nonTerminated===!1))if(!f)a!=="named"&&c(4,l);else if(a==="named"){if(p&&!C)c(5,1);else if(N!==f&&(i=o+N.length,l=1+i-o,p=!1),!p){const e=N?1:3;if(n.attribute){const w=t.charCodeAt(i);w===61?(c(e,l),C=""):j.isAlphanumerical(w)?C="":c(e,l)}else c(e,l)}g=C}else{p||c(2,l);let e=Number.parseInt(f,a==="hexadecimal"?16:10);if(P(e))c(7,l),g="�";else if(e in I.characterReferenceInvalid)c(6,l),g=I.characterReferenceInvalid[e];else{let w="";U(e)&&c(6,l),e>65535&&(e-=65536,w+=String.fromCharCode(e>>>10|55296),e=56320|e&1023),g=w+String.fromCharCode(e)}}if(g){E(),y=b(),d=i-1,u+=i-s+1,A.push(g);const e=b();e.offset++,n.reference&&n.reference.call(n.referenceContext||void 0,g,{start:y,end:e},t.slice(s-1,i)),y=e}else f=t.slice(s-1,i),h+=f,u+=f.length,d=i-1}else x===10&&($++,R++,u=0),Number.isNaN(x)?E():(h+=String.fromCharCode(x),u++);return A.join("");function b(){return{line:$,column:u,offset:d+((m?m.offset:0)||0)}}function c(r,s){let o;n.warning&&(o=b(),o.column+=s,o.offset+=s,n.warning.call(n.warningContext||void 0,M[r],o,r))}function E(){h&&(A.push(h),n.text&&n.text.call(n.textContext||void 0,h,{start:y,end:b()}),h="")}}function P(t){return t>=55296&&t<=57343||t>1114111}function U(t){return t>=1&&t<=8||t===11||t>=13&&t<=31||t>=127&&t<=159||t>=64976&&t<=65007||(t&65535)===65535||(t&65535)===65534}exports.parseEntities=O;
//# sourceMappingURL=index.cjs.js.map
